-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Language restrictions for SYCL kernel functions from 6.3 section
- disallow allocation in kernel functions (Overloaded 'new' operations are allowed if no storage is allocated) - disallow recursion in kernel functions Signed-off-by: Blower, Melanie <melanie.blower@intel.com> Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
- Loading branch information
1 parent
6a70b70
commit 4efe9fc
Showing
7 changed files
with
357 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// RUN: %clang_cc1 -fcxx-exceptions -fsycl-is-device -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only -std=c++17 %s | ||
|
||
// This recursive function is not called from sycl kernel, | ||
// so it should not be diagnosed. | ||
int fib(int n) | ||
{ | ||
if (n <= 1) | ||
return n; | ||
return fib(n-1) + fib(n-2); | ||
} | ||
|
||
typedef struct S { | ||
template <typename T> | ||
// expected-note@+1 2{{function implemented using recursion declared here}} | ||
T factT(T i, T j) | ||
{ | ||
// expected-error@+1 1{{SYCL kernel cannot call a recursive function}} | ||
return factT(j,i); | ||
} | ||
|
||
int fact(unsigned i) | ||
{ | ||
if (i==0) return 1; | ||
// expected-error@+1 1{{SYCL kernel cannot call a recursive function}} | ||
else return factT<unsigned>(i-1, i); | ||
} | ||
} S_type; | ||
|
||
|
||
// expected-note@+1 2{{function implemented using recursion declared here}} | ||
int fact(unsigned i); | ||
// expected-note@+1 2{{function implemented using recursion declared here}} | ||
int fact1(unsigned i) | ||
{ | ||
if (i==0) return 1; | ||
// expected-error@+1 {{SYCL kernel cannot call a recursive function}} | ||
else return fact(i-1) * i; | ||
} | ||
int fact(unsigned i) | ||
{ | ||
if (i==0) return 1; | ||
// expected-error@+1 {{SYCL kernel cannot call a recursive function}} | ||
else return fact1(i-1) * i; | ||
} | ||
|
||
bool isa_B(void) { | ||
S_type s; | ||
|
||
unsigned f = s.fact(3); | ||
// expected-error@+1 1{{SYCL kernel cannot call a recursive function}} | ||
unsigned f1 = s.factT<unsigned>(3,4); | ||
// expected-error@+1 {{SYCL kernel cannot call a recursive function}} | ||
unsigned g = fact(3); | ||
// expected-error@+1 {{SYCL kernel cannot call a recursive function}} | ||
unsigned g1 = fact1(3); | ||
return 0; | ||
} | ||
|
||
__attribute__((sycl_kernel)) void kernel1(void) { | ||
isa_B(); | ||
} | ||
// expected-note@+1 2{{function implemented using recursion declared here}} | ||
__attribute__((sycl_kernel)) void kernel2(void) { | ||
// expected-error@+1 {{SYCL kernel cannot call a recursive function}} | ||
kernel2(); | ||
} | ||
__attribute__((sycl_kernel)) void kernel3(void) { | ||
; | ||
} | ||
|
||
using myFuncDef = int(int,int); | ||
|
||
void usage( myFuncDef functionPtr ) { | ||
kernel1(); | ||
} | ||
void usage2( myFuncDef functionPtr ) { | ||
// expected-error@+1 {{SYCL kernel cannot call a recursive function}} | ||
kernel2(); | ||
} | ||
void usage3( myFuncDef functionPtr ) { | ||
kernel3(); | ||
} | ||
|
||
int addInt(int n, int m) { | ||
return n+m; | ||
} | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
template <typename name, typename Func> | ||
// expected-note@+1 2{{function implemented using recursion declared here}} | ||
__attribute__((sycl_kernel)) void kernel_single_task2(Func kernelFunc) { | ||
kernelFunc(); | ||
// expected-error@+1 2{{SYCL kernel cannot call a recursive function}} | ||
kernel_single_task2<name, Func>(kernelFunc); | ||
} | ||
|
||
int main() { | ||
kernel_single_task<class fake_kernel>([]() { usage( &addInt ); }); | ||
kernel_single_task<class fake_kernel>([]() { usage2( &addInt ); }); | ||
kernel_single_task2<class fake_kernel>([]() { usage3( &addInt ); }); | ||
return fib(5); | ||
} | ||
|
Oops, something went wrong.