1
1
// RUN: %{build} -o %t.out
2
2
// RUN: %{run} %t.out
3
3
//
4
- // Fail is flaky for level_zero, enable when fixed.
5
- // UNSUPPORTED: level_zero
6
- //
7
- // Consistently fails with opencl gpu, enable when fixed.
8
- // XFAIL: opencl && gpu
9
-
10
4
// ==--- kernel_info.cpp - SYCL kernel info test ----------------------------==//
11
5
//
12
6
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
17
11
18
12
#include < cassert>
19
13
#include < sycl/detail/core.hpp>
14
+ #include < sycl/ext/oneapi/get_kernel_info.hpp>
20
15
21
16
using namespace sycl ;
17
+ namespace syclex = sycl::ext::oneapi;
18
+
19
+ auto checkExceptionIsThrown = [](auto &getInfoFunc,
20
+ const std::string &refErrMsg,
21
+ std::error_code refErrc) {
22
+ std::string errMsg = " " ;
23
+ std::error_code errc;
24
+ bool exceptionWasThrown = false ;
25
+ try {
26
+ std::ignore = getInfoFunc ();
27
+ } catch (exception &e) {
28
+ errMsg = e.what ();
29
+ errc = e.code ();
30
+ exceptionWasThrown = true ;
31
+ }
32
+ assert (exceptionWasThrown);
33
+ assert (errMsg == refErrMsg);
34
+ assert (errc == refErrc);
35
+ };
22
36
23
37
int main () {
24
38
queue q;
25
-
39
+ auto ctx = q. get_context ();
26
40
buffer<int , 1 > buf (range<1 >(1 ));
27
- auto KernelID = sycl::get_kernel_id<class SingleTask >();
28
- auto KB =
29
- get_kernel_bundle<bundle_state::executable>(q.get_context (), {KernelID});
30
- kernel krn = KB.get_kernel (KernelID);
41
+ auto kernelID = sycl::get_kernel_id<class SingleTask >();
42
+ auto kb = get_kernel_bundle<bundle_state::executable>(ctx, {kernelID});
43
+ kernel krn = kb.get_kernel (kernelID);
31
44
32
45
q.submit ([&](handler &cgh) {
33
46
auto acc = buf.get_access <access::mode::read_write>(cgh);
@@ -37,30 +50,34 @@ int main() {
37
50
const std::string krnName = krn.get_info <info::kernel::function_name>();
38
51
assert (!krnName.empty ());
39
52
40
- std::string ErrMsg = " " ;
41
- std::error_code Errc;
42
- bool ExceptionWasThrown = false ;
43
- try {
44
- const cl_uint krnArgCount = krn.get_info <info::kernel::num_args>();
45
- } catch (exception &e) {
46
- ErrMsg = e.what ();
47
- Errc = e.code ();
48
- ExceptionWasThrown = true ;
49
- }
50
- assert (ExceptionWasThrown && " Invalid using of \" info::kernel::num_args\" "
51
- " query should throw an exception." );
52
- assert (ErrMsg ==
53
- " info::kernel::num_args descriptor may only be used to query a kernel "
54
- " that resides in a kernel bundle constructed using a backend specific"
55
- " interoperability function or to query a device built-in kernel" );
56
- assert (Errc == errc::invalid);
53
+ auto refErrMsg =
54
+ " info::kernel::num_args descriptor may only be used to query a kernel "
55
+ " that resides in a kernel bundle constructed using a backend specific"
56
+ " interoperability function or to query a device built-in kernel" ;
57
+ auto refErrc = errc::invalid;
58
+ auto getInfoNumArgsFunc = [&]() -> cl_uint {
59
+ return krn.get_info <info::kernel::num_args>();
60
+ };
61
+ checkExceptionIsThrown (getInfoNumArgsFunc, refErrMsg, refErrc);
62
+ auto getInfoNumArgsFuncExt = [&]() {
63
+ return syclex::get_kernel_info<SingleTask, info::kernel::num_args>(ctx);
64
+ };
65
+ checkExceptionIsThrown (getInfoNumArgsFuncExt, refErrMsg, refErrc);
57
66
58
67
const context krnCtx = krn.get_info <info::kernel::context>();
59
68
assert (krnCtx == q.get_context ());
60
69
const cl_uint krnRefCount = krn.get_info <info::kernel::reference_count>();
61
70
assert (krnRefCount > 0 );
62
- const std::string krnAttr = krn.get_info <info::kernel::attributes>();
63
- assert (krnAttr.empty ());
71
+
72
+ // Use ext_oneapi_get_kernel_info extension and check that answers match.
73
+ const context krnCtxExt =
74
+ syclex::get_kernel_info<SingleTask, info::kernel::context>(ctx);
75
+ assert (krnCtxExt == krnCtx);
76
+ // Reference count might be different because we have to retain the kernel
77
+ // handle first to fetch the info. So just check that it is not 0.
78
+ const cl_uint krnRefCountExt =
79
+ syclex::get_kernel_info<SingleTask, info::kernel::reference_count>(ctx);
80
+ assert (krnRefCountExt > 0 );
64
81
65
82
device dev = q.get_device ();
66
83
const size_t wgSize =
@@ -82,34 +99,70 @@ int main() {
82
99
krn.get_info <info::kernel_device_specific::compile_num_sub_groups>(dev);
83
100
assert (compileNumSg <= maxNumSg);
84
101
85
- {
86
- std::error_code Errc;
87
- std::string ErrMsg = " " ;
88
- bool IsExceptionThrown = false ;
89
- try {
90
- krn.get_info <sycl::info::kernel_device_specific::global_work_size>(dev);
91
- auto BuiltInIds = dev.get_info <info::device::built_in_kernel_ids>();
92
- bool isBuiltInKernel = std::find (BuiltInIds.begin (), BuiltInIds.end (),
93
- KernelID) != BuiltInIds.end ();
94
- bool isCustomDevice = dev.get_info <sycl::info::device::device_type>() ==
95
- sycl::info::device_type::custom;
96
- assert ((isCustomDevice || isBuiltInKernel) &&
97
- " info::kernel_device_specific::global_work_size descriptor can "
98
- " only be used with custom device "
99
- " or built-in kernel." );
102
+ // Use ext_oneapi_get_kernel_info extension and check that answers match.
103
+ const size_t wgSizeExt = syclex::get_kernel_info<
104
+ SingleTask, info::kernel_device_specific::work_group_size>(ctx, dev);
105
+ assert (wgSizeExt == wgSize);
106
+ const size_t prefWGSizeMultExt = syclex::get_kernel_info<
107
+ SingleTask,
108
+ info::kernel_device_specific::preferred_work_group_size_multiple>(ctx,
109
+ dev);
110
+ assert (prefWGSizeMultExt == prefWGSizeMult);
111
+ const cl_uint maxSgSizeExt = syclex::get_kernel_info<
112
+ SingleTask, info::kernel_device_specific::max_sub_group_size>(ctx, dev);
113
+ assert (maxSgSizeExt == maxSgSize);
114
+ const cl_uint compileSgSizeExt = syclex::get_kernel_info<
115
+ SingleTask, info::kernel_device_specific::compile_sub_group_size>(ctx,
116
+ dev);
117
+ assert (compileSgSizeExt == compileSgSize);
118
+ const cl_uint maxNumSgExt = syclex::get_kernel_info<
119
+ SingleTask, info::kernel_device_specific::max_num_sub_groups>(ctx, dev);
120
+ assert (maxNumSgExt == maxNumSg);
121
+ const cl_uint compileNumSgExt = syclex::get_kernel_info<
122
+ SingleTask, info::kernel_device_specific::compile_num_sub_groups>(ctx,
123
+ dev);
124
+ assert (compileNumSgExt == compileNumSg);
100
125
101
- } catch (sycl::exception &e) {
102
- IsExceptionThrown = true ;
103
- Errc = e.code ();
104
- ErrMsg = e.what ();
105
- }
106
- assert (IsExceptionThrown &&
107
- " Invalid using of info::kernel_device_specific::global_work_size "
108
- " query should throw an exception." );
109
- assert (Errc == errc::invalid);
110
- assert (ErrMsg ==
111
- " info::kernel_device_specific::global_work_size descriptor may only "
112
- " be used if the device type is device_type::custom or if the "
113
- " kernel is a built-in kernel." );
114
- }
126
+ // Use ext_oneapi_get_kernel_info extension with queue parameter and check the
127
+ // result.
128
+ const size_t wgSizeExtQ =
129
+ syclex::get_kernel_info<SingleTask,
130
+ info::kernel_device_specific::work_group_size>(q);
131
+ assert (wgSizeExtQ == wgSize);
132
+ const size_t prefWGSizeMultExtQ = syclex::get_kernel_info<
133
+ SingleTask,
134
+ info::kernel_device_specific::preferred_work_group_size_multiple>(q);
135
+ assert (prefWGSizeMultExtQ == prefWGSizeMult);
136
+ const cl_uint maxSgSizeExtQ = syclex::get_kernel_info<
137
+ SingleTask, info::kernel_device_specific::max_sub_group_size>(q);
138
+ assert (maxSgSizeExtQ == maxSgSize);
139
+ const cl_uint compileSgSizeExtQ = syclex::get_kernel_info<
140
+ SingleTask, info::kernel_device_specific::compile_sub_group_size>(q);
141
+ assert (compileSgSizeExtQ == compileSgSize);
142
+ const cl_uint maxNumSgExtQ = syclex::get_kernel_info<
143
+ SingleTask, info::kernel_device_specific::max_num_sub_groups>(q);
144
+ assert (maxNumSgExtQ == maxNumSg);
145
+ const cl_uint compileNumSgExtQ = syclex::get_kernel_info<
146
+ SingleTask, info::kernel_device_specific::compile_num_sub_groups>(q);
147
+ assert (compileNumSgExtQ == compileNumSg);
148
+
149
+ refErrMsg =
150
+ " info::kernel_device_specific::global_work_size descriptor may only "
151
+ " be used if the device type is device_type::custom or if the "
152
+ " kernel is a built-in kernel." ;
153
+ auto getInfoGWSFunc = [&]() {
154
+ return krn.get_info <sycl::info::kernel_device_specific::global_work_size>(
155
+ dev);
156
+ };
157
+ checkExceptionIsThrown (getInfoGWSFunc, refErrMsg, refErrc);
158
+ auto getInfoGWSFuncExt = [&]() {
159
+ return syclex::get_kernel_info<
160
+ SingleTask, info::kernel_device_specific::global_work_size>(ctx, dev);
161
+ };
162
+ checkExceptionIsThrown (getInfoGWSFuncExt, refErrMsg, refErrc);
163
+ auto getInfoGWSFuncExtQ = [&]() {
164
+ return syclex::get_kernel_info<
165
+ SingleTask, info::kernel_device_specific::global_work_size>(q);
166
+ };
167
+ checkExceptionIsThrown (getInfoGWSFuncExtQ, refErrMsg, refErrc);
115
168
}
0 commit comments