[SDK][rocprofv3] MI300 Stochastic PC sampling (#92)
* MI300 Stochastic PC sampling SDK API implementation
* ROCProfV3: Stochastic PC sampling Support (#94)
* ROCProfV3: MI300 Stochastic PC sampling initial draft
* ROCProfV3: Initial Stochastic PC sampling Tests (#95)
ROCProfV3: Initial Stochastic PC sampling tests
* Update rocprofiler_pc_sampling_record_stochastic_v0_t
- update doxygen docs for members
- replace rocprofiler_correlation_id_t with rocprofiler_async_correlation_id_t
* Relax the check in JSON tests
* drain PC sampling buffer during finalize_rocprofv3
* Increase timeout for "Test Install Build" step
- 10 minutes -> 20 minutes
- "Test Installed Packages" has 20 minutes so "Test Install Build" should also
---------
Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
[ROCm/rocprofiler-sdk commit: 49ce79a5b5]
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <rocprofiler-sdk/external_correlation.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/internal_threading.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
#include <rocprofiler-sdk/rocprofiler.h>
|
||||
#include <rocprofiler-sdk/cxx/name_info.hpp>
|
||||
#include <rocprofiler-sdk/cxx/perfetto.hpp>
|
||||
@@ -930,6 +931,93 @@ save(ArchiveT& ar, rocprofiler_pc_sampling_record_host_trap_v0_t data)
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("wave_in_grp", wave_in_group);
|
||||
}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void
|
||||
save(ArchiveT& ar, rocprofiler_pc_sampling_record_stochastic_header_t data)
|
||||
{
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("has_mem_cnt", has_memory_counter);
|
||||
}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void
|
||||
save_pc_sampling_inst_type(ArchiveT& ar, rocprofiler_pc_sampling_instruction_type_t inst_type)
|
||||
{
|
||||
ar(make_nvp("inst_type",
|
||||
std::string(rocprofiler_get_pc_sampling_instruction_type_name(inst_type))));
|
||||
}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void
|
||||
save_pc_sampling_stall_reason(ArchiveT& ar,
|
||||
rocprofiler_pc_sampling_instruction_not_issued_reason_t stall_reason)
|
||||
{
|
||||
ar(make_nvp(
|
||||
"stall_reason",
|
||||
std::string(rocprofiler_get_pc_sampling_instruction_not_issued_reason_name(stall_reason))));
|
||||
}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void
|
||||
save(ArchiveT& ar, rocprofiler_pc_sampling_snapshot_v0_t data)
|
||||
{
|
||||
save_pc_sampling_stall_reason(
|
||||
ar,
|
||||
static_cast<rocprofiler_pc_sampling_instruction_not_issued_reason_t>(
|
||||
data.reason_not_issued));
|
||||
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("dual_issue_valu", dual_issue_valu);
|
||||
|
||||
// Arb state (pipe issued)
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_valu", arb_state_issue_valu);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_matrix", arb_state_issue_matrix);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_lds", arb_state_issue_lds);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_lds_direct", arb_state_issue_lds_direct);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_scalar", arb_state_issue_scalar);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_vmem_tex", arb_state_issue_vmem_tex);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_flat", arb_state_issue_flat);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_exp", arb_state_issue_exp);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_misc", arb_state_issue_misc);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_issue_brmsg", arb_state_issue_brmsg);
|
||||
// Arb state (pipe stalled)
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_valu", arb_state_stall_valu);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_matrix", arb_state_stall_matrix);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_lds", arb_state_stall_lds);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_lds_direct", arb_state_stall_lds_direct);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_scalar", arb_state_stall_scalar);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_vmem_tex", arb_state_stall_vmem_tex);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_flat", arb_state_stall_flat);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_exp", arb_state_stall_exp);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_misc", arb_state_stall_misc);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("arb_state_stall_brmsg", arb_state_stall_brmsg);
|
||||
}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void
|
||||
save(ArchiveT& ar, rocprofiler_pc_sampling_record_stochastic_v0_t data)
|
||||
{
|
||||
// flags specific for stochastic sampling
|
||||
ROCP_SDK_SAVE_DATA_FIELD(flags);
|
||||
|
||||
// Common for host-trap and stochastic
|
||||
ROCP_SDK_SAVE_DATA_FIELD(hw_id);
|
||||
ROCP_SDK_SAVE_DATA_FIELD(pc);
|
||||
ROCP_SDK_SAVE_DATA_FIELD(exec_mask);
|
||||
ROCP_SDK_SAVE_DATA_FIELD(timestamp);
|
||||
ROCP_SDK_SAVE_DATA_FIELD(dispatch_id);
|
||||
ROCP_SDK_SAVE_DATA_VALUE("corr_id", correlation_id);
|
||||
ROCP_SDK_SAVE_DATA_VALUE("wrkgrp_id", workgroup_id);
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("wave_in_grp", wave_in_group);
|
||||
|
||||
// fields specific for stochastic
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("wave_issued", wave_issued);
|
||||
save_pc_sampling_inst_type(
|
||||
ar, static_cast<rocprofiler_pc_sampling_instruction_type_t>(data.inst_type));
|
||||
ROCP_SDK_SAVE_DATA_BITFIELD("wave_cnt", wave_count);
|
||||
ROCP_SDK_SAVE_DATA_FIELD(snapshot);
|
||||
|
||||
// TODO: add memory counters
|
||||
}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void
|
||||
save(ArchiveT& ar, rocprofiler_agent_io_link_t data)
|
||||
|
||||
@@ -475,8 +475,9 @@ typedef enum
|
||||
typedef enum
|
||||
{
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_NONE = 0,
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_INVALID_SAMPLE, ///< ::rocprofiler_pc_sampling_record_invalid_t
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_HOST_TRAP_V0_SAMPLE, ///< ::rocprofiler_pc_sampling_record_host_trap_v0_t
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_STOCHASTIC_V0_SAMPLE, ///< for the future use
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_STOCHASTIC_V0_SAMPLE, ///< ::rocprofiler_pc_sampling_record_stochastic_v0_t
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_LAST,
|
||||
} rocprofiler_pc_sampling_record_kind_t;
|
||||
|
||||
|
||||
@@ -106,11 +106,13 @@ ROCPROFILER_EXTERN_C_INIT
|
||||
* 1. PC sampling is already configured with configuration different than requested,
|
||||
* 2. PC sampling is requested from a process that runs within the ROCgdb.
|
||||
* 3. HSA runtime does not support PC sampling.
|
||||
* 4. GPU device does not support requested PC sampling method.
|
||||
* @retval ::ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL the amdgpu driver installed on the system
|
||||
* does not support the PC sampling feature
|
||||
* @retval ::ROCPROFILER_STATUS_ERROR a general error caused by the amdgpu driver
|
||||
* @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT counter collection service already
|
||||
* setup in the context
|
||||
* @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT function invoked with an invalid argument
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
rocprofiler_configure_pc_sampling_service(rocprofiler_context_id_t context_id,
|
||||
@@ -121,6 +123,19 @@ rocprofiler_configure_pc_sampling_service(rocprofiler_context_id_t conte
|
||||
rocprofiler_buffer_id_t buffer_id,
|
||||
int flags) ROCPROFILER_API;
|
||||
|
||||
/**
|
||||
* @brief Enumeration describing values of flags of ::rocprofiler_pc_sampling_configuration_t.
|
||||
*/
|
||||
typedef enum rocprofiler_pc_sampling_configuration_flags_t
|
||||
{
|
||||
ROCPROFILER_PC_SAMPLING_CONFIGURATION_FLAGS_NONE = 0,
|
||||
ROCPROFILER_PC_SAMPLING_CONFIGURATION_FLAGS_INTERVAL_POW2,
|
||||
ROCPROFILER_PC_SAMPLING_CONFIGURATION_FLAGS_LAST
|
||||
|
||||
/// @var ROCPROFILER_PC_SAMPLING_CONFIGURATION_FLAGS_INTERVAL_POW2
|
||||
/// @brief The interval value must be a power of 2.
|
||||
} rocprofiler_pc_sampling_configuration_flags_t;
|
||||
|
||||
/**
|
||||
* @brief PC sampling configuration supported by a GPU agent.
|
||||
*/
|
||||
@@ -131,7 +146,7 @@ typedef struct
|
||||
rocprofiler_pc_sampling_unit_t unit;
|
||||
size_t min_interval;
|
||||
size_t max_interval;
|
||||
uint64_t flags; /// for future use
|
||||
uint64_t flags; ///< take values from ::rocprofiler_pc_sampling_configuration_flags_t
|
||||
|
||||
/// @var method
|
||||
/// @brief Sampling method supported by the GPU agent.
|
||||
@@ -202,12 +217,11 @@ rocprofiler_query_pc_sampling_agent_configurations(
|
||||
*/
|
||||
typedef struct rocprofiler_pc_sampling_hw_id_v0_t
|
||||
{
|
||||
uint64_t chiplet : 6; ///< chiplet index (3 bits allocated by the ROCr runtime)
|
||||
uint64_t wave_id : 7; ///< wave slot index
|
||||
uint64_t simd_id : 2; ///< SIMD index
|
||||
uint64_t pipe_id : 4; ///< pipe index
|
||||
uint64_t cu_or_wgp_id : 4; ///< Index of compute unit on GFX9 or workgroup processer on other
|
||||
///< architectures
|
||||
uint64_t chiplet : 6; ///< chiplet index (3 bits allocated by the ROCr runtime)
|
||||
uint64_t wave_id : 7; ///< wave slot index
|
||||
uint64_t simd_id : 2; ///< SIMD index
|
||||
uint64_t pipe_id : 4; ///< pipe index
|
||||
uint64_t cu_or_wgp_id : 4;
|
||||
uint64_t shader_array_id : 1; ///< Shared array index
|
||||
uint64_t shader_engine_id : 5; ///< shared engine index
|
||||
uint64_t workgroup_id : 7; ///< thread_group index on GFX9, and workgroup index on GFX10+
|
||||
@@ -215,6 +229,9 @@ typedef struct rocprofiler_pc_sampling_hw_id_v0_t
|
||||
uint64_t queue_id : 4; ///< queue id
|
||||
uint64_t microengine_id : 2; ///< ACE (microengine) index
|
||||
uint64_t reserved0 : 16; ///< Reserved for the future use
|
||||
|
||||
/// @var cu_or_wgp_id
|
||||
/// @brief Compute unit index on GFX9 or workgroup processor index on GFX10+.
|
||||
} rocprofiler_pc_sampling_hw_id_v0_t;
|
||||
|
||||
/**
|
||||
@@ -242,7 +259,6 @@ typedef struct
|
||||
/// @ref code_object_id is equal to the ::ROCPROFILER_CODE_OBJECT_ID_NONE.
|
||||
} rocprofiler_pc_t;
|
||||
|
||||
// TODO: The definition of this struct might change over time.
|
||||
/**
|
||||
* @brief ROCProfiler Host-Trap PC Sampling Record.
|
||||
*/
|
||||
@@ -263,6 +279,239 @@ typedef struct rocprofiler_pc_sampling_record_host_trap_v0_t
|
||||
/// @brief API launch call id that matches dispatch ID
|
||||
} rocprofiler_pc_sampling_record_host_trap_v0_t;
|
||||
|
||||
/**
|
||||
* @brief The header of the @ref rocprofiler_pc_sampling_record_stochastic_v0_t, indicating
|
||||
* what fields of the @ref rocprofiler_pc_sampling_record_stochastic_v0_t instance are meaningful
|
||||
* for the sample.
|
||||
*/
|
||||
typedef struct rocprofiler_pc_sampling_record_stochastic_header_t
|
||||
{
|
||||
uint8_t has_memory_counter : 1; ///< pc sample provides memory counters information
|
||||
///< via ::rocprofiler_pc_sampling_memory_counters_t
|
||||
uint8_t reserved_type : 7;
|
||||
} rocprofiler_pc_sampling_record_stochastic_header_t;
|
||||
|
||||
/**
|
||||
* @brief Enumeration describing type of sampled issued instruction.
|
||||
*/
|
||||
typedef enum rocprofiler_pc_sampling_instruction_type_t
|
||||
{
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_NONE = 0,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_VALU, ///< vector ALU instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_MATRIX, ///< matrix instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_SCALAR, ///< scalar (memory) instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_TEX, ///< texture memory instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_LDS, ///< LDS memory instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_LDS_DIRECT, ///< LDS direct memory instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_FLAT, ///< flat memory instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_EXPORT, ///< export instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_MESSAGE, ///< message instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BARRIER, ///< barrier instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BRANCH_NOT_TAKEN,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BRANCH_TAKEN,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_JUMP, ///< jump instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_OTHER, ///< other types of instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_NO_INST, ///< no instruction issued
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_DUAL_VALU, /// dual VALU instruction
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_LAST
|
||||
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BRANCH_NOT_TAKEN
|
||||
/// @brief Instruction representing a branch not being taken.
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BRANCH_TAKEN
|
||||
/// @brief Instruction representing a taken branch.
|
||||
} rocprofiler_pc_sampling_instruction_type_t;
|
||||
|
||||
/**
|
||||
* @brief Enumeration describing reason for not issuing an instruction.
|
||||
*/
|
||||
typedef enum rocprofiler_pc_sampling_instruction_not_issued_reason_t
|
||||
{
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_NONE = 0,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_NO_INSTRUCTION_AVAILABLE,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ALU_DEPENDENCY,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_WAITCNT, ///< waitcnt dependency
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_INTERNAL_INSTRUCTION,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_BARRIER_WAIT, ///< waiting on a barrier
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ARBITER_NOT_WIN,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ARBITER_WIN_EX_STALL,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_OTHER_WAIT,
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_SLEEP_WAIT, ///< wave was sleeping
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_LAST
|
||||
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_NO_INSTRUCTION_AVAILABLE
|
||||
/// @brief No instruction available in the instruction cache.
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ALU_DEPENDENCY
|
||||
/// @brief ALU dependency not resolved.
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_INTERNAL_INSTRUCTION
|
||||
/// @brief Wave executes an internal instruction.
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ARBITER_NOT_WIN
|
||||
/// @brief The instruction did not win the arbiter.
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ARBITER_WIN_EX_STALL
|
||||
/// @brief Arbiter issued an instruction, but the execution pipe pushed it back from execution.
|
||||
/// @var ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_OTHER_WAIT
|
||||
/// @brief Other types of wait (e.g., wait for XNACK acknowledgment).
|
||||
|
||||
} rocprofiler_pc_sampling_instruction_not_issued_reason_t;
|
||||
|
||||
/**
|
||||
* @brief Data provided by stochastic sampling hardware.
|
||||
*
|
||||
*/
|
||||
typedef struct rocprofiler_pc_sampling_snapshot_v0_t
|
||||
{
|
||||
uint32_t reason_not_issued : 4;
|
||||
uint32_t reserved0 : 1; ///< reserved for future use
|
||||
uint32_t arb_state_issue_valu : 1; ///< arbiter issued a VALU instruction
|
||||
uint32_t arb_state_issue_matrix : 1; ///< arbiter issued a matrix instruction
|
||||
uint32_t arb_state_issue_lds : 1; ///< arbiter issued a LDS instruction
|
||||
uint32_t arb_state_issue_lds_direct : 1; ///< arbiter issued a LDS direct instruction
|
||||
uint32_t arb_state_issue_scalar : 1; ///< arbiter issued a scalar (SALU/SMEM) instruction
|
||||
uint32_t arb_state_issue_vmem_tex : 1; ///< arbiter issued a texture instruction
|
||||
uint32_t arb_state_issue_flat : 1; ///< arbiter issued a FLAT instruction
|
||||
uint32_t arb_state_issue_exp : 1; ///< arbiter issued a export instruction
|
||||
uint32_t arb_state_issue_misc : 1; ///< arbiter issued a miscellaneous instruction
|
||||
uint32_t arb_state_issue_brmsg : 1; ///< arbiter issued a branch/message instruction
|
||||
uint32_t arb_state_issue_reserved : 1; ///< reserved for the future use
|
||||
uint32_t arb_state_stall_valu : 1;
|
||||
uint32_t arb_state_stall_matrix : 1; ///< matrix instruction was stalled
|
||||
uint32_t arb_state_stall_lds : 1; ///< LDS instruction was stalled
|
||||
uint32_t arb_state_stall_lds_direct : 1; ///< LDS direct instruction was stalled
|
||||
uint32_t arb_state_stall_scalar : 1; ///< Scalar (SALU/SMEM) instruction was stalled
|
||||
uint32_t arb_state_stall_vmem_tex : 1; ///< texture instruction was stalled
|
||||
uint32_t arb_state_stall_flat : 1; ///< flat instruction was stalled
|
||||
uint32_t arb_state_stall_exp : 1; ///< export instruction was stalled
|
||||
uint32_t arb_state_stall_misc : 1; ///< miscellaneous instruction was stalled
|
||||
uint32_t arb_state_stall_brmsg : 1; ///< branch/message instruction was stalled
|
||||
uint32_t arb_state_state_reserved : 1; ///< reserved for the future use
|
||||
// We have two reserved bits
|
||||
uint32_t dual_issue_valu : 1;
|
||||
uint32_t reserved1 : 1; ///< reserved for the future use
|
||||
uint32_t reserved2 : 3; ///< reserved for the future use
|
||||
|
||||
/// @var reason_not_issued
|
||||
/// @brief The reason for not issuing an instruction. The field takes one of the value defined
|
||||
/// in @ref ::rocprofiler_pc_sampling_instruction_not_issued_reason_t
|
||||
/// @var arb_state_stall_valu
|
||||
/// @brief VALU instruction was stalled when a sample was generated
|
||||
/// @var dual_issue_valu
|
||||
/// @brief Two VALU instructions were issued for coexecution (MI3xx specific)
|
||||
} rocprofiler_pc_sampling_snapshot_v0_t;
|
||||
|
||||
/**
|
||||
* @brief Counters of issued but not yet completed instructions.
|
||||
*/
|
||||
typedef struct rocprofiler_pc_sampling_memory_counters_t
|
||||
{
|
||||
uint32_t load_cnt : 6;
|
||||
uint32_t store_cnt : 6;
|
||||
uint32_t bvh_cnt : 3;
|
||||
uint32_t sample_cnt : 6;
|
||||
uint32_t ds_cnt : 6;
|
||||
uint32_t km_cnt : 5;
|
||||
|
||||
/// @var load_cnt
|
||||
/// @brief Counts the number of VMEM load instructions issued but not yet completed.
|
||||
/// @var store_cnt
|
||||
/// @brief Counts the number of VMEM store instructions issued but not yet completed.
|
||||
/// @var bvh_cnt
|
||||
/// @brief Counts the number of VMEM BVH instructions issued but not yet completed.
|
||||
/// @var sample_cnt
|
||||
/// @brief Counts the number of VMEM sample instructions issued but not yet completed.
|
||||
/// @var ds_cnt
|
||||
/// @brief Counts the number of LDS instructions issued but not yet completed.
|
||||
/// @var km_cnt
|
||||
/// @brief Counts the number of scalar memory reads and memory instructions issued but not yet
|
||||
/// completed.
|
||||
} rocprofiler_pc_sampling_memory_counters_t;
|
||||
|
||||
/**
|
||||
* @brief ROCProfiler Stochastic PC Sampling Record.
|
||||
*/
|
||||
typedef struct rocprofiler_pc_sampling_record_stochastic_v0_t
|
||||
{
|
||||
uint64_t size; ///< Size of this struct
|
||||
rocprofiler_pc_sampling_record_stochastic_header_t flags;
|
||||
uint8_t wave_in_group;
|
||||
uint8_t wave_issued : 1;
|
||||
uint8_t inst_type : 5;
|
||||
uint8_t reserved : 2;
|
||||
rocprofiler_pc_sampling_hw_id_v0_t hw_id;
|
||||
rocprofiler_pc_t pc;
|
||||
uint64_t exec_mask;
|
||||
rocprofiler_dim3_t workgroup_id;
|
||||
uint32_t wave_count;
|
||||
uint64_t timestamp;
|
||||
uint64_t dispatch_id;
|
||||
rocprofiler_async_correlation_id_t correlation_id;
|
||||
rocprofiler_pc_sampling_snapshot_v0_t snapshot;
|
||||
rocprofiler_pc_sampling_memory_counters_t memory_counters;
|
||||
|
||||
/// @var flags
|
||||
/// @brief Defines what fields are meaningful for the sample.
|
||||
/// @var wave_in_group
|
||||
/// @brief wave position within the workgroup (0-15)
|
||||
/// @var wave_issued
|
||||
/// @brief wave issued the instruction represented with the PC
|
||||
/// @var inst_type
|
||||
/// @brief instruction type, takes a value defined in @ref
|
||||
/// ::rocprofiler_pc_sampling_instruction_type_t
|
||||
/// @var reserved
|
||||
/// @brief reserved 2 bits must be zero
|
||||
/// @var hw_id
|
||||
/// @brief @see ::rocprofiler_pc_sampling_hw_id_v0_t
|
||||
/// @var pc
|
||||
/// @brief information about sampled program counter
|
||||
/// @var exec_mask
|
||||
/// @brief active SIMD lanes at the moment of sampling
|
||||
/// @var workgroup_id
|
||||
/// @brief wave coordinates within the workgroup
|
||||
/// @var wave_count
|
||||
/// @brief active waves on the CU at the moment of sampling
|
||||
/// @var timestamp
|
||||
/// @brief timestamp when sample is generated
|
||||
/// @var dispatch_id
|
||||
/// @brief originating kernel dispatch ID
|
||||
/// @var correlation_id
|
||||
/// @brief API launch call id that matches dispatch ID
|
||||
/// @var snapshot
|
||||
/// @brief Data provided by stochastic sampling hardware. @see
|
||||
/// ::rocprofiler_pc_sampling_snapshot_v0_t
|
||||
/// @var memory_counters
|
||||
/// @brief Counters of issued but not yet completed instructions. @see
|
||||
/// ::rocprofiler_pc_sampling_memory_counters_t
|
||||
} rocprofiler_pc_sampling_record_stochastic_v0_t;
|
||||
|
||||
/**
|
||||
* @brief Record representing an invalid PC Sampling Record.
|
||||
*/
|
||||
typedef struct rocprofiler_pc_sampling_record_invalid_t
|
||||
{
|
||||
uint64_t size; ///< Size of the struct
|
||||
} rocprofiler_pc_sampling_record_invalid_t;
|
||||
|
||||
/**
|
||||
* @fn C compatible string representation of the PC sampling instruction type
|
||||
* @brief Return the string encoding of @ref rocprofiler_pc_sampling_instruction_type_t value
|
||||
* @param [in] instruction_type instruction type enum value
|
||||
* @return Will return a nullptr if invalid/unsupported @ref
|
||||
* rocprofiler_pc_sampling_instruction_type_t value is provided.
|
||||
*/
|
||||
const char*
|
||||
rocprofiler_get_pc_sampling_instruction_type_name(
|
||||
rocprofiler_pc_sampling_instruction_type_t instruction_type) ROCPROFILER_API;
|
||||
|
||||
/**
|
||||
* @fn C compatible string representation of reason for not issuing an instruciton
|
||||
* @brief Return the string encoding of @ref rocprofiler_pc_sampling_instruction_not_issued_reason_t
|
||||
* value
|
||||
* @param [in] not_issued_reason no issue reason enum value
|
||||
* @return Will return a nullptr if invalid/unsupported @ref
|
||||
* rocprofiler_pc_sampling_instruction_not_issued_reason_t value is provided.
|
||||
*/
|
||||
const char*
|
||||
rocprofiler_get_pc_sampling_instruction_not_issued_reason_name(
|
||||
rocprofiler_pc_sampling_instruction_not_issued_reason_t not_issued_reason) ROCPROFILER_API;
|
||||
|
||||
/** @} */
|
||||
|
||||
ROCPROFILER_EXTERN_C_FINI
|
||||
|
||||
@@ -168,5 +168,8 @@ using kernel_dispatch_buffered_output_with_stream_t =
|
||||
domain_type::KERNEL_DISPATCH>;
|
||||
using memory_copy_buffered_output_with_stream_t =
|
||||
buffered_output<tool_buffer_tracing_memory_copy_with_stream_record_t, domain_type::MEMORY_COPY>;
|
||||
using pc_sampling_stochastic_buffered_output_t =
|
||||
buffered_output<rocprofiler::tool::rocprofiler_tool_pc_sampling_stochastic_record_t,
|
||||
domain_type::PC_SAMPLING_STOCHASTIC>;
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -111,6 +111,7 @@ using stats_csv_encoder = csv_encoder<8>;
|
||||
using pc_sampling_host_trap_csv_encoder = csv_encoder<6>;
|
||||
using kernel_trace_with_stream_csv_encoder = csv_encoder<19>;
|
||||
using memory_copy_with_stream_csv_encoder = csv_encoder<8>;
|
||||
using pc_sampling_stochastic_csv_encoder = csv_encoder<10>;
|
||||
} // namespace csv
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -63,6 +63,10 @@ DEFINE_BUFFER_TYPE_NAME(PC_SAMPLING_HOST_TRAP,
|
||||
"pc_sampling_host_trap_stats")
|
||||
DEFINE_BUFFER_TYPE_NAME(ROCDECODE, "ROCDECODE_API", "rocdecode_api_trace", "rocdecode_api_stats")
|
||||
DEFINE_BUFFER_TYPE_NAME(ROCJPEG, "ROCJPEG_API", "rocjpeg_api_trace", "rocjpeg_api_stats")
|
||||
DEFINE_BUFFER_TYPE_NAME(PC_SAMPLING_STOCHASTIC,
|
||||
"PC_SAMPLING_STOCHASTIC",
|
||||
"pc_sampling_stochastic",
|
||||
"pc_sampling_stochastic_stats")
|
||||
|
||||
#undef DEFINE_BUFFER_TYPE_NAME
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ enum class domain_type
|
||||
PC_SAMPLING_HOST_TRAP,
|
||||
ROCDECODE,
|
||||
ROCJPEG,
|
||||
PC_SAMPLING_STOCHASTIC,
|
||||
LAST,
|
||||
};
|
||||
|
||||
|
||||
@@ -877,6 +877,79 @@ generate_csv(const output_config& c
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_stochastic_record_t>& data,
|
||||
const stats_entry_t& stats)
|
||||
{
|
||||
if(data.empty()) return;
|
||||
|
||||
if(cfg.stats && stats)
|
||||
write_stats(get_stats_output_file(cfg, domain_type::PC_SAMPLING_STOCHASTIC), stats.entries);
|
||||
|
||||
auto ofs = tool::csv_output_file{cfg,
|
||||
domain_type::PC_SAMPLING_STOCHASTIC,
|
||||
tool::csv::pc_sampling_stochastic_csv_encoder{},
|
||||
{
|
||||
"Sample_Timestamp",
|
||||
"Exec_Mask",
|
||||
"Dispatch_Id",
|
||||
"Instruction",
|
||||
"Instruction_Comment",
|
||||
"Correlation_Id",
|
||||
"Wave_Issued_Instruction",
|
||||
"Instruction_Type",
|
||||
"Stall_Reason",
|
||||
"Wave_Count",
|
||||
}};
|
||||
for(auto ditr : data)
|
||||
{
|
||||
for(const auto& record : data.get(ditr))
|
||||
{
|
||||
std::string inst;
|
||||
std::string inst_comment;
|
||||
if(record.inst_index == -1)
|
||||
{
|
||||
// A sample originates from a blit kernel or self-modifying code,
|
||||
// so instruction cannot be decoded
|
||||
inst_comment = "Unrecognized code object id, physical virtual address of PC:" +
|
||||
std::to_string(record.pc_sample_record.pc.code_object_offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Provide decoded instruction and comment
|
||||
inst = tool_metadata.get_instruction(record.inst_index);
|
||||
inst_comment = tool_metadata.get_comment(record.inst_index);
|
||||
}
|
||||
|
||||
auto row_ss = std::stringstream{};
|
||||
rocprofiler::tool::csv::pc_sampling_stochastic_csv_encoder::write_row(
|
||||
row_ss,
|
||||
record.pc_sample_record.timestamp,
|
||||
record.pc_sample_record.exec_mask,
|
||||
record.pc_sample_record.dispatch_id,
|
||||
inst,
|
||||
inst_comment,
|
||||
record.pc_sample_record.correlation_id.internal,
|
||||
// As wave_issued is uint8_t of size 1, it can be dumped as char.
|
||||
// To prevent that, explicitly cast it to integer, so that CSV output
|
||||
// shows human-readable 0/1 values.
|
||||
static_cast<unsigned int>(record.pc_sample_record.wave_issued),
|
||||
std::string(rocprofiler_get_pc_sampling_instruction_type_name(
|
||||
static_cast<rocprofiler_pc_sampling_instruction_type_t>(
|
||||
record.pc_sample_record.inst_type))),
|
||||
std::string(rocprofiler_get_pc_sampling_instruction_not_issued_reason_name(
|
||||
static_cast<rocprofiler_pc_sampling_instruction_not_issued_reason_t>(
|
||||
record.pc_sample_record.snapshot.reason_not_issued))),
|
||||
// Similar reasoning as for wave_issued.
|
||||
static_cast<unsigned int>(record.pc_sample_record.wave_count));
|
||||
|
||||
ofs << row_ss.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& /*tool_metadata*/,
|
||||
|
||||
@@ -110,6 +110,12 @@ generate_csv(const output_config& c
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& data,
|
||||
const stats_entry_t& stats);
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_stochastic_record_t>& data,
|
||||
const stats_entry_t& stats);
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
|
||||
@@ -196,10 +196,10 @@ write_json(json_output& json_ar,
|
||||
generator<rocprofiler_buffer_tracing_scratch_memory_record_t> scratch_memory_gen,
|
||||
generator<rocprofiler_buffer_tracing_rccl_api_record_t> rccl_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_gen,
|
||||
generator<rocprofiler_buffer_tracing_rocdecode_api_record_t> rocdecode_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t> rocjpeg_api_gen)
|
||||
|
||||
generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t> rocjpeg_api_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_host_trap_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_stochastic_record_t> pc_sampling_stochastic_gen)
|
||||
{
|
||||
// summary
|
||||
{
|
||||
@@ -239,9 +239,10 @@ write_json(json_output& json_ar,
|
||||
json_ar(cereal::make_nvp("memory_copy", memory_copy_gen));
|
||||
json_ar(cereal::make_nvp("memory_allocation", memory_allocation_gen));
|
||||
json_ar(cereal::make_nvp("scratch_memory", scratch_memory_gen));
|
||||
json_ar(cereal::make_nvp("pc_sample_host_trap", pc_sampling_gen));
|
||||
json_ar(cereal::make_nvp("rocdecode_api", rocdecode_api_gen));
|
||||
json_ar(cereal::make_nvp("rocjpeg_api", rocjpeg_api_gen));
|
||||
json_ar(cereal::make_nvp("pc_sample_host_trap", pc_sampling_host_trap_gen));
|
||||
json_ar(cereal::make_nvp("pc_sample_stochastic", pc_sampling_stochastic_gen));
|
||||
json_ar.finishNode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ write_json(json_output& j
|
||||
generator<rocprofiler_buffer_tracing_scratch_memory_record_t> scratch_memory_gen,
|
||||
generator<rocprofiler_buffer_tracing_rccl_api_record_t> rccl_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_gen,
|
||||
generator<rocprofiler_buffer_tracing_rocdecode_api_record_t> rocdecode_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t> rocjpeg_api_gen);
|
||||
|
||||
generator<rocprofiler_buffer_tracing_rocjpeg_api_record_t> rocjpeg_api_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_host_trap_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_stochastic_record_t> pc_sampling_stochastic_gen);
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -453,7 +453,23 @@ generate_stats(const output_config& /* cfg*/,
|
||||
const metadata& /*tool_metadata*/,
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& /*data*/)
|
||||
{
|
||||
// TODO:
|
||||
// 1. Implement serialization for PC sampling stats.
|
||||
// The format differs significantly from tracing stats.
|
||||
// 2. Decide what is going to be part of the stats.
|
||||
// Some basic information is already available in the tool_metadata.pc_sampling_stats.
|
||||
// This contains the total number of valid VS invalid samples.
|
||||
return stats_entry_t{};
|
||||
}
|
||||
|
||||
stats_entry_t
|
||||
generate_stats(const output_config& /* cfg*/,
|
||||
const metadata& /*tool_metadata*/,
|
||||
const generator<rocprofiler_tool_pc_sampling_stochastic_record_t>& /*data*/)
|
||||
{
|
||||
// TODO: sames TODOS from the function above applies here.
|
||||
return stats_entry_t{};
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -90,6 +90,12 @@ stats_entry_t
|
||||
generate_stats(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& data);
|
||||
|
||||
stats_entry_t
|
||||
generate_stats(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_stochastic_record_t>& data);
|
||||
|
||||
void
|
||||
generate_stats(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
|
||||
@@ -87,6 +87,9 @@ using att_filenames_map_t = std::unordered_map<rocprofiler_dispatch_id_t, att_
|
||||
using code_object_load_info_vec_t = std::vector<rocprofiler::att_wrapper::CodeobjLoadInfo>;
|
||||
template <typename Tp>
|
||||
using synced_map = common::Synchronized<Tp, true>;
|
||||
template <typename Tp>
|
||||
using synced_obj = common::Synchronized<Tp, true>;
|
||||
using pc_sampling_stats_t = rocprofiler_tool_pc_sampling_stats;
|
||||
|
||||
enum class agent_indexing
|
||||
{
|
||||
@@ -133,6 +136,7 @@ struct metadata
|
||||
synced_map<host_function_info_map_t> host_functions = {};
|
||||
synced_map<code_object_load_info_vec_t> code_object_load = {};
|
||||
att_filenames_map_t att_filenames = {};
|
||||
synced_obj<pc_sampling_stats_t> pc_sampling_stats = {};
|
||||
|
||||
metadata() = default;
|
||||
metadata(inprocess);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
#include <rocprofiler-sdk/cxx/codeobj/code_printing.hpp>
|
||||
#include <rocprofiler-sdk/cxx/serialization.hpp>
|
||||
|
||||
@@ -79,5 +80,32 @@ struct rocprofiler_tool_pc_sampling_host_trap_record_t
|
||||
}
|
||||
};
|
||||
|
||||
// TODO:: Check if we can template this structure
|
||||
struct rocprofiler_tool_pc_sampling_stochastic_record_t
|
||||
{
|
||||
rocprofiler_pc_sampling_record_stochastic_v0_t pc_sample_record;
|
||||
int64_t inst_index;
|
||||
|
||||
rocprofiler_tool_pc_sampling_stochastic_record_t(
|
||||
rocprofiler_pc_sampling_record_stochastic_v0_t record,
|
||||
int64_t index)
|
||||
: pc_sample_record(record)
|
||||
, inst_index(index)
|
||||
{}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void save(ArchiveT& ar) const
|
||||
{
|
||||
ar(cereal::make_nvp("record", pc_sample_record));
|
||||
ar(cereal::make_nvp("inst_index", inst_index));
|
||||
}
|
||||
};
|
||||
|
||||
struct rocprofiler_tool_pc_sampling_stats
|
||||
{
|
||||
uint64_t valid_samples = 0;
|
||||
uint64_t invalid_samples = 0;
|
||||
};
|
||||
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -285,10 +285,28 @@ config::config()
|
||||
{"stochastic", ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC},
|
||||
{"host_trap", ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP}};
|
||||
|
||||
pc_sampling_method_value = pc_sampling_method_map.at(pc_sampling_method);
|
||||
try
|
||||
{
|
||||
pc_sampling_method_value = pc_sampling_method_map.at(pc_sampling_method);
|
||||
} catch(...)
|
||||
{
|
||||
ROCP_FATAL << "Invalid value for ROCPROF_PC_SAMPLING_METHOD: " << pc_sampling_method << "."
|
||||
<< "Valid choices are stochastic and host_trap\n";
|
||||
}
|
||||
|
||||
if(pc_sampling_method_value == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
pc_sampling_host_trap = true;
|
||||
pc_sampling_unit_value = pc_sampling_unit_map.at(pc_sampling_unit);
|
||||
else if(pc_sampling_method_value == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
pc_sampling_stochastic = true;
|
||||
|
||||
try
|
||||
{
|
||||
pc_sampling_unit_value = pc_sampling_unit_map.at(pc_sampling_unit);
|
||||
} catch(...)
|
||||
{
|
||||
ROCP_FATAL << "Invalid value for ROCPROF_PC_SAMPLING_UNIT: " << pc_sampling_unit << "."
|
||||
<< "Valid choices are instructions, cycles and time\n";
|
||||
}
|
||||
|
||||
if(auto _collection_period = get_env("ROCPROF_COLLECTION_PERIOD", "");
|
||||
!_collection_period.empty())
|
||||
|
||||
@@ -116,6 +116,7 @@ struct config : output_config
|
||||
bool list_metrics_output_file = get_env("ROCPROF_OUTPUT_LIST_METRICS_FILE", false);
|
||||
bool pc_sampling_host_trap = false;
|
||||
bool advanced_thread_trace = get_env("ROCPROF_ADVANCED_THREAD_TRACE", false);
|
||||
bool pc_sampling_stochastic = false;
|
||||
size_t pc_sampling_interval = get_env("ROCPROF_PC_SAMPLING_INTERVAL", 1);
|
||||
bool att_serialize_all = get_env("ROCPROF_ATT_PARAM_SERIALIZE_ALL", false);
|
||||
rocprofiler_pc_sampling_method_t pc_sampling_method_value = ROCPROFILER_PC_SAMPLING_METHOD_NONE;
|
||||
|
||||
@@ -147,10 +147,11 @@ struct buffer_ids
|
||||
rocprofiler_buffer_id_t pc_sampling_host_trap = {};
|
||||
rocprofiler_buffer_id_t rocdecode_api_trace = {};
|
||||
rocprofiler_buffer_id_t rocjpeg_api_trace = {};
|
||||
rocprofiler_buffer_id_t pc_sampling_stochastic = {};
|
||||
|
||||
auto as_array() const
|
||||
{
|
||||
return std::array<rocprofiler_buffer_id_t, 11>{hsa_api_trace,
|
||||
return std::array<rocprofiler_buffer_id_t, 12>{hsa_api_trace,
|
||||
hip_api_trace,
|
||||
kernel_trace,
|
||||
memory_copy_trace,
|
||||
@@ -160,7 +161,8 @@ struct buffer_ids
|
||||
rccl_api_trace,
|
||||
pc_sampling_host_trap,
|
||||
rocdecode_api_trace,
|
||||
rocjpeg_api_trace};
|
||||
rocjpeg_api_trace,
|
||||
pc_sampling_stochastic};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -726,7 +728,8 @@ code_object_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
auto* obj_data = static_cast<tool::rocprofiler_code_object_info_t*>(record.payload);
|
||||
|
||||
CHECK_NOTNULL(tool_metadata)->add_code_object(*obj_data);
|
||||
if(tool::get_config().pc_sampling_host_trap)
|
||||
if(tool::get_config().pc_sampling_host_trap ||
|
||||
tool::get_config().pc_sampling_stochastic)
|
||||
{
|
||||
CHECK_NOTNULL(tool_metadata)->add_decoder(obj_data);
|
||||
}
|
||||
@@ -1178,6 +1181,10 @@ rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /* context_id*/,
|
||||
{
|
||||
if(!headers) return;
|
||||
|
||||
// count number of valid VS invalid samples delivered by this callback
|
||||
uint64_t valid_samples_cnt = 0;
|
||||
uint64_t invalid_samples_cnt = 0;
|
||||
|
||||
for(size_t i = 0; i < num_headers; i++)
|
||||
{
|
||||
auto* cur_header = headers[i];
|
||||
@@ -1202,6 +1209,25 @@ rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /* context_id*/,
|
||||
|
||||
rocprofiler::tool::write_ring_buffer(pc_sample_tool_record,
|
||||
domain_type::PC_SAMPLING_HOST_TRAP);
|
||||
|
||||
valid_samples_cnt++;
|
||||
}
|
||||
else if(cur_header->kind == ROCPROFILER_PC_SAMPLING_RECORD_STOCHASTIC_V0_SAMPLE)
|
||||
{
|
||||
auto* pc_sample = static_cast<rocprofiler_pc_sampling_record_stochastic_v0_t*>(
|
||||
cur_header->payload);
|
||||
|
||||
auto pc_sample_tool_record =
|
||||
rocprofiler::tool::rocprofiler_tool_pc_sampling_stochastic_record_t(
|
||||
*pc_sample, get_instruction_index(pc_sample->pc));
|
||||
|
||||
rocprofiler::tool::write_ring_buffer(pc_sample_tool_record,
|
||||
domain_type::PC_SAMPLING_STOCHASTIC);
|
||||
valid_samples_cnt++;
|
||||
}
|
||||
else if(cur_header->kind == ROCPROFILER_PC_SAMPLING_RECORD_INVALID_SAMPLE)
|
||||
{
|
||||
invalid_samples_cnt++;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1209,6 +1235,13 @@ rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /* context_id*/,
|
||||
ROCP_FATAL << "unexpected rocprofiler_record_header_t category + kind";
|
||||
}
|
||||
}
|
||||
|
||||
// sum up number of valid/invalid samples for pc sampling stats
|
||||
tool_metadata->pc_sampling_stats.wlock(
|
||||
[valid_samples_cnt, invalid_samples_cnt](auto& pc_sampling_stats) {
|
||||
pc_sampling_stats.valid_samples += valid_samples_cnt;
|
||||
pc_sampling_stats.invalid_samples += invalid_samples_cnt;
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1377,6 +1410,52 @@ if_pc_sample_config_match(rocprofiler_agent_id_t agent_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
configure_pc_sampling_on_all_agents(uint64_t buffer_size,
|
||||
uint64_t buffer_watermark,
|
||||
void* tool_data)
|
||||
{
|
||||
auto method = tool::get_config().pc_sampling_method_value;
|
||||
auto unit = tool::get_config().pc_sampling_unit_value;
|
||||
|
||||
// Find the proper buffer_id based on the method
|
||||
auto* buffer_id = (method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
? &get_buffers().pc_sampling_host_trap
|
||||
: &get_buffers().pc_sampling_stochastic;
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(get_client_ctx(),
|
||||
buffer_size,
|
||||
buffer_watermark,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
tool_data,
|
||||
buffer_id),
|
||||
"buffer creation");
|
||||
|
||||
bool config_match_found = false;
|
||||
auto agent_ptr_vec = get_gpu_agents();
|
||||
for(auto& itr : agent_ptr_vec)
|
||||
{
|
||||
if(if_pc_sample_config_match(
|
||||
itr->id, method, unit, tool::get_config().pc_sampling_interval))
|
||||
{
|
||||
config_match_found = true;
|
||||
int flags = 0;
|
||||
ROCPROFILER_CALL(
|
||||
rocprofiler_configure_pc_sampling_service(get_client_ctx(),
|
||||
itr->id,
|
||||
method,
|
||||
unit,
|
||||
tool::get_config().pc_sampling_interval,
|
||||
*buffer_id,
|
||||
flags),
|
||||
"configure PC sampling");
|
||||
}
|
||||
}
|
||||
if(!config_match_found)
|
||||
ROCP_FATAL << "Given PC sampling configuration is not supported on any of the agents";
|
||||
}
|
||||
|
||||
int
|
||||
tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
{
|
||||
@@ -1745,38 +1824,11 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
|
||||
if(tool::get_config().pc_sampling_host_trap)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(get_client_ctx(),
|
||||
buffer_size,
|
||||
buffer_watermark,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
tool_data,
|
||||
&get_buffers().pc_sampling_host_trap),
|
||||
"buffer creation");
|
||||
bool config_match_found = false;
|
||||
auto agent_ptr_vec = get_gpu_agents();
|
||||
for(auto& itr : agent_ptr_vec)
|
||||
{
|
||||
auto method = tool::get_config().pc_sampling_method_value;
|
||||
auto unit = tool::get_config().pc_sampling_unit_value;
|
||||
if(if_pc_sample_config_match(
|
||||
itr->id, method, unit, tool::get_config().pc_sampling_interval))
|
||||
{
|
||||
config_match_found = true;
|
||||
int flags = 0;
|
||||
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(
|
||||
get_client_ctx(),
|
||||
itr->id,
|
||||
method,
|
||||
unit,
|
||||
tool::get_config().pc_sampling_interval,
|
||||
get_buffers().pc_sampling_host_trap,
|
||||
flags),
|
||||
"configure PC sampling");
|
||||
}
|
||||
}
|
||||
if(!config_match_found)
|
||||
ROCP_FATAL << "Given PC sampling configuration is not supported on any of the agents";
|
||||
configure_pc_sampling_on_all_agents(buffer_size, buffer_watermark, tool_data);
|
||||
}
|
||||
else if(tool::get_config().pc_sampling_stochastic)
|
||||
{
|
||||
configure_pc_sampling_on_all_agents(buffer_size, buffer_watermark, tool_data);
|
||||
}
|
||||
|
||||
for(auto itr : get_buffers().as_array())
|
||||
@@ -1897,6 +1949,8 @@ tool_fini(void* /*tool_data*/)
|
||||
auto rocdecode_output =
|
||||
tool::rocdecode_buffered_output_t{tool::get_config().rocdecode_api_trace};
|
||||
auto rocjpeg_output = tool::rocjpeg_buffered_output_t{tool::get_config().rocjpeg_api_trace};
|
||||
auto pc_sampling_stochastic_output =
|
||||
tool::pc_sampling_stochastic_buffered_output_t{tool::get_config().pc_sampling_stochastic};
|
||||
|
||||
auto node_id_sort = [](const auto& lhs, const auto& rhs) { return lhs.node_id < rhs.node_id; };
|
||||
auto agents_output = CHECK_NOTNULL(tool_metadata)->agents;
|
||||
@@ -1917,6 +1971,7 @@ tool_fini(void* /*tool_data*/)
|
||||
generate_output(rocdecode_output, num_output, contributions);
|
||||
generate_output(pc_sampling_host_trap_output, num_output, contributions);
|
||||
generate_output(rocjpeg_output, num_output, contributions);
|
||||
generate_output(pc_sampling_stochastic_output, num_output, contributions);
|
||||
|
||||
if(tool::get_config().advanced_thread_trace && !tool::get_config().att_capability.empty() &&
|
||||
!tool_metadata->att_filenames.empty())
|
||||
@@ -1955,9 +2010,10 @@ tool_fini(void* /*tool_data*/)
|
||||
scratch_memory_output.get_generator(),
|
||||
rccl_output.get_generator(),
|
||||
memory_allocation_output.get_generator(),
|
||||
pc_sampling_host_trap_output.get_generator(),
|
||||
rocdecode_output.get_generator(),
|
||||
rocjpeg_output.get_generator());
|
||||
rocjpeg_output.get_generator(),
|
||||
pc_sampling_host_trap_output.get_generator(),
|
||||
pc_sampling_stochastic_output.get_generator());
|
||||
json_ar.finish_process();
|
||||
|
||||
tool::close_json(json_ar);
|
||||
@@ -2074,6 +2130,7 @@ tool_fini(void* /*tool_data*/)
|
||||
destroy_output(pc_sampling_host_trap_output);
|
||||
destroy_output(rocdecode_output);
|
||||
destroy_output(rocjpeg_output);
|
||||
destroy_output(pc_sampling_stochastic_output);
|
||||
|
||||
if(kernel_rename_and_stream_display_pair_dtors != nullptr)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,87 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
#define ROCPROFILER_INSTRUCTION_TYPE_STRING(CODE) \
|
||||
template <> \
|
||||
struct instruction_type_string<CODE> \
|
||||
{ \
|
||||
static constexpr auto name = #CODE; \
|
||||
};
|
||||
|
||||
#define ROCPROFILER_NO_ISSUE_REASON_STRING(CODE) \
|
||||
template <> \
|
||||
struct no_issue_reason_string<CODE> \
|
||||
{ \
|
||||
static constexpr auto name = #CODE; \
|
||||
};
|
||||
|
||||
template <size_t Idx>
|
||||
struct instruction_type_string;
|
||||
|
||||
template <size_t Idx>
|
||||
struct no_issue_reason_string;
|
||||
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_NONE);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_VALU);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_MATRIX);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_SCALAR);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_TEX);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_LDS);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_LDS_DIRECT);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_FLAT);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_EXPORT);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_MESSAGE);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BARRIER);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BRANCH_NOT_TAKEN);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_BRANCH_TAKEN);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_JUMP);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_OTHER);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_NO_INST);
|
||||
ROCPROFILER_INSTRUCTION_TYPE_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_DUAL_VALU);
|
||||
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_NONE);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_NO_INSTRUCTION_AVAILABLE);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ALU_DEPENDENCY);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_WAITCNT);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_INTERNAL_INSTRUCTION);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_BARRIER_WAIT);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ARBITER_NOT_WIN);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_ARBITER_WIN_EX_STALL);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_OTHER_WAIT);
|
||||
ROCPROFILER_NO_ISSUE_REASON_STRING(
|
||||
ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_SLEEP_WAIT);
|
||||
|
||||
template <size_t Idx, size_t... Tail>
|
||||
const char*
|
||||
get_instruction_type_name(rocprofiler_pc_sampling_instruction_type_t instruction_type,
|
||||
std::index_sequence<Idx, Tail...>)
|
||||
{
|
||||
if(instruction_type == Idx) return instruction_type_string<Idx>::name;
|
||||
// recursion until tail empty
|
||||
if constexpr(sizeof...(Tail) > 0)
|
||||
return get_instruction_type_name(instruction_type, std::index_sequence<Tail...>{});
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <size_t Idx, size_t... Tail>
|
||||
const char*
|
||||
get_no_issue_reason_name(rocprofiler_pc_sampling_instruction_not_issued_reason_t no_issue_reason,
|
||||
std::index_sequence<Idx, Tail...>)
|
||||
{
|
||||
if(no_issue_reason == Idx) return no_issue_reason_string<Idx>::name;
|
||||
// recursion until tail empty
|
||||
if constexpr(sizeof...(Tail) > 0)
|
||||
return get_no_issue_reason_name(no_issue_reason, std::index_sequence<Tail...>{});
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
@@ -130,4 +211,22 @@ rocprofiler_query_pc_sampling_agent_configurations(
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char*
|
||||
rocprofiler_get_pc_sampling_instruction_type_name(
|
||||
rocprofiler_pc_sampling_instruction_type_t instruction_type)
|
||||
{
|
||||
return get_instruction_type_name(
|
||||
instruction_type,
|
||||
std::make_index_sequence<ROCPROFILER_PC_SAMPLING_INSTRUCTION_TYPE_LAST>{});
|
||||
}
|
||||
|
||||
const char*
|
||||
rocprofiler_get_pc_sampling_instruction_not_issued_reason_name(
|
||||
rocprofiler_pc_sampling_instruction_not_issued_reason_t not_issued_reason)
|
||||
{
|
||||
return get_no_issue_reason_name(
|
||||
not_issued_reason,
|
||||
std::make_index_sequence<ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED_REASON_LAST>{});
|
||||
}
|
||||
}
|
||||
|
||||
+198
-77
@@ -46,17 +46,46 @@ namespace
|
||||
{
|
||||
#define PC_SAMPLING_IOCTL_BITMASK 0xFFFF
|
||||
|
||||
/**
|
||||
* @brief Used to determine the version of PC sampling
|
||||
* IOCTL implementation in the driver.
|
||||
*
|
||||
* @todo Remove this once the KFD IOCTL is upstreamed
|
||||
*/
|
||||
struct pc_sampling_ioctl_version_t
|
||||
#define PC_SAMPLING_IOCTL_COMPUTE_VERSION(major, minor) ROCPROFILER_COMPUTE_VERSION(major, minor, 0)
|
||||
|
||||
using pcs_ioctl_version_t = uint32_t;
|
||||
|
||||
#define KFD_ROCP_PCS_METHOD_PAIR(KFD_ENUM_VAL, ROCP_ENUM_VAL) \
|
||||
template <> \
|
||||
struct pcs_method_pair<KFD_ENUM_VAL> \
|
||||
{ \
|
||||
static constexpr auto rocp_enum_val = ROCP_ENUM_VAL; \
|
||||
};
|
||||
|
||||
template <size_t Idx>
|
||||
struct pcs_method_pair;
|
||||
|
||||
KFD_ROCP_PCS_METHOD_PAIR(ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_NONE,
|
||||
ROCPROFILER_PC_SAMPLING_METHOD_NONE);
|
||||
KFD_ROCP_PCS_METHOD_PAIR(ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_HOSTTRAP_V1,
|
||||
ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP);
|
||||
KFD_ROCP_PCS_METHOD_PAIR(ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_STOCHASTIC_V1,
|
||||
ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC);
|
||||
|
||||
template <size_t Idx, size_t... Tail>
|
||||
rocprofiler_pc_sampling_method_t
|
||||
get_rocp_pcs_method(rocprofiler_ioctl_pc_sampling_method_kind_t kfd_method,
|
||||
std::index_sequence<Idx, Tail...>)
|
||||
{
|
||||
uint32_t major_version; /// PC sampling IOCTL major version
|
||||
uint32_t minor_version; /// PC sampling IOCTL minor version
|
||||
};
|
||||
if(kfd_method == Idx) return pcs_method_pair<Idx>::rocp_enum_val;
|
||||
// recursion until tail empty
|
||||
if constexpr(sizeof...(Tail) > 0)
|
||||
return get_rocp_pcs_method(kfd_method, std::index_sequence<Tail...>{});
|
||||
// Return none value if matching fails
|
||||
return ROCPROFILER_PC_SAMPLING_METHOD_NONE;
|
||||
}
|
||||
|
||||
rocprofiler_pc_sampling_method_t
|
||||
get_rocp_pcs_method_from_kfd(rocprofiler_ioctl_pc_sampling_method_kind_t kfd_method)
|
||||
{
|
||||
return get_rocp_pcs_method(
|
||||
kfd_method, std::make_index_sequence<ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_LAST>{});
|
||||
}
|
||||
|
||||
int
|
||||
kfd_open()
|
||||
@@ -137,7 +166,7 @@ get_ioctl_version(rocprofiler_ioctl_version_info_t& ioctl_version)
|
||||
* @return ::rocprofiler_status_t
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
get_pc_sampling_ioctl_version(uint32_t kfd_gpu_id, pc_sampling_ioctl_version_t& pcs_ioctl_version)
|
||||
get_pc_sampling_ioctl_version(uint32_t kfd_gpu_id, pcs_ioctl_version_t* pcs_ioctl_version)
|
||||
{
|
||||
struct kfd_ioctl_pc_sample_args args;
|
||||
args.op = KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES;
|
||||
@@ -172,29 +201,27 @@ get_pc_sampling_ioctl_version(uint32_t kfd_gpu_id, pc_sampling_ioctl_version_t&
|
||||
// `version` field contains PC Sampling IOCTL version
|
||||
auto version = args.version;
|
||||
// Lower 16 bits represent minor version
|
||||
pcs_ioctl_version.minor_version = version & PC_SAMPLING_IOCTL_BITMASK;
|
||||
auto minor_version = version & PC_SAMPLING_IOCTL_BITMASK;
|
||||
// Upper 16 bits represent major version
|
||||
pcs_ioctl_version.major_version = (version >> 16) & PC_SAMPLING_IOCTL_BITMASK;
|
||||
auto major_version = (version >> 16) & PC_SAMPLING_IOCTL_BITMASK;
|
||||
// finally, compute the version
|
||||
*pcs_ioctl_version = PC_SAMPLING_IOCTL_COMPUTE_VERSION(major_version, minor_version);
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if PC sampling is supported on the device with @p kfd_gpu_id.
|
||||
* @brief Check if PC sampling feature is supported in KFD.
|
||||
*
|
||||
* Starting from KFD IOCTL 1.16, KFD delivers beta implementation of the PC sampling.
|
||||
* Furthermore, ROCProfiler-SDK expects PC sampling IOCTL 0.1 version.
|
||||
* @todo: Once KFD is upstreamed, ROCProfiler-SDK will rely only on KFD IOCTL version.
|
||||
*
|
||||
* @return ::rocprofiler_status_t
|
||||
* @retval ::ROCPROFILER_STATUS_SUCCESS PC sampling is supported in the driver.
|
||||
* Other values informs users about the reason why PC sampling is not supported.
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
is_pc_sampling_supported(const rocprofiler_agent_t* agent)
|
||||
is_pc_sampling_supported()
|
||||
{
|
||||
auto kfd_gpu_id = agent->gpu_id;
|
||||
std::string_view agent_name = agent->name;
|
||||
// Verify KFD 1.16 version
|
||||
rocprofiler_ioctl_version_info_t ioctl_version = {.major_version = 0, .minor_version = 0};
|
||||
auto status = get_ioctl_version(ioctl_version);
|
||||
@@ -208,58 +235,131 @@ is_pc_sampling_supported(const rocprofiler_agent_t* agent)
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
|
||||
// TODO: remove once KFD is upstreamed
|
||||
// Verify PC sampling IOCTL version
|
||||
pc_sampling_ioctl_version_t pcs_ioctl_version = {.major_version = 0, .minor_version = 0};
|
||||
status = get_pc_sampling_ioctl_version(kfd_gpu_id, pcs_ioctl_version);
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS)
|
||||
// PC Sampling feature is supported in the driver.
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if PC sampling method is supported on the agent.
|
||||
*
|
||||
* The function complements the @ref is_pc_sampling_supported function.
|
||||
* It introduces a strict check against the PC sampling IOCTL version
|
||||
* that tells us whether a certain PC sampling method is safe to be used
|
||||
* on the specific device architecture.
|
||||
*
|
||||
* @param method - PC sampling method to be checked
|
||||
* @param agent - The agent to be checked
|
||||
* @param pcs_ioctl_version - The PC sampling IOCTL version
|
||||
* @return ::rocprofiler_status_t
|
||||
* @retval ::ROCPROFILER_STATUS_SUCCESS - The method is supported
|
||||
* Other values informs users about the reason why the method is not supported.
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
is_pc_sampling_method_supported(rocprofiler_pc_sampling_method_t method,
|
||||
const rocprofiler_agent_t* agent,
|
||||
pcs_ioctl_version_t pcs_ioctl_version)
|
||||
{
|
||||
std::string_view agent_name = agent->name;
|
||||
if(method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
{
|
||||
// The reason for not emitting the "PC sampling unavailable" message is the following.
|
||||
// Assume that all devices except one support PC sampling on the system.
|
||||
// By emitting the message for that one device that doesn't support PC sampling,
|
||||
// all tests and samples are skipped. Instead, tests and samples will ignore
|
||||
// that one problematic device and continue using PC sampling on other devices
|
||||
// that support this feature.
|
||||
return status;
|
||||
if(agent_name == "gfx90a")
|
||||
{
|
||||
// 0.1 version enables host-trap PC sampling on gfx90a
|
||||
if(pcs_ioctl_version >= PC_SAMPLING_IOCTL_COMPUTE_VERSION(0, 1))
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
else if(agent_name.find("gfx94") == 0)
|
||||
{
|
||||
// 0.3 version enables host-trap PC sampling on gfx940, gfx941, gfx942, etc.
|
||||
if(pcs_ioctl_version >= PC_SAMPLING_IOCTL_COMPUTE_VERSION(0, 3))
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
else if(agent_name.find("gfx95") == 0)
|
||||
{
|
||||
// 1.2 version enables host-trap PC sampling on gfx950
|
||||
if(pcs_ioctl_version >= PC_SAMPLING_IOCTL_COMPUTE_VERSION(1, 2))
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
}
|
||||
else if(agent_name == "gfx90a")
|
||||
else if(method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
{
|
||||
// For gfx90a, we expect PC sampling IOCTL to be at least 0.1.
|
||||
if(pcs_ioctl_version.major_version > 0 || pcs_ioctl_version.minor_version >= 1)
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
else if(agent_name.find("gfx94") == 0)
|
||||
{
|
||||
// We expect PC sampling IOCTL to be at least 0.3 for gfx940, gfx941, gfx942, etc.
|
||||
if(pcs_ioctl_version.major_version > 0 || pcs_ioctl_version.minor_version >= 3)
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
else if(agent_name.find("gfx95") == 0)
|
||||
{
|
||||
// As I am not sure if the PCS IOCTL is going to be bumped for gfx950,
|
||||
// I introduced a separate branch for it.
|
||||
// We expect PC sampling IOCTL to be at least 0.3 for gfx950.
|
||||
if(pcs_ioctl_version.major_version > 0 || pcs_ioctl_version.minor_version >= 3)
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
if(agent_name == "gfx90a")
|
||||
{
|
||||
// gfx90a doesn't support stochastic PC sampling
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
else if(agent_name.find("gfx94") == 0)
|
||||
{
|
||||
// 1.3 version enables stochastic PC sampling on gfx940, gfx941, gfx942, etc.
|
||||
if(pcs_ioctl_version >= PC_SAMPLING_IOCTL_COMPUTE_VERSION(1, 3))
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
else if(agent_name.find("gfx95") == 0)
|
||||
{
|
||||
// 1.4 version enables stochastic PC sampling on gfx950
|
||||
if(pcs_ioctl_version >= PC_SAMPLING_IOCTL_COMPUTE_VERSION(1, 4))
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
else
|
||||
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The agent does not support PC sampling.
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Other architecture do not support the PC sampling method.
|
||||
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the PC sampling IOCTL version if the PC sampling feature is supported in the
|
||||
* driver.
|
||||
*
|
||||
* First, check the minimal driver version via @ref is_pc_sampling_supported.
|
||||
* Then, determines the PC sampling IOCTL version via @ref get_pc_sampling_ioctl_version.
|
||||
*
|
||||
* @param [in] kfd_gpu_id - The KFD GPU identifier
|
||||
* @param [out] pcs_ioctl_version_t - The PC sampling IOCTL version
|
||||
* @return ::rocprofiler_status_t
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
get_pcs_ioctl_version_if_kfd_supports(uint32_t kfd_gpu_id, pcs_ioctl_version_t* pcs_ioctl_version)
|
||||
{
|
||||
// Check if the PC sampling feature is supported in the driver
|
||||
auto status = is_pc_sampling_supported();
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
|
||||
|
||||
// Get the PC sampling IOCTL version
|
||||
status = get_pc_sampling_ioctl_version(kfd_gpu_id, pcs_ioctl_version);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Same as @ref is_pc_sampling_method_supported.
|
||||
*/
|
||||
rocprofiler_status_t
|
||||
is_pc_sampling_method_supported(rocprofiler_ioctl_pc_sampling_method_kind_t ioctl_method,
|
||||
const rocprofiler_agent_t* agent,
|
||||
pcs_ioctl_version_t pcs_ioctl_version)
|
||||
{
|
||||
auto rocp_method = get_rocp_pcs_method_from_kfd(ioctl_method);
|
||||
return is_pc_sampling_method_supported(rocp_method, agent, pcs_ioctl_version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
rocprofiler_ioctl_status_t
|
||||
ioctl_query_pc_sampling_capabilities(uint32_t kfd_gpu_id,
|
||||
void* sample_info,
|
||||
uint32_t sample_info_sz,
|
||||
@@ -366,8 +466,9 @@ get_kfd_fd()
|
||||
rocprofiler_status_t
|
||||
ioctl_query_pcs_configs(const rocprofiler_agent_t* agent, rocp_pcs_cfgs_vec_t& rocp_configs)
|
||||
{
|
||||
if(auto status = is_pc_sampling_supported(agent); status != ROCPROFILER_STATUS_SUCCESS)
|
||||
return status;
|
||||
pcs_ioctl_version_t pcs_ioctl_version = 0;
|
||||
auto status = get_pcs_ioctl_version_if_kfd_supports(agent->gpu_id, &pcs_ioctl_version);
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
|
||||
|
||||
uint32_t kfd_gpu_id = agent->gpu_id;
|
||||
|
||||
@@ -400,8 +501,15 @@ ioctl_query_pcs_configs(const rocprofiler_agent_t* agent, rocp_pcs_cfgs_vec_t& r
|
||||
{
|
||||
// FIXME: Why this happens?
|
||||
if(ioctl_cfg.method == 0) continue;
|
||||
// Skip showing stochastic sampling until it's fully supported.
|
||||
if(ioctl_cfg.method == ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_STOCHASTIC_V1) continue;
|
||||
|
||||
// Strict check whether the driver version (safely) supports the sampling method for
|
||||
// this specific device architecture.
|
||||
// If not, skip showing this configuration to the user, as it's not safe to use this
|
||||
// sampling method on this device.
|
||||
if(is_pc_sampling_method_supported(ioctl_cfg.method, agent, pcs_ioctl_version) !=
|
||||
ROCPROFILER_STATUS_SUCCESS)
|
||||
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)
|
||||
@@ -470,12 +578,15 @@ ioctl_pcs_create(const rocprofiler_agent_t* agent,
|
||||
uint64_t interval,
|
||||
uint32_t* ioctl_pcs_id)
|
||||
{
|
||||
if(auto status = is_pc_sampling_supported(agent); status != ROCPROFILER_STATUS_SUCCESS)
|
||||
return status;
|
||||
pcs_ioctl_version_t pcs_ioctl_version = 0;
|
||||
auto status = get_pcs_ioctl_version_if_kfd_supports(agent->gpu_id, &pcs_ioctl_version);
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
|
||||
|
||||
// Block configuring stochastic sampling until it's fully supported.
|
||||
if(method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
// Strict check: whether the driver version (safely) supports the sampling method for
|
||||
// this specific device architecture. If not, return an error and prevent the user from
|
||||
// using this sampling method on this device.
|
||||
status = is_pc_sampling_method_supported(method, agent, pcs_ioctl_version);
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
|
||||
|
||||
rocprofiler_ioctl_pc_sampling_info_t ioctl_cfg;
|
||||
auto ret = create_ioctl_pcs_config_from_rocp(ioctl_cfg, method, unit, interval);
|
||||
@@ -501,17 +612,27 @@ ioctl_pcs_create(const rocprofiler_agent_t* agent,
|
||||
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))
|
||||
if(ioctl_ret != 0)
|
||||
{
|
||||
// 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;
|
||||
if(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(errno == EINVAL)
|
||||
{
|
||||
// invalid argument (e.g., interval must be power of 2, but a value that's
|
||||
// not power of 2 is provided)
|
||||
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
// generic error
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
|
||||
+14
-12
@@ -43,7 +43,7 @@ namespace ioctl
|
||||
// 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
|
||||
typedef enum rocprofiler_ioctl_status_t
|
||||
{
|
||||
ROCPROFILER_IOCTL_STATUS_SUCCESS = 0, /// Operation successful // USED
|
||||
ROCPROFILER_IOCTL_STATUS_ERROR = 1, /// General error return if not otherwise specified // USED
|
||||
@@ -72,7 +72,7 @@ typedef enum _ROCPROFILER_IOCTL_STATUS
|
||||
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;
|
||||
} rocprofiler_ioctl_status_t;
|
||||
|
||||
typedef struct rocprofiler_ioctl_version_info_s
|
||||
{
|
||||
@@ -80,27 +80,29 @@ typedef struct rocprofiler_ioctl_version_info_s
|
||||
uint32_t minor_version; /// supported IOCTL interface minor version
|
||||
} rocprofiler_ioctl_version_info_t;
|
||||
|
||||
typedef enum _ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND
|
||||
typedef enum rocprofiler_ioctl_pc_sampling_method_kind_t
|
||||
{
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_NONE = 0,
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_HOSTTRAP_V1 = 1,
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_STOCHASTIC_V1,
|
||||
} ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND;
|
||||
ROCPROFILER_IOCTL_PC_SAMPLING_METHOD_KIND_LAST,
|
||||
} rocprofiler_ioctl_pc_sampling_method_kind_t;
|
||||
|
||||
typedef enum _ROCPROFILER_IOCTL_PC_SAMPLING_UNITS
|
||||
typedef enum rocprofiler_ioctl_pc_sampling_unit_interval_t
|
||||
{
|
||||
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;
|
||||
} rocprofiler_ioctl_pc_sampling_unit_interval_t;
|
||||
|
||||
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;
|
||||
uint64_t interval;
|
||||
uint64_t interval_min;
|
||||
uint64_t interval_max;
|
||||
uint64_t flags;
|
||||
rocprofiler_ioctl_pc_sampling_method_kind_t method;
|
||||
rocprofiler_ioctl_pc_sampling_unit_interval_t units;
|
||||
} rocprofiler_ioctl_pc_sampling_info_t;
|
||||
|
||||
} // namespace ioctl
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_SOURCES pc_record_interface.cpp)
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS
|
||||
correlation.hpp gfx9.hpp gfx11.hpp parser_types.hpp pc_record_interface.hpp rocr.h
|
||||
stochastic_records.h translation.hpp)
|
||||
translation.hpp)
|
||||
|
||||
target_sources(
|
||||
rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_SOURCES}
|
||||
|
||||
@@ -241,6 +241,8 @@ add_upcoming_samples(const device_handle device,
|
||||
|
||||
auto& pc_sample = samples[p];
|
||||
pc_sample = copySample<GFXIP, PcSamplingRecordT>((const void*) (buffer + p));
|
||||
// skip invalid samples
|
||||
if(pc_sample.size == 0) continue;
|
||||
|
||||
// Convert PC -> (loaded code object id containing PC, offset within code object)
|
||||
if(!cache_addr_range.inrange(snap->pc))
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
TYPE_TEX,
|
||||
TYPE_LDS,
|
||||
TYPE_LDS_DIRECT,
|
||||
TYPE_EXP,
|
||||
TYPE_EXPORT,
|
||||
TYPE_MESSAGE,
|
||||
TYPE_BARRIER,
|
||||
TYPE_BRANCH_NOT_TAKEN,
|
||||
@@ -47,15 +47,15 @@ public:
|
||||
|
||||
enum reason_not_issued
|
||||
{
|
||||
REASON_NOT_AVAILABLE = 0,
|
||||
REASON_ALU,
|
||||
REASON_NO_INSTRUCTION_AVAILABLE = 0,
|
||||
REASON_ALU_DEPENDENCY,
|
||||
REASON_WAITCNT,
|
||||
REASON_ARBITER,
|
||||
REASON_SLEEP,
|
||||
REASON_BARRIER,
|
||||
REASON_ARBITER_NOT_WIN,
|
||||
REASON_SLEEP_WAIT,
|
||||
REASON_BARRIER_WAIT,
|
||||
REASON_OTHER_WAIT,
|
||||
REASON_INTERNAL = 31,
|
||||
REASON_EX_STALL = 31,
|
||||
REASON_INTERNAL_INSTRUCTION = 31,
|
||||
REASON_ARBITER_WIN_EX_STALL = 31,
|
||||
};
|
||||
|
||||
enum arb_state
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
class GFX9
|
||||
{
|
||||
public:
|
||||
// matches values specified in perf_snapshot_data register
|
||||
enum inst_type_issued
|
||||
{
|
||||
TYPE_VALU = 0,
|
||||
@@ -33,7 +34,7 @@ public:
|
||||
TYPE_TEX,
|
||||
TYPE_LDS,
|
||||
TYPE_FLAT,
|
||||
TYPE_EXP,
|
||||
TYPE_EXPORT,
|
||||
TYPE_MESSAGE,
|
||||
TYPE_BARRIER,
|
||||
TYPE_BRANCH_NOT_TAKEN,
|
||||
@@ -46,30 +47,32 @@ public:
|
||||
TYPE_LDS_DIRECT = 31
|
||||
};
|
||||
|
||||
// matces values specified in perf_snapshot_data register
|
||||
enum reason_not_issued
|
||||
{
|
||||
REASON_NOT_AVAILABLE = 0,
|
||||
REASON_ALU,
|
||||
REASON_NO_INSTRUCTION_AVAILABLE = 0,
|
||||
REASON_ALU_DEPENDENCY,
|
||||
REASON_WAITCNT,
|
||||
REASON_INTERNAL,
|
||||
REASON_BARRIER,
|
||||
REASON_ARBITER,
|
||||
REASON_EX_STALL,
|
||||
REASON_INTERNAL_INSTRUCTION,
|
||||
REASON_BARRIER_WAIT,
|
||||
REASON_ARBITER_NOT_WIN,
|
||||
REASON_ARBITER_WIN_EX_STALL,
|
||||
REASON_OTHER_WAIT,
|
||||
REASON_LAST,
|
||||
REASON_SLEEP = 31
|
||||
REASON_SLEEP_WAIT = 31
|
||||
};
|
||||
|
||||
// matches the order of arb_state bits in perf_snapshot_data register
|
||||
enum arb_state
|
||||
{
|
||||
ISSUE_VALU = 0,
|
||||
ISSUE_MATRIX,
|
||||
ISSUE_SCALAR,
|
||||
ISSUE_VMEM_TEX,
|
||||
ISSUE_LDS,
|
||||
ISSUE_FLAT,
|
||||
ISSUE_MISC = 0,
|
||||
ISSUE_EXP,
|
||||
ISSUE_MISC,
|
||||
ISSUE_FLAT,
|
||||
ISSUE_LDS,
|
||||
ISSUE_VMEM_TEX,
|
||||
ISSUE_SCALAR,
|
||||
ISSUE_MATRIX,
|
||||
ISSUE_VALU,
|
||||
ISSUE_LAST,
|
||||
ISSUE_LDS_DIRECT = 31,
|
||||
ISSUE_BRMSG = 31,
|
||||
|
||||
+40
-2
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
|
||||
#include "lib/common/utility.hpp"
|
||||
|
||||
template <>
|
||||
uint64_t
|
||||
PCSamplingParserContext::alloc<rocprofiler_pc_sampling_record_host_trap_v0_t>(
|
||||
@@ -127,6 +129,43 @@ PCSamplingParserContext::shouldFlipRocrBuffer(const dispatch_pkt_id_t& pkt) cons
|
||||
return corr_map->checkDispatch(pkt);
|
||||
}
|
||||
|
||||
template <typename PcSamplingRecordKindT>
|
||||
inline void
|
||||
emplace_records_in_buffer(rocprofiler::buffer::instance* buff,
|
||||
const PcSamplingRecordKindT* samples,
|
||||
size_t num_samples,
|
||||
rocprofiler_pc_sampling_record_kind_t record_kind)
|
||||
{
|
||||
for(size_t i = 0; i < num_samples; i++)
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING, record_kind, samples[i]);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void
|
||||
emplace_records_in_buffer<rocprofiler_pc_sampling_record_stochastic_v0_t>(
|
||||
rocprofiler::buffer::instance* buff,
|
||||
const rocprofiler_pc_sampling_record_stochastic_v0_t* samples,
|
||||
size_t num_samples,
|
||||
rocprofiler_pc_sampling_record_kind_t record_kind)
|
||||
{
|
||||
for(size_t i = 0; i < num_samples; i++)
|
||||
{
|
||||
if(samples[i].size == 0)
|
||||
{
|
||||
// `size == 0` internally means invalid sample, so generate it.
|
||||
auto invalid_sample = rocprofiler::common::init_public_api_struct(
|
||||
rocprofiler_pc_sampling_record_invalid_t{});
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING,
|
||||
ROCPROFILER_PC_SAMPLING_RECORD_INVALID_SAMPLE,
|
||||
invalid_sample);
|
||||
}
|
||||
else
|
||||
{
|
||||
buff->emplace(ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING, record_kind, samples[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename PcSamplingRecordKindT>
|
||||
void
|
||||
PCSamplingParserContext::generate_upcoming_pc_record(
|
||||
@@ -141,8 +180,7 @@ PCSamplingParserContext::generate_upcoming_pc_record(
|
||||
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, record_kind, samples[i]);
|
||||
emplace_records_in_buffer(buff, samples, num_samples, record_kind);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
+1
-1
@@ -25,9 +25,9 @@
|
||||
#include "lib/rocprofiler-sdk/buffer.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/stochastic_records.h"
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
#include <rocprofiler-sdk/cxx/hash.hpp>
|
||||
#include <rocprofiler-sdk/cxx/operators.hpp>
|
||||
|
||||
|
||||
+311
-232
@@ -30,75 +30,113 @@
|
||||
#include <rocprofiler-sdk/cxx/operators.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#define GFXIP_MAJOR 9
|
||||
|
||||
#define TYPECHECK(x) \
|
||||
snapshots.push_back(rocprofiler_pc_sampling_snapshot_v1_t{.dual_issue_valu = 0, \
|
||||
.inst_type = ::PCSAMPLE::x, \
|
||||
.reason_not_issued = 0, \
|
||||
.arb_state_issue = 0, \
|
||||
.arb_state_stall = 0});
|
||||
#define UNROLL_TYPECHECK() \
|
||||
TYPECHECK(TYPE_VALU); \
|
||||
TYPECHECK(TYPE_MATRIX); \
|
||||
TYPECHECK(TYPE_SCALAR); \
|
||||
TYPECHECK(TYPE_TEX); \
|
||||
TYPECHECK(TYPE_LDS); \
|
||||
TYPECHECK(TYPE_FLAT); \
|
||||
TYPECHECK(TYPE_EXP); \
|
||||
TYPECHECK(TYPE_MESSAGE); \
|
||||
TYPECHECK(TYPE_BARRIER); \
|
||||
TYPECHECK(TYPE_BRANCH_NOT_TAKEN); \
|
||||
TYPECHECK(TYPE_BRANCH_TAKEN); \
|
||||
TYPECHECK(TYPE_JUMP); \
|
||||
TYPECHECK(TYPE_OTHER); \
|
||||
TYPECHECK(TYPE_NO_INST);
|
||||
#define RECORD_INST_TYPE(x) \
|
||||
{ \
|
||||
PcSamplingRecordT sample{}; \
|
||||
sample.inst_type = ROCPROFILER_PC_SAMPLING_INSTRUCTION##_##x; \
|
||||
snapshots.push_back(sample); \
|
||||
}
|
||||
|
||||
#define REASONCHECK(x) \
|
||||
snapshots.push_back(rocprofiler_pc_sampling_snapshot_v1_t{.dual_issue_valu = 0, \
|
||||
.inst_type = 0, \
|
||||
.reason_not_issued = ::PCSAMPLE::x, \
|
||||
.arb_state_issue = 0, \
|
||||
.arb_state_stall = 0});
|
||||
#define UNROLL_REASONCHECK(x) \
|
||||
REASONCHECK(REASON_NOT_AVAILABLE); \
|
||||
REASONCHECK(REASON_ALU); \
|
||||
REASONCHECK(REASON_WAITCNT); \
|
||||
REASONCHECK(REASON_INTERNAL); \
|
||||
REASONCHECK(REASON_BARRIER); \
|
||||
REASONCHECK(REASON_ARBITER); \
|
||||
REASONCHECK(REASON_EX_STALL); \
|
||||
REASONCHECK(REASON_OTHER_WAIT);
|
||||
#define GENERATE_RECORDS_INST_TYPE() \
|
||||
RECORD_INST_TYPE(TYPE_VALU); \
|
||||
RECORD_INST_TYPE(TYPE_MATRIX); \
|
||||
RECORD_INST_TYPE(TYPE_SCALAR); \
|
||||
RECORD_INST_TYPE(TYPE_TEX); \
|
||||
RECORD_INST_TYPE(TYPE_LDS); \
|
||||
RECORD_INST_TYPE(TYPE_FLAT); \
|
||||
RECORD_INST_TYPE(TYPE_EXPORT); \
|
||||
RECORD_INST_TYPE(TYPE_MESSAGE); \
|
||||
RECORD_INST_TYPE(TYPE_BARRIER); \
|
||||
RECORD_INST_TYPE(TYPE_BRANCH_NOT_TAKEN); \
|
||||
RECORD_INST_TYPE(TYPE_BRANCH_TAKEN); \
|
||||
RECORD_INST_TYPE(TYPE_JUMP); \
|
||||
RECORD_INST_TYPE(TYPE_OTHER); \
|
||||
RECORD_INST_TYPE(TYPE_NO_INST);
|
||||
|
||||
#define ARBCHECK1(x, y) \
|
||||
snapshots.push_back( \
|
||||
rocprofiler_pc_sampling_snapshot_v1_t{.dual_issue_valu = 0, \
|
||||
.inst_type = 0, \
|
||||
.reason_not_issued = 0, \
|
||||
.arb_state_issue = 1 << ::PCSAMPLE::x, \
|
||||
.arb_state_stall = 1 << ::PCSAMPLE::y});
|
||||
#define ARBCHECK2(x) \
|
||||
ARBCHECK1(x, ISSUE_VALU); \
|
||||
ARBCHECK1(x, ISSUE_MATRIX); \
|
||||
ARBCHECK1(x, ISSUE_SCALAR); \
|
||||
ARBCHECK1(x, ISSUE_VMEM_TEX); \
|
||||
ARBCHECK1(x, ISSUE_LDS); \
|
||||
ARBCHECK1(x, ISSUE_FLAT); \
|
||||
ARBCHECK1(x, ISSUE_EXP); \
|
||||
ARBCHECK1(x, ISSUE_MISC);
|
||||
#define RECORD_NOT_ISSUED_REASON(x) \
|
||||
{ \
|
||||
PcSamplingRecordT sample{}; \
|
||||
sample.snapshot.reason_not_issued = ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED##_##x; \
|
||||
snapshots.push_back(sample); \
|
||||
}
|
||||
|
||||
#define UNROLL_ARBCHECK() \
|
||||
ARBCHECK2(ISSUE_VALU); \
|
||||
ARBCHECK2(ISSUE_MATRIX); \
|
||||
ARBCHECK2(ISSUE_SCALAR); \
|
||||
ARBCHECK2(ISSUE_VMEM_TEX); \
|
||||
ARBCHECK2(ISSUE_LDS); \
|
||||
ARBCHECK2(ISSUE_FLAT); \
|
||||
ARBCHECK2(ISSUE_EXP); \
|
||||
ARBCHECK2(ISSUE_MISC);
|
||||
#define GENERATE_RECORDS_NOT_ISSUED_REASON(x) \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_NO_INSTRUCTION_AVAILABLE); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_ALU_DEPENDENCY); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_WAITCNT); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_INTERNAL_INSTRUCTION); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_BARRIER_WAIT); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_ARBITER_NOT_WIN); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_ARBITER_WIN_EX_STALL); \
|
||||
RECORD_NOT_ISSUED_REASON(REASON_OTHER_WAIT);
|
||||
|
||||
#define RECORD_ARBSTATE_ISSUE_STALL(x, y) \
|
||||
{ \
|
||||
PcSamplingRecordT sample{}; \
|
||||
sample.snapshot.arb_state##_##x = 1; \
|
||||
sample.snapshot.arb_state##_##y = 1; \
|
||||
snapshots.push_back(sample); \
|
||||
}
|
||||
|
||||
// Respecting the order of elements in GFX9:arb_state that match the order of arb_state bits
|
||||
// in perf_snapshot_data register
|
||||
#define RECORD_ARBSTATE_ISSUE(x) \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_misc); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_exp); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_flat); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_lds); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_vmem_tex); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_scalar); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_matrix); \
|
||||
RECORD_ARBSTATE_ISSUE_STALL(x, stall_valu);
|
||||
|
||||
// Respecting the order of elements in GFX9:arb_state that match the order of arb_state bits
|
||||
// in perf_snapshot_data register
|
||||
#define GENERATE_RECORDS_ARBSTATE_ISSUE() \
|
||||
RECORD_ARBSTATE_ISSUE(issue_misc); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_exp); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_flat); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_lds); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_vmem_tex); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_scalar); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_matrix); \
|
||||
RECORD_ARBSTATE_ISSUE(issue_valu);
|
||||
|
||||
#define NON_GFX9_ARBSTATE_IS_ZERO(x, y) \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_lds_direct, 0); \
|
||||
EXPECT_EQ(y.snapshot.arb_state_issue_lds_direct, 0); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_brmsg, 0); \
|
||||
EXPECT_EQ(y.snapshot.arb_state_issue_brmsg, 0); \
|
||||
\
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_lds_direct, 0); \
|
||||
EXPECT_EQ(y.snapshot.arb_state_stall_lds_direct, 0); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_brmsg, 0); \
|
||||
EXPECT_EQ(y.snapshot.arb_state_stall_brmsg, 0);
|
||||
|
||||
#define MATCH_ARBSTATE(x, y) \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_valu, y.snapshot.arb_state_issue_valu); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_matrix, y.snapshot.arb_state_issue_matrix); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_lds, y.snapshot.arb_state_issue_lds); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_scalar, y.snapshot.arb_state_issue_scalar); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_vmem_tex, y.snapshot.arb_state_issue_vmem_tex); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_flat, y.snapshot.arb_state_issue_flat); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_exp, y.snapshot.arb_state_issue_exp); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_issue_misc, y.snapshot.arb_state_issue_misc); \
|
||||
\
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_valu, y.snapshot.arb_state_stall_valu); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_matrix, y.snapshot.arb_state_stall_matrix); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_lds, y.snapshot.arb_state_stall_lds); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_scalar, y.snapshot.arb_state_stall_scalar); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_vmem_tex, y.snapshot.arb_state_stall_vmem_tex); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_flat, y.snapshot.arb_state_stall_flat); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_exp, y.snapshot.arb_state_stall_exp); \
|
||||
EXPECT_EQ(x.snapshot.arb_state_stall_misc, y.snapshot.arb_state_stall_misc); \
|
||||
\
|
||||
NON_GFX9_ARBSTATE_IS_ZERO(x, y)
|
||||
|
||||
template <typename PcSamplingRecordT>
|
||||
class WaveSnapTest
|
||||
@@ -134,10 +172,11 @@ public:
|
||||
snap.correlation_id = dispatch->getMockId().raw;
|
||||
|
||||
snap.perf_snapshot_data = (inst_type << 3) | (reason << 7);
|
||||
snap.perf_snapshot_data |= 0x1; // sample is valid
|
||||
snap.perf_snapshot_data |= (arb_issue << 10) | (arb_stall << 18);
|
||||
snap.perf_snapshot_data1 = wave_cnt;
|
||||
|
||||
assert(dispatch.get());
|
||||
EXPECT_NE(dispatch.get(), nullptr);
|
||||
dispatch->submit(packet_union_t{.snap = snap});
|
||||
};
|
||||
|
||||
@@ -156,180 +195,213 @@ public:
|
||||
this->buffer->genUpcomingSamples(max_wave_number);
|
||||
for(size_t i = 0; i < max_wave_number; i++)
|
||||
this->genPCSample(
|
||||
i, GFX9::TYPE_LDS, GFX9::REASON_ALU, GFX9::ISSUE_VALU, GFX9::ISSUE_VALU);
|
||||
i, GFX9::TYPE_LDS, GFX9::REASON_ALU_DEPENDENCY, GFX9::ISSUE_VALU, GFX9::ISSUE_VALU);
|
||||
}
|
||||
|
||||
void CheckBuffers() override
|
||||
{
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
assert(parsed.size() == 1);
|
||||
assert(parsed[0].size() == max_wave_number);
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), max_wave_number);
|
||||
|
||||
for(size_t i = 0; i < max_wave_number; i++)
|
||||
assert(parsed[0][i].wave_count == i);
|
||||
EXPECT_EQ(parsed[0][i].wave_count, i);
|
||||
}
|
||||
|
||||
const size_t max_wave_number = 64;
|
||||
std::vector<PcSamplingRecordT> snapshots;
|
||||
};
|
||||
|
||||
// class InstTypeTest : public WaveSnapTest
|
||||
// {
|
||||
// public:
|
||||
// void FillBuffers() override
|
||||
// {
|
||||
// // Loop over inst_type_issued
|
||||
// UNROLL_TYPECHECK();
|
||||
// buffer->genUpcomingSamples(GFX9::TYPE_LAST);
|
||||
// for(int i = 0; i < GFX9::TYPE_LAST; i++)
|
||||
// genPCSample(i, i, GFX9::REASON_ALU, GFX9::ISSUE_MATRIX, GFX9::ISSUE_MATRIX);
|
||||
// }
|
||||
template <typename PcSamplingRecordT>
|
||||
class InstTypeTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
{
|
||||
public:
|
||||
void FillBuffers() override
|
||||
{
|
||||
// Loop over inst_type_issued
|
||||
GENERATE_RECORDS_INST_TYPE();
|
||||
this->buffer->genUpcomingSamples(GFX9::TYPE_LAST);
|
||||
for(int i = 0; i < GFX9::TYPE_LAST; i++)
|
||||
this->genPCSample(
|
||||
i, i, GFX9::REASON_ALU_DEPENDENCY, GFX9::ISSUE_MATRIX, GFX9::ISSUE_MATRIX);
|
||||
}
|
||||
|
||||
// void CheckBuffers() override
|
||||
// {
|
||||
// auto parsed = buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
// assert(parsed.size() == 1);
|
||||
// assert(parsed[0].size() == GFX9::TYPE_LAST);
|
||||
// assert(snapshots.size() == GFX9::TYPE_LAST);
|
||||
void CheckBuffers() override
|
||||
{
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), GFX9::TYPE_LAST);
|
||||
EXPECT_EQ(snapshots.size(), GFX9::TYPE_LAST);
|
||||
|
||||
// for(size_t i = 0; i < GFX9::TYPE_LAST; i++)
|
||||
// assert(snapshots[i].inst_type == parsed[0][i].snapshot.inst_type);
|
||||
// }
|
||||
for(size_t i = 0; i < GFX9::TYPE_LAST; i++)
|
||||
EXPECT_EQ(snapshots[i].inst_type, parsed[0][i].inst_type);
|
||||
}
|
||||
|
||||
// std::vector<rocprofiler_pc_sampling_snapshot_v1_t> snapshots;
|
||||
// };
|
||||
std::vector<PcSamplingRecordT> snapshots;
|
||||
};
|
||||
|
||||
// class StallReasonTest : public WaveSnapTest
|
||||
// {
|
||||
// public:
|
||||
// void FillBuffers() override
|
||||
// {
|
||||
// // Loop over reason_not_issued
|
||||
// UNROLL_REASONCHECK();
|
||||
// buffer->genUpcomingSamples(GFX9::REASON_LAST);
|
||||
// for(int i = 0; i < GFX9::REASON_LAST; i++)
|
||||
// genPCSample(i, GFX9::TYPE_MATRIX, i, GFX9::ISSUE_MATRIX, GFX9::ISSUE_MATRIX);
|
||||
// }
|
||||
template <typename PcSamplingRecordT>
|
||||
class StallReasonTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
{
|
||||
public:
|
||||
void FillBuffers() override
|
||||
{
|
||||
// Loop over reason_not_issued
|
||||
GENERATE_RECORDS_NOT_ISSUED_REASON();
|
||||
this->buffer->genUpcomingSamples(GFX9::REASON_LAST);
|
||||
for(int i = 0; i < GFX9::REASON_LAST; i++)
|
||||
this->genPCSample(i, GFX9::TYPE_MATRIX, i, GFX9::ISSUE_MATRIX, GFX9::ISSUE_MATRIX);
|
||||
}
|
||||
|
||||
// void CheckBuffers() override
|
||||
// {
|
||||
// auto parsed = buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
// assert(parsed.size() == 1);
|
||||
// assert(parsed[0].size() == GFX9::REASON_LAST);
|
||||
// assert(snapshots.size() == GFX9::REASON_LAST);
|
||||
void CheckBuffers() override
|
||||
{
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), GFX9::REASON_LAST);
|
||||
EXPECT_EQ(snapshots.size(), GFX9::REASON_LAST);
|
||||
|
||||
// for(size_t i = 0; i < GFX9::REASON_LAST; i++)
|
||||
// assert(snapshots[i].reason_not_issued == parsed[0][i].snapshot.reason_not_issued);
|
||||
// }
|
||||
for(size_t i = 0; i < GFX9::REASON_LAST; i++)
|
||||
EXPECT_EQ(snapshots[i].snapshot.reason_not_issued,
|
||||
parsed[0][i].snapshot.reason_not_issued);
|
||||
}
|
||||
|
||||
// std::vector<rocprofiler_pc_sampling_snapshot_v1_t> snapshots;
|
||||
// };
|
||||
std::vector<PcSamplingRecordT> snapshots;
|
||||
};
|
||||
|
||||
// class ArbStateTest : public WaveSnapTest
|
||||
// {
|
||||
// public:
|
||||
// void FillBuffers() override
|
||||
// {
|
||||
// // Loop over arb_state_issue
|
||||
// UNROLL_ARBCHECK();
|
||||
// buffer->genUpcomingSamples(GFX9::ISSUE_LAST * GFX9::ISSUE_LAST);
|
||||
// for(int i = 0; i < GFX9::ISSUE_LAST; i++)
|
||||
// for(int j = 0; j < GFX9::ISSUE_LAST; j++)
|
||||
// genPCSample(i, GFX9::TYPE_MATRIX, GFX9::REASON_ALU, 1 << i, 1 << j);
|
||||
// }
|
||||
template <typename PcSamplingRecordT>
|
||||
class ArbStateTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
{
|
||||
public:
|
||||
void FillBuffers() override
|
||||
{
|
||||
// Loop over arb_state_issue
|
||||
GENERATE_RECORDS_ARBSTATE_ISSUE();
|
||||
this->buffer->genUpcomingSamples(GFX9::ISSUE_LAST * GFX9::ISSUE_LAST);
|
||||
// To match the order of instantiating snapshots inside `GENERATE_RECORDS_ARBSTATE_ISSUE`
|
||||
// we loop over GFX9::
|
||||
for(int i = 0; i < GFX9::ISSUE_LAST; i++)
|
||||
for(int j = 0; j < GFX9::ISSUE_LAST; j++)
|
||||
this->genPCSample(
|
||||
i, GFX9::TYPE_MATRIX, GFX9::REASON_ALU_DEPENDENCY, 1 << i, 1 << j);
|
||||
}
|
||||
|
||||
// void CheckBuffers() override
|
||||
// {
|
||||
// auto parsed = buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
// assert(parsed.size() == 1);
|
||||
// assert(parsed[0].size() == GFX9::ISSUE_LAST * GFX9::ISSUE_LAST);
|
||||
// assert(snapshots.size() == GFX9::ISSUE_LAST * GFX9::ISSUE_LAST);
|
||||
void CheckBuffers() override
|
||||
{
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), GFX9::ISSUE_LAST * GFX9::ISSUE_LAST);
|
||||
EXPECT_EQ(snapshots.size(), GFX9::ISSUE_LAST * GFX9::ISSUE_LAST);
|
||||
|
||||
// for(size_t i = 0; i < GFX9::ISSUE_LAST * GFX9::ISSUE_LAST; i++)
|
||||
// {
|
||||
// auto& snap = snapshots[i];
|
||||
// assert(snap.arb_state_issue == parsed[0][i].snapshot.arb_state_issue);
|
||||
// assert(snap.arb_state_stall == parsed[0][i].snapshot.arb_state_stall);
|
||||
// }
|
||||
// }
|
||||
for(size_t i = 0; i < GFX9::ISSUE_LAST * GFX9::ISSUE_LAST; i++)
|
||||
{
|
||||
auto& snap = snapshots[i];
|
||||
MATCH_ARBSTATE(snap, parsed[0][i])
|
||||
}
|
||||
}
|
||||
|
||||
// std::vector<rocprofiler_pc_sampling_snapshot_v1_t> snapshots;
|
||||
// };
|
||||
std::vector<PcSamplingRecordT> snapshots;
|
||||
};
|
||||
|
||||
// class WaveIssueAndErrorTest : public WaveSnapTest
|
||||
// {
|
||||
// void FillBuffers() override
|
||||
// {
|
||||
// buffer->genUpcomingSamples(16);
|
||||
// for(int valid = 0; valid <= 1; valid++)
|
||||
// for(int issued = 0; issued <= 1; issued++)
|
||||
// for(int dual = 0; dual <= 1; dual++)
|
||||
// for(int error = 0; error <= 1; error++)
|
||||
// genPCSample(valid, issued, dual, error);
|
||||
// }
|
||||
template <typename PcSamplingRecordT, typename PcSamplingRecordInvalidT>
|
||||
class WaveIssueAndErrorTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
{
|
||||
struct pc_sampling_test_record_t
|
||||
{
|
||||
bool valid;
|
||||
union
|
||||
{
|
||||
PcSamplingRecordT valid_record;
|
||||
PcSamplingRecordInvalidT invalid_record;
|
||||
};
|
||||
};
|
||||
|
||||
// void CheckBuffers() override
|
||||
// {
|
||||
// const int num_combinations = 16;
|
||||
// auto parsed = buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
// assert(parsed.size() == 1);
|
||||
// assert(parsed[0].size() == num_combinations);
|
||||
// assert(compare.size() == num_combinations);
|
||||
void FillBuffers() override
|
||||
{
|
||||
this->buffer->genUpcomingSamples(16);
|
||||
for(int valid = 0; valid <= 1; valid++)
|
||||
for(int issued = 0; issued <= 1; issued++)
|
||||
for(int dual = 0; dual <= 1; dual++)
|
||||
for(int error = 0; error <= 1; error++)
|
||||
genPCSample(valid, issued, dual, error);
|
||||
}
|
||||
|
||||
// for(size_t i = 0; i < num_combinations; i++)
|
||||
// {
|
||||
// assert(compare[i].flags.valid == parsed[0][i].flags.valid);
|
||||
// assert(compare[i].wave_issued == parsed[0][i].wave_issued);
|
||||
// assert(compare[i].snapshot.dual_issue_valu == parsed[0][i].snapshot.dual_issue_valu);
|
||||
// }
|
||||
// }
|
||||
void CheckBuffers() override
|
||||
{
|
||||
const int num_combinations = 16;
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), num_combinations);
|
||||
EXPECT_EQ(compare.size(), num_combinations);
|
||||
|
||||
// union trap_snapshot_v1
|
||||
// {
|
||||
// struct
|
||||
// {
|
||||
// uint32_t valid : 1;
|
||||
// uint32_t issued : 1;
|
||||
// uint32_t dual : 1;
|
||||
// uint32_t reserved : 23;
|
||||
// uint32_t error : 1;
|
||||
// uint32_t reserved2 : 5;
|
||||
// };
|
||||
// uint32_t raw;
|
||||
// };
|
||||
for(size_t i = 0; i < num_combinations; i++)
|
||||
{
|
||||
if(compare[i].valid)
|
||||
{
|
||||
EXPECT_EQ(compare[i].valid_record.wave_issued, parsed[0][i].wave_issued);
|
||||
EXPECT_EQ(compare[i].valid_record.snapshot.dual_issue_valu,
|
||||
parsed[0][i].snapshot.dual_issue_valu);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Internally (inside the parser) invalid samples are represented with
|
||||
// PcSamplingRecordT of size 0. Eventually, those records are replaced with the
|
||||
// PcSamplingRecordInvalidT prior to putting inside the SDK buffer.
|
||||
EXPECT_EQ(parsed[0][i].size, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void genPCSample(bool valid, bool issued, bool dual, bool error)
|
||||
// {
|
||||
// rocprofiler_pc_sampling_record_t sample;
|
||||
// ::memset(&sample, 0, sizeof(sample));
|
||||
// // TODO: Since code objects are not mocked, use pc.code_object_offset
|
||||
// // as the absolute physical address of the mocked PC.
|
||||
// sample.pc.code_object_offset = dispatch->unique_id;
|
||||
union trap_snapshot_v1
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t valid : 1;
|
||||
uint32_t issued : 1;
|
||||
uint32_t dual : 1;
|
||||
uint32_t reserved : 23;
|
||||
uint32_t error : 1;
|
||||
uint32_t reserved2 : 5;
|
||||
};
|
||||
uint32_t raw;
|
||||
};
|
||||
|
||||
// sample.correlation_id.internal = dispatch->getMockId().raw;
|
||||
void genPCSample(bool valid, bool issued, bool dual, bool error)
|
||||
{
|
||||
pc_sampling_test_record_t record{};
|
||||
record.valid = valid && !error;
|
||||
if(record.valid)
|
||||
{
|
||||
// Fill in the data for the valid record.
|
||||
auto& sample = record.valid_record;
|
||||
|
||||
// sample.flags.valid = valid && !error;
|
||||
// sample.wave_issued = issued;
|
||||
// sample.snapshot.dual_issue_valu = dual;
|
||||
// TODO: Since code objects are not mocked, use pc.code_object_offset
|
||||
// as the absolute physical address of the mocked PC.
|
||||
sample.pc.code_object_offset = this->dispatch->unique_id;
|
||||
|
||||
// assert(dispatch.get());
|
||||
sample.correlation_id.internal = this->dispatch->getMockId().raw;
|
||||
|
||||
// compare.push_back(sample);
|
||||
sample.wave_issued = issued;
|
||||
sample.snapshot.dual_issue_valu = dual;
|
||||
|
||||
// trap_snapshot_v1 snap;
|
||||
// snap.valid = valid;
|
||||
// snap.issued = issued;
|
||||
// snap.dual = dual;
|
||||
// snap.error = error;
|
||||
EXPECT_NE(this->dispatch.get(), nullptr);
|
||||
}
|
||||
|
||||
// perf_sample_snapshot_v1 pss;
|
||||
// pss.perf_snapshot_data = snap.raw;
|
||||
// pss.correlation_id = dispatch->getMockId().raw;
|
||||
// dispatch->submit(std::move(pss));
|
||||
// };
|
||||
compare.push_back(record);
|
||||
|
||||
// std::vector<rocprofiler_pc_sampling_record_t> compare;
|
||||
// };
|
||||
trap_snapshot_v1 snap;
|
||||
snap.valid = valid;
|
||||
snap.issued = issued;
|
||||
snap.dual = dual;
|
||||
snap.error = error;
|
||||
|
||||
perf_sample_snapshot_v1 pss;
|
||||
pss.perf_snapshot_data = snap.raw;
|
||||
pss.correlation_id = this->dispatch->getMockId().raw;
|
||||
this->dispatch->submit(std::move(pss));
|
||||
};
|
||||
|
||||
std::vector<pc_sampling_test_record_t> compare;
|
||||
};
|
||||
|
||||
template <typename PcSamplingRecordT>
|
||||
class HwIdTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
@@ -405,23 +477,23 @@ class HwIdTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
void CheckBuffers() override
|
||||
{
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
assert(parsed.size() == 1);
|
||||
assert(parsed[0].size() == 3);
|
||||
assert(compare.size() == 3);
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), 3);
|
||||
EXPECT_EQ(compare.size(), 3);
|
||||
|
||||
for(size_t i = 0; i < 3; i++)
|
||||
{
|
||||
// Comparing individual fields
|
||||
assert(compare[i].hw_id.wave_id == parsed[0][i].hw_id.wave_id);
|
||||
assert(compare[i].hw_id.simd_id == parsed[0][i].hw_id.simd_id);
|
||||
assert(compare[i].hw_id.pipe_id == parsed[0][i].hw_id.pipe_id);
|
||||
assert(compare[i].hw_id.cu_or_wgp_id == parsed[0][i].hw_id.cu_or_wgp_id);
|
||||
assert(compare[i].hw_id.shader_array_id == parsed[0][i].hw_id.shader_array_id);
|
||||
assert(compare[i].hw_id.shader_engine_id == parsed[0][i].hw_id.shader_engine_id);
|
||||
assert(compare[i].hw_id.workgroup_id == parsed[0][i].hw_id.workgroup_id);
|
||||
assert(compare[i].hw_id.vm_id == parsed[0][i].hw_id.vm_id);
|
||||
assert(compare[i].hw_id.queue_id == parsed[0][i].hw_id.queue_id);
|
||||
assert(compare[i].hw_id.microengine_id == parsed[0][i].hw_id.microengine_id);
|
||||
EXPECT_EQ(compare[i].hw_id.wave_id, parsed[0][i].hw_id.wave_id);
|
||||
EXPECT_EQ(compare[i].hw_id.simd_id, parsed[0][i].hw_id.simd_id);
|
||||
EXPECT_EQ(compare[i].hw_id.pipe_id, parsed[0][i].hw_id.pipe_id);
|
||||
EXPECT_EQ(compare[i].hw_id.cu_or_wgp_id, parsed[0][i].hw_id.cu_or_wgp_id);
|
||||
EXPECT_EQ(compare[i].hw_id.shader_array_id, parsed[0][i].hw_id.shader_array_id);
|
||||
EXPECT_EQ(compare[i].hw_id.shader_engine_id, parsed[0][i].hw_id.shader_engine_id);
|
||||
EXPECT_EQ(compare[i].hw_id.workgroup_id, parsed[0][i].hw_id.workgroup_id);
|
||||
EXPECT_EQ(compare[i].hw_id.vm_id, parsed[0][i].hw_id.vm_id);
|
||||
EXPECT_EQ(compare[i].hw_id.queue_id, parsed[0][i].hw_id.queue_id);
|
||||
EXPECT_EQ(compare[i].hw_id.microengine_id, parsed[0][i].hw_id.microengine_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,8 +523,9 @@ class HwIdTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
// raw register value
|
||||
snap.hw_id = hw_id.raw;
|
||||
snap.correlation_id = this->dispatch->getMockId().raw;
|
||||
snap.perf_snapshot_data |= 0x1; // sample is valid
|
||||
|
||||
assert(this->dispatch.get());
|
||||
EXPECT_NE(this->dispatch.get(), nullptr);
|
||||
this->dispatch->submit(snap);
|
||||
};
|
||||
|
||||
@@ -473,26 +546,26 @@ class WaveOtherFieldsTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
void CheckBuffers() override
|
||||
{
|
||||
auto parsed = this->buffer->get_parsed_buffer(9); // GFXIP==9
|
||||
assert(parsed.size() == 1);
|
||||
assert(parsed[0].size() == 3);
|
||||
assert(compare.size() == 3);
|
||||
EXPECT_EQ(parsed.size(), 1);
|
||||
EXPECT_EQ(parsed[0].size(), 3);
|
||||
EXPECT_EQ(compare.size(), 3);
|
||||
|
||||
for(size_t i = 0; i < 3; i++)
|
||||
{
|
||||
// TODO: if we decide to test flags, make specialization for
|
||||
// rocprofiler_pc_sampling_record_stochastic_v0_t
|
||||
// assert(parsed[0][i].flags.has_stall_reason == true);
|
||||
// assert(parsed[0][i].flags.has_wave_cnt == true);
|
||||
// assert(parsed[0][i].flags.reserved == false);
|
||||
// EXPECT_EQ(parsed[0][i].flags.has_stall_reason, true);
|
||||
// EXPECT_EQ(parsed[0][i].flags.has_wave_cnt, true);
|
||||
// EXPECT_EQ(parsed[0][i].flags.reserved, false);
|
||||
|
||||
assert(compare[i].exec_mask == parsed[0][i].exec_mask);
|
||||
assert(compare[i].workgroup_id == parsed[0][i].workgroup_id);
|
||||
EXPECT_EQ(compare[i].exec_mask, parsed[0][i].exec_mask);
|
||||
EXPECT_EQ(compare[i].workgroup_id, parsed[0][i].workgroup_id);
|
||||
|
||||
assert(compare[i].hw_id.chiplet == parsed[0][i].hw_id.chiplet);
|
||||
assert(compare[i].wave_in_group == parsed[0][i].wave_in_group);
|
||||
EXPECT_EQ(compare[i].hw_id.chiplet, parsed[0][i].hw_id.chiplet);
|
||||
EXPECT_EQ(compare[i].wave_in_group, parsed[0][i].wave_in_group);
|
||||
// TODO: handle HW_ID as well.
|
||||
// assert(compare[i].hw_id == parsed[0][i].hw_id);
|
||||
assert(compare[i].correlation_id.internal == parsed[0][i].correlation_id.internal);
|
||||
// EXPECT_EQ(compare[i].hw_id, parsed[0][i].hw_id);
|
||||
EXPECT_EQ(compare[i].correlation_id.internal, parsed[0][i].correlation_id.internal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,7 +598,11 @@ class WaveOtherFieldsTest : public WaveSnapTest<PcSamplingRecordT>
|
||||
snap.chiplet_and_wave_id = (chip << 8) | (wave & 0x3F);
|
||||
snap.correlation_id = this->dispatch->getMockId().raw;
|
||||
|
||||
assert(this->dispatch.get());
|
||||
// to ensure all stochastic samples are generated properly,
|
||||
// marked them as valid
|
||||
snap.perf_snapshot_data |= 0x1; // set the bit indicating the sample is valid
|
||||
|
||||
EXPECT_NE(this->dispatch.get(), nullptr);
|
||||
this->dispatch->submit(snap);
|
||||
|
||||
(void) pc;
|
||||
@@ -538,10 +615,12 @@ TEST(pcs_parser, gfx9_test)
|
||||
{
|
||||
// Tests specific to stochastic sampling only
|
||||
WaveCntTest<rocprofiler_pc_sampling_record_stochastic_v0_t>{}.Test();
|
||||
// InstTypeTest{}.Test();
|
||||
// StallReasonTest{}.Test();
|
||||
// ArbStateTest{}.Test();
|
||||
// WaveIssueAndErrorTest{}.Test();
|
||||
InstTypeTest<rocprofiler_pc_sampling_record_stochastic_v0_t>{}.Test();
|
||||
StallReasonTest<rocprofiler_pc_sampling_record_stochastic_v0_t>{}.Test();
|
||||
ArbStateTest<rocprofiler_pc_sampling_record_stochastic_v0_t>{}.Test();
|
||||
WaveIssueAndErrorTest<rocprofiler_pc_sampling_record_stochastic_v0_t,
|
||||
rocprofiler_pc_sampling_record_invalid_t>{}
|
||||
.Test();
|
||||
|
||||
// Tests commong for both host trap and stochastic sampling.
|
||||
HwIdTest<rocprofiler_pc_sampling_record_host_trap_v0_t>{}.Test();
|
||||
|
||||
@@ -309,6 +309,8 @@ public:
|
||||
::memset(&uni, 0, sizeof(uni));
|
||||
uni.snap.pc = dispatch->unique_id;
|
||||
uni.snap.correlation_id = dispatch->getMockId().raw;
|
||||
// mark sample valid in case of stochastic sampling tests
|
||||
uni.snap.perf_snapshot_data |= 0x1; // stochastic sample is valid
|
||||
dispatch->submit(uni);
|
||||
};
|
||||
void print()
|
||||
|
||||
+1
@@ -250,6 +250,7 @@ multithread_codeobj(size_t tid, Latch* latch)
|
||||
for(int s = 0; s < NUM_SAMPLES; s++)
|
||||
{
|
||||
uni.snap.pc = pc_base_addr + s;
|
||||
uni.snap.perf_snapshot_data |= 0x1; // sample is valid
|
||||
dispatch->submit(uni);
|
||||
}
|
||||
|
||||
|
||||
+124
-84
@@ -30,7 +30,8 @@
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx9.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/rocr.h"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/stochastic_records.h"
|
||||
|
||||
#include <rocprofiler-sdk/pc_sampling.h>
|
||||
|
||||
// TODO: refactor the commented code for stochastic sampling
|
||||
|
||||
@@ -51,7 +52,6 @@
|
||||
|
||||
// ret.wave_count = sample.perf_snapshot_data1 & 0x3F;
|
||||
|
||||
// ret.wave_issued = sample.perf_snapshot_data >> 1;
|
||||
// ret.snapshot.dual_issue_valu = sample.perf_snapshot_data >> 2;
|
||||
// ret.snapshot.inst_type = sample.perf_snapshot_data >> 3;
|
||||
// ret.snapshot.reason_not_issued = (sample.perf_snapshot_data >> 7) & 0x7;
|
||||
@@ -103,90 +103,76 @@
|
||||
|
||||
// #undef BITSHIFT
|
||||
|
||||
// #define LUTOVERLOAD(sname) this->operator[](GFX::sname) = PCSAMPLE::sname
|
||||
#define LUTOVERLOAD(sname, rocp_prefix) this->operator[](GFX::sname) = rocp_prefix##_##sname
|
||||
#define LUTOVERLOAD_INST(sname) LUTOVERLOAD(sname, ROCPROFILER_PC_SAMPLING_INSTRUCTION)
|
||||
#define LUTOVERLOAD_INST_NOT_ISSUED(sname) \
|
||||
LUTOVERLOAD(sname, ROCPROFILER_PC_SAMPLING_INSTRUCTION_NOT_ISSUED)
|
||||
|
||||
// template <typename GFX>
|
||||
// class GFX_REASON_LUT : public std::array<int, 32>
|
||||
// {
|
||||
// public:
|
||||
// GFX_REASON_LUT()
|
||||
// {
|
||||
// std::memset(data(), 0, size() * sizeof(int));
|
||||
// LUTOVERLOAD(REASON_NOT_AVAILABLE);
|
||||
// LUTOVERLOAD(REASON_ALU);
|
||||
// LUTOVERLOAD(REASON_WAITCNT);
|
||||
// LUTOVERLOAD(REASON_INTERNAL);
|
||||
// LUTOVERLOAD(REASON_BARRIER);
|
||||
// LUTOVERLOAD(REASON_ARBITER);
|
||||
// LUTOVERLOAD(REASON_EX_STALL);
|
||||
// LUTOVERLOAD(REASON_OTHER_WAIT);
|
||||
// LUTOVERLOAD(REASON_SLEEP);
|
||||
// }
|
||||
// };
|
||||
template <typename GFX>
|
||||
struct gfx_inst_lut : public std::array<int, 32>
|
||||
{
|
||||
gfx_inst_lut()
|
||||
{
|
||||
std::memset(data(), 0, size() * sizeof(int));
|
||||
LUTOVERLOAD_INST(TYPE_VALU);
|
||||
LUTOVERLOAD_INST(TYPE_MATRIX);
|
||||
LUTOVERLOAD_INST(TYPE_SCALAR);
|
||||
LUTOVERLOAD_INST(TYPE_TEX);
|
||||
LUTOVERLOAD_INST(TYPE_LDS);
|
||||
LUTOVERLOAD_INST(TYPE_LDS_DIRECT);
|
||||
LUTOVERLOAD_INST(TYPE_FLAT);
|
||||
LUTOVERLOAD_INST(TYPE_EXPORT);
|
||||
LUTOVERLOAD_INST(TYPE_MESSAGE);
|
||||
LUTOVERLOAD_INST(TYPE_BARRIER);
|
||||
LUTOVERLOAD_INST(TYPE_BRANCH_NOT_TAKEN);
|
||||
LUTOVERLOAD_INST(TYPE_BRANCH_TAKEN);
|
||||
LUTOVERLOAD_INST(TYPE_JUMP);
|
||||
LUTOVERLOAD_INST(TYPE_OTHER);
|
||||
LUTOVERLOAD_INST(TYPE_NO_INST);
|
||||
LUTOVERLOAD_INST(TYPE_DUAL_VALU);
|
||||
}
|
||||
};
|
||||
|
||||
// template <typename GFX>
|
||||
// class GFX_INST_LUT : public std::array<int, 32>
|
||||
// {
|
||||
// public:
|
||||
// GFX_INST_LUT()
|
||||
// {
|
||||
// std::memset(data(), 0, size() * sizeof(int));
|
||||
// LUTOVERLOAD(TYPE_VALU);
|
||||
// LUTOVERLOAD(TYPE_MATRIX);
|
||||
// LUTOVERLOAD(TYPE_SCALAR);
|
||||
// LUTOVERLOAD(TYPE_TEX);
|
||||
// LUTOVERLOAD(TYPE_LDS);
|
||||
// LUTOVERLOAD(TYPE_LDS_DIRECT);
|
||||
// LUTOVERLOAD(TYPE_FLAT);
|
||||
// LUTOVERLOAD(TYPE_EXP);
|
||||
// LUTOVERLOAD(TYPE_MESSAGE);
|
||||
// LUTOVERLOAD(TYPE_BARRIER);
|
||||
// LUTOVERLOAD(TYPE_BRANCH_NOT_TAKEN);
|
||||
// LUTOVERLOAD(TYPE_BRANCH_TAKEN);
|
||||
// LUTOVERLOAD(TYPE_JUMP);
|
||||
// LUTOVERLOAD(TYPE_OTHER);
|
||||
// LUTOVERLOAD(TYPE_NO_INST);
|
||||
// LUTOVERLOAD(TYPE_DUAL_VALU);
|
||||
// }
|
||||
// };
|
||||
template <typename GFX>
|
||||
struct gfx_reason_lut : public std::array<int, 32>
|
||||
{
|
||||
gfx_reason_lut()
|
||||
{
|
||||
std::memset(data(), 0, size() * sizeof(int));
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_NO_INSTRUCTION_AVAILABLE);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_ALU_DEPENDENCY);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_WAITCNT);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_INTERNAL_INSTRUCTION);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_BARRIER_WAIT);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_ARBITER_NOT_WIN);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_ARBITER_WIN_EX_STALL);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_OTHER_WAIT);
|
||||
LUTOVERLOAD_INST_NOT_ISSUED(REASON_SLEEP_WAIT);
|
||||
}
|
||||
};
|
||||
|
||||
// template <typename GFX>
|
||||
// inline int
|
||||
// translate_reason(int in)
|
||||
// {
|
||||
// static GFX_REASON_LUT<GFX> lut;
|
||||
// return lut[in & 0x1F];
|
||||
// }
|
||||
template <typename GFX>
|
||||
inline int
|
||||
translate_inst(int in)
|
||||
{
|
||||
static gfx_inst_lut<GFX> lut;
|
||||
return lut[in & 0x1F];
|
||||
}
|
||||
|
||||
// template <typename GFX>
|
||||
// inline int
|
||||
// translate_inst(int in)
|
||||
// {
|
||||
// static GFX_INST_LUT<GFX> lut;
|
||||
// return lut[in & 0x1F];
|
||||
// }
|
||||
template <typename GFX>
|
||||
inline int
|
||||
translate_reason(int in)
|
||||
{
|
||||
static gfx_reason_lut<GFX> lut;
|
||||
return lut[in & 0x1F];
|
||||
}
|
||||
|
||||
// #undef LUTOVERLOAD
|
||||
|
||||
// template <bool HostTrap, typename GFX>
|
||||
// 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_t ret =
|
||||
// copyStochasticSample<GFX>(*(const perf_sample_snapshot_v1*) sample);
|
||||
|
||||
// ret.snapshot.inst_type = translate_inst<GFX>(ret.snapshot.inst_type);
|
||||
// ret.snapshot.arb_state_issue = translate_arb<GFX>(ret.snapshot.arb_state_issue);
|
||||
// ret.snapshot.arb_state_stall = translate_arb<GFX>(ret.snapshot.arb_state_stall);
|
||||
// ret.snapshot.reason_not_issued = translate_reason<GFX>(ret.snapshot.reason_not_issued);
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
#undef LUTOVERLOAD_INST_NOT_ISSUED
|
||||
#undef LUTOVERLOAD_INST
|
||||
#undef LUTOVERLOAD
|
||||
|
||||
#define EXTRACT_BITS(val, bit_end, bit_start) \
|
||||
(val >> bit_start) & ((1U << (bit_end - bit_start + 1)) - 1)
|
||||
((val >> bit_start) & ((1U << (bit_end - bit_start + 1)) - 1))
|
||||
|
||||
template <typename GFX, typename PcSamplingRecordT, typename SType>
|
||||
inline void
|
||||
@@ -228,8 +214,6 @@ copyHwId<GFX9, rocprofiler_pc_sampling_hw_id_v0_t>(rocprofiler_pc_sampling_hw_id
|
||||
hw_id.microengine_id = EXTRACT_BITS(hw_id_reg, 31, 30);
|
||||
}
|
||||
|
||||
#undef EXTRACT_BITS
|
||||
|
||||
template <typename PcSamplingRecordT, typename SType>
|
||||
inline PcSamplingRecordT
|
||||
copySampleHeader(const SType& sample)
|
||||
@@ -276,11 +260,65 @@ inline rocprofiler_pc_sampling_record_stochastic_v0_t
|
||||
copySample<GFX9, rocprofiler_pc_sampling_record_stochastic_v0_t>(const void* sample)
|
||||
{
|
||||
const auto& sample_ = *static_cast<const perf_sample_snapshot_v1*>(sample);
|
||||
auto ret = copySampleHeader<rocprofiler_pc_sampling_record_stochastic_v0_t>(sample_);
|
||||
|
||||
// Extracting data from the perf_snapshot_data register
|
||||
auto perf_snapshot_data = sample_.perf_snapshot_data;
|
||||
// The sample is valid iff neither of perf_snapshot_data.valid and perf_snapshot_data.error == 0
|
||||
// is one
|
||||
auto valid = static_cast<bool>(EXTRACT_BITS(perf_snapshot_data, 0, 0) &
|
||||
~EXTRACT_BITS(perf_snapshot_data, 26, 26));
|
||||
if(!valid)
|
||||
{
|
||||
// To reduce refactoring of the PC sampling parser, we agreed to internally represent
|
||||
// invalid samples with `rocprofiler_pc_sampling_record_stochastic_v0_t` with size 0.
|
||||
// Eventually, those records are replaced with rocprofiler_pc_sampling_record_invalid_t
|
||||
// and placed into the SDK buffer consumed by the end tool.
|
||||
rocprofiler_pc_sampling_record_stochastic_v0_t invalid{};
|
||||
invalid.size = 0;
|
||||
// No need to further process invalid samples
|
||||
return invalid;
|
||||
}
|
||||
|
||||
auto ret = copySampleHeader<rocprofiler_pc_sampling_record_stochastic_v0_t>(sample_);
|
||||
copyChipletId<GFX9>(ret, sample_);
|
||||
copyHwId<GFX9>(ret.hw_id, sample_.hw_id);
|
||||
ret.wave_count = sample_.perf_snapshot_data1 & 0x3F;
|
||||
// TODO: implement logic for manipulating stochastic related fields
|
||||
|
||||
// no memory counters on GFX9
|
||||
ret.flags.has_memory_counter = false;
|
||||
|
||||
// wave issued an instruction
|
||||
ret.wave_issued = EXTRACT_BITS(perf_snapshot_data, 1, 1);
|
||||
// type of issued instruction, valid only if `ret.wave_issued` is true.
|
||||
ret.inst_type = translate_inst<GFX9>(EXTRACT_BITS(perf_snapshot_data, 6, 3));
|
||||
// two VALU instructions issued in this cycles
|
||||
ret.snapshot.dual_issue_valu = EXTRACT_BITS(perf_snapshot_data, 2, 2);
|
||||
// reason for not issuing an instruction, valid only if `ret.wave_issued` is false
|
||||
ret.snapshot.reason_not_issued = translate_reason<GFX9>(EXTRACT_BITS(perf_snapshot_data, 9, 7));
|
||||
|
||||
// arbiter state information
|
||||
uint16_t arb_state = EXTRACT_BITS(perf_snapshot_data, 25, 10);
|
||||
ret.snapshot.arb_state_issue_valu = EXTRACT_BITS(arb_state, 7, 7);
|
||||
ret.snapshot.arb_state_issue_matrix = EXTRACT_BITS(arb_state, 6, 6);
|
||||
ret.snapshot.arb_state_issue_lds = EXTRACT_BITS(arb_state, 3, 3);
|
||||
ret.snapshot.arb_state_issue_scalar = EXTRACT_BITS(arb_state, 5, 5);
|
||||
ret.snapshot.arb_state_issue_vmem_tex = EXTRACT_BITS(arb_state, 4, 4);
|
||||
ret.snapshot.arb_state_issue_flat = EXTRACT_BITS(arb_state, 2, 2);
|
||||
ret.snapshot.arb_state_issue_exp = EXTRACT_BITS(arb_state, 1, 1);
|
||||
ret.snapshot.arb_state_issue_misc = EXTRACT_BITS(arb_state, 0, 0);
|
||||
|
||||
ret.snapshot.arb_state_stall_valu = EXTRACT_BITS(arb_state, 15, 15);
|
||||
ret.snapshot.arb_state_stall_matrix = EXTRACT_BITS(arb_state, 14, 14);
|
||||
ret.snapshot.arb_state_stall_lds = EXTRACT_BITS(arb_state, 11, 11);
|
||||
ret.snapshot.arb_state_stall_scalar = EXTRACT_BITS(arb_state, 13, 13);
|
||||
ret.snapshot.arb_state_stall_vmem_tex = EXTRACT_BITS(arb_state, 12, 12);
|
||||
ret.snapshot.arb_state_stall_flat = EXTRACT_BITS(arb_state, 10, 10);
|
||||
ret.snapshot.arb_state_stall_exp = EXTRACT_BITS(arb_state, 9, 9);
|
||||
ret.snapshot.arb_state_stall_misc = EXTRACT_BITS(arb_state, 8, 8);
|
||||
|
||||
// Extracting data from the perf_snapshot_data1 register
|
||||
// Active waves on CU at the moment of sampling
|
||||
ret.wave_count = EXTRACT_BITS(sample_.perf_snapshot_data1, 5, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -309,3 +347,5 @@ copySample<GFX11, rocprofiler_pc_sampling_record_stochastic_v0_t>(const void* sa
|
||||
// ret.wave_count = sample_.perf_snapshot_data1 & 0x3F;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#undef EXTRACT_BITS
|
||||
|
||||
@@ -263,6 +263,7 @@ flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id)
|
||||
auto* service = get_configured_pc_sampling_service().load();
|
||||
if(service && ctx->pc_sampler.get() == service)
|
||||
{
|
||||
rocprofiler_status_t status = ROCPROFILER_STATUS_SUCCESS;
|
||||
// The context `ctx` (that holds the buffer with `buffer_id`)
|
||||
// is the one containing PC sampling service.
|
||||
// The HSA interception table is registered.
|
||||
@@ -272,7 +273,10 @@ flush_internal_agent_buffers(rocprofiler_buffer_id_t 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());
|
||||
// NOTE: one rocprofiler-SDK PC sampling buffer can be tied
|
||||
// to multiple agent (agent sessions).
|
||||
status = hsa::flush_internal_agent_buffers(agent_session.get());
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,6 +285,41 @@ flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id)
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
flush_all_agent_buffers()
|
||||
{
|
||||
auto* service = get_configured_pc_sampling_service().load();
|
||||
if(!service) return ROCPROFILER_STATUS_ERROR;
|
||||
|
||||
rocprofiler_status_t status = ROCPROFILER_STATUS_SUCCESS;
|
||||
// Loop over all agents that have PC sampling service configured
|
||||
// and drain their internal buffers.
|
||||
// NOTE: one SDK buffer can consume data from multiple agents
|
||||
// (multiple HSA runtime buffers)
|
||||
for(const auto& [_, agent_session] : service->agent_sessions)
|
||||
{
|
||||
status = flush_internal_agent_buffers(agent_session->buffer_id);
|
||||
if(status != ROCPROFILER_STATUS_SUCCESS)
|
||||
{
|
||||
ROCP_ERROR << "Failed to flush internal HSA buffers tied to rocp buffer "
|
||||
<< agent_session->buffer_id.handle;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
service_sync()
|
||||
{
|
||||
flush_all_agent_buffers();
|
||||
}
|
||||
|
||||
void
|
||||
service_fini()
|
||||
{
|
||||
flush_all_agent_buffers();
|
||||
}
|
||||
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
|
||||
|
||||
@@ -67,6 +67,12 @@ is_pc_sample_service_configured(rocprofiler_agent_id_t agent_id);
|
||||
|
||||
rocprofiler_status_t
|
||||
flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id);
|
||||
|
||||
void
|
||||
service_sync();
|
||||
|
||||
void
|
||||
service_fini();
|
||||
} // namespace pc_sampling
|
||||
} // namespace rocprofiler
|
||||
|
||||
|
||||
+66
-14
@@ -138,8 +138,9 @@ find_all_gpu_agents_supporting_pc_sampling_impl(rocprofiler_agent_version_t vers
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
const rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer_stochastic(rocprofiler_agent_id_t agent_id)
|
||||
rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer(rocprofiler_pc_sampling_method_t method,
|
||||
rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
auto cb = [](const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
size_t num_config,
|
||||
@@ -158,31 +159,46 @@ extract_pc_sampling_config_prefer_stochastic(rocprofiler_agent_id_t agent_id)
|
||||
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
|
||||
const rocprofiler_pc_sampling_configuration_t* first_preferred_method_config = nullptr;
|
||||
const rocprofiler_pc_sampling_configuration_t* first_remained_method_config = nullptr;
|
||||
// Search until encountering the prefered method configuration, if any.
|
||||
// Otherwise, use what remained.
|
||||
for(auto const& cfg : configs)
|
||||
{
|
||||
if(cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
if(cfg.method == method)
|
||||
{
|
||||
// Temporarily disable stochastic sampling as it's not fully supported.
|
||||
// first_stochastic_config = &cfg;
|
||||
// break;
|
||||
first_preferred_method_config = &cfg;
|
||||
break;
|
||||
}
|
||||
else if(!first_host_trap_config && cfg.method == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
else if(!first_remained_method_config &&
|
||||
cfg.method != ROCPROFILER_PC_SAMPLING_METHOD_NONE &&
|
||||
cfg.method != ROCPROFILER_PC_SAMPLING_METHOD_LAST)
|
||||
{
|
||||
first_host_trap_config = &cfg;
|
||||
first_remained_method_config = &cfg;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the stochastic config is found. Use host trap config otherwise.
|
||||
// Check if the config with the preferred method is found. Use config with other method
|
||||
// otherwise.
|
||||
const rocprofiler_pc_sampling_configuration_t* picked_cfg =
|
||||
(first_stochastic_config != nullptr) ? first_stochastic_config : first_host_trap_config;
|
||||
(first_preferred_method_config != nullptr) ? first_preferred_method_config
|
||||
: first_remained_method_config;
|
||||
|
||||
return *picked_cfg;
|
||||
}
|
||||
|
||||
rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer_stochastic(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
return extract_pc_sampling_config_prefer(ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC, agent_id);
|
||||
}
|
||||
|
||||
rocprofiler_pc_sampling_configuration_t
|
||||
extract_pc_sampling_config_prefer_host_trap(rocprofiler_agent_id_t agent_id)
|
||||
{
|
||||
return extract_pc_sampling_config_prefer(ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP, agent_id);
|
||||
}
|
||||
|
||||
void
|
||||
rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /*context_id*/,
|
||||
rocprofiler_buffer_id_t /*buffer_id*/,
|
||||
@@ -306,6 +322,41 @@ test_fail_because_service_is_already_configured(
|
||||
ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Current limitation - Stochastic and Host-Trap PC sampling cannot coexist
|
||||
* on the same device simultaneously.
|
||||
*/
|
||||
void
|
||||
test_fail_stochastic_vs_host_trap(const callback_data* cb_data,
|
||||
rocprofiler_agent_id_t agent_id,
|
||||
const rocprofiler_pc_sampling_configuration_t* picked_pcs_config)
|
||||
{
|
||||
// Ensure that stochastic sampling has been configured on the device.
|
||||
if(picked_pcs_config->method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
|
||||
{
|
||||
// KFD is implemented in the way that if stochastic is configured,
|
||||
// no host-trap configuration will be returned (and vice-versa).
|
||||
// Thus, ensure that the following function, although prefers host-trap,
|
||||
// returns stochastic.
|
||||
auto still_stochastic_config = extract_pc_sampling_config_prefer_host_trap(agent_id);
|
||||
EXPECT_EQ(still_stochastic_config.method, ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC);
|
||||
|
||||
constexpr uint64_t host_trap_interva_us = 1;
|
||||
// Now, ensure that a user cannot still force rocprofiler-sdk and configure host-trap
|
||||
// sampling on the device with configured stochastic sampling.
|
||||
// ensure that stochastic and host trap sampling cannot coexist on the same device.
|
||||
EXPECT_EQ(
|
||||
rocprofiler_configure_pc_sampling_service(cb_data->client_ctx,
|
||||
agent_id,
|
||||
ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP,
|
||||
ROCPROFILER_PC_SAMPLING_UNIT_TIME,
|
||||
host_trap_interva_us,
|
||||
cb_data->client_buffer,
|
||||
0),
|
||||
ROCPROFILER_STATUS_ERROR_SERVICE_ALREADY_CONFIGURED);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(pc_sampling, rocprofiler_configure_pc_sampling_service)
|
||||
@@ -388,6 +439,7 @@ TEST(pc_sampling, rocprofiler_configure_pc_sampling_service)
|
||||
"Failed to configure PC sampling service");
|
||||
|
||||
test_fail_because_service_is_already_configured(cb_data, agent_id, &pcs_config);
|
||||
test_fail_stochastic_vs_host_trap(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,
|
||||
|
||||
@@ -601,6 +601,7 @@ invoke_client_finalizer(rocprofiler_client_id_t client_id)
|
||||
|
||||
hsa::async_copy_sync();
|
||||
hsa::queue_controller_sync();
|
||||
pc_sampling::service_sync();
|
||||
|
||||
auto _fini_status = get_fini_status();
|
||||
if(_fini_status == 0) set_fini_status(-1);
|
||||
@@ -726,6 +727,8 @@ finalize()
|
||||
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
|
||||
// WARNING: this must precede `code_object::finalize()`
|
||||
pc_sampling::code_object::finalize();
|
||||
// WARNING: this must follows queue_controller_fini.
|
||||
pc_sampling::service_fini();
|
||||
#endif
|
||||
code_object::finalize();
|
||||
context::correlation_id_finalize();
|
||||
|
||||
Reference in New Issue
Block a user