From 69a786e8d1abb6c5c195b1a92e76c6e949bf81dd Mon Sep 17 00:00:00 2001 From: agodavar Date: Tue, 5 Jan 2021 04:53:59 -0500 Subject: [PATCH] SWDEV-245381 : Updated guarantee error messages to print based on BUILD_TYPE Change-Id: Ia21039326b440f6d807a6495a9a05dd52b384c76 --- rocclr/device/device.cpp | 4 ++-- rocclr/platform/kernel.cpp | 4 ++-- rocclr/platform/program.cpp | 2 +- rocclr/utils/debug.cpp | 6 +++++- rocclr/utils/debug.hpp | 9 ++++++--- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/rocclr/device/device.cpp b/rocclr/device/device.cpp index 0e7c24ebdb..44b93ebfd3 100644 --- a/rocclr/device/device.cpp +++ b/rocclr/device/device.cpp @@ -98,7 +98,7 @@ void MemObjMap::AddMemObj(const void* k, amd::Memory* v) { if (!rval.second) { DevLogPrintfError("Memobj map already has an entry for ptr: 0x%x", reinterpret_cast(k)); - guarantee(false); + guarantee(false, "Memobj map already has an entry for ptr"); } } @@ -108,7 +108,7 @@ void MemObjMap::RemoveMemObj(const void* k) { if (rval != 1) { DevLogPrintfError("Memobj map does not have ptr: 0x%x", reinterpret_cast(k)); - guarantee(false); + guarantee(false, "Memobj map does not have ptr"); } } diff --git a/rocclr/platform/kernel.cpp b/rocclr/platform/kernel.cpp index 2712b35d3c..55d2bd1b89 100644 --- a/rocclr/platform/kernel.cpp +++ b/rocclr/platform/kernel.cpp @@ -30,14 +30,14 @@ namespace amd { Kernel::Kernel(Program& program, const Symbol& symbol, const std::string& name) : program_(program), symbol_(symbol), name_(name) { parameters_ = new (signature()) KernelParameters(const_cast(signature())); - fixme_guarantee(parameters_ != NULL && "out of memory"); + fixme_guarantee(parameters_ != NULL, "out of memory"); name_ += '\0'; } Kernel::Kernel(const Kernel& rhs) : program_(rhs.program_()), symbol_(rhs.symbol_), name_(rhs.name_) { parameters_ = new(signature()) KernelParameters(*rhs.parameters_); - fixme_guarantee(parameters_ != NULL && "out of memory"); + fixme_guarantee(parameters_ != NULL, "out of memory"); } Kernel::~Kernel() { diff --git a/rocclr/platform/program.cpp b/rocclr/platform/program.cpp index b12c93f086..4c046b36ea 100644 --- a/rocclr/platform/program.cpp +++ b/rocclr/platform/program.cpp @@ -175,7 +175,7 @@ int32_t Program::addDeviceProgram(Device& device, const void* image, size_t leng const device::Program* same_dev_prog = nullptr; if ((amd::IS_HIP) && (same_prog != nullptr)) { auto same_dev_prog_map_ = same_prog->devicePrograms(); - guarantee(same_dev_prog_map_.size() == 1); + guarantee(same_dev_prog_map_.size() == 1, "For same_prog, devicePrograms size != 1"); same_dev_prog = same_dev_prog_map_.begin()->second; } diff --git a/rocclr/utils/debug.cpp b/rocclr/utils/debug.cpp index d76c09de1f..f8f5793910 100644 --- a/rocclr/utils/debug.cpp +++ b/rocclr/utils/debug.cpp @@ -46,7 +46,11 @@ extern "C" void breakpoint(void) { void report_fatal(const char* file, int line, const char* message) { // FIXME_lmoriche: Obfuscate the message string - fprintf(stderr, "%s:%d: %s\n", file, line, message); + #if (defined(DEBUG)) + fprintf(stderr, "%s:%d: %s\n", file, line, message); + #else + fprintf(stderr, "%s\n", message); + #endif ::abort(); } diff --git a/rocclr/utils/debug.hpp b/rocclr/utils/debug.hpp index 18d779bf5f..6bcc68a5be 100644 --- a/rocclr/utils/debug.hpp +++ b/rocclr/utils/debug.hpp @@ -90,13 +90,16 @@ extern void log_printf(LogLevel level, const char* file, int line, uint64_t *sta #endif // __INTEL_COMPILER //! \brief Abort the program if the invariant \a cond is false. -#define guarantee(cond) \ +#define guarantee(cond, ...) \ if (!(cond)) { \ - amd::report_fatal(__FILE__, __LINE__, "guarantee(" XSTR(cond) ")"); \ + if(strlen(#__VA_ARGS__) == 0) \ + amd::report_fatal(__FILE__, __LINE__, XSTR(cond) ); \ + else \ + amd::report_fatal(__FILE__, __LINE__, XSTR(__VA_ARGS__) ); \ amd::breakpoint(); \ } -#define fixme_guarantee(cond) guarantee(cond) +#define fixme_guarantee(cond, ...) guarantee(cond, __VA_ARGS__) //! \brief Abort the program with a fatal error message. #define fatal(msg) \