// Copyright (c) 2018-2023 Advanced Micro Devices, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. #pragma once #include #include #include "fmt/core.h" #include "fmt/ranges.h" #include #include #include #include #include #include #if !defined(ROCPROFILER_HSA_RUNTIME_EXT_AMD_VERSION) # define ROCPROFILER_HSA_RUNTIME_EXT_AMD_VERSION \ ((10000 * HSA_AMD_INTERFACE_VERSION_MAJOR) + (100 * HSA_AMD_INTERFACE_VERSION_MINOR)) #endif namespace rocprofiler { namespace hsa { namespace utils { template struct is_pair_impl { static constexpr auto value = false; }; template struct is_pair_impl> { static constexpr auto value = true; }; template struct is_pair : is_pair_impl>>> {}; template auto stringize_impl(const Tp& _v) { if constexpr(is_pair::value) { return std::make_pair(stringize_impl(_v.first), stringize_impl(_v.second)); } else if constexpr(fmt::is_formattable::value && !std::is_pointer::value) { return fmt::format("{}", _v); } else { auto _ss = std::stringstream{}; _ss << _v; return _ss.str(); } } template auto stringize(Args... args) { return std::vector>{stringize_impl(args)...}; } template struct handle_formatter { template constexpr auto parse(ParseContext& ctx) { return ctx.begin(); } template auto format(const Tp& v, Ctx& ctx) const { return fmt::format_to(ctx.out(), "handle={}", v.handle); } }; template struct handle_formatter : handle_formatter {}; } // namespace utils } // namespace hsa } // namespace rocprofiler #if ROCPROFILER_HSA_RUNTIME_EXT_AMD_VERSION >= 10300 namespace fmt { template <> struct formatter : rocprofiler::hsa::utils::handle_formatter {}; template <> struct formatter : rocprofiler::hsa::utils::handle_formatter {}; template <> struct formatter { template constexpr auto parse(ParseContext& ctx) { return ctx.begin(); } template auto format(const hsa_amd_memory_access_desc_t& v, Ctx& ctx) const { return fmt::format_to( ctx.out(), "permissions={}, agent_handle={}", v.permissions, v.agent_handle); } }; } // namespace fmt #endif