Skip to content

Commit

Permalink
added filename and line number to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lslusarczyk committed Jan 29, 2025
1 parent 14f4a3b commit db49889
Show file tree
Hide file tree
Showing 47 changed files with 462 additions and 421 deletions.
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

add_definitions(-DUR_VERSION="${PROJECT_VERSION_MAJOR}")
add_definitions(-DUR_VALIDATION_LAYER_SUPPORTED_VERSION="${PROJECT_VERSION_MAJOR}")
string(LENGTH "${CMAKE_SOURCE_DIR}/" SRC_PATH_SIZE)
add_definitions("-DSRC_PATH_SIZE=${SRC_PATH_SIZE}") # for nicer log messages

add_subdirectory(common)
add_subdirectory(loader)
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/cuda/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
#define UR_CALL(Call, Result) \
{ \
if (PrintTrace) \
logger::always("UR ---> {}", #Call); \
URLOG_ALWAYS("UR ---> {}", #Call); \
Result = (Call); \
if (PrintTrace) \
logger::always("UR <--- {}({})", #Call, Result); \
URLOG_ALWAYS("UR <--- {}({})", #Call, Result); \
}

enum class CommandType {
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/cuda/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void checkErrorUR(CUresult Result, const char *Function, int Line,
<< "\n\tDescription: " << ErrorString
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
<< ":" << Line << "\n";
logger::error("{}", SS.str());
URLOG(ERR, "{}", SS.str());

if (std::getenv("PI_CUDA_ABORT") != nullptr ||
std::getenv("UR_CUDA_ABORT") != nullptr) {
Expand All @@ -73,7 +73,7 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line,
SS << "\nUR ERROR:"
<< "\n\tValue: " << Result << "\n\tFunction: " << Function
<< "\n\tSource Location: " << File << ":" << Line << "\n";
logger::error("{}", SS.str());
URLOG(ERR, "{}", SS.str());

if (std::getenv("PI_CUDA_ABORT") != nullptr) {
std::abort();
Expand All @@ -93,7 +93,7 @@ std::string getCudaVersionString() {
}

void detail::ur::die(const char *Message) {
logger::always("ur_die:{}", Message);
URLOG_ALWAYS("ur_die:{}", Message);
std::terminate();
}

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
std::getenv("UR_CUDA_ENABLE_IMAGE_SUPPORT") != nullptr) {
Enabled = true;
} else {
logger::always(
URLOG_ALWAYS(
"Images are not fully supported by the CUDA BE, their support is "
"disabled by default. Their partial support can be activated by "
"setting UR_CUDA_ENABLE_IMAGE_SUPPORT environment variable at "
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/cuda/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp(

// we don't support copying between different image types.
if (pSrcImageDesc->type != pDstImageDesc->type) {
logger::error(
"Unsupported copy operation between different type of images");
URLOG(ERR,
"Unsupported copy operation between different type of images");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down
8 changes: 4 additions & 4 deletions source/adapters/hip/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void checkErrorUR(amd_comgr_status_t Result, const char *Function, int Line,
<< "\n\tDescription: " << ErrorString
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
<< ":" << Line << "\n";
logger::error("{}", SS.str());
URLOG(ERR, "{}", SS.str());

if (std::getenv("PI_HIP_ABORT") != nullptr ||
std::getenv("UR_HIP_ABORT") != nullptr) {
Expand All @@ -109,7 +109,7 @@ void checkErrorUR(hipError_t Result, const char *Function, int Line,
<< "\n\tDescription: " << ErrorString
<< "\n\tFunction: " << Function << "\n\tSource Location: " << File
<< ":" << Line << "\n";
logger::error("{}", SS.str());
URLOG(ERR, "{}", SS.str());

if (std::getenv("PI_HIP_ABORT") != nullptr ||
std::getenv("UR_HIP_ABORT") != nullptr) {
Expand All @@ -129,7 +129,7 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line,
SS << "\nUR HIP ERROR:"
<< "\n\tValue: " << Result << "\n\tFunction: " << Function
<< "\n\tSource Location: " << File << ":" << Line << "\n";
logger::error("{}", SS.str());
URLOG(ERR, "{}", SS.str());

if (std::getenv("PI_HIP_ABORT") != nullptr ||
std::getenv("UR_HIP_ABORT") != nullptr) {
Expand All @@ -153,7 +153,7 @@ hipError_t getHipVersionString(std::string &Version) {
}

void detail::ur::die(const char *pMessage) {
logger::always("ur_die: {}", pMessage);
URLOG_ALWAYS("ur_die: {}", pMessage);
std::terminate();
}

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
if (std::getenv("UR_HIP_ENABLE_IMAGE_SUPPORT") != nullptr) {
Enabled = true;
} else {
logger::always(
URLOG_ALWAYS(
"Images are not fully supported by the HIP BE, their support is "
"disabled by default. Their partial support can be activated by "
"setting UR_HIP_ENABLE_IMAGE_SUPPORT environment variable at "
Expand Down
41 changes: 21 additions & 20 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ur_result_t initPlatforms(PlatformVec &platforms,
ZE2UR_CALL(zeDriverGet, (&ZeDriverGetCount, ZeDriverGetHandles.data()));
}
if (ZeDriverGetCount == 0 && GlobalAdapter->ZeInitDriversCount == 0) {
logger::error("\nNo Valid L0 Drivers found.\n");
URLOG(ERR, "\nNo Valid L0 Drivers found.\n");
return UR_RESULT_SUCCESS;
}

Expand All @@ -188,9 +188,10 @@ ur_result_t initPlatforms(PlatformVec &platforms,
// newer drivers.
if (ZeDriverGetProperties.driverVersion !=
ZeInitDriverProperties.driverVersion) {
logger::debug("\nzeDriverHandle {} added to the zeInitDrivers list "
"of possible handles.\n",
ZeDriverGetHandles[Y]);
URLOG(DEBUG,
"\nzeDriverHandle {} added to the zeInitDrivers list "
"of possible handles.\n",
ZeDriverGetHandles[Y]);
ZeDrivers.push_back(ZeDriverGetHandles[Y]);
}
}
Expand All @@ -201,7 +202,7 @@ ur_result_t initPlatforms(PlatformVec &platforms,
ZeDrivers.assign(ZeDriverGetHandles.begin(), ZeDriverGetHandles.end());
}
ZeDriverCount = ZeDrivers.size();
logger::debug("\n{} L0 Drivers found.\n", ZeDriverCount);
URLOG(DEBUG, "\n{} L0 Drivers found.\n", ZeDriverCount);
for (uint32_t I = 0; I < ZeDriverCount; ++I) {
// Keep track of the first platform init for this Driver
bool DriverPlatformInit = false;
Expand Down Expand Up @@ -351,8 +352,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
}

if (getenv("SYCL_ENABLE_PCI") != nullptr) {
logger::warning(
"WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n");
URLOG(WARN,
"WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n");
}

// TODO: We can still safely recover if something goes wrong during the
Expand All @@ -373,13 +374,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
if (UrL0InitAllDrivers) {
L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
}
logger::debug("\nzeInit with flags value of {}\n",
static_cast<int>(L0InitFlags));
URLOG(DEBUG, "\nzeInit with flags value of {}\n",
static_cast<int>(L0InitFlags));
GlobalAdapter->ZeInitResult = ZE_CALL_NOCHECK(zeInit, (L0InitFlags));
if (GlobalAdapter->ZeInitResult != ZE_RESULT_SUCCESS) {
const char *ErrorString = "Unknown";
zeParseError(GlobalAdapter->ZeInitResult, ErrorString);
logger::error("\nzeInit failed with {}\n", ErrorString);
URLOG(ERR, "\nzeInit failed with {}\n", ErrorString);
}

bool useInitDrivers = false;
Expand All @@ -395,9 +396,9 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
if (strncmp(versions[i].component_name, "loader",
strlen("loader")) == 0) {
loader_version = versions[i].component_lib_version;
logger::debug("\nLevel Zero Loader Version: {}.{}.{}\n",
loader_version.major, loader_version.minor,
loader_version.patch);
URLOG(DEBUG, "\nLevel Zero Loader Version: {}.{}.{}\n",
loader_version.major, loader_version.minor,
loader_version.patch);
break;
}
}
Expand All @@ -416,8 +417,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
(ze_pfnInitDrivers_t)ur_loader::LibLoader::getFunctionPtr(
processHandle, "zeInitDrivers");
if (GlobalAdapter->initDriversFunctionPtr) {
logger::debug("\nzeInitDrivers with flags value of {}\n",
static_cast<int>(GlobalAdapter->InitDriversDesc.flags));
URLOG(DEBUG, "\nzeInitDrivers with flags value of {}\n",
static_cast<int>(GlobalAdapter->InitDriversDesc.flags));
GlobalAdapter->ZeInitDriversResult =
ZE_CALL_NOCHECK(GlobalAdapter->initDriversFunctionPtr,
(&GlobalAdapter->ZeInitDriversCount, nullptr,
Expand All @@ -427,7 +428,7 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
} else {
const char *ErrorString = "Unknown";
zeParseError(GlobalAdapter->ZeInitDriversResult, ErrorString);
logger::error("\nzeInitDrivers failed with {}\n", ErrorString);
URLOG(ERR, "\nzeInitDrivers failed with {}\n", ErrorString);
}
}
}
Expand All @@ -445,12 +446,12 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()

// Absorb the ZE_RESULT_ERROR_UNINITIALIZED and just return 0 Platforms.
if (*GlobalAdapter->ZeResult == ZE_RESULT_ERROR_UNINITIALIZED) {
logger::error("Level Zero Uninitialized\n");
URLOG(ERR, "Level Zero Uninitialized\n");
result = std::move(platforms);
return;
}
if (*GlobalAdapter->ZeResult != ZE_RESULT_SUCCESS) {
logger::error("Level Zero initialization failure\n");
URLOG(ERR, "Level Zero initialization failure\n");
result = ze2urResult(*GlobalAdapter->ZeResult);

return;
Expand Down Expand Up @@ -499,8 +500,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
GlobalAdapter->getSysManDriversFunctionPtr &&
GlobalAdapter->sysManInitFunctionPtr) {
ze_init_flags_t L0ZesInitFlags = 0;
logger::debug("\nzesInit with flags value of {}\n",
static_cast<int>(L0ZesInitFlags));
URLOG(DEBUG, "\nzesInit with flags value of {}\n",
static_cast<int>(L0ZesInitFlags));
GlobalAdapter->ZesResult = ZE_CALL_NOCHECK(
GlobalAdapter->sysManInitFunctionPtr, (L0ZesInitFlags));
} else {
Expand Down
24 changes: 13 additions & 11 deletions source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// Print the name of a variable and its value in the L0 debug log
#define DEBUG_LOG(VAR) logger::debug(#VAR " {}", VAR);
#define DEBUG_LOG(VAR) URLOG(DEBUG, #VAR " {}", VAR);

namespace {

Expand All @@ -44,17 +44,19 @@ bool checkImmediateAppendSupport(ur_context_handle_t Context,
const bool EnableAppendPath = std::atoi(UrRet) == 1;

if (EnableAppendPath && !Device->ImmCommandListUsed) {
logger::error("{} is set but immediate command-lists are currently "
"disabled. Immediate command-lists are "
"required to use the immediate append path.",
AppendEnvVarName);
URLOG(ERR,
"{} is set but immediate command-lists are currently "
"disabled. Immediate command-lists are "
"required to use the immediate append path.",
AppendEnvVarName);
std::abort();
}
if (EnableAppendPath && !DriverSupportsImmediateAppend) {
logger::error("{} is set but "
"the current driver does not support the "
"zeCommandListImmediateAppendCommandListsExp entrypoint.",
AppendEnvVarName);
URLOG(ERR,
"{} is set but "
"the current driver does not support the "
"zeCommandListImmediateAppendCommandListsExp entrypoint.",
AppendEnvVarName);
std::abort();
}

Expand Down Expand Up @@ -1775,7 +1777,7 @@ ur_result_t validateCommandDesc(
auto SupportedFeatures =
Command->CommandBuffer->Device->ZeDeviceMutableCmdListsProperties
->mutableCommandFlags;
logger::debug("Mutable features supported by device {}", SupportedFeatures);
URLOG(DEBUG, "Mutable features supported by device {}", SupportedFeatures);

UR_ASSERT(
!CommandDesc->hNewKernel ||
Expand All @@ -1801,7 +1803,7 @@ ur_result_t validateCommandDesc(
if (NewGlobalWorkOffset) {
if (!CommandBuffer->Context->getPlatform()
->ZeDriverGlobalOffsetExtensionFound) {
logger::error("No global offset extension found on this driver");
URLOG(ERR, "No global offset extension found on this driver");
return UR_RESULT_ERROR_INVALID_VALUE;
}
}
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/level_zero/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ bool setEnvVar(const char *name, const char *value) {
int Res = setenv(name, value, 1);
#endif
if (Res != 0) {
logger::debug(
"UR L0 Adapter was unable to set the environment variable: {}", name);
URLOG(DEBUG, "UR L0 Adapter was unable to set the environment variable: {}",
name);
return false;
}
return true;
Expand Down Expand Up @@ -139,7 +139,7 @@ void zeParseError(ze_result_t ZeError, const char *&ErrorString) {

ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
const char *ZeArgs, bool TraceError) {
logger::debug("ZE ---> {}{}", ZeName, ZeArgs);
URLOG(DEBUG, "ZE ---> {}{}", ZeName, ZeArgs);

if (ZeResult == ZE_RESULT_SUCCESS) {
if (UrL0LeaksDebug) {
Expand All @@ -151,7 +151,7 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
if (TraceError) {
const char *ErrorString = "Unknown";
zeParseError(ZeResult, ErrorString);
logger::error("Error ({}) in {}", ErrorString, ZeName);
URLOG(ERR, "Error ({}) in {}", ErrorString, ZeName);
}
return ZeResult;
}
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ static auto getUrResultString = [](ur_result_t Result) {
#define UR_CALL(Call) \
{ \
if (PrintTrace) \
logger::always("UR ---> {}", #Call); \
URLOG_ALWAYS("UR ---> {}", #Call); \
ur_result_t Result = (Call); \
if (PrintTrace) \
logger::always("UR <--- {}({})", #Call, getUrResultString(Result)); \
URLOG_ALWAYS("UR <--- {}({})", #Call, getUrResultString(Result)); \
if (Result != UR_RESULT_SUCCESS) \
return Result; \
}
Expand All @@ -186,10 +186,10 @@ static auto getUrResultString = [](ur_result_t Result) {
#define UR_CALL_THROWS(Call) \
{ \
if (PrintTrace) \
logger::always("UR ---> {}", #Call); \
URLOG_ALWAYS("UR ---> {}", #Call); \
ur_result_t Result = (Call); \
if (PrintTrace) \
logger::always("UR <--- {}({})", #Call, getUrResultString(Result)); \
URLOG_ALWAYS("UR <--- {}({})", #Call, getUrResultString(Result)); \
if (Result != UR_RESULT_SUCCESS) \
throw Result; \
}
Expand Down
Loading

0 comments on commit db49889

Please sign in to comment.