OmniSciDB  c1a53651b2
 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 2022 HEAVY.AI, 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 "CompilationContext.h"
27 #include "QueryMemoryInitializer.h"
28 
29 #include <boost/core/noncopyable.hpp>
30 #include <vector>
31 
34 
35 struct RelAlgExecutionUnit;
37 class Executor;
38 
39 class QueryExecutionContext : boost::noncopyable {
40  public:
41  // TODO(alex): remove device_type
42  QueryExecutionContext(const RelAlgExecutionUnit& ra_exe_unit,
43  const QueryMemoryDescriptor&,
44  const Executor* executor,
45  const ExecutorDeviceType device_type,
46  const ExecutorDispatchMode dispatch_mode,
47  const int device_id,
48  const shared::TableKey& outer_table_key,
49  const int64_t num_rows,
50  const std::vector<std::vector<const int8_t*>>& col_buffers,
51  const std::vector<std::vector<uint64_t>>& frag_offsets,
52  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
53  const bool output_columnar,
54  const bool sort_on_gpu,
55  const size_t thread_idx,
56  RenderInfo*);
57 
58  ResultSetPtr getRowSet(const RelAlgExecutionUnit& ra_exe_unit,
60 
61  ResultSetPtr groupBufferToResults(const size_t i) const;
62 
63  std::vector<int64_t*> launchGpuCode(
64  const RelAlgExecutionUnit& ra_exe_unit,
65  const CompilationContext* compilation_context,
66  const bool hoist_literals,
67  const std::vector<int8_t>& literal_buff,
68  std::vector<std::vector<const int8_t*>> col_buffers,
69  const std::vector<std::vector<int64_t>>& num_rows,
70  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
71  const int32_t scan_limit,
72  Data_Namespace::DataMgr* data_mgr,
73  const unsigned block_size_x,
74  const unsigned grid_size_x,
75  const int device_id,
76  const size_t shared_memory_size,
77  int32_t* error_code,
78  const uint32_t num_tables,
79  const bool allow_runtime_interrupt,
80  const std::vector<int8_t*>& join_hash_tables,
81  RenderAllocatorMap* render_allocator_map,
82  bool optimize_cuda_block_and_grid_sizes);
83 
84  std::vector<int64_t*> launchCpuCode(
85  const RelAlgExecutionUnit& ra_exe_unit,
86  const CpuCompilationContext* fn_ptrs,
87  const bool hoist_literals,
88  const std::vector<int8_t>& literal_buff,
89  std::vector<std::vector<const int8_t*>> col_buffers,
90  const std::vector<std::vector<int64_t>>& num_rows,
91  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
92  const int32_t scan_limit,
93  int32_t* error_code,
94  const uint32_t num_tables,
95  const std::vector<int8_t*>& join_hash_tables,
96  const int64_t num_rows_to_process = -1);
97 
98  int64_t getAggInitValForIndex(const size_t index) const;
99 
100  private:
101  enum {
116  };
117 
118  std::vector<int8_t*> 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<int8_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 
133  ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const;
134 
135  std::unique_ptr<DeviceAllocator> gpu_allocator_;
136 
137  // TODO(adb): convert to shared_ptr
142  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
143  const bool output_columnar_;
144  std::unique_ptr<QueryMemoryInitializer> query_buffers_;
145  mutable std::unique_ptr<ResultSet> estimator_result_set_;
146 
147  friend class Executor;
148 };
149 
150 #endif // QUERYENGINE_QUERYEXECUTIONCONTEXT_H
std::unique_ptr< DeviceAllocator > 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 shared::TableKey &outer_table_key, 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 *)
ExecutorDeviceType
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, const int device_id)
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< int8_t * > &join_hash_tables, const int64_t num_rows_to_process=-1)
const ExecutorDispatchMode dispatch_mode_
size_t num_rows_to_process(const size_t start_row_index, const size_t max_fragment_size, const size_t rows_remaining)
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:244
std::vector< int8_t * > prepareKernelParams(const std::vector< std::vector< const int8_t * >> &col_buffers, const std::vector< int8_t > &literal_buff, const std::vector< std::vector< int64_t >> &num_rows, const std::vector< std::vector< uint64_t >> &frag_offsets, const int32_t scan_limit, const std::vector< int64_t > &init_agg_vals, const std::vector< int32_t > &error_codes, const uint32_t num_tables, const std::vector< int8_t * > &join_hash_tables, Data_Namespace::DataMgr *data_mgr, const int device_id, const bool hoist_literals, const bool is_group_by) const
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const
ResultSetPtr groupBufferToResults(const size_t i) const
Basic constructors and methods of the row set interface.
Allocate GPU memory using GpuBuffers via DataMgr.
std::unique_ptr< ResultSet > estimator_result_set_
std::vector< int64_t * > launchGpuCode(const RelAlgExecutionUnit &ra_exe_unit, const CompilationContext *compilation_context, 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< int8_t * > &join_hash_tables, RenderAllocatorMap *render_allocator_map, bool optimize_cuda_block_and_grid_sizes)