OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 size_t executor_id, 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 ()
 
ALWAYS_INLINE void check_watchdog_with_seed (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

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

Definition at line 386 of file ResultSetReduction.cpp.

References dynamic_watchdog(), and UNLIKELY.

Referenced by ResultSetStorage::reduceEntriesNoCollisionsColWise().

386  {
387  if (UNLIKELY(dynamic_watchdog())) {
388  // TODO(alex): distinguish between the deadline and interrupt
389  throw std::runtime_error(
390  "Query execution has exceeded the time limit or was interrupted during result "
391  "set reduction");
392  }
393 }
__device__ bool dynamic_watchdog()
#define UNLIKELY(x)
Definition: likely.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 395 of file ResultSetReduction.cpp.

References dynamic_watchdog(), and UNLIKELY.

Referenced by ResultSetStorage::reduceOneEntryBaseline().

395  {
396  if (UNLIKELY((sample_seed & 0x3F) == 0 && dynamic_watchdog())) {
397  // TODO(alex): distinguish between the deadline and interrupt
398  throw std::runtime_error(
399  "Query execution has exceeded the time limit or was interrupted during result "
400  "set reduction");
401  }
402 }
__device__ bool dynamic_watchdog()
#define UNLIKELY(x)
Definition: likely.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 89 of file ResultSetReduction.cpp.

References EMPTY_KEY_32.

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

89  {
90  for (size_t i = 0; i < key_count; ++i) {
91  key_ptr_i32[i] = EMPTY_KEY_32;
92  }
93 }
#define EMPTY_KEY_32

+ Here is the caller graph for this function:

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

Definition at line 96 of file ResultSetReduction.cpp.

References EMPTY_KEY_64.

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

96  {
97  for (size_t i = 0; i < key_count; ++i) {
98  key_ptr_i64[i] = EMPTY_KEY_64;
99  }
100 }
#define EMPTY_KEY_64

+ Here is the caller graph for this function:

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 65 of file ResultSetReduction.cpp.

References 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().

70  {
71  const auto slot_count = query_mem_desc.getBufferColSlotCount();
72  const auto key_count = query_mem_desc.getGroupbyColCount();
73  if (query_mem_desc.didOutputColumnar()) {
74  for (size_t i = 0, dst_slot_off = 0; i < slot_count;
75  ++i, dst_slot_off += dst_entry_count) {
76  dst_entry[dst_slot_off] =
77  src_buff[slot_offset_colwise(src_entry_idx, i, key_count, src_entry_count)];
78  }
79  } else {
80  const auto row_ptr = src_buff + get_row_qw_count(query_mem_desc) * src_entry_idx;
81  const auto slot_off_quad = get_slot_off_quad(query_mem_desc);
82  for (size_t i = 0; i < slot_count; ++i) {
83  dst_entry[i] = row_ptr[slot_off_quad + i];
84  }
85  }
86 }
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 getGroupbyColCount() const
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:

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 102 of file ResultSetReduction.cpp.

References CHECK.

Referenced by ResultSetStorage::reduceSingleRow().

104  {
105  int64_t ret = std::numeric_limits<int64_t>::min();
106  switch (comp_sz) {
107  case 1: {
108  ret = group_by_buffer[index];
109  break;
110  }
111  case 2: {
112  const int16_t* buffer_ptr = reinterpret_cast<const int16_t*>(group_by_buffer);
113  ret = buffer_ptr[index];
114  break;
115  }
116  case 4: {
117  const int32_t* buffer_ptr = reinterpret_cast<const int32_t*>(group_by_buffer);
118  ret = buffer_ptr[index];
119  break;
120  }
121  case 8: {
122  const int64_t* buffer_ptr = reinterpret_cast<const int64_t*>(group_by_buffer);
123  ret = buffer_ptr[index];
124  break;
125  }
126  default:
127  CHECK(false);
128  }
129  return ret;
130 }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

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 655 of file ResultSetReduction.cpp.

References get_matching_group_value_columnar_reduction(), and key_hash().

Referenced by ResultSetStorage::reduceOneEntryBaseline().

659  {
660  uint32_t h = key_hash(key, key_qw_count, sizeof(int64_t)) % groups_buffer_entry_count;
662  groups_buffer, h, key, key_qw_count, groups_buffer_entry_count);
663  if (matching_gvi.first) {
664  return matching_gvi;
665  }
666  uint32_t h_probe = (h + 1) % groups_buffer_entry_count;
667  while (h_probe != h) {
669  groups_buffer, h_probe, key, key_qw_count, groups_buffer_entry_count);
670  if (matching_gvi.first) {
671  return matching_gvi;
672  }
673  h_probe = (h_probe + 1) % groups_buffer_entry_count;
674  }
675  return {nullptr, true};
676 }
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)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE uint32_t key_hash(const int64_t *key, const uint32_t key_count, const uint32_t key_byte_width)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 628 of file ResultSetReduction.cpp.

References EMPTY_KEY_64, and mapd_cas.

Referenced by get_group_value_columnar_reduction().

632  {
633  auto off = h;
634  const auto old_key = mapd_cas(&groups_buffer[off], EMPTY_KEY_64, *key);
635  if (old_key == EMPTY_KEY_64) {
636  for (size_t i = 0; i < key_qw_count; ++i) {
637  groups_buffer[off] = key[i];
638  off += entry_count;
639  }
640  return {&groups_buffer[off], true};
641  }
642  off = h;
643  for (size_t i = 0; i < key_qw_count; ++i) {
644  if (groups_buffer[off] != key[i]) {
645  return {nullptr, true};
646  }
647  off += entry_count;
648  }
649  return {&groups_buffer[off], false};
650 }
#define EMPTY_KEY_64
#define mapd_cas(address, compare, val)

