-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] fix for __sycl_unregister_lib() on Windows and tests #19633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sycl
Are you sure you want to change the base?
Changes from all commits
c480714
8c1905e
8688a67
6742db0
154eaf0
44bef0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// UNSUPPORTED: hip | ||
// UNSUPPORTED-TRACKER: CMPLRLLVM-69478 | ||
|
||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <sycl/detail/core.hpp> | ||
|
||
#if defined(_WIN32) | ||
#define API_EXPORT __declspec(dllexport) | ||
#else | ||
#define API_EXPORT | ||
#endif | ||
|
||
#ifndef INC | ||
#define INC 1 | ||
#endif | ||
|
||
#ifndef CLASSNAME | ||
#define CLASSNAME same | ||
#endif | ||
|
||
extern "C" API_EXPORT void performIncrementation(sycl::queue &q, | ||
sycl::buffer<int, 1> &buf) { | ||
sycl::range<1> r = buf.get_range(); | ||
q.submit([&](sycl::handler &cgh) { | ||
auto acc = buf.get_access<sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<class CLASSNAME>( | ||
r, [=](sycl::id<1> idx) { acc[idx] += INC; }); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,142 @@ | ||||||
// UNSUPPORTED: cuda || hip | ||||||
// UNSUPPORTED-TRACKER: CMPLRLLVM-69415 | ||||||
|
||||||
// REQUIRES: level_zero | ||||||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove "REQUIRES: level_zero"? It looks like test is supposed to work on OpenCL backend as well. |
||||||
|
||||||
// DEFINE: %{fPIC_flag} = %if windows %{%} %else %{-fPIC%} | ||||||
// DEFINE: %{shared_lib_ext} = %if windows %{dll%} %else %{so%} | ||||||
|
||||||
// clang-format off | ||||||
// IMPORTANT -DSO_PATH='R"(%T)"' WTF ?? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// We need to capture %T, the build directory, in a string | ||||||
// and the normal STRINGIFY() macros hack won't work. | ||||||
// Because on Windows, the path delimiters are \, | ||||||
// which C++ preprocessor converts to escape sequences, | ||||||
// which becomes a nightmare. | ||||||
// SO the hack here is to put heredoc in the definition | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// and use single quotes, which Python forgivingly accepts. | ||||||
// clang-format on | ||||||
|
||||||
// RUN: %{build} %{fPIC_flag} -DSO_PATH='R"(%T)"' -o %t.out | ||||||
|
||||||
// RUN: %clangxx -fsycl %{fPIC_flag} -shared -DINC=1 -o %T/lib_a.%{shared_lib_ext} %S/Inputs/incrementing_lib.cpp | ||||||
// RUN: %clangxx -fsycl %{fPIC_flag} -shared -DINC=2 -o %T/lib_b.%{shared_lib_ext} %S/Inputs/incrementing_lib.cpp | ||||||
// RUN: %clangxx -fsycl %{fPIC_flag} -shared -DINC=4 -o %T/lib_c.%{shared_lib_ext} %S/Inputs/incrementing_lib.cpp | ||||||
|
||||||
// RUN: env UR_L0_LEAKS_DEBUG=1 %{run} %t.out | ||||||
|
||||||
// This test uses a kernel of the same name in three different shared libraries. | ||||||
// It loads each library, calls the kernel, and checks that the incrementation | ||||||
// is done correctly, and then unloads the library. | ||||||
// This test ensures that __sycl_register_lib() and __sycl_unregister_lib() | ||||||
// are called correctly, and that the device images are cleaned up properly. | ||||||
|
||||||
#include <sycl/detail/core.hpp> | ||||||
|
||||||
using namespace sycl::ext::oneapi::experimental; | ||||||
|
||||||
|
||||||
#ifdef _WIN32 | ||||||
#include <windows.h> | ||||||
|
||||||
void *loadOsLibrary(const std::string &LibraryPath) { | ||||||
HMODULE h = | ||||||
LoadLibraryExA(LibraryPath.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||||||
return (void *)h; | ||||||
} | ||||||
int unloadOsLibrary(void *Library) { | ||||||
return FreeLibrary((HMODULE)Library) ? 0 : 1; | ||||||
} | ||||||
void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) { | ||||||
return (void *)GetProcAddress((HMODULE)Library, FunctionName.c_str()); | ||||||
} | ||||||
|
||||||
#else | ||||||
#include <dlfcn.h> | ||||||
|
||||||
void *loadOsLibrary(const std::string &LibraryPath) { | ||||||
void *so = dlopen(LibraryPath.c_str(), RTLD_NOW); | ||||||
if (!so) { | ||||||
char *Error = dlerror(); | ||||||
std::cerr << "dlopen(" << LibraryPath << ") failed with <" | ||||||
<< (Error ? Error : "unknown error") << ">" << std::endl; | ||||||
} | ||||||
return so; | ||||||
} | ||||||
|
||||||
int unloadOsLibrary(void *Library) { return dlclose(Library); } | ||||||
|
||||||
void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) { | ||||||
return dlsym(Library, FunctionName.c_str()); | ||||||
} | ||||||
#endif | ||||||
|
||||||
// Define the function pointer type for performIncrementation | ||||||
using IncFuncT = void(sycl::queue &, sycl::buffer<int, 1> &); | ||||||
|
||||||
void initializeBuffer(sycl::buffer<int, 1> &buf) { | ||||||
auto acc = sycl::host_accessor<int, 1>(buf); | ||||||
for (size_t i = 0; i < buf.size(); ++i) | ||||||
acc[i] = 0; | ||||||
} | ||||||
|
||||||
void checkIncrementation(sycl::buffer<int, 1> &buf, int val) { | ||||||
auto acc = sycl::host_accessor<int, 1>(buf); | ||||||
for (size_t i = 0; i < buf.size(); ++i) { | ||||||
std::cout << acc[i] << " "; | ||||||
assert(acc[i] == val); | ||||||
} | ||||||
std::cout << std::endl; | ||||||
} | ||||||
|
||||||
int main() { | ||||||
sycl::queue q; | ||||||
|
||||||
sycl::range<1> r(8); | ||||||
sycl::buffer<int, 1> buf(r); | ||||||
initializeBuffer(buf); | ||||||
|
||||||
std::string base_path = SO_PATH; | ||||||
|
||||||
#ifdef _WIN32 | ||||||
std::string path_to_lib_a = base_path + "\\lib_a.dll"; | ||||||
std::string path_to_lib_b = base_path + "\\lib_b.dll"; | ||||||
std::string path_to_lib_c = base_path + "\\lib_c.dll"; | ||||||
#else | ||||||
std::string path_to_lib_a = base_path + "/lib_a.so"; | ||||||
std::string path_to_lib_b = base_path + "/lib_b.so"; | ||||||
std::string path_to_lib_c = base_path + "/lib_c.so"; | ||||||
#endif | ||||||
|
||||||
std::cout << "paths: " << path_to_lib_a << std::endl; | ||||||
std::cout << "SO_PATH: " << SO_PATH << std::endl; | ||||||
|
||||||
void *lib_a = loadOsLibrary(path_to_lib_a); | ||||||
void *f = getOsLibraryFuncAddress(lib_a, "performIncrementation"); | ||||||
auto performIncrementationFuncA = reinterpret_cast<IncFuncT *>(f); | ||||||
performIncrementationFuncA(q, buf); // call the function from lib_a | ||||||
q.wait(); | ||||||
checkIncrementation(buf, 1); | ||||||
unloadOsLibrary(lib_a); | ||||||
std::cout << "lib_a done" << std::endl; | ||||||
|
||||||
void *lib_b = loadOsLibrary(path_to_lib_b); | ||||||
f = getOsLibraryFuncAddress(lib_b, "performIncrementation"); | ||||||
auto performIncrementationFuncB = reinterpret_cast<IncFuncT *>(f); | ||||||
performIncrementationFuncB(q, buf); // call the function from lib_b | ||||||
q.wait(); | ||||||
checkIncrementation(buf, 1 + 2); | ||||||
unloadOsLibrary(lib_b); | ||||||
std::cout << "lib_b done" << std::endl; | ||||||
|
||||||
void *lib_c = loadOsLibrary(path_to_lib_c); | ||||||
f = getOsLibraryFuncAddress(lib_c, "performIncrementation"); | ||||||
auto performIncrementationFuncC = reinterpret_cast<IncFuncT *>(f); | ||||||
q.wait(); | ||||||
performIncrementationFuncC(q, buf); // call the function from lib_c | ||||||
checkIncrementation(buf, 1 + 2 + 4); | ||||||
unloadOsLibrary(lib_c); | ||||||
std::cout << "lib_c done" << std::endl; | ||||||
|
||||||
return 0; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,16 +303,6 @@ void checkAllInvolvedContainers(ProgramManagerExposed &PM, size_t ExpectedCount, | |
} | ||
EXPECT_EQ(PM.getKernelImplicitLocalArgPos().size(), ExpectedCount) << Comment; | ||
|
||
{ | ||
sycl::detail::DeviceGlobalMap &DeviceGlobalMap = PM.getDeviceGlobals(); | ||
EXPECT_EQ(DeviceGlobalMap.size(), ExpectedCount) << Comment; | ||
EXPECT_TRUE(DeviceGlobalMap.count(generateRefName("A", "DeviceGlobal")) > 0) | ||
<< Comment; | ||
EXPECT_TRUE(DeviceGlobalMap.count(generateRefName("B", "DeviceGlobal")) > 0) | ||
<< Comment; | ||
EXPECT_EQ(DeviceGlobalMap.getPointerMap().size(), ExpectedCount) << Comment; | ||
} | ||
|
||
Comment on lines
-306
to
-315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to add a test for new behavior to compensate the removed test? |
||
{ | ||
EXPECT_EQ(PM.getHostPipes().size(), ExpectedCount) << Comment; | ||
EXPECT_TRUE(PM.getHostPipes().count(generateRefName("A", "HostPipe")) > 0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.