Skip to content
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: 2 additions & 0 deletions custom_ops/gpu_ops/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace cub = hipcub;
using json = nlohmann::json;
#endif

#define CEILDIV(a, b) (((a + b - 1) / b))

This comment was marked as outdated.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ 疑问 CEILDIV 宏存在两个潜在问题:

  1. 整数溢出a + b - 1a 接近 INT_MAX 时会溢出(例如 int32_t 场景)。
  2. 宏参数未加括号:若传入表达式(如 CEILDIV(x+1, y)),a 展开后无括号保护可能导致运算符优先级错误。

建议修改为:

#define CEILDIV(a, b) (((a) + (b) - 1) / (b))

或使用 inline 函数以避免宏的副作用:

template <typename T>
inline T ceildiv(T a, T b) { return (a + b - 1) / b; }


#define CUDA_CHECK(call) \
do { \
const cudaError_t error_code = call; \
Expand Down
Loading
Loading