Skip to content

Commit 2881051

Browse files
committed
[SYCL] Implement sycl_ext_oneapi_get_kernel_info extension
Extension: https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_get_kernel_info.asciidoc Outlined kernel::attributes test to a separate file with XFAIL markings and reenabled kernel_info.cpp.
1 parent 3a1c3cb commit 2881051

File tree

6 files changed

+145
-17
lines changed

6 files changed

+145
-17
lines changed

sycl/doc/extensions/proposed/sycl_ext_oneapi_get_kernel_info.asciidoc renamed to sycl/doc/extensions/supported/sycl_ext_oneapi_get_kernel_info.asciidoc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ SYCL specification refer to that revision.
4343

4444
== Status
4545

46-
This is a proposed extension specification, intended to gather community
47-
feedback. Interfaces defined in this specification may not be implemented yet
48-
or may be in a preliminary state. The specification itself may also change in
49-
incompatible ways before it is finalized. *Shipping software products should
50-
not rely on APIs defined in this specification.*
46+
This extension is implemented and fully supported by DPC++.
5147

5248

5349
== Overview
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//==----- get_kernel_info.hpp --- SYCL get_kernel_info extension -------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===------------------------------------------------------------------===//
8+
9+
#pragma once
10+
#include <sycl/context.hpp>
11+
#include <sycl/detail/export.hpp>
12+
#include <sycl/detail/info_desc_helpers.hpp>
13+
#include <sycl/device.hpp>
14+
#include <sycl/queue.hpp>
15+
16+
namespace sycl {
17+
inline namespace _V1 {
18+
namespace ext::oneapi::experimental {
19+
20+
template <typename KernelName, typename Param>
21+
typename sycl::detail::is_kernel_info_desc<Param>::return_type
22+
get_kernel_info(const context &Ctx) {
23+
auto Bundle =
24+
sycl::get_kernel_bundle<KernelName, sycl::bundle_state::executable>(Ctx);
25+
return Bundle.template get_kernel<KernelName>().template get_info<Param>();
26+
}
27+
28+
template <typename KernelName, typename Param>
29+
typename sycl::detail::is_kernel_device_specific_info_desc<Param>::return_type
30+
get_kernel_info(const context &Ctx, const device &Dev) {
31+
auto Bundle =
32+
sycl::get_kernel_bundle<KernelName, sycl::bundle_state::executable>(Ctx);
33+
return Bundle.template get_kernel<KernelName>().template get_info<Param>(Dev);
34+
}
35+
36+
template <typename KernelName, typename Param>
37+
typename sycl::detail::is_kernel_device_specific_info_desc<Param>::return_type
38+
get_kernel_info(const queue &Q) {
39+
auto Bundle =
40+
sycl::get_kernel_bundle<KernelName, sycl::bundle_state::executable>(
41+
Q.get_context());
42+
return Bundle.template get_kernel<KernelName>().template get_info<Param>(
43+
Q.get_device());
44+
}
45+
46+
} // namespace ext::oneapi::experimental
47+
} // namespace _V1
48+
} // namespace sycl

sycl/include/sycl/sycl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#include <sycl/ext/oneapi/filter_selector.hpp>
104104
#include <sycl/ext/oneapi/free_function_queries.hpp>
105105
#include <sycl/ext/oneapi/functional.hpp>
106+
#include <sycl/ext/oneapi/get_kernel_info.hpp>
106107
#include <sycl/ext/oneapi/group_local_memory.hpp>
107108
#include <sycl/ext/oneapi/kernel_properties/properties.hpp>
108109
#include <sycl/ext/oneapi/matrix/matrix.hpp>

