Skip to content

Commit 589824d

Browse files
authored
[SYCL] Add default constructor to sycl::local_accessor. (#7815)
Adding default constructor to sycl::local_accessor to comply with spec.
1 parent a246cdb commit 589824d

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,12 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
24052405
ConcreteASPtrType MData;
24062406

24072407
#else
2408+
public:
2409+
local_accessor_base()
2410+
: detail::LocalAccessorBaseHost{/*Size*/ sycl::range<3>{0, 0, 0},
2411+
/*Dims*/ 0, /*ElemSize*/ sizeof(DataT)} {}
2412+
2413+
protected:
24082414
local_accessor_base(const detail::LocalAccessorImplPtr &Impl)
24092415
: detail::LocalAccessorBaseHost{Impl} {}
24102416

@@ -2681,7 +2687,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
26812687
size_t byte_size() const noexcept { return this->size() * sizeof(DataT); }
26822688

26832689
size_t max_size() const noexcept {
2684-
return (std::numeric_limits<difference_type>::max)();
2690+
return empty() ? 0 : (std::numeric_limits<difference_type>::max)();
26852691
}
26862692

26872693
bool empty() const noexcept { return this->size() == 0; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_sycl_unittest(AccessorTests OBJECT
22
AccessorIterator.cpp
3+
LocalAccessorDefaultCtor.cpp
34
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <gtest/gtest.h>
2+
#include <sycl/sycl.hpp>
3+
4+
#include <vector>
5+
6+
using namespace sycl;
7+
using AccT = sycl::local_accessor<int, 1>;
8+
9+
TEST(LocalAccessorDefaultCtorTest, LocalAcessorDefaultCtorIsEmpty) {
10+
bool empty;
11+
12+
AccT acc;
13+
empty = acc.empty();
14+
15+
EXPECT_TRUE(empty == true);
16+
}
17+
18+
TEST(LocalAccessorDefaultCtorTest, LocalAcessorDefaultCtorSizeQueries) {
19+
AccT acc;
20+
size_t byte_size;
21+
size_t size;
22+
size_t max_size;
23+
24+
byte_size = acc.byte_size();
25+
size = acc.size();
26+
max_size = acc.max_size();
27+
28+
EXPECT_TRUE(byte_size == 0);
29+
EXPECT_TRUE(size == 0);
30+
EXPECT_TRUE(max_size == 0);
31+
}
32+
33+
TEST(LocalAccessorDefaultCtorTest, LocalAcessorDefaultCtorPtrQueries) {
34+
AccT acc;
35+
36+
// The return values of get_pointer() and get_multi_ptr() are
37+
// unspecified. Just check they can run without any issue.
38+
auto ptr = acc.get_pointer();
39+
(void)ptr;
40+
// TODO: uncomment check with get_multi_ptr() when SYCL 2020 multi_ptr feature
41+
// will be merged
42+
// auto multi_ptr = acc.get_multi_ptr();
43+
// (void)multi_ptr;
44+
}

0 commit comments

Comments
 (0)