Skip to content

Commit 9a16b66

Browse files
author
Ivan Karachun
committed
Added a test and reworked solution
Signed-off-by: Ivan Karachun <[email protected]>
1 parent 7e99986 commit 9a16b66

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

sycl/include/CL/sycl/handler.hpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,7 @@ class __SYCL_EXPORT handler {
386386
static_cast<int>(AccessTarget), ArgIndex);
387387
}
388388

389-
template <typename T> struct ShouldEnableSetArgHelper {
390-
static constexpr bool value = std::is_trivially_copyable<T>::value
391-
#ifdef CL_SYCL_LANGUAGE_VERSION
392-
#if CL_SYCL_LANGUAGE_VERSION <= 121
393-
&& std::is_standard_layout<T>::value
394-
#endif
395-
#endif
396-
;
397-
};
398-
399-
template <typename T>
400-
typename std::enable_if<ShouldEnableSetArgHelper<T>::value, void>::type
401-
setArgHelper(int ArgIndex, T &&Arg) {
389+
template <typename T> void setArgHelper(int ArgIndex, T &&Arg) {
402390
void *StoredArg = (void *)storePlainArg(Arg);
403391

404392
if (!std::is_same<cl_mem, T>::value && std::is_pointer<T>::value) {
@@ -808,13 +796,39 @@ class __SYCL_EXPORT handler {
808796
}
809797
}
810798

799+
template <typename T>
800+
using remove_cv_ref_t =
801+
typename std::remove_cv<detail::remove_reference_t<T>>::type;
802+
803+
template <typename T> struct ShouldEnableSetArg {
804+
static constexpr bool value =
805+
std::is_trivially_copyable<T>::value
806+
#if CL_SYCL_LANGUAGE_VERSION && CL_SYCL_LANGUAGE_VERSION <= 121
807+
&& std::is_standard_layout<T>::value
808+
#endif
809+
|| std::is_same<sampler, remove_cv_ref_t<T>>::value // Sampler
810+
|| (!std::is_same<cl_mem, remove_cv_ref_t<T>>::value &&
811+
std::is_pointer<remove_cv_ref_t<T>>::value) // USM
812+
|| std::is_same<cl_mem, remove_cv_ref_t<T>>::value; // Interop
813+
};
814+
811815
/// Sets argument for OpenCL interoperability kernels.
812816
///
813817
/// Registers Arg passed as argument # ArgIndex.
814818
///
815819
/// \param ArgIndex is a positional number of argument to be set.
816820
/// \param Arg is an argument value to be set.
817-
template <typename T> void set_arg(int ArgIndex, T &&Arg) {
821+
template <typename T>
822+
typename std::enable_if<ShouldEnableSetArg<T>::value, void>::type
823+
set_arg(int ArgIndex, T &&Arg) {
824+
setArgHelper(ArgIndex, std::move(Arg));
825+
}
826+
827+
template <typename DataT, int Dims, access::mode AccessMode,
828+
access::target AccessTarget, access::placeholder IsPlaceholder>
829+
void
830+
set_arg(int ArgIndex,
831+
accessor<DataT, Dims, AccessMode, AccessTarget, IsPlaceholder> Arg) {
818832
setArgHelper(ArgIndex, std::move(Arg));
819833
}
820834

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %clangxx -fsycl -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning -fsyntax-only
2+
3+
#include <CL/sycl.hpp>
4+
5+
struct TriviallyCopyable {
6+
int a;
7+
int b;
8+
};
9+
10+
struct NonTriviallyCopyable {
11+
NonTriviallyCopyable() = default;
12+
NonTriviallyCopyable(NonTriviallyCopyable const &) {}
13+
int a;
14+
int b;
15+
};
16+
17+
struct NonStdLayout {
18+
int a;
19+
20+
private:
21+
int b;
22+
};
23+
24+
int main() {
25+
constexpr size_t size = 1;
26+
cl::sycl::buffer<int> buf(size);
27+
cl::sycl::queue q;
28+
q.submit([&](cl::sycl::handler &h) {
29+
auto global_acc = buf.get_access<cl::sycl::access::mode::write>(h);
30+
cl::sycl::sampler samp(cl::sycl::coordinate_normalization_mode::normalized,
31+
cl::sycl::addressing_mode::clamp,
32+
cl::sycl::filtering_mode::nearest);
33+
cl::sycl::accessor<int, 1, cl::sycl::access::mode::read_write,
34+
cl::sycl::access::target::local>
35+
local_acc({size}, h);
36+
h.set_arg(0, local_acc);
37+
h.set_arg(1, global_acc);
38+
h.set_arg(2, samp);
39+
h.set_arg(3, TriviallyCopyable{});
40+
h.set_arg( // expected-error {{no matching member function for call to 'set_arg'}}
41+
5, NonTriviallyCopyable{});
42+
#ifdef CL_SYCL_LANGUAGE_VERSION &&CL_SYCL_LANGUAGE_VERSION <= 121
43+
h.set_arg( // expected-error {{no matching member function for call to 'set_arg'}}
44+
4, NonStdLayout{});
45+
#endif
46+
});
47+
}

0 commit comments

Comments
 (0)