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 Jan 1, 2024
1 parent 412316c commit 2010298
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 40 deletions.
4 changes: 3 additions & 1 deletion taichi/analysis/gen_offline_cache_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ class ASTSerializer : public IRVisitor, public ExpressionVisitor {
}

#define DEFINE_EMIT_ENUM(EnumType) \
void emit(EnumType type) { emit_pod(type); }
void emit(EnumType type) { \
emit_pod(type); \
}

DEFINE_EMIT_ENUM(ExprOpCode);
DEFINE_EMIT_ENUM(StmtOpCode);
Expand Down
4 changes: 2 additions & 2 deletions taichi/codegen/spirv/kernel_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ class KernelContextAttributes {
/**
* Get all argpacks.
*/
inline const std::vector<std::pair<std::vector<int>, const Type *>>
&argpack_types() const {
inline const std::vector<std::pair<std::vector<int>, const Type *>> &
argpack_types() const {
return argpack_types_;
}

Expand Down
4 changes: 2 additions & 2 deletions taichi/common/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ class Dict {
}

template <typename T>
std::enable_if_t<std::is_reference<T>::value, std::remove_reference_t<T>>
&get(std::string key) const {
std::enable_if_t<std::is_reference<T>::value, std::remove_reference_t<T>> &
get(std::string key) const {
return *get_ptr<std::remove_reference_t<T>>(key);
}

Expand Down
10 changes: 7 additions & 3 deletions taichi/common/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ class InterfaceHolder {
} \
} ImplementationInjector_##base_class_name##class_name##instance;

#define TI_NAME(alias) \
virtual std::string get_name() const override { return get_name_static(); } \
static std::string get_name_static() { return alias; }
#define TI_NAME(alias) \
virtual std::string get_name() const override { \
return get_name_static(); \
} \
static std::string get_name_static() { \
return alias; \
}

} // namespace taichi
6 changes: 4 additions & 2 deletions taichi/ir/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ class ExpressionVisitor {
bool invoke_default_visitor_{false};
};

#define TI_DEFINE_ACCEPT_FOR_EXPRESSION \
void accept(ExpressionVisitor *visitor) override { visitor->visit(this); }
#define TI_DEFINE_ACCEPT_FOR_EXPRESSION \
void accept(ExpressionVisitor *visitor) override { \
visitor->visit(this); \
}

} // namespace taichi::lang
12 changes: 9 additions & 3 deletions taichi/ir/expression_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
Expr expr_##opname(const Expr &expr) { \
return Expr::make<UnaryOpExpression>(UnaryOpType::opname, expr); \
} \
Expr operator op(const Expr &expr) { return expr_##opname(expr); }
Expr operator op(const Expr &expr) { \
return expr_##opname(expr); \
}

#define DEFINE_EXPRESSION_FUNC_UNARY(opname) \
Expr opname(const Expr &expr) { \
return Expr::make<UnaryOpExpression>(UnaryOpType::opname, expr); \
} \
Expr expr_##opname(const Expr &expr) { return opname(expr); }
Expr expr_##opname(const Expr &expr) { \
return opname(expr); \
}

#define DEFINE_EXPRESSION_OP_BINARY(op, opname) \
Expr operator op(const Expr &lhs, const Expr &rhs) { \
return Expr::make<BinaryOpExpression>(BinaryOpType::opname, lhs, rhs); \
} \
Expr expr_##opname(const Expr &lhs, const Expr &rhs) { return lhs op rhs; }
Expr expr_##opname(const Expr &lhs, const Expr &rhs) { \
return lhs op rhs; \
}

