OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResultSetReductionJIT Class Reference

#include <ResultSetReductionJIT.h>

+ Inheritance diagram for ResultSetReductionJIT:
+ Collaboration diagram for ResultSetReductionJIT:

Public Member Functions

 ResultSetReductionJIT (const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const std::vector< int64_t > &target_init_vals, const size_t executor_id)
 
virtual ~ResultSetReductionJIT ()=default
 
virtual ReductionCode codegen () const
 

Protected Member Functions

void isEmpty (const ReductionCode &reduction_code) const
 
void reduceOneEntryNoCollisions (const ReductionCode &reduction_code) const
 
void reduceOneEntryNoCollisionsIdx (const ReductionCode &reduction_code) const
 
void reduceLoop (const ReductionCode &reduction_code) const
 

Protected Attributes

size_t executor_id_
 

Private Member Functions

void reduceOneEntryTargetsNoCollisions (Function *ir_reduce_one_entry, Value *this_targets_start_ptr, Value *that_targets_start_ptr) const
 
void reduceOneEntryBaseline (const ReductionCode &reduction_code) const
 
void reduceOneEntryBaselineIdx (const ReductionCode &reduction_code) const
 
void reduceOneSlot (Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const size_t first_slot_idx_for_target, Function *ir_reduce_one_entry) const
 
void reduceOneAggregateSlot (Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const int64_t init_val, const int8_t chosen_bytes, Function *ir_reduce_one_entry) const
 
void reduceOneCountDistinctSlot (Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
 
void reduceOneApproxQuantileSlot (Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
 
void finalizeReductionCode (ReductionCode &reduction_code, const llvm::Function *ir_is_empty, const llvm::Function *ir_reduce_one_entry, const llvm::Function *ir_reduce_one_entry_idx, const CodeCacheKey &key) const
 
std::string cacheKey () const
 

Private Attributes

const QueryMemoryDescriptor query_mem_desc_
 
const std::vector< TargetInfotargets_
 
const std::vector< int64_t > target_init_vals_
 

Detailed Description

Definition at line 52 of file ResultSetReductionJIT.h.

Constructor & Destructor Documentation

ResultSetReductionJIT::ResultSetReductionJIT ( const QueryMemoryDescriptor query_mem_desc,
const std::vector< TargetInfo > &  targets,
const std::vector< int64_t > &  target_init_vals,
const size_t  executor_id 
)

Definition at line 513 of file ResultSetReductionJIT.cpp.

517  : executor_id_(executor_id)
518  , query_mem_desc_(query_mem_desc)
519  , targets_(targets)
520  , target_init_vals_(target_init_vals) {}
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
const std::vector< TargetInfo > targets_
virtual ResultSetReductionJIT::~ResultSetReductionJIT ( )
virtualdefault

Member Function Documentation

std::string ResultSetReductionJIT::cacheKey ( ) const
private

Definition at line 1279 of file ResultSetReductionJIT.cpp.

References join(), query_mem_desc_, QueryMemoryDescriptor::reductionKey(), anonymous_namespace{ResultSetReductionJIT.cpp}::target_info_key(), target_init_vals_, targets_, to_string(), and shared::transform().

Referenced by codegen().

1279  {
1280  std::vector<std::string> target_init_vals_strings;
1282  target_init_vals_.end(),
1283  std::back_inserter(target_init_vals_strings),
1284  [](const int64_t v) { return std::to_string(v); });
1285  const auto target_init_vals_key =
1286  boost::algorithm::join(target_init_vals_strings, ", ");
1287  std::vector<std::string> targets_strings;
1289  targets_.begin(),
1290  targets_.end(),
1291  std::back_inserter(targets_strings),
1292  [](const TargetInfo& target_info) { return target_info_key(target_info); });
1293  const auto targets_key = boost::algorithm::join(targets_strings, ", ");
1294  return query_mem_desc_.reductionKey() + "\n" + target_init_vals_key + "\n" +
1295  targets_key;
1296 }
std::string join(T const &container, std::string const &delim)
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
std::string to_string(char const *&&v)
std::string target_info_key(const TargetInfo &target_info)
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296
std::string reductionKey() const
const std::vector< TargetInfo > targets_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ReductionCode ResultSetReductionJIT::codegen ( ) const
virtual

Reimplemented in GpuReductionHelperJIT.

Definition at line 553 of file ResultSetReductionJIT.cpp.

