OmniSciDB  a5dc49c757
 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_
 

Detailed Description

Definition at line 14 of file QueryEngine.h.

Constructor & Destructor Documentation

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

Definition at line 16 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().

17  : cuda_mgr_(cuda_mgr)
21  "s_stubs_cache"))
25  "s_code_cache"))
29  "cpu_code_cache"))
33  "gpu_code_cache"))
37  "tf_code_cache")) {
38  if (cpu_only) {
40  }
41 #ifdef HAVE_CUDA
43  // See:
44  // https://docs.nvidia.com/cuda/cuda-runtime-api/stream-sync-behavior.html
45  LOG(INFO) << "Query Engine CUDA streams enabled";
46  int original_device_context = cuda_mgr_->getContext();
47  CUstream s;
48  for (int device_num = 0; device_num < cuda_mgr_->getDeviceCount(); ++device_num) {
49  cuda_mgr_->setContext(device_num);
50  checkCudaErrors(cuStreamCreate(&s, /*CU_STREAM_DEFAULT*/ CU_STREAM_NON_BLOCKING));
51  cuda_streams_.push_back(s);
52  }
53  cuda_mgr_->setContext(original_device_context);
54  } else {
55  LOG(INFO) << "Query Engine CUDA streams disabled";
56  }
57 #endif // HAVE_CUDA
58  }
std::unique_ptr< CodeCacheAccessor< CpuCompilationContext > > cpu_code_accessor
Definition: QueryEngine.h:119
size_t g_gpu_code_cache_max_size_in_bytes
Definition: QueryEngine.h:12
void * CUstream
Definition: nocuda.h:23
#define LOG(tag)
Definition: Logger.h:285
void checkCudaErrors(CUresult err)
Definition: sample.cpp:38
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: QueryEngine.h:110
std::unique_ptr< CodeCacheAccessor< CompilationContext > > tf_code_accessor
Definition: QueryEngine.h:121
void setContext(const int device_num) const
Definition: CudaMgr.cpp:511
int getDeviceCount() const
Definition: CudaMgr.h:90
size_t g_code_cache_max_num_items
Definition: QueryEngine.h:11
std::vector< CUstream > cuda_streams_
Definition: QueryEngine.h:111
std::unique_ptr< CodeCacheAccessor< CpuCompilationContext > > s_stubs_accessor
Definition: QueryEngine.h:117
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:10
std::unique_ptr< CodeCacheAccessor< GpuCompilationContext > > gpu_code_accessor
Definition: QueryEngine.h:120
std::unique_ptr< CodeCacheAccessor< CpuCompilationContext > > s_code_accessor
Definition: QueryEngine.h:118

+ Here is the call graph for this function:

QueryEngine::~QueryEngine ( )
inline

Definition at line 60 of file QueryEngine.h.

References checkCudaErrors(), cuda_streams_, and g_query_engine_cuda_streams.

60  {
61 #ifdef HAVE_CUDA
63  for (auto& c : cuda_streams_) {
64  checkCudaErrors(cuStreamDestroy(c));
65  }
66  }
67 #endif // HAVE_CUDA
68  }
void checkCudaErrors(CUresult err)
Definition: sample.cpp:38
std::vector< CUstream > cuda_streams_
Definition: QueryEngine.h:111
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:10

+ 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 97 of file QueryEngine.h.

References instance_, and mutex_.

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

98  {
100  if (auto s = instance_.lock()) {
101  return s;
102  } else {
103  s = std::make_shared<QueryEngine>(cuda_mgr, cpu_only);
104  instance_ = s;
105  return s;
106  }
107  }
static std::weak_ptr< QueryEngine > instance_
Definition: QueryEngine.h:114
std::unique_lock< T > unique_lock
static std::mutex mutex_
Definition: QueryEngine.h:113

+ Here is the caller graph for this function:

CUstream QueryEngine::getCudaStream ( )
inline

Definition at line 70 of file QueryEngine.h.

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

70  { // NOTE: CUstream is cudaStream_t
72  int device_num = cuda_mgr_->getContext();
73  return getCudaStreamForDevice(device_num);
74  } else {
75  return 0;
76  }
77  }
CUstream getCudaStreamForDevice(int device_num)
Definition: QueryEngine.h:79
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: QueryEngine.h:110
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:10

+ Here is the call graph for this function:

CUstream QueryEngine::getCudaStreamForDevice ( int  device_num)
inline

Definition at line 79 of file QueryEngine.h.

References CHECK_GE, CHECK_LT, cuda_streams_, and g_query_engine_cuda_streams.

Referenced by getCudaStream().

79  { // NOTE: CUstream is cudaStream_t
81  CHECK_GE(device_num, 0);
82  CHECK_LT((size_t)device_num, cuda_streams_.size());
83  return cuda_streams_[device_num];
84  } else {
85  return 0;
86  }
87  }
#define CHECK_GE(x, y)
Definition: Logger.h:306
std::vector< CUstream > cuda_streams_
Definition: QueryEngine.h:111
#define CHECK_LT(x, y)
Definition: Logger.h:303
bool g_query_engine_cuda_streams
Definition: QueryEngine.h:10

+ Here is the caller graph for this function:

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

Definition at line 89 of file QueryEngine.h.

References instance_.

Referenced by ResultSetReductionJIT::codegen(), TableFunctionCompilationContext::compile(), StubGenerator::generateStub(), getQueryEngineCudaStream(), getQueryEngineCudaStreamForDevice(), anonymous_namespace{DBHandler.cpp}::log_cache_size(), Executor::optimizeAndCodegenCPU(), and Executor::reset().

89  {
90  if (auto s = instance_.lock()) {
91  return s;
92  } else {
93  throw std::runtime_error("QueryEngine instance hasn't been created");
94  }
95  }
static std::weak_ptr< QueryEngine > instance_
Definition: QueryEngine.h:114

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 119 of file QueryEngine.h.

CudaMgr_Namespace::CudaMgr* QueryEngine::cuda_mgr_
private

Definition at line 110 of file QueryEngine.h.

Referenced by getCudaStream(), and QueryEngine().

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

Definition at line 111 of file QueryEngine.h.

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

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

Definition at line 120 of file QueryEngine.h.

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

Definition at line 114 of file QueryEngine.h.

Referenced by createInstance(), and getInstance().

std::mutex QueryEngine::mutex_
inlinestaticprivate

Definition at line 113 of file QueryEngine.h.

Referenced by createInstance().

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

Definition at line 118 of file QueryEngine.h.

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

Definition at line 117 of file QueryEngine.h.

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

Definition at line 121 of file QueryEngine.h.


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