OmniSciDB  72c90bc290
 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 reduceOneModeSlot (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 524 of file ResultSetReductionJIT.cpp.

528  : executor_id_(executor_id)
529  , query_mem_desc_(query_mem_desc)
530  , targets_(targets)
531  , 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 1305 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().

1305  {
1306  std::vector<std::string> target_init_vals_strings;
1308  target_init_vals_.end(),
1309  std::back_inserter(target_init_vals_strings),
1310  [](const int64_t v) { return std::to_string(v); });
1311  const auto target_init_vals_key =
1312  boost::algorithm::join(target_init_vals_strings, ", ");
1313  std::vector<std::string> targets_strings;
1315  targets_.begin(),
1316  targets_.end(),
1317  std::back_inserter(targets_strings),
1318  [](const TargetInfo& target_info) { return target_info_key(target_info); });
1319  const auto targets_key = boost::algorithm::join(targets_strings, ", ");
1320  return query_mem_desc_.reductionKey() + "\n" + target_init_vals_key + "\n" +
1321  targets_key;
1322 }
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:320
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 564 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_, 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().

564  {
565  const auto hash_type = query_mem_desc_.getQueryDescriptionType();
567  return {};
568  }
569  auto reduction_code = setup_functions_ir(hash_type);
570  isEmpty(reduction_code);
574  reduceOneEntryNoCollisions(reduction_code);
575  reduceOneEntryNoCollisionsIdx(reduction_code);
576  break;
577  }
579  reduceOneEntryBaseline(reduction_code);
580  reduceOneEntryBaselineIdx(reduction_code);
581  break;
582  }
583  default: {
584  LOG(FATAL) << "Unexpected query description type";
585  }
586  }
587  reduceLoop(reduction_code);
588  // For small result sets, avoid native code generation and use the interpreter instead.
591  return reduction_code;
592  }
593  auto executor = Executor::getExecutor(executor_id_);
594  CodeCacheKey key{cacheKey()};
595  std::lock_guard<std::mutex> compilation_lock(executor->compilation_mutex_);
596  const auto compilation_context =
597  QueryEngine::getInstance()->s_code_accessor->get_or_wait(key);
598  if (compilation_context) {
599  reduction_code.func_ptr =
600  reinterpret_cast<ReductionCode::FuncPtr>(compilation_context->get()->func());
601  return reduction_code;
602  }
603  auto cgen_state_ = std::unique_ptr<CgenState>(new CgenState({}, false, executor.get()));
604  auto cgen_state = reduction_code.cgen_state = cgen_state_.get();
605  cgen_state->set_module_shallow_copy(executor->get_rt_module());
606  reduction_code.module = cgen_state->module_;
607 
608  AUTOMATIC_IR_METADATA(cgen_state);
609  auto ir_is_empty = create_llvm_function(reduction_code.ir_is_empty.get(), cgen_state);
610  auto ir_reduce_one_entry =
611  create_llvm_function(reduction_code.ir_reduce_one_entry.get(), cgen_state);
612  auto ir_reduce_one_entry_idx =
613  create_llvm_function(reduction_code.ir_reduce_one_entry_idx.get(), cgen_state);
614  auto ir_reduce_loop =
615  create_llvm_function(reduction_code.ir_reduce_loop.get(), cgen_state);
616  std::unordered_map<const Function*, llvm::Function*> f;
617  f.emplace(reduction_code.ir_is_empty.get(), ir_is_empty);
618  f.emplace(reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry);
619  f.emplace(reduction_code.ir_reduce_one_entry_idx.get(), ir_reduce_one_entry_idx);
620  f.emplace(reduction_code.ir_reduce_loop.get(), ir_reduce_loop);
621  translate_function(reduction_code.ir_is_empty.get(), ir_is_empty, reduction_code, f);
623  reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry, reduction_code, f);
624  translate_function(reduction_code.ir_reduce_one_entry_idx.get(),
625  ir_reduce_one_entry_idx,
626  reduction_code,
627  f);
629  reduction_code.ir_reduce_loop.get(), ir_reduce_loop, reduction_code, f);
630  reduction_code.llvm_reduce_loop = ir_reduce_loop;
632  reduction_code.cgen_state = nullptr;
634  reduction_code, ir_is_empty, ir_reduce_one_entry, ir_reduce_one_entry_idx, key);
635  return reduction_code;
636 }
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:285
void reduceLoop(const ReductionCode &reduction_code) const
void reduceOneEntryNoCollisionsIdx(const ReductionCode &reduction_code) const
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:24
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_
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:509
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
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
void isEmpty(const ReductionCode &reduction_code) const
void reduceOneEntryBaseline(const ReductionCode &reduction_code) const
static std::shared_ptr< QueryEngine > getInstance()
Definition: QueryEngine.h:89
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 1254 of file ResultSetReductionJIT.cpp.

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

