|
| 1 | +// RUN: %clang_cc1 -internal-isystem %S/Inputs -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s |
| 2 | + |
| 3 | +// This test tests the builtin __builtin_sycl_is_kernel |
| 4 | + |
| 5 | +#include "sycl.hpp" |
| 6 | + |
| 7 | +using namespace sycl; |
| 8 | +queue q; |
| 9 | + |
| 10 | +__attribute__((sycl_device)) |
| 11 | +[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]] |
| 12 | +void sstk_free_func() { |
| 13 | +} |
| 14 | + |
| 15 | +template <typename T> |
| 16 | +[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 4)]] |
| 17 | +void sstk_free_func_tmpl(T *ptr) { |
| 18 | + for (int i = 0; i <= 7; i++) |
| 19 | + ptr[i] = i + 11; |
| 20 | +} |
| 21 | + |
| 22 | +__attribute__((sycl_device)) |
| 23 | +[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 1)]] |
| 24 | +void ovl_free_func(int *ptr) { |
| 25 | + for (int i = 0; i <= 7; i++) |
| 26 | + ptr[i] = i; |
| 27 | +} |
| 28 | + |
| 29 | +__attribute__((sycl_device)) |
| 30 | +[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 1)]] |
| 31 | +void ovl_free_func(int *ptr, int val) { |
| 32 | + for (int i = 0; i <= 7; i++) |
| 33 | + ptr[i] = i + val; |
| 34 | +} |
| 35 | + |
| 36 | +__attribute__((sycl_device)) |
| 37 | +[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 4)]] |
| 38 | +void sndrk_free_func() { |
| 39 | +} |
| 40 | + |
| 41 | +void func() {} |
| 42 | + |
| 43 | +void foo() { |
| 44 | + bool b1 = __builtin_sycl_is_kernel(sstk_free_func); |
| 45 | + // CHECK: store i8 1, ptr addrspace(4) %b1{{.*}}, align 1 |
| 46 | + bool b2 = __builtin_sycl_is_kernel(*sstk_free_func); |
| 47 | + // CHECK: store i8 1, ptr addrspace(4) %b2{{.*}}, align 1 |
| 48 | + bool b3 = __builtin_sycl_is_kernel(&sstk_free_func); |
| 49 | + // CHECK: store i8 1, ptr addrspace(4) %b3{{.*}}, align 1 |
| 50 | + bool b4 = __builtin_sycl_is_kernel(func); |
| 51 | + // CHECK: store i8 0, ptr addrspace(4) %b4{{.*}}, align 1 |
| 52 | + bool b5 = __builtin_sycl_is_kernel(sndrk_free_func); |
| 53 | + // CHECK: store i8 1, ptr addrspace(4) %b5{{.*}}, align 1 |
| 54 | + |
| 55 | + // Constexpr forms of the valid cases. |
| 56 | + constexpr bool b6 = __builtin_sycl_is_kernel(sstk_free_func); // Okay and true. |
| 57 | + // CHECK: store i8 1, ptr addrspace(4) %b6{{.*}}, align 1 |
| 58 | + constexpr bool b7 = __builtin_sycl_is_kernel(func); // Okay, but false. |
| 59 | + // CHECK: store i8 0, ptr addrspace(4) %b7{{.*}}, align 1 |
| 60 | + constexpr bool b8 = __builtin_sycl_is_kernel(sndrk_free_func); // Okay, but false. |
| 61 | + // CHECK: store i8 1, ptr addrspace(4) %b8{{.*}}, align 1 |
| 62 | + |
| 63 | + // Test function template. |
| 64 | + constexpr bool b9 = __builtin_sycl_is_kernel((void(*)(int *))sstk_free_func_tmpl<int>); // Okay |
| 65 | + // CHECK: store i8 1, ptr addrspace(4) %b9{{.*}}, align 1 |
| 66 | + |
| 67 | + // Test overloaded functions. |
| 68 | + constexpr bool b10 = __builtin_sycl_is_kernel((void(*)(int *))ovl_free_func); // Okay |
| 69 | + // CHECK: store i8 1, ptr addrspace(4) %b10{{.*}}, align 1 |
| 70 | + constexpr bool b11 = __builtin_sycl_is_kernel((void(*)(int *, int))ovl_free_func); // Okay |
| 71 | + // CHECK: store i8 1, ptr addrspace(4) %b11{{.*}}, align 1 |
| 72 | +} |
| 73 | + |
| 74 | +void f() { |
| 75 | + auto L = []() { foo(); }; |
| 76 | + q.submit([&](handler &h) { |
| 77 | + h.single_task<class kernel_name_1>(L); |
| 78 | + }); |
| 79 | +} |
0 commit comments