/
info.clj
1414 lines (1181 loc) · 54.5 KB
/
info.clj
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
996
997
998
999
1000
(ns ^{:author "Dragan Djuric"}
uncomplicate.clojurecl.info
"Info functions for all OpenCL objects (platforms, devices, etc...).
The OpenCL standard defines info functions for all cl structures. Typically
in OpenCL C, you would have a reference to an object representing, for example,
platform, and then call a dedicated info function, in this case
[`clGetPlatformInfo`](http://www.jocl.org/doc/org/jocl/CL.html#clGetPlatformInfo-org.jocl.cl_platform_id-int-long-org.jocl.Pointer-long:A-)
with a parameter param_name that specifies which of the several available
informations you want about that object. If you need all information, then you
need to call this function as many times as different kinds of information there is.
ClojureCL provides many conveniences for obtaining information about cl objects:
1. **There is a universal, high-level, [[info]] function** that works for all kinds
of cl objects (platform, context, device, memory, etc.) and displays all available
information. This function also accepts a keyword argument for returning
only a specific kind of information, not all information. The information
will be converted from low-level C enums to a Clojre-friendly format that
uses keywords, sequences, sets, etc. It will release all additional cl objects
that it has to use to obtain information. If there is an OpenCL error in obtaining
the information, which may happen if the driver does not support that kind of
information, the [ExceptionInfo](http://clojuredocs.org/clojure.core/ex-info)
will be returned as a result for that particular information, instead of
raising an exception. This function is useful in when the information
is going to be displayed to the user.
2. For each information kind, there is a dedicated, low-level, function that
returns the raw, unconverted information. If the result is a cl object that
needs to be released after use, it is the responsibility of the caller to
call the [[core/release]] function. If the information is not supported,
the exception is raised. These functions are convenient in the parts
of the program where the returned info is used by other parts of the program,
for example to calculate some parameters for an algorithm.
3. Some information is not only about the objects, for example program, but
about the specific use of that object, for example a program build. In that
case, aditional X-info function is provided, for example [[build-info]].
Most keywords in the [[info]] function are exactly the same as the corresponding
low-level function name, except in a few cases where that would produce a clash
with some other functionality. You can check the available keywords in
the documentation of appropriate positional methods:
[[->PlatformInfo]], [[->DeviceInfo]], [[->CommandQueueInfo]], [[->ContextInfo]],
[[->KernelInfo]], [[->KernelArgInfo]], [[->ProgramInfo]], [[->ProgramBuildinfo]],
[[->EventInfo]], [[->Profilinginfo]], [[->MemObjectInfo]], etc...
###Cheat Sheet
#### Low-level info functions grouped by resource type:
* [`cl_platform_id`](http://www.jocl.org/doc/org/jocl/cl_platform_id.html) info:
[[version]], [[icd-suffix-khr]], [[profile]], [[name-info]], [[vendor]],
[[extensions]]
* [`cl_device_id`] (http://www.jocl.org/doc/org/jocl/cl_device_id.html) info:
[[address-bits]], [[available]], [[built-in-kernels]], [[compiler-available]],
[[double-fp-config]], [[endian-little]], [[error-correction-support]],
[[execution-capabilities]], [[global-mem-cache-size]], [[global-=mem-cache-type]],
[[global-mem-cacheline-size]], [[global-mem-size]],
[[global-variable-preferred-total-size]], [[image2d-max-height]],
[[image2d-max-width]], [[image3d-max-depth]], [[image3d-max-height]],
[[image3d-max-width]], [[image-base-address-alignment]], [[image-max-array-size]],
[[image-max-array-size]], [[image-max-buffer-size]], [[image-pitch-alignment]],
[[image-support]], [[linker-available]], [[local-mem-size]], [[local-mem-type]],
[[max-clock-frequency]], [[max-compute-units]], [[max-constant-args]],
[[max-constant-buffer-size]], [[max-global-variable-size]], [[max-mem-aloc-size]],
[[max-on-device-events]], [[max-on-device-queues]], [[max-parameter-size]],
[[max-pipe-args]], [[max-read-image-args]], [[max-read-write-image-args]],
[[max-samplers]], [[max-work-group-size]], [[max-work-item-dimensions]],
[[max-work-item-sizes]], [[max-write-image-args]], [[mem-base-addr-align]],
[[native-vector-width-char]], [[native-vector-width-short]],
[[native-vector-width-int]], [[native-vector-width-long]],
[[native-vector-width-float]], [[native-vector-width-double]],
[[native-vector-width-half]], [[opencl-c-version]], [[parent-device]],
[[partition-affinity-domain]], [[partition-max-sub-devices]],
[[partition-properties]], [[partition-type]],[[pipe-max-active-reservations]],
[[pipe-max-packet-size]], [[platform]], [[preferred-global-atomic-alignment]],
[[preferred-interop-user-sync]], [[preferred-local-atomic-alignment]],
[[preferred-platform-atomic-alignment]], [[preferred-vector-width-char]],
[[preferred-vector-width-short]], [[preferred-vector-width-int]],
[[preferred-vector-width-long]], [[preferred-vector-width-float]],
[[preferred-vector-width-double]], [[preferred-vector-width-half]],
[[printf-buffer-size]], [[profiling-timer-resolution]], [[queue-on-device-max-size]],
[[queue-on-device-properties]], [[queue-on-host-properties]],
[[single-fp-config]], [[spir-versions]], [[svm-capabilities]],
[[device-type]], [[vendor-id]], [[device-version]],
[[driver-version]], [[extensions]], [[name-info]], [[profile]], [[vendor]],
[[reference-count]]
* [`cl_context`] (http://www.jocl.org/doc/org/jocl/cl_context.html) info:
[[num-devices-in-context]], [[devices-in-context]], [[properties]],
[[reference-count]]
* [`cl_command_queue`] (http://www.jocl.org/doc/org/jocl/cl_command_queue.html) info:
[[queue-context]], [[queue-device]], [[queue-size]], [[properties]],
[[reference-count]]
* [`cl_event`] (http://www.jocl.org/doc/org/jocl/cl_event.html) info:
[[event-command-queue]], [[event-context]], [[command-type]], [[execution-status]],
[[reference-count]]
* profiling event info: **[[profiling-info]]**,
[[queued]], [[submit]], [[start]], [[end]]
* [`cl_kernel`] (http://www.jocl.org/doc/org/jocl/cl_kernel.html) info:
[[function-name]], [[num-args]], [[kernel-context]], [[kernel-program]],
[[attributes]], [[reference-count]]
* kernel argument info: **[[arg-info]]**
[[arg-address-qualifier]], [[arg-access-qualifier]], [[arg-type-name]],
[[arg-type-qualifier]], [[arg-name]]
* [`cl_mem`] (http://www.jocl.org/doc/org/jocl/cl_mem.html) info:
[[mem-type]], [[flags]], [[mem-size]], [[map-count]], [[mem-context]],
[[associated-memobject]], [[offset]], [[uses-svm-pointer]], [[reference-count]]
* [`cl_program`] (http://www.jocl.org/doc/org/jocl/cl_program.html) info:
[[program-context]], [[program-num-devices]], [[program-devices]],
[[program-source]], [[binary-sizes]], [[binaries]], [[program-num-kernels]],
[[kernel-names]], [[reference-count]]
* program build info: **[[build-info]]**,
[[build-status]], [[build-options]], [[build-log]], [[binary-type]],
[[global-variable-total-size]]
#### Hihg-level info and keywords (in a few cases different than low-level function names)
[[->PlatformInfo]], [[->DeviceInfo]], [[->CommandQueueInfo]], [[->ContextInfo]],
[[->KernelInfo]], [[->KernelArgInfo]], [[->ProgramInfo]], [[->ProgramBuildinfo]],
[[->EventInfo]], [[->Profilinginfo]], [[->MemObjectInfo]],
"
(:require [clojure.string :as str]
[uncomplicate.clojurecl
[constants :refer :all]
[utils :refer :all]]
[vertigo
[bytes :refer [buffer direct-buffer byte-seq byte-count slice]]
[structs :refer [int32 int64 wrap-byte-seq]]])
(:import [org.jocl CL cl_platform_id cl_device_id cl_context cl_command_queue
cl_program cl_kernel cl_sampler cl_event cl_device_partition_property
cl_mem Sizeof Pointer]
[java.nio ByteBuffer]))
;; TODO Check for memory leaks. Some of the returned resources should be released
;; after showing them in the big info function (contexts, devices, etc...)
;;actually, this is not that hard: info should pick up which data to show, for example
;;just name of the device, and release the resource immediately. the low-level function
;;should just return the raw id, of which the user should be responsible.
;; =================== Info* utility macros ===============================
(defmacro ^:private info-count*
([method clobject info sizeof]
`(/ (info-count* ~method ~clobject ~info) ~sizeof))
([method clobject info]
`(long (let [res# (long-array 1)
err# (~method ~clobject ~info 0 nil res#)]
(with-check err# (aget res# 0))))))
(defmacro ^:private info-string* [method clobject info]
`(let [size# (info-count* ~method ~clobject ~info)
res# (byte-array size#)
err# (~method ~clobject ~info
(alength res#) (Pointer/to res#)
nil)]
(with-check err#
(String. res# 0 (dec size#)))))
(defn ^:private to-set [s]
(if (str/blank? s)
#{}
(apply hash-set (str/split s #" "))))
(defn ^:private native-pointer
[^"[Lorg.jocl.NativePointerObject;" np]
(Pointer/to np))
(defmacro ^:private info-native* [method clobject info type size]
`(let [bytesize# (info-count* ~method ~clobject ~info)
res# (make-array ~type (/ bytesize# ~size))
err# (~method ~clobject ~info
bytesize# (~native-pointer res#)
nil)]
(with-check err# res#)))
(defn ^:private pointer-to-buffer [^ByteBuffer b]
(Pointer/toBuffer b))
(defmacro ^:private info-size*
([method clobject info num]
`(let [res# (buffer (* Sizeof/size_t (long ~num)))
err# (~method ~clobject ~info
(* Sizeof/size_t (long ~num))
(~pointer-to-buffer res#)
nil)]
(with-check err#
(wrap-byte-seq (if (= 8 Sizeof/size_t)
int64
int32)
(byte-seq res#)))))
([method clobject info]
`(first (info-size* ~method ~clobject ~info 1))))
(defmacro ^:private info-long*
([method clobject info num]
`(let [res# (long-array ~num)
err# (~method ~clobject ~info
(* Sizeof/cl_long (long ~num))
(Pointer/to res#)
nil)]
(with-check err# res#)))
([method clobject info]
`(aget (longs (info-long* ~method ~clobject ~info 1)) 0)))
(defmacro ^:private info-int*
([method clobject info num]
`(let [res# (int-array ~num)
err# (~method ~clobject ~info
(* Sizeof/cl_int (long ~num))
(Pointer/to res#)
nil)]
(with-check err# res#)))
([method clobject info]
`(aget (ints (info-int* ~method ~clobject ~info 1)) 0)))
(defmacro ^:private info-bool* [method clobject info]
`(not= 0 (info-int* ~method ~clobject ~info)))
;; =================== Protocols ==================================
(defprotocol Info
(info [this info-type] [this]))
(defprotocol InfoExtensions
(extensions [this]))
(defprotocol InfoName
(name-info [this]))
(defprotocol InfoProfile
(profile [this]))
(defprotocol InfoVendor
(vendor [this]))
(defprotocol InfoReferenceCount
(reference-count [this]))
(defprotocol InfoProperties
(properties [this]))
;; =================== Platform ===================================
(defn version [platform]
(info-string* CL/clGetPlatformInfo platform CL/CL_PLATFORM_VERSION))
(defn icd-suffix-khr [platform]
(info-string* CL/clGetPlatformInfo platform CL/CL_PLATFORM_ICD_SUFFIX_KHR))
(defrecord PlatformInfo [profile version name vendor extensions icd-suffix-khr])
(extend-type cl_platform_id
Info
(info
([p info-type]
(maybe
(case info-type
:profile (profile p)
:version (version p)
:name (name-info p)
:vendor (vendor p)
:extensions (extensions p)
:icd-suffix-khr (icd-suffix-khr p)
nil)))
([p]
(->PlatformInfo (maybe (profile p)) (maybe (version p)) (maybe (name-info p))
(maybe (vendor p)) (maybe (extensions p))
(maybe (icd-suffix-khr p)))))
InfoExtensions
(extensions [p]
(to-set (info-string* CL/clGetPlatformInfo p CL/CL_PLATFORM_EXTENSIONS)))
InfoName
(name-info [p]
(info-string* CL/clGetPlatformInfo p CL/CL_PLATFORM_NAME))
InfoProfile
(profile [p]
(info-string* CL/clGetPlatformInfo p CL/CL_PLATFORM_PROFILE))
InfoVendor
(vendor [p]
(info-string* CL/clGetPlatformInfo p CL/CL_PLATFORM_VENDOR)))
;; =================== Device ==============================================
(defn address-bits ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_ADDRESS_BITS))
(defn available [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_AVAILABLE))
(defn built-in-kernels [device]
(to-set (info-string* CL/clGetDeviceInfo device
CL/CL_DEVICE_BUILT_IN_KERNELS)))
(defn compiler-available [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_COMPILER_AVAILABLE))
(defn double-fp-config ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_DOUBLE_FP_CONFIG))
(defn endian-little [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_ENDIAN_LITTLE))
(defn error-correction-support [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_ERROR_CORRECTION_SUPPORT))
(defn execution-capabilities ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_EXECUTION_CAPABILITIES))
(defn global-mem-cache-size ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_GLOBAL_MEM_CACHE_SIZE))
(defn global-mem-cache-type ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_GLOBAL_MEM_CACHE_TYPE))
(defn global-mem-cacheline-size ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE))
(defn global-mem-size ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_GLOBAL_MEM_SIZE))
(defn global-variable-preferred-total-size ^long [device]
(info-size* CL/clGetDeviceInfo device
CL/CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE))
(defn image2d-max-height ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE2D_MAX_HEIGHT))
(defn image2d-max-width ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE2D_MAX_WIDTH))
(defn image3d-max-depth ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE3D_MAX_DEPTH))
(defn image3d-max-height ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE3D_MAX_HEIGHT))
(defn image3d-max-width ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE3D_MAX_WIDTH))
(defn image-base-address-alignment ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT))
(defn image-max-array-size ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE_MAX_ARRAY_SIZE))
(defn image-max-buffer-size ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE_MAX_BUFFER_SIZE))
(defn image-pitch-alignment ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE_PITCH_ALIGNMENT))
(defn image-support [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_IMAGE_SUPPORT))
(defn linker-available [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_LINKER_AVAILABLE))
(defn local-mem-size ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_LOCAL_MEM_SIZE))
(defn local-mem-type ^long [device]
(info-long* CL/clGetDeviceInfo device
CL/CL_DEVICE_LOCAL_MEM_TYPE))
(defn max-clock-frequency ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_CLOCK_FREQUENCY))
(defn max-compute-units ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_COMPUTE_UNITS))
(defn max-constant-args ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_CONSTANT_ARGS))
(defn max-constant-buffer-size ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE))
(defn max-global-variable-size ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE))
(defn max-mem-aloc-size ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_MEM_ALLOC_SIZE))
(defn max-on-device-events ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_ON_DEVICE_EVENTS))
(defn max-on-device-queues ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_ON_DEVICE_QUEUES))
(defn max-parameter-size ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_PARAMETER_SIZE))
(defn max-pipe-args ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_PIPE_ARGS))
(defn max-read-image-args ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_READ_IMAGE_ARGS))
(defn max-read-write-image-args ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS))
(defn max-samplers ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_SAMPLERS))
(defn max-work-group-size ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_WORK_GROUP_SIZE))
(defn max-work-item-dimensions ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS))
(defn max-work-item-sizes [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_WORK_ITEM_SIZES
(max-work-item-dimensions device)))
(defn max-write-image-args ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MAX_WRITE_IMAGE_ARGS))
(defn mem-base-addr-align ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_MEM_BASE_ADDR_ALIGN))
(defn native-vector-width-char ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR))
(defn native-vector-width-short ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT))
(defn native-vector-width-int ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_INT))
(defn native-vector-width-long ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG))
(defn native-vector-width-float ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT))
(defn native-vector-width-double ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE))
(defn native-vector-width-half ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF))
(defn opencl-c-version [device]
(let [info (str/split (info-string* CL/clGetDeviceInfo device
CL/CL_DEVICE_OPENCL_C_VERSION)
#" ")]
{:version (Double/parseDouble (info 2))
:vendor-specific-info (get info 3)}))
(defn parent-device [device]
(let [parent (cl_device_id.)
id (info-long* CL/clGetDeviceInfo device
CL/CL_DEVICE_PARENT_DEVICE)]
(if (= 0 id)
nil
(let [parent (cl_device_id.)
err (CL/clGetDeviceInfo device CL/CL_DEVICE_PARENT_DEVICE
Sizeof/cl_device_id
(Pointer/to parent)
nil)]
(with-check err parent)))))
(defn partition-affinity-domain ^long [device]
(info-long* CL/clGetDeviceInfo device
CL/CL_DEVICE_PARTITION_AFFINITY_DOMAIN))
(defn partition-max-sub-devices ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PARTITION_MAX_SUB_DEVICES))
(defn partition-properties [device]
(info-long* CL/clGetDeviceInfo device
CL/CL_DEVICE_PARTITION_PROPERTIES
(info-count* CL/clGetDeviceInfo device
CL/CL_DEVICE_PARTITION_PROPERTIES
Sizeof/cl_long)))
;;TODO
(defn partition-type [device]
(info-long* CL/clGetDeviceInfo device
CL/CL_DEVICE_PARTITION_TYPE
(info-count* CL/clGetDeviceInfo device
CL/CL_DEVICE_PARTITION_TYPE
Sizeof/cl_long)) )
(defn pipe-max-active-reservations ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS))
(defn pipe-max-packet-size ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_PIPE_MAX_PACKET_SIZE))
(defn platform [device]
(let [p (cl_platform_id.)
err (CL/clGetDeviceInfo device CL/CL_DEVICE_PLATFORM
Sizeof/cl_platform_id
(Pointer/to p)
nil)]
(with-check err p)))
(defn preferred-global-atomic-alignment ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT))
(defn preferred-interop-user-sync [device]
(info-bool* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_INTEROP_USER_SYNC))
(defn preferred-local-atomic-alignment ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT))
(defn preferred-platform-atomic-alignment ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT))
(defn preferred-vector-width-char ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR))
(defn preferred-vector-width-short ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT))
(defn preferred-vector-width-int ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT))
(defn preferred-vector-width-long ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG))
(defn preferred-vector-width-float ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT))
(defn preferred-vector-width-double ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE))
(defn preferred-vector-width-half ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF))
(defn printf-buffer-size ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_PRINTF_BUFFER_SIZE))
(defn profiling-timer-resolution ^long [device]
(info-size* CL/clGetDeviceInfo device CL/CL_DEVICE_PROFILING_TIMER_RESOLUTION))
(defn queue-on-device-max-size ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE))
(defn queue-on-device-preferred-size ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE))
(defn queue-on-device-properties ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES))
(defn queue-on-host-properties ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_QUEUE_ON_HOST_PROPERTIES))
(defn single-fp-config ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_SINGLE_FP_CONFIG))
(defn spir-versions [device]
(apply hash-set
(map #(Double/parseDouble %)
(str/split (info-string* CL/clGetDeviceInfo
device CL_DEVICE_SPIR_VERSIONS)
#" "))))
(defn svm-capabilities ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_SVM_CAPABILITIES))
(defn device-type ^long [device]
(info-long* CL/clGetDeviceInfo device CL/CL_DEVICE_TYPE))
(defn vendor-id ^long [device]
(info-int* CL/clGetDeviceInfo device CL/CL_DEVICE_VENDOR_ID))
(defn device-version [device]
(info-string* CL/clGetDeviceInfo device CL/CL_DEVICE_VERSION))
(defn driver-version [device]
(info-string* CL/clGetDeviceInfo device CL/CL_DRIVER_VERSION))
(defrecord DeviceInfo
[address-bits
available
built-in-kernels
compiler-available
double-fp-config
endian-little
error-correction-support
execution-capabilities
extensions
global-mem-cache-size
global-mem-cache-type
global-mem-cacheline-size
global-mem-size
global-variable-preferred-total-size
image2d-max-height
image2d-max-width
image3d-max-depth
image3d-max-height
image3d-max-width
image-base-address-alignment
image-max-array-size
image-max-buffer-size
image-pitch-alignment
image-support
linker-available
local-mem-size
local-mem-type
max-clock-frequency
max-compute-units
max-constant-args
max-constant-buffer-size
max-global-variable-size
max-mem-aloc-size
max-on-device-events
max-on-device-queues
max-parameter-size
max-pipe-args
max-read-image-args
max-read-write-image-args
max-samplers
max-work-group-size
max-work-item-dimensions
max-work-item-sizes
max-write-image-args
mem-base-addr-align
name
native-vector-width-char
native-vector-width-short
native-vector-width-int
native-vector-width-long
native-vector-width-double
native-vector-width-float
native-vector-width-half
opencl-c-version
parent-device
partition-affinity-domain
partition-max-sub-devices
partition-properties
partition-type
pipe-max-active-reservations
pipe-max-packet-size
platform
preferred-global-atomic-alignment
preferred-interop-user-sync
preferred-local-atomic-alignment
preferred-platform-atomic-alignment
preferred-vector-width-char
preferred-vector-width-short
preferred-vector-width-int
preferred-vector-width-long
preferred-vector-width-double
preferred-vector-width-float
preferred-vector-width-half
printf-buffer-size
profile
profiling-timer-resolution
queue-on-device-max-size
queue-on-device-preferred-size
queue-on-device-properties
queue-on-host-properties
reference-count
single-fp-config
spir-versions
svm-capabilities
device-type
vendor
vendor-id
device-version
driver-version])
(extend-type cl_device_id
Info
(info
([d info-type]
(maybe
(case info-type
:address-bits (address-bits d)
:available (available d)
:built-in-kernels (built-in-kernels d)
:compiler-available (compiler-available d)
:double-fp-config (set (unmask cl-device-fp-config (double-fp-config d)))
:endian-little (endian-little d)
:error-correction-support (error-correction-support d)
:execution-capabilities
(set (unmask cl-device-exec-capabilities (execution-capabilities d)))
:extensions (extensions d)
:global-mem-cache-size (global-mem-cache-size d)
:global-mem-cache-type
(unmask1 cl-device-mem-cache-type (global-mem-cache-type d))
:global-mem-cacheline-size (global-mem-cacheline-size d)
:global-mem-size (global-mem-size d)
:global-variable-preferred-total-size
(global-variable-preferred-total-size d)
:image2d-max-height (image2d-max-height d)
:image2d-max-width (image2d-max-width d)
:image3d-max-depth (image3d-max-depth d)
:image3d-max-height (image3d-max-height d)
:image3d-max-width (image3d-max-width d)
:image-base-address-alignment (image-base-address-alignment d)
:image-max-array-size (image-max-array-size d)
:image-max-buffer-size (image-max-buffer-size d)
:image-pitch-alignment (image-pitch-alignment d)
:image-support (image-support d)
:linker-available (linker-available d)
:local-mem-size (local-mem-size d)
:local-mem-type
(unmask1 cl-local-mem-type (local-mem-type d))
:max-clock-frequency (max-clock-frequency d)
:max-compute-units (max-compute-units d)
:max-constant-args (max-constant-args d)
:max-constant-buffer-size (max-constant-buffer-size d)
:max-global-variable-size (max-global-variable-size d)
:max-mem-alloc-size (max-mem-aloc-size d)
:max-on-device-events (max-on-device-events d)
:max-parameter-queues (max-on-device-queues d)
:max-parameter-size (max-parameter-size d)
:max-pipe-args (max-pipe-args d)
:max-read-image-args (max-read-image-args d)
:max-read-write-image-args (max-read-write-image-args d)
:max-samplers (max-samplers d)
:max-work-group-size (max-work-group-size d)
:max-work-item-dimensions (max-work-item-dimensions d)
:max-work-item-sizes (max-work-item-sizes d)
:max-write-image-args (max-write-image-args d)
:mem-base-addr-align (mem-base-addr-align d)
:name (name-info d)
:native-vector-width-char (native-vector-width-char d)
:native-vector-width-short (native-vector-width-short d)
:native-vector-width-int (native-vector-width-int d)
:native-vector-width-long (native-vector-width-long d)
:native-vector-width-double (native-vector-width-double d)
:native-vector-width-float (native-vector-width-float d)
:native-vector-width-half (native-vector-width-half d)
:opencl-c-version (opencl-c-version d)
:parent-device (parent-device d)
:partition-affinity-domain
(set (unmask cl-device-affinity-domain (partition-affinity-domain d)))
:partition-max-sub-devices (partition-max-sub-devices d)
:partition-properties (map dec-device-partition-property (partition-properties d))
:partition-type (map dec-device-partition-property (partition-type d))
:pipe-max-active-reservations (pipe-max-active-reservations d)
:pipe-max-packet-size (pipe-max-packet-size d)
:platform (platform d)
:preferred-global-atomic-alignment (preferred-global-atomic-alignment d)
:preferred-interop-user-sync (preferred-interop-user-sync d)
:preferred-local-atomic-alignment (preferred-local-atomic-alignment d)
:preferred-platform-atomic-alignment (preferred-platform-atomic-alignment d)
:preferred-vector-width-char (preferred-vector-width-char d)
:preferred-vector-width-short (preferred-vector-width-short d)
:preferred-vector-width-int (preferred-vector-width-int d)
:preferred-vector-width-long (preferred-vector-width-long d)
:preferred-vector-width-double (preferred-vector-width-double d)
:preferred-vector-width-float (preferred-vector-width-float d)
:preferred-vector-width-half (preferred-vector-width-half d)
:printf-buffer-size (printf-buffer-size d)
:profile (profile d)
:profiling-timer-resolution (profiling-timer-resolution d)
:queue-on-device-max-size (queue-on-device-max-size d)
:queue-on-device-preferred-size (queue-on-device-preferred-size d)
:queue-on-device-properties
(set (unmask cl-command-queue-properties (queue-on-device-properties d)))
:queue-on-host-properties
(set (unmask cl-command-queue-properties (queue-on-host-properties d)))
:reference-count (reference-count d)
:single-fp-config
(set (unmask cl-device-fp-config (single-fp-config d)))
:spir-versions (spir-versions d)
:svm-capabilities
(set (unmask cl-device-svm-capabilities (svm-capabilities d)))
:device-type
(unmask1 cl-device-type (device-type d))
:vendor (vendor d)
:vendor-id (vendor-id d)
:device-version (device-version d)
:driver-version (driver-version d)
nil)))
([d]
(->DeviceInfo
(maybe (address-bits d))
(maybe (available d))
(maybe (built-in-kernels d))
(maybe (compiler-available d))
(maybe (set (unmask cl-device-fp-config (double-fp-config d))))
(maybe (endian-little d))
(maybe (error-correction-support d))
(maybe (set (unmask cl-device-exec-capabilities (execution-capabilities d))))
(maybe (extensions d))
(maybe (global-mem-cache-size d))
(maybe (unmask1 cl-device-mem-cache-type (global-mem-cache-type d)))
(maybe (global-mem-cacheline-size d))
(maybe (global-mem-size d))
(maybe (global-variable-preferred-total-size d))
(maybe (image2d-max-height d))
(maybe (image2d-max-width d))
(maybe (image3d-max-depth d))
(maybe (image3d-max-height d))
(maybe (image3d-max-width d))
(maybe (image-base-address-alignment d))
(maybe (image-max-array-size d))
(maybe (image-max-buffer-size d))
(maybe (image-pitch-alignment d))
(maybe (image-support d))
(maybe (linker-available d))
(maybe (local-mem-size d))
(maybe (unmask1 cl-local-mem-type (local-mem-type d)))
(maybe (max-clock-frequency d))
(maybe (max-compute-units d))
(maybe (max-constant-args d))
(maybe (max-constant-buffer-size d))
(maybe (max-global-variable-size d))
(maybe (max-mem-aloc-size d))
(maybe (max-on-device-events d))
(maybe (max-on-device-queues d))
(maybe (max-parameter-size d))
(maybe (max-pipe-args d))
(maybe (max-read-image-args d))
(maybe (max-read-write-image-args d))
(maybe (max-samplers d))
(maybe (max-work-group-size d))
(maybe (max-work-item-dimensions d))
(maybe (max-work-item-sizes d))
(maybe (max-write-image-args d))
(maybe (mem-base-addr-align d))
(maybe (name-info d))
(maybe (native-vector-width-char d))
(maybe (native-vector-width-short d))
(maybe (native-vector-width-int d))
(maybe (native-vector-width-long d))
(maybe (native-vector-width-double d))
(maybe (native-vector-width-float d))
(maybe (native-vector-width-half d))
(maybe (opencl-c-version d))
(maybe (parent-device d))
(maybe (set (unmask cl-device-affinity-domain (partition-affinity-domain d))))
(maybe (partition-max-sub-devices d))
(maybe (map dec-device-partition-property (partition-properties d)))
(maybe (map dec-device-partition-property (partition-type d)))
(maybe (pipe-max-active-reservations d))
(maybe (pipe-max-packet-size d))
(maybe (platform d))
(maybe (preferred-global-atomic-alignment d))
(maybe (preferred-interop-user-sync d))
(maybe (preferred-local-atomic-alignment d))
(maybe (preferred-platform-atomic-alignment d))
(maybe (preferred-vector-width-char d))
(maybe (preferred-vector-width-short d))
(maybe (preferred-vector-width-int d))
(maybe (preferred-vector-width-long d))
(maybe (preferred-vector-width-double d))
(maybe (preferred-vector-width-float d))
(maybe (preferred-vector-width-half d))
(maybe (printf-buffer-size d))
(maybe (profile d))
(maybe (profiling-timer-resolution d))
(maybe (queue-on-device-max-size d))
(maybe (queue-on-device-preferred-size d))
(maybe (set (unmask cl-command-queue-properties
(queue-on-device-properties d))))
(maybe (set (unmask cl-command-queue-properties
(queue-on-host-properties d))))
(maybe (reference-count d))
(maybe (set (unmask cl-device-fp-config (single-fp-config d))))
(maybe (spir-versions d))
(maybe (set (unmask cl-device-svm-capabilities (svm-capabilities d))))
(maybe (unmask1 cl-device-type (device-type d)))
(maybe (vendor d))
(maybe (vendor-id d))
(maybe (device-version d))
(maybe (driver-version d)))))
InfoExtensions
(extensions [d]
(to-set (info-string* CL/clGetDeviceInfo d CL/CL_DEVICE_EXTENSIONS)))
InfoName
(name-info [d]
(info-string* CL/clGetDeviceInfo d CL/CL_DEVICE_NAME))
InfoProfile
(profile [d]
(info-string* CL/clGetDeviceInfo d CL/CL_DEVICE_PROFILE))
InfoVendor
(vendor [d]
(info-string* CL/clGetDeviceInfo d CL/CL_DEVICE_VENDOR))
InfoReferenceCount
(reference-count [d]
(info-int* CL/clGetDeviceInfo d CL/CL_DEVICE_REFERENCE_COUNT)))
;; =================== Context =============================================
(defn num-devices-in-context ^long [context]
(info-int* CL/clGetContextInfo context CL/CL_CONTEXT_NUM_DEVICES))
(defn devices-in-context [context]
(vec (info-native* CL/clGetContextInfo context CL/CL_CONTEXT_DEVICES
cl_device_id Sizeof/cl_device_id)))
(defrecord ContextInfo [num-devices reference-count devices properties])
(extend-type cl_context
Info
(info
([c info-type]
(maybe
(case info-type
:num-devices (num-devices-in-context c)
:reference-count (reference-count c)
:devices (devices-in-context c)
:properties (map dec-context-properties (remove zero? (properties c)))
nil)))
([c]
(->ContextInfo (maybe (num-devices-in-context c))
(maybe (reference-count c))
(maybe (devices-in-context c))
(maybe (map dec-context-properties (remove zero? (properties c)))))))
InfoProperties
(properties [c]
(info-long* CL/clGetContextInfo c
CL/CL_CONTEXT_PROPERTIES
(info-count* CL/clGetContextInfo c
CL/CL_CONTEXT_PROPERTIES
Sizeof/cl_long)))
InfoReferenceCount
(reference-count [c]
(info-int* CL/clGetContextInfo c CL/CL_CONTEXT_REFERENCE_COUNT)))
;; =================== Command Queue =======================================
(defn queue-context [queue]
(let [c (cl_context.)
err (CL/clGetCommandQueueInfo queue CL/CL_QUEUE_CONTEXT
Sizeof/cl_context
(Pointer/to c)
nil)]
(with-check err c)))
(defn queue-device [queue]
(let [d (cl_device_id.)
err (CL/clGetCommandQueueInfo queue CL/CL_QUEUE_DEVICE
Sizeof/cl_device_id
(Pointer/to d)
nil)]
(with-check err d)))
(defn queue-size ^long [queue]
(info-int* CL/clGetCommandQueueInfo queue CL/CL_QUEUE_SIZE))
(defrecord CommandQueueInfo [context device reference-count
properties size])
(extend-type cl_command_queue
Info
(info
([cq info-type]
(maybe
(case info-type
:context (queue-context cq)
:device (queue-device cq)
:reference-count (reference-count cq)
:properties (set (unmask cl-command-queue-properties (properties cq)))
:size (queue-size cq)
nil)))
([cq]
(->CommandQueueInfo (maybe (queue-context cq)) (maybe (queue-device cq))
(maybe (reference-count cq))
(maybe (set (unmask cl-command-queue-properties
(properties cq))))
(maybe (queue-size cq)))))
InfoReferenceCount
(reference-count [cq]
(info-int* CL/clGetCommandQueueInfo cq CL/CL_QUEUE_REFERENCE_COUNT))
InfoProperties
(properties [cq]
(info-long* CL/clGetCommandQueueInfo cq CL/CL_QUEUE_PROPERTIES)))
;; =================== Event ===============================================
(defn event-command-queue [event]
(let [cq (cl_command_queue.)
err (CL/clGetEventInfo event CL/CL_EVENT_COMMAND_QUEUE
Sizeof/cl_command_queue
(Pointer/to cq)
nil)]
(with-check err cq)))
(defn event-context [event]
(let [c (cl_context.)
err (CL/clGetEventInfo event CL/CL_EVENT_CONTEXT
Sizeof/cl_context
(Pointer/to c)
nil)]
(with-check err c)))
(defn command-type [event]
(info-int* CL/clGetEventInfo event CL/CL_EVENT_COMMAND_TYPE))
(defn execution-status [event]
(info-int* CL/clGetEventInfo event
CL/CL_EVENT_COMMAND_EXECUTION_STATUS))