diff --git a/dnn-providers/hipblaslt-provider/CMakeLists.txt b/dnn-providers/hipblaslt-provider/CMakeLists.txt index 916dea7e08d..6e5667749bb 100644 --- a/dnn-providers/hipblaslt-provider/CMakeLists.txt +++ b/dnn-providers/hipblaslt-provider/CMakeLists.txt @@ -110,16 +110,12 @@ add_library( HipblasltMatmulDesc.cpp HipblasltMatrixLayout.cpp ) -target_compile_definitions(hipblaslt_plugin_private PRIVATE) target_include_directories(hipblaslt_plugin_private PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(hipblaslt_plugin_private PUBLIC roc::hipblaslt hipdnn_data_sdk hipdnn_plugin_sdk hip::host) -# Enable spdlog support via plugin_sdk helper function -hipdnn_enable_spdlog(hipblaslt_plugin_private) target_compile_options(hipblaslt_plugin_private PRIVATE ${HIPDNN_WARNING_COMPILE_OPTIONS}) add_library(hipblaslt_plugin SHARED HipblasltPluginPublic.cpp) -target_compile_definitions(hipblaslt_plugin PRIVATE) target_link_libraries(hipblaslt_plugin PRIVATE hipblaslt_plugin_private) target_link_libraries( hipblaslt_plugin PRIVATE "-Xlinker --exclude-libs=ALL" diff --git a/dnn-providers/hipblaslt-provider/HipblasltPlugin.cpp b/dnn-providers/hipblaslt-provider/HipblasltPlugin.cpp index eb58a562374..4a4258c6c4f 100644 --- a/dnn-providers/hipblaslt-provider/HipblasltPlugin.cpp +++ b/dnn-providers/hipblaslt-provider/HipblasltPlugin.cpp @@ -35,53 +35,53 @@ extern "C" { hipdnnPluginStatus_t hipdnnPluginGetNameImpl(const char** name) { - LOG_API_ENTRY("name_ptr={:p}", static_cast(name)); + LOG_API_ENTRY("name_ptr=" << static_cast(name)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(name); *name = pluginName; - LOG_API_SUCCESS(apiName, "pluginName={:p}", static_cast(name)); + LOG_API_SUCCESS(apiName, "pluginName=" << static_cast(name)); }); } hipdnnPluginStatus_t hipdnnPluginGetVersionImpl(const char** version) { - LOG_API_ENTRY("versionPtr={:p}", static_cast(version)); + LOG_API_ENTRY("versionPtr=" << static_cast(version)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(version); *version = pluginVersion; - LOG_API_SUCCESS(apiName, "version={:p}", static_cast(version)); + LOG_API_SUCCESS(apiName, "version=" << static_cast(version)); }); } hipdnnPluginStatus_t hipdnnPluginGetTypeImpl(hipdnnPluginType_t* type) { - LOG_API_ENTRY("typePtr={:p}", static_cast(type)); + LOG_API_ENTRY("typePtr=" << static_cast(type)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(type); *type = HIPDNN_PLUGIN_TYPE_ENGINE; - LOG_API_SUCCESS(apiName, "type={}", toString(*type)); + LOG_API_SUCCESS(apiName, "type=" << toString(*type)); }); } void hipdnnPluginGetLastErrorStringImpl(const char** errorStr) { - LOG_API_ENTRY("errorStrPtr={:p}", static_cast(errorStr)); + LOG_API_ENTRY("errorStrPtr=" << static_cast(errorStr)); hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(errorStr); *errorStr = PluginLastErrorManager::getLastError(); - LOG_API_SUCCESS(apiName, "errorStr={:p}", static_cast(errorStr)); + LOG_API_SUCCESS(apiName, "errorStr=" << static_cast(errorStr)); }); } @@ -90,8 +90,8 @@ hipdnnPluginStatus_t hipdnnPluginSetLoggingCallbackImpl(hipdnnCallback_t callbac { return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(callback); - hipdnn::logging::initializeCallbackLogging(pluginName, callback); - LOG_API_SUCCESS(apiName, "", ""); + hipdnn_plugin_sdk::logging::initializeCallbackLogging(pluginName, callback); + LOG_API_SUCCESS(apiName, ""); }); } @@ -99,10 +99,8 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetAllEngineIdsImpl(int64_t* engineIds, uint32_t maxEngines, uint32_t* numEngines) { - LOG_API_ENTRY("engineIds={:p}, maxEngines={}, numEngines={:p}", - static_cast(engineIds), - maxEngines, - static_cast(numEngines)); + LOG_API_ENTRY("engineIds=" << static_cast(engineIds) << ", maxEngines=" << maxEngines + << ", numEngines=" << static_cast(numEngines)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { if(maxEngines != 0) @@ -130,11 +128,10 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetAllEngineIdsImpl(int64_t* engineIds, if(*numEngines == maxEngines) { *numEngines = static_cast(allEngineIds.size()); - HIPDNN_PLUGIN_LOG_INFO( - "Maximum number of engines reached ({}), ignoring additional " - "engines, numEngines count: {}", - maxEngines, - *numEngines); + HIPDNN_PLUGIN_LOG_INFO("Maximum number of engines reached (" + << maxEngines + << "), ignoring additional engines, numEngines count: " + << *numEngines); break; } @@ -143,13 +140,13 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetAllEngineIdsImpl(int64_t* engineIds, } } - LOG_API_SUCCESS(apiName, "numEngines={}", *numEngines); + LOG_API_SUCCESS(apiName, "numEngines=" << *numEngines); }); } hipdnnPluginStatus_t hipdnnEnginePluginCreateImpl(hipdnnEnginePluginHandle_t* handle) { - LOG_API_ENTRY("handle_ptr={:p}", static_cast(handle)); + LOG_API_ENTRY("handle_ptr=" << static_cast(handle)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -181,13 +178,13 @@ hipdnnPluginStatus_t hipdnnEnginePluginCreateImpl(hipdnnEnginePluginHandle_t* ha } } - LOG_API_SUCCESS(apiName, "createdHandle={:p}", static_cast(*handle)); + LOG_API_SUCCESS(apiName, "createdHandle=" << static_cast(*handle)); }); } hipdnnPluginStatus_t hipdnnEnginePluginDestroyImpl(hipdnnEnginePluginHandle_t handle) { - LOG_API_ENTRY("handle={:p}", static_cast(handle)); + LOG_API_ENTRY("handle=" << static_cast(handle)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -196,22 +193,22 @@ hipdnnPluginStatus_t hipdnnEnginePluginDestroyImpl(hipdnnEnginePluginHandle_t ha delete handle; handle = nullptr; - LOG_API_SUCCESS(apiName, "", ""); + LOG_API_SUCCESS(apiName, ""); }); } hipdnnPluginStatus_t hipdnnEnginePluginSetStreamImpl(hipdnnEnginePluginHandle_t handle, hipStream_t stream) { - LOG_API_ENTRY( - "handle={:p}, stream_id={:p}", static_cast(handle), static_cast(stream)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", stream_id=" << static_cast(stream)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); handle->setStream(stream); - LOG_API_SUCCESS(apiName, "", ""); + LOG_API_SUCCESS(apiName, ""); }); } @@ -222,12 +219,10 @@ hipdnnPluginStatus_t uint32_t maxEngines, uint32_t* numEngines) { - LOG_API_ENTRY("handle={:p}, opGraph={:p}, engineIds={:p}, maxEngines={}, numEngines={:p}", - static_cast(handle), - static_cast(opGraph), - static_cast(engineIds), - maxEngines, - static_cast(numEngines)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", opGraph=" << static_cast(opGraph) << ", engineIds=" + << static_cast(engineIds) << ", maxEngines=" << maxEngines + << ", numEngines=" << static_cast(numEngines)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -249,11 +244,10 @@ hipdnnPluginStatus_t if(*numEngines == maxEngines) { *numEngines = static_cast(applicableEngines.size()); - HIPDNN_PLUGIN_LOG_INFO( - "Maximum number of engines reached ({}), ignoring additional " - "engines, numEngines count: {}", - maxEngines, - *numEngines); + HIPDNN_PLUGIN_LOG_INFO("Maximum number of engines reached (" + << maxEngines + << "), ignoring additional engines, numEngines count: " + << *numEngines); break; } @@ -261,7 +255,7 @@ hipdnnPluginStatus_t (*numEngines)++; } - LOG_API_SUCCESS(apiName, "numEngines={}", *numEngines); + LOG_API_SUCCESS(apiName, "numEngines=" << *numEngines); }); } @@ -270,11 +264,9 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetEngineDetailsImpl(hipdnnEnginePluginHa const hipdnnPluginConstData_t* opGraph, hipdnnPluginConstData_t* engineDetails) { - LOG_API_ENTRY("handle={:p}, engineId={}, opGraph={:p}, engineDetails={:p}", - static_cast(handle), - engineId, - static_cast(opGraph), - static_cast(engineDetails)); + LOG_API_ENTRY("handle=" << static_cast(handle) << ", engineId=" << engineId + << ", opGraph=" << static_cast(opGraph) + << ", engineDetails=" << static_cast(engineDetails)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -286,7 +278,7 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetEngineDetailsImpl(hipdnnEnginePluginHa engineManager.getEngineDetails(*handle, opGraphWrapper, engineId, *engineDetails); - LOG_API_SUCCESS(apiName, "engineDetails->ptr={:p}", engineDetails->ptr); + LOG_API_SUCCESS(apiName, "engineDetails->ptr=" << engineDetails->ptr); }); } @@ -294,9 +286,8 @@ hipdnnPluginStatus_t hipdnnEnginePluginDestroyEngineDetailsImpl(hipdnnEnginePluginHandle_t handle, hipdnnPluginConstData_t* engineDetails) { - LOG_API_ENTRY("handle={:p}, engineDetails={}", - static_cast(handle), - static_cast(engineDetails)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", engineDetails=" << static_cast(engineDetails)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -305,7 +296,7 @@ hipdnnPluginStatus_t handle->removeEngineDetailsDetachedBuffer(engineDetails->ptr); - LOG_API_SUCCESS(apiName, "engineDetails->ptr={:p}", engineDetails->ptr); + LOG_API_SUCCESS(apiName, "engineDetails->ptr=" << engineDetails->ptr); }); } @@ -315,11 +306,10 @@ hipdnnPluginStatus_t const hipdnnPluginConstData_t* opGraph, size_t* workspaceSize) { - LOG_API_ENTRY("handle={:p}, engineConfig={:p}, opGraph={:p}, workspaceSize={:p}", - static_cast(handle), - static_cast(engineConfig), - static_cast(opGraph), - static_cast(workspaceSize)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", engineConfig=" << static_cast(engineConfig) + << ", opGraph=" << static_cast(opGraph) + << ", workspaceSize=" << static_cast(workspaceSize)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -334,7 +324,7 @@ hipdnnPluginStatus_t *workspaceSize = engineManager.getWorkspaceSize( *handle, engineConfigWrapper.engineId(), opGraphWrapper); - LOG_API_SUCCESS(apiName, "workspaceSize={}", *workspaceSize); + LOG_API_SUCCESS(apiName, "workspaceSize=" << *workspaceSize); }); } @@ -344,11 +334,10 @@ hipdnnPluginStatus_t hipdnnEnginePluginCreateExecutionContextImpl( const hipdnnPluginConstData_t* opGraph, hipdnnEnginePluginExecutionContext_t* executionContext) { - LOG_API_ENTRY("handle={:p}, engineConfig={:p}, opGraph={:p}, executionContext={:p}", - static_cast(handle), - static_cast(engineConfig), - static_cast(opGraph), - static_cast(executionContext)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", engineConfig=" << static_cast(engineConfig) + << ", opGraph=" << static_cast(opGraph) + << ", executionContext=" << static_cast(executionContext)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -376,17 +365,16 @@ hipdnnPluginStatus_t hipdnnEnginePluginCreateExecutionContextImpl( *executionContext = context; - LOG_API_SUCCESS( - apiName, "created_execution_context={:p}", static_cast(*executionContext)); + LOG_API_SUCCESS(apiName, + "created_execution_context=" << static_cast(*executionContext)); }); } hipdnnPluginStatus_t hipdnnEnginePluginDestroyExecutionContextImpl( hipdnnEnginePluginHandle_t handle, hipdnnEnginePluginExecutionContext_t executionContext) { - LOG_API_ENTRY("handle={:p}, executionContext={:p}", - static_cast(handle), - static_cast(executionContext)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", executionContext=" << static_cast(executionContext)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -394,7 +382,7 @@ hipdnnPluginStatus_t hipdnnEnginePluginDestroyExecutionContextImpl( delete executionContext; - LOG_API_SUCCESS(apiName, "destroyed executionContext", ""); + LOG_API_SUCCESS(apiName, "destroyed executionContext"); }); } @@ -403,10 +391,9 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetWorkspaceSizeFromExecutionContextImpl( hipdnnEnginePluginExecutionContext_t executionContext, size_t* workspaceSize) { - LOG_API_ENTRY("handle={:p}, executionContext={:p}, workspaceSize={:p}", - static_cast(handle), - static_cast(executionContext), - static_cast(workspaceSize)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", executionContext=" << static_cast(executionContext) + << ", workspaceSize=" << static_cast(workspaceSize)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -415,7 +402,7 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetWorkspaceSizeFromExecutionContextImpl( *workspaceSize = executionContext->plan().getWorkspaceSize(*handle); - LOG_API_SUCCESS(apiName, "workspaceSize={}", *workspaceSize); + LOG_API_SUCCESS(apiName, "workspaceSize=" << *workspaceSize); }); } @@ -426,13 +413,10 @@ hipdnnPluginStatus_t const hipdnnPluginDeviceBuffer_t* deviceBuffers, uint32_t numDeviceBuffers) { - LOG_API_ENTRY("handle={:p}, executionContext={:p}, workspace={:p}, deviceBuffers={:p}, " - "numDeviceBuffers={}", - static_cast(handle), - static_cast(executionContext), - workspace, - static_cast(deviceBuffers), - numDeviceBuffers); + LOG_API_ENTRY("handle=" << static_cast(handle) << ", executionContext=" + << static_cast(executionContext) << ", workspace=" << workspace + << ", deviceBuffers=" << static_cast(deviceBuffers) + << ", numDeviceBuffers=" << numDeviceBuffers); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -441,7 +425,7 @@ hipdnnPluginStatus_t executionContext->plan().execute(*handle, deviceBuffers, numDeviceBuffers, workspace); - LOG_API_SUCCESS(apiName, "executed graph", ""); + LOG_API_SUCCESS(apiName, "executed graph"); }); } diff --git a/dnn-providers/hipblaslt-provider/HipblasltUtils.hpp b/dnn-providers/hipblaslt-provider/HipblasltUtils.hpp index 42751723d9d..612ee8d5b81 100644 --- a/dnn-providers/hipblaslt-provider/HipblasltUtils.hpp +++ b/dnn-providers/hipblaslt-provider/HipblasltUtils.hpp @@ -13,15 +13,15 @@ #include #include -#define LOG_ON_HIPBLASLT_FAILURE(status) \ - do \ - { \ - if(status != HIPBLAS_STATUS_SUCCESS) \ - { \ - HIPDNN_PLUGIN_LOG_ERROR( \ - "hipBLASLt error occurred: {}", \ - hipblaslt_plugin::hipblaslt_utils::hipblas_status_to_string(status)); \ - } \ +#define LOG_ON_HIPBLASLT_FAILURE(status) \ + do \ + { \ + if(status != HIPBLAS_STATUS_SUCCESS) \ + { \ + HIPDNN_PLUGIN_LOG_ERROR( \ + "hipBLASLt error occurred: " \ + << hipblaslt_plugin::hipblaslt_utils::hipblas_status_to_string(status)); \ + } \ } while(0) #define THROW_ON_HIPBLASLT_FAILURE(status) \ diff --git a/dnn-providers/hipblaslt-provider/HipdnnEnginePluginHandle.hpp b/dnn-providers/hipblaslt-provider/HipdnnEnginePluginHandle.hpp index 0f12dad1785..ea5132367c5 100644 --- a/dnn-providers/hipblaslt-provider/HipdnnEnginePluginHandle.hpp +++ b/dnn-providers/hipblaslt-provider/HipdnnEnginePluginHandle.hpp @@ -41,13 +41,13 @@ struct HipdnnEnginePluginHandle void storeEngineDetailsDetachedBuffer(const void* ptr, std::unique_ptr buffer) { - HIPDNN_PLUGIN_LOG_INFO("Storing detached buffer at address: {:p}", ptr); + HIPDNN_PLUGIN_LOG_INFO("Storing detached buffer at address: " << ptr); _engineDetailsBuffers[ptr] = std::move(buffer); } void removeEngineDetailsDetachedBuffer(const void* ptr) { - HIPDNN_PLUGIN_LOG_INFO("Removing detached buffer at address: {:p}", ptr); + HIPDNN_PLUGIN_LOG_INFO("Removing detached buffer at address: " << ptr); auto it = _engineDetailsBuffers.find(ptr); if(it != _engineDetailsBuffers.end()) @@ -57,10 +57,11 @@ struct HipdnnEnginePluginHandle else { HIPDNN_PLUGIN_LOG_WARN( - "No detached buffer found at address: {:p}. Could not remove engine " - "details. Ensure you " - "are using the same hipdnn handle you used for engine details creation", - ptr); + "No detached buffer found at address: " + << ptr + << ". Could not remove engine " + "details. Ensure you " + "are using the same hipdnn handle you used for engine details creation"); } } diff --git a/dnn-providers/hipblaslt-provider/engines/plans/HipblasltMatmulPlanBuilder.cpp b/dnn-providers/hipblaslt-provider/engines/plans/HipblasltMatmulPlanBuilder.cpp index 1164b37d09a..150e4c12f2a 100644 --- a/dnn-providers/hipblaslt-provider/engines/plans/HipblasltMatmulPlanBuilder.cpp +++ b/dnn-providers/hipblaslt-provider/engines/plans/HipblasltMatmulPlanBuilder.cpp @@ -119,7 +119,7 @@ void HipblasltMatmulPlanBuilder::buildPlan( validateGraphConfiguration(opGraph); const auto& nodeWrapper = opGraph.getNodeWrapper(0); - HIPDNN_PLUGIN_LOG_INFO("Building matmul plan for node: {}", nodeWrapper.name()); + HIPDNN_PLUGIN_LOG_INFO("Building matmul plan for node: " << nodeWrapper.name()); const auto& attr = nodeWrapper.attributesAs(); MatmulParams params(attr, opGraph.getTensorMap()); diff --git a/dnn-providers/hipblaslt-provider/integration_tests/CMakeLists.txt b/dnn-providers/hipblaslt-provider/integration_tests/CMakeLists.txt index f8902efb28e..eb6c5f20607 100644 --- a/dnn-providers/hipblaslt-provider/integration_tests/CMakeLists.txt +++ b/dnn-providers/hipblaslt-provider/integration_tests/CMakeLists.txt @@ -25,9 +25,6 @@ target_link_libraries( hipblaslt_plugin_integration_tests PUBLIC GTest::gtest hip::host hipdnn_test_sdk hipdnn_plugin_sdk Threads::Threads ) -# Enable spdlog support for fmt-style logging -hipdnn_enable_spdlog(hipblaslt_plugin_integration_tests) - # Ensure that the hipblaslt_plugin is built before the hipblaslt_plugin_integration_tests, as the # integration tests depend on the hipBLASLt Provider Plugin add_dependencies(hipblaslt_plugin_integration_tests hipblaslt_plugin) diff --git a/dnn-providers/hipblaslt-provider/integration_tests/IntegrationGraphVerificationHarness.hpp b/dnn-providers/hipblaslt-provider/integration_tests/IntegrationGraphVerificationHarness.hpp index 70a7997f815..48c5ac0ccb7 100644 --- a/dnn-providers/hipblaslt-provider/integration_tests/IntegrationGraphVerificationHarness.hpp +++ b/dnn-providers/hipblaslt-provider/integration_tests/IntegrationGraphVerificationHarness.hpp @@ -89,7 +89,7 @@ class IntegrationGraphVerificationHarness : public ::testing::TestWithParam -#include #include #include @@ -19,7 +18,5 @@ int main(int argc, char** argv) testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); listeners.Append(new hipdnn_test_sdk::utilities::HipErrorHandler); - auto result = RUN_ALL_TESTS(); - spdlog::shutdown(); - return result; + return RUN_ALL_TESTS(); } diff --git a/dnn-providers/hipblaslt-provider/tests/main.cpp b/dnn-providers/hipblaslt-provider/tests/main.cpp index ba9c7e27059..783aa565360 100644 --- a/dnn-providers/hipblaslt-provider/tests/main.cpp +++ b/dnn-providers/hipblaslt-provider/tests/main.cpp @@ -4,7 +4,6 @@ SPDX-License-Identifier: MIT */ #include -#include #include #include @@ -13,14 +12,12 @@ SPDX-License-Identifier: MIT int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - hipdnn::logging::initializeCallbackLogging("hipblaslt_plugin_tests", - hipdnn_test_sdk::utilities::testLoggingCallback); + hipdnn_plugin_sdk::logging::initializeCallbackLogging( + "hipblaslt_plugin_tests", hipdnn_test_sdk::utilities::testLoggingCallback); // Register HipErrorHandler to check and clear HIP errors after each test testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); listeners.Append(new hipdnn_test_sdk::utilities::HipErrorHandler); - auto result = RUN_ALL_TESTS(); - spdlog::shutdown(); - return result; + return RUN_ALL_TESTS(); } diff --git a/dnn-providers/miopen-provider/CMakeLists.txt b/dnn-providers/miopen-provider/CMakeLists.txt index fae8c5c43cb..adbe0972aa9 100644 --- a/dnn-providers/miopen-provider/CMakeLists.txt +++ b/dnn-providers/miopen-provider/CMakeLists.txt @@ -132,12 +132,9 @@ add_library( MiopenPlugin.cpp MiopenPluginPublic.cpp ) -target_compile_definitions(miopen_plugin_impl PRIVATE) target_include_directories(miopen_plugin_impl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(miopen_plugin_impl PUBLIC MIOpen hipdnn_data_sdk hipdnn_plugin_sdk) -# Enable spdlog support via plugin_sdk helper function -hipdnn_enable_spdlog(miopen_plugin_impl) target_compile_options(miopen_plugin_impl PRIVATE ${HIPDNN_WARNING_COMPILE_OPTIONS}) set_target_properties(miopen_plugin_impl PROPERTIES CXX_VISIBILITY_PRESET hidden @@ -150,16 +147,14 @@ endif() # Static library for unit tests to link against (provides access to internal implementation) add_library(miopen_plugin_private STATIC $) -target_compile_definitions(miopen_plugin_private PRIVATE) target_include_directories(miopen_plugin_private PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -# Link to miopen_plugin_impl to inherit its PUBLIC properties (including spdlog setup) +# Link to miopen_plugin_impl to inherit its PUBLIC properties target_link_libraries(miopen_plugin_private PUBLIC MIOpen hipdnn_data_sdk hipdnn_plugin_sdk miopen_plugin_impl) # Backwards compatibility alias add_library(miopen_legacy_plugin_private ALIAS miopen_plugin_private) # miopen_legacy_plugin - REAL target for current TheRock compatibility add_library(miopen_legacy_plugin SHARED $) -target_compile_definitions(miopen_legacy_plugin PRIVATE) target_link_libraries(miopen_legacy_plugin PRIVATE MIOpen hipdnn_data_sdk hipdnn_plugin_sdk) target_link_libraries(miopen_legacy_plugin PRIVATE "-Xlinker --exclude-libs=ALL") target_compile_options(miopen_legacy_plugin PRIVATE ${HIPDNN_WARNING_COMPILE_OPTIONS}) @@ -176,7 +171,6 @@ set_target_properties( # miopen_plugin - REAL target for updated TheRock add_library(miopen_plugin SHARED $) -target_compile_definitions(miopen_plugin PRIVATE) target_link_libraries(miopen_plugin PRIVATE MIOpen hipdnn_data_sdk hipdnn_plugin_sdk) target_link_libraries(miopen_plugin PRIVATE "-Xlinker --exclude-libs=ALL") target_compile_options(miopen_plugin PRIVATE ${HIPDNN_WARNING_COMPILE_OPTIONS}) diff --git a/dnn-providers/miopen-provider/HipdnnEnginePluginHandle.hpp b/dnn-providers/miopen-provider/HipdnnEnginePluginHandle.hpp index d3b5127092e..e8e5464426d 100644 --- a/dnn-providers/miopen-provider/HipdnnEnginePluginHandle.hpp +++ b/dnn-providers/miopen-provider/HipdnnEnginePluginHandle.hpp @@ -42,13 +42,13 @@ struct HipdnnEnginePluginHandle void storeEngineDetailsDetachedBuffer(const void* ptr, std::unique_ptr buffer) { - HIPDNN_PLUGIN_LOG_INFO("Storing detached buffer at address: {:p}", ptr); + HIPDNN_PLUGIN_LOG_INFO("Storing detached buffer at address: " << ptr); _engineDetailsBuffers[ptr] = std::move(buffer); } void removeEngineDetailsDetachedBuffer(const void* ptr) { - HIPDNN_PLUGIN_LOG_INFO("Removing detached buffer at address: {:p}", ptr); + HIPDNN_PLUGIN_LOG_INFO("Removing detached buffer at address: " << ptr); auto it = _engineDetailsBuffers.find(ptr); if(it != _engineDetailsBuffers.end()) @@ -58,10 +58,11 @@ struct HipdnnEnginePluginHandle else { HIPDNN_PLUGIN_LOG_WARN( - "No detached buffer found at address: {:p}. Could not remove engine " - "details. Ensure you " - "are using the same hipdnn handle you used for engine details creation", - ptr); + "No detached buffer found at address: " + << ptr + << ". Could not remove engine " + "details. Ensure you " + "are using the same hipdnn handle you used for engine details creation"); } } diff --git a/dnn-providers/miopen-provider/MiopenPlugin.cpp b/dnn-providers/miopen-provider/MiopenPlugin.cpp index e701fe1d757..e0a0f11afba 100644 --- a/dnn-providers/miopen-provider/MiopenPlugin.cpp +++ b/dnn-providers/miopen-provider/MiopenPlugin.cpp @@ -41,53 +41,53 @@ extern "C" { hipdnnPluginStatus_t hipdnnPluginGetNameImpl(const char** name) { - LOG_API_ENTRY("name_ptr={:p}", static_cast(name)); + LOG_API_ENTRY("name_ptr=" << static_cast(name)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(name); *name = pluginName; - LOG_API_SUCCESS(apiName, "pluginName={:p}", static_cast(name)); + LOG_API_SUCCESS(apiName, "pluginName=" << static_cast(name)); }); } hipdnnPluginStatus_t hipdnnPluginGetVersionImpl(const char** version) { - LOG_API_ENTRY("versionPtr={:p}", static_cast(version)); + LOG_API_ENTRY("versionPtr=" << static_cast(version)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(version); *version = pluginVersion; - LOG_API_SUCCESS(apiName, "version={:p}", static_cast(version)); + LOG_API_SUCCESS(apiName, "version=" << static_cast(version)); }); } hipdnnPluginStatus_t hipdnnPluginGetTypeImpl(hipdnnPluginType_t* type) { - LOG_API_ENTRY("typePtr={:p}", static_cast(type)); + LOG_API_ENTRY("typePtr=" << static_cast(type)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(type); *type = HIPDNN_PLUGIN_TYPE_ENGINE; - LOG_API_SUCCESS(apiName, "type={}", toString(*type)); + LOG_API_SUCCESS(apiName, "type=" << toString(*type)); }); } void hipdnnPluginGetLastErrorStringImpl(const char** errorStr) { - LOG_API_ENTRY("errorStrPtr={:p}", static_cast(errorStr)); + LOG_API_ENTRY("errorStrPtr=" << static_cast(errorStr)); hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(errorStr); *errorStr = PluginLastErrorManager::getLastError(); - LOG_API_SUCCESS(apiName, "errorStr={:p}", static_cast(errorStr)); + LOG_API_SUCCESS(apiName, "errorStr=" << static_cast(errorStr)); }); } @@ -96,8 +96,8 @@ hipdnnPluginStatus_t hipdnnPluginSetLoggingCallbackImpl(hipdnnCallback_t callbac { return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(callback); - hipdnn::logging::initializeCallbackLogging(pluginName, callback); - LOG_API_SUCCESS(apiName, "", ""); + hipdnn_plugin_sdk::logging::initializeCallbackLogging(pluginName, callback); + LOG_API_SUCCESS(apiName, ""); }); } @@ -105,10 +105,8 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetAllEngineIdsImpl(int64_t* engineIds, uint32_t maxEngines, uint32_t* numEngines) { - LOG_API_ENTRY("engineIds={:p}, maxEngines={}, numEngines={:p}", - static_cast(engineIds), - maxEngines, - static_cast(numEngines)); + LOG_API_ENTRY("engineIds=" << static_cast(engineIds) << ", maxEngines=" << maxEngines + << ", numEngines=" << static_cast(numEngines)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { if(maxEngines != 0) @@ -119,13 +117,13 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetAllEngineIdsImpl(int64_t* engineIds, auto totalEngines = MiopenContainer::copyEngineIds(engineIds, maxEngines, *numEngines); - LOG_API_SUCCESS(apiName, "numEngines={} totalEngines={}", *numEngines, totalEngines); + LOG_API_SUCCESS(apiName, "numEngines=" << *numEngines << " totalEngines=" << totalEngines); }); } hipdnnPluginStatus_t hipdnnEnginePluginCreateImpl(hipdnnEnginePluginHandle_t* handle) { - LOG_API_ENTRY("handle_ptr={:p}", static_cast(handle)); + LOG_API_ENTRY("handle_ptr=" << static_cast(handle)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -157,13 +155,13 @@ hipdnnPluginStatus_t hipdnnEnginePluginCreateImpl(hipdnnEnginePluginHandle_t* ha } } - LOG_API_SUCCESS(apiName, "createdHandle={:p}", static_cast(*handle)); + LOG_API_SUCCESS(apiName, "createdHandle=" << static_cast(*handle)); }); } hipdnnPluginStatus_t hipdnnEnginePluginDestroyImpl(hipdnnEnginePluginHandle_t handle) { - LOG_API_ENTRY("handle={:p}", static_cast(handle)); + LOG_API_ENTRY("handle=" << static_cast(handle)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -172,22 +170,22 @@ hipdnnPluginStatus_t hipdnnEnginePluginDestroyImpl(hipdnnEnginePluginHandle_t ha delete handle; handle = nullptr; - LOG_API_SUCCESS(apiName, "", ""); + LOG_API_SUCCESS(apiName, ""); }); } hipdnnPluginStatus_t hipdnnEnginePluginSetStreamImpl(hipdnnEnginePluginHandle_t handle, hipStream_t stream) { - LOG_API_ENTRY( - "handle={:p}, stream_id={:p}", static_cast(handle), static_cast(stream)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", stream_id=" << static_cast(stream)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); handle->setStream(stream); - LOG_API_SUCCESS(apiName, "", ""); + LOG_API_SUCCESS(apiName, ""); }); } @@ -198,12 +196,10 @@ hipdnnPluginStatus_t uint32_t maxEngines, uint32_t* numEngines) { - LOG_API_ENTRY("handle={:p}, opGraph={:p}, engineIds={:p}, maxEngines={}, numEngines={:p}", - static_cast(handle), - static_cast(opGraph), - static_cast(engineIds), - maxEngines, - static_cast(numEngines)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", opGraph=" << static_cast(opGraph) << ", engineIds=" + << static_cast(engineIds) << ", maxEngines=" << maxEngines + << ", numEngines=" << static_cast(numEngines)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -225,11 +221,10 @@ hipdnnPluginStatus_t if(*numEngines == maxEngines) { *numEngines = static_cast(applicableEngines.size()); - HIPDNN_PLUGIN_LOG_INFO( - "Maximum number of engines reached ({}), ignoring additional " - "engines, numEngines count: {}", - maxEngines, - *numEngines); + HIPDNN_PLUGIN_LOG_INFO("Maximum number of engines reached (" + << maxEngines + << "), ignoring additional engines, numEngines count: " + << *numEngines); break; } @@ -237,7 +232,7 @@ hipdnnPluginStatus_t (*numEngines)++; } - LOG_API_SUCCESS(apiName, "numEngines={}", *numEngines); + LOG_API_SUCCESS(apiName, "numEngines=" << *numEngines); }); } @@ -246,11 +241,9 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetEngineDetailsImpl(hipdnnEnginePluginHa const hipdnnPluginConstData_t* opGraph, hipdnnPluginConstData_t* engineDetails) { - LOG_API_ENTRY("handle={:p}, engineId={}, opGraph={:p}, engineDetails={:p}", - static_cast(handle), - engineId, - static_cast(opGraph), - static_cast(engineDetails)); + LOG_API_ENTRY("handle=" << static_cast(handle) << ", engineId=" << engineId + << ", opGraph=" << static_cast(opGraph) + << ", engineDetails=" << static_cast(engineDetails)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -262,7 +255,7 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetEngineDetailsImpl(hipdnnEnginePluginHa engineManager.getEngineDetails(*handle, opGraphWrapper, engineId, *engineDetails); - LOG_API_SUCCESS(apiName, "engineDetails->ptr={:p}", engineDetails->ptr); + LOG_API_SUCCESS(apiName, "engineDetails->ptr=" << engineDetails->ptr); }); } @@ -270,9 +263,8 @@ hipdnnPluginStatus_t hipdnnEnginePluginDestroyEngineDetailsImpl(hipdnnEnginePluginHandle_t handle, hipdnnPluginConstData_t* engineDetails) { - LOG_API_ENTRY("handle={:p}, engineDetails={}", - static_cast(handle), - static_cast(engineDetails)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", engineDetails=" << static_cast(engineDetails)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -281,7 +273,7 @@ hipdnnPluginStatus_t handle->removeEngineDetailsDetachedBuffer(engineDetails->ptr); - LOG_API_SUCCESS(apiName, "engineDetails->ptr={:p}", engineDetails->ptr); + LOG_API_SUCCESS(apiName, "engineDetails->ptr=" << engineDetails->ptr); }); } @@ -291,11 +283,10 @@ hipdnnPluginStatus_t const hipdnnPluginConstData_t* opGraph, size_t* workspaceSize) { - LOG_API_ENTRY("handle={:p}, engineConfig={:p}, opGraph={:p}, workspaceSize={:p}", - static_cast(handle), - static_cast(engineConfig), - static_cast(opGraph), - static_cast(workspaceSize)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", engineConfig=" << static_cast(engineConfig) + << ", opGraph=" << static_cast(opGraph) + << ", workspaceSize=" << static_cast(workspaceSize)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -310,7 +301,7 @@ hipdnnPluginStatus_t *workspaceSize = engineManager.getWorkspaceSize( *handle, engineConfigWrapper.engineId(), opGraphWrapper); - LOG_API_SUCCESS(apiName, "workspaceSize={}", *workspaceSize); + LOG_API_SUCCESS(apiName, "workspaceSize=" << *workspaceSize); }); } @@ -320,11 +311,10 @@ hipdnnPluginStatus_t hipdnnEnginePluginCreateExecutionContextImpl( const hipdnnPluginConstData_t* opGraph, hipdnnEnginePluginExecutionContext_t* executionContext) { - LOG_API_ENTRY("handle={:p}, engineConfig={:p}, opGraph={:p}, executionContext={:p}", - static_cast(handle), - static_cast(engineConfig), - static_cast(opGraph), - static_cast(executionContext)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", engineConfig=" << static_cast(engineConfig) + << ", opGraph=" << static_cast(opGraph) + << ", executionContext=" << static_cast(executionContext)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -352,17 +342,16 @@ hipdnnPluginStatus_t hipdnnEnginePluginCreateExecutionContextImpl( *executionContext = context; - LOG_API_SUCCESS( - apiName, "created_execution_context={:p}", static_cast(*executionContext)); + LOG_API_SUCCESS(apiName, + "created_execution_context=" << static_cast(*executionContext)); }); } hipdnnPluginStatus_t hipdnnEnginePluginDestroyExecutionContextImpl( hipdnnEnginePluginHandle_t handle, hipdnnEnginePluginExecutionContext_t executionContext) { - LOG_API_ENTRY("handle={:p}, executionContext={:p}", - static_cast(handle), - static_cast(executionContext)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", executionContext=" << static_cast(executionContext)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -370,7 +359,7 @@ hipdnnPluginStatus_t hipdnnEnginePluginDestroyExecutionContextImpl( delete executionContext; - LOG_API_SUCCESS(apiName, "destroyed executionContext", ""); + LOG_API_SUCCESS(apiName, "destroyed executionContext"); }); } @@ -379,10 +368,9 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetWorkspaceSizeFromExecutionContextImpl( hipdnnEnginePluginExecutionContext_t executionContext, size_t* workspaceSize) { - LOG_API_ENTRY("handle={:p}, executionContext={:p}, workspaceSize={:p}", - static_cast(handle), - static_cast(executionContext), - static_cast(workspaceSize)); + LOG_API_ENTRY("handle=" << static_cast(handle) + << ", executionContext=" << static_cast(executionContext) + << ", workspaceSize=" << static_cast(workspaceSize)); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -391,7 +379,7 @@ hipdnnPluginStatus_t hipdnnEnginePluginGetWorkspaceSizeFromExecutionContextImpl( *workspaceSize = executionContext->plan().getWorkspaceSize(*handle); - LOG_API_SUCCESS(apiName, "workspaceSize={}", *workspaceSize); + LOG_API_SUCCESS(apiName, "workspaceSize=" << *workspaceSize); }); } @@ -402,13 +390,10 @@ hipdnnPluginStatus_t const hipdnnPluginDeviceBuffer_t* deviceBuffers, uint32_t numDeviceBuffers) { - LOG_API_ENTRY("handle={:p}, executionContext={:p}, workspace={:p}, deviceBuffers={:p}, " - "numDeviceBuffers={}", - static_cast(handle), - static_cast(executionContext), - workspace, - static_cast(deviceBuffers), - numDeviceBuffers); + LOG_API_ENTRY("handle=" << static_cast(handle) << ", executionContext=" + << static_cast(executionContext) << ", workspace=" << workspace + << ", deviceBuffers=" << static_cast(deviceBuffers) + << ", numDeviceBuffers=" << numDeviceBuffers); return hipdnn_plugin_sdk::tryCatch([&, apiName = __func__]() { throwIfNull(handle); @@ -417,7 +402,7 @@ hipdnnPluginStatus_t executionContext->plan().execute(*handle, deviceBuffers, numDeviceBuffers, workspace); - LOG_API_SUCCESS(apiName, "executed graph", ""); + LOG_API_SUCCESS(apiName, "executed graph"); }); } diff --git a/dnn-providers/miopen-provider/MiopenUtils.hpp b/dnn-providers/miopen-provider/MiopenUtils.hpp index 3c21c559c24..638f57023e3 100644 --- a/dnn-providers/miopen-provider/MiopenUtils.hpp +++ b/dnn-providers/miopen-provider/MiopenUtils.hpp @@ -22,7 +22,7 @@ { \ if(status != miopenStatusSuccess) \ { \ - HIPDNN_PLUGIN_LOG_ERROR("MIOpen error occurred: {}", miopenGetErrorString(status)); \ + HIPDNN_PLUGIN_LOG_ERROR("MIOpen error occurred: " << miopenGetErrorString(status)); \ } \ } while(0) @@ -66,8 +66,8 @@ class ScopedTuningPolicy auto status = miopenGetTuningPolicy(_handle, &_originalPolicy); if(status != miopenStatusSuccess) { - HIPDNN_PLUGIN_LOG_ERROR("Failed to get tuning policy: {}", - miopenGetErrorString(status)); + HIPDNN_PLUGIN_LOG_ERROR( + "Failed to get tuning policy: " << miopenGetErrorString(status)); _originalPolicy = miopenTuningPolicyNone; // Fallback } @@ -76,8 +76,8 @@ class ScopedTuningPolicy status = miopenSetTuningPolicy(_handle, policy); if(status != miopenStatusSuccess) { - HIPDNN_PLUGIN_LOG_ERROR("Failed to set tuning policy: {}", - miopenGetErrorString(status)); + HIPDNN_PLUGIN_LOG_ERROR( + "Failed to set tuning policy: " << miopenGetErrorString(status)); } } @@ -87,8 +87,8 @@ class ScopedTuningPolicy auto status = miopenSetTuningPolicy(_handle, _originalPolicy); if(status != miopenStatusSuccess) { - HIPDNN_PLUGIN_LOG_ERROR("Failed to restore tuning policy: {}", - miopenGetErrorString(status)); + HIPDNN_PLUGIN_LOG_ERROR( + "Failed to restore tuning policy: " << miopenGetErrorString(status)); } } diff --git a/dnn-providers/miopen-provider/engines/MiopenEngine.cpp b/dnn-providers/miopen-provider/engines/MiopenEngine.cpp index aefaa234933..c5b5462b839 100644 --- a/dnn-providers/miopen-provider/engines/MiopenEngine.cpp +++ b/dnn-providers/miopen-provider/engines/MiopenEngine.cpp @@ -118,8 +118,8 @@ void MiopenEngine::initializeExecutionContext( else { HIPDNN_PLUGIN_LOG_WARN( - "Benchmarking knob setting value is not an integer. Type: {}", - hipdnn_data_sdk::data_objects::EnumNameKnobValue(knobSetting.valueType())); + "Benchmarking knob setting value is not an integer. Type: " + << hipdnn_data_sdk::data_objects::EnumNameKnobValue(knobSetting.valueType())); } } } diff --git a/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormFwdTrainingPlan.cpp b/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormFwdTrainingPlan.cpp index 652012cbcc8..f8bb766a5b8 100644 --- a/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormFwdTrainingPlan.cpp +++ b/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormFwdTrainingPlan.cpp @@ -237,8 +237,8 @@ void BatchnormFwdTrainingPlan::execute(const HipdnnEnginePluginHandle& handle, if(_trainingParams.hasRunningStats()) { expAvgFactor = _trainingParams.momentumValue(); - HIPDNN_PLUGIN_LOG_INFO("BatchnormFwdTrainingPlan: expAvgFactor (momentum) = {}", - expAvgFactor); + HIPDNN_PLUGIN_LOG_INFO( + "BatchnormFwdTrainingPlan: expAvgFactor (momentum) = " << expAvgFactor); } // Get all required device buffers diff --git a/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormPlanBuilder.cpp b/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormPlanBuilder.cpp index 5d10bab821f..bc1fd3055e3 100644 --- a/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormPlanBuilder.cpp +++ b/dnn-providers/miopen-provider/engines/plans/MiopenBatchnormPlanBuilder.cpp @@ -590,8 +590,8 @@ bool MiopenBatchnormPlanBuilder::isApplicable( { HIPDNN_PLUGIN_LOG_INFO( "Batchnorm plan builder is applicable only for 1, 2 or 3 node graphs. " - "Graph has {} nodes", - opGraph.nodeCount()); + "Graph has " + << opGraph.nodeCount() << " nodes"); return false; } } @@ -760,20 +760,20 @@ void MiopenBatchnormPlanBuilder::buildPlan( switch(nodeWrapper.attributesType()) { case hipdnn_data_sdk::data_objects::NodeAttributes::BatchnormInferenceAttributes: - HIPDNN_PLUGIN_LOG_INFO("Building batchnorm fwd inference plan for node: {}", nodeName); + HIPDNN_PLUGIN_LOG_INFO("Building batchnorm fwd inference plan for node: " << nodeName); buildPlanInferenceSingleNode(handle, opGraph, nodeWrapper, executionContext); break; case hipdnn_data_sdk::data_objects::NodeAttributes::BatchnormInferenceAttributesVarianceExt: - HIPDNN_PLUGIN_LOG_INFO("Building batchnorm fwd inference with variance plan for node: {}", - nodeName); + HIPDNN_PLUGIN_LOG_INFO( + "Building batchnorm fwd inference with variance plan for node: " << nodeName); buildPlanInferenceWithVarianceSingleNode(handle, opGraph, nodeWrapper, executionContext); break; case hipdnn_data_sdk::data_objects::NodeAttributes::BatchnormAttributes: - HIPDNN_PLUGIN_LOG_INFO("Building batchnorm fwd training plan for node: {}", nodeName); + HIPDNN_PLUGIN_LOG_INFO("Building batchnorm fwd training plan for node: " << nodeName); buildPlanFwdTrainingSingleNode(handle, opGraph, nodeWrapper, executionContext); break; case hipdnn_data_sdk::data_objects::NodeAttributes::BatchnormBackwardAttributes: - HIPDNN_PLUGIN_LOG_INFO("Building batchnorm backward plan for node: {}", nodeName); + HIPDNN_PLUGIN_LOG_INFO("Building batchnorm backward plan for node: " << nodeName); buildPlanBwdSingleNode(handle, opGraph, nodeWrapper, executionContext); break; default: diff --git a/dnn-providers/miopen-provider/engines/plans/MiopenConvPlanBuilder.cpp b/dnn-providers/miopen-provider/engines/plans/MiopenConvPlanBuilder.cpp index 802b5f1d9f2..422703d3664 100644 --- a/dnn-providers/miopen-provider/engines/plans/MiopenConvPlanBuilder.cpp +++ b/dnn-providers/miopen-provider/engines/plans/MiopenConvPlanBuilder.cpp @@ -247,8 +247,8 @@ bool MiopenConvPlanBuilder::isApplicable( { HIPDNN_PLUGIN_LOG_INFO( "Convolution plan builder is applicable only for single node graphs. Graph " - "has {} nodes", - opGraph.nodeCount()); + "has " + << opGraph.nodeCount() << " nodes"); return false; } @@ -334,15 +334,15 @@ void MiopenConvPlanBuilder::buildPlan( switch(nodeWrapper.attributesType()) { case hipdnn_data_sdk::data_objects::NodeAttributes::ConvolutionFwdAttributes: - HIPDNN_PLUGIN_LOG_INFO("Building convolution fwd plan for node: {}", nodeName); + HIPDNN_PLUGIN_LOG_INFO("Building convolution fwd plan for node: " << nodeName); buildPlanFwd(handle, opGraph, executionContext, _deterministic); break; case hipdnn_data_sdk::data_objects::NodeAttributes::ConvolutionBwdAttributes: - HIPDNN_PLUGIN_LOG_INFO("Building convolution bwd plan for node: {}", nodeName); + HIPDNN_PLUGIN_LOG_INFO("Building convolution bwd plan for node: " << nodeName); buildPlanBwd(handle, opGraph, executionContext, _deterministic); break; case hipdnn_data_sdk::data_objects::NodeAttributes::ConvolutionWrwAttributes: - HIPDNN_PLUGIN_LOG_INFO("Building convolution wrw plan for node: {}", nodeName); + HIPDNN_PLUGIN_LOG_INFO("Building convolution wrw plan for node: " << nodeName); buildPlanWrw(handle, opGraph, executionContext, _deterministic); break; default: diff --git a/dnn-providers/miopen-provider/integration_tests/CMakeLists.txt b/dnn-providers/miopen-provider/integration_tests/CMakeLists.txt index 71a36d9d719..66fa932d043 100644 --- a/dnn-providers/miopen-provider/integration_tests/CMakeLists.txt +++ b/dnn-providers/miopen-provider/integration_tests/CMakeLists.txt @@ -39,9 +39,6 @@ target_link_libraries( miopen_plugin_integration_tests PUBLIC GTest::gtest hip::host hipdnn_test_sdk hipdnn_plugin_sdk Threads::Threads ) -# Enable spdlog support for fmt-style logging -hipdnn_enable_spdlog(miopen_plugin_integration_tests) - # Ensure that the miopen_plugin is built before the integration tests add_dependencies(miopen_plugin_integration_tests miopen_plugin) diff --git a/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormForwardTraining.cpp b/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormForwardTraining.cpp index 540c66dd653..e0819a4e05a 100644 --- a/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormForwardTraining.cpp +++ b/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormForwardTraining.cpp @@ -64,7 +64,7 @@ class BatchnormForwardTraining : public IntegrationGraphVerificationHarnessGetParam(); - HIPDNN_PLUGIN_LOG_INFO("Test is using {} for its random seed", testCase.seed); + HIPDNN_PLUGIN_LOG_INFO("Test is using " << testCase.seed << " for its random seed"); hipdnn_frontend::graph::Graph graphObj; graphObj.set_name("BatchnormForwardTrainingTest"); diff --git a/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormFwdTrainingActiv.cpp b/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormFwdTrainingActiv.cpp index c25cff507a9..44ee3a61f69 100644 --- a/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormFwdTrainingActiv.cpp +++ b/dnn-providers/miopen-provider/integration_tests/IntegrationGpuBatchnormFwdTrainingActiv.cpp @@ -69,7 +69,7 @@ class BatchnormFwdTrainingActivation { const auto& [bnTestCase, activTestCase] = this->GetParam(); - HIPDNN_PLUGIN_LOG_INFO("Test is using {} for its random seed", bnTestCase.seed); + HIPDNN_PLUGIN_LOG_INFO("Test is using " << bnTestCase.seed << " for its random seed"); hipdnn_frontend::graph::Graph graphObj; graphObj.set_name("BatchnormFwdTrainingActivTest"); diff --git a/dnn-providers/miopen-provider/integration_tests/IntegrationGraphVerificationHarness.hpp b/dnn-providers/miopen-provider/integration_tests/IntegrationGraphVerificationHarness.hpp index 4f9bf127ce9..0e5d0475b05 100644 --- a/dnn-providers/miopen-provider/integration_tests/IntegrationGraphVerificationHarness.hpp +++ b/dnn-providers/miopen-provider/integration_tests/IntegrationGraphVerificationHarness.hpp @@ -90,7 +90,7 @@ class IntegrationGraphVerificationHarness : public ::testing::TestWithParam -#include #include #include @@ -19,7 +18,5 @@ int main(int argc, char** argv) testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); listeners.Append(new hipdnn_test_sdk::utilities::HipErrorHandler); - auto result = RUN_ALL_TESTS(); - spdlog::shutdown(); - return result; + return RUN_ALL_TESTS(); } diff --git a/dnn-providers/miopen-provider/tests/main.cpp b/dnn-providers/miopen-provider/tests/main.cpp index dd04251240c..7b97043e03f 100644 --- a/dnn-providers/miopen-provider/tests/main.cpp +++ b/dnn-providers/miopen-provider/tests/main.cpp @@ -4,7 +4,6 @@ SPDX-License-Identifier: MIT */ #include -#include #include #include @@ -13,14 +12,12 @@ SPDX-License-Identifier: MIT int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - hipdnn::logging::initializeCallbackLogging("miopen_plugin_tests", - hipdnn_test_sdk::utilities::testLoggingCallback); + hipdnn_plugin_sdk::logging::initializeCallbackLogging( + "miopen_plugin_tests", hipdnn_test_sdk::utilities::testLoggingCallback); // Register HipErrorHandler to check and clear HIP errors after each test testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); listeners.Append(new hipdnn_test_sdk::utilities::HipErrorHandler); - auto result = RUN_ALL_TESTS(); - spdlog::shutdown(); - return result; + return RUN_ALL_TESTS(); } diff --git a/projects/hipdnn/backend/src/logging/CallbackSink.hpp b/projects/hipdnn/backend/src/logging/CallbackSink.hpp deleted file mode 100644 index f33d302a6be..00000000000 --- a/projects/hipdnn/backend/src/logging/CallbackSink.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright © Advanced Micro Devices, Inc., or its affiliates. -// SPDX-License-Identifier: MIT - -#pragma once - -#include "LoggingUtils.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace hipdnn::backend::logging -{ - -inline hipdnnSeverity_t spdlogToHipdnnSeverity(spdlog::level::level_enum level) -{ - switch(level) - { - case spdlog::level::critical: - return HIPDNN_SEV_FATAL; - case spdlog::level::err: - return HIPDNN_SEV_ERROR; - case spdlog::level::warn: - return HIPDNN_SEV_WARN; - case spdlog::level::off: - return HIPDNN_SEV_OFF; - default: - return HIPDNN_SEV_INFO; - } -} - -// This warning is for cross-compiler compatibility, so it's safe to ignore since we only use Clang. -// Moreover, MSVC is likely the incompatible compiler here. -// NOLINTBEGIN(portability-template-virtual-member-function) -template -class CallbackSink final : public spdlog::sinks::base_sink -{ -public: - explicit CallbackSink(hipdnnCallback_t callback) - : _callbackFn{callback} - { - } - ~CallbackSink() override = default; - -protected: - void sink_it_(const spdlog::details::log_msg& msg) override - { - if(_callbackFn == nullptr) - { - return; - } - - spdlog::memory_buf_t formatted; - spdlog::sinks::base_sink::formatter_->format(msg, formatted); - std::string formattedStr(formatted.data(), formatted.size()); - - while(!formattedStr.empty() && (formattedStr.back() == '\n' || formattedStr.back() == '\r')) - { - formattedStr.pop_back(); - } - - hipdnnSeverity_t severity = spdlogToHipdnnSeverity(msg.level); - - _callbackFn(severity, formattedStr.c_str()); - } - - void flush_() override {} - -private: - hipdnnCallback_t _callbackFn; -}; -// NOLINTEND(portability-template-virtual-member-function) - -using CallbackSinkMt = CallbackSink; - -inline std::shared_ptr createAsyncCallbackLoggerMt(hipdnnCallback_t callback, - const std::string& source) -{ - auto sink = std::make_shared(callback); - auto logger = std::make_shared( - source, sink, spdlog::thread_pool(), spdlog::async_overflow_policy::block); - logger->set_pattern(generatePatternString(source)); - logger->flush_on(spdlog::level::info); - return logger; -} - -template -inline std::shared_ptr createCallbackLoggerMt(hipdnnCallback_t callback, - const std::string& source) -{ - auto logger = Factory::template create(source, callback); - logger->set_pattern(generatePatternString(source)); - return logger; -} - -} // namespace hipdnn::backend::logging diff --git a/projects/hipdnn/backend/src/logging/ComponentFormatter.hpp b/projects/hipdnn/backend/src/logging/ComponentFormatter.hpp deleted file mode 100644 index 9e47745e531..00000000000 --- a/projects/hipdnn/backend/src/logging/ComponentFormatter.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright © Advanced Micro Devices, Inc., or its affiliates. -// SPDX-License-Identifier: MIT - -#pragma once - -#include "LoggingUtils.hpp" -#include -#include -#include -#include - -namespace hipdnn::backend::logging -{ - -class ComponentFormatter final : public spdlog::formatter -{ -public: - // NOLINTNEXTLINE(modernize-use-equals-default) - not trivial, has member initializer - ComponentFormatter() - : _callbackReceiverFormatter{ - std::make_unique(generateCallbackReceiverPatternString())} - { - } - - // NOLINTNEXTLINE(readability-convert-member-functions-to-static) - virtual override - void format(const spdlog::details::log_msg& msg, spdlog::memory_buf_t& dest) override - { - // The logger "hipdnn_callback_receiver" receives pre-formatted strings from a callback sink. - // The component name is already prepended to the message, so we use a pattern without [component]. - if(msg.logger_name == "hipdnn_callback_receiver") - { - _callbackReceiverFormatter->format(msg, dest); - } - else - { - auto standardFormatter = std::make_unique( - generatePatternString(std::string(msg.logger_name.data(), msg.logger_name.size()))); - standardFormatter->format(msg, dest); - } - } - - // NOLINTNEXTLINE(readability-convert-member-functions-to-static) - virtual override - std::unique_ptr clone() const override - { - return std::make_unique(); - } - -private: - std::unique_ptr _callbackReceiverFormatter; -}; - -} // namespace hipdnn::backend::logging diff --git a/projects/hipdnn/backend/src/logging/Logging.cpp b/projects/hipdnn/backend/src/logging/Logging.cpp index 32725d9d6e9..e7906e32945 100644 --- a/projects/hipdnn/backend/src/logging/Logging.cpp +++ b/projects/hipdnn/backend/src/logging/Logging.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT #include "Logging.hpp" -#include "ComponentFormatter.hpp" #include "PlatformUtils.hpp" #include @@ -31,7 +30,16 @@ namespace std::mutex s_loggingInitMutex; // NOLINT(readability-identifier-naming) bool s_loggingInitialized = false; // NOLINT(readability-identifier-naming) const std::string S_BACKEND_LOGGER_NAME = "hipdnn_backend"; -const std::string S_CALLBACK_RECEIVER_LOGGER_NAME = "hipdnn_callback_receiver"; + +// Pattern string for the backend logger. +// Component name is already included in messages (e.g., "[hipdnn_backend] ..."), +// so the pattern includes timestamp, thread ID, and log level, but not a component name. +constexpr const char* BACKEND_LOGGER_PATTERN = "[%Y-%m-%d %H:%M:%S.%e] [tid %t] [%l] %v"; + +std::shared_ptr getBackendLogger() +{ + return spdlog::get(S_BACKEND_LOGGER_NAME); +} } // namespace @@ -99,10 +107,12 @@ void initialize() // Register the global callback so non-backend components can send logs to the backend hipdnn_data_sdk::logging::registerLoggingCallback(hipdnnLoggingCallback); - std::string logLevel = hipdnn_data_sdk::utilities::getEnv("HIPDNN_LOG_LEVEL", "off"); + std::string logLevelStr = hipdnn_data_sdk::utilities::getEnv("HIPDNN_LOG_LEVEL", "off"); + hipdnnSeverity_t logLevel + = hipdnn_data_sdk::logging::detail::stringToSeverityOrOff(logLevelStr); // It doesn't need to return if logLevel == off, but it avoids unnecessary initialization - if(logLevel == "off") + if(logLevel == HIPDNN_SEV_OFF) { s_loggingInitialized = true; return; @@ -128,21 +138,19 @@ void initialize() auto backendLogger = std::make_shared( S_BACKEND_LOGGER_NAME, sharedSink, spdlog::thread_pool()); - // In spdlog, the formatting is a property of the underlying sink, not the logger. - // However, we need one destination sink for thread safety because the mutex is attached to the sink. - // Therefore, we implement a custom formatter to have distinct formatting for the backend, which does not use a callback sink. - backendLogger->set_formatter( - std::make_unique()); - spdlog::register_logger(backendLogger); + // Use a simple pattern formatter for the single unified logger + // Component name is already included in the message (e.g., "[hipdnn_backend] ...") + backendLogger->set_pattern(BACKEND_LOGGER_PATTERN); - auto callbackReceiverLogger = std::make_shared( - S_CALLBACK_RECEIVER_LOGGER_NAME, sharedSink, spdlog::thread_pool()); - // Use ComponentFormatter which detects "hipdnn_callback_receiver" and applies appropriate formatting - callbackReceiverLogger->set_formatter( - std::make_unique()); - spdlog::register_logger(callbackReceiverLogger); + // Set spdlog to accept all messages (trace is most verbose) + // Actual filtering is done in HIPDNN_BACKEND_LOG*() macro via isLogLevelEnabled() + backendLogger->set_level(spdlog::level::trace); + + spdlog::register_logger(backendLogger); - setLogLevel(logLevel); + // Update the data_sdk log level cache for use by the + // HIPDNN_BACKEND_LOG*() macros to filter-out logs based on level. + hipdnn_data_sdk::logging::setLogLevel(logLevel); s_loggingInitialized = true; @@ -165,64 +173,47 @@ void cleanup() s_loggingInitialized = false; } -void setLogLevel(const std::string& level) +namespace { - if(level == "off") - { - spdlog::set_level(spdlog::level::off); - } - else if(level == "info") - { - spdlog::set_level(spdlog::level::info); - } - else if(level == "warn") - { - spdlog::set_level(spdlog::level::warn); - } - else if(level == "error") - { - spdlog::set_level(spdlog::level::err); - } - else if(level == "fatal") +// Helper to convert hipdnnSeverity_t to spdlog level +spdlog::level::level_enum toSpdlogLevel(hipdnnSeverity_t severity) +{ + switch(severity) { - spdlog::set_level(spdlog::level::critical); + case HIPDNN_SEV_FATAL: + return spdlog::level::critical; + case HIPDNN_SEV_ERROR: + return spdlog::level::err; + case HIPDNN_SEV_WARN: + return spdlog::level::warn; + case HIPDNN_SEV_INFO: + return spdlog::level::info; + case HIPDNN_SEV_OFF: + default: + return spdlog::level::off; } } +} // namespace -std::shared_ptr getCallbackReceiverLogger() +void logMessage(hipdnnSeverity_t severity, const std::string& message) { - return spdlog::get(S_CALLBACK_RECEIVER_LOGGER_NAME); -} + // Check log level using data_sdk infrastructure + if(!hipdnn_data_sdk::logging::isLogLevelEnabled(severity)) + { + return; + } -std::shared_ptr getBackendLogger() -{ - return spdlog::get(S_BACKEND_LOGGER_NAME); + if(auto logger = getBackendLogger()) + { + logger->log(toSpdlogLevel(severity), message); + } } void hipdnnLoggingCallback(hipdnnSeverity_t severity, const char* msg) { - initialize(); - - if(auto logger = getCallbackReceiverLogger()) - { - switch(severity) - { - case HIPDNN_SEV_FATAL: - logger->critical(msg); - break; - case HIPDNN_SEV_ERROR: - logger->error(msg); - break; - case HIPDNN_SEV_WARN: - logger->warn(msg); - break; - case HIPDNN_SEV_OFF: - break; - default: - logger->info(msg); - break; - } - } + // Message already includes component name from source (frontend/plugins) + // Route through central backend logMessage function + logMessage(severity, msg); } } // namespace logging diff --git a/projects/hipdnn/backend/src/logging/Logging.hpp b/projects/hipdnn/backend/src/logging/Logging.hpp index ccc31a9166f..4a99533cb95 100644 --- a/projects/hipdnn/backend/src/logging/Logging.hpp +++ b/projects/hipdnn/backend/src/logging/Logging.hpp @@ -12,25 +12,52 @@ // Backend-specific logging macros // These are separate from HIPDNN_LOG_* used by frontend/plugins to avoid conflicts #ifdef HIPDNN_BACKEND_COMPILATION -#define _HIPDNN_BACKEND_LOG_ACTION(spdlog_level, ...) \ - do \ - { \ - hipdnn_backend::logging::initialize(); \ - auto _logger = hipdnn_backend::logging::getBackendLogger(); \ - if(_logger && _logger->should_log(spdlog_level)) \ - { \ - _logger->log(spdlog_level, __VA_ARGS__); \ - } \ +#include +#include + +#define HIPDNN_BACKEND_LOG_INFO(...) \ + do \ + { \ + hipdnn_backend::logging::initialize(); \ + if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_INFO)) \ + { \ + hipdnn_backend::logging::logMessage( \ + HIPDNN_SEV_INFO, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \ + } \ + } while(0) + +#define HIPDNN_BACKEND_LOG_WARN(...) \ + do \ + { \ + hipdnn_backend::logging::initialize(); \ + if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_WARN)) \ + { \ + hipdnn_backend::logging::logMessage( \ + HIPDNN_SEV_WARN, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \ + } \ + } while(0) + +#define HIPDNN_BACKEND_LOG_ERROR(...) \ + do \ + { \ + hipdnn_backend::logging::initialize(); \ + if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_ERROR)) \ + { \ + hipdnn_backend::logging::logMessage( \ + HIPDNN_SEV_ERROR, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \ + } \ } while(0) -#define HIPDNN_BACKEND_LOG_INFO(...) \ - _HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::info, __VA_ARGS__) -#define HIPDNN_BACKEND_LOG_WARN(...) \ - _HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::warn, __VA_ARGS__) -#define HIPDNN_BACKEND_LOG_ERROR(...) \ - _HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::err, __VA_ARGS__) -#define HIPDNN_BACKEND_LOG_FATAL(...) \ - _HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::critical, __VA_ARGS__) +#define HIPDNN_BACKEND_LOG_FATAL(...) \ + do \ + { \ + hipdnn_backend::logging::initialize(); \ + if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_FATAL)) \ + { \ + hipdnn_backend::logging::logMessage( \ + HIPDNN_SEV_FATAL, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \ + } \ + } while(0) #endif // HIPDNN_BACKEND_COMPILATION namespace hipdnn_backend::logging @@ -40,11 +67,7 @@ void initialize(); void cleanup(); -void setLogLevel(const std::string& level); - -std::shared_ptr getBackendLogger(); - -std::shared_ptr getCallbackReceiverLogger(); +void logMessage(hipdnnSeverity_t severity, const std::string& message); void hipdnnLoggingCallback(hipdnnSeverity_t severity, const char* msg); diff --git a/projects/hipdnn/backend/src/logging/LoggingUtils.hpp b/projects/hipdnn/backend/src/logging/LoggingUtils.hpp deleted file mode 100644 index 20db90c6e28..00000000000 --- a/projects/hipdnn/backend/src/logging/LoggingUtils.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © Advanced Micro Devices, Inc., or its affiliates. -// SPDX-License-Identifier: MIT - -#pragma once - -#include - -namespace hipdnn::backend::logging -{ - -/** - * @brief Generate the spdlog pattern string for a component - * - * This is used internally by the backend for formatting log messages. - * The pattern includes timestamp, thread ID, log level, and component name. - * - * @param componentName The name of the component - * @return The spdlog pattern string - */ -inline std::string generatePatternString(const std::string& componentName) -{ - return "[%Y-%m-%d %H:%M:%S.%e] [tid %t] [%l] [" + componentName + "] %v"; -} - -/** - * @brief Generate the spdlog pattern string for callback-received messages - * - * This is used for messages received via the logging callback from non-backend components. - * The component name is already prepended to the message, so we only add timestamp, thread ID, and level. - * - * @return The spdlog pattern string - */ -inline std::string generateCallbackReceiverPatternString() -{ - return "[%Y-%m-%d %H:%M:%S.%e] [tid %t] [%l] %v"; -} - -} // namespace hipdnn::backend::logging diff --git a/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LogLevel.hpp b/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LogLevel.hpp index d812529a47e..d824803533a 100644 --- a/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LogLevel.hpp +++ b/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LogLevel.hpp @@ -6,8 +6,10 @@ #include "CallbackTypes.h" #include #include +#include #include +#include #include namespace hipdnn_data_sdk::logging @@ -29,25 +31,53 @@ HIPDNN_HIDDEN inline std::atomic& getLogLevelInitialized() return s_initialized; } -inline hipdnnSeverity_t stringToSeverity(const std::string& level) +/** + * @brief Convert a log level string to severity enum + * + * Valid levels are: "off", "info", "warn", "error", "fatal" (case-insensitive, whitespace-tolerant) + * + * @param level The log level string to convert + * @return The severity enum if valid, std::nullopt if the string is not a valid log level + */ +inline std::optional stringToSeverity(const std::string& level) { - if(level == "info") + // Normalize input: trim whitespace and convert to lowercase + std::string normalized = utilities::toLower(utilities::trim(level)); + + if(normalized == "off") + { + return HIPDNN_SEV_OFF; + } + if(normalized == "info") { return HIPDNN_SEV_INFO; } - if(level == "warn") + if(normalized == "warn") { return HIPDNN_SEV_WARN; } - if(level == "error") + if(normalized == "error") { return HIPDNN_SEV_ERROR; } - if(level == "fatal") + if(normalized == "fatal") { return HIPDNN_SEV_FATAL; } - return HIPDNN_SEV_OFF; + return std::nullopt; +} + +/** + * @brief Convert a log level string to severity enum, defaulting to OFF for invalid input + * + * This is a convenience wrapper around stringToSeverity() that treats invalid input as OFF. + * + * @param level The log level string to convert + * @return The severity enum, or HIPDNN_SEV_OFF if the string is not a valid log level + */ +inline hipdnnSeverity_t stringToSeverityOrOff(const std::string& level) +{ + return stringToSeverity(level).value_or(HIPDNN_SEV_OFF); } } // namespace detail @@ -65,7 +95,8 @@ inline void initializeLogLevel() } std::string logLevel = hipdnn_data_sdk::utilities::getEnv("HIPDNN_LOG_LEVEL", "off"); - detail::getLogLevelCache().store(detail::stringToSeverity(logLevel), std::memory_order_relaxed); + detail::getLogLevelCache().store(detail::stringToSeverityOrOff(logLevel), + std::memory_order_relaxed); } /** diff --git a/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LoggingUtils.hpp b/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LoggingUtils.hpp index dbf75497730..1fb1f870a99 100644 --- a/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LoggingUtils.hpp +++ b/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/logging/LoggingUtils.hpp @@ -3,27 +3,35 @@ #pragma once -#include -#include +#include "LogLevel.hpp" #include #include namespace hipdnn_data_sdk::logging { -inline constexpr std::array VALID_LOG_LEVELS - = {"off", "info", "warn", "error", "fatal"}; - +/** + * @brief Check if a log level string is valid + * + * Valid levels are: "off", "info", "warn", "error", "fatal" (case-insensitive, whitespace-tolerant) + * + * @param level The log level string to validate + * @return true if the level is valid, false otherwise + */ inline bool isValidLogLevel(const std::string& level) { - return std::find(VALID_LOG_LEVELS.begin(), VALID_LOG_LEVELS.end(), level) - != VALID_LOG_LEVELS.end(); + return detail::stringToSeverity(level).has_value(); } +/** + * @brief Check if logging is currently enabled based on HIPDNN_LOG_LEVEL environment variable + * + * @return true if logging is enabled (level != "off"), false otherwise + */ inline bool isLoggingEnabled() { auto logLevel = hipdnn_data_sdk::utilities::getEnv("HIPDNN_LOG_LEVEL", "off"); - return isValidLogLevel(logLevel) && logLevel != "off"; + return detail::stringToSeverityOrOff(logLevel) != HIPDNN_SEV_OFF; } } // namespace hipdnn_data_sdk::logging diff --git a/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/utilities/StringUtil.hpp b/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/utilities/StringUtil.hpp index 6c6de36ce8f..e6604d532f7 100644 --- a/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/utilities/StringUtil.hpp +++ b/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/utilities/StringUtil.hpp @@ -84,6 +84,17 @@ inline std::string toLower(const std::string& str) return lowerStr; } +inline std::string trim(const std::string& str) +{ + const auto start = str.find_first_not_of(" \t\n\r\f\v"); + if(start == std::string::npos) + { + return ""; + } + const auto end = str.find_last_not_of(" \t\n\r\f\v"); + return str.substr(start, end - start + 1); +} + inline std::string removeNewlines(const std::string& str) { std::string result = str; diff --git a/projects/hipdnn/data_sdk/tests/utilities/TestStringUtil.cpp b/projects/hipdnn/data_sdk/tests/utilities/TestStringUtil.cpp index 03d7b53cd2e..1ba678af9ec 100644 --- a/projects/hipdnn/data_sdk/tests/utilities/TestStringUtil.cpp +++ b/projects/hipdnn/data_sdk/tests/utilities/TestStringUtil.cpp @@ -156,6 +156,56 @@ TEST_F(TestStringUtil, Fnv1aHashKnownValues) EXPECT_NE(hash1, hash2); } +// Tests for trim function +TEST_F(TestStringUtil, TrimRemovesLeadingWhitespace) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(" hello"), "hello"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("\thello"), "hello"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("\nhello"), "hello"); +} + +TEST_F(TestStringUtil, TrimRemovesTrailingWhitespace) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("hello "), "hello"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("hello\t"), "hello"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("hello\n"), "hello"); +} + +TEST_F(TestStringUtil, TrimRemovesBothEnds) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(" hello "), "hello"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("\t\nhello\r\n"), "hello"); +} + +TEST_F(TestStringUtil, TrimHandlesEmptyString) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(""), ""); +} + +TEST_F(TestStringUtil, TrimHandlesAllWhitespace) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(" "), ""); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("\t\n\r"), ""); +} + +TEST_F(TestStringUtil, TrimPreservesInternalWhitespace) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(" hello world "), "hello world"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(" hello\tworld "), "hello\tworld"); +} + +TEST_F(TestStringUtil, TrimHandlesVariousWhitespaceTypes) +{ + // Test all whitespace characters: space, tab, newline, carriage return, form feed, vertical tab + EXPECT_EQ(hipdnn_data_sdk::utilities::trim(" \t\n\r\f\vhello \t\n\r\f\v"), "hello"); +} + +TEST_F(TestStringUtil, TrimNoOpOnTrimmedString) +{ + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("hello"), "hello"); + EXPECT_EQ(hipdnn_data_sdk::utilities::trim("hello world"), "hello world"); +} + // Tests for other StringUtil functions (existing functionality) TEST_F(TestStringUtil, ToLower) { diff --git a/projects/hipdnn/plugin_sdk/include/hipdnn_plugin_sdk/PluginLogging.hpp b/projects/hipdnn/plugin_sdk/include/hipdnn_plugin_sdk/PluginLogging.hpp index 965a1208b44..934451eb64b 100644 --- a/projects/hipdnn/plugin_sdk/include/hipdnn_plugin_sdk/PluginLogging.hpp +++ b/projects/hipdnn/plugin_sdk/include/hipdnn_plugin_sdk/PluginLogging.hpp @@ -29,10 +29,10 @@ // Always include the SDK logging infrastructure #include -#include +#include #include -namespace hipdnn::logging +namespace hipdnn_plugin_sdk::logging { /// Default component name for plugins if not initialized @@ -54,27 +54,27 @@ HIPDNN_HIDDEN inline std::string& getStoredComponentName() return s_componentName; } -HIPDNN_HIDDEN inline std::mutex& getComponentNameMutex() +HIPDNN_HIDDEN inline std::shared_mutex& getComponentNameMutex() { - static std::mutex s_mutex; + static std::shared_mutex s_mutex; return s_mutex; } inline void setComponentName(const std::string& name) { - std::lock_guard lock(getComponentNameMutex()); + std::unique_lock lock(getComponentNameMutex()); getStoredComponentName() = name; } inline std::string getComponentName() { - std::lock_guard lock(getComponentNameMutex()); + std::shared_lock lock(getComponentNameMutex()); return getStoredComponentName(); } } // namespace detail -} // namespace hipdnn::logging +} // namespace hipdnn_plugin_sdk::logging #ifdef HIPDNN_PLUGIN_USE_SPDLOG // ============================================================================ @@ -96,18 +96,18 @@ inline std::string getComponentName() // retrieving component name (which requires mutex lock + string allocation). // Note: spdlog's should_log checks the logger's level, but we can short-circuit // earlier by checking the SDK log level. -#define _HIPDNN_SPDLOG_ACTION(spdlog_level, hipdnn_severity, ...) \ - do \ - { \ - if(::hipdnn_data_sdk::logging::isLogLevelEnabled(hipdnn_severity)) \ - { \ - auto componentName = ::hipdnn::logging::detail::getComponentName(); \ - auto logger = spdlog::get(componentName); \ - if(logger && logger->should_log(spdlog_level)) \ - { \ - logger->log(spdlog_level, __VA_ARGS__); \ - } \ - } \ +#define _HIPDNN_SPDLOG_ACTION(spdlog_level, hipdnn_severity, ...) \ + do \ + { \ + if(::hipdnn_data_sdk::logging::isLogLevelEnabled(hipdnn_severity)) \ + { \ + auto componentName = ::hipdnn_plugin_sdk::logging::detail::getComponentName(); \ + auto logger = spdlog::get(componentName); \ + if(logger && logger->should_log(spdlog_level)) \ + { \ + logger->log(spdlog_level, __VA_ARGS__); \ + } \ + } \ } while(0) #define HIPDNN_PLUGIN_LOG_TRACE(...) \ @@ -121,7 +121,7 @@ inline std::string getComponentName() #define HIPDNN_PLUGIN_LOG_FATAL(...) \ _HIPDNN_SPDLOG_ACTION(spdlog::level::level_enum::critical, HIPDNN_SEV_FATAL, __VA_ARGS__) -namespace hipdnn::logging +namespace hipdnn_plugin_sdk::logging { /** @@ -163,7 +163,7 @@ HIPDNN_HIDDEN inline void initializeCallbackLogging(const std::string& component } } -} // namespace hipdnn::logging +} // namespace hipdnn_plugin_sdk::logging #else // ============================================================================ @@ -175,57 +175,57 @@ HIPDNN_HIDDEN inline void initializeCallbackLogging(const std::string& component // NOTE: Log level is checked BEFORE retrieving component name because // getComponentName() requires a mutex lock and string copy. -#define HIPDNN_PLUGIN_LOG_TRACE(msg) \ - do \ - { \ - if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_INFO)) \ - { \ - auto _hipdnn_comp = ::hipdnn::logging::detail::getComponentName(); \ - HIPDNN_SDK_LOG_INFO_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ - } \ +#define HIPDNN_PLUGIN_LOG_TRACE(msg) \ + do \ + { \ + if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_INFO)) \ + { \ + auto _hipdnn_comp = ::hipdnn_plugin_sdk::logging::detail::getComponentName(); \ + HIPDNN_SDK_LOG_INFO_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ + } \ } while(0) -#define HIPDNN_PLUGIN_LOG_INFO(msg) \ - do \ - { \ - if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_INFO)) \ - { \ - auto _hipdnn_comp = ::hipdnn::logging::detail::getComponentName(); \ - HIPDNN_SDK_LOG_INFO_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ - } \ +#define HIPDNN_PLUGIN_LOG_INFO(msg) \ + do \ + { \ + if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_INFO)) \ + { \ + auto _hipdnn_comp = ::hipdnn_plugin_sdk::logging::detail::getComponentName(); \ + HIPDNN_SDK_LOG_INFO_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ + } \ } while(0) -#define HIPDNN_PLUGIN_LOG_WARN(msg) \ - do \ - { \ - if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_WARN)) \ - { \ - auto _hipdnn_comp = ::hipdnn::logging::detail::getComponentName(); \ - HIPDNN_SDK_LOG_WARN_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ - } \ +#define HIPDNN_PLUGIN_LOG_WARN(msg) \ + do \ + { \ + if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_WARN)) \ + { \ + auto _hipdnn_comp = ::hipdnn_plugin_sdk::logging::detail::getComponentName(); \ + HIPDNN_SDK_LOG_WARN_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ + } \ } while(0) -#define HIPDNN_PLUGIN_LOG_ERROR(msg) \ - do \ - { \ - if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_ERROR)) \ - { \ - auto _hipdnn_comp = ::hipdnn::logging::detail::getComponentName(); \ - HIPDNN_SDK_LOG_ERROR_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ - } \ +#define HIPDNN_PLUGIN_LOG_ERROR(msg) \ + do \ + { \ + if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_ERROR)) \ + { \ + auto _hipdnn_comp = ::hipdnn_plugin_sdk::logging::detail::getComponentName(); \ + HIPDNN_SDK_LOG_ERROR_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ + } \ } while(0) -#define HIPDNN_PLUGIN_LOG_FATAL(msg) \ - do \ - { \ - if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_FATAL)) \ - { \ - auto _hipdnn_comp = ::hipdnn::logging::detail::getComponentName(); \ - HIPDNN_SDK_LOG_FATAL_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ - } \ +#define HIPDNN_PLUGIN_LOG_FATAL(msg) \ + do \ + { \ + if(::hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_FATAL)) \ + { \ + auto _hipdnn_comp = ::hipdnn_plugin_sdk::logging::detail::getComponentName(); \ + HIPDNN_SDK_LOG_FATAL_WITH_COMPONENT(_hipdnn_comp.c_str(), msg); \ + } \ } while(0) -namespace hipdnn::logging +namespace hipdnn_plugin_sdk::logging { /** @@ -244,6 +244,6 @@ inline void initializeCallbackLogging(const std::string& componentName, hipdnn_data_sdk::logging::registerLoggingCallback(callbackFunction); } -} // namespace hipdnn::logging +} // namespace hipdnn_plugin_sdk::logging #endif // HIPDNN_PLUGIN_USE_SPDLOG diff --git a/projects/hipdnn/test_sdk/tests/utilities/TestLoggingUtils.cpp b/projects/hipdnn/test_sdk/tests/utilities/TestLoggingUtils.cpp index 5f8f243c4d4..db650fdf70c 100644 --- a/projects/hipdnn/test_sdk/tests/utilities/TestLoggingUtils.cpp +++ b/projects/hipdnn/test_sdk/tests/utilities/TestLoggingUtils.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include +#include #include #include #include @@ -28,12 +29,27 @@ TEST(TestLoggingUtils, IsValidLogLevelWithInvalidLevels) EXPECT_FALSE(isValidLogLevel("trace")); EXPECT_FALSE(isValidLogLevel("verbose")); EXPECT_FALSE(isValidLogLevel("invalid")); - EXPECT_FALSE(isValidLogLevel("INFO")); - EXPECT_FALSE(isValidLogLevel("Off")); - EXPECT_FALSE(isValidLogLevel("ERROR")); EXPECT_FALSE(isValidLogLevel("123")); - EXPECT_FALSE(isValidLogLevel(" info")); - EXPECT_FALSE(isValidLogLevel("info ")); +} + +TEST(TestLoggingUtils, IsValidLogLevelCaseInsensitive) +{ + // Log levels should be case-insensitive + EXPECT_TRUE(isValidLogLevel("INFO")); + EXPECT_TRUE(isValidLogLevel("Off")); + EXPECT_TRUE(isValidLogLevel("ERROR")); + EXPECT_TRUE(isValidLogLevel("Warn")); + EXPECT_TRUE(isValidLogLevel("FATAL")); +} + +TEST(TestLoggingUtils, IsValidLogLevelTrimsWhitespace) +{ + // Log levels should trim leading/trailing whitespace + EXPECT_TRUE(isValidLogLevel(" info")); + EXPECT_TRUE(isValidLogLevel("info ")); + EXPECT_TRUE(isValidLogLevel(" warn ")); + EXPECT_TRUE(isValidLogLevel("\terror\t")); + EXPECT_TRUE(isValidLogLevel("\n off \n")); } TEST(TestLoggingUtils, IsLoggingEnabledWithValidLevels) @@ -59,3 +75,137 @@ TEST(TestLoggingUtils, IsLoggingEnabledWithInvalidOrUnsetLevels) hipdnn_data_sdk::utilities::unsetEnv("HIPDNN_LOG_LEVEL"); EXPECT_FALSE(isLoggingEnabled()); } + +// ============================================================================ +// Tests for stringToSeverity() - returns std::optional +// ============================================================================ + +TEST(TestStringToSeverity, ValidOffReturnsOptionalWithOff) +{ + auto result = detail::stringToSeverity("off"); + ASSERT_TRUE(result.has_value()); + EXPECT_EQ(result.value(), HIPDNN_SEV_OFF); +} + +TEST(TestStringToSeverity, ValidInfoReturnsOptionalWithInfo) +{ + auto result = detail::stringToSeverity("info"); + ASSERT_TRUE(result.has_value()); + EXPECT_EQ(result.value(), HIPDNN_SEV_INFO); +} + +TEST(TestStringToSeverity, ValidWarnReturnsOptionalWithWarn) +{ + auto result = detail::stringToSeverity("warn"); + ASSERT_TRUE(result.has_value()); + EXPECT_EQ(result.value(), HIPDNN_SEV_WARN); +} + +TEST(TestStringToSeverity, ValidErrorReturnsOptionalWithError) +{ + auto result = detail::stringToSeverity("error"); + ASSERT_TRUE(result.has_value()); + EXPECT_EQ(result.value(), HIPDNN_SEV_ERROR); +} + +TEST(TestStringToSeverity, ValidFatalReturnsOptionalWithFatal) +{ + auto result = detail::stringToSeverity("fatal"); + ASSERT_TRUE(result.has_value()); + EXPECT_EQ(result.value(), HIPDNN_SEV_FATAL); +} + +TEST(TestStringToSeverity, InvalidStringReturnsNullopt) +{ + EXPECT_FALSE(detail::stringToSeverity("invalid").has_value()); + EXPECT_FALSE(detail::stringToSeverity("debug").has_value()); + EXPECT_FALSE(detail::stringToSeverity("trace").has_value()); + EXPECT_FALSE(detail::stringToSeverity("verbose").has_value()); + EXPECT_FALSE(detail::stringToSeverity("123").has_value()); +} + +TEST(TestStringToSeverity, EmptyStringReturnsNullopt) +{ + EXPECT_FALSE(detail::stringToSeverity("").has_value()); +} + +TEST(TestStringToSeverity, CaseInsensitiveMatching) +{ + // Uppercase + ASSERT_TRUE(detail::stringToSeverity("OFF").has_value()); + EXPECT_EQ(detail::stringToSeverity("OFF").value(), HIPDNN_SEV_OFF); + + ASSERT_TRUE(detail::stringToSeverity("INFO").has_value()); + EXPECT_EQ(detail::stringToSeverity("INFO").value(), HIPDNN_SEV_INFO); + + ASSERT_TRUE(detail::stringToSeverity("WARN").has_value()); + EXPECT_EQ(detail::stringToSeverity("WARN").value(), HIPDNN_SEV_WARN); + + ASSERT_TRUE(detail::stringToSeverity("ERROR").has_value()); + EXPECT_EQ(detail::stringToSeverity("ERROR").value(), HIPDNN_SEV_ERROR); + + ASSERT_TRUE(detail::stringToSeverity("FATAL").has_value()); + EXPECT_EQ(detail::stringToSeverity("FATAL").value(), HIPDNN_SEV_FATAL); + + // Mixed case + ASSERT_TRUE(detail::stringToSeverity("Info").has_value()); + EXPECT_EQ(detail::stringToSeverity("Info").value(), HIPDNN_SEV_INFO); + + ASSERT_TRUE(detail::stringToSeverity("WaRn").has_value()); + EXPECT_EQ(detail::stringToSeverity("WaRn").value(), HIPDNN_SEV_WARN); +} + +TEST(TestStringToSeverity, TrimsWhitespace) +{ + // Leading whitespace + ASSERT_TRUE(detail::stringToSeverity(" info").has_value()); + EXPECT_EQ(detail::stringToSeverity(" info").value(), HIPDNN_SEV_INFO); + + // Trailing whitespace + ASSERT_TRUE(detail::stringToSeverity("warn ").has_value()); + EXPECT_EQ(detail::stringToSeverity("warn ").value(), HIPDNN_SEV_WARN); + + // Both ends + ASSERT_TRUE(detail::stringToSeverity(" error ").has_value()); + EXPECT_EQ(detail::stringToSeverity(" error ").value(), HIPDNN_SEV_ERROR); + + // Tabs and newlines + ASSERT_TRUE(detail::stringToSeverity("\tfatal\n").has_value()); + EXPECT_EQ(detail::stringToSeverity("\tfatal\n").value(), HIPDNN_SEV_FATAL); + + // Whitespace-only still invalid + EXPECT_FALSE(detail::stringToSeverity(" ").has_value()); +} + +// ============================================================================ +// Tests for stringToSeverityOrOff() - returns hipdnnSeverity_t (OFF on invalid) +// ============================================================================ + +TEST(TestStringToSeverityOrOff, ValidInputsReturnCorrectEnum) +{ + EXPECT_EQ(detail::stringToSeverityOrOff("off"), HIPDNN_SEV_OFF); + EXPECT_EQ(detail::stringToSeverityOrOff("info"), HIPDNN_SEV_INFO); + EXPECT_EQ(detail::stringToSeverityOrOff("warn"), HIPDNN_SEV_WARN); + EXPECT_EQ(detail::stringToSeverityOrOff("error"), HIPDNN_SEV_ERROR); + EXPECT_EQ(detail::stringToSeverityOrOff("fatal"), HIPDNN_SEV_FATAL); +} + +TEST(TestStringToSeverityOrOff, InvalidInputReturnsOff) +{ + EXPECT_EQ(detail::stringToSeverityOrOff("invalid"), HIPDNN_SEV_OFF); + EXPECT_EQ(detail::stringToSeverityOrOff("debug"), HIPDNN_SEV_OFF); + EXPECT_EQ(detail::stringToSeverityOrOff("trace"), HIPDNN_SEV_OFF); + EXPECT_EQ(detail::stringToSeverityOrOff("123"), HIPDNN_SEV_OFF); +} + +TEST(TestStringToSeverityOrOff, EmptyStringReturnsOff) +{ + EXPECT_EQ(detail::stringToSeverityOrOff(""), HIPDNN_SEV_OFF); +} + +TEST(TestStringToSeverityOrOff, CaseInsensitiveAndTrimsWhitespace) +{ + EXPECT_EQ(detail::stringToSeverityOrOff(" INFO "), HIPDNN_SEV_INFO); + EXPECT_EQ(detail::stringToSeverityOrOff("\tWARN\n"), HIPDNN_SEV_WARN); + EXPECT_EQ(detail::stringToSeverityOrOff("Error"), HIPDNN_SEV_ERROR); +}