diff --git a/source/adapters/level_zero/adapter.cpp b/source/adapters/level_zero/adapter.cpp index 39a0934b4f..694c5271ba 100644 --- a/source/adapters/level_zero/adapter.cpp +++ b/source/adapters/level_zero/adapter.cpp @@ -19,6 +19,21 @@ ur_adapter_handle_t_ *GlobalAdapter = new ur_adapter_handle_t_(); ur_adapter_handle_t_ *GlobalAdapter; #endif +class ur_legacy_sink : public logger::Sink { +public: + ur_legacy_sink(std::string logger_name = "", bool skip_prefix = true) + : Sink(std::move(logger_name), skip_prefix) { + this->ostream = &std::cerr; + } + + virtual void print([[maybe_unused]] logger::Level level, + const std::string &msg) override { + fprintf(stderr, "%s", msg.c_str()); + } + + ~ur_legacy_sink() = default; +}; + ur_result_t initPlatforms(PlatformVec &platforms) noexcept try { uint32_t ZeDriverCount = 0; ZE2UR_CALL(zeDriverGet, (&ZeDriverCount, nullptr)); @@ -44,7 +59,18 @@ ur_result_t initPlatforms(PlatformVec &platforms) noexcept try { ur_result_t adapterStateInit() { return UR_RESULT_SUCCESS; } -ur_adapter_handle_t_::ur_adapter_handle_t_() { +ur_adapter_handle_t_::ur_adapter_handle_t_() + : logger(logger::get_logger("level_zero")) { + + if (UrL0Debug & UR_L0_DEBUG_BASIC) { + logger.setLegacySink(std::make_unique()); + }; + + if (UrL0Debug & UR_L0_DEBUG_VALIDATION) { + setEnvVar("ZE_ENABLE_VALIDATION_LAYER", "1"); + setEnvVar("ZE_ENABLE_PARAMETER_VALIDATION", "1"); + } + PlatformCache.Compute = [](Result &result) { static std::once_flag ZeCallCountInitialized; try { @@ -68,7 +94,7 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() { } if (getenv("SYCL_ENABLE_PCI") != nullptr) { - urPrint( + logger::warning( "WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n"); } @@ -91,8 +117,9 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() { return; } if (*GlobalAdapter->ZeResult != ZE_RESULT_SUCCESS) { - urPrint("zeInit: Level Zero initialization failure\n"); + logger::error("zeInit: Level Zero initialization failure\n"); result = ze2urResult(*GlobalAdapter->ZeResult); + return; } @@ -157,10 +184,10 @@ ur_result_t adapterStateTeardown() { // zeMemAllocShared = 0 \---> zeMemFree = 1 // // clang-format on - - fprintf(stderr, "Check balance of create/destroy calls\n"); - fprintf(stderr, - "----------------------------------------------------------\n"); + // TODO: use logger to print this messages + std::cerr << "Check balance of create/destroy calls\n"; + std::cerr << "----------------------------------------------------------\n"; + std::stringstream ss; for (const auto &Row : CreateDestroySet) { int diff = 0; for (auto I = Row.begin(); I != Row.end();) { @@ -171,23 +198,30 @@ ur_result_t adapterStateTeardown() { bool Last = (++I == Row.end()); if (Last) { - fprintf(stderr, " \\--->"); + ss << " \\--->"; diff -= ZeCount; } else { diff += ZeCount; if (!First) { - fprintf(stderr, " | \n"); + ss << " | "; + std::cerr << ss.str() << "\n"; + ss.str(""); + ss.clear(); } } - - fprintf(stderr, "%30s = %-5d", ZeName, ZeCount); + ss << std::setw(30) << std::right << ZeName; + ss << " = "; + ss << std::setw(5) << std::left << ZeCount; } if (diff) { LeakFound = true; - fprintf(stderr, " ---> LEAK = %d", diff); + ss << " ---> LEAK = " << diff; } - fprintf(stderr, "\n"); + + std::cerr << ss.str() << '\n'; + ss.str(""); + ss.clear(); } ZeCallCount->clear(); diff --git a/source/adapters/level_zero/adapter.hpp b/source/adapters/level_zero/adapter.hpp index 1fdf3a9294..5de83b02e4 100644 --- a/source/adapters/level_zero/adapter.hpp +++ b/source/adapters/level_zero/adapter.hpp @@ -8,6 +8,7 @@ // //===----------------------------------------------------------------------===// +#include "logger/ur_logger.hpp" #include #include #include @@ -16,6 +17,8 @@ using PlatformVec = std::vector>; +class ur_legacy_sink; + struct ur_adapter_handle_t_ { ur_adapter_handle_t_(); std::atomic RefCount = 0; @@ -23,6 +26,7 @@ struct ur_adapter_handle_t_ { std::optional ZeResult; ZeCache> PlatformCache; + logger::Logger &logger; }; extern ur_adapter_handle_t_ *GlobalAdapter; diff --git a/source/adapters/level_zero/command_buffer.cpp b/source/adapters/level_zero/command_buffer.cpp index d38bac92f6..959c3f4bdb 100644 --- a/source/adapters/level_zero/command_buffer.cpp +++ b/source/adapters/level_zero/command_buffer.cpp @@ -8,6 +8,7 @@ // //===----------------------------------------------------------------------===// #include "command_buffer.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" /* L0 Command-buffer Extension Doc see: @@ -140,16 +141,16 @@ ur_result_t calculateKernelWorkDimensions( while (GlobalWorkSize3D[I] % GroupSize[I]) { --GroupSize[I]; } - if (GlobalWorkSize3D[I] / GroupSize[I] > UINT32_MAX) { - urPrint("calculateKernelWorkDimensions: can't find a WG size " - "suitable for global work size > UINT32_MAX\n"); + if (GlobalWorkSize[I] / GroupSize[I] > UINT32_MAX) { + logger::debug("calculateKernelWorkDimensions: 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("calculateKernelWorkDimensions: using computed WG size = {%d, " - "%d, %d}\n", - WG[0], WG[1], WG[2]); + logger::debug("calculateKernelWorkDimensions: using computed WG " + "size = {{{}, {}, {}}}", + WG[0], WG[1], WG[2]); } } @@ -177,30 +178,27 @@ ur_result_t calculateKernelWorkDimensions( break; default: - urPrint("calculateKernelWorkDimensions: unsupported work_dim\n"); + logger::error("calculateKernelWorkDimensions: unsupported work_dim"); return UR_RESULT_ERROR_INVALID_VALUE; } // Error handling for non-uniform group size case if (GlobalWorkSize3D[0] != size_t(ZeThreadGroupDimensions.groupCountX) * WG[0]) { - urPrint("calculateKernelWorkDimensions: invalid work_dim. The range " - "is not a " - "multiple of the group size in the 1st dimension\n"); + logger::error("calculateKernelWorkDimensions: 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 (GlobalWorkSize3D[1] != size_t(ZeThreadGroupDimensions.groupCountY) * WG[1]) { - urPrint("calculateKernelWorkDimensions: invalid work_dim. The range " - "is not a " - "multiple of the group size in the 2nd dimension\n"); + logger::error("calculateKernelWorkDimensions: 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 (GlobalWorkSize3D[2] != size_t(ZeThreadGroupDimensions.groupCountZ) * WG[2]) { - urPrint("calculateKernelWorkDimensions: invalid work_dim. The range " - "is not a " - "multiple of the group size in the 3rd dimension\n"); + logger::error("calculateKernelWorkDimensions: 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; } @@ -268,9 +266,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(LaunchEvent->ZeEvent)); + logger::debug("calling zeCommandListAppendMemoryCopy() with" + " ZeEvent {}", + ur_cast(LaunchEvent->ZeEvent)); return UR_RESULT_SUCCESS; } @@ -335,9 +333,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(LaunchEvent->ZeEvent)); + logger::debug("calling zeCommandListAppendMemoryCopyRegion() with" + " ZeEvent {}", + ur_cast(LaunchEvent->ZeEvent)); return UR_RESULT_SUCCESS; } @@ -378,9 +376,9 @@ static ur_result_t enqueueCommandBufferFillHelper( (CommandBuffer->ZeCommandList, Ptr, Pattern, PatternSize, Size, LaunchEvent->ZeEvent, ZeEventList.size(), ZeEventList.data())); - urPrint("calling zeCommandListAppendMemoryFill() with" - " ZeEvent %#lx\n", - ur_cast(LaunchEvent->ZeEvent)); + logger::debug("calling zeCommandListAppendMemoryFill() with" + " ZeEvent {}", + ur_cast(LaunchEvent->ZeEvent)); return UR_RESULT_SUCCESS; } @@ -519,7 +517,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; } @@ -606,9 +604,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(LaunchEvent->ZeEvent)); + logger::debug("calling zeCommandListAppendLaunchKernel() with" + " ZeEvent {}", + ur_cast(LaunchEvent->ZeEvent)); return UR_RESULT_SUCCESS; } @@ -1068,7 +1066,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp( if (NewGlobalWorkOffset && Dim > 0) { if (!CommandBuffer->Context->getPlatform() ->ZeDriverGlobalOffsetExtensionFound) { - urPrint("No global offset extension found on this driver\n"); + logger::error("No global offset extension found on this driver"); return UR_RESULT_ERROR_INVALID_VALUE; } auto MutableGroupOffestDesc = @@ -1277,8 +1275,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp( // Zero. continue; } else { - urPrint("urCommandBufferUpdateKernelLaunchExp: unsupported name of " - "execution attribute.\n"); + logger::error("urCommandBufferUpdateKernelLaunchExp: unsupported name of " + "execution attribute."); return UR_RESULT_ERROR_INVALID_VALUE; } } diff --git a/source/adapters/level_zero/common.cpp b/source/adapters/level_zero/common.cpp index 7ec5f9ef6b..7ae7272355 100644 --- a/source/adapters/level_zero/common.cpp +++ b/source/adapters/level_zero/common.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// #include "common.hpp" +#include "logger/ur_logger.hpp" #include "usm.hpp" ur_result_t ze2urResult(ze_result_t ZeResult) { @@ -65,15 +66,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(); @@ -86,8 +78,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; @@ -149,7 +141,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 (UrL0LeaksDebug) { ++(*ZeCallCount)[ZeName]; @@ -158,7 +150,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; } diff --git a/source/adapters/level_zero/common.hpp b/source/adapters/level_zero/common.hpp index 7a56f6e149..93bf407567 100644 --- a/source/adapters/level_zero/common.hpp +++ b/source/adapters/level_zero/common.hpp @@ -174,10 +174,10 @@ static auto getUrResultString = [](ur_result_t Result) { #define UR_CALL(Call) \ { \ if (PrintTrace) \ - fprintf(stderr, "UR ---> %s\n", #Call); \ + logger::always("UR ---> {}", #Call); \ ur_result_t Result = (Call); \ if (PrintTrace) \ - fprintf(stderr, "UR <--- %s(%s)\n", #Call, getUrResultString(Result)); \ + logger::always("UR <--- {}({})", #Call, getUrResultString(Result)); \ if (Result != UR_RESULT_SUCCESS) \ return Result; \ } @@ -268,9 +268,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)) \ @@ -301,9 +298,6 @@ template 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)) \ diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 6ae028a535..782fa1c840 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -15,6 +15,7 @@ #include "adapters/level_zero/queue.hpp" #include "context.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" UR_APIEXPORT ur_result_t UR_APICALL urContextCreate( @@ -175,7 +176,8 @@ 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(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -511,7 +513,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 ZeDevices; if (ZeDevice) { diff --git a/source/adapters/level_zero/device.cpp b/source/adapters/level_zero/device.cpp index b1eb1a7b1b..2fd13b50ec 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -7,9 +7,9 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// - #include "device.hpp" #include "adapter.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" #include "ur_util.hpp" #include @@ -96,7 +96,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet( break; default: Matched = false; - urPrint("Unknown device type"); + logger::warning("Unknown device type"); break; } @@ -169,7 +169,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; } } @@ -949,8 +949,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo( case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_WIDTH_EXP: case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_HEIGHT_EXP: case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_PITCH_EXP: - urPrint("Unsupported ParamName in urGetDeviceInfo\n"); - urPrint("ParamName=%d(0x%x)\n", ParamName, ParamName); + logger::error("Unsupported ParamName in urGetDeviceInfo"); + logger::error("ParamName=%{}(0x{})", ParamName, logger::toHex(ParamName)); return UR_RESULT_ERROR_INVALID_VALUE; case UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP: return ReturnValue(true); @@ -963,8 +963,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo( case UR_DEVICE_INFO_INTEROP_SEMAPHORE_IMPORT_SUPPORT_EXP: case UR_DEVICE_INFO_INTEROP_SEMAPHORE_EXPORT_SUPPORT_EXP: default: - urPrint("Unsupported ParamName in urGetDeviceInfo\n"); - urPrint("ParamName=%d(0x%x)\n", ParamName, ParamName); + logger::error("Unsupported ParamName in urGetDeviceInfo"); + logger::error("ParamNameParamName={}(0x{})", ParamName, + logger::toHex(ParamName)); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -1006,8 +1007,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; } @@ -1177,7 +1178,8 @@ 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(logger::LegacyMessage("NOTE: Number of queue groups = {}"), + "Number of queue groups = {}", numQueueGroups); std::vector> QueueGroupProperties(numQueueGroups); ZE2UR_CALL(zeDeviceGetCommandQueueGroupProperties, @@ -1230,14 +1232,22 @@ 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(logger::LegacyMessage( + "NOTE: main blitter/copy engine is not available"), + "main blitter/copy engine is not available"); else - urPrint("NOTE: main blitter/copy engine is available\n"); + logger::info(logger::LegacyMessage( + "NOTE: main blitter/copy engine is available"), + "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(logger::LegacyMessage( + "NOTE: link blitter/copy engines are not available"), + "link blitter/copy engines are not available"); else - urPrint("NOTE: link blitter/copy engines are available\n"); + logger::info(logger::LegacyMessage( + "NOTE: link blitter/copy engines are available"), + "link blitter/copy engines are available"); } } diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index 32c0951793..97ffe2f19e 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -17,17 +17,18 @@ #include "command_buffer.hpp" #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(UrZeEventList.ZeEventList[I])); + ss << " " << ur_cast(UrZeEventList.ZeEventList[I]); } - - urPrint("\n"); + logger::debug(ss.str().c_str()); } } @@ -446,8 +447,9 @@ 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=ParamName={}(0x{})", + PropName, logger::toHex(PropName)); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -538,7 +540,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo( return ReturnValue(ContextEndTime); } default: - urPrint("urEventGetProfilingInfo: not supported ParamName\n"); + logger::error("urEventGetProfilingInfo: not supported ParamName"); return UR_RESULT_ERROR_INVALID_VALUE; } } else { @@ -581,7 +583,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; } @@ -678,7 +680,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(ZeEvent)); + logger::debug("ZeEvent = {}", ur_cast(ZeEvent)); ZE2UR_CALL(zeHostSynchronize, (ZeEvent)); Event->Completed = true; } @@ -828,7 +830,8 @@ 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(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/image.cpp b/source/adapters/level_zero/image.cpp index 582121d91a..3b767f9127 100644 --- a/source/adapters/level_zero/image.cpp +++ b/source/adapters/level_zero/image.cpp @@ -12,6 +12,7 @@ #include "common.hpp" #include "context.hpp" #include "event.hpp" +#include "logger/ur_logger.hpp" #include "sampler.hpp" #include "ur_level_zero.hpp" @@ -68,8 +69,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ZeImageFormatTypeSize = 32; break; default: - urPrint("ze2urImageFormat: unsupported image format layout: layout = %d\n", - ZeImageFormat.layout); + logger::error( + "ze2urImageFormat: unsupported image format layout: layout = {}", + ZeImageFormat.layout); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -86,8 +88,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelOrder = UR_IMAGE_CHANNEL_ORDER_A; break; default: - urPrint("ze2urImageFormat: unexpected image format channel x: x = %d\n", - ZeImageFormat.x); + logger::error( + "ze2urImageFormat: unexpected image format channel x: x = {}", + ZeImageFormat.x); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -95,8 +98,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, case ZE_IMAGE_FORMAT_LAYOUT_16_16: case ZE_IMAGE_FORMAT_LAYOUT_32_32: if (ZeImageFormat.x != ZE_IMAGE_FORMAT_SWIZZLE_R) { - urPrint("ze2urImageFormat: unexpected image format channel x: x = %d\n", - ZeImageFormat.x); + logger::error( + "ze2urImageFormat: unexpected image format channel x: x = {}", + ZeImageFormat.x); return UR_RESULT_ERROR_INVALID_VALUE; } switch (ZeImageFormat.y) { @@ -110,8 +114,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelOrder = UR_IMAGE_CHANNEL_ORDER_RX; break; default: - urPrint("ze2urImageFormat: unexpected image format channel y: y = %d\n", - ZeImageFormat.x); + logger::error( + "ze2urImageFormat: unexpected image format channel y: y = {}\n", + ZeImageFormat.x); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -129,8 +134,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelOrder = UR_IMAGE_CHANNEL_ORDER_RGBA; break; default: - urPrint("ze2urImageFormat: unexpected image format channel w: w = %d\n", - ZeImageFormat.x); + logger::error("ze2urImageFormat: unexpected image format channel w: w " + "= {}", + ZeImageFormat.x); return UR_RESULT_ERROR_INVALID_VALUE; } } else if (ZeImageFormat.x == ZE_IMAGE_FORMAT_SWIZZLE_A && @@ -144,13 +150,14 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ZeImageFormat.w == ZE_IMAGE_FORMAT_SWIZZLE_A) { ChannelOrder = UR_IMAGE_CHANNEL_ORDER_BGRA; } else { - urPrint("ze2urImageFormat: unexpected image format channel\n"); + logger::error("ze2urImageFormat: unexpected image format channel"); return UR_RESULT_ERROR_INVALID_VALUE; } break; default: - urPrint("ze2urImageFormat: unsupported image format layout: layout = %d\n", - ZeImageFormat.layout); + logger::error( + "ze2urImageFormat: unsupported image format layout: layout = {}", + ZeImageFormat.layout); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -168,9 +175,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelType = UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32; break; default: - urPrint( - "ze2urImageFormat: unexpected image format type size: size = %zu\n", - ZeImageFormatTypeSize); + logger::error("ze2urImageFormat: unexpected image format type size: size " + "= {}", + ZeImageFormatTypeSize); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -186,9 +193,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelType = UR_IMAGE_CHANNEL_TYPE_SIGNED_INT32; break; default: - urPrint( - "ze2urImageFormat: unexpected image format type size: size = %zu\n", - ZeImageFormatTypeSize); + logger::error("ze2urImageFormat: unexpected image format type size: size " + "= {}", + ZeImageFormatTypeSize); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -201,9 +208,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelType = UR_IMAGE_CHANNEL_TYPE_UNORM_INT16; break; default: - urPrint( - "ze2urImageFormat: unexpected image format type size: size = %zu\n", - ZeImageFormatTypeSize); + logger::error("ze2urImageFormat: unexpected image format type size: size " + "= {}", + ZeImageFormatTypeSize); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -216,9 +223,9 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelType = UR_IMAGE_CHANNEL_TYPE_SNORM_INT16; break; default: - urPrint( - "ze2urImageFormat: unexpected image format type size: size = %zu\n", - ZeImageFormatTypeSize); + logger::error("ze2urImageFormat: unexpected image format type size: size " + "= {}", + ZeImageFormatTypeSize); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -231,15 +238,15 @@ ur_result_t ze2urImageFormat(const ze_image_desc_t *ZeImageDesc, ChannelType = UR_IMAGE_CHANNEL_TYPE_FLOAT; break; default: - urPrint( - "ze2urImageFormat: unexpected image format type size: size = %zu\n", - ZeImageFormatTypeSize); + logger::error("ze2urImageFormat: unexpected image format type size: size " + "= {}", + ZeImageFormatTypeSize); return UR_RESULT_ERROR_INVALID_VALUE; } break; default: - urPrint("ze2urImageFormat: unsupported image format type: type = %d\n", - ZeImageFormat.type); + logger::error("ze2urImageFormat: unsupported image format type: type = {}", + ZeImageFormat.type); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -270,7 +277,7 @@ ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, ZeImageFormatLayout = ZE_IMAGE_FORMAT_LAYOUT_32; break; default: - urPrint("ur2zeImageDesc: unexpected data type size\n"); + logger::error("ur2zeImageDesc: unexpected data type size"); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -289,7 +296,7 @@ ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, ZeImageFormatLayout = ZE_IMAGE_FORMAT_LAYOUT_32_32; break; default: - urPrint("ur2zeImageDesc: unexpected data type size\n"); + logger::error("ur2zeImageDesc: unexpected data type size"); return UR_RESULT_ERROR_INVALID_VALUE; } break; @@ -309,13 +316,13 @@ ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, ZeImageFormatLayout = ZE_IMAGE_FORMAT_LAYOUT_32_32_32_32; break; default: - urPrint("ur2zeImageDesc: unexpected data type size\n"); + logger::error("ur2zeImageDesc: unexpected data type size"); return UR_RESULT_ERROR_INVALID_VALUE; } break; } default: - urPrint("format channel order = %d\n", ImageFormat->channelOrder); + logger::error("format channel order = {}", ImageFormat->channelOrder); die("ur2zeImageDesc: unsupported image channel order\n"); break; } @@ -344,7 +351,7 @@ ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, ZeImageType = ZE_IMAGE_TYPE_2DARRAY; break; default: - urPrint("ur2zeImageDesc: unsupported image type\n"); + logger::error("ur2zeImageDesc: unsupported image type"); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -540,8 +547,9 @@ getImageFormatTypeAndSize(const ur_image_format_t *ImageFormat) { break; } default: - urPrint("urMemImageCreate: unsupported image data type: data type = %d\n", - ImageFormat->channelType); + logger::error( + "urMemImageCreate: unsupported image data type: data type = {}", + ImageFormat->channelType); ur::unreachable(); } return {ZeImageFormatType, ZeImageFormatTypeSize}; @@ -565,9 +573,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMPitchedAllocExp( DriverHandle, "zeMemGetPitchFor2dImage", (void **)&zeMemGetPitchFor2dImageFunctionPtr); if (Result != ZE_RESULT_SUCCESS) - urPrint("zeDriverGetExtensionFunctionAddress zeMemGetPitchFor2dImage " - "failed, err = %d\n", - Result); + logger::error( + "zeDriverGetExtensionFunctionAddress zeMemGetPitchFor2dImage " + "failed, err = {}", + Result); }); if (!zeMemGetPitchFor2dImageFunctionPtr) return UR_RESULT_ERROR_INVALID_OPERATION; @@ -714,9 +723,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp( DriverHandle, "zeImageGetDeviceOffsetExp", (void **)&zeImageGetDeviceOffsetExpFunctionPtr); if (Result != ZE_RESULT_SUCCESS) - urPrint("zeDriverGetExtensionFunctionAddress zeImageGetDeviceOffsetExp " - "failed, err = %d\n", - Result); + logger::error("zeDriverGetExtensionFunctionAddress " + "zeImageGetDeviceOffsetExpv failed, err = {}", + Result); }); if (!zeImageGetDeviceOffsetExpFunctionPtr) return UR_RESULT_ERROR_INVALID_OPERATION; @@ -856,7 +865,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp( WaitList.Length, WaitList.ZeEventList)); } } else { - urPrint("urBindlessImagesImageCopyExp: unexpected imageCopyFlags\n"); + logger::error("urBindlessImagesImageCopyExp: unexpected imageCopyFlags"); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -924,7 +933,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMipmapGetLevelExp( std::ignore = hImageMem; std::ignore = mipmapLevel; std::ignore = phImageMem; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -943,7 +953,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImportOpaqueFDExp( std::ignore = size; std::ignore = pInteropMemDesc; std::ignore = phInteropMem; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -958,7 +969,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( std::ignore = pImageDesc; std::ignore = hInteropMem; std::ignore = phImageMem; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -968,7 +980,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesReleaseInteropExp( std::ignore = hContext; std::ignore = hDevice; std::ignore = hInteropMem; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -981,7 +994,8 @@ urBindlessImagesImportExternalSemaphoreOpaqueFDExp( std::ignore = hDevice; std::ignore = pInteropSemaphoreDesc; std::ignore = phInteropSemaphoreHandle; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -991,7 +1005,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesDestroyExternalSemaphoreExp( std::ignore = hContext; std::ignore = hDevice; std::ignore = hInteropSemaphore; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1004,7 +1019,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesWaitExternalSemaphoreExp( std::ignore = numEventsInWaitList; std::ignore = phEventWaitList; std::ignore = phEvent; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] "), + " {} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1017,6 +1033,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSignalExternalSemaphoreExp( std::ignore = numEventsInWaitList; std::ignore = phEventWaitList; std::ignore = phEvent; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/kernel.cpp b/source/adapters/level_zero/kernel.cpp index 2cdf4b2cd2..d96351dd5d 100644 --- a/source/adapters/level_zero/kernel.cpp +++ b/source/adapters/level_zero/kernel.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// #include "kernel.hpp" +#include "logger/ur_logger.hpp" #include "ur_api.h" #include "ur_level_zero.hpp" @@ -60,7 +61,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch( Queue->Mutex, Kernel->Mutex, Kernel->Program->Mutex); if (GlobalWorkOffset != NULL) { if (!Queue->Device->Platform->ZeDriverGlobalOffsetExtensionFound) { - urPrint("No global offset extension found on this driver\n"); + logger::error("No global offset extension found on this driver"); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -127,15 +128,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch( while (GlobalWorkSize3D[I] % GroupSize[I]) { --GroupSize[I]; } + if (GlobalWorkSize3D[I] / GroupSize[I] > UINT32_MAX) { - urPrint("urEnqueueKernelLaunch: can't find a WG size " - "suitable for global work size > UINT32_MAX\n"); + logger::error("urEnqueueKernelLaunch: 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("urEnqueueKernelLaunch: using computed WG size = {%d, %d, %d}\n", - WG[0], WG[1], WG[2]); + logger::debug( + "urEnqueueKernelLaunch: using computed WG size = {{{}, {}, {}}}", + WG[0], WG[1], WG[2]); } } @@ -164,27 +167,27 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch( break; default: - urPrint("urEnqueueKernelLaunch: unsupported work_dim\n"); + logger::error("urEnqueueKernelLaunch: unsupported work_dim"); return UR_RESULT_ERROR_INVALID_VALUE; } // Error handling for non-uniform group size case if (GlobalWorkSize3D[0] != size_t(ZeThreadGroupDimensions.groupCountX) * WG[0]) { - urPrint("urEnqueueKernelLaunch: invalid work_dim. The range is not a " - "multiple of the group size in the 1st dimension\n"); + logger::error("urEnqueueKernelLaunch: 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 (GlobalWorkSize3D[1] != size_t(ZeThreadGroupDimensions.groupCountY) * WG[1]) { - urPrint("urEnqueueKernelLaunch: invalid work_dim. The range is not a " - "multiple of the group size in the 2nd dimension\n"); + logger::error("urEnqueueKernelLaunch: 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 (GlobalWorkSize3D[2] != size_t(ZeThreadGroupDimensions.groupCountZ) * WG[2]) { - urPrint("urEnqueueKernelLaunch: invalid work_dim. The range is not a " - "multiple of the group size in the 3rd dimension\n"); + logger::debug("urEnqueueKernelLaunch: 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; } @@ -252,9 +255,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch( (*Event)->WaitList.Length, (*Event)->WaitList.ZeEventList)); } - urPrint("calling zeCommandListAppendLaunchKernel() with" - " ZeEvent %#" PRIxPTR "\n", - ur_cast(ZeEvent)); + logger::debug("calling zeCommandListAppendLaunchKernel() with" + " ZeEvent {}", + ur_cast(ZeEvent)); printZeEventList((*Event)->WaitList); // Execute command list asynchronously, as the event will be used @@ -537,8 +540,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo( return UR_RESULT_ERROR_UNKNOWN; } default: - urPrint("Unsupported ParamName in urKernelGetInfo: ParamName=%d(0x%x)\n", - ParamName, ParamName); + logger::error( + "Unsupported ParamName in urKernelGetInfo: ParamName={}(0x{})", + ParamName, logger::toHex(ParamName)); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -606,8 +610,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetGroupInfo( return ReturnValue(uint32_t{Kernel->ZeKernelProperties->privateMemSize}); } default: { - urPrint("Unknown ParamName in urKernelGetGroupInfo: ParamName=%d(0x%x)\n", - ParamName, ParamName); + logger::error( + "Unknown ParamName in urKernelGetGroupInfo: ParamName={}(0x{})", + ParamName, logger::toHex(ParamName)); return UR_RESULT_ERROR_INVALID_VALUE; } } @@ -736,7 +741,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetExecInfo( return UR_RESULT_ERROR_INVALID_VALUE; ZE2UR_CALL(zeKernelSetCacheConfig, (ZeKernel, ZeCacheConfig);); } else { - urPrint("urKernelSetExecInfo: unsupported ParamName\n"); + logger::error("urKernelSetExecInfo: unsupported ParamName"); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -880,6 +885,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetSpecializationConstants( std::ignore = Kernel; std::ignore = Count; std::ignore = SpecConstants; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index 94e808eb50..39a970063f 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -15,6 +15,7 @@ #include "context.hpp" #include "event.hpp" #include "image.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" // Default to using compute engine for fill operation, but allow to @@ -75,9 +76,9 @@ ur_result_t enqueueMemCopyHelper(ur_command_t CommandType, const auto &ZeCommandList = CommandList->first; const auto &WaitList = (*Event)->WaitList; - urPrint("calling zeCommandListAppendMemoryCopy() with\n" - " ZeEvent %#" PRIxPTR "\n", - ur_cast(ZeEvent)); + logger::debug("calling zeCommandListAppendMemoryCopy() with" + " ZeEvent {}", + ur_cast(ZeEvent)); printZeEventList(WaitList); ZE2UR_CALL(zeCommandListAppendMemoryCopy, @@ -126,9 +127,9 @@ ur_result_t enqueueMemCopyRectHelper( const auto &ZeCommandList = CommandList->first; const auto &WaitList = (*Event)->WaitList; - urPrint("calling zeCommandListAppendMemoryCopy() with\n" - " ZeEvent %#" PRIxPTR "\n", - ur_cast(ZeEvent)); + logger::debug("calling zeCommandListAppendMemoryCopy() with" + " ZeEvent {}", + ur_cast(ZeEvent)); printZeEventList(WaitList); uint32_t SrcOriginX = ur_cast(SrcOrigin.x); @@ -167,7 +168,7 @@ ur_result_t enqueueMemCopyRectHelper( SrcBuffer, &ZeSrcRegion, SrcPitch, SrcSlicePitch, ZeEvent, WaitList.Length, WaitList.ZeEventList)); - urPrint("calling zeCommandListAppendMemoryCopyRegion()\n"); + logger::debug("calling zeCommandListAppendMemoryCopyRegion()"); UR_CALL(Queue->executeCommandList(CommandList, Blocking, OkToBatch)); @@ -240,9 +241,9 @@ static ur_result_t enqueueMemFillHelper(ur_command_t CommandType, (ZeCommandList, Ptr, Pattern, PatternSize, Size, ZeEvent, WaitList.Length, WaitList.ZeEventList)); - urPrint("calling zeCommandListAppendMemoryFill() with\n" - " ZeEvent %#" PRIxPTR "\n", - ur_cast(ZeEvent)); + logger::debug("calling zeCommandListAppendMemoryFill() with" + " ZeEvent {}", + ur_cast(ZeEvent)); printZeEventList(WaitList); // Execute command list asynchronously, as the event will be used @@ -417,7 +418,7 @@ static ur_result_t enqueueMemImageCommandHelper( ur_cast(ZeHandleSrc), &ZeDstRegion, &ZeSrcRegion, ZeEvent, 0, nullptr)); } else { - urPrint("enqueueMemImageUpdate: unsupported image command type\n"); + logger::error("enqueueMemImageUpdate: unsupported image command type"); return UR_RESULT_ERROR_INVALID_OPERATION; } @@ -938,7 +939,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap( // False as the second value in pair means that mapping was not inserted // because mapping already exists. if (!Res.second) { - urPrint("urEnqueueMemBufferMap: duplicate mapping detected\n"); + logger::error("urEnqueueMemBufferMap: duplicate mapping detected"); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -991,7 +992,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap( // False as the second value in pair means that mapping was not inserted // because mapping already exists. if (!Res.second) { - urPrint("urEnqueueMemBufferMap: duplicate mapping detected\n"); + logger::error("urEnqueueMemBufferMap: duplicate mapping detected"); return UR_RESULT_ERROR_INVALID_VALUE; } return UR_RESULT_SUCCESS; @@ -1044,7 +1045,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap( std::scoped_lock Guard(Buffer->Mutex); auto It = Buffer->Mappings.find(MappedPtr); if (It == Buffer->Mappings.end()) { - urPrint("urEnqueueMemUnmap: unknown memory mapping\n"); + logger::error("urEnqueueMemUnmap: unknown memory mapping"); return UR_RESULT_ERROR_INVALID_VALUE; } MapInfo = It->second; @@ -1141,7 +1142,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemset( std::ignore = NumEventsInWaitList; std::ignore = EventWaitList; std::ignore = Event; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1334,7 +1336,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill2D( std::ignore = NumEventsInWaitList; std::ignore = EventWaitList; std::ignore = OutEvent; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1366,7 +1369,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemset2D( std::ignore = NumEventsInWaitList; std::ignore = EventWaitList; std::ignore = OutEvent; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -1436,13 +1440,13 @@ static ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, ZeImageFormatLayout = ZE_IMAGE_FORMAT_LAYOUT_32_32_32_32; break; default: - urPrint("urMemImageCreate: unexpected data type Size\n"); + logger::error("urMemImageCreate: unexpected data type Size"); return UR_RESULT_ERROR_INVALID_VALUE; } break; } default: - urPrint("format layout = %d\n", ImageFormat->channelOrder); + logger::error("format layout = {}", ImageFormat->channelOrder); die("urMemImageCreate: unsupported image format layout\n"); break; } @@ -1471,7 +1475,7 @@ static ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, ZeImageType = ZE_IMAGE_TYPE_2DARRAY; break; default: - urPrint("urMemImageCreate: unsupported image type\n"); + logger::error("urMemImageCreate: unsupported image type"); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -1897,7 +1901,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo( std::ignore = PropSize; std::ignore = ImgInfo; std::ignore = PropSizeRet; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -2146,8 +2151,8 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode, } } - urPrint("getZeHandle(pi_device{%p}) = %p\n", (void *)Device, - (void *)Allocation.ZeHandle); + logger::debug("getZeHandle(pi_device{{{}}}) = {}", (void *)Device, + (void *)Allocation.ZeHandle); return UR_RESULT_SUCCESS; } @@ -2329,7 +2334,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( std::ignore = numEventsInWaitList; std::ignore = phEventWaitList; std::ignore = phEvent; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -2347,6 +2353,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( std::ignore = numEventsInWaitList; std::ignore = phEventWaitList; std::ignore = phEvent; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/platform.cpp b/source/adapters/level_zero/platform.cpp index 19ecac7fee..20ed58258c 100644 --- a/source/adapters/level_zero/platform.cpp +++ b/source/adapters/level_zero/platform.cpp @@ -94,7 +94,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo( case UR_PLATFORM_INFO_BACKEND: return ReturnValue(UR_PLATFORM_BACKEND_LEVEL_ZERO); default: - urPrint("urPlatformGetInfo: unrecognized ParamName\n"); + logger::debug("urPlatformGetInfo: unrecognized ParamName"); return UR_RESULT_ERROR_INVALID_VALUE; } diff --git a/source/adapters/level_zero/program.cpp b/source/adapters/level_zero/program.cpp index d60b2a3322..e71ef2a8f9 100644 --- a/source/adapters/level_zero/program.cpp +++ b/source/adapters/level_zero/program.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// #include "program.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" extern "C" { @@ -405,8 +406,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp( ZeModuleDesc.pBuildFlags = ZeExtModuleDesc.pBuildFlags[0]; ZeModuleDesc.pConstants = ZeExtModuleDesc.pConstants[0]; } else { - urPrint("urProgramLink: level_zero driver does not have static linking " - "support."); + logger::error( + "urProgramLink: level_zero driver does not have static linking " + "support."); return UR_RESULT_ERROR_INVALID_VALUE; } } @@ -796,7 +798,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetBuildInfo( // program. return ReturnValue(""); } else { - urPrint("urProgramGetBuildInfo: unsupported ParamName\n"); + logger::error("urProgramGetBuildInfo: unsupported ParamName"); return UR_RESULT_ERROR_INVALID_VALUE; } return UR_RESULT_SUCCESS; @@ -812,7 +814,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstant( std::ignore = SpecId; std::ignore = SpecSize; std::ignore = SpecValue; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!"); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index e21e4e1b0a..a5e1066a23 100644 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -451,8 +451,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo( return ReturnValue(true); } default: - urPrint("Unsupported ParamName in urQueueGetInfo: ParamName=%d(0x%x)\n", - ParamName, ParamName); + logger::error( + "Unsupported ParamName in urQueueGetInfo: ParamName=ParamName={}(0x{})", + ParamName, logger::toHex(ParamName)); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -981,9 +982,9 @@ static const zeCommandListBatchConfig ZeCommandListBatchConfig(bool IsCopy) { Val = std::stoi(BatchConfig.substr(Pos)); } catch (...) { if (IsCopy) - urPrint("UR_L0_COPY_BATCH_SIZE: failed to parse value\n"); + logger::error("UR_L0_COPY_BATCH_SIZE: failed to parse value"); else - urPrint("UR_L0_BATCH_SIZE: failed to parse value\n"); + logger::error("UR_L0_BATCH_SIZE: failed to parse value"); break; } switch (Ord) { @@ -1006,20 +1007,20 @@ static const zeCommandListBatchConfig ZeCommandListBatchConfig(bool IsCopy) { die("Unexpected batch config"); } if (IsCopy) - urPrint("UR_L0_COPY_BATCH_SIZE: dynamic batch param " - "#%d: %d\n", - (int)Ord, (int)Val); + logger::error("UR_L0_COPY_BATCH_SIZE: dynamic batch param " + "#{}: {}", + (int)Ord, (int)Val); else - urPrint("UR_L0_BATCH_SIZE: dynamic batch param #%d: %d\n", (int)Ord, - (int)Val); + logger::error("UR_L0_BATCH_SIZE: dynamic batch param #{}: {}", + (int)Ord, (int)Val); }; } else { // Negative batch sizes are silently ignored. if (IsCopy) - urPrint("UR_L0_COPY_BATCH_SIZE: ignored negative value\n"); + logger::warning("UR_L0_COPY_BATCH_SIZE: ignored negative value"); else - urPrint("UR_L0_BATCH_SIZE: ignored negative value\n"); + logger::warning("UR_L0_BATCH_SIZE: ignored negative value"); } } return Config; @@ -1188,7 +1189,7 @@ void ur_queue_handle_t_::adjustBatchSizeForFullBatch(bool IsCopy) { ZeCommandListBatchConfig.NumTimesClosedFullThreshold) { if (QueueBatchSize < ZeCommandListBatchConfig.DynamicSizeMax) { QueueBatchSize += ZeCommandListBatchConfig.DynamicSizeStep; - urPrint("Raising QueueBatchSize to %d\n", QueueBatchSize); + logger::debug("Raising QueueBatchSize to {}", QueueBatchSize); } CommandBatch.NumTimesClosedEarly = 0; CommandBatch.NumTimesClosedFull = 0; @@ -1215,7 +1216,7 @@ void ur_queue_handle_t_::adjustBatchSizeForPartialBatch(bool IsCopy) { QueueBatchSize = CommandBatch.OpenCommandList->second.size() - 1; if (QueueBatchSize < 1) QueueBatchSize = 1; - urPrint("Lowering QueueBatchSize to %d\n", QueueBatchSize); + logger::debug("Lowering QueueBatchSize to {}", QueueBatchSize); CommandBatch.NumTimesClosedEarly = 0; CommandBatch.NumTimesClosedFull = 0; } @@ -1531,14 +1532,14 @@ ur_result_t urQueueReleaseInternal(ur_queue_handle_t Queue) { } } - urPrint("urQueueRelease(compute) NumTimesClosedFull %d, " - "NumTimesClosedEarly %d\n", - UrQueue->ComputeCommandBatch.NumTimesClosedFull, - UrQueue->ComputeCommandBatch.NumTimesClosedEarly); - urPrint("urQueueRelease(copy) NumTimesClosedFull %d, NumTimesClosedEarly " - "%d\n", - UrQueue->CopyCommandBatch.NumTimesClosedFull, - UrQueue->CopyCommandBatch.NumTimesClosedEarly); + logger::debug("urQueueRelease(compute) NumTimesClosedFull {}, " + "NumTimesClosedEarly {}", + UrQueue->ComputeCommandBatch.NumTimesClosedFull, + UrQueue->ComputeCommandBatch.NumTimesClosedEarly); + logger::debug( + "urQueueRelease(copy) NumTimesClosedFull {}, NumTimesClosedEarly {}", + UrQueue->CopyCommandBatch.NumTimesClosedFull, + UrQueue->CopyCommandBatch.NumTimesClosedEarly); delete UrQueue; @@ -2072,10 +2073,10 @@ ur_queue_handle_t_::ur_queue_group_t::getZeQueue(uint32_t *QueueGroupOrdinal) { ZeCommandQueueDesc.flags = ZE_COMMAND_QUEUE_FLAG_EXPLICIT_ONLY; } - urPrint("[getZeQueue]: create queue ordinal = %d, index = %d " - "(round robin in [%d, %d]) priority = %s\n", - ZeCommandQueueDesc.ordinal, ZeCommandQueueDesc.index, LowerIndex, - UpperIndex, Priority); + logger::debug("[getZeQueue]: create queue ordinal = {}, index = {} " + "(round robin in [{}, {}]) priority = {}", + ZeCommandQueueDesc.ordinal, ZeCommandQueueDesc.index, + LowerIndex, UpperIndex, Priority); auto ZeResult = ZE_CALL_NOCHECK( zeCommandQueueCreate, (Queue->Context->ZeContext, Queue->Device->ZeDevice, @@ -2287,10 +2288,10 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() { // If cache didn't contain a command list, create one. if (!ZeCommandList) { - urPrint("[getZeQueue]: create queue ordinal = %d, index = %d " - "(round robin in [%d, %d]) priority = %s\n", - ZeCommandQueueDesc.ordinal, ZeCommandQueueDesc.index, LowerIndex, - UpperIndex, Priority); + logger::debug("[getZeQueue]: create queue ordinal = {}, index = {} " + "(round robin in [{}, {}]) priority = {}", + ZeCommandQueueDesc.ordinal, ZeCommandQueueDesc.index, + LowerIndex, UpperIndex, Priority); ZE_CALL_NOCHECK(zeCommandListCreateImmediate, (Queue->Context->ZeContext, Queue->Device->ZeDevice, diff --git a/source/adapters/level_zero/sampler.cpp b/source/adapters/level_zero/sampler.cpp index f32c59aeeb..e96c0db55a 100644 --- a/source/adapters/level_zero/sampler.cpp +++ b/source/adapters/level_zero/sampler.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// #include "sampler.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreate( @@ -75,9 +76,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreate( ZeSamplerDesc.addressMode = ZE_SAMPLER_ADDRESS_MODE_MIRROR; break; default: - urPrint("urSamplerCreate: unsupported " - "UR_SAMPLER_PROPERTIES_ADDRESSING_MODEE " - "value\n"); + logger::error("urSamplerCreate: unsupported " + "UR_SAMPLER_PROPERTIES_ADDRESSING_MODEE " + "value"); return UR_RESULT_ERROR_INVALID_VALUE; } @@ -86,7 +87,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreate( else if (Props->filterMode == UR_SAMPLER_FILTER_MODE_LINEAR) ZeSamplerDesc.filterMode = ZE_SAMPLER_FILTER_MODE_LINEAR; else { - urPrint("urSamplerCreate: unsupported UR_SAMPLER_FILTER_MODE value\n"); + logger::error( + "urSamplerCreate: unsupported UR_SAMPLER_FILTER_MODE value"); return UR_RESULT_ERROR_INVALID_VALUE; } } @@ -144,7 +146,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerGetInfo( std::ignore = PropValueSize; std::ignore = PropValue; std::ignore = PropSizeRet; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -155,7 +158,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerGetNativeHandle( ) { std::ignore = Sampler; std::ignore = NativeSampler; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -173,6 +177,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreateWithNativeHandle( std::ignore = Context; std::ignore = Properties; std::ignore = Sampler; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 4772986c1c..09e340dfe0 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -16,6 +16,7 @@ #include "event.hpp" #include "usm.hpp" +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" #include @@ -597,7 +598,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMGetMemAllocInfo( MemAllocaType = UR_USM_TYPE_SHARED; break; default: - urPrint("urUSMGetMemAllocInfo: unexpected usm memory type\n"); + logger::error("urUSMGetMemAllocInfo: unexpected usm memory type"); return UR_RESULT_ERROR_INVALID_VALUE; } return ReturnValue(MemAllocaType); @@ -655,7 +656,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMGetMemAllocInfo( return UR_RESULT_ERROR_INVALID_VALUE; } default: - urPrint("urUSMGetMemAllocInfo: unsupported ParamName\n"); + logger::error("urUSMGetMemAllocInfo: unsupported ParamName"); return UR_RESULT_ERROR_INVALID_VALUE; } return UR_RESULT_SUCCESS; @@ -822,7 +823,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context, break; } default: { - urPrint("urUSMPoolCreate: unexpected chained stype\n"); + logger::error("urUSMPoolCreate: unexpected chained stype"); throw UsmAllocationException(UR_RESULT_ERROR_INVALID_ARGUMENT); } } diff --git a/source/adapters/level_zero/usm_p2p.cpp b/source/adapters/level_zero/usm_p2p.cpp index f122b8cbdb..71cc173784 100644 --- a/source/adapters/level_zero/usm_p2p.cpp +++ b/source/adapters/level_zero/usm_p2p.cpp @@ -8,6 +8,7 @@ // //===----------------------------------------------------------------------===// +#include "logger/ur_logger.hpp" #include "ur_level_zero.hpp" UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PEnablePeerAccessExp( @@ -16,7 +17,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PEnablePeerAccessExp( std::ignore = commandDevice; std::ignore = peerDevice; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -26,7 +28,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PDisablePeerAccessExp( std::ignore = commandDevice; std::ignore = peerDevice; - urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__); + logger::error(logger::LegacyMessage("[UR][L0] {} function not implemented!"), + "{} function not implemented!", __FUNCTION__); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/virtual_mem.cpp b/source/adapters/level_zero/virtual_mem.cpp index de72502614..e3b90121a1 100644 --- a/source/adapters/level_zero/virtual_mem.cpp +++ b/source/adapters/level_zero/virtual_mem.cpp @@ -11,6 +11,7 @@ #include "common.hpp" #include "context.hpp" #include "device.hpp" +#include "logger/ur_logger.hpp" #include "physical_mem.hpp" #include "ur_level_zero.hpp" @@ -31,8 +32,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urVirtualMemGranularityGetInfo( return ReturnValue(PageSize); } default: - urPrint("Unsupported propName in urQueueGetInfo: propName=%d(0x%x)\n", - propName, propName); + logger::error("Unsupported propName in urQueueGetInfo: propName={}({})", + propName, propName); return UR_RESULT_ERROR_INVALID_VALUE; } return UR_RESULT_SUCCESS; @@ -111,8 +112,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urVirtualMemGetInfo( return ReturnValue(RetFlags); } default: - urPrint("Unsupported propName in urQueueGetInfo: propName=%d(0x%x)\n", - propName, propName); + logger::error("Unsupported propName in urQueueGetInfo: propName={}({})", + propName, propName); return UR_RESULT_ERROR_INVALID_VALUE; }