Skip to content

Commit 9ce2e8d

Browse files
committed
[SYCL][PI] get backend type from Plugin, not env
useBackend queried for "SYCL_BE" env. scheduler wrongly relied on this. Instead it should get the backend type from the used plugin Signed-off-by: hiaselhans <[email protected]>
1 parent 5d0d034 commit 9ce2e8d

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

sycl/include/CL/sycl/detail/pi.h

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ using pi_uint64 = uint64_t;
6060
using pi_bool = pi_uint32;
6161
using pi_bitfield = pi_uint64;
6262

63+
// For selection of SYCL RT back-end, now manually through the "SYCL_BE"
64+
// environment variable.
65+
enum Backend { SYCL_BE_PI_OPENCL, SYCL_BE_PI_CUDA, SYCL_BE_PI_OTHER };
66+
6367
//
6468
// NOTE: prefer to map 1:1 to OpenCL so that no translation is needed
6569
// for PI <-> OpenCL ways. The PI <-> to other BE translation is almost
@@ -1346,6 +1350,8 @@ struct _pi_plugin {
13461350
const char PiVersion[4] = _PI_H_VERSION_STRING;
13471351
// Plugin edits this.
13481352
char PluginVersion[4] = _PI_H_VERSION_STRING;
1353+
// Plugin type
1354+
Backend backend;
13491355
char *Targets;
13501356
struct FunctionPointers {
13511357
#define _PI_API(api) decltype(::api) *api;

sycl/include/CL/sycl/detail/pi.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ void *loadOsLibrary(const std::string &Library);
103103
// library, implementation is OS dependent.
104104
void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName);
105105

106-
// For selection of SYCL RT back-end, now manually through the "SYCL_BE"
107-
// environment variable.
108-
enum Backend { SYCL_BE_PI_OPENCL, SYCL_BE_PI_CUDA, SYCL_BE_PI_OTHER };
109-
110106
// Check for manually selected BE at run-time.
111107
bool useBackend(Backend Backend);
112108

sycl/plugins/cuda/pi_cuda.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3564,6 +3564,9 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
35643564
// PI interface supports higher version or the same version.
35653565
strncpy(PluginInit->PluginVersion, SupportedVersion, 4);
35663566

3567+
// Set plugin Type
3568+
PluginInit->backend = SYCL_BE_PI_CUDA;
3569+
35673570
// Set whole function table to zero to make it easier to detect if
35683571
// functions are not set up below.
35693572
std::memset(&(PluginInit->PiFunctionTable), 0,

sycl/plugins/opencl/pi_opencl.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
10541054
// PI interface supports higher version or the same version.
10551055
strncpy(PluginInit->PluginVersion, SupportedVersion, 4);
10561056

1057+
// Set plugin Type
1058+
PluginInit->backend = SYCL_BE_PI_OPENCL;
1059+
10571060
#define _PI_CL(pi_api, ocl_api) \
10581061
(PluginInit->PiFunctionTable).pi_api = (decltype(&::pi_api))(&ocl_api);
10591062

sycl/source/detail/plugin.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class plugin {
3131

3232
const RT::PiPlugin &getPiPlugin() const { return MPlugin; }
3333

34+
bool isBackendType(Backend backend) const {
35+
return MPlugin.backend == backend;
36+
}
37+
3438
/// Checks return value from PI calls.
3539
///
3640
/// \throw Exception if pi_result is not a PI_SUCCESS.

sycl/source/detail/program_manager/program_manager.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,10 @@ static bool isDeviceBinaryTypeSupported(const context &C,
269269
return false;
270270
}
271271

272+
ContextImplPtr ContextImpl = getSyclObjImpl(C);
273+
272274
// OpenCL 2.1 and greater require clCreateProgramWithIL
273-
if (pi::useBackend(pi::SYCL_BE_PI_OPENCL) &&
275+
if (ContextImpl->getPlugin().isBackendType(Backend::SYCL_BE_PI_OPENCL) &&
274276
C.get_platform().get_info<info::platform::version>() >= "2.1")
275277
return true;
276278

sycl/source/detail/scheduler/commands.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ cl_int ExecCGCommand::enqueueImp() {
16611661
Requirement *Req = (Requirement *)(Arg.MPtr);
16621662
AllocaCommandBase *AllocaCmd = getAllocaForReq(Req);
16631663
RT::PiMem MemArg = (RT::PiMem)AllocaCmd->getMemAllocation();
1664-
if (RT::useBackend(pi::Backend::SYCL_BE_PI_OPENCL)) {
1664+
if (Plugin.isBackendType(Backend::SYCL_BE_PI_OPENCL)) {
16651665
Plugin.call<PiApiKind::piKernelSetArg>(Kernel, Arg.MIndex,
16661666
sizeof(RT::PiMem), &MemArg);
16671667
} else {

0 commit comments

Comments
 (0)