@@ -59,7 +59,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
59
59
UR_CHECK_ERROR (cuDeviceGetAttribute (
60
60
&ComputeUnits, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
61
61
hDevice->get ()));
62
- detail::ur::assertion (ComputeUnits >= 0 );
62
+ if (ComputeUnits < 0 ) {
63
+ return UR_RESULT_ERROR_INVALID_SIZE;
64
+ }
63
65
return ReturnValue (static_cast <uint32_t >(ComputeUnits));
64
66
}
65
67
case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS: {
@@ -73,15 +75,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
73
75
int MaxX = 0 , MaxY = 0 , MaxZ = 0 ;
74
76
UR_CHECK_ERROR (cuDeviceGetAttribute (
75
77
&MaxX, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, hDevice->get ()));
76
- detail::ur::assertion (MaxX >= 0 );
78
+ if (MaxX < 0 ) {
79
+ return UR_RESULT_ERROR_INVALID_SIZE;
80
+ }
77
81
78
82
UR_CHECK_ERROR (cuDeviceGetAttribute (
79
83
&MaxY, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, hDevice->get ()));
80
- detail::ur::assertion (MaxY >= 0 );
84
+ if (MaxY < 0 ) {
85
+ return UR_RESULT_ERROR_INVALID_SIZE;
86
+ }
81
87
82
88
UR_CHECK_ERROR (cuDeviceGetAttribute (
83
89
&MaxZ, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z, hDevice->get ()));
84
- detail::ur::assertion (MaxZ >= 0 );
90
+ if (MaxZ < 0 ) {
91
+ return UR_RESULT_ERROR_INVALID_SIZE;
92
+ }
85
93
86
94
ReturnSizes.Sizes [0 ] = size_t (MaxX);
87
95
ReturnSizes.Sizes [1 ] = size_t (MaxY);
@@ -96,15 +104,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
96
104
int MaxX = 0 , MaxY = 0 , MaxZ = 0 ;
97
105
UR_CHECK_ERROR (cuDeviceGetAttribute (
98
106
&MaxX, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X, hDevice->get ()));
99
- detail::ur::assertion (MaxX >= 0 );
107
+ if (MaxX < 0 ) {
108
+ return UR_RESULT_ERROR_INVALID_SIZE;
109
+ }
100
110
101
111
UR_CHECK_ERROR (cuDeviceGetAttribute (
102
112
&MaxY, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y, hDevice->get ()));
103
- detail::ur::assertion (MaxY >= 0 );
113
+ if (MaxY < 0 ) {
114
+ return UR_RESULT_ERROR_INVALID_SIZE;
115
+ }
104
116
105
117
UR_CHECK_ERROR (cuDeviceGetAttribute (
106
118
&MaxZ, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z, hDevice->get ()));
107
- detail::ur::assertion (MaxZ >= 0 );
119
+ if (MaxZ < 0 ) {
120
+ return UR_RESULT_ERROR_INVALID_SIZE;
121
+ }
108
122
109
123
ReturnSizes.Sizes [0 ] = size_t (MaxX);
110
124
ReturnSizes.Sizes [1 ] = size_t (MaxY);
@@ -118,7 +132,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
118
132
&MaxWorkGroupSize, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
119
133
hDevice->get ()));
120
134
121
- detail::ur::assertion (MaxWorkGroupSize >= 0 );
135
+ if (MaxWorkGroupSize < 0 ) {
136
+ return UR_RESULT_ERROR_INVALID_SIZE;
137
+ }
122
138
123
139
return ReturnValue (size_t (MaxWorkGroupSize));
124
140
}
@@ -261,7 +277,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
261
277
int ClockFreq = 0 ;
262
278
UR_CHECK_ERROR (cuDeviceGetAttribute (
263
279
&ClockFreq, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, hDevice->get ()));
264
- detail::ur::assertion (ClockFreq >= 0 );
280
+ if (ClockFreq < 0 ) {
281
+ return UR_RESULT_ERROR_INVALID_SIZE;
282
+ }
265
283
return ReturnValue (static_cast <uint32_t >(ClockFreq) / 1000u );
266
284
}
267
285
case UR_DEVICE_INFO_ADDRESS_BITS: {
@@ -305,12 +323,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
305
323
UR_CHECK_ERROR (cuDeviceGetAttribute (
306
324
&TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT,
307
325
hDevice->get ()));
308
- detail::ur::assertion (TexHeight >= 0 );
326
+ if (TexHeight < 0 ) {
327
+ return UR_RESULT_ERROR_INVALID_SIZE;
328
+ }
309
329
int SurfHeight = 0 ;
310
330
UR_CHECK_ERROR (cuDeviceGetAttribute (
311
331
&SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT,
312
332
hDevice->get ()));
313
- detail::ur::assertion (SurfHeight >= 0 );
333
+ if (SurfHeight < 0 ) {
334
+ return UR_RESULT_ERROR_INVALID_SIZE;
335
+ }
314
336
315
337
int Min = std::min (TexHeight, SurfHeight);
316
338
@@ -322,12 +344,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
322
344
UR_CHECK_ERROR (cuDeviceGetAttribute (
323
345
&TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH,
324
346
hDevice->get ()));
325
- detail::ur::assertion (TexWidth >= 0 );
347
+ if (TexWidth < 0 ) {
348
+ return UR_RESULT_ERROR_INVALID_SIZE;
349
+ }
326
350
int SurfWidth = 0 ;
327
351
UR_CHECK_ERROR (cuDeviceGetAttribute (
328
352
&SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH,
329
353
hDevice->get ()));
330
- detail::ur::assertion (SurfWidth >= 0 );
354
+ if (SurfWidth < 0 ) {
355
+ return UR_RESULT_ERROR_INVALID_SIZE;
356
+ }
331
357
332
358
int Min = std::min (TexWidth, SurfWidth);
333
359
@@ -339,12 +365,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
339
365
UR_CHECK_ERROR (cuDeviceGetAttribute (
340
366
&TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT,
341
367
hDevice->get ()));
342
- detail::ur::assertion (TexHeight >= 0 );
368
+ if (TexHeight < 0 ) {
369
+ return UR_RESULT_ERROR_INVALID_SIZE;
370
+ }
343
371
int SurfHeight = 0 ;
344
372
UR_CHECK_ERROR (cuDeviceGetAttribute (
345
373
&SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT,
346
374
hDevice->get ()));
347
- detail::ur::assertion (SurfHeight >= 0 );
375
+ if (SurfHeight < 0 ) {
376
+ return UR_RESULT_ERROR_INVALID_SIZE;
377
+ }
348
378
349
379
int Min = std::min (TexHeight, SurfHeight);
350
380
@@ -356,12 +386,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
356
386
UR_CHECK_ERROR (cuDeviceGetAttribute (
357
387
&TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH,
358
388
hDevice->get ()));
359
- detail::ur::assertion (TexWidth >= 0 );
389
+ if (TexWidth < 0 ) {
390
+ return UR_RESULT_ERROR_INVALID_SIZE;
391
+ }
360
392
int SurfWidth = 0 ;
361
393
UR_CHECK_ERROR (cuDeviceGetAttribute (
362
394
&SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH,
363
395
hDevice->get ()));
364
- detail::ur::assertion (SurfWidth >= 0 );
396
+ if (SurfWidth < 0 ) {
397
+ return UR_RESULT_ERROR_INVALID_SIZE;
398
+ }
365
399
366
400
int Min = std::min (TexWidth, SurfWidth);
367
401
@@ -373,12 +407,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
373
407
UR_CHECK_ERROR (cuDeviceGetAttribute (
374
408
&TexDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH,
375
409
hDevice->get ()));
376
- detail::ur::assertion (TexDepth >= 0 );
410
+ if (TexDepth < 0 ) {
411
+ return UR_RESULT_ERROR_INVALID_SIZE;
412
+ }
377
413
int SurfDepth = 0 ;
378
414
UR_CHECK_ERROR (cuDeviceGetAttribute (
379
415
&SurfDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH,
380
416
hDevice->get ()));
381
- detail::ur::assertion (SurfDepth >= 0 );
417
+ if (SurfDepth < 0 ) {
418
+ return UR_RESULT_ERROR_INVALID_SIZE;
419
+ }
382
420
383
421
int Min = std::min (TexDepth, SurfDepth);
384
422
@@ -390,12 +428,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
390
428
UR_CHECK_ERROR (cuDeviceGetAttribute (
391
429
&TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH,
392
430
hDevice->get ()));
393
- detail::ur::assertion (TexWidth >= 0 );
431
+ if (TexWidth < 0 ) {
432
+ return UR_RESULT_ERROR_INVALID_SIZE;
433
+ }
394
434
int SurfWidth = 0 ;
395
435
UR_CHECK_ERROR (cuDeviceGetAttribute (
396
436
&SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH,
397
437
hDevice->get ()));
398
- detail::ur::assertion (SurfWidth >= 0 );
438
+ if (SurfWidth < 0 ) {
439
+ return UR_RESULT_ERROR_INVALID_SIZE;
440
+ }
399
441
400
442
int Min = std::min (TexWidth, SurfWidth);
401
443
@@ -464,23 +506,28 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
464
506
int CacheSize = 0 ;
465
507
UR_CHECK_ERROR (cuDeviceGetAttribute (
466
508
&CacheSize, CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE, hDevice->get ()));
467
- detail::ur::assertion (CacheSize >= 0 );
509
+ if (CacheSize < 0 ) {
510
+ return UR_RESULT_ERROR_INVALID_SIZE;
511
+ }
468
512
// The L2 cache is global to the GPU.
469
513
return ReturnValue (static_cast <uint64_t >(CacheSize));
470
514
}
471
515
case UR_DEVICE_INFO_GLOBAL_MEM_SIZE: {
472
516
size_t Bytes = 0 ;
473
517
// Runtime API has easy access to this value, driver API info is scarse.
474
- detail::ur::assertion (cuDeviceTotalMem (&Bytes, hDevice->get ()) ==
475
- CUDA_SUCCESS);
518
+ if (cuDeviceTotalMem (&Bytes, hDevice->get ()) != CUDA_SUCCESS) {
519
+ return UR_RESULT_ERROR_INVALID_OPERATION;
520
+ }
476
521
return ReturnValue (uint64_t {Bytes});
477
522
}
478
523
case UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE: {
479
524
int ConstantMemory = 0 ;
480
525
UR_CHECK_ERROR (cuDeviceGetAttribute (
481
526
&ConstantMemory, CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY,
482
527
hDevice->get ()));
483
- detail::ur::assertion (ConstantMemory >= 0 );
528
+ if (ConstantMemory < 0 ) {
529
+ return UR_RESULT_ERROR_INVALID_SIZE;
530
+ }
484
531
485
532
return ReturnValue (static_cast <uint64_t >(ConstantMemory));
486
533
}
@@ -510,7 +557,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
510
557
UR_CHECK_ERROR (cuDeviceGetAttribute (
511
558
&ECCEnabled, CU_DEVICE_ATTRIBUTE_ECC_ENABLED, hDevice->get ()));
512
559
513
- detail::ur::assertion ((ECCEnabled == 0 ) | (ECCEnabled == 1 ));
560
+ if ((ECCEnabled != 0 ) | (ECCEnabled != 1 )) {
561
+ return UR_RESULT_ERROR_INVALID_OPERATION;
562
+ }
514
563
auto Result = static_cast <bool >(ECCEnabled);
515
564
return ReturnValue (Result);
516
565
}
@@ -519,7 +568,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
519
568
UR_CHECK_ERROR (cuDeviceGetAttribute (
520
569
&IsIntegrated, CU_DEVICE_ATTRIBUTE_INTEGRATED, hDevice->get ()));
521
570
522
- detail::ur::assertion ((IsIntegrated == 0 ) | (IsIntegrated == 1 ));
571
+ if ((IsIntegrated != 0 ) | (IsIntegrated != 1 )) {
572
+ return UR_RESULT_ERROR_INVALID_OPERATION;
573
+ }
523
574
auto result = static_cast <bool >(IsIntegrated);
524
575
return ReturnValue (result);
525
576
}
@@ -800,24 +851,28 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
800
851
case UR_DEVICE_INFO_GLOBAL_MEM_FREE: {
801
852
size_t FreeMemory = 0 ;
802
853
size_t TotalMemory = 0 ;
803
- detail::ur::assertion (cuMemGetInfo (&FreeMemory, &TotalMemory) ==
804
- CUDA_SUCCESS,
805
- " failed cuMemGetInfo() API. " );
854
+ if (cuMemGetInfo (&FreeMemory, &TotalMemory) != CUDA_SUCCESS) {
855
+ return UR_RESULT_ERROR_INVALID_OPERATION;
856
+ }
806
857
return ReturnValue (FreeMemory);
807
858
}
808
859
case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: {
809
860
int Value = 0 ;
810
861
UR_CHECK_ERROR (cuDeviceGetAttribute (
811
862
&Value, CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, hDevice->get ()));
812
- detail::ur::assertion (Value >= 0 );
863
+ if (Value < 0 ) {
864
+ return UR_RESULT_ERROR_INVALID_SIZE;
865
+ }
813
866
// Convert kilohertz to megahertz when returning.
814
867
return ReturnValue (Value / 1000 );
815
868
}
816
869
case UR_DEVICE_INFO_MEMORY_BUS_WIDTH: {
817
870
int Value = 0 ;
818
871
UR_CHECK_ERROR (cuDeviceGetAttribute (
819
872
&Value, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, hDevice->get ()));
820
- detail::ur::assertion (Value >= 0 );
873
+ if (Value < 0 ) {
874
+ return UR_RESULT_ERROR_INVALID_SIZE;
875
+ }
821
876
return ReturnValue (Value);
822
877
}
823
878
case UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES: {
@@ -905,17 +960,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
905
960
int Value = 0 ;
906
961
UR_CHECK_ERROR (cuDeviceGetAttribute (
907
962
&Value, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, hDevice->get ()));
908
- detail::ur::assertion (Value >= 0 );
963
+ if (Value < 0 ) {
964
+ return UR_RESULT_ERROR_INVALID_SIZE;
965
+ }
909
966
return ReturnValue (Value);
910
967
}
911
968
case UR_DEVICE_INFO_UUID: {
912
969
CUuuid UUID;
913
970
#if (CUDA_VERSION >= 11040)
914
- detail::ur::assertion (cuDeviceGetUuid_v2 (&UUID, hDevice->get ()) ==
915
- CUDA_SUCCESS);
971
+ if (cuDeviceGetUuid_v2 (&UUID, hDevice->get ()) != CUDA_SUCCESS) {
972
+ return UR_RESULT_ERROR_INVALID_DEVICE;
973
+ }
916
974
#else
917
- detail::ur::assertion (cuDeviceGetUuid (&UUID, hDevice->get ()) ==
918
- CUDA_SUCCESS);
975
+ if (cuDeviceGetUuid (&UUID, hDevice->get ()) != CUDA_SUCCESS) {
976
+ return UR_RESULT_ERROR_INVALID_DEVICE;
977
+ }
919
978
#endif
920
979
std::array<unsigned char , 16 > Name;
921
980
std::copy (UUID.bytes , UUID.bytes + 16 , Name.begin ());
@@ -994,7 +1053,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
994
1053
&MaxRegisters, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK,
995
1054
hDevice->get ()));
996
1055
997
- detail::ur::assertion (MaxRegisters >= 0 );
1056
+ if (MaxRegisters < 0 ) {
1057
+ return UR_RESULT_ERROR_INVALID_SIZE;
1058
+ }
998
1059
999
1060
return ReturnValue (static_cast <uint32_t >(MaxRegisters));
1000
1061
}
@@ -1008,7 +1069,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
1008
1069
UR_CHECK_ERROR (
1009
1070
cuDeviceGetPCIBusId (AddressBuffer, AddressBufferSize, hDevice->get ()));
1010
1071
// CUDA API (8.x - 12.1) guarantees 12 bytes + \0 are written
1011
- detail::ur::assertion (strnlen (AddressBuffer, AddressBufferSize) == 12 );
1072
+ if (strnlen (AddressBuffer, AddressBufferSize) != 12 ) {
1073
+ return UR_RESULT_ERROR_INVALID_OPERATION;
1074
+ }
1012
1075
return ReturnValue (AddressBuffer,
1013
1076
strnlen (AddressBuffer, AddressBufferSize - 1 ) + 1 );
1014
1077
}
0 commit comments