OmniSciDB  29e35f4d58
anonymous_namespace{ResultSetReduction.cpp} Namespace Reference

Functions

bool use_multithreaded_reduction (const size_t entry_count)
 
size_t get_row_qw_count (const QueryMemoryDescriptor &query_mem_desc)
 
std::vector< int64_t > make_key (const int64_t *buff, const size_t entry_count, const size_t key_count)
 
void fill_slots (int64_t *dst_entry, const size_t dst_entry_count, const int64_t *src_buff, const size_t src_entry_idx, const size_t src_entry_count, const QueryMemoryDescriptor &query_mem_desc)
 
ALWAYS_INLINE void fill_empty_key_32 (int32_t *key_ptr_i32, const size_t key_count)
 
ALWAYS_INLINE void fill_empty_key_64 (int64_t *key_ptr_i64, const size_t key_count)
 
int64_t get_component (const int8_t *group_by_buffer, const size_t comp_sz, const size_t index=0)
 
void run_reduction_code (const ReductionCode &reduction_code, 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)
 
ALWAYS_INLINE void check_watchdog (const size_t sample_seed)
 
GroupValueInfo get_matching_group_value_columnar_reduction (int64_t *groups_buffer, const uint32_t h, const int64_t *key, const uint32_t key_qw_count, const size_t entry_count)
 
GroupValueInfo get_group_value_columnar_reduction (int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_qw_count)
 
template<typename T = int64_t>
GroupValueInfo get_matching_group_value_reduction (int64_t *groups_buffer, const uint32_t h, const T *key, const uint32_t key_count, const QueryMemoryDescriptor &query_mem_desc, const int64_t *that_buff_i64, const size_t that_entry_idx, const size_t that_entry_count, const uint32_t row_size_quad)
 
GroupValueInfo get_matching_group_value_reduction (int64_t *groups_buffer, const uint32_t h, const int64_t *key, const uint32_t key_count, const size_t key_width, const QueryMemoryDescriptor &query_mem_desc, const int64_t *that_buff_i64, const size_t that_entry_idx, const size_t that_entry_count, const uint32_t row_size_quad)
 

Function Documentation

◆ check_watchdog()

ALWAYS_INLINE void anonymous_namespace{ResultSetReduction.cpp}::check_watchdog ( const size_t  sample_seed)

Definition at line 373 of file ResultSetReduction.cpp.

References dynamic_watchdog(), g_enable_dynamic_watchdog, and UNLIKELY.

Referenced by ResultSetStorage::reduceEntriesNoCollisionsColWise(), and ResultSetStorage::reduceOneEntryBaseline().

373  {
374  if (UNLIKELY(g_enable_dynamic_watchdog && (sample_seed & 0x3F) == 0 &&
375  dynamic_watchdog())) {
376  // TODO(alex): distinguish between the deadline and interrupt
377  throw std::runtime_error(
378  "Query execution has exceeded the time limit or was interrupted during result "
379  "set reduction");
380  }
381 }
bool dynamic_watchdog()
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
#define UNLIKELY(x)
Definition: likely.h:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill_empty_key_32()

ALWAYS_INLINE void anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_32 ( int32_t *  key_ptr_i32,
const size_t  key_count 
)

Definition at line 92 of file ResultSetReduction.cpp.

References ALWAYS_INLINE, and EMPTY_KEY_32.

Referenced by fill_empty_key(), and ResultSetStorage::initializeRowWise().

92  {
93  for (size_t i = 0; i < key_count; ++i) {
94  key_ptr_i32[i] = EMPTY_KEY_32;
95  }
96 }
#define EMPTY_KEY_32
+ Here is the caller graph for this function:

◆ fill_empty_key_64()

ALWAYS_INLINE void anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_64 ( int64_t *  key_ptr_i64,
const size_t  key_count 
)

Definition at line 99 of file ResultSetReduction.cpp.

References EMPTY_KEY_64.

Referenced by fill_empty_key(), and ResultSetStorage::initializeRowWise().

99  {
100  for (size_t i = 0; i < key_count; ++i) {
101  key_ptr_i64[i] = EMPTY_KEY_64;
102  }
103 }
#define EMPTY_KEY_64
+ Here is the caller graph for this function:

◆ fill_slots()

void anonymous_namespace{ResultSetReduction.cpp}::fill_slots ( int64_t *  dst_entry,
const size_t  dst_entry_count,
const int64_t *  src_buff,
const size_t  src_entry_idx,
const size_t  src_entry_count,
const QueryMemoryDescriptor query_mem_desc 
)

