Skip to content

Commit d7bec67

Browse files
author
Mike Essenmacher
committed
Additional updates
Signed-off-by: Mike Essenmacher <[email protected]>
1 parent 209f559 commit d7bec67

File tree

10 files changed

+94
-91
lines changed

10 files changed

+94
-91
lines changed

src/Accelerators/Accelerator.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
#define CREATE_ACCEL_ENUM(name) name,
3434
#define DECLARE_ACCEL_INIT_FUNCTION(name) extern Accelerator *create##name();
3535
#define INVOKE_ACCEL_INIT_FUNCTION(name, kinds) \
36-
if (!kinds.empty() && \
36+
if (!(kinds).empty() && \
3737
llvm::is_contained(kinds, accel::Accelerator::Kind::name)) \
3838
create##name()->setName(#name);
3939
#define CREATE_ACCEL_CL_ENUM(name) \
4040
clEnumValN(accel::Accelerator::Kind::name, #name, #name " accelerator"),
4141
#define ACCEL_CL_ENUM_FROM_STRING(name, var, str) \
42-
if (str.compare(std::string(#name)) == 0) { \
43-
var = accel::Accelerator::Kind::name; \
42+
if ((str).compare(std::string(#name)) == 0) { \
43+
(var) = accel::Accelerator::Kind::name; \
4444
return true; \
4545
}
4646
#define ACCEL_CL_ENUM_TO_STRING(name, map) \
@@ -165,4 +165,4 @@ extern void initAccelerators(llvm::ArrayRef<Accelerator::Kind> kinds);
165165

166166
} // namespace accel
167167
} // namespace onnx_mlir
168-
#endif
168+
#endif

src/Runtime/OMSort.inc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
//
5555
#define compareFunctionBody(typeName, direction, load, dataPtr, idx1p, idx2p) \
5656
{ \
57-
uint64_t idx1 = *((uint64_t *)idx1p); \
58-
uint64_t idx2 = *((uint64_t *)idx2p); \
59-
typeName *data = (typeName *)dataPtr; \
57+
uint64_t idx1 = *((uint64_t *)(idx1p)); \
58+
uint64_t idx2 = *((uint64_t *)(idx2p)); \
59+
typeName *data = (typeName *)(dataPtr); \
6060
load(typeName, v1, data[idx1]); \
6161
load(typeName, v2, data[idx2]); \
6262
return (direction(v1, v2) || (v1 == v2 && idx1 < idx2)) ? -1 : 1; \
@@ -89,15 +89,15 @@ typedef int(
8989
#pragma GCC diagnostic ignored "-Wcast-qual"
9090
#endif
9191

92-
#define Load(typeName, to, from) typeName to = from
92+
#define Load(typeName, to, from) typeName (to) = (from)
9393

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

102102
// declare ascending functions
103103
#define Ascending(lhs, rhs) ((lhs) < (rhs))
@@ -169,35 +169,35 @@ typedef struct indexStack {
169169

170170
#define STACK_INIT(stack, stackSize) \
171171
do { \
172-
assert(stackSize > 0); \
173-
stack.stackData = (uint64_t *)alloca(stackSize * sizeof(uint64_t)); \
174-
assert(stack.stackData != NULL); \
175-
stack.stackSize = stackSize; \
176-
stack.stackTop = 0; \
172+
assert((stackSize) > 0); \
173+
(stack).stackData = (uint64_t *)alloca((stackSize) * sizeof(uint64_t)); \
174+
assert((stack).stackData != NULL); \
175+
(stack).stackSize = (stackSize); \
176+
(stack).stackTop = 0; \
177177
} while (0)
178-
#define STACK_ISEMPTY(stack) (stack.stackTop == 0)
178+
#define STACK_ISEMPTY(stack) ((stack).stackTop == 0)
179179
#define STACK_PUSH(stack, begin, end) \
180180
do { \
181-
assert(stack.stackTop <= stack.stackSize - 2); \
182-
stack.stackData[(stack.stackTop)++] = begin; \
183-
stack.stackData[(stack.stackTop)++] = end; \
181+
assert((stack).stackTop <= (stack).stackSize - 2); \
182+
(stack).stackData[((stack).stackTop)++] = (begin); \
183+
(stack).stackData[((stack).stackTop)++] = (end); \
184184
} while (0)
185185
#define STACK_POP(stack, begin, end) \
186186
do { \
187-
assert(stack.stackTop >= 2); \
188-
end = stack.stackData[--(stack.stackTop)]; \
189-
begin = stack.stackData[--(stack.stackTop)]; \
187+
assert((stack).stackTop >= 2); \
188+
(end) = (stack).stackData[--((stack).stackTop)]; \
189+
(begin) = (stack).stackData[--((stack).stackTop)]; \
190190
} while (0)
191191
#define STACK_PRINT(stack) \
192192
do { \
193-
assert(stack.stackTop >= 0); \
193+
assert((stack).stackTop >= 0); \
194194
fprintf(stderr, "Stack: ["); \
195-
for (int64_t i = 0; (i + 1) < stack.stackTop; i += 2) { \
195+
for (int64_t i = 0; (i + 1) < (stack).stackTop; i += 2) { \
196196
fprintf( \
197-
stderr, "<%ld:%ld>, ", stack.stackData[i], stack.stackData[i + 1]); \
197+
stderr, "<%ld:%ld>, ", (stack).stackData[i], (stack).stackData[i + 1]);\
198198
} \
199199
fprintf( \
200-
stderr, "] (Top=%ld,Size=%ld)\n", stack.stackTop, stack.stackSize); \
200+
stderr, "] (Top=%ld,Size=%ld)\n", (stack).stackTop, (stack).stackSize);\
201201
fflush(stderr); \
202202
} while (0)
203203

src/Runtime/OMTensor.inc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -480,42 +480,42 @@ static void printData(FILE *fout, const OMTensor *tensor) {
480480
/* Helper macros to print data for 1-4D tensors */
481481
#define LOOP_1(INDEX, IV, UB) \
482482
fprintf(fout, "["); \
483-
for (int64_t IV = 0; IV < UB; ++IV) { \
483+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
484484
if (IV) \
485485
fprintf(fout, ", "); \
486-
indexes[INDEX] = IV; \
486+
indexes[(INDEX)] = (IV); \
487487
int64_t elemOffset = computeElemOffset(tensor->_strides, indexes, rank); \
488488
printElement(fout, dataPtr, elemOffset, dataType); \
489489
} \
490490
fprintf(fout, "]");
491491

492492
#define LOOP_2(INDEX, IV, UB, ...) \
493493
fprintf(fout, "["); \
494-
for (int64_t IV = 0; IV < UB; ++IV) { \
494+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
495495
if (IV) \
496496
fprintf(fout, ", "); \
497-
indexes[INDEX] = IV; \
498-
LOOP_1(INDEX + 1, __VA_ARGS__) \
497+
indexes[(INDEX)] = (IV); \
498+
LOOP_1((INDEX) + 1, __VA_ARGS__) \
499499
} \
500500
fprintf(fout, "]");
501501

502502
#define LOOP_3(INDEX, IV, UB, ...) \
503503
fprintf(fout, "["); \
504-
for (int64_t IV = 0; IV < UB; ++IV) { \
504+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
505505
if (IV) \
506506
fprintf(fout, ", "); \
507-
indexes[INDEX] = IV; \
508-
LOOP_2(INDEX + 1, __VA_ARGS__) \
507+
indexes[(INDEX)] = (IV); \
508+
LOOP_2((INDEX) + 1, __VA_ARGS__) \
509509
} \
510510
fprintf(fout, "]");
511511

512512
#define LOOP_4(INDEX, IV, UB, ...) \
513513
fprintf(fout, "["); \
514-
for (int64_t IV = 0; IV < UB; ++IV) { \
514+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
515515
if (IV) \
516516
fprintf(fout, ", "); \
517-
indexes[INDEX] = IV; \
518-
LOOP_3(INDEX + 1, __VA_ARGS__) \
517+
indexes[(INDEX)] = (IV); \
518+
LOOP_3((INDEX) + 1, __VA_ARGS__) \
519519
} \
520520
fprintf(fout, "]");
521521

src/Runtime/jni/jnilog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static pthread_key_t log_inited;
4040
static pthread_key_t log_level;
4141
static pthread_key_t log_fp;
4242

43-
#define THREAD_LOCAL_INIT(key, func) pthread_once(key, func)
43+
#define THREAD_LOCAL_INIT(key, func) pthread_once((key), (func))
4444

4545
INLINE void key_init() {
4646
pthread_key_create(&log_inited, NULL);

src/Runtime/jni/jnilog.h

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL };
2323
#define LOG_MAX_LEN 4096 /* max number of chars to output */
2424
#define LOG_MAX_NUM 128 /* max number of elements to output */
2525

26-
#define MIN(x, y) ((x) > (y) ? y : x)
26+
#define MIN(x, y) ((x) > (y) ? (y) : (x))
2727

2828
/* Construct string of up to LOG_MAX_NUM elements of an array of C type
2929
* To avoid variable name clash, prefix with double underscores.
3030
*/
3131
#define LOG_BUF_C_TYPE(type, format, buf, data, n) \
3232
do { \
33-
char *__p = buf; \
33+
char *__p = (buf); \
3434
/* Reserve 5 char at the end for " ... \0". Note the first \
3535
* space will come from the '\0' of the previous string. \
3636
*/ \
37-
int __i = 0, __j = sizeof(buf) - 5, __k, __l = MIN(n, LOG_MAX_NUM); \
37+
int __i = 0, __j = sizeof(buf) - 5, __k, __l = MIN((n), LOG_MAX_NUM); \
3838
/* j is the available number of chars including '\0'. k is the \
3939
* number of chars printed without '\0'. So as long as k < j, \
4040
* it means the output, with a trailing '\0', fits in the buffer. \
4141
*/ \
4242
while (__i < __l && \
43-
(__k = snprintf(__p, __j, format, ((type *)data)[__i])) < __j) { \
43+
(__k = snprintf(__p, __j, (format), ((type *)(data))[__i])) < __j) {\
4444
assert(__k >= 0 && "snprintf write error to __p"); \
4545
__p += __k; \
4646
__j -= __k; \
@@ -69,66 +69,69 @@ enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL };
6969
switch (type) { \
7070
case ONNX_TYPE_UINT8: \
7171
case ONNX_TYPE_INT8: \
72-
LOG_BUF_C_TYPE(const char, hex ? " %02x" : "%c", buf, data, n); \
72+
LOG_BUF_C_TYPE(const char, (hex) ? " %02x" : "%c", (buf), (data), (n)); \
7373
break; \
7474
case ONNX_TYPE_UINT16: \
7575
case ONNX_TYPE_INT16: \
76-
LOG_BUF_C_TYPE(const short, hex ? " %04x" : " %d", buf, data, n); \
76+
LOG_BUF_C_TYPE(const short, (hex) ? " %04x" : " %d", (buf), (data), (n));\
7777
break; \
7878
case ONNX_TYPE_UINT32: \
7979
case ONNX_TYPE_INT32: \
80-
LOG_BUF_C_TYPE(const int, hex ? " %08x" : " %d", buf, data, n); \
80+
LOG_BUF_C_TYPE(const int, (hex) ? " %08x" : " %d", (buf), (data), (n)); \
8181
break; \
8282
case ONNX_TYPE_UINT64: \
8383
case ONNX_TYPE_INT64: \
84-
LOG_BUF_C_TYPE(const long, hex ? " %016x" : " %ld", buf, data, n); \
84+
LOG_BUF_C_TYPE(const long, (hex) ? " %016x" : " %ld", (buf), (data), (n));\
8585
break; \
8686
case ONNX_TYPE_FLOAT16: \
87-
LOG_BUF_C_TYPE(const short, " %04x", buf, data, n); \
87+
LOG_BUF_C_TYPE(const short, " %04x", (buf), (data), (n)); \
8888
break; \
8989
case ONNX_TYPE_FLOAT: \
90-
LOG_BUF_C_TYPE(const float, hex ? " %08x" : " %f", buf, data, n); \
90+
LOG_BUF_C_TYPE(const float, (hex) ? " %08x" : " %f", (buf), (data), (n));\
9191
break; \
9292
case ONNX_TYPE_DOUBLE: \
93-
LOG_BUF_C_TYPE(const double, hex ? " %016x" : " %lf", buf, data, n); \
93+
LOG_BUF_C_TYPE(const double, (hex) ? " %016x" : " %lf", (buf), (data), (n));\
9494
break; \
9595
default: { \
96-
int __a = sprintf(buf, " unsupported data type %d ", type); \
96+
int __a = sprintf((buf), " unsupported data type %d ", (type)); \
9797
assert(__a >= 0 && "sprintf write error to buf"); \
9898
} \
9999
} \
100100
} while (0)
101101

102-
#define LOG_BUF(type, buf, data, n) LOG_BUF_ONNX_TYPE(type, buf, data, n, 0)
103-
#define LOG_XBUF(type, buf, data, n) LOG_BUF_ONNX_TYPE(type, buf, data, n, 1)
102+
#define LOG_BUF(type, buf, data, n) \
103+
LOG_BUF_ONNX_TYPE((type), (buf), (data), (n), 0)
104+
#define LOG_XBUF(type, buf, data, n) \
105+
LOG_BUF_ONNX_TYPE((type),(buf), (data), (n), 1)
104106

105107
#define LOG_CHAR_BUF(buf, data, n) \
106-
LOG_BUF_C_TYPE(const char, "%c", buf, data, n)
108+
LOG_BUF_C_TYPE(const char, "%c", (buf), (data), (n))
107109
#define LOG_CHAR_XBUF(buf, data, n) \
108-
LOG_BUF_C_TYPE(const char, " %02x", buf, data, n)
110+
LOG_BUF_C_TYPE(const char, " %02x", (buf), (data), (n))
109111
#define LOG_SHORT_BUF(buf, data, n) \
110-
LOG_BUF_C_TYPE(const short, " %d", buf, data, n)
112+
LOG_BUF_C_TYPE(const short, " %d", (buf), (data), (n))
111113
#define LOG_SHORT_XBUF(buf, data, n) \
112-
LOG_BUF_C_TYPE(const short, " %04x", buf, data, n)
113-
#define LOG_INT_BUF(buf, data, n) LOG_BUF_C_TYPE(const int, " %d", buf, data, n)
114+
LOG_BUF_C_TYPE(const short, " %04x", (buf), (data), (n))
115+
#define LOG_INT_BUF(buf, data, n) \
116+
LOG_BUF_C_TYPE(const int, " %d", (buf), (data), (n))
114117
#define LOG_INT_XBUF(buf, data, n) \
115-
LOG_BUF_C_TYPE(const int, " %08x", buf, data, n)
118+
LOG_BUF_C_TYPE(const int, " %08x", (buf), (data), (n))
116119
#define LOG_LONG_BUF(buf, data, n) \
117-
LOG_BUF_C_TYPE(const long, " %ld", buf, data, n)
120+
LOG_BUF_C_TYPE(const long, " %ld", (buf), (data), (n))
118121
#define LOG_LONG_XBUF(buf, data, n) \
119-
LOG_BUF_C_TYPE(const long, " %016x", buf, data, n)
122+
LOG_BUF_C_TYPE(const long, " %016x", (buf), (data), (n))
120123
#define LOG_FLOAT_BUF(buf, data, n) \
121-
LOG_BUF_C_TYPE(const float, " %f", buf, data, n)
124+
LOG_BUF_C_TYPE(const float, " %f", (buf), (data), (n))
122125
#define LOG_FLOAT_XBUF(buf, data, n) \
123-
LOG_BUF_C_TYPE(const float, " %08x", buf, data, n)
126+
LOG_BUF_C_TYPE(const float, " %08x", (buf), (data), (n))
124127
#define LOG_DOUBLE_BUF(buf, data, n) \
125-
LOG_BUF_C_TYPE(const double, " %lf", buf, data, n)
128+
LOG_BUF_C_TYPE(const double, " %lf", (buf), (data), (n))
126129
#define LOG_DOUBLE_XBUF(buf, data, n) \
127-
LOG_BUF_C_TYPE(const double, " %016x", buf, data, n)
130+
LOG_BUF_C_TYPE(const double, " %016x", (buf), (data),(n))
128131

129132
/* Main macro for log output */
130133
#define LOG_PRINTF(level, ...) \
131-
log_printf(level, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
134+
log_printf((level), __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
132135

133136
/* Generic log routine */
134137
extern void log_init(void);

0 commit comments

Comments
 (0)