Use small_vector for API iterate_args (#597)

* Use small_vector for API iterate_args

- replace dim3 value arguments with rocprofiler_dim3_t
  - dim3 has a non-trivial destructor
- common::mpl::unqualified_type
- common::stringified_argument_array_t<N> alias
- assert_public_data_type_properties()
- common::container::small_vector<T>::at function
- stringize returns small_vector<stringified_argument>
  - stack allocated vector
- remove has_pc_sampling condition (HSA, HIP)
  - this will be handled in queue interception

* Misc tweaks
This commit is contained in:
Jonathan R. Madsen
2024-03-13 07:36:55 -05:00
committed by GitHub
parent 2a262235db
commit 8591ed1c96
14 changed files with 175 additions and 97 deletions
+23 -11
View File
@@ -109,6 +109,21 @@ set_data_retval(DataT& _data, Tp _val)
static_assert(std::is_empty<Tp>::value, "Error! unsupported return type");
}
}
template <typename Tp>
decltype(auto)
convert_arg_type(Tp&& val)
{
using data_type = common::mpl::unqualified_type_t<Tp>;
if constexpr(std::is_same<data_type, dim3>::value)
{
return rocprofiler_dim3_t{val.x, val.y, val.z};
}
else
{
return std::forward<Tp>(val);
}
}
} // namespace
hip_api_table_t&
@@ -195,8 +210,6 @@ populate_contexts(rocprofiler_callback_tracing_kind_t callback_domain_idx,
{
if(!itr) continue;
// if(itr->pc_sampler) has_pc_sampling = true;
if(itr->callback_tracer)
{
// if the given domain + op is not enabled, skip this context
@@ -228,7 +241,6 @@ hip_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
auto thr_id = common::get_tid();
auto callback_contexts = std::vector<callback_context_data>{};
auto buffered_contexts = std::vector<buffered_context_data>{};
auto has_pc_sampling = false;
populate_contexts(info_type::callback_domain_idx,
info_type::buffered_domain_idx,
@@ -245,11 +257,11 @@ hip_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
return 0;
}
auto ref_count = (has_pc_sampling) ? 4 : 2;
auto buffer_record = common::init_public_api_struct(buffered_api_data_t{});
auto tracer_data = callback_api_data_t{.size = sizeof(callback_api_data_t)};
auto* corr_id = correlation_service::construct(ref_count);
auto internal_corr_id = corr_id->internal;
constexpr auto ref_count = 2;
auto buffer_record = common::init_public_api_struct(buffered_api_data_t{});
auto tracer_data = common::init_public_api_struct(callback_api_data_t{});
auto* corr_id = correlation_service::construct(ref_count);
auto internal_corr_id = corr_id->internal;
// construct the buffered info before the callback so the callbacks are as closely wrapped
// around the function call as possible
@@ -264,12 +276,12 @@ hip_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
}
tracer_data.size = sizeof(callback_api_data_t);
set_data_args(info_type::get_api_data_args(tracer_data.args), std::forward<Args>(args)...);
// invoke the callbacks
if(!callback_contexts.empty())
{
set_data_args(info_type::get_api_data_args(tracer_data.args), std::forward<Args>(args)...);
set_data_args(info_type::get_api_data_args(tracer_data.args),
convert_arg_type(std::forward<Args>(args))...);
for(auto& itr : callback_contexts)
{
@@ -455,7 +467,7 @@ iterate_args(const uint32_t id,
arg_addr.at(i), // arg_value_addr
arg_list.at(i).indirection_level, // indirection
arg_list.at(i).type, // arg_type
arg_list.at(i).name.c_str(), // arg_name
arg_list.at(i).name, // arg_name
arg_list.at(i).value.c_str(), // arg_value_str
arg_list.at(i).dereference_count, // num deref in str
user_data);
+21 -1
View File
@@ -72,9 +72,29 @@ template <typename... Args>
auto
stringize(int32_t max_deref, Args... args)
{
return std::vector<common::stringified_argument>{common::stringize_arg(
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 hip
} // namespace rocprofiler
namespace fmt
{
template <>
struct formatter<rocprofiler_dim3_t>
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}
template <typename Ctx>
auto format(const rocprofiler_dim3_t& v, Ctx& ctx) const
{
return fmt::format_to(ctx.out(), "{}z={}, y={}, x={}{}", '{', v.z, v.y, v.x, '}');
}
};
} // namespace fmt
+8 -10
View File
@@ -167,7 +167,8 @@ get_table()
.core_ = get_core_table(),
.amd_ext_ = get_amd_ext_table(),
.finalizer_ext_ = get_fini_ext_table(),
.image_ext_ = get_img_ext_table()};
.image_ext_ = get_img_ext_table(),
.tools_ = nullptr};
return tbl;
}
@@ -246,8 +247,6 @@ populate_contexts(rocprofiler_callback_tracing_kind_t callback_domain_idx,
{
if(!itr) continue;
// if(itr->pc_sampler) has_pc_sampling = true;
if(itr->callback_tracer)
{
// if the given domain + op is not enabled, skip this context
@@ -286,7 +285,6 @@ hsa_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
auto thr_id = common::get_tid();
auto callback_contexts = std::vector<callback_context_data>{};
auto buffered_contexts = std::vector<buffered_context_data>{};
auto has_pc_sampling = false;
populate_contexts(info_type::callback_domain_idx,
info_type::buffered_domain_idx,
@@ -303,11 +301,11 @@ hsa_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
return HSA_STATUS_SUCCESS;
}
auto ref_count = (has_pc_sampling) ? 4 : 2;
auto buffer_record = common::init_public_api_struct(buffer_hsa_api_record_t{});
auto tracer_data = common::init_public_api_struct(callback_hsa_api_data_t{});
auto* corr_id = correlation_service::construct(ref_count);
auto internal_corr_id = corr_id->internal;
constexpr auto ref_count = 2;
auto buffer_record = common::init_public_api_struct(buffer_hsa_api_record_t{});
auto tracer_data = common::init_public_api_struct(callback_hsa_api_data_t{});
auto* corr_id = correlation_service::construct(ref_count);
auto internal_corr_id = corr_id->internal;
// construct the buffered info before the callback so the callbacks are as closely wrapped
// around the function call as possible
@@ -513,7 +511,7 @@ iterate_args(const uint32_t id,
arg_addr.at(i), // arg_value_addr
arg_list.at(i).indirection_level, // indirection
arg_list.at(i).type, // arg_type
arg_list.at(i).name.c_str(), // arg_name
arg_list.at(i).name, // arg_name
arg_list.at(i).value.c_str(), // arg_value_str
arg_list.at(i).dereference_count, // num deref in str
user_data);
+2 -1
View File
@@ -75,7 +75,8 @@ template <typename... Args>
auto
stringize(int32_t max_deref, Args... args)
{
return std::vector<common::stringified_argument>{common::stringize_arg(
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); })...};
}
+5 -7
View File
@@ -131,8 +131,7 @@ roctx_api_impl<TableIdx, OpIdx>::exec(FuncT&& _func, Args&&... args)
namespace
{
using correlation_service = context::correlation_tracing_service;
using buffer_marker_api_record_t = rocprofiler_buffer_tracing_marker_api_record_t;
using correlation_service = context::correlation_tracing_service;
struct callback_context_data
{
@@ -162,8 +161,6 @@ populate_contexts(rocprofiler_callback_tracing_kind_t callback_domain_idx,
{
if(!itr) continue;
// if(itr->pc_sampler) has_pc_sampling = true;
if(itr->callback_tracer)
{
// if the given domain + op is not enabled, skip this context
@@ -190,6 +187,7 @@ roctx_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
{
using info_type = roctx_api_info<TableIdx, OpIdx>;
using callback_api_data_t = typename roctx_domain_info<TableIdx>::callback_data_type;
using buffered_api_data_t = typename roctx_domain_info<TableIdx>::buffer_data_type;
auto thr_id = common::get_tid();
auto callback_contexts = std::vector<callback_context_data>{};
@@ -211,8 +209,8 @@ roctx_api_impl<TableIdx, OpIdx>::functor(Args&&... args)
}
auto ref_count = 2;
auto buffer_record = common::init_public_api_struct(buffer_marker_api_record_t{});
auto tracer_data = callback_api_data_t{.size = sizeof(callback_api_data_t)};
auto buffer_record = common::init_public_api_struct(buffered_api_data_t{});
auto tracer_data = common::init_public_api_struct(callback_api_data_t{});
auto* corr_id = correlation_service::construct(ref_count);
auto internal_corr_id = corr_id->internal;
@@ -420,7 +418,7 @@ iterate_args(const uint32_t id,
arg_addr.at(i), // arg_value_addr
arg_list.at(i).indirection_level, // indirection
arg_list.at(i).type, // arg_type
arg_list.at(i).name.c_str(), // arg_name
arg_list.at(i).name, // arg_name
arg_list.at(i).value.c_str(), // arg_value_str
arg_list.at(i).dereference_count, // num deref in str
user_data);
+2 -1
View File
@@ -66,7 +66,8 @@ template <typename... Args>
auto
stringize(int32_t max_deref, Args... args)
{
return std::vector<common::stringified_argument>{common::stringize_arg(
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); })...};
}