Skip to content

[SYCL] Fix compile error for handler::copy with -fsycl-unnamed-lambda #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sycl/include/CL/sycl/detail/kernel_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ template <class KernelNameType> struct KernelInfo {
static constexpr const char *getName() { return ""; }
};
#else
template <char...> struct KernelInfoData; // Should this have dummy impl?
template <char...> struct KernelInfoData {
static constexpr unsigned getNumParams() { return 0; }
static const kernel_param_desc_t &getParamDesc(int Idx) {
static kernel_param_desc_t Dummy;
return Dummy;
}
static constexpr const char *getName() { return ""; }
};

// C++14 like index_sequence and make_index_sequence
// not needed C++14 members (value_type, size) not implemented
Expand Down
59 changes: 59 additions & 0 deletions sycl/test/regression/copy-with-unnamed-lambda.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda %s -o %t.out
// The purpose of this test is to check that the following code can be
// successfully compiled
#include <CL/sycl.hpp>

#include <iostream>

int main() {
auto AsyncHandler = [](cl::sycl::exception_list EL) {
for (std::exception_ptr const &P : EL) {
try {
std::rethrow_exception(P);
} catch (std::exception const &E) {
std::cerr << "Caught async SYCL exception: " << E.what() << std::endl;
}
}
};

cl::sycl::queue Q(AsyncHandler);

constexpr size_t Size = 10;
const int ReferenceData[Size] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

cl::sycl::buffer<int> Buf(Size);

Q.submit([&](cl::sycl::handler &CGH) {
auto Acc = Buf.get_access<cl::sycl::access::mode::write>(CGH);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. Not sure that we need so heavy test to just check that there is no compile time error.

Copy link
Contributor Author

@AlexeySachkov AlexeySachkov Dec 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed several RUN lines to leave only compilation for this test.
I would like to leave the code as-is to be able to execute it if it necessary to check that it actually works

CGH.copy(ReferenceData, Acc);
});

Q.wait_and_throw();

auto Acc = Buf.get_access<cl::sycl::access::mode::read>();
for (size_t I = 0; I < Size; ++I) {
if (ReferenceData[I] != Acc[I]) {
std::cerr << "Incorrect result, got: " << Acc[I]
<< ", expected: " << ReferenceData[I] << std::endl;
return 1;
}
}

int CopybackData[Size] = { 0 };
Q.submit([&](cl::sycl::handler &CGH) {
auto Acc = Buf.get_access<cl::sycl::access::mode::read>(CGH);
CGH.copy(Acc, CopybackData);
});

Q.wait_and_throw();

for (size_t I = 0; I < Size; ++I) {
if (ReferenceData[I] != CopybackData[I]) {
std::cerr << "Incorrect result, got: " << Acc[I]
<< ", expected: " << ReferenceData[I] << std::endl;
return 1;
}
}

return 0;
}