Skip to content

Commit 76f8dcf

Browse files
committed
optimize UR_CALL
1 parent a123482 commit 76f8dcf

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

unified-runtime/source/ur/ur.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <cassert>
1414

1515
// Controls tracing UR calls from within the UR itself.
16-
bool PrintTrace = [] {
16+
const bool PrintTrace = [] {
1717
const char *UrRet = std::getenv("SYCL_UR_TRACE");
1818
const char *PiRet = std::getenv("SYCL_PI_TRACE");
1919
const char *Trace = UrRet ? UrRet : (PiRet ? PiRet : nullptr);

unified-runtime/source/ur/ur.hpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,63 @@
2929
#include "logger/ur_logger.hpp"
3030
#include "ur_util.hpp"
3131

32+
#include "llvm/Support/Compiler.h"
33+
3234
// Helper for one-liner validation. Not really an assertion. To be renamed.
3335
// For assertion that abort program use UR_DASSERT or UR_FASSERT from
3436
// ur_logger.hpp
3537
#define UR_ASSERT(condition, error) \
36-
if (!(condition)) \
38+
if (LLVM_UNLIKELY(!(condition))) \
3739
return error;
3840

3941
// Trace an internal UR call; returns in case of an error.
4042
#define UR_CALL(Call) \
4143
{ \
42-
if (PrintTrace) \
44+
ur_result_t Result; \
45+
if (LLVM_UNLIKELY(PrintTrace)) { \
4346
UR_LOG(QUIET, "UR ---> {}", #Call); \
44-
ur_result_t Result = (Call); \
45-
if (PrintTrace) \
47+
Result = (Call); \
4648
UR_LOG(QUIET, "UR <--- {}({})", #Call, Result); \
49+
} else { \
50+
Result = (Call); \
51+
} \
4752
if (Result != UR_RESULT_SUCCESS) \
4853
return Result; \
4954
}
5055

5156
// Trace an internal UR call; throw in case of an error.
5257
#define UR_CALL_THROWS(Call) \
5358
{ \
54-
if (PrintTrace) \
59+
ur_result_t Result; \
60+
if (LLVM_UNLIKELY(PrintTrace)) { \
5561
UR_LOG(QUIET, "UR ---> {}", #Call); \
56-
ur_result_t Result = (Call); \
57-
if (PrintTrace) \
62+
Result = (Call); \
5863
UR_LOG(QUIET, "UR <--- {}({})", #Call, Result); \
64+
} else { \
65+
Result = (Call); \
66+
} \
5967
if (Result != UR_RESULT_SUCCESS) \
6068
throw Result; \
6169
}
6270

6371
// Trace an internal UR call; ignore errors (useful in destructors).
6472
#define UR_CALL_NOCHECK(Call) \
6573
{ \
66-
if (PrintTrace) \
74+
if (LLVM_UNLIKELY(PrintTrace)) { \
6775
UR_LOG(QUIET, "UR ---> {}", #Call); \
68-
(void)(Call); \
69-
if (PrintTrace) \
76+
(void)(Call); \
7077
UR_LOG(QUIET, "UR <--- {}", #Call); \
78+
} else { \
79+
(void)(Call); \
80+
} \
7181
}
7282

7383
template <class To, class From> To ur_cast(From Value) {
7484
// TODO: see if more sanity checks are possible.
75-
assert(sizeof(From) == sizeof(To));
85+
static_assert(sizeof(From) == sizeof(To),
86+
"Size of From and To must be equal");
87+
// TODO: a very bad cast, change a to static_cast and fix all compiler
88+
// warnings
7689
return (To)(Value);
7790
}
7891

@@ -214,7 +227,7 @@ struct ur_dditable_t;
214227
struct ur_platform {};
215228

216229
// Controls tracing UR calls from within the UR itself.
217-
extern bool PrintTrace;
230+
extern const bool PrintTrace;
218231

219232
// The getInfo*/ReturnHelper facilities provide shortcut way of
220233
// writing return bytes for the various getInfo APIs.

0 commit comments

Comments
 (0)