OmniSciDB  29e35f4d58
ResultSetReduction.cpp File Reference

Reduction part of the row set interface. More...

#include "DynamicWatchdog.h"
#include "Execute.h"
#include "ResultSet.h"
#include "ResultSetReductionInterpreter.h"
#include "ResultSetReductionJIT.h"
#include "RuntimeFunctions.h"
#include "Shared/SqlTypesLayout.h"
#include "Shared/likely.h"
#include "Shared/thread_count.h"
#include <llvm/ExecutionEngine/GenericValue.h>
#include <algorithm>
#include <future>
#include <numeric>
+ Include dependency graph for ResultSetReduction.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{ResultSetReduction.cpp}
 

Macros

#define cas_cst(ptr, expected, desired)
 
#define store_cst(ptr, val)   __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST)
 
#define load_cst(ptr)   __atomic_load_n(ptr, __ATOMIC_SEQ_CST)
 
#define AGGREGATE_ONE_VALUE( agg_kind__, val_ptr__, other_ptr__, chosen_bytes__, agg_info__)
 
#define AGGREGATE_ONE_NULLABLE_VALUE( agg_kind__, val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
 
#define AGGREGATE_ONE_COUNT(val_ptr__, other_ptr__, chosen_bytes__)
 
#define AGGREGATE_ONE_NULLABLE_COUNT( val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
 
#define AGGREGATE_ONE_VALUE_SMALL( agg_kind__, val_ptr__, other_ptr__, chosen_bytes__, agg_info__)
 
#define AGGREGATE_ONE_NULLABLE_VALUE_SMALL( agg_kind__, val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
 

Functions

bool anonymous_namespace{ResultSetReduction.cpp}::use_multithreaded_reduction (const size_t entry_count)
 
size_t anonymous_namespace{ResultSetReduction.cpp}::get_row_qw_count (const QueryMemoryDescriptor &query_mem_desc)
 
std::vector< int64_t > anonymous_namespace{ResultSetReduction.cpp}::make_key (const int64_t *buff, const size_t entry_count, const size_t key_count)
 
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)
 
ALWAYS_INLINE void anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_32 (int32_t *key_ptr_i32, const size_t key_count)
 
ALWAYS_INLINE void anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_64 (int64_t *key_ptr_i64, const size_t key_count)
 
int64_t anonymous_namespace{ResultSetReduction.cpp}::get_component (const int8_t *group_by_buffer, const size_t comp_sz, const size_t index=0)
 
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)
 
void fill_empty_key (void *key_ptr, const size_t key_count, const size_t key_width)
 
ALWAYS_INLINE void anonymous_namespace{ResultSetReduction.cpp}::check_watchdog (const size_t sample_seed)
 
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)
 
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)
 
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)
 
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)
 
GroupValueInfo get_group_value_reduction (int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, 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)
 
int8_t get_width_for_slot (const size_t target_slot_idx, const bool float_argument_input, const QueryMemoryDescriptor &query_mem_desc)
 

Variables

bool g_enable_dynamic_watchdog
 

Detailed Description

Reduction part of the row set interface.

Author
Alex Suhan alex@.nosp@m.mapd.nosp@m..com Copyright (c) 2014 MapD Technologies, Inc. All rights reserved.

Definition in file ResultSetReduction.cpp.

Macro Definition Documentation

◆ AGGREGATE_ONE_COUNT

#define AGGREGATE_ONE_COUNT (   val_ptr__,
  other_ptr__,
  chosen_bytes__ 
)
Value:
do { \
if (chosen_bytes__ == sizeof(int32_t)) { \
auto val_ptr = reinterpret_cast<int32_t*>(val_ptr__); \
auto other_ptr = reinterpret_cast<const int32_t*>(other_ptr__); \
agg_sum_int32(val_ptr, *other_ptr); \
} else { \
auto val_ptr = reinterpret_cast<int64_t*>(val_ptr__); \
auto other_ptr = reinterpret_cast<const int64_t*>(other_ptr__); \
agg_sum(val_ptr, *other_ptr); \
} \
} while (0)

Definition at line 1258 of file ResultSetReduction.cpp.

Referenced by ResultSetStorage::reduceOneSlot(), and ResultSetStorage::reduceSingleRow().

◆ AGGREGATE_ONE_NULLABLE_COUNT

