pcs parser: includes fixed, GLOB removed (#286)
* pcs parser: includes fixed, GLOB removed * source formatting (clang-format v11) (#287) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> * cmake formatting (cmake-format) (#288) Co-authored-by: vlaindic <vlaindic@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: vlaindic <vlaindic@users.noreply.github.com>
Bu işleme şunda yer alıyor:
işlemeyi yapan:
GitHub
ebeveyn
efbb154515
işleme
200be03bb4
@@ -1,5 +1,7 @@
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_SOURCES pc_record_interface.cpp)
|
||||
file(GLOB ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS *.h *.hpp)
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS
|
||||
correlation.hpp gfx9.hpp gfx11.hpp gfx_unknown.hpp parser_types.h pc_record_interface.hpp
|
||||
rocr.h translation.hpp)
|
||||
|
||||
target_sources(
|
||||
rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_SOURCES}
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "correlation.hpp"
|
||||
|
||||
template <>
|
||||
struct std::hash<device_handle>
|
||||
{
|
||||
size_t operator()(const device_handle& d) const { return d.handle; }
|
||||
};
|
||||
bool
|
||||
operator==(device_handle a, device_handle b)
|
||||
{
|
||||
return a.handle == b.handle;
|
||||
}
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
bool
|
||||
operator==(const DispatchPkt& a, const DispatchPkt& b)
|
||||
{
|
||||
return a.correlation_id_in == b.correlation_id_in && a.dev == b.dev;
|
||||
}
|
||||
} // namespace Parser
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
/**
|
||||
* Coordinates DispatchMap and DoorBellMap to reconstruct the original correlation_id
|
||||
* from the correlation_id seen by the trap handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks wether a dispatch pkt will generate a collision.
|
||||
* Returns true on collision and false when slot is available.
|
||||
*/
|
||||
bool
|
||||
CorrelationMap::checkDispatch(const dispatch_pkt_id_t& pkt) const
|
||||
{
|
||||
uint64_t trap = wrap_correlation_id(pkt.doorbell_id, pkt.write_index, pkt.queue_size);
|
||||
return dispatch_to_correlation.find({trap, pkt.device}) != dispatch_to_correlation.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the mapping of dispatch_id to correlation_id
|
||||
*/
|
||||
void
|
||||
CorrelationMap::newDispatch(const dispatch_pkt_id_t& pkt)
|
||||
{
|
||||
cache_dev_id = ~0ul;
|
||||
uint64_t trap_id = wrap_correlation_id(pkt.doorbell_id, pkt.write_index, pkt.queue_size);
|
||||
dispatch_to_correlation[{trap_id, pkt.device}] = pkt.correlation_id;
|
||||
}
|
||||
|
||||
void
|
||||
CorrelationMap::forget(const dispatch_pkt_id_t& pkt)
|
||||
{
|
||||
cache_dev_id = ~0ul;
|
||||
uint64_t trap_id = wrap_correlation_id(pkt.doorbell_id, pkt.write_index, pkt.queue_size);
|
||||
dispatch_to_correlation.erase({trap_id, pkt.device});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a device dev, doorbell and and wrapped dispatch_id, returns the
|
||||
* correlation_id set by dispatch_pkt_id_t
|
||||
*/
|
||||
uint64_t
|
||||
CorrelationMap::get(device_handle dev, uint64_t correlation_in)
|
||||
{
|
||||
#ifndef _PARSER_CORRELATION_DISABLE_CACHE
|
||||
if(dev.handle == cache_dev_id && correlation_in == cache_correlation_id_in)
|
||||
return cache_correlation_id_out;
|
||||
#endif
|
||||
cache_dev_id = dev.handle;
|
||||
cache_correlation_id_in = correlation_in;
|
||||
cache_correlation_id_out = dispatch_to_correlation.at({correlation_in, dev});
|
||||
return cache_correlation_id_out;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
CorrelationMap::wrap_correlation_id(uint64_t doorbell, uint64_t write_idx, uint64_t queue_size)
|
||||
{
|
||||
static constexpr uint64_t WRITE_WRAP = (1 << 25) - 1;
|
||||
return ((write_idx % queue_size) & WRITE_WRAP) | (uint64_t(doorbell) << 32);
|
||||
}
|
||||
|
||||
} // namespace Parser
|
||||
|
||||
/**
|
||||
* @brief Parses a given set of pc samples.
|
||||
* @param[in] buffer Pointer to a buffer containing metadata and pcsamples.
|
||||
* @param[in] buffer_size The number of elements in the buffer.
|
||||
* @param[in] gfxip_major GFXIP major version of the samples.
|
||||
* @param[in] callback A callback function that accepts a double pointer to write the samples to,
|
||||
* a size requested parameter (number of pc_sample_t) and a void* to userdata.
|
||||
* The callback is expected to allocate 64B-aligned memory where the parsed samples are going to
|
||||
* be written to, and return the size of memory that was allocated, in multiples of
|
||||
* sizeof(generic_sample_t). If the callback returns 0 or a larger size than requested,
|
||||
* parse_buffer() will return PCSAMPLE_STATUS_CALLBACK_ERROR. If the callback returns
|
||||
* a size smaller than requested, then it may be called again requesting more memory.
|
||||
* @param[in] userdata parameter forwarded to the user callback.
|
||||
*/
|
||||
pcsample_status_t
|
||||
parse_buffer(generic_sample_t* buffer,
|
||||
uint64_t buffer_size,
|
||||
int gfxip_major,
|
||||
user_callback_t callback,
|
||||
void* userdata)
|
||||
{
|
||||
static auto corr_map = std::make_unique<Parser::CorrelationMap>();
|
||||
|
||||
auto parseSample_func = _parse_buffer<GFX9>;
|
||||
if(gfxip_major == 9)
|
||||
parseSample_func = _parse_buffer<GFX9>;
|
||||
else if(gfxip_major == 11)
|
||||
parseSample_func = _parse_buffer<GFX11>;
|
||||
else if(gfxip_major == 0)
|
||||
parseSample_func = _parse_buffer<gfx_unknown>;
|
||||
else
|
||||
return PCSAMPLE_STATUS_INVALID_GFXIP;
|
||||
|
||||
return parseSample_func(buffer, buffer_size, callback, userdata, corr_map.get());
|
||||
};
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "translation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp"
|
||||
|
||||
template <>
|
||||
struct std::hash<device_handle>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include "pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
|
||||
uint64_t
|
||||
PCSamplingParserContext::alloc(pcsample_v1_t** buffer, uint64_t size)
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "correlation.hpp"
|
||||
#include "parser_types.h"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/parser_types.h"
|
||||
|
||||
struct PCSamplingData
|
||||
{
|
||||
|
||||
@@ -8,8 +8,7 @@ set(PCTEST_INCLUDE_DIR
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_ID_TEST_SOURCES correlation_id_test.cpp)
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_BENCH_TEST_SOURCES benchmark_test.cpp)
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_GFX9_TEST_SOURCES gfx9test.cpp)
|
||||
file(GLOB ROCPROFILER_LIB_PC_SAMPLING_PARSER_TEST_HEADERS mocks.hpp
|
||||
${ROCPROFILER_LIB_PC_SAMPLING_PARSER_HEADERS})
|
||||
set(ROCPROFILER_LIB_PC_SAMPLING_PARSER_TEST_HEADERS mocks.hpp)
|
||||
|
||||
add_executable(pcs_gfx9_test)
|
||||
|
||||
@@ -17,7 +16,10 @@ target_sources(pcs_gfx9_test
|
||||
PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_GFX9_TEST_SOURCES})
|
||||
target_include_directories(pcs_gfx9_test PRIVATE ${PCTEST_INCLUDE_DIR})
|
||||
|
||||
target_link_libraries(pcs_gfx9_test PRIVATE GTest::gtest GTest::gtest_main)
|
||||
target_link_libraries(
|
||||
pcs_gfx9_test
|
||||
PRIVATE rocprofiler::rocprofiler-common-library
|
||||
rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main)
|
||||
|
||||
gtest_add_tests(
|
||||
TARGET pcs_gfx9_test
|
||||
@@ -32,7 +34,10 @@ add_executable(pcs_id_test)
|
||||
target_sources(pcs_id_test PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_ID_TEST_SOURCES})
|
||||
target_include_directories(pcs_id_test PRIVATE ${PCTEST_INCLUDE_DIR})
|
||||
|
||||
target_link_libraries(pcs_id_test PRIVATE GTest::gtest GTest::gtest_main)
|
||||
target_link_libraries(
|
||||
pcs_id_test
|
||||
PRIVATE rocprofiler::rocprofiler-common-library
|
||||
rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main)
|
||||
|
||||
gtest_add_tests(
|
||||
TARGET pcs_id_test
|
||||
@@ -49,4 +54,7 @@ target_sources(pcs_bench_test
|
||||
PRIVATE ${ROCPROFILER_LIB_PC_SAMPLING_PARSER_BENCH_TEST_SOURCES})
|
||||
target_include_directories(pcs_bench_test PRIVATE ${PCTEST_INCLUDE_DIR})
|
||||
|
||||
target_link_libraries(pcs_bench_test PRIVATE GTest::gtest GTest::gtest_main)
|
||||
target_link_libraries(
|
||||
pcs_bench_test
|
||||
PRIVATE rocprofiler::rocprofiler-common-library
|
||||
rocprofiler::rocprofiler-static-library GTest::gtest GTest::gtest_main)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstddef>
|
||||
|
||||
#include "mocks.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp"
|
||||
|
||||
#define GFXIP_MAJOR 9
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstddef>
|
||||
|
||||
#include "mocks.hpp"
|
||||
#include "pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp"
|
||||
|
||||
#define GFXIP_MAJOR 9
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#include "mocks.hpp"
|
||||
#include "pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/tests/mocks.hpp"
|
||||
|
||||
#define GFXIP_MAJOR 9
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <random>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "correlation.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/correlation.hpp"
|
||||
|
||||
#define CHECK_PARSER(x) \
|
||||
{ \
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/translation.hpp"
|
||||
|
||||
pcsample_v1_t
|
||||
copyHostTrapSample(const perf_sample_host_trap_v1& sample)
|
||||
{
|
||||
pcsample_v1_t ret = PCSParserTranslation::copySampleHeader<perf_sample_host_trap_v1>(sample);
|
||||
ret.flags.type = AMD_HOST_TRAP_V1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename SType>
|
||||
pcsample_v1_t
|
||||
PCSParserTranslation::copySampleHeader(const SType& sample)
|
||||
{
|
||||
pcsample_v1_t ret;
|
||||
ret.flags.type = AMD_SNAPSHOT_V1;
|
||||
|
||||
ret.pc = sample.pc;
|
||||
ret.exec_mask = sample.exec_mask;
|
||||
ret.workgroup_id_x = sample.workgroup_id_x;
|
||||
ret.workgroup_id_y = sample.workgroup_id_y;
|
||||
ret.workgroup_id_z = sample.workgroup_id_z;
|
||||
|
||||
ret.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;
|
||||
}
|
||||
|
||||
template <typename gfx>
|
||||
pcsample_v1_t
|
||||
PCSParserTranslation::copyStochasticSample(const perf_sample_snapshot_v1& sample)
|
||||
{
|
||||
(void) sample;
|
||||
return {};
|
||||
};
|
||||
|
||||
template <>
|
||||
pcsample_v1_t
|
||||
PCSParserTranslation::copyStochasticSample<GFX9>(const perf_sample_snapshot_v1& sample)
|
||||
{
|
||||
pcsample_v1_t ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
ret.flags.valid = sample.perf_snapshot_data & (~sample.perf_snapshot_data >> 26) & 0x1;
|
||||
// Check wave_id matches snapshot_wave_id
|
||||
|
||||
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;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <>
|
||||
pcsample_v1_t
|
||||
PCSParserTranslation::copyStochasticSample<GFX11>(const perf_sample_snapshot_v1& sample)
|
||||
{
|
||||
// TODO: finish this
|
||||
return copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
}
|
||||
|
||||
template <>
|
||||
pcsample_v1_t
|
||||
PCSParserTranslation::copyStochasticSample<gfx_unknown>(const perf_sample_snapshot_v1& sample)
|
||||
{
|
||||
pcsample_v1_t ret = copySampleHeader<perf_sample_snapshot_v1>(sample);
|
||||
ret.flags.valid = sample.perf_snapshot_data & 0x1;
|
||||
// Check wave_id matches snapshot_wave_id
|
||||
|
||||
ret.flags.has_wave_cnt = true;
|
||||
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.wave_count = sample.perf_snapshot_data1 & 0x3F;
|
||||
ret.snapshot.arb_state_issue = (sample.perf_snapshot_data1 >> 6) & 0xFF;
|
||||
ret.snapshot.arb_state_stall = (sample.perf_snapshot_data1 >> 14) & 0xFF;
|
||||
|
||||
ret.flags.has_memory_counter = true;
|
||||
ret.memory_counters.raw = sample.perf_snapshot_data2;
|
||||
return ret;
|
||||
}
|
||||
@@ -26,11 +26,11 @@
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "gfx11.hpp"
|
||||
#include "gfx_unknown.hpp"
|
||||
#include "gfx9.hpp"
|
||||
#include "parser_types.h"
|
||||
#include "rocr.h"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx11.hpp"
|
||||
#include "lib/rocprofiler-sdk/pc_sampling/parser/gfx_unknown.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"
|
||||
|
||||
template <typename SType>
|
||||
inline pcsample_v1_t
|
||||
|
||||
Yeni konuda referans
Bir kullanıcı engelle