SWDEV-465322: Adding support for Perfcounter SIMD Mask in ATT (#910)

* SWDEV-465322: Adding support for r Perfcounter SIMD Mask in ATT

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Welton <bewelton@amd.com>

* Adding unit tests

* Adding counters check for gfx9 and SQ block only

* Addressing review comments

* changing the struct size

* fixing header includes

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Welton <bewelton@amd.com>
此提交包含在:
Manjunath P Jakaraddi
2024-06-12 16:25:06 -07:00
提交者 GitHub
父節點 cfe3af9d7e
當前提交 c49719649b
共有 12 個檔案被更改,包括 227 行新增 和 43 行删除
+100 -4
查看文件
@@ -20,15 +20,28 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "lib/rocprofiler-sdk/agent.hpp"
#include "lib/rocprofiler-sdk/aql/helpers.hpp"
#include "lib/rocprofiler-sdk/aql/packet_construct.hpp"
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/counters/metrics.hpp"
#include "lib/rocprofiler-sdk/counters/tests/hsa_tables.hpp"
#include "lib/rocprofiler-sdk/hsa/agent_cache.hpp"
#include "lib/rocprofiler-sdk/hsa/queue.hpp"
#include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
#include "lib/rocprofiler-sdk/registration.hpp"
#include "lib/rocprofiler-sdk/thread_trace/att_core.hpp"
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <algorithm>
#include <cstdint>
#include <functional>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <hsa/hsa.h>
#include <hsa/hsa_api_trace.h>
#include <hsa/hsa_ven_amd_aqlprofile.h>
@@ -127,10 +140,10 @@ TEST(thread_trace, configure_test)
ROCPROFILER_CALL(rocprofiler_create_context(&ctx), "context creation failed");
std::vector<rocprofiler_att_parameter_t> params;
params.push_back({ROCPROFILER_ATT_PARAMETER_TARGET_CU, 1});
params.push_back({ROCPROFILER_ATT_PARAMETER_SHADER_ENGINE_MASK, 0xF});
params.push_back({ROCPROFILER_ATT_PARAMETER_BUFFER_SIZE, 0x1000000});
params.push_back({ROCPROFILER_ATT_PARAMETER_SIMD_SELECT, 0xF});
params.push_back({ROCPROFILER_ATT_PARAMETER_TARGET_CU, {1}});
params.push_back({ROCPROFILER_ATT_PARAMETER_SHADER_ENGINE_MASK, {0xF}});
params.push_back({ROCPROFILER_ATT_PARAMETER_BUFFER_SIZE, {0x1000000}});
params.push_back({ROCPROFILER_ATT_PARAMETER_SIMD_SELECT, {0xF}});
rocprofiler_configure_thread_trace_service(
ctx,
@@ -147,5 +160,88 @@ TEST(thread_trace, configure_test)
ASSERT_EQ(hsa_init(), HSA_STATUS_SUCCESS);
ROCPROFILER_CALL(rocprofiler_start_context(ctx), "context start failed");
ROCPROFILER_CALL(rocprofiler_stop_context(ctx), "context stop failed");
context::pop_client(1);
hsa_shut_down();
}
TEST(thread_trace, perfcounters_configure_test)
{
test_init();
registration::init_logging();
registration::set_init_status(-1);
context::push_client(1);
rocprofiler_context_id_t ctx;
ROCPROFILER_CALL(rocprofiler_create_context(&ctx), "context creation failed");
// Only GFX9 SQ Block counters are supported
std::vector<std::pair<std::string, uint64_t>> perf_counters = {
{"SQ_WAVES", 0x1}, {"SQ_WAVES", 0x2}, {"SQ_WAVES", 0x2}, {"GRBM_COUNT", 0x3}};
std::set<uint32_t> expected;
std::vector<rocprofiler_att_parameter_t> params;
params.push_back({ROCPROFILER_ATT_PARAMETER_PERFCOUNTERS_CTRL, {1}});
auto metrics = rocprofiler::counters::getMetricsForAgent("gfx90a");
for(auto& [counter_name, simd_mask] : perf_counters)
for(auto& metric : metrics)
if(metric.name() == counter_name)
{
params.push_back({ROCPROFILER_ATT_PARAMETER_PERFCOUNTER,
{.counter_id = {metric.id()}, .simd_mask = simd_mask}});
expected.insert(std::atoi(metric.event().c_str()) | (simd_mask << 28));
}
rocprofiler_configure_thread_trace_service(
ctx,
params.data(),
params.size(),
[](rocprofiler_queue_id_t,
const rocprofiler_agent_t*,
rocprofiler_correlation_id_t,
rocprofiler_kernel_id_t,
void*) { return ROCPROFILER_ATT_CONTROL_NONE; },
[](int64_t, void*, size_t, void*) {},
nullptr);
auto* context = rocprofiler::context::get_mutable_registered_context(ctx);
thread_trace_parameter_pack _params = context->thread_trace->params;
ASSERT_EQ(_params.perfcounter_ctrl, 1);
ASSERT_EQ(_params.perfcounters.size(), 3);
for(uint32_t param : _params.perfcounters)
EXPECT_TRUE(expected.find(param) != expected.end())
<< "valid AQLprofile mask not generated for perfcounters";
context::pop_client(1);
hsa_shut_down();
}
TEST(thread_trace, perfcounters_aql_options_test)
{
hsa_init();
test_init();
registration::init_logging();
registration::set_init_status(-1);
context::push_client(1);
const std::uint8_t sqtt_default_num_options = 5;
auto agents = hsa::get_queue_controller()->get_supported_agents();
thread_trace_parameter_pack _params = {};
auto metrics = rocprofiler::counters::getMetricsForAgent("gfx90a");
std::vector<std::pair<std::string, uint64_t>> perf_counters = {
{"SQ_WAVES", 0x1}, {"SQ_WAVES", 0x2}, {"GRBM_COUNT", 0x3}};
for(auto& [counter_name, simd_mask] : perf_counters)
for(auto& metric : metrics)
if(metric.name() == counter_name)
_params.perfcounters.push_back(std::atoi(metric.event().c_str()) |
(simd_mask << 28));
_params.perfcounter_ctrl = 2;
auto new_tracer = std::make_unique<AgentThreadTracer>(
_params, begin(agents)->second, get_api_table(), get_ext_table());
ASSERT_EQ(new_tracer->factory->get_aql_params().size(),
sqtt_default_num_options + perf_counters.size());
context::pop_client(1);
hsa_shut_down();
}