#define AGGREGATE_ONE_NULLABLE_COUNT (   val_ptr__,
  other_ptr__,
  init_val__,
  chosen_bytes__,
  agg_info__ 
)

Definition at line 1271 of file ResultSetReduction.cpp.

Referenced by ResultSetStorage::reduceSingleRow().

◆ AGGREGATE_ONE_NULLABLE_VALUE

#define AGGREGATE_ONE_NULLABLE_VALUE (   agg_kind__,
  val_ptr__,
  other_ptr__,
  init_val__,
  chosen_bytes__,
  agg_info__ 
)

◆ AGGREGATE_ONE_NULLABLE_VALUE_SMALL

#define AGGREGATE_ONE_NULLABLE_VALUE_SMALL (   agg_kind__,
  val_ptr__,
  other_ptr__,
  init_val__,
  chosen_bytes__,
  agg_info__ 
)
Value:
do { \
if (agg_info__.skip_null_val) { \
if (chosen_bytes__ == sizeof(int16_t)) { \
int16_t* val_ptr = reinterpret_cast<int16_t*>(val_ptr__); \
const int16_t* other_ptr = reinterpret_cast<const int16_t*>(other_ptr__); \
const auto null_val = static_cast<int16_t>(init_val__); \
agg_##agg_kind__##_int16_skip_val(val_ptr, *other_ptr, null_val); \
} else if (chosen_bytes == sizeof(int8_t)) { \
int8_t* val_ptr = reinterpret_cast<int8_t*>(val_ptr__); \
const int8_t* other_ptr = reinterpret_cast<const int8_t*>(other_ptr__); \
const auto null_val = static_cast<int8_t>(init_val__); \
agg_##agg_kind__##_int8_skip_val(val_ptr, *other_ptr, null_val); \
} \
} else { \
AGGREGATE_ONE_VALUE_SMALL( \
agg_kind__, val_ptr__, other_ptr__, chosen_bytes__, agg_info__); \
} \
} while (0)

Definition at line 1324 of file ResultSetReduction.cpp.

Referenced by ResultSetStorage::reduceOneSlot(), and ResultSetStorage::reduceSingleRow().

◆ AGGREGATE_ONE_VALUE

#define AGGREGATE_ONE_VALUE (   agg_kind__,
  val_ptr__,
  other_ptr__,
  chosen_bytes__,
  agg_info__ 
)
Value:
do { \
const auto sql_type = get_compact_type(agg_info__); \
if (sql_type.is_fp()) { \
if (chosen_bytes__ == sizeof(float)) { \
agg_##agg_kind__##_float(reinterpret_cast<int32_t*>(val_ptr__), \
*reinterpret_cast<const float*>(other_ptr__)); \
} else { \
agg_##agg_kind__##_double(reinterpret_cast<int64_t*>(val_ptr__), \
*reinterpret_cast<const double*>(other_ptr__)); \
} \
} else { \
if (chosen_bytes__ == sizeof(int32_t)) { \
auto val_ptr = reinterpret_cast<int32_t*>(val_ptr__); \
auto other_ptr = reinterpret_cast<const int32_t*>(other_ptr__); \
agg_##agg_kind__##_int32(val_ptr, *other_ptr); \
} else { \
auto val_ptr = reinterpret_cast<int64_t*>(val_ptr__); \
auto other_ptr = reinterpret_cast<const int64_t*>(other_ptr__); \
agg_##agg_kind__(val_ptr, *other_ptr); \
} \
} \
} while (0)
const SQLTypeInfo get_compact_type(const TargetInfo &target)

Definition at line 1197 of file ResultSetReduction.cpp.

◆ AGGREGATE_ONE_VALUE_SMALL

#define AGGREGATE_ONE_VALUE_SMALL (   agg_kind__,
  val_ptr__,
  other_ptr__,
  chosen_bytes__,
  agg_info__ 
)
Value:
do { \
if (chosen_bytes__ == sizeof(int16_t)) { \
auto val_ptr = reinterpret_cast<int16_t*>(val_ptr__); \
auto other_ptr = reinterpret_cast<const int16_t*>(other_ptr__); \
agg_##agg_kind__##_int16(val_ptr, *other_ptr); \
} else if (chosen_bytes__ == sizeof(int8_t)) { \
auto val_ptr = reinterpret_cast<int8_t*>(val_ptr__); \
auto other_ptr = reinterpret_cast<const int8_t*>(other_ptr__); \
agg_##agg_kind__##_int8(val_ptr, *other_ptr); \
} else { \
UNREACHABLE(); \
} \
} while (0)

