From 87524a959e6d9f29f1d1889e022c57108e5a2e0f Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Wed, 3 Nov 2021 17:46:06 +0300 Subject: [PATCH 1/7] [SYCL] Make sycl::marray trivially copyable --- sycl/include/CL/sycl/marray.hpp | 19 +++---------------- sycl/include/CL/sycl/types.hpp | 6 ------ 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/sycl/include/CL/sycl/marray.hpp b/sycl/include/CL/sycl/marray.hpp index fa3ad0d1b0462..6bc2c7bfffe47 100644 --- a/sycl/include/CL/sycl/marray.hpp +++ b/sycl/include/CL/sycl/marray.hpp @@ -66,17 +66,9 @@ template class marray { typename = typename std::enable_if::type> constexpr marray(const ArgTN &... Args) : MData{Args...} {} - constexpr marray(const marray &Rhs) { - for (std::size_t I = 0; I < NumElements; ++I) { - MData[I] = Rhs.MData[I]; - } - } + constexpr marray(const marray &Rhs) = default; - constexpr marray(marray &&Rhs) { - for (std::size_t I = 0; I < NumElements; ++I) { - MData[I] = Rhs.MData[I]; - } - } + constexpr marray(marray &&Rhs) = default; // Available only when: NumElements == 1 template class marray { const_reference operator[](std::size_t index) const { return MData[index]; } - marray &operator=(const marray &Rhs) { - for (std::size_t I = 0; I < NumElements; ++I) { - MData[I] = Rhs.MData[I]; - } - return *this; - } + marray &operator=(const marray &Rhs) = default; // broadcasting operator marray &operator=(const Type &Rhs) { diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index 5ec1c9325c79a..4bfa5eb146e4c 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -2414,12 +2414,6 @@ struct is_device_copyable> : detail::bool_constant::value && is_device_copyable>::value> {}; -// marray is device copyable if element type is device copyable -template -struct is_device_copyable, - std::enable_if_t::value>> - : std::true_type {}; - namespace detail { template struct IsDeprecatedDeviceCopyable : std::false_type {}; From aad02a42c71e113c3b39581aedac336136fbaab1 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Mon, 8 Nov 2021 11:31:39 +0300 Subject: [PATCH 2/7] [SYCL] Add a test for marray's copy constructor --- sycl/test/basic_tests/SYCL-2020-spec-constants.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp b/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp index 6ea415cfe04a7..1539cab139e6a 100644 --- a/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp +++ b/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp @@ -38,6 +38,8 @@ constexpr sycl::specialization_id uint64_id(8); constexpr sycl::specialization_id float_id(10.0); constexpr sycl::specialization_id double_id(11.0); constexpr sycl::marray ma; +constexpr sycl::marray mb(ma); +constexpr sycl::marray mc = ma; constexpr sycl::specialization_id> marray_id5(11.0); constexpr sycl::specialization_id> marray_id1(11.0); constexpr sycl::specialization_id> marray_id_def(ma); From 73077200b0312079cb59e7dbea0ac01f7f15527c Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Wed, 17 Nov 2021 11:23:35 +0300 Subject: [PATCH 3/7] [SYCL] Update tests for sycl::marray --- sycl/test/basic_tests/SYCL-2020-spec-constants.cpp | 2 -- sycl/test/basic_tests/marray/marray.cpp | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp b/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp index 138f5efbb1a9e..16b2cbf45bac7 100644 --- a/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp +++ b/sycl/test/basic_tests/SYCL-2020-spec-constants.cpp @@ -38,8 +38,6 @@ constexpr sycl::specialization_id uint64_id(8); constexpr sycl::specialization_id float_id(10.0); constexpr sycl::specialization_id double_id(11.0); constexpr sycl::marray ma; -constexpr sycl::marray mb(ma); -constexpr sycl::marray mc = ma; constexpr sycl::specialization_id> marray_id5(11.0); constexpr sycl::specialization_id> marray_id1(11.0); constexpr sycl::specialization_id> marray_id_def(ma); diff --git a/sycl/test/basic_tests/marray/marray.cpp b/sycl/test/basic_tests/marray/marray.cpp index 148b6958691fc..a4c21835faf8a 100755 --- a/sycl/test/basic_tests/marray/marray.cpp +++ b/sycl/test/basic_tests/marray/marray.cpp @@ -94,5 +94,10 @@ int main() { b___ = !mint3{0, 1, 2}; assert(b___[0] == true && b___[1] == false && b___[2] == false); + // check copyability + constexpr sycl::marray ma; + constexpr sycl::marray mb(ma); + constexpr sycl::marray mc = ma; + return 0; } From 897b199c10a4386671999add68c8a30b97d7c49f Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Wed, 17 Nov 2021 16:50:17 +0300 Subject: [PATCH 4/7] [SYCL] Test passing structures with sycl::marray to kernel --- sycl/test/basic_tests/valid_kernel_args.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sycl/test/basic_tests/valid_kernel_args.cpp b/sycl/test/basic_tests/valid_kernel_args.cpp index e6bc307ddd0e7..1f05990b0ed49 100644 --- a/sycl/test/basic_tests/valid_kernel_args.cpp +++ b/sycl/test/basic_tests/valid_kernel_args.cpp @@ -23,6 +23,10 @@ struct SomeStructure { } v; }; +struct SomeMarrayStructure { + cl::sycl::marray points; +}; + #define CHECK_PASSING_TO_KERNEL_BY_VALUE(Type) \ static_assert(std::is_standard_layout::value, \ "Is not standard layouti type."); \ @@ -34,3 +38,4 @@ CHECK_PASSING_TO_KERNEL_BY_VALUE(int) CHECK_PASSING_TO_KERNEL_BY_VALUE(cl::sycl::cl_uchar4) CHECK_PASSING_TO_KERNEL_BY_VALUE(SomeStructure) #endif +CHECK_PASSING_TO_KERNEL_BY_VALUE(SomeMarrayStructure) From 4dab8adc2935c4c297f12dd715a2a30deb8b7b49 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Thu, 18 Nov 2021 10:02:50 +0300 Subject: [PATCH 5/7] [SYCL] Mark sycl::marray as device copyable if T is device copyable sycl::marray is device copyable if element type is device copyable and it is also not trivially copyable (if the element type is trivially copyable, the marray is device copyable by default). The tests are also added. --- sycl/include/CL/sycl/types.hpp | 9 +++++++++ sycl/test/basic_tests/marray/marray.cpp | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index 46110d33a4cab..5bb77ec0b4372 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -2414,6 +2414,15 @@ struct is_device_copyable> : detail::bool_constant::value && is_device_copyable>::value> {}; +// marray is device copyable if element type is device copyable and it is also +// not trivially copyable (if the element type is trivially copyable, the marray +// is device copyable by default). +template +struct is_device_copyable< + sycl::marray, std::enable_if_t::value && + !std::is_trivially_copyable::value>> + : std::true_type {}; + // vec is device copyable on host, on device vec is trivially copyable // and therefore is device copyable too. #ifndef __SYCL_DEVICE_ONLY__ diff --git a/sycl/test/basic_tests/marray/marray.cpp b/sycl/test/basic_tests/marray/marray.cpp index a4c21835faf8a..89ea2421f7165 100755 --- a/sycl/test/basic_tests/marray/marray.cpp +++ b/sycl/test/basic_tests/marray/marray.cpp @@ -99,5 +99,21 @@ int main() { constexpr sycl::marray mb(ma); constexpr sycl::marray mc = ma; + // check trivially copyability + struct Copyable { + int a; + double b; + const char *name; + }; + + static_assert(std::is_trivially_copyable>::value, + "sycl::marray is not trivially copyable type"); + static_assert(sycl::is_device_copyable, 5>>::value, + "sycl::marray, 5> is not device copyable type"); + static_assert(!std::is_trivially_copyable, 5>>::value, + "sycl::marray, 5> is trivially copyable type"); + static_assert(!sycl::is_device_copyable>::value, + "sycl::marray is device copyable type"); + return 0; } From ff22be780e58fc970b9a463005dd111be695939f Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Thu, 18 Nov 2021 10:07:43 +0300 Subject: [PATCH 6/7] [SYCL][NFC] Fix formatting issues --- sycl/test/basic_tests/marray/marray.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sycl/test/basic_tests/marray/marray.cpp b/sycl/test/basic_tests/marray/marray.cpp index 89ea2421f7165..eca6a1a81f5b7 100755 --- a/sycl/test/basic_tests/marray/marray.cpp +++ b/sycl/test/basic_tests/marray/marray.cpp @@ -110,8 +110,9 @@ int main() { "sycl::marray is not trivially copyable type"); static_assert(sycl::is_device_copyable, 5>>::value, "sycl::marray, 5> is not device copyable type"); - static_assert(!std::is_trivially_copyable, 5>>::value, - "sycl::marray, 5> is trivially copyable type"); + static_assert( + !std::is_trivially_copyable, 5>>::value, + "sycl::marray, 5> is trivially copyable type"); static_assert(!sycl::is_device_copyable>::value, "sycl::marray is device copyable type"); From 301d6fd5d4c51df541cda586d7586e434fe8b920 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Thu, 18 Nov 2021 10:42:25 +0300 Subject: [PATCH 7/7] [SYCL] Update tests for sycl::marray --- sycl/test/basic_tests/marray/marray.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sycl/test/basic_tests/marray/marray.cpp b/sycl/test/basic_tests/marray/marray.cpp index eca6a1a81f5b7..1c5debd1fdd48 100755 --- a/sycl/test/basic_tests/marray/marray.cpp +++ b/sycl/test/basic_tests/marray/marray.cpp @@ -108,13 +108,17 @@ int main() { static_assert(std::is_trivially_copyable>::value, "sycl::marray is not trivially copyable type"); + static_assert( + !std::is_trivially_copyable>::value, + "sycl::marray is trivially copyable type"); + + // check device copyability static_assert(sycl::is_device_copyable, 5>>::value, "sycl::marray, 5> is not device copyable type"); - static_assert( - !std::is_trivially_copyable, 5>>::value, - "sycl::marray, 5> is trivially copyable type"); static_assert(!sycl::is_device_copyable>::value, "sycl::marray is device copyable type"); return 0; + + return 0; }