Skip to content

Commit

Permalink
Update macro parameter names with parentheses (#2913)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Essenmacher <[email protected]>
  • Loading branch information
mikeessen authored Aug 21, 2024
1 parent 2e9bcf2 commit 72d6c11
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 109 deletions.
8 changes: 4 additions & 4 deletions src/Accelerators/Accelerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
#define CREATE_ACCEL_ENUM(name) name,
#define DECLARE_ACCEL_INIT_FUNCTION(name) extern Accelerator *create##name();
#define INVOKE_ACCEL_INIT_FUNCTION(name, kinds) \
if (!kinds.empty() && \
if (!(kinds).empty() && \
llvm::is_contained(kinds, accel::Accelerator::Kind::name)) \
create##name()->setName(#name);
#define CREATE_ACCEL_CL_ENUM(name) \
clEnumValN(accel::Accelerator::Kind::name, #name, #name " accelerator"),
#define ACCEL_CL_ENUM_FROM_STRING(name, var, str) \
if (str.compare(std::string(#name)) == 0) { \
var = accel::Accelerator::Kind::name; \
if ((str).compare(std::string(#name)) == 0) { \
(var) = accel::Accelerator::Kind::name; \
return true; \
}
#define ACCEL_CL_ENUM_TO_STRING(name, map) \
Expand Down Expand Up @@ -165,4 +165,4 @@ extern void initAccelerators(llvm::ArrayRef<Accelerator::Kind> kinds);

} // namespace accel
} // namespace onnx_mlir
#endif
#endif
2 changes: 0 additions & 2 deletions src/Accelerators/NNPA/Runtime/zDNNExtension/zDNNExtension.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ void checkStatus(zdnn_status status, const char *zdnn_name) {
}
}

#define CHECK_ZDNN_STATUS(status, zdnn_name) checkStatus(status, zdnn_name)

void getUnmappedShape(const zdnn_ztensor *t, UnmappedShape *shape) {
const zdnn_tensor_desc *desc = t->transformed_desc;
shape->e4 = desc->dim4;
Expand Down
4 changes: 2 additions & 2 deletions src/Accelerators/NNPA/Runtime/zDNNExtension/zDNNExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extern bool OMStatusMessagesEnabled;
// Misc Macros
// -----------------------------------------------------------------------------

#define CEIL(a, b) (uint64_t)((a + b - 1) / b) // positive numbers only
#define CEIL(a, b) (uint64_t)(((a) + (b)-1) / (b)) // positive numbers only

// -----------------------------------------------------------------------------
// Common structures
Expand Down Expand Up @@ -159,7 +159,7 @@ inline void omUnreachable() {
*/
void checkStatus(zdnn_status status, const char *zdnn_name);

#define CHECK_ZDNN_STATUS(status, zdnn_name) checkStatus(status, zdnn_name)
#define CHECK_ZDNN_STATUS(status, zdnn_name) checkStatus((status), (zdnn_name))

/**
* \brief Get the unmapped shape (4D) of ztensor.
Expand Down
26 changes: 13 additions & 13 deletions src/Accelerators/NNPA/Support/Stickify/Stickify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ zdnn_status verify_transformed_descriptor(const zdnn_tensor_desc *tfrmd_desc);

#define ZDNN_MAX_DIMS 4 // number of dims in AIU's Tensor Descriptor

#define CEIL(a, b) (uint64_t)((a + b - 1) / b) // positive numbers only
#define MIN(a, b) ((a > b) ? b : a)
#define MAX(a, b) ((a < b) ? b : a)
#define CEIL(a, b) (uint64_t)(((a) + (b)-1) / (b)) // positive numbers only
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define BIT_SIZEOF(a) (sizeof(a) * 8)

// padded = next multiple of AIU_2BYTE_CELLS_PER_STICK
#define PADDED(x) \
((uint32_t)CEIL(x, AIU_2BYTE_CELLS_PER_STICK) * AIU_2BYTE_CELLS_PER_STICK)
((uint32_t)CEIL((x), AIU_2BYTE_CELLS_PER_STICK) * AIU_2BYTE_CELLS_PER_STICK)
#define ZDNN_STATUS_OK ZDNN_OK

typedef enum elements_mode {
Expand Down Expand Up @@ -92,8 +92,8 @@ DECLARE_DATA_FORMAT_STR(ZDNN_FORMAT_4DKERNEL)
static short get_data_layout_num_gates(zdnn_data_layouts layout) {

#define CASE_RTN_GATES(a, b) \
case a: \
return b;
case (a): \
return (b);

switch (layout) {
CASE_RTN_GATES(ZDNN_BIDIR_ZRH, 3);
Expand All @@ -109,8 +109,8 @@ static short get_data_layout_num_gates(zdnn_data_layouts layout) {
static short get_data_layout_dims(zdnn_data_layouts layout) {

#define CASE_RTN_DIM(a, b) \
case a: \
return b;
case (a): \
return (b);

switch (layout) {
CASE_RTN_DIM(ZDNN_1D, 1);
Expand Down Expand Up @@ -152,7 +152,7 @@ uint32_t get_rnn_concatenated_dim2(uint32_t val, zdnn_concat_info info) {
short get_func_code_num_gates(nnpa_function_code func_code) {

#define CASE_RTN_GATES(a, b) \
case a: \
case (a): \
return get_data_layout_num_gates(b); // piggyback thus no need to hardcode

switch (func_code) {
Expand All @@ -167,7 +167,7 @@ short get_func_code_num_gates(nnpa_function_code func_code) {
const char *get_data_layout_str(zdnn_data_layouts layout) {

#define CASE_RTN_STR(a) \
case a: \
case (a): \
return DATA_LAYOUT_STR_##a;

switch (layout) {
Expand All @@ -194,7 +194,7 @@ const char *get_data_layout_str(zdnn_data_layouts layout) {
const char *get_data_format_str(zdnn_data_formats format) {

#define CASE_RTN_STR(a) \
case a: \
case (a): \
return DATA_FORMAT_STR_##a;

switch (format) {
Expand All @@ -209,8 +209,8 @@ const char *get_data_format_str(zdnn_data_formats format) {
short get_data_type_size(zdnn_data_types type) {

#define CASE_RTN_SIZE(a, b) \
case a: \
return b;
case (a): \
return (b);

switch (type) {
CASE_RTN_SIZE(BFLOAT, 2);
Expand Down
42 changes: 21 additions & 21 deletions src/Runtime/OMSort.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
//
#define compareFunctionBody(typeName, direction, load, dataPtr, idx1p, idx2p) \
{ \
uint64_t idx1 = *((uint64_t *)idx1p); \
uint64_t idx2 = *((uint64_t *)idx2p); \
typeName *data = (typeName *)dataPtr; \
uint64_t idx1 = *((uint64_t *)(idx1p)); \
uint64_t idx2 = *((uint64_t *)(idx2p)); \
typeName *data = (typeName *)(dataPtr); \
load(typeName, v1, data[idx1]); \
load(typeName, v2, data[idx2]); \
return (direction(v1, v2) || (v1 == v2 && idx1 < idx2)) ? -1 : 1; \
Expand Down Expand Up @@ -89,15 +89,15 @@ typedef int(
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif

#define Load(typeName, to, from) typeName to = from
#define Load(typeName, to, from) typeName (to) = (from)

// Convert f16 elements to f32 for comparison because we don't have logic to
// compare f16 elements directly on all platforms.
// TODO: Use Convert(_Float16, to, from) on supported platforms.
// Or consider converting the whole tensor to f32, sort as f32, and then
// convert the sorted tensor back to f16. That may be faster than
// converting elements for each comparison during sorting.
#define LoadF16AsF32(typeName, to, from) float to = om_f16_to_f32(from)
#define LoadF16AsF32(typeName, to, from) float (to) = om_f16_to_f32(from)

// declare ascending functions
#define Ascending(lhs, rhs) ((lhs) < (rhs))
Expand Down Expand Up @@ -169,35 +169,35 @@ typedef struct indexStack {

#define STACK_INIT(stack, stackSize) \
do { \
assert(stackSize > 0); \
stack.stackData = (uint64_t *)alloca(stackSize * sizeof(uint64_t)); \
assert(stack.stackData != NULL); \
stack.stackSize = stackSize; \
stack.stackTop = 0; \
assert((stackSize) > 0); \
(stack).stackData = (uint64_t *)alloca((stackSize) * sizeof(uint64_t)); \
assert((stack).stackData != NULL); \
(stack).stackSize = (stackSize); \
(stack).stackTop = 0; \
} while (0)
#define STACK_ISEMPTY(stack) (stack.stackTop == 0)
#define STACK_ISEMPTY(stack) ((stack).stackTop == 0)
#define STACK_PUSH(stack, begin, end) \
do { \
assert(stack.stackTop <= stack.stackSize - 2); \
stack.stackData[(stack.stackTop)++] = begin; \
stack.stackData[(stack.stackTop)++] = end; \
assert((stack).stackTop <= (stack).stackSize - 2); \
(stack).stackData[((stack).stackTop)++] = (begin); \
(stack).stackData[((stack).stackTop)++] = (end); \
} while (0)
#define STACK_POP(stack, begin, end) \
do { \
assert(stack.stackTop >= 2); \
end = stack.stackData[--(stack.stackTop)]; \
begin = stack.stackData[--(stack.stackTop)]; \
assert((stack).stackTop >= 2); \
(end) = (stack).stackData[--((stack).stackTop)]; \
(begin) = (stack).stackData[--((stack).stackTop)]; \
} while (0)
#define STACK_PRINT(stack) \
do { \
assert(stack.stackTop >= 0); \
assert((stack).stackTop >= 0); \
fprintf(stderr, "Stack: ["); \
for (int64_t i = 0; (i + 1) < stack.stackTop; i += 2) { \
for (int64_t i = 0; (i + 1) < (stack).stackTop; i += 2) { \
fprintf( \
stderr, "<%ld:%ld>, ", stack.stackData[i], stack.stackData[i + 1]); \
stderr, "<%ld:%ld>, ", (stack).stackData[i], (stack).stackData[i + 1]);\
} \
fprintf( \
stderr, "] (Top=%ld,Size=%ld)\n", stack.stackTop, stack.stackSize); \
stderr, "] (Top=%ld,Size=%ld)\n", (stack).stackTop, (stack).stackSize);\
fflush(stderr); \
} while (0)

Expand Down
22 changes: 11 additions & 11 deletions src/Runtime/OMTensor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -480,42 +480,42 @@ static void printData(FILE *fout, const OMTensor *tensor) {
/* Helper macros to print data for 1-4D tensors */
#define LOOP_1(INDEX, IV, UB) \
fprintf(fout, "["); \
for (int64_t IV = 0; IV < UB; ++IV) { \
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
if (IV) \
fprintf(fout, ", "); \
indexes[INDEX] = IV; \
indexes[(INDEX)] = (IV); \
int64_t elemOffset = computeElemOffset(tensor->_strides, indexes, rank); \
printElement(fout, dataPtr, elemOffset, dataType); \
} \
fprintf(fout, "]");

#define LOOP_2(INDEX, IV, UB, ...) \
fprintf(fout, "["); \
for (int64_t IV = 0; IV < UB; ++IV) { \
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
if (IV) \
fprintf(fout, ", "); \
indexes[INDEX] = IV; \
LOOP_1(INDEX + 1, __VA_ARGS__) \
indexes[(INDEX)] = (IV); \
LOOP_1((INDEX) + 1, __VA_ARGS__) \
} \
fprintf(fout, "]");

#define LOOP_3(INDEX, IV, UB, ...) \
fprintf(fout, "["); \
for (int64_t IV = 0; IV < UB; ++IV) { \
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
if (IV) \
fprintf(fout, ", "); \
indexes[INDEX] = IV; \
LOOP_2(INDEX + 1, __VA_ARGS__) \
indexes[(INDEX)] = (IV); \
LOOP_2((INDEX) + 1, __VA_ARGS__) \
} \
fprintf(fout, "]");

#define LOOP_4(INDEX, IV, UB, ...) \
fprintf(fout, "["); \
for (int64_t IV = 0; IV < UB; ++IV) { \
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
if (IV) \
fprintf(fout, ", "); \
indexes[INDEX] = IV; \
LOOP_3(INDEX + 1, __VA_ARGS__) \
indexes[(INDEX)] = (IV); \
LOOP_3((INDEX) + 1, __VA_ARGS__) \
} \
fprintf(fout, "]");

Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/jni/jnilog.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static pthread_key_t log_inited;
static pthread_key_t log_level;
static pthread_key_t log_fp;

#define THREAD_LOCAL_INIT(key, func) pthread_once(key, func)
#define THREAD_LOCAL_INIT(key, func) pthread_once((key), (func))

INLINE void key_init() {
pthread_key_create(&log_inited, NULL);
Expand Down
Loading

0 comments on commit 72d6c11

Please sign in to comment.