OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryEngine Class Reference

#include <QueryEngine.h>

+ Collaboration diagram for QueryEngine:

Public Member Functions

 QueryEngine (CudaMgr_Namespace::CudaMgr *cuda_mgr, bool cpu_only)
 
 ~QueryEngine ()
 
CUstream getCudaStream ()
 
CUstream getCudaStreamForDevice (int device_num)
 

Static Public Member Functions

static std::shared_ptr
< QueryEngine
getInstance ()
 
static std::shared_ptr
< QueryEngine
createInstance (CudaMgr_Namespace::CudaMgr *cuda_mgr, bool cpu_only)
 

Public Attributes

std::unique_ptr
< CodeCacheAccessor
< CpuCompilationContext > > 
s_stubs_accessor
 
std::unique_ptr
< CodeCacheAccessor
< CpuCompilationContext > > 
s_code_accessor
 
std::unique_ptr
< CodeCacheAccessor
< CpuCompilationContext > > 
cpu_code_accessor
 
std::unique_ptr
< CodeCacheAccessor
< GpuCompilationContext > > 
gpu_code_accessor
 
std::unique_ptr
< CodeCacheAccessor
< CompilationContext > > 
tf_code_accessor
 

Private Attributes

CudaMgr_Namespace::CudaMgrcuda_mgr_
 
std::vector< CUstreamcuda_streams_
 

Static Private Attributes

static std::mutex mutex_
 
static std::weak_ptr< QueryEngineinstance_
 
static constexpr size_t code_cache_size {1000}
 

Detailed Description

Definition at line 11 of file QueryEngine.h.

Constructor & Destructor Documentation

QueryEngine::QueryEngine ( CudaMgr_Namespace::CudaMgr cuda_mgr,
bool  cpu_only 
)
inline

Definition at line 13 of file QueryEngine.h.

References checkCudaErrors(), cuda_mgr_, cuda_streams_, g_query_engine_cuda_streams, CudaMgr_Namespace::CudaMgr::getContext(), CudaMgr_Namespace::CudaMgr::getDeviceCount(), logger::INFO, LOG, and CudaMgr_Namespace::CudaMgr::setContext().

14  : cuda_mgr_(cuda_mgr)
17  "s_stubs_cache"))
20  "s_code_cache"))
23  "cpu_code_cache"))
26  "gpu_code_cache"))
29  "tf_code_cache")) {
30  if (cpu_only) {
32  }
33 #ifdef HAVE_CUDA
35  // See:
36  // https://docs.nvidia.com/cuda/cuda-runtime-api/stream-sync-behavior.html
37  LOG(INFO) << "Query Engine CUDA streams enabled";
38  int original_device_context = cuda_mgr_->getContext();
39  CUstream s;
40  for (int device_num = 0; device_num < cuda_mgr_->getDeviceCount(); ++device_num) {
41  cuda_mgr_->setContext(device_num);
42  checkCudaErrors(cuStreamCreate(&s, /*CU_STREAM_DEFAULT*/ CU_STREAM_NON_BLOCKING));
43  cuda_streams_.push_back(s);
44  }
45  cuda_mgr_->setContext(original_device_context);
46  } else {
47  LOG(INFO) << "Query Engine CUDA streams disabled";
48  }
49 #endif // HAVE_CUDA
50  }
std::unique_ptr< CodeCacheAccessor< CpuCompilationContext > > cpu_code_accessor
Definition: QueryEngine.h:113
void * CUstream
Definition: nocuda.h:23
#define LOG(tag)
Definition: Logger.h:216
void checkCudaErrors(CUresult err)
Definition: sample.cpp:38
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: QueryEngine.h:102
std::unique_ptr< CodeCacheAccessor< CompilationContext > > tf_code_accessor
Definition: QueryEngine.h:115
void setContext(const int device_num) const
Definition: CudaMgr.cpp:405
int getDeviceCount() const
Definition: CudaMgr.h:87
static constexpr size_t code_cache_size
Definition: QueryEngine.h:108
std::vector< CUstream > cuda_streams_
Definition: QueryEngine.h:103
std::unique_ptr< CodeCacheAccessor< CpuCompilationContext > > s_stubs_accessor
Definition: QueryEngine.h:111
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:9
std::unique_ptr< CodeCacheAccessor< GpuCompilationContext > > gpu_code_accessor
Definition: QueryEngine.h:114
std::unique_ptr< CodeCacheAccessor< CpuCompilationContext > > s_code_accessor
Definition: QueryEngine.h:112

+ Here is the call graph for this function:

QueryEngine::~QueryEngine ( )
inline

Definition at line 52 of file QueryEngine.h.

References checkCudaErrors(), cuda_streams_, and g_query_engine_cuda_streams.

52  {
53 #ifdef HAVE_CUDA
55  for (auto& c : cuda_streams_) {
56  checkCudaErrors(cuStreamDestroy(c));
57  }
58  }
59 #endif // HAVE_CUDA
60  }
void checkCudaErrors(CUresult err)
Definition: sample.cpp:38
std::vector< CUstream > cuda_streams_
Definition: QueryEngine.h:103
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:9

