summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/CLDevice.java
blob: bac93cca723133ac65e2cabbe4ddccfa649fb790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
/*
 * Copyright (c) 2009 JogAmp Community. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are those of the
 * authors and should not be interpreted as representing official policies, either expressed
 * or implied, of JogAmp Community.
 */

package com.jogamp.opencl;

import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

import com.jogamp.opencl.llb.CL;
import com.jogamp.opencl.llb.CLDeviceBinding;
import com.jogamp.opencl.spi.CLInfoAccessor;
import com.jogamp.opencl.util.CLUtil;

/**
 * This object represents an OpenCL device.
 * @see CLPlatform#listCLDevices(com.jogamp.opencl.CLDevice.Type...)
 * @see CLPlatform#getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type...)
 * @see CLContext#getDevices()
 * @see CLContext#getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type)
 * @author Michael Bien, et al.
 */
public class CLDevice extends CLObject {

    private Set<String> extensions;

    private final CLInfoAccessor deviceInfo;
    private final CLPlatform platform;

    protected CLDevice(final CLPlatform platform, final long id) {
        super(id);
        this.platform = platform;
        this.deviceInfo = platform.getAccessorFactory().createDeviceInfoAccessor(platform.getDeviceBinding(), id);
    }

    protected CLDevice(final CLContext context, final long id) {
        super(context, id);
        this.platform = context.getPlatform();
        this.deviceInfo = platform.getAccessorFactory().createDeviceInfoAccessor(platform.getDeviceBinding(), id);
    }

    public CLCommandQueue createCommandQueue() {
        return createCommandQueue(0);
    }

    public CLCommandQueue createCommandQueue(final CLCommandQueue.Mode property) {
        return createCommandQueue(property.QUEUE_MODE);
    }

    public CLCommandQueue createCommandQueue(final CLCommandQueue.Mode... properties) {
        int flags = 0;
        if(properties != null) {
            for (int i = 0; i < properties.length; i++) {
                flags |= properties[i].QUEUE_MODE;
            }
        }
        return createCommandQueue(flags);
    }

    public CLCommandQueue createCommandQueue(final long properties) {
        if(context == null)
            throw new IllegalStateException("this device is not associated with a context");
        return context.createCommandQueue(this, properties);
    }

    /*keep this package private*/
    void setContext(final CLContext context) {
        this.context = context;
    }

    @Override
    public CLPlatform getPlatform() {
        return platform;
    }

    /**
     * Returns the name of this device.
     */
    @CLProperty("CL_DEVICE_NAME")
    public String getName() {
        return deviceInfo.getString(CLDeviceBinding.CL_DEVICE_NAME);
    }

    /**
     * Returns the OpenCL profile of this device.
     */
    @CLProperty("CL_DEVICE_PROFILE")
    public String getProfile() {
        return deviceInfo.getString(CLDeviceBinding.CL_DEVICE_PROFILE);
    }

    /**
     * Returns the vendor of this device.
     */
    @CLProperty("CL_DEVICE_VENDOR")
    public String getVendor() {
        return deviceInfo.getString(CLDeviceBinding.CL_DEVICE_VENDOR);
    }