Referenced by codegen().

1259  {
1260  CompilationOptions co{
1262  VLOG(3) << "Reduction Loop:\n"
1263  << serialize_llvm_object(reduction_code.llvm_reduce_loop);
1264  VLOG(3) << "Reduction Is Empty Func:\n" << serialize_llvm_object(ir_is_empty);
1265  VLOG(3) << "Reduction One Entry Func:\n" << serialize_llvm_object(ir_reduce_one_entry);
1266  VLOG(3) << "Reduction One Entry Idx Func:\n"
1267  << serialize_llvm_object(ir_reduce_one_entry_idx);
1268 #ifdef NDEBUG
1269  LOG(IR) << "Reduction Loop:\n"
1270  << serialize_llvm_object(reduction_code.llvm_reduce_loop);
1271  LOG(IR) << "Reduction Is Empty Func:\n" << serialize_llvm_object(ir_is_empty);
1272  LOG(IR) << "Reduction One Entry Func:\n" << serialize_llvm_object(ir_reduce_one_entry);
1273  LOG(IR) << "Reduction One Entry Idx Func:\n"
1274  << serialize_llvm_object(ir_reduce_one_entry_idx);
1275 #else
1276  LOG(IR) << serialize_llvm_object(reduction_code.module);
1277 #endif
1279  reduction_code.llvm_reduce_loop, {reduction_code.llvm_reduce_loop}, co);
1280  auto cpu_compilation_context = std::make_shared<CpuCompilationContext>(std::move(ee));
1281  cpu_compilation_context->setFunctionPointer(reduction_code.llvm_reduce_loop);
1282  reduction_code.func_ptr =
1283  reinterpret_cast<ReductionCode::FuncPtr>(cpu_compilation_context->func());
1284  CHECK(reduction_code.llvm_reduce_loop->getParent() == reduction_code.module);
1285  auto executor = Executor::getExecutor(executor_id_);
1286  QueryEngine::getInstance()->s_code_accessor->reset(key,
1287  std::move(cpu_compilation_context));
1288 }
#define LOG(tag)
Definition: Logger.h:285
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:509
llvm::Module * module
std::string serialize_llvm_object(const T *llvm_obj)
#define CHECK(condition)
Definition: Logger.h:291
static std::shared_ptr< QueryEngine > getInstance()
Definition: QueryEngine.h:89
#define VLOG(n)
Definition: Logger.h:388

+ 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 638 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().

