forked from kenba/opencl3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.rs
2186 lines (1822 loc) · 74.6 KB
/
device.rs
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
// Copyright (c) 2020-2022 Via Technology Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub use cl3::device::*;
pub use cl3::ext::cl_device_feature_capabilities_intel;
use super::platform::get_platforms;
use super::Result;
#[allow(unused_imports)]
use cl3::types::{
cl_device_fp_config, cl_device_id, cl_device_info, cl_device_partition_property,
cl_device_svm_capabilities, cl_device_type, cl_name_version, cl_platform_id, cl_uint, cl_ulong,
CL_FALSE,
};
use libc::{intptr_t, size_t};
/// Get the ids of all available devices of the given type.
pub fn get_all_devices(device_type: cl_device_type) -> Result<Vec<cl_device_id>> {
let mut device_ids = Vec::<cl_device_id>::new();
let platforms = get_platforms()?;
for platform in platforms {
let mut devices = platform.get_devices(device_type)?;
device_ids.append(&mut devices);
}
Ok(device_ids)
}
#[cfg(feature = "CL_VERSION_1_2")]
#[derive(Debug)]
pub struct SubDevice {
id: cl_device_id,
}
#[cfg(feature = "CL_VERSION_1_2")]
impl From<cl_device_id> for SubDevice {
fn from(id: cl_device_id) -> Self {
SubDevice { id }
}
}
#[cfg(feature = "CL_VERSION_1_2")]
impl From<SubDevice> for cl_device_id {
fn from(value: SubDevice) -> Self {
value.id
}
}
#[cfg(feature = "CL_VERSION_1_2")]
impl Drop for SubDevice {
fn drop(&mut self) {
unsafe { release_device(self.id()).expect("Error: clReleaseDevice") };
}
}
#[cfg(feature = "CL_VERSION_1_2")]
unsafe impl Send for SubDevice {}
#[cfg(feature = "CL_VERSION_1_2")]
unsafe impl Sync for SubDevice {}
#[cfg(feature = "CL_VERSION_1_2")]
impl SubDevice {
pub fn new(id: cl_device_id) -> SubDevice {
SubDevice { id }
}
/// Accessor for the underlying device id.
pub fn id(&self) -> cl_device_id {
self.id
}
}
/// An OpenCL device id and methods to query it.
/// The query methods calls clGetDeviceInfo with the relevant param_name, see:
/// [Device Queries](https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#device-queries-table).
#[derive(Copy, Clone, Debug)]
pub struct Device {
id: intptr_t,
}
impl From<cl_device_id> for Device {
fn from(value: cl_device_id) -> Self {
Device {
id: value as intptr_t,
}
}
}
impl From<Device> for cl_device_id {
fn from(value: Device) -> Self {
value.id as cl_device_id
}
}
unsafe impl Send for Device {}
unsafe impl Sync for Device {}
impl Device {
pub fn new(id: cl_device_id) -> Device {
Device { id: id as intptr_t }
}
/// Accessor for the underlying device id.
pub fn id(&self) -> cl_device_id {
self.id as cl_device_id
}
/// Create sub-devices by partitioning an OpenCL device.
///
/// * `properties` - the slice of cl_device_partition_property, see
/// [Subdevice Partition](https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#subdevice-partition-table).
///
/// returns a Result containing a vector of available SubDevices
/// or the error code from the OpenCL C API function.
#[cfg(feature = "CL_VERSION_1_2")]
pub fn create_sub_devices(
&self,
properties: &[cl_device_partition_property],
) -> Result<Vec<SubDevice>> {
let sub_device_ids = create_sub_devices(self.id(), properties)?;
Ok(sub_device_ids
.iter()
.map(|id| SubDevice::new(*id))
.collect::<Vec<SubDevice>>())
}
#[cfg(feature = "CL_VERSION_2_1")]
#[inline]
pub fn get_device_and_host_timer(&self) -> Result<[cl_ulong; 2]> {
Ok(get_device_and_host_timer(self.id())?)
}
#[cfg(feature = "CL_VERSION_2_1")]
#[inline]
pub fn get_host_timer(&self) -> Result<cl_ulong> {
Ok(get_host_timer(self.id())?)
}
/// The OpenCL device type, see
/// [Device Types](https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#device-types-table).
pub fn dev_type(&self) -> Result<cl_device_type> {
Ok(get_device_info(self.id(), CL_DEVICE_TYPE)?.into())
}
/// A unique device vendor identifier: a [PCI vendor ID](https://www.pcilookup.com/)
/// or a Khronos vendor ID if the vendor does not have a PCI vendor ID.
pub fn vendor_id(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_VENDOR_ID)?.into())
}
/// The number of parallel compute units on the device, minimum 1.
pub fn max_compute_units(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_COMPUTE_UNITS)?.into())
}
/// Maximum dimensions for global and local work-item IDs, minimum 3
/// if device is not CL_DEVICE_TYPE_CUSTOM.
pub fn max_work_item_dimensions(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS)?.into())
}
/// Maximum number of work-items for each dimension of a work-group,
/// minimum [1, 1, 1] if device is not CL_DEVICE_TYPE_CUSTOM.
pub fn max_work_group_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_WORK_GROUP_SIZE)?.into())
}
pub fn max_work_item_sizes(&self) -> Result<Vec<size_t>> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_WORK_ITEM_SIZES)?.into())
}
pub fn max_preferred_vector_width_char(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR)?.into())
}
pub fn max_preferred_vector_width_short(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT)?.into())
}
pub fn max_preferred_vector_width_int(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT)?.into())
}
pub fn max_preferred_vector_width_long(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG)?.into())
}
pub fn max_preferred_vector_width_float(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT)?.into())
}
pub fn max_preferred_vector_width_double(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE)?.into())
}
pub fn max_clock_frequency(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_CLOCK_FREQUENCY)?.into())
}
pub fn address_bits(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_ADDRESS_BITS)?.into())
}
pub fn max_read_image_args(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_READ_IMAGE_ARGS)?.into())
}
pub fn max_write_image_args(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_WRITE_IMAGE_ARGS)?.into())
}
pub fn max_mem_alloc_size(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_MEM_ALLOC_SIZE)?.into())
}
pub fn image2d_max_width(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE2D_MAX_WIDTH)?.into())
}
pub fn image2d_max_height(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE2D_MAX_HEIGHT)?.into())
}
pub fn image3d_max_width(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE3D_MAX_WIDTH)?.into())
}
pub fn image3d_max_height(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE3D_MAX_HEIGHT)?.into())
}
pub fn image3d_max_depth(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE3D_MAX_DEPTH)?.into())
}
pub fn image_support(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_IMAGE_SUPPORT)?) != CL_FALSE)
}
pub fn max_parameter_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_PARAMETER_SIZE)?.into())
}
pub fn max_device_samples(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_SAMPLERS)?.into())
}
pub fn mem_base_addr_align(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MEM_BASE_ADDR_ALIGN)?.into())
}
pub fn min_data_type_align_size(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE)?.into())
}
pub fn single_fp_config(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_SINGLE_FP_CONFIG)?.into())
}
pub fn global_mem_cache_type(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_CACHE_TYPE)?.into())
}
pub fn global_mem_cacheline_size(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE)?.into())
}
pub fn global_mem_cache_size(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_CACHE_SIZE)?.into())
}
pub fn global_mem_size(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_SIZE)?.into())
}
pub fn max_constant_buffer_size(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE)?.into())
}
pub fn max_constant_args(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_CONSTANT_ARGS)?.into())
}
pub fn local_mem_type(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_LOCAL_MEM_TYPE)?.into())
}
pub fn local_mem_size(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_LOCAL_MEM_SIZE)?.into())
}
pub fn error_correction_support(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(
self.id(),
CL_DEVICE_ERROR_CORRECTION_SUPPORT,
)?) != CL_FALSE)
}
pub fn profiling_timer_resolution(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_PROFILING_TIMER_RESOLUTION)?.into())
}
pub fn endian_little(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_ENDIAN_LITTLE)?) != CL_FALSE)
}
pub fn available(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_AVAILABLE)?) != CL_FALSE)
}
pub fn compiler_available(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_COMPILER_AVAILABLE)?) != CL_FALSE)
}
pub fn execution_capabilities(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_EXECUTION_CAPABILITIES)?.into())
}
pub fn queue_on_host_properties(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_QUEUE_ON_HOST_PROPERTIES)?.into())
}
pub fn name(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_NAME)?.into())
}
pub fn vendor(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_VENDOR)?.into())
}
pub fn driver_version(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DRIVER_VERSION)?.into())
}
pub fn profile(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_PROFILE)?.into())
}
pub fn version(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_VERSION)?.into())
}
pub fn extensions(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_EXTENSIONS)?.into())
}
pub fn platform(&self) -> Result<cl_platform_id> {
Ok(intptr_t::from(get_device_info(self.id(), CL_DEVICE_PLATFORM)?) as cl_platform_id)
}
/// CL_VERSION_1_2
pub fn double_fp_config(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_DOUBLE_FP_CONFIG)?.into())
}
pub fn half_fp_config(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_HALF_FP_CONFIG)?.into())
}
pub fn preferred_vector_width_half(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF)?.into())
}
// DEPRECATED 2.0
pub fn host_unified_memory(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_HOST_UNIFIED_MEMORY)?) != CL_FALSE)
}
pub fn native_vector_width_char(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR)?.into())
}
pub fn native_vector_width_short(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT)?.into())
}
pub fn native_vector_width_int(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_INT)?.into())
}
pub fn native_vector_width_long(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG)?.into())
}
pub fn native_vector_width_float(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT)?.into())
}
pub fn native_vector_width_double(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE)?.into())
}
pub fn native_vector_width_half(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF)?.into())
}
pub fn opencl_c_version(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_OPENCL_C_VERSION)?.into())
}
/// CL_VERSION_1_2
pub fn linker_available(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_LINKER_AVAILABLE)?) != CL_FALSE)
}
/// CL_VERSION_1_2
pub fn built_in_kernels(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_BUILT_IN_KERNELS)?.into())
}
/// CL_VERSION_1_2
pub fn image_max_buffer_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE_MAX_BUFFER_SIZE)?.into())
}
/// CL_VERSION_1_2
pub fn image_max_array_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE_MAX_ARRAY_SIZE)?.into())
}
/// CL_VERSION_1_2
pub fn parent_device(&self) -> Result<cl_device_id> {
Ok(intptr_t::from(get_device_info(self.id(), CL_DEVICE_PARENT_DEVICE)?) as cl_device_id)
}
/// CL_VERSION_1_2
pub fn partition_max_sub_devices(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PARTITION_MAX_SUB_DEVICES)?.into())
}
/// CL_VERSION_1_2
pub fn partition_properties(&self) -> Result<Vec<intptr_t>> {
Ok(get_device_info(self.id(), CL_DEVICE_PARTITION_PROPERTIES)?.into())
}
/// CL_VERSION_1_2
pub fn partition_affinity_domain(&self) -> Result<Vec<cl_ulong>> {
Ok(get_device_info(self.id(), CL_DEVICE_PARTITION_AFFINITY_DOMAIN)?.into())
}
/// CL_VERSION_1_2
pub fn partition_type(&self) -> Result<Vec<intptr_t>> {
Ok(get_device_info(self.id(), CL_DEVICE_PARTITION_TYPE)?.into())
}
/// CL_VERSION_1_2
pub fn reference_count(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_REFERENCE_COUNT)?.into())
}
/// CL_VERSION_1_2
pub fn preferred_interop_user_sync(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(
self.id(),
CL_DEVICE_PREFERRED_INTEROP_USER_SYNC,
)?) != CL_FALSE)
}
/// CL_VERSION_1_2
pub fn printf_buffer_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_PRINTF_BUFFER_SIZE)?.into())
}
/// CL_VERSION_2_0
pub fn image_pitch_alignment(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE_PITCH_ALIGNMENT)?.into())
}
/// CL_VERSION_2_0
pub fn image_base_address_alignment(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT)?.into())
}
/// CL_VERSION_2_0
pub fn max_read_write_image_args(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS)?.into())
}
/// CL_VERSION_2_0
pub fn max_global_variable_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE)?.into())
}
/// CL_VERSION_2_0
pub fn queue_on_device_properties(&self) -> Result<Vec<intptr_t>> {
Ok(get_device_info(self.id(), CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES)?.into())
}
/// CL_VERSION_2_0
pub fn queue_on_device_preferred_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE)?.into())
}
/// CL_VERSION_2_0
pub fn queue_on_device_max_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE)?.into())
}
/// CL_VERSION_2_0
pub fn max_on_device_queues(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_ON_DEVICE_QUEUES)?.into())
}
/// CL_VERSION_2_0
pub fn max_on_device_events(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_ON_DEVICE_EVENTS)?.into())
}
/// CL_VERSION_2_0
pub fn svm_capabilities(&self) -> Result<cl_device_svm_capabilities> {
Ok(get_device_info(self.id(), CL_DEVICE_SVM_CAPABILITIES)?.into())
}
/// CL_VERSION_2_0
pub fn global_variable_preferred_total_size(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE)?.into())
}
/// CL_VERSION_2_0
pub fn max_pipe_args(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_PIPE_ARGS)?.into())
}
/// CL_VERSION_2_0
pub fn pipe_max_active_reservations(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS)?.into())
}
/// CL_VERSION_2_0
pub fn pipe_max_packet_size(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PIPE_MAX_PACKET_SIZE)?.into())
}
/// CL_VERSION_2_0
pub fn preferred_platform_atomic_alignment(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT)?.into())
}
/// CL_VERSION_2_0
pub fn preferred_global_atomic_alignment(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT)?.into())
}
/// CL_VERSION_2_0
pub fn preferred_local_atomic_alignment(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT)?.into())
}
/// CL_VERSION_2_1
pub fn il_version(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_IL_VERSION)?.into())
}
/// CL_VERSION_2_1
pub fn max_num_sub_groups(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_NUM_SUB_GROUPS)?.into())
}
/// CL_VERSION_2_1
pub fn sub_group_independent_forward_progress(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(
self.id(),
CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS,
)?) != CL_FALSE)
}
/// CL_VERSION_3_0
pub fn numeric_version(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NUMERIC_VERSION)?.into())
}
/// CL_VERSION_3_0
pub fn extensions_with_version(&self) -> Result<Vec<cl_name_version>> {
Ok(get_device_info(self.id(), CL_DEVICE_EXTENSIONS_WITH_VERSION)?.into())
}
/// CL_VERSION_3_0
pub fn ils_with_version(&self) -> Result<Vec<cl_name_version>> {
Ok(get_device_info(self.id(), CL_DEVICE_ILS_WITH_VERSION)?.into())
}
/// CL_VERSION_3_0
pub fn built_in_kernels_with_version(&self) -> Result<Vec<cl_name_version>> {
Ok(get_device_info(self.id(), CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION)?.into())
}
/// CL_VERSION_3_0
pub fn atomic_memory_capabilities(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES)?.into())
}
/// CL_VERSION_3_0
pub fn atomic_fence_capabilities(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_ATOMIC_FENCE_CAPABILITIES)?.into())
}
/// CL_VERSION_3_0
pub fn non_uniform_work_group_support(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(
self.id(),
CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT,
)?) != CL_FALSE)
}
/// CL_VERSION_3_0
pub fn opencl_c_all_versions(&self) -> Result<Vec<cl_name_version>> {
Ok(get_device_info(self.id(), CL_DEVICE_OPENCL_C_ALL_VERSIONS)?.into())
}
/// CL_VERSION_3_0
pub fn preferred_work_group_size_multiple(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE)?.into())
}
/// CL_VERSION_3_0
pub fn work_group_collective_functions_support(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(
self.id(),
CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT,
)?) != CL_FALSE)
}
/// CL_VERSION_3_0
pub fn generic_address_space_support(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(
self.id(),
CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT,
)?) != CL_FALSE)
}
/// CL_VERSION_3_0
pub fn uuid_khr(&self) -> Result<[u8; CL_UUID_SIZE_KHR]> {
Ok(get_device_info(self.id(), CL_DEVICE_UUID_KHR)?.into())
}
/// CL_VERSION_3_0
pub fn driver_uuid_khr(&self) -> Result<[u8; CL_UUID_SIZE_KHR]> {
Ok(get_device_info(self.id(), CL_DRIVER_UUID_KHR)?.into())
}
/// CL_VERSION_3_0
pub fn luid_valid_khr(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_LUID_VALID_KHR)?) != CL_FALSE)
}
/// CL_VERSION_3_0
pub fn luid_khr(&self) -> Result<[u8; CL_LUID_SIZE_KHR]> {
Ok(get_device_info(self.id(), CL_DEVICE_LUID_KHR)?.into())
}
/// CL_VERSION_3_0
pub fn node_mask_khr(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NODE_MASK_KHR)?.into())
}
/// CL_VERSION_3_0
pub fn opencl_c_features(&self) -> Result<Vec<cl_name_version>> {
Ok(get_device_info(self.id(), CL_DEVICE_OPENCL_C_FEATURES)?.into())
}
/// CL_VERSION_3_0
pub fn device_enqueue_capabilities(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES)?.into())
}
/// CL_VERSION_3_0
pub fn pipe_support(&self) -> Result<bool> {
Ok(cl_uint::from(get_device_info(self.id(), CL_DEVICE_PIPE_SUPPORT)?) != CL_FALSE)
}
/// CL_VERSION_3_0
pub fn latest_conformance_version_passed(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED)?.into())
}
pub fn integer_dot_product_capabilities_khr(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR)?.into())
}
pub fn integer_dot_product_acceleration_properties_8bit_khr(
&self,
) -> Result<cl_device_integer_dot_product_acceleration_properties_khr> {
let value: Vec<u8> = get_device_info(
self.id(),
CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR,
)?
.into();
Ok(get_device_integer_dot_product_acceleration_properties_khr(
&value,
))
}
pub fn integer_dot_product_acceleration_properties_4x8bit_packed_khr(
&self,
) -> Result<cl_device_integer_dot_product_acceleration_properties_khr> {
let value: Vec<u8> = get_device_info(
self.id(),
CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_PACKED_KHR,
)?
.into();
Ok(get_device_integer_dot_product_acceleration_properties_khr(
&value,
))
}
pub fn compute_capability_major_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV)?.into())
}
pub fn compute_capability_minor_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV)?.into())
}
pub fn registers_per_block_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_REGISTERS_PER_BLOCK_NV)?.into())
}
pub fn wrap_size_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_WARP_SIZE_NV)?.into())
}
pub fn gpu_overlap_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GPU_OVERLAP_NV)?.into())
}
pub fn compute_kernel_exec_timeout_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV)?.into())
}
pub fn integrated_memory_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_INTEGRATED_MEMORY_NV)?.into())
}
pub fn pci_bus_id_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PCI_BUS_ID_NV)?.into())
}
pub fn pci_slot_id_nv(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PCI_SLOT_ID_NV)?.into())
}
pub fn profiling_timer_offset_amd(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_PROFILING_TIMER_OFFSET_AMD)?.into())
}
pub fn topology_amd(&self) -> Result<cl_amd_device_topology> {
let value: Vec<u8> = get_device_info(self.id(), CL_DEVICE_TOPOLOGY_AMD)?.into();
Ok(get_amd_device_topology(&value))
}
pub fn pci_bus_id_amd(&self) -> Result<cl_uint> {
let value = self.topology_amd()?;
Ok(value.bus as cl_uint)
}
pub fn board_name_amd(&self) -> Result<String> {
Ok(get_device_info(self.id(), CL_DEVICE_BOARD_NAME_AMD)?.into())
}
pub fn global_free_memory_amd(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_FREE_MEMORY_AMD)?.into())
}
pub fn simd_per_compute_unit_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD)?.into())
}
pub fn simd_width_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_SIMD_WIDTH_AMD)?.into())
}
pub fn simd_instruction_width_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD)?.into())
}
pub fn wavefront_width_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_WAVEFRONT_WIDTH_AMD)?.into())
}
pub fn global_mem_channels_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD)?.into())
}
pub fn global_mem_channel_banks_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD)?.into())
}
pub fn global_mem_channel_bank_width_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD)?.into())
}
pub fn local_mem_size_per_compute_unit_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD)?.into())
}
pub fn local_mem_banks_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_LOCAL_MEM_BANKS_AMD)?.into())
}
pub fn thread_trace_supported_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD)?.into())
}
pub fn gfxip_major_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GFXIP_MAJOR_AMD)?.into())
}
pub fn gfxip_minor_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_GFXIP_MINOR_AMD)?.into())
}
pub fn available_async_queues_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD)?.into())
}
pub fn preferred_work_group_size_amd(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD)?.into())
}
pub fn max_work_group_size_amd(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD)?.into())
}
pub fn preferred_constant_buffer_size_amd(&self) -> Result<size_t> {
Ok(get_device_info(self.id(), CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD)?.into())
}
pub fn pcie_id_amd(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_PCIE_ID_AMD)?.into())
}
pub fn device_ip_version_intel(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_IP_VERSION_INTEL)?.into())
}
pub fn device_id_intel(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_ID_INTEL)?.into())
}
pub fn device_num_slices_intel(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NUM_SLICES_INTEL)?.into())
}
pub fn device_num_sub_slices_per_slice_intel(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NUM_SUB_SLICES_PER_SLICE_INTEL)?.into())
}
pub fn device_num_eus_per_sub_slice_intel(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NUM_EUS_PER_SUB_SLICE_INTEL)?.into())
}
pub fn device_num_threads_per_eu_intel(&self) -> Result<cl_uint> {
Ok(get_device_info(self.id(), CL_DEVICE_NUM_THREADS_PER_EU_INTEL)?.into())
}
pub fn device_feature_capabilities_intel(
&self,
) -> Result<cl_device_feature_capabilities_intel> {
Ok(get_device_info(self.id(), CL_DEVICE_FEATURE_CAPABILITIES_INTEL)?.into())
}
pub fn device_external_memory_import_handle_types_khr(&self) -> Result<Vec<u32>> {
Ok(get_device_info(self.id(), CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR)?.into())
}
pub fn device_semaphore_import_handle_types_khr(&self) -> Result<Vec<u32>> {
Ok(get_device_info(self.id(), CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR)?.into())
}
pub fn device_semaphore_export_handle_types_khr(&self) -> Result<Vec<u32>> {
Ok(get_device_info(self.id(), CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR)?.into())
}
pub fn device_semaphore_types_khr(&self) -> Result<Vec<u32>> {
Ok(get_device_info(self.id(), CL_DEVICE_SEMAPHORE_TYPES_KHR)?.into())
}
pub fn device_command_buffer_capabilities_khr(&self) -> Result<cl_ulong> {
Ok(get_device_info(self.id(), CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR)?.into())
}
pub fn device_command_buffer_required_queue_properties_khr(&self) -> Result<cl_ulong> {
Ok(get_device_info(
self.id(),
CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR,
)?
.into())
}
/// Get data about an OpenCL device.
/// Calls clGetDeviceInfo to get the desired data about the device.
pub fn get_data(&self, param_name: cl_device_info) -> Result<Vec<u8>> {
Ok(get_device_data(self.id(), param_name)?)
}
/// Determine if the device supports the given half floating point capability.
/// Returns true if the device supports it, false otherwise.
pub fn supports_half(&self, min_fp_capability: cl_device_fp_config) -> bool {
if let Ok(fp) = self.half_fp_config() {
0 < fp & min_fp_capability
} else {
false
}
}
/// Determine if the device supports the given double floating point capability.
/// Returns true if the device supports it, false otherwise.
///
/// CL_VERSION_1_2
pub fn supports_double(&self, min_fp_capability: cl_device_fp_config) -> bool {
if let Ok(fp) = self.double_fp_config() {
0 < fp & min_fp_capability
} else {
false
}
}
/// Determine if the device supports SVM and, if so, what kind of SVM.
/// Returns zero if the device does not support SVM.
///
/// CL_VERSION_2_0
pub fn svm_mem_capability(&self) -> cl_device_svm_capabilities {
if let Ok(svm) = self.svm_capabilities() {
svm
} else {
0
}
}
#[cfg(feature = "cl_khr_external_semaphore")]
pub fn get_semaphore_handle_for_type_khr(
&self,
sema_object: ext::cl_semaphore_khr,
handle_type: ext::cl_external_semaphore_handle_type_khr,
) -> Result<ext::cl_semaphore_khr> {
Ok(ext::get_semaphore_handle_for_type_khr(
sema_object,
self.id(),
handle_type,
)?)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::get_platforms;
use cl3::info_type::InfoType;
#[cfg(feature = "CL_VERSION_1_2")]
use std::ptr;
#[test]
fn test_get_devices() {
let platforms = get_platforms().unwrap();
println!("Number of platforms: {}", platforms.len());
assert!(0 < platforms.len());
for platform in platforms {
println!("CL_PLATFORM_NAME: {}", platform.name().unwrap());
let devices = platform.get_devices(CL_DEVICE_TYPE_ALL).unwrap();
for device_id in devices {
let device = Device::new(device_id);
println!("Device Debug Trait: {:?}", device);
println!("\tCL_DEVICE_NAME: {}", device.name().unwrap());
println!("\tCL_DEVICE_TYPE: {:X}", device.dev_type().unwrap());
println!("\tCL_DEVICE_VENDOR_ID: {:X}", device.vendor_id().unwrap());
println!("\tCL_DEVICE_VENDOR: {}", device.vendor().unwrap());
println!(
"\tCL_DEVICE_OPENCL_C_VERSION: {:?}",
device.opencl_c_version().unwrap()
);
println!();
}
}
}
#[cfg(feature = "CL_VERSION_1_2")]
#[test]
fn test_get_sub_devices() {
let platforms = get_platforms().unwrap();
println!("Number of platforms: {}", platforms.len());
assert!(0 < platforms.len());
// Find an OpenCL device with sub devices
let mut device_id = ptr::null_mut();
let mut has_sub_devices: bool = false;