Definition at line 68 of file ResultSetReduction.cpp.

References ALWAYS_INLINE, QueryMemoryDescriptor::didOutputColumnar(), get_row_qw_count(), get_slot_off_quad(), QueryMemoryDescriptor::getBufferColSlotCount(), QueryMemoryDescriptor::getGroupbyColCount(), and slot_offset_colwise().

Referenced by get_matching_group_value_reduction(), ResultSetStorage::moveOneEntryToBuffer(), and ResultSetStorage::reduceOneEntryBaseline().

73  {
74  const auto slot_count = query_mem_desc.getBufferColSlotCount();
75  const auto key_count = query_mem_desc.getGroupbyColCount();
76  if (query_mem_desc.didOutputColumnar()) {
77  for (size_t i = 0, dst_slot_off = 0; i < slot_count;
78  ++i, dst_slot_off += dst_entry_count) {
79  dst_entry[dst_slot_off] =
80  src_buff[slot_offset_colwise(src_entry_idx, i, key_count, src_entry_count)];
81  }
82  } else {
83  const auto row_ptr = src_buff + get_row_qw_count(query_mem_desc) * src_entry_idx;
84  const auto slot_off_quad = get_slot_off_quad(query_mem_desc);
85  for (size_t i = 0; i < slot_count; ++i) {
86  dst_entry[i] = row_ptr[slot_off_quad + i];
87  }
88  }
89 }
size_t slot_offset_colwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t entry_count)
size_t get_slot_off_quad(const QueryMemoryDescriptor &query_mem_desc)
size_t get_row_qw_count(const QueryMemoryDescriptor &query_mem_desc)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_component()

int64_t anonymous_namespace{ResultSetReduction.cpp}::get_component ( const int8_t *  group_by_buffer,
const size_t  comp_sz,
const size_t  index = 0 
)
inline

Definition at line 105 of file ResultSetReduction.cpp.

References CHECK.

Referenced by ResultSetStorage::reduceSingleRow().

107  {
108  int64_t ret = std::numeric_limits<int64_t>::min();
109  switch (comp_sz) {
110  case 1: {
111  ret = group_by_buffer[index];
112  break;
113  }
114  case 2: {
115  const int16_t* buffer_ptr = reinterpret_cast<const int16_t*>(group_by_buffer);
116  ret = buffer_ptr[index];
117  break;
118  }
119  case 4: {
120  const int32_t* buffer_ptr = reinterpret_cast<const int32_t*>(group_by_buffer);
121  ret = buffer_ptr[index];
122  break;
123  }
124  case 8: {
125  const int64_t* buffer_ptr = reinterpret_cast<const int64_t*>(group_by_buffer);
126  ret = buffer_ptr[index];
127  break;
128  }
129  default:
130  CHECK(false);
131  }
132  return ret;
133 }
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the caller graph for this function:

◆ get_group_value_columnar_reduction()

GroupValueInfo anonymous_namespace{ResultSetReduction.cpp}::get_group_value_columnar_reduction ( int64_t *  groups_buffer,
const uint32_t  groups_buffer_entry_count,
const int64_t *  key,
const uint32_t  key_qw_count 
)

Definition at line 616 of file ResultSetReduction.cpp.

References get_matching_group_value_columnar_reduction(), groups_buffer_entry_count, and key_hash().

Referenced by ResultSetStorage::reduceOneEntryBaseline().

620  {
621  uint32_t h = key_hash(key, key_qw_count, sizeof(int64_t)) % groups_buffer_entry_count;
623  groups_buffer, h, key, key_qw_count, groups_buffer_entry_count);
624  if (matching_gvi.first) {
625  return matching_gvi;
626  }
627  uint32_t h_probe = (h + 1) % groups_buffer_entry_count;
628  while (h_probe != h) {
630  groups_buffer, h_probe, key, key_qw_count, groups_buffer_entry_count);
631  if (matching_gvi.first) {
632  return matching_gvi;
633  }
634  h_probe = (h_probe + 1) % groups_buffer_entry_count;
635  }
636  return {nullptr, true};
637 }
ALWAYS_INLINE DEVICE uint32_t key_hash(const int64_t *key, const uint32_t key_count, const uint32_t key_byte_width)
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
GroupValueInfo get_matching_group_value_columnar_reduction(int64_t *groups_buffer, const uint32_t h, const int64_t *key, const uint32_t key_qw_count, const size_t entry_count)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_matching_group_value_columnar_reduction()

