Skip to content

Commit 167a4fa

Browse files
[SYCL] Add fallback support for KernelCompiler loading of ocloc (#18245)
Presently, the KernelCompiler just tries to load whatever ocloc shared library is in the environment. And if it doesn't find a compatible one, then it reports that OpenCL C compilation is not supported. But on Windows this should be more robust, so we are adding fallback support. If the ocloc shared library in the environment isn't compatible, try the one in the OneAPI installation. Signed-off-by: Chris Perkins <[email protected]>
1 parent 08c1785 commit 167a4fa

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

sycl/source/detail/kernel_compiler/kernel_compiler_opencl.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,40 @@ static std::unique_ptr<void, std::function<void(void *)>>
7070

7171
void loadOclocLibrary(const std::vector<uint32_t> &IPVersionVec) {
7272
#ifdef __SYCL_RT_OS_WINDOWS
73-
static const std::string OclocPath = "ocloc64.dll";
73+
// first the environment, if not compatible will move on to absolute path.
74+
static const std::vector<std::string> OclocPaths = {
75+
"ocloc64.dll",
76+
"C:\\Program Files (x86)\\Intel\\oneAPI\\ocloc\\latest\\ocloc64.dll"};
7477
#else
75-
static const std::string OclocPath = "libocloc.so";
78+
static const std::vector<std::string> OclocPaths = {"libocloc.so"};
7679
#endif
7780

78-
// set OclocLibrary value by side effect.
79-
try {
80-
// Load then perform checks. Each check throws.
81-
void *tempPtr = sycl::detail::ur::loadOsLibrary(OclocPath);
82-
OclocLibrary.reset(tempPtr);
81+
// attemptLoad() sets OclocLibrary value by side effect.
82+
auto attemptLoad = [&](std::string OclocPath) {
83+
try {
84+
// Load then perform checks. Each check throws.
85+
void *tempPtr = sycl::detail::ur::loadOsLibrary(OclocPath);
86+
OclocLibrary.reset(tempPtr);
8387

84-
if (tempPtr == nullptr)
85-
throw sycl::exception(make_error_code(errc::build),
86-
"Unable to load ocloc from " + OclocPath);
88+
if (tempPtr == nullptr)
89+
throw sycl::exception(make_error_code(errc::build),
90+
"Unable to load ocloc from " + OclocPath);
8791

88-
checkOclocLibrary(tempPtr);
92+
checkOclocLibrary(tempPtr);
8993

90-
InvokeOclocQuery(IPVersionVec, "CL_DEVICE_OPENCL_C_ALL_VERSIONS");
91-
} catch (const sycl::exception &) {
92-
OclocLibrary.reset(nullptr);
93-
std::rethrow_exception(std::current_exception());
94+
InvokeOclocQuery(IPVersionVec, "CL_DEVICE_OPENCL_C_ALL_VERSIONS");
95+
} catch (const sycl::exception &) {
96+
OclocLibrary.reset(nullptr);
97+
return false;
98+
}
99+
return true;
100+
};
101+
for (auto result : OclocPaths) {
102+
if (attemptLoad(result))
103+
return; // exit on successful attempt
94104
}
105+
// If we haven't exited yet, then throw to indicate failure.
106+
throw sycl::exception(make_error_code(errc::build), "Unable to load ocloc");
95107
}
96108

97109
bool OpenCLC_Compilation_Available(const std::vector<uint32_t> &IPVersionVec) {

0 commit comments

Comments
 (0)