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

#include <StringDictionaryTranslationMgr.h>

+ Collaboration diagram for StringDictionaryTranslationMgr:

Public Member Functions

 StringDictionaryTranslationMgr (const int32_t source_string_dict_id, const int32_t dest_string_dict_id, const bool translate_intersection_only, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, const Data_Namespace::MemoryLevel memory_level, const int device_count, Executor *executor, Data_Namespace::DataMgr *data_mgr, const bool delay_translation)
 
 ~StringDictionaryTranslationMgr ()
 
void buildTranslationMap ()
 
void createKernelBuffers ()
 
llvm::Value * codegen (llvm::Value *str_id_input, const SQLTypeInfo &input_ti, const bool add_nullcheck, const CompilationOptions &co) const
 
bool isMapValid () const
 
const int32_t * data () const
 
int32_t minSourceStringId () const
 

Private Attributes

const int32_t source_string_dict_id_
 
const int32_t dest_string_dict_id_
 
const bool translate_intersection_only_
 
const std::vector
< StringOps_Namespace::StringOpInfo
string_op_infos_
 
const bool has_null_string_op_
 
const Data_Namespace::MemoryLevel memory_level_
 
const int device_count_
 
Executorexecutor_
 
Data_Namespace::DataMgrdata_mgr_
 
const
StringDictionaryProxy::IdMap
*host_translation_map_ 
nullptr
 
std::vector< const int32_t * > kernel_translation_maps_
 
std::vector
< Data_Namespace::AbstractBuffer * > 
device_buffers_
 

Detailed Description

Definition at line 47 of file StringDictionaryTranslationMgr.h.

Constructor & Destructor Documentation

StringDictionaryTranslationMgr::StringDictionaryTranslationMgr ( const int32_t  source_string_dict_id,
const int32_t  dest_string_dict_id,
const bool  translate_intersection_only,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos,
const Data_Namespace::MemoryLevel  memory_level,
const int  device_count,
Executor executor,
Data_Namespace::DataMgr data_mgr,
const bool  delay_translation 
)

Definition at line 50 of file StringDictionaryTranslationMgr.cpp.

References buildTranslationMap(), CHECK, CHECK_EQ, Data_Namespace::CPU_LEVEL, createKernelBuffers(), Data_Namespace::GPU_LEVEL, has_null_string_op_, and memory_level_.

60  : source_string_dict_id_(source_string_dict_id)
61  , dest_string_dict_id_(dest_string_dict_id)
62  , translate_intersection_only_(translate_intersection_only)
63  , string_op_infos_(string_op_infos)
65  , memory_level_(memory_level)
66  , device_count_(device_count)
67  , executor_(executor)
68  , data_mgr_(data_mgr) {
69 #ifdef HAVE_CUDA
71  memory_level == Data_Namespace::GPU_LEVEL);
72 #else
74 #endif // HAVE_CUDA
75  if (!delay_translation && !has_null_string_op_) {
78  }
79 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const Data_Namespace::MemoryLevel memory_level_
bool one_or_more_string_ops_is_null(const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos)
#define CHECK(condition)
Definition: Logger.h:222
const std::vector< StringOps_Namespace::StringOpInfo > string_op_infos_

+ Here is the call graph for this function:

StringDictionaryTranslationMgr::~StringDictionaryTranslationMgr ( )

Definition at line 81 of file StringDictionaryTranslationMgr.cpp.

References CHECK, data_mgr_, device_buffers_, and Data_Namespace::DataMgr::free().

81  {
83  for (auto& device_buffer : device_buffers_) {
84  data_mgr_->free(device_buffer);
85  }
86 }
#define CHECK(condition)
Definition: Logger.h:222
std::vector< Data_Namespace::AbstractBuffer * > device_buffers_
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:528

+ Here is the call graph for this function:

Member Function Documentation

void StringDictionaryTranslationMgr::buildTranslationMap ( )

Definition at line 88 of file StringDictionaryTranslationMgr.cpp.

References dest_string_dict_id_, executor_, RowSetMemoryOwner::SOURCE_INTERSECTION, source_string_dict_id_, RowSetMemoryOwner::SOURCE_UNION, string_op_infos_, and translate_intersection_only_.

Referenced by StringDictionaryTranslationMgr().

+ Here is the caller graph for this function:

llvm::Value * StringDictionaryTranslationMgr::codegen ( llvm::Value *  str_id_input,
const SQLTypeInfo input_ti,
const bool  add_nullcheck,
const CompilationOptions co 
) const

Definition at line 126 of file StringDictionaryTranslationMgr.cpp.

References Parser::IntLiteral::analyzeValue(), AUTOMATIC_IR_METADATA, CHECK, CHECK_EQ, CHECK_GE, device_count_, CompilationOptions::device_type, executor_, SQLTypeInfo::get_notnull(), GPU, Data_Namespace::GPU_LEVEL, has_null_string_op_, CompilationOptions::hoist_literals, kENCODING_DICT, kENCODING_NONE, kernel_translation_maps_, kTEXT, memory_level_, and minSourceStringId().

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenCastFromString(), and CodeGenerator::codegenPseudoStringOper().

