Skip to content

Commit 098416a

Browse files
authored
[SYCL] Fix image selection for AOT on intel_cpu_{spr, gnr} (#15208)
When AOT compiling for cpu, the generic `spir64_x86_64` target is used with `-fsycl-targets`. #14909, functionality was added to select device images based on their `compile_target` property in the image. The selection mechanism had to consider CPU as a special case due to not having explicit targets. However, the mechanism only considered `x86_64` and not `intel_cpu_spr` or `intel_cpu_gnr`; therefore on a `intel_cpu_spr` or `intel_cpu_gnr` device, trying to launch a program compiled with `-fsycl-targets=spir64_x86_64`, device image selection would fail to find an image (and thus fail to launch any kernels). This PR updates the logic to include `intel_cpu_spr` and `intel_cpu_gnr`. Note: for tests, this functionality is checked by any test that AOT compiled for CPU and launches a kernel (includes [AOT/cpu.cpp](https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/AOT/cpu.cpp), [AOT/double.cpp](https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/AOT/double.cpp), [AOT/half.cpp](https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/AOT/half.cpp)).
1 parent 811db84 commit 098416a

File tree

2 files changed

+62
-28
lines changed

2 files changed

+62
-28
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,15 @@ RTDeviceBinaryImage *getBinImageFromMultiMap(
13211321
reinterpret_cast<const char *>(&CompileTargetByteArray[0]),
13221322
CompileTargetByteArray.size());
13231323
// Note: there are no explicit targets for CPUs, so on x86_64,
1324-
// so we use a spir64_x86_64 compile target image.
1324+
// intel_cpu_spr, and intel_cpu_gnr, we use a spir64_x86_64
1325+
// compile target image.
1326+
// TODO: When dedicated targets for CPU are added, (i.e.
1327+
// -fsycl-targets=intel_cpu_spr etc.) remove this special
1328+
// handling of CPU targets.
13251329
if ((ArchName == CompileTarget) ||
1326-
(ArchName == "x86_64" && CompileTarget == "spir64_x86_64")) {
1330+
(CompileTarget == "spir64_x86_64" &&
1331+
(ArchName == "x86_64" || ArchName == "intel_cpu_spr" ||
1332+
ArchName == "intel_cpu_gnr"))) {
13271333
AddImg();
13281334
}
13291335
}

