source: trunk/CrypPlugins/Libs/OpenCLNet/Device.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: 28.3 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.ComponentModel;
29using System.Runtime.InteropServices;
30using System.Runtime.InteropServices.ComTypes;
31using System.Text;
32using System.IO;
33
34namespace OpenCLNet
35{
36    unsafe public class Device : IDisposable, InteropTools.IPropertyContainer
37    {
38        protected HashSet<string> ExtensionHashSet = new HashSet<string>();
39        private bool IsSubDevice;
40        // Track whether Dispose has been called.
41        private bool disposed = false;
42       
43        internal Device(Platform platform, IntPtr deviceID)
44        {
45            Platform = platform;
46            DeviceID = deviceID;
47
48            InitializeExtensionHashSet();
49        }
50
51        // Use C# destructor syntax for finalization code.
52        // This destructor will run only if the Dispose method
53        // does not get called.
54        // It gives your base class the opportunity to finalize.
55        // Do not provide destructors in types derived from this class.
56        ~Device()
57        {
58            // Do not re-create Dispose clean-up code here.
59            // Calling Dispose(false) is optimal in terms of
60            // readability and maintainability.
61            Dispose(false);
62        }
63
64        #region IDisposable Members
65
66        // Implement IDisposable.
67        // Do not make this method virtual.
68        // A derived class should not be able to override this method.
69        public void Dispose()
70        {
71            Dispose(true);
72            // This object will be cleaned up by the Dispose method.
73            // Therefore, you should call GC.SupressFinalize to
74            // take this object off the finalization queue
75            // and prevent finalization code for this object
76            // from executing a second time.
77            GC.SuppressFinalize(this);
78        }
79
80        // Dispose(bool disposing) executes in two distinct scenarios.
81        // If disposing equals true, the method has been called directly
82        // or indirectly by a user's code. Managed and unmanaged resources
83        // can be disposed.
84        // If disposing equals false, the method has been called by the
85        // runtime from inside the finalizer and you should not reference
86        // other objects. Only unmanaged resources can be disposed.
87        private void Dispose(bool disposing)
88        {
89            // Check to see if Dispose has already been called.
90            if (!this.disposed)
91            {
92                // If disposing equals true, dispose all managed
93                // and unmanaged resources.
94                if (disposing)
95                {
96                    // Dispose managed resources.
97                }
98
99                // Call the appropriate methods to clean up
100                // unmanaged resources here.
101                // If disposing is false,
102                // only the following code is executed.
103                if( IsSubDevice )
104                    OpenCL.ReleaseDeviceEXT(DeviceID);
105
106                // Note disposing has been done.
107                disposed = true;
108            }
109        }
110
111        #endregion
112
113
114        #region Device Fission API (Extension)
115
116        public void ReleaseDeviceEXT()
117        {
118            ErrorCode result;
119           
120            result = OpenCL.ReleaseDeviceEXT(DeviceID);
121            if (result != ErrorCode.SUCCESS)
122                throw new OpenCLException("ReleaseDeviceEXT failed with error code: "+result, result);
123        }
124
125        public void RetainDeviceEXT()
126        {
127            ErrorCode result;
128
129            result = OpenCL.RetainDeviceEXT(DeviceID);
130            if (result != ErrorCode.SUCCESS)
131                throw new OpenCLException("RetainDeviceEXT failed with error code: " + result, result);
132        }
133
134        /// <summary>
135        /// CreateSubDevicesEXT uses a slightly modified API,
136        /// due to the overall messiness of creating a
137        /// cl_device_partition_property_ext in managed C#.
138        ///
139        /// The object list properties is a linear list of partition properties and arguments
140        /// add the DevicePartition property IDs  and ListTerminators as ulongs and the argument lists as ints
141        /// CreateSubDevicesEXT will use that info to construct a binary block
142        /// </summary>
143        /// <param name="properties"></param>
144        public unsafe Device[] CreateSubDevicesEXT(List<object> properties)
145        {
146            ErrorCode result;
147            MemoryStream ms = new MemoryStream();
148            BinaryWriter bw = new BinaryWriter(ms);
149
150            for (int i = 0; i < properties.Count; i++)
151            {
152                if (properties[i] is ulong)
153                    bw.Write((ulong)properties[i]);
154                else if (properties[i] is int)
155                    bw.Write((int)properties[i]);
156                else
157                    throw new ArgumentException("CreateSubDevicesEXT: property lists only accepts ulongs and ints");
158            }
159            bw.Flush();
160            byte[] propertyArray = ms.ToArray();
161            uint numDevices;
162            result = OpenCL.CreateSubDevicesEXT(DeviceID, propertyArray, 0, null, &numDevices);
163            if (result != ErrorCode.SUCCESS)
164                throw new OpenCLException("CreateSubDevicesEXT failed with error code: "+result, result);
165
166            IntPtr[] subDeviceIDs = new IntPtr[(int)numDevices];
167            result = OpenCL.CreateSubDevicesEXT(DeviceID, propertyArray, numDevices, subDeviceIDs, null);
168            if (result != ErrorCode.SUCCESS)
169                throw new OpenCLException("CreateSubDevicesEXT failed with error code: " + result, result);
170
171            Device[] subDevices = new Device[(int)numDevices];
172            for (int i = 0; i < (int)numDevices; i++)
173            {
174                Device d = new Device(Platform, subDeviceIDs[i]);
175                d.IsSubDevice = true;
176                subDevices[i] = d;
177            }
178            return subDevices;
179        }
180
181        #endregion
182
183        public static implicit operator IntPtr(Device d)
184        {
185            return d.DeviceID;
186        }
187
188        #region Properties
189
190        public IntPtr DeviceID { get; protected set; }
191
192        public DeviceType DeviceType { get { return (DeviceType) InteropTools.ReadULong( this, (uint)DeviceInfo.TYPE ); } }
193        /// <summary>
194        /// A unique device vendor identifier. An example of a unique device identifier could be the PCIe ID.
195        /// </summary>
196        public uint VendorID { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.VENDOR_ID ); } }
197        /// <summary>
198        /// The number of parallel compute cores on the OpenCL device. The minimum value is 1.
199        /// </summary>
200        public uint MaxComputeUnits { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MAX_COMPUTE_UNITS ); } }
201        /// <summary>
202        /// Maximum dimensions that specify the global and local work-item IDs used by the data parallel execution model.
203        /// (Refer to clEnqueueNDRangeKernel). The minimum value is 3.
204        /// </summary>
205        public uint MaxWorkItemDimensions { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MAX_WORK_ITEM_DIMENSIONS ); } }
206        /// <summary>
207        /// Maximum number of work-items that can be specified in each dimension of
208        /// the work-group to clEnqueueNDRangeKernel.
209        ///
210        /// Returns n size_t entries, where n is the value returned by the query for
211        /// CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS.
212        ///
213        /// The minimum value is (1, 1, 1).
214        /// </summary>
215        public IntPtr[] MaxWorkItemSizes { get { return InteropTools.ReadIntPtrArray( this, (uint)DeviceInfo.MAX_WORK_ITEM_SIZES ); } }
216        /// <summary>
217        /// Maximum number of work-items in a work-group executing a kernel using the data parallel execution model.
218        /// (Refer to clEnqueueNDRangeKernel).
219        ///
220        /// The minimum value is 1.
221        /// </summary>
222        public long MaxWorkGroupSize { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.MAX_WORK_GROUP_SIZE ).ToInt64(); } }
223        public uint PreferredVectorWidthChar { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_CHAR ); } }
224        public uint PreferredVectorWidthShort { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_SHORT ); } }
225        public uint PreferredVectorWidthInt { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_INT ); } }
226        public uint PreferredVectorWidthLong { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_LONG ); } }
227        public uint PreferredVectorWidthFloat { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_FLOAT ); } }
228        public uint PreferredVectorWidthDouble { get { return InteropTools.ReadUInt(this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_DOUBLE); } }
229        public uint PreferredVectorWidthHalf { get { return InteropTools.ReadUInt(this, (uint)DeviceInfo.PREFERRED_VECTOR_WIDTH_HALF); } }
230        /// <summary>
231        /// Maximum configured clock frequency of the device in MHz.
232        /// </summary>
233        public uint MaxClockFrequency { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MAX_CLOCK_FREQUENCY ); } }
234        /// <summary>
235        /// The default compute device address space size specified as an unsigned
236        /// integer value in bits. Currently supported values are 32 or 64 bits.
237        /// </summary>
238        public uint AddressBits { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.ADDRESS_BITS ); } }
239        /// <summary>
240        /// Max size of memory object allocation in bytes. The minimum value is max
241        /// (1/4th of CL_DEVICE_GLOBAL_MEM_SIZE, 128*1024*1024)
242        /// </summary>
243        public ulong MaxMemAllocSize { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.MAX_MEM_ALLOC_SIZE ); } }
244        /// <summary>
245        /// Is true if images are supported by the OpenCL device and CL_FALSE otherwise.
246        /// </summary>
247        public bool ImageSupport { get { return InteropTools.ReadBool( this, (uint)DeviceInfo.IMAGE_SUPPORT ); } }
248        /// <summary>
249        /// Max number of simultaneous image objects that can be read by a kernel.
250        /// The minimum value is 128 if CL_DEVICE_IMAGE_SUPPORT is true.
251        /// </summary>
252        public uint MaxReadImageArgs { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MAX_READ_IMAGE_ARGS ); } }
253        /// <summary>
254        /// Max number of simultaneous image objects that can be written to by a
255        /// kernel. The minimum value is 8 if CL_DEVICE_IMAGE_SUPPORT is true.
256        /// </summary>
257        public uint MaxWriteImageArgs { get { return InteropTools.ReadUInt(this, (uint)DeviceInfo.MAX_WRITE_IMAGE_ARGS); } }
258        /// <summary>
259        /// Max width of 2D image in pixels. The minimum value is 8192 if CL_DEVICE_IMAGE_SUPPORT is true.
260        /// </summary>
261        public long Image2DMaxWidth { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.IMAGE2D_MAX_WIDTH ).ToInt64(); } }
262        /// <summary>
263        /// Max height of 2D image in pixels. The minimum value is 8192 if CL_DEVICE_IMAGE_SUPPORT is true.
264        /// </summary>
265        public long Image2DMaxHeight { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.IMAGE2D_MAX_HEIGHT ).ToInt64(); } }
266        /// <summary>
267        /// Max width of 3D image in pixels. The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is true.
268        /// </summary>
269        public long Image3DMaxWidth { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.IMAGE3D_MAX_WIDTH ).ToInt64(); } }
270        /// <summary>
271        /// Max height of 3D image in pixels. The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is true.
272        /// </summary>
273        public long Image3DMaxHeight { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.IMAGE3D_MAX_HEIGHT ).ToInt64(); } }
274        /// <summary>
275        /// Max depth of 3D image in pixels. The minimum value is 2048 if CL_DEVICE_IMAGE_SUPPORT is true.
276        /// </summary>
277        public long Image3DMaxDepth { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.IMAGE3D_MAX_DEPTH ).ToInt64(); } }
278        /// <summary>
279        /// Maximum number of samplers that can be used in a kernel. Refer to section 6.11.8 for a detailed
280        /// description on samplers. The minimum value is 16 if CL_DEVICE_IMAGE_SUPPORT is true.
281        /// </summary>
282        public uint MaxSamplers { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MAX_SAMPLERS ); } }
283        /// <summary>
284        /// Max size in bytes of the arguments that can be passed to a kernel. The minimum value is 256.
285        /// </summary>
286        public long MaxParameterSize { get { return InteropTools.ReadIntPtr( this, (uint)DeviceInfo.MAX_PARAMETER_SIZE ).ToInt64(); } }
287        /// <summary>
288        /// Describes the alignment in bits of the base address of any allocated memory object.
289        /// </summary>
290        public uint MemBaseAddrAlign { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MEM_BASE_ADDR_ALIGN ); } }
291        /// <summary>
292        /// The smallest alignment in bytes which can be used for any data type.
293        /// </summary>
294        public uint MinDataTypeAlignSize { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MIN_DATA_TYPE_ALIGN_SIZE ); } }
295        public ulong SingleFPConfig { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.SINGLE_FP_CONFIG ); } }
296        /// <summary>
297        /// Type of global memory cache supported. Valid values are: CL_NONE, CL_READ_ONLY_CACHE and CL_READ_WRITE_CACHE.
298        /// </summary>
299        public DeviceMemCacheType GlobalMemCacheType { get { return (DeviceMemCacheType)InteropTools.ReadUInt( this, (uint)DeviceInfo.GLOBAL_MEM_CACHE_TYPE ); } }
300        /// <summary>
301        /// Size of global memory cache line in bytes.
302        /// </summary>
303        public uint GlobalMemCacheLineSize { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.GLOBAL_MEM_CACHELINE_SIZE ); } }
304        /// <summary>
305        /// Size of global memory cache in bytes.
306        /// </summary>
307        public ulong GlobalMemCacheSize { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.GLOBAL_MEM_CACHE_SIZE ); } }
308        /// <summary>
309        /// Size of global device memory in bytes.
310        /// </summary>
311        public ulong GlobalMemSize { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.GLOBAL_MEM_SIZE ); } }
312        /// <summary>
313        /// Max size in bytes of a constant buffer allocation. The minimum value is 64 KB.
314        /// </summary>
315        public ulong MaxConstantBufferSize { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.MAX_CONSTANT_BUFFER_SIZE ); } }
316        /// <summary>
317        /// Max number of arguments declared with the __constant qualifier in a kernel. The minimum value is 8.
318        /// </summary>
319        public uint MaxConstantArgs { get { return InteropTools.ReadUInt( this, (uint)DeviceInfo.MAX_CONSTANT_ARGS ); } }
320        /// <summary>
321        /// Type of local memory supported. This can be set to CL_LOCAL implying dedicated local memory storage such as SRAM, or CL_GLOBAL.
322        /// </summary>
323        public DeviceLocalMemType LocalMemType { get { return (DeviceLocalMemType)InteropTools.ReadUInt( this, (uint)DeviceInfo.LOCAL_MEM_TYPE ); } }
324        /// <summary>
325        /// Size of local memory arena in bytes. The minimum value is 16 KB.
326        /// </summary>
327        public ulong LocalMemSize { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.LOCAL_MEM_SIZE ); } }
328        /// <summary>
329        /// Is CL_TRUE if the device implements error correction for the memories,
330        /// caches, registers etc. in the device. Is CL_FALSE if the device does not
331        /// implement error correction. This can be a requirement for certain clients of OpenCL.
332        /// </summary>
333        public bool ErrorCorrectionSupport { get { return InteropTools.ReadBool(this, (uint)DeviceInfo.ERROR_CORRECTION_SUPPORT); } }
334        /// <summary>
335        /// Is CL_TRUE if the device and the host have a unified memory subsystem
336        /// and is CL_FALSE otherwise.
337        /// </summary>
338        public bool HostUnifiedMemory { get { return InteropTools.ReadBool(this, (uint)DeviceInfo.HOST_UNIFIED_MEMORY); } }
339        /// <summary>
340        /// Describes the resolution of device timer. This is measured in nanoseconds. Refer to section 5.9 for details.
341        /// </summary>
342        public ulong ProfilingTimerResolution { get { return (ulong)InteropTools.ReadIntPtr( this, (uint)DeviceInfo.PROFILING_TIMER_RESOLUTION ).ToInt64(); } }
343        /// <summary>
344        /// Is CL_TRUE if the OpenCL device is a little endian device and CL_FALSE otherwise.
345        /// </summary>
346        public bool EndianLittle { get { return InteropTools.ReadBool( this, (uint)DeviceInfo.ENDIAN_LITTLE ); } }
347        /// <summary>
348        /// Is CL_TRUE if the device is available and CL_FALSE if the device is not available.
349        /// </summary>
350        public bool Available { get { return InteropTools.ReadBool( this, (uint)DeviceInfo.AVAILABLE ); } }
351        /// <summary>
352        /// Is CL_FALSE if the implementation does not have a compiler available to compile the program source.
353        /// Is CL_TRUE if the compiler is available.
354        /// This can be CL_FALSE for the embededed platform profile only.
355        /// </summary>
356        public bool CompilerAvailable { get { return InteropTools.ReadBool( this, (uint)DeviceInfo.COMPILER_AVAILABLE ); } }
357        /// <summary>
358        /// Describes the execution capabilities of the device. This is a bit-field that describes one or more of the following values:
359        /// CL_EXEC_KERNEL – The OpenCL device can execute OpenCL kernels.
360        /// CL_EXEC_NATIVE_KERNEL – The OpenCL device can execute native kernels.
361        /// The mandated minimum capability is: CL_EXEC_KERNEL.
362        /// </summary>
363        public ulong ExecutionCapabilities { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.EXECUTION_CAPABILITIES ); } }
364        /// <summary>
365        /// Describes the command-queue properties supported by the device.
366        /// This is a bit-field that describes one or more of the following values:
367        /// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
368        /// CL_QUEUE_PROFILING_ENABLE
369        /// These properties are described in table 5.1.
370        ///
371        /// The mandated minimum capability is:
372        /// CL_QUEUE_PROFILING_ENABLE.
373        /// </summary>
374        public ulong QueueProperties { get { return InteropTools.ReadULong( this, (uint)DeviceInfo.QUEUE_PROPERTIES ); } }
375        /// <summary>
376        /// The platform associated with this device.
377        /// </summary>
378        public Platform Platform { get; protected set; }
379        /// <summary>
380        /// Device name string.
381        /// </summary>
382        public string Name { get { return InteropTools.ReadString( this, (uint)DeviceInfo.NAME ); } }
383        /// <summary>
384        /// Vendor name string.
385        /// </summary>
386        public string Vendor { get { return InteropTools.ReadString( this, (uint)DeviceInfo.VENDOR ); } }
387        /// <summary>
388        /// OpenCL software driver version string in the form major_number.minor_number.
389        /// </summary>
390        public string DriverVersion { get { return InteropTools.ReadString( this, (uint)DeviceInfo.DRIVER_VERSION ); } }
391        /// <summary>
392        /// OpenCL profile string. Returns the profile name supported by the device.
393        /// The profile name returned can be one of the following strings:
394        /// FULL_PROFILE – if the device supports the OpenCL specification (functionality defined as part of the
395        /// core specification and does not require any extensions to be supported).
396        /// EMBEDDED_PROFILE - if the device supports the OpenCL embedded profile.
397        /// </summary>
398        public string Profile { get { return InteropTools.ReadString( this, (uint)DeviceInfo.PROFILE ); } }
399        /// <summary>
400        /// OpenCL version string. Returns the OpenCL version supported by the device. This version string has the
401        /// following format:
402        /// OpenCL&lt;space&gt;&lt;major_version.minor_version&gt;&lt;space&gt;&lt;vendor-specificinformation&gt;
403        /// </summary>
404        public string Version { get { return InteropTools.ReadString(this, (uint)DeviceInfo.VERSION); } }
405        /// <summary>
406        /// OpenCL C version string. Returns the highest OpenCL C version supported
407        /// by the compiler for this device. This version string has the following format:
408        /// OpenCL&lt;space&gt;C&lt;space&gt;&lt;major_version.minor_version&gt;&lt;space&gt;&lt;vendor-specific information&gt;
409        /// </summary>
410        public string OpenCL_C_Version { get { return InteropTools.ReadString(this, (uint)DeviceInfo.OPENCL_C_VERSION); } }
411        /// <summary>
412        /// Returns a space separated list of extension names
413        /// (the extension names themselves do not contain any spaces).
414        /// The list of extension names returned currently can include one or more of
415        /// the following approved extension names:
416        /// cl_khr_fp64
417        /// cl_khr_select_fprounding_mode
418        /// cl_khr_global_int32_base_atomics
419        /// cl_khr_global_int32_extended_atomics
420        /// cl_khr_local_int32_base_atomics
421        /// cl_khr_local_int32_extended_atomics
422        /// cl_khr_int64_base_atomics
423        /// cl_khr_int64_extended_atomics
424        /// cl_khr_3d_image_writes
425        /// cl_khr_byte_addressable_store
426        /// cl_khr_fp16
427        /// cl_khr_gl_sharing
428        /// Please refer to the OpenCL specification for a detailed
429        /// description of these extensions.
430        /// </summary>
431        public string Extensions { get { return InteropTools.ReadString( this, (uint)DeviceInfo.EXTENSIONS ); } }
432
433        #endregion
434
435        #region IPropertyContainer Members
436
437        public IntPtr GetPropertySize( uint key )
438        {
439            IntPtr size;
440            ErrorCode result;
441
442            result = (ErrorCode)OpenCL.GetDeviceInfo( DeviceID, key, IntPtr.Zero, null, out size );
443            if( result!=ErrorCode.SUCCESS )
444                throw new OpenCLException( "Unable to get device info for device "+DeviceID, result);
445            return size;
446        }
447
448        public void ReadProperty( uint key, IntPtr keyLength, void* pBuffer )
449        {
450            IntPtr size;
451            ErrorCode result;
452
453            result = (ErrorCode)OpenCL.GetDeviceInfo( DeviceID, (uint)key, keyLength, pBuffer, out size );
454            if( result!=(int)ErrorCode.SUCCESS )
455                throw new OpenCLException( "Unable to get device info for device "+DeviceID, result);
456        }
457
458        #endregion
459
460        #region HasExtension
461
462        protected void InitializeExtensionHashSet()
463        {
464            string[] ext = Extensions.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
465
466            foreach (string s in ext)
467                ExtensionHashSet.Add(s);
468        }
469
470        public bool HasExtension(string extension)
471        {
472            return ExtensionHashSet.Contains(extension);
473        }
474
475        public bool HasExtensions(string[] extensions)
476        {
477            foreach (string s in extensions)
478                if (!ExtensionHashSet.Contains(s))
479                    return false;
480            return true;
481        }
482
483        #endregion
484
485        #region ToString
486
487        public override string ToString()
488        {
489            StringBuilder sb = new StringBuilder();
490
491            sb.AppendLine( "Name: "+Name );
492            sb.AppendLine( "Vendor: "+Vendor );
493            sb.AppendLine( "VendorID: "+VendorID );
494            sb.AppendLine( "DriverVersion: "+DriverVersion );
495            sb.AppendLine( "Profile: "+Profile );
496            sb.AppendLine( "Version: "+Version );
497            sb.AppendLine( "Extensions: "+Extensions );
498            sb.AppendLine( "DeviceType: "+DeviceType );
499            sb.AppendLine( "MaxComputeUnits: "+MaxComputeUnits );
500            sb.AppendLine( "MaxWorkItemDimensions: "+MaxWorkItemDimensions );
501            sb.Append( "MaxWorkItemSizes:" );
502            for( int i=0; i<MaxWorkItemSizes.Length; i++ )
503                sb.Append( " "+i+"="+(int)MaxWorkItemSizes[i] );
504            sb.AppendLine( "" );
505            sb.AppendLine( "MaxWorkGroupSize: "+MaxWorkGroupSize );
506            sb.AppendLine( "PreferredVectorWidthChar: "+PreferredVectorWidthChar );
507            sb.AppendLine( "PreferredVectorWidthShort: "+PreferredVectorWidthShort );
508            sb.AppendLine( "PreferredVectorWidthInt: "+PreferredVectorWidthInt );
509            sb.AppendLine( "PreferredVectorWidthLong: "+PreferredVectorWidthLong );
510            sb.AppendLine( "PreferredVectorWidthFloat: "+PreferredVectorWidthFloat );
511            sb.AppendLine( "PreferredVectorWidthDouble: "+PreferredVectorWidthDouble );
512            sb.AppendLine( "MaxClockFrequency: "+MaxClockFrequency );
513            sb.AppendLine( "AddressBits: "+AddressBits );
514            sb.AppendLine( "MaxMemAllocSize: "+MaxMemAllocSize );
515            sb.AppendLine( "ImageSupport: "+ImageSupport );
516            sb.AppendLine( "MaxReadImageArgs: "+MaxReadImageArgs );
517            sb.AppendLine( "MaxWriteImageArgs: "+MaxWriteImageArgs );
518            sb.AppendLine( "Image2DMaxWidth: "+Image2DMaxWidth );
519            sb.AppendLine( "Image2DMaxHeight: "+Image2DMaxHeight );
520            sb.AppendLine( "Image3DMaxWidth: "+Image3DMaxWidth );
521            sb.AppendLine( "Image3DMaxHeight: "+Image3DMaxHeight );
522            sb.AppendLine( "Image3DMaxDepth: "+Image3DMaxDepth );
523            sb.AppendLine( "MaxSamplers: "+MaxSamplers );
524            sb.AppendLine( "MaxParameterSize: "+MaxParameterSize );
525            sb.AppendLine( "MemBaseAddrAlign: "+MemBaseAddrAlign );
526            sb.AppendLine( "MinDataTypeAlignSize: "+MinDataTypeAlignSize );
527            sb.AppendLine( "SingleFPConfig: "+SingleFPConfig );
528            sb.AppendLine( "GlobalMemCacheType: "+GlobalMemCacheType );
529            sb.AppendLine( "GlobalMemCacheLineSize: "+GlobalMemCacheLineSize );
530            sb.AppendLine( "GlobalMemCacheSize: "+GlobalMemCacheSize );
531            sb.AppendLine( "GlobalMemSize: "+GlobalMemSize );
532            sb.AppendLine( "MaxConstantBufferSize: "+MaxConstantBufferSize );
533            sb.AppendLine( "MaxConstantArgs: "+MaxConstantArgs );
534            sb.AppendLine( "LocalMemType: "+LocalMemType );
535            sb.AppendLine( "LocalMemSize: "+LocalMemSize );
536            sb.AppendLine( "ErrorCorrectionSupport: "+ErrorCorrectionSupport );
537            sb.AppendLine( "ProfilingTimerResolution: "+ProfilingTimerResolution );
538            sb.AppendLine( "EndianLittle: "+EndianLittle );
539            sb.AppendLine( "Available: "+Available );
540            sb.AppendLine( "CompilerAvailable: "+CompilerAvailable );
541            sb.AppendLine( "ExecutionCapabilities: "+ExecutionCapabilities );
542            sb.AppendLine( "QueueProperties: "+QueueProperties );
543            return sb.ToString();
544        }
545
546        #endregion
547
548    }
549}
Note: See TracBrowser for help on using the repository browser.