129  {
130  CHECK(kernel_translation_maps_.size() == static_cast<size_t>(device_count_) ||
132  if (!co.hoist_literals && kernel_translation_maps_.size() > 1UL) {
133  // Currently the only way to have multiple kernel translation maps is
134  // to be running on GPU, where we would need to have a different pointer
135  // per GPU to the translation map, as the address space is not shared
136  // between GPUs
137 
140 
141  // Since we currently cannot support different code per device, the only
142  // way to allow for a different kernel translation map/kernel per
143  // device(i.e. GPU) is via hoisting the map handle literal so that
144  // it can be paramertized as a kernel argument. Hence if literal
145  // hoisting is disabled (generally b/c we have an update query),
146  // the surest fire way of ensuring one and only one translation map
147  // that can have a hard-coded handle in the generated code is by running
148  // on CPU (which per the comment above currently always has a device
149  // count of 1).
150 
151  // This is not currently a major limitation as we currently run
152  // all update queries on CPU, but it would be if we want to run
153  // on multiple GPUs.
154 
155  // Todo(todd): Examine ways around the above limitation, likely either
156  // a dedicated kernel parameter for translation maps (like we have for
157  // join hash tables), or perhaps better for a number of reasons, reworking
158  // the translation map plumbing to use the join infra (which would also
159  // mean we could use pieces like the baseline hash join for multiple
160  // input string dictionaries, i.e. CONCAT on two string columns).
161 
162  throw QueryMustRunOnCpu();
163  }
164  CHECK(co.hoist_literals || kernel_translation_maps_.size() == 1UL);
165 
166  auto cgen_state_ptr = executor_->getCgenStatePtr();
167  AUTOMATIC_IR_METADATA(cgen_state_ptr);
168 
169  if (has_null_string_op_) {
170  // If any of the string ops can statically be determined to output all nulls
171  // (currently determined by whether any of the constant literal inputs to the
172  // string operation are null), then simply generate codegen a null
173  // dictionary-encoded value
174  const auto null_ti = SQLTypeInfo(kTEXT, true /* is_nullable */, kENCODING_DICT);
175  return static_cast<llvm::Value*>(executor_->cgen_state_->inlineIntNull(null_ti));
176  }
177 
178  std::vector<std::shared_ptr<const Analyzer::Constant>> constants_owned;
179  std::vector<const Analyzer::Constant*> constants;
180  for (const auto kernel_translation_map : kernel_translation_maps_) {
181  const int64_t translation_map_handle =
182  reinterpret_cast<int64_t>(kernel_translation_map);
183  const auto translation_map_handle_literal =
184  std::dynamic_pointer_cast<Analyzer::Constant>(
185  Parser::IntLiteral::analyzeValue(translation_map_handle));
186  CHECK(translation_map_handle_literal);
188  translation_map_handle_literal->get_type_info().get_compression());
189  constants_owned.push_back(translation_map_handle_literal);
190  constants.push_back(translation_map_handle_literal.get());
191  }
192  CHECK_GE(constants.size(), 1UL);
193  CHECK(co.hoist_literals || constants.size() == 1UL);
194 
195  CodeGenerator code_generator(executor_);
196 
197  const auto translation_map_handle_lvs =
198  co.hoist_literals
199  ? code_generator.codegenHoistedConstants(constants, kENCODING_NONE, 0)
200  : code_generator.codegen(constants[0], false, co);
201  CHECK_EQ(size_t(1), translation_map_handle_lvs.size());
202 
203  std::unique_ptr<CodeGenerator::NullCheckCodegen> nullcheck_codegen;
204  const bool is_nullable = !input_ti.get_notnull();
205  const auto decoded_input_ti = SQLTypeInfo(kTEXT, is_nullable, kENCODING_DICT);
206  if (add_nullcheck && is_nullable) {
207  nullcheck_codegen = std::make_unique<CodeGenerator::NullCheckCodegen>(
208  cgen_state_ptr,
209  executor_,
210  input_str_id_lv,
211  decoded_input_ti,
212  "dict_encoded_str_cast_nullcheck");
213  }
214  llvm::Value* ret = cgen_state_ptr->emitCall(
215  "map_string_dict_id",
216  {input_str_id_lv,
217  cgen_state_ptr->castToTypeIn(translation_map_handle_lvs.front(), 64),
218  cgen_state_ptr->llInt(minSourceStringId())});
219 
220  if (nullcheck_codegen) {
221  ret =
222  nullcheck_codegen->finalize(cgen_state_ptr->inlineIntNull(decoded_input_ti), ret);
223  }
224  return ret;
225 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const Data_Namespace::MemoryLevel memory_level_
static std::shared_ptr< Analyzer::Expr > analyzeValue(const int64_t intval)
Definition: ParserNode.cpp:161
#define CHECK_GE(x, y)
Definition: Logger.h:235
#define AUTOMATIC_IR_METADATA(CGENSTATE)
ExecutorDeviceType device_type
std::vector< const int32_t * > kernel_translation_maps_
Definition: sqltypes.h:52
#define CHECK(condition)
Definition: Logger.h:222
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void StringDictionaryTranslationMgr::createKernelBuffers ( )

Definition at line 100 of file StringDictionaryTranslationMgr.cpp.

References CudaAllocator::allocGpuAbstractBuffer(), CHECK_EQ, copy_to_nvidia_gpu(), Data_Namespace::CPU_LEVEL, data_mgr_, device_buffers_, device_count_, Data_Namespace::GPU_LEVEL, kernel_translation_maps_, and memory_level_.

Referenced by StringDictionaryTranslationMgr().

100  {
101 #ifdef HAVE_CUDA
103  const size_t translation_map_size_bytes{host_translation_map_->getVectorMap().size() *
104  sizeof(int32_t)};
105  for (int device_id = 0; device_id < device_count_; ++device_id) {
107  data_mgr_, translation_map_size_bytes, device_id));
108  auto device_buffer =
109  reinterpret_cast<int32_t*>(device_buffers_.back()->getMemoryPtr());
111  reinterpret_cast<CUdeviceptr>(device_buffer),
112  host_translation_map_->data(),
113  translation_map_size_bytes,
114  device_id);
115  kernel_translation_maps_.push_back(device_buffer);
116  }
117  }
118 #else
119  CHECK_EQ(1, device_count_);
120 #endif // HAVE_CUDA
122  kernel_translation_maps_.push_back(host_translation_map_->data());
123  }
124 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const Data_Namespace::MemoryLevel memory_level_
std::vector< const int32_t * > kernel_translation_maps_
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
void copy_to_nvidia_gpu(Data_Namespace::DataMgr *data_mgr, CUdeviceptr dst, const void *src, const size_t num_bytes, const int device_id)
Definition: GpuMemUtils.cpp:35
std::vector< Data_Namespace::AbstractBuffer * > device_buffers_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int32_t * StringDictionaryTranslationMgr::data ( ) const

