@@ -273,9 +273,16 @@ class accessor :
273
273
using PtrType = typename detail::PtrValueType<DataT, AS>::type *;
274
274
275
275
template <int Dims = Dimensions> size_t getLinearIndex (id<Dims> Id) const {
276
+
277
+ #ifdef __SYCL_DEVICE_ONLY__
278
+ // Pointer is already adjusted for 1D case.
279
+ if (Dimensions == 1 )
280
+ return Id[0 ];
281
+ #endif // __SYCL_DEVICE_ONLY__
282
+
276
283
size_t Result = 0 ;
277
284
for (int I = 0 ; I < Dims; ++I)
278
- Result = Result * getOrigRange ()[I] + get_offset ()[I] + Id[I];
285
+ Result = Result * getOrigRange ()[I] + getOffset ()[I] + Id[I];
279
286
return Result;
280
287
}
281
288
@@ -301,10 +308,12 @@ class accessor :
301
308
getRange ()[I] = AccessRange[I];
302
309
getOrigRange ()[I] = MemRange[I];
303
310
}
311
+ // In case of 1D buffer, adjust pointer during initialization rather
312
+ // then each time in operator[] or get_pointer functions.
313
+ if (1 == AdjustedDim)
314
+ MData += Offset[0 ];
304
315
}
305
316
306
- void *getPtr () { return MData; }
307
-
308
317
PtrType getQualifiedPtr () const { return MData; }
309
318
#else
310
319
@@ -466,7 +475,8 @@ class accessor :
466
475
template <int Dims = Dimensions,
467
476
typename = enable_if_t <IsAccessAnyWrite && Dims == 0 >>
468
477
operator RefType () const {
469
- return *(getQualifiedPtr () + get_offset ()[0 ]);
478
+ const size_t LinearIndex = getLinearIndex (id<Dimensions>());
479
+ return *(getQualifiedPtr () + LinearIndex);
470
480
}
471
481
472
482
template <int Dims = Dimensions,
@@ -479,13 +489,15 @@ class accessor :
479
489
template <int Dims = Dimensions,
480
490
typename = enable_if_t <IsAccessAnyWrite && Dims == 1 >>
481
491
RefType operator [](size_t Index) const {
482
- return getQualifiedPtr ()[Index + get_offset ()[0 ]];
492
+ const size_t LinearIndex = getLinearIndex (id<Dimensions>(Index));
493
+ return getQualifiedPtr ()[LinearIndex];
483
494
}
484
495
485
496
template <int Dims = Dimensions,
486
497
typename = enable_if_t <IsAccessReadOnly && Dims == 0 >>
487
498
operator DataT () const {
488
- return *(getQualifiedPtr () + get_offset ()[0 ]);
499
+ const size_t LinearIndex = getLinearIndex (id<AdjustedDim>());
500
+ return *(getQualifiedPtr () + LinearIndex);
489
501
}
490
502
491
503
template <int Dims = Dimensions,
@@ -498,14 +510,17 @@ class accessor :
498
510
template <int Dims = Dimensions,
499
511
typename = enable_if_t <IsAccessReadOnly && Dims == 1 >>
500
512
DataT operator [](size_t Index) const {
501
- return getQualifiedPtr ()[Index + get_offset ()[0 ]];
513
+ const size_t LinearIndex = getLinearIndex (id<Dimensions>(Index));
514
+ return getQualifiedPtr ()[LinearIndex];
502
515
}
503
516
504
517
template <
505
518
int Dims = Dimensions,
506
519
typename = enable_if_t <AccessMode == access::mode::atomic && Dims == 0 >>
507
520
operator atomic<DataT, AS>() const {
508
- return atomic<DataT, AS>(multi_ptr<DataT, AS>(getQualifiedPtr ()));
521
+ const size_t LinearIndex = getLinearIndex (id<AdjustedDim>());
522
+ return atomic<DataT, AS>(
523
+ multi_ptr<DataT, AS>(getQualifiedPtr () + LinearIndex));
509
524
}
510
525
511
526
template <
@@ -521,14 +536,15 @@ class accessor :
521
536
int Dims = Dimensions,
522
537
typename = enable_if_t <AccessMode == access::mode::atomic && Dims == 1 >>
523
538
atomic<DataT, AS> operator [](size_t Index) const {
539
+ const size_t LinearIndex = getLinearIndex (id<AdjustedDim>(Index));
524
540
return atomic<DataT, AS>(
525
- multi_ptr<DataT, AS>(getQualifiedPtr () + Index + get_offset ()[ 0 ] ));
541
+ multi_ptr<DataT, AS>(getQualifiedPtr () + LinearIndex ));
526
542
}
527
543
528
544
template <int Dims = Dimensions, typename = enable_if_t <(Dims > 1 )>>
529
545
typename AccessorCommonT::template AccessorSubscript<Dims - 1 >
530
546
operator [](size_t Index) const {
531
- return AccessorSubscript<Dims - 1 >(*this , Index + get_offset ()[ 0 ] );
547
+ return AccessorSubscript<Dims - 1 >(*this , Index);
532
548
}
533
549
534
550
template <
0 commit comments