References AUTOMATIC_IR_METADATA, AUTOMATIC_IR_METADATA_DONE, QueryMemoryDescriptor::blocksShareMemory(), cacheKey(), anonymous_namespace{ResultSetReductionJIT.cpp}::create_llvm_function(), QueryMemoryDescriptor::didOutputColumnar(), executor_id_, anonymous_namespace{Utm.h}::f, logger::FATAL, finalizeReductionCode(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getExecutor(), Executor::getExecutor(), QueryEngine::getInstance(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, GroupByPerfectHash, anonymous_namespace{ResultSetReductionJIT.cpp}::INTERP_THRESHOLD, anonymous_namespace{ResultSetReductionJIT.cpp}::is_aggregate_query(), isEmpty(), LOG, NonGroupedAggregate, query_mem_desc_, reduceLoop(), reduceOneEntryBaseline(), reduceOneEntryBaselineIdx(), reduceOneEntryNoCollisions(), reduceOneEntryNoCollisionsIdx(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_functions_ir(), and translate_function().

Referenced by anonymous_namespace{Execute.cpp}::get_reduction_code(), and ResultSetManager::reduce().

553  {
554  const auto hash_type = query_mem_desc_.getQueryDescriptionType();
556  return {};
557  }
558  auto reduction_code = setup_functions_ir(hash_type);
559  isEmpty(reduction_code);
563  reduceOneEntryNoCollisions(reduction_code);
564  reduceOneEntryNoCollisionsIdx(reduction_code);
565  break;
566  }
568  reduceOneEntryBaseline(reduction_code);
569  reduceOneEntryBaselineIdx(reduction_code);
570  break;
571  }
572  default: {
573  LOG(FATAL) << "Unexpected query description type";
574  }
575  }
576  reduceLoop(reduction_code);
577  // For small result sets, avoid native code generation and use the interpreter instead.
580  return reduction_code;
581  }
582  auto executor = Executor::getExecutor(executor_id_);
583  CodeCacheKey key{cacheKey()};
584  std::lock_guard<std::mutex> compilation_lock(executor->compilation_mutex_);
585  const auto compilation_context =
586  QueryEngine::getInstance()->s_code_accessor->get_or_wait(key);
587  if (compilation_context) {
588  reduction_code.func_ptr =
589  reinterpret_cast<ReductionCode::FuncPtr>(compilation_context->get()->func());
590  return reduction_code;
591  }
592  auto cgen_state_ = std::unique_ptr<CgenState>(new CgenState({}, false, executor.get()));
593  auto cgen_state = reduction_code.cgen_state = cgen_state_.get();
594  cgen_state->set_module_shallow_copy(executor->get_rt_module());
595  reduction_code.module = cgen_state->module_;
596 
597  AUTOMATIC_IR_METADATA(cgen_state);
598  auto ir_is_empty = create_llvm_function(reduction_code.ir_is_empty.get(), cgen_state);
599  auto ir_reduce_one_entry =
600  create_llvm_function(reduction_code.ir_reduce_one_entry.get(), cgen_state);
601  auto ir_reduce_one_entry_idx =
602  create_llvm_function(reduction_code.ir_reduce_one_entry_idx.get(), cgen_state);
603  auto ir_reduce_loop =
604  create_llvm_function(reduction_code.ir_reduce_loop.get(), cgen_state);
605  std::unordered_map<const Function*, llvm::Function*> f;
606  f.emplace(reduction_code.ir_is_empty.get(), ir_is_empty);
607  f.emplace(reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry);
608  f.emplace(reduction_code.ir_reduce_one_entry_idx.get(), ir_reduce_one_entry_idx);
609  f.emplace(reduction_code.ir_reduce_loop.get(), ir_reduce_loop);
610  translate_function(reduction_code.ir_is_empty.get(), ir_is_empty, reduction_code, f);
612  reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry, reduction_code, f);
613  translate_function(reduction_code.ir_reduce_one_entry_idx.get(),
614  ir_reduce_one_entry_idx,
615  reduction_code,
616  f);
618  reduction_code.ir_reduce_loop.get(), ir_reduce_loop, reduction_code, f);
619  reduction_code.llvm_reduce_loop = ir_reduce_loop;
621  reduction_code.cgen_state = nullptr;
623  reduction_code, ir_is_empty, ir_reduce_one_entry, ir_reduce_one_entry_idx, key);
624  return reduction_code;
625 }
bool is_aggregate_query(const QueryDescriptionType hash_type)
void reduceOneEntryNoCollisions(const ReductionCode &reduction_code) const
void reduceOneEntryBaselineIdx(const ReductionCode &reduction_code) const
#define LOG(tag)
Definition: Logger.h:216
void reduceLoop(const ReductionCode &reduction_code) const
void reduceOneEntryNoCollisionsIdx(const ReductionCode &reduction_code) const
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:25
std::string cacheKey() const
int32_t(*)(int8_t *this_buff, const int8_t *that_buff, const int32_t start_entry_index, const int32_t end_entry_index, const int32_t that_entry_count, const void *this_qmd, const void *that_qmd, const void *serialized_varlen_buffer) FuncPtr
const QueryMemoryDescriptor query_mem_desc_
constexpr double f
Definition: Utm.h:31
void translate_function(const Function *function, llvm::Function *llvm_function, const ReductionCode &reduction_code, const std::unordered_map< const Function *, llvm::Function * > &f)
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:477
ReductionCode setup_functions_ir(const QueryDescriptionType hash_type)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
QueryDescriptionType getQueryDescriptionType() const
#define AUTOMATIC_IR_METADATA_DONE()
void finalizeReductionCode(ReductionCode &reduction_code, const llvm::Function *ir_is_empty, const llvm::Function *ir_reduce_one_entry, const llvm::Function *ir_reduce_one_entry_idx, const CodeCacheKey &key) const
void isEmpty(const ReductionCode &reduction_code) const
void reduceOneEntryBaseline(const ReductionCode &reduction_code) const
static std::shared_ptr< QueryEngine > getInstance()
Definition: QueryEngine.h:81
llvm::Function * create_llvm_function(const Function *function, CgenState *cgen_state)
const Executor * getExecutor() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::finalizeReductionCode ( ReductionCode reduction_code,
const llvm::Function *  ir_is_empty,
const llvm::Function *  ir_reduce_one_entry,
const llvm::Function *  ir_reduce_one_entry_idx,
const CodeCacheKey key 
) const
private

Definition at line 1234 of file ResultSetReductionJIT.cpp.