+ Here is the call graph for this function:

Member Function Documentation

static std::shared_ptr<QueryEngine> QueryEngine::createInstance ( CudaMgr_Namespace::CudaMgr cuda_mgr,
bool  cpu_only 
)
inlinestatic

Definition at line 89 of file QueryEngine.h.

References instance_, and mutex_.

Referenced by DBHandler::initialize(), and QueryRunner::QueryRunner::QueryRunner().

90  {
92  if (auto s = instance_.lock()) {
93  return s;
94  } else {
95  s = std::make_shared<QueryEngine>(cuda_mgr, cpu_only);
96  instance_ = s;
97  return s;
98  }
99  }
static std::weak_ptr< QueryEngine > instance_
Definition: QueryEngine.h:106
std::unique_lock< T > unique_lock
static std::mutex mutex_
Definition: QueryEngine.h:105

+ Here is the caller graph for this function:

CUstream QueryEngine::getCudaStream ( )
inline

Definition at line 62 of file QueryEngine.h.

References cuda_mgr_, g_query_engine_cuda_streams, CudaMgr_Namespace::CudaMgr::getContext(), and getCudaStreamForDevice().

62  { // NOTE: CUstream is cudaStream_t
64  int device_num = cuda_mgr_->getContext();
65  return getCudaStreamForDevice(device_num);
66  } else {
67  return 0;
68  }
69  }
CUstream getCudaStreamForDevice(int device_num)
Definition: QueryEngine.h:71
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: QueryEngine.h:102
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:9

+ Here is the call graph for this function:

CUstream QueryEngine::getCudaStreamForDevice ( int  device_num)
inline

Definition at line 71 of file QueryEngine.h.

References CHECK_GE, CHECK_LT, cuda_streams_, and g_query_engine_cuda_streams.

Referenced by getCudaStream().

71  { // NOTE: CUstream is cudaStream_t
73  CHECK_GE(device_num, 0);
74  CHECK_LT((size_t)device_num, cuda_streams_.size());
75  return cuda_streams_[device_num];
76  } else {
77  return 0;
78  }
79  }
#define CHECK_GE(x, y)
Definition: Logger.h:235
std::vector< CUstream > cuda_streams_
Definition: QueryEngine.h:103
#define CHECK_LT(x, y)
Definition: Logger.h:232
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:9

+ Here is the caller graph for this function:

static std::shared_ptr<QueryEngine> QueryEngine::getInstance ( )
inlinestatic

Definition at line 81 of file QueryEngine.h.

References instance_.

Referenced by ResultSetReductionJIT::codegen(), TableFunctionCompilationContext::compile(), StubGenerator::generateStub(), getQueryEngineCudaStream(), getQueryEngineCudaStreamForDevice(), Executor::optimizeAndCodegenCPU(), and Executor::reset().

81  {
82  if (auto s = instance_.lock()) {
83  return s;
84  } else {
85  throw std::runtime_error("QueryEngine instance hasn't been created");
86  }
87  }
static std::weak_ptr< QueryEngine > instance_
Definition: QueryEngine.h:106

+ Here is the caller graph for this function:

Member Data Documentation

constexpr size_t QueryEngine::code_cache_size {1000}
staticprivate

Definition at line 108 of file QueryEngine.h.

std::unique_ptr<CodeCacheAccessor<CpuCompilationContext> > QueryEngine::cpu_code_accessor

Definition at line 113 of file QueryEngine.h.

CudaMgr_Namespace::CudaMgr* QueryEngine::cuda_mgr_
private

Definition at line 102 of file QueryEngine.h.

Referenced by getCudaStream(), and QueryEngine().

std::vector<CUstream> QueryEngine::cuda_streams_
private

Definition at line 103 of file QueryEngine.h.

Referenced by getCudaStreamForDevice(), QueryEngine(), and ~QueryEngine().

std::unique_ptr<CodeCacheAccessor<GpuCompilationContext> > QueryEngine::gpu_code_accessor

Definition at line 114 of file QueryEngine.h.

std::weak_ptr<QueryEngine> QueryEngine::instance_
inlinestaticprivate

Definition at line 106 of file QueryEngine.h.

Referenced by createInstance(), and getInstance().

std::mutex QueryEngine::mutex_
inlinestaticprivate

Definition at line 105 of file QueryEngine.h.

Referenced by createInstance().

std::unique_ptr<CodeCacheAccessor<CpuCompilationContext> > QueryEngine::s_code_accessor

Definition at line 112 of file QueryEngine.h.

std::unique_ptr<CodeCacheAccessor<CpuCompilationContext> > QueryEngine::s_stubs_accessor

Definition at line 111 of file QueryEngine.h.

std::unique_ptr<CodeCacheAccessor<CompilationContext> > QueryEngine::tf_code_accessor

Definition at line 115 of file QueryEngine.h.


The documentation for this class was generated from the following file: