Skip to content

Commit 5cdcce7

Browse files
LU-JOHNAlexeySachkov
authored andcommitted
[SYCL] Allow device code to be exported by a Windows DLL (intel#14962)
Allow device code to be exported by a Windows DLL. --------- Signed-off-by: Lu, John <[email protected]>
1 parent b9801c7 commit 5cdcce7

File tree

13 files changed

+78
-45
lines changed

13 files changed

+78
-45
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12372,7 +12372,6 @@ def err_sycl_restrict : Error<
1237212372
"|call through a function pointer"
1237312373
"|allocate storage"
1237412374
"|use inline assembly"
12375-
"|call a dllimport function"
1237612375
"|call a variadic function"
1237712376
"|call an undefined function without SYCL_EXTERNAL attribute"
1237812377
"|use a const static or global variable that is neither zero-initialized "

clang/include/clang/Sema/SemaSYCL.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ class SemaSYCL : public SemaBase {
308308
KernelCallFunctionPointer,
309309
KernelAllocateStorage,
310310
KernelUseAssembly,
311-
KernelCallDllimportFunction,
312311
KernelCallVariadicFunction,
313312
KernelCallUndefinedFunction,
314313
KernelConstStaticVariable

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -598,18 +598,6 @@ class DiagDeviceFunction : public RecursiveASTVisitor<DiagDeviceFunction> {
598598
<< SemaSYCL::KernelCallRecursiveFunction;
599599
}
600600

601-
if (auto const *FD = dyn_cast<FunctionDecl>(Callee)) {
602-
// FIXME: We need check all target specified attributes for error if
603-
// that function with attribute can not be called from sycl kernel. The
604-
// info is in ParsedAttr. We don't have to map from Attr to ParsedAttr
605-
// currently. Erich is currently working on that in LLVM, once that is
606-
// committed we need to change this".
607-
if (FD->hasAttr<DLLImportAttr>()) {
608-
SemaSYCLRef.Diag(e->getExprLoc(), diag::err_sycl_restrict)
609-
<< SemaSYCL::KernelCallDllimportFunction;
610-
SemaSYCLRef.Diag(FD->getLocation(), diag::note_callee_decl) << FD;
611-
}
612-
}
613601
// Specifically check if the math library function corresponding to this
614602
// builtin is supported for SYCL
615603
unsigned BuiltinID = Callee->getBuiltinID();

clang/test/SemaSYCL/sycl-dllimport-dllexport.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ int zoo() __attribute__((dllimport));
3636

3737
#else
3838

39-
// emit error if dllimport function is called in sycl kernel
4039
int __declspec(dllexport) foo(int a) {
4140
return a;
4241
}
43-
// expected-note@+1 {{'bar' declared here}}
42+
4443
SYCL_EXTERNAL int __declspec(dllimport) bar();
4544
// expected-note@+1 {{previous declaration is here}}
46-
int __declspec(dllimport) foobar(); // expected-note {{'foobar' declared here}}
45+
int __declspec(dllimport) foobar();
4746
int foobar() // expected-warning {{'foobar' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
4847
{
4948
return 10;
@@ -59,8 +58,8 @@ int main() {
5958
bar(); // expected-no-error
6059
kernel_single_task<class fake_kernel>([]() {
6160
foo(10);// expected-no-error
62-
bar(); // expected-error {{SYCL kernel cannot call a dllimport function}}
63-
foobar(); // expected-error {{SYCL kernel cannot call a dllimport function}}
61+
bar();
62+
foobar();
6463
});
6564
bar(); // expected-no-error
6665
return 0;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include <iostream>
1+
#define A_EXPORT
22
#include "a.hpp"
33
#include "b.hpp"
4+
#include <iostream>
45

5-
SYCL_EXTERNAL int levelA(int val) {
6+
A_DECLSPEC SYCL_EXTERNAL int levelA(int val) {
67
#ifndef __SYCL_DEVICE_ONLY__
78
std::cerr << "Host symbol used" << std::endl;
8-
return 0;
9+
val ^= 0x1234;
910
#endif
1011
val=levelB(val);
1112
return val|=(0xA<<0);
1213
}
13-
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
#include <sycl/detail/core.hpp>
22

3-
SYCL_EXTERNAL int levelA(int val);
3+
#if defined(MAKE_DLL)
4+
#ifdef A_EXPORT
5+
#define A_DECLSPEC __declspec(dllexport)
6+
#else
7+
#define A_DECLSPEC __declspec(dllimport)
8+
#endif
9+
#else
10+
#define A_DECLSPEC
11+
#endif
12+
13+
A_DECLSPEC SYCL_EXTERNAL int levelA(int val);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include <iostream>
1+
#define B_EXPORT
22
#include "b.hpp"
33
#include "c.hpp"
4+
#include <iostream>
45

5-
SYCL_EXTERNAL int levelB(int val) {
6+
B_DECLSPEC SYCL_EXTERNAL int levelB(int val) {
67
#ifndef __SYCL_DEVICE_ONLY__
78
std::cerr << "Host symbol used" << std::endl;
8-
return 0;
9+
val ^= 0x2345;
910
#endif
1011
val=levelC(val);
1112
return val|=(0xB<<4);
1213
}
13-
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
#include <sycl/detail/core.hpp>
22

3-
SYCL_EXTERNAL int levelB(int val);
3+
#if defined(MAKE_DLL)
4+
#ifdef B_EXPORT
5+
#define B_DECLSPEC __declspec(dllexport)
6+
#else
7+
#define B_DECLSPEC __declspec(dllimport)
8+
#endif
9+
#else
10+
#define B_DECLSPEC
11+
#endif
12+
13+
B_DECLSPEC SYCL_EXTERNAL int levelB(int val);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include <iostream>
1+
#define C_EXPORT
22
#include "c.hpp"
33
#include "d.hpp"
4+
#include <iostream>
45

5-
SYCL_EXTERNAL int levelC(int val) {
6+
C_DECLSPEC SYCL_EXTERNAL int levelC(int val) {
67
#ifndef __SYCL_DEVICE_ONLY__
78
std::cerr << "Host symbol used" << std::endl;
8-
return 0;
9+
val ^= 0x3456;
910
#endif
1011
val=levelD(val);
1112
return val|=(0xC<<8);
1213
}
13-
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
#include <sycl/detail/core.hpp>
22

3-
SYCL_EXTERNAL int levelC(int val);
3+
#if defined(MAKE_DLL)
4+
#ifdef C_EXPORT
5+
#define C_DECLSPEC __declspec(dllexport)
6+
#else
7+
#define C_DECLSPEC __declspec(dllimport)
8+
#endif
9+
#else
10+
#define C_DECLSPEC
11+
#endif
12+
13+
C_DECLSPEC SYCL_EXTERNAL int levelC(int val);

0 commit comments

Comments
 (0)