638  {
639  auto ir_is_empty = reduction_code.ir_is_empty.get();
642  Value* key{nullptr};
643  Value* empty_key_val{nullptr};
644  const auto keys_ptr = ir_is_empty->arg(0);
649  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
650  target_init_vals_.size());
651  const int64_t target_slot_off = result_set::get_byteoff_of_slot(
653  const auto slot_ptr = ir_is_empty->add<GetElementPtr>(
654  keys_ptr,
655  ir_is_empty->addConstant<ConstantInt>(target_slot_off, Type::Int32),
656  "is_empty_slot_ptr");
657  const auto compact_sz =
659  key = emit_read_int_from_buff(slot_ptr, compact_sz, ir_is_empty);
660  empty_key_val = ir_is_empty->addConstant<ConstantInt>(
662  } else {
664  case 4: {
667  key = emit_load_i32(keys_ptr, ir_is_empty);
668  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_32, Type::Int32);
669  break;
670  }
671  case 8: {
672  key = emit_load_i64(keys_ptr, ir_is_empty);
673  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_64, Type::Int64);
674  break;
675  }
676  default:
677  LOG(FATAL) << "Invalid key width";
678  }
679  }
680  const auto ret =
681  ir_is_empty->add<ICmp>(ICmp::Predicate::EQ, key, empty_key_val, "is_key_empty");
682  ir_is_empty->add<Ret>(ret);
683 }
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:285
#define CHECK_GE(x, y)
Definition: Logger.h:306
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:303
Value * emit_load_i64(Value *ptr, Function *function)
#define CHECK(condition)
Definition: Logger.h:291
#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 1030 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().

1030  {
1031  auto ir_reduce_loop = reduction_code.ir_reduce_loop.get();
1032  const auto this_buff_arg = ir_reduce_loop->arg(0);
1033  const auto that_buff_arg = ir_reduce_loop->arg(1);
1034  const auto start_index_arg = ir_reduce_loop->arg(2);
1035  const auto end_index_arg = ir_reduce_loop->arg(3);
1036  const auto that_entry_count_arg = ir_reduce_loop->arg(4);
1037  const auto this_qmd_handle_arg = ir_reduce_loop->arg(5);
1038  const auto that_qmd_handle_arg = ir_reduce_loop->arg(6);
1039  const auto serialized_varlen_buffer_arg = ir_reduce_loop->arg(7);
1040  For* for_loop =
1041  static_cast<For*>(ir_reduce_loop->add<For>(start_index_arg, end_index_arg, ""));
1042  generate_loop_body(for_loop,
1043  ir_reduce_loop,
1044  reduction_code.ir_reduce_one_entry_idx.get(),
1045  this_buff_arg,
1046  that_buff_arg,
1047  start_index_arg,
1048  that_entry_count_arg,
1049  this_qmd_handle_arg,
1050  that_qmd_handle_arg,
1051  serialized_varlen_buffer_arg);
1052  ir_reduce_loop->add<Ret>(ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int32));
1053 }
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 1130 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(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), is_distinct_target(), kAPPROX_COUNT_DISTINCT, kAPPROX_QUANTILE, kAVG, kCOUNT, kCOUNT_IF, kMAX, kMIN, kMODE, kSUM, kSUM_IF, query_mem_desc_, reduceOneApproxQuantileSlot(), reduceOneCountDistinctSlot(), reduceOneModeSlot(), and UNREACHABLE.

Referenced by reduceOneSlot().

