OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InValuesBitmap Class Reference

#include <InValuesBitmap.h>

+ Collaboration diagram for InValuesBitmap:

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
 
size_t gpuBuffers () const
 

Private Attributes

std::vector
< Data_Namespace::AbstractBuffer * > 
gpu_buffers_
 
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_
 
Data_Namespace::DataMgrdata_mgr_
 

Detailed Description

Definition at line 42 of file InValuesBitmap.h.

Constructor & Destructor Documentation

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::allocGpuAbstractBuffer(), bitmap_bits_to_bytes(), bitsets_, CHECK, CHECK_EQ, checked_calloc(), copy_to_gpu(), Data_Namespace::CPU_LEVEL, device_count_, gpu_buffers_, 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  , data_mgr_(data_mgr) {
49 #ifdef HAVE_CUDA
51  memory_level == Data_Namespace::GPU_LEVEL);
52 #else
54 #endif // HAVE_CUDA
55  if (values.empty()) {
56  return;
57  }
58  min_val_ = std::numeric_limits<int64_t>::max();
59  max_val_ = std::numeric_limits<int64_t>::min();
60  for (const auto value : values) {
61  if (value == null_val) {
62  rhs_has_null_ = true;
63  continue;
64  }
65  if (value < min_val_) {
66  min_val_ = value;
67  }
68  if (value > max_val_) {
69  max_val_ = value;
70  }
71  }
72  if (max_val_ < min_val_) {
73  CHECK_EQ(std::numeric_limits<int64_t>::max(), min_val_);
74  CHECK_EQ(std::numeric_limits<int64_t>::min(), max_val_);
76  return;
77  }
78  const int64_t MAX_BITMAP_BITS{8 * 1000 * 1000 * 1000L};
79  const auto bitmap_sz_bits =
80  static_cast<int64_t>(checked_int64_t(max_val_) - min_val_ + 1);
81  if (bitmap_sz_bits > MAX_BITMAP_BITS) {
82  throw FailedToCreateBitmap();
83  }
84  const auto bitmap_sz_bytes = bitmap_bits_to_bytes(bitmap_sz_bits);
85  auto cpu_bitset = static_cast<int8_t*>(checked_calloc(bitmap_sz_bytes, 1));
86  for (const auto value : values) {
87  if (value == null_val) {
88  continue;
89  }
90  agg_count_distinct_bitmap(reinterpret_cast<int64_t*>(&cpu_bitset), value, min_val_);
91  }
92 #ifdef HAVE_CUDA
94  for (int device_id = 0; device_id < device_count_; ++device_id) {
95  gpu_buffers_.emplace_back(
96  CudaAllocator::allocGpuAbstractBuffer(data_mgr, bitmap_sz_bytes, device_id));
97  auto gpu_bitset = gpu_buffers_.back()->getMemoryPtr();
98  copy_to_gpu(data_mgr,
99  reinterpret_cast<CUdeviceptr>(gpu_bitset),
100  cpu_bitset,
101  bitmap_sz_bytes,
102  device_id);
103  bitsets_.push_back(gpu_bitset);
104  }
105  free(cpu_bitset);
106  } else {
107  bitsets_.push_back(cpu_bitset);
108  }
109 #else
110  CHECK_EQ(1, device_count_);
111  bitsets_.push_back(cpu_bitset);
112 #endif // HAVE_CUDA
113 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void >> checked_int64_t
size_t bitmap_bits_to_bytes(const size_t bitmap_sz)
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:30
std::vector< int8_t * > bitsets_
std::vector< Data_Namespace::AbstractBuffer * > gpu_buffers_
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:52
const int64_t null_val_
Data_Namespace::DataMgr * data_mgr_
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
const int device_count_
#define CHECK(condition)
Definition: Logger.h:197
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 ( )

Definition at line 115 of file InValuesBitmap.cpp.

References bitsets_, CHECK, CHECK_EQ, Data_Namespace::CPU_LEVEL, data_mgr_, Data_Namespace::DataMgr::free(), gpu_buffers_, and memory_level_.

115  {
116  if (bitsets_.empty()) {
117  return;
118  }
120  CHECK_EQ(size_t(1), bitsets_.size());
121  free(bitsets_.front());
122  } else {
123  CHECK(data_mgr_);
124  for (auto& gpu_buffer : gpu_buffers_) {
125  data_mgr_->free(gpu_buffer);
126  }
127  }
128 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::vector< int8_t * > bitsets_
std::vector< Data_Namespace::AbstractBuffer * > gpu_buffers_
Data_Namespace::DataMgr * data_mgr_
#define CHECK(condition)
Definition: Logger.h:197
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:461
const Data_Namespace::MemoryLevel memory_level_

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 130 of file InValuesBitmap.cpp.

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

