OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Codec.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "Codec.h"
18 #include "LLVMGlobalContext.h"
19 #include "Logger/Logger.h"
20 
21 #include <llvm/IR/Constants.h>
22 #include <llvm/IR/Instruction.h>
23 #include <llvm/IR/Module.h>
24 #include <llvm/IR/Value.h>
25 
26 FixedWidthInt::FixedWidthInt(const size_t byte_width) : byte_width_{byte_width} {}
27 
28 llvm::Instruction* FixedWidthInt::codegenDecode(llvm::Value* byte_stream,
29  llvm::Value* pos,
30  llvm::Module* llvm_module) const {
31  auto& context = llvm_module->getContext();
32  auto f = llvm_module->getFunction("fixed_width_int_decode");
33  CHECK(f);
34  llvm::Value* args[] = {
35  byte_stream,
36  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
37  pos};
38  return llvm::CallInst::Create(f, args);
39 }
40 
42  : byte_width_{byte_width} {}
43 
44 llvm::Instruction* FixedWidthUnsigned::codegenDecode(llvm::Value* byte_stream,
45  llvm::Value* pos,
46  llvm::Module* llvm_module) const {
47  auto& context = llvm_module->getContext();
48  auto f = llvm_module->getFunction("fixed_width_unsigned_decode");
49  CHECK(f);
50  llvm::Value* args[] = {
51  byte_stream,
52  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
53  pos};
54  return llvm::CallInst::Create(f, args);
55 }
56 
57 DiffFixedWidthInt::DiffFixedWidthInt(const size_t byte_width, const int64_t baseline)
58  : byte_width_{byte_width}, baseline_{baseline} {}
59 
60 llvm::Instruction* DiffFixedWidthInt::codegenDecode(llvm::Value* byte_stream,
61  llvm::Value* pos,
62  llvm::Module* llvm_module) const {
63  auto& context = llvm_module->getContext();
64  auto f = llvm_module->getFunction("diff_fixed_width_int_decode");
65  CHECK(f);
66  llvm::Value* args[] = {
67  byte_stream,
68  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
69  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), baseline_),
70  pos};
71  return llvm::CallInst::Create(f, args);
72 }
73 
74 FixedWidthReal::FixedWidthReal(const bool is_double) : is_double_(is_double) {}
75 
76 llvm::Instruction* FixedWidthReal::codegenDecode(llvm::Value* byte_stream,
77  llvm::Value* pos,
78  llvm::Module* llvm_module) const {
79  auto f = llvm_module->getFunction(is_double_ ? "fixed_width_double_decode"
80  : "fixed_width_float_decode");
81  CHECK(f);
82  llvm::Value* args[] = {byte_stream, pos};
83  return llvm::CallInst::Create(f, args);
84 }
85 
87  : byte_width_{byte_width}, null_val_{byte_width == 4 ? NULL_INT : NULL_SMALLINT} {}
88 
89 llvm::Instruction* FixedWidthSmallDate::codegenDecode(llvm::Value* byte_stream,
90  llvm::Value* pos,
91  llvm::Module* llvm_module) const {
92  auto& context = llvm_module->getContext();
93  auto f = llvm_module->getFunction("fixed_width_small_date_decode");
94  CHECK(f);
95  llvm::Value* args[] = {
96  byte_stream,
97  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
98  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), null_val_),
99  llvm::ConstantInt::get(llvm::Type::getInt64Ty(context), ret_null_val_),
100  pos};
101  return llvm::CallInst::Create(f, args);
102 }
FixedWidthUnsigned(const size_t byte_width)
Definition: Codec.cpp:41
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *llvm_module) const override
Definition: Codec.cpp:28
const size_t byte_width_
Definition: Codec.h:42
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *llvm_module) const override
Definition: Codec.cpp:44
FixedWidthSmallDate(const size_t byte_width)
Definition: Codec.cpp:86
FixedWidthReal(const bool is_double)
Definition: Codec.cpp:74
DiffFixedWidthInt(const size_t byte_width, const int64_t baseline)
Definition: Codec.cpp:57
#define NULL_INT
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *llvm_module) const override
Definition: Codec.cpp:76
FixedWidthInt(const size_t byte_width)
Definition: Codec.cpp:26
const int64_t baseline_
Definition: Codec.h:65
const int32_t null_val_
Definition: Codec.h:88
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *llvm_module) const override
Definition: Codec.cpp:60
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *llvm_module) const override
Definition: Codec.cpp:89
const size_t byte_width_
Definition: Codec.h:53
const bool is_double_
Definition: Codec.h:76
static constexpr int64_t ret_null_val_
Definition: Codec.h:89
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
const size_t byte_width_
Definition: Codec.h:64
#define CHECK(condition)
Definition: Logger.h:291
#define NULL_SMALLINT
const size_t byte_width_
Definition: Codec.h:87