OmniSciDB  04ee39c94c
InValuesBitmap Class Reference

#include <InValuesBitmap.h>

Public Member Functions

 InValuesBitmap (const std::vector< int64_t > &values, const int64_t null_val, const Data_Namespace::MemoryLevel memory_level, const int device_count, Data_Namespace::DataMgr *data_mgr)
 
 ~InValuesBitmap ()
 
llvm::Value * codegen (llvm::Value *needle, Executor *executor) const
 
bool isEmpty () const
 
bool hasNull () const
 

Private Attributes

std::vector< int8_t * > bitsets_
 
bool rhs_has_null_
 
int64_t min_val_
 
int64_t max_val_
 
const int64_t null_val_
 
const Data_Namespace::MemoryLevel memory_level_
 
const int device_count_
 

Detailed Description

Definition at line 42 of file InValuesBitmap.h.

Constructor & Destructor Documentation

◆ InValuesBitmap()

InValuesBitmap::InValuesBitmap ( const std::vector< int64_t > &  values,
const int64_t  null_val,
const Data_Namespace::MemoryLevel  memory_level,
const int  device_count,
Data_Namespace::DataMgr data_mgr 
)

Definition at line 39 of file InValuesBitmap.cpp.

References agg_count_distinct_bitmap(), CudaAllocator::alloc(), bitmap_bits_to_bytes(), bitsets_, CHECK, CHECK_EQ, checked_calloc(), copy_to_gpu(), Data_Namespace::CPU_LEVEL, device_count_, Data_Namespace::GPU_LEVEL, max_val_, memory_level_, min_val_, and rhs_has_null_.

44  : rhs_has_null_(false)
45  , null_val_(null_val)
46  , memory_level_(memory_level)
47  , device_count_(device_count) {
48 #ifdef HAVE_CUDA
50  memory_level == Data_Namespace::GPU_LEVEL);
51 #else
53 #endif // HAVE_CUDA
54  if (values.empty()) {
55  return;
56  }
57  min_val_ = std::numeric_limits<int64_t>::max();
58  max_val_ = std::numeric_limits<int64_t>::min();
59  for (const auto value : values) {
60  if (value == null_val) {
61  rhs_has_null_ = true;
62  continue;
63  }
64  if (value < min_val_) {
65  min_val_ = value;
66  }
67  if (value > max_val_) {
68  max_val_ = value;
69  }
70  }
71  if (max_val_ < min_val_) {
72  CHECK_EQ(std::numeric_limits<int64_t>::max(), min_val_);
73  CHECK_EQ(std::numeric_limits<int64_t>::min(), max_val_);
75  return;
76  }
77  const int64_t MAX_BITMAP_BITS{8 * 1000 * 1000 * 1000L};
78  const auto bitmap_sz_bits =
79  static_cast<int64_t>(checked_int64_t(max_val_) - min_val_ + 1);
80  if (bitmap_sz_bits > MAX_BITMAP_BITS) {
81  throw FailedToCreateBitmap();
82  }
83  const auto bitmap_sz_bytes = bitmap_bits_to_bytes(bitmap_sz_bits);
84  auto cpu_bitset = static_cast<int8_t*>(checked_calloc(bitmap_sz_bytes, 1));
85  for (const auto value : values) {
86  if (value == null_val) {
87  continue;
88  }
89  agg_count_distinct_bitmap(reinterpret_cast<int64_t*>(&cpu_bitset), value, min_val_);
90  }
91 #ifdef HAVE_CUDA
93  for (int device_id = 0; device_id < device_count_; ++device_id) {
94  auto gpu_bitset = CudaAllocator::alloc(data_mgr, bitmap_sz_bytes, device_id);
95  copy_to_gpu(data_mgr,
96  reinterpret_cast<CUdeviceptr>(gpu_bitset),
97  cpu_bitset,
98  bitmap_sz_bytes,
99  device_id);
100  bitsets_.push_back(gpu_bitset);
101  }
102  free(cpu_bitset);
103  } else {
104  bitsets_.push_back(cpu_bitset);
105  }
106 #else
107  CHECK_EQ(1, device_count_);
108  bitsets_.push_back(cpu_bitset);
109 #endif // HAVE_CUDA
110 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
size_t bitmap_bits_to_bytes(const size_t bitmap_sz)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void > > checked_int64_t
static int8_t * alloc(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
void copy_to_gpu(Data_Namespace::DataMgr *data_mgr, CUdeviceptr dst, const void *src, const size_t num_bytes, const int device_id)
Definition: GpuMemUtils.cpp:31
std::vector< int8_t * > bitsets_
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:48
const int64_t null_val_
const int device_count_
#define CHECK(condition)
Definition: Logger.h:187
ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val)
const Data_Namespace::MemoryLevel memory_level_
+ Here is the call graph for this function:

◆ ~InValuesBitmap()

