@@ -522,6 +522,79 @@ class __SYCL_EXPORT handler {
522
522
return true ;
523
523
}
524
524
525
+ #ifndef __SYCL_DEVICE_ONLY__
526
+ // / Copies the content of memory object accessed by Src into the memory
527
+ // / pointed by Dst.
528
+ // /
529
+ // / \param Src is a source SYCL accessor.
530
+ // / \param Dst is a pointer to destination memory.
531
+ template <typename TSrc, typename TDst, int Dim, access::mode AccMode,
532
+ access::target AccTarget, access::placeholder IsPH>
533
+ detail::enable_if_t <(Dim > 0 )>
534
+ copyAccToPtrHost (accessor<TSrc, Dim, AccMode, AccTarget, IsPH> Src,
535
+ TDst *Dst) {
536
+ range<Dim> Range = Src.get_range ();
537
+ parallel_for<class __copyAcc2Ptr <TSrc, TDst, Dim, AccMode, AccTarget, IsPH>>
538
+ (Range, [=](id<Dim> Index) {
539
+ size_t LinearIndex = Index[0 ];
540
+ for (int I = 1 ; I < Dim; ++I)
541
+ LinearIndex += Range[I] * Index[I];
542
+ (reinterpret_cast <TSrc *>(Dst))[LinearIndex] = Src[Index];
543
+ });
544
+ }
545
+
546
+ // / Copies 1 element accessed by 0-dimensional accessor Src into the memory
547
+ // / pointed by Dst.
548
+ // /
549
+ // / \param Src is a source SYCL accessor.
550
+ // / \param Dst is a pointer to destination memory.
551
+ template <typename TSrc, typename TDst, int Dim, access::mode AccMode,
552
+ access::target AccTarget, access::placeholder IsPH>
553
+ detail::enable_if_t <Dim == 0 >
554
+ copyAccToPtrHost (accessor<TSrc, Dim, AccMode, AccTarget, IsPH> Src,
555
+ TDst *Dst) {
556
+ single_task<class __copyAcc2Ptr <TSrc, TDst, Dim, AccMode, AccTarget, IsPH>>
557
+ ([=]() {
558
+ *Dst = readFromFirstAccElement (Src);
559
+ });
560
+ }
561
+
562
+ // / Copies the memory pointed by Src into the memory accessed by Dst.
563
+ // /
564
+ // / \param Src is a pointer to source memory.
565
+ // / \param Dst is a destination SYCL accessor.
566
+ template <typename TSrc, typename TDst, int Dim, access::mode AccMode,
567
+ access::target AccTarget, access::placeholder IsPH>
568
+ detail::enable_if_t <(Dim > 0 )>
569
+ copyPtrToAccHost (TDst *Src,
570
+ accessor<TSrc, Dim, AccMode, AccTarget, IsPH> Dst) {
571
+ range<Dim> Range = Dst.get_range ();
572
+ parallel_for<class __copyPtr2Acc <TSrc, TDst, Dim, AccMode, AccTarget, IsPH>>
573
+ (Range, [=](id<Dim> Index) {
574
+ size_t LinearIndex = Index[0 ];
575
+ for (int I = 1 ; I < Dim; ++I)
576
+ LinearIndex += Range[I] * Index[I];
577
+ Dst[Index] = (reinterpret_cast <TDst *>(Src))[LinearIndex];
578
+ });
579
+ }
580
+
581
+ // / Copies 1 element pointed by Src to memory accessed by 0-dimensional
582
+ // / accessor Dst.
583
+ // /
584
+ // / \param Src is a pointer to source memory.
585
+ // / \param Dst is a destination SYCL accessor.
586
+ template <typename TSrc, typename TDst, int Dim, access::mode AccMode,
587
+ access::target AccTarget, access::placeholder IsPH>
588
+ detail::enable_if_t <Dim == 0 >
589
+ copyPtrToAccHost (TDst *Src,
590
+ accessor<TSrc, Dim, AccMode, AccTarget, IsPH> Dst) {
591
+ single_task<class __copyPtr2Acc <TSrc, TDst, Dim, AccMode, AccTarget, IsPH>>
592
+ ([=]() {
593
+ writeToFirstAccElement (Dst, *Src);
594
+ });
595
+ }
596
+ #endif // __SYCL_DEVICE_ONLY__
597
+
525
598
constexpr static bool isConstOrGlobal (access::target AccessTarget) {
526
599
return AccessTarget == access::target::global_buffer ||
527
600
AccessTarget == access::target::constant_buffer;
@@ -1206,7 +1279,7 @@ class __SYCL_EXPORT handler {
1206
1279
1207
1280
// Explicit copy operations API
1208
1281
1209
- // / Copies the contents of memory object accessed by Src into the memory
1282
+ // / Copies the content of memory object accessed by Src into the memory
1210
1283
// / pointed by Dst.
1211
1284
// /
1212
1285
// / Source must have at least as many bytes as the range accessed by Dst.
@@ -1228,7 +1301,7 @@ class __SYCL_EXPORT handler {
1228
1301
copy (Src, RawDstPtr);
1229
1302
}
1230
1303
1231
- // / Copies the contents of memory pointed by Src into the memory object
1304
+ // / Copies the content of memory pointed by Src into the memory object
1232
1305
// / accessed by Dst.
1233
1306
// /
1234
1307
// / Source must have at least as many bytes as the range accessed by Dst.
@@ -1251,14 +1324,13 @@ class __SYCL_EXPORT handler {
1251
1324
copy (RawSrcPtr, Dst);
1252
1325
}
1253
1326
1254
- // / Copies the contents of memory object accessed by Src into the memory
1327
+ // / Copies the content of memory object accessed by Src into the memory
1255
1328
// / pointed by Dst.
1256
1329
// /
1257
1330
// / Source must have at least as many bytes as the range accessed by Dst.
1258
1331
// /
1259
1332
// / \param Src is a source SYCL accessor.
1260
1333
// / \param Dst is a pointer to destination memory.
1261
- // TODO: support 0-dimensional and atomic accessors.
1262
1334
template <typename T_Src, typename T_Dst, int Dims, access::mode AccessMode,
1263
1335
access::target AccessTarget,
1264
1336
access::placeholder IsPlaceholder = access::placeholder::false_t >
@@ -1270,17 +1342,8 @@ class __SYCL_EXPORT handler {
1270
1342
#ifndef __SYCL_DEVICE_ONLY__
1271
1343
if (MIsHost) {
1272
1344
// TODO: Temporary implementation for host. Should be handled by memory
1273
- // manger.
1274
- range<Dims> Range = Src.get_range ();
1275
- parallel_for< class __copyAcc2Ptr < T_Src, T_Dst, Dims, AccessMode,
1276
- AccessTarget, IsPlaceholder>>
1277
- (Range, [=](id<Dims> Index) {
1278
- size_t LinearIndex = Index[0 ];
1279
- for (int I = 1 ; I < Dims; ++I)
1280
- LinearIndex += Range[I] * Index[I];
1281
- ((T_Src *)Dst)[LinearIndex] = Src[Index];
1282
- });
1283
-
1345
+ // manager.
1346
+ copyAccToPtrHost (Src, Dst);
1284
1347
return ;
1285
1348
}
1286
1349
#endif
@@ -1297,14 +1360,13 @@ class __SYCL_EXPORT handler {
1297
1360
MAccStorage.push_back (std::move (AccImpl));
1298
1361
}
1299
1362
1300
- // / Copies the contents of memory pointed by Src into the memory object
1363
+ // / Copies the content of memory pointed by Src into the memory object
1301
1364
// / accessed by Dst.
1302
1365
// /
1303
1366
// / Source must have at least as many bytes as the range accessed by Dst.
1304
1367
// /
1305
1368
// / \param Src is a pointer to source memory.
1306
1369
// / \param Dst is a destination SYCL accessor.
1307
- // TODO: support 0-dimensional and atomic accessors.
1308
1370
template <typename T_Src, typename T_Dst, int Dims, access::mode AccessMode,
1309
1371
access::target AccessTarget,
1310
1372
access::placeholder IsPlaceholder = access::placeholder::false_t >
@@ -1317,17 +1379,8 @@ class __SYCL_EXPORT handler {
1317
1379
#ifndef __SYCL_DEVICE_ONLY__
1318
1380
if (MIsHost) {
1319
1381
// TODO: Temporary implementation for host. Should be handled by memory
1320
- // manger.
1321
- range<Dims> Range = Dst.get_range ();
1322
- parallel_for< class __copyPtr2Acc < T_Src, T_Dst, Dims, AccessMode,
1323
- AccessTarget, IsPlaceholder>>
1324
- (Range, [=](id<Dims> Index) {
1325
- size_t LinearIndex = Index[0 ];
1326
- for (int I = 1 ; I < Dims; ++I)
1327
- LinearIndex += Range[I] * Index[I];
1328
-
1329
- Dst[Index] = ((T_Dst *)Src)[LinearIndex];
1330
- });
1382
+ // manager.
1383
+ copyPtrToAccHost (Src, Dst);
1331
1384
return ;
1332
1385
}
1333
1386
#endif
@@ -1344,7 +1397,7 @@ class __SYCL_EXPORT handler {
1344
1397
MAccStorage.push_back (std::move (AccImpl));
1345
1398
}
1346
1399
1347
- // / Copies the contents of memory object accessed by Src to the memory
1400
+ // / Copies the content of memory object accessed by Src to the memory
1348
1401
// / object accessed by Dst.
1349
1402
// /
1350
1403
// / Dst must have at least as many bytes as the range accessed by Src.
0 commit comments