OmniSciDB  d2f719934e
 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 "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 int outer_table_id,
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 
83  std::vector<int64_t*> launchCpuCode(
84  const RelAlgExecutionUnit& ra_exe_unit,
85  const CpuCompilationContext* fn_ptrs,
86  const bool hoist_literals,
87  const std::vector<int8_t>& literal_buff,
88  std::vector<std::vector<const int8_t*>> col_buffers,
89  const std::vector<std::vector<int64_t>>& num_rows,
90  const std::vector<std::vector<uint64_t>>& frag_row_offsets,
91  const int32_t scan_limit,
92  int32_t* error_code,
93  const uint32_t num_tables,
94  const std::vector<int8_t*>& join_hash_tables,
95  const int64_t num_rows_to_process = -1);
96 
97  int64_t getAggInitValForIndex(const size_t index) const;
98 
99  private:
100  enum {
114  };
115 
116  std::vector<int8_t*> prepareKernelParams(
117  const std::vector<std::vector<const int8_t*>>& col_buffers,
118  const std::vector<int8_t>& literal_buff,
119  const std::vector<std::vector<int64_t>>& num_rows,
120  const std::vector<std::vector<uint64_t>>& frag_offsets,
121  const int32_t scan_limit,
122  const std::vector<int64_t>& init_agg_vals,
123  const std::vector<int32_t>& error_codes,
124  const uint32_t num_tables,
125  const std::vector<int8_t*>& join_hash_tables,
126  Data_Namespace::DataMgr* data_mgr,
127  const int device_id,
128  const bool hoist_literals,
129  const bool is_group_by) const;
130 
131  ResultSetPtr groupBufferToDeinterleavedResults(const size_t i) const;
132 
133  std::unique_ptr<DeviceAllocator> gpu_allocator_;
134 
135  // TODO(adb): convert to shared_ptr
140  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
141  const bool output_columnar_;
142  std::unique_ptr<QueryMemoryInitializer> query_buffers_;
143  mutable std::unique_ptr<ResultSet> estimator_result_set_;
144 
145  friend class Executor;
146 };
147 
148 #endif // QUERYENGINE_QUERYEXECUTIONCONTEXT_H
std::unique_ptr< DeviceAllocator > gpu_allocator_
ExecutorDeviceType
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_
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:156
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
QueryExecutionContext(const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &, const Executor *executor, const ExecutorDeviceType device_type, const ExecutorDispatchMode dispatch_mode, const int device_id, const int outer_table_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 * > 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)
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)
Allocate GPU memory using GpuBuffers via DataMgr.
std::unique_ptr< ResultSet > estimator_result_set_