InValuesBitmap::~InValuesBitmap ( )

Definition at line 112 of file InValuesBitmap.cpp.

References bitsets_, CHECK_EQ, Data_Namespace::CPU_LEVEL, and memory_level_.

112  {
113  if (bitsets_.empty()) {
114  return;
115  }
117  CHECK_EQ(size_t(1), bitsets_.size());
118  free(bitsets_.front());
119  }
120 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::vector< int8_t * > bitsets_
const Data_Namespace::MemoryLevel memory_level_

Member Function Documentation

◆ codegen()

llvm::Value * InValuesBitmap::codegen ( llvm::Value *  needle,
Executor executor 
) const

Definition at line 122 of file InValuesBitmap.cpp.

References Parser::IntLiteral::analyzeValue(), bitsets_, CHECK, CHECK_EQ, CodeGenerator::codegenHoistedConstants(), inline_int_null_val(), kBOOLEAN, kENCODING_NONE, max_val_, min_val_, and null_val_.

Referenced by CodeGenerator::codegen().

122  {
123  CHECK(!bitsets_.empty());
124  std::vector<std::shared_ptr<const Analyzer::Constant>> constants_owned;
125  std::vector<const Analyzer::Constant*> constants;
126  for (const auto bitset : bitsets_) {
127  const int64_t bitset_handle = reinterpret_cast<int64_t>(bitset);
128  const auto bitset_handle_literal = std::dynamic_pointer_cast<Analyzer::Constant>(
129  Parser::IntLiteral::analyzeValue(bitset_handle));
130  CHECK(bitset_handle_literal);
131  CHECK_EQ(kENCODING_NONE, bitset_handle_literal->get_type_info().get_compression());
132  constants_owned.push_back(bitset_handle_literal);
133  constants.push_back(bitset_handle_literal.get());
134  }
135  CodeGenerator code_generator(executor);
136  const auto bitset_handle_lvs =
137  code_generator.codegenHoistedConstants(constants, kENCODING_NONE, 0);
138  CHECK_EQ(size_t(1), bitset_handle_lvs.size());
139  const auto needle_i64 = executor->cgen_state_->castToTypeIn(needle, 64);
140  const auto null_bool_val =
141  static_cast<int8_t>(inline_int_null_val(SQLTypeInfo(kBOOLEAN, false)));
142  return executor->cgen_state_->emitCall(
143  "bit_is_set",
144  {executor->cgen_state_->castToTypeIn(bitset_handle_lvs.front(), 64),
145  needle_i64,
146  executor->cgen_state_->llInt(min_val_),
147  executor->cgen_state_->llInt(max_val_),
148  executor->cgen_state_->llInt(null_val_),
149  executor->cgen_state_->llInt(null_bool_val)});
150 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
static std::shared_ptr< Analyzer::Expr > analyzeValue(const int64_t intval)
Definition: ParserNode.cpp:108
std::vector< int8_t * > bitsets_
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:823
const int64_t null_val_
#define CHECK(condition)
Definition: Logger.h:187
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasNull()

bool InValuesBitmap::hasNull ( ) const

Definition at line 156 of file InValuesBitmap.cpp.

References rhs_has_null_.

156  {
157  return rhs_has_null_;
158 }

◆ isEmpty()

bool InValuesBitmap::isEmpty ( ) const

Definition at line 152 of file InValuesBitmap.cpp.

References bitsets_.

152  {
153  return bitsets_.empty();
154 }
std::vector< int8_t * > bitsets_

Member Data Documentation

◆ bitsets_

std::vector<int8_t*> InValuesBitmap::bitsets_
private

Definition at line 58 of file InValuesBitmap.h.

Referenced by codegen(), InValuesBitmap(), isEmpty(), and ~InValuesBitmap().

◆ device_count_

const int InValuesBitmap::device_count_
private

Definition at line 64 of file InValuesBitmap.h.

Referenced by InValuesBitmap().

◆ max_val_

int64_t InValuesBitmap::max_val_
private

Definition at line 61 of file InValuesBitmap.h.

Referenced by codegen(), and InValuesBitmap().

◆ memory_level_

const Data_Namespace::MemoryLevel InValuesBitmap::memory_level_
private

Definition at line 63 of file InValuesBitmap.h.

Referenced by InValuesBitmap(), and ~InValuesBitmap().

◆ min_val_

int64_t InValuesBitmap::min_val_
private

Definition at line 60 of file InValuesBitmap.h.

Referenced by codegen(), and InValuesBitmap().

◆ null_val_

const int64_t InValuesBitmap::null_val_
private

Definition at line 62 of file InValuesBitmap.h.

Referenced by codegen().

◆ rhs_has_null_

bool InValuesBitmap::rhs_has_null_
private

Definition at line 59 of file InValuesBitmap.h.

Referenced by hasNull(), and InValuesBitmap().


The documentation for this class was generated from the following files: