Skip to content

Commit ed658f1

Browse files
Preamble end at the middle of #if is fine
1 parent 736efc4 commit ed658f1

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,18 +1151,6 @@ void iota(float start, float *ptr) {
11511151

11521152
Limitations:
11531153

1154-
* Preamble detection is done at the Lexer level and can't handle code like
1155-
1156-
[source,c++]
1157-
----
1158-
#if 1
1159-
#include <sycl/sycl.hpp>
1160-
#else
1161-
// Auto-detected preamble ends in the middle of `#else` and would fail to compile.
1162-
void foo() {}
1163-
#endif
1164-
----
1165-
11661154
* Any changes in either preamble or compilation options (including
11671155
`-DSOMETHING`!) result in a creation of a new pre-compiled header/preamble.
11681156

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %} %{run} %t.out
3+
4+
// UNSUPPORTED: target-native_cpu
5+
// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/20142
6+
7+
// Verify that preamble ending in the middle of #if.. works.
8+
9+
#include <sycl/detail/core.hpp>
10+
#include <sycl/kernel_bundle.hpp>
11+
12+
#include <chrono>
13+
#include <iostream>
14+
#include <sstream>
15+
#include <string_view>
16+
17+
using namespace std::string_view_literals;
18+
namespace syclexp = sycl::ext::oneapi::experimental;
19+
20+
int main(int argc, char **argv) {
21+
auto Test = [](std::string src) {
22+
sycl::queue q;
23+
// Two iterations to test pch creation/use:
24+
for (int i = 0; i < 2; ++i) {
25+
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src =
26+
syclexp::create_kernel_bundle_from_source(
27+
q.get_context(), syclexp::source_language::sycl, src);
28+
sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe =
29+
syclexp::build(kb_src, syclexp::properties{syclexp::build_options{
30+
std::vector<std::string>{"--auto-pch"}}}
31+
32+
);
33+
}
34+
};
35+
36+
Test(R"""(
37+
#if 1
38+
#include <sycl/ext/oneapi/free_function_queries.hpp>
39+
#include <sycl/ext/oneapi/kernel_properties/properties.hpp>
40+
namespace syclext = sycl::ext::oneapi;
41+
namespace syclexp = sycl::ext::oneapi::experimental;
42+
#else
43+
fail_to_compile = 1;
44+
#endif
45+
46+
extern "C"
47+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
48+
void iota(float start, float *ptr) {
49+
size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id();
50+
ptr[id] = start + static_cast<float>(id);
51+
}
52+
)""");
53+
54+
Test(R"""(
55+
#if 0
56+
fail_to_compile = 1;
57+
#else
58+
#include <sycl/ext/oneapi/free_function_queries.hpp>
59+
#include <sycl/ext/oneapi/kernel_properties/properties.hpp>
60+
namespace syclext = sycl::ext::oneapi;
61+
namespace syclexp = sycl::ext::oneapi::experimental;
62+
#endif
63+
64+
extern "C"
65+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
66+
void iota(float start, float *ptr) {
67+
size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id();
68+
ptr[id] = start + static_cast<float>(id);
69+
}
70+
)""");
71+
}

0 commit comments

Comments
 (0)