PC Sampling Support (#715)
* cmake formatting (cmake-format) (#188) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * source formatting (clang-format v11) (#189) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: design of the pc sampling data struct; guarding parts of code that uses ROCr marker packets * source formatting (clang-format v11) (#191) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * cmake formatting (cmake-format) (#192) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: shadow variable fix * pcs: fix for compiler errors reported by CI/CD * source formatting (clang-format v11) (#193) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: docs fix; samples uses rocprofiler::rocprofiler library * cmake formatting (cmake-format) (#195) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: client in samples folder fixed * pcs: client requires rocprofiler package as dependency * pcs: client uses single context * source formatting (clang-format v11) (#196) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: client using single buffer; no buffer destroy in client * pcs: client::setup explicitly called from the example * pcs: rocprofiler_pc_sample_record_t updated * pcs: fixed init of external correlation id * source formatting (clang-format v11) (#198) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: remove outdated files; update CMakeLists * cmake formatting (cmake-format) (#212) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: using rocprofiler_agent_id_t * pcs: Removing trailing whitespaces Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> * source formatting (clang-format v11) (#214) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: mapping agent_id to the agent * source formatting (clang-format v11) (#215) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: const while iterating over agents * source formatting (clang-format v11) (#216) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: calling get_buffer instead of get_buffers * pcs: workgroup typo * pcs: documentation for the public PC sampling API * pcs: queue_cb_t signature adaptation * pcs: mocks removed * pcs: updating HsaApiTable with HSA/ROCr PC sampling API * pcs: querying available PC sampling configs through IOCTL * pcs: create the PCS session in IOCTL * pcs: first actual PC samples delivered to the rocprofiler's client :) * pcs: works with marker packet too * pcs: using HSA table to call pc sampling related functions * pcs: using ioctl instead of kfd in naming * pcs: configuration service test fixed * pcs: sample processing test fixed * pcs: marker packet macro wrapper removed * pcs: marker packet is part of the rocprofiler_packet union * pcs: one fixme added * pcs: client that uses pc-sampling and code obj tracing * pcs: client that supprts PC sampling and code obj tracing refactored * pcs: show more info for each PC sample * pcs: hex output for the samples that do not belong to the matmul kernel * pcs: querying avail configuration happens immediately before configuring * pcs: hsa_ven_amd_pcs_create_from_id renamed * pcs: using hsa_stop; accessing a buffer by id from parser * pcs: includes reworked, tests returned to life * pcs: rocrofiler dir removed as outdated * cmake formatting (cmake-format) (#271) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * source formatting (clang-format v11) (#272) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: some warnings fixed * source formatting (clang-format v11) (#273) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * cmake formatting (cmake-format) (#274) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: show MI200 relevant information in the sample * pcs: queue cb fixed; rocr.h include fixed * source formatting (clang-format v11) (#296) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: getting hsa_agent and the doorbell_id from hsa_queue * source formatting (clang-format v11) (#297) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: correlation ID logic fixed * source formatting (clang-format v11) (#303) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: pure pc sampling example fixed * source formatting (clang-format v11) (#307) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * cmake formatting (cmake-format) (#308) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: interval value if the PC sampling is already configured * pcs: ROCPROFILER_STATUS_ERROR_PC_SAMPLING_ALREADY_CONFIGURED New status code if another process configured PC sampling service with different configuration. Samples are extended to consider this case and retry if it happens. * pcs: hsa_amd_queue_get_info mocked in tests * source formatting (clang-format v11) (#328) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs (tests): query configs after configuring service * source formatting (clang-format v11) (#329) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: sample checks workgroup_id_* and wave_id * source formatting (clang-format v11) (#330) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs samples: running samples on the device 0 * pcs: kfd_ioctl updated * pcs: ioctl config struct changed fields names * pcs: status when PC sampling is configured by another process is renamed * pcs: HSA PC sampling API table fixed * pcs: tmp hack to be able to use HSA pc sampling table * source formatting (clang-format v11) (#443) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs service use CIDs generated by HIP API tracing service * source formatting (clang-format v11) (#455) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * cmake formatting (cmake-format) (#456) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: CID manager * pcs: explicit flush with no delivered data executes retirement logic * source formatting (clang-format v11) (#464) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: rocprofiler_query_pc_sampling_agent_configurations docs update * source formatting (clang-format v11) (#465) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: rocprofiler_configure_pc_sampling_service docs update * pcs: explicit sync introduced in PCSCIDManager * pcs: new logic for retiring CIDs in PC sampling service documented * pcs: queue interception cb signature updated * source formatting (clang-format v11) (#471) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: if no agents supports PC sampling, fail gracefully * elaborating when KFD returns EBUSY and EEXIST * pcs: the second PC sampling examples fails gracefully * code samples use only single kernel for now * pcs: CID manager refactored * source formatting (clang-format v11) (#481) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * pcs: ioctl update * source formatting (clang-format v11) (#531) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs:code sample to test PC sampling applied on concurrent kernels * source formatting (clang-format v11) (#533) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: pc sampling strest test included * cmake formatting (cmake-format) (#539) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * source formatting (clang-format v11) (#540) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: standalone benchmark * cmake formatting (cmake-format) (#555) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: glance in external correlation IDs * source formatting (clang-format v11) (#557) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * another change in ioctl interface * pcs: update queue interceptor callbacks and samples accroding to the agent 0 version * source formatting (clang-format v11) (#611) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: avoid running problematic PC sampling test * pcs: guarding tests not to fail on architectures not supporting PC sampling * source formatting (clang-format v11) (#617) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: check IOCTL version prior to each KFD call * pcs: ioctl refactoring * pcs: PC sampling service increases the ref_count of the correlation ID of the kernel dispatch * cmake formatting (cmake-format) (#631) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * source formatting (clang-format v11) (#632) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: PC sampling service provides external correlation IDs * source formatting (clang-format v11) (#644) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: use rocprofiler_dim3_t for workgrou_ip * source formatting (clang-format v11) (#645) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: minor fixes * pcs: updating the documentation for the pc sampling API functions * pcs: api table and queue controller fix * pcs: don't generate marker packets for the agent if PC sampling is not configured on it * pcs: multi-GPU and single-GPU clients * source formatting (clang-format v11) (#700) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: warning and errors fixed * source formatting (clang-format v11) (#702) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: clang compiler errors and warnings fixed * source formatting (clang-format v11) (#716) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: const reference in cid manager * source formatting (clang-format v11) (#717) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: const & func in manager explicit * pcs: test to cover creating PC sampling service of agent that does not exist * pcs: generate marker packets if service is active * source formatting (clang-format v11) (#719) Co-authored-by: vlaindic <139573562+vlaindic@users.noreply.github.com> * pcs: refactoring hsa_adapter; use the correlation_id->thread_idx * Update source/lib/rocprofiler-sdk/pc_sampling/cid_manager.cpp * Update source/lib/rocprofiler-sdk/pc_sampling/cid_manager.cpp * Update source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp * Update source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp * Update source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp * Update source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp * Update source/lib/rocprofiler-sdk/pc_sampling/utils.cpp * Update utils.cpp * moving pc-sampling tests and samples to pc-sampling label * Format fix * pcs: use configured instead of active service * Update source/lib/rocprofiler-sdk/pc_sampling/service.cpp * pcs: ensure configuring PC sampling on the HSA level is called only once * pcs: minor fix * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * pcs: refactoring IOCTL integration * Update source/lib/rocprofiler-sdk/pc_sampling/tests/CMakeLists.txt Co-authored-by: Ammar ELWazir <ammar.elwazir@amd.com> * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter_types.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter_types.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * pcs: reverting back what bot doubled * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter_types.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * pcs: retesting the bot * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter_types.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * pcs: why bot fails on this IOCTL status * pcs: why failing on <vector> * Update source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * pcs: returning commits removed by bot * pcs: formatting locally * pcs: clients are flushing buffers inside the tool_fini * pcs: sync function in public API * pcs: sync prior to unloading the code object * pcs: sync function requires context * pcs: client uses CID retirement service * pcs: test for flusing internal ROCr buffers * pcs: source formatting * Update source/lib/rocprofiler-sdk/pc_sampling/tests/CMakeLists.txt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * pcs: code samples refactoring * pcs: public API header refactored * pcs: rocprofiler_buffer_flush drains internal PC sampling buffers too * pcs: remove unnecessary functions * pcs: do not call hsa's copytables * pcs: include reordering * pcs: using ROCP_ERROR inside PC sampling implementation * pcs: pc_sampling sample uses ostream instean of printfs * pcs: pc_sampling_codeobj tracing using ostream instead of prints * pcs: registering once for interceptor callbacks * pcs: do not generate internal CIDs if not in debug mode * pcs: rebasing fixed; missing external correlation IDs * pcs: code formatting * enable kernel tracing service to receive external correlation IDs * pcs: using ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL * pcs: polishing parser * formatting * updating parser to use workgroup_id * kfd_ioctl.h extracted in details folder * refactoring * pcs: preparing to generate code object information * flush internal buffers prior to unloading code object * pcs: generating marker records * pcs: wrap code_object's shutdown function * ROCR_VISIBLE_DEVICES and HIP_VISISBLE_DEVICES unsupported at the moment * documenting the ignorance of ROCR/HIP_VISIBLE_DEVICES * pcs: separate structs for code object loading/unloading markers * pcs: inst_pkt_t changed the namespace * pcs: removing wrapper around the shutdown function * pcs: size in record field * pcs: documentation refactoring + typdefs * renaming PCSAgentConfig to PCSAgentSession * pcs: service does not keep a pointer to the context * pcs: static assertions related to the versioning * pcs: rocprofiler_pc_sampling_configuration_t size field * pcs: report API unimplemented unleass explicitly enabled * pcs: skip tests if KFD does not support PC sampling * pcs: if ROCr hides some devices, no PC samples will be delivered for it * pcs: hip error check after kernel launch * formatting * removing PCS info from agent.h * fix based on review * Update continuous integration workflow - use mi200 runner for code coverage (supports PC sampling) - split sanitizer jobs across navi3, vega20, and mi300 * Updating pc sampling test labels * ROCP_PC_SAMPLING_ENABLED env in CI * ROCP_PC_SAMPLING_ENABLED for all CI mi200 jobs * Rearrange sanitizer assignments * fixes according to review * removed unused functions * pcs: rocprofiler_agent_id_t instead of handle as a key in map * Update source/lib/rocprofiler-sdk/context/context.hpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * removing drm_fd from the agent.h * pcs: removing one sample due to complexity * pcs: refactoring sample * simplifying sample * new lines * Improve queue_control enable intercepter logic * Update lib/rocprofiler-sdk/hsa/types.hpp - handle amd_ext size for HSA 1.12.0 * ROCP_PC_SAMPLING_ENABLED -> ROCPROFILER_PC_SAMPLING_BETA_ENABLED * Update hsa_adapter.cpp - anonymous namespace + remove debug * parser update * Apply suggestions from code review --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> Co-authored-by: vlaindic <vladimir.indic@amd.com> Co-authored-by: vlaindic <vlaindic@amd.com> Co-authored-by: Vladimir Indic <139573562+vlaindic@users.noreply.github.com> Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> Co-authored-by: gobhardw <gopesh.bhardwaj@amd.com> Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
@@ -48,6 +48,7 @@ add_subdirectory(thread_trace)
|
||||
add_subdirectory(tracing)
|
||||
add_subdirectory(kernel_dispatch)
|
||||
add_subdirectory(page_migration)
|
||||
add_subdirectory(details)
|
||||
|
||||
target_link_libraries(
|
||||
rocprofiler-object-library
|
||||
|
||||
@@ -355,12 +355,6 @@ read_property(const MapT& data, const std::string& label, Tp& value)
|
||||
}
|
||||
}
|
||||
|
||||
constexpr auto
|
||||
compute_version(uint32_t major_v, uint32_t minor_v, uint32_t patch_v)
|
||||
{
|
||||
return (major_v * 10000) + (minor_v * 100) + patch_v;
|
||||
}
|
||||
|
||||
auto
|
||||
read_topology()
|
||||
{
|
||||
@@ -371,15 +365,6 @@ read_topology()
|
||||
throw std::runtime_error{
|
||||
fmt::format("sysfs nodes path '{}' does not exist", sysfs_nodes_path.string())};
|
||||
|
||||
using pc_sampling_config_vec_t = std::vector<rocprofiler_pc_sampling_configuration_t>;
|
||||
|
||||
static auto mi200_pc_sampling_config = pc_sampling_config_vec_t{
|
||||
rocprofiler_pc_sampling_configuration_t{ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP,
|
||||
ROCPROFILER_PC_SAMPLING_UNIT_TIME,
|
||||
1UL,
|
||||
1000000000UL,
|
||||
0}};
|
||||
|
||||
const auto& cpu_info_v = get_cpu_info();
|
||||
auto data = std::vector<unique_agent_t>{};
|
||||
uint64_t idcount = 0;
|
||||
@@ -513,18 +498,6 @@ read_topology()
|
||||
}
|
||||
drmClose(drm_fd);
|
||||
}
|
||||
|
||||
// TODO(jomadsen): make contingent on whether this process acquired the PC sampling
|
||||
// device lock
|
||||
{
|
||||
constexpr auto gfx90a_version = compute_version(9, 0, 10);
|
||||
|
||||
if(agent_info.gfx_target_version >= gfx90a_version)
|
||||
{
|
||||
agent_info.pc_sampling_configs = mi200_pc_sampling_config.data();
|
||||
agent_info.num_pc_sampling_configs = mi200_pc_sampling_config.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(agent_info.type == ROCPROFILER_AGENT_TYPE_CPU)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "lib/rocprofiler-sdk/context/domain.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
|
||||
#include "lib/rocprofiler-sdk/internal_threading.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
#include "lib/rocprofiler-sdk/registration.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
@@ -271,6 +272,10 @@ rocprofiler_create_buffer(rocprofiler_context_id_t context,
|
||||
rocprofiler_status_t
|
||||
rocprofiler_flush_buffer(rocprofiler_buffer_id_t buffer_id)
|
||||
{
|
||||
// Drain internal PC sampling buffers, if needed.
|
||||
auto status = rocprofiler::pc_sampling::flush_internal_agent_buffers(buffer_id);
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
|
||||
|
||||
return rocprofiler::buffer::flush(buffer_id, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "lib/rocprofiler-sdk/buffer.hpp"
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/core.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
#include "lib/rocprofiler-sdk/thread_trace/att_core.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -322,6 +323,7 @@ start_context(rocprofiler_context_id_t context_id)
|
||||
if(cfg->counter_collection) rocprofiler::counters::start_context(cfg);
|
||||
if(cfg->thread_trace) cfg->thread_trace->start_context();
|
||||
if(cfg->agent_counter_collection) status = rocprofiler::counters::start_agent_ctx(cfg);
|
||||
if(cfg->pc_sampler) status = rocprofiler::pc_sampling::start_service(cfg);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -357,6 +359,12 @@ stop_context(rocprofiler_context_id_t idx)
|
||||
{
|
||||
rocprofiler::counters::stop_agent_ctx(const_cast<context*>(_expected));
|
||||
}
|
||||
|
||||
if(_expected->pc_sampler)
|
||||
{
|
||||
rocprofiler::pc_sampling::stop_service(_expected);
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,16 @@
|
||||
#include "lib/rocprofiler-sdk/counters/agent_profiling.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/core.hpp"
|
||||
#include "lib/rocprofiler-sdk/external_correlation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
|
||||
#include "lib/rocprofiler-sdk/thread_trace/att_core.hpp"
|
||||
#include "rocprofiler-sdk/agent.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
@@ -112,6 +115,16 @@ struct agent_counter_collection_service
|
||||
common::Synchronized<bool> enabled{false};
|
||||
};
|
||||
|
||||
struct pc_sampling_service
|
||||
{
|
||||
// Contains a map with pairs (rocprofiler_agent_id_t, PCSAgentSession*).
|
||||
// The PCSAgentSession encapsulates the information about the configured PC sampling session
|
||||
// used on the agent with `rocprofiler_agent_id_t`.
|
||||
std::unordered_map<rocprofiler_agent_id_t,
|
||||
std::unique_ptr<rocprofiler::pc_sampling::PCSAgentSession>>
|
||||
agent_sessions;
|
||||
};
|
||||
|
||||
struct context
|
||||
{
|
||||
// size is used to ensure that we never read past the end of the version
|
||||
@@ -125,6 +138,7 @@ struct context
|
||||
std::unique_ptr<dispatch_counter_collection_service> counter_collection = {};
|
||||
std::unique_ptr<agent_counter_collection_service> agent_counter_collection = {};
|
||||
std::shared_ptr<ThreadTracer> thread_trace = {};
|
||||
std::unique_ptr<pc_sampling_service> pc_sampler = {};
|
||||
};
|
||||
|
||||
// set the client index needs to be called before allocate_context()
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
set(ROCPROFILER_DETAILS_SOURCES)
|
||||
set(ROCPROFILER_DETAILS_HEADERS kfd_ioctl.h)
|
||||
|
||||
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_DETAILS_SOURCES}
|
||||
${ROCPROFILER_DETAILS_HEADERS})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,8 @@
|
||||
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
|
||||
#include "lib/rocprofiler-sdk/kernel_dispatch/tracing.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
#include "lib/rocprofiler-sdk/registration.hpp"
|
||||
#include "lib/rocprofiler-sdk/tracing/tracing.hpp"
|
||||
|
||||
@@ -369,6 +371,12 @@ WriteInterceptor(const void* packets,
|
||||
CreateBarrierPacket(nullptr, nullptr, transformed_packets);
|
||||
}
|
||||
|
||||
if(pc_sampling::is_pc_sample_service_configured(queue.get_agent().get_rocp_agent()->id))
|
||||
{
|
||||
transformed_packets.emplace_back(pc_sampling::hsa::generate_marker_packet_for_kernel(
|
||||
corr_id, tracing_data_v.external_correlation_ids));
|
||||
}
|
||||
|
||||
transformed_packets.emplace_back(kernel_pkt);
|
||||
|
||||
// Make a copy of the original packet, adding its signal to a barrier
|
||||
|
||||
@@ -136,8 +136,6 @@ constexpr rocprofiler_agent_t default_agent =
|
||||
.vendor_name = nullptr,
|
||||
.product_name = nullptr,
|
||||
.model_name = nullptr,
|
||||
.num_pc_sampling_configs = 0,
|
||||
.pc_sampling_configs = nullptr,
|
||||
.node_id = 0,
|
||||
.logical_node_id = 0};
|
||||
} // namespace
|
||||
@@ -256,26 +254,24 @@ QueueController::init(CoreApiTable& core_table, AmdExtTable& ext_table)
|
||||
auto enable_intercepter = false;
|
||||
for(const auto& itr : context::get_registered_contexts())
|
||||
{
|
||||
constexpr auto expected_context_size = 192UL;
|
||||
constexpr auto expected_context_size = 200UL;
|
||||
static_assert(
|
||||
sizeof(context::context) ==
|
||||
expected_context_size + sizeof(std::shared_ptr<rocprofiler::ThreadTracer>),
|
||||
"If you added a new field to context struct, make sure there is a check here if it "
|
||||
"requires queue interception. Once you have done so, increment expected_context_size");
|
||||
|
||||
if(itr->counter_collection)
|
||||
bool has_kernel_tracing =
|
||||
(itr->callback_tracer &&
|
||||
itr->callback_tracer->domains(ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH)) ||
|
||||
(itr->buffered_tracer &&
|
||||
itr->buffered_tracer->domains(ROCPROFILER_BUFFER_TRACING_KERNEL_DISPATCH));
|
||||
|
||||
if(itr->counter_collection || itr->pc_sampler || has_kernel_tracing)
|
||||
{
|
||||
enable_intercepter = true;
|
||||
break;
|
||||
}
|
||||
else if(itr->buffered_tracer)
|
||||
{
|
||||
if(itr->buffered_tracer->domains(ROCPROFILER_BUFFER_TRACING_KERNEL_DISPATCH))
|
||||
{
|
||||
enable_intercepter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(itr->thread_trace)
|
||||
{
|
||||
enable_intercepter = true;
|
||||
@@ -288,15 +284,6 @@ QueueController::init(CoreApiTable& core_table, AmdExtTable& ext_table)
|
||||
[trace](const AgentCache& cache, const CoreApiTable&, const AmdExtTable&) {
|
||||
if(auto locked = trace.lock()) locked->resource_deinit(cache);
|
||||
});
|
||||
break;
|
||||
}
|
||||
else if(itr->callback_tracer)
|
||||
{
|
||||
if(itr->callback_tracer->domains(ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH))
|
||||
{
|
||||
enable_intercepter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ union rocprofiler_packet
|
||||
hsa_kernel_dispatch_packet_t kernel_dispatch;
|
||||
hsa_barrier_and_packet_t barrier_and;
|
||||
hsa_barrier_or_packet_t barrier_or;
|
||||
amd_aql_intercept_marker_t marker;
|
||||
|
||||
rocprofiler_packet()
|
||||
: ext_amd_aql_pm4{null_amd_aql_pm4_packet}
|
||||
@@ -66,6 +67,10 @@ union rocprofiler_packet
|
||||
: barrier_or{val}
|
||||
{}
|
||||
|
||||
rocprofiler_packet(amd_aql_intercept_marker_t val)
|
||||
: marker{val}
|
||||
{}
|
||||
|
||||
~rocprofiler_packet() = default;
|
||||
rocprofiler_packet(const rocprofiler_packet&) = default;
|
||||
rocprofiler_packet(rocprofiler_packet&&) noexcept = default;
|
||||
|
||||
@@ -152,8 +152,10 @@ struct table_size<ROCPROFILER_COMPUTE_VERSION(1, 12, 0)>
|
||||
// TODO(jomadsen): come up with a better way of handling this
|
||||
# if HSA_AMD_EXT_API_TABLE_STEP_VERSION == 0x00
|
||||
static constexpr size_t amd_ext = 552;
|
||||
# else
|
||||
# elif HSA_AMD_EXT_API_TABLE_STEP_VERSION == 0x1
|
||||
static constexpr size_t amd_ext = 560;
|
||||
# else
|
||||
static constexpr size_t amd_ext = 568;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
@@ -5,5 +5,3 @@ set(ROCPROFILER_LIB_UVM_HEADERS defines.hpp page_migration.hpp utils.hpp)
|
||||
|
||||
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_UVM_SOURCES}
|
||||
${ROCPROFILER_LIB_UVM_HEADERS})
|
||||
|
||||
add_subdirectory(details)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#
|
||||
#
|
||||
set(ROCPROFILER_LIB_UVM_DETAILS_SOURCES)
|
||||
set(ROCPROFILER_LIB_UVM_DETAILS_HEADERS kfd_ioctl.h)
|
||||
|
||||
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_UVM_DETAILS_SOURCES}
|
||||
${ROCPROFILER_LIB_UVM_DETAILS_HEADERS})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,8 +27,8 @@
|
||||
#include "lib/rocprofiler-sdk/agent.hpp"
|
||||
#include "lib/rocprofiler-sdk/buffer.hpp"
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/details/kfd_ioctl.h"
|
||||
#include "lib/rocprofiler-sdk/internal_threading.hpp"
|
||||
#include "lib/rocprofiler-sdk/page_migration/details/kfd_ioctl.h"
|
||||
#include "lib/rocprofiler-sdk/page_migration/utils.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/agent.h>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/rocprofiler-sdk/page_migration/details/kfd_ioctl.h"
|
||||
#include "lib/rocprofiler-sdk/details/kfd_ioctl.h"
|
||||
|
||||
#include <rocprofiler-sdk/buffer_tracing.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
|
||||
@@ -23,10 +23,38 @@
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
|
||||
#include "lib/common/utility.hpp"
|
||||
#include "lib/common/environment.hpp"
|
||||
#include "lib/rocprofiler-sdk/agent.hpp"
|
||||
#include "lib/rocprofiler-sdk/buffer.hpp"
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
|
||||
#include "lib/rocprofiler-sdk/registration.hpp"
|
||||
|
||||
using ::rocprofiler::common::consume_args;
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* @brief The functions checks if the `ROCPROFILER_PC_SAMPLING_BETA_ENABLED` is set.
|
||||
* If so, it will enable PC sampling API. Otherwise, the API is reported
|
||||
* as not implemented.
|
||||
*
|
||||
* The PC sampling is in experimental phase and its usage may hang the machine
|
||||
* requiring the reboot. By enabling the `ROCPROFILER_PC_SAMPLING_BETA_ENABLED`,
|
||||
* user accepts all consequences of using early implementation of PC sampling API.
|
||||
*/
|
||||
bool
|
||||
is_pc_sampling_explicitly_enabled()
|
||||
{
|
||||
auto pc_sampling_enabled =
|
||||
rocprofiler::common::get_env("ROCPROFILER_PC_SAMPLING_BETA_ENABLED", false);
|
||||
|
||||
if(!pc_sampling_enabled) LOG(ERROR) << "PC sampling unavailable\n";
|
||||
|
||||
return pc_sampling_enabled;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
rocprofiler_status_t
|
||||
@@ -37,20 +65,61 @@ rocprofiler_configure_pc_sampling_service(rocprofiler_context_id_t conte
|
||||
uint64_t interval,
|
||||
rocprofiler_buffer_id_t buffer_id)
|
||||
{
|
||||
if(rocprofiler::registration::get_init_status() > 0)
|
||||
if(!is_pc_sampling_explicitly_enabled()) return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
|
||||
if(rocprofiler::registration::get_init_status() > -1)
|
||||
return ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED;
|
||||
|
||||
consume_args(context_id, agent_id, method, unit, interval, buffer_id);
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
|
||||
const auto* agent = rocprofiler::agent::get_agent(agent_id);
|
||||
if(!agent) return ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND;
|
||||
|
||||
// checking if the registered context exists
|
||||
auto* ctx = rocprofiler::context::get_mutable_registered_context(context_id);
|
||||
if(!ctx) return ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND;
|
||||
|
||||
// checking if the buffer is registered
|
||||
auto const* buff = rocprofiler::buffer::get_buffer(buffer_id);
|
||||
if(!buff) return ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND;
|
||||
|
||||
return rocprofiler::pc_sampling::configure_pc_sampling_service(
|
||||
ctx, agent, method, unit, interval, buffer_id);
|
||||
#else
|
||||
(void) context_id;
|
||||
(void) agent_id;
|
||||
(void) method;
|
||||
(void) unit;
|
||||
(void) interval;
|
||||
(void) buffer_id;
|
||||
|
||||
// ROCr runtime is missing PC sampling.
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
rocprofiler_status_t ROCPROFILER_API
|
||||
rocprofiler_status_t
|
||||
rocprofiler_query_pc_sampling_agent_configurations(
|
||||
rocprofiler_agent_id_t agent_id,
|
||||
rocprofiler_available_pc_sampling_configurations_cb_t cb,
|
||||
void* user_data)
|
||||
{
|
||||
consume_args(agent_id, cb, user_data);
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
|
||||
if(!is_pc_sampling_explicitly_enabled()) return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
|
||||
const auto* agent = rocprofiler::agent::get_agent(agent_id);
|
||||
if(!agent) return ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND;
|
||||
|
||||
std::vector<rocprofiler_pc_sampling_configuration_t> configs;
|
||||
auto status = rocprofiler::pc_sampling::ioctl::ioctl_query_pcs_configs(agent, configs);
|
||||
return (status == ROCPROFILER_STATUS_SUCCESS) ? cb(configs.data(), configs.size(), user_data)
|
||||
: status;
|
||||
#else
|
||||
(void) agent_id;
|
||||
(void) cb;
|
||||
(void) user_data;
|
||||
|
||||
// ROCr runtime is missing PC sampling.
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,14 @@
|
||||
set(ROCPROFILER_PC_SAMPLING_SOURCES hsa_adapter.cpp utils.cpp service.cpp cid_manager.cpp
|
||||
code_object.cpp)
|
||||
set(ROCPROFILER_PC_SAMPLING_HEADERS hsa_adapter.hpp utils.hpp service.hpp types.hpp
|
||||
cid_manager.hpp code_object.hpp)
|
||||
|
||||
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_PC_SAMPLING_SOURCES}
|
||||
${ROCPROFILER_PC_SAMPLING_HEADERS})
|
||||
|
||||
add_subdirectory(parser)
|
||||
add_subdirectory(ioctl)
|
||||
|
||||
if(ROCPROFILER_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/pc_sampling/cid_manager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
void
|
||||
PCSCIDManager::cid_async_activity_completed(context::correlation_id* cid)
|
||||
{
|
||||
// Hold the lock while updating the state of PCSCIDManager
|
||||
std::unique_lock<std::mutex> lock(m);
|
||||
// The kernel of the `cid` completed, so add cid to `q1`.
|
||||
q1.emplace_back(cid);
|
||||
}
|
||||
|
||||
void
|
||||
PCSCIDManager::manage_cids_implicit(const pc_samples_copy_fn_t& pc_samples_copy_fn)
|
||||
{
|
||||
std::vector<context::correlation_id*> q3;
|
||||
{
|
||||
// To manipulate the contents of q1 and q2 and change the state of PCSCIDManager,
|
||||
// acquire the lock.
|
||||
std::unique_lock<std::mutex> lock(m);
|
||||
// Move all CIDs from q2 to the q3 local for this function.
|
||||
// Note: two buffer flushes happened since kernels of q3's CIDs completed.
|
||||
q3 = std::move(q2);
|
||||
// Move all CIDs from q1 to q2.
|
||||
// Note: exactly one buffer flush occured since kernels of q2's CIDs completed.
|
||||
q2 = std::move(q1);
|
||||
|
||||
// We move CIDs from one queue to another to reflect that an implicit ROCr's buffer flush
|
||||
// occured. move from q1 to q2 reflects the first buffer flush since kernels of q1's CIDs
|
||||
// completed move from q2 to local q3 reflects the second buffer flush since kernels of q2's
|
||||
// CIDs completed.
|
||||
|
||||
// Empty the q1 to indicate that there are no CIDs with the following property:
|
||||
// no buffer flush occured since the kernel of CID is marked completed.
|
||||
q1.clear();
|
||||
|
||||
// The code that follows does not change the state of the PCSCIDManager, so release the lock
|
||||
// implicitly.
|
||||
}
|
||||
|
||||
// Copy PC samples from the ROCr's buffer to the SDK's buffer by invoking the passed function.
|
||||
pc_samples_copy_fn();
|
||||
|
||||
// Exactly two implicit buffer flushes occured since kernels of q3's CIDs completed.
|
||||
// Since all PC samples corresponding to these CIDs are placed in the SDK's buffer,
|
||||
// decrement their reference counters to indicate that PC sampling service will not use
|
||||
// these CIDs anymore.
|
||||
// Eventually, CIDs retirement service will report retirement of these CIDs
|
||||
// to the client tool.
|
||||
// Note: the q3 is local to the function, so there is no need for inter-thread synchronization.
|
||||
retire_cids_of(q3);
|
||||
}
|
||||
|
||||
void
|
||||
PCSCIDManager::manage_cids_explicit(const pc_samples_copy_fn_t& pc_samples_explicit_flush_fn)
|
||||
{
|
||||
std::vector<context::correlation_id*> q1_copy;
|
||||
std::vector<context::correlation_id*> q2_copy;
|
||||
{
|
||||
// To manipulate the contents of q1 and q2 and change the state of PCSCIDManager,
|
||||
// acquire the lock.
|
||||
std::unique_lock<std::mutex> lock(m);
|
||||
|
||||
// Move all CIDs from q1 and q2 to local q1_copy and q2_copy, respectively
|
||||
q1_copy = std::move(q1);
|
||||
q2_copy = std::move(q2);
|
||||
|
||||
// Drop CIDs from q1 and q2, because the following explicit flush
|
||||
// will deliver corresponding samples.
|
||||
q1.clear();
|
||||
q2.clear();
|
||||
|
||||
// The code that follows does not change the state of the PCSCIDManager, so release the lock
|
||||
// implicitly.
|
||||
}
|
||||
|
||||
// Call the passed lambda function to initiate an explicit flush of ROCr buffer by leveraging
|
||||
// the `hsa_ven_amd_pcs_flush flush`. The latter function guarantees delivery of all samples
|
||||
// generated (sequenced) before the call to the `hsa_ven_amd_pcs_flush`.
|
||||
// Thus, all samples corresponding to CIDs of `q1_copy` and `q2_copy` will be copied
|
||||
// from the ROCr's buffer to the SDK's buffer,
|
||||
// meaning CIDs of `q1_copy` and `q2_copy` will not be used anymore by the PC sampling service.
|
||||
pc_samples_explicit_flush_fn();
|
||||
|
||||
// The PC sampling service will not use q1_copy's and q2_copy's CIDs anymore, so it decrements
|
||||
// their CIDs. Eventually, CIDs retirement service will report retirement of these CIDs to the
|
||||
// client tool. Note: both `q1_copy` and `q2_copy` are local to the function, so there is no
|
||||
// need for inter-thread synchronization.
|
||||
retire_cids_of(q1_copy);
|
||||
retire_cids_of(q2_copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A helper function used to notify that the correlation IDs of @p q
|
||||
* are ready to be retired by decrementing their ref_counters.
|
||||
* Furthermore, this function notifies the PC sampling parser that
|
||||
* kernels matching these CIDs are completed and can be removed from parser's
|
||||
* internal maps.
|
||||
*/
|
||||
void
|
||||
PCSCIDManager::retire_cids_of(std::vector<context::correlation_id*>& q)
|
||||
{
|
||||
// This function does not change the local state of the manager,
|
||||
// so it does not need synchronization.
|
||||
for(auto* cid : q)
|
||||
{
|
||||
// Notify the parser that the kernel has completed.
|
||||
pcs_parser->completeDispatch(cid->internal);
|
||||
// Decrement the ref_counter. Eventually, the CID is retired.
|
||||
cid->sub_ref_count();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,119 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/rocprofiler-sdk/context/correlation_id.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
/**
|
||||
* @brief A class that encapsulates the logic for marking the correlation IDs retired
|
||||
* by PC sampling service.
|
||||
*
|
||||
* To reduce the overhead, SDK's PC sampling service tries to avoid flushing the ROCr's buffer
|
||||
* explicitly. Instead, it waits for the ROCr to deliver the PC samples once the buffer's watermark
|
||||
* is crossed.
|
||||
*
|
||||
* There are some subtleties we need to consider when implementing the PC sampling service.
|
||||
* Currently, the 2nd level trap handler uses the double-buffering scheme, meaning the following
|
||||
* scenario can occur. Assume that one of the buffers (referred to as A) is full and is reported to
|
||||
* the PC sampling service via `data_ready_callback`. In the meantime, the 2nd level trap handler is
|
||||
* filling the buffer B with samples of currently active kernel K that is about to finish. Let's
|
||||
* mark the thread executing the `data_ready_callback` as TA. Before TA accesses the information
|
||||
* about all completed correlation IDs, it might be intercepted by another thread TB that receives
|
||||
* the kernel completion callback for the kernel K. While executing this callback, the thread TB
|
||||
* marks the K's correlation ID as completed. After TB finishes executing the callback, the TA
|
||||
* continues executing the `data_ready_callback` and observes that the K's CID has been marked as
|
||||
* completed. The TA drains the buffer A and decrements ref counts of all completed CIDs including
|
||||
* K's CID. If the count reaches zero, then the K's CID might be reported as retired. However, the
|
||||
* buffer B might still contain samples generated by the kernel K. To be sure that PC sampling
|
||||
* service drains all samples generated by the kernel K, we require one of the following
|
||||
* two scenarios to happen:
|
||||
*
|
||||
* 1. two implicit buffer flushes happened after the kernel of the correlation ID has completed,
|
||||
* 2. one explicit buffer flush initiated via `hsa_ven_amd_pcs_flush` happened after the kernel
|
||||
* of the correlation ID has completed. The reason why only one explicit flush is enough is because
|
||||
* the `hsa_ven_amd_pcs_flush` guarantees that all samples generated prior to (sequenced-before) the
|
||||
* call to the `hsa_ven_amd_pcs_flush` will be delivered.
|
||||
*
|
||||
* This way, we can guarantee that all samples are
|
||||
* drained from both buffers filled by 2nd level trap handler.
|
||||
*
|
||||
* To know if all samples produced by a kernel are drained from the ROCr's and 2nd level trap
|
||||
* handler's buffers and placed in the SDK's buffer, the PC sampling service employs the CID
|
||||
* retirement protocol implemented in the PCSCIDManager class. Refer to the comments of the
|
||||
* PCSCIDManager's attributes and methods for more details about the CID retirement protocol.
|
||||
*
|
||||
* PCSCIDManager is a singleton per PCSAgentSession.
|
||||
*/
|
||||
class PCSCIDManager
|
||||
{
|
||||
/// A lock that must be hold while updating the state of PCSCIDManager.
|
||||
std::mutex m;
|
||||
/// Correlation IDs with the following property: no ROCr's buffer flush happened
|
||||
/// since a corresponding kernel completed
|
||||
std::vector<context::correlation_id*> q1;
|
||||
/// Correlation IDs with the following property: exactly one ROCr's buffer flush occured
|
||||
/// since a corresponding kernel completed
|
||||
std::vector<context::correlation_id*> q2;
|
||||
/// A pointer to the PC sampling parser to be notified when the CID is retired.
|
||||
PCSamplingParserContext* pcs_parser = nullptr;
|
||||
|
||||
/// Prepare the CIDs of q to be retired. Refer to the implementation for more information.
|
||||
void retire_cids_of(std::vector<context::correlation_id*>& q);
|
||||
|
||||
public:
|
||||
PCSCIDManager(PCSamplingParserContext* parser)
|
||||
: pcs_parser(parser)
|
||||
{}
|
||||
|
||||
/// Called by the `kernel_completion_callback` to mark the kernel matching @p cid completed.
|
||||
void cid_async_activity_completed(context::correlation_id* cid);
|
||||
|
||||
/// a callback function for copying PC samples from ROCr's buffer to the SDK's buffer
|
||||
using pc_samples_copy_fn_t = std::function<void(void)>;
|
||||
|
||||
/// Called by the @p data_ready_callback.
|
||||
/// Encapsulates the logic for verifying that two implicit ROCr's buffer flushes
|
||||
/// happened after a kernel of the CID is marked completed (scenario 1 from above),
|
||||
/// before retiring that CID.
|
||||
/// @p manage_cids_implicit calls @p pc_samples_copy_fn to copy samples from
|
||||
/// ROCr's buffer to the SDK's buffer.
|
||||
void manage_cids_implicit(const pc_samples_copy_fn_t& pc_samples_copy_fn);
|
||||
|
||||
/// Called by the PC sampling service prior to initiating an explicit ROCr's buffer flush.
|
||||
/// The explicit flush is initiated by the @p pc_samples_explicit_flush_fn` callback.
|
||||
/// @p manage_cids_explicit` retires all CIDs whose corresponding kernels completed
|
||||
/// (sequenced) before the call to the @p manage_cids_explicit (scenario 2 from above).
|
||||
void manage_cids_explicit(const pc_samples_copy_fn_t& pc_samples_explicit_flush_fn);
|
||||
};
|
||||
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,190 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2024 ROCm Developer Tools
|
||||
//
|
||||
// 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/pc_sampling/code_object.hpp"
|
||||
|
||||
#include "lib/common/container/operators.hpp"
|
||||
#include "lib/common/logging.hpp"
|
||||
#include "lib/rocprofiler-sdk/code_object/code_object.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
#include <rocprofiler-sdk/cxx/operators.hpp>
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <hsa/hsa.h>
|
||||
#include <hsa/hsa_api_trace.h>
|
||||
#include <hsa/hsa_ven_amd_loader.h>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace code_object
|
||||
{
|
||||
namespace
|
||||
{
|
||||
auto&
|
||||
get_freeze_function()
|
||||
{
|
||||
static decltype(::hsa_executable_freeze)* _v = nullptr;
|
||||
return _v;
|
||||
}
|
||||
|
||||
auto&
|
||||
get_destroy_function()
|
||||
{
|
||||
static decltype(::hsa_executable_destroy)* _v = nullptr;
|
||||
return _v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flush internal PC sampling buffers and generate a marker record
|
||||
* for the code object load/unload event.
|
||||
*
|
||||
* By using the @p code_object, the function finds the corresponding agent.
|
||||
* Then, it drains internal (ROCr + 2nd level trap) buffers of this agent
|
||||
* and places all samples in the SDK PC sampling buffer.
|
||||
* Finally, it places the marker record representing code object load/unload event
|
||||
* in the SDK PC sampling buffer.
|
||||
*
|
||||
* @param [in] phase - loading/unloading phase
|
||||
* @param [in] code_object - loaded/unloaded code object.
|
||||
*/
|
||||
void
|
||||
flush_buffers_generate_marker_record(rocprofiler_callback_phase_t phase,
|
||||
const rocprofiler::code_object::hsa::code_object& code_object)
|
||||
{
|
||||
auto agent_id = code_object.rocp_data.rocp_agent;
|
||||
if(!is_pc_sample_service_configured(agent_id)) return;
|
||||
|
||||
// The PC sampling service is configured on the agent.
|
||||
// Find the agent's buffer and place marker record.
|
||||
// TODO: Creating a function that gives the buffer_id based on the agent_id?
|
||||
const auto* pcs_service = get_configured_pc_sampling_service().load();
|
||||
const auto* agent_session = pcs_service->agent_sessions.at(agent_id).get();
|
||||
auto agent_buffer_id = agent_session->buffer_id;
|
||||
|
||||
// flush internal PC sampling buffers
|
||||
flush_internal_agent_buffers(agent_buffer_id);
|
||||
|
||||
auto* buff = rocprofiler::buffer::get_buffer(agent_buffer_id);
|
||||
|
||||
// create code object load/unload marker record and emplace it into the SDK's PC SAMPLING
|
||||
// buffer.
|
||||
if(phase == ROCPROFILER_CALLBACK_PHASE_LOAD)
|
||||
{
|
||||
auto marker =
|
||||
common::init_public_api_struct(rocprofiler_pc_sampling_code_object_load_marker_t{});
|
||||
marker.code_object_id = code_object.rocp_data.code_object_id;
|
||||
// emplace marker to the SDK's PC sampling buffer
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING,
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_CODE_OBJECT_LOAD_MARKER,
|
||||
marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto marker =
|
||||
common::init_public_api_struct(rocprofiler_pc_sampling_code_object_unload_marker_t{});
|
||||
marker.code_object_id = code_object.rocp_data.code_object_id;
|
||||
// emplace marker to the SDK's PC sampling buffer
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING,
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_CODE_OBJECT_UNLOAD_MARKER,
|
||||
marker);
|
||||
}
|
||||
|
||||
// Assuming that the `rocprofiler_pc_sampling_code_object_load_marker_t` and
|
||||
// `rocprofiler_pc_sampling_code_object_unload_marker_t` share the same content,
|
||||
// we could replace the previous if else with the following
|
||||
/*
|
||||
auto marker =
|
||||
common::init_public_api_struct(rocprofiler_pc_sampling_code_object_load_marker_t{});
|
||||
marker.code_object_id = code_object.rocp_data.code_object_id;
|
||||
// emplace marker to the SDK's PC sampling buffer
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING,
|
||||
(phase == ROCPROFILER_CALLBACK_PHASE_LOAD) ?
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_CODE_OBJECT_LOAD_MARKER
|
||||
: ROCPROFILER_PC_SAMPLING_RECORD_CODE_OBJECT_UNLOAD_MARKER,
|
||||
marker);
|
||||
*/
|
||||
}
|
||||
|
||||
hsa_status_t
|
||||
executable_freeze(hsa_executable_t executable, const char* options)
|
||||
{
|
||||
// Call underlying function
|
||||
hsa_status_t status = CHECK_NOTNULL(get_freeze_function())(executable, options);
|
||||
if(status != HSA_STATUS_SUCCESS) return status;
|
||||
|
||||
rocprofiler::code_object::iterate_loaded_code_objects(
|
||||
[&](const rocprofiler::code_object::hsa::code_object& code_object) {
|
||||
if(code_object.hsa_executable == executable)
|
||||
flush_buffers_generate_marker_record(ROCPROFILER_CALLBACK_PHASE_LOAD, code_object);
|
||||
});
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t
|
||||
executable_destroy(hsa_executable_t executable)
|
||||
{
|
||||
rocprofiler::code_object::iterate_loaded_code_objects(
|
||||
[&](const rocprofiler::code_object::hsa::code_object& code_object) {
|
||||
if(code_object.hsa_executable == executable)
|
||||
flush_buffers_generate_marker_record(ROCPROFILER_CALLBACK_PHASE_UNLOAD,
|
||||
code_object);
|
||||
});
|
||||
|
||||
// Call underlying function
|
||||
return CHECK_NOTNULL(get_destroy_function())(executable);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void
|
||||
initialize(HsaApiTable* table)
|
||||
{
|
||||
(void) table;
|
||||
auto& core_table = *table->core_;
|
||||
|
||||
get_freeze_function() = CHECK_NOTNULL(core_table.hsa_executable_freeze_fn);
|
||||
get_destroy_function() = CHECK_NOTNULL(core_table.hsa_executable_destroy_fn);
|
||||
core_table.hsa_executable_freeze_fn = executable_freeze;
|
||||
core_table.hsa_executable_destroy_fn = executable_destroy;
|
||||
LOG_IF(FATAL, get_freeze_function() == core_table.hsa_executable_freeze_fn)
|
||||
<< "infinite recursion";
|
||||
LOG_IF(FATAL, get_destroy_function() == core_table.hsa_executable_destroy_fn)
|
||||
<< "infinite recursion";
|
||||
}
|
||||
|
||||
void
|
||||
finalize()
|
||||
{
|
||||
rocprofiler::code_object::iterate_loaded_code_objects(
|
||||
[&](const rocprofiler::code_object::hsa::code_object& code_object) {
|
||||
flush_buffers_generate_marker_record(ROCPROFILER_CALLBACK_PHASE_UNLOAD, code_object);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace code_object
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,40 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2024 ROCm Developer Tools
|
||||
//
|
||||
// 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 <hsa/hsa_api_trace.h>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace code_object
|
||||
{
|
||||
void
|
||||
initialize(HsaApiTable* table);
|
||||
|
||||
void
|
||||
finalize();
|
||||
} // namespace code_object
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,378 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/pc_sampling/hsa_adapter.hpp"
|
||||
|
||||
#include "lib/common/logging.hpp"
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
|
||||
|
||||
#include <hsa/hsa.h>
|
||||
#include <hsa/hsa_ext_amd.h>
|
||||
#include <hsa/hsa_ven_amd_pc_sampling.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace hsa
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const PCSAgentSession*
|
||||
get_pcs_session_of(hsa_agent_t hsa_agent)
|
||||
{
|
||||
// TODO: optimize this
|
||||
auto* service = get_configured_pc_sampling_service().load();
|
||||
for(const auto& [_, agent_session] : service->agent_sessions)
|
||||
{
|
||||
if(agent_session->hsa_agent->handle == hsa_agent.handle)
|
||||
{
|
||||
return agent_session.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Called just before the dispatch packet is put inside the real hardware queue.
|
||||
void
|
||||
amd_intercept_marker_handler_callback(const struct amd_aql_intercept_marker_s* packet,
|
||||
hsa_queue_t* queue,
|
||||
uint64_t packet_id)
|
||||
{
|
||||
auto* ext_table_ = rocprofiler::hsa::get_table().amd_ext_;
|
||||
hsa_agent_t hsa_agent;
|
||||
if(ext_table_->hsa_amd_queue_get_info_fn(queue, HSA_AMD_QUEUE_INFO_AGENT, &hsa_agent) !=
|
||||
HSA_STATUS_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Cannot map hsa_queue_t* to hsa_agent_t");
|
||||
}
|
||||
|
||||
uint64_t doorbell_id = 0;
|
||||
if(ext_table_->hsa_amd_queue_get_info_fn(queue, HSA_AMD_QUEUE_INFO_DOORBELL_ID, &doorbell_id) !=
|
||||
HSA_STATUS_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Cannot map hsa_queue_t* to doorbell_id");
|
||||
}
|
||||
|
||||
auto internal_correlation = packet->user_data[0];
|
||||
auto external_correlation = rocprofiler_user_data_t{.value = packet->user_data[1]};
|
||||
|
||||
auto const* pcs_session = get_pcs_session_of(hsa_agent);
|
||||
assert(pcs_session);
|
||||
|
||||
dispatch_pkt_id_t dispatch_pkt;
|
||||
dispatch_pkt.type = (pcs_session->method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
? AMD_HOST_TRAP_V1
|
||||
: AMD_SNAPSHOT_V1;
|
||||
// Use rocp_agent handle to uniquely identify the GPU device
|
||||
dispatch_pkt.device = device_handle{static_cast<uint32_t>(pcs_session->agent->id.handle)};
|
||||
dispatch_pkt.doorbell_id = doorbell_id;
|
||||
dispatch_pkt.queue_size = queue->size;
|
||||
dispatch_pkt.write_index = packet_id;
|
||||
dispatch_pkt.correlation_id = {.internal = internal_correlation,
|
||||
.external = external_correlation};
|
||||
|
||||
auto* parser = pcs_session->parser.get();
|
||||
if(parser->shouldFlipRocrBuffer(dispatch_pkt))
|
||||
{
|
||||
rocprofiler::hsa::get_table().pc_sampling_ext_->hsa_ven_amd_pcs_flush_fn(
|
||||
pcs_session->hsa_pc_sampling);
|
||||
}
|
||||
|
||||
parser->newDispatch(dispatch_pkt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called by HSA interceptor when the kernel has completed.
|
||||
*/
|
||||
void
|
||||
kernel_completion_cb(const rocprofiler_agent_t* rocp_agent,
|
||||
rocprofiler::hsa::rocprofiler_packet& /*kernel_pkt*/,
|
||||
const rocprofiler::hsa::Queue::queue_info_session_t& session)
|
||||
{
|
||||
// No internal correlation IDs, meaning there is no need to call CID manager.
|
||||
if(!session.correlation_id) return;
|
||||
|
||||
// Check if the PC sampling service is configured on this agent.
|
||||
if(!is_pc_sample_service_configured(rocp_agent->id)) return;
|
||||
|
||||
auto* service = get_configured_pc_sampling_service().load();
|
||||
assert(service);
|
||||
auto* agent_session = service->agent_sessions.at(rocp_agent->id).get();
|
||||
// Mark the correlation ID as completed
|
||||
agent_session->cid_manager->cid_async_activity_completed(session.correlation_id);
|
||||
}
|
||||
|
||||
void
|
||||
data_ready_callback(void* client_callback_data,
|
||||
size_t data_size,
|
||||
size_t lost_sample_count,
|
||||
hsa_ven_amd_pcs_data_copy_callback_t data_copy_callback,
|
||||
void* hsa_callback_data)
|
||||
{
|
||||
(void) lost_sample_count; // TODO: How is this exposed to the tool?
|
||||
|
||||
auto* agent_session = static_cast<pc_sampling::PCSAgentSession*>(client_callback_data);
|
||||
|
||||
// Wrap around the logic for copying PC samples from ROCr's buffer to the SDK's
|
||||
// PC sampling buffer inside the lambda function called by the CID manager,
|
||||
// a component responsible for managing the PC sampling related part of the
|
||||
// process of retiring correlation IDs.
|
||||
agent_session->cid_manager->manage_cids_implicit([&]() {
|
||||
size_t samples_num = data_size / sizeof(packet_union_t);
|
||||
// allocate a temporary buffer for copying PC samples
|
||||
// TODO: think about how to optimize this (e.g., introduce a buffer pool)
|
||||
auto buff = std::make_unique<packet_union_t[]>(samples_num);
|
||||
|
||||
// copy all the data
|
||||
data_copy_callback(hsa_callback_data, data_size, buff.get());
|
||||
|
||||
upcoming_samples_t upc;
|
||||
// rocp_agent handle uniquely identifies the device
|
||||
upc.device = device_handle{static_cast<uint32_t>(agent_session->agent->id.handle)};
|
||||
upc.which_sample_type = (agent_session->method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
? AMD_HOST_TRAP_V1
|
||||
: AMD_SNAPSHOT_V1;
|
||||
upc.num_samples = samples_num;
|
||||
|
||||
// TODO: how about using std::future
|
||||
std::condition_variable cv;
|
||||
|
||||
auto gfx_major = ((agent_session->agent->gfx_target_version / 10000) % 100);
|
||||
auto pcs_parser_status = agent_session->parser->parse(
|
||||
upc, reinterpret_cast<const generic_sample_t*>(buff.get()), gfx_major, cv, false);
|
||||
|
||||
if(pcs_parser_status != PCSAMPLE_STATUS_SUCCESS)
|
||||
{
|
||||
// TODO: should we end program here or somehow report an error to the user and continue?
|
||||
throw std::runtime_error("Error while parsing PC samples");
|
||||
}
|
||||
});
|
||||
}
|
||||
} // namespace
|
||||
|
||||
rocprofiler::hsa::rocprofiler_packet
|
||||
generate_marker_packet_for_kernel(
|
||||
context::correlation_id* correlation_id,
|
||||
const tracing::external_correlation_id_map_t& external_correlation_ids)
|
||||
{
|
||||
// This function executes for each kernel dispatched to the agent on which
|
||||
// the PC sampling service is configured.
|
||||
// By doing this, we allow the following scenario to happen:
|
||||
// A tool configures PC sampling on an agent and offloads some kernels on that agent.
|
||||
// In the middle of the kernel execution, a tool starts/activates PC sampling service
|
||||
// to collect samples. Although the PC sampling service was not started/activated
|
||||
// at the moment of dispatching kernels, the configured PC sampling service is aware of all
|
||||
// kernels dispatched on the agent and can recreate their correlation IDs.
|
||||
// The disadvantage of this approach is that it introduces overhead when PC sampling
|
||||
// service is inactive/stopped.
|
||||
amd_aql_intercept_marker_t marker_pkt;
|
||||
marker_pkt.header = HSA_PACKET_TYPE_VENDOR_SPECIFIC;
|
||||
marker_pkt.format = AMD_AQL_FORMAT_INTERCEPT_MARKER;
|
||||
marker_pkt.callback = amd_intercept_marker_handler_callback;
|
||||
|
||||
if(correlation_id != nullptr)
|
||||
{
|
||||
correlation_id->add_ref_count();
|
||||
// Use the internal correlation ID generated by the tracing service.
|
||||
marker_pkt.user_data[0] = correlation_id->internal;
|
||||
|
||||
// Find a context that holds PC sampling service.
|
||||
auto contexts = context::get_registered_contexts(
|
||||
[](const auto* ctx) { return ctx->pc_sampler != nullptr; });
|
||||
assert(contexts.size() == 1);
|
||||
const auto* pcs_context = contexts.at(0);
|
||||
|
||||
// Get an external correlation that corresponds to the context
|
||||
// enclosing PC sampling service.
|
||||
auto external_corr = tracing::empty_user_data;
|
||||
auto external_corr_it = external_correlation_ids.find(pcs_context);
|
||||
if(external_corr_it != external_correlation_ids.end())
|
||||
external_corr = external_corr_it->second;
|
||||
marker_pkt.user_data[1] = external_corr.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
marker_pkt.user_data[0] = 0;
|
||||
// No external correlation ID
|
||||
marker_pkt.user_data[1] = 0;
|
||||
}
|
||||
|
||||
return rocprofiler::hsa::rocprofiler_packet(marker_pkt);
|
||||
}
|
||||
|
||||
void
|
||||
pc_sampling_service_start(context::pc_sampling_service* service)
|
||||
{
|
||||
auto* pc_sampling_table_ = rocprofiler::hsa::get_table().pc_sampling_ext_;
|
||||
for(const auto& [_, agent_session] : service->agent_sessions)
|
||||
{
|
||||
// If the agent has been hidden by the ROCR_VISIBLE_DEVICES, no need to start PC sampling.
|
||||
// Please check `pc_sampling_service_finish_configuration` for more information.
|
||||
if(!agent_session->hsa_agent.has_value()) continue;
|
||||
|
||||
if(pc_sampling_table_->hsa_ven_amd_pcs_start_fn(agent_session->hsa_pc_sampling) !=
|
||||
HSA_STATUS_SUCCESS)
|
||||
{
|
||||
// Two concurrent calls to the pc_sampling::start_service are invoked on the same
|
||||
// service. The "faster" one succeeds and starts the PC sampling service on the HSA
|
||||
// level. Although the "slower fails", the service is started.
|
||||
ROCP_ERROR << "HSA runtime failed to start PC sampling on the agent "
|
||||
<< agent_session->agent->id.handle << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pc_sampling_service_stop(context::pc_sampling_service* service)
|
||||
{
|
||||
auto* pc_sampling_table_ = rocprofiler::hsa::get_table().pc_sampling_ext_;
|
||||
for(const auto& [_, agent_session] : service->agent_sessions)
|
||||
{
|
||||
// If the agent has been hidden by the ROCR_VISIBLE_DEVICES, no need to stop PC sampling.
|
||||
// Please check `pc_sampling_service_finish_configuration` for more information.
|
||||
if(!agent_session->hsa_agent.has_value()) continue;
|
||||
|
||||
if(pc_sampling_table_->hsa_ven_amd_pcs_stop_fn(agent_session->hsa_pc_sampling) !=
|
||||
HSA_STATUS_SUCCESS)
|
||||
{
|
||||
// Two concurrent calls to the pc_sampling::stop_serivce are invoked on the same
|
||||
// service. The "faster" one succeeds and stops the PC sampling service on the HSA
|
||||
// level. Although the "slower fails", the service is stopped. The "slower" continues,
|
||||
// while the "faster" tries flushing the ROCr's buffer below.
|
||||
ROCP_ERROR << "HSA runtime failed to stop PC sampling on the agent "
|
||||
<< agent_session->agent->id.handle << "\n";
|
||||
continue;
|
||||
};
|
||||
|
||||
// Flush internal PC sampling buffers (ROCr + 2nd level trap handler buffers)
|
||||
flush_internal_agent_buffers(agent_session.get());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pc_sampling_service_finish_configuration(context::pc_sampling_service* service)
|
||||
{
|
||||
// This function is executed once by a single thread.
|
||||
// No synchronization needed.
|
||||
auto* pc_sampling_table_ = rocprofiler::hsa::get_table().pc_sampling_ext_;
|
||||
|
||||
for(const auto& [_, agent_session] : service->agent_sessions)
|
||||
{
|
||||
// Get the HSA agent handle
|
||||
agent_session->hsa_agent = rocprofiler::agent::get_hsa_agent(agent_session->agent);
|
||||
|
||||
// Check if HSA agent corresponding to the KFD node id is hidden via ROCR_VISIBLE_DEVICES,
|
||||
// If so, we cannot finish the configuration on the ROCr level.
|
||||
// Consequently, no PC samples will be delivered for this device.
|
||||
if(!agent_session->hsa_agent.has_value()) continue;
|
||||
|
||||
// Create PC sampling session on the ROCr level.
|
||||
// ROCr reuses IOCTL session with `agent_session->ioctl_pcs_id`.
|
||||
hsa_status_t status = pc_sampling_table_->hsa_ven_amd_pcs_create_from_id_fn(
|
||||
agent_session->ioctl_pcs_id,
|
||||
agent_session->hsa_agent.value(),
|
||||
pc_sampling::utils::get_matching_hsa_pcs_method(agent_session->method),
|
||||
pc_sampling::utils::get_matching_hsa_pcs_units(agent_session->unit),
|
||||
agent_session->interval,
|
||||
pc_sampling::utils::get_hsa_pcs_latency(),
|
||||
pc_sampling::utils::get_hsa_pcs_buffer_size(),
|
||||
data_ready_callback,
|
||||
agent_session.get(),
|
||||
&agent_session->hsa_pc_sampling);
|
||||
|
||||
if(status != HSA_STATUS_SUCCESS)
|
||||
{
|
||||
ROCP_ERROR << "HSA runtime failed to finish configuring PC sampling service"
|
||||
<< " on the agent with id: " << agent_session->agent->id.handle << "\n";
|
||||
std::runtime_error("PC sampling config on the HSA/ROCr level failed");
|
||||
}
|
||||
|
||||
// TODO: any better way of informing the parser about what buffer is used for a
|
||||
// specific agent?
|
||||
if(!agent_session->parser->register_buffer_for_agent(agent_session->buffer_id,
|
||||
agent_session->agent->id))
|
||||
{
|
||||
std::runtime_error("PCS parser does not accept buffer");
|
||||
}
|
||||
}
|
||||
|
||||
// Register callbacks for the HSA's queue interceptor.
|
||||
// TODO: should we store callback ID in the service?
|
||||
rocprofiler::hsa::get_queue_controller()->add_callback(
|
||||
std::nullopt,
|
||||
[](const rocprofiler::hsa::Queue&,
|
||||
const rocprofiler::hsa::rocprofiler_packet&,
|
||||
rocprofiler_kernel_id_t /*kernel_id*/,
|
||||
rocprofiler_dispatch_id_t /*dispatch_id*/,
|
||||
rocprofiler_user_data_t*,
|
||||
const rocprofiler::hsa::Queue::queue_info_session_t::external_corr_id_map_t&,
|
||||
const context::correlation_id*) { return nullptr; },
|
||||
// Completion CB
|
||||
[](const rocprofiler::hsa::Queue& q,
|
||||
rocprofiler::hsa::rocprofiler_packet kern_pkt,
|
||||
const rocprofiler::hsa::Queue::queue_info_session_t& session,
|
||||
rocprofiler::hsa::inst_pkt_t&) {
|
||||
kernel_completion_cb(q.get_agent().get_rocp_agent(), kern_pkt, session);
|
||||
});
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
flush_internal_agent_buffers(const PCSAgentSession* agent_session)
|
||||
{
|
||||
// If the agent has been hidden by the ROCR_VISIBLE_DEVICES,
|
||||
// there is no ROCr internal buffers to flush.
|
||||
if(!agent_session->hsa_agent.has_value()) return ROCPROFILER_STATUS_SUCCESS;
|
||||
|
||||
auto* pc_sampling_table_ = rocprofiler::hsa::get_table().pc_sampling_ext_;
|
||||
|
||||
// HSA table has not been loaded, so ROCr buffers does not exist yet.
|
||||
if(!pc_sampling_table_->hsa_ven_amd_pcs_flush_fn)
|
||||
return ROCPROFILER_STATUS_ERROR_HSA_NOT_LOADED;
|
||||
|
||||
auto hsa_pcs_handle = agent_session->hsa_pc_sampling;
|
||||
// Explicitly flush ROCr's buffers and sync completed CIDs.
|
||||
agent_session->cid_manager->manage_cids_explicit([=]() {
|
||||
// TODO: investigate whether the ROCr should maintain an extra buffer
|
||||
// beyond the 2nd level trap handler buffers.
|
||||
if(pc_sampling_table_->hsa_ven_amd_pcs_flush_fn(hsa_pcs_handle) != HSA_STATUS_SUCCESS)
|
||||
{
|
||||
// TODO: Think if it is possible to recover from this error.
|
||||
std::runtime_error("Fail to flush ROCr's buffer explicitly");
|
||||
}
|
||||
});
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
} // namespace hsa
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,56 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/queue.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
|
||||
#include "lib/rocprofiler-sdk/tracing/fwd.hpp"
|
||||
|
||||
#include <hsa/hsa_api_trace.h>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace hsa
|
||||
{
|
||||
rocprofiler::hsa::rocprofiler_packet
|
||||
generate_marker_packet_for_kernel(
|
||||
context::correlation_id* correlation_id,
|
||||
const tracing::external_correlation_id_map_t& external_correlation_ids);
|
||||
|
||||
void
|
||||
pc_sampling_service_start(context::pc_sampling_service* service);
|
||||
|
||||
void
|
||||
pc_sampling_service_stop(context::pc_sampling_service* service);
|
||||
|
||||
void
|
||||
pc_sampling_service_finish_configuration(context::pc_sampling_service* service);
|
||||
|
||||
rocprofiler_status_t
|
||||
flush_internal_agent_buffers(const PCSAgentSession* agent_session);
|
||||
} // namespace hsa
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,6 @@
|
||||
set(ROCPROFILER_PC_SAMPLING_IOCTL_SOURCES ioctl_adapter.cpp)
|
||||
set(ROCPROFILER_PC_SAMPLING_IOCTL_HEADERS ioctl_adapter.hpp ioctl_adapter_types.hpp)
|
||||
|
||||
target_sources(
|
||||
rocprofiler-object-library PRIVATE ${ROCPROFILER_PC_SAMPLING_IOCTL_SOURCES}
|
||||
${ROCPROFILER_PC_SAMPLING_IOCTL_HEADERS})
|
||||
@@ -0,0 +1,383 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/pc_sampling/ioctl/ioctl_adapter.hpp"
|
||||
|
||||
#include "lib/rocprofiler-sdk/details/kfd_ioctl.h"
|
||||
|
||||
#include "lib/common/logging.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter_types.hpp"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace ioctl
|
||||
{
|
||||
// forward declaration
|
||||
rocprofiler_ioctl_version_info_t&
|
||||
get_ioctl_version();
|
||||
|
||||
// IOCTL 1.16 is the first one supporting PC sampling.
|
||||
#define CHECK_IOCTL_VERSION \
|
||||
do \
|
||||
{ \
|
||||
auto ioctl_version = get_ioctl_version(); \
|
||||
if(ioctl_version.major_version < 1 || ioctl_version.minor_version < 16) \
|
||||
{ \
|
||||
LOG(ERROR) << "PC sampling unavailable\n"; \
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
int
|
||||
kfd_open()
|
||||
{
|
||||
int fd = -1;
|
||||
static const char kfd_device_name[] = "/dev/kfd";
|
||||
|
||||
fd = open(kfd_device_name, O_RDWR | O_CLOEXEC);
|
||||
|
||||
if(fd == -1)
|
||||
{
|
||||
throw std::runtime_error("Cannot open /dev/kfd");
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
get_kfd_fd()
|
||||
{
|
||||
static auto _v = kfd_open();
|
||||
return _v;
|
||||
}
|
||||
|
||||
/** Call ioctl, restarting if it is interrupted
|
||||
* Taken from libhsakmt.c
|
||||
*/
|
||||
int
|
||||
ioctl(int fd, unsigned long request, void* arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do
|
||||
{
|
||||
ret = ::ioctl(fd, request, arg);
|
||||
} while(ret == -1 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
if(ret == -1 && errno == EBADF)
|
||||
{
|
||||
/* In case pthread_atfork didn't catch it, this will
|
||||
* make any subsequent hsaKmt calls fail in CHECK_KFD_OPEN.
|
||||
*/
|
||||
printf("Invalid KFD descriptor: %d\n", fd);
|
||||
}
|
||||
|
||||
return ret * errno;
|
||||
}
|
||||
|
||||
// More or less taken from the HsaKmt
|
||||
rocprofiler_ioctl_version_info_t
|
||||
query_ioctl_version(void)
|
||||
{
|
||||
rocprofiler_ioctl_version_info_t ioctl_version;
|
||||
ioctl_version.minor_version = 0;
|
||||
ioctl_version.major_version = 0;
|
||||
|
||||
// If querying the IOCTL version fails, return major_version/minor_version = 0;
|
||||
struct kfd_ioctl_get_version_args args = {.major_version = 0, .minor_version = 0};
|
||||
|
||||
if(ioctl(get_kfd_fd(), AMDKFD_IOC_GET_VERSION, &args) == 0)
|
||||
{
|
||||
ioctl_version.major_version = args.major_version;
|
||||
ioctl_version.minor_version = args.minor_version;
|
||||
}
|
||||
|
||||
return ioctl_version;
|
||||
}
|
||||
|
||||
rocprofiler_ioctl_version_info_t&
|
||||
get_ioctl_version()
|
||||
{
|
||||
static auto v = query_ioctl_version();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @kfd_gpu_id represents the gpu identifier read from the content of the
|
||||
* /sys/class/kfd/kfd/topology/nodes/<node-id>/gpu_id.
|
||||
*/
|
||||
ROCPROFILER_IOCTL_STATUS
|
||||
ioctl_query_pc_sampling_capabilities(uint32_t kfd_gpu_id,
|
||||
void* sample_info,
|
||||
uint32_t sample_info_sz,
|
||||
uint32_t* size)
|
||||
{
|
||||
int ret;
|
||||
struct kfd_ioctl_pc_sample_args args;
|
||||
|
||||
assert(sizeof(rocprofiler_ioctl_pc_sampling_info_t) == sizeof(struct kfd_pc_sample_info));
|
||||
|
||||
ret = ROCPROFILER_IOCTL_STATUS_SUCCESS;
|
||||
args.op = KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES;
|
||||
args.gpu_id = kfd_gpu_id;
|
||||
args.sample_info_ptr = (uint64_t) sample_info;
|
||||
args.num_sample_info = sample_info_sz;
|
||||
args.flags = 0;
|
||||
|
||||
ret = ioctl(get_kfd_fd(), AMDKFD_IOC_PC_SAMPLE, &args);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
if(ret == -EBUSY)
|
||||
{
|
||||
// Querying PC sampling capabilities is requsted from within the ROCgdb
|
||||
// which is not supported.
|
||||
return ROCPROFILER_IOCTL_STATUS_UNAVAILABLE;
|
||||
}
|
||||
ROCP_ERROR << "IOCTL failed to query PC sampling configs: " << ret << "\n";
|
||||
}
|
||||
*size = args.num_sample_info;
|
||||
|
||||
return (ret == -ENOSPC) ? ROCPROFILER_IOCTL_STATUS_BUFFER_TOO_SMALL
|
||||
: (ret != 0) ? ROCPROFILER_IOCTL_STATUS_ERROR
|
||||
: ROCPROFILER_IOCTL_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
convert_ioctl_pcs_config_to_rocp(const rocprofiler_ioctl_pc_sampling_info_t& ioctl_pcs_config,
|
||||
rocprofiler_pc_sampling_configuration_t& rocp_pcs_config)
|
||||
{
|
||||
// Sometimes, the KFD returns 0 for `method` and `units` as an error.
|
||||
// Note: the 0 is not of the matching enumeration.
|
||||
// Thus, the default case remains here to indicate that KFD edge case
|
||||
// and prevents failures inside rocprofiler.
|
||||
|
||||
switch(ioctl_pcs_config.method)
|
||||
{
|
||||
case ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_HOSTTRAP_V1:
|
||||
rocp_pcs_config.method = ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP;
|
||||
break;
|
||||
case ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_STOCHASTIC_V1:
|
||||
rocp_pcs_config.method = ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC;
|
||||
break;
|
||||
default:
|
||||
// Sampling method unsupported, return the error
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
switch(ioctl_pcs_config.units)
|
||||
{
|
||||
case ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_MICROSECONDS:
|
||||
rocp_pcs_config.unit = ROCPROFILER_PC_SAMPLING_UNIT_TIME;
|
||||
break;
|
||||
case ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_CYCLES:
|
||||
rocp_pcs_config.unit = ROCPROFILER_PC_SAMPLING_UNIT_CYCLES;
|
||||
break;
|
||||
case ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_INSTRUCTIONS:
|
||||
rocp_pcs_config.unit = ROCPROFILER_PC_SAMPLING_UNIT_INSTRUCTIONS;
|
||||
break;
|
||||
default:
|
||||
// Sampling unit unsupported, return error
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if(ioctl_pcs_config.interval != 0)
|
||||
{
|
||||
// The pc sampling is configured on the corresponding device.
|
||||
// The `interval` contains the value of the interval used for deliverying samples.
|
||||
// Values of `interval_min` and `interval_max` are irrelevant.
|
||||
rocp_pcs_config.min_interval = ioctl_pcs_config.interval;
|
||||
rocp_pcs_config.max_interval = ioctl_pcs_config.interval;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No one configured PC sampling on the corresponding device.
|
||||
// Read the values of min and max interval provided by the KFD
|
||||
rocp_pcs_config.min_interval = ioctl_pcs_config.interval_min;
|
||||
rocp_pcs_config.max_interval = ioctl_pcs_config.interval_max;
|
||||
}
|
||||
|
||||
rocp_pcs_config.flags = ioctl_pcs_config.flags;
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
ioctl_query_pcs_configs(const rocprofiler_agent_t* agent, rocp_pcs_cfgs_vec_t& rocp_configs)
|
||||
{
|
||||
// Assert the IOCTL version
|
||||
CHECK_IOCTL_VERSION;
|
||||
|
||||
uint32_t kfd_gpu_id = agent->gpu_id;
|
||||
|
||||
const size_t ioctl_configs_num = 10;
|
||||
uint32_t size = 0;
|
||||
|
||||
std::vector<rocprofiler_ioctl_pc_sampling_info_t> ioctl_configs(ioctl_configs_num);
|
||||
|
||||
auto ret = ioctl_query_pc_sampling_capabilities(
|
||||
kfd_gpu_id, ioctl_configs.data(), ioctl_configs.size(), &size);
|
||||
if(ret == ROCPROFILER_IOCTL_STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
ioctl_configs.resize(size);
|
||||
ret = ioctl_query_pc_sampling_capabilities(
|
||||
kfd_gpu_id, ioctl_configs.data(), ioctl_configs.size(), &size);
|
||||
}
|
||||
|
||||
if(ret == ROCPROFILER_IOCTL_STATUS_UNAVAILABLE)
|
||||
{
|
||||
// The PC sampling is accessed from within the ROCgdb which is not supported.
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
else if(ret != ROCPROFILER_IOCTL_STATUS_SUCCESS)
|
||||
{
|
||||
ROCP_ERROR << "......... Failed while iterating over PC sampling configurations\n";
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
for(auto const& ioctl_cfg : ioctl_configs)
|
||||
{
|
||||
// FIXME: Why this happens?
|
||||
if(ioctl_cfg.method == 0) continue;
|
||||
auto rocp_cfg = common::init_public_api_struct(rocprofiler_pc_sampling_configuration_t{});
|
||||
auto rocp_ret = convert_ioctl_pcs_config_to_rocp(ioctl_cfg, rocp_cfg);
|
||||
if(rocp_ret != ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
// This should never happened, unless the KFD is broken.
|
||||
continue;
|
||||
}
|
||||
rocp_configs.emplace_back(rocp_cfg);
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
create_ioctl_pcs_config_from_rocp(rocprofiler_ioctl_pc_sampling_info_t& ioctl_cfg,
|
||||
rocprofiler_pc_sampling_method_t method,
|
||||
rocprofiler_pc_sampling_unit_t unit,
|
||||
uint64_t interval)
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
case ROCPROFILER_PC_SAMPLING_METHOD_NONE: return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
case ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC:
|
||||
ioctl_cfg.method = ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_STOCHASTIC_V1;
|
||||
break;
|
||||
case ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP:
|
||||
ioctl_cfg.method = ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_HOSTTRAP_V1;
|
||||
break;
|
||||
case ROCPROFILER_PC_SAMPLING_METHOD_LAST: return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
switch(unit)
|
||||
{
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_NONE: return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_INSTRUCTIONS:
|
||||
ioctl_cfg.units = ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_INSTRUCTIONS;
|
||||
break;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_CYCLES:
|
||||
ioctl_cfg.units = ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_CYCLES;
|
||||
break;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_TIME:
|
||||
ioctl_cfg.units = ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_MICROSECONDS;
|
||||
break;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_LAST: return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
ioctl_cfg.interval = interval;
|
||||
// TODO: Is it possible to use flags for interval values that are power of 2
|
||||
// when specifying stochastic on MI300?
|
||||
ioctl_cfg.flags = 0;
|
||||
ioctl_cfg.interval_min = 0;
|
||||
ioctl_cfg.interval_max = 0;
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reserve PC sampling service on the device
|
||||
* @param[out] ioctl_pcs_id - If the return value is ROCPROFILER_STATUS_SUCCESS,
|
||||
* contains the id that uniquely identifies PC sampling session within IOCTL.
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
ioctl_pcs_create(const rocprofiler_agent_t* agent,
|
||||
rocprofiler_pc_sampling_method_t method,
|
||||
rocprofiler_pc_sampling_unit_t unit,
|
||||
uint64_t interval,
|
||||
uint32_t* ioctl_pcs_id)
|
||||
{
|
||||
// Assert the IOCTL version
|
||||
CHECK_IOCTL_VERSION;
|
||||
|
||||
rocprofiler_ioctl_pc_sampling_info_t ioctl_cfg;
|
||||
auto ret = create_ioctl_pcs_config_from_rocp(ioctl_cfg, method, unit, interval);
|
||||
if(ret != ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct kfd_ioctl_pc_sample_args args;
|
||||
|
||||
if(!ioctl_pcs_id) return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
*ioctl_pcs_id = INVALID_TRACE_ID;
|
||||
|
||||
args.op = KFD_IOCTL_PCS_OP_CREATE;
|
||||
args.gpu_id = agent->gpu_id;
|
||||
args.sample_info_ptr = (uint64_t)(&ioctl_cfg);
|
||||
args.num_sample_info = 1;
|
||||
args.trace_id = INVALID_TRACE_ID;
|
||||
|
||||
auto ioctl_ret = ioctl(get_kfd_fd(), AMDKFD_IOC_PC_SAMPLE, &args);
|
||||
*ioctl_pcs_id = args.trace_id;
|
||||
|
||||
if(ioctl_ret != 0 && (errno == EBUSY || errno == EEXIST))
|
||||
{
|
||||
// Currently, KFD uses EBUSY when e.g., PC sampling create is requested from
|
||||
// withing the ROCgdb.
|
||||
// On the other hand, EEXIST is used when one tries to create a PC sampling
|
||||
// with a configuration different than the one already active.
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
else if(ioctl_ret != 0)
|
||||
{
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace ioctl
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,50 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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 <rocprofiler-sdk/fwd.h>
|
||||
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace ioctl
|
||||
{
|
||||
using rocp_pcs_cfgs_vec_t = std::vector<rocprofiler_pc_sampling_configuration_t>;
|
||||
|
||||
rocprofiler_status_t
|
||||
ioctl_query_pcs_configs(const rocprofiler_agent_t* agent, rocp_pcs_cfgs_vec_t& rocp_configs);
|
||||
|
||||
rocprofiler_status_t
|
||||
ioctl_pcs_create(const rocprofiler_agent_t* agent,
|
||||
rocprofiler_pc_sampling_method_t method,
|
||||
rocprofiler_pc_sampling_unit_t unit,
|
||||
uint64_t interval,
|
||||
uint32_t* ioctl_pcs_id);
|
||||
|
||||
} // namespace ioctl
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,108 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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 <rocprofiler-sdk/fwd.h>
|
||||
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace ioctl
|
||||
{
|
||||
#define INVALID_TRACE_ID 0x0
|
||||
|
||||
// The data structure copied from the HsaKmt
|
||||
// Currently, we are using the following status codes:
|
||||
// 1. ROCPROFILER_IOCTL_STATUS_SUCCESS
|
||||
// 2. ROCPROFILER_IOCTL_STATUS_ERROR
|
||||
// 3. ROCPROFILER_IOCTL_STATUS_BUFFER_TOO_SMALL
|
||||
// 4. ROCPROFILER_IOCTL_STATUS_UNAVAILABLE
|
||||
// We might replace 1, 2, and 4 with rocprofiler_status_t, but still lacking a counterpart
|
||||
// for the ROCPROFILER_IOCTL_STATUS_BUFFER_TOO_SMALL
|
||||
typedef enum _ROCPROFILER_IOCTL_STATUS
|
||||
{
|
||||
ROCPROFILER_IOCTL_STATUS_SUCCESS = 0, /// Operation successful // USED
|
||||
ROCPROFILER_IOCTL_STATUS_ERROR = 1, /// General error return if not otherwise specified // USED
|
||||
ROCPROFILER_IOCTL_STATUS_DRIVER_MISMATCH =
|
||||
2, /// User mode component is not compatible with kernel HSA driver
|
||||
ROCPROFILER_IOCTL_STATUS_INVALID_NODE_UNIT =
|
||||
5, /// KFD identifies node or unit parameter invalid
|
||||
ROCPROFILER_IOCTL_STATUS_NO_MEMORY =
|
||||
6, /// No memory available (when allocating queues or memory)
|
||||
ROCPROFILER_IOCTL_STATUS_BUFFER_TOO_SMALL =
|
||||
7, /// A buffer needed to handle a request is too small //USED
|
||||
ROCPROFILER_IOCTL_STATUS_NOT_IMPLEMENTED =
|
||||
10, /// KFD function is not implemented for this set of paramters
|
||||
ROCPROFILER_IOCTL_STATUS_UNAVAILABLE = 12, /// KFD function is not available currently on this
|
||||
/// // USED node (but may be at a later time)
|
||||
ROCPROFILER_IOCTL_STATUS_OUT_OF_RESOURCES =
|
||||
13, /// KFD function request exceeds the resources currently available.
|
||||
ROCPROFILER_IOCTL_STATUS_KERNEL_COMMUNICATION_ERROR =
|
||||
21, /// user-kernel mode communication failure
|
||||
ROCPROFILER_IOCTL_STATUS_KERNEL_ALREADY_OPENED = 22, /// KFD driver path already opened
|
||||
ROCPROFILER_IOCTL_STATUS_HSAMMU_UNAVAILABLE =
|
||||
23, /// ATS/PRI 1.1 (Address Translation Services) not available
|
||||
/// (IOMMU driver not installed or not-available)
|
||||
ROCPROFILER_IOCTL_STATUS_WAIT_FAILURE = 30, /// The wait operation failed
|
||||
ROCPROFILER_IOCTL_STATUS_WAIT_TIMEOUT = 31, /// The wait operation timed out
|
||||
ROCPROFILER_IOCTL_STATUS_MEMORY_ALREADY_REGISTERED = 35, /// Memory buffer already registered
|
||||
ROCPROFILER_IOCTL_STATUS_MEMORY_NOT_REGISTERED = 36, /// Memory buffer not registered
|
||||
ROCPROFILER_IOCTL_STATUS_MEMORY_ALIGNMENT = 37, /// Memory parameter not aligned
|
||||
} ROCPROFILER_IOCTL_STATUS;
|
||||
|
||||
typedef struct rocprofiler_ioctl_version_info_s
|
||||
{
|
||||
uint32_t major_version; /// supported IOCTL interface major version
|
||||
uint32_t minor_version; /// supported IOCTL interface minor version
|
||||
} rocprofiler_ioctl_version_info_t;
|
||||
|
||||
typedef enum _ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND
|
||||
{
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_HOSTTRAP_V1 = 1,
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_STOCHASTIC_V1,
|
||||
} ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND;
|
||||
|
||||
typedef enum _ROCPROFILER_IOCTL_PC_SAMPLING_UNITS
|
||||
{
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_MICROSECONDS,
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_CYCLES,
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL_INSTRUCTIONS,
|
||||
} ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL;
|
||||
|
||||
typedef struct rocprofiler_ioctl_pc_sampling_info_s
|
||||
{
|
||||
uint64_t interval;
|
||||
uint64_t interval_min;
|
||||
uint64_t interval_max;
|
||||
uint64_t flags;
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND method;
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_UNIT_INTERVAL units;
|
||||
} rocprofiler_ioctl_pc_sampling_info_t;
|
||||
|
||||
} // namespace ioctl
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -184,17 +184,20 @@ add_upcoming_samples(const device_handle device,
|
||||
const generic_sample_t* buffer,
|
||||
const size_t available_samples,
|
||||
Parser::CorrelationMap* corr_map,
|
||||
rocprofiler_pc_sampling_record_s* samples)
|
||||
rocprofiler_pc_sampling_record_t* samples)
|
||||
{
|
||||
pcsample_status_t status = PCSAMPLE_STATUS_SUCCESS;
|
||||
for(uint64_t p = 0; p < available_samples; p++)
|
||||
{
|
||||
const auto* snap = reinterpret_cast<const perf_sample_snapshot_v1*>(buffer + p);
|
||||
samples[p] = copySample<bHostTrap, GFXIP>((const void*) (buffer + p));
|
||||
samples[p].size = 0; // pc sampling record with size 0 will indicate invalid sample
|
||||
try
|
||||
{
|
||||
Parser::trap_correlation_id_t trap{.raw = snap->correlation_id};
|
||||
samples[p].correlation_id = corr_map->get(device, trap);
|
||||
samples[p].size = sizeof(rocprofiler_pc_sampling_record_t);
|
||||
// set size after corr_map->get which may throw
|
||||
} catch(std::exception& e)
|
||||
{
|
||||
status = PCSAMPLE_STATUS_PARSER_ERROR;
|
||||
@@ -240,7 +243,7 @@ _parse_buffer(generic_sample_t* buffer,
|
||||
|
||||
while(pkt_counter > 0)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s* samples = nullptr;
|
||||
rocprofiler_pc_sampling_record_t* samples = nullptr;
|
||||
uint64_t available_samples = callback(&samples, pkt_counter, userdata);
|
||||
|
||||
if(available_samples == 0 || available_samples > pkt_counter)
|
||||
|
||||
@@ -87,7 +87,7 @@ union pcsample_header_v1_t
|
||||
uint8_t raw;
|
||||
};
|
||||
|
||||
typedef uint64_t (*user_callback_t)(rocprofiler_pc_sampling_record_s**, uint64_t, void*);
|
||||
typedef uint64_t (*user_callback_t)(rocprofiler_pc_sampling_record_t**, uint64_t, void*);
|
||||
|
||||
/**
|
||||
* The types of errors to be returned by parse_buffer.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
|
||||
uint64_t
|
||||
PCSamplingParserContext::alloc(rocprofiler_pc_sampling_record_s** buffer, uint64_t size)
|
||||
PCSamplingParserContext::alloc(rocprofiler_pc_sampling_record_t** buffer, uint64_t size)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mut);
|
||||
assert(buffer != nullptr);
|
||||
@@ -97,3 +97,21 @@ PCSamplingParserContext::shouldFlipRocrBuffer(const dispatch_pkt_id_t& pkt) cons
|
||||
std::shared_lock<std::shared_mutex> lock(mut);
|
||||
return corr_map->checkDispatch(pkt);
|
||||
}
|
||||
|
||||
void
|
||||
PCSamplingParserContext::generate_upcoming_pc_record(
|
||||
uint64_t agent_id_handle,
|
||||
const rocprofiler_pc_sampling_record_t* samples,
|
||||
size_t num_samples)
|
||||
{
|
||||
auto buff_id = _agent_buffers.at(rocprofiler_agent_id_t{agent_id_handle});
|
||||
rocprofiler::buffer::instance* buff = rocprofiler::buffer::get_buffer(buff_id);
|
||||
|
||||
if(!buff)
|
||||
throw std::runtime_error(fmt::format("Buffer with id: {} does not exists", buff_id.handle));
|
||||
|
||||
for(size_t i = 0; i < num_samples; i++)
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING,
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_SAMPLE,
|
||||
samples[i]);
|
||||
};
|
||||
@@ -22,23 +22,32 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/rocprofiler-sdk/buffer.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h"
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/cxx/hash.hpp>
|
||||
#include <rocprofiler-sdk/cxx/operators.hpp>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <sys/types.h>
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h"
|
||||
|
||||
struct PCSamplingData
|
||||
{
|
||||
PCSamplingData(size_t size)
|
||||
: samples(size){};
|
||||
PCSamplingData& operator=(PCSamplingData&) = delete;
|
||||
|
||||
std::vector<rocprofiler_pc_sampling_record_s> samples;
|
||||
std::vector<rocprofiler_pc_sampling_record_t> samples;
|
||||
};
|
||||
|
||||
class PCSamplingParserContext
|
||||
@@ -52,7 +61,7 @@ public:
|
||||
* @param[in] size Number of samples requested.
|
||||
* @returns Number of samples actually allocated on *buffer.
|
||||
*/
|
||||
uint64_t alloc(rocprofiler_pc_sampling_record_s** buffer, uint64_t size);
|
||||
uint64_t alloc(rocprofiler_pc_sampling_record_t** buffer, uint64_t size);
|
||||
|
||||
/**
|
||||
* @brief Parses a chunk of samples.
|
||||
@@ -95,6 +104,24 @@ public:
|
||||
*/
|
||||
bool shouldFlipRocrBuffer(const dispatch_pkt_id_t& pkt) const;
|
||||
|
||||
bool register_buffer_for_agent(rocprofiler_buffer_id_t buffer_id,
|
||||
rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mut);
|
||||
// Single buffer per agent is allowed
|
||||
if(_agent_buffers.count(agent_id) > 0) return false;
|
||||
|
||||
_agent_buffers.emplace(agent_id, buffer_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
void unregister_buffer_from_agent(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mut);
|
||||
|
||||
_agent_buffers.erase(agent_id);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Parses the given input data and generates pc sampling records.
|
||||
@@ -103,7 +130,7 @@ protected:
|
||||
template <typename GFX>
|
||||
pcsample_status_t _parse(const upcoming_samples_t& upcoming, const generic_sample_t* data_)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mut);
|
||||
// std::shared_lock<std::shared_mutex> lock(mut);
|
||||
|
||||
pcsample_status_t status = PCSAMPLE_STATUS_SUCCESS;
|
||||
uint64_t pkt_counter = upcoming.num_samples;
|
||||
@@ -112,7 +139,7 @@ protected:
|
||||
|
||||
while(pkt_counter > 0)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s* samples = nullptr;
|
||||
rocprofiler_pc_sampling_record_t* samples = nullptr;
|
||||
uint64_t memsize = alloc(&samples, pkt_counter);
|
||||
|
||||
if(memsize == 0 || memsize > pkt_counter) return PCSAMPLE_STATUS_CALLBACK_ERROR;
|
||||
@@ -125,7 +152,7 @@ protected:
|
||||
|
||||
data_ += memsize;
|
||||
pkt_counter -= memsize;
|
||||
generate_upcoming_pc_record(samples, memsize);
|
||||
generate_upcoming_pc_record(dev.handle, samples, memsize);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -137,12 +164,9 @@ protected:
|
||||
*/
|
||||
pcsample_status_t flushForgetList();
|
||||
static void generate_id_completion_record(const dispatch_pkt_id_t& pkt) { (void) pkt; };
|
||||
static void generate_upcoming_pc_record(const rocprofiler_pc_sampling_record_s* samples,
|
||||
size_t num_samples)
|
||||
{
|
||||
(void) samples;
|
||||
(void) num_samples;
|
||||
};
|
||||
void generate_upcoming_pc_record(uint64_t agent_id_handle,
|
||||
const rocprofiler_pc_sampling_record_t* samples,
|
||||
size_t num_samples);
|
||||
|
||||
//! Maps doorbells and dispatch_index to correlation_id
|
||||
std::unique_ptr<Parser::CorrelationMap> corr_map;
|
||||
@@ -156,4 +180,7 @@ protected:
|
||||
std::unordered_set<uint64_t> forget_list;
|
||||
|
||||
mutable std::shared_mutex mut;
|
||||
|
||||
private:
|
||||
std::unordered_map<rocprofiler_agent_id_t, rocprofiler_buffer_id_t> _agent_buffers;
|
||||
};
|
||||
|
||||
@@ -56,8 +56,8 @@ Benchmark(bool bWarmup)
|
||||
for(size_t i = 0; i < SAMPLE_PER_DISPATCH; i++)
|
||||
MockWave(dispatch).genPCSample();
|
||||
|
||||
std::pair<rocprofiler_pc_sampling_record_s*, size_t> userdata;
|
||||
userdata.first = new rocprofiler_pc_sampling_record_s[TOTAL_NUM_SAMPLES];
|
||||
std::pair<rocprofiler_pc_sampling_record_t*, size_t> userdata;
|
||||
userdata.first = new rocprofiler_pc_sampling_record_t[TOTAL_NUM_SAMPLES];
|
||||
userdata.second = TOTAL_NUM_SAMPLES;
|
||||
|
||||
auto t0 = std::chrono::system_clock::now();
|
||||
@@ -65,9 +65,9 @@ Benchmark(bool bWarmup)
|
||||
(generic_sample_t*) buffer->packets.data(),
|
||||
buffer->packets.size(),
|
||||
GFXIP_MAJOR,
|
||||
[](rocprofiler_pc_sampling_record_s** sample, uint64_t size, void* userdata_) {
|
||||
[](rocprofiler_pc_sampling_record_t** sample, uint64_t size, void* userdata_) {
|
||||
auto* pair =
|
||||
reinterpret_cast<std::pair<rocprofiler_pc_sampling_record_s*, size_t>*>(userdata_);
|
||||
reinterpret_cast<std::pair<rocprofiler_pc_sampling_record_t*, size_t>*>(userdata_);
|
||||
assert(TOTAL_NUM_SAMPLES == pair->second);
|
||||
*sample = pair->first;
|
||||
return size;
|
||||
@@ -80,7 +80,7 @@ Benchmark(bool bWarmup)
|
||||
{
|
||||
std::cout << "Benchmark: Parsed " << int(samples_per_us * 1E3f + 0.5f) * 1E-3f
|
||||
<< " Msample/s (";
|
||||
std::cout << int(sizeof(rocprofiler_pc_sampling_record_s) * samples_per_us) << " MB/s)"
|
||||
std::cout << int(sizeof(rocprofiler_pc_sampling_record_t) * samples_per_us) << " MB/s)"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@ std::mt19937 rdgen(1);
|
||||
/**
|
||||
* Sample user memory allocation callback.
|
||||
* It expects userdata to be cast-able to a pointer to
|
||||
* std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>>
|
||||
* std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>>
|
||||
*/
|
||||
static uint64_t
|
||||
alloc_callback(rocprofiler_pc_sampling_record_s** buffer, uint64_t size, void* userdata)
|
||||
alloc_callback(rocprofiler_pc_sampling_record_t** buffer, uint64_t size, void* userdata)
|
||||
{
|
||||
*buffer = new rocprofiler_pc_sampling_record_s[size];
|
||||
*buffer = new rocprofiler_pc_sampling_record_t[size];
|
||||
auto& vector =
|
||||
*reinterpret_cast<std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>>*>(
|
||||
*reinterpret_cast<std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>>*>(
|
||||
userdata);
|
||||
vector.push_back({*buffer, size});
|
||||
return size;
|
||||
@@ -51,7 +51,7 @@ alloc_callback(rocprofiler_pc_sampling_record_s** buffer, uint64_t size, void* u
|
||||
* the reconstructed correlation_id.
|
||||
*/
|
||||
static bool
|
||||
check_samples(rocprofiler_pc_sampling_record_s* samples, uint64_t size)
|
||||
check_samples(rocprofiler_pc_sampling_record_t* samples, uint64_t size)
|
||||
{
|
||||
for(size_t i = 0; i < size; i++)
|
||||
if(samples[i].correlation_id.internal != samples[i].pc) return false;
|
||||
@@ -71,7 +71,7 @@ TEST(pcs_parser, hello_world)
|
||||
MockWave(dispatch).genPCSample();
|
||||
MockWave(dispatch).genPCSample();
|
||||
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>> all_allocations;
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>> all_allocations;
|
||||
|
||||
CHECK_PARSER(parse_buffer((generic_sample_t*) buffer->packets.data(),
|
||||
buffer->packets.size(),
|
||||
@@ -114,7 +114,7 @@ TEST(pcs_parser, reverse_wave_order)
|
||||
for(auto it = dispatches.begin(); it != dispatches.end(); it++)
|
||||
MockWave(*it).genPCSample();
|
||||
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>> all_allocations;
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>> all_allocations;
|
||||
|
||||
CHECK_PARSER(parse_buffer((generic_sample_t*) buffer->packets.data(),
|
||||
buffer->packets.size(),
|
||||
@@ -150,7 +150,7 @@ TEST(pcs_parser, dispatch_wrapping)
|
||||
MockWave(dispatch).genPCSample();
|
||||
}
|
||||
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>> all_allocations;
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>> all_allocations;
|
||||
|
||||
CHECK_PARSER(parse_buffer((generic_sample_t*) buffer->packets.data(),
|
||||
buffer->packets.size(),
|
||||
@@ -197,7 +197,7 @@ TEST(pcs_parser, random_samples)
|
||||
for(int i = 0; i < num_samples; i++)
|
||||
MockWave(dispatches[rdgen() % dispatches.size()]).genPCSample();
|
||||
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>> all_allocations;
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>> all_allocations;
|
||||
|
||||
CHECK_PARSER(parse_buffer((generic_sample_t*) buffer->packets.data(),
|
||||
buffer->packets.size(),
|
||||
@@ -290,7 +290,7 @@ TEST(pcs_parser, queue_hammer)
|
||||
<< std::endl;
|
||||
std::cout << "Max queue occupancy: " << max_q_occupancy << "\n\n" << std::endl;
|
||||
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>> all_allocations;
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>> all_allocations;
|
||||
|
||||
CHECK_PARSER(parse_buffer((generic_sample_t*) buffer->packets.data(),
|
||||
buffer->packets.size(),
|
||||
@@ -302,7 +302,7 @@ TEST(pcs_parser, queue_hammer)
|
||||
NUM_ACTIONS); // QueueHammer test: Incorrect number of callbacks
|
||||
for(auto sb = 0ul; sb < all_allocations.size(); sb++)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s* samples = all_allocations[sb].first;
|
||||
rocprofiler_pc_sampling_record_t* samples = all_allocations[sb].first;
|
||||
size_t num_samples = all_allocations[sb].second;
|
||||
|
||||
EXPECT_EQ(num_samples, NUM_QUEUES); // QueueHammer: Incorrect number of samples
|
||||
@@ -329,7 +329,7 @@ TEST(pcs_parser, multi_buffer)
|
||||
const auto& packets = firstBuffer->packets;
|
||||
secondBuffer->packets = std::vector<packet_union_t>(packets.begin() + 2, packets.end());
|
||||
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_s*, uint64_t>> all_allocations;
|
||||
std::vector<std::pair<rocprofiler_pc_sampling_record_t*, uint64_t>> all_allocations;
|
||||
|
||||
CHECK_PARSER(parse_buffer((generic_sample_t*) firstBuffer->packets.data(),
|
||||
firstBuffer->packets.size(),
|
||||
|
||||
@@ -24,13 +24,15 @@
|
||||
# undef NDEBUG
|
||||
#endif
|
||||
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/cxx/operators.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp"
|
||||
|
||||
#define GFXIP_MAJOR 9
|
||||
|
||||
#define TYPECHECK(x) \
|
||||
@@ -295,7 +297,7 @@ class WaveIssueAndErrorTest : public WaveSnapTest
|
||||
|
||||
void genPCSample(bool valid, bool issued, bool dual, bool error)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s sample;
|
||||
rocprofiler_pc_sampling_record_t sample;
|
||||
::memset(&sample, 0, sizeof(sample));
|
||||
sample.pc = dispatch->unique_id;
|
||||
sample.correlation_id.internal = dispatch->getMockId().raw;
|
||||
@@ -320,7 +322,7 @@ class WaveIssueAndErrorTest : public WaveSnapTest
|
||||
dispatch->submit(std::move(pss));
|
||||
};
|
||||
|
||||
std::vector<rocprofiler_pc_sampling_record_s> compare;
|
||||
std::vector<rocprofiler_pc_sampling_record_t> compare;
|
||||
};
|
||||
|
||||
class WaveOtherFieldsTest : public WaveSnapTest
|
||||
@@ -347,9 +349,7 @@ class WaveOtherFieldsTest : public WaveSnapTest
|
||||
assert(parsed[0][i].flags.reserved == false);
|
||||
|
||||
assert(compare[i].exec_mask == parsed[0][i].exec_mask);
|
||||
assert(compare[i].workgroup_id_x == parsed[0][i].workgroup_id_x);
|
||||
assert(compare[i].workgroup_id_y == parsed[0][i].workgroup_id_y);
|
||||
assert(compare[i].workgroup_id_z == parsed[0][i].workgroup_id_z);
|
||||
assert(compare[i].workgroup_id == parsed[0][i].workgroup_id);
|
||||
|
||||
assert(compare[i].chiplet == parsed[0][i].chiplet);
|
||||
assert(compare[i].wave_id == parsed[0][i].wave_id);
|
||||
@@ -360,13 +360,13 @@ class WaveOtherFieldsTest : public WaveSnapTest
|
||||
|
||||
void genPCSample(int pc, int exec, int blkx, int blky, int blkz, int chip, int wave, int hwid)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s sample;
|
||||
rocprofiler_pc_sampling_record_t sample;
|
||||
::memset(&sample, 0, sizeof(sample));
|
||||
|
||||
sample.exec_mask = exec;
|
||||
sample.workgroup_id_x = blkx;
|
||||
sample.workgroup_id_y = blky;
|
||||
sample.workgroup_id_z = blkz;
|
||||
sample.workgroup_id.x = blkx;
|
||||
sample.workgroup_id.y = blky;
|
||||
sample.workgroup_id.z = blkz;
|
||||
|
||||
sample.chiplet = chip;
|
||||
sample.wave_id = wave;
|
||||
@@ -392,7 +392,7 @@ class WaveOtherFieldsTest : public WaveSnapTest
|
||||
(void) pc;
|
||||
};
|
||||
|
||||
std::vector<rocprofiler_pc_sampling_record_s> compare;
|
||||
std::vector<rocprofiler_pc_sampling_record_t> compare;
|
||||
};
|
||||
|
||||
TEST(pcs_parser, gfx9_test)
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
submit(uni);
|
||||
}
|
||||
|
||||
std::vector<std::vector<rocprofiler_pc_sampling_record_s>> get_parsed_buffer(int GFXIP_MAJOR)
|
||||
std::vector<std::vector<rocprofiler_pc_sampling_record_t>> get_parsed_buffer(int GFXIP_MAJOR)
|
||||
{
|
||||
parsed_data = {};
|
||||
|
||||
@@ -78,18 +78,18 @@ public:
|
||||
return parsed_data;
|
||||
}
|
||||
|
||||
static uint64_t alloc_parse_memory(rocprofiler_pc_sampling_record_s** sample,
|
||||
static uint64_t alloc_parse_memory(rocprofiler_pc_sampling_record_t** sample,
|
||||
uint64_t req_size,
|
||||
void* userdata)
|
||||
{
|
||||
auto* buffer = reinterpret_cast<MockRuntimeBuffer*>(userdata);
|
||||
buffer->parsed_data.push_back(std::vector<rocprofiler_pc_sampling_record_s>(req_size));
|
||||
buffer->parsed_data.push_back(std::vector<rocprofiler_pc_sampling_record_t>(req_size));
|
||||
*sample = buffer->parsed_data.back().data();
|
||||
return req_size;
|
||||
}
|
||||
|
||||
std::vector<packet_union_t> packets;
|
||||
std::vector<std::vector<rocprofiler_pc_sampling_record_s>> parsed_data;
|
||||
std::vector<std::vector<rocprofiler_pc_sampling_record_t>> parsed_data;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,18 +32,18 @@
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/rocr.h"
|
||||
|
||||
template <typename SType>
|
||||
inline rocprofiler_pc_sampling_record_s
|
||||
inline rocprofiler_pc_sampling_record_t
|
||||
copySampleHeader(const SType& sample)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s ret;
|
||||
rocprofiler_pc_sampling_record_t ret;
|
||||
ret.flags = pcsample_header_v1_t{.raw = 0}.flags;
|
||||
ret.flags.type = AMD_SNAPSHOT_V1;
|
||||
|
||||
ret.pc = sample.pc;
|
||||
ret.exec_mask = sample.exec_mask;
|
||||
ret.workgroup_id_x = sample.workgroup_id_x;
|
||||
ret.workgroup_id_y = sample.workgroup_id_y;
|
||||
ret.workgroup_id_z = sample.workgroup_id_z;
|
||||
ret.workgroup_id.x = sample.workgroup_id_x;
|
||||
ret.workgroup_id.y = sample.workgroup_id_y;
|
||||
ret.workgroup_id.z = sample.workgroup_id_z;
|
||||
|
||||
ret.chiplet = sample.chiplet_and_wave_id >> 8;
|
||||
ret.wave_id = sample.chiplet_and_wave_id & 0x3F;
|
||||
@@ -52,23 +52,23 @@ copySampleHeader(const SType& sample)
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline rocprofiler_pc_sampling_record_s
|
||||
inline rocprofiler_pc_sampling_record_t
|
||||
copyHostTrapSample(const perf_sample_host_trap_v1& sample)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s ret = copySampleHeader<perf_sample_host_trap_v1>(sample);
|
||||
rocprofiler_pc_sampling_record_t ret = copySampleHeader<perf_sample_host_trap_v1>(sample);
|
||||
ret.flags.type = AMD_HOST_TRAP_V1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename gfx>
|
||||
inline rocprofiler_pc_sampling_record_s
|
||||
inline rocprofiler_pc_sampling_record_t
|
||||
copyStochasticSample(const perf_sample_snapshot_v1& sample);
|
||||
|
||||
template <>
|
||||
inline rocprofiler_pc_sampling_record_s
|
||||
inline rocprofiler_pc_sampling_record_t
|
||||
copyStochasticSample<GFX9>(const perf_sample_snapshot_v1& sample)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
rocprofiler_pc_sampling_record_t ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
ret.flags.valid = sample.perf_snapshot_data & (~sample.perf_snapshot_data >> 26) & 0x1;
|
||||
// Check wave_id matches snapshot_wave_id
|
||||
|
||||
@@ -88,10 +88,10 @@ copyStochasticSample<GFX9>(const perf_sample_snapshot_v1& sample)
|
||||
}
|
||||
|
||||
template <>
|
||||
inline rocprofiler_pc_sampling_record_s
|
||||
inline rocprofiler_pc_sampling_record_t
|
||||
copyStochasticSample<GFX11>(const perf_sample_snapshot_v1& sample)
|
||||
{
|
||||
rocprofiler_pc_sampling_record_s ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
rocprofiler_pc_sampling_record_t ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
ret.flags.valid = sample.perf_snapshot_data & (~sample.perf_snapshot_data >> 23) & 0x1;
|
||||
// Check wave_id matches snapshot_wave_id
|
||||
|
||||
@@ -195,12 +195,12 @@ translate_inst(int in)
|
||||
#undef LUTOVERLOAD
|
||||
|
||||
template <bool HostTrap, typename GFX>
|
||||
inline rocprofiler_pc_sampling_record_s
|
||||
inline rocprofiler_pc_sampling_record_t
|
||||
copySample(const void* sample)
|
||||
{
|
||||
if(HostTrap) return copyHostTrapSample(*(const perf_sample_host_trap_v1*) sample);
|
||||
|
||||
rocprofiler_pc_sampling_record_s ret =
|
||||
rocprofiler_pc_sampling_record_t ret =
|
||||
copyStochasticSample<GFX>(*(const perf_sample_snapshot_v1*) sample);
|
||||
|
||||
ret.snapshot.inst_type = translate_inst<GFX>(ret.snapshot.inst_type);
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/pc_sampling/service.hpp"
|
||||
|
||||
#include "lib/common/logging.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
using hsa_initialized_t = std::atomic<bool>;
|
||||
|
||||
hsa_initialized_t&
|
||||
is_hsa_initialized()
|
||||
{
|
||||
static auto _v = hsa_initialized_t{false};
|
||||
return _v;
|
||||
}
|
||||
|
||||
// The function returns the atomic pointer to the active PC sampling service.
|
||||
// The nullptr means the PC sampling service is inactive.
|
||||
atomic_pc_sampling_service_t&
|
||||
get_active_pc_sampling_service()
|
||||
{
|
||||
static auto _v = atomic_pc_sampling_service_t{nullptr};
|
||||
return _v;
|
||||
}
|
||||
|
||||
// The function returns the atomic pointer to the configured pc sampling service.
|
||||
// The nullptr means the PC sampling service is not configured.
|
||||
atomic_pc_sampling_service_t&
|
||||
get_configured_pc_sampling_service()
|
||||
{
|
||||
static auto _v = atomic_pc_sampling_service_t{nullptr};
|
||||
return _v;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
start_service(const context::context* ctx)
|
||||
{
|
||||
auto* service = ctx->pc_sampler.get();
|
||||
|
||||
context::pc_sampling_service* _expected = nullptr;
|
||||
// If there is no active pc_sampling_service, mark `service` as activated.
|
||||
bool success = get_active_pc_sampling_service().compare_exchange_strong(_expected, service);
|
||||
|
||||
if(!success)
|
||||
{
|
||||
// Some other context is active at the moment.
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if(is_hsa_initialized().load())
|
||||
{
|
||||
hsa::pc_sampling_service_start(service);
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
stop_service(const context::context* ctx)
|
||||
{
|
||||
auto* service = ctx->pc_sampler.get();
|
||||
|
||||
if(get_active_pc_sampling_service().load() != service)
|
||||
{
|
||||
// Some other service is activated at the moment.
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if(is_hsa_initialized().load())
|
||||
{
|
||||
hsa::pc_sampling_service_stop(service);
|
||||
}
|
||||
|
||||
// No active PC sampling services
|
||||
bool success = get_active_pc_sampling_service().compare_exchange_strong(service, nullptr);
|
||||
|
||||
return (success) ? ROCPROFILER_STATUS_SUCCESS : ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
void
|
||||
post_hsa_init_start_active_service()
|
||||
{
|
||||
// Called as part of the registration of the HSA table
|
||||
if(is_hsa_initialized().load())
|
||||
{
|
||||
// If there is a guarantee that the `rocprofiler_set_api_table`
|
||||
// can be called only once for the HSA, then this condition is redundant.
|
||||
return;
|
||||
}
|
||||
|
||||
// If the PC sampling service is not configured on any of the agents, return.
|
||||
if(!get_configured_pc_sampling_service().load()) return;
|
||||
|
||||
static auto _once = std::once_flag{};
|
||||
std::call_once(_once, []() {
|
||||
// Configure PC sampling on the ROCr level only once.
|
||||
hsa::pc_sampling_service_finish_configuration(get_configured_pc_sampling_service().load());
|
||||
});
|
||||
|
||||
// Theoretically, the remainder of the function
|
||||
// can execute concurrently with start_context/stop_context.
|
||||
|
||||
context::pc_sampling_service* _expected = nullptr;
|
||||
void* invalid_ptr = reinterpret_cast<void*>(0xDEADBEEF);
|
||||
context::pc_sampling_service* pseudo_sevice =
|
||||
static_cast<context::pc_sampling_service*>(invalid_ptr);
|
||||
|
||||
if(get_active_pc_sampling_service().compare_exchange_strong(_expected, pseudo_sevice))
|
||||
{
|
||||
// At this point, we prevented any `start_context` instance from activating the service.
|
||||
is_hsa_initialized().store(true);
|
||||
// Now, allow `start_context` to active the service.
|
||||
get_active_pc_sampling_service().compare_exchange_strong(pseudo_sevice, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Someone already called `start_context` that activated service.
|
||||
// The pointer to this service is written inside `_expected`.
|
||||
// Start PC sampling service on the HSA level in the name of the
|
||||
// `start_context` caller.
|
||||
hsa::pc_sampling_service_start(_expected);
|
||||
// Although the caller of the `start_context` might try calling the hsa_start,
|
||||
// it will fail, which is fine, since the service is eventually started.
|
||||
is_hsa_initialized().store(true);
|
||||
}
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
configure_pc_sampling_service(context::context* ctx,
|
||||
const rocprofiler_agent_t* agent,
|
||||
rocprofiler_pc_sampling_method_t method,
|
||||
rocprofiler_pc_sampling_unit_t unit,
|
||||
uint64_t interval,
|
||||
rocprofiler_buffer_id_t buffer_id)
|
||||
{
|
||||
if(!ctx->pc_sampler)
|
||||
{
|
||||
ctx->pc_sampler = std::make_unique<context::pc_sampling_service>();
|
||||
}
|
||||
|
||||
if(ctx->pc_sampler->agent_sessions.count(agent->id) > 0)
|
||||
{
|
||||
// The service has already been configured for this agent.
|
||||
return ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED;
|
||||
}
|
||||
|
||||
// The restriction we agreed at the moment is that at most one context
|
||||
// can have PC sampling service configured, meaning
|
||||
// at most one instance of the `context::pc_sampling_service` can be configured
|
||||
// This `pc_sampling_service` contains at most one configuration per agent.
|
||||
context::pc_sampling_service* expected = nullptr;
|
||||
// Try registering the new instance of the `pc_sampling_service`.
|
||||
if(!get_configured_pc_sampling_service().compare_exchange_strong(expected,
|
||||
ctx->pc_sampler.get()))
|
||||
{
|
||||
// A `pc_sampling_service` instance has already been configured.
|
||||
// Note: the `expected` contains the pointer to the configured `pc_sampling_service`
|
||||
// instance.
|
||||
if(expected != ctx->pc_sampler.get())
|
||||
{
|
||||
// Someone tried configuring a new `pc_sampling_service instance`, which we do not
|
||||
// allow. Invalidate the `pc_sampling_service` from the `ctx` and return an error.
|
||||
ctx->pc_sampler = nullptr;
|
||||
// TODO: new status code needed
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
// Someone is trying to enable PC sampling on another agent, and we allow registering
|
||||
// new agent inside `pc_sampling_service` instance.
|
||||
}
|
||||
|
||||
// calling KFD to check if the configuration is actually supported at the moment
|
||||
uint32_t ioctl_pcs_id;
|
||||
auto ioctl_status = ioctl::ioctl_pcs_create(agent, method, unit, interval, &ioctl_pcs_id);
|
||||
if(ioctl_status != ROCPROFILER_STATUS_SUCCESS) return ioctl_status;
|
||||
|
||||
ctx->pc_sampler->agent_sessions[agent->id] = std::make_unique<PCSAgentSession>();
|
||||
|
||||
auto* session = ctx->pc_sampler->agent_sessions[agent->id].get();
|
||||
session->agent = agent;
|
||||
session->method = method;
|
||||
session->unit = unit;
|
||||
session->interval = interval;
|
||||
session->buffer_id = buffer_id;
|
||||
session->ioctl_pcs_id = ioctl_pcs_id;
|
||||
session->parser = std::make_unique<PCSamplingParserContext>();
|
||||
session->cid_manager = std::make_unique<PCSCIDManager>(session->parser.get());
|
||||
|
||||
ROCP_ERROR << "PC sampling session with id: " << session->ioctl_pcs_id
|
||||
<< " hsa been created!\n";
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
is_pc_sample_service_configured(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto* service = get_configured_pc_sampling_service().load();
|
||||
if(service)
|
||||
{
|
||||
// If the agent_id is in the service->agent_sessions map,
|
||||
// then the PC sampling service is configured on this agent.
|
||||
return service->agent_sessions.find(agent_id) != service->agent_sessions.end();
|
||||
}
|
||||
// The PC sampling service is not configured on this agent
|
||||
return false;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id)
|
||||
{
|
||||
// checking if the buffer is registered
|
||||
auto const* buff = rocprofiler::buffer::get_buffer(buffer_id);
|
||||
if(!buff) return ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND;
|
||||
|
||||
// Checking if the context is registered
|
||||
const auto* ctx = rocprofiler::context::get_registered_context(
|
||||
rocprofiler_context_id_t{.handle = buff->context_id});
|
||||
if(!ctx) return ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND;
|
||||
|
||||
auto* service = get_configured_pc_sampling_service().load();
|
||||
if(service && ctx->pc_sampler.get() == service)
|
||||
{
|
||||
// The context `ctx` (that holds the buffer with `buffer_id`)
|
||||
// is the one containing PC sampling service.
|
||||
// The HSA interception table is registered.
|
||||
for(const auto& [_, agent_session] : service->agent_sessions)
|
||||
{
|
||||
// Find the agent that fills the buffer with `buffer_id`
|
||||
if(agent_session->buffer_id.handle == buffer_id.handle)
|
||||
{
|
||||
// Flush internal PC sampling buffers filled by the agent
|
||||
return hsa::flush_internal_agent_buffers(agent_session.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PC sampling service not configured.
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,66 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/rocprofiler-sdk/context/context.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
|
||||
#include <hsa/hsa_api_trace.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
using atomic_pc_sampling_service_t = std::atomic<context::pc_sampling_service*>;
|
||||
|
||||
atomic_pc_sampling_service_t&
|
||||
get_configured_pc_sampling_service();
|
||||
|
||||
rocprofiler_status_t
|
||||
start_service(const context::context* ctx);
|
||||
|
||||
rocprofiler_status_t
|
||||
stop_service(const context::context* ctx);
|
||||
|
||||
void
|
||||
post_hsa_init_start_active_service();
|
||||
|
||||
rocprofiler_status_t
|
||||
configure_pc_sampling_service(context::context* ctx,
|
||||
const rocprofiler_agent_t* agent,
|
||||
rocprofiler_pc_sampling_method_t method,
|
||||
rocprofiler_pc_sampling_unit_t unit,
|
||||
uint64_t interval,
|
||||
rocprofiler_buffer_id_t buffer_id);
|
||||
|
||||
bool
|
||||
is_pc_sample_service_configured(rocprofiler_agent_id_t agent_id);
|
||||
|
||||
rocprofiler_status_t
|
||||
flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id);
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,29 @@
|
||||
rocprofiler_deactivate_clang_tidy()
|
||||
|
||||
include(GoogleTest)
|
||||
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_TEST_SOURCES
|
||||
configure_service.cpp
|
||||
# samples_processing.cpp
|
||||
query_configuration.cpp)
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_TEST_HEADERS pc_sampling_internals.hpp)
|
||||
|
||||
add_executable(pcs-test)
|
||||
|
||||
target_sources(pcs-test PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_TEST_SOURCES}
|
||||
${ROCPROFILER_LIB_PC_SAMPLING_TEST_HEADERS})
|
||||
|
||||
target_link_libraries(
|
||||
pcs-test
|
||||
PRIVATE rocprofiler::rocprofiler-common-library
|
||||
rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main)
|
||||
|
||||
gtest_add_tests(
|
||||
TARGET pcs-test
|
||||
SOURCES ${ROCPROFILER_LIB_COUNTER_TEST_SOURCES}
|
||||
TEST_LIST pcs-tests_TESTS
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set_tests_properties(
|
||||
${pcs-tests_TESTS} PROPERTIES TIMEOUT 45 LABELS "unittests;pc-sampling"
|
||||
SKIP_REGULAR_EXPRESSION "PC sampling unavailable")
|
||||
@@ -0,0 +1,453 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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 <rocprofiler-sdk/buffer.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/internal_threading.h>
|
||||
#include <rocprofiler-sdk/registration.h>
|
||||
#include <rocprofiler-sdk/rocprofiler.h>
|
||||
|
||||
#include "lib/common/utility.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr size_t BUFFER_SIZE_BYTES = 8192;
|
||||
constexpr size_t WATERMARK = (BUFFER_SIZE_BYTES / 4);
|
||||
|
||||
#define ROCPROFILER_CALL(ARG, MSG) \
|
||||
{ \
|
||||
auto _status = (ARG); \
|
||||
EXPECT_EQ(_status, ROCPROFILER_STATUS_SUCCESS) << MSG << " :: " << #ARG; \
|
||||
}
|
||||
|
||||
struct callback_data
|
||||
{
|
||||
rocprofiler_client_id_t* client_id = nullptr;
|
||||
rocprofiler_client_finalize_t client_fini_func = nullptr;
|
||||
rocprofiler_context_id_t client_ctx = {};
|
||||
rocprofiler_buffer_id_t client_buffer = {};
|
||||
rocprofiler_callback_thread_t client_thread = {};
|
||||
uint64_t client_workflow_count = {};
|
||||
uint64_t client_callback_count = {};
|
||||
int64_t current_depth = 0;
|
||||
int64_t max_depth = 0;
|
||||
std::map<uint64_t, rocprofiler_user_data_t> client_correlation = {};
|
||||
std::vector<const rocprofiler_agent_t*> gpu_pcs_agents = {};
|
||||
};
|
||||
|
||||
struct agent_data
|
||||
{
|
||||
uint64_t agent_count = 0;
|
||||
std::vector<hsa_device_type_t> agents = {};
|
||||
};
|
||||
|
||||
bool
|
||||
is_pc_sampling_supported(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data) {
|
||||
auto* avail_configs =
|
||||
static_cast<std::vector<rocprofiler_pc_sampling_configuration_t>*>(user_data);
|
||||
// printf("The agent with the id: %lu supports the %lu configurations: \n",
|
||||
// agent_id_.handle, num_config);
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
avail_configs->emplace_back(configs[i]);
|
||||
}
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
std::vector<rocprofiler_pc_sampling_configuration_t> configs;
|
||||
auto status = rocprofiler_query_pc_sampling_agent_configurations(agent_id, cb, &configs);
|
||||
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
// PC sampling is not supported
|
||||
return false;
|
||||
}
|
||||
else if(configs.size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
find_all_gpu_agents_supporting_pc_sampling_impl(rocprofiler_agent_version_t version,
|
||||
const void** agents,
|
||||
size_t num_agents,
|
||||
void* user_data)
|
||||
{
|
||||
EXPECT_EQ(version, ROCPROFILER_AGENT_INFO_VERSION_0);
|
||||
|
||||
// user_data represent the pointer to the array where gpu_agent will be stored
|
||||
if(!user_data) return ROCPROFILER_STATUS_ERROR;
|
||||
|
||||
auto* _out_agents = static_cast<std::vector<const rocprofiler_agent_t*>*>(user_data);
|
||||
auto* _agents = reinterpret_cast<const rocprofiler_agent_t**>(agents);
|
||||
for(size_t i = 0; i < num_agents; i++)
|
||||
{
|
||||
if(_agents[i]->type == ROCPROFILER_AGENT_TYPE_GPU)
|
||||
{
|
||||
if(is_pc_sampling_supported(_agents[i]->id)) _out_agents->push_back(_agents[i]);
|
||||
|
||||
printf("[%s] %s :: id=%zu, type=%i\n",
|
||||
__FUNCTION__,
|
||||
_agents[i]->name,
|
||||
_agents[i]->id.handle,
|
||||
_agents[i]->type);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[%s] %s :: id=%zu, type=%i\n",
|
||||
__FUNCTION__,
|
||||
_agents[i]->name,
|
||||
_agents[i]->id.handle,
|
||||
_agents[i]->type);
|
||||
}
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
const rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer_stochastic(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data) {
|
||||
auto* avail_configs =
|
||||
static_cast<std::vector<rocprofiler_pc_sampling_configuration_t>*>(user_data);
|
||||
// printf("The agent with the id: %lu supports the %lu configurations: \n",
|
||||
// agent_id_.handle, num_config);
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
avail_configs->emplace_back(configs[i]);
|
||||
}
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
std::vector<rocprofiler_pc_sampling_configuration_t> configs;
|
||||
ROCPROFILER_CALL(rocprofiler_query_pc_sampling_agent_configurations(agent_id, cb, &configs),
|
||||
"Failed to query available configurations");
|
||||
|
||||
const rocprofiler_pc_sampling_configuration_t* first_host_trap_config = nullptr;
|
||||
const rocprofiler_pc_sampling_configuration_t* first_stochastic_config = nullptr;
|
||||
// Search until encountering on the stochastic configuration, if any.
|
||||
// Otherwise, use the host trap config
|
||||
for(auto const& cfg : configs)
|
||||
{
|
||||
if(cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
{
|
||||
first_stochastic_config = &cfg;
|
||||
break;
|
||||
}
|
||||
else if(!first_host_trap_config && cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
{
|
||||
first_host_trap_config = &cfg;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the stochastic config is found. Use host trap config otherwise.
|
||||
const rocprofiler_pc_sampling_configuration_t* picked_cfg =
|
||||
(first_stochastic_config != nullptr) ? first_stochastic_config : first_host_trap_config;
|
||||
|
||||
return *picked_cfg;
|
||||
}
|
||||
|
||||
void
|
||||
rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /*context_id*/,
|
||||
rocprofiler_buffer_id_t /*buffer_id*/,
|
||||
rocprofiler_record_header_t** /*headers*/,
|
||||
size_t /*num_headers*/,
|
||||
void* /*data*/,
|
||||
uint64_t /*drop_count*/)
|
||||
{}
|
||||
|
||||
void
|
||||
test_fail_because_of_wrong_agent(const callback_data* cb_data,
|
||||
const rocprofiler_pc_sampling_configuration_t* pcs_config)
|
||||
{
|
||||
auto not_existing_agent = rocprofiler_agent_id_t{0xDEADBEEF};
|
||||
|
||||
EXPECT_EQ(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
not_existing_agent,
|
||||
pcs_config->method,
|
||||
pcs_config->unit,
|
||||
pcs_config->min_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
void
|
||||
test_fail_because_of_wrong_context(const callback_data* cb_data,
|
||||
rocprofiler_agent_id_t agent_id,
|
||||
const rocprofiler_pc_sampling_configuration_t* pcs_config)
|
||||
{
|
||||
auto not_existing_ctx = rocprofiler_context_id_t{0xDEADBEEF};
|
||||
|
||||
EXPECT_EQ(rocprofiler_configure_pc_sampling_service(not_existing_ctx,
|
||||
agent_id,
|
||||
pcs_config->method,
|
||||
pcs_config->unit,
|
||||
pcs_config->min_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND);
|
||||
}
|
||||
|
||||
void
|
||||
test_fail_because_of_wrong_buffer(const callback_data* cb_data,
|
||||
rocprofiler_agent_id_t agent_id,
|
||||
const rocprofiler_pc_sampling_configuration_t* pcs_config)
|
||||
{
|
||||
auto not_existing_buffer_id = rocprofiler_buffer_id_t{0xDEADBEEF};
|
||||
|
||||
EXPECT_EQ(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
pcs_config->method,
|
||||
pcs_config->unit,
|
||||
pcs_config->min_interval,
|
||||
not_existing_buffer_id),
|
||||
ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND);
|
||||
}
|
||||
|
||||
void
|
||||
test_fail_because_of_unsupported_configuration(
|
||||
const callback_data* cb_data,
|
||||
rocprofiler_agent_id_t agent_id,
|
||||
const rocprofiler_pc_sampling_configuration_t* pcs_config)
|
||||
{
|
||||
auto less_than_min_interval = pcs_config->min_interval - 1;
|
||||
auto greater_than_max_interval = pcs_config->max_interval + 1;
|
||||
auto wrong_method = ROCPROFILER_PC_SAMPLING_METHOD_LAST;
|
||||
auto wrong_unit = ROCPROFILER_PC_SAMPLING_UNIT_NONE;
|
||||
|
||||
EXPECT_NE(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
pcs_config->method,
|
||||
pcs_config->unit,
|
||||
less_than_min_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_SUCCESS);
|
||||
|
||||
EXPECT_NE(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
pcs_config->method,
|
||||
pcs_config->unit,
|
||||
greater_than_max_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_SUCCESS);
|
||||
|
||||
EXPECT_NE(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
wrong_method,
|
||||
pcs_config->unit,
|
||||
pcs_config->max_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_SUCCESS);
|
||||
|
||||
EXPECT_NE(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
pcs_config->method,
|
||||
wrong_unit,
|
||||
pcs_config->max_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
test_fail_because_service_is_already_configured(
|
||||
const callback_data* cb_data,
|
||||
rocprofiler_agent_id_t agent_id,
|
||||
const rocprofiler_pc_sampling_configuration_t* pcs_config)
|
||||
{
|
||||
EXPECT_EQ(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
pcs_config->method,
|
||||
pcs_config->unit,
|
||||
pcs_config->min_interval,
|
||||
cb_data->client_buffer),
|
||||
ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(pc_sampling, rocprofiler_configure_pc_sampling_service)
|
||||
{
|
||||
using init_func_t = int (*)(rocprofiler_client_finalize_t, void*);
|
||||
using fini_func_t = void (*)(void*);
|
||||
|
||||
// using hsa_iterate_agents_cb_t = hsa_status_t (*)(hsa_agent_t, void*);
|
||||
|
||||
auto cmd_line = rocprofiler::common::read_command_line(getpid());
|
||||
ASSERT_FALSE(cmd_line.empty());
|
||||
|
||||
static init_func_t tool_init = [](rocprofiler_client_finalize_t fini_func,
|
||||
void* client_data) -> int {
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
|
||||
cb_data->client_workflow_count++;
|
||||
cb_data->client_fini_func = fini_func;
|
||||
|
||||
// This function returns the all gpu agents supporting some kind of PC sampling
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_query_available_agents(ROCPROFILER_AGENT_INFO_VERSION_0,
|
||||
&find_all_gpu_agents_supporting_pc_sampling_impl,
|
||||
sizeof(rocprofiler_agent_t),
|
||||
static_cast<void*>(&cb_data->gpu_pcs_agents)),
|
||||
"Failed to find GPU agents");
|
||||
|
||||
// TODO-VLAINDIC: Can we dynamically skip the test if the underlying
|
||||
// HW does not support PC sampling
|
||||
if(cb_data->gpu_pcs_agents.size() == 0) exit(0);
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&cb_data->client_ctx),
|
||||
"failed to create context");
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(cb_data->client_ctx,
|
||||
BUFFER_SIZE_BYTES,
|
||||
WATERMARK,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
client_data,
|
||||
&cb_data->client_buffer),
|
||||
"buffer creation failed");
|
||||
|
||||
// We will create another context and try configuring pc sampling inside it,
|
||||
// that is supposed to fail.
|
||||
rocprofiler_context_id_t another_ctx;
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&another_ctx), "failed to create context");
|
||||
rocprofiler_buffer_id_t another_buff;
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(another_ctx,
|
||||
4096,
|
||||
2048,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
nullptr,
|
||||
&another_buff),
|
||||
"buffer creation failed");
|
||||
|
||||
for(const auto* agent : cb_data->gpu_pcs_agents)
|
||||
{
|
||||
const auto agent_id = agent->id;
|
||||
const auto pcs_config = extract_pc_sampling_config_prefer_stochastic(agent_id);
|
||||
|
||||
test_fail_because_of_wrong_agent(cb_data, &pcs_config);
|
||||
test_fail_because_of_wrong_context(cb_data, agent_id, &pcs_config);
|
||||
test_fail_because_of_wrong_buffer(cb_data, agent_id, &pcs_config);
|
||||
test_fail_because_of_unsupported_configuration(cb_data, agent_id, &pcs_config);
|
||||
|
||||
size_t interval = pcs_config.max_interval;
|
||||
|
||||
// This calls succeeds
|
||||
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
pcs_config.method,
|
||||
pcs_config.unit,
|
||||
interval,
|
||||
cb_data->client_buffer),
|
||||
"Failed to configure PC sampling service");
|
||||
|
||||
test_fail_because_service_is_already_configured(cb_data, agent_id, &pcs_config);
|
||||
|
||||
// Cannot create PC sampling service in context different than the `cb_data->client_ctx`
|
||||
EXPECT_EQ(rocprofiler_configure_pc_sampling_service(another_ctx,
|
||||
agent_id,
|
||||
pcs_config.method,
|
||||
pcs_config.unit,
|
||||
interval,
|
||||
another_buff),
|
||||
ROCPROFILER_STATUS_ERROR);
|
||||
}
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_callback_thread(&cb_data->client_thread),
|
||||
"failure creating callback thread");
|
||||
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_assign_callback_thread(cb_data->client_buffer, cb_data->client_thread),
|
||||
"failed to assign thread for buffer");
|
||||
|
||||
int valid_ctx = 0;
|
||||
ROCPROFILER_CALL(rocprofiler_context_is_valid(cb_data->client_ctx, &valid_ctx),
|
||||
"failure checking context validity");
|
||||
|
||||
EXPECT_EQ(valid_ctx, 1);
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_start_context(cb_data->client_ctx),
|
||||
"rocprofiler context start failed");
|
||||
|
||||
// no errors
|
||||
return 0;
|
||||
};
|
||||
|
||||
static fini_func_t tool_fini = [](void* client_data) -> void {
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
ROCPROFILER_CALL(rocprofiler_stop_context(cb_data->client_ctx),
|
||||
"rocprofiler context stop failed");
|
||||
|
||||
static_cast<callback_data*>(client_data)->client_workflow_count++;
|
||||
};
|
||||
|
||||
static auto cb_data = callback_data{};
|
||||
|
||||
static auto cfg_result =
|
||||
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
||||
tool_init,
|
||||
tool_fini,
|
||||
static_cast<void*>(&cb_data)};
|
||||
|
||||
static rocprofiler_configure_func_t rocp_init =
|
||||
[](uint32_t version,
|
||||
const char* runtime_version,
|
||||
uint32_t prio,
|
||||
rocprofiler_client_id_t* client_id) -> rocprofiler_tool_configure_result_t* {
|
||||
auto expected_version = ROCPROFILER_VERSION;
|
||||
EXPECT_EQ(expected_version, version);
|
||||
EXPECT_EQ(std::string_view{runtime_version}, std::string_view{ROCPROFILER_VERSION_STRING});
|
||||
EXPECT_EQ(prio, 0);
|
||||
EXPECT_EQ(client_id->name, nullptr);
|
||||
cb_data.client_id = client_id;
|
||||
cb_data.client_id->name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
|
||||
|
||||
return &cfg_result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
|
||||
|
||||
// Further tests assumes the existence of at least one GPU agent supporting
|
||||
if(cb_data.gpu_pcs_agents.size() == 0) return;
|
||||
|
||||
const auto* agent = cb_data.gpu_pcs_agents.at(0);
|
||||
EXPECT_EQ(rocprofiler_configure_pc_sampling_service(cb_data.client_ctx,
|
||||
agent->id,
|
||||
ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP,
|
||||
ROCPROFILER_PC_SAMPLING_UNIT_TIME,
|
||||
1,
|
||||
cb_data.client_buffer),
|
||||
ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
void
|
||||
post_hsa_init_start_active_service();
|
||||
|
||||
namespace hsa
|
||||
{
|
||||
extern void
|
||||
amd_intercept_marker_handler_callback(const struct amd_aql_intercept_marker_s* packet,
|
||||
hsa_queue_t* queue,
|
||||
uint64_t packet_id);
|
||||
|
||||
extern void
|
||||
kernel_completion_cb(const std::shared_ptr<rocprofiler::counters::counter_callback_info>& info,
|
||||
const rocprofiler_agent_t* rocp_agent,
|
||||
rocprofiler::hsa::ClientID client_id,
|
||||
const rocprofiler::hsa::rocprofiler_packet& kernel_pkt,
|
||||
const rocprofiler::hsa::Queue::queue_info_session_t& session,
|
||||
std::unique_ptr<rocprofiler::hsa::AQLPacket> pkt);
|
||||
|
||||
extern void
|
||||
data_ready_callback(void* client_callback_data,
|
||||
size_t data_size,
|
||||
size_t lost_sample_count,
|
||||
hsa_ven_amd_pcs_data_copy_callback_t data_copy_callback,
|
||||
void* hsa_callback_data);
|
||||
|
||||
extern atomic_pc_sampling_service_t&
|
||||
get_active_pc_sampling_service();
|
||||
|
||||
} // namespace hsa
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,364 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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 <gtest/gtest.h>
|
||||
#include <rocprofiler-sdk/buffer.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/internal_threading.h>
|
||||
#include <rocprofiler-sdk/registration.h>
|
||||
#include <rocprofiler-sdk/rocprofiler.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
#define USER_DATA_VAL 33
|
||||
|
||||
constexpr size_t BUFFER_SIZE_BYTES = 8192;
|
||||
constexpr size_t WATERMARK = (BUFFER_SIZE_BYTES / 4);
|
||||
|
||||
#define ROCPROFILER_CALL(ARG, MSG) \
|
||||
{ \
|
||||
auto _status = (ARG); \
|
||||
EXPECT_EQ(_status, ROCPROFILER_STATUS_SUCCESS) << MSG << " :: " << #ARG; \
|
||||
}
|
||||
|
||||
struct callback_data
|
||||
{
|
||||
rocprofiler_client_id_t* client_id = nullptr;
|
||||
rocprofiler_client_finalize_t client_fini_func = nullptr;
|
||||
rocprofiler_context_id_t client_ctx = {};
|
||||
rocprofiler_buffer_id_t client_buffer = {};
|
||||
rocprofiler_callback_thread_t client_thread = {};
|
||||
uint64_t client_workflow_count = {};
|
||||
uint64_t client_callback_count = {};
|
||||
int64_t current_depth = 0;
|
||||
int64_t max_depth = 0;
|
||||
std::map<uint64_t, rocprofiler_user_data_t> client_correlation = {};
|
||||
std::vector<const rocprofiler_agent_t*> gpu_pcs_agents = {};
|
||||
};
|
||||
|
||||
struct agent_data
|
||||
{
|
||||
uint64_t agent_count = 0;
|
||||
std::vector<hsa_device_type_t> agents = {};
|
||||
};
|
||||
|
||||
bool
|
||||
is_pc_sampling_supported(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data) {
|
||||
auto* avail_configs =
|
||||
static_cast<std::vector<rocprofiler_pc_sampling_configuration_t>*>(user_data);
|
||||
// printf("The agent with the id: %lu supports the %lu configurations: \n",
|
||||
// agent_id_.handle, num_config);
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
avail_configs->emplace_back(configs[i]);
|
||||
}
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
std::vector<rocprofiler_pc_sampling_configuration_t> configs;
|
||||
auto status = rocprofiler_query_pc_sampling_agent_configurations(agent_id, cb, &configs);
|
||||
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
// PC sampling is not supported
|
||||
return false;
|
||||
}
|
||||
else if(configs.size() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
find_all_gpu_agents_supporting_pc_sampling_impl(rocprofiler_agent_version_t version,
|
||||
const void** agents,
|
||||
size_t num_agents,
|
||||
void* user_data)
|
||||
{
|
||||
EXPECT_EQ(version, ROCPROFILER_AGENT_INFO_VERSION_0);
|
||||
|
||||
// user_data represent the pointer to the array where gpu_agent will be stored
|
||||
if(!user_data) return ROCPROFILER_STATUS_ERROR;
|
||||
|
||||
auto* _out_agents = static_cast<std::vector<const rocprofiler_agent_t*>*>(user_data);
|
||||
auto* _agents = reinterpret_cast<const rocprofiler_agent_t**>(agents);
|
||||
for(size_t i = 0; i < num_agents; i++)
|
||||
{
|
||||
if(_agents[i]->type == ROCPROFILER_AGENT_TYPE_GPU)
|
||||
{
|
||||
if(is_pc_sampling_supported(_agents[i]->id)) _out_agents->push_back(_agents[i]);
|
||||
|
||||
printf("[%s] %s :: id=%zu, type=%i\n",
|
||||
__FUNCTION__,
|
||||
_agents[i]->name,
|
||||
_agents[i]->id.handle,
|
||||
_agents[i]->type);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[%s] %s :: id=%zu, type=%i\n",
|
||||
__FUNCTION__,
|
||||
_agents[i]->name,
|
||||
_agents[i]->id.handle,
|
||||
_agents[i]->type);
|
||||
}
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer_stochastic(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data) {
|
||||
auto* avail_configs =
|
||||
static_cast<std::vector<rocprofiler_pc_sampling_configuration_t>*>(user_data);
|
||||
// printf("The agent with the id: %lu supports the %lu configurations: \n",
|
||||
// agent_id_.handle, num_config);
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
avail_configs->emplace_back(configs[i]);
|
||||
}
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
std::vector<rocprofiler_pc_sampling_configuration_t> configs;
|
||||
ROCPROFILER_CALL(rocprofiler_query_pc_sampling_agent_configurations(agent_id, cb, &configs),
|
||||
"Failed to query available configurations");
|
||||
|
||||
const rocprofiler_pc_sampling_configuration_t* first_host_trap_config = nullptr;
|
||||
const rocprofiler_pc_sampling_configuration_t* first_stochastic_config = nullptr;
|
||||
// Search until encountering on the stochastic configuration, if any.
|
||||
// Otherwise, use the host trap config
|
||||
for(auto const& cfg : configs)
|
||||
{
|
||||
if(cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
{
|
||||
first_stochastic_config = &cfg;
|
||||
break;
|
||||
}
|
||||
else if(!first_host_trap_config && cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
{
|
||||
first_host_trap_config = &cfg;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the stochastic config is found. Use host trap config otherwise.
|
||||
const rocprofiler_pc_sampling_configuration_t* picked_cfg =
|
||||
(first_stochastic_config != nullptr) ? first_stochastic_config : first_host_trap_config;
|
||||
|
||||
return *picked_cfg;
|
||||
}
|
||||
|
||||
void
|
||||
rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /*context_id*/,
|
||||
rocprofiler_buffer_id_t /*buffer_id*/,
|
||||
rocprofiler_record_header_t** /*headers*/,
|
||||
size_t /*num_headers*/,
|
||||
void* /*data*/,
|
||||
uint64_t /*drop_count*/)
|
||||
{}
|
||||
|
||||
rocprofiler_status_t
|
||||
check_all_configs_cb(const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data)
|
||||
{
|
||||
auto* val = reinterpret_cast<int*>(user_data);
|
||||
EXPECT_EQ(*val, USER_DATA_VAL);
|
||||
|
||||
if(num_config == 0) return ROCPROFILER_STATUS_ERROR;
|
||||
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
const auto* cfg = &configs[i];
|
||||
EXPECT_LT(ROCPROFILER_PC_SAMPLING_METHOD_NONE, cfg->method);
|
||||
EXPECT_LT(cfg->method, ROCPROFILER_PC_SAMPLING_METHOD_LAST);
|
||||
|
||||
EXPECT_LT(ROCPROFILER_PC_SAMPLING_UNIT_NONE, cfg->unit);
|
||||
EXPECT_LT(cfg->unit, ROCPROFILER_PC_SAMPLING_UNIT_LAST);
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// TODO: change according to the actual implementation
|
||||
TEST(pc_sampling, query_configs_agent_does_not_exists)
|
||||
{
|
||||
int cb_data = USER_DATA_VAL;
|
||||
// The agent does not exists
|
||||
EXPECT_EQ(rocprofiler_query_pc_sampling_agent_configurations(
|
||||
rocprofiler_agent_id_t{.handle = 0xDEADBEEF}, check_all_configs_cb, &cb_data),
|
||||
ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
TEST(pc_sampling, query_configs_after_service_setup)
|
||||
{
|
||||
using init_func_t = int (*)(rocprofiler_client_finalize_t, void*);
|
||||
using fini_func_t = void (*)(void*);
|
||||
|
||||
// TODO: configure PC sampling and query if the configuration is listed
|
||||
static init_func_t tool_init = [](rocprofiler_client_finalize_t fini_func,
|
||||
void* client_data) -> int {
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
|
||||
cb_data->client_workflow_count++;
|
||||
cb_data->client_fini_func = fini_func;
|
||||
|
||||
// This function returns the all gpu agents supporting some kind of PC sampling
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_query_available_agents(ROCPROFILER_AGENT_INFO_VERSION_0,
|
||||
&find_all_gpu_agents_supporting_pc_sampling_impl,
|
||||
sizeof(rocprofiler_agent_t),
|
||||
static_cast<void*>(&cb_data->gpu_pcs_agents)),
|
||||
"Failed to find GPU agents");
|
||||
|
||||
// TODO-VLAINDIC: Can we dynamically skip the test if the underlying
|
||||
// HW does not support PC sampling
|
||||
if(cb_data->gpu_pcs_agents.size() == 0) exit(0);
|
||||
|
||||
int query_cb_data = USER_DATA_VAL;
|
||||
const auto* agent = cb_data->gpu_pcs_agents.at(0);
|
||||
const auto agent_id = agent->id;
|
||||
auto status = rocprofiler_query_pc_sampling_agent_configurations(
|
||||
agent_id, check_all_configs_cb, &query_cb_data);
|
||||
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
// The agent does not support PC sampling
|
||||
return -1;
|
||||
}
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&cb_data->client_ctx),
|
||||
"failed to create context");
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(cb_data->client_ctx,
|
||||
BUFFER_SIZE_BYTES,
|
||||
WATERMARK,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
client_data,
|
||||
&cb_data->client_buffer),
|
||||
"buffer creation failed");
|
||||
|
||||
auto pcs_config = extract_pc_sampling_config_prefer_stochastic(agent_id);
|
||||
|
||||
size_t interval = pcs_config.max_interval;
|
||||
|
||||
// This calls succeeds
|
||||
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent->id,
|
||||
pcs_config.method,
|
||||
pcs_config.unit,
|
||||
interval,
|
||||
cb_data->client_buffer),
|
||||
"Failed to configure PC sampling service");
|
||||
|
||||
// query configuration and expect to see `pcs_config->max_interval` as the `interval`
|
||||
auto post_setup_conf_cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data) {
|
||||
const rocprofiler_pc_sampling_configuration_t* picked_cfg =
|
||||
static_cast<rocprofiler_pc_sampling_configuration_t*>(user_data);
|
||||
|
||||
EXPECT_EQ(num_config, 1);
|
||||
|
||||
const auto* cfg = &configs[0];
|
||||
EXPECT_EQ(cfg->method, picked_cfg->method);
|
||||
EXPECT_EQ(cfg->unit, picked_cfg->unit);
|
||||
// Min and max interval are equeal when PC sampling is enabled
|
||||
EXPECT_EQ(cfg->min_interval, cfg->max_interval);
|
||||
// When set up the PC sampling, we used the max_interval of the picked_cfg
|
||||
EXPECT_EQ(cfg->max_interval, picked_cfg->max_interval);
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
EXPECT_EQ(rocprofiler_query_pc_sampling_agent_configurations(
|
||||
agent_id, post_setup_conf_cb, &pcs_config),
|
||||
ROCPROFILER_STATUS_SUCCESS);
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_callback_thread(&cb_data->client_thread),
|
||||
"failure creating callback thread");
|
||||
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_assign_callback_thread(cb_data->client_buffer, cb_data->client_thread),
|
||||
"failed to assign thread for buffer");
|
||||
|
||||
int valid_ctx = 0;
|
||||
ROCPROFILER_CALL(rocprofiler_context_is_valid(cb_data->client_ctx, &valid_ctx),
|
||||
"failure checking context validity");
|
||||
|
||||
EXPECT_EQ(valid_ctx, 1);
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_start_context(cb_data->client_ctx),
|
||||
"rocprofiler context start failed");
|
||||
|
||||
// no errors
|
||||
return 0;
|
||||
};
|
||||
|
||||
static fini_func_t tool_fini = [](void* client_data) -> void {
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
ROCPROFILER_CALL(rocprofiler_stop_context(cb_data->client_ctx),
|
||||
"rocprofiler context stop failed");
|
||||
|
||||
cb_data->client_workflow_count++;
|
||||
};
|
||||
|
||||
static auto cb_data = callback_data{};
|
||||
|
||||
static auto cfg_result =
|
||||
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
||||
tool_init,
|
||||
tool_fini,
|
||||
static_cast<void*>(&cb_data)};
|
||||
|
||||
static rocprofiler_configure_func_t rocp_init =
|
||||
[](uint32_t version,
|
||||
const char* runtime_version,
|
||||
uint32_t prio,
|
||||
rocprofiler_client_id_t* client_id) -> rocprofiler_tool_configure_result_t* {
|
||||
auto expected_version = ROCPROFILER_VERSION;
|
||||
EXPECT_EQ(expected_version, version);
|
||||
EXPECT_EQ(std::string_view{runtime_version}, std::string_view{ROCPROFILER_VERSION_STRING});
|
||||
EXPECT_EQ(prio, 0);
|
||||
EXPECT_EQ(client_id->name, nullptr);
|
||||
cb_data.client_id = client_id;
|
||||
cb_data.client_id->name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
|
||||
|
||||
return &cfg_result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
|
||||
}
|
||||
@@ -0,0 +1,437 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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 <hsa/hsa.h>
|
||||
#include <rocprofiler-sdk/buffer.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/internal_threading.h>
|
||||
#include <rocprofiler-sdk/registration.h>
|
||||
#include <rocprofiler-sdk/rocprofiler.h>
|
||||
|
||||
#include "lib/common/utility.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/agent_cache.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/queue.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/rocr.h"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/tests/pc_sampling_internals.hpp"
|
||||
#include "pc_sampling_internals.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
constexpr size_t BUFFER_SIZE_BYTES = 8192;
|
||||
constexpr size_t WATERMARK = (BUFFER_SIZE_BYTES / 4);
|
||||
|
||||
#define ROCPROFILER_CALL(ARG, MSG) \
|
||||
{ \
|
||||
auto _status = (ARG); \
|
||||
EXPECT_EQ(_status, ROCPROFILER_STATUS_SUCCESS) << MSG << " :: " << #ARG; \
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
#define NUM_SAMPLES 5
|
||||
#define TRAP_ID 0
|
||||
|
||||
struct callback_data
|
||||
{
|
||||
rocprofiler_client_id_t* client_id = nullptr;
|
||||
rocprofiler_client_finalize_t client_fini_func = nullptr;
|
||||
rocprofiler_context_id_t client_ctx = {};
|
||||
rocprofiler_buffer_id_t client_buffer = {};
|
||||
rocprofiler_callback_thread_t client_thread = {};
|
||||
uint64_t client_workflow_count = {};
|
||||
uint64_t client_callback_count = {};
|
||||
int64_t current_depth = 0;
|
||||
int64_t max_depth = 0;
|
||||
std::map<uint64_t, rocprofiler_user_data_t> client_correlation = {};
|
||||
std::vector<const rocprofiler_agent_t*> gpu_pcs_agents = {};
|
||||
};
|
||||
|
||||
struct agent_data
|
||||
{
|
||||
uint64_t agent_count = 0;
|
||||
std::vector<hsa_device_type_t> agents = {};
|
||||
};
|
||||
|
||||
rocprofiler_status_t
|
||||
find_all_gpu_agents_supporting_pc_sampling_impl(const rocprofiler_agent_t** agents,
|
||||
size_t num_agents,
|
||||
void* user_data)
|
||||
{
|
||||
// user_data represent the pointer to the array where gpu_agent will be stored
|
||||
if(!user_data) return ROCPROFILER_STATUS_ERROR;
|
||||
|
||||
auto* _out_agents = static_cast<std::vector<const rocprofiler_agent_t*>*>(user_data);
|
||||
// find the first GPU agent
|
||||
for(size_t i = 0; i < num_agents; i++)
|
||||
{
|
||||
if(agents[i]->type == ROCPROFILER_AGENT_TYPE_GPU)
|
||||
{
|
||||
// Skip GPU agents not supporting PC sampling
|
||||
// Vladimir: The assumption is that if a GPU agent does not support PC sampling,
|
||||
// the size is 0.
|
||||
if(agents[i]->num_pc_sampling_configs == 0) continue;
|
||||
|
||||
_out_agents->push_back(agents[i]);
|
||||
|
||||
printf("[%s] %s :: id=%zu, type=%i, num pc sample configs=%zu\n",
|
||||
__FUNCTION__,
|
||||
agents[i]->name,
|
||||
agents[i]->id.handle,
|
||||
agents[i]->type,
|
||||
agents[i]->num_pc_sampling_configs);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[%s] %s :: id=%zu, type=%i, num pc sample configs=%zu\n",
|
||||
__FUNCTION__,
|
||||
agents[i]->name,
|
||||
agents[i]->id.handle,
|
||||
agents[i]->type,
|
||||
agents[i]->num_pc_sampling_configs);
|
||||
}
|
||||
}
|
||||
|
||||
return !_out_agents->empty() ? ROCPROFILER_STATUS_SUCCESS : ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
const rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer_stochastic(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
void* user_data) {
|
||||
auto* avail_configs =
|
||||
static_cast<std::vector<rocprofiler_pc_sampling_configuration_t>*>(user_data);
|
||||
// printf("The agent with the id: %lu supports the %lu configurations: \n",
|
||||
// agent_id_.handle, num_config);
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
avail_configs->emplace_back(configs[i]);
|
||||
}
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
};
|
||||
std::vector<rocprofiler_pc_sampling_configuration_t> configs;
|
||||
ROCPROFILER_CALL(rocprofiler_query_pc_sampling_agent_configurations(agent_id, cb, &configs),
|
||||
"Failed to query available configurations");
|
||||
|
||||
const rocprofiler_pc_sampling_configuration_t* first_host_trap_config = nullptr;
|
||||
const rocprofiler_pc_sampling_configuration_t* first_stochastic_config = nullptr;
|
||||
// Search until encountering on the stochastic configuration, if any.
|
||||
// Otherwise, use the host trap config
|
||||
for(auto const& cfg : configs)
|
||||
{
|
||||
if(cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
{
|
||||
first_stochastic_config = &cfg;
|
||||
break;
|
||||
}
|
||||
else if(!first_host_trap_config && cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
{
|
||||
first_host_trap_config = &cfg;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the stochastic config is found. Use host trap config otherwise.
|
||||
const rocprofiler_pc_sampling_configuration_t* picked_cfg =
|
||||
(first_stochastic_config != nullptr) ? first_stochastic_config : first_host_trap_config;
|
||||
|
||||
return *picked_cfg;
|
||||
}
|
||||
|
||||
void
|
||||
rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /*context_id*/,
|
||||
rocprofiler_buffer_id_t /*buffer_id*/,
|
||||
rocprofiler_record_header_t** headers,
|
||||
size_t num_headers,
|
||||
void* /*data*/,
|
||||
uint64_t drop_count)
|
||||
{
|
||||
EXPECT_EQ(drop_count, 0);
|
||||
|
||||
for(size_t i = 0; i < num_headers; i++)
|
||||
{
|
||||
auto* cur_header = headers[i];
|
||||
|
||||
if(cur_header == nullptr)
|
||||
{
|
||||
throw std::runtime_error{
|
||||
"rocprofiler provided a null pointer to header. this should never happen"};
|
||||
}
|
||||
else if(cur_header->hash !=
|
||||
rocprofiler_record_header_compute_hash(cur_header->category, cur_header->kind))
|
||||
{
|
||||
throw std::runtime_error{"rocprofiler_record_header_t (category | kind) != hash"};
|
||||
}
|
||||
else if(cur_header->category == ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING)
|
||||
{
|
||||
auto* pc_sample = static_cast<rocprofiler_pc_sampling_record_t*>(cur_header->payload);
|
||||
// FIXME: find the cause why this fails
|
||||
// EXPECT_EQ(pc_sample->correlation_id.internal, 1);
|
||||
EXPECT_EQ(pc_sample->pc, i + 1);
|
||||
EXPECT_EQ(pc_sample->timestamp, i + 33);
|
||||
EXPECT_EQ(pc_sample->hw_id, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error{"unexpected rocprofiler_record_header_t category + kind"};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(pc_sampling, processing_pc_samples)
|
||||
{
|
||||
using init_func_t = int (*)(rocprofiler_client_finalize_t, void*);
|
||||
using fini_func_t = void (*)(void*);
|
||||
|
||||
// using hsa_iterate_agents_cb_t = hsa_status_t (*)(hsa_agent_t, void*);
|
||||
|
||||
auto cmd_line = rocprofiler::common::read_command_line(getpid());
|
||||
ASSERT_FALSE(cmd_line.empty());
|
||||
|
||||
static init_func_t tool_init = [](rocprofiler_client_finalize_t fini_func,
|
||||
void* client_data) -> int {
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
|
||||
cb_data->client_workflow_count++;
|
||||
cb_data->client_fini_func = fini_func;
|
||||
|
||||
// This function returns the all gpu agents supporting some kind of PC sampling
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_query_available_agents(&find_all_gpu_agents_supporting_pc_sampling_impl,
|
||||
sizeof(rocprofiler_agent_t),
|
||||
static_cast<void*>(&cb_data->gpu_pcs_agents)),
|
||||
"Failed to find GPU agents");
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&cb_data->client_ctx),
|
||||
"failed to create context");
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(cb_data->client_ctx,
|
||||
4096,
|
||||
2048,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
client_data,
|
||||
&cb_data->client_buffer),
|
||||
"buffer creation failed");
|
||||
|
||||
const auto* agent = cb_data->gpu_pcs_agents.at(0);
|
||||
const auto agent_id = agent->id;
|
||||
const auto pcs_config = extract_pc_sampling_config_prefer_stochastic(agent_id);
|
||||
|
||||
size_t interval = pcs_config.max_interval;
|
||||
|
||||
// This calls succeeds
|
||||
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent->id,
|
||||
pcs_config.method,
|
||||
pcs_config.unit,
|
||||
interval,
|
||||
cb_data->client_buffer),
|
||||
"Failed to configure PC sampling service");
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_callback_thread(&cb_data->client_thread),
|
||||
"failure creating callback thread");
|
||||
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_assign_callback_thread(cb_data->client_buffer, cb_data->client_thread),
|
||||
"failed to assign thread for buffer");
|
||||
|
||||
int valid_ctx = 0;
|
||||
ROCPROFILER_CALL(rocprofiler_context_is_valid(cb_data->client_ctx, &valid_ctx),
|
||||
"failure checking context validity");
|
||||
|
||||
EXPECT_EQ(valid_ctx, 1);
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_start_context(cb_data->client_ctx),
|
||||
"rocprofiler context start failed");
|
||||
|
||||
// no errors
|
||||
return 0;
|
||||
};
|
||||
|
||||
static fini_func_t tool_fini = [](void* client_data) -> void {
|
||||
auto* cb_data = static_cast<callback_data*>(client_data);
|
||||
// FIXME: for some reason, this returns context not found
|
||||
// ROCPROFILER_CALL(rocprofiler_stop_context(cb_data->client_ctx),
|
||||
// "rocprofiler context stop failed");
|
||||
|
||||
cb_data->client_workflow_count++;
|
||||
};
|
||||
|
||||
static auto cb_data = callback_data{};
|
||||
|
||||
static auto cfg_result =
|
||||
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
||||
tool_init,
|
||||
tool_fini,
|
||||
static_cast<void*>(&cb_data)};
|
||||
|
||||
static rocprofiler_configure_func_t rocp_init =
|
||||
[](uint32_t version,
|
||||
const char* runtime_version,
|
||||
uint32_t prio,
|
||||
rocprofiler_client_id_t* client_id) -> rocprofiler_tool_configure_result_t* {
|
||||
auto expected_version = ROCPROFILER_VERSION;
|
||||
EXPECT_EQ(expected_version, version);
|
||||
EXPECT_EQ(std::string_view{runtime_version}, std::string_view{ROCPROFILER_VERSION_STRING});
|
||||
EXPECT_EQ(prio, 0);
|
||||
EXPECT_EQ(client_id->name, nullptr);
|
||||
cb_data.client_id = client_id;
|
||||
cb_data.client_id->name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
|
||||
|
||||
return &cfg_result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(rocprofiler_force_configure(rocp_init), ROCPROFILER_STATUS_SUCCESS);
|
||||
|
||||
// Further tests assumes the existence of at least one GPU agent supporting
|
||||
if(cb_data.gpu_pcs_agents.size() == 0) return;
|
||||
|
||||
auto& hsa_table = rocprofiler::hsa::get_table();
|
||||
auto* pc_sampling_table_ = hsa_table.pc_sampling_ext_;
|
||||
EXPECT_NE(pc_sampling_table_, nullptr);
|
||||
|
||||
pc_sampling_table_->hsa_ven_amd_pcs_create_from_id_fn =
|
||||
[](uint32_t /*ioctl_pcs_id*/,
|
||||
hsa_agent_t /*agent*/,
|
||||
hsa_ven_amd_pcs_method_kind_t /*method*/,
|
||||
hsa_ven_amd_pcs_units_t /*units*/,
|
||||
size_t /*interval*/,
|
||||
size_t /*latency*/,
|
||||
size_t /*buffer_size*/,
|
||||
hsa_ven_amd_pcs_data_ready_callback_t /*data_ready_callback*/,
|
||||
void* /*client_callback_data*/,
|
||||
hsa_ven_amd_pcs_t* /*pc_sampling*/) { return HSA_STATUS_SUCCESS; };
|
||||
|
||||
pc_sampling_table_->hsa_ven_amd_pcs_flush_fn = [](hsa_ven_amd_pcs_t /*pc_sampling*/) {
|
||||
return HSA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
auto* ext_table_ = hsa_table.amd_ext_;
|
||||
EXPECT_NE(ext_table_, nullptr);
|
||||
|
||||
ext_table_->hsa_amd_queue_get_info_fn =
|
||||
[](hsa_queue_t* queue, hsa_queue_info_attribute_t attribute, void* value) {
|
||||
(void) queue;
|
||||
switch(attribute)
|
||||
{
|
||||
case HSA_AMD_QUEUE_INFO_AGENT:
|
||||
*(reinterpret_cast<hsa_agent_t*>(value)) = hsa_agent_t{.handle = 1};
|
||||
break;
|
||||
case HSA_AMD_QUEUE_INFO_DOORBELL_ID:
|
||||
*(reinterpret_cast<uint64_t*>(value)) = 0;
|
||||
break;
|
||||
default: return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
return HSA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
#if 1
|
||||
|
||||
// Set the HSA agent for the active PCSamplingConfiguration,
|
||||
// The reason for setting HSA agent manually follows.
|
||||
// The test links against rocporifler static library.
|
||||
// Hence, the rocprofiler_set_api_table is not called.
|
||||
auto* service = rocprofiler::pc_sampling::get_active_pc_sampling_service().load();
|
||||
EXPECT_NE(service, nullptr);
|
||||
const auto* rocp_agent = cb_data.gpu_pcs_agents.at(0);
|
||||
auto agent_session = service->agent_sessions.at(rocp_agent->id).get();
|
||||
hsa_agent_t pseudo_hsa_agent = {.handle = 1};
|
||||
agent_session->hsa_agent = std::make_unique<hsa_agent_t>(pseudo_hsa_agent);
|
||||
|
||||
// TODO: We need to register the agent inside the parser
|
||||
rocprofiler::pc_sampling::hsa::get_pc_sampling_parser().register_buffer_for_agent(
|
||||
cb_data.client_buffer.handle, rocp_agent->id.handle);
|
||||
|
||||
// The following test calls some segments of internal PC sampling API implementation
|
||||
// by mimicking the HIP and ROCr
|
||||
|
||||
// Generate dispatch and marker packet
|
||||
rocprofiler::hsa::rocprofiler_packet dispatch_pkt;
|
||||
auto marker_pkt =
|
||||
rocprofiler::pc_sampling::hsa::generate_marker_packet_for_kernel(&dispatch_pkt);
|
||||
|
||||
// create a pseudo hsa queue
|
||||
hsa_queue_t queue;
|
||||
queue.size = 1024;
|
||||
// Mimic the ROCr and notify the pc sampling service that the marker packet has been encoutered.
|
||||
rocprofiler::pc_sampling::hsa::amd_intercept_marker_handler_callback(
|
||||
&marker_pkt.marker, &queue, 0);
|
||||
|
||||
// We need to generate some samples and send them via data_ready_calllback.
|
||||
size_t num_samples = NUM_SAMPLES;
|
||||
auto samples_data_size = num_samples * sizeof(packet_union_t);
|
||||
|
||||
static hsa_ven_amd_pcs_data_copy_callback_t hsa_mock_data_copy_callback =
|
||||
[](void* hsa_callback_data, size_t data_size, void* destination) {
|
||||
(void) hsa_callback_data;
|
||||
(void) data_size;
|
||||
using rocr_buffer_t = std::vector<packet_union_t>;
|
||||
auto samples_buff = rocr_buffer_t{};
|
||||
for(size_t i = 0; i < NUM_SAMPLES; i++)
|
||||
{
|
||||
perf_sample_host_trap_v1 hs;
|
||||
hs.pc = i + 1;
|
||||
hs.exec_mask = 0xF;
|
||||
hs.workgroup_id_x = 1;
|
||||
hs.workgroup_id_y = 2;
|
||||
hs.workgroup_id_z = 3;
|
||||
hs.chiplet_and_wave_id = 0;
|
||||
hs.hw_id = 0;
|
||||
hs.timestamp = 33 + i;
|
||||
hs.correlation_id = TRAP_ID;
|
||||
samples_buff.push_back(packet_union_t{.host = hs});
|
||||
}
|
||||
// copy the data
|
||||
std::memcpy(destination, samples_buff.data(), NUM_SAMPLES * sizeof(packet_union_t));
|
||||
// clear the data
|
||||
return HSA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
// calling data_ready_callback that will result in copying the data from above
|
||||
// to the client buffer via PC sampling parser
|
||||
rocprofiler::pc_sampling::PCSAgentSession pcs_agent_session;
|
||||
pcs_agent_session.agent = rocp_agent;
|
||||
pcs_agent_session.method = ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP;
|
||||
|
||||
size_t lost_samples = 0;
|
||||
|
||||
rocprofiler::pc_sampling::hsa::data_ready_callback(
|
||||
&pcs_agent_session, samples_data_size, lost_samples, hsa_mock_data_copy_callback, nullptr);
|
||||
|
||||
rocprofiler::pc_sampling::hsa::kernel_completion_cb(
|
||||
nullptr, rocp_agent, static_cast<int64_t>(1), dispatch_pkt, nullptr);
|
||||
|
||||
// Flush the buffer explicitly
|
||||
ROCPROFILER_CALL(rocprofiler_flush_buffer(cb_data.client_buffer),
|
||||
"rocprofiler flush buffer failed");
|
||||
// Stop the context
|
||||
ROCPROFILER_CALL(rocprofiler_stop_context(cb_data.client_ctx),
|
||||
"rocprofiler context stop failed");
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/rocprofiler-sdk/hsa/queue.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/cid_manager.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/agent.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
|
||||
#include <hsa/hsa.h>
|
||||
#include <hsa/hsa_ven_amd_pc_sampling.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
// forward declaration to avoid circular dependency
|
||||
class PCSCIDManager;
|
||||
|
||||
struct PCSAgentSession
|
||||
{
|
||||
const rocprofiler_agent_t* agent;
|
||||
rocprofiler_pc_sampling_method_t method;
|
||||
rocprofiler_pc_sampling_unit_t unit;
|
||||
uint64_t interval;
|
||||
rocprofiler_buffer_id_t buffer_id;
|
||||
// hsa relevant information
|
||||
std::optional<hsa_agent_t> hsa_agent = std::nullopt;
|
||||
hsa_ven_amd_pcs_t hsa_pc_sampling;
|
||||
hsa::ClientID intercept_cb_id{-1};
|
||||
// ioctl relevant information
|
||||
uint32_t ioctl_pcs_id;
|
||||
// PC sampling parser
|
||||
std::unique_ptr<PCSamplingParserContext> parser;
|
||||
// Manager responsible for retiring CIDs
|
||||
std::unique_ptr<PCSCIDManager> cid_manager;
|
||||
};
|
||||
|
||||
// TODO static assertions
|
||||
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,79 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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/pc_sampling/utils.hpp"
|
||||
#include "lib/rocprofiler-sdk/agent.hpp"
|
||||
|
||||
#include <hsa/hsa_ext_amd.h>
|
||||
#include <hsa/hsa_ven_amd_pc_sampling.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <glog/logging.h>
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
hsa_ven_amd_pcs_method_kind_t
|
||||
get_matching_hsa_pcs_method(rocprofiler_pc_sampling_method_t method)
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
case ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC: return HSA_VEN_AMD_PCS_METHOD_STOCHASTIC_V1;
|
||||
case ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP: return HSA_VEN_AMD_PCS_METHOD_HOSTTRAP_V1;
|
||||
default: throw std::runtime_error("Illegal pc sampling method\n");
|
||||
}
|
||||
}
|
||||
|
||||
hsa_ven_amd_pcs_units_t
|
||||
get_matching_hsa_pcs_units(rocprofiler_pc_sampling_unit_t unit)
|
||||
{
|
||||
switch(unit)
|
||||
{
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_NONE: break;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_INSTRUCTIONS:
|
||||
return HSA_VEN_AMD_PCS_INTERVAL_UNITS_INSTRUCTIONS;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_CYCLES:
|
||||
return HSA_VEN_AMD_PCS_INTERVAL_UNITS_CLOCK_CYCLES;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_TIME: return HSA_VEN_AMD_PCS_INTERVAL_UNITS_MICRO_SECONDS;
|
||||
case ROCPROFILER_PC_SAMPLING_UNIT_LAST: break;
|
||||
}
|
||||
|
||||
throw std::runtime_error("Illegal pc sampling units\n");
|
||||
}
|
||||
|
||||
uint64_t
|
||||
get_unique_correlation_id()
|
||||
{
|
||||
// TODO: Remove once we confirmed it is unnecessary.
|
||||
// Also, update the PC sampling parser not to decode correlation ID
|
||||
// (or always 0 for both internal/external correlation IDs)
|
||||
static auto _cnt = std::atomic<int>{0};
|
||||
return ++_cnt;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,62 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 ROCm Developer Tools
|
||||
//
|
||||
// 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 <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
|
||||
#include <hsa/hsa.h>
|
||||
#include <hsa/hsa_ven_amd_pc_sampling.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace pc_sampling
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
hsa_ven_amd_pcs_method_kind_t
|
||||
get_matching_hsa_pcs_method(rocprofiler_pc_sampling_method_t method);
|
||||
|
||||
hsa_ven_amd_pcs_units_t
|
||||
get_matching_hsa_pcs_units(rocprofiler_pc_sampling_unit_t unit);
|
||||
|
||||
inline constexpr size_t
|
||||
get_hsa_pcs_latency()
|
||||
{
|
||||
// TODO: Check with David about the default value in the hsa-runtime
|
||||
return 1000;
|
||||
}
|
||||
|
||||
inline constexpr size_t
|
||||
get_hsa_pcs_buffer_size()
|
||||
{
|
||||
// TODO: Find the minimum size of all buffers and use that.
|
||||
return 1024 * sizeof(perf_sample_hosttrap_v1_t);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
get_unique_correlation_id();
|
||||
} // namespace utils
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
@@ -39,6 +39,8 @@
|
||||
#include "lib/rocprofiler-sdk/internal_threading.hpp"
|
||||
#include "lib/rocprofiler-sdk/marker/marker.hpp"
|
||||
#include "lib/rocprofiler-sdk/page_migration/page_migration.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/code_object.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/context.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
@@ -601,6 +603,10 @@ finalize()
|
||||
hsa::async_copy_fini();
|
||||
hsa::queue_controller_fini();
|
||||
page_migration::finalize();
|
||||
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
|
||||
// WARNING: this must precede `code_object::finalize()`
|
||||
pc_sampling::code_object::finalize();
|
||||
#endif
|
||||
code_object::finalize();
|
||||
if(get_init_status() > 0)
|
||||
{
|
||||
@@ -753,6 +759,9 @@ rocprofiler_set_api_table(const char* name,
|
||||
|
||||
rocprofiler::hsa::async_copy_init(hsa_api_table, lib_instance);
|
||||
rocprofiler::code_object::initialize(hsa_api_table);
|
||||
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
|
||||
rocprofiler::pc_sampling::code_object::initialize(hsa_api_table);
|
||||
#endif
|
||||
|
||||
// install rocprofiler API wrappers
|
||||
rocprofiler::hsa::update_table(hsa_api_table->core_, lib_instance);
|
||||
@@ -761,6 +770,11 @@ rocprofiler_set_api_table(const char* name,
|
||||
rocprofiler::hsa::update_table(hsa_api_table->finalizer_ext_, lib_instance);
|
||||
rocprofiler::hsa::update_table(hsa_api_table->tools_, lib_instance);
|
||||
|
||||
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
|
||||
// Initialize PC sampling service if configured
|
||||
rocprofiler::pc_sampling::post_hsa_init_start_active_service();
|
||||
#endif
|
||||
|
||||
// allow tools to install API wrappers
|
||||
rocprofiler::intercept_table::notify_intercept_table_registration(
|
||||
ROCPROFILER_HSA_TABLE, lib_version, lib_instance, std::make_tuple(hsa_api_table));
|
||||
@@ -816,6 +830,7 @@ rocprofiler_set_api_table(const char* name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// #if 0
|
||||
bool
|
||||
OnLoad(HsaApiTable* table,
|
||||
uint64_t runtime_version,
|
||||
@@ -843,4 +858,5 @@ OnUnload()
|
||||
::rocprofiler::registration::finalize();
|
||||
ROCP_INFO << "Finalization complete.";
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
@@ -107,6 +107,11 @@ ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_NO_HARDWARE_COUNTERS,
|
||||
"Counter set does not include any hardware counters")
|
||||
ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_AGENT_MISMATCH,
|
||||
"Counter profile agent does not match the agent in the context")
|
||||
ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE,
|
||||
"The service is not available."
|
||||
"Please refer to API functions that return this status code"
|
||||
"for more information.")
|
||||
|
||||
template <size_t Idx, size_t... Tail>
|
||||
const char*
|
||||
get_status_name(rocprofiler_status_t status, std::index_sequence<Idx, Tail...>)
|
||||
|
||||
@@ -101,13 +101,11 @@ TEST(rocprofiler_lib, agent_abi)
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, vendor_name), 256) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, product_name), 264) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, model_name), 272) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, num_pc_sampling_configs), 280) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, pc_sampling_configs), 288) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, node_id), 296) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, logical_node_id), 300) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, node_id), 280) << msg;
|
||||
EXPECT_EQ(offsetof(rocprofiler_agent_t, logical_node_id), 284) << msg;
|
||||
// Add test for offset of new field above this. Do NOT change any existing values!
|
||||
|
||||
constexpr auto expected_rocp_agent_size = 304;
|
||||
constexpr auto expected_rocp_agent_size = 288;
|
||||
// If a new field is added, increase this value by the size of the new field(s)
|
||||
EXPECT_EQ(sizeof(rocprofiler_agent_t), expected_rocp_agent_size)
|
||||
<< "ABI break. If you added a new field, make sure that this is the only new check that "
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "lib/common/defines.hpp"
|
||||
#include "lib/rocprofiler-sdk/page_migration/details/kfd_ioctl.h"
|
||||
#include "lib/rocprofiler-sdk/details/kfd_ioctl.h"
|
||||
#include "lib/rocprofiler-sdk/page_migration/utils.hpp"
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
|
||||
Reference in New Issue
Block a user