Referenced by CodeGenerator::codegen().

130  {
131  AUTOMATIC_IR_METADATA(executor->cgen_state_.get());
132  std::vector<std::shared_ptr<const Analyzer::Constant>> constants_owned;
133  std::vector<const Analyzer::Constant*> constants;
134  for (const auto bitset : bitsets_) {
135  const int64_t bitset_handle = reinterpret_cast<int64_t>(bitset);
136  const auto bitset_handle_literal = std::dynamic_pointer_cast<Analyzer::Constant>(
137  Parser::IntLiteral::analyzeValue(bitset_handle));
138  CHECK(bitset_handle_literal);
139  CHECK_EQ(kENCODING_NONE, bitset_handle_literal->get_type_info().get_compression());
140  constants_owned.push_back(bitset_handle_literal);
141  constants.push_back(bitset_handle_literal.get());
142  }
143  const auto needle_i64 = executor->cgen_state_->castToTypeIn(needle, 64);
144  const auto null_bool_val =
145  static_cast<int8_t>(inline_int_null_val(SQLTypeInfo(kBOOLEAN, false)));
146  if (bitsets_.empty()) {
147  return executor->cgen_state_->emitCall("bit_is_set",
148  {executor->cgen_state_->llInt(int64_t(0)),
149  needle_i64,
150  executor->cgen_state_->llInt(int64_t(0)),
151  executor->cgen_state_->llInt(int64_t(0)),
152  executor->cgen_state_->llInt(null_val_),
153  executor->cgen_state_->llInt(null_bool_val)});
154  }
155  CodeGenerator code_generator(executor);
156  const auto bitset_handle_lvs =
157  code_generator.codegenHoistedConstants(constants, kENCODING_NONE, 0);
158  CHECK_EQ(size_t(1), bitset_handle_lvs.size());
159  return executor->cgen_state_->emitCall(
160  "bit_is_set",
161  {executor->cgen_state_->castToTypeIn(bitset_handle_lvs.front(), 64),
162  needle_i64,
163  executor->cgen_state_->llInt(min_val_),
164  executor->cgen_state_->llInt(max_val_),
165  executor->cgen_state_->llInt(null_val_),
166  executor->cgen_state_->llInt(null_bool_val)});
167 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
static std::shared_ptr< Analyzer::Expr > analyzeValue(const int64_t intval)
Definition: ParserNode.cpp:115
std::vector< int8_t * > bitsets_
#define AUTOMATIC_IR_METADATA(CGENSTATE)
const int64_t null_val_
#define CHECK(condition)
Definition: Logger.h:197
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:

size_t InValuesBitmap::gpuBuffers ( ) const
inline

Definition at line 57 of file InValuesBitmap.h.

References gpu_buffers_.

57 { return gpu_buffers_.size(); }
std::vector< Data_Namespace::AbstractBuffer * > gpu_buffers_
bool InValuesBitmap::hasNull ( ) const

Definition at line 173 of file InValuesBitmap.cpp.

References rhs_has_null_.

173  {
174  return rhs_has_null_;
175 }
bool InValuesBitmap::isEmpty ( ) const

Definition at line 169 of file InValuesBitmap.cpp.

References bitsets_.

169  {
170  return bitsets_.empty();
171 }
std::vector< int8_t * > bitsets_

Member Data Documentation

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

Definition at line 61 of file InValuesBitmap.h.

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

Data_Namespace::DataMgr* InValuesBitmap::data_mgr_
private

Definition at line 68 of file InValuesBitmap.h.

Referenced by ~InValuesBitmap().

const int InValuesBitmap::device_count_
private

Definition at line 67 of file InValuesBitmap.h.

Referenced by InValuesBitmap().

std::vector<Data_Namespace::AbstractBuffer*> InValuesBitmap::gpu_buffers_
private

Definition at line 60 of file InValuesBitmap.h.

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

int64_t InValuesBitmap::max_val_
private

Definition at line 64 of file InValuesBitmap.h.

Referenced by codegen(), and InValuesBitmap().

const Data_Namespace::MemoryLevel InValuesBitmap::memory_level_
private

Definition at line 66 of file InValuesBitmap.h.

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

int64_t InValuesBitmap::min_val_
private

Definition at line 63 of file InValuesBitmap.h.

Referenced by codegen(), and InValuesBitmap().

const int64_t InValuesBitmap::null_val_
private

Definition at line 65 of file InValuesBitmap.h.

Referenced by codegen().

bool InValuesBitmap::rhs_has_null_
private

Definition at line 62 of file InValuesBitmap.h.

Referenced by hasNull(), and InValuesBitmap().


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