Split ROCTx API tables and update intercept table API (#421)

* Update include/rocprofiler-sdk

- buffer_tracing.h
  - fix doxygen for rocprofiler_buffer_tracing_hip_api_record_t
  - update doxygen for rocprofiler_buffer_tracing_marker_api_record_t
    - remove unused marker_id field
- fwd.h
  - Split ROCPROFILER_CALLBACK_TRACING_MARKER_API into ROCPROFILER_CALLBACK_TRACING_MARKER_{CORE,CONTROL,NAME}_API
  - Split ROCPROFILER_BUFFER_TRACING_MARKER_API into ROCPROFILER_BUFFER_TRACING_MARKER_{CORE,CONTROL,NAME}_API
  - split rocprofiler_runtime_library_t into rocprofiler_runtime_library_t and rocprofiler_intercept_table_t
    - after split of ROCTx into 3 tables, specifying rocprofiler_at_internal_thread_create became confusing

* Update include/rocprofiler-sdk-roctx/api_trace.h

- Split into three tables: core, control, and name
  - core: what it sounds like
  - control: functions for controling the profiler
  - name: functions for giving resources names

* Update lib/rocprofiler-sdk-roctx/roctx.cpp

- modifications following split into multiple tables

* Update lib/rocprofiler-sdk/marker/*

- modifications following split of ROCTx API into multiple intercept tables

* Update lib/rocprofiler-sdk/tests

- common.hpp
  - add enums to get_callback_tracing_names() and get_buffer_tracing_names()
- intercept_table.cpp
  - update test to use rocprofiler_intercept_table_t (and enums) instead of rocproifler_runtime_library_t
  - update OR combos tested
- roctx.cpp
  - updates following split of ROCTx API table into multiple tables
  - use simplified specification of control API

* Update lib/rocprofiler-sdk

- buffer_tracing.cpp
  - Updates for ROCPROFILER_BUFFER_TRACING_MARKER_{CORE,CONTROL,NAME}_API enum values
- callback_tracing.cpp
  - Updates for ROCPROFILER_CALLBACK_TRACING_MARKER_{CORE,CONTROL,NAME}_API enum values
- intercept_table.hpp
  - notify_runtime_api_registration -> notify_intercept_table_registration
- intercept_table.cpp
  - updates for new rocprofiler_intercept_table_t enum and new ROCTx tables
- registration.cpp
  - updates for new rocprofiler_intercept_table_t enum and new ROCTx tables
  - updates for notify_runtime_api_registration -> notify_intercept_table_registration

* Update lib/rocprofiler-sdk-tool

- helper.cpp
  - Updates for new enums in get_callback_id_names() and get_buffer_id_names()
- tool.cpp
  - migrate to new enums for split ROCTx tables
  - use simplified split for control table vs. core+name tables

* Update samples/{api_callback_tracing,intercept_table}

- intercept_table/client.cpp
  - rocprofiler_runtime_library_t -> rocprofiler_intercept_table_t
- api_callback_tracing/client.cpp
  - Updates for new enums in get_callback_id_names()
  - use simplified split for control table vs. core+name tables
  - migrate to new enums for split ROCTx tables

* Update tests

- rocprofv3/tracing/validate.py
  - handle new marker domain names
- tools/json-tool.cpp
  - Updates for new enums in get_callback_id_names() and get_buffer_id_names()
  - use simplified split for control table vs. core+name tables
  - migrate to new enums for split ROCTx tables

* Update tests/rocprofv3/tracing/CMakeLists.txt

- fix FAIL_REGULAR_EXPRESSION for rocprofv3-test-trace-execute

* Update lib/rocprofiler-sdk-tool/{output_file,tool}.*

- logging in output_file dtor
- support stdout/stderr

* Update lib/common/container/record_header_buffer.hpp

- reduce probability of is_empty() returning true while emplace is happening

* Update lib/rocprofiler-sdk-tool/tool.cpp

- logging for buffered_tracing_callback
- counter collection uses CSV encoder

* Update bin/rocprofv3

- remove -i flag from help menu
This commit is contained in:
Jonathan R. Madsen
2024-01-26 13:56:15 -06:00
committed by GitHub
parent 75264b5587
commit 9efafc4d23
32 changed files with 881 additions and 628 deletions
+101 -74
View File
@@ -26,6 +26,7 @@
#include <rocprofiler-sdk-roctx/types.h>
#include "lib/common/logging.hpp"
#include "lib/common/static_object.hpp"
#include "lib/common/utility.hpp"
#include <glog/logging.h>
@@ -45,6 +46,8 @@ namespace roctx
{
namespace
{
namespace common = ::rocprofiler::common;
constexpr size_t
compute_table_offset(size_t n)
{
@@ -57,27 +60,38 @@ compute_table_size(size_t nmembers)
return (sizeof(uint64_t) + (nmembers * sizeof(void*)));
}
#define ROCTX_ASSERT_OFFSET(MEMBER, IDX) \
static_assert(offsetof(roctxApiTable_t, MEMBER) == compute_table_offset(IDX), \
#define ROCTX_ASSERT_OFFSET(TABLE, MEMBER, IDX) \
static_assert(offsetof(TABLE, MEMBER) == compute_table_offset(IDX), \
"Do not re-arrange the table members")
ROCTX_ASSERT_OFFSET(roctxMarkA_fn, 0);
ROCTX_ASSERT_OFFSET(roctxRangePushA_fn, 1);
ROCTX_ASSERT_OFFSET(roctxRangePop_fn, 2);
ROCTX_ASSERT_OFFSET(roctxRangeStartA_fn, 3);
ROCTX_ASSERT_OFFSET(roctxRangeStop_fn, 4);
ROCTX_ASSERT_OFFSET(roctxProfilerPause_fn, 5);
ROCTX_ASSERT_OFFSET(roctxProfilerResume_fn, 6);
ROCTX_ASSERT_OFFSET(roctxNameOsThread_fn, 7);
ROCTX_ASSERT_OFFSET(roctxNameHsaAgent_fn, 8);
ROCTX_ASSERT_OFFSET(roctxNameHipDevice_fn, 9);
ROCTX_ASSERT_OFFSET(roctxNameHipStream_fn, 10);
ROCTX_ASSERT_OFFSET(roctxGetThreadId_fn, 11);
// core
ROCTX_ASSERT_OFFSET(roctxCoreApiTable_t, roctxMarkA_fn, 0);
ROCTX_ASSERT_OFFSET(roctxCoreApiTable_t, roctxRangePushA_fn, 1);
ROCTX_ASSERT_OFFSET(roctxCoreApiTable_t, roctxRangePop_fn, 2);
ROCTX_ASSERT_OFFSET(roctxCoreApiTable_t, roctxRangeStartA_fn, 3);
ROCTX_ASSERT_OFFSET(roctxCoreApiTable_t, roctxRangeStop_fn, 4);
ROCTX_ASSERT_OFFSET(roctxCoreApiTable_t, roctxGetThreadId_fn, 5);
// control
ROCTX_ASSERT_OFFSET(roctxControlApiTable_t, roctxProfilerPause_fn, 0);
ROCTX_ASSERT_OFFSET(roctxControlApiTable_t, roctxProfilerResume_fn, 1);
// name
ROCTX_ASSERT_OFFSET(roctxNameApiTable_t, roctxNameOsThread_fn, 0);
ROCTX_ASSERT_OFFSET(roctxNameApiTable_t, roctxNameHsaAgent_fn, 1);
ROCTX_ASSERT_OFFSET(roctxNameApiTable_t, roctxNameHipDevice_fn, 2);
ROCTX_ASSERT_OFFSET(roctxNameApiTable_t, roctxNameHipStream_fn, 3);
#undef ROCTX_ASSERT_OFFSET
static_assert(
sizeof(roctxApiTable_t) == compute_table_size(12),
sizeof(roctxCoreApiTable_t) == compute_table_size(6),
"Update table major/step version and add a new offset assertion if this fails to compile");
static_assert(
sizeof(roctxControlApiTable_t) == compute_table_size(2),
"Update table major/step version and add a new offset assertion if this fails to compile");
static_assert(
sizeof(roctxNameApiTable_t) == compute_table_size(4),
"Update table major/step version and add a new offset assertion if this fails to compile");
auto&
@@ -155,26 +169,39 @@ roctxNameHipStream(const char*, const struct ihipStream_t*)
return 0;
}
auto&
struct roctx_api_table
{
roctxCoreApiTable_t core = common::init_public_api_struct(roctxCoreApiTable_t{});
roctxControlApiTable_t control = common::init_public_api_struct(roctxControlApiTable_t{});
roctxNameApiTable_t name = common::init_public_api_struct(roctxNameApiTable_t{});
};
auto*&
get_table_impl()
{
rocprofiler::common::init_logging("ROCTX_LOG_LEVEL");
static auto val = roctxApiTable_t{sizeof(roctxApiTable_t),
&::roctx::roctxMarkA,
&::roctx::roctxRangePushA,
&::roctx::roctxRangePop,
&::roctx::roctxRangeStartA,
&::roctx::roctxRangeStop,
&::roctx::roctxProfilerPause,
&::roctx::roctxProfilerResume,
&::roctx::roctxNameOsThread,
&::roctx::roctxNameHsaAgent,
&::roctx::roctxNameHipDevice,
&::roctx::roctxNameHipStream,
&::roctx::roctxGetThreadId};
auto*& tbl = rocprofiler::common::static_object<roctx_api_table>::construct();
auto table_array = std::array<void*, 1>{&val};
tbl->core = roctxCoreApiTable_t{sizeof(roctxCoreApiTable_t),
&::roctx::roctxMarkA,
&::roctx::roctxRangePushA,
&::roctx::roctxRangePop,
&::roctx::roctxRangeStartA,
&::roctx::roctxRangeStop,
&::roctx::roctxGetThreadId};
tbl->control = roctxControlApiTable_t{sizeof(roctxControlApiTable_t),
&::roctx::roctxProfilerPause,
&::roctx::roctxProfilerResume};
tbl->name = roctxNameApiTable_t{sizeof(roctxNameApiTable_t),
&::roctx::roctxNameOsThread,
&::roctx::roctxNameHsaAgent,
&::roctx::roctxNameHipDevice,
&::roctx::roctxNameHipStream};
auto table_array = std::array<void*, 3>{&tbl->core, &tbl->control, &tbl->name};
auto lib_id = rocprofiler_register_library_indentifier_t{};
auto rocp_reg_status =
rocprofiler_register_library_api_table("roctx",
@@ -192,13 +219,13 @@ get_table_impl()
<< "] rocprofiler-register failed with error code " << rocp_reg_status << ": "
<< rocprofiler_register_error_string(rocp_reg_status);
return val;
return tbl;
}
const auto*
get_table()
{
static const auto* tbl = &get_table_impl();
static auto*& tbl = get_table_impl();
return tbl;
}
} // namespace
@@ -209,73 +236,73 @@ ROCTX_EXTERN_C_INIT
void
roctxMarkA(const char* message)
{
::roctx::get_table()->roctxMarkA_fn(message);
::roctx::get_table()->core.roctxMarkA_fn(message);
}
int
roctxRangePushA(const char* message)
{
return ::roctx::get_table()->roctxRangePushA_fn(message);
return ::roctx::get_table()->core.roctxRangePushA_fn(message);
}
int
roctxRangePop()
{
return ::roctx::get_table()->roctxRangePop_fn();
return ::roctx::get_table()->core.roctxRangePop_fn();
}
roctx_range_id_t
roctxRangeStartA(const char* message)
{
return ::roctx::get_table()->roctxRangeStartA_fn(message);
return ::roctx::get_table()->core.roctxRangeStartA_fn(message);
}
void
roctxRangeStop(roctx_range_id_t id)
{
return ::roctx::get_table()->roctxRangeStop_fn(id);
}
int
roctxProfilerPause(roctx_thread_id_t tid)
{
return ::roctx::get_table()->roctxProfilerPause_fn(tid);
}
int
roctxProfilerResume(roctx_thread_id_t tid)
{
return ::roctx::get_table()->roctxProfilerResume_fn(tid);
}
int
roctxNameOsThread(const char* name)
{
return ::roctx::get_table()->roctxNameOsThread_fn(name);
}
int
roctxNameHsaAgent(const char* name, const struct hsa_agent_s* agent)
{
return ::roctx::get_table()->roctxNameHsaAgent_fn(name, agent);
}
int
roctxNameHipDevice(const char* name, int device_id)
{
return ::roctx::get_table()->roctxNameHipDevice_fn(name, device_id);
}
int
roctxNameHipStream(const char* name, const struct ihipStream_t* stream)
{
return ::roctx::get_table()->roctxNameHipStream_fn(name, stream);
return ::roctx::get_table()->core.roctxRangeStop_fn(id);
}
int
roctxGetThreadId(roctx_thread_id_t* tid)
{
return ::roctx::get_table()->roctxGetThreadId_fn(tid);
return ::roctx::get_table()->core.roctxGetThreadId_fn(tid);
}
int
roctxProfilerPause(roctx_thread_id_t tid)
{
return ::roctx::get_table()->control.roctxProfilerPause_fn(tid);
}
int
roctxProfilerResume(roctx_thread_id_t tid)
{
return ::roctx::get_table()->control.roctxProfilerResume_fn(tid);
}
int
roctxNameOsThread(const char* name)
{
return ::roctx::get_table()->name.roctxNameOsThread_fn(name);
}
int
roctxNameHsaAgent(const char* name, const struct hsa_agent_s* agent)
{
return ::roctx::get_table()->name.roctxNameHsaAgent_fn(name, agent);
}
int
roctxNameHipDevice(const char* name, int device_id)
{
return ::roctx::get_table()->name.roctxNameHipDevice_fn(name, device_id);
}
int
roctxNameHipStream(const char* name, const struct ihipStream_t* stream)
{
return ::roctx::get_table()->name.roctxNameHipStream_fn(name, stream);
}
ROCTX_EXTERN_C_FINI