Skip to content

Commit 6e02880

Browse files
authored
[SYCL] Mark sycl::marray device copyable (intel#4427)
sycl::marray is device copyable if the element type is device copyable. Also test was added to verify that the following types are device copyable: - sycl::marray<T> when T is device copyable; - sycl::vec<T> (all supported element types are device copyable); - sycl::id; - sycl::range.
1 parent f5c838c commit 6e02880

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

sycl/include/CL/sycl/types.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646
#error "SYCL device compiler is built without ext_vector_type support"
4747
#endif // __HAS_EXT_VECTOR_TYPE__
4848

49-
#include <CL/sycl/aliases.hpp>
5049
#include <CL/sycl/access/access.hpp>
50+
#include <CL/sycl/aliases.hpp>
5151
#include <CL/sycl/detail/common.hpp>
5252
#include <CL/sycl/detail/helpers.hpp>
5353
#include <CL/sycl/detail/type_traits.hpp>
5454
#include <CL/sycl/half_type.hpp>
55+
#include <CL/sycl/marray.hpp>
5556
#include <CL/sycl/multi_ptr.hpp>
5657

5758
#include <array>
@@ -2333,6 +2334,12 @@ struct is_device_copyable<std::tuple<T, Ts...>>
23332334
: detail::bool_constant<is_device_copyable<T>::value &&
23342335
is_device_copyable<std::tuple<Ts...>>::value> {};
23352336

2337+
// marray is device copyable if element type is device copyable
2338+
template <typename T, std::size_t N>
2339+
struct is_device_copyable<sycl::marray<T, N>,
2340+
std::enable_if_t<is_device_copyable<T>::value>>
2341+
: std::true_type {};
2342+
23362343
namespace detail {
23372344
template <typename T, typename = void>
23382345
struct IsDeprecatedDeviceCopyable : std::false_type {};

sycl/test/basic_tests/is_device_copyable.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,20 @@ void test() {
6969
BCopyable IamBadButCopyable(1);
7070
C IamAlsoGood;
7171
DCopyable IamAlsoBadButCopyable{0};
72+
marray<int, 5> MarrayForCopyableIsCopyable(0);
73+
range<2> Range{1,2};
74+
id<3> Id{1,2,3};
75+
vec<int, 3> VecForCopyableIsCopyable{3};
7276
queue Q;
7377
Q.single_task<class TestA>([=] {
7478
int A = IamGood.i;
7579
int B = IamBadButCopyable.i;
7680
int C = IamAlsoBadButCopyable.i;
7781
int D = IamAlsoGood.i;
82+
int E = MarrayForCopyableIsCopyable[0];
83+
int F = Range[1];
84+
int G = Id[2];
85+
int H = VecForCopyableIsCopyable[0];
7886
});
7987

8088
Q.single_task<class TestB>(FunctorA{});

sycl/test/basic_tests/is_device_copyable_neg.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ struct FunctorB : public D {
5555
void test() {
5656
A IamBad(1);
5757
B IamAlsoBad{0};
58+
marray<B, 2> MarrayForNotCopyable;
5859
queue Q;
5960
Q.single_task<class TestA>([=] {
6061
int A = IamBad.i;
6162
int B = IamAlsoBad.i;
63+
int MB = MarrayForNotCopyable[0].i;
6264
});
6365

6466
FunctorA FA;
@@ -69,13 +71,16 @@ void test() {
6971
}
7072

7173
// CHECK: static_assert failed due to requirement 'is_device_copyable<A, void>
72-
// CHECK: is_device_copyable_neg.cpp:59:5: note: in instantiation of function
74+
// CHECK: is_device_copyable_neg.cpp:60:5: note: in instantiation of function
7375

7476
// CHECK: static_assert failed due to requirement 'is_device_copyable<B, void>
75-
// CHECK: is_device_copyable_neg.cpp:59:5: note: in instantiation of function
77+
// CHECK: is_device_copyable_neg.cpp:60:5: note: in instantiation of function
78+
79+
// CHECK: static_assert failed due to requirement 'is_device_copyable<sycl::marray<B, 2>, void>
80+
// CHECK: is_device_copyable_neg.cpp:60:5: note: in instantiation of function
7681

7782
// CHECK: static_assert failed due to requirement 'is_device_copyable<C, void>
78-
// CHECK: is_device_copyable_neg.cpp:65:5: note: in instantiation of function
83+
// CHECK: is_device_copyable_neg.cpp:67:5: note: in instantiation of function
7984

8085
// CHECK: static_assert failed due to requirement 'is_device_copyable<D, void>
81-
// CHECK: is_device_copyable_neg.cpp:68:5: note: in instantiation of function
86+
// CHECK: is_device_copyable_neg.cpp:70:5: note: in instantiation of function

0 commit comments

Comments
 (0)