OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSetReduction.cpp File Reference

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

#include "DynamicWatchdog.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

#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)
ALWAYS_INLINE int32_t agg_sum_int32(int32_t *agg, const int32_t val)
ALWAYS_INLINE int64_t agg_sum(int64_t *agg, const int64_t val)

Definition at line 1253 of file ResultSetReduction.cpp.

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

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

Definition at line 1266 of file ResultSetReduction.cpp.

Referenced by ResultSetStorage::reduceSingleRow().

#define AGGREGATE_ONE_NULLABLE_VALUE (   agg_kind__,
  val_ptr__,
  other_ptr__,
  init_val__,
  chosen_bytes__,
  agg_info__ 
)
#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 { \
agg_kind__, val_ptr__, other_ptr__, chosen_bytes__, agg_info__); \
} \
} while (0)
#define AGGREGATE_ONE_VALUE_SMALL(agg_kind__, val_ptr__, other_ptr__, chosen_bytes__, agg_info__)

Definition at line 1319 of file ResultSetReduction.cpp.

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

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

#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 { \
} \
} while (0)
#define UNREACHABLE()
Definition: Logger.h:234

Definition at line 1302 of file ResultSetReduction.cpp.

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

Definition at line 634 of file ResultSetReduction.cpp.

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

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

Function Documentation

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

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

175  {
176  switch (key_width) {
177  case 4: {
178  auto key_ptr_i32 = reinterpret_cast<int32_t*>(key_ptr);
179  fill_empty_key_32(key_ptr_i32, key_count);
180  break;
181  }
182  case 8: {
183  auto key_ptr_i64 = reinterpret_cast<int64_t*>(key_ptr);
184  fill_empty_key_64(key_ptr_i64, key_count);
185  break;
186  }
187  default:
188  CHECK(false);
189  }
190 }
ALWAYS_INLINE void fill_empty_key_32(int32_t *key_ptr_i32, const size_t key_count)
CHECK(cgen_state)
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:

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

735  {
736  uint32_t h = key_hash(key, key_count, key_width) % groups_buffer_entry_count;
738  h,
739  key,
740  key_count,
741  key_width,
742  query_mem_desc,
743  that_buff_i64,
744  that_entry_idx,
745  that_entry_count,
746  row_size_quad);
747  if (matching_gvi.first) {
748  return matching_gvi;
749  }
750  uint32_t h_probe = (h + 1) % groups_buffer_entry_count;
751  while (h_probe != h) {
753  h_probe,
754  key,
755  key_count,
756  key_width,
757  query_mem_desc,
758  that_buff_i64,
759  that_entry_idx,
760  that_entry_count,
761  row_size_quad);
762  if (matching_gvi.first) {
763  return matching_gvi;
764  }
765  h_probe = (h_probe + 1) % groups_buffer_entry_count;
766  }
767  return {nullptr, true};
768 }
const int32_t groups_buffer_size return groups_buffer
ALWAYS_INLINE DEVICE uint32_t key_hash(const int64_t *key, const uint32_t key_count, const uint32_t key_byte_width)
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)
const int64_t const uint32_t groups_buffer_entry_count

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References QueryMemoryDescriptor::getPaddedSlotWidthBytes().

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

1342  {
1343  if (float_argument_input) {
1344  return sizeof(float);
1345  }
1346  return query_mem_desc.getPaddedSlotWidthBytes(target_slot_idx);
1347 }
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