-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Add support for SYCL_EXTERNAL #622
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
Merged
bader
merged 2 commits into
intel:sycl
from
sndmitriev:public/sndmitriev/sycl-external-macro
Sep 19, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
// RUN: %clang_cc1 -triple spir64-unknown-linux-sycldevice -std=c++11 -fsycl-is-device -disable-llvm-passes -S -emit-llvm -x c++ %s -o - | FileCheck %s | ||
// Test code generation for sycl_device attribute. | ||
|
||
int bar(int b); | ||
|
||
// CHECK-DAG: define spir_func i32 @_Z3fooii | ||
__attribute__((sycl_device)) | ||
int foo(int a, int b) { return a + bar(b); } | ||
|
||
// CHECK-DAG: define spir_func i32 @_Z3bari | ||
int bar(int b) { return b; } | ||
|
||
// CHECK-DAG: define spir_func i32 @_Z3fari | ||
int far(int b) { return b; } | ||
|
||
// CHECK-DAG: define spir_func i32 @_Z3booii | ||
__attribute__((sycl_device)) | ||
int boo(int a, int b) { return a + far(b); } | ||
|
||
// CHECK-DAG: define spir_func i32 @_Z3cari | ||
__attribute__((sycl_device)) | ||
int car(int b); | ||
int car(int b) { return b; } | ||
|
||
// CHECK-DAG: define spir_func i32 @_Z3cazi | ||
int caz(int b); | ||
__attribute__((sycl_device)) | ||
int caz(int b) { return b; } | ||
|
||
template<typename T> | ||
__attribute__((sycl_device)) | ||
void taf(T t) {} | ||
|
||
// CHECK-DAG: define weak_odr spir_func void @_Z3tafIiEvT_ | ||
template void taf<int>(int t); | ||
|
||
// CHECK-DAG: define spir_func void @_Z3tafIcEvT_ | ||
template<> void taf<char>(char t) {} | ||
|
||
template<typename T> | ||
void tar(T t) {} | ||
|
||
// CHECK-DAG: define spir_func void @_Z3tarIcEvT_ | ||
template<> | ||
__attribute__((sycl_device)) | ||
void tar<char>(char t) {} | ||
|
||
// CHECK-NOT: @_Z3tarIiEvT_ | ||
template void tar<int>(int t); | ||
|
||
// CHECK-NOT: @_Z3gooi | ||
int goo(int b) { return b; } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -verify -DNO_SYCL %s | ||
|
||
#ifndef NO_SYCL | ||
|
||
__attribute__((sycl_device)) // expected-warning {{'sycl_device' attribute only applies to functions}} | ||
int N; | ||
|
||
__attribute__((sycl_device(3))) // expected-error {{'sycl_device' attribute takes no arguments}} | ||
void bar() {} | ||
|
||
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a static function or function in an anonymous namespace}} | ||
static void func1() {} | ||
|
||
namespace { | ||
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a static function or function in an anonymous namespace}} | ||
void func2() {} | ||
} | ||
|
||
class A { | ||
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a class member function}} | ||
A() {} | ||
|
||
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a class member function}} | ||
int func3() {} | ||
}; | ||
|
||
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer return type}} | ||
int* func3() { return nullptr; } | ||
|
||
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer parameter type}} | ||
void func3(int *) {} | ||
|
||
#else | ||
|
||
__attribute__((sycl_device)) // expected-warning {{'sycl_device' attribute ignored}} | ||
void baz() {} | ||
|
||
#endif // NO_SYCL |
This file contains hidden or 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 hidden or 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,73 @@ | ||
// Test1 - check that kernel can call a SYCL_EXTERNAL function defined in a | ||
// different object file. | ||
// RUN: %clangxx -fsycl -DSOURCE1 -c %s -o %t1.o | ||
// RUN: %clangxx -fsycl -DSOURCE2 -c %s -o %t2.o | ||
// RUN: %clangxx -fsycl %t1.o %t2.o -o %t.exe | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.exe | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.exe | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.exe | ||
// | ||
// Test2 - check that kernel can call a SYCL_EXTERNAL function defined in a | ||
// static library. | ||
// RUN: rm -f %t.a | ||
// RUN: llvm-ar crv %t.a %t1.o | ||
// RUN: %clangxx -fsycl %t2.o -foffload-static-lib=%t.a -o %t.exe | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.exe | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.exe | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.exe | ||
|
||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
|
||
#ifdef SOURCE1 | ||
int bar(int b); | ||
|
||
SYCL_EXTERNAL | ||
int foo(int a, int b) { | ||
return a + bar(b); | ||
} | ||
|
||
int bar(int b) { | ||
return b + 5; | ||
} | ||
#endif // SOURCE1 | ||
|
||
#ifdef SOURCE2 | ||
SYCL_EXTERNAL | ||
int foo(int A, int B); | ||
|
||
int main(void) { | ||
constexpr unsigned Size = 4; | ||
int A[Size] = {1, 2, 3, 4}; | ||
int B[Size] = {1, 2, 3, 4}; | ||
int C[Size]; | ||
|
||
{ | ||
cl::sycl::range<1> range{Size}; | ||
cl::sycl::buffer<int, 1> bufA(A, range); | ||
cl::sycl::buffer<int, 1> bufB(B, range); | ||
cl::sycl::buffer<int, 1> bufC(C, range); | ||
|
||
cl::sycl::queue().submit([&](cl::sycl::handler &cgh) { | ||
auto accA = bufA.get_access<cl::sycl::access::mode::read>(cgh); | ||
auto accB = bufB.get_access<cl::sycl::access::mode::read>(cgh); | ||
auto accC = bufC.get_access<cl::sycl::access::mode::write>(cgh); | ||
|
||
cgh.parallel_for<class Test>(range, [=](cl::sycl::id<1> ID) { | ||
accC[ID] = foo(accA[ID], accB[ID]); | ||
}); | ||
}); | ||
} | ||
|
||
for (unsigned I = 0; I < Size; ++I) { | ||
int Ref = foo(A[I], B[I]); | ||
if (C[I] != Ref) { | ||
std::cout << "fail: [" << I << "] == " << C[I] << ", expected " << Ref | ||
<< "\n"; | ||
return 1; | ||
} | ||
} | ||
std::cout << "pass\n"; | ||
return 0; | ||
} | ||
#endif // SOURCE2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks for providing the doc!