Skip to content

Commit 9ca2f91

Browse files
authored
[SYCL][L0] Enable global offset support for level_zero. (#3593)
Signed-off-by: rbegam <[email protected]>
1 parent ed537bc commit 9ca2f91

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ static sycl::detail::SpinLock *PiPlatformsCacheMutex =
278278
new sycl::detail::SpinLock;
279279
static bool PiPlatformCachePopulated = false;
280280

281+
// Keeps track if the global offset extension is found
282+
static bool PiDriverGlobalOffsetExtensionFound = false;
283+
281284
// TODO:: In the following 4 methods we may want to distinguish read access vs.
282285
// write (as it is OK for multiple threads to read the map without locking it).
283286

@@ -1125,6 +1128,26 @@ pi_result _pi_platform::initialize() {
11251128
ZeDriverApiVersion = std::to_string(ZE_MAJOR_VERSION(ZeApiVersion)) + "." +
11261129
std::to_string(ZE_MINOR_VERSION(ZeApiVersion));
11271130

1131+
// Cache driver extension properties
1132+
uint32_t Count = 0;
1133+
ZE_CALL(zeDriverGetExtensionProperties, (ZeDriver, &Count, nullptr));
1134+
1135+
std::vector<ze_driver_extension_properties_t> zeExtensions(Count);
1136+
1137+
ZE_CALL(zeDriverGetExtensionProperties,
1138+
(ZeDriver, &Count, zeExtensions.data()));
1139+
1140+
for (auto extension : zeExtensions) {
1141+
// Check if global offset extension is available
1142+
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
1143+
strlen(ZE_GLOBAL_OFFSET_EXP_NAME) + 1) == 0) {
1144+
if (extension.version == ZE_GLOBAL_OFFSET_EXP_VERSION_1_0) {
1145+
PiDriverGlobalOffsetExtensionFound = true;
1146+
}
1147+
}
1148+
zeDriverExtensionMap[extension.name] = extension.version;
1149+
}
1150+
11281151
return PI_SUCCESS;
11291152
}
11301153

@@ -3748,11 +3771,14 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
37483771
PI_ASSERT((WorkDim > 0) && (WorkDim < 4), PI_INVALID_WORK_DIMENSION);
37493772

37503773
if (GlobalWorkOffset != NULL) {
3751-
for (pi_uint32 i = 0; i < WorkDim; i++) {
3752-
if (GlobalWorkOffset[i] != 0) {
3753-
return PI_INVALID_VALUE;
3754-
}
3774+
if (!PiDriverGlobalOffsetExtensionFound) {
3775+
zePrint("No global offset extension found on this driver\n");
3776+
return PI_INVALID_VALUE;
37553777
}
3778+
3779+
ZE_CALL(zeKernelSetGlobalOffsetExp,
3780+
(Kernel->ZeKernel, GlobalWorkOffset[0], GlobalWorkOffset[1],
3781+
GlobalWorkOffset[2]));
37563782
}
37573783

37583784
ze_group_count_t ZeThreadGroupDimensions{1, 1, 1};

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ struct _pi_platform {
7979
std::string ZeDriverVersion;
8080
std::string ZeDriverApiVersion;
8181

82+
// Cache driver extensions
83+
std::unordered_map<std::string, uint32_t> zeDriverExtensionMap;
84+
8285
// Cache pi_devices for reuse
8386
std::vector<std::unique_ptr<_pi_device>> PiDevicesCache;
8487
std::mutex PiDevicesCacheMutex;

0 commit comments

Comments
 (0)