References CPU, CodeGenerator::generateNativeCPUCode(), logger::IR, ReductionCode::llvm_reduce_loop, LOG, ReductionCode::module, ReductionJIT, and serialize_llvm_object().

Referenced by codegen().

1239  {
1240  CompilationOptions co{
1242 #ifdef NDEBUG
1243  LOG(IR) << "Reduction Loop:\n"
1244  << serialize_llvm_object(reduction_code.llvm_reduce_loop);
1245  LOG(IR) << "Reduction Is Empty Func:\n" << serialize_llvm_object(ir_is_empty);
1246  LOG(IR) << "Reduction One Entry Func:\n" << serialize_llvm_object(ir_reduce_one_entry);
1247  LOG(IR) << "Reduction One Entry Idx Func:\n"
1248  << serialize_llvm_object(ir_reduce_one_entry_idx);
1249 #else
1250  LOG(IR) << serialize_llvm_object(reduction_code.module);
1251 #endif
1253  reduction_code.llvm_reduce_loop, {reduction_code.llvm_reduce_loop}, co);
1254  auto cpu_compilation_context = std::make_shared<CpuCompilationContext>(std::move(ee));
1255  cpu_compilation_context->setFunctionPointer(reduction_code.llvm_reduce_loop);
1256  reduction_code.func_ptr =
1257  reinterpret_cast<ReductionCode::FuncPtr>(cpu_compilation_context->func());
1258  CHECK(reduction_code.llvm_reduce_loop->getParent() == reduction_code.module);
1259  auto executor = Executor::getExecutor(executor_id_);
1260  QueryEngine::getInstance()->s_code_accessor->swap(key,
1261  std::move(cpu_compilation_context));
1262 }
#define LOG(tag)
Definition: Logger.h:216
llvm::Function * llvm_reduce_loop
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co)
int32_t(*)(int8_t *this_buff, const int8_t *that_buff, const int32_t start_entry_index, const int32_t end_entry_index, const int32_t that_entry_count, const void *this_qmd, const void *that_qmd, const void *serialized_varlen_buffer) FuncPtr
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:477
llvm::Module * module
std::string serialize_llvm_object(const T *llvm_obj)
#define CHECK(condition)
Definition: Logger.h:222
static std::shared_ptr< QueryEngine > getInstance()
Definition: QueryEngine.h:81

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::isEmpty ( const ReductionCode reduction_code) const
protected

Definition at line 627 of file ResultSetReductionJIT.cpp.

References CHECK, CHECK_GE, CHECK_LT, QueryMemoryDescriptor::didOutputColumnar(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i32(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_read_int_from_buff(), EMPTY_KEY_32, EMPTY_KEY_64, ICmp::EQ, logger::FATAL, result_set::get_byteoff_of_slot(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getTargetIdxForKey(), GroupByPerfectHash, QueryMemoryDescriptor::hasKeylessHash(), Int32, Int64, ReductionCode::ir_is_empty, anonymous_namespace{ResultSetReductionJIT.cpp}::is_aggregate_query(), LOG, query_mem_desc_, and target_init_vals_.

Referenced by codegen(), and GpuReductionHelperJIT::codegen().

627  {
628  auto ir_is_empty = reduction_code.ir_is_empty.get();
631  Value* key{nullptr};
632  Value* empty_key_val{nullptr};
633  const auto keys_ptr = ir_is_empty->arg(0);
638  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
639  target_init_vals_.size());
640  const int64_t target_slot_off = result_set::get_byteoff_of_slot(
642  const auto slot_ptr = ir_is_empty->add<GetElementPtr>(
643  keys_ptr,
644  ir_is_empty->addConstant<ConstantInt>(target_slot_off, Type::Int32),
645  "is_empty_slot_ptr");
646  const auto compact_sz =
648  key = emit_read_int_from_buff(slot_ptr, compact_sz, ir_is_empty);
649  empty_key_val = ir_is_empty->addConstant<ConstantInt>(
651  } else {
653  case 4: {
656  key = emit_load_i32(keys_ptr, ir_is_empty);
657  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_32, Type::Int32);
658  break;
659  }
660  case 8: {
661  key = emit_load_i64(keys_ptr, ir_is_empty);
662  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_64, Type::Int64);
663  break;
664  }
665  default:
666  LOG(FATAL) << "Invalid key width";
667  }
668  }
669  const auto ret =
670  ir_is_empty->add<ICmp>(ICmp::Predicate::EQ, key, empty_key_val, "is_key_empty");
671  ir_is_empty->add<Ret>(ret);
672 }
bool is_aggregate_query(const QueryDescriptionType hash_type)
#define EMPTY_KEY_64
Value * emit_read_int_from_buff(Value *ptr, const int8_t compact_sz, Function *function)
#define LOG(tag)
Definition: Logger.h:216
#define CHECK_GE(x, y)
Definition: Logger.h:235
size_t getEffectiveKeyWidth() const
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
Value * emit_load_i32(Value *ptr, Function *function)
size_t get_byteoff_of_slot(const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
QueryDescriptionType getQueryDescriptionType() const
#define CHECK_LT(x, y)
Definition: Logger.h:232
Value * emit_load_i64(Value *ptr, Function *function)
#define CHECK(condition)
Definition: Logger.h:222
#define EMPTY_KEY_32
int32_t getTargetIdxForKey() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceLoop ( const ReductionCode reduction_code) const
protected

Definition at line 1019 of file ResultSetReductionJIT.cpp.

References anonymous_namespace{ResultSetReductionJIT.cpp}::generate_loop_body(), Int32, ReductionCode::ir_reduce_loop, and ReductionCode::ir_reduce_one_entry_idx.

Referenced by codegen(), and GpuReductionHelperJIT::codegen().

1019  {
1020  auto ir_reduce_loop = reduction_code.ir_reduce_loop.get();
1021  const auto this_buff_arg = ir_reduce_loop->arg(0);
1022  const auto that_buff_arg = ir_reduce_loop->arg(1);
1023  const auto start_index_arg = ir_reduce_loop->arg(2);
1024  const auto end_index_arg = ir_reduce_loop->arg(3);
1025  const auto that_entry_count_arg = ir_reduce_loop->arg(4);
1026  const auto this_qmd_handle_arg = ir_reduce_loop->arg(5);
1027  const auto that_qmd_handle_arg = ir_reduce_loop->arg(6);
1028  const auto serialized_varlen_buffer_arg = ir_reduce_loop->arg(7);
1029  For* for_loop =
1030  static_cast<For*>(ir_reduce_loop->add<For>(start_index_arg, end_index_arg, ""));
1031  generate_loop_body(for_loop,
1032  ir_reduce_loop,
1033  reduction_code.ir_reduce_one_entry_idx.get(),
1034  this_buff_arg,
1035  that_buff_arg,
1036  start_index_arg,
1037  that_entry_count_arg,
1038  this_qmd_handle_arg,
1039  that_qmd_handle_arg,
1040  serialized_varlen_buffer_arg);
1041  ir_reduce_loop->add<Ret>(ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int32));
1042 }
std::unique_ptr< Function > ir_reduce_loop
void generate_loop_body(For *for_loop, Function *ir_reduce_loop, Function *ir_reduce_one_entry_idx, Value *this_buff, Value *that_buff, Value *start_index, Value *that_entry_count, Value *this_qmd_handle, Value *that_qmd_handle, Value *serialized_varlen_buffer)
std::unique_ptr< Function > ir_reduce_one_entry_idx

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneAggregateSlot ( Value this_ptr1,
Value this_ptr2,
Value that_ptr1,
Value that_ptr2,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  target_slot_idx,
const int64_t  init_val,
const int8_t  chosen_bytes,
Function ir_reduce_one_entry 
) const
private

