Skip to content

Commit 9c14f91

Browse files
[SYCL] kernel_compiler include file paths collision fix (#14490)
kernel_compiler include_file support shouldn't have files that might collide. Spec has been recently clarified as well ( a6d8758 )
1 parent 21c2e1c commit 9c14f91

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

sycl/source/detail/kernel_compiler/kernel_compiler_sycl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void outputIncludeFiles(const std::filesystem::path &Dirpath,
138138
using pairStrings = std::pair<std::string, std::string>;
139139
for (pairStrings p : IncludePairs) {
140140
std::filesystem::path FilePath = Dirpath / p.first;
141+
std::filesystem::create_directories(FilePath.parent_path());
141142
std::ofstream outfile(FilePath, std::ios::out | std::ios::trunc);
142143
if (outfile.is_open()) {
143144
outfile << p.second << std::endl;

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ auto constexpr AddEmH = R"===(
2121
}
2222
)===";
2323

24+
auto constexpr PlusEmH = R"===(
25+
int PlusEm(int a, int b){
26+
return a + b + 6;
27+
}
28+
)===";
29+
2430
// TODO: remove SYCL_EXTERNAL once it is no longer needed.
2531
auto constexpr SYCLSource = R"===(
2632
#include <sycl/sycl.hpp>
27-
#include "AddEm.h"
33+
#include "intermediate/AddEm.h"
34+
#include "intermediate/PlusEm.h"
2835
2936
// use extern "C" to avoid name mangling
3037
extern "C" SYCL_EXTERNAL SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((sycl::ext::oneapi::experimental::nd_range_kernel<1>))
@@ -45,7 +52,7 @@ void ff_templated(T *ptr) {
4552
sycl::nd_item<1> Item = sycl::ext::oneapi::this_work_item::get_nd_item<1>();
4653
4754
sycl::id<1> GId = Item.get_global_id();
48-
ptr[GId.get(0)] = GId.get(0) + 39;
55+
ptr[GId.get(0)] = PlusEm(GId.get(0), 38);
4956
}
5057
)===";
5158

@@ -100,8 +107,8 @@ void test_1(sycl::queue &Queue, sycl::kernel &Kernel, int seed) {
100107
Queue.wait();
101108

102109
for (int i = 0; i < Range; i++) {
103-
std::cout << usmPtr[i] << " ";
104-
assert(usmPtr[i] = i + seed);
110+
std::cout << usmPtr[i] << "=" << (i + seed) << " ";
111+
assert(usmPtr[i] == i + seed);
105112
}
106113
std::cout << std::endl;
107114

@@ -127,9 +134,11 @@ void test_build_and_run() {
127134
}
128135

129136
// Create from source.
137+
syclex::include_files incFiles{"intermediate/AddEm.h", AddEmH};
138+
incFiles.add("intermediate/PlusEm.h", PlusEmH);
130139
source_kb kbSrc = syclex::create_kernel_bundle_from_source(
131140
ctx, syclex::source_language::sycl, SYCLSource,
132-
syclex::properties{syclex::include_files{"AddEm.h", AddEmH}});
141+
syclex::properties{incFiles});
133142

134143
// Double check kernel_bundle.get_source() / get_backend().
135144
sycl::context ctxRes = kbSrc.get_context();
@@ -167,8 +176,8 @@ void test_build_and_run() {
167176
// clang-format on
168177

169178
// Test the kernels.
170-
test_1(q, k, 37 + 5); // AddEm will add 5 more.
171-
test_1(q, k2, 39);
179+
test_1(q, k, 37 + 5); // ff_cp seeds 37. AddEm will add 5 more.
180+
test_1(q, k2, 38 + 6); // ff_templated seeds 38. PlusEm adds 6 more.
172181
}
173182

174183
void test_error() {

0 commit comments

Comments
 (0)