OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExecutionKernel Class Reference

#include <ExecutionKernel.h>

+ Collaboration diagram for ExecutionKernel:

Public Member Functions

 ExecutionKernel (const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType chosen_device_type, int chosen_device_id, const ExecutionOptions &eo, const ColumnFetcher &column_fetcher, const QueryCompilationDescriptor &query_comp_desc, const QueryMemoryDescriptor &query_mem_desc, const FragmentsList &frag_list, const ExecutorDispatchMode kernel_dispatch_mode, RenderInfo *render_info, const int64_t rowid_lookup_key)
 
void run (Executor *executor, const size_t thread_idx, SharedKernelContext &shared_context)
 

Private Member Functions

void runImpl (Executor *executor, const size_t thread_idx, SharedKernelContext &shared_context)
 

Private Attributes

const RelAlgExecutionUnitra_exe_unit_
 
const ExecutorDeviceType chosen_device_type
 
int chosen_device_id
 
const ExecutionOptionseo
 
const ColumnFetchercolumn_fetcher
 
const QueryCompilationDescriptorquery_comp_desc
 
const QueryMemoryDescriptorquery_mem_desc
 
const FragmentsList frag_list
 
const ExecutorDispatchMode kernel_dispatch_mode
 
RenderInforender_info_
 
const int64_t rowid_lookup_key
 
ResultSetPtr device_results_
 

Detailed Description

Definition at line 49 of file ExecutionKernel.h.

Constructor & Destructor Documentation

ExecutionKernel::ExecutionKernel ( const RelAlgExecutionUnit ra_exe_unit,
const ExecutorDeviceType  chosen_device_type,
int  chosen_device_id,
const ExecutionOptions eo,
const ColumnFetcher column_fetcher,
const QueryCompilationDescriptor query_comp_desc,
const QueryMemoryDescriptor query_mem_desc,
const FragmentsList frag_list,
const ExecutorDispatchMode  kernel_dispatch_mode,
RenderInfo render_info,
const int64_t  rowid_lookup_key 
)
inline

Definition at line 51 of file ExecutionKernel.h.

62  : ra_exe_unit_(ra_exe_unit)
65  , eo(eo)
66  , column_fetcher(column_fetcher)
67  , query_comp_desc(query_comp_desc)
68  , query_mem_desc(query_mem_desc)
71  , render_info_(render_info)
const ExecutionOptions & eo
const ExecutorDispatchMode kernel_dispatch_mode
const RelAlgExecutionUnit & ra_exe_unit_
const int64_t rowid_lookup_key
const ExecutorDeviceType chosen_device_type
RenderInfo * render_info_
const QueryMemoryDescriptor & query_mem_desc
const QueryCompilationDescriptor & query_comp_desc
const FragmentsList frag_list
const ColumnFetcher & column_fetcher

Member Function Documentation

void ExecutionKernel::run ( Executor executor,
const size_t  thread_idx,
SharedKernelContext shared_context 
)

Definition at line 90 of file ExecutionKernel.cpp.

References DEBUG_TIMER, Executor::ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED, Executor::ERR_OUT_OF_CPU_MEM, Executor::ERR_OUT_OF_GPU_MEM, Executor::ERR_OUT_OF_RENDER_MEM, Executor::ERR_STRING_CONST_IN_RESULTSET, Executor::ERR_TOO_MANY_LITERALS, QueryMemoryDescriptor::getQueryDescriptionType(), INJECT_TIMER, kernel_dispatch_mode, MultifragmentKernel, query_mem_desc, runImpl(), and OutOfHostMemory::what().

Referenced by Executor::executeUpdate(), Executor::executeWorkUnitPerFragment(), and Executor::launchKernels().

92  {
93  DEBUG_TIMER("ExecutionKernel::run");
94  INJECT_TIMER(kernel_run);
95  try {
96  runImpl(executor, thread_idx, shared_context);
97  } catch (const OutOfHostMemory& e) {
99  } catch (const std::bad_alloc& e) {
101  } catch (const OutOfRenderMemory& e) {
103  } catch (const OutOfMemory& e) {
104  throw QueryExecutionError(
106  e.what(),
110  } catch (const ColumnarConversionNotSupported& e) {
112  } catch (const TooManyLiterals& e) {
114  } catch (const StringConstInResultSet& e) {
116  } catch (const QueryExecutionError& e) {
117  throw e;
118  }
119 }
virtual const char * what() const noexceptfinal
Definition: checked_alloc.h:39
const ExecutorDispatchMode kernel_dispatch_mode
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1123
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1124
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1122
#define INJECT_TIMER(DESC)
Definition: measure.h:93
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1117
const QueryMemoryDescriptor & query_mem_desc
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1114
QueryDescriptionType getQueryDescriptionType() const
void runImpl(Executor *executor, const size_t thread_idx, SharedKernelContext &shared_context)
#define DEBUG_TIMER(name)
Definition: Logger.h:322
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1118

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExecutionKernel::runImpl ( Executor executor,
const size_t  thread_idx,
SharedKernelContext shared_context 
)
private

Definition at line 121 of file ExecutionKernel.cpp.

References gpu_enabled::accumulate(), SharedKernelContext::addDeviceResults(), ExecutionOptions::allow_runtime_query_interrupt, CHECK, CHECK_EQ, CHECK_GE, CHECK_GT, CHECK_LT, chosen_device_id, chosen_device_type, FetchResult::col_buffers, column_fetcher, QueryFragmentDescriptor::computeAllTablesFragments(), CPU, Data_Namespace::CPU_LEVEL, device_results_, dynamic_watchdog_init(), SharedKernelContext::dynamic_watchdog_set, ExecutionOptions::dynamic_watchdog_time_limit, eo, Executor::ERR_OUT_OF_CPU_MEM, Executor::ERR_OUT_OF_GPU_MEM, ExecutionOptions::executor_type, Extern, frag_list, FetchResult::frag_offsets, QueryCompilationDescriptor::getCompilationResult(), SharedKernelContext::getFragOffsets(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getQueryExecutionContext(), SharedKernelContext::getQueryInfos(), GPU, Data_Namespace::GPU_LEVEL, RelAlgExecutionUnit::groupby_exprs, QueryCompilationDescriptor::hoistLiterals(), logger::INFO, RelAlgExecutionUnit::input_descs, RenderInfo::isPotentialInSituRender(), kernel_dispatch_mode, KernelPerFragment, LOG, Executor::max_gpu_count, MultifragmentKernel, Native, anonymous_namespace{ExecutionKernel.cpp}::need_to_hold_chunk(), FetchResult::num_rows, CompilationResult::output_columnar, Projection, query_comp_desc, anonymous_namespace{ExecutionKernel.cpp}::query_has_inner_join(), query_mem_desc, ra_exe_unit_, render_info_, rowid_lookup_key, run_query_external(), RelAlgExecutionUnit::scan_limit, serialize_to_sql(), QueryMemoryDescriptor::sortOnGpu(), RelAlgExecutionUnit::target_exprs, target_exprs_to_infos(), to_string(), RelAlgExecutionUnit::union_all, VLOG, and ExecutionOptions::with_dynamic_watchdog.

Referenced by run().

123  {
124  CHECK(executor);
125  const auto memory_level = chosen_device_type == ExecutorDeviceType::GPU
128  CHECK_GE(frag_list.size(), size_t(1));
129  // frag_list[0].table_id is how we tell which query we are running for UNION ALL.
130  const int outer_table_id = ra_exe_unit_.union_all
131  ? frag_list[0].table_id
132  : ra_exe_unit_.input_descs[0].getTableId();
133  CHECK_EQ(frag_list[0].table_id, outer_table_id);
134  const auto& outer_tab_frag_ids = frag_list[0].fragment_ids;
135 
138 
139  auto catalog = executor->getCatalog();
140  CHECK(catalog);
141 
142  // need to own them while query executes
143  auto chunk_iterators_ptr = std::make_shared<std::list<ChunkIter>>();
144  std::list<std::shared_ptr<Chunk_NS::Chunk>> chunks;
145  std::unique_ptr<std::lock_guard<std::mutex>> gpu_lock;
146  std::unique_ptr<CudaAllocator> device_allocator;
148  gpu_lock.reset(
149  new std::lock_guard<std::mutex>(executor->gpu_exec_mutex_[chosen_device_id]));
150  device_allocator =
151  std::make_unique<CudaAllocator>(&catalog->getDataMgr(), chosen_device_id);
152  }
153  FetchResult fetch_result;
154  try {
155  std::map<int, const TableFragments*> all_tables_fragments;
157  all_tables_fragments, ra_exe_unit_, shared_context.getQueryInfos());
158 
159  fetch_result = ra_exe_unit_.union_all
160  ? executor->fetchUnionChunks(column_fetcher,
161  ra_exe_unit_,
163  memory_level,
164  all_tables_fragments,
165  frag_list,
166  *catalog,
167  *chunk_iterators_ptr,
168  chunks,
169  device_allocator.get(),
170  thread_idx,
172  : executor->fetchChunks(column_fetcher,
173  ra_exe_unit_,
175  memory_level,
176  all_tables_fragments,
177  frag_list,
178  *catalog,
179  *chunk_iterators_ptr,
180  chunks,
181  device_allocator.get(),
182  thread_idx,
184  if (fetch_result.num_rows.empty()) {
185  return;
186  }
188  !shared_context.dynamic_watchdog_set.test_and_set(std::memory_order_acquire)) {
191  LOG(INFO) << "Dynamic Watchdog budget: CPU: "
193  << std::to_string(cycle_budget) << " cycles";
194  }
195  } catch (const OutOfMemory&) {
196  throw QueryExecutionError(
202  return;
203  }
204 
206  if (ra_exe_unit_.input_descs.size() > 1) {
207  throw std::runtime_error("Joins not supported through external execution");
208  }
209  const auto query = serialize_to_sql(&ra_exe_unit_, catalog);
210  GroupByAndAggregate group_by_and_aggregate(executor,
212  ra_exe_unit_,
213  shared_context.getQueryInfos(),
214  executor->row_set_mem_owner_,
215  std::nullopt);
216  const auto query_mem_desc =
217  group_by_and_aggregate.initQueryMemoryDescriptor(false, 0, 8, nullptr, false);
219  query,
220  fetch_result,
221  executor->plan_state_.get(),
225  executor});
226  shared_context.addDeviceResults(std::move(device_results_), outer_tab_frag_ids);
227  return;
228  }
229  const CompilationResult& compilation_result = query_comp_desc.getCompilationResult();
230  std::unique_ptr<QueryExecutionContext> query_exe_context_owned;
231  const bool do_render = render_info_ && render_info_->isPotentialInSituRender();
232 
233  int64_t total_num_input_rows{-1};
235  query_mem_desc.getQueryDescriptionType() == QueryDescriptionType::Projection) {
236  total_num_input_rows = 0;
237  std::for_each(fetch_result.num_rows.begin(),
238  fetch_result.num_rows.end(),
239  [&total_num_input_rows](const std::vector<int64_t>& frag_row_count) {
240  total_num_input_rows = std::accumulate(frag_row_count.begin(),
241  frag_row_count.end(),
242  total_num_input_rows);
243  });
244  VLOG(2) << "total_num_input_rows=" << total_num_input_rows;
245  // TODO(adb): we may want to take this early out for all queries, but we are most
246  // likely to see this query pattern on the kernel per fragment path (e.g. with HAVING
247  // 0=1)
248  if (total_num_input_rows == 0) {
249  return;
250  }
251 
253  total_num_input_rows *= ra_exe_unit_.input_descs.size();
254  }
255  }
256 
258  try {
259  query_exe_context_owned =
260  query_mem_desc.getQueryExecutionContext(ra_exe_unit_,
261  executor,
265  total_num_input_rows,
266  fetch_result.col_buffers,
267  fetch_result.frag_offsets,
268  executor->getRowSetMemoryOwner(),
269  compilation_result.output_columnar,
270  query_mem_desc.sortOnGpu(),
271  thread_idx,
272  do_render ? render_info_ : nullptr);
273  } catch (const OutOfHostMemory& e) {
274  throw QueryExecutionError(Executor::ERR_OUT_OF_CPU_MEM);
275  }
276  }
277  QueryExecutionContext* query_exe_context{query_exe_context_owned.get()};
278  CHECK(query_exe_context);
279  int32_t err{0};
280  uint32_t start_rowid{0};
281  if (rowid_lookup_key >= 0) {
282  if (!frag_list.empty()) {
283  const auto& all_frag_row_offsets = shared_context.getFragOffsets();
284  start_rowid = rowid_lookup_key -
285  all_frag_row_offsets[frag_list.begin()->fragment_ids.front()];
286  }
287  }
288 
289  if (ra_exe_unit_.groupby_exprs.empty()) {
290  err = executor->executePlanWithoutGroupBy(ra_exe_unit_,
291  compilation_result,
296  fetch_result.col_buffers,
297  query_exe_context,
298  fetch_result.num_rows,
299  fetch_result.frag_offsets,
300  &catalog->getDataMgr(),
302  start_rowid,
303  ra_exe_unit_.input_descs.size(),
305  do_render ? render_info_ : nullptr);
306  } else {
307  if (ra_exe_unit_.union_all) {
308  VLOG(1) << "outer_table_id=" << outer_table_id
309  << " ra_exe_unit_.scan_limit=" << ra_exe_unit_.scan_limit;
310  }
311  err = executor->executePlanWithGroupBy(ra_exe_unit_,
312  compilation_result,
316  fetch_result.col_buffers,
317  outer_tab_frag_ids,
318  query_exe_context,
319  fetch_result.num_rows,
320  fetch_result.frag_offsets,
321  &catalog->getDataMgr(),
323  outer_table_id,
325  start_rowid,
326  ra_exe_unit_.input_descs.size(),
328  do_render ? render_info_ : nullptr);
329  }
330  if (device_results_) {
331  std::list<std::shared_ptr<Chunk_NS::Chunk>> chunks_to_hold;
332  for (const auto& chunk : chunks) {
333  if (need_to_hold_chunk(chunk.get(), ra_exe_unit_)) {
334  chunks_to_hold.push_back(chunk);
335  }
336  }
337  device_results_->holdChunks(chunks_to_hold);
338  device_results_->holdChunkIterators(chunk_iterators_ptr);
339  } else {
340  VLOG(1) << "null device_results.";
341  }
342  if (err) {
343  throw QueryExecutionError(err);
344  }
345  shared_context.addDeviceResults(std::move(device_results_), outer_tab_frag_ids);
346 }
std::vector< Analyzer::Expr * > target_exprs
#define CHECK_EQ(x, y)
Definition: Logger.h:214
std::atomic_flag dynamic_watchdog_set
const ExecutionOptions & eo
const std::vector< uint64_t > & getFragOffsets()
static const int max_gpu_count
Definition: Execute.h:1032
const std::optional< bool > union_all
#define LOG(tag)
Definition: Logger.h:200
const ExecutorDispatchMode kernel_dispatch_mode
const RelAlgExecutionUnit & ra_exe_unit_
const int64_t rowid_lookup_key
void addDeviceResults(ResultSetPtr &&device_results, std::vector< size_t > outer_table_fragment_ids)
std::vector< InputDescriptor > input_descs
const ExecutorDeviceType chosen_device_type
#define CHECK_GE(x, y)
Definition: Logger.h:219
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
std::unique_ptr< ResultSet > run_query_external(const ExecutionUnitSql &sql, const FetchResult &fetch_result, const PlanState *plan_state, const ExternalQueryOutputSpec &output_spec)
RenderInfo * render_info_
#define CHECK_GT(x, y)
Definition: Logger.h:218
std::string to_string(char const *&&v)
ExecutorType executor_type
const QueryMemoryDescriptor & query_mem_desc
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
const QueryCompilationDescriptor & query_comp_desc
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1114
bool need_to_hold_chunk(const Chunk_NS::Chunk *chunk, const RelAlgExecutionUnit &ra_exe_unit)
QueryDescriptionType getQueryDescriptionType() const
RUNTIME_EXPORT uint64_t dynamic_watchdog_init(unsigned ms_budget)
#define CHECK_LT(x, y)
Definition: Logger.h:216
const FragmentsList frag_list
bool query_has_inner_join(const RelAlgExecutionUnit &ra_exe_unit)
const std::vector< InputTableInfo > & getQueryInfos() const
ResultSetPtr device_results_
bool isPotentialInSituRender() const
Definition: RenderInfo.cpp:64
#define CHECK(condition)
Definition: Logger.h:206
std::vector< TargetInfo > target_exprs_to_infos(const std::vector< Analyzer::Expr * > &targets, const QueryMemoryDescriptor &query_mem_desc)
unsigned dynamic_watchdog_time_limit
ExecutionUnitSql serialize_to_sql(const RelAlgExecutionUnit *ra_exe_unit, const Catalog_Namespace::Catalog *catalog)
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1118
static void computeAllTablesFragments(std::map< int, const TableFragments * > &all_tables_fragments, const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos)
#define VLOG(n)
Definition: Logger.h:300
const ColumnFetcher & column_fetcher

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