GroupValueInfo anonymous_namespace{ResultSetReduction.cpp}::get_matching_group_value_columnar_reduction ( int64_t *  groups_buffer,
const uint32_t  h,
const int64_t *  key,
const uint32_t  key_qw_count,
const size_t  entry_count 
)

Definition at line 590 of file ResultSetReduction.cpp.

References EMPTY_KEY_64, and key_qw_count.

Referenced by get_group_value_columnar_reduction().

594  {
595  auto off = h;
596  const auto old_key =
597  __sync_val_compare_and_swap(&groups_buffer[off], EMPTY_KEY_64, *key);
598  if (old_key == EMPTY_KEY_64) {
599  for (size_t i = 0; i < key_qw_count; ++i) {
600  groups_buffer[off] = key[i];
601  off += entry_count;
602  }
603  return {&groups_buffer[off], true};
604  }
605  off = h;
606  for (size_t i = 0; i < key_qw_count; ++i) {
607  if (groups_buffer[off] != key[i]) {
608  return {nullptr, true};
609  }
610  off += entry_count;
611  }
612  return {&groups_buffer[off], false};
613 }
#define EMPTY_KEY_64
const int64_t const uint32_t const uint32_t key_qw_count
+ Here is the caller graph for this function:

◆ get_matching_group_value_reduction() [1/2]

template<typename T = int64_t>
GroupValueInfo anonymous_namespace{ResultSetReduction.cpp}::get_matching_group_value_reduction ( int64_t *  groups_buffer,
const uint32_t  h,
const T *  key,
const uint32_t  key_count,
const QueryMemoryDescriptor query_mem_desc,
const int64_t *  that_buff_i64,
const size_t  that_entry_idx,
const size_t  that_entry_count,
const uint32_t  row_size_quad 
)

Definition at line 646 of file ResultSetReduction.cpp.

References cas_cst, fill_slots(), get_slot_off_quad(), QueryMemoryDescriptor::getEntryCount(), load_cst, and store_cst.

655  {
656  auto off = h * row_size_quad;
657  T empty_key = get_empty_key<T>();
658  T write_pending = get_empty_key<T>() - 1;
659  auto row_ptr = reinterpret_cast<T*>(groups_buffer + off);
660  const auto slot_off_quad = get_slot_off_quad(query_mem_desc);
661  const bool success = cas_cst(row_ptr, &empty_key, write_pending);
662  if (success) {
663  fill_slots(groups_buffer + off + slot_off_quad,
664  query_mem_desc.getEntryCount(),
665  that_buff_i64,
666  that_entry_idx,
667  that_entry_count,
668  query_mem_desc);
669  if (key_count > 1) {
670  memcpy(row_ptr + 1, key + 1, (key_count - 1) * sizeof(T));
671  }
672  store_cst(row_ptr, *key);
673  return {groups_buffer + off + slot_off_quad, true};
674  }
675  while (load_cst(row_ptr) == write_pending) {
676  // spin until the winning thread has finished writing the entire key and the init
677  // value
678  }
679  for (size_t i = 0; i < key_count; ++i) {
680  if (load_cst(row_ptr + i) != key[i]) {
681  return {nullptr, true};
682  }
683  }
684  return {groups_buffer + off + slot_off_quad, false};
685 }
void fill_slots(int64_t *dst_entry, const size_t dst_entry_count, const int64_t *src_buff, const size_t src_entry_idx, const size_t src_entry_count, const QueryMemoryDescriptor &query_mem_desc)
size_t get_slot_off_quad(const QueryMemoryDescriptor &query_mem_desc)
#define store_cst(ptr, val)
#define cas_cst(ptr, expected, desired)
#define load_cst(ptr)
+ Here is the call graph for this function:

◆ get_matching_group_value_reduction() [2/2]

GroupValueInfo anonymous_namespace{ResultSetReduction.cpp}::get_matching_group_value_reduction ( int64_t *  groups_buffer,
const uint32_t  h,
const int64_t *  key,
const uint32_t  key_count,
const size_t  key_width,
const QueryMemoryDescriptor query_mem_desc,
const int64_t *  that_buff_i64,
const size_t  that_entry_idx,
const size_t  that_entry_count,
const uint32_t  row_size_quad 
)
inline

Definition at line 691 of file ResultSetReduction.cpp.

References CHECK.

Referenced by get_group_value_reduction().

