OmniSciDB  04ee39c94c
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 
21 #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 
31 struct RelAlgExecutionUnit;
33 class Executor;
34 
35 class QueryExecutionContext : boost::noncopyable {
36  public:
37  // TODO(alex): remove device_type
38  QueryExecutionContext(const RelAlgExecutionUnit& ra_exe_unit,
39  const QueryMemoryDescriptor&,
40  const Executor* executor,
41  const ExecutorDeviceType device_type,
42  const ExecutorDispatchMode dispatch_mode,
43  const int device_id,
44  const int64_t num_rows,
45  const std::vector<std::vector<const int8_t*>>& col_buffers,
46  const std::vector<std::vector<uint64_t>>& frag_offsets,
47  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
48  const bool output_columnar,
49  const bool sort_on_gpu,
50  RenderInfo*);
51 
52  ResultSetPtr getRowSet(const RelAlgExecutionUnit& ra_exe_unit,
53  const QueryMemoryDescriptor& query_mem_desc) const;
54 
55  ResultSetPtr groupBufferToResults(const size_t i) const;
56 
57  std::vector<int64_t*> launchGpuCode(
58  const RelAlgExecutionUnit& ra_exe_unit,
59  const std::vector<std::pair<void*, void*>>& cu_functions,
60  const bool hoist_literals,
61  const std::vector<int8_t>& literal_buff,
62  std::vector<std::vector<const int8_t*>> col_buffers,
63  const std::vector<std::vector<int64_t>>& num_rows,
64  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
65  const int32_t scan_limit,
66  Data_Namespace::DataMgr* data_mgr,
67  const unsigned block_size_x,
68  const unsigned grid_size_x,
69  const int device_id,
70  int32_t* error_code,
71  const uint32_t num_tables,
72  const std::vector<int64_t>& join_hash_tables,
73  RenderAllocatorMap* render_allocator_map);
74 
75  std::vector<int64_t*> launchCpuCode(
76  const RelAlgExecutionUnit& ra_exe_unit,
77  const std::vector<std::pair<void*, void*>>& fn_ptrs,
78  const bool hoist_literals,
79  const std::vector<int8_t>& literal_buff,
80  std::vector<std::vector<const int8_t*>> col_buffers,
81  const std::vector<std::vector<int64_t>>& num_rows,
82  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
83  const int32_t scan_limit,
84  int32_t* error_code,
85  const uint32_t num_tables,
86  const std::vector<int64_t>& join_hash_tables);
87 
88  int64_t getAggInitValForIndex(const size_t index) const;
89 
90  private:
91 #ifdef HAVE_CUDA
92  enum {
93  COL_BUFFERS,
94  NUM_FRAGMENTS,
95  LITERALS,
96  NUM_ROWS,
97  FRAG_ROW_OFFSETS,
98  MAX_MATCHED,
99  TOTAL_MATCHED,
100  INIT_AGG_VALS,
101  GROUPBY_BUF,
102  ERROR_CODE,
103  NUM_TABLES,
104  JOIN_HASH_TABLES,
105  KERN_PARAM_COUNT,
106  };
107 
108  void initializeDynamicWatchdog(void* native_module, const int device_id) const;
109 
110  std::vector<CUdeviceptr> prepareKernelParams(
111  const std::vector<std::vector<const int8_t*>>& col_buffers,
112  const std::vector<int8_t>& literal_buff,
113  const std::vector<std::vector<int64_t>>& num_rows,
114  const std::vector<std::vector<uint64_t>>& frag_offsets,
115  const int32_t scan_limit,
116  const std::vector<int64_t>& init_agg_vals,
117  const std::vector<int32_t>& error_codes,
118  const uint32_t num_tables,
119  const std::vector<int64_t>& join_hash_tables,
120  Data_Namespace::DataMgr* data_mgr,
121  const int device_id,
122  const bool hoist_literals,
123  const bool is_group_by) const;
124 #endif // HAVE_CUDA
125 
126  ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const;
127 
128  std::unique_ptr<CudaAllocator> gpu_allocator_;
129 
130  // TODO(adb): convert to shared_ptr
135  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
136  const bool output_columnar_;
137  std::unique_ptr<QueryMemoryInitializer> query_buffers_;
138  mutable std::unique_ptr<ResultSet> estimator_result_set_;
139 
140  friend class Executor;
141 
142  // Temporary; Reduction egress needs to become part of executor
143  template <typename META_CLASS_TYPE>
145 };
146 
147 #endif // QUERYENGINE_QUERYEXECUTIONCONTEXT_H
std::vector< int64_t * > launchGpuCode(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< std::pair< void *, void *>> &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, int32_t *error_code, const uint32_t num_tables, const std::vector< int64_t > &join_hash_tables, RenderAllocatorMap *render_allocator_map)
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t * join_hash_tables
const int8_t const int64_t * num_rows
ExecutorDeviceType
const ExecutorDispatchMode dispatch_mode_
std::shared_ptr< ResultSet > ResultSetPtr
int64_t getAggInitValForIndex(const size_t index) const
std::vector< int64_t * > launchCpuCode(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< std::pair< void *, void *>> &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)
const ExecutorDeviceType device_type_
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, RenderInfo *)
ExecutorDispatchMode
std::unique_ptr< QueryMemoryInitializer > query_buffers_
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const
ResultSetPtr getRowSet(const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &query_mem_desc) const
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
ResultSetPtr groupBufferToResults(const size_t i) const
std::unique_ptr< CudaAllocator > gpu_allocator_
Executor(const int db_id, const size_t block_size_x, const size_t grid_size_x, const std::string &debug_dir, const std::string &debug_file, ::QueryRenderer::QueryRenderManager *render_manager)
Definition: Execute.cpp:101
const int8_t const int64_t const uint64_t * frag_row_offsets
Basic constructors and methods of the row set interface.
Allocate GPU memory using GpuBuffers via DataMgr.
std::unique_ptr< ResultSet > estimator_result_set_
const QueryMemoryDescriptor query_mem_desc_
void sort_on_gpu(int64_t *val_buff, int32_t *key_buff, const uint64_t entry_count, const bool desc, const uint32_t chosen_bytes, ThrustAllocator &alloc)