Definition at line 231 of file StringDictionaryTranslationMgr.cpp.

References isMapValid().

231  {
232  return isMapValid() ? host_translation_map_->data() : nullptr;
233 }

+ Here is the call graph for this function:

bool StringDictionaryTranslationMgr::isMapValid ( ) const

Definition at line 227 of file StringDictionaryTranslationMgr.cpp.

Referenced by data(), and minSourceStringId().

227  {
228  return host_translation_map_ && !host_translation_map_->empty();
229 }

+ Here is the caller graph for this function:

int32_t StringDictionaryTranslationMgr::minSourceStringId ( ) const

Definition at line 235 of file StringDictionaryTranslationMgr.cpp.

References isMapValid().

Referenced by codegen().

235  {
236  return isMapValid() ? host_translation_map_->domainStart() : 0;
237 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Data_Namespace::DataMgr* StringDictionaryTranslationMgr::data_mgr_
private
const int32_t StringDictionaryTranslationMgr::dest_string_dict_id_
private

Definition at line 74 of file StringDictionaryTranslationMgr.h.

Referenced by buildTranslationMap().

std::vector<Data_Namespace::AbstractBuffer*> StringDictionaryTranslationMgr::device_buffers_
private
const int StringDictionaryTranslationMgr::device_count_
private

Definition at line 79 of file StringDictionaryTranslationMgr.h.

Referenced by codegen(), and createKernelBuffers().

Executor* StringDictionaryTranslationMgr::executor_
private

Definition at line 80 of file StringDictionaryTranslationMgr.h.

Referenced by buildTranslationMap(), and codegen().

const bool StringDictionaryTranslationMgr::has_null_string_op_
private

Definition at line 77 of file StringDictionaryTranslationMgr.h.

Referenced by codegen(), and StringDictionaryTranslationMgr().

std::vector<const int32_t*> StringDictionaryTranslationMgr::kernel_translation_maps_
private

Definition at line 83 of file StringDictionaryTranslationMgr.h.

Referenced by codegen(), and createKernelBuffers().

const Data_Namespace::MemoryLevel StringDictionaryTranslationMgr::memory_level_
private
const StringDictionaryProxy::IdMap* host_translation_map_ StringDictionaryTranslationMgr::nullptr
private

Definition at line 82 of file StringDictionaryTranslationMgr.h.

const int32_t StringDictionaryTranslationMgr::source_string_dict_id_
private

Definition at line 73 of file StringDictionaryTranslationMgr.h.

Referenced by buildTranslationMap().

const std::vector<StringOps_Namespace::StringOpInfo> StringDictionaryTranslationMgr::string_op_infos_
private

Definition at line 76 of file StringDictionaryTranslationMgr.h.

Referenced by buildTranslationMap().

const bool StringDictionaryTranslationMgr::translate_intersection_only_
private

Definition at line 75 of file StringDictionaryTranslationMgr.h.

Referenced by buildTranslationMap().


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