Skip to content

Commit

Permalink
[SYCL] Add ext_intel_device_id to sycl_ext_intel_device_info (#7010)
Browse files Browse the repository at this point in the history
This adds the ability to query the device ID of a device, which must be
equal to the PCI device ID for PCI devices. An important use case of
this feature is detecting the GPU architecture, which is necessary in
applications that have dedicated code paths for different architectures.
Querying the device ID is implemented for Level Zero and OpenCL as well.
  • Loading branch information
atafra authored Oct 12, 2022
1 parent b91b732 commit 1d99344
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 1 deletion.
38 changes: 38 additions & 0 deletions sycl/doc/extensions/supported/sycl_ext_intel_device_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@ The Feature Test Macro SYCL\_EXT\_INTEL\_DEVICE\_INFO will be defined as one of
| 2 | Device UUID is supported |
| 3 | HW threads per EU device query is supported |
| 4 | Free device memory query is supported |
| 5 | Device ID is supported |



# Device ID #

A new device descriptor will be added which will provide the device ID.

If the implementation is driven primarily by a PCI device with a PCI device ID, the device ID must be that PCI device ID. Otherwise, the choice of what to return may be dictated by operating system or platform policies - but should uniquely identify both the device version and any major configuration options (for example, core count in the case of multi-core devices).

## Version ##

The extension supports this query in version 5 and later.

## Device Information Descriptors ##

| Device Descriptors | Return Type | Description |
| ------------------ | ----------- | ----------- |
| ext\:\:intel\:\:info\:\:device\:\:device\_id | uint32\_t| Returns the device ID.|


## Aspects ##

A new aspect, ext\_intel\_device\_id, will be added.


## Error Condition ##

An invalid object runtime error will be thrown if the device does not support aspect\:\:ext\_intel\_device\_id.

## Example Usage ##

The device ID can be obtained using the standard get\_info() interface.

if (dev.has(aspect::ext_intel_device_id)) {
auto deviceID = dev.get_info<ext::intel::info::device::device_id>();
}



# Device UUID #
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ typedef enum {
// Intel UUID extension.
PI_DEVICE_INFO_UUID = 0x106A,
// These are Intel-specific extensions.
PI_DEVICE_INFO_DEVICE_ID = 0x4251,
PI_DEVICE_INFO_PCI_ADDRESS = 0x10020,
PI_DEVICE_INFO_GPU_EU_COUNT = 0x10021,
PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH = 0x10022,
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/feature_test.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
// Feature test macro definitions

// TODO: Move these feature-test macros to compiler driver.
#define SYCL_EXT_INTEL_DEVICE_INFO 3
#define SYCL_EXT_INTEL_DEVICE_INFO 5
#define SYCL_EXT_ONEAPI_SUB_GROUP_MASK 1
#define SYCL_EXT_ONEAPI_LOCAL_MEMORY 1
#define SYCL_EXT_ONEAPI_MATRIX 1
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/info/aspects.def
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ __SYCL_ASPECT(ext_intel_gpu_hw_threads_per_eu, 33)
__SYCL_ASPECT(ext_oneapi_cuda_async_barrier, 34)
__SYCL_ASPECT(ext_oneapi_bfloat16, 35)
__SYCL_ASPECT(ext_intel_free_memory, 36)
__SYCL_ASPECT(ext_intel_device_id, 37)
1 change: 1 addition & 0 deletions sycl/include/sycl/info/ext_intel_device_traits.def
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF
#define __SYCL_PARAM_TRAITS_TEMPLATE_SPEC __SYCL_PARAM_TRAITS_SPEC
#endif
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, device_id, pi_uint32, PI_DEVICE_INFO_DEVICE_ID)
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, pci_address, std::string, PI_DEVICE_INFO_PCI_ADDRESS)
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, gpu_eu_count, pi_uint32, PI_DEVICE_INFO_GPU_EU_COUNT)
__SYCL_PARAM_TRAITS_SPEC(ext::intel, device, gpu_eu_simd_width, pi_uint32, PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH)
Expand Down
1 change: 1 addition & 0 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,7 @@ pi_result cuda_piDeviceGetInfo(pi_device device, pi_device_info param_name,
}

// TODO: Investigate if this information is available on CUDA.
case PI_DEVICE_INFO_DEVICE_ID:
case PI_DEVICE_INFO_PCI_ADDRESS:
case PI_DEVICE_INFO_GPU_EU_COUNT:
case PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH:
Expand Down
1 change: 1 addition & 0 deletions sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
CASE_PI_UNSUPPORTED(PI_DEVICE_INFO_IL_VERSION)

