source: trunk/CrypPlugins/Libs/OpenCLNet/SimpleOCLHelper.cs @ 2040

Last change on this file since 2040 was 2040, checked in by Sven Rech, 11 years ago
  • added OpenCL.Net project
  • added OpenCL settings in KeySearcher
  • changed rereservation status message behavior
File size: 3.0 KB
RevLine 
[2040]1/*
2 * Copyright (c) 2009 Olav Kalgraf(olav.kalgraf@gmail.com)
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26using System;
27using System.Collections.Generic;
28using System.Linq;
29using System.Text;
30
31namespace OpenCLNet
32{
33    [Obsolete("SimpleOCLHelper is superseded by OpenCLManager")]
34    public class SimpleOCLHelper
35    {
36        public Platform Platform;
37        /// <summary>
38        /// The devices bound to the Helper
39        /// </summary>
40        public Device[] Devices;
41        /// <summary>
42        /// The Context associated with this Helper
43        /// </summary>
44        public Context Context;
45        /// <summary>
46        /// CommandQueue for device with same index
47        /// </summary>
48        public CommandQueue[] CQs;
49        /// <summary>
50        /// Alias for CQs[0]
51        /// </summary>
52        public CommandQueue CQ;
53        public Program Program;
54        protected Dictionary<string, Kernel> Kernels;
55
56        public SimpleOCLHelper(Platform platform, DeviceType deviceType, string source)
57        {
58            Platform = platform;
59            Initialize(deviceType, source);
60        }
61
62        protected virtual void Initialize(DeviceType deviceType, string source)
63        {
64            Devices = Platform.QueryDevices(deviceType);
65            if (Devices.Length == 0)
66                throw new OpenCLException("No devices of type "+deviceType+" present");
67
68            Context = Platform.CreateContext(null,Devices,null, IntPtr.Zero);
69            CQs = new CommandQueue[Devices.Length];
70            for( int i=0; i<CQs.Length; i++ )
71                CQs[i] = Context.CreateCommandQueue(Devices[i], CommandQueueProperties.PROFILING_ENABLE);
72            CQ = CQs[0];
73            Program = Context.CreateProgramWithSource(source);
74            Program.Build();
75            Kernels = Program.CreateKernelDictionary();
76        }
77
78        public Kernel GetKernel(string kernelName)
79        {
80            return Kernels[kernelName];
81        }
82    }
83}
Note: See TracBrowser for help on using the repository browser.