Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions sycl/test-e2e/DeviceImageDependencies/dynamic_link_opt_win.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Test that device image dependencies from a DLL are not dropped when the
// application is built at higher optimization levels on Windows.
//
// The bug: at /O2 the linker sees that no host symbol from the DLL is
// referenced and drops the DLL import, which prevents the SYCL runtime
// from discovering the device image in the DLL.

// REQUIRES: windows

// Build the DLL using the existing input:
// RUN: %clangxx -fsycl -fsycl-allow-device-image-dependencies -DMAKE_DLL -O2 %shared_lib %S/Inputs/d.cpp -o %t_d.dll

// Build app at -O0 — should work:
// RUN: %clangxx -fsycl -fsycl-allow-device-image-dependencies %O0 %s %t_d.lib -o %t_O0.exe
// RUN: %{run} %t_O0.exe

// Build app at -O2 — fails due to the bug (DLL import dropped):
// RUN: %clangxx -fsycl -fsycl-allow-device-image-dependencies -O2 %s %t_d.lib -o %t_O2.exe
// RUN: %{run} %t_O2.exe

// XFAIL: windows && run-mode
// XFAIL-TRACKER: CMPLRLLVM-76054

#include <cassert>
#include <sycl/sycl.hpp>

// No __declspec(dllimport) — only a device-side dependency on the DLL.
SYCL_EXTERNAL int levelD(int val);

int main() {
int result = 0;
{
sycl::queue q;
int *d = sycl::malloc_device<int>(1, q);
q.single_task([=] { *d = levelD(0); }).wait();
q.memcpy(&result, d, sizeof(int)).wait();
sycl::free(d, q);
}
// Device path of levelD: val |= (0xD << 12) => 0xD000
assert(result == 0xD000);
return 0;
}
Loading