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

[lang] Export a few types from the share library #5220

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/vulkan_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class VulkanResourceBinder : public ResourceBinder {
sizeof(VulkanResourceBinder::Binding) % sizeof(uint32_t) == 0,
"sizeof(VulkanResourceBinder::Binding) is not a multiple of 4");
size_t n = sizeof(VulkanResourceBinder::Binding) / sizeof(uint32_t);
for (int i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
binding_hash = binding_hash ^ u32_ptr[i];
binding_hash = (binding_hash << 7) | (binding_hash >> (64 - 7));
}
Expand Down
62 changes: 31 additions & 31 deletions taichi/ir/type_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,6 @@ std::string data_type_name(DataType t) {
TI_NOT_IMPLEMENTED
}

std::string data_type_format(DataType dt) {
if (dt->is_primitive(PrimitiveTypeID::i16)) {
return "%hd";
} else if (dt->is_primitive(PrimitiveTypeID::u16)) {
return "%hu";
} else if (dt->is_primitive(PrimitiveTypeID::i32)) {
return "%d";
} else if (dt->is_primitive(PrimitiveTypeID::u32)) {
return "%u";
} else if (dt->is_primitive(PrimitiveTypeID::i64)) {
// Use %lld on Windows.
// Discussion: https://github.com/taichi-dev/taichi/issues/2522
return "%lld";
} else if (dt->is_primitive(PrimitiveTypeID::u64)) {
return "%llu";
} else if (dt->is_primitive(PrimitiveTypeID::f32)) {
return "%f";
} else if (dt->is_primitive(PrimitiveTypeID::f64)) {
return "%.12f";
} else if (dt->is<QuantIntType>()) {
return "%d";
} else if (dt->is_primitive(PrimitiveTypeID::f16)) {
// f16 (and f32) is converted to f64 before printing, see
// CodeGenLLVM::visit(PrintStmt *stmt) and
// CodeGenLLVMCUDA::visit(PrintStmt *stmt) for more details.
return "%f";
} else {
TI_NOT_IMPLEMENTED
}
}

int data_type_size(DataType t) {
// TODO:
// 1. Ensure in the old code, pointer attributes of t are correct (by
Expand Down Expand Up @@ -84,5 +53,36 @@ int data_type_size(DataType t) {
}
}

std::string data_type_format(DataType dt) {
if (dt->is_primitive(PrimitiveTypeID::i16)) {
return "%hd";
} else if (dt->is_primitive(PrimitiveTypeID::u16)) {
return "%hu";
} else if (dt->is_primitive(PrimitiveTypeID::i32)) {
return "%d";
} else if (dt->is_primitive(PrimitiveTypeID::u32)) {
return "%u";
} else if (dt->is_primitive(PrimitiveTypeID::i64)) {
// Use %lld on Windows.
// Discussion: https://github.com/taichi-dev/taichi/issues/2522
return "%lld";
} else if (dt->is_primitive(PrimitiveTypeID::u64)) {
return "%llu";
} else if (dt->is_primitive(PrimitiveTypeID::f32)) {
return "%f";
} else if (dt->is_primitive(PrimitiveTypeID::f64)) {
return "%.12f";
} else if (dt->is<QuantIntType>()) {
return "%d";
} else if (dt->is_primitive(PrimitiveTypeID::f16)) {
// f16 (and f32) is converted to f64 before printing, see
// CodeGenLLVM::visit(PrintStmt *stmt) and
// CodeGenLLVMCUDA::visit(PrintStmt *stmt) for more details.
return "%f";
} else {
TI_NOT_IMPLEMENTED
}
}

} // namespace lang
} // namespace taichi
6 changes: 3 additions & 3 deletions taichi/ir/type_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace taichi {
namespace lang {

std::string data_type_name(DataType t);
TI_DLL_EXPORT std::string data_type_name(DataType t);

std::string data_type_format(DataType dt);
TI_DLL_EXPORT int data_type_size(DataType t);

int data_type_size(DataType t);
TI_DLL_EXPORT std::string data_type_format(DataType dt);

inline int data_type_bits(DataType t) {
return data_type_size(t) * 8;
Expand Down