1139  {
1140  auto agg_kind = target_info.agg_kind;
1141  switch (agg_kind) {
1142  case kCOUNT:
1143  case kCOUNT_IF:
1145  if (is_distinct_target(target_info)) {
1146  CHECK_EQ(static_cast<size_t>(chosen_bytes), sizeof(int64_t));
1148  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1149  break;
1150  }
1151  CHECK_EQ(int64_t(0), init_val);
1152  emit_aggregate_one_count(this_ptr1, that_ptr1, chosen_bytes, ir_reduce_one_entry);
1153  break;
1154  case kAPPROX_QUANTILE:
1155  CHECK_EQ(sizeof(int64_t), static_cast<size_t>(chosen_bytes));
1157  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1158  break;
1159  case kMODE:
1160  reduceOneModeSlot(this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1161  break;
1162  case kAVG:
1163  // Ignore float argument compaction for count component for fear of its overflow
1164  emit_aggregate_one_count(this_ptr2,
1165  that_ptr2,
1166  query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx),
1167  ir_reduce_one_entry);
1168  agg_kind = kSUM;
1169  // fall thru
1170  case kSUM:
1171  case kMIN:
1172  case kMAX:
1173  // for conditional aggregation, we already "conditionally" aggregate value for each
1174  // resultset, so reduction just can use the non-conditional aggregation logic
1175  case kSUM_IF:
1177  this_ptr1,
1178  that_ptr1,
1179  init_val,
1180  chosen_bytes,
1181  target_info,
1182  ir_reduce_one_entry);
1183  break;
1184  default:
1185  UNREACHABLE() << "Invalid aggregate type: " << agg_kind;
1186  }
1187 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define UNREACHABLE()
Definition: Logger.h:338
const QueryMemoryDescriptor query_mem_desc_
Definition: sqldefs.h:75
void reduceOneCountDistinctSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
void emit_aggregate_one_nullable_value(SQLAgg const sql_agg, 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)
Definition: sqldefs.h:77
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:102
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:51
Definition: sqldefs.h:78
void emit_aggregate_one_count(Value *val_ptr, Value *other_ptr, const size_t chosen_bytes, Function *ir_reduce_one_entry)
Definition: sqldefs.h:76
Definition: sqldefs.h:74
void reduceOneApproxQuantileSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
Definition: sqldefs.h:83
void reduceOneModeSlot(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 1211 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().

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

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

801  {
802  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
803  const auto this_targets_ptr_arg = ir_reduce_one_entry->arg(0);
804  const auto that_targets_ptr_arg = ir_reduce_one_entry->arg(1);
805  Value* this_ptr1 = this_targets_ptr_arg;
806  Value* that_ptr1 = that_targets_ptr_arg;
807  size_t j = 0;
808  size_t init_agg_val_idx = 0;
809  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
810  ++target_logical_idx) {
811  const auto& target_info = targets_[target_logical_idx];
812  Value* this_ptr2{nullptr};
813  Value* that_ptr2{nullptr};
814  if (target_info.is_agg &&
815  (target_info.agg_kind == kAVG ||
816  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
817  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
818  const auto second_slot_rel_off =
819  ir_reduce_one_entry->addConstant<ConstantInt>(sizeof(int64_t), Type::Int32);
820  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
821  this_ptr1, second_slot_rel_off, "this_" + desc);
822  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
823  that_ptr1, second_slot_rel_off, "that_" + desc);
824  }
825  reduceOneSlot(this_ptr1,
826  this_ptr2,
827  that_ptr1,
828  that_ptr2,
829  target_info,
830  target_logical_idx,
831  j,
832  init_agg_val_idx,
833  j,
834  ir_reduce_one_entry);
835  if (target_logical_idx + 1 == targets_.size()) {
836  break;
837  }
839  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
840  } else {
841  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
842  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
843  }
844  }
845  j = advance_slot(j, target_info, false);
846  const auto next_desc =
847  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
848  auto next_slot_rel_off = ir_reduce_one_entry->addConstant<ConstantInt>(
849  init_agg_val_idx * sizeof(int64_t), Type::Int32);
850  this_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
851  this_targets_ptr_arg, next_slot_rel_off, next_desc);
852  that_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
853  that_targets_ptr_arg, next_slot_rel_off, next_desc);
854  }
855  ir_reduce_one_entry->add<Ret>(
856  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
857 }
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:74
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 893 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().