Definition at line 1307 of file ResultSetReduction.cpp.

◆ cas_cst

#define cas_cst (   ptr,
  expected,
  desired 
)
Value:
__atomic_compare_exchange_n( \
ptr, expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)

Definition at line 639 of file ResultSetReduction.cpp.

Referenced by anonymous_namespace{ResultSetReduction.cpp}::get_matching_group_value_reduction().

◆ load_cst

#define load_cst (   ptr)    __atomic_load_n(ptr, __ATOMIC_SEQ_CST)

◆ store_cst

#define store_cst (   ptr,
  val 
)    __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST)

Function Documentation

◆ fill_empty_key()

void fill_empty_key ( void *  key_ptr,
const size_t  key_count,
const size_t  key_width 
)

Definition at line 180 of file ResultSetReduction.cpp.

References CHECK, anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_32(), and anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_64().

Referenced by QueryMemoryInitializer::initGroups(), and RowSortException::RowSortException().

180  {
181  switch (key_width) {
182  case 4: {
183  auto key_ptr_i32 = reinterpret_cast<int32_t*>(key_ptr);
184  fill_empty_key_32(key_ptr_i32, key_count);
185  break;
186  }
187  case 8: {
188  auto key_ptr_i64 = reinterpret_cast<int64_t*>(key_ptr);
189  fill_empty_key_64(key_ptr_i64, key_count);
190  break;
191  }
192  default:
193  CHECK(false);
194  }
195 }
ALWAYS_INLINE void fill_empty_key_32(int32_t *key_ptr_i32, const size_t key_count)
#define CHECK(condition)
Definition: Logger.h:193
ALWAYS_INLINE void fill_empty_key_64(int64_t *key_ptr_i64, const size_t key_count)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_group_value_reduction()

GroupValueInfo get_group_value_reduction ( int64_t *  groups_buffer,
const uint32_t  groups_buffer_entry_count,
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 
)

Definition at line 731 of file ResultSetReduction.cpp.

References anonymous_namespace{ResultSetReduction.cpp}::get_matching_group_value_reduction(), groups_buffer_entry_count, and key_hash().

Referenced by get_group_value_reduction_rt().

740  {
741  uint32_t h = key_hash(key, key_count, key_width) % groups_buffer_entry_count;
742  auto matching_gvi = get_matching_group_value_reduction(groups_buffer,
743  h,
744  key,
745  key_count,
746  key_width,
747  query_mem_desc,
748  that_buff_i64,
749  that_entry_idx,
750  that_entry_count,
751  row_size_quad);
752  if (matching_gvi.first) {
753  return matching_gvi;
754  }
755  uint32_t h_probe = (h + 1) % groups_buffer_entry_count;
756  while (h_probe != h) {
757  matching_gvi = get_matching_group_value_reduction(groups_buffer,
758  h_probe,
759  key,
760  key_count,
761  key_width,
762  query_mem_desc,
763  that_buff_i64,
764  that_entry_idx,
765  that_entry_count,
766  row_size_quad);
767  if (matching_gvi.first) {
768  return matching_gvi;
769  }
770  h_probe = (h_probe + 1) % groups_buffer_entry_count;
771  }
772  return {nullptr, true};
773 }
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
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 call graph for this function:
+ Here is the caller graph for this function:

◆ get_width_for_slot()

int8_t get_width_for_slot ( const size_t  target_slot_idx,
const bool  float_argument_input,
const QueryMemoryDescriptor query_mem_desc 
)

Definition at line 1345 of file ResultSetReduction.cpp.

References QueryMemoryDescriptor::getPaddedSlotWidthBytes().

Referenced by ResultSetReductionJIT::reduceOneSlot(), ResultSetStorage::reduceOneSlot(), ResultSetStorage::reduceOneSlotSingleValue(), and RowSortException::RowSortException().

1347  {
1348  if (float_argument_input) {
1349  return sizeof(float);
1350  }
1351  return query_mem_desc.getPaddedSlotWidthBytes(target_slot_idx);
1352 }
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ g_enable_dynamic_watchdog