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

#include <InValuesBitmap.h>

+ Collaboration diagram for InValuesBitmap:

Classes

struct  BitIsSetParams
 

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, CompilationOptions const &co)
 
 ~InValuesBitmap ()
 
llvm::Value * codegen (llvm::Value *needle, Executor *executor) const
 
bool isEmpty () const
 
bool hasNull () const
 
size_t gpuBuffers () const
 
BitIsSetParams prepareBitIsSetParams (Executor *executor, std::vector< std::shared_ptr< const Analyzer::Constant >> const &constant_owned) 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_
 
CompilationOptions co_
 

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,
CompilationOptions const &  co 
)

Definition at line 35 of file InValuesBitmap.cpp.

References agg_count_distinct_bitmap(), Data_Namespace::DataMgr::alloc(), bitsets_, CHECK, CHECK_EQ, checked_calloc(), Data_Namespace::CPU_LEVEL, data_mgr_, device_count_, g_bitmap_memory_limit, getQueryEngineCudaStreamForDevice(), gpu_buffers_, Data_Namespace::GPU_LEVEL, max_val_, memory_level_, min_val_, and rhs_has_null_.

41  : rhs_has_null_(false)
42  , null_val_(null_val)
43  , memory_level_(memory_level)
44  , device_count_(device_count)
45  , data_mgr_(data_mgr)
46  , co_(co) {
47 #ifdef HAVE_CUDA
49  memory_level == Data_Namespace::GPU_LEVEL);
50 #else
52 #endif // HAVE_CUDA
53  if (values.empty()) {
54  return;
55  }
56  min_val_ = std::numeric_limits<int64_t>::max();
57  max_val_ = std::numeric_limits<int64_t>::min();
58  for (const auto value : values) {
59  if (value == null_val) {
60  rhs_has_null_ = true;
61  continue;
62  }
63  if (value < min_val_) {
64  min_val_ = value;
65  }
66  if (value > max_val_) {
67  max_val_ = value;
68  }
69  }
70  if (max_val_ < min_val_) {
71  CHECK_EQ(std::numeric_limits<int64_t>::max(), min_val_);
72  CHECK_EQ(std::numeric_limits<int64_t>::min(), max_val_);
74  return;
75  }
76  uint64_t const bitmap_sz_bits_minus_one = max_val_ - min_val_;
77  if (static_cast<uint64_t>(g_bitmap_memory_limit) <= bitmap_sz_bits_minus_one) {
78  throw FailedToCreateBitmap();
79  }
80  // bitmap_sz_bytes = ceil(bitmap_sz_bits / 8.0) = (bitmap_sz_bits-1) / 8 + 1
81  uint64_t const bitmap_sz_bytes = bitmap_sz_bits_minus_one / 8 + 1;
82  auto cpu_bitset = static_cast<int8_t*>(checked_calloc(bitmap_sz_bytes, 1));
83  for (const auto value : values) {
84  if (value == null_val) {
85  continue;
86  }
88  reinterpret_cast<int64_t*>(&cpu_bitset), value, min_val_, 0);
89  }
90 #ifdef HAVE_CUDA
92  for (int device_id = 0; device_id < device_count_; ++device_id) {
93  auto device_allocator = std::make_unique<CudaAllocator>(
94  data_mgr_, device_id, getQueryEngineCudaStreamForDevice(device_id));
95  gpu_buffers_.emplace_back(
96  data_mgr->alloc(Data_Namespace::GPU_LEVEL, device_id, bitmap_sz_bytes));
97  auto gpu_bitset = gpu_buffers_.back()->getMemoryPtr();
98  device_allocator->copyToDevice(gpu_bitset, cpu_bitset, bitmap_sz_bytes);
99  bitsets_.push_back(gpu_bitset);
100  }
101  free(cpu_bitset);
102  } else {
103  bitsets_.push_back(cpu_bitset);
104  }
105 #else
106  CHECK_EQ(1, device_count_);
107  bitsets_.push_back(cpu_bitset);
108 #endif // HAVE_CUDA
109 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
CompilationOptions co_
RUNTIME_EXPORT ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val, const int64_t bucket_size)
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:53
int64_t g_bitmap_memory_limit
const int64_t null_val_
Data_Namespace::DataMgr * data_mgr_
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
const int device_count_
#define CHECK(condition)
Definition: Logger.h:291
AbstractBuffer * alloc(const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
Definition: DataMgr.cpp:605
const Data_Namespace::MemoryLevel memory_level_

+ Here is the call graph for this function:

InValuesBitmap::~InValuesBitmap ( )

Definition at line 111 of file InValuesBitmap.cpp.

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

111  {
112  if (bitsets_.empty()) {
113  return;
114  }
116  CHECK_EQ(size_t(1), bitsets_.size());
117  free(bitsets_.front());
118  } else {
119  CHECK(data_mgr_);
120  for (auto& gpu_buffer : gpu_buffers_) {
121  data_mgr_->free(gpu_buffer);
122  }
123  }
124 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< int8_t * > bitsets_
std::vector< Data_Namespace::AbstractBuffer * > gpu_buffers_
Data_Namespace::DataMgr * data_mgr_
#define CHECK(condition)
Definition: Logger.h:291
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:614
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 166 of file InValuesBitmap.cpp.

References Parser::IntLiteral::analyzeValue(), AUTOMATIC_IR_METADATA, bitsets_, CHECK, CHECK_EQ, inline_int_null_val(), kBOOLEAN, kENCODING_NONE, and prepareBitIsSetParams().

Referenced by CodeGenerator::codegen().

166  {
167  auto cgen_state = executor->getCgenStatePtr();
168  AUTOMATIC_IR_METADATA(cgen_state);
169  std::vector<std::shared_ptr<const Analyzer::Constant>> constants_owned;
170  for (const auto bitset : bitsets_) {
171  const int64_t bitset_handle = reinterpret_cast<int64_t>(bitset);
172  const auto bitset_handle_literal = std::dynamic_pointer_cast<Analyzer::Constant>(
173  Parser::IntLiteral::analyzeValue(bitset_handle));
174  CHECK(bitset_handle_literal);
175  CHECK_EQ(kENCODING_NONE, bitset_handle_literal->get_type_info().get_compression());
176  constants_owned.push_back(bitset_handle_literal);
177  }
178  const auto needle_i64 = cgen_state->castToTypeIn(needle, 64);
179  const auto null_bool_val =
180  static_cast<int8_t>(inline_int_null_val(SQLTypeInfo(kBOOLEAN, false)));
181  auto const func_params = prepareBitIsSetParams(executor, constants_owned);
182  return cgen_state->emitCall("bit_is_set",
183  {func_params.bitmap_ptr_lv,
184  needle_i64,
185  func_params.min_val_lv,
186  func_params.max_val_lv,
187  func_params.null_val_lv,
188  cgen_state->llInt(null_bool_val)});
189 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
BitIsSetParams prepareBitIsSetParams(Executor *executor, std::vector< std::shared_ptr< const Analyzer::Constant >> const &constant_owned) const
static std::shared_ptr< Analyzer::Expr > analyzeValue(const int64_t intval)
Definition: ParserNode.cpp:166
std::vector< int8_t * > bitsets_
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define CHECK(condition)
Definition: Logger.h:291
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 58 of file InValuesBitmap.h.

References gpu_buffers_.

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

Definition at line 195 of file InValuesBitmap.cpp.

References rhs_has_null_.

195  {
196  return rhs_has_null_;
197 }
bool InValuesBitmap::isEmpty ( ) const

Definition at line 191 of file InValuesBitmap.cpp.

References bitsets_.

191  {
192  return bitsets_.empty();
193 }
std::vector< int8_t * > bitsets_
InValuesBitmap::BitIsSetParams InValuesBitmap::prepareBitIsSetParams ( Executor executor,
std::vector< std::shared_ptr< const Analyzer::Constant >> const &  constant_owned 
) const

Definition at line 126 of file InValuesBitmap.cpp.

References InValuesBitmap::BitIsSetParams::bitmap_ptr_lv, bitsets_, CHECK_EQ, co_, CodeGenerator::codegenHoistedConstants(), device_count_, get_int_type(), CodegenUtil::hoistLiteral(), kBIGINT, kENCODING_NONE, max_val_, InValuesBitmap::BitIsSetParams::max_val_lv, min_val_, InValuesBitmap::BitIsSetParams::min_val_lv, null_val_, InValuesBitmap::BitIsSetParams::null_val_lv, and report::params.

Referenced by codegen().

128  {
129  BitIsSetParams params;
130  auto pi8_ty =
131  llvm::PointerType::get(get_int_type(8, executor->cgen_state_->context_), 0);
132  CodeGenerator code_generator(executor);
133  params.null_val_lv =
135  &code_generator, co_, make_datum<int64_t>(null_val_), kBIGINT, device_count_)
136  .front();
137  if (bitsets_.empty()) {
138  auto const zero_lvs = CodegenUtil::hoistLiteral(
139  &code_generator, co_, make_datum<int64_t>(0), kBIGINT, device_count_);
140  params.min_val_lv = zero_lvs.front();
141  params.max_val_lv = zero_lvs.front();
142  params.bitmap_ptr_lv =
143  executor->cgen_state_->ir_builder_.CreateIntToPtr(zero_lvs.front(), pi8_ty);
144  } else {
145  params.min_val_lv =
147  &code_generator, co_, make_datum<int64_t>(min_val_), kBIGINT, device_count_)
148  .front();
149  params.max_val_lv =
151  &code_generator, co_, make_datum<int64_t>(max_val_), kBIGINT, device_count_)
152  .front();
153  auto to_raw_ptr = [](const auto& ptr) { return ptr.get(); };
154  auto begin = boost::make_transform_iterator(constant_owned.begin(), to_raw_ptr);
155  auto end = boost::make_transform_iterator(constant_owned.end(), to_raw_ptr);
156  std::vector<const Analyzer::Constant*> bitmap_constants(begin, end);
157  const auto bitset_handle_lvs =
158  code_generator.codegenHoistedConstants(bitmap_constants, kENCODING_NONE, {});
159  CHECK_EQ(size_t(1), bitset_handle_lvs.size());
160  params.bitmap_ptr_lv = executor->cgen_state_->ir_builder_.CreateIntToPtr(
161  bitset_handle_lvs.front(), pi8_ty);
162  }
163  return params;
164 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< llvm::Value * > hoistLiteral(CodeGenerator *code_generator, CompilationOptions const &co, Datum d, SQLTypeInfo type, size_t num_devices_to_hoist_literal)
CompilationOptions co_
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::vector< int8_t * > bitsets_
const int64_t null_val_
dictionary params
Definition: report.py:27
const int device_count_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 81 of file InValuesBitmap.h.

Referenced by prepareBitIsSetParams().

Data_Namespace::DataMgr* InValuesBitmap::data_mgr_
private

Definition at line 80 of file InValuesBitmap.h.

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

const int InValuesBitmap::device_count_
private

Definition at line 79 of file InValuesBitmap.h.

Referenced by InValuesBitmap(), and prepareBitIsSetParams().

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

Definition at line 72 of file InValuesBitmap.h.

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

int64_t InValuesBitmap::max_val_
private

Definition at line 76 of file InValuesBitmap.h.

Referenced by InValuesBitmap(), and prepareBitIsSetParams().

const Data_Namespace::MemoryLevel InValuesBitmap::memory_level_
private

Definition at line 78 of file InValuesBitmap.h.

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

int64_t InValuesBitmap::min_val_
private

Definition at line 75 of file InValuesBitmap.h.

Referenced by InValuesBitmap(), and prepareBitIsSetParams().

const int64_t InValuesBitmap::null_val_
private

Definition at line 77 of file InValuesBitmap.h.

Referenced by prepareBitIsSetParams().

bool InValuesBitmap::rhs_has_null_
private

Definition at line 74 of file InValuesBitmap.h.

Referenced by hasNull(), and InValuesBitmap().


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