894  {
895  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
900  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
901  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
902  const auto that_entry_idx = ir_reduce_one_entry_idx->arg(2);
903  const auto that_entry_count = ir_reduce_one_entry_idx->arg(3);
904  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
905  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
906  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
907  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
909  const auto that_entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
910  Cast::CastOp::SExt, that_entry_idx, Type::Int64, "that_entry_idx_64");
911  const auto that_row_off_in_bytes =
912  ir_reduce_one_entry_idx->add<BinaryOperator>(BinaryOperator::BinaryOp::Mul,
913  that_entry_idx_64,
914  row_bytes,
915  "that_row_off_in_bytes");
916  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
917  that_buff, that_row_off_in_bytes, "that_row_ptr");
918  const auto that_is_empty =
919  ir_reduce_one_entry_idx->add<Call>(reduction_code.ir_is_empty.get(),
920  std::vector<const Value*>{that_row_ptr},
921  "that_is_empty");
922  ir_reduce_one_entry_idx->add<ReturnEarly>(
923  that_is_empty,
924  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
925  "");
926  const auto key_count = query_mem_desc_.getGroupbyColCount();
927  const auto one_element =
928  ir_reduce_one_entry_idx->addConstant<ConstantInt>(1, Type::Int32);
929  const auto this_targets_ptr_i64_ptr = ir_reduce_one_entry_idx->add<Alloca>(
930  Type::Int64Ptr, one_element, "this_targets_ptr_out");
931  const auto this_is_empty_ptr =
932  ir_reduce_one_entry_idx->add<Alloca>(Type::Int8, one_element, "this_is_empty_out");
933  ir_reduce_one_entry_idx->add<ExternalCall>(
934  "get_group_value_reduction_rt",
935  Type::Void,
936  std::vector<const Value*>{
937  this_buff,
938  that_row_ptr,
939  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_count, Type::Int32),
940  this_qmd_handle,
941  that_buff,
942  that_entry_idx,
943  that_entry_count,
944  row_bytes,
945  this_targets_ptr_i64_ptr,
946  this_is_empty_ptr},
947  "");
948  const auto this_targets_ptr_i64 = ir_reduce_one_entry_idx->add<Load>(
949  this_targets_ptr_i64_ptr, "this_targets_ptr_i64");
950  auto this_is_empty =
951  ir_reduce_one_entry_idx->add<Load>(this_is_empty_ptr, "this_is_empty");
952  this_is_empty = ir_reduce_one_entry_idx->add<Cast>(
953  Cast::CastOp::Trunc, this_is_empty, Type::Int1, "this_is_empty_bool");
954  ir_reduce_one_entry_idx->add<ReturnEarly>(
955  this_is_empty,
956  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
957  "");
958  const auto key_qw_count = get_slot_off_quad(query_mem_desc_);
959  const auto this_targets_ptr = ir_reduce_one_entry_idx->add<Cast>(
960  Cast::CastOp::BitCast, this_targets_ptr_i64, Type::Int8Ptr, "this_targets_ptr");
961  const auto key_byte_count = key_qw_count * sizeof(int64_t);
962  const auto key_byte_count_lv =
963  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_byte_count, Type::Int32);
964  const auto that_targets_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
965  that_row_ptr, key_byte_count_lv, "that_targets_ptr");
966  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
967  reduction_code.ir_reduce_one_entry.get(),
968  std::vector<const Value*>{this_targets_ptr,
969  that_targets_ptr,
970  this_qmd_handle,
971  that_qmd_handle,
972  serialized_varlen_buffer_arg},
973  "");
974  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
975 }
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:291

+ 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 685 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().

686  {
687  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
688  const auto this_row_ptr = ir_reduce_one_entry->arg(0);
689  const auto that_row_ptr = ir_reduce_one_entry->arg(1);
690  const auto that_is_empty =
691  ir_reduce_one_entry->add<Call>(reduction_code.ir_is_empty.get(),
692  std::vector<const Value*>{that_row_ptr},
693  "that_is_empty");
694  ir_reduce_one_entry->add<ReturnEarly>(
695  that_is_empty, ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32), "");
696 
697  const auto key_bytes = get_key_bytes_rowwise(query_mem_desc_);
698  if (key_bytes) { // copy the key from right hand side
699  ir_reduce_one_entry->add<MemCpy>(
700  this_row_ptr,
701  that_row_ptr,
702  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes, Type::Int32));
703  }
704 
705  const auto key_bytes_with_padding = align_to_int64(key_bytes);
706  const auto key_bytes_lv =
707  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes_with_padding, Type::Int32);
708  const auto this_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
709  this_row_ptr, key_bytes_lv, "this_targets_start");
710  const auto that_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
711  that_row_ptr, key_bytes_lv, "that_targets_start");
712 
714  ir_reduce_one_entry, this_targets_start_ptr, that_targets_start_ptr);
715 }
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 859 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().