701  {
702  switch (key_width) {
703  case 4:
704  return get_matching_group_value_reduction(groups_buffer,
705  h,
706  reinterpret_cast<const int32_t*>(key),
707  key_count,
708  query_mem_desc,
709  that_buff_i64,
710  that_entry_idx,
711  that_entry_count,
712  row_size_quad);
713  case 8:
714  return get_matching_group_value_reduction(groups_buffer,
715  h,
716  key,
717  key_count,
718  query_mem_desc,
719  that_buff_i64,
720  that_entry_idx,
721  that_entry_count,
722  row_size_quad);
723  default:
724  CHECK(false);
725  return {nullptr, true};
726  }
727 }
#define CHECK(condition)
Definition: Logger.h:193
GroupValueInfo get_matching_group_value_reduction(int64_t *groups_buffer, const uint32_t h, const int64_t *key, const uint32_t key_count, const size_t key_width, const QueryMemoryDescriptor &query_mem_desc, const int64_t *that_buff_i64, const size_t that_entry_idx, const size_t that_entry_count, const uint32_t row_size_quad)
+ Here is the caller graph for this function:

◆ get_row_qw_count()

size_t anonymous_namespace{ResultSetReduction.cpp}::get_row_qw_count ( const QueryMemoryDescriptor query_mem_desc)

Definition at line 50 of file ResultSetReduction.cpp.

References CHECK_EQ, and get_row_bytes().

Referenced by fill_slots(), and ResultSetStorage::moveEntriesToBuffer().

50  {
51  const auto row_bytes = get_row_bytes(query_mem_desc);
52  CHECK_EQ(size_t(0), row_bytes % 8);
53  return row_bytes / 8;
54 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_key()

std::vector<int64_t> anonymous_namespace{ResultSetReduction.cpp}::make_key ( const int64_t *  buff,
const size_t  entry_count,
const size_t  key_count 
)

Definition at line 56 of file ResultSetReduction.cpp.

Referenced by ResultSetStorage::moveOneEntryToBuffer(), and ResultSetStorage::reduceOneEntryBaseline().

58  {
59  std::vector<int64_t> key;
60  size_t off = 0;
61  for (size_t i = 0; i < key_count; ++i) {
62  key.push_back(buff[off]);
63  off += entry_count;
64  }
65  return key;
66 }
+ Here is the caller graph for this function:

◆ run_reduction_code()

void anonymous_namespace{ResultSetReduction.cpp}::run_reduction_code ( const ReductionCode reduction_code,
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 
)

Definition at line 135 of file ResultSetReduction.cpp.

References Executor::ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES, ReductionCode::func_ptr, ReductionInterpreter::EvalValue::int_val, ReductionCode::ir_reduce_loop, ReductionInterpreter::EvalValue::ptr, and ReductionInterpreter::run().

Referenced by ResultSetStorage::reduce().

143  {
144  int err = 0;
145  if (reduction_code.func_ptr) {
146  err = reduction_code.func_ptr(this_buff,
147  that_buff,
148  start_entry_index,
149  end_entry_index,
150  that_entry_count,
151  this_qmd,
152  that_qmd,
153  serialized_varlen_buffer);
154  } else {
155  auto ret = ReductionInterpreter::run(
156  reduction_code.ir_reduce_loop.get(),
157  {ReductionInterpreter::EvalValue{.ptr = this_buff},
158  ReductionInterpreter::EvalValue{.ptr = that_buff},
159  ReductionInterpreter::EvalValue{.int_val = start_entry_index},
160  ReductionInterpreter::EvalValue{.int_val = end_entry_index},
161  ReductionInterpreter::EvalValue{.int_val = that_entry_count},
164  ReductionInterpreter::EvalValue{.ptr = serialized_varlen_buffer}});
165  err = ret.int_val;
166  }
167  if (err) {
169  throw std::runtime_error("Multiple distinct values encountered");
170  }
171 
172  throw std::runtime_error(
173  "Query execution has exceeded the time limit or was interrupted during result "
174  "set reduction");
175  }
176 }
std::unique_ptr< Function > ir_reduce_loop
static EvalValue run(const Function *function, const std::vector< EvalValue > &inputs)
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:985
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ use_multithreaded_reduction()

bool anonymous_namespace{ResultSetReduction.cpp}::use_multithreaded_reduction ( const size_t  entry_count)

Definition at line 46 of file ResultSetReduction.cpp.

Referenced by ResultSetStorage::moveEntriesToBuffer(), and ResultSetStorage::reduce().

46  {
47  return entry_count > 100000;
48 }
+ Here is the caller graph for this function: