Skip to content

Commit f97d7c3

Browse files
authored
Merge pull request #2525 from dyniols/num_compute_units
Addition of num_compute_units query for device info
2 parents b35afd1 + 3ee2609 commit f97d7c3

File tree

10 files changed

+67
-2
lines changed

10 files changed

+67
-2
lines changed

include/ur_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2198,9 +2198,11 @@ typedef enum ur_device_info_t {
21982198
/// to the `USMPool` entry points and usage of the `pool` parameter of the
21992199
/// USM alloc entry points.
22002200
UR_DEVICE_INFO_USM_POOL_SUPPORT = 119,
2201+
/// [uint32_t] the number of compute units for specific backend.
2202+
UR_DEVICE_INFO_NUM_COMPUTE_UNITS = 120,
22012203
/// [::ur_bool_t] support the ::urProgramSetSpecializationConstants entry
22022204
/// point
2203-
UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 120,
2205+
UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 121,
22042206
/// [::ur_bool_t] Returns true if the device supports the use of
22052207
/// command-buffers.
22062208
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000,

include/ur_print.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,6 +2917,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) {
29172917
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
29182918
os << "UR_DEVICE_INFO_USM_POOL_SUPPORT";
29192919
break;
2920+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS:
2921+
os << "UR_DEVICE_INFO_NUM_COMPUTE_UNITS";
2922+
break;
29202923
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS:
29212924
os << "UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS";
29222925
break;
@@ -4551,6 +4554,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
45514554

45524555
os << ")";
45534556
} break;
4557+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS: {
4558+
const uint32_t *tptr = (const uint32_t *)ptr;
4559+
if (sizeof(uint32_t) > size) {
4560+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t)
4561+
<< ")";
4562+
return UR_RESULT_ERROR_INVALID_SIZE;
4563+
}
4564+
os << (const void *)(tptr) << " (";
4565+
4566+
os << *tptr;
4567+
4568+
os << ")";
4569+
} break;
45544570
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS: {
45554571
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
45564572
if (sizeof(ur_bool_t) > size) {

scripts/core/device.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ etors:
443443
desc: "[$x_bool_t] return true if the device supports the `EnqueueDeviceGlobalVariableWrite` and `EnqueueDeviceGlobalVariableRead` entry points."
444444
- name: USM_POOL_SUPPORT
445445
desc: "[$x_bool_t] return true if the device supports USM pooling. Pertains to the `USMPool` entry points and usage of the `pool` parameter of the USM alloc entry points."
446+
- name: NUM_COMPUTE_UNITS
447+
desc: "[uint32_t] the number of compute units for specific backend."
446448
- name: PROGRAM_SET_SPECIALIZATION_CONSTANTS
447449
desc: "[$x_bool_t] support the $xProgramSetSpecializationConstants entry point"
448450
--- #--------------------------------------------------------------------------

source/adapters/cuda/device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
5656
case UR_DEVICE_INFO_VENDOR_ID: {
5757
return ReturnValue(4318u);
5858
}
59+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS:
5960
case UR_DEVICE_INFO_MAX_COMPUTE_UNITS: {
6061
return ReturnValue(hDevice->getNumComputeUnits());
6162
}

source/adapters/hip/device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
5757
#endif
5858
return ReturnValue(VendorId);
5959
}
60+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS:
6061
case UR_DEVICE_INFO_MAX_COMPUTE_UNITS: {
6162
int ComputeUnits = 0;
6263
UR_CHECK_ERROR(hipDeviceGetAttribute(

source/adapters/level_zero/device.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ ur_result_t urDeviceGetInfo(
324324

325325
return ReturnValue(uint32_t{MaxComputeUnits});
326326
}
327+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS: {
328+
uint32_t NumComputeUnits =
329+
Device->ZeDeviceProperties->numSubslicesPerSlice *
330+
Device->ZeDeviceProperties->numSlices;
331+
return ReturnValue(uint32_t{NumComputeUnits});
332+
}
327333
case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS:
328334
// Level Zero spec defines only three dimensions
329335
return ReturnValue(uint32_t{3});

source/adapters/native_cpu/device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
164164
return ReturnValue(bool{true});
165165
case UR_DEVICE_INFO_LINKER_AVAILABLE:
166166
return ReturnValue(bool{true});
167+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS:
167168
case UR_DEVICE_INFO_MAX_COMPUTE_UNITS:
168169
return ReturnValue(static_cast<uint32_t>(hDevice->tp.num_threads()));
169170
case UR_DEVICE_INFO_PARTITION_MAX_SUB_DEVICES:

source/adapters/opencl/device.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,38 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
828828
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT: {
829829
return ReturnValue(false);
830830
}
831+
case UR_DEVICE_INFO_NUM_COMPUTE_UNITS: {
832+
833+
bool ExtensionSupported = false;
834+
UR_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
835+
cl_adapter::cast<cl_device_id>(hDevice),
836+
{"cl_intel_device_attribute_query"}, ExtensionSupported));
837+
838+
cl_device_type CLType;
839+
CL_RETURN_ON_FAILURE(
840+
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_TYPE,
841+
sizeof(cl_device_type), &CLType, nullptr));
842+
843+
cl_uint NumComputeUnits;
844+
if (ExtensionSupported && (CLType & CL_DEVICE_TYPE_GPU)) {
845+
cl_uint SliceCount = 0;
846+
cl_uint SubSlicePerSliceCount = 0;
847+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
848+
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_NUM_SLICES_INTEL,
849+
sizeof(cl_uint), &SliceCount, nullptr));
850+
CL_RETURN_ON_FAILURE(
851+
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice),
852+
CL_DEVICE_NUM_SUB_SLICES_PER_SLICE_INTEL,
853+
sizeof(cl_uint), &SubSlicePerSliceCount, nullptr));
854+
NumComputeUnits = SliceCount * SubSlicePerSliceCount;
855+
} else {
856+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
857+
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_MAX_COMPUTE_UNITS,
858+
sizeof(cl_uint), &NumComputeUnits, nullptr));
859+
}
860+
861+
return ReturnValue(static_cast<uint32_t>(NumComputeUnits));
862+
}
831863
case UR_DEVICE_INFO_TIMESTAMP_RECORDING_SUPPORT_EXP: {
832864
return ReturnValue(false);
833865
}