    /**
     * Returns the vendor id of this device.
     */
    @CLProperty("CL_DEVICE_VENDOR_ID")
    public long getVendorID() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_VENDOR_ID);
    }

    /**
     * Returns the OpenCL version supported by the device.
     */
    @CLProperty("CL_DEVICE_VERSION")
    public CLVersion getVersion() {
        return new CLVersion(deviceInfo.getString(CLDeviceBinding.CL_DEVICE_VERSION));
    }

    /**
     * Returns the OpenCL-C version supported by the device.
     */
    @CLProperty("CL_DEVICE_OPENCL_C_VERSION")
    public CLVersion getCVersion() {
        return new CLVersion(deviceInfo.getString(CLDeviceBinding.CL_DEVICE_OPENCL_C_VERSION));
    }

    /**
     * Returns OpenCL software driver version string in the form major_number.minor_number.
     */
    @CLProperty("CL_DRIVER_VERSION")
    public String getDriverVersion() {
        return deviceInfo.getString(CL.CL_DRIVER_VERSION);
    }

    /**
     * Returns the type of this device.
     */
    @CLProperty("CL_DEVICE_TYPE")
    public Type getType() {
        return Type.valueOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_TYPE));
    }

    /**
     * The default compute device address space size specified in bits.
     * Currently supported values are 32 or 64 bits.
     */
    @CLProperty("CL_DEVICE_ADDRESS_BITS")
    public int getAddressBits() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_ADDRESS_BITS);
    }

    /**
     * Preferred native vector width size for built-in short vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT")
    public int getPreferredShortVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT);
    }

    /**
     * Preferred native vector width size for built-in char vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR")
    public int getPreferredCharVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR);
    }

    /**
     * Preferred native vector width size for built-in int vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT")
    public int getPreferredIntVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT);
    }

    /**
     * Preferred native vector width size for built-in long vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG")
    public int getPreferredLongVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG);
    }

    /**
     * Preferred native vector width size for built-in float vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT")
    public int getPreferredFloatVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT);
    }

    /**
     * Preferred native vector width size for built-in double vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE")
    public int getPreferredDoubleVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE);
    }

    /**
     * Native vector width size for built-in char vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR")
    public int getNativeCharVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR);
    }

    /**
     * Native vector width size for built-in short vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT")
    public int getNativeShortVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT);
    }

    /**
     * Native vector width size for built-in int vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_INT")
    public int getNativeIntVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_INT);
    }

    /**
     * Native vector width size for built-in long vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG")
    public int getNativeLongVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG);
    }

    /**
     * Native vector width size for built-in half vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF")
    public int getNativeHalfVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF);
    }

    /**
     * Native vector width size for built-in float vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT")
    public int getNativeFloatVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT);
    }

    /**
     * Native vector width size for built-in double vectors.
     * The vector width is defined as the number of scalar elements that can be stored in the vector.
     */
    @CLProperty("CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE")
    public int getNativeDoubleVectorWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE);
    }

    /**
     * Returns the number of parallel compute cores on the OpenCL device.
     * The minimum value is 1.
     */
    @CLProperty("CL_DEVICE_MAX_COMPUTE_UNITS")
    public int getMaxComputeUnits() {
        return (int) deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_COMPUTE_UNITS);
    }

    /**
     * Returns the maximum number of work-items in a work-group executing
     * a kernel using the data parallel execution model.
     * The minimum value is 1.
     */
    @CLProperty("CL_DEVICE_MAX_WORK_GROUP_SIZE")
    public int getMaxWorkGroupSize() {
        return (int) deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_WORK_GROUP_SIZE);
    }

    /**
     * Returns the maximum configured clock frequency of the device in MHz.
     */
    @CLProperty("CL_DEVICE_MAX_CLOCK_FREQUENCY")
    public int getMaxClockFrequency() {
        return (int) (deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_CLOCK_FREQUENCY));
    }

    /**
     * Returns the maximum dimensions that specify the global and local work-item
     * IDs used by the data parallel execution model.
     * The minimum value is 3.
     */
    @CLProperty("CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS")
    public int getMaxWorkItemDimensions() {
        return (int) deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS);
    }

    /**
     * Returns the maximum number of work-items that can be specified in each
     * dimension of the work-group.
     * The minimum value is (1, 1, 1).
     */
    @CLProperty("CL_DEVICE_MAX_WORK_ITEM_SIZES")
    public int[] getMaxWorkItemSizes() {
        final int n = getMaxWorkItemDimensions();
        return deviceInfo.getInts(CLDeviceBinding.CL_DEVICE_MAX_WORK_ITEM_SIZES, n);
    }

    /**
     * Returns the max size in bytes of the arguments that can be passed to a kernel.<br/>
     * The minimum OpenCL 1.0 value is 256.<br/>
     * The minimum OpenCL 1.1 value is 1024.<br/>
     */
    @CLProperty("CL_DEVICE_MAX_PARAMETER_SIZE")
    public long getMaxParameterSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_PARAMETER_SIZE);
    }

    /**
     * Returns the largest allocatable size of a {@link CLBuffer} on this device.
     */
    @CLProperty("CL_DEVICE_MAX_MEM_ALLOC_SIZE")
    public long getMaxMemAllocSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_MEM_ALLOC_SIZE);
    }

    /**
     * Returns the <code>uint32_t</code> memory base address alignment
     * value reinterpreted as a <code>long</code> value.
     */
    @CLProperty("CL_DEVICE_MEM_BASE_ADDR_ALIGN")
    public long getMemBaseAddrAlign() {
        return deviceInfo.getUInt32Long(CLDeviceBinding.CL_DEVICE_MEM_BASE_ADDR_ALIGN);
    }

    /**
     * Returns the global memory size in bytes.
     */
    @CLProperty("CL_DEVICE_GLOBAL_MEM_SIZE")
    public long getGlobalMemSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_GLOBAL_MEM_SIZE);
    }

    /**
     * Returns the local memory size in bytes.<br/>
     * The minimum OpenCL 1.0 value is 16 KB.<br/>
     * The minimum OpenCL 1.1 value is 32 KB.<br/>
     */
    @CLProperty("CL_DEVICE_LOCAL_MEM_SIZE")
    public long getLocalMemSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_LOCAL_MEM_SIZE);
    }

    /**
     * Returns true if the device and the host have a unified memory subsystem.
     */
    @CLProperty("CL_DEVICE_HOST_UNIFIED_MEMORY")
    public boolean isMemoryUnified() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_HOST_UNIFIED_MEMORY) == CL.CL_TRUE;
    }

    /**
     * Returns the max size in bytes of a constant buffer allocation.
     * The minimum value is 64 KB.
     */
    @CLProperty("CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE")
    public long getMaxConstantBufferSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE);
    }

    /**
     * Returns the size of global memory cache line in bytes.
     */
    @CLProperty("CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE")
    public long getGlobalMemCachelineSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE);
    }

    /**
     * Returns the size of global memory cache in bytes.
     */
    @CLProperty("CL_DEVICE_GLOBAL_MEM_CACHE_SIZE")
    public long getGlobalMemCacheSize() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_GLOBAL_MEM_CACHE_SIZE);
    }

    /**
     * Returns the max number of arguments declared with the <code>constant</code>
     * qualifier in a kernel. The minimum value is 8.
     */
    @CLProperty("CL_DEVICE_MAX_CONSTANT_ARGS")
    public long getMaxConstantArgs() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_CONSTANT_ARGS);
    }

    /**
     * Returns true if images are supported by the OpenCL device and false otherwise.
     */
    @CLProperty("CL_DEVICE_IMAGE_SUPPORT")
    public boolean isImageSupportAvailable() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_IMAGE_SUPPORT) == CL.CL_TRUE;
    }

    /**
     * Returns the max number of simultaneous image objects that can be read by a kernel.
     * The minimum value is 128 if image support is available.
     */
    @CLProperty("CL_DEVICE_MAX_READ_IMAGE_ARGS")
    public int getMaxReadImageArgs() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_READ_IMAGE_ARGS);
    }

    /**
     * Returns the max number of simultaneous image objects that can be written by a kernel.
     * The minimum value is 8 if image support is available.
     */
    @CLProperty("CL_DEVICE_MAX_WRITE_IMAGE_ARGS")
    public int getMaxWriteImageArgs() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_WRITE_IMAGE_ARGS);
    }

    /**
     * Returns the max width of 2D image in pixels. The minimum value is 8192 if
     * image support is available.
     */
    @CLProperty("CL_DEVICE_IMAGE2D_MAX_WIDTH")
    public int getMaxImage2dWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_IMAGE2D_MAX_WIDTH);
    }

    /**
     * Returns the max height of 2D image in pixels. The minimum value is 8192 if
     * image support is available.
     */
    @CLProperty("CL_DEVICE_IMAGE2D_MAX_HEIGHT")
    public int getMaxImage2dHeight() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_IMAGE2D_MAX_HEIGHT);
    }

    /**
     * Returns the max width of 3D image in pixels. The minimum value is 2048 if
     * image support is available.
     */
    @CLProperty("CL_DEVICE_IMAGE3D_MAX_WIDTH")
    public int getMaxImage3dWidth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_IMAGE3D_MAX_WIDTH);
    }

    /**
     * Returns the max height of 3D image in pixels. The minimum value is 2048 if
     * image support is available.
     */
    @CLProperty("CL_DEVICE_IMAGE3D_MAX_HEIGHT")
    public int getMaxImage3dHeight() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_IMAGE3D_MAX_HEIGHT);
    }

    /**
     * Returns the max depth of 3D image in pixels. The minimum value is 2048 if
     * image support is available.
     */
    @CLProperty("CL_DEVICE_IMAGE3D_MAX_DEPTH")
    public int getMaxImage3dDepth() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_IMAGE3D_MAX_DEPTH);
    }

    /**
     * Returns the maximum number of samplers that can be used in a kernel. The
     * minimum value is 16 if image support is available.
     */
    @CLProperty("CL_DEVICE_MAX_SAMPLERS")
    public int getMaxSamplers() {
        return (int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_MAX_SAMPLERS);
    }

    /**
     * Returns the resolution of device timer. This is measured in nanoseconds.
     */
    @CLProperty("CL_DEVICE_PROFILING_TIMER_RESOLUTION")
    public long getProfilingTimerResolution() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_PROFILING_TIMER_RESOLUTION);
    }

    /**
     * Returns the execution capabilities as EnumSet.
     */
    @CLProperty("CL_DEVICE_EXECUTION_CAPABILITIES")
    public EnumSet<Capabilities> getExecutionCapabilities() {
        return Capabilities.valuesOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_EXECUTION_CAPABILITIES));
    }

    /**
     * Returns the optional half precision floating-point capability of the device.
     * The required minimum half precision floating-point capabilities as implemented by this
     * extension are {@link FPConfig#ROUND_TO_ZERO}, {@link FPConfig#ROUND_TO_INF}
     * and {@link FPConfig#INF_NAN}.
     * @return An EnumSet containing the extensions, never null.
     */
    @CLProperty("CL_DEVICE_HALF_FP_CONFIG")
    public EnumSet<FPConfig> getHalfFPConfig() {
        if(isHalfFPAvailable())
            return FPConfig.valuesOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_HALF_FP_CONFIG));
        else
            return EnumSet.noneOf(FPConfig.class);
    }

    /**
     * Returns the single precision floating-point capability of the device.
     * The mandated minimum floating-point capabilities are {@link FPConfig#ROUND_TO_NEAREST} and
     * {@link FPConfig#INF_NAN}.
     * @return An EnumSet containing the extensions, never null.
     */
    @CLProperty("CL_DEVICE_SINGLE_FP_CONFIG")
    public EnumSet<FPConfig> getSingleFPConfig() {
        return FPConfig.valuesOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_SINGLE_FP_CONFIG));
    }

    /**
     * Returns the optional double precision floating-point capability of the device.
     * The mandated minimum double precision floating-point capabilities are {@link FPConfig#FMA},
     * {@link FPConfig#ROUND_TO_NEAREST}, {@link FPConfig#ROUND_TO_ZERO},
     * {@link FPConfig#ROUND_TO_INF}, {@link FPConfig#INF_NAN}, and {@link FPConfig#DENORM}.
     * @return An EnumSet containing the extensions, never null.
     */
    @CLProperty("CL_DEVICE_DOUBLE_FP_CONFIG")
    public EnumSet<FPConfig> getDoubleFPConfig() {
        if(isDoubleFPAvailable())
            return FPConfig.valuesOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_DOUBLE_FP_CONFIG));
        else
            return EnumSet.noneOf(FPConfig.class);
    }

    /**
     * Returns the local memory type.
     */
    @CLProperty("CL_DEVICE_LOCAL_MEM_TYPE")
    public LocalMemType getLocalMemType() {
        return LocalMemType.valueOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_LOCAL_MEM_TYPE));
    }

    /**
     * Returns the type of global memory cache supported.
     */
    @CLProperty("CL_DEVICE_GLOBAL_MEM_CACHE_TYPE")
    public GlobalMemCacheType getGlobalMemCacheType() {
        return GlobalMemCacheType.valueOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_GLOBAL_MEM_CACHE_TYPE));
    }


    /**
     * Returns the command-queue properties supported by the device.
     */
    @CLProperty("CL_DEVICE_QUEUE_PROPERTIES")
    public EnumSet<CLCommandQueue.Mode> getQueueProperties() {
        return CLCommandQueue.Mode.valuesOf((int)deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_QUEUE_PROPERTIES));
    }

    /**
     * Returns true if this device is available.
     */
    @CLProperty("CL_DEVICE_AVAILABLE")
    public boolean isAvailable() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_AVAILABLE) == CL.CL_TRUE;
    }

    /**
     * Returns false if the implementation does not have a compiler available to
     * compile the program source. Is true if the compiler is available.
     * This can be false for the OpenCL ES profile only.
     */
    @CLProperty("CL_DEVICE_COMPILER_AVAILABLE")
    public boolean isCompilerAvailable() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_COMPILER_AVAILABLE) == CL.CL_TRUE;
    }

    /**
     * Returns true if the OpenCL device is a little endian device and false otherwise.
     */
    @CLProperty("CL_DEVICE_ENDIAN_LITTLE")
    public boolean isLittleEndian() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_ENDIAN_LITTLE) == CL.CL_TRUE;
    }

    /**
     * Returns true if the device implements error correction for the memories,
     * caches, registers etc. in the device. Is false if the device does not
     * implement error correction.
     */
    @CLProperty("CL_DEVICE_ERROR_CORRECTION_SUPPORT")
    public boolean isErrorCorrectionSupported() {
        return deviceInfo.getLong(CLDeviceBinding.CL_DEVICE_ERROR_CORRECTION_SUPPORT) == CL.CL_TRUE;
    }

    /**
     * Returns {@link #isExtensionAvailable}("cl_khr_fp16").
     * @see #getExtensions()
     */
    @CLProperty("cl_khr_fp16")
    public boolean isHalfFPAvailable() {
        return isExtensionAvailable("cl_khr_fp16");
    }

    /**
     * Returns {@link #isExtensionAvailable}("cl_khr_fp64").
     * @see #getExtensions()
     */
    @CLProperty("cl_khr_fp64")
    public boolean isDoubleFPAvailable() {
        return isExtensionAvailable("cl_khr_fp64");
    }

    /**
     * Returns {@link #isExtensionAvailable}("cl_khr_icd").
     * @see #getExtensions()
     */
    @CLProperty("cl_khr_icd")
    public boolean isICDAvailable() {
        return isExtensionAvailable("cl_khr_icd");
    }

    /**
     * Returns {@link #isExtensionAvailable}("cl_khr_gl_sharing") || {@link #isExtensionAvailable}("cl_APPLE_gl_sharing").
     * @see #getExtensions()
     */
    @CLProperty("cl_khr_gl_sharing | cl_APPLE_gl_sharing")
    public boolean isGLMemorySharingSupported() {
        return isExtensionAvailable("cl_khr_gl_sharing") || isExtensionAvailable("cl_APPLE_gl_sharing");
    }

    /**
     * Returns true if the extension is supported on this device.
     * @see #getExtensions()
     */
    public boolean isExtensionAvailable(final String extension) {
        return getExtensions().contains(extension);
    }

    /**
     * Returns {@link ByteOrder#LITTLE_ENDIAN} or {@link ByteOrder#BIG_ENDIAN}.
     */
    public ByteOrder getByteOrder() {
        if(isLittleEndian()) {
            return ByteOrder.LITTLE_ENDIAN;
        }else{
            return ByteOrder.BIG_ENDIAN;
        }
    }

    /**
     * Returns all device extension names as unmodifiable Set.
     */
    @CLProperty("CL_DEVICE_EXTENSIONS")
    public Set<String> getExtensions() {

        if(extensions == null) {
            extensions = new HashSet<String>();
            final String ext = deviceInfo.getString(CLDeviceBinding.CL_DEVICE_EXTENSIONS);
            final Scanner scanner = new Scanner(ext);

            while(scanner.hasNext())
                extensions.add(scanner.next());

            extensions = Collections.unmodifiableSet(extensions);
        }

        return extensions;
    }

    /**
     * Returns a Map of device properties with the enum names as keys.
     * @see CLUtil#obtainDeviceProperties(com.jogamp.opencl.CLDevice)
     */
    public Map<String, String> getProperties() {
        return CLUtil.obtainDeviceProperties(this);
    }

    public final CLInfoAccessor getCLAccessor() {
        return deviceInfo;
    }

    @Override
    public String toString() {
        return "CLDevice [id: " + ID
                      + " name: " + getName()
                      + " type: " + getType()
                      + " profile: " + getProfile()+"]";
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CLDevice other = (CLDevice) obj;
        if (this.ID != other.ID) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 79 * hash + (int) (this.ID ^ (this.ID >>> 32));
        return hash;
    }

    /**
     * Enumeration for the execution capabilities of the device.
     */
    public enum Capabilities {

        /**
         * The OpenCL device can execute OpenCL kernels.
         */
        EXEC_KERNEL(CL.CL_EXEC_KERNEL),

        /**
         * The OpenCL device can execute native kernels.
         */
        EXEC_NATIVE_KERNEL(CL.CL_EXEC_NATIVE_KERNEL);

        /**
         * Value of wrapped OpenCL device type.
         */
        public final int CAPS;

        private Capabilities(final int type) {
            this.CAPS = type;
        }

        public static Capabilities valueOf(final int caps) {
            switch(caps) {
                case(CL.CL_EXEC_KERNEL):
                    return EXEC_KERNEL;
                case(CL.CL_EXEC_NATIVE_KERNEL):
                    return EXEC_NATIVE_KERNEL;
            }
            return null;
        }

        public static EnumSet<Capabilities> valuesOf(final int bitfield) {
            if((EXEC_KERNEL.CAPS & bitfield) != 0) {
                if((EXEC_NATIVE_KERNEL.CAPS & bitfield) != 0) {
                    return EnumSet.of(EXEC_KERNEL, EXEC_NATIVE_KERNEL);
                }else{
                    return EnumSet.of(EXEC_KERNEL);
                }
            }else if((EXEC_NATIVE_KERNEL.CAPS & bitfield) != 0){
                return EnumSet.of(EXEC_NATIVE_KERNEL);
            }
            return null;
        }

    }

    /**
     * Enumeration for the type of a device.
     */
    public enum Type {
        /**
         * CL_DEVICE_TYPE_CPU
         */
        CPU(CL.CL_DEVICE_TYPE_CPU),
        /**
         * CL_DEVICE_TYPE_GPU
         */
        GPU(CL.CL_DEVICE_TYPE_GPU),
        /**
         * CL_DEVICE_TYPE_ACCELERATOR
         */
        ACCELERATOR(CL.CL_DEVICE_TYPE_ACCELERATOR),
        /**
         * CL_DEVICE_TYPE_DEFAULT. This type can be used for creating a context on
         * the default device, a single device can never have this type.
         */
        DEFAULT(CL.CL_DEVICE_TYPE_DEFAULT),
        /**
         * CL_DEVICE_TYPE_ALL. This type can be used for creating a context on
         * all devices, a single device can never have this type.
         */
        ALL(CL.CL_DEVICE_TYPE_ALL);

        /**
         * Value of wrapped OpenCL device type.
         */
        public final long TYPE;

        private Type(final long type) {
            this.TYPE = type;
        }

        public static Type valueOf(final long clDeviceType) {

            if(clDeviceType == CLDeviceBinding.CL_DEVICE_TYPE_ALL)
                return ALL;

            switch((int)clDeviceType) {
                case(CLDeviceBinding.CL_DEVICE_TYPE_DEFAULT):
                    return DEFAULT;
                case(CLDeviceBinding.CL_DEVICE_TYPE_CPU):
                    return CPU;
                case(CLDeviceBinding.CL_DEVICE_TYPE_GPU):
                    return GPU;
                case(CLDeviceBinding.CL_DEVICE_TYPE_ACCELERATOR):
                    return ACCELERATOR;
            }
            return null;
        }
    }

    /**
     * Describes floating-point capability of the device.
     * Zero or more values are possible.
     */
    public enum FPConfig {

        /**
         * denorms are supported.
         */
        DENORM(CL.CL_FP_DENORM),

        /**
         * INF and quiet NaNs are supported.
         */
        INF_NAN(CL.CL_FP_INF_NAN),

        /**
         * round to nearest rounding mode supported.
         */
        ROUND_TO_NEAREST(CL.CL_FP_ROUND_TO_NEAREST),

        /**
         * round to positive and negative infinity rounding modes supported.
         */
        ROUND_TO_INF(CL.CL_FP_ROUND_TO_INF),

        /**
         * round to zero rounding mode supported.
         */
        ROUND_TO_ZERO(CL.CL_FP_ROUND_TO_ZERO),

        /**
         * IEEE754-2008 fused multiply-add is supported.
         */
        FMA(CL.CL_FP_FMA);


        /**
         * Value of wrapped OpenCL bitfield.
         */
        public final int CONFIG;

        private FPConfig(final int config) {
            this.CONFIG = config;
        }

        /**
         * Returns a EnumSet for the given bitfield.
         */
        public static EnumSet<FPConfig> valuesOf(final int bitfield) {
            final List<FPConfig> matching = new ArrayList<FPConfig>();
            final FPConfig[] values = FPConfig.values();
            for (final FPConfig value : values) {
                if((value.CONFIG & bitfield) != 0)
                    matching.add(value);
            }
            if(matching.isEmpty())
                return EnumSet.noneOf(FPConfig.class);
            else
                return EnumSet.copyOf(matching);
        }

    }

    /**
     * Type of global memory cache supported.
     */
    public enum GlobalMemCacheType {

        /**
         * Global memory cache not supported.
         */
        NONE(CL.CL_NONE),

        /**
         * Read only cache.
         */
        READ_ONLY(CL.CL_READ_ONLY_CACHE),

        /**
         * Read-write cache.
         */
        READ_WRITE(CL.CL_READ_WRITE_CACHE);


        /**
         * Value of wrapped OpenCL value.
         */
        public final int TYPE;

        private GlobalMemCacheType(final int type) {
            this.TYPE = type;
        }

        /**
         * Returns the matching GlobalMemCacheType for the given cl type.
         */
        public static GlobalMemCacheType valueOf(final int bitfield) {
            final GlobalMemCacheType[] values = GlobalMemCacheType.values();
            for (final GlobalMemCacheType value : values) {
                if(value.TYPE == bitfield)
                    return value;
            }
            return null;
        }
    }

    /**
     * Type of local memory cache supported.
     */
    public enum LocalMemType {

        /**
         * GLOBAL implies that no dedicated memory storage is available (global mem is used instead).
         */
        GLOBAL(CL.CL_GLOBAL),

        /**
         * LOCAL implies dedicated local memory storage such as SRAM.
         */
        LOCAL(CL.CL_LOCAL);

        /**
         * Value of wrapped OpenCL value.
         */
        public final int TYPE;

        private LocalMemType(final int type) {
            this.TYPE = type;
        }

        /**
         * Returns the matching LocalMemCacheType for the given cl type.
         */
        public static LocalMemType valueOf(final int clLocalCacheType) {
            if(clLocalCacheType == CLDeviceBinding.CL_GLOBAL)
                return GLOBAL;
            else if(clLocalCacheType == CLDeviceBinding.CL_LOCAL)
                return LOCAL;
            return null;
        }

    }

}