Skip to content

Commit e73d2ce

Browse files
AlexeySachkovbader
authored andcommitted
[SYCL] Fix compile error for handler::copy with -fsycl-unnamed-lambda (#903)
Some `copy` methods in handler are implemented via `parallel_for` for host device and hence, we need to have `KernelInfo` struct (provided by integration header) to compile them. This effectively creates cyclic dependency and we already have some kind of a workaround for it for regular mode (without -fsycl-unnamed-lambda). This patch applies the same solution for unnamed lambda mechanism. Signed-off-by: Alexey Sachkov <[email protected]>
1 parent f9296b6 commit e73d2ce

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

sycl/include/CL/sycl/detail/kernel_desc.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ template <class KernelNameType> struct KernelInfo {
6363
static constexpr const char *getName() { return ""; }
6464
};
6565
#else
66-
template <char...> struct KernelInfoData; // Should this have dummy impl?
66+
template <char...> struct KernelInfoData {
67+
static constexpr unsigned getNumParams() { return 0; }
68+
static const kernel_param_desc_t &getParamDesc(int Idx) {
69+
static kernel_param_desc_t Dummy;
70+
return Dummy;
71+
}
72+
static constexpr const char *getName() { return ""; }
73+
};
6774

6875
// C++14 like index_sequence and make_index_sequence
6976
// not needed C++14 members (value_type, size) not implemented
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda %s -o %t.out
2+
// The purpose of this test is to check that the following code can be
3+
// successfully compiled
4+
#include <CL/sycl.hpp>
5+
6+
#include <iostream>
7+
8+
int main() {
9+
auto AsyncHandler = [](cl::sycl::exception_list EL) {
10+
for (std::exception_ptr const &P : EL) {
11+
try {
12+
std::rethrow_exception(P);
13+
} catch (std::exception const &E) {
14+
std::cerr << "Caught async SYCL exception: " << E.what() << std::endl;
15+
}
16+
}
17+
};
18+
19+
cl::sycl::queue Q(AsyncHandler);
20+
21+
constexpr size_t Size = 10;
22+
const int ReferenceData[Size] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
23+
24+
cl::sycl::buffer<int> Buf(Size);
25+
26+
Q.submit([&](cl::sycl::handler &CGH) {
27+
auto Acc = Buf.get_access<cl::sycl::access::mode::write>(CGH);
28+
CGH.copy(ReferenceData, Acc);
29+
});
30+
31+
Q.wait_and_throw();
32+
33+
auto Acc = Buf.get_access<cl::sycl::access::mode::read>();
34+
for (size_t I = 0; I < Size; ++I) {
35+
if (ReferenceData[I] != Acc[I]) {
36+
std::cerr << "Incorrect result, got: " << Acc[I]
37+
<< ", expected: " << ReferenceData[I] << std::endl;
38+
return 1;
39+
}
40+
}
41+
42+
int CopybackData[Size] = { 0 };
43+
Q.submit([&](cl::sycl::handler &CGH) {
44+
auto Acc = Buf.get_access<cl::sycl::access::mode::read>(CGH);
45+
CGH.copy(Acc, CopybackData);
46+
});
47+
48+
Q.wait_and_throw();
49+
50+
for (size_t I = 0; I < Size; ++I) {
51+
if (ReferenceData[I] != CopybackData[I]) {
52+
std::cerr << "Incorrect result, got: " << Acc[I]
53+
<< ", expected: " << ReferenceData[I] << std::endl;
54+
return 1;
55+
}
56+
}
57+
58+
return 0;
59+
}

0 commit comments

Comments
 (0)