// Intel-specific extensions
CASE_PI_UNSUPPORTED(PI_DEVICE_INFO_DEVICE_ID)
CASE_PI_UNSUPPORTED(PI_DEVICE_INFO_PCI_ADDRESS)
CASE_PI_UNSUPPORTED(PI_DEVICE_INFO_GPU_EU_COUNT)
CASE_PI_UNSUPPORTED(PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH)
Expand Down
1 change: 1 addition & 0 deletions sycl/plugins/hip/pi_hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,7 @@ pi_result hip_piDeviceGetInfo(pi_device device, pi_device_info param_name,
case PI_DEVICE_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES:
// TODO: Investigate if this information is available on HIP.
case PI_DEVICE_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES:
case PI_DEVICE_INFO_DEVICE_ID:
case PI_DEVICE_INFO_PCI_ADDRESS:
case PI_DEVICE_INFO_GPU_EU_COUNT:
case PI_DEVICE_INFO_GPU_EU_SIMD_WIDTH:
Expand Down
3 changes: 3 additions & 0 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,9 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
}

// intel extensions for GPU information
case PI_DEVICE_INFO_DEVICE_ID:
return ReturnValue(
pi_uint32{Device->ZeDeviceProperties->deviceId});
case PI_DEVICE_INFO_PCI_ADDRESS: {
if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
zePrint("Set SYCL_ENABLE_PCI=1 to obtain PCI data.\n");
Expand Down
4 changes: 4 additions & 0 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ bool device_impl::has(aspect Aspect) const {
return get_info<info::device::usm_restricted_shared_allocations>();
case aspect::usm_system_allocations:
return get_info<info::device::usm_system_allocations>();
case aspect::ext_intel_device_id:
return getPlugin().call_nocheck<detail::PiApiKind::piDeviceGetInfo>(
MDevice, PI_DEVICE_INFO_DEVICE_ID, 0,
nullptr, &return_size) == PI_SUCCESS;
case aspect::ext_intel_pci_address:
return getPlugin().call_nocheck<detail::PiApiKind::piDeviceGetInfo>(
MDevice, PI_DEVICE_INFO_PCI_ADDRESS, 0, nullptr, &return_size) ==
Expand Down
7 changes: 7 additions & 0 deletions sycl/source/detail/device_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,13 @@ inline bool get_device_info_host<info::device::ext_intel_mem_channel>() {
// Specializations for intel extensions for Level Zero low-level
// detail device descriptors (not support on host).
template <>
inline uint32_t
get_device_info_host<ext::intel::info::device::device_id>() {
throw runtime_error(
"Obtaining the device ID is not supported on HOST device",
PI_ERROR_INVALID_DEVICE);
}
template <>
inline std::string
get_device_info_host<ext::intel::info::device::pci_address>() {
throw runtime_error(
Expand Down
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,7 @@ _ZNK4sycl3_V16device8get_infoINS0_3ext5intel4info6device21gpu_hw_threads_per_euE
_ZNK4sycl3_V16device8get_infoINS0_3ext5intel4info6device23gpu_subslices_per_sliceEEENS0_6detail19is_device_info_descIT_E11return_typeEv
_ZNK4sycl3_V16device8get_infoINS0_3ext5intel4info6device25gpu_eu_count_per_subsliceEEENS0_6detail19is_device_info_descIT_E11return_typeEv
_ZNK4sycl3_V16device8get_infoINS0_3ext5intel4info6device4uuidEEENS0_6detail19is_device_info_descIT_E11return_typeEv
_ZNK4sycl3_V16device8get_infoINS0_3ext5intel4info6device9device_idEEENS0_6detail19is_device_info_descIT_E11return_typeEv
_ZNK4sycl3_V16device8get_infoINS0_3ext6oneapi12experimental4info6device15max_work_groupsILi1EEEEENS0_6detail19is_device_info_descIT_E11return_typeEv
_ZNK4sycl3_V16device8get_infoINS0_3ext6oneapi12experimental4info6device15max_work_groupsILi2EEEEENS0_6detail19is_device_info_descIT_E11return_typeEv
_ZNK4sycl3_V16device8get_infoINS0_3ext6oneapi12experimental4info6device15max_work_groupsILi3EEEEENS0_6detail19is_device_info_descIT_E11return_typeEv
Expand Down
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
??$get_info@Ucontext@kernel@info@_V1@sycl@@@kernel@_V1@sycl@@QEBA?AVcontext@12@XZ
??$get_info@Ucontext@queue@info@_V1@sycl@@@queue@_V1@sycl@@QEBA?AVcontext@12@XZ
??$get_info@Udevice@queue@info@_V1@sycl@@@queue@_V1@sycl@@QEBA?AVdevice@12@XZ
??$get_info@Udevice_id@device@info@intel@ext@_V1@sycl@@@device@_V1@sycl@@QEBAIXZ
??$get_info@Udevice_type@device@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AW4device_type@info@12@XZ
??$get_info@Udevices@context@info@_V1@sycl@@@context@_V1@sycl@@QEBA?AV?$vector@Vdevice@_V1@sycl@@V?$allocator@Vdevice@_V1@sycl@@@std@@@std@@XZ
??$get_info@Udouble_fp_config@device@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$vector@W4fp_config@info@_V1@sycl@@V?$allocator@W4fp_config@info@_V1@sycl@@@std@@@std@@XZ
Expand Down

0 comments on commit 1d99344

Please sign in to comment.