Skip to content

Commit

Permalink
change urprint to the new logger framework
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Plewa <lukasz.plewa@intel.com>
  • Loading branch information
lplewa committed Nov 9, 2023
1 parent 2f44433 commit 953c95c
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 185 deletions.
2 changes: 2 additions & 0 deletions source/adapters/level_zero/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
//
//===----------------------------------------------------------------------===//

#include "logger/ur_logger.hpp"
#include <atomic>
#include <mutex>

struct ur_adapter_handle_t_ {
std::atomic<uint32_t> RefCount = 0;
std::mutex Mutex;
logger::Logger &logger = logger::get_logger("level_zero");
};

extern ur_adapter_handle_t_ Adapter;
57 changes: 31 additions & 26 deletions source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//
//===----------------------------------------------------------------------===//
#include "command_buffer.hpp"
#include "logger/ur_logger.hpp"
#include "ur_level_zero.hpp"

/* Command-buffer Extension
Expand Down Expand Up @@ -182,16 +183,17 @@ ur_result_t calculateKernelWorkDimensions(
--GroupSize[I];
}
if (GlobalWorkSize[I] / GroupSize[I] > UINT32_MAX) {
urPrint("urCommandBufferAppendKernelLaunchExp: can't find a WG size "
"suitable for global work size > UINT32_MAX\n");
logger::debug(
"urCommandBufferAppendKernelLaunchExp: can't find a WG size "
"suitable for global work size > UINT32_MAX");
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
}
WG[I] = GroupSize[I];
}
urPrint(
"urCommandBufferAppendKernelLaunchExp: using computed WG size = {%d, "
"%d, %d}\n",
WG[0], WG[1], WG[2]);
logger::debug("urCommandBufferAppendKernelLaunchExp: using computed WG "
"size = {{{}, "
"{}, {}}}",
WG[0], WG[1], WG[2]);
}
}

Expand Down Expand Up @@ -219,30 +221,33 @@ ur_result_t calculateKernelWorkDimensions(
break;

default:
urPrint("urCommandBufferAppendKernelLaunchExp: unsupported work_dim\n");
logger::error("urCommandBufferAppendKernelLaunchExp: unsupported work_dim");
return UR_RESULT_ERROR_INVALID_VALUE;
}

// Error handling for non-uniform group size case
if (GlobalWorkSize[0] !=
size_t(ZeThreadGroupDimensions.groupCountX) * WG[0]) {
urPrint("urCommandBufferAppendKernelLaunchExp: invalid work_dim. The range "
"is not a "
"multiple of the group size in the 1st dimension\n");
logger::error(
"urCommandBufferAppendKernelLaunchExp: invalid work_dim. The range "
"is not a "
"multiple of the group size in the 1st dimension");
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
}
if (GlobalWorkSize[1] !=
size_t(ZeThreadGroupDimensions.groupCountY) * WG[1]) {
urPrint("urCommandBufferAppendKernelLaunchExp: invalid work_dim. The range "
"is not a "
"multiple of the group size in the 2nd dimension\n");
logger::error(
"urCommandBufferAppendKernelLaunchExp: invalid work_dim. The range "
"is not a "
"multiple of the group size in the 2nd dimension");
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
}
if (GlobalWorkSize[2] !=
size_t(ZeThreadGroupDimensions.groupCountZ) * WG[2]) {
urPrint("urCommandBufferAppendKernelLaunchExp: invalid work_dim. The range "
"is not a "
"multiple of the group size in the 3rd dimension\n");
logger::error(
"urCommandBufferAppendKernelLaunchExp: invalid work_dim. The range "
"is not a "
"multiple of the group size in the 3rd dimension");
return UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE;
}

Expand Down Expand Up @@ -306,9 +311,9 @@ static ur_result_t enqueueCommandBufferMemCopyHelper(
(CommandBuffer->ZeCommandList, Dst, Src, Size,
LaunchEvent->ZeEvent, ZeEventList.size(), ZeEventList.data()));

urPrint("calling zeCommandListAppendMemoryCopy() with"
" ZeEvent %#" PRIxPTR "\n",
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
logger::debug("calling zeCommandListAppendMemoryCopy() with"
" ZeEvent {}",
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -372,9 +377,9 @@ static ur_result_t enqueueCommandBufferMemCopyRectHelper(
DstSlicePitch, Src, &ZeSrcRegion, SrcPitch, SrcSlicePitch,
LaunchEvent->ZeEvent, ZeEventList.size(), ZeEventList.data()));

urPrint("calling zeCommandListAppendMemoryCopyRegion() with"
" ZeEvent %#" PRIxPTR "\n",
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
logger::debug("calling zeCommandListAppendMemoryCopyRegion() with"
" ZeEvent {}",
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -483,7 +488,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
if (GlobalWorkOffset != NULL) {
if (!CommandBuffer->Context->getPlatform()
->ZeDriverGlobalOffsetExtensionFound) {
urPrint("No global offset extension found on this driver\n");
logger::debug("No global offset extension found on this driver");
return UR_RESULT_ERROR_INVALID_VALUE;
}

Expand Down Expand Up @@ -538,9 +543,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
&ZeThreadGroupDimensions, LaunchEvent->ZeEvent,
ZeEventList.size(), ZeEventList.data()));

urPrint("calling zeCommandListAppendLaunchKernel() with"
" ZeEvent %#" PRIxPTR "\n",
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));
logger::debug("calling zeCommandListAppendLaunchKernel() with"
" ZeEvent {}",
ur_cast<std::uintptr_t>(LaunchEvent->ZeEvent));

return UR_RESULT_SUCCESS;
}
Expand Down
18 changes: 5 additions & 13 deletions source/adapters/level_zero/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//===----------------------------------------------------------------------===//

#include "common.hpp"
#include "logger/ur_logger.hpp"
#include "usm.hpp"

ur_result_t ze2urResult(ze_result_t ZeResult) {
Expand Down Expand Up @@ -63,15 +64,6 @@ ur_result_t ze2urResult(ze_result_t ZeResult) {
}
}

void urPrint(const char *Format, ...) {
if (UrL0Debug & UR_L0_DEBUG_BASIC) {
va_list Args;
va_start(Args, Format);
vfprintf(stderr, Format, Args);
va_end(Args);
}
}

usm::DisjointPoolAllConfigs DisjointPoolConfigInstance =
InitializeDisjointPoolConfig();

Expand All @@ -84,8 +76,8 @@ bool setEnvVar(const char *name, const char *value) {
int Res = setenv(name, value, 1);
#endif
if (Res != 0) {
urPrint("UR L0 Adapter was unable to set the environment variable: %s\n",
name);
logger::debug(
"UR L0 Adapter was unable to set the environment variable: {}", name);
return false;
}
return true;
Expand Down Expand Up @@ -147,7 +139,7 @@ inline 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) {
urPrint("ZE ---> %s%s\n", ZeName, ZeArgs);
logger::debug("ZE ---> {}{}", ZeName, ZeArgs);

if (UrL0Debug & UR_L0_DEBUG_CALL_COUNT) {
++(*ZeCallCount)[ZeName];
Expand All @@ -156,7 +148,7 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
if (ZeResult && TraceError) {
const char *ErrorString = "Unknown";
zeParseError(ZeResult, ErrorString);
urPrint("Error (%s) in %s\n", ErrorString, ZeName);
logger::error("Error ({}) in {}", ErrorString, ZeName);
}
return ZeResult;
}
Expand Down
6 changes: 0 additions & 6 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ class ZeCall {
// setting environment variables.
bool setEnvVar(const char *name, const char *value);

// Prints to stderr if UR_L0_DEBUG allows it
void urPrint(const char *Format, ...);

// Helper for one-liner validation
#define UR_ASSERT(condition, error) \
if (!(condition)) \
Expand Down Expand Up @@ -297,9 +294,6 @@ template <class T> struct ZesStruct : public T {
// setting environment variables.
bool setEnvVar(const char *name, const char *value);

// Prints to stderr if UR_L0_DEBUG allows it
void urPrint(const char *Format, ...);

// Helper for one-liner validation
#define UR_ASSERT(condition, error) \
if (!(condition)) \
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string.h>

#include "context.hpp"
#include "logger/ur_logger.hpp"
#include "ur_level_zero.hpp"

UR_APIEXPORT ur_result_t UR_APICALL urContextCreate(
Expand Down Expand Up @@ -174,7 +175,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter(
std::ignore = Context;
std::ignore = Deleter;
std::ignore = UserData;
urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__);
logger::error("{} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down Expand Up @@ -508,7 +509,8 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
if (ProfilingEnabled)
ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
urPrint("ze_event_pool_desc_t flags set to: %d\n", ZeEventPoolDesc.flags);
logger::debug("ze_event_pool_desc_t flags set to: {}",
ZeEventPoolDesc.flags);

std::vector<ze_device_handle_t> ZeDevices;
std::for_each(
Expand Down
23 changes: 12 additions & 11 deletions source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//===----------------------------------------------------------------------===//

#include "device.hpp"
#include "logger/ur_logger.hpp"
#include "ur_level_zero.hpp"
#include <algorithm>
#include <climits>
Expand Down Expand Up @@ -65,7 +66,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
break;
default:
Matched = false;
urPrint("Unknown device type");
logger::warning("Unknown device type");
break;
}
if (Matched)
Expand Down Expand Up @@ -114,7 +115,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
case ZE_DEVICE_TYPE_FPGA:
return ReturnValue(UR_DEVICE_TYPE_FPGA);
default:
urPrint("This device type is not supported\n");
logger::error("This device type is not supported");
return UR_RESULT_ERROR_INVALID_VALUE;
}
}
Expand Down Expand Up @@ -799,8 +800,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
}

default:
urPrint("Unsupported ParamName in urGetDeviceInfo\n");
urPrint("ParamName=%d(0x%x)\n", ParamName, ParamName);
logger::error("Unsupported ParamName in urGetDeviceInfo");
logger::error("ParamName={}", ParamName);
return UR_RESULT_ERROR_INVALID_VALUE;
}

Expand Down Expand Up @@ -842,8 +843,8 @@ getRangeOfAllowedCopyEngines(const ur_device_handle_t &Device) {
int UpperCopyEngineIndex = std::stoi(CopyEngineRange.substr(pos + 1));
if ((LowerCopyEngineIndex > UpperCopyEngineIndex) ||
(LowerCopyEngineIndex < -1) || (UpperCopyEngineIndex < -1)) {
urPrint("UR_L0_LEVEL_ZERO_USE_COPY_ENGINE: invalid value provided, "
"default set.\n");
logger::error("UR_L0_LEVEL_ZERO_USE_COPY_ENGINE: invalid value provided, "
"default set.");
LowerCopyEngineIndex = 0;
UpperCopyEngineIndex = INT_MAX;
}
Expand Down Expand Up @@ -981,7 +982,7 @@ ur_result_t ur_device_handle_t_::initialize(int SubSubDeviceOrdinal,
if (numQueueGroups == 0) {
return UR_RESULT_ERROR_UNKNOWN;
}
urPrint("NOTE: Number of queue groups = %d\n", numQueueGroups);
logger::info("Number of queue groups = {}", numQueueGroups);
std::vector<ZeStruct<ze_command_queue_group_properties_t>>
QueueGroupProperties(numQueueGroups);
ZE2UR_CALL(zeDeviceGetCommandQueueGroupProperties,
Expand Down Expand Up @@ -1034,14 +1035,14 @@ ur_result_t ur_device_handle_t_::initialize(int SubSubDeviceOrdinal,
}
}
if (QueueGroup[queue_group_info_t::MainCopy].ZeOrdinal < 0)
urPrint("NOTE: main blitter/copy engine is not available\n");
logger::info("main blitter/copy engine is not available");
else
urPrint("NOTE: main blitter/copy engine is available\n");
logger::info("main blitter/copy engine is available");

if (QueueGroup[queue_group_info_t::LinkCopy].ZeOrdinal < 0)
urPrint("NOTE: link blitter/copy engines are not available\n");
logger::info("link blitter/copy engines are not available");
else
urPrint("NOTE: link blitter/copy engines are available\n");
logger::info("link blitter/copy engines are available");
}
}

Expand Down
23 changes: 11 additions & 12 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@

#include "common.hpp"
#include "event.hpp"
#include "logger/ur_logger.hpp"
#include "ur_level_zero.hpp"

void printZeEventList(const _ur_ze_event_list_t &UrZeEventList) {
if (UrL0Debug & UR_L0_DEBUG_BASIC) {
urPrint(" NumEventsInWaitList %d:", UrZeEventList.Length);
std::stringstream ss;
ss << " NumEventsInWaitList" << UrZeEventList.Length << ":";

for (uint32_t I = 0; I < UrZeEventList.Length; I++) {
urPrint(" %#llx", ur_cast<std::uintptr_t>(UrZeEventList.ZeEventList[I]));
}

urPrint("\n");
for (uint32_t I = 0; I < UrZeEventList.Length; I++) {
ss << " " << ur_cast<std::uintptr_t>(UrZeEventList.ZeEventList[I]);
}
logger::debug(ss.str().c_str());
}

// This is an experimental option that allows the use of multiple command lists
Expand Down Expand Up @@ -428,8 +427,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(
return ReturnValue(Event->RefCount.load());
}
default:
urPrint("Unsupported ParamName in urEventGetInfo: ParamName=%d(%x)\n",
PropName, PropName);
logger::error("Unsupported ParamName in urEventGetInfo: ParamName={}",
PropName);
return UR_RESULT_ERROR_INVALID_VALUE;
}

Expand Down Expand Up @@ -498,7 +497,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
//
return ReturnValue(uint64_t{0});
default:
urPrint("urEventGetProfilingInfo: not supported ParamName\n");
logger::error("urEventGetProfilingInfo: not supported ParamName");
return UR_RESULT_ERROR_INVALID_VALUE;
}

Expand Down Expand Up @@ -594,7 +593,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait(
die("The host-visible proxy event missing");

ze_event_handle_t ZeEvent = HostVisibleEvent->ZeEvent;
urPrint("ZeEvent = %#llx\n", ur_cast<std::uintptr_t>(ZeEvent));
logger::debug("ZeEvent = {}", ur_cast<std::uintptr_t>(ZeEvent));
ZE2UR_CALL(zeHostSynchronize, (ZeEvent));
Event->Completed = true;
}
Expand Down Expand Up @@ -742,7 +741,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventSetCallback(
std::ignore = ExecStatus;
std::ignore = Notify;
std::ignore = UserData;
urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__);
logger::error("[UR][L0] {} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down
Loading

0 comments on commit 953c95c

Please sign in to comment.