Files
rocm-systems/source/lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp
T

213 wiersze
7.0 KiB
C++
Czysty Zwykły widok Historia

2023-11-14 10:58:33 -06:00
// MIT License
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
2023-10-26 12:14:02 -03:00
#pragma once
2023-12-07 19:42:56 -03:00
#include <array>
2023-10-26 12:14:02 -03:00
#include <cstdint>
#include <cstring>
#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx11.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx9.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h"
#include "lib/rocprofiler-sdk/pc_sampling/parser/rocr.h"
2023-10-26 12:14:02 -03:00
2023-12-07 19:42:56 -03:00
template <typename SType>
2024-05-24 09:49:44 -05:00
inline rocprofiler_pc_sampling_record_t
2023-12-07 19:42:56 -03:00
copySampleHeader(const SType& sample)
{
2024-05-24 09:49:44 -05:00
rocprofiler_pc_sampling_record_t ret;
2024-04-18 07:42:26 -03:00
ret.flags = pcsample_header_v1_t{.raw = 0}.flags;
2023-12-07 19:42:56 -03:00
ret.flags.type = AMD_SNAPSHOT_V1;
ret.pc = sample.pc;
ret.exec_mask = sample.exec_mask;
2024-05-24 09:49:44 -05:00
ret.workgroup_id.x = sample.workgroup_id_x;
ret.workgroup_id.y = sample.workgroup_id_y;
ret.workgroup_id.z = sample.workgroup_id_z;
2023-12-07 19:42:56 -03:00
ret.chiplet = sample.chiplet_and_wave_id >> 8;
ret.wave_id = sample.chiplet_and_wave_id & 0x3F;
ret.hw_id = sample.hw_id;
ret.timestamp = sample.timestamp;
return ret;
}
2023-10-26 12:14:02 -03:00
2024-05-24 09:49:44 -05:00
inline rocprofiler_pc_sampling_record_t
2023-12-07 19:42:56 -03:00
copyHostTrapSample(const perf_sample_host_trap_v1& sample)
2023-10-26 12:14:02 -03:00
{
2024-05-24 09:49:44 -05:00
rocprofiler_pc_sampling_record_t ret = copySampleHeader<perf_sample_host_trap_v1>(sample);
2024-04-18 07:42:26 -03:00
ret.flags.type = AMD_HOST_TRAP_V1;
2023-12-07 19:42:56 -03:00
return ret;
}
2023-10-26 12:14:02 -03:00
2023-12-07 19:42:56 -03:00
template <typename gfx>
2024-05-24 09:49:44 -05:00
inline rocprofiler_pc_sampling_record_t
2023-12-07 19:42:56 -03:00
copyStochasticSample(const perf_sample_snapshot_v1& sample);
template <>
2024-05-24 09:49:44 -05:00
inline rocprofiler_pc_sampling_record_t
2023-12-07 19:42:56 -03:00
copyStochasticSample<GFX9>(const perf_sample_snapshot_v1& sample)
{
2024-05-24 09:49:44 -05:00
rocprofiler_pc_sampling_record_t ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
2024-04-18 07:42:26 -03:00
ret.flags.valid = sample.perf_snapshot_data & (~sample.perf_snapshot_data >> 26) & 0x1;
2023-12-07 19:42:56 -03:00
// Check wave_id matches snapshot_wave_id
ret.flags.has_wave_cnt = true;
ret.flags.has_stall_reason = true;
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;
ret.snapshot.arb_state_issue = (sample.perf_snapshot_data >> 10) & 0xFF;
ret.snapshot.arb_state_stall = (sample.perf_snapshot_data >> 18) & 0xFF;
2024-04-18 07:42:26 -03:00
ret.reserved = 0;
2023-12-07 19:42:56 -03:00
return ret;
}
template <>
2024-05-24 09:49:44 -05:00
inline rocprofiler_pc_sampling_record_t
2023-12-07 19:42:56 -03:00
copyStochasticSample<GFX11>(const perf_sample_snapshot_v1& sample)
{
2024-05-24 09:49:44 -05:00
rocprofiler_pc_sampling_record_t ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
2024-04-18 07:42:26 -03:00
ret.flags.valid = sample.perf_snapshot_data & (~sample.perf_snapshot_data >> 23) & 0x1;
2023-12-07 19:42:56 -03:00
// Check wave_id matches snapshot_wave_id
ret.flags.has_stall_reason = true;
ret.wave_issued = sample.perf_snapshot_data >> 1;
ret.snapshot.inst_type = sample.perf_snapshot_data >> 2;
ret.snapshot.reason_not_issued = (sample.perf_snapshot_data >> 6) & 0x7;
ret.snapshot.arb_state_issue = (sample.perf_snapshot_data >> 9) & 0x7F;
ret.snapshot.arb_state_stall = (sample.perf_snapshot_data >> 16) & 0x7F;
ret.snapshot.dual_issue_valu = false;
2024-04-18 07:42:26 -03:00
ret.reserved = 0;
2023-12-07 19:42:56 -03:00
return ret;
}
2023-10-26 12:14:02 -03:00
#define BITSHIFT(sname) out |= ((in >> GFX::sname) & 1) << PCSAMPLE::sname
template <typename GFX>
2023-12-07 19:42:56 -03:00
inline int
2023-10-26 12:14:02 -03:00
translate_arb(int in)
{
size_t out = 0;
BITSHIFT(ISSUE_VALU);
BITSHIFT(ISSUE_MATRIX);
BITSHIFT(ISSUE_LDS);
BITSHIFT(ISSUE_LDS_DIRECT);
BITSHIFT(ISSUE_SCALAR);
BITSHIFT(ISSUE_VMEM_TEX);
BITSHIFT(ISSUE_FLAT);
BITSHIFT(ISSUE_EXP);
BITSHIFT(ISSUE_MISC);
BITSHIFT(ISSUE_BRMSG);
return out & 0x3FF;
}
#undef BITSHIFT
#define LUTOVERLOAD(sname) this->operator[](GFX::sname) = PCSAMPLE::sname
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>
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>
2023-12-07 19:42:56 -03:00
inline int
2023-10-26 12:14:02 -03:00
translate_reason(int in)
{
static GFX_REASON_LUT<GFX> lut;
2023-12-07 19:42:56 -03:00
return lut[in & 0x1F];
2023-10-26 12:14:02 -03:00
}
template <typename GFX>
2023-12-07 19:42:56 -03:00
inline int
2023-10-26 12:14:02 -03:00
translate_inst(int in)
{
static GFX_INST_LUT<GFX> lut;
2023-12-07 19:42:56 -03:00
return lut[in & 0x1F];
2023-10-26 12:14:02 -03:00
}
#undef LUTOVERLOAD
template <bool HostTrap, typename GFX>
2024-05-24 09:49:44 -05:00
inline rocprofiler_pc_sampling_record_t
2023-10-26 12:14:02 -03:00
copySample(const void* sample)
{
if(HostTrap) return copyHostTrapSample(*(const perf_sample_host_trap_v1*) sample);
2024-05-24 09:49:44 -05:00
rocprofiler_pc_sampling_record_t ret =
2024-04-18 07:42:26 -03:00
copyStochasticSample<GFX>(*(const perf_sample_snapshot_v1*) sample);
2023-10-26 12:14:02 -03:00
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;
}