[SDK] Callback Tracing Iterate Args Support for rocDecode (#294)

Callback tracing for rocdecode created

[ROCm/rocprofiler-sdk commit: cd4676ae6f]
This commit is contained in:
Trowbridge, Ian
2025-03-23 19:15:30 -05:00
committed by GitHub
parent 8f891cdcc8
commit 374dbc2c9d
6 changed files with 402 additions and 1 deletions
@@ -180,6 +180,12 @@
return std::vector<void*>{ \
GET_ADDR_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)}; \
} \
static auto as_arg_list(callback_data_type trace_data, int32_t max_deref) \
{ \
return utils::stringize( \
max_deref, \
GET_NAMED_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)); \
} \
}; \
} \
}
@@ -0,0 +1,9 @@
#
#
#
set(ROCPROFILER_LIB_ROCDECODE_DETAILS_SOURCES)
set(ROCPROFILER_LIB_ROCDECODE_DETAILS_HEADERS format.hpp)
target_sources(
rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_ROCDECODE_DETAILS_SOURCES}
${ROCPROFILER_LIB_ROCDECODE_DETAILS_HEADERS})
@@ -0,0 +1,315 @@
// MIT License
//
// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
//
// 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 <rocprofiler-sdk/rocdecode/api_args.h>
#include "fmt/core.h"
#define ROCP_SDK_ROCDECODE_FORMATTER(TYPE, ...) \
template <> \
struct formatter<TYPE> : rocprofiler::rocdecode::details::base_formatter \
{ \
template <typename Ctx> \
auto format(const TYPE& v, Ctx& ctx) const \
{ \
return fmt::format_to(ctx.out(), __VA_ARGS__); \
} \
};
#define ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(PREFIX, SUFFIX) \
case PREFIX##_##SUFFIX: return fmt::format_to(ctx.out(), #SUFFIX)
namespace rocprofiler
{
namespace rocdecode
{
namespace details
{
struct base_formatter
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}
};
} // namespace details
} // namespace rocdecode
} // namespace rocprofiler
namespace fmt
{
template <>
struct formatter<rocDecStatus> : rocprofiler::rocdecode::details::base_formatter
{
template <typename Ctx>
auto format(rocDecStatus v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, DEVICE_INVALID);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, CONTEXT_INVALID);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, RUNTIME_ERROR);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, OUTOF_MEMORY);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, INVALID_PARAMETER);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, NOT_IMPLEMENTED);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, NOT_INITIALIZED);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, NOT_SUPPORTED);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(ROCDEC, SUCCESS);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<rocDecDecodeStatus> : rocprofiler::rocdecode::details::base_formatter
{
template <typename Ctx>
auto format(rocDecDecodeStatus v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Invalid);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, InProgress);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Success);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Error);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Error_Concealed);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecodeStatus, Displaying);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<rocDecVideoCodec> : rocprofiler::rocdecode::details::base_formatter
{
template <typename Ctx>
auto format(rocDecVideoCodec v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, MPEG1);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, MPEG2);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, MPEG4);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, AVC);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, HEVC);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, AV1);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, VP8);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, VP9);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, JPEG);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, NumCodecs);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, YUV420);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, YV12);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, NV12);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, YUYV);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoCodec, UYVY);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<rocDecVideoChromaFormat> : rocprofiler::rocdecode::details::base_formatter
{
template <typename Ctx>
auto format(rocDecVideoChromaFormat v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, Monochrome);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, 420);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, 422);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoChromaFormat, 444);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<rocDecVideoSurfaceFormat> : rocprofiler::rocdecode::details::base_formatter
{
template <typename Ctx>
auto format(rocDecVideoSurfaceFormat v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, NV12);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, P016);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV444);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV444_16Bit);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV420);
ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT(rocDecVideoSurfaceFormat, YUV420_16Bit);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
ROCP_SDK_ROCDECODE_FORMATTER(
_RocdecParserParams,
"{}codec_type={},max_num_decode_surfaces={}, clock_rate={}, error_threshold={}, "
"max_display_delay={}, annex_b={}, reserved={}, user_data={}, ext_video_info={}{}",
'{',
v.codec_type,
v.max_num_decode_surfaces,
v.clock_rate,
v.error_threshold,
v.max_display_delay,
v.annex_b,
v.reserved,
v.user_data,
static_cast<void*>(v.ext_video_info),
'}')
ROCP_SDK_ROCDECODE_FORMATTER(RocdecTimeStamp, "{}RocdecTimeStamp={}{}", '{', v, '}')
ROCP_SDK_ROCDECODE_FORMATTER(_RocdecSourceDataPacket,
"{}flags={}, payload_size={}, payload={}, pts={}{}",
'{',
v.flags,
v.payload_size,
static_cast<const void*>(v.payload),
v.pts,
'}')
ROCP_SDK_ROCDECODE_FORMATTER(
_RocDecoderCreateInfo,
"{}device_id={}, width={}, height={}, num_decode_surfaces={}, codec_type={}, chroma_format={}, "
"bit_depth_minus_8={}, intra_decode_only={}, max_width={}, max_height={}, "
"display_rect={}left={}, right={}, top={}, bottom={}{}, target_width={}, target_height={}, "
"num_output_surfaces={}, target_rect={}left={}, right={}, top={}, bottom={}{}{}",
'{',
v.device_id,
v.width,
v.height,
v.num_decode_surfaces,
v.codec_type,
v.chroma_format,
v.bit_depth_minus_8,
v.intra_decode_only,
v.max_width,
v.max_height,
'{',
v.display_rect.left,
v.display_rect.right,
v.display_rect.top,
v.display_rect.bottom,
'}',
v.target_width,
v.target_height,
v.num_output_surfaces,
'{',
v.target_rect.left,
v.target_rect.right,
v.target_rect.top,
v.target_rect.bottom,
'}',
'}')
ROCP_SDK_ROCDECODE_FORMATTER(_RocdecReconfigureDecoderInfo,
"{}width={}, height={}, target_width={}, target_height={}, "
"num_decode_surfaces={}, display_rect={}left={}, right={}, top={}, "
"bottom={}{}, target_rect={}left={}, right={}, top={}, bottom={}{}{}",
'{',
v.width,
v.height,
v.target_width,
v.target_height,
v.num_decode_surfaces,
'{',
v.display_rect.left,
v.display_rect.right,
v.display_rect.top,
v.display_rect.bottom,
'}',
'{',
v.target_rect.left,
v.target_rect.right,
v.target_rect.top,
v.target_rect.bottom,
'}',
'}')
ROCP_SDK_ROCDECODE_FORMATTER(_RocdecDecodeStatus,
"{}decode_status={}, p_reserved={}{}",
'{',
v.decode_status,
v.p_reserved,
'}')
ROCP_SDK_ROCDECODE_FORMATTER(
_RocdecPicParams,
"{}pic_width={}, pic_height={}, curr_pic_idx={}, field_pic_flag={}, bottom_field_flag={}, "
"second_field={}, bitstream_data_len={}, bitstream_data={}, num_slices={}, ref_pic_flag={}, "
"intra_pic_flag={}{}",
'{',
v.pic_width,
v.pic_height,
v.curr_pic_idx,
v.field_pic_flag,
v.bottom_field_flag,
v.second_field,
v.bitstream_data_len,
static_cast<const void*>(v.bitstream_data),
v.num_slices,
v.ref_pic_flag,
v.intra_pic_flag,
'}')
ROCP_SDK_ROCDECODE_FORMATTER(
_RocdecDecodeCaps,
"{}device_id={}, codec_type={}, chroma_format={}, bit_depth_minus_8={}, is_supported={}, "
"num_decoders={}, output_format_mask={}, max_width={}, max_height={}, min_width={}, "
"min_height={}{}",
'{',
v.device_id,
v.codec_type,
v.chroma_format,
v.bit_depth_minus_8,
v.is_supported,
v.num_decoders,
v.output_format_mask,
v.max_width,
v.max_height,
v.min_width,
v.min_height,
'}')
ROCP_SDK_ROCDECODE_FORMATTER(
_RocdecProcParams,
"{}progressive_frame={}, top_field_first={}, raw_input_dptr={}, raw_input_pitch={}, "
"raw_input_format={}, raw_output_dptr={}, raw_output_pitch={}, raw_output_format={}{}",
'{',
v.progressive_frame,
v.top_field_first,
v.raw_input_dptr,
v.raw_input_pitch,
v.raw_input_format,
v.raw_output_dptr,
v.raw_output_pitch,
v.raw_output_format,
'}')
} // namespace fmt
#undef ROCP_SDK_ROCDECODE_FORMATTER
#undef ROCP_SDK_ROCDECODE_FORMAT_CASE_STMT
@@ -556,7 +556,9 @@ using rocdecode_op_args_cb_t = rocprofiler_callback_tracing_operation_args_cb_t;
template const char* name_by_id<TABLE_IDX>(uint32_t); \
template uint32_t id_by_name<TABLE_IDX>(const char*); \
template std::vector<uint32_t> get_ids<TABLE_IDX>(); \
template std::vector<const char*> get_names<TABLE_IDX>();
template std::vector<const char*> get_names<TABLE_IDX>(); \
template void iterate_args<TABLE_IDX>( \
uint32_t, const rocdecode_api_data_t&, rocdecode_op_args_cb_t, int32_t, void*);
INSTANTIATE_ROCDECODE_TABLE_FUNC(rocdecode_api_func_table_t, ROCPROFILER_ROCDECODE_TABLE_ID_CORE)
} // namespace rocdecode
@@ -22,6 +22,7 @@
#include "lib/rocprofiler-sdk/rocdecode/defines.hpp"
#include "lib/rocprofiler-sdk/rocdecode/rocdecode.hpp"
#include "lib/rocprofiler-sdk/rocdecode/utils.hpp"
#include <rocprofiler-sdk/external_correlation.h>
#include <rocprofiler-sdk/fwd.h>
@@ -0,0 +1,68 @@
// MIT License
//
// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
//
// 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 "lib/common/stringize_arg.hpp"
#include "lib/rocprofiler-sdk/rocdecode/details/format.hpp"
#include "fmt/core.h"
#include "fmt/ranges.h"
#include <sstream>
#include <type_traits>
namespace rocprofiler
{
namespace rocdecode
{
namespace utils
{
template <typename Tp>
auto
stringize_impl(const Tp& _v)
{
using value_type = std::decay_t<Tp>;
if constexpr(fmt::is_formattable<value_type>::value && !std::is_pointer<value_type>::value)
{
return fmt::format("{}", _v);
}
else
{
auto _ss = std::stringstream{};
_ss << _v;
return _ss.str();
}
}
template <typename... Args>
auto
stringize(int32_t max_deref, Args... args)
{
using array_type = common::stringified_argument_array_t<sizeof...(Args)>;
return array_type{common::stringize_arg(
max_deref, args, [](const auto& _v) { return stringize_impl(_v); })...};
}
} // namespace utils
} // namespace rocdecode
} // namespace rocprofiler