Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type] Support SNode.cell_size_bytes #2142

Merged
merged 5 commits into from
Jan 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
.
yuanming-hu committed Jan 4, 2021
commit 91b015d856d8a85c3e40824af7d28a7229ac4ba9
10 changes: 6 additions & 4 deletions taichi/codegen/codegen_llvm.cpp
Original file line number Diff line number Diff line change
@@ -1055,6 +1055,7 @@ llvm::Value *CodeGenLLVM::atomic_add_custom_float(AtomicOpStmt *stmt,
auto cit = cft->get_digits_type()->as<CustomIntType>();
auto val_store = float_to_custom_int(cft, cit, llvm_val[stmt->val]);
auto physical_type = cit->get_physical_type();
val_store = builder->CreateSExt(val_store, llvm_type(physical_type));

return create_call(
fmt::format("atomic_add_partial_bits_b{}", data_type_bits(physical_type)),
@@ -2034,13 +2035,14 @@ void CodeGenLLVM::create_offload_struct_for(OffloadedStmt *stmt, bool spmd) {

llvm::Function *body = nullptr;
auto leaf_block = stmt->snode;

// When looping over bit_arrays and bit_structs, we generate struct for on
// their parent node (usually "dense") instead of itself for higher
// performance. Also, note that the loop must be bit_vectorized for
// bit_arrays.
if ((leaf_block->type == SNodeType::bit_array ||
leaf_block->type == SNodeType::bit_struct) &&
leaf_block->parent) {
// bit_arrays, and their parent must be "dense".
if (leaf_block->type == SNodeType::bit_struct) {
leaf_block = leaf_block->parent;
} else if (leaf_block->type == SNodeType::bit_array) {
if (leaf_block->parent->type == SNodeType::dense) {
leaf_block = leaf_block->parent;
} else {
4 changes: 4 additions & 0 deletions taichi/struct/struct_llvm.cpp
Original file line number Diff line number Diff line change
@@ -83,6 +83,10 @@ void StructCompilerLLVM::generate_types(SNode &snode) {
}
ch->bit_offset = total_offset;
total_offset += component_cit->get_num_bits();
auto bit_struct_size = data_type_bits(snode.physical_type);
TI_ERROR_IF(total_offset > bit_struct_size,
"Bit struct overflows: {} bits used out of {}.", total_offset,
bit_struct_size);
}

snode.dt = TypeFactory::get_instance().get_bit_struct_type(
13 changes: 13 additions & 0 deletions taichi/transforms/demote_atomics.cpp
Original file line number Diff line number Diff line change
@@ -62,6 +62,19 @@ class DemoteAtomics : public BasicStmtVisitor {
demote = true;
is_local = true;
}

if (auto dest_pointer_type = stmt->dest->ret_type->cast<PointerType>()) {
if (auto cft =
dest_pointer_type->get_pointee_type()->cast<CustomFloatType>()) {
if (cft->get_exponent_type()) {
TI_WARN(
"AtomicOp on CustomFloatType with exponent is not supported. "
"Demoting to non-atomic RMW.");
demote = true;
}
}
}

if (demote) {
// replace atomics with load, add, store
auto bin_type = atomic_to_binary_op_type(stmt->op_type);