Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 11, 2022
1 parent 9b4a451 commit 1e8b0f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions taichi/codegen/llvm/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,11 @@ void CodeGenLLVM::visit(GlobalStoreStmt *stmt) {
auto ptr_type = stmt->dest->ret_type->as<PointerType>();
if (ptr_type->is_bit_pointer()) {
auto pointee_type = ptr_type->get_pointee_type();
if (stmt->dest->as<GetChStmt>()->input_snode->type == SNodeType::bit_struct) {
if (stmt->dest->as<GetChStmt>()->input_snode->type ==
SNodeType::bit_struct) {
TI_ERROR(
"Bit struct stores with type {} should have been handled by BitStructStoreStmt.",
"Bit struct stores with type {} should have been handled by "
"BitStructStoreStmt.",
pointee_type->to_string());
}
if (auto qit = pointee_type->cast<QuantIntType>()) {
Expand Down
9 changes: 6 additions & 3 deletions taichi/codegen/llvm/codegen_llvm_quant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ llvm::Value *CodeGenLLVM::atomic_add_quant_fixed(AtomicOpStmt *stmt,
tlctx->get_constant(qit->get_num_bits()), val_store});
}

llvm::Value *CodeGenLLVM::to_quant_fixed(llvm::Value *real, QuantFixedType *qfxt) {
llvm::Value *CodeGenLLVM::to_quant_fixed(llvm::Value *real,
QuantFixedType *qfxt) {
// Compute int(real * (1.0 / scale) + 0.5)
auto compute_type = qfxt->get_compute_type();
auto s = builder->CreateFPCast(tlctx->get_constant(1.0 / qfxt->get_scale()), llvm_type(compute_type));
auto s = builder->CreateFPCast(tlctx->get_constant(1.0 / qfxt->get_scale()),
llvm_type(compute_type));
auto input_real = builder->CreateFPCast(real, llvm_type(compute_type));
auto scaled = builder->CreateFMul(input_real, s);

Expand Down Expand Up @@ -80,7 +82,8 @@ void CodeGenLLVM::store_quant_fixed(llvm::Value *bit_ptr,
QuantFixedType *qfxt,
llvm::Value *value,
bool atomic) {
store_quant_int(bit_ptr, qfxt->get_digits_type()->as<QuantIntType>(), to_quant_fixed(value, qfxt), atomic);
store_quant_int(bit_ptr, qfxt->get_digits_type()->as<QuantIntType>(),
to_quant_fixed(value, qfxt), atomic);
}

void CodeGenLLVM::store_masked(llvm::Value *byte_ptr,
Expand Down
3 changes: 2 additions & 1 deletion taichi/ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ class QuantArrayType : public Type {
if (auto qit = element_type_->cast<QuantIntType>()) {
element_num_bits_ = qit->get_num_bits();
} else if (auto qfxt = element_type_->cast<QuantFixedType>()) {
element_num_bits_ = qfxt->get_digits_type()->as<QuantIntType>()->get_num_bits();
element_num_bits_ =
qfxt->get_digits_type()->as<QuantIntType>()->get_num_bits();
} else {
TI_ERROR("Quant array only supports quant int/fixed type for now.");
}
Expand Down

0 comments on commit 1e8b0f3

Please sign in to comment.