860  {
861  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
866  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
867  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
868  const auto entry_idx = ir_reduce_one_entry_idx->arg(2);
869  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
870  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
871  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
872  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
874  const auto entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
875  Cast::CastOp::SExt, entry_idx, Type::Int64, "entry_idx_64");
876  const auto row_off_in_bytes = ir_reduce_one_entry_idx->add<BinaryOperator>(
877  BinaryOperator::BinaryOp::Mul, entry_idx_64, row_bytes, "row_off_in_bytes");
878  const auto this_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
879  this_buff, row_off_in_bytes, "this_row_ptr");
880  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
881  that_buff, row_off_in_bytes, "that_row_ptr");
882  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
883  reduction_code.ir_reduce_one_entry.get(),
884  std::vector<const Value*>{this_row_ptr,
885  that_row_ptr,
886  this_qmd_handle,
887  that_qmd_handle,
888  serialized_varlen_buffer_arg},
889  "");
890  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
891 }
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:291

+ 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 717 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().

720  {
721  const auto& col_slot_context = query_mem_desc_.getColSlotContext();
722  Value* this_targets_ptr = this_targets_start_ptr;
723  Value* that_targets_ptr = that_targets_start_ptr;
724  size_t init_agg_val_idx = 0;
725  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
726  ++target_logical_idx) {
727  const auto& target_info = targets_[target_logical_idx];
728  const auto& slots_for_col = col_slot_context.getSlotsForCol(target_logical_idx);
729  Value* this_ptr2{nullptr};
730  Value* that_ptr2{nullptr};
731 
732  bool two_slot_target{false};
733  if (target_info.is_agg &&
734  (target_info.agg_kind == kAVG ||
735  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
736  // Note that this assumes if one of the slot pairs in a given target is an array,
737  // all slot pairs are arrays. Currently this is true for all geo targets, but we
738  // should better codify and store this information in the future
739  two_slot_target = true;
740  }
741 
742  for (size_t target_slot_idx = slots_for_col.front();
743  target_slot_idx < slots_for_col.back() + 1;
744  target_slot_idx += 2) {
745  const auto slot_off_val = query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx);
746  const auto slot_off =
747  ir_reduce_one_entry->addConstant<ConstantInt>(slot_off_val, Type::Int32);
748  if (UNLIKELY(two_slot_target)) {
749  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
750  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
751  this_targets_ptr, slot_off, "this_" + desc);
752  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
753  that_targets_ptr, slot_off, "that_" + desc);
754  }
755  reduceOneSlot(this_targets_ptr,
756  this_ptr2,
757  that_targets_ptr,
758  that_ptr2,
759  target_info,
760  target_logical_idx,
761  target_slot_idx,
762  init_agg_val_idx,
763  slots_for_col.front(),
764  ir_reduce_one_entry);
765  auto increment_agg_val_idx_maybe =
766  [&init_agg_val_idx, &target_logical_idx, this](const int slot_count) {
768  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
769  init_agg_val_idx += slot_count;
770  }
771  };
772  if (target_logical_idx + 1 == targets_.size() &&
773  target_slot_idx + 1 >= slots_for_col.back()) {
774  break;
775  }
776  const auto next_desc =
777  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
778  if (UNLIKELY(two_slot_target)) {
779  increment_agg_val_idx_maybe(2);
780  const auto two_slot_off = ir_reduce_one_entry->addConstant<ConstantInt>(
781  slot_off_val + query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx + 1),
782  Type::Int32);
783  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
784  this_targets_ptr, two_slot_off, "this_" + next_desc);
785  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
786  that_targets_ptr, two_slot_off, "that_" + next_desc);
787  } else {
788  increment_agg_val_idx_maybe(1);
789  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
790  this_targets_ptr, slot_off, "this_" + next_desc);
791  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
792  that_targets_ptr, slot_off, "that_" + next_desc);
793  }
794  }
795  }
796  ir_reduce_one_entry->add<Ret>(
797  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
798 }
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:74
const std::vector< TargetInfo > targets_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1233 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().

