Skip to content

Commit 48ed377

Browse files
committed
[SYCL][CUDA] Select only NVPTX64 device binaries
Search through the available binary images and select the first one for the PI_DEVICE_BINARY_TARGET_NVPTX64 ("nvptx64") target. Return PI_INVALID_BINARY if no "nvptx64" image is available. Signed-off-by: Andrea Bocci <[email protected]>
1 parent 2b7d50a commit 48ed377

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,10 @@ pi_result cuda_piDevicePartition(
673673
return {};
674674
}
675675

676-
pi_result cuda_piextDeviceSelectBinary(
677-
pi_device device, // TODO: does this need to be context?
678-
pi_device_binary *binaries, pi_uint32 num_binaries,
679-
pi_device_binary *selected_binary) {
676+
pi_result cuda_piextDeviceSelectBinary(pi_device device,
677+
pi_device_binary *binaries,
678+
pi_uint32 num_binaries,
679+
pi_device_binary *selected_binary) {
680680
if (!binaries) {
681681
cl::sycl::detail::pi::die("No list of device images provided");
682682
}
@@ -686,8 +686,19 @@ pi_result cuda_piextDeviceSelectBinary(
686686
if (!selected_binary) {
687687
cl::sycl::detail::pi::die("No storage for device binary provided");
688688
}
689-
*selected_binary = binaries[0];
690-
return PI_SUCCESS;
689+
690+
// Look for an image for the NVPTX64 target, and return the first one that is
691+
// found
692+
for (pi_uint32 i = 0; i < num_binaries; i++) {
693+
if (strcmp(binaries[i]->DeviceTargetSpec,
694+
PI_DEVICE_BINARY_TARGET_NVPTX64) == 0) {
695+
*selected_binary = binaries[i];
696+
return PI_SUCCESS;
697+
}
698+
}
699+
700+
// No image can be loaded for the given device
701+
return PI_INVALID_BINARY;
691702
}
692703

693704
pi_result cuda_piextGetDeviceFunctionPointer(pi_device device,

0 commit comments

Comments
 (0)