Definition at line 1119 of file ResultSetReductionJIT.cpp.

References TargetInfo::agg_kind, CHECK_EQ, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_count(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), logger::FATAL, QueryMemoryDescriptor::getPaddedSlotWidthBytes(), is_distinct_target(), kAPPROX_COUNT_DISTINCT, kAPPROX_QUANTILE, kAVG, kCOUNT, kMAX, kMIN, kSUM, LOG, query_mem_desc_, reduceOneApproxQuantileSlot(), and reduceOneCountDistinctSlot().

Referenced by reduceOneSlot().

1128  {
1129  switch (target_info.agg_kind) {
1130  case kCOUNT:
1131  case kAPPROX_COUNT_DISTINCT: {
1132  if (is_distinct_target(target_info)) {
1133  CHECK_EQ(static_cast<size_t>(chosen_bytes), sizeof(int64_t));
1135  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1136  break;
1137  }
1138  CHECK_EQ(int64_t(0), init_val);
1139  emit_aggregate_one_count(this_ptr1, that_ptr1, chosen_bytes, ir_reduce_one_entry);
1140  break;
1141  }
1142  case kAPPROX_QUANTILE:
1143  CHECK_EQ(chosen_bytes, static_cast<int8_t>(sizeof(int64_t)));
1145  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1146  break;
1147  case kAVG: {
1148  // Ignore float argument compaction for count component for fear of its overflow
1149  emit_aggregate_one_count(this_ptr2,
1150  that_ptr2,
1151  query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx),
1152  ir_reduce_one_entry);
1153  }
1154  // fall thru
1155  case kSUM: {
1157  this_ptr1,
1158  that_ptr1,
1159  init_val,
1160  chosen_bytes,
1161  target_info,
1162  ir_reduce_one_entry);
1163  break;
1164  }
1165  case kMIN: {
1167  this_ptr1,
1168  that_ptr1,
1169  init_val,
1170  chosen_bytes,
1171  target_info,
1172  ir_reduce_one_entry);
1173  break;
1174  }
1175  case kMAX: {
1177  this_ptr1,
1178  that_ptr1,
1179  init_val,
1180  chosen_bytes,
1181  target_info,
1182  ir_reduce_one_entry);
1183  break;
1184  }
1185  default:
1186  LOG(FATAL) << "Invalid aggregate type";
1187  }
1188 }
void emit_aggregate_one_nullable_value(const std::string &agg_kind, Value *val_ptr, Value *other_ptr, const int64_t init_val, const size_t chosen_bytes, const TargetInfo &agg_info, Function *ir_reduce_one_entry)
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define LOG(tag)
Definition: Logger.h:216
const QueryMemoryDescriptor query_mem_desc_
Definition: sqldefs.h:74
void reduceOneCountDistinctSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
Definition: sqldefs.h:76
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:107
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:51
Definition: sqldefs.h:77
void emit_aggregate_one_count(Value *val_ptr, Value *other_ptr, const size_t chosen_bytes, Function *ir_reduce_one_entry)
Definition: sqldefs.h:75
Definition: sqldefs.h:73
void reduceOneApproxQuantileSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneApproxQuantileSlot ( Value this_ptr1,
Value that_ptr1,
const size_t  target_logical_idx,
Function ir_reduce_one_entry 
) const
private

