Skip to content

Commit a963dac

Browse files
AlexeySachkovmaksimsab
authored andcommitted
Add Frontend test
1 parent a4c5443 commit a963dac

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

clang/test/Frontend/Inputs/sycl.hpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#define ATTR_SYCL_KERNEL __attribute__((sycl_kernel))
4+
5+
inline namespace cl {
6+
namespace sycl {
7+
8+
// Dummy aspect enum with limited enumerators
9+
enum class aspect {
10+
host = 0,
11+
cpu = 1,
12+
gpu = 2,
13+
accelerator = 3,
14+
custom = 4,
15+
fp16 = 5,
16+
fp64 = 6,
17+
};
18+
19+
class kernel {};
20+
class context {};
21+
class device {};
22+
class event {};
23+
24+
class queue {
25+
public:
26+
template <typename T>
27+
event submit(T cgf) { return event{}; }
28+
29+
void wait() {}
30+
void wait_and_throw() {}
31+
void throw_asynchronous() {}
32+
};
33+
34+
class auto_name {};
35+
template <typename Name, typename Type>
36+
struct get_kernel_name_t {
37+
using name = Name;
38+
};
39+
template <typename Type>
40+
struct get_kernel_name_t<auto_name, Type> {
41+
using name = Type;
42+
};
43+
44+
class kernel_handler {
45+
void __init_specialization_constants_buffer(char *specialization_constants_buffer) {}
46+
};
47+
48+
#define ATTR_SYCL_KERNEL __attribute__((sycl_kernel))
49+
template <typename KernelName, typename KernelType>
50+
ATTR_SYCL_KERNEL void kernel_single_task(const KernelType &kernelFunc) { // #KernelSingleTask
51+
kernelFunc();
52+
}
53+
54+
class handler {
55+
public:
56+
template <typename KernelName = auto_name, typename KernelType>
57+
void single_task(const KernelType &kernelFunc) {
58+
using NameT = typename get_kernel_name_t<KernelName, KernelType>::name;
59+
#ifdef __SYCL_DEVICE_ONLY__
60+
kernel_single_task<NameT>(kernelFunc);
61+
#else
62+
kernelFunc();
63+
#endif
64+
}
65+
};
66+
67+
} // namespace sycl
68+
} // namespace cl
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Test checks Propagate Aspect Usage pass.
2+
3+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm %s -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-WARNINGS
4+
5+
// RUNx: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown %s -debug-info-kind=constructor -dwarf-version=5 -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix CHECK-WARNINGS-DBG -DPATH=%s
6+
7+
// CHECK-WARNINGS: warning: function 'func1(int)' uses aspect 'fp16' not listed in 'sycl::device_has()'
8+
// CHECK-WARNINGS-NEXT: note: the actual use is in func3(int, int, int), compile with '-g' to get source location
9+
// CHECK-WARNINGS-NEXT: note: which is called by func2(int, int), compile with '-g' to get source location
10+
// CHECK-WARNINGS-NEXT: note: which is called by func1(int), compile with '-g' to get source location
11+
//
12+
// CHECK-WARNINGS-DBG: warning: function 'func1(int)' uses aspect 'fp16' not listed in 'sycl::device_has()'
13+
// CHECK-WARNINGS-DBG-NEXT: note: the actual use is in func3(int, int, int) at [[PATH]]:36:5
14+
// CHECK-WARNINGS-DBG-NEXT: note: which is called by func2(int, int) at [[PATH]]:40:34
15+
// CHECK-WARNINGS-DBG-NEXT: note: which is called by func1(int) at [[PATH]]:42:62
16+
17+
#include "Inputs/sycl.hpp"
18+
19+
using namespace cl::sycl;
20+
21+
class KernelName;
22+
23+
struct [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] Struct {
24+
int a = 0;
25+
};
26+
27+
int func3(int a, int b, int c) {
28+
Struct s;
29+
s.a = 1;
30+
return s.a;
31+
}
32+
33+
int func2(int a, int b) { return func3(a, b, 1); }
34+
35+
[[sycl::device_has(aspect::fp64)]] int func1(int a) { return func2(a, 1); }
36+
37+
int main() {
38+
queue Q;
39+
Q.submit([&](handler &h) {
40+
h.single_task<KernelName>([=]() { int a = func1(1); });
41+
});
42+
}

0 commit comments

Comments
 (0)