+ Here is the caller graph for this function:

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 697 of file ResultSetReduction.cpp.

References cas_cst, fill_slots(), get_slot_off_quad(), QueryMemoryDescriptor::getEntryCount(), load_cst, query_mem_desc, store_cst, and heavydb.dtypes::T.

Referenced by result_set::get_group_value_reduction(), and get_matching_group_value_reduction().

706  {
707  auto off = h * row_size_quad;
708  T empty_key = get_empty_key<T>();
709  T write_pending = get_empty_key<T>() - 1;
710  auto row_ptr = reinterpret_cast<T*>(groups_buffer + off);
711  const auto slot_off_quad = get_slot_off_quad(query_mem_desc);
712  const bool success = cas_cst(row_ptr, &empty_key, write_pending);
713  if (success) {
714  fill_slots(groups_buffer + off + slot_off_quad,
715  query_mem_desc.getEntryCount(),
716  that_buff_i64,
717  that_entry_idx,
718  that_entry_count,
720  if (key_count > 1) {
721  memcpy(row_ptr + 1, key + 1, (key_count - 1) * sizeof(T));
722  }
723  store_cst(row_ptr, *key);
724  return {groups_buffer + off + slot_off_quad, true};
725  }
726  while (load_cst(row_ptr) == write_pending) {
727  // spin until the winning thread has finished writing the entire key and the init
728  // value
729  }
730  for (size_t i = 0; i < key_count; ++i) {
731  if (load_cst(row_ptr + i) != key[i]) {
732  return {nullptr, true};
733  }
734  }
735  return {groups_buffer + off + slot_off_quad, false};
736 }
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:

+ Here is the caller graph for this function:

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 742 of file ResultSetReduction.cpp.

References CHECK, and get_matching_group_value_reduction().

752  {
753  switch (key_width) {
754  case 4:
755  return get_matching_group_value_reduction(groups_buffer,
756  h,
757  reinterpret_cast<const int32_t*>(key),
758  key_count,
759  query_mem_desc,
760  that_buff_i64,
761  that_entry_idx,
762  that_entry_count,
763  row_size_quad);
764  case 8:
765  return get_matching_group_value_reduction(groups_buffer,
766  h,
767  key,
768  key_count,
769  query_mem_desc,
770  that_buff_i64,
771  that_entry_idx,
772  that_entry_count,
773  row_size_quad);
774  default:
775  CHECK(false);
776  return {nullptr, true};
777  }
778 }
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)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

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

Definition at line 47 of file ResultSetReduction.cpp.

References CHECK_EQ, and get_row_bytes().

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

47  {
48  const auto row_bytes = get_row_bytes(query_mem_desc);
49  CHECK_EQ(size_t(0), row_bytes % 8);
50  return row_bytes / 8;
51 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
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:

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 53 of file ResultSetReduction.cpp.

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

55  {
56  std::vector<int64_t> key;
57  size_t off = 0;
58  for (size_t i = 0; i < key_count; ++i) {
59  key.push_back(buff[off]);
60  off += entry_count;
61  }
62  return key;
63 }

+ Here is the caller graph for this function:

void anonymous_namespace{ResultSetReduction.cpp}::run_reduction_code ( const size_t  executor_id,
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 132 of file ResultSetReduction.cpp.

References ReductionCode::func_ptr, ReductionInterpreter::EvalValue::int_val, ReductionCode::ir_reduce_loop, ReductionInterpreter::MakeEvalValue(), and ReductionInterpreter::run().

Referenced by ResultSetStorage::reduce().

141  {
142  int err = 0;
143  if (reduction_code.func_ptr) {
144  err = reduction_code.func_ptr(this_buff,
145  that_buff,
146  start_entry_index,
147  end_entry_index,
148  that_entry_count,
149  this_qmd,
150  that_qmd,
151  serialized_varlen_buffer);
152  } else {
153  auto ret = ReductionInterpreter::run(
154  executor_id,
155  reduction_code.ir_reduce_loop.get(),
158  ReductionInterpreter::MakeEvalValue(start_entry_index),
159  ReductionInterpreter::MakeEvalValue(end_entry_index),
160  ReductionInterpreter::MakeEvalValue(that_entry_count),
163  ReductionInterpreter::MakeEvalValue(serialized_varlen_buffer)});
164  err = ret.int_val;
165  }
166  if (err) {
167  if (err == int32_t(heavyai::ErrorCode::SINGLE_VALUE_FOUND_MULTIPLE_VALUES)) {
168  throw std::runtime_error("Multiple distinct values encountered");
169  } else if (err == int32_t(heavyai::ErrorCode::INTERRUPTED)) {
170  throw std::runtime_error(
171  "Query execution has interrupted during result set reduction");
172  }
173  throw std::runtime_error(
174  "Query execution has exceeded the time limit or was interrupted during result "
175  "set reduction");
176  }
177 }
std::unique_ptr< Function > ir_reduce_loop
static EvalValue MakeEvalValue(const T &val)
static EvalValue run(const size_t execution_id, const Function *function, const std::vector< EvalValue > &inputs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 43 of file ResultSetReduction.cpp.

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

43  {
44  return entry_count > 100000;
45 }

+ Here is the caller graph for this function: