Skip to content
Draft
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 unified-runtime/cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ function(add_ur_target_compile_options name)
)
endif()
endif()
target_include_directories(${name} PRIVATE "${PROJECT_SOURCE_DIR}/../llvm/include")
target_include_directories(${name} PRIVATE "${PROJECT_BINARY_DIR}/include")
endfunction()

function(add_ur_target_link_options name)
Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/ur/ur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <cassert>

// Controls tracing UR calls from within the UR itself.
bool PrintTrace = [] {
const bool PrintTrace = [] {
const char *UrRet = std::getenv("SYCL_UR_TRACE");
const char *PiRet = std::getenv("SYCL_PI_TRACE");
const char *Trace = UrRet ? UrRet : (PiRet ? PiRet : nullptr);
Expand Down
37 changes: 25 additions & 12 deletions unified-runtime/source/ur/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,63 @@
#include "logger/ur_logger.hpp"
#include "ur_util.hpp"

#include "llvm/Support/Compiler.h"

// Helper for one-liner validation. Not really an assertion. To be renamed.
// For assertion that abort program use UR_DASSERT or UR_FASSERT from
// ur_logger.hpp
#define UR_ASSERT(condition, error) \
if (!(condition)) \
if (LLVM_UNLIKELY(!(condition))) \
return error;

// Trace an internal UR call; returns in case of an error.
#define UR_CALL(Call) \
{ \
if (PrintTrace) \
ur_result_t Result; \
if (LLVM_UNLIKELY(PrintTrace)) { \
UR_LOG(QUIET, "UR ---> {}", #Call); \
ur_result_t Result = (Call); \
if (PrintTrace) \
Result = (Call); \
UR_LOG(QUIET, "UR <--- {}({})", #Call, Result); \
} else { \
Result = (Call); \
} \
if (Result != UR_RESULT_SUCCESS) \
return Result; \
}

// Trace an internal UR call; throw in case of an error.
#define UR_CALL_THROWS(Call) \
{ \
if (PrintTrace) \
ur_result_t Result; \
if (LLVM_UNLIKELY(PrintTrace)) { \
UR_LOG(QUIET, "UR ---> {}", #Call); \
ur_result_t Result = (Call); \
if (PrintTrace) \
Result = (Call); \
UR_LOG(QUIET, "UR <--- {}({})", #Call, Result); \
} else { \
Result = (Call); \
} \
if (Result != UR_RESULT_SUCCESS) \
throw Result; \
}

// Trace an internal UR call; ignore errors (useful in destructors).
#define UR_CALL_NOCHECK(Call) \
{ \
if (PrintTrace) \
if (LLVM_UNLIKELY(PrintTrace)) { \
UR_LOG(QUIET, "UR ---> {}", #Call); \
(void)(Call); \
if (PrintTrace) \
(void)(Call); \
UR_LOG(QUIET, "UR <--- {}", #Call); \
} else { \
(void)(Call); \
} \
}

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

Expand Down Expand Up @@ -214,7 +227,7 @@ struct ur_dditable_t;
struct ur_platform {};

// Controls tracing UR calls from within the UR itself.
extern bool PrintTrace;
extern const bool PrintTrace;

// The getInfo*/ReturnHelper facilities provide shortcut way of
// writing return bytes for the various getInfo APIs.
Expand Down
Loading