Definition at line 1212 of file ResultSetReductionJIT.cpp.

References CHECK_LT, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64(), QueryMemoryDescriptor::getCountDistinctDescriptorsSize(), Int64, query_mem_desc_, and Void.

Referenced by reduceOneAggregateSlot().

1216  {
1218  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1219  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1220  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1221  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1222  ir_reduce_one_entry->add<ExternalCall>(
1223  "approx_quantile_jit_rt",
1224  Type::Void,
1225  std::vector<const Value*>{
1226  new_set_handle,
1227  old_set_handle,
1228  that_qmd_arg,
1229  this_qmd_arg,
1230  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1231  "");
1232 }
const QueryMemoryDescriptor query_mem_desc_
size_t getCountDistinctDescriptorsSize() const
#define CHECK_LT(x, y)
Definition: Logger.h:232
Value * emit_load_i64(Value *ptr, Function *function)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneCountDistinctSlot ( Value this_ptr1,
Value that_ptr1,
const size_t  target_logical_idx,
Function ir_reduce_one_entry 
) const
private

Definition at line 1190 of file ResultSetReductionJIT.cpp.

References CHECK_LT, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64(), QueryMemoryDescriptor::getCountDistinctDescriptorsSize(), Int64, query_mem_desc_, and Void.

Referenced by reduceOneAggregateSlot().

1194  {
1196  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1197  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1198  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1199  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1200  ir_reduce_one_entry->add<ExternalCall>(
1201  "count_distinct_set_union_jit_rt",
1202  Type::Void,
1203  std::vector<const Value*>{
1204  new_set_handle,
1205  old_set_handle,
1206  that_qmd_arg,
1207  this_qmd_arg,
1208  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1209  "");
1210 }
const QueryMemoryDescriptor query_mem_desc_
size_t getCountDistinctDescriptorsSize() const
#define CHECK_LT(x, y)
Definition: Logger.h:232
Value * emit_load_i64(Value *ptr, Function *function)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneEntryBaseline ( const ReductionCode reduction_code) const
private

Definition at line 789 of file ResultSetReductionJIT.cpp.

References advance_slot(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, ReductionCode::ir_reduce_one_entry, kAVG, kSAMPLE, query_mem_desc_, reduceOneSlot(), QueryMemoryDescriptor::targetGroupbyIndicesSize(), targets_, and to_string().

Referenced by codegen().

790  {
791  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
792  const auto this_targets_ptr_arg = ir_reduce_one_entry->arg(0);
793  const auto that_targets_ptr_arg = ir_reduce_one_entry->arg(1);
794  Value* this_ptr1 = this_targets_ptr_arg;
795  Value* that_ptr1 = that_targets_ptr_arg;
796  size_t j = 0;
797  size_t init_agg_val_idx = 0;
798  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
799  ++target_logical_idx) {
800  const auto& target_info = targets_[target_logical_idx];
801  Value* this_ptr2{nullptr};
802  Value* that_ptr2{nullptr};
803  if (target_info.is_agg &&
804  (target_info.agg_kind == kAVG ||
805  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
806  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
807  const auto second_slot_rel_off =
808  ir_reduce_one_entry->addConstant<ConstantInt>(sizeof(int64_t), Type::Int32);
809  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
810  this_ptr1, second_slot_rel_off, "this_" + desc);
811  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
812  that_ptr1, second_slot_rel_off, "that_" + desc);
813  }
814  reduceOneSlot(this_ptr1,
815  this_ptr2,
816  that_ptr1,
817  that_ptr2,
818  target_info,
819  target_logical_idx,
820  j,
821  init_agg_val_idx,
822  j,
823  ir_reduce_one_entry);
824  if (target_logical_idx + 1 == targets_.size()) {
825  break;
826  }
828  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
829  } else {
830  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
831  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
832  }
833  }
834  j = advance_slot(j, target_info, false);
835  const auto next_desc =
836  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
837  auto next_slot_rel_off = ir_reduce_one_entry->addConstant<ConstantInt>(
838  init_agg_val_idx * sizeof(int64_t), Type::Int32);
839  this_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
840  this_targets_ptr_arg, next_slot_rel_off, next_desc);
841  that_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
842  that_targets_ptr_arg, next_slot_rel_off, next_desc);
843  }
844  ir_reduce_one_entry->add<Ret>(
845  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
846 }
void reduceOneSlot(Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const size_t first_slot_idx_for_target, Function *ir_reduce_one_entry) const
int64_t getTargetGroupbyIndex(const size_t target_idx) const
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::string to_string(char const *&&v)
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
size_t targetGroupbyIndicesSize() const
Definition: sqldefs.h:73
const std::vector< TargetInfo > targets_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneEntryBaselineIdx ( const ReductionCode reduction_code) const
private

Definition at line 882 of file ResultSetReductionJIT.cpp.