1236  {
1238  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1239  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1240  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1241  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1242  ir_reduce_one_entry->add<ExternalCall>(
1243  "mode_jit_rt",
1244  Type::Void,
1245  std::vector<const Value*>{
1246  new_set_handle,
1247  old_set_handle,
1248  that_qmd_arg,
1249  this_qmd_arg,
1250  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1251  "");
1252 }
const QueryMemoryDescriptor query_mem_desc_
size_t getCountDistinctDescriptorsSize() const
#define CHECK_LT(x, y)
Definition: Logger.h:303
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::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 1055 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().

1064  {
1066  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
1067  return;
1068  }
1069  }
1070  const bool float_argument_input = takes_float_argument(target_info);
1071  const auto chosen_bytes = result_set::get_width_for_slot(
1072  target_slot_idx, float_argument_input, query_mem_desc_);
1073  CHECK_LT(init_agg_val_idx, target_init_vals_.size());
1074  auto init_val = target_init_vals_[init_agg_val_idx];
1075  if (target_info.is_agg &&
1076  (target_info.agg_kind != kSINGLE_VALUE && target_info.agg_kind != kSAMPLE)) {
1077  reduceOneAggregateSlot(this_ptr1,
1078  this_ptr2,
1079  that_ptr1,
1080  that_ptr2,
1081  target_info,
1082  target_logical_idx,
1083  target_slot_idx,
1084  init_val,
1085  chosen_bytes,
1086  ir_reduce_one_entry);
1087  } else if (target_info.agg_kind == kSINGLE_VALUE) {
1088  const auto checked_rc = emit_checked_write_projection(
1089  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1090 
1091  auto checked_rc_bool = ir_reduce_one_entry->add<ICmp>(
1093  checked_rc,
1094  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32),
1095  "");
1096 
1097  ir_reduce_one_entry->add<ReturnEarly>(checked_rc_bool, checked_rc, "");
1098 
1099  } else {
1101  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1102  if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) {
1103  CHECK(this_ptr2 && that_ptr2);
1104  size_t length_to_elems{0};
1105  if (target_info.sql_type.is_geometry()) {
1106  // TODO: Assumes hard-coded sizes for geometry targets
1107  length_to_elems = target_slot_idx == first_slot_idx_for_target ? 1 : 4;
1108  } else {
1109  const auto& elem_ti = target_info.sql_type.get_elem_type();
1110  length_to_elems = target_info.sql_type.is_string() ? 1 : elem_ti.get_size();
1111  }
1112  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry->arg(4);
1113  ir_reduce_one_entry->add<ExternalCall>(
1114  "serialized_varlen_buffer_sample",
1115  Type::Void,
1116  std::vector<const Value*>{
1117  serialized_varlen_buffer_arg,
1118  this_ptr1,
1119  this_ptr2,
1120  that_ptr1,
1121  that_ptr2,
1122  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64),
1123  ir_reduce_one_entry->addConstant<ConstantInt>(length_to_elems,
1124  Type::Int64)},
1125  "");
1126  }
1127  }
1128 }
int64_t getTargetGroupbyIndex(const size_t target_idx) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
bool is_varlen() const
Definition: sqltypes.h:629
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:106
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:303
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:595
bool is_string() const
Definition: sqltypes.h:559
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:975

+ 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 142 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: