DPC++ Runtime
Runtime libraries for oneAPI DPC++
cg.hpp
Go to the documentation of this file.
1 //==-------------- CG.hpp - SYCL standard header file ----------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/accessor.hpp> // for AccessorImplHost, AccessorImplPtr
12 #include <sycl/detail/cg_types.hpp> // for ArgDesc, HostTask, HostKernelBase
13 #include <sycl/detail/common.hpp> // for code_location
14 #include <sycl/detail/helpers.hpp> // for context_impl
15 #include <sycl/detail/ur.hpp> // for ur_rect_region_t, ur_rect_offset_t
16 #include <sycl/event.hpp> // for event_impl
17 #include <sycl/exception_list.hpp> // for queue_impl
18 #include <sycl/kernel.hpp> // for kernel_impl
19 #include <sycl/kernel_bundle.hpp> // for kernel_bundle_impl
20 
21 #include <assert.h> // for assert
22 #include <memory> // for shared_ptr, unique_ptr
23 #include <stddef.h> // for size_t
24 #include <stdint.h> // for int32_t
25 #include <string> // for string
26 #include <utility> // for move
27 #include <vector> // for vector
28 
29 namespace sycl {
30 inline namespace _V1 {
31 
32 // Forward declarations
33 class queue;
34 
35 namespace ext::oneapi::experimental::detail {
36 class exec_graph_impl;
37 }
38 
39 namespace detail {
40 
41 class event_impl;
42 using EventImplPtr = std::shared_ptr<event_impl>;
43 
44 class stream_impl;
45 class queue_impl;
46 class kernel_bundle_impl;
47 
48 // The structure represents kernel argument.
49 class ArgDesc {
50 public:
51  ArgDesc(sycl::detail::kernel_param_kind_t Type, void *Ptr, int Size,
52  int Index)
53  : MType(Type), MPtr(Ptr), MSize(Size), MIndex(Index) {}
54 
56  void *MPtr;
57  int MSize;
58  int MIndex;
59 };
60 
61 // The structure represents NDRange - global, local sizes, global offset and
62 // number of dimensions.
63 class NDRDescT {
64  // The method initializes all sizes for dimensions greater than the passed one
65  // to the default values, so they will not affect execution.
66  void setNDRangeLeftover() {
67  for (int I = Dims; I < 3; ++I) {
68  GlobalSize[I] = 1;
69  LocalSize[I] = LocalSize[0] ? 1 : 0;
70  GlobalOffset[I] = 0;
71  NumWorkGroups[I] = 0;
72  }
73  }
74 
75  template <int Dims> static sycl::range<3> padRange(sycl::range<Dims> Range) {
76  if constexpr (Dims == 3) {
77  return Range;
78  } else {
79  sycl::range<3> Res{0, 0, 0};
80  for (int I = 0; I < Dims; ++I)
81  Res[I] = Range[I];
82  return Res;
83  }
84  }
85 
86  template <int Dims> static sycl::id<3> padId(sycl::id<Dims> Id) {
87  if constexpr (Dims == 3) {
88  return Id;
89  } else {
90  sycl::id<3> Res{0, 0, 0};
91  for (int I = 0; I < Dims; ++I)
92  Res[I] = Id[I];
93  return Res;
94  }
95  }
96 
97 public:
98  NDRDescT() = default;
99  NDRDescT(const NDRDescT &Desc) = default;
100  NDRDescT(NDRDescT &&Desc) = default;
101 
102  NDRDescT(sycl::range<3> N, bool SetNumWorkGroups, int DimsArg)
103  : GlobalSize{SetNumWorkGroups ? sycl::range<3>{0, 0, 0} : N},
104  NumWorkGroups{SetNumWorkGroups ? N : sycl::range<3>{0, 0, 0}},
105  Dims{size_t(DimsArg)} {
106  setNDRangeLeftover();
107  }
108 
109  NDRDescT(sycl::range<3> NumWorkItems, sycl::id<3> Offset, int DimsArg)
110  : GlobalSize{NumWorkItems}, GlobalOffset{Offset}, Dims{size_t(DimsArg)} {}
111 
112  NDRDescT(sycl::range<3> NumWorkItems, sycl::range<3> LocalSize,
113  sycl::id<3> Offset, int DimsArg)
114  : GlobalSize{NumWorkItems}, LocalSize{LocalSize}, GlobalOffset{Offset},
115  Dims{size_t(DimsArg)} {
116  setNDRangeLeftover();
117  }
118 
119  template <int Dims_>
120  NDRDescT(sycl::nd_range<Dims_> ExecutionRange, int DimsArg)
121  : NDRDescT(padRange(ExecutionRange.get_global_range()),
122  padRange(ExecutionRange.get_local_range()),
123  padId(ExecutionRange.get_offset()), size_t(DimsArg)) {
124  setNDRangeLeftover();
125  }
126 
127  template <int Dims_>
129  : NDRDescT(ExecutionRange, Dims_) {}
130 
131  template <int Dims_>
133  : NDRDescT(padRange(Range), /*SetNumWorkGroups=*/false, Dims_) {}
134 
136  if (this->Dims != size_t(Dims)) {
137  throw std::runtime_error(
138  "Dimensionality of cluster, global and local ranges must be same");
139  }
140 
141  for (int I = 0; I < 3; ++I)
142  ClusterDimensions[I] = (I < Dims) ? N[I] : 1;
143  }
144 
145  NDRDescT &operator=(const NDRDescT &Desc) = default;
146  NDRDescT &operator=(NDRDescT &&Desc) = default;
147 
148  sycl::range<3> GlobalSize{0, 0, 0};
149  sycl::range<3> LocalSize{0, 0, 0};
150  sycl::id<3> GlobalOffset{0, 0, 0};
154  sycl::range<3> NumWorkGroups{0, 0, 0};
155  sycl::range<3> ClusterDimensions{1, 1, 1};
156  size_t Dims = 0;
157 };
158 
160 class CG {
161 public:
163  StorageInitHelper() = default;
164  StorageInitHelper(std::vector<std::vector<char>> ArgsStorage,
165  std::vector<detail::AccessorImplPtr> AccStorage,
166  std::vector<std::shared_ptr<const void>> SharedPtrStorage,
167  std::vector<AccessorImplHost *> Requirements,
168  std::vector<detail::EventImplPtr> Events)
169  : MArgsStorage(std::move(ArgsStorage)),
170  MAccStorage(std::move(AccStorage)),
171  MSharedPtrStorage(std::move(SharedPtrStorage)),
172  MRequirements(std::move(Requirements)), MEvents(std::move(Events)) {}
175  // The following storages are needed to ensure that arguments won't die
176  // while we are using them.
178  std::vector<std::vector<char>> MArgsStorage;
180  std::vector<detail::AccessorImplPtr> MAccStorage;
182  std::vector<std::shared_ptr<const void>> MSharedPtrStorage;
183 
186  std::vector<AccessorImplHost *> MRequirements;
188  std::vector<detail::EventImplPtr> MEvents;
189  };
190 
192  : MType(Type), MData(std::move(D)) {
193  // Capture the user code-location from Q.submit(), Q.parallel_for()
194  // etc for later use; if code location information is not available,
195  // the file name and function name members will be empty strings
196  if (loc.functionName())
197  MFunctionName = loc.functionName();
198  if (loc.fileName())
199  MFileName = loc.fileName();
200  MLine = loc.lineNumber();
201  MColumn = loc.columnNumber();
202  }
203 
204  CG(CG &&CommandGroup) = default;
205  CG(const CG &CommandGroup) = default;
206 
207  CGType getType() const { return MType; }
208 
209  std::vector<std::vector<char>> &getArgsStorage() {
210  return MData.MArgsStorage;
211  }
212  std::vector<detail::AccessorImplPtr> &getAccStorage() {
213  return MData.MAccStorage;
214  }
215  std::vector<std::shared_ptr<const void>> &getSharedPtrStorage() {
216  return MData.MSharedPtrStorage;
217  }
218 
219  std::vector<AccessorImplHost *> &getRequirements() {
220  return MData.MRequirements;
221  }
222  std::vector<detail::EventImplPtr> &getEvents() { return MData.MEvents; }
223 
224  virtual std::vector<std::shared_ptr<const void>>
226  return {};
227  }
228  virtual void clearAuxiliaryResources() {};
229 
230  virtual ~CG() = default;
231 
232 private:
233  CGType MType;
234  StorageInitHelper MData;
235 
236 public:
237  // Member variables to capture the user code-location
238  // information from Q.submit(), Q.parallel_for() etc
239  // Storage for function name and source file name
240  std::string MFunctionName, MFileName;
241  // Storage for line and column of code location
242  int32_t MLine, MColumn;
243 };
244 
246 class CGExecKernel : public CG {
247 public:
250  std::shared_ptr<HostKernelBase> MHostKernel;
251  std::shared_ptr<detail::kernel_impl> MSyclKernel;
252  std::shared_ptr<detail::kernel_bundle_impl> MKernelBundle;
253  std::vector<ArgDesc> MArgs;
254  std::string MKernelName;
255  std::vector<std::shared_ptr<detail::stream_impl>> MStreams;
256  std::vector<std::shared_ptr<const void>> MAuxiliaryResources;
257  ur_kernel_cache_config_t MKernelCacheConfig;
258  bool MKernelIsCooperative = false;
259  bool MKernelUsesClusterLaunch = false;
260 
261  CGExecKernel(NDRDescT NDRDesc, std::shared_ptr<HostKernelBase> HKernel,
262  std::shared_ptr<detail::kernel_impl> SyclKernel,
263  std::shared_ptr<detail::kernel_bundle_impl> KernelBundle,
264  CG::StorageInitHelper CGData, std::vector<ArgDesc> Args,
265  std::string KernelName,
266  std::vector<std::shared_ptr<detail::stream_impl>> Streams,
267  std::vector<std::shared_ptr<const void>> AuxiliaryResources,
268  CGType Type, ur_kernel_cache_config_t KernelCacheConfig,
269  bool KernelIsCooperative, bool MKernelUsesClusterLaunch,
270  detail::code_location loc = {})
271  : CG(Type, std::move(CGData), std::move(loc)),
272  MNDRDesc(std::move(NDRDesc)), MHostKernel(std::move(HKernel)),
273  MSyclKernel(std::move(SyclKernel)),
274  MKernelBundle(std::move(KernelBundle)), MArgs(std::move(Args)),
275  MKernelName(std::move(KernelName)), MStreams(std::move(Streams)),
276  MAuxiliaryResources(std::move(AuxiliaryResources)),
277  MKernelCacheConfig(std::move(KernelCacheConfig)),
278  MKernelIsCooperative(KernelIsCooperative),
279  MKernelUsesClusterLaunch(MKernelUsesClusterLaunch) {
280  assert(getType() == CGType::Kernel && "Wrong type of exec kernel CG.");
281  }
282 
283  CGExecKernel(const CGExecKernel &CGExec) = default;
284 
285  std::vector<ArgDesc> getArguments() const { return MArgs; }
286  std::string getKernelName() const { return MKernelName; }
287  std::vector<std::shared_ptr<detail::stream_impl>> getStreams() const {
288  return MStreams;
289  }
290 
291  std::vector<std::shared_ptr<const void>>
292  getAuxiliaryResources() const override {
293  return MAuxiliaryResources;
294  }
295  void clearAuxiliaryResources() override { MAuxiliaryResources.clear(); }
296 
297  std::shared_ptr<detail::kernel_bundle_impl> getKernelBundle() {
298  return MKernelBundle;
299  }
300 
301  void clearStreams() { MStreams.clear(); }
302  bool hasStreams() { return !MStreams.empty(); }
303 };
304 
306 class CGCopy : public CG {
307  void *MSrc;
308  void *MDst;
309  std::vector<std::shared_ptr<const void>> MAuxiliaryResources;
310 
311 public:
312  CGCopy(CGType CopyType, void *Src, void *Dst, CG::StorageInitHelper CGData,
313  std::vector<std::shared_ptr<const void>> AuxiliaryResources,
314  detail::code_location loc = {})
315  : CG(CopyType, std::move(CGData), std::move(loc)), MSrc(Src), MDst(Dst),
316  MAuxiliaryResources{AuxiliaryResources} {}
317  void *getSrc() { return MSrc; }
318  void *getDst() { return MDst; }
319 
320  std::vector<std::shared_ptr<const void>>
321  getAuxiliaryResources() const override {
322  return MAuxiliaryResources;
323  }
324  void clearAuxiliaryResources() override { MAuxiliaryResources.clear(); }
325 };
326 
328 class CGFill : public CG {
329 public:
330  std::vector<unsigned char> MPattern;
332 
333  CGFill(std::vector<unsigned char> Pattern, void *Ptr,
335  : CG(CGType::Fill, std::move(CGData), std::move(loc)),
336  MPattern(std::move(Pattern)), MPtr((AccessorImplHost *)Ptr) {}
337  AccessorImplHost *getReqToFill() { return MPtr; }
338 };
339 
341 class CGUpdateHost : public CG {
342  AccessorImplHost *MPtr;
343 
344 public:
346  detail::code_location loc = {})
347  : CG(CGType::UpdateHost, std::move(CGData), std::move(loc)),
348  MPtr((AccessorImplHost *)Ptr) {}
349 
350  AccessorImplHost *getReqToUpdate() { return MPtr; }
351 };
352 
354 class CGCopyUSM : public CG {
355  void *MSrc;
356  void *MDst;
357  size_t MLength;
358 
359 public:
360  CGCopyUSM(void *Src, void *Dst, size_t Length, CG::StorageInitHelper CGData,
361  detail::code_location loc = {})
362  : CG(CGType::CopyUSM, std::move(CGData), std::move(loc)), MSrc(Src),
363  MDst(Dst), MLength(Length) {}
364 
365  void *getSrc() { return MSrc; }
366  void *getDst() { return MDst; }
367  size_t getLength() { return MLength; }
368 };
369 
371 class CGFillUSM : public CG {
372  std::vector<unsigned char> MPattern;
373  void *MDst;
374  size_t MLength;
375 
376 public:
377  CGFillUSM(std::vector<unsigned char> Pattern, void *DstPtr, size_t Length,
379  : CG(CGType::FillUSM, std::move(CGData), std::move(loc)),
380  MPattern(std::move(Pattern)), MDst(DstPtr), MLength(Length) {}
381  void *getDst() { return MDst; }
382  size_t getLength() { return MLength; }
383  const std::vector<unsigned char> &getPattern() { return MPattern; }
384 };
385 
387 class CGPrefetchUSM : public CG {
388  void *MDst;
389  size_t MLength;
390 
391 public:
392  CGPrefetchUSM(void *DstPtr, size_t Length, CG::StorageInitHelper CGData,
393  detail::code_location loc = {})
394  : CG(CGType::PrefetchUSM, std::move(CGData), std::move(loc)),
395  MDst(DstPtr), MLength(Length) {}
396  void *getDst() { return MDst; }
397  size_t getLength() { return MLength; }
398 };
399 
401 class CGAdviseUSM : public CG {
402  void *MDst;
403  size_t MLength;
404  ur_usm_advice_flags_t MAdvice;
405 
406 public:
407  CGAdviseUSM(void *DstPtr, size_t Length, ur_usm_advice_flags_t Advice,
408  CG::StorageInitHelper CGData, CGType Type,
409  detail::code_location loc = {})
410  : CG(Type, std::move(CGData), std::move(loc)), MDst(DstPtr),
411  MLength(Length), MAdvice(Advice) {}
412  void *getDst() { return MDst; }
413  size_t getLength() { return MLength; }
414  ur_usm_advice_flags_t getAdvice() { return MAdvice; }
415 };
416 
417 class CGBarrier : public CG {
418 public:
419  std::vector<detail::EventImplPtr> MEventsWaitWithBarrier;
420 
421  CGBarrier(std::vector<detail::EventImplPtr> EventsWaitWithBarrier,
422  CG::StorageInitHelper CGData, CGType Type,
423  detail::code_location loc = {})
424  : CG(Type, std::move(CGData), std::move(loc)),
425  MEventsWaitWithBarrier(std::move(EventsWaitWithBarrier)) {}
426 };
427 
428 class CGProfilingTag : public CG {
429 public:
431  : CG(CGType::ProfilingTag, std::move(CGData), std::move(loc)) {}
432 };
433 
435 class CGCopy2DUSM : public CG {
436  void *MSrc;
437  void *MDst;
438  size_t MSrcPitch;
439  size_t MDstPitch;
440  size_t MWidth;
441  size_t MHeight;
442 
443 public:
444  CGCopy2DUSM(void *Src, void *Dst, size_t SrcPitch, size_t DstPitch,
445  size_t Width, size_t Height, CG::StorageInitHelper CGData,
446  detail::code_location loc = {})
447  : CG(CGType::Copy2DUSM, std::move(CGData), std::move(loc)), MSrc(Src),
448  MDst(Dst), MSrcPitch(SrcPitch), MDstPitch(DstPitch), MWidth(Width),
449  MHeight(Height) {}
450 
451  void *getSrc() const { return MSrc; }
452  void *getDst() const { return MDst; }
453  size_t getSrcPitch() const { return MSrcPitch; }
454  size_t getDstPitch() const { return MDstPitch; }
455  size_t getWidth() const { return MWidth; }
456  size_t getHeight() const { return MHeight; }
457 };
458 
460 class CGFill2DUSM : public CG {
461  std::vector<unsigned char> MPattern;
462  void *MDst;
463  size_t MPitch;
464  size_t MWidth;
465  size_t MHeight;
466 
467 public:
468  CGFill2DUSM(std::vector<unsigned char> Pattern, void *DstPtr, size_t Pitch,
469  size_t Width, size_t Height, CG::StorageInitHelper CGData,
470  detail::code_location loc = {})
471  : CG(CGType::Fill2DUSM, std::move(CGData), std::move(loc)),
472  MPattern(std::move(Pattern)), MDst(DstPtr), MPitch(Pitch),
473  MWidth(Width), MHeight(Height) {}
474  void *getDst() const { return MDst; }
475  size_t getPitch() const { return MPitch; }
476  size_t getWidth() const { return MWidth; }
477  size_t getHeight() const { return MHeight; }
478  const std::vector<unsigned char> &getPattern() const { return MPattern; }
479 };
480 
482 class CGMemset2DUSM : public CG {
483  char MValue;
484  void *MDst;
485  size_t MPitch;
486  size_t MWidth;
487  size_t MHeight;
488 
489 public:
490  CGMemset2DUSM(char Value, void *DstPtr, size_t Pitch, size_t Width,
491  size_t Height, CG::StorageInitHelper CGData,
492  detail::code_location loc = {})
493  : CG(CGType::Memset2DUSM, std::move(CGData), std::move(loc)),
494  MValue(Value), MDst(DstPtr), MPitch(Pitch), MWidth(Width),
495  MHeight(Height) {}
496  void *getDst() const { return MDst; }
497  size_t getPitch() const { return MPitch; }
498  size_t getWidth() const { return MWidth; }
499  size_t getHeight() const { return MHeight; }
500  char getValue() const { return MValue; }
501 };
502 
504 class CGReadWriteHostPipe : public CG {
505  std::string PipeName;
506  bool Blocking;
507  void *HostPtr;
508  size_t TypeSize;
509  bool IsReadOp;
510 
511 public:
512  CGReadWriteHostPipe(const std::string &Name, bool Block, void *Ptr,
513  size_t Size, bool Read, CG::StorageInitHelper CGData,
514  detail::code_location loc = {})
515  : CG(CGType::ReadWriteHostPipe, std::move(CGData), std::move(loc)),
516  PipeName(Name), Blocking(Block), HostPtr(Ptr), TypeSize(Size),
517  IsReadOp(Read) {}
518 
519  std::string getPipeName() { return PipeName; }
520  void *getHostPtr() { return HostPtr; }
521  size_t getTypeSize() { return TypeSize; }
522  bool isBlocking() { return Blocking; }
523  bool isReadHostPipe() { return IsReadOp; }
524 };
525 
527 class CGCopyToDeviceGlobal : public CG {
528  void *MSrc;
529  void *MDeviceGlobalPtr;
530  bool MIsDeviceImageScoped;
531  size_t MNumBytes;
532  size_t MOffset;
533 
534 public:
535  CGCopyToDeviceGlobal(void *Src, void *DeviceGlobalPtr,
536  bool IsDeviceImageScoped, size_t NumBytes, size_t Offset,
537  CG::StorageInitHelper CGData,
538  detail::code_location loc = {})
539  : CG(CGType::CopyToDeviceGlobal, std::move(CGData), std::move(loc)),
540  MSrc(Src), MDeviceGlobalPtr(DeviceGlobalPtr),
541  MIsDeviceImageScoped(IsDeviceImageScoped), MNumBytes(NumBytes),
542  MOffset(Offset) {}
543 
544  void *getSrc() { return MSrc; }
545  void *getDeviceGlobalPtr() { return MDeviceGlobalPtr; }
546  bool isDeviceImageScoped() { return MIsDeviceImageScoped; }
547  size_t getNumBytes() { return MNumBytes; }
548  size_t getOffset() { return MOffset; }
549 };
550 
552 class CGCopyFromDeviceGlobal : public CG {
553  void *MDeviceGlobalPtr;
554  void *MDest;
555  bool MIsDeviceImageScoped;
556  size_t MNumBytes;
557  size_t MOffset;
558 
559 public:
560  CGCopyFromDeviceGlobal(void *DeviceGlobalPtr, void *Dest,
561  bool IsDeviceImageScoped, size_t NumBytes,
562  size_t Offset, CG::StorageInitHelper CGData,
563  detail::code_location loc = {})
564  : CG(CGType::CopyFromDeviceGlobal, std::move(CGData), std::move(loc)),
565  MDeviceGlobalPtr(DeviceGlobalPtr), MDest(Dest),
566  MIsDeviceImageScoped(IsDeviceImageScoped), MNumBytes(NumBytes),
567  MOffset(Offset) {}
568 
569  void *getDeviceGlobalPtr() { return MDeviceGlobalPtr; }
570  void *getDest() { return MDest; }
571  bool isDeviceImageScoped() { return MIsDeviceImageScoped; }
572  size_t getNumBytes() { return MNumBytes; }
573  size_t getOffset() { return MOffset; }
574 };
576 class CGCopyImage : public CG {
577  void *MSrc;
578  void *MDst;
579  ur_image_desc_t MSrcImageDesc;
580  ur_image_desc_t MDstImageDesc;
581  ur_image_format_t MSrcImageFormat;
582  ur_image_format_t MDstImageFormat;
583  ur_exp_image_copy_flags_t MImageCopyFlags;
584  ur_rect_offset_t MSrcOffset;
585  ur_rect_offset_t MDstOffset;
586  ur_rect_region_t MCopyExtent;
587 
588 public:
589  CGCopyImage(void *Src, void *Dst, ur_image_desc_t SrcImageDesc,
590  ur_image_desc_t DstImageDesc, ur_image_format_t SrcImageFormat,
591  ur_image_format_t DstImageFormat,
592  ur_exp_image_copy_flags_t ImageCopyFlags,
593  ur_rect_offset_t SrcOffset, ur_rect_offset_t DstOffset,
594  ur_rect_region_t CopyExtent, CG::StorageInitHelper CGData,
595  detail::code_location loc = {})
596  : CG(CGType::CopyImage, std::move(CGData), std::move(loc)), MSrc(Src),
597  MDst(Dst), MSrcImageDesc(SrcImageDesc), MDstImageDesc(DstImageDesc),
598  MSrcImageFormat(SrcImageFormat), MDstImageFormat(DstImageFormat),
599  MImageCopyFlags(ImageCopyFlags), MSrcOffset(SrcOffset),
600  MDstOffset(DstOffset), MCopyExtent(CopyExtent) {}
601 
602  void *getSrc() const { return MSrc; }
603  void *getDst() const { return MDst; }
604  ur_image_desc_t getSrcDesc() const { return MSrcImageDesc; }
605  ur_image_desc_t getDstDesc() const { return MDstImageDesc; }
606  ur_image_format_t getSrcFormat() const { return MSrcImageFormat; }
607  ur_image_format_t getDstFormat() const { return MDstImageFormat; }
608  ur_exp_image_copy_flags_t getCopyFlags() const { return MImageCopyFlags; }
609  ur_rect_offset_t getSrcOffset() const { return MSrcOffset; }
610  ur_rect_offset_t getDstOffset() const { return MDstOffset; }
611  ur_rect_region_t getCopyExtent() const { return MCopyExtent; }
612 };
613 
615 class CGSemaphoreWait : public CG {
616  ur_exp_interop_semaphore_handle_t MInteropSemaphoreHandle;
617  std::optional<uint64_t> MWaitValue;
618 
619 public:
620  CGSemaphoreWait(ur_exp_interop_semaphore_handle_t InteropSemaphoreHandle,
621  std::optional<uint64_t> WaitValue,
623  : CG(CGType::SemaphoreWait, std::move(CGData), std::move(loc)),
624  MInteropSemaphoreHandle(InteropSemaphoreHandle), MWaitValue(WaitValue) {
625  }
626 
627  ur_exp_interop_semaphore_handle_t getInteropSemaphoreHandle() const {
628  return MInteropSemaphoreHandle;
629  }
630  std::optional<uint64_t> getWaitValue() const { return MWaitValue; }
631 };
632 
634 class CGSemaphoreSignal : public CG {
635  ur_exp_interop_semaphore_handle_t MInteropSemaphoreHandle;
636  std::optional<uint64_t> MSignalValue;
637 
638 public:
639  CGSemaphoreSignal(ur_exp_interop_semaphore_handle_t InteropSemaphoreHandle,
640  std::optional<uint64_t> SignalValue,
641  CG::StorageInitHelper CGData,
642  detail::code_location loc = {})
643  : CG(CGType::SemaphoreSignal, std::move(CGData), std::move(loc)),
644  MInteropSemaphoreHandle(InteropSemaphoreHandle),
645  MSignalValue(SignalValue) {}
646 
647  ur_exp_interop_semaphore_handle_t getInteropSemaphoreHandle() const {
648  return MInteropSemaphoreHandle;
649  }
650  std::optional<uint64_t> getSignalValue() const { return MSignalValue; }
651 };
652 
654 class CGExecCommandBuffer : public CG {
655 public:
656  ur_exp_command_buffer_handle_t MCommandBuffer;
657  std::shared_ptr<sycl::ext::oneapi::experimental::detail::exec_graph_impl>
659 
661  const ur_exp_command_buffer_handle_t &CommandBuffer,
662  const std::shared_ptr<
664  CG::StorageInitHelper CGData)
665  : CG(CGType::ExecCommandBuffer, std::move(CGData)),
666  MCommandBuffer(CommandBuffer), MExecGraph(ExecGraph) {}
667 };
668 
669 class CGHostTask : public CG {
670 public:
671  std::shared_ptr<HostTask> MHostTask;
672  // queue for host-interop task
673  std::shared_ptr<detail::queue_impl> MQueue;
674  // context for host-interop task
675  std::shared_ptr<detail::context_impl> MContext;
676  std::vector<ArgDesc> MArgs;
677 
678  CGHostTask(std::shared_ptr<HostTask> HostTask,
679  std::shared_ptr<detail::queue_impl> Queue,
680  std::shared_ptr<detail::context_impl> Context,
681  std::vector<ArgDesc> Args, CG::StorageInitHelper CGData,
682  CGType Type, detail::code_location loc = {})
683  : CG(Type, std::move(CGData), std::move(loc)),
684  MHostTask(std::move(HostTask)), MQueue(Queue), MContext(Context),
685  MArgs(std::move(Args)) {}
686 };
687 
688 } // namespace detail
689 } // namespace _V1
690 } // namespace sycl
The file contains implementations of accessor class.
ArgDesc(sycl::detail::kernel_param_kind_t Type, void *Ptr, int Size, int Index)
Definition: cg.hpp:51
sycl::detail::kernel_param_kind_t MType
Definition: cg.hpp:55
"Advise USM" command group class.
Definition: cg.hpp:401
ur_usm_advice_flags_t getAdvice()
Definition: cg.hpp:414
CGAdviseUSM(void *DstPtr, size_t Length, ur_usm_advice_flags_t Advice, CG::StorageInitHelper CGData, CGType Type, detail::code_location loc={})
Definition: cg.hpp:407
std::vector< detail::EventImplPtr > MEventsWaitWithBarrier
Definition: cg.hpp:419
CGBarrier(std::vector< detail::EventImplPtr > EventsWaitWithBarrier, CG::StorageInitHelper CGData, CGType Type, detail::code_location loc={})
Definition: cg.hpp:421
"Copy 2D USM" command group class.
Definition: cg.hpp:435
size_t getDstPitch() const
Definition: cg.hpp:454
size_t getWidth() const
Definition: cg.hpp:455
void * getSrc() const
Definition: cg.hpp:451
void * getDst() const
Definition: cg.hpp:452
size_t getHeight() const
Definition: cg.hpp:456
size_t getSrcPitch() const
Definition: cg.hpp:453
CGCopy2DUSM(void *Src, void *Dst, size_t SrcPitch, size_t DstPitch, size_t Width, size_t Height, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:444
"Copy to device_global" command group class.
Definition: cg.hpp:552
CGCopyFromDeviceGlobal(void *DeviceGlobalPtr, void *Dest, bool IsDeviceImageScoped, size_t NumBytes, size_t Offset, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:560
"Copy Image" command group class.
Definition: cg.hpp:576
void * getDst() const
Definition: cg.hpp:603
ur_rect_offset_t getSrcOffset() const
Definition: cg.hpp:609
ur_rect_region_t getCopyExtent() const
Definition: cg.hpp:611
void * getSrc() const
Definition: cg.hpp:602
ur_image_format_t getSrcFormat() const
Definition: cg.hpp:606
ur_image_format_t getDstFormat() const
Definition: cg.hpp:607
CGCopyImage(void *Src, void *Dst, ur_image_desc_t SrcImageDesc, ur_image_desc_t DstImageDesc, ur_image_format_t SrcImageFormat, ur_image_format_t DstImageFormat, ur_exp_image_copy_flags_t ImageCopyFlags, ur_rect_offset_t SrcOffset, ur_rect_offset_t DstOffset, ur_rect_region_t CopyExtent, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:589
ur_image_desc_t getDstDesc() const
Definition: cg.hpp:605
ur_image_desc_t getSrcDesc() const
Definition: cg.hpp:604
ur_exp_image_copy_flags_t getCopyFlags() const
Definition: cg.hpp:608
ur_rect_offset_t getDstOffset() const
Definition: cg.hpp:610
"Copy to device_global" command group class.
Definition: cg.hpp:527
CGCopyToDeviceGlobal(void *Src, void *DeviceGlobalPtr, bool IsDeviceImageScoped, size_t NumBytes, size_t Offset, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:535
"Copy USM" command group class.
Definition: cg.hpp:354
CGCopyUSM(void *Src, void *Dst, size_t Length, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:360
"Copy memory" command group class.
Definition: cg.hpp:306
void clearAuxiliaryResources() override
Definition: cg.hpp:324
CGCopy(CGType CopyType, void *Src, void *Dst, CG::StorageInitHelper CGData, std::vector< std::shared_ptr< const void >> AuxiliaryResources, detail::code_location loc={})
Definition: cg.hpp:312
std::vector< std::shared_ptr< const void > > getAuxiliaryResources() const override
Definition: cg.hpp:321
"Execute command-buffer" command group class.
Definition: cg.hpp:654
CGExecCommandBuffer(const ur_exp_command_buffer_handle_t &CommandBuffer, const std::shared_ptr< sycl::ext::oneapi::experimental::detail::exec_graph_impl > &ExecGraph, CG::StorageInitHelper CGData)
Definition: cg.hpp:660
std::shared_ptr< sycl::ext::oneapi::experimental::detail::exec_graph_impl > MExecGraph
Definition: cg.hpp:658
ur_exp_command_buffer_handle_t MCommandBuffer
Definition: cg.hpp:656
"Execute kernel" command group class.
Definition: cg.hpp:246
CGExecKernel(NDRDescT NDRDesc, std::shared_ptr< HostKernelBase > HKernel, std::shared_ptr< detail::kernel_impl > SyclKernel, std::shared_ptr< detail::kernel_bundle_impl > KernelBundle, CG::StorageInitHelper CGData, std::vector< ArgDesc > Args, std::string KernelName, std::vector< std::shared_ptr< detail::stream_impl >> Streams, std::vector< std::shared_ptr< const void >> AuxiliaryResources, CGType Type, ur_kernel_cache_config_t KernelCacheConfig, bool KernelIsCooperative, bool MKernelUsesClusterLaunch, detail::code_location loc={})
Definition: cg.hpp:261
std::shared_ptr< detail::kernel_bundle_impl > MKernelBundle
Definition: cg.hpp:252
std::vector< std::shared_ptr< const void > > getAuxiliaryResources() const override
Definition: cg.hpp:292
std::vector< std::shared_ptr< const void > > MAuxiliaryResources
Definition: cg.hpp:256
void clearAuxiliaryResources() override
Definition: cg.hpp:295
std::string getKernelName() const
Definition: cg.hpp:286
std::vector< ArgDesc > MArgs
Definition: cg.hpp:253
NDRDescT MNDRDesc
Stores ND-range description.
Definition: cg.hpp:249
std::shared_ptr< detail::kernel_impl > MSyclKernel
Definition: cg.hpp:251
std::shared_ptr< HostKernelBase > MHostKernel
Definition: cg.hpp:250
CGExecKernel(const CGExecKernel &CGExec)=default
std::vector< std::shared_ptr< detail::stream_impl > > getStreams() const
Definition: cg.hpp:287
ur_kernel_cache_config_t MKernelCacheConfig
Definition: cg.hpp:257
std::vector< std::shared_ptr< detail::stream_impl > > MStreams
Definition: cg.hpp:255
std::shared_ptr< detail::kernel_bundle_impl > getKernelBundle()
Definition: cg.hpp:297
std::vector< ArgDesc > getArguments() const
Definition: cg.hpp:285
"Fill 2D USM" command group class.
Definition: cg.hpp:460
void * getDst() const
Definition: cg.hpp:474
size_t getWidth() const
Definition: cg.hpp:476
size_t getHeight() const
Definition: cg.hpp:477
CGFill2DUSM(std::vector< unsigned char > Pattern, void *DstPtr, size_t Pitch, size_t Width, size_t Height, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:468
size_t getPitch() const
Definition: cg.hpp:475
const std::vector< unsigned char > & getPattern() const
Definition: cg.hpp:478
"Fill USM" command group class.
Definition: cg.hpp:371
CGFillUSM(std::vector< unsigned char > Pattern, void *DstPtr, size_t Length, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:377
const std::vector< unsigned char > & getPattern()
Definition: cg.hpp:383
"Fill memory" command group class.
Definition: cg.hpp:328
std::vector< unsigned char > MPattern
Definition: cg.hpp:330
CGFill(std::vector< unsigned char > Pattern, void *Ptr, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:333
AccessorImplHost * getReqToFill()
Definition: cg.hpp:337
AccessorImplHost * MPtr
Definition: cg.hpp:331
CGHostTask(std::shared_ptr< HostTask > HostTask, std::shared_ptr< detail::queue_impl > Queue, std::shared_ptr< detail::context_impl > Context, std::vector< ArgDesc > Args, CG::StorageInitHelper CGData, CGType Type, detail::code_location loc={})
Definition: cg.hpp:678
std::shared_ptr< detail::context_impl > MContext
Definition: cg.hpp:675
std::shared_ptr< detail::queue_impl > MQueue
Definition: cg.hpp:673
std::vector< ArgDesc > MArgs
Definition: cg.hpp:676
std::shared_ptr< HostTask > MHostTask
Definition: cg.hpp:671
"Memset 2D USM" command group class.
Definition: cg.hpp:482
size_t getPitch() const
Definition: cg.hpp:497
size_t getWidth() const
Definition: cg.hpp:498
size_t getHeight() const
Definition: cg.hpp:499
CGMemset2DUSM(char Value, void *DstPtr, size_t Pitch, size_t Width, size_t Height, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:490
"Prefetch USM" command group class.
Definition: cg.hpp:387
CGPrefetchUSM(void *DstPtr, size_t Length, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:392
CGProfilingTag(CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:430
"ReadWriteHostPipe" command group class.
Definition: cg.hpp:504
CGReadWriteHostPipe(const std::string &Name, bool Block, void *Ptr, size_t Size, bool Read, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:512
"Semaphore Signal" command group class.
Definition: cg.hpp:634
std::optional< uint64_t > getSignalValue() const
Definition: cg.hpp:650
CGSemaphoreSignal(ur_exp_interop_semaphore_handle_t InteropSemaphoreHandle, std::optional< uint64_t > SignalValue, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:639
ur_exp_interop_semaphore_handle_t getInteropSemaphoreHandle() const
Definition: cg.hpp:647
"Semaphore Wait" command group class.
Definition: cg.hpp:615
std::optional< uint64_t > getWaitValue() const
Definition: cg.hpp:630
ur_exp_interop_semaphore_handle_t getInteropSemaphoreHandle() const
Definition: cg.hpp:627
CGSemaphoreWait(ur_exp_interop_semaphore_handle_t InteropSemaphoreHandle, std::optional< uint64_t > WaitValue, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:620
"Update host" command group class.
Definition: cg.hpp:341
AccessorImplHost * getReqToUpdate()
Definition: cg.hpp:350
CGUpdateHost(void *Ptr, CG::StorageInitHelper CGData, detail::code_location loc={})
Definition: cg.hpp:345
Base class for all types of command groups.
Definition: cg.hpp:160
std::vector< detail::AccessorImplPtr > & getAccStorage()
Definition: cg.hpp:212
std::vector< detail::EventImplPtr > & getEvents()
Definition: cg.hpp:222
CG(const CG &CommandGroup)=default
std::vector< std::vector< char > > & getArgsStorage()
Definition: cg.hpp:209
virtual void clearAuxiliaryResources()
Definition: cg.hpp:228
virtual std::vector< std::shared_ptr< const void > > getAuxiliaryResources() const
Definition: cg.hpp:225
virtual ~CG()=default
std::string MFileName
Definition: cg.hpp:240
CG(CGType Type, StorageInitHelper D, detail::code_location loc={})
Definition: cg.hpp:191
std::vector< AccessorImplHost * > & getRequirements()
Definition: cg.hpp:219
int32_t MColumn
Definition: cg.hpp:242
CG(CG &&CommandGroup)=default
CGType getType() const
Definition: cg.hpp:207
std::vector< std::shared_ptr< const void > > & getSharedPtrStorage()
Definition: cg.hpp:215
sycl::range< 3 > GlobalSize
Definition: cg.hpp:148
sycl::range< 3 > NumWorkGroups
Number of workgroups, used to record the number of workgroups from the simplest form of parallel_for_...
Definition: cg.hpp:154
NDRDescT(sycl::nd_range< Dims_ > ExecutionRange, int DimsArg)
Definition: cg.hpp:120
NDRDescT(sycl::range< 3 > NumWorkItems, sycl::id< 3 > Offset, int DimsArg)
Definition: cg.hpp:109
NDRDescT & operator=(NDRDescT &&Desc)=default
NDRDescT(sycl::range< Dims_ > Range)
Definition: cg.hpp:132
sycl::id< 3 > GlobalOffset
Definition: cg.hpp:150
NDRDescT(sycl::range< 3 > N, bool SetNumWorkGroups, int DimsArg)
Definition: cg.hpp:102
NDRDescT(sycl::nd_range< Dims_ > ExecutionRange)
Definition: cg.hpp:128
NDRDescT(NDRDescT &&Desc)=default
sycl::range< 3 > LocalSize
Definition: cg.hpp:149
NDRDescT & operator=(const NDRDescT &Desc)=default
NDRDescT(sycl::range< 3 > NumWorkItems, sycl::range< 3 > LocalSize, sycl::id< 3 > Offset, int DimsArg)
Definition: cg.hpp:112
void setClusterDimensions(sycl::range< 3 > N, int Dims)
Definition: cg.hpp:135
NDRDescT(const NDRDescT &Desc)=default
Class representing the implementation of command_graph<executable>.
A unique identifier of an item in an index space.
Definition: id.hpp:36
Defines the iteration domain of both the work-groups and the overall dispatch.
Definition: nd_range.hpp:22
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: range.hpp:26
std::shared_ptr< event_impl > EventImplPtr
Definition: handler.hpp:183
CGType
Type of the command group.
Definition: cg_types.hpp:42
sycl::detail::kernel_bundle_impl kernel_bundle_impl
Definition: access.hpp:18
static size_t get_offset(sycl::id< 3 > id, size_t slice, size_t pitch)
Definition: memory.hpp:329
StorageInitHelper(StorageInitHelper &&)=default
std::vector< detail::AccessorImplPtr > MAccStorage
Storage for accessors.
Definition: cg.hpp:180
std::vector< std::vector< char > > MArgsStorage
Storage for standard layout arguments.
Definition: cg.hpp:178
StorageInitHelper(std::vector< std::vector< char >> ArgsStorage, std::vector< detail::AccessorImplPtr > AccStorage, std::vector< std::shared_ptr< const void >> SharedPtrStorage, std::vector< AccessorImplHost * > Requirements, std::vector< detail::EventImplPtr > Events)
Definition: cg.hpp:164
std::vector< std::shared_ptr< const void > > MSharedPtrStorage
Storage for shared_ptrs.
Definition: cg.hpp:182
std::vector< detail::EventImplPtr > MEvents
List of events that order the execution of this CG.
Definition: cg.hpp:188
StorageInitHelper(const StorageInitHelper &)=default
std::vector< AccessorImplHost * > MRequirements
List of requirements that specify which memory is needed for the command group to be executed.
Definition: cg.hpp:186
C++ utilities for Unified Runtime integration.