References Cast::BitCast, CHECK, QueryMemoryDescriptor::didOutputColumnar(), get_row_bytes(), get_slot_off_quad(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, QueryMemoryDescriptor::hasKeylessHash(), Int1, Int32, Int64, Int64Ptr, Int8, Int8Ptr, ReductionCode::ir_is_empty, ReductionCode::ir_reduce_one_entry, ReductionCode::ir_reduce_one_entry_idx, BinaryOperator::Mul, query_mem_desc_, Cast::SExt, Cast::Trunc, and Void.

Referenced by codegen().

883  {
884  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
889  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
890  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
891  const auto that_entry_idx = ir_reduce_one_entry_idx->arg(2);
892  const auto that_entry_count = ir_reduce_one_entry_idx->arg(3);
893  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
894  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
895  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
896  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
898  const auto that_entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
899  Cast::CastOp::SExt, that_entry_idx, Type::Int64, "that_entry_idx_64");
900  const auto that_row_off_in_bytes =
901  ir_reduce_one_entry_idx->add<BinaryOperator>(BinaryOperator::BinaryOp::Mul,
902  that_entry_idx_64,
903  row_bytes,
904  "that_row_off_in_bytes");
905  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
906  that_buff, that_row_off_in_bytes, "that_row_ptr");
907  const auto that_is_empty =
908  ir_reduce_one_entry_idx->add<Call>(reduction_code.ir_is_empty.get(),
909  std::vector<const Value*>{that_row_ptr},
910  "that_is_empty");
911  ir_reduce_one_entry_idx->add<ReturnEarly>(
912  that_is_empty,
913  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
914  "");
915  const auto key_count = query_mem_desc_.getGroupbyColCount();
916  const auto one_element =
917  ir_reduce_one_entry_idx->addConstant<ConstantInt>(1, Type::Int32);
918  const auto this_targets_ptr_i64_ptr = ir_reduce_one_entry_idx->add<Alloca>(
919  Type::Int64Ptr, one_element, "this_targets_ptr_out");
920  const auto this_is_empty_ptr =
921  ir_reduce_one_entry_idx->add<Alloca>(Type::Int8, one_element, "this_is_empty_out");
922  ir_reduce_one_entry_idx->add<ExternalCall>(
923  "get_group_value_reduction_rt",
924  Type::Void,
925  std::vector<const Value*>{
926  this_buff,
927  that_row_ptr,
928  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_count, Type::Int32),
929  this_qmd_handle,
930  that_buff,
931  that_entry_idx,
932  that_entry_count,
933  row_bytes,
934  this_targets_ptr_i64_ptr,
935  this_is_empty_ptr},
936  "");
937  const auto this_targets_ptr_i64 = ir_reduce_one_entry_idx->add<Load>(
938  this_targets_ptr_i64_ptr, "this_targets_ptr_i64");
939  auto this_is_empty =
940  ir_reduce_one_entry_idx->add<Load>(this_is_empty_ptr, "this_is_empty");
941  this_is_empty = ir_reduce_one_entry_idx->add<Cast>(
942  Cast::CastOp::Trunc, this_is_empty, Type::Int1, "this_is_empty_bool");
943  ir_reduce_one_entry_idx->add<ReturnEarly>(
944  this_is_empty,
945  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
946  "");
947  const auto key_qw_count = get_slot_off_quad(query_mem_desc_);
948  const auto this_targets_ptr = ir_reduce_one_entry_idx->add<Cast>(
949  Cast::CastOp::BitCast, this_targets_ptr_i64, Type::Int8Ptr, "this_targets_ptr");
950  const auto key_byte_count = key_qw_count * sizeof(int64_t);
951  const auto key_byte_count_lv =
952  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_byte_count, Type::Int32);
953  const auto that_targets_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
954  that_row_ptr, key_byte_count_lv, "that_targets_ptr");
955  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
956  reduction_code.ir_reduce_one_entry.get(),
957  std::vector<const Value*>{this_targets_ptr,
958  that_targets_ptr,
959  this_qmd_handle,
960  that_qmd_handle,
961  serialized_varlen_buffer_arg},
962  "");
963  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
964 }
size_t get_slot_off_quad(const QueryMemoryDescriptor &query_mem_desc)
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
size_t getGroupbyColCount() const
std::unique_ptr< Function > ir_reduce_one_entry_idx
QueryDescriptionType getQueryDescriptionType() const
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneEntryNoCollisions ( const ReductionCode reduction_code) const
protected

Definition at line 674 of file ResultSetReductionJIT.cpp.

References align_to_int64(), get_key_bytes_rowwise(), Int32, ReductionCode::ir_is_empty, ReductionCode::ir_reduce_one_entry, query_mem_desc_, and reduceOneEntryTargetsNoCollisions().

Referenced by codegen(), and GpuReductionHelperJIT::codegen().

675  {
676  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
677  const auto this_row_ptr = ir_reduce_one_entry->arg(0);
678  const auto that_row_ptr = ir_reduce_one_entry->arg(1);
679  const auto that_is_empty =
680  ir_reduce_one_entry->add<Call>(reduction_code.ir_is_empty.get(),
681  std::vector<const Value*>{that_row_ptr},
682  "that_is_empty");
683  ir_reduce_one_entry->add<ReturnEarly>(
684  that_is_empty, ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32), "");
685 
686  const auto key_bytes = get_key_bytes_rowwise(query_mem_desc_);
687  if (key_bytes) { // copy the key from right hand side
688  ir_reduce_one_entry->add<MemCpy>(
689  this_row_ptr,
690  that_row_ptr,
691  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes, Type::Int32));
692  }
693 
694  const auto key_bytes_with_padding = align_to_int64(key_bytes);
695  const auto key_bytes_lv =
696  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes_with_padding, Type::Int32);
697  const auto this_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
698  this_row_ptr, key_bytes_lv, "this_targets_start");
699  const auto that_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
700  that_row_ptr, key_bytes_lv, "that_targets_start");
701 
703  ir_reduce_one_entry, this_targets_start_ptr, that_targets_start_ptr);
704 }
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
void reduceOneEntryTargetsNoCollisions(Function *ir_reduce_one_entry, Value *this_targets_start_ptr, Value *that_targets_start_ptr) const
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneEntryNoCollisionsIdx ( const ReductionCode reduction_code) const
protected