int ExecutionKernel::chosen_device_id
private

Definition at line 81 of file ExecutionKernel.h.

Referenced by runImpl().

const ExecutorDeviceType ExecutionKernel::chosen_device_type
private

Definition at line 80 of file ExecutionKernel.h.

Referenced by runImpl().

const ColumnFetcher& ExecutionKernel::column_fetcher
private

Definition at line 83 of file ExecutionKernel.h.

Referenced by runImpl().

ResultSetPtr ExecutionKernel::device_results_
private

Definition at line 91 of file ExecutionKernel.h.

Referenced by runImpl().

const ExecutionOptions& ExecutionKernel::eo
private

Definition at line 82 of file ExecutionKernel.h.

Referenced by runImpl().

const FragmentsList ExecutionKernel::frag_list
private

Definition at line 86 of file ExecutionKernel.h.

Referenced by runImpl().

const ExecutorDispatchMode ExecutionKernel::kernel_dispatch_mode
private

Definition at line 87 of file ExecutionKernel.h.

Referenced by run(), and runImpl().

const QueryCompilationDescriptor& ExecutionKernel::query_comp_desc
private

Definition at line 84 of file ExecutionKernel.h.

Referenced by runImpl().

const QueryMemoryDescriptor& ExecutionKernel::query_mem_desc
private

Definition at line 85 of file ExecutionKernel.h.

Referenced by run(), and runImpl().

const RelAlgExecutionUnit& ExecutionKernel::ra_exe_unit_
private

Definition at line 79 of file ExecutionKernel.h.

Referenced by runImpl().

RenderInfo* ExecutionKernel::render_info_
private

Definition at line 88 of file ExecutionKernel.h.

Referenced by runImpl().

const int64_t ExecutionKernel::rowid_lookup_key
private

Definition at line 89 of file ExecutionKernel.h.

Referenced by runImpl().


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