From 080ceb783568941deb10b7cfe08b54a597d17e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Plewa?= Date: Fri, 24 Nov 2023 17:44:06 +0100 Subject: [PATCH] update CUDA adapter to new logger --- source/adapters/cuda/adapter.cpp | 5 +- source/adapters/cuda/command_buffer.hpp | 5 +- source/adapters/cuda/common.cpp | 60 +++++++++++-------- source/adapters/cuda/common.hpp | 3 - source/adapters/cuda/device.cpp | 3 +- source/adapters/level_zero/command_buffer.cpp | 6 +- 6 files changed, 45 insertions(+), 37 deletions(-) diff --git a/source/adapters/cuda/adapter.cpp b/source/adapters/cuda/adapter.cpp index 5b897a8768..673796168f 100644 --- a/source/adapters/cuda/adapter.cpp +++ b/source/adapters/cuda/adapter.cpp @@ -8,9 +8,9 @@ // //===----------------------------------------------------------------------===// -#include - #include "common.hpp" +#include "logger/ur_logger.hpp" +#include void enableCUDATracing(); void disableCUDATracing(); @@ -18,6 +18,7 @@ void disableCUDATracing(); struct ur_adapter_handle_t_ { std::atomic RefCount = 0; std::mutex Mutex; + logger::Logger &logger = logger::get_logger("cuda"); }; ur_adapter_handle_t_ adapter{}; diff --git a/source/adapters/cuda/command_buffer.hpp b/source/adapters/cuda/command_buffer.hpp index 18264410c4..611ba2a15e 100644 --- a/source/adapters/cuda/command_buffer.hpp +++ b/source/adapters/cuda/command_buffer.hpp @@ -12,6 +12,7 @@ #include #include "context.hpp" +#include "logger/ur_logger.hpp" #include #include @@ -169,10 +170,10 @@ static inline const char *getUrResultString(ur_result_t Result) { #define UR_CALL(Call, Result) \ { \ if (PrintTrace) \ - fprintf(stderr, "UR ---> %s\n", #Call); \ + logger::debug("UR ---> {}", #Call); \ Result = (Call); \ if (PrintTrace) \ - fprintf(stderr, "UR <--- %s(%s)\n", #Call, getUrResultString(Result)); \ + logger::debug("UR <--- {}({})", #Call, getUrResultString(Result)); \ } struct ur_exp_command_buffer_handle_t_ { diff --git a/source/adapters/cuda/common.cpp b/source/adapters/cuda/common.cpp index 9f2a330262..5325c31878 100644 --- a/source/adapters/cuda/common.cpp +++ b/source/adapters/cuda/common.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// #include "common.hpp" +#include "logger/ur_logger.hpp" #include @@ -37,29 +38,34 @@ ur_result_t mapErrorUR(CUresult Result) { void checkErrorUR(CUresult Result, const char *Function, int Line, const char *File) { + static bool suppress_error = + std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr && + std::getenv("UR_SUPPRESS_ERROR_MESSAGE") == nullptr; + + static bool abort = std::getenv("PI_CUDA_ABORT") != nullptr || + std::getenv("UR_CUDA_ABORT") != nullptr; + if (Result == CUDA_SUCCESS || Result == CUDA_ERROR_DEINITIALIZED) { return; } - if (std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr && - std::getenv("UR_SUPPRESS_ERROR_MESSAGE") == nullptr) { + if (suppress_error) { const char *ErrorString = nullptr; const char *ErrorName = nullptr; cuGetErrorName(Result, &ErrorName); cuGetErrorString(Result, &ErrorString); std::stringstream SS; - SS << "\nUR CUDA ERROR:" - << "\n\tValue: " << Result - << "\n\tName: " << ErrorName - << "\n\tDescription: " << ErrorString - << "\n\tFunction: " << Function << "\n\tSource Location: " << File - << ":" << Line << "\n" - << std::endl; - std::cerr << SS.str(); + SS << std::endl + << "CUDA Error" << std::endl + << "\tValue: " << Result << std::endl + << "\tName: " << ErrorName << std::endl + << "\tDescription: " << ErrorString << std::endl + << "\tFunction: " << Function << std::endl + << "\tSource Location: " << File << ":" << Line << std::endl; + logger::error("{}", SS.str()); } - if (std::getenv("PI_CUDA_ABORT") != nullptr || - std::getenv("UR_CUDA_ABORT") != nullptr) { + if (abort) { std::abort(); } @@ -68,22 +74,28 @@ void checkErrorUR(CUresult Result, const char *Function, int Line, void checkErrorUR(ur_result_t Result, const char *Function, int Line, const char *File) { + static bool suppress_error = + std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr && + std::getenv("UR_SUPPRESS_ERROR_MESSAGE") == nullptr; + + static bool abort = std::getenv("PI_CUDA_ABORT") != nullptr || + std::getenv("UR_CUDA_ABORT") != nullptr; + if (Result == UR_RESULT_SUCCESS) { return; } - if (std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr && - std::getenv("UR_SUPPRESS_ERROR_MESSAGE") == nullptr) { + if (suppress_error) { std::stringstream SS; - SS << "\nUR ERROR:" - << "\n\tValue: " << Result - << "\n\tFunction: " << Function << "\n\tSource Location: " << File - << ":" << Line << "\n" - << std::endl; - std::cerr << SS.str(); + SS << std::endl + << "UR ERROR:" << std::endl + << "\tValue: " << Result << std::endl + << "\tFunction: " << Function << std::endl + << "\tSource Location: " << File << ":" << Line << std::endl; + logger::error("{}", SS.str()); } - if (std::getenv("PI_CUDA_ABORT") != nullptr) { + if (abort) { std::abort(); } @@ -101,7 +113,7 @@ std::string getCudaVersionString() { } void detail::ur::die(const char *Message) { - std::cerr << "ur_die: " << Message << std::endl; + logger::error("{}", Message); std::terminate(); } @@ -110,10 +122,6 @@ void detail::ur::assertion(bool Condition, const char *Message) { die(Message); } -void detail::ur::cuPrint(const char *Message) { - std::cerr << "ur_print: " << Message << std::endl; -} - // Global variables for ZER_EXT_RESULT_ADAPTER_SPECIFIC_ERROR thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS; thread_local char ErrorMessage[MaxMessageSize]; diff --git a/source/adapters/cuda/common.hpp b/source/adapters/cuda/common.hpp index 67223c45bc..37f1328ec4 100644 --- a/source/adapters/cuda/common.hpp +++ b/source/adapters/cuda/common.hpp @@ -52,9 +52,6 @@ namespace ur { // [[noreturn]] void die(const char *Message); -// Reports error messages -void cuPrint(const char *Message); - void assertion(bool Condition, const char *Message = nullptr); } // namespace ur diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index 0723cfe4e7..9bfb0b48a4 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -15,6 +15,7 @@ #include "adapter.hpp" #include "context.hpp" #include "device.hpp" +#include "logger/ur_logger.hpp" #include "platform.hpp" #include "ur_util.hpp" @@ -279,7 +280,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 { - detail::ur::cuPrint( + logger::info( "Images are not fully supported by the CUDA BE, their support is " "disabled by default. Their partial support can be activated by " "setting SYCL_PI_CUDA_ENABLE_IMAGE_SUPPORT environment variable at " diff --git a/source/adapters/level_zero/command_buffer.cpp b/source/adapters/level_zero/command_buffer.cpp index 231ce58f82..b6d3b36a28 100644 --- a/source/adapters/level_zero/command_buffer.cpp +++ b/source/adapters/level_zero/command_buffer.cpp @@ -419,9 +419,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; }