sycl/unittests/program_manager/CompileTarget.cpp

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,25 @@ static sycl::unittest::UrImage Img[] = {
9797

9898
static sycl::unittest::UrImageArray<std::size(Img)> ImgArray{Img};
9999

100-
ur_device_handle_t MockSklDeviceHandle =
101-
reinterpret_cast<ur_device_handle_t>(1);
102-
ur_device_handle_t MockPvcDeviceHandle =
103-
reinterpret_cast<ur_device_handle_t>(2);
104-
ur_device_handle_t MockX86DeviceHandle =
105-
reinterpret_cast<ur_device_handle_t>(3);
106-
constexpr int SklIp = 0x02400009;
107-
constexpr int PvcIp = 0x030f0000;
108-
constexpr int X86Ip = 0;
109-
110-
ur_device_handle_t MockDevices[] = {
111-
MockSklDeviceHandle,
112-
MockPvcDeviceHandle,
113-
MockX86DeviceHandle,
100+
struct MockDeviceData {
101+
int Ip;
102+
ur_device_type_t DeviceType;
103+
ur_device_handle_t getHandle() {
104+
return reinterpret_cast<ur_device_handle_t>(this);
105+
}
106+
static MockDeviceData *fromHandle(ur_device_handle_t handle) {
107+
return reinterpret_cast<MockDeviceData *>(handle);
108+
}
109+
};
110+
111+
// IP are from IntelGPUArchitectures/IntelCPUArchitectures in
112+
// sycl/source/detail/device_info.hpp
113+
MockDeviceData MockDevices[] = {
114+
{0x02400009, UR_DEVICE_TYPE_GPU}, // Skl
115+
{0x030f0000, UR_DEVICE_TYPE_GPU}, // Pvc
116+
{0, UR_DEVICE_TYPE_CPU}, // X86
117+
{8, UR_DEVICE_TYPE_CPU}, // Spr
118+
{9, UR_DEVICE_TYPE_CPU}, // Gnr
114119
};
115120

116121
static ur_result_t redefinedDeviceGet(void *pParams) {
@@ -123,7 +128,7 @@ static ur_result_t redefinedDeviceGet(void *pParams) {
123128
if (*params.pphDevices) {
124129
assert(*params.pNumEntries <= std::size(MockDevices));
125130
for (uint32_t i = 0; i < *params.pNumEntries; ++i) {
126-
(*params.pphDevices)[i] = MockDevices[i];
131+
(*params.pphDevices)[i] = MockDevices[i].getHandle();
127132
}
128133
}
129134

@@ -149,27 +154,22 @@ static ur_result_t redefinedDeviceGetInfo(void *pParams) {
149154
auto params = *static_cast<ur_device_get_info_params_t *>(pParams);
150155
if (*params.ppropName == UR_DEVICE_INFO_IP_VERSION && *params.ppPropValue) {
151156
int &ret = *static_cast<int *>(*params.ppPropValue);
152-
if (*params.phDevice == MockSklDeviceHandle)
153-
ret = SklIp;
154-
if (*params.phDevice == MockPvcDeviceHandle)
155-
ret = PvcIp;
156-
if (*params.phDevice == MockX86DeviceHandle)
157-
ret = X86Ip;
157+
ret = MockDeviceData::fromHandle(*params.phDevice)->Ip;
158158
}
159-
if (*params.ppropName == UR_DEVICE_INFO_TYPE &&
160-
*params.phDevice == MockX86DeviceHandle) {
159+
if (*params.ppropName == UR_DEVICE_INFO_TYPE) {
161160
if (*params.ppPropValue)
162161
*static_cast<ur_device_type_t *>(*params.ppPropValue) =
163-
UR_DEVICE_TYPE_CPU;
162+
MockDeviceData::fromHandle(*params.phDevice)->DeviceType;
164163
if (*params.ppPropSizeRet)
165-
**params.ppPropSizeRet = sizeof(UR_DEVICE_TYPE_CPU);
164+
**params.ppPropSizeRet = sizeof(ur_device_type_t);
166165
}
167166
return UR_RESULT_SUCCESS;
168167
}
169168

170169
static ur_result_t redefinedDeviceSelectBinary(void *pParams) {
171170
auto params = *static_cast<ur_device_select_binary_params_t *>(pParams);
172-
auto target = *params.phDevice == MockX86DeviceHandle
171+
auto target = MockDeviceData::fromHandle(*params.phDevice)->DeviceType ==
172+
UR_DEVICE_TYPE_CPU
173173
? UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64
174174
: UR_DEVICE_BINARY_TARGET_SPIRV64_GEN;
175175
uint32_t fallback = *params.pNumBinaries;
@@ -246,6 +246,16 @@ TEST_F(CompileTargetTest, SingleTask) {
246246
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
247247
launchSingleTaskKernel(queue{archSelector(syclex::architecture::x86_64)});
248248
});
249+
250+
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
251+
launchSingleTaskKernel(
252+
queue{archSelector(syclex::architecture::intel_cpu_spr)});
253+
});
254+
255+
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
256+
launchSingleTaskKernel(
257+
queue{archSelector(syclex::architecture::intel_cpu_gnr)});
258+
});
249259
}
250260

251261
void launchNDRangeKernel(queue q) {
@@ -268,6 +278,16 @@ TEST_F(CompileTargetTest, NDRangeKernel) {
268278
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
269279
launchNDRangeKernel(queue{archSelector(syclex::architecture::x86_64)});
270280
});
281+
282+
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
283+
launchNDRangeKernel(
284+
queue{archSelector(syclex::architecture::intel_cpu_spr)});
285+
});
286+
287+
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
288+
launchNDRangeKernel(
289+
queue{archSelector(syclex::architecture::intel_cpu_gnr)});
290+
});
271291
}
272292

273293
void launchRangeKernel(queue q) {
@@ -288,6 +308,14 @@ TEST_F(CompileTargetTest, RangeKernel) {
288308
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
289309
launchRangeKernel(queue{archSelector(syclex::architecture::x86_64)});
290310
});
311+
312+
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
313+
launchRangeKernel(queue{archSelector(syclex::architecture::intel_cpu_spr)});
314+
});
315+
316+
checkUsedImageWithCompileTarget("spir64_x86_64", [&]() {
317+
launchRangeKernel(queue{archSelector(syclex::architecture::intel_cpu_gnr)});
318+
});
291319
}
292320

293321
TEST_F(CompileTargetTest, NoDeviceKernel) {

0 commit comments

Comments
 (0)