OmniSciDB  04ee39c94c
ResultSetReduction.cpp File Reference

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

#include "DynamicWatchdog.h"
#include "ResultSet.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 1392 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 1405 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 1458 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 1331 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 1441 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 745 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 181 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().

181  {
182  switch (key_width) {
183  case 4: {
184  auto key_ptr_i32 = reinterpret_cast<int32_t*>(key_ptr);
185  fill_empty_key_32(key_ptr_i32, key_count);
186  break;
187  }
188  case 8: {
189  auto key_ptr_i64 = reinterpret_cast<int64_t*>(key_ptr);
190  fill_empty_key_64(key_ptr_i64, key_count);
191  break;
192  }
193  default:
194  CHECK(false);
195  }
196 }
ALWAYS_INLINE void fill_empty_key_32(int32_t *key_ptr_i32, const size_t key_count)
#define CHECK(condition)
Definition: Logger.h:187
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 837 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(), and ResultSetStorage::reduceOneEntryBaseline().

846  {
847  uint32_t h = key_hash(key, key_count, key_width) % groups_buffer_entry_count;
848  auto matching_gvi = get_matching_group_value_reduction(groups_buffer,
849  h,
850  key,
851  key_count,
852  key_width,
853  query_mem_desc,
854  that_buff_i64,
855  that_entry_idx,
856  that_entry_count,
857  row_size_quad);
858  if (matching_gvi.first) {
859  return matching_gvi;
860  }
861  uint32_t h_probe = (h + 1) % groups_buffer_entry_count;
862  while (h_probe != h) {
863  matching_gvi = get_matching_group_value_reduction(groups_buffer,
864  h_probe,
865  key,
866  key_count,
867  key_width,
868  query_mem_desc,
869  that_buff_i64,
870  that_entry_idx,
871  that_entry_count,
872  row_size_quad);
873  if (matching_gvi.first) {
874  return matching_gvi;
875  }
876  h_probe = (h_probe + 1) % groups_buffer_entry_count;
877  }
878  return {nullptr, true};
879 }
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 1479 of file ResultSetReduction.cpp.

References QueryMemoryDescriptor::getPaddedSlotWidthBytes().

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

1481  {
1482  if (float_argument_input) {
1483  return sizeof(float);
1484  }
1485  return query_mem_desc.getPaddedSlotWidthBytes(target_slot_idx);
1486 }
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