test/conformance/device/urDeviceGetInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ static std::unordered_map<ur_device_info_t, size_t> device_info_size_map = {
128128
sizeof(ur_memory_scope_capability_flags_t)},
129129
{UR_DEVICE_INFO_ESIMD_SUPPORT, sizeof(ur_bool_t)},
130130
{UR_DEVICE_INFO_IP_VERSION, sizeof(uint32_t)},
131-
{UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT, sizeof(ur_bool_t)}};
131+
{UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT, sizeof(ur_bool_t)},
132+
{UR_DEVICE_INFO_NUM_COMPUTE_UNITS, sizeof(uint32_t)}};
132133

133134
using urDeviceGetInfoTest = uur::urDeviceTestWithParam<ur_device_info_t>;
134135

@@ -253,6 +254,7 @@ UUR_DEVICE_TEST_SUITE_P(
253254
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_DOUBLE, //
254255
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_HALF, //
255256
UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_INT, //
257+
UR_DEVICE_INFO_NUM_COMPUTE_UNITS, //
256258
UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS //
257259
),
258260
uur::deviceTestWithParamPrinter<ur_device_info_t>);

tools/urinfo/urinfo.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice,
327327
std::cout << prefix;
328328
printDeviceInfo<ur_bool_t>(hDevice, UR_DEVICE_INFO_USM_POOL_SUPPORT);
329329
std::cout << prefix;
330+
printDeviceInfo<uint32_t>(hDevice, UR_DEVICE_INFO_NUM_COMPUTE_UNITS);
331+
std::cout << prefix;
330332
printDeviceInfo<ur_bool_t>(
331333
hDevice, UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS);
332334
std::cout << prefix;

0 commit comments

Comments
 (0)