sycl/source/feature_test.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ inline namespace _V1 {
108108
#define SYCL_EXT_ONEAPI_RAW_KERNEL_ARG 1
109109
#define SYCL_EXT_ONEAPI_PROFILING_TAG 1
110110
#define SYCL_EXT_ONEAPI_ENQUEUE_NATIVE_COMMAND 1
111+
#define SYCL_EXT_ONEAPI_GET_KERNEL_INFO 1
111112
// In progress yet
112113
#define SYCL_EXT_ONEAPI_ATOMIC16 0
113114

sycl/test-e2e/Basic/kernel_info.cpp

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// RUN: %{build} -o %t.out
22
// RUN: %{run} %t.out
33
//
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-
104
//==--- kernel_info.cpp - SYCL kernel info test ----------------------------==//
115
//
126
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -17,16 +11,17 @@
1711

1812
#include <cassert>
1913
#include <sycl/detail/core.hpp>
14+
#include <sycl/ext/oneapi/get_kernel_info.hpp>
2015

2116
using namespace sycl;
17+
namespace syclex = sycl::ext::oneapi;
2218

2319
int main() {
2420
queue q;
25-
21+
auto ctx = q.get_context();
2622
buffer<int, 1> buf(range<1>(1));
2723
auto KernelID = sycl::get_kernel_id<class SingleTask>();
28-
auto KB =
29-
get_kernel_bundle<bundle_state::executable>(q.get_context(), {KernelID});
24+
auto KB = get_kernel_bundle<bundle_state::executable>(ctx, {KernelID});
3025
kernel krn = KB.get_kernel(KernelID);
3126

3227
q.submit([&](handler &cgh) {
@@ -42,6 +37,10 @@ int main() {
4237
bool ExceptionWasThrown = false;
4338
try {
4439
const cl_uint krnArgCount = krn.get_info<info::kernel::num_args>();
40+
// Use ext_oneapi_get_kernel_info extension and check that answers match.
41+
const cl_uint krnArgCountExt =
42+
syclex::get_kernel_info<SingleTask, info::kernel::num_args>(ctx);
43+
assert(krnArgCountExt == krnArgCount);
4544
} catch (exception &e) {
4645
ErrMsg = e.what();
4746
Errc = e.code();
@@ -59,8 +58,16 @@ int main() {
5958
assert(krnCtx == q.get_context());
6059
const cl_uint krnRefCount = krn.get_info<info::kernel::reference_count>();
6160
assert(krnRefCount > 0);
62-
const std::string krnAttr = krn.get_info<info::kernel::attributes>();
63-
assert(krnAttr.empty());
61+
62+
// Use ext_oneapi_get_kernel_info extension and check that answers match.
63+
const context krnCtxExt =
64+
syclex::get_kernel_info<SingleTask, info::kernel::context>(ctx);
65+
assert(krnCtxExt == krnCtx);
66+
// Reference count might be different because we have to retain the kernel
67+
// handle first to fetch the info. So just check that it is not 0.
68+
const cl_uint krnRefCountExt =
69+
syclex::get_kernel_info<SingleTask, info::kernel::reference_count>(ctx);
70+
assert(krnRefCountExt > 0);
6471

6572
device dev = q.get_device();
6673
const size_t wgSize =
@@ -82,12 +89,42 @@ int main() {
8289
krn.get_info<info::kernel_device_specific::compile_num_sub_groups>(dev);
8390
assert(compileNumSg <= maxNumSg);
8491

92+
// Use ext_oneapi_get_kernel_info extension and check that answers match.
93+
const size_t wgSizeExt = syclex::get_kernel_info<
94+
SingleTask, info::kernel_device_specific::work_group_size>(ctx, dev);
95+
assert(wgSizeExt == wgSize);
96+
const size_t prefWGSizeMultExt = syclex::get_kernel_info<
97+
SingleTask,
98+
info::kernel_device_specific::preferred_work_group_size_multiple>(ctx,
99+
dev);
100+
assert(prefWGSizeMultExt == prefWGSizeMult);
101+
const cl_uint maxSgSizeExt = syclex::get_kernel_info<
102+
SingleTask, info::kernel_device_specific::max_sub_group_size>(ctx, dev);
103+
assert(maxSgSizeExt == maxSgSize);
104+
const cl_uint compileSgSizeExt = syclex::get_kernel_info<
105+
SingleTask, info::kernel_device_specific::compile_sub_group_size>(ctx,
106+
dev);
107+
assert(compileSgSizeExt == compileSgSize);
108+
const cl_uint maxNumSgExt = syclex::get_kernel_info<
109+
SingleTask, info::kernel_device_specific::max_num_sub_groups>(ctx, dev);
110+
assert(maxNumSgExt == maxNumSg);
111+
const cl_uint compileNumSgExt = syclex::get_kernel_info<
112+
SingleTask, info::kernel_device_specific::compile_num_sub_groups>(ctx,
113+
dev);
114+
assert(compileNumSgExt == compileNumSg);
115+
85116
{
86117
std::error_code Errc;
87118
std::string ErrMsg = "";
88119
bool IsExceptionThrown = false;
89120
try {
90-
krn.get_info<sycl::info::kernel_device_specific::global_work_size>(dev);
121+
auto globalWorkSize =
122+
krn.get_info<sycl::info::kernel_device_specific::global_work_size>(
123+
dev);
124+
// Use ext_oneapi_get_kernel_info extension and check that answers match.
125+
auto globalWorkSizeExt = syclex::get_kernel_info<
126+
SingleTask, info::kernel_device_specific::global_work_size>(ctx, dev);
127+
assert(globalWorkSize == globalWorkSizeExt);
91128
auto BuiltInIds = dev.get_info<info::device::built_in_kernel_ids>();
92129
bool isBuiltInKernel = std::find(BuiltInIds.begin(), BuiltInIds.end(),
93130
KernelID) != BuiltInIds.end();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
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+
// XFAIL-TRACKER: GSD-8971
10+
11+
//==--- kernel_info_attr.cpp - SYCL info::kernel::attributes test ---==//
12+
//
13+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
14+
// See https://llvm.org/LICENSE.txt for license information.
15+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
16+
//
17+
//===---------------------------------------------------------------===//
18+
19+
#include <cassert>
20+
#include <sycl/detail/core.hpp>
21+
#include <sycl/ext/oneapi/get_kernel_info.hpp>
22+
23+
using namespace sycl;
24+
namespace syclex = sycl::ext::oneapi;
25+
26+
int main() {
27+
queue q;
28+
auto ctx = q.get_context();
29+
buffer<int, 1> buf(range<1>(1));
30+
auto KernelID = sycl::get_kernel_id<class SingleTask>();
31+
auto KB = get_kernel_bundle<bundle_state::executable>(ctx, {KernelID});
32+
kernel krn = KB.get_kernel(KernelID);
33+
34+
q.submit([&](handler &cgh) {
35+
auto acc = buf.get_access<access::mode::read_write>(cgh);
36+
cgh.single_task<class SingleTask>(krn, [=]() { acc[0] = acc[0] + 1; });
37+
});
38+
39+
const std::string krnAttr = krn.get_info<info::kernel::attributes>();
40+
assert(krnAttr.empty());
41+
const std::string krnAttrExt =
42+
syclex::get_kernel_info<SingleTask, info::kernel::attributes>(ctx);
43+
assert(krnAttr == krnAttrExt);
44+
return 0;
45+
}

0 commit comments

Comments
 (0)