Definition at line 848 of file ResultSetReductionJIT.cpp.

References CHECK, get_row_bytes(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByPerfectHash, Int64, ReductionCode::ir_reduce_one_entry, ReductionCode::ir_reduce_one_entry_idx, BinaryOperator::Mul, NonGroupedAggregate, query_mem_desc_, and Cast::SExt.

Referenced by codegen(), and GpuReductionHelperJIT::codegen().

849  {
850  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
855  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
856  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
857  const auto entry_idx = ir_reduce_one_entry_idx->arg(2);
858  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
859  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
860  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
861  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
863  const auto entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
864  Cast::CastOp::SExt, entry_idx, Type::Int64, "entry_idx_64");
865  const auto row_off_in_bytes = ir_reduce_one_entry_idx->add<BinaryOperator>(
866  BinaryOperator::BinaryOp::Mul, entry_idx_64, row_bytes, "row_off_in_bytes");
867  const auto this_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
868  this_buff, row_off_in_bytes, "this_row_ptr");
869  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
870  that_buff, row_off_in_bytes, "that_row_ptr");
871  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
872  reduction_code.ir_reduce_one_entry.get(),
873  std::vector<const Value*>{this_row_ptr,
874  that_row_ptr,
875  this_qmd_handle,
876  that_qmd_handle,
877  serialized_varlen_buffer_arg},
878  "");
879  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
880 }
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_reduce_one_entry_idx
QueryDescriptionType getQueryDescriptionType() const
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneEntryTargetsNoCollisions ( Function ir_reduce_one_entry,
Value this_targets_start_ptr,
Value that_targets_start_ptr 
) const
private

Definition at line 706 of file ResultSetReductionJIT.cpp.

References QueryMemoryDescriptor::getColSlotContext(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, kAVG, kSAMPLE, query_mem_desc_, reduceOneSlot(), QueryMemoryDescriptor::targetGroupbyIndicesSize(), targets_, to_string(), and UNLIKELY.

Referenced by reduceOneEntryNoCollisions().

709  {
710  const auto& col_slot_context = query_mem_desc_.getColSlotContext();
711  Value* this_targets_ptr = this_targets_start_ptr;
712  Value* that_targets_ptr = that_targets_start_ptr;
713  size_t init_agg_val_idx = 0;
714  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
715  ++target_logical_idx) {
716  const auto& target_info = targets_[target_logical_idx];
717  const auto& slots_for_col = col_slot_context.getSlotsForCol(target_logical_idx);
718  Value* this_ptr2{nullptr};
719  Value* that_ptr2{nullptr};
720 
721  bool two_slot_target{false};
722  if (target_info.is_agg &&
723  (target_info.agg_kind == kAVG ||
724  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
725  // Note that this assumes if one of the slot pairs in a given target is an array,
726  // all slot pairs are arrays. Currently this is true for all geo targets, but we
727  // should better codify and store this information in the future
728  two_slot_target = true;
729  }
730 
731  for (size_t target_slot_idx = slots_for_col.front();
732  target_slot_idx < slots_for_col.back() + 1;
733  target_slot_idx += 2) {
734  const auto slot_off_val = query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx);
735  const auto slot_off =
736  ir_reduce_one_entry->addConstant<ConstantInt>(slot_off_val, Type::Int32);
737  if (UNLIKELY(two_slot_target)) {
738  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
739  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
740  this_targets_ptr, slot_off, "this_" + desc);
741  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
742  that_targets_ptr, slot_off, "that_" + desc);
743  }
744  reduceOneSlot(this_targets_ptr,
745  this_ptr2,
746  that_targets_ptr,
747  that_ptr2,
748  target_info,
749  target_logical_idx,
750  target_slot_idx,
751  init_agg_val_idx,
752  slots_for_col.front(),
753  ir_reduce_one_entry);
754  auto increment_agg_val_idx_maybe =
755  [&init_agg_val_idx, &target_logical_idx, this](const int slot_count) {
757  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
758  init_agg_val_idx += slot_count;
759  }
760  };
761  if (target_logical_idx + 1 == targets_.size() &&
762  target_slot_idx + 1 >= slots_for_col.back()) {
763  break;
764  }
765  const auto next_desc =
766  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
767  if (UNLIKELY(two_slot_target)) {
768  increment_agg_val_idx_maybe(2);
769  const auto two_slot_off = ir_reduce_one_entry->addConstant<ConstantInt>(
770  slot_off_val + query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx + 1),
771  Type::Int32);
772  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
773  this_targets_ptr, two_slot_off, "this_" + next_desc);
774  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
775  that_targets_ptr, two_slot_off, "that_" + next_desc);
776  } else {
777  increment_agg_val_idx_maybe(1);
778  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
779  this_targets_ptr, slot_off, "this_" + next_desc);
780  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
781  that_targets_ptr, slot_off, "that_" + next_desc);
782  }
783  }
784  }
785  ir_reduce_one_entry->add<Ret>(
786  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
787 }
void reduceOneSlot(Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const size_t first_slot_idx_for_target, Function *ir_reduce_one_entry) const
int64_t getTargetGroupbyIndex(const size_t target_idx) const
const QueryMemoryDescriptor query_mem_desc_
std::string to_string(char const *&&v)
size_t targetGroupbyIndicesSize() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define UNLIKELY(x)
Definition: likely.h:25
const ColSlotContext & getColSlotContext() const
Definition: sqldefs.h:73
const std::vector< TargetInfo > targets_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetReductionJIT::reduceOneSlot ( Value this_ptr1,
Value this_ptr2,
Value that_ptr1,
Value that_ptr2,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  target_slot_idx,
const size_t  init_agg_val_idx,
const size_t  first_slot_idx_for_target,
Function ir_reduce_one_entry 
) const
private