#define DEFINE_EXPRESSION_FUNC_BINARY(opname) \
Expr opname(const Expr &lhs, const Expr &rhs) { \
Expand Down
6 changes: 4 additions & 2 deletions taichi/ir/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class StatementTypeNameVisitor : public IRVisitor {
StatementTypeNameVisitor() {
}

#define PER_STATEMENT(x) \
void visit(x *stmt) override { type_name = #x; }
#define PER_STATEMENT(x) \
void visit(x *stmt) override { \
type_name = #x; \
}
#include "taichi/inc/statements.inc.h"

#undef PER_STATEMENT
Expand Down
6 changes: 4 additions & 2 deletions taichi/ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ class IRNode {
std::unique_ptr<IRNode> clone();
};

#define TI_DEFINE_ACCEPT \
void accept(IRVisitor *visitor) override { visitor->visit(this); }
#define TI_DEFINE_ACCEPT \
void accept(IRVisitor *visitor) override { \
visitor->visit(this); \
}

#define TI_DEFINE_CLONE \
std::unique_ptr<Stmt> clone() const override { \
Expand Down
12 changes: 8 additions & 4 deletions taichi/program/field_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ enum class FieldSource : int {
HostMappedPtr = 1,
};

#define DEFINE_PROPERTY(Type, name) \
Type name; \
void set_##name(const Type &new_name) { name = new_name; } \
Type get_##name() { return name; }
#define DEFINE_PROPERTY(Type, name) \
Type name; \
void set_##name(const Type &new_name) { \
name = new_name; \
} \
Type get_##name() { \
return name; \
}

struct FieldInfo {
DEFINE_PROPERTY(bool, valid)
Expand Down
4 changes: 3 additions & 1 deletion taichi/rhi/public_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ constexpr size_t kBufferSizeEntireSize = std::numeric_limits<size_t>::max();
inline name operator&(name a, name b) { \
return static_cast<name>(int(a) & int(b)); \
} \
inline bool operator&&(name a, name b) { return (int(a) & int(b)) != 0; }
inline bool operator&&(name a, name b) { \
return (int(a) & int(b)) != 0; \
}

enum class BlendOp : uint32_t { add, subtract, reverse_subtract, min, max };

Expand Down
4 changes: 2 additions & 2 deletions taichi/rhi/vulkan/vulkan_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ class VulkanPipeline : public Pipeline {
return graphics_pipeline_template_ != nullptr;
}

std::unordered_map<uint32_t, VulkanResourceSet>
&get_resource_set_templates() {
std::unordered_map<uint32_t, VulkanResourceSet> &
get_resource_set_templates() {
return set_templates_;
}

Expand Down
18 changes: 12 additions & 6 deletions taichi/runtime/llvm/runtime_module/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ DEFINE_ATOMIC_OP_INTRINSIC(xor, i64)
DEFINE_ATOMIC_OP_INTRINSIC(xor, u32)
DEFINE_ATOMIC_OP_INTRINSIC(xor, u64)

#define DEFINE_ADD(T) \
T add_##T(T a, T b) { return a + b; }
#define DEFINE_ADD(T) \
T add_##T(T a, T b) { \
return a + b; \
}

#define DEFINE_MIN(T) \
T min_##T(T a, T b) { return b > a ? a : b; }
#define DEFINE_MIN(T) \
T min_##T(T a, T b) { \
return b > a ? a : b; \
}

#define DEFINE_MAX(T) \
T max_##T(T a, T b) { return b < a ? a : b; }
#define DEFINE_MAX(T) \
T max_##T(T a, T b) { \
return b < a ? a : b; \
}

#define DEFINE_ATOMIC_OP_COMP_EXCH(OP, T) \
T atomic_##OP##_##T(volatile T *dest, T inc) { \
Expand Down
24 changes: 17 additions & 7 deletions taichi/runtime/llvm/runtime_module/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ __asm__(".symver expf,expf@GLIBC_2.2.5");
#endif

// For accessing struct fields
#define STRUCT_FIELD(S, F) \
extern "C" decltype(S::F) S##_get_##F(S *s) { return s->F; } \
extern "C" decltype(S::F) *S##_get_ptr_##F(S *s) { return &(s->F); } \
extern "C" void S##_set_##F(S *s, decltype(S::F) f) { s->F = f; }
#define STRUCT_FIELD(S, F) \
extern "C" decltype(S::F) S##_get_##F(S *s) { \
return s->F; \
} \
extern "C" decltype(S::F) *S##_get_ptr_##F(S *s) { \
return &(s->F); \
} \
extern "C" void S##_set_##F(S *s, decltype(S::F) f) { \
s->F = f; \
}

#define STRUCT_FIELD_ARRAY(S, F) \
extern "C" std::remove_all_extents_t<decltype(S::F)> S##_get_##F(S *s, \
Expand Down Expand Up @@ -159,9 +165,13 @@ std::size_t taichi_strlen(const char *str) {
return len;
}

#define DEFINE_UNARY_REAL_FUNC(F) \
f32 F##_f32(f32 x) { return std::F(x); } \
f64 F##_f64(f64 x) { return std::F(x); }
#define DEFINE_UNARY_REAL_FUNC(F) \
f32 F##_f32(f32 x) { \
return std::F(x); \
} \
f64 F##_f64(f64 x) { \
return std::F(x); \
}

DEFINE_UNARY_REAL_FUNC(exp)
DEFINE_UNARY_REAL_FUNC(log)
Expand Down
10 changes: 7 additions & 3 deletions taichi/util/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ constexpr int bit_length() {
return std::is_same<T, bool>() ? 1 : sizeof(T) * 8;
}

#define TI_BIT_FIELD(T, name, start) \
T get_##name() const { return (T)Base::get<start, bit::bit_length<T>()>(); } \
void set_##name(const T &val) { Base::set<start, bit::bit_length<T>()>(val); }
#define TI_BIT_FIELD(T, name, start) \
T get_##name() const { \
return (T)Base::get<start, bit::bit_length<T>()>(); \
} \
void set_##name(const T &val) { \
Base::set<start, bit::bit_length<T>()>(val); \
}

template <typename T, int N>
TI_FORCE_INLINE constexpr T product(const std::array<T, N> arr) {
Expand Down

0 comments on commit 2010298

Please sign in to comment.