OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryExecutionContext.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QUERYENGINE_QUERYEXECUTIONCONTEXT_H
18 #define QUERYENGINE_QUERYEXECUTIONCONTEXT_H
19 
20 #include "CompilationOptions.h"
22 #include "GpuMemUtils.h"
23 #include "Rendering/RenderInfo.h"
24 #include "ResultSet.h"
25 
26 #include "QueryMemoryInitializer.h"
27 
28 #include <boost/core/noncopyable.hpp>
29 #include <vector>
30 
33 
34 struct RelAlgExecutionUnit;
36 class Executor;
37 
38 class QueryExecutionContext : boost::noncopyable {
39  public:
40  // TODO(alex): remove device_type
41  QueryExecutionContext(const RelAlgExecutionUnit& ra_exe_unit,
42  const QueryMemoryDescriptor&,
43  const Executor* executor,
44  const ExecutorDeviceType device_type,
45  const ExecutorDispatchMode dispatch_mode,
46  const int device_id,
47  const int64_t num_rows,
48  const std::vector<std::vector<const int8_t*>>& col_buffers,
49  const std::vector<std::vector<uint64_t>>& frag_offsets,
50  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
51  const bool output_columnar,
52  const bool sort_on_gpu,
53  const size_t thread_idx,
54  RenderInfo*);
55 
56  ResultSetPtr getRowSet(const RelAlgExecutionUnit& ra_exe_unit,
58 
59  ResultSetPtr groupBufferToResults(const size_t i) const;
60 
61  std::vector<int64_t*> launchGpuCode(
62  const RelAlgExecutionUnit& ra_exe_unit,
63  const GpuCompilationContext* cu_functions,
64  const bool hoist_literals,
65  const std::vector<int8_t>& literal_buff,
66  std::vector<std::vector<const int8_t*>> col_buffers,
67  const std::vector<std::vector<int64_t>>& num_rows,
68  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
69  const int32_t scan_limit,
70  Data_Namespace::DataMgr* data_mgr,
71  const unsigned block_size_x,
72  const unsigned grid_size_x,
73  const int device_id,
74  const size_t shared_memory_size,
75  int32_t* error_code,
76  const uint32_t num_tables,
77  const bool allow_runtime_interrupt,
78  const std::vector<int64_t>& join_hash_tables,
79  RenderAllocatorMap* render_allocator_map);
80 
81  std::vector<int64_t*> launchCpuCode(
82  const RelAlgExecutionUnit& ra_exe_unit,
83  const CpuCompilationContext* fn_ptrs,
84  const bool hoist_literals,
85  const std::vector<int8_t>& literal_buff,
86  std::vector<std::vector<const int8_t*>> col_buffers,
87  const std::vector<std::vector<int64_t>>& num_rows,
88  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
89  const int32_t scan_limit,
90  int32_t* error_code,
91  const uint32_t num_tables,
92  const std::vector<int64_t>& join_hash_tables);
93 
94  int64_t getAggInitValForIndex(const size_t index) const;
95 
96  private:
97 #ifdef HAVE_CUDA
98  enum {
100  NUM_FRAGMENTS,
101  LITERALS,
102  NUM_ROWS,
103  FRAG_ROW_OFFSETS,
104  MAX_MATCHED,
105  TOTAL_MATCHED,
106  INIT_AGG_VALS,
107  GROUPBY_BUF,
108  ERROR_CODE,
109  NUM_TABLES,
110  JOIN_HASH_TABLES,
111  KERN_PARAM_COUNT,
112  };
113 
114  void initializeDynamicWatchdog(void* native_module, const int device_id) const;
115 
116  void initializeRuntimeInterrupter(void* native_module, const int device_id) const;
117 
118  std::vector<CUdeviceptr> prepareKernelParams(
119  const std::vector<std::vector<const int8_t*>>& col_buffers,
120  const std::vector<int8_t>& literal_buff,
121  const std::vector<std::vector<int64_t>>& num_rows,
122  const std::vector<std::vector<uint64_t>>& frag_offsets,
123  const int32_t scan_limit,
124  const std::vector<int64_t>& init_agg_vals,
125  const std::vector<int32_t>& error_codes,
126  const uint32_t num_tables,
127  const std::vector<int64_t>& join_hash_tables,
128  Data_Namespace::DataMgr* data_mgr,
129  const int device_id,
130  const bool hoist_literals,
131  const bool is_group_by) const;
132 #endif // HAVE_CUDA
133 
134  ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const;
135 
136  std::unique_ptr<CudaAllocator> gpu_allocator_;
137 
138  // TODO(adb): convert to shared_ptr
143  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
144  const bool output_columnar_;
145  std::unique_ptr<QueryMemoryInitializer> query_buffers_;
146  mutable std::unique_ptr<ResultSet> estimator_result_set_;
147 
148  friend class Executor;
149 };
150 
151 #endif // QUERYENGINE_QUERYEXECUTIONCONTEXT_H
ExecutorDeviceType
const ExecutorDispatchMode dispatch_mode_
std::shared_ptr< ResultSet > ResultSetPtr
const ExecutorDeviceType device_type_
ExecutorDispatchMode
std::unique_ptr< QueryMemoryInitializer > query_buffers_
ResultSetPtr getRowSet(const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &query_mem_desc) const
int64_t getAggInitValForIndex(const size_t index) const
QueryMemoryDescriptor query_mem_desc_
Executor(const ExecutorId id, Data_Namespace::DataMgr *data_mgr, const size_t block_size_x, const size_t grid_size_x, const size_t max_gpu_slab_size, const std::string &debug_dir, const std::string &debug_file)
Definition: Execute.cpp:146
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const
ResultSetPtr groupBufferToResults(const size_t i) const
std::unique_ptr< CudaAllocator > gpu_allocator_
QueryExecutionContext(const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &, const Executor *executor, const ExecutorDeviceType device_type, const ExecutorDispatchMode dispatch_mode, const int device_id, const int64_t num_rows, const std::vector< std::vector< const int8_t * >> &col_buffers, const std::vector< std::vector< uint64_t >> &frag_offsets, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const bool output_columnar, const bool sort_on_gpu, const size_t thread_idx, RenderInfo *)
std::vector< int64_t * > launchCpuCode(const RelAlgExecutionUnit &ra_exe_unit, const CpuCompilationContext *fn_ptrs, const bool hoist_literals, const std::vector< int8_t > &literal_buff, std::vector< std::vector< const int8_t * >> col_buffers, const std::vector< std::vector< int64_t >> &num_rows, const std::vector< std::vector< uint64_t >> &frag_row_offsets, const int32_t scan_limit, int32_t *error_code, const uint32_t num_tables, const std::vector< int64_t > &join_hash_tables)
Basic constructors and methods of the row set interface.
void sort_on_gpu(int64_t *val_buff, int32_t *idx_buff, const uint64_t entry_count, const bool desc, const uint32_t chosen_bytes, ThrustAllocator &alloc)
std::vector< int64_t * > launchGpuCode(const RelAlgExecutionUnit &ra_exe_unit, const GpuCompilationContext *cu_functions, const bool hoist_literals, const std::vector< int8_t > &literal_buff, std::vector< std::vector< const int8_t * >> col_buffers, const std::vector< std::vector< int64_t >> &num_rows, const std::vector< std::vector< uint64_t >> &frag_row_offsets, const int32_t scan_limit, Data_Namespace::DataMgr *data_mgr, const unsigned block_size_x, const unsigned grid_size_x, const int device_id, const size_t shared_memory_size, int32_t *error_code, const uint32_t num_tables, const bool allow_runtime_interrupt, const std::vector< int64_t > &join_hash_tables, RenderAllocatorMap *render_allocator_map)
Allocate GPU memory using GpuBuffers via DataMgr.
std::unique_ptr< ResultSet > estimator_result_set_