Skip to content
Merged
56 changes: 32 additions & 24 deletions clang/test/SemaSYCL/built-in-type-kernel-arg.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -ast-dump %s | FileCheck %s
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -ast-dump %s | FileCheck %s

// This test checks that compiler generates correct initialization for arguments
// that have struct or built-in type inside the OpenCL kernel

#include "Inputs/sycl.hpp"
#include "sycl.hpp"

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
kernelFunc();
}
sycl::queue deviceQueue;

struct test_struct {
int data;
Expand All @@ -18,10 +15,12 @@ struct test_struct {
};

void test(const int some_const) {
kernel<class kernel_const>(
[=]() {
int a = some_const;
});
deviceQueue.submit([&](sycl::handler &h) {
h.single_task<class kernel_const>(
[=]() {
int a = some_const;
});
});
}

int main() {
Expand All @@ -31,20 +30,29 @@ int main() {
int *ptr_array[2];
test_struct s;
s.data = data;
kernel<class kernel_int>(
[=]() {
int kernel_data = data;
});
kernel<class kernel_struct>(
[=]() {
test_struct k_s;
k_s = s;
});
kernel<class kernel_pointer>(
[=]() {
new_data_addr[0] = data_addr[0];
int *local = ptr_array[1];
});

deviceQueue.submit([&](sycl::handler &h) {
h.single_task<class kernel_int>(
[=]() {
int kernel_data = data;
});
});

deviceQueue.submit([&](sycl::handler &h) {
h.single_task<class kernel_struct>(
[=]() {
test_struct k_s;
k_s = s;
});
});

deviceQueue.submit([&](sycl::handler &h) {
h.single_task<class kernel_pointer>(
[=]() {
new_data_addr[0] = data_addr[0];
int *local = ptr_array[1];
});
});

const int some_const = 10;
test(some_const);
Expand Down
153 changes: 77 additions & 76 deletions clang/test/SemaSYCL/call-to-undefined-function.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -Wno-sycl-2017-compat -verify -fsyntax-only %s
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify -fsyntax-only %s

#include "sycl.hpp"

sycl::queue deviceQueue;

void defined() {
}
Expand All @@ -8,11 +12,6 @@ void undefined();

SYCL_EXTERNAL void undefinedExternal();

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
kernelFunc();
}

template <typename T>
void definedTpl() {
}
Expand Down Expand Up @@ -95,76 +94,78 @@ int main() {
// No problems in host code
undefined();

kernel_single_task<class CallToUndefinedFnTester>([]() {
// expected-note@-1 {{called by 'operator()'}}
// expected-note@-2 {{called by 'operator()'}}

// simple functions
defined();
undefinedExternal();
undefined();
// expected-error@-1 {{SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute}}

// templated functions
definedTpl<int>();
undefinedExternalTpl<int>();
undefinedTpl<int>();
// expected-error@-1 {{SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute}}

// partially specialized template function
definedPartialTpl<int, false>();
definedPartialTpl<int, true>();
definedPartialTpl<char, false>();
definedPartialTpl<char, true>();

// template class with specialization
{
Tpl<int, false> tpl;
tpl.defined();
}

{
Tpl<int, true> tpl;
tpl.defined();
}

// template class with template method, both have specializations.
{
TplWithTplMethod<int, false> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

{
TplWithTplMethod<int, true> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

{
TplWithTplMethod2<int, false> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

{
TplWithTplMethod2<int, true> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

// forward-declared function
useFwDeclFn();
forwardDeclFn();
forwardDeclFn2();
deviceQueue.submit([&](sycl::handler &h) {
h.single_task<class CallToUndefinedFnTester>([]() {
// expected-note@-1 {{called by 'operator()'}}
// expected-note@-2 {{called by 'operator()'}}

// simple functions
defined();
undefinedExternal();
undefined();
// expected-error@-1 {{SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute}}

// templated functions
definedTpl<int>();
undefinedExternalTpl<int>();
undefinedTpl<int>();
// expected-error@-1 {{SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute}}

// partially specialized template function
definedPartialTpl<int, false>();
definedPartialTpl<int, true>();
definedPartialTpl<char, false>();
definedPartialTpl<char, true>();

// template class with specialization
{
Tpl<int, false> tpl;
tpl.defined();
}

{
Tpl<int, true> tpl;
tpl.defined();
}

// template class with template method, both have specializations.
{
TplWithTplMethod<int, false> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

{
TplWithTplMethod<int, true> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

{
TplWithTplMethod2<int, false> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

{
TplWithTplMethod2<int, true> tpl;
tpl.defined<char, false>();
tpl.defined<char, true>();
tpl.defined<int, false>();
tpl.defined<int, true>();
}

// forward-declared function
useFwDeclFn();
forwardDeclFn();
forwardDeclFn2();
});
});
}

Expand Down
26 changes: 11 additions & 15 deletions clang/test/SemaSYCL/deferred-diagnostics-aux-builtin.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// RUN: %clang_cc1 -triple spir64-unknown-unknown-sycldevice -fsycl -fsycl-is-device -aux-triple x86_64-unknown-linux-gnu -Wno-sycl-2017-compat -verify -fsyntax-only %s
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -aux-triple x86_64-unknown-linux-gnu -Wno-sycl-2017-compat -verify -fsyntax-only %s

inline namespace cl {
namespace sycl {
#include "sycl.hpp"

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
// expected-note@+1 {{called by 'kernel_single_task<AName, (lambda}}
kernelFunc();
}

} // namespace sycl
} // namespace cl
sycl::queue deviceQueue;

int main(int argc, char **argv) {
//_mm_prefetch is an x86-64 specific builtin where the second integer parameter is required to be a constant
Expand All @@ -19,9 +11,13 @@ int main(int argc, char **argv) {

_mm_prefetch("test", 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}}

cl::sycl::kernel_single_task<class AName>([]() {
_mm_prefetch("test", 4); // expected-error {{builtin is not supported on this target}}
_mm_prefetch("test", 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}} expected-error {{builtin is not supported on this target}}
deviceQueue.submit([&](sycl::handler &h) {
// expected-note@Inputs/sycl.hpp:212 {{called by 'kernel_single_task<AName, (lambda}}
h.single_task<class AName>([]() {
_mm_prefetch("test", 4); // expected-error {{builtin is not supported on this target}}
_mm_prefetch("test", 8); // expected-error {{argument value 8 is outside the valid range [0, 7]}} expected-error {{builtin is not supported on this target}}
});
});

return 0;
}
}
Loading