rocJPEG API Tracing (#73)

* rocDecode API Tracing support

* Test bin file added to rocdecode. Need to add validate python methods

* Added option to not make rocDecode tests

* Added rocdecode and rocprofv3 tests

* Added csv test

* Address PR comments. Changed tests to use built-in rocstreambit decoder to remove ffmpeg dependancy. Changed cmake option to disbale tests rather than not build them. Tests work locally, but will fail until rocDecode is built with tracing enabled on CI

* Add option to avoid building rocdecode tests

* Added option to avoid building rocdecode bin file

* Support for rocJPEG API Trace

* Added newline to rocjpeg_version.h

* json-tool code added, initial test/bin commit

* Formatting

* Resolved rocjpeg bin test compilation errors

* Tests implemented. Perfetto module currently resulting in errors, so need to retest whenever it is fixed

* Formatting and compilation errors

* Minor fixes

* Copyright year update and minor fixes

* Doc update fix

* Added rocjpeg csv file in data

* Addresses review comments: Updated fixed Findroc.. and uses root directory as a hint, fixed documentation error, changed tables to use _CORE, minor style fixes

* Added rocdecode and rocjpeg to CI

* Removed rocdecode and rocjpeg from CI and added back build tests option

* Updated Cmake Files

* Added rocDecode and rocJPEG to CI

* Remove cmake line added in error

* Temporarily modified tests to pass if rocdecode or rocjpeg tracing are not supported for CI, cmake changes

* Added find_package for test

* Added back use of system rocDecode and rocJPEG, modifies system files to include prefix path

* Updated no-link to include INCLUDE_DIR/roc(decode|jpeg), added comments for tests

* Resolve merge conflicts and formatting

* Added regex find and replace instead of include for CI

* VAAPI package causing errors on Vega20

* Removed system rocjpeg and rocdecode use temporarily until cmake issues resolved

* Removed workflows regex

* Formatting and minor test modification

* Modified test for vega20

* Update rocDecode and rocJPEG cmake and tests

* Changelog

* Fix merge conflict

* Added back if-statements around add-tests since cmake-generator-expressions are resulting in errors when the packages are missing

* Removed if found statements, replaced with TARGET:EXISTS

* Skip json file for rocjpeg and rocdecode tests if not supported

* Add os import

---------

Co-authored-by: Kandula, Venkateshwar reddy <Venkateshwarreddy.Kandula@amd.com>
Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
Trowbridge, Ian
2025-02-21 15:43:49 -06:00
committed by GitHub
parent 95e0341266
commit 31fe8858d1
92 changed files with 4614 additions and 242 deletions
+2
View File
@@ -165,5 +165,7 @@ using pc_sampling_host_trap_buffered_output_t =
domain_type::PC_SAMPLING_HOST_TRAP>;
using rocdecode_buffered_output_t =
buffered_output<rocprofiler_buffer_tracing_rocdecode_api_record_t, domain_type::ROCDECODE>;
using rocjpeg_buffered_output_t =
buffered_output<rocprofiler_buffer_tracing_rocjpeg_api_record_t, domain_type::ROCJPEG>;
} // namespace tool
} // namespace rocprofiler
+1
View File
@@ -62,6 +62,7 @@ DEFINE_BUFFER_TYPE_NAME(PC_SAMPLING_HOST_TRAP,
"pc_sampling_host_trap",
"pc_sampling_host_trap_stats")
DEFINE_BUFFER_TYPE_NAME(ROCDECODE, "ROCDECODE_API", "rocdecode_api_trace", "rocdecode_api_stats")
DEFINE_BUFFER_TYPE_NAME(ROCJPEG, "ROCJPEG_API", "rocjpeg_api_trace", "rocjpeg_api_stats")
#undef DEFINE_BUFFER_TYPE_NAME
+1
View File
@@ -38,6 +38,7 @@ enum class domain_type
COUNTER_VALUES,
PC_SAMPLING_HOST_TRAP,
ROCDECODE,
ROCJPEG,
LAST,
};
+42
View File
@@ -766,6 +766,48 @@ generate_csv(const output_config&
}
}
void
generate_csv(const output_config& cfg,
const metadata& tool_metadata,
const generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t>& data,
const stats_entry_t& stats)
{
if(data.empty()) return;
if(cfg.stats && stats)
write_stats(get_stats_output_file(cfg, domain_type::ROCJPEG), stats.entries);
auto ofs = tool::csv_output_file{cfg,
domain_type::ROCJPEG,
tool::csv::api_csv_encoder{},
{"Domain",
"Function",
"Process_Id",
"Thread_Id",
"Correlation_Id",
"Start_Timestamp",
"End_Timestamp"}};
for(auto ditr : data)
{
for(auto record : data.get(ditr))
{
auto row_ss = std::stringstream{};
auto api_name = tool_metadata.get_operation_name(record.kind, record.operation);
rocprofiler::tool::csv::api_csv_encoder::write_row(
row_ss,
tool_metadata.get_kind_name(record.kind),
api_name,
tool_metadata.process_id,
record.thread_id,
record.correlation_id.internal,
record.start_timestamp,
record.end_timestamp);
ofs << row_ss.str();
}
}
}
void
generate_csv(const output_config& cfg,
const metadata& tool_metadata,
+6
View File
@@ -93,6 +93,12 @@ generate_csv(const output_config&
const generator<rocprofiler_buffer_tracing_rocdecode_api_record_t>& data,
const stats_entry_t& stats);
void
generate_csv(const output_config& cfg,
const metadata& tool_metadata,
const generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t>& data,
const stats_entry_t& stats);
void
generate_csv(const output_config& cfg,
const metadata& tool_metadata,
+3 -1
View File
@@ -196,7 +196,8 @@ write_json(json_output& json_ar,
generator<rocprofiler_buffer_tracing_rccl_api_record_t> rccl_api_gen,
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen,
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_gen,
generator<rocprofiler_buffer_tracing_rocdecode_api_record_t> rocdecode_api_gen)
generator<rocprofiler_buffer_tracing_rocdecode_api_record_t> rocdecode_api_gen,
generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t> rocjpeg_api_gen)
{
// summary
@@ -239,6 +240,7 @@ write_json(json_output& json_ar,
json_ar(cereal::make_nvp("scratch_memory", scratch_memory_gen));
json_ar(cereal::make_nvp("pc_sample_host_trap", pc_sampling_gen));
json_ar(cereal::make_nvp("rocdecode_api", rocdecode_api_gen));
json_ar(cereal::make_nvp("rocjpeg_api", rocjpeg_api_gen));
json_ar.finishNode();
}
}
+2 -1
View File
@@ -95,7 +95,8 @@ write_json(json_output& json
generator<rocprofiler_buffer_tracing_rccl_api_record_t> rccl_api_gen,
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen,
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_gen,
generator<rocprofiler_buffer_tracing_rocdecode_api_record_t> rocdecode_api_gen);
generator<rocprofiler_buffer_tracing_rocdecode_api_record_t> rocdecode_api_gen,
generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t> rocjpeg_api_gen);
} // namespace tool
} // namespace rocprofiler
+5 -1
View File
@@ -368,7 +368,8 @@ write_otf2(
std::deque<rocprofiler_buffer_tracing_scratch_memory_record_t>* /*scratch_memory_data*/,
std::deque<rocprofiler_buffer_tracing_rccl_api_record_t>* rccl_api_data,
std::deque<rocprofiler_buffer_tracing_memory_allocation_record_t>* memory_allocation_data,
std::deque<rocprofiler_buffer_tracing_rocdecode_api_record_t>* rocdecode_api_data)
std::deque<rocprofiler_buffer_tracing_rocdecode_api_record_t>* rocdecode_api_data,
std::deque<rocprofiler_buffer_tracing_rocjpeg_api_record_t>* rocjpeg_api_data)
{
namespace sdk = ::rocprofiler::sdk;
@@ -421,6 +422,8 @@ write_otf2(
tids.emplace(itr.thread_id);
for(auto itr : *rocdecode_api_data)
tids.emplace(itr.thread_id);
for(auto itr : *rocjpeg_api_data)
tids.emplace(itr.thread_id);
for(auto itr : *memory_copy_data)
{
@@ -618,6 +621,7 @@ write_otf2(
add_event_data(marker_api_data, sdk::category::marker_api{});
add_event_data(rccl_api_data, sdk::category::rccl_api{});
add_event_data(rocdecode_api_data, sdk::category::rocdecode_api{});
add_event_data(rocjpeg_api_data, sdk::category::rocjpeg_api{});
}
for(auto itr : *memory_copy_data)
+2 -1
View File
@@ -47,6 +47,7 @@ write_otf2(
std::deque<rocprofiler_buffer_tracing_scratch_memory_record_t>* scratch_memory_data,
std::deque<rocprofiler_buffer_tracing_rccl_api_record_t>* rccl_api_data,
std::deque<rocprofiler_buffer_tracing_memory_allocation_record_t>* memory_allocation_data,
std::deque<rocprofiler_buffer_tracing_rocdecode_api_record_t>* rocdecode_api_data);
std::deque<rocprofiler_buffer_tracing_rocdecode_api_record_t>* rocdecode_api_data,
std::deque<rocprofiler_buffer_tracing_rocjpeg_api_record_t>* rocjpeg_api_data);
} // namespace tool
} // namespace rocprofiler
+36 -1
View File
@@ -73,7 +73,8 @@ write_perfetto(
const generator<rocprofiler_buffer_tracing_scratch_memory_record_t>& /*scratch_memory_gen*/,
const generator<rocprofiler_buffer_tracing_rccl_api_record_t>& rccl_api_gen,
const generator<rocprofiler_buffer_tracing_memory_allocation_record_t>& memory_allocation_gen,
const generator<rocprofiler_buffer_tracing_rocdecode_api_record_t>& rocdecode_api_gen)
const generator<rocprofiler_buffer_tracing_rocdecode_api_record_t>& rocdecode_api_gen,
const generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t>& rocjpeg_api_gen)
{
namespace sdk = ::rocprofiler::sdk;
@@ -172,6 +173,9 @@ write_perfetto(
for(auto ditr : rocdecode_api_gen)
for(auto itr : rocdecode_api_gen.get(ditr))
tids.emplace(itr.thread_id);
for(auto ditr : rocjpeg_api_gen)
for(auto itr : rocjpeg_api_gen.get(ditr))
tids.emplace(itr.thread_id);
for(auto ditr : memory_copy_gen)
for(auto itr : memory_copy_gen.get(ditr))
@@ -434,6 +438,37 @@ write_perfetto(
tracing_session->FlushBlocking();
}
for(auto ditr : rocjpeg_api_gen)
for(auto itr : rocjpeg_api_gen.get(ditr))
{
auto name = buffer_names.at(itr.kind, itr.operation);
auto& track = thread_tracks.at(itr.thread_id);
TRACE_EVENT_BEGIN(sdk::perfetto_category<sdk::category::rocjpeg_api>::name,
::perfetto::StaticString(name.data()),
track,
itr.start_timestamp,
::perfetto::Flow::ProcessScoped(itr.correlation_id.internal),
"begin_ns",
itr.start_timestamp,
"end_ns",
itr.end_timestamp,
"delta_ns",
(itr.end_timestamp - itr.start_timestamp),
"tid",
itr.thread_id,
"kind",
itr.kind,
"operation",
itr.operation,
"corr_id",
itr.correlation_id.internal);
TRACE_EVENT_END(sdk::perfetto_category<sdk::category::rocjpeg_api>::name,
track,
itr.end_timestamp);
tracing_session->FlushBlocking();
}
for(auto ditr : memory_copy_gen)
for(auto itr : memory_copy_gen.get(ditr))
{
+2 -1
View File
@@ -47,6 +47,7 @@ write_perfetto(
const generator<rocprofiler_buffer_tracing_scratch_memory_record_t>& scratch_memory_gen,
const generator<rocprofiler_buffer_tracing_rccl_api_record_t>& rccl_api_gen,
const generator<rocprofiler_buffer_tracing_memory_allocation_record_t>& memory_allocation_gen,
const generator<rocprofiler_buffer_tracing_rocdecode_api_record_t>& rocdecode_api_gen);
const generator<rocprofiler_buffer_tracing_rocdecode_api_record_t>& rocdecode_api_gen,
const generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t>& rocjpeg_api_gen);
} // namespace tool
} // namespace rocprofiler
+18
View File
@@ -246,6 +246,24 @@ generate_stats(const output_config& /*cfg*/,
return get_stats(rocdecode_stats);
}
stats_entry_t
generate_stats(const output_config& /*cfg*/,
const metadata& tool_metadata,
const generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t>& data)
{
auto rocjpeg_stats = stats_map_t{};
for(auto ditr : data)
{
for(auto record : data.get(ditr))
{
auto api_name = tool_metadata.get_operation_name(record.kind, record.operation);
rocjpeg_stats[api_name] += (record.end_timestamp - record.start_timestamp);
}
}
return get_stats(rocjpeg_stats);
}
namespace
{
void
+5
View File
@@ -80,6 +80,11 @@ generate_stats(const output_config&
const metadata& tool_metadata,
const generator<rocprofiler_buffer_tracing_rocdecode_api_record_t>& data);
stats_entry_t
generate_stats(const output_config& cfg,
const metadata& tool_metadata,
const generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t>& data);
stats_entry_t
generate_stats(const output_config& cfg,
const metadata& tool_metadata,
@@ -111,6 +111,7 @@ struct config : output_config
bool hip_compiler_api_trace = get_env("ROCPROF_HIP_COMPILER_API_TRACE", false);
bool rccl_api_trace = get_env("ROCPROF_RCCL_API_TRACE", false);
bool rocdecode_api_trace = get_env("ROCPROF_ROCDECODE_API_TRACE", false);
bool rocjpeg_api_trace = get_env("ROCPROF_ROCJPEG_API_TRACE", false);
bool list_metrics = get_env("ROCPROF_LIST_METRICS", false);
bool list_metrics_output_file = get_env("ROCPROF_OUTPUT_LIST_METRICS_FILE", false);
bool pc_sampling_host_trap = false;
+44 -8
View File
@@ -143,10 +143,11 @@ struct buffer_ids
rocprofiler_buffer_id_t rccl_api_trace = {};
rocprofiler_buffer_id_t pc_sampling_host_trap = {};
rocprofiler_buffer_id_t rocdecode_api_trace = {};
rocprofiler_buffer_id_t rocjpeg_api_trace = {};
auto as_array() const
{
return std::array<rocprofiler_buffer_id_t, 10>{hsa_api_trace,
return std::array<rocprofiler_buffer_id_t, 11>{hsa_api_trace,
hip_api_trace,
kernel_trace,
memory_copy_trace,
@@ -155,7 +156,8 @@ struct buffer_ids
scratch_memory,
rccl_api_trace,
pc_sampling_host_trap,
rocdecode_api_trace};
rocdecode_api_trace,
rocjpeg_api_trace};
}
};
@@ -831,6 +833,13 @@ buffered_tracing_callback(rocprofiler_context_id_t /*context*/,
tool::write_ring_buffer(*record, domain_type::ROCDECODE);
}
else if(header->kind == ROCPROFILER_BUFFER_TRACING_ROCJPEG_API)
{
auto* record =
static_cast<rocprofiler_buffer_tracing_rocjpeg_api_record_t*>(header->payload);
tool::write_ring_buffer(*record, domain_type::ROCJPEG);
}
else
{
ROCP_FATAL << fmt::format(
@@ -1491,6 +1500,26 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
"buffer tracing service for ROCDecode api configure");
}
if(tool::get_config().rocjpeg_api_trace)
{
ROCPROFILER_CALL(rocprofiler_create_buffer(get_client_ctx(),
buffer_size,
buffer_watermark,
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
buffered_tracing_callback,
tool_data,
&get_buffers().rocjpeg_api_trace),
"buffer creation");
ROCPROFILER_CALL(
rocprofiler_configure_buffer_tracing_service(get_client_ctx(),
ROCPROFILER_BUFFER_TRACING_ROCJPEG_API,
nullptr,
0,
get_buffers().rocjpeg_api_trace),
"buffer tracing service for ROCDecode api configure");
}
if(tool::get_config().kernel_rename)
{
auto rename_ctx = rocprofiler_context_id_t{0};
@@ -1671,10 +1700,11 @@ tool_fini(void* /*tool_data*/)
tool::memory_allocation_buffered_output_t{tool::get_config().memory_allocation_trace};
auto counters_records_output =
tool::counter_records_buffered_output_t{tool::get_config().counter_collection};
auto rocdecode_output =
tool::rocdecode_buffered_output_t{tool::get_config().rocdecode_api_trace};
auto pc_sampling_host_trap_output =
tool::pc_sampling_host_trap_buffered_output_t{tool::get_config().pc_sampling_host_trap};
auto rocdecode_output =
tool::rocdecode_buffered_output_t{tool::get_config().rocdecode_api_trace};
auto rocjpeg_output = tool::rocjpeg_buffered_output_t{tool::get_config().rocjpeg_api_trace};
auto node_id_sort = [](const auto& lhs, const auto& rhs) { return lhs.node_id < rhs.node_id; };
auto agents_output = CHECK_NOTNULL(tool_metadata)->agents;
@@ -1694,6 +1724,7 @@ tool_fini(void* /*tool_data*/)
generate_output(scratch_memory_output, num_output, contributions);
generate_output(rocdecode_output, num_output, contributions);
generate_output(pc_sampling_host_trap_output, num_output, contributions);
generate_output(rocjpeg_output, num_output, contributions);
if(tool::get_config().advanced_thread_trace && !tool::get_config().att_capability.empty() &&
!tool_metadata->att_filenames.empty())
@@ -1767,7 +1798,8 @@ tool_fini(void* /*tool_data*/)
rccl_output.get_generator(),
memory_allocation_output.get_generator(),
pc_sampling_host_trap_output.get_generator(),
rocdecode_output.get_generator());
rocdecode_output.get_generator(),
rocjpeg_output.get_generator());
json_ar.finish_process();
tool::close_json(json_ar);
@@ -1786,7 +1818,8 @@ tool_fini(void* /*tool_data*/)
scratch_memory_output.get_generator(),
rccl_output.get_generator(),
memory_allocation_output.get_generator(),
rocdecode_output.get_generator());
rocdecode_output.get_generator(),
rocjpeg_output.get_generator());
}
if(tool::get_config().otf2_output && num_output > 0)
@@ -1800,6 +1833,7 @@ tool_fini(void* /*tool_data*/)
auto rccl_elem_data = rccl_output.load_all();
auto memory_allocation_elem_data = memory_allocation_output.load_all();
auto rocdecode_elem_data = rocdecode_output.load_all();
auto rocjpeg_elem_data = rocjpeg_output.load_all();
tool::write_otf2(tool::get_config(),
*tool_metadata,
@@ -1813,7 +1847,8 @@ tool_fini(void* /*tool_data*/)
&scratch_memory_elem_data,
&rccl_elem_data,
&memory_allocation_elem_data,
&rocdecode_elem_data);
&rocdecode_elem_data,
&rocjpeg_elem_data);
}
if(tool::get_config().summary_output && num_output > 0)
@@ -1833,8 +1868,9 @@ tool_fini(void* /*tool_data*/)
destroy_output(scratch_memory_output);
destroy_output(rccl_output);
destroy_output(counters_records_output);
destroy_output(rocdecode_output);
destroy_output(pc_sampling_host_trap_output);
destroy_output(rocdecode_output);
destroy_output(rocjpeg_output);
if(destructors)
{
+2 -1
View File
@@ -38,7 +38,6 @@ add_library(rocprofiler-sdk::rocprofiler-sdk-object-library ALIAS
target_sources(rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_SOURCES}
${ROCPROFILER_LIB_HEADERS})
add_subdirectory(hsa)
add_subdirectory(hip)
add_subdirectory(code_object)
@@ -53,6 +52,7 @@ add_subdirectory(kernel_dispatch)
add_subdirectory(page_migration)
add_subdirectory(rccl)
add_subdirectory(rocdecode)
add_subdirectory(rocjpeg)
add_subdirectory(details)
add_subdirectory(ompt)
@@ -63,6 +63,7 @@ target_link_libraries(
rocprofiler-sdk::rocprofiler-sdk-hsa-runtime-nolink
rocprofiler-sdk::rocprofiler-sdk-rccl-nolink
rocprofiler-sdk::rocprofiler-sdk-rocdecode-nolink
rocprofiler-sdk::rocprofiler-sdk-rocjpeg-nolink
PRIVATE rocprofiler-sdk::rocprofiler-sdk-build-flags
rocprofiler-sdk::rocprofiler-sdk-memcheck
rocprofiler-sdk::rocprofiler-sdk-common-library
+1 -1
View File
@@ -483,7 +483,7 @@ update_agent_runtime_visibility(rocprofiler_agent_t& agent_info)
};
static_assert(
ROCPROFILER_LIBRARY_LAST == ROCPROFILER_ROCDECODE_LIBRARY,
ROCPROFILER_LIBRARY_LAST == ROCPROFILER_ROCJPEG_LIBRARY,
"Since a new library was added to rocprofiler_runtime_library_t, please make sure "
"rocprofiler_agent_runtime_visiblity_t has an entry for this library (if "
"necessary) and make the necessary updates to the logic below has been updated");
+16 -2
View File
@@ -35,6 +35,7 @@
#include "lib/rocprofiler-sdk/rccl/rccl.hpp"
#include "lib/rocprofiler-sdk/registration.hpp"
#include "lib/rocprofiler-sdk/rocdecode/rocdecode.hpp"
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include "lib/rocprofiler-sdk/runtime_initialization.hpp"
#include <rocprofiler-sdk/fwd.h>
@@ -43,6 +44,7 @@
#include <rocprofiler-sdk/marker/table_id.h>
#include <rocprofiler-sdk/rccl/table_id.h>
#include <rocprofiler-sdk/rocdecode/table_id.h>
#include <rocprofiler-sdk/rocjpeg/table_id.h>
#include <rocprofiler-sdk/rocprofiler.h>
#include <atomic>
@@ -94,6 +96,7 @@ ROCPROFILER_BUFFER_TRACING_KIND_STRING(RCCL_API)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(OMPT)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(RUNTIME_INITIALIZATION)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(ROCDECODE_API)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(ROCJPEG_API)
template <size_t Idx, size_t... Tail>
std::pair<const char*, size_t>
@@ -293,7 +296,13 @@ rocprofiler_query_buffer_tracing_kind_operation_name(rocprofiler_buffer_tracing_
}
case ROCPROFILER_BUFFER_TRACING_ROCDECODE_API:
{
val = rocprofiler::rocdecode::name_by_id<ROCPROFILER_ROCDECODE_TABLE_ID>(operation);
val =
rocprofiler::rocdecode::name_by_id<ROCPROFILER_ROCDECODE_TABLE_ID_CORE>(operation);
break;
}
case ROCPROFILER_BUFFER_TRACING_ROCJPEG_API:
{
val = rocprofiler::rocjpeg::name_by_id<ROCPROFILER_ROCJPEG_TABLE_ID_CORE>(operation);
break;
}
};
@@ -429,7 +438,12 @@ rocprofiler_iterate_buffer_tracing_kind_operations(
}
case ROCPROFILER_BUFFER_TRACING_ROCDECODE_API:
{
ops = rocprofiler::rocdecode::get_ids<ROCPROFILER_ROCDECODE_TABLE_ID>();
ops = rocprofiler::rocdecode::get_ids<ROCPROFILER_ROCDECODE_TABLE_ID_CORE>();
break;
}
case ROCPROFILER_BUFFER_TRACING_ROCJPEG_API:
{
ops = rocprofiler::rocjpeg::get_ids<ROCPROFILER_ROCJPEG_TABLE_ID_CORE>();
break;
}
}
@@ -34,6 +34,7 @@
#include "lib/rocprofiler-sdk/rccl/rccl.hpp"
#include "lib/rocprofiler-sdk/registration.hpp"
#include "lib/rocprofiler-sdk/rocdecode/rocdecode.hpp"
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include "lib/rocprofiler-sdk/runtime_initialization.hpp"
#include <rocprofiler-sdk/callback_tracing.h>
@@ -43,6 +44,7 @@
#include <rocprofiler-sdk/marker/table_id.h>
#include <rocprofiler-sdk/rccl/table_id.h>
#include <rocprofiler-sdk/rocdecode/table_id.h>
#include <rocprofiler-sdk/rocjpeg/table_id.h>
#include <rocprofiler-sdk/rocprofiler.h>
#include <atomic>
@@ -91,6 +93,7 @@ ROCPROFILER_CALLBACK_TRACING_KIND_STRING(RCCL_API)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(OMPT)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(RUNTIME_INITIALIZATION)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(ROCDECODE_API)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(ROCJPEG_API)
template <size_t Idx, size_t... Tail>
std::pair<const char*, size_t>
@@ -276,7 +279,13 @@ rocprofiler_query_callback_tracing_kind_operation_name(rocprofiler_callback_trac
}
case ROCPROFILER_CALLBACK_TRACING_ROCDECODE_API:
{
val = rocprofiler::rocdecode::name_by_id<ROCPROFILER_ROCDECODE_TABLE_ID>(operation);
val =
rocprofiler::rocdecode::name_by_id<ROCPROFILER_ROCDECODE_TABLE_ID_CORE>(operation);
break;
}
case ROCPROFILER_CALLBACK_TRACING_ROCJPEG_API:
{
val = rocprofiler::rocjpeg::name_by_id<ROCPROFILER_ROCJPEG_TABLE_ID_CORE>(operation);
break;
}
};
@@ -410,7 +419,12 @@ rocprofiler_iterate_callback_tracing_kind_operations(
}
case ROCPROFILER_CALLBACK_TRACING_ROCDECODE_API:
{
ops = rocprofiler::rocdecode::get_ids<ROCPROFILER_ROCDECODE_TABLE_ID>();
ops = rocprofiler::rocdecode::get_ids<ROCPROFILER_ROCDECODE_TABLE_ID_CORE>();
break;
}
case ROCPROFILER_CALLBACK_TRACING_ROCJPEG_API:
{
ops = rocprofiler::rocjpeg::get_ids<ROCPROFILER_ROCJPEG_TABLE_ID_CORE>();
break;
}
};
@@ -554,8 +568,9 @@ rocprofiler_iterate_callback_tracing_kind_operation_args(
case ROCPROFILER_CALLBACK_TRACING_MEMORY_COPY:
case ROCPROFILER_CALLBACK_TRACING_MEMORY_ALLOCATION:
case ROCPROFILER_CALLBACK_TRACING_RCCL_API:
case ROCPROFILER_CALLBACK_TRACING_ROCDECODE_API:
case ROCPROFILER_CALLBACK_TRACING_RUNTIME_INITIALIZATION:
case ROCPROFILER_CALLBACK_TRACING_ROCDECODE_API:
case ROCPROFILER_CALLBACK_TRACING_ROCJPEG_API:
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
}
@@ -35,6 +35,7 @@
#include <hip/amd_detail/hip_api_trace.hpp>
#include "lib/rocprofiler-sdk/rccl/rccl.hpp"
#include "lib/rocprofiler-sdk/rocdecode/rocdecode.hpp"
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include <cstdint>
#include <mutex>
@@ -59,7 +60,8 @@ constexpr auto intercept_library_seq = library_sequence_t<ROCPROFILER_HSA_TABLE,
ROCPROFILER_MARKER_CONTROL_TABLE,
ROCPROFILER_MARKER_NAME_TABLE,
ROCPROFILER_RCCL_TABLE,
ROCPROFILER_ROCDECODE_TABLE>{};
ROCPROFILER_ROCDECODE_TABLE,
ROCPROFILER_ROCJPEG_TABLE>{};
// check that intercept_library_seq is up to date
static_assert((1 << (intercept_library_seq.size() - 1)) == ROCPROFILER_TABLE_LAST,
@@ -199,6 +201,11 @@ template void notify_intercept_table_registration(rocprofiler_intercept_table_t,
uint64_t,
uint64_t,
std::tuple<RocDecodeDispatchTable*>);
template void notify_intercept_table_registration(rocprofiler_intercept_table_t,
uint64_t,
uint64_t,
std::tuple<RocJpegDispatchTable*>);
} // namespace intercept_table
} // namespace rocprofiler
@@ -123,7 +123,8 @@ constexpr auto creation_notifier_library_seq = library_sequence_t<ROCPROFILER_LI
ROCPROFILER_HIP_LIBRARY,
ROCPROFILER_MARKER_LIBRARY,
ROCPROFILER_RCCL_LIBRARY,
ROCPROFILER_ROCDECODE_LIBRARY>{};
ROCPROFILER_ROCDECODE_LIBRARY,
ROCPROFILER_ROCJPEG_LIBRARY>{};
// check that creation_notifier_library_seq is up to date
static_assert((1 << (creation_notifier_library_seq.size() - 1)) == ROCPROFILER_LIBRARY_LAST,
+24 -2
View File
@@ -47,6 +47,7 @@
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
#include "lib/rocprofiler-sdk/rccl/rccl.hpp"
#include "lib/rocprofiler-sdk/rocdecode/rocdecode.hpp"
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include "lib/rocprofiler-sdk/runtime_initialization.hpp"
#include <rocprofiler-sdk/context.h>
@@ -1004,10 +1005,31 @@ rocprofiler_set_api_table(const char* name,
rocprofiler::intercept_table::notify_intercept_table_registration(
ROCPROFILER_ROCDECODE_TABLE, lib_version, lib_instance, std::make_tuple(rocdecode_api));
}
else if(std::string_view{name} == "rocjpeg")
{
ROCP_ERROR_IF(num_tables > 1)
<< "rocprofiler expected rocJPEG library to pass 1 API table, not " << num_tables;
auto* rocjpeg_api = static_cast<RocJpegDispatchTable*>(tables[0]);
// any internal modifications to the rocjpegApiFuncTable need to be done before we make
// the copy or else those modifications will be lost when rocJPEG API tracing is enabled
// because the rocJPEG API tracing invokes the function pointers from the copy below
rocprofiler::rocjpeg::copy_table(rocjpeg_api, lib_instance);
// install rocprofiler API wrappers
rocprofiler::rocjpeg::update_table(rocjpeg_api);
// Tracing notifications the runtime has initialized
rocprofiler::runtime_init::initialize(
ROCPROFILER_RUNTIME_INITIALIZATION_ROCJPEG, lib_version, lib_instance);
// allow tools to install API wrappers
rocprofiler::intercept_table::notify_intercept_table_registration(
ROCPROFILER_ROCJPEG_TABLE, lib_version, lib_instance, std::make_tuple(rocjpeg_api));
}
else
{
ROCP_ERROR << "rocprofiler does not accept API tables from " << name;
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
}
@@ -555,6 +555,6 @@ using rocdecode_op_args_cb_t = rocprofiler_callback_tracing_operation_args_cb_t;
template std::vector<uint32_t> get_ids<TABLE_IDX>(); \
template std::vector<const char*> get_names<TABLE_IDX>();
INSTANTIATE_ROCDECODE_TABLE_FUNC(rocdecode_api_func_table_t, ROCPROFILER_ROCDECODE_TABLE_ID)
INSTANTIATE_ROCDECODE_TABLE_FUNC(rocdecode_api_func_table_t, ROCPROFILER_ROCDECODE_TABLE_ID_CORE)
} // namespace rocdecode
} // namespace rocprofiler
@@ -42,7 +42,7 @@ struct rocdecode_domain_info<ROCPROFILER_ROCDECODE_TABLE_ID_LAST>
};
template <>
struct rocdecode_domain_info<ROCPROFILER_ROCDECODE_TABLE_ID>
struct rocdecode_domain_info<ROCPROFILER_ROCDECODE_TABLE_ID_CORE>
: rocdecode_domain_info<ROCPROFILER_ROCDECODE_TABLE_ID_LAST>
{
using enum_type = rocprofiler_marker_core_api_id_t;
@@ -61,26 +61,26 @@ struct rocdecode_domain_info<ROCPROFILER_ROCDECODE_TABLE_ID>
ROCPROFILER_LIB_ROCPROFILER_SDK_ROCDECODE_ROCDECODE_CPP_IMPL == 1
// clang-format off
ROCDECODE_API_TABLE_LOOKUP_DEFINITION(ROCPROFILER_ROCDECODE_TABLE_ID, rocdecode_api_func_table_t)
ROCDECODE_API_TABLE_LOOKUP_DEFINITION(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, rocdecode_api_func_table_t)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecCreateVideoParser, rocDecCreateVideoParser, pfn_rocdec_create_video_parser, parser_handle, params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecParseVideoData, rocDecParseVideoData, pfn_rocdec_parse_video_data, parser_handle, packet)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecDestroyVideoParser, rocDecDestroyVideoParser, pfn_rocdec_destroy_video_parser, parser_handle)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecCreateDecoder, rocDecCreateDecoder, pfn_rocdec_create_decoder, decoder_handle, decoder_create_info)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecDestroyDecoder, rocDecDestroyDecoder, pfn_rocdec_destroy_decoder, decoder_handle)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetDecoderCaps, rocDecGetDecoderCaps, pfn_rocdec_get_gecoder_caps, decode_caps)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecDecodeFrame, rocDecDecodeFrame, pfn_rocdec_decode_frame, decoder_handle, pic_params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetDecodeStatus, rocDecGetDecodeStatus, pfn_rocdec_get_decode_status, decoder_handle, pic_idx, decode_status)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecReconfigureDecoder, rocDecReconfigureDecoder, pfn_rocdec_reconfigure_decoder, decoder_handle, reconfig_params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetVideoFrame, rocDecGetVideoFrame, pfn_rocdec_get_video_frame, decoder_handle, pic_idx, dev_mem_ptr, horizontal_pitch, vid_postproc_params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetErrorName, rocDecGetErrorName, pfn_rocdec_get_error_name, rocdec_status)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecCreateVideoParser, rocDecCreateVideoParser, pfn_rocdec_create_video_parser, parser_handle, params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecParseVideoData, rocDecParseVideoData, pfn_rocdec_parse_video_data, parser_handle, packet)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecDestroyVideoParser, rocDecDestroyVideoParser, pfn_rocdec_destroy_video_parser, parser_handle)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecCreateDecoder, rocDecCreateDecoder, pfn_rocdec_create_decoder, decoder_handle, decoder_create_info)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecDestroyDecoder, rocDecDestroyDecoder, pfn_rocdec_destroy_decoder, decoder_handle)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetDecoderCaps, rocDecGetDecoderCaps, pfn_rocdec_get_gecoder_caps, decode_caps)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecDecodeFrame, rocDecDecodeFrame, pfn_rocdec_decode_frame, decoder_handle, pic_params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetDecodeStatus, rocDecGetDecodeStatus, pfn_rocdec_get_decode_status, decoder_handle, pic_idx, decode_status)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecReconfigureDecoder, rocDecReconfigureDecoder, pfn_rocdec_reconfigure_decoder, decoder_handle, reconfig_params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetVideoFrame, rocDecGetVideoFrame, pfn_rocdec_get_video_frame, decoder_handle, pic_idx, dev_mem_ptr, horizontal_pitch, vid_postproc_params)
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetErrorName, rocDecGetErrorName, pfn_rocdec_get_error_name, rocdec_status)
#if ROCDECODE_RUNTIME_API_TABLE_STEP_VERSION >= 1
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecCreateBitstreamReader, rocDecCreateBitstreamReader, pfn_rocdec_create_bitstream_reader, bs_reader_handle, input_file_path);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetBitstreamCodecType, rocDecGetBitstreamCodecType, pfn_rocdec_get_bitstream_codec_type, bs_reader_handle, codec_type);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetBitstreamBitDepth, rocDecGetBitstreamBitDepth, pfn_rocdec_get_bitstream_bit_depth, bs_reader_handle, bit_depth);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecGetBitstreamPicData, rocDecGetBitstreamPicData, pfn_rocdec_get_bitstream_pic_data, bs_reader_handle, pic_data, pic_size, pts);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID, ROCPROFILER_ROCDECODE_API_ID_rocDecDestroyBitstreamReader, rocDecDestroyBitstreamReader, pfn_rocdec_destroy_bitstream_reader, bs_reader_handle);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecCreateBitstreamReader, rocDecCreateBitstreamReader, pfn_rocdec_create_bitstream_reader, bs_reader_handle, input_file_path);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetBitstreamCodecType, rocDecGetBitstreamCodecType, pfn_rocdec_get_bitstream_codec_type, bs_reader_handle, codec_type);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetBitstreamBitDepth, rocDecGetBitstreamBitDepth, pfn_rocdec_get_bitstream_bit_depth, bs_reader_handle, bit_depth);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecGetBitstreamPicData, rocDecGetBitstreamPicData, pfn_rocdec_get_bitstream_pic_data, bs_reader_handle, pic_data, pic_size, pts);
ROCDECODE_API_INFO_DEFINITION_V(ROCPROFILER_ROCDECODE_TABLE_ID_CORE, ROCPROFILER_ROCDECODE_API_ID_rocDecDestroyBitstreamReader, rocDecDestroyBitstreamReader, pfn_rocdec_destroy_bitstream_reader, bs_reader_handle);
#endif
#else
# error \
@@ -22,17 +22,7 @@
#pragma once
#if !defined(ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE)
# if defined __has_include
# if __has_include(<rocdecode/amd_detail/api_trace.h>)
# define ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE 1
# else
# define ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE 0
# endif
# else
# define ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE 0
# endif
#endif
#include <rocprofiler-sdk/rocdecode/details/rocdecode_headers.h>
#if ROCPROFILER_SDK_USE_SYSTEM_ROCDECODE > 0
# include <rocdecode/amd_detail/rocdecode_api_trace.h>
@@ -0,0 +1,5 @@
set(ROCPROFILER_LIB_ROCJPEG_SOURCES abi.cpp rocjpeg.cpp)
set(ROCPROFILER_LIB_ROCJPEG_HEADERS defines.hpp rocjpeg.hpp)
target_sources(rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_ROCJPEG_SOURCES}
${ROCPROFILER_LIB_ROCJPEG_HEADERS})
@@ -0,0 +1,51 @@
// 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.
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include "lib/common/abi.hpp"
#include "lib/common/defines.hpp"
#include <rocprofiler-sdk/rocjpeg.h>
#include <rocprofiler-sdk/version.h>
namespace rocprofiler
{
namespace rocjpeg
{
static_assert(ROCJPEG_RUNTIME_API_TABLE_MAJOR_VERSION == 0,
"Major version updated for rocJPEG dispatch table");
ROCP_SDK_ENFORCE_ABI_VERSIONING(::RocJpegDispatchTable, 9)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_stream_create, 0)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_stream_parse, 1)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_stream_destroy, 2)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_create, 3)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_destroy, 4)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_get_image_info, 5)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_decode, 6)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_decode_batched, 7)
ROCP_SDK_ENFORCE_ABI(::RocJpegDispatchTable, pfn_rocjpeg_get_error_name, 8)
} // namespace rocjpeg
} // namespace rocprofiler
@@ -0,0 +1,214 @@
// 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/defines.hpp"
#define ROCJPEG_API_INFO_DEFINITION_0( \
ROCJPEG_TABLE, ROCJPEG_API_ID, ROCJPEG_FUNC, ROCJPEG_FUNC_PTR) \
namespace rocprofiler \
{ \
namespace rocjpeg \
{ \
template <> \
struct rocjpeg_api_info<ROCJPEG_TABLE, ROCJPEG_API_ID> : rocjpeg_domain_info<ROCJPEG_TABLE> \
{ \
static constexpr auto table_idx = ROCJPEG_TABLE; \
static constexpr auto operation_idx = ROCJPEG_API_ID; \
static constexpr auto name = #ROCJPEG_FUNC; \
\
using domain_type = rocjpeg_domain_info<table_idx>; \
using this_type = rocjpeg_api_info<table_idx, operation_idx>; \
using base_type = rocjpeg_api_impl<table_idx, operation_idx>; \
\
using domain_type::callback_domain_idx; \
using domain_type::buffered_domain_idx; \
using domain_type::args_type; \
using domain_type::retval_type; \
using domain_type::callback_data_type; \
\
static constexpr auto offset() \
{ \
return offsetof(rocjpeg_table_lookup<table_idx>::type, ROCJPEG_FUNC_PTR); \
} \
\
static_assert(offsetof(rocjpeg_table_lookup<table_idx>::type, ROCJPEG_FUNC_PTR) == \
(sizeof(size_t) + (operation_idx * sizeof(void*))), \
"ABI error for " #ROCJPEG_FUNC); \
\
static auto& get_table() { return rocjpeg_table_lookup<table_idx>{}(); } \
\
template <typename TableT> \
static auto& get_table(TableT& _v) \
{ \
return rocjpeg_table_lookup<table_idx>{}(_v); \
} \
\
template <typename TableT> \
static auto& get_table_func(TableT& _table) \
{ \
if constexpr(std::is_pointer<TableT>::value) \
{ \
assert(_table != nullptr && "nullptr to MARKER table for " #ROCJPEG_FUNC \
" function"); \
return _table->ROCJPEG_FUNC_PTR; \
} \
else \
{ \
return _table.ROCJPEG_FUNC_PTR; \
} \
} \
\
static auto& get_table_func() { return get_table_func(get_table()); } \
\
template <typename DataT> \
static auto& get_api_data_args(DataT& _data) \
{ \
return _data.ROCJPEG_FUNC; \
} \
\
template <typename RetT, typename... Args> \
static auto get_functor(RetT (*)(Args...)) \
{ \
return &base_type::functor<RetT, Args...>; \
} \
\
static std::vector<void*> as_arg_addr(callback_data_type) { return std::vector<void*>{}; } \
\
static std::vector<common::stringified_argument> as_arg_list(callback_data_type, int32_t) \
{ \
return {}; \
} \
}; \
} \
}
#define ROCJPEG_API_INFO_DEFINITION_V( \
ROCJPEG_TABLE, ROCJPEG_API_ID, ROCJPEG_FUNC, ROCJPEG_FUNC_PTR, ...) \
namespace rocprofiler \
{ \
namespace rocjpeg \
{ \
template <> \
struct rocjpeg_api_info<ROCJPEG_TABLE, ROCJPEG_API_ID> : rocjpeg_domain_info<ROCJPEG_TABLE> \
{ \
static constexpr auto table_idx = ROCJPEG_TABLE; \
static constexpr auto operation_idx = ROCJPEG_API_ID; \
static constexpr auto name = #ROCJPEG_FUNC; \
\
using domain_type = rocjpeg_domain_info<table_idx>; \
using this_type = rocjpeg_api_info<table_idx, operation_idx>; \
using base_type = rocjpeg_api_impl<table_idx, operation_idx>; \
\
static constexpr auto callback_domain_idx = domain_type::callback_domain_idx; \
static constexpr auto buffered_domain_idx = domain_type::buffered_domain_idx; \
\
using domain_type::args_type; \
using domain_type::retval_type; \
using domain_type::callback_data_type; \
\
static constexpr auto offset() \
{ \
return offsetof(rocjpeg_table_lookup<table_idx>::type, ROCJPEG_FUNC_PTR); \
} \
\
static_assert(offsetof(rocjpeg_table_lookup<table_idx>::type, ROCJPEG_FUNC_PTR) == \
(sizeof(size_t) + (operation_idx * sizeof(void*))), \
"ABI error for " #ROCJPEG_FUNC); \
\
static auto& get_table() { return rocjpeg_table_lookup<table_idx>{}(); } \
\
template <typename TableT> \
static auto& get_table(TableT& _v) \
{ \
return rocjpeg_table_lookup<table_idx>{}(_v); \
} \
\
template <typename TableT> \
static auto& get_table_func(TableT& _table) \
{ \
if constexpr(std::is_pointer<TableT>::value) \
{ \
assert(_table != nullptr && "nullptr to MARKER table for " #ROCJPEG_FUNC \
" function"); \
return _table->ROCJPEG_FUNC_PTR; \
} \
else \
{ \
return _table.ROCJPEG_FUNC_PTR; \
} \
} \
\
static auto& get_table_func() { return get_table_func(get_table()); } \
\
template <typename DataT> \
static auto& get_api_data_args(DataT& _data) \
{ \
return _data.ROCJPEG_FUNC; \
} \
\
template <typename RetT, typename... Args> \
static auto get_functor(RetT (*)(Args...)) \
{ \
return &base_type::functor<RetT, Args...>; \
} \
\
static std::vector<void*> as_arg_addr(callback_data_type trace_data) \
{ \
return std::vector<void*>{ \
GET_ADDR_MEMBER_FIELDS(get_api_data_args(trace_data.args), __VA_ARGS__)}; \
} \
}; \
} \
}
#define ROCJPEG_API_TABLE_LOOKUP_DEFINITION(TABLE_ID, TYPE) \
namespace rocprofiler \
{ \
namespace rocjpeg \
{ \
namespace \
{ \
template <> \
auto* get_table<TABLE_ID>() \
{ \
return get_table_impl<TYPE>(); \
} \
} \
\
template <> \
struct rocjpeg_table_lookup<TABLE_ID> \
{ \
using type = TYPE; \
auto& operator()(type& _v) const { return _v; } \
auto& operator()(type* _v) const { return *_v; } \
auto& operator()() const { return (*this)(get_table<TABLE_ID>()); } \
}; \
\
template <> \
struct rocjpeg_table_id_lookup<TYPE> \
{ \
static constexpr auto value = TABLE_ID; \
}; \
} \
}
@@ -0,0 +1,560 @@
// 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.
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include "lib/common/defines.hpp"
#include "lib/common/static_object.hpp"
#include "lib/common/utility.hpp"
#include "lib/rocprofiler-sdk/buffer.hpp"
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/hip/utils.hpp"
#include "lib/rocprofiler-sdk/registration.hpp"
#include "lib/rocprofiler-sdk/tracing/tracing.hpp"
#include <rocprofiler-sdk/buffer.h>
#include <rocprofiler-sdk/callback_tracing.h>
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/rocjpeg/table_id.h>
#include <hip/driver_types.h>
#include <hip/hip_runtime_api.h>
// must be included after runtime api
#include <hip/hip_deprecated.h>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>
namespace rocprofiler
{
namespace rocjpeg
{
namespace
{
struct null_type
{};
template <typename Tp>
auto
get_default_retval()
{
if constexpr(std::is_pointer<Tp>::value)
{
Tp v = nullptr;
return v;
}
else if constexpr(std::is_same<Tp, RocJpegStatus>::value)
return ROCJPEG_STATUS_RUNTIME_ERROR;
else if constexpr(std::is_same<Tp, const char*>::value)
return "UnknownString";
else
static_assert(std::is_empty<Tp>::value, "Error! unsupported return type");
}
template <typename DataT, typename Tp>
void
set_data_retval(DataT& _data, Tp _val)
{
if constexpr(std::is_same<Tp, RocJpegStatus>::value)
{
_data.rocJpegStatus_retval = _val;
}
else if constexpr(std::is_same<Tp, const char*>::value)
{
_data.const_charp_retval = _val;
}
else
{
static_assert(std::is_empty<Tp>::value, "Error! unsupported return type");
}
}
template <typename Tp>
Tp*
get_table_impl()
{
static auto*& _v = common::static_object<Tp>::construct(common::init_public_api_struct(Tp{}));
return _v;
}
template <size_t TableIdx>
auto*
get_table();
} // namespace
template <size_t TableIdx, size_t OpIdx>
template <typename DataArgsT, typename... Args>
auto
rocjpeg_api_impl<TableIdx, OpIdx>::set_data_args(DataArgsT& _data_args, Args... args)
{
if constexpr(sizeof...(Args) == 0)
_data_args.no_args.empty = '\0';
else
_data_args = DataArgsT{args...};
}
template <size_t TableIdx, size_t OpIdx>
template <typename FuncT, typename... Args>
auto
rocjpeg_api_impl<TableIdx, OpIdx>::exec(FuncT&& _func, Args&&... args)
{
using return_type = std::decay_t<std::invoke_result_t<FuncT, Args...>>;
if(_func)
{
if constexpr(std::is_void<return_type>::value)
{
_func(std::forward<Args>(args)...);
return null_type{};
}
else
{
return _func(std::forward<Args>(args)...);
}
}
using info_type = rocjpeg_api_info<TableIdx, OpIdx>;
ROCP_ERROR << "nullptr to next rocjpeg function for " << info_type::name << " ("
<< info_type::operation_idx << ")";
return get_default_retval<return_type>();
}
template <size_t TableIdx, size_t OpIdx>
template <typename RetT, typename... Args>
RetT
rocjpeg_api_impl<TableIdx, OpIdx>::functor(Args... args)
{
using info_type = rocjpeg_api_info<TableIdx, OpIdx>;
using callback_api_data_t = typename rocjpeg_domain_info<TableIdx>::callback_data_type;
using buffered_api_data_t = typename rocjpeg_domain_info<TableIdx>::buffer_data_type;
constexpr auto external_corr_id_domain_idx =
rocjpeg_domain_info<TableIdx>::external_correlation_id_domain_idx;
if(registration::get_fini_status() != 0)
{
[[maybe_unused]] auto _ret = exec(info_type::get_table_func(), std::forward<Args>(args)...);
if constexpr(!std::is_void<RetT>::value)
return _ret;
else
return;
}
constexpr auto ref_count = 2;
auto thr_id = common::get_tid();
auto callback_contexts = tracing::callback_context_data_vec_t{};
auto buffered_contexts = tracing::buffered_context_data_vec_t{};
auto external_corr_ids = tracing::external_correlation_id_map_t{};
tracing::populate_contexts(info_type::callback_domain_idx,
info_type::buffered_domain_idx,
info_type::operation_idx,
callback_contexts,
buffered_contexts,
external_corr_ids);
if(callback_contexts.empty() && buffered_contexts.empty())
{
[[maybe_unused]] auto _ret = exec(info_type::get_table_func(), std::forward<Args>(args)...);
if constexpr(!std::is_void<RetT>::value)
return _ret;
else
return;
}
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 = tracing::correlation_service::construct(ref_count);
auto internal_corr_id = corr_id->internal;
tracing::populate_external_correlation_ids(external_corr_ids,
thr_id,
external_corr_id_domain_idx,
info_type::operation_idx,
internal_corr_id);
// invoke the callbacks
if(!callback_contexts.empty())
{
set_data_args(info_type::get_api_data_args(tracer_data.args), std::forward<Args>(args)...);
tracing::execute_phase_enter_callbacks(callback_contexts,
thr_id,
internal_corr_id,
external_corr_ids,
info_type::callback_domain_idx,
info_type::operation_idx,
tracer_data);
}
// enter callback may update the external correlation id field
tracing::update_external_correlation_ids(
external_corr_ids, thr_id, external_corr_id_domain_idx);
// record the start timestamp as close to the function call as possible
if(!buffered_contexts.empty())
{
buffer_record.start_timestamp = common::timestamp_ns();
}
// decrement the reference count before invoking
corr_id->sub_ref_count();
auto _ret = exec(info_type::get_table_func(), std::forward<Args>(args)...);
// record the end timestamp as close to the function call as possible
if(!buffered_contexts.empty())
{
buffer_record.end_timestamp = common::timestamp_ns();
}
if(!callback_contexts.empty())
{
set_data_retval(tracer_data.retval, _ret);
tracing::execute_phase_exit_callbacks(callback_contexts,
external_corr_ids,
info_type::callback_domain_idx,
info_type::operation_idx,
tracer_data);
}
if(!buffered_contexts.empty())
{
tracing::execute_buffer_record_emplace(buffered_contexts,
thr_id,
internal_corr_id,
external_corr_ids,
info_type::buffered_domain_idx,
info_type::operation_idx,
buffer_record);
}
// decrement the reference count after usage in the callback/buffers
corr_id->sub_ref_count();
context::pop_latest_correlation_id(corr_id);
if constexpr(!std::is_void<RetT>::value) return _ret;
}
} // namespace rocjpeg
} // namespace rocprofiler
#define ROCPROFILER_LIB_ROCPROFILER_SDK_ROCJPEG_ROCJPEG_CPP_IMPL 1
// template specializations
#include "rocjpeg.def.cpp"
namespace rocprofiler
{
namespace rocjpeg
{
namespace
{
template <size_t TableIdx, size_t OpIdx, size_t... OpIdxTail>
const char*
name_by_id(const uint32_t id, std::index_sequence<OpIdx, OpIdxTail...>)
{
if(OpIdx == id) return rocjpeg_api_info<TableIdx, OpIdx>::name;
if constexpr(sizeof...(OpIdxTail) > 0)
return name_by_id<TableIdx>(id, std::index_sequence<OpIdxTail...>{});
else
return nullptr;
}
template <size_t TableIdx, size_t OpIdx, size_t... OpIdxTail>
uint32_t
id_by_name(const char* name, std::index_sequence<OpIdx, OpIdxTail...>)
{
if(std::string_view{rocjpeg_api_info<TableIdx, OpIdx>::name} == std::string_view{name})
return rocjpeg_api_info<TableIdx, OpIdx>::operation_idx;
if constexpr(sizeof...(OpIdxTail) > 0)
return id_by_name<TableIdx>(name, std::index_sequence<OpIdxTail...>{});
else
return rocjpeg_domain_info<TableIdx>::none;
}
template <size_t TableIdx, size_t OpIdx, size_t... OpIdxTail>
void
get_ids(std::vector<uint32_t>& _id_list, std::index_sequence<OpIdx, OpIdxTail...>)
{
auto _idx = rocjpeg_api_info<TableIdx, OpIdx>::operation_idx;
if(_idx < rocjpeg_domain_info<TableIdx>::last) _id_list.emplace_back(_idx);
if constexpr(sizeof...(OpIdxTail) > 0)
get_ids<TableIdx>(_id_list, std::index_sequence<OpIdxTail...>{});
}
template <size_t TableIdx, size_t OpIdx, size_t... OpIdxTail>
void
get_names(std::vector<const char*>& _name_list, std::index_sequence<OpIdx, OpIdxTail...>)
{
auto&& _name = rocjpeg_api_info<TableIdx, OpIdx>::name;
if(_name != nullptr && strnlen(_name, 1) > 0) _name_list.emplace_back(_name);
if constexpr(sizeof...(OpIdxTail) > 0)
get_names<TableIdx>(_name_list, std::index_sequence<OpIdxTail...>{});
}
template <size_t TableIdx, typename DataT, size_t OpIdx, size_t... OpIdxTail>
void
iterate_args(const uint32_t id,
const DataT& data,
rocprofiler_callback_tracing_operation_args_cb_t func,
int32_t max_deref,
void* user_data,
std::index_sequence<OpIdx, OpIdxTail...>)
{
if(OpIdx == id)
{
using info_type = rocjpeg_api_info<TableIdx, OpIdx>;
auto&& arg_list = info_type::as_arg_list(data, max_deref);
auto&& arg_addr = info_type::as_arg_addr(data);
for(size_t i = 0; i < std::min(arg_list.size(), arg_addr.size()); ++i)
{
auto ret = func(info_type::callback_domain_idx, // kind
id, // operation
i, // arg_number
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, // arg_name
arg_list.at(i).value.c_str(), // arg_value_str
arg_list.at(i).dereference_count, // num deref in str
user_data);
if(ret != 0) break;
}
return;
}
if constexpr(sizeof...(OpIdxTail) > 0)
iterate_args<TableIdx>(
id, data, func, max_deref, user_data, std::index_sequence<OpIdxTail...>{});
}
bool
should_wrap_functor(rocprofiler_callback_tracing_kind_t _callback_domain,
rocprofiler_buffer_tracing_kind_t _buffered_domain,
int _operation)
{
// we loop over all the *registered* contexts and see if any of them, at any point in time,
// might require callback or buffered API tracing
for(const auto& itr : context::get_registered_contexts())
{
if(!itr) continue;
// if there is a callback tracer enabled for the given domain and op, we need to wrap
if(itr->callback_tracer && itr->callback_tracer->domains(_callback_domain) &&
itr->callback_tracer->domains(_callback_domain, _operation))
return true;
// if there is a buffered tracer enabled for the given domain and op, we need to wrap
if(itr->buffered_tracer && itr->buffered_tracer->domains(_buffered_domain) &&
itr->buffered_tracer->domains(_buffered_domain, _operation))
return true;
}
return false;
}
template <size_t TableIdx, typename Tp, size_t OpIdx>
void
copy_table(Tp* _orig, uint64_t _tbl_instance, std::integral_constant<size_t, OpIdx>)
{
using table_type = typename rocjpeg_table_lookup<TableIdx>::type;
if constexpr(std::is_same<table_type, Tp>::value)
{
auto _info = rocjpeg_api_info<TableIdx, OpIdx>{};
// make sure we don't access a field that doesn't exist in input table
if(_info.offset() >= _orig->size) return;
// 1. get the sub-table containing the function pointer in original table
// 2. get reference to function pointer in sub-table in original table
auto& _orig_table = _info.get_table(_orig);
auto& _orig_func = _info.get_table_func(_orig_table);
// 3. get the sub-table containing the function pointer in saved table
// 4. get reference to function pointer in sub-table in saved table
// 5. save the original function in the saved table
auto& _copy_table = _info.get_table(*get_table<TableIdx>());
auto& _copy_func = _info.get_table_func(_copy_table);
ROCP_FATAL_IF(_copy_func && _tbl_instance == 0)
<< _info.name << " has non-null function pointer " << _copy_func
<< " despite this being the first instance of the library being copies";
if(!_copy_func)
{
ROCP_TRACE << "copying table entry for " << _info.name;
_copy_func = _orig_func;
}
else
{
ROCP_TRACE << "skipping copying table entry for " << _info.name
<< " from table instance " << _tbl_instance;
}
}
}
template <size_t TableIdx, typename Tp, size_t OpIdx>
void
update_table(Tp* _orig, std::integral_constant<size_t, OpIdx>)
{
using table_type = typename rocjpeg_table_lookup<TableIdx>::type;
if constexpr(std::is_same<table_type, Tp>::value)
{
auto _info = rocjpeg_api_info<TableIdx, OpIdx>{};
// make sure we don't access a field that doesn't exist in input table
if(_info.offset() >= _orig->size) return;
// check to see if there are any contexts which enable this operation in the rocJPEG API
// domain
if(!should_wrap_functor(
_info.callback_domain_idx, _info.buffered_domain_idx, _info.operation_idx))
return;
ROCP_TRACE << "updating table entry for " << _info.name;
// 1. get the sub-table containing the function pointer in original table
// 2. get reference to function pointer in sub-table in original table
// 3. update function pointer with wrapper
auto& _table = _info.get_table(_orig);
auto& _func = _info.get_table_func(_table);
_func = _info.get_functor(_func);
}
}
template <size_t TableIdx, typename Tp, size_t OpIdx, size_t... OpIdxTail>
void
copy_table(Tp* _orig, uint64_t _tbl_instance, std::index_sequence<OpIdx, OpIdxTail...>)
{
copy_table<TableIdx>(_orig, _tbl_instance, std::integral_constant<size_t, OpIdx>{});
if constexpr(sizeof...(OpIdxTail) > 0)
copy_table<TableIdx>(_orig, _tbl_instance, std::index_sequence<OpIdxTail...>{});
}
template <size_t TableIdx, typename Tp, size_t OpIdx, size_t... OpIdxTail>
void
update_table(Tp* _orig, std::index_sequence<OpIdx, OpIdxTail...>)
{
update_table<TableIdx>(_orig, std::integral_constant<size_t, OpIdx>{});
if constexpr(sizeof...(OpIdxTail) > 0)
update_table<TableIdx>(_orig, std::index_sequence<OpIdxTail...>{});
}
} // namespace
// check out the assembly here... this compiles to a switch statement
template <size_t TableIdx>
const char*
name_by_id(uint32_t id)
{
return name_by_id<TableIdx>(id,
std::make_index_sequence<rocjpeg_domain_info<TableIdx>::last>{});
}
template <size_t TableIdx>
uint32_t
id_by_name(const char* name)
{
return id_by_name<TableIdx>(name,
std::make_index_sequence<rocjpeg_domain_info<TableIdx>::last>{});
}
template <size_t TableIdx>
std::vector<uint32_t>
get_ids()
{
constexpr auto last_api_id = rocjpeg_domain_info<TableIdx>::last;
auto _data = std::vector<uint32_t>{};
_data.reserve(last_api_id);
get_ids<TableIdx>(_data, std::make_index_sequence<last_api_id>{});
return _data;
}
template <size_t TableIdx>
std::vector<const char*>
get_names()
{
constexpr auto last_api_id = rocjpeg_domain_info<TableIdx>::last;
auto _data = std::vector<const char*>{};
_data.reserve(last_api_id);
get_names<TableIdx>(_data, std::make_index_sequence<last_api_id>{});
return _data;
}
template <size_t TableIdx>
void
iterate_args(uint32_t id,
const rocprofiler_callback_tracing_rocjpeg_api_data_t& data,
rocprofiler_callback_tracing_operation_args_cb_t callback,
int32_t max_deref,
void* user_data)
{
if(callback)
iterate_args<TableIdx>(id,
data,
callback,
max_deref,
user_data,
std::make_index_sequence<rocjpeg_domain_info<TableIdx>::last>{});
}
template <typename TableT>
void
copy_table(TableT* _orig, uint64_t _tbl_instance)
{
constexpr auto TableIdx = rocjpeg_table_id_lookup<TableT>::value;
if(_orig)
copy_table<TableIdx>(
_orig, _tbl_instance, std::make_index_sequence<rocjpeg_domain_info<TableIdx>::last>{});
}
template <typename TableT>
void
update_table(TableT* _orig)
{
constexpr auto TableIdx = rocjpeg_table_id_lookup<TableT>::value;
if(_orig)
update_table<TableIdx>(_orig,
std::make_index_sequence<rocjpeg_domain_info<TableIdx>::last>{});
}
using rocjpeg_api_data_t = rocprofiler_callback_tracing_rocjpeg_api_data_t;
using rocjpeg_op_args_cb_t = rocprofiler_callback_tracing_operation_args_cb_t;
#define INSTANTIATE_ROCJPEG_TABLE_FUNC(TABLE_TYPE, TABLE_IDX) \
template void copy_table<TABLE_TYPE>(TABLE_TYPE * _tbl, uint64_t _instv); \
template void update_table<TABLE_TYPE>(TABLE_TYPE * _tbl); \
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>();
INSTANTIATE_ROCJPEG_TABLE_FUNC(rocjpeg_api_func_table_t, ROCPROFILER_ROCJPEG_TABLE_ID_CORE)
} // namespace rocjpeg
} // namespace rocprofiler
@@ -0,0 +1,81 @@
// 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.
#include "lib/rocprofiler-sdk/rocjpeg/defines.hpp"
#include "lib/rocprofiler-sdk/rocjpeg/rocjpeg.hpp"
#include <rocprofiler-sdk/external_correlation.h>
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/rocjpeg.h>
#include <rocprofiler-sdk/rocjpeg/table_id.h>
namespace rocprofiler
{
namespace rocjpeg
{
template <>
struct rocjpeg_domain_info<ROCPROFILER_ROCJPEG_TABLE_ID_LAST>
{
using args_type = rocprofiler_rocjpeg_api_args_t;
using retval_type = rocprofiler_rocjpeg_api_retval_t;
using callback_data_type = rocprofiler_callback_tracing_rocjpeg_api_data_t;
using buffer_data_type = rocprofiler_buffer_tracing_rocjpeg_api_record_t;
};
template <>
struct rocjpeg_domain_info<ROCPROFILER_ROCJPEG_TABLE_ID_CORE>
: rocjpeg_domain_info<ROCPROFILER_ROCJPEG_TABLE_ID_LAST>
{
using enum_type = rocprofiler_marker_core_api_id_t;
static constexpr auto callback_domain_idx = ROCPROFILER_CALLBACK_TRACING_ROCJPEG_API;
static constexpr auto buffered_domain_idx = ROCPROFILER_BUFFER_TRACING_ROCJPEG_API;
static constexpr auto none = ROCPROFILER_ROCJPEG_API_ID_NONE;
static constexpr auto last = ROCPROFILER_ROCJPEG_API_ID_LAST;
static constexpr auto external_correlation_id_domain_idx =
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_ROCJPEG_API;
};
} // namespace rocjpeg
} // namespace rocprofiler
#if defined(ROCPROFILER_LIB_ROCPROFILER_SDK_ROCJPEG_ROCJPEG_CPP_IMPL) && \
ROCPROFILER_LIB_ROCPROFILER_SDK_ROCJPEG_ROCJPEG_CPP_IMPL == 1
// clang-format off
ROCJPEG_API_TABLE_LOOKUP_DEFINITION(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, rocjpeg_api_func_table_t)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegStreamCreate, rocJpegStreamCreate, pfn_rocjpeg_stream_create, jpeg_stream_handle)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegStreamParse, rocJpegStreamParse, pfn_rocjpeg_stream_parse, data, length, jpeg_stream_handle)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegStreamDestroy, rocJpegStreamDestroy, pfn_rocjpeg_stream_destroy, jpeg_stream_handle)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegCreate, rocJpegCreate, pfn_rocjpeg_create, backend, device_id, handle)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegDestroy, rocJpegDestroy, pfn_rocjpeg_destroy, handle)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegGetImageInfo, rocJpegGetImageInfo, pfn_rocjpeg_get_image_info, handle, jpeg_stream_handle, num_components, subsampling, widths, heights)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegDecode, rocJpegDecode, pfn_rocjpeg_decode, handle, jpeg_stream_handle, decode_params, destination)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegDecodeBatched, rocJpegDecodeBatched, pfn_rocjpeg_decode_batched, handle, jpeg_stream_handles, batch_size, decode_params, destinations)
ROCJPEG_API_INFO_DEFINITION_V(ROCPROFILER_ROCJPEG_TABLE_ID_CORE, ROCPROFILER_ROCJPEG_API_ID_rocJpegGetErrorName, rocJpegGetErrorName, pfn_rocjpeg_get_error_name, rocjpeg_status)
#else
# error \
"Do not compile this file directly. It is included by lib/rocprofiler-sdk/rocjpeg/rocjpeg.cpp"
#endif
@@ -0,0 +1,114 @@
// 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/rocjpeg/details/rocjpeg_headers.h>
#if ROCPROFILER_SDK_USE_SYSTEM_ROCJPEG > 0
# include <rocjpeg/amd_detail/rocjpeg_api_trace.h>
# include <rocjpeg/rocjpeg.h>
#else
# include <rocprofiler-sdk/rocjpeg/details/rocjpeg.h>
# include <rocprofiler-sdk/rocjpeg/details/rocjpeg_api_trace.h>
#endif
#include <rocprofiler-sdk/rocprofiler.h>
#include <cstdint>
#include <vector>
namespace rocprofiler
{
namespace rocjpeg
{
using rocjpeg_api_func_table_t = ::RocJpegDispatchTable;
struct RocJPEGAPITable
{
rocjpeg_api_func_table_t* rocjpeg_api_table = nullptr;
};
using rocjpeg_api_table_t = RocJPEGAPITable;
rocjpeg_api_table_t&
get_table();
template <size_t OpIdx>
struct rocjpeg_table_lookup;
template <typename Tp>
struct rocjpeg_table_id_lookup;
template <size_t TableIdx>
struct rocjpeg_domain_info;
template <size_t TableIdx, size_t OpIdx>
struct rocjpeg_api_info;
template <size_t TableIdx, size_t OpIdx>
struct rocjpeg_api_impl : rocjpeg_domain_info<TableIdx>
{
template <typename DataArgsT, typename... Args>
static auto set_data_args(DataArgsT&, Args... args);
template <typename FuncT, typename... Args>
static auto exec(FuncT&&, Args&&... args);
template <typename RetT, typename... Args>
static RetT functor(Args... args);
};
template <size_t TableIdx>
const char*
name_by_id(uint32_t id);
template <size_t TableIdx>
uint32_t
id_by_name(const char* name);
template <size_t TableIdx>
std::vector<const char*>
get_names();
template <size_t TableIdx>
std::vector<uint32_t>
get_ids();
template <size_t TableIdx>
void
iterate_args(uint32_t id,
const rocprofiler_callback_tracing_rocjpeg_api_data_t& data,
rocprofiler_callback_tracing_operation_args_cb_t callback,
int32_t max_deref,
void* user_data);
template <typename TableT>
void
copy_table(TableT* _orig, uint64_t _tbl_instance);
template <typename TableT>
void
update_table(TableT* _orig);
} // namespace rocjpeg
} // namespace rocprofiler
@@ -57,7 +57,8 @@ SPECIALIZE_RUNTIME_INIT_INFO(HSA, "HSA runtime")
SPECIALIZE_RUNTIME_INIT_INFO(HIP, "HIP runtime")
SPECIALIZE_RUNTIME_INIT_INFO(MARKER, "Marker (ROCTx) runtime")
SPECIALIZE_RUNTIME_INIT_INFO(RCCL, "RCCL runtime")
SPECIALIZE_RUNTIME_INIT_INFO(ROCDECODE, "ROCDecode runtime")
SPECIALIZE_RUNTIME_INIT_INFO(ROCDECODE, "rocDecode runtime")
SPECIALIZE_RUNTIME_INIT_INFO(ROCJPEG, "rocJPEG runtime")
#undef SPECIALIZE_RUNTIME_INIT_INFO