From 1f51c70e7e0dc0c51d643231105de708924022c3 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Wed, 17 Aug 2022 06:17:29 -0400 Subject: [PATCH 1/2] [SYCL] Add missing sycl::span constructor Fixed a compilation issue with fully specialized sycl::span. --- sycl/include/sycl/sycl_span.hpp | 9 +++++++++ sycl/test/basic_tests/span.cpp | 7 +++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sycl/include/sycl/sycl_span.hpp b/sycl/include/sycl/sycl_span.hpp index 84b5b8eeeeba4..b7790fdc4891d 100644 --- a/sycl/include/sycl/sycl_span.hpp +++ b/sycl/include/sycl/sycl_span.hpp @@ -217,6 +217,15 @@ template class _SYCL_SPAN_TEMPLATE_VIS span { constexpr span(const span &) noexcept = default; constexpr span &operator=(const span &) noexcept = default; + template + _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span( + element_type (&__arr)[_Sz]) + : __data{__arr} { + (void)_Sz; + _SYCL_SPAN_ASSERT(_Extent == _Sz, + "size mismatch in span's constructor (&_arr)[_Sz]"); + } + _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr} { diff --git a/sycl/test/basic_tests/span.cpp b/sycl/test/basic_tests/span.cpp index ae2a13099b8fb..e2f958d9289d8 100644 --- a/sycl/test/basic_tests/span.cpp +++ b/sycl/test/basic_tests/span.cpp @@ -28,10 +28,9 @@ int main() { sycl::span fromIntVec{vec}; // fully specialized - // TODO: fix fully specialized span from array declaration support - // sycl::span fullSpecArray{arr}; - // sycl::span fullSpecConstArray{constArr}; + sycl::span fullSpecArray{arr}; + sycl::span fullSpecConstArray{constArr}; sycl::span fullSpecVecArray{vec}; return 0; -} \ No newline at end of file +} From 00c95b42d5fa7fcc9b8cf929ce76d16e713dab31 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Wed, 17 Aug 2022 09:03:58 -0400 Subject: [PATCH 2/2] Fix extent deduction for unspecialized sycl::span --- sycl/include/sycl/sycl_span.hpp | 5 ++--- sycl/test/basic_tests/span.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sycl/include/sycl/sycl_span.hpp b/sycl/include/sycl/sycl_span.hpp index b7790fdc4891d..a87ea835b0811 100644 --- a/sycl/include/sycl/sycl_span.hpp +++ b/sycl/include/sycl/sycl_span.hpp @@ -618,10 +618,9 @@ as_writable_bytes(span<_Tp, _Extent> __s) noexcept // Deduction guides -// array arg deduction guide. dynamic_extent arg used to select -// the correct template. The _Sz will be used for the __size of the span. +// array arg deduction guide template -span(_Tp (&)[_Sz]) -> span<_Tp, dynamic_extent>; +span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>; template span(std::array<_Tp, _Sz> &) -> span<_Tp, _Sz>; diff --git a/sycl/test/basic_tests/span.cpp b/sycl/test/basic_tests/span.cpp index e2f958d9289d8..634ed0085227e 100644 --- a/sycl/test/basic_tests/span.cpp +++ b/sycl/test/basic_tests/span.cpp @@ -32,5 +32,14 @@ int main() { sycl::span fullSpecConstArray{constArr}; sycl::span fullSpecVecArray{vec}; + // check that the extent is deduced correctly + static_assert(decltype(fromArray)::extent == decltype(fullSpecArray)::extent, + "extent doesn't match between unspecialized and fully " + "specialized span from array"); + static_assert(decltype(fromConstArray)::extent == + decltype(fullSpecConstArray)::extent, + "extent doesn't match between unspecialized and fully " + "specialized span from const array"); + return 0; }