From da61c5d1da8cf827f84a21f56e0ca6d8adaa5ab2 Mon Sep 17 00:00:00 2001 From: "Betigeri, Sourabh" Date: Mon, 11 Aug 2025 08:54:24 -0700 Subject: [PATCH] SWDEV-528351 - Cleanup template specializations and overloads for enums (#360) * SWDEV-528351 - Adds temlplate specialization for enums * SWDEV-528351 - Removes template specializations for enums --- hipamd/src/hip_formatting.hpp | 14 +++++ hipamd/src/hip_internal.hpp | 1 - hipamd/src/trace_helper.h | 102 ++-------------------------------- 3 files changed, 20 insertions(+), 97 deletions(-) diff --git a/hipamd/src/hip_formatting.hpp b/hipamd/src/hip_formatting.hpp index 0fae05e1a6..b80051573c 100644 --- a/hipamd/src/hip_formatting.hpp +++ b/hipamd/src/hip_formatting.hpp @@ -923,3 +923,17 @@ inline std::ostream& operator<<(std::ostream& os, const hipIpcEventHandle_t* s) //TODO fill in later return os; } + +inline std::ostream& operator<<(std::ostream& os, const hipPitchedPtr& p) { + os << "pitchPtr:" << std::hex << reinterpret_cast(p.ptr); + return os; +} + +inline std::ostream& operator<<(std::ostream& os, const hipPitchedPtr* p) { + if (p) { + os << *p; + } else { + os << "nullptr"; + } + return os; +} diff --git a/hipamd/src/hip_internal.hpp b/hipamd/src/hip_internal.hpp index 8b33102695..a475c19064 100644 --- a/hipamd/src/hip_internal.hpp +++ b/hipamd/src/hip_internal.hpp @@ -25,7 +25,6 @@ #include "hip_prof_api.h" #include "trace_helper.h" #include "rocclr/utils/debug.hpp" -#include "hip_formatting.hpp" #include "hip_graph_capture.hpp" #include diff --git a/hipamd/src/trace_helper.h b/hipamd/src/trace_helper.h index 98097b27c1..07186cf955 100644 --- a/hipamd/src/trace_helper.h +++ b/hipamd/src/trace_helper.h @@ -20,10 +20,13 @@ #pragma once +#include "hip_formatting.hpp" + #include #include #include #include + //--- // Helper functions to convert HIP function arguments into strings. // Handles POD data types as well as enumerations (ie hipMemcpyKind). @@ -109,6 +112,9 @@ inline std::string ToHexString(T v) { return ss.str(); }; +//--- +// Template overloads for ToString to handle specific types + template inline std::string ToString(T* v) { std::ostringstream ss; @@ -131,9 +137,6 @@ inline std::string ToString(T** v) { return ss.str(); }; -//--- -// Template overloads for ToString to handle specific types - // This is the default which works for most types: template inline std::string ToString(T v) { @@ -142,101 +145,9 @@ inline std::string ToString(T v) { return ss.str(); }; -template <> -inline std::string ToString(hipFunction_t v) { - std::ostringstream ss; - ss << "0x" << std::hex << static_cast(v); - return ss.str(); -}; - -// hipEvent_t specialization. TODO - maybe add an event ID for debug? -template <> -inline std::string ToString(hipEvent_t v) { - std::ostringstream ss; - ss << "event:" << std::hex << static_cast(v); - return ss.str(); -}; -// hipStream_t -template <> -inline std::string ToString(hipStream_t v) { - std::ostringstream ss; - if (v == NULL) { - ss << "stream:"; - } else { - ss << "stream:" << std::hex << static_cast(v); - } - - return ss.str(); -}; - -// hipCtx_t -template <> -inline std::string ToString(hipCtx_t v) { - std::ostringstream ss; - if (v == NULL) { - ss << "context:"; - } else { - ss << "context:" << std::hex << static_cast(v); - } - - return ss.str(); -}; - -// hipPitchedPtr -template <> -inline std::string ToString(hipPitchedPtr v) { - std::ostringstream ss; - ss << "pitchPtr:" << std::hex << static_cast(v.ptr); - return ss.str(); -}; - -// hipMemcpyKind specialization -template <> -inline std::string ToString(hipMemcpyKind v) { - switch (v) { - CASE_STR(hipMemcpyHostToHost); - CASE_STR(hipMemcpyHostToDevice); - CASE_STR(hipMemcpyDeviceToHost); - CASE_STR(hipMemcpyDeviceToDevice); - CASE_STR(hipMemcpyDefault); - CASE_STR(hipMemcpyDeviceToDeviceNoCU); - default: - return ToHexString(v); - }; -}; - -template <> -inline std::string ToString(hipFuncCache_t v) { - switch (v) { - CASE_STR(hipFuncCachePreferNone); - CASE_STR(hipFuncCachePreferShared); - CASE_STR(hipFuncCachePreferL1); - CASE_STR(hipFuncCachePreferEqual); - default: - return ToHexString(v); - }; -}; - -template <> -inline std::string ToString(hipSharedMemConfig v) { - switch (v) { - CASE_STR(hipSharedMemBankSizeDefault); - CASE_STR(hipSharedMemBankSizeFourByte); - CASE_STR(hipSharedMemBankSizeEightByte); - default: - return ToHexString(v); - }; -}; - -template <> -inline std::string ToString(hipError_t v) { - return ihipErrorString(v); -}; - // Catch empty arguments case inline std::string ToString() { return (""); } - //--- // C++11 variadic template - peels off first argument, converts to string, and calls itself again to // peel the next arg. Strings are automatically separated by comma+space. @@ -245,7 +156,6 @@ inline std::string ToString(T first, Args... args) { return ToString(first) + ", " + ToString(args...); } - inline hipError_t ConvertCLErrorIntoHIPError(cl_int cl_error) { hipError_t hip_error = hipSuccess; switch (cl_error) {