Definition at line 1044 of file ResultSetReductionJIT.cpp.

References TargetInfo::agg_kind, CHECK, CHECK_LT, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_checked_write_projection(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_write_projection(), SQLTypeInfo::get_elem_type(), result_set::get_width_for_slot(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, Int64, TargetInfo::is_agg, SQLTypeInfo::is_geometry(), SQLTypeInfo::is_string(), SQLTypeInfo::is_varlen(), kSAMPLE, kSINGLE_VALUE, ICmp::NE, query_mem_desc_, reduceOneAggregateSlot(), TargetInfo::sql_type, takes_float_argument(), target_init_vals_, QueryMemoryDescriptor::targetGroupbyIndicesSize(), and Void.

Referenced by reduceOneEntryBaseline(), and reduceOneEntryTargetsNoCollisions().

1053  {
1055  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
1056  return;
1057  }
1058  }
1059  const bool float_argument_input = takes_float_argument(target_info);
1060  const auto chosen_bytes = result_set::get_width_for_slot(
1061  target_slot_idx, float_argument_input, query_mem_desc_);
1062  CHECK_LT(init_agg_val_idx, target_init_vals_.size());
1063  auto init_val = target_init_vals_[init_agg_val_idx];
1064  if (target_info.is_agg &&
1065  (target_info.agg_kind != kSINGLE_VALUE && target_info.agg_kind != kSAMPLE)) {
1066  reduceOneAggregateSlot(this_ptr1,
1067  this_ptr2,
1068  that_ptr1,
1069  that_ptr2,
1070  target_info,
1071  target_logical_idx,
1072  target_slot_idx,
1073  init_val,
1074  chosen_bytes,
1075  ir_reduce_one_entry);
1076  } else if (target_info.agg_kind == kSINGLE_VALUE) {
1077  const auto checked_rc = emit_checked_write_projection(
1078  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1079 
1080  auto checked_rc_bool = ir_reduce_one_entry->add<ICmp>(
1082  checked_rc,
1083  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32),
1084  "");
1085 
1086  ir_reduce_one_entry->add<ReturnEarly>(checked_rc_bool, checked_rc, "");
1087 
1088  } else {
1090  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1091  if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) {
1092  CHECK(this_ptr2 && that_ptr2);
1093  size_t length_to_elems{0};
1094  if (target_info.sql_type.is_geometry()) {
1095  // TODO: Assumes hard-coded sizes for geometry targets
1096  length_to_elems = target_slot_idx == first_slot_idx_for_target ? 1 : 4;
1097  } else {
1098  const auto& elem_ti = target_info.sql_type.get_elem_type();
1099  length_to_elems = target_info.sql_type.is_string() ? 1 : elem_ti.get_size();
1100  }
1101  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry->arg(4);
1102  ir_reduce_one_entry->add<ExternalCall>(
1103  "serialized_varlen_buffer_sample",
1104  Type::Void,
1105  std::vector<const Value*>{
1106  serialized_varlen_buffer_arg,
1107  this_ptr1,
1108  this_ptr2,
1109  that_ptr1,
1110  that_ptr2,
1111  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64),
1112  ir_reduce_one_entry->addConstant<ConstantInt>(length_to_elems,
1113  Type::Int64)},
1114  "");
1115  }
1116  }
1117 }
int64_t getTargetGroupbyIndex(const size_t target_idx) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
bool is_varlen() const
Definition: sqltypes.h:615
const std::vector< int64_t > target_init_vals_
void reduceOneAggregateSlot(Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const int64_t init_val, const int8_t chosen_bytes, Function *ir_reduce_one_entry) const
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:111
const Value * emit_checked_write_projection(Value *slot_pi8, Value *other_pi8, const int64_t init_val, const size_t chosen_bytes, Function *ir_reduce_one_entry)
const QueryMemoryDescriptor query_mem_desc_
int8_t get_width_for_slot(const size_t target_slot_idx, const bool float_argument_input, const QueryMemoryDescriptor &query_mem_desc)
bool is_agg
Definition: TargetInfo.h:50
size_t targetGroupbyIndicesSize() const
void emit_write_projection(Value *slot_pi8, Value *other_pi8, const int64_t init_val, const size_t chosen_bytes, Function *ir_reduce_one_entry)
SQLAgg agg_kind
Definition: TargetInfo.h:51
#define CHECK_LT(x, y)
Definition: Logger.h:232
#define CHECK(condition)
Definition: Logger.h:222
bool is_geometry() const
Definition: sqltypes.h:587
bool is_string() const
Definition: sqltypes.h:575
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:956

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

size_t ResultSetReductionJIT::executor_id_
protected

Definition at line 78 of file ResultSetReductionJIT.h.

Referenced by codegen(), and GpuReductionHelperJIT::codegen().

const std::vector<int64_t> ResultSetReductionJIT::target_init_vals_
private

Definition at line 137 of file ResultSetReductionJIT.h.

Referenced by cacheKey(), isEmpty(), and reduceOneSlot().

const std::vector<TargetInfo> ResultSetReductionJIT::targets_
private

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