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 Apr 4, 2023
1 parent 603d9e6 commit 7a9d9c4
Show file tree
Hide file tree
Showing 27 changed files with 136 additions and 92 deletions.
28 changes: 14 additions & 14 deletions c_api/src/c_api_test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ static void float32(float *__restrict out, const uint16_t in) {
uint32_t t2;
uint32_t t3;

t1 = in & 0x7fffu; // Non-sign bits
t2 = in & 0x8000u; // Sign bit
t3 = in & 0x7c00u; // Exponent
t1 = in & 0x7fffu; // Non-sign bits
t2 = in & 0x8000u; // Sign bit
t3 = in & 0x7c00u; // Exponent

t1 <<= 13u; // Align mantissa on MSB
t2 <<= 16u; // Shift sign bit into position
t1 <<= 13u; // Align mantissa on MSB
t2 <<= 16u; // Shift sign bit into position

t1 += 0x38000000; // Adjust bias
t1 += 0x38000000; // Adjust bias

t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero

t1 |= t2; // Re-insert sign bit
t1 |= t2; // Re-insert sign bit

*((uint32_t *)out) = t1;
};
Expand All @@ -75,20 +75,20 @@ static void float16(uint16_t *__restrict out, const float in) {
uint32_t t2;
uint32_t t3;

t1 = inu & 0x7fffffffu; // Non-sign bits
t2 = inu & 0x80000000u; // Sign bit
t3 = inu & 0x7f800000u; // Exponent
t1 = inu & 0x7fffffffu; // Non-sign bits
t2 = inu & 0x80000000u; // Sign bit
t3 = inu & 0x7f800000u; // Exponent

t1 >>= 13u; // Align mantissa on MSB
t2 >>= 16u; // Shift sign bit into position
t1 >>= 13u; // Align mantissa on MSB
t2 >>= 16u; // Shift sign bit into position

t1 -= 0x1c000; // Adjust bias
t1 -= 0x1c000; // Adjust bias

t1 = (t3 < 0x38800000u) ? 0 : t1; // Flush-to-zero
t1 = (t3 > 0x8e000000u) ? 0x7bff : t1; // Clamp-to-max
t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero

t1 |= t2; // Re-insert sign bit
t1 |= t2; // Re-insert sign bit

*((uint16_t *)out) = t1;
};
Expand Down
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 @@ -623,7 +623,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
6 changes: 3 additions & 3 deletions taichi/codegen/spirv/spirv_ir_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,8 @@ Value IRBuilder::cast(const SType &dst_type, Value value) {
to.to_string());
return Value();
}
} else if (to->is_primitive(PrimitiveTypeID::u1)) { // Bool
if (is_integral(from) && is_signed(from)) { // Int -> Bool
} else if (to->is_primitive(PrimitiveTypeID::u1)) { // Bool
if (is_integral(from) && is_signed(from)) { // Int -> Bool
return ne(value, int_immediate_number(value.stype, 0));
} else if (is_integral(from) && is_unsigned(from)) { // UInt -> Bool
return ne(value, uint_immediate_number(value.stype, 0));
Expand Down Expand Up @@ -1178,7 +1178,7 @@ Value IRBuilder::cast(const SType &dst_type, Value value) {
is_real(to)) { // Int -> Float
return make_value(spv::OpConvertSToF, dst_type, value);
} else if (is_integral(from) && is_unsigned(from) &&
is_real(to)) { // UInt -> Float
is_real(to)) { // UInt -> Float
return make_value(spv::OpConvertUToF, dst_type, value);
} else if (is_real(from) && is_real(to)) { // Float -> Float
return make_value(spv::OpFConvert, dst_type, value);
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
8 changes: 4 additions & 4 deletions taichi/common/miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ int mz_inflate(mz_streamp pStream, int flush) {
uncompressed data left in the output dictionary -
oh well). */
else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress
without supplying more input or by setting flush
to MZ_FINISH. */
return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress
without supplying more input or by setting flush
to MZ_FINISH. */
else if (flush == MZ_FINISH) {
/* The output buffer MUST be large to hold the remaining uncompressed data
* when flush==MZ_FINISH. */
Expand Down Expand Up @@ -3295,7 +3295,7 @@ static int mz_stat64(const char *path, struct __stat64 *buffer) {

#else
#pragma message( \
"Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.")
"Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.")
#ifndef MINIZ_NO_TIME
#include <utime.h>
#endif
Expand Down
16 changes: 8 additions & 8 deletions taichi/common/miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,22 @@ typedef struct mz_stream_s {
unsigned int avail_in; /* number of bytes available at next_in */
mz_ulong total_in; /* total number of bytes consumed so far */

unsigned char *next_out; /* pointer to next byte to write */
unsigned int avail_out; /* number of bytes that can be written to next_out */
mz_ulong total_out; /* total number of bytes produced so far */
unsigned char *next_out; /* pointer to next byte to write */
unsigned int avail_out; /* number of bytes that can be written to next_out */
mz_ulong total_out; /* total number of bytes produced so far */

char *msg; /* error msg (unused) */
char *msg; /* error msg (unused) */
struct mz_internal_state
*state; /* internal state, allocated by zalloc/zfree */
*state; /* internal state, allocated by zalloc/zfree */

mz_alloc_func
zalloc; /* optional heap allocation function (defaults to malloc) */
mz_free_func zfree; /* optional heap free function (defaults to free) */
void *opaque; /* heap alloc function user pointer */

int data_type; /* data_type (unused) */
mz_ulong adler; /* adler32 of the source or uncompressed data */
mz_ulong reserved; /* not used */
int data_type; /* data_type (unused) */
mz_ulong adler; /* adler32 of the source or uncompressed data */
mz_ulong reserved; /* not used */
} mz_stream;

typedef mz_stream *mz_streamp;
Expand Down
6 changes: 4 additions & 2 deletions taichi/ir/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,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 @@ -267,8 +267,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: 6 additions & 6 deletions taichi/ir/statements.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ class ExternalFuncCallStmt : public Stmt,
enum Type { SHARED_OBJECT = 0, ASSEMBLY = 1, BITCODE = 2 };

Type type;
void *so_func; // SHARED_OBJECT
std::string asm_source; // ASM
std::string bc_filename; // BITCODE
std::string bc_funcname; // BITCODE
void *so_func; // SHARED_OBJECT
std::string asm_source; // ASM
std::string bc_filename; // BITCODE
std::string bc_funcname; // BITCODE
std::vector<Stmt *> arg_stmts;
std::vector<Stmt *> output_stmts; // BITCODE doesn't use this

Expand Down Expand Up @@ -1338,9 +1338,9 @@ class OffloadedStmt : public Stmt {
std::unordered_map<mesh::MeshElementType, Stmt *>
total_offset_local; // |total_offset[idx]|
std::unordered_map<mesh::MeshElementType, Stmt *>
owned_num_local; // |owned_offset[idx+1] - owned_offset[idx]|
owned_num_local; // |owned_offset[idx+1] - owned_offset[idx]|
std::unordered_map<mesh::MeshElementType, Stmt *>
total_num_local; // |total_offset[idx+1] - total_offset[idx]|
total_num_local; // |total_offset[idx+1] - total_offset[idx]|

std::vector<int> index_offsets;

Expand Down
2 changes: 1 addition & 1 deletion taichi/program/compile_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct CompileConfig {
bool offline_cache{false};
std::string offline_cache_file_path{get_repo_dir() + "ticache"};
std::string offline_cache_cleaning_policy{
"lru"}; // "never"|"version"|"lru"|"fifo"
"lru"}; // "never"|"version"|"lru"|"fifo"
int offline_cache_max_size_of_files{100 * 1024 *
1024}; // bytes, default: 100MB
double offline_cache_cleaning_factor{0.25}; // [0.f, 1.f]
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: 2 additions & 2 deletions taichi/python/export_ggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ py::array_t<float> mat4_to_nparray(glm::mat4 mat) {
return py::array_t<float>(
py::detail::any_container<ssize_t>({4, 4}), // shape (rows, cols)
py::detail::any_container<ssize_t>(
{sizeof(float) * 4, sizeof(float)}), // strides in bytes
glm::value_ptr(mat), // buffer pointer
{sizeof(float) * 4, sizeof(float)}), // strides in bytes
glm::value_ptr(mat), // buffer pointer
nullptr);
}

Expand Down
6 changes: 3 additions & 3 deletions taichi/rhi/cuda/cuda_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ typedef enum CUfunction_attribute_enum {
* 3D array descriptor
*/
typedef struct CUDA_ARRAY3D_DESCRIPTOR_st {
size_t Width; /**< Width of 3D array */
size_t Height; /**< Height of 3D array */
size_t Depth; /**< Depth of 3D array */
size_t Width; /**< Width of 3D array */
size_t Height; /**< Height of 3D array */
size_t Depth; /**< Depth of 3D array */

CUarray_format Format; /**< Array format */
unsigned int NumChannels; /**< Channels per array element */
Expand Down
2 changes: 1 addition & 1 deletion taichi/rhi/cuda/cupti_toolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ bool get_counter_data_prefix_image(
return true;
}

#else // CUDA_VERSION < 11040
#else // CUDA_VERSION < 11040

// copy from : CUPTI/samples/extensions/src/profilerhost_util/Metric.cpp
bool get_raw_metric_requests(
Expand Down
4 changes: 2 additions & 2 deletions taichi/rhi/dx/dx_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ HRESULT create_compute_device(ID3D11Device **out_device,

AdjustWindowRect(&window_rect, WS_OVERLAPPEDWINDOW, false);

hWnd = CreateWindowEx(0, // Optional window styles.
CLASS_NAME, // Window class
hWnd = CreateWindowEx(0, // Optional window styles.
CLASS_NAME, // Window class
std::wstring(window_name.begin(), window_name.end())
.data(), // Window text
WS_OVERLAPPEDWINDOW, // Window style
Expand Down
6 changes: 4 additions & 2 deletions taichi/rhi/public_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#else // C++20 and below
#ifdef __GNUC__ // GCC, Clang, ICC
#define RHI_UNREACHABLE __builtin_unreachable();
#else // MSVC
#else // MSVC
#define RHI_UNREACHABLE __assume(false);
#endif
#endif
Expand Down 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
Loading

0 comments on commit 7a9d9c4

Please sign in to comment.