-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect support for dynamic linking to user options (#14575)
Add option "-fsycl-allow-device-dependencies" to enable support for dynamic linking. Also: 1. No functions are importable without "-fsycl-allow-device-dependencies" 2. Deal with SYCL_EXTERNAL header decls that have lost SYCL_EXTERNAL attribute in LLVM IR 3. SPIRV/SYCL/ESIMD builtins cannot be an imported function Tested in three E2E test cases. Minor change: Change SYCL-EXTERNAL to SYCL_EXTERNAL in testcase comment. --------- Signed-off-by: Lu, John <john.lu@intel.com> Co-authored-by: Marcos Maronas <marcos.maronas@intel.com>
- Loading branch information
1 parent
13ef711
commit 3c0532d
Showing
19 changed files
with
243 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include "a.hpp" | ||
#include "b.hpp" | ||
|
||
SYCL_EXTERNAL int levelA(int val) { | ||
#ifndef __SYCL_DEVICE_ONLY__ | ||
std::cerr << "Host symbol used" << std::endl; | ||
return 0; | ||
#endif | ||
val=levelB(val); | ||
return val|=(0xA<<0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <sycl/detail/core.hpp> | ||
|
||
SYCL_EXTERNAL int levelA(int val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include "b.hpp" | ||
#include "c.hpp" | ||
|
||
SYCL_EXTERNAL int levelB(int val) { | ||
#ifndef __SYCL_DEVICE_ONLY__ | ||
std::cerr << "Host symbol used" << std::endl; | ||
return 0; | ||
#endif | ||
val=levelC(val); | ||
return val|=(0xB<<4); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <sycl/detail/core.hpp> | ||
|
||
SYCL_EXTERNAL int levelB(int val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <iostream> | ||
#include "c.hpp" | ||
#include "d.hpp" | ||
|
||
SYCL_EXTERNAL int levelC(int val) { | ||
#ifndef __SYCL_DEVICE_ONLY__ | ||
std::cerr << "Host symbol used" << std::endl; | ||
return 0; | ||
#endif | ||
val=levelD(val); | ||
return val|=(0xC<<8); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <sycl/detail/core.hpp> | ||
|
||
SYCL_EXTERNAL int levelC(int val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
#include "d.hpp" | ||
|
||
SYCL_EXTERNAL int levelD(int val) { | ||
#ifndef __SYCL_DEVICE_ONLY__ | ||
std::cerr << "Host symbol used" << std::endl; | ||
return 0; | ||
#endif | ||
return val|=(0xD<<12); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <sycl/detail/core.hpp> | ||
|
||
SYCL_EXTERNAL int levelD(int val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <sycl/detail/core.hpp> | ||
#include "a.hpp" | ||
#include <iostream> | ||
#define EXPORT | ||
#include "wrapper.hpp" | ||
|
||
using namespace sycl; | ||
|
||
class ExeKernel; | ||
|
||
int wrapper() { | ||
int val = 0; | ||
{ | ||
buffer<int, 1> buf(&val, range<1>(1)); | ||
queue q; | ||
q.submit([&](handler &cgh) { | ||
auto acc = buf.get_access(cgh); | ||
cgh.single_task<ExeKernel>([=]() {acc[0] = levelA(acc[0]);}); | ||
}); | ||
} | ||
|
||
std::cout << "val=" << std::hex << val << "\n"; | ||
if (val!=0xDCBA) | ||
return (1); | ||
return(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#if defined(_WIN32) | ||
#ifdef EXPORT | ||
__declspec(dllexport) | ||
#else | ||
__declspec(dllimport) | ||
#endif | ||
#endif | ||
int wrapper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Test -fsycl-allow-device-dependencies with dynamic libraries. | ||
|
||
// REQUIRES: linux | ||
// UNSUPPORTED: cuda || hip | ||
|
||
// RUN: %clangxx -fsycl -fPIC -shared -fsycl-allow-device-dependencies %S/Inputs/a.cpp -I %S/Inputs -o %T/libdevice_a.so | ||
// RUN: %clangxx -fsycl -fPIC -shared -fsycl-allow-device-dependencies %S/Inputs/b.cpp -I %S/Inputs -o %T/libdevice_b.so | ||
// RUN: %clangxx -fsycl -fPIC -shared -fsycl-allow-device-dependencies %S/Inputs/c.cpp -I %S/Inputs -o %T/libdevice_c.so | ||
// RUN: %clangxx -fsycl -fPIC -shared -fsycl-allow-device-dependencies %S/Inputs/d.cpp -I %S/Inputs -o %T/libdevice_d.so | ||
// RUN: %{build} -fsycl-allow-device-dependencies -L%T -ldevice_a -ldevice_b -ldevice_c -ldevice_d -I %S/Inputs -o %t.out -Wl,-rpath=%T | ||
// RUN: %{run} %t.out | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include "a.hpp" | ||
#include <iostream> | ||
|
||
using namespace sycl; | ||
|
||
class ExeKernel; | ||
|
||
int main() { | ||
int val = 0; | ||
{ | ||
buffer<int, 1> buf(&val, range<1>(1)); | ||
queue q; | ||
q.submit([&](handler &cgh) { | ||
auto acc = buf.get_access(cgh); | ||
cgh.single_task<ExeKernel>([=]() {acc[0] = levelA(acc[0]);}); | ||
}); | ||
} | ||
|
||
std::cout << "val=" << std::hex << val << "\n"; | ||
if (val!=0xDCBA) | ||
return (1); | ||
return(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Test -fsycl-allow-device-dependencies with objects. | ||
|
||
// UNSUPPORTED: cuda || hip | ||
|
||
// RUN: %clangxx -fsycl %S/Inputs/a.cpp -I %S/Inputs -c -o %t_a.o | ||
// RUN: %clangxx -fsycl %S/Inputs/b.cpp -I %S/Inputs -c -o %t_b.o | ||
// RUN: %clangxx -fsycl %S/Inputs/c.cpp -I %S/Inputs -c -o %t_c.o | ||
// RUN: %clangxx -fsycl %S/Inputs/d.cpp -I %S/Inputs -c -o %t_d.o | ||
// RUN: %{build} -fsycl-allow-device-dependencies %t_a.o %t_b.o %t_c.o %t_d.o -I %S/Inputs -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include "a.hpp" | ||
#include <iostream> | ||
|
||
using namespace sycl; | ||
|
||
class ExeKernel; | ||
|
||
int main() { | ||
int val = 0; | ||
{ | ||
buffer<int, 1> buf(&val, range<1>(1)); | ||
queue q; | ||
q.submit([&](handler &cgh) { | ||
auto acc = buf.get_access(cgh); | ||
cgh.single_task<ExeKernel>([=]() {acc[0] = levelA(acc[0]);}); | ||
}); | ||
} | ||
|
||
std::cout << "val=" << std::hex << val << "\n"; | ||
if (val!=0xDCBA) | ||
return (1); | ||
return(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Test -fsycl-allow-device-dependencies with a single dynamic library on Windows | ||
// and Linux. | ||
|
||
// UNSUPPORTED: cuda || hip | ||
|
||
// RUN: %clangxx -fsycl %fPIC %shared_lib -fsycl-allow-device-dependencies -I %S/Inputs \ | ||
// RUN: %S/Inputs/a.cpp \ | ||
// RUN: %S/Inputs/b.cpp \ | ||
// RUN: %S/Inputs/c.cpp \ | ||
// RUN: %S/Inputs/d.cpp \ | ||
// RUN: %S/Inputs/wrapper.cpp \ | ||
// RUN: -o %if windows %{%T/device_single.dll%} %else %{%T/libdevice_single.so%} | ||
|
||
// RUN: %{build} -I%S/Inputs -o %t.out \ | ||
// RUN: %if windows \ | ||
// RUN: %{%T/device_single.lib%} \ | ||
// RUN: %else \ | ||
// RUN: %{-L%T -ldevice_single -Wl,-rpath=%T%} | ||
|
||
// RUN: %{run} %t.out | ||
|
||
#include "wrapper.hpp" | ||
|
||
int main() { | ||
return(wrapper()); | ||
} |