Skip to content

Commit 5417473

Browse files
committed
Correction of error in get_range API for local_accessors.
Also optimized other changes done in previous patch to use the converttoArrayofN(Dims, Default_value) method. Signed-off-by: Garima Gupta <[email protected]>
1 parent 6ccaa83 commit 5417473

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,7 @@ class image_accessor
458458

459459
#ifdef __SYCL_DEVICE_ONLY__
460460

461-
size_t get_count() const {
462-
return get_range<Dimensions>().size();
463-
}
461+
size_t get_count() const { return get_range<Dimensions>().size(); }
464462

465463
template <int Dims = Dimensions, typename = detail::enable_if_t<Dims == 1>>
466464
range<1> get_range() const {
@@ -481,27 +479,11 @@ class image_accessor
481479
#else
482480
size_t get_count() const { return MImageCount; };
483481

484-
template <int Dims = Dimensions, typename = detail::enable_if_t<Dims == 1>>
485-
range<1> get_range() const {
486-
range<1> RetRange(0);
487-
RetRange[0] = getAccessRange()[0];
488-
return RetRange;
489-
}
490-
template <int Dims = Dimensions, typename = detail::enable_if_t<Dims == 2>>
491-
range<2> get_range() const {
492-
range<2> RetRange(0, 0);
493-
RetRange[0] = getAccessRange()[0];
494-
RetRange[1] = getAccessRange()[1];
495-
return RetRange;
496-
}
497-
template <int Dims = Dimensions, typename = detail::enable_if_t<Dims == 3>>
498-
range<3> get_range() const {
499-
range<3> RetRange(0, 0, 0);
500-
RetRange[0] = getAccessRange()[0];
501-
RetRange[1] = getAccessRange()[1];
502-
RetRange[2] = getAccessRange()[2];
503-
return RetRange;
482+
template <int Dims = Dimensions, typename = detail::enable_if_t<(Dims > 0)>>
483+
range<Dims> get_range() const {
484+
return detail::convertToArrayOfN<Dims, 1>(getAccessRange());
504485
}
486+
505487
#endif
506488

507489
// Available only when:
@@ -648,15 +630,10 @@ class __image_array_slice__ {
648630
return MBaseAcc.MImageCount / MBaseAcc.getAccessRange()[Dimensions];
649631
}
650632

651-
template <int Dims = Dimensions, typename = detail::enable_if_t<Dims == 1>>
652-
range<1> get_range() const {
653-
return range<1>(MBaseAcc.getAccessRange()[0]);
654-
}
655-
656-
template <int Dims = Dimensions, typename = detail::enable_if_t<Dims == 2>>
657-
range<2> get_range() const {
658-
range<3> BaseAccessRange = MBaseAcc.getAccessRange();
659-
return range<2>(BaseAccessRange[0], BaseAccessRange[1]);
633+
template <int Dims = Dimensions,
634+
typename = detail::enable_if_t<(Dims == 1 || Dims == 2)>>
635+
range<Dims> get_range() const {
636+
return detail::convertToArrayOfN<Dims, 1>(MBaseAcc.getAccessRange());
660637
}
661638

662639
#endif
@@ -1130,8 +1107,8 @@ class accessor<DataT, Dimensions, AccessMode, access::target::local,
11301107
size_t get_count() const { return getSize().size(); }
11311108

11321109
template <int Dims = Dimensions, typename = detail::enable_if_t<(Dims > 0)>>
1133-
range<Dimensions> get_range() const {
1134-
return getSize();
1110+
range<Dims> get_range() const {
1111+
return detail::convertToArrayOfN<Dims, 1>(getSize());
11351112
}
11361113

11371114
template <int Dims = Dimensions,

sycl/test/basic_tests/device_event.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ int test_strideN(size_t stride) {
9595
// that are not supposed to happen, but who knows..., c) to see those
9696
// values at the end if something goes wrong during the ASYNC MEM COPY.
9797
out_ptr[item.get_global_id()[0]] = item.get_global_id()[0] + 700;
98-
98+
// Just a check of get_range() API.
99+
local_acc.get_range();
99100
item.barrier();
100101

101102
// Copy from local memory to global memory.

0 commit comments

Comments
 (0)