YAKL
YAKL_LaunchConfig.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 
10 namespace yakl {
11  // Set default vector lengths. On GPU devices, this is the block size
12  #ifndef YAKL_DEFAULT_VECTOR_LEN
13  #if defined(YAKL_ARCH_CUDA)
14  #define YAKL_DEFAULT_VECTOR_LEN 128
15  #elif defined(YAKL_ARCH_HIP)
16  #define YAKL_DEFAULT_VECTOR_LEN 256
17  #elif defined(YAKL_ARCH_SYCL)
18  #define YAKL_DEFAULT_VECTOR_LEN 128
19  #else
20 
21  #define YAKL_DEFAULT_VECTOR_LEN 128
22  #endif
23  #endif
24 
25 
26  // Empty launch config struct to set the vector length for a kernel launch
43  template <int VL = YAKL_DEFAULT_VECTOR_LEN, bool B4B = false>
44  struct LaunchConfig {
45  public:
47  int inner_size;
49  Stream stream;
51  LaunchConfig() { inner_size = VL; }
52  ~LaunchConfig() { inner_size = VL; }
54  LaunchConfig (LaunchConfig const &rhs) { copyfrom(rhs); }
58  LaunchConfig & operator=(LaunchConfig const &rhs) { copyfrom(rhs); return *this; }
60  LaunchConfig & operator=(LaunchConfig &&rhs) { copyfrom(rhs); return *this; }
61  void copyfrom(LaunchConfig const &rhs) { this->inner_size = rhs.inner_size; this->stream = rhs.stream; }
64  LaunchConfig set_inner_size(int num) { this->inner_size = num; return *this; }
66  int get_inner_size() const { return this->inner_size; }
68  LaunchConfig set_stream(Stream stream) { this->stream = stream; return *this; }
70  Stream get_stream() const { return this->stream; }
71  };
72 
73 
78 
82  template <int VecLen=YAKL_DEFAULT_VECTOR_LEN> using LaunchConfigB4b = LaunchConfig<VecLen,true>;
83 
88 
89 
98  #if defined(YAKL_ARCH_SYCL)
99  // This wraps a pointer to a sycl::nd_item<1> object for the SYCL backend's outer,inner parallelism
100  // The object is guaranteed to stay in scope throughout a call to parallel_outer, which is the duration
101  // of this class's use. Therefore, this behavior is safe to assume.
102  // This is necessary because SYCL unfortunately doesn't expose a constructor for nd_item<1>
103  class InnerHandler {
104  public:
105  sycl::nd_item<1> const *ptr;
106  YAKL_INLINE InnerHandler() { ptr = nullptr; }
107  YAKL_INLINE explicit InnerHandler(sycl::nd_item<1> const &item) { this->ptr = &item; }
108  YAKL_INLINE sycl::nd_item<1> get_item() const { return *ptr; }
109  };
110  #else
111  typedef struct InnerHandlerEmpty {} InnerHandler;
112  #endif
113 }
115 
116 
yakl::LaunchConfig::get_inner_size
int get_inner_size() const
Get the inner loop size for hierarchical parallelism.
Definition: YAKL_LaunchConfig.h:66
yakl::InnerHandler
struct yakl::InnerHandlerEmpty InnerHandler
This class is necessary for coordination of two-level parallelism.
yakl::LaunchConfig::LaunchConfig
LaunchConfig(LaunchConfig &&rhs)
LaunchConfig objects may be copied or moved.
Definition: YAKL_LaunchConfig.h:56
yakl::LaunchConfig::~LaunchConfig
~LaunchConfig()
Definition: YAKL_LaunchConfig.h:52
yakl::Stream
Implements the functionality of a stream for parallel kernel execution. If the Stream::create() metho...
Definition: YAKL_streams_events.h:394
yakl::LaunchConfig
This class informs YAKL parallel_for and parallel_outer routines how to launch kernels.
Definition: YAKL_LaunchConfig.h:44
yakl::LaunchConfig::LaunchConfig
LaunchConfig(LaunchConfig const &rhs)
LaunchConfig objects may be copied or moved.
Definition: YAKL_LaunchConfig.h:54
yakl::LaunchConfig::LaunchConfig
LaunchConfig()
set_inner_size() defaults to YAKL_DEFAULT_VECTOR_LEN
Definition: YAKL_LaunchConfig.h:51
yakl::LaunchConfig::operator=
LaunchConfig & operator=(LaunchConfig const &rhs)
LaunchConfig objects may be copied or moved.
Definition: YAKL_LaunchConfig.h:58
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
YAKL_INLINE
#define YAKL_INLINE
Used to decorate functions called from kernels (parallel_for and parallel_outer) or from CPU function...
Definition: YAKL_defines.h:140
yakl::InnerHandlerEmpty
This class is necessary for coordination of two-level parallelism.
Definition: YAKL_LaunchConfig.h:111
yakl::LaunchConfig::set_stream
LaunchConfig set_stream(Stream stream)
Set the stream in which this launch will run.
Definition: YAKL_LaunchConfig.h:68
yakl::LaunchConfig::copyfrom
void copyfrom(LaunchConfig const &rhs)
Definition: YAKL_LaunchConfig.h:61
yakl::LaunchConfig::get_stream
Stream get_stream() const
Get the stream in which this launch will run.
Definition: YAKL_LaunchConfig.h:70
yakl
yakl::LaunchConfig::set_inner_size
LaunchConfig set_inner_size(int num)
This sets the actual inner looping size whereas the template parameter VL sets the maximum inner loop...
Definition: YAKL_LaunchConfig.h:64
yakl::LaunchConfig::operator=
LaunchConfig & operator=(LaunchConfig &&rhs)
LaunchConfig objects may be copied or moved.
Definition: YAKL_LaunchConfig.h:60