Contributors:
Ammar ELWazir <aelwazir@amd.com>
AravindanC <aravindan.cheruvally@amd.com>
Benjamin Welton <bewelton@amd.com>
Ma, Bing <Bing.Ma@amd.com>
Chun Yang <chun.yang@amd.com>
Cole Nelson <cole.nelson@amd.com>
Ethan Stewart <ethan.stewart@amd.com>
Evgeny <evgeny.shcherbakov@amd.com>
Freddy Paul <Freddy.paul@amd.com>
Giovanni Baraldi <gbaraldi@amd.com>
Gopesh Bhardwaj <Gopesh.Bhardwaj@amd.com>
Icarus Sparry <icarus.sparry@amd.com>
itrowbri <Ian.Trowbridge@amd.com>
James Edwards <JamesAdrian.Edwards@amd.com>
jatang <jatang@amd.com>
Jeremy Newton <Jeremy.Newton@amd.com>
Jonathan Kim <jonathan.kim@amd.com>
Kent Russell <kent.russell@amd.com>
Kiumars Sabeti <kiumars.sabeti@amd.com>
Lang Yu <lang.yu@amd.com>
Laurent Morichetti <laurent.morichetti@amd.com>
Mallya, Ameya Keshava <AmeyaKeshava.Mallya@amd.com>
Manjunath Jakaraddi <manjunath.jakaraddi@amd.com>
Mark Laws <markdavid.laws@amd.com>
Mohan Kumar Mithur <Mohan.KumarMithur@amd.com>
Nicholas Curtis <nicurtis@amd.com>
Nirmal Unnikrishnan <Nirmal.Unnikrishnan@amd.com>
Parag Bhandari <parag.bhandari@amd.com>
Ranjith Ramakrishnan <Ranjith.Ramakrishnan@amd.com>
Robert Gregory <Robert.Gregory@amd.com>
Saravanan Solaiyappan <saravanan.solaiyappan@amd.com>
Saurabh Verma <saurabh.verma@amd.com>
Srihari Uttanur <srihari.u@amd.com>
Srinivasan Subramanian <srinivasan.subramanian@amd.com>
Sriraksha Nagaraj <Sriraksha.Nagaraj@amd.com>
Sushma Vaddireddy <svaddire@amd.com>
Xianwei Zhang <Xianwei.Zhang@amd.com>
Šī revīzija ir iekļauta:
Evgeny
2017-06-20 17:43:27 -05:00
revīziju iesūtīja Ammar ELWazir
vecāks 7c7d7b4022
revīzija 1ed169e30c
157 mainīti faili ar 371830 papildinājumiem un 0 dzēšanām
+41
Parādīt failu
@@ -0,0 +1,41 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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.
#ifndef TEST_PGEN_TEST_PGEN_H_
#define TEST_PGEN_TEST_PGEN_H_
#include "pgen/test_pmgr.h"
// simple_convolution: Class implements OpenCL simple_convolution sample
class TestPGen : public TestPMgr {
protected:
typedef hsa_ext_amd_aql_pm4_packet_t packet_t;
packet_t* PrePacket() { return reinterpret_cast<packet_t*>(&pre_packet_); }
packet_t* PostPacket() { return reinterpret_cast<packet_t*>(&post_packet_); }
public:
explicit TestPGen(TestAql* t) : TestPMgr(t) {}
};
#endif // TEST_PGEN_TEST_PGEN_H_
+82
Parādīt failu
@@ -0,0 +1,82 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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.
#ifndef TEST_PGEN_TEST_PGEN_PCSMP_H_
#define TEST_PGEN_TEST_PGEN_PCSMP_H_
#include <cstdint>
#include <iostream>
#include "pgen/test_pgen.h"
#include "pgen/test_pgen_sqtt.h"
#include "util/test_assert.h"
// PC sampling callback data
struct pcsmp_callback_data_t {
const char* kernel_name; // sampled kernel name
void* data_buffer; // host buffer for tracing data
uint64_t id; // sample id
uint64_t cycle; // sample cycle
uint64_t pc; // sample PC
};
hsa_status_t TestPGenPcsmpCallback(hsa_ven_amd_aqlprofile_info_type_t info_type,
hsa_ven_amd_aqlprofile_info_data_t* info_data,
void* callback_data) {
hsa_status_t status = HSA_STATUS_SUCCESS;
pcsmp_callback_data_t* pcsmp_data = reinterpret_cast<pcsmp_callback_data_t*>(callback_data);
std::cout << "id(" << std::dec << pcsmp_data->id << ") cycle(" << std::dec << pcsmp_data->cycle
<< ") pc(0x" << std::hex << pcsmp_data->pc << ") name(\"" << pcsmp_data->kernel_name
<< "\")" << std::dec << std::endl
<< std::flush;
return status;
}
// Class implements SQTT profiling
class TestPGenPcsmp : public TestPGenSqtt {
public:
explicit TestPGenPcsmp(TestAql* t) : TestPGenSqtt(t) {
std::clog << "Test: PGen PC sampling" << std::endl;
}
bool DumpData() {
std::clog << "TestPGenPcsmp::DumpData :" << std::endl;
TEST_ASSERT(profile_.event_count == 0);
profile_.event_count = UINT32_MAX;
pcsmp_callback_data_t data{};
data.kernel_name = Name();
// allocate host space
void* sys_buf = GetRsrcFactory()->AllocateSysMemory(GetAgentInfo(), TestPGenSqtt::buffer_size_);
TEST_ASSERT(sys_buf != NULL);
if (sys_buf == NULL) return false;
data.data_buffer = sys_buf;
api_->hsa_ven_amd_aqlprofile_iterate_data(&profile_, TestPGenPcsmpCallback, &data);
return true;
}
};
#endif // TEST_PGEN_TEST_PGEN_PCSMP_H_
+190
Parādīt failu
@@ -0,0 +1,190 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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.
#ifndef TEST_PGEN_TEST_PGEN_PMC_H_
#define TEST_PGEN_TEST_PGEN_PMC_H_
#include <list>
#include <vector>
#include "pgen/test_pgen.h"
#include "util/test_assert.h"
typedef std::vector<hsa_ven_amd_aqlprofile_info_data_t> callback_data_t;
hsa_status_t TestPGenPmcCallback(hsa_ven_amd_aqlprofile_info_type_t info_type,
hsa_ven_amd_aqlprofile_info_data_t* info_data,
void* callback_data) {
hsa_status_t status = HSA_STATUS_SUCCESS;
reinterpret_cast<callback_data_t*>(callback_data)->push_back(*info_data);
return status;
}
// Class implements PMC profiling
template <int MODE>
class TestPGenPmc : public TestPGen {
public:
explicit TestPGenPmc(TestAql* t) : TestPGen(t) {
std::clog << "Test: PGen PMC" << std::endl;
profile_ = hsa_ven_amd_aqlprofile_profile_t{};
}
~TestPGenPmc() { delete[] profile_.events; }
bool Initialize(int arg_cnt, char** arg_list) {
std::vector<hsa_ven_amd_aqlprofile_event_t> event_vec;
for (int i = 0; i < arg_cnt; ++i) {
unsigned block_id = 0;
unsigned block_index = 0;
unsigned event_id = 0;
sscanf(arg_list[i], "%u:%u:%u", &block_id, &block_index, &event_id);
const hsa_ven_amd_aqlprofile_event_t event = {
static_cast<hsa_ven_amd_aqlprofile_block_name_t>(block_id), block_index, event_id};
event_vec.push_back(event);
}
if (!TestPMgr::Initialize(arg_cnt, arg_list)) return false;
hsa_status_t status;
hsa_agent_t agent;
uint32_t command_buffer_alignment;
uint32_t command_buffer_size;
uint32_t output_buffer_alignment;
uint32_t output_buffer_size;
// GPU identificator
agent = GetAgentInfo()->dev_id;
// Preparing events vector
std::vector<hsa_ven_amd_aqlprofile_event_t> event_vec_filtered;
for (auto it = event_vec.begin(); it != event_vec.end(); ++it) {
bool result = false;
hsa_status_t status = api_->hsa_ven_amd_aqlprofile_validate_event(agent, &(*it), &result);
if (status != HSA_STATUS_SUCCESS) {
const char* str = "";
api_->hsa_ven_amd_aqlprofile_error_string(&str);
std::cerr << "aqlprofile err: " << str << std::endl;
}
if (!result) {
std::cerr << "Bad event: block (" << it->block_name << "_" << it->block_index << ") id ("
<< it->counter_id << ")" << std::endl;
} else {
event_vec_filtered.push_back(*it);
std::cerr << "Good event: block (" << it->block_name << "_" << it->block_index << ") id ("
<< it->counter_id << ")" << std::endl;
}
}
const size_t event_count = event_vec_filtered.size();
hsa_ven_amd_aqlprofile_event_t* events = new hsa_ven_amd_aqlprofile_event_t[event_count];
for (uint32_t i = 0; i < event_count; ++i) {
events[i] = event_vec_filtered.at(i);
}
if (!event_count) return false;
// Initialization the profile
memset(&profile_, 0, sizeof(profile_));
profile_.agent = agent;
profile_.type = HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_PMC;
// Set enabled events list
profile_.events = events;
profile_.event_count = event_count;
// Profile buffers attributes
command_buffer_alignment = buffer_alignment_;
output_buffer_alignment = buffer_alignment_;
status = api_->hsa_ven_amd_aqlprofile_start(&profile_, NULL);
if (status != HSA_STATUS_SUCCESS) {
const char* str;
api_->hsa_ven_amd_aqlprofile_error_string(&str);
std::cerr << "aqlprofile err: " << str << std::endl;
}
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
if (status != HSA_STATUS_SUCCESS) return false;
command_buffer_size = profile_.command_buffer.size;
output_buffer_size = profile_.output_buffer.size;
// Application is allocating the command buffer
// Allocate(command_buffer_alignment, command_buffer_size,
// MODE_HOST_ACC|MODE_DEV_ACC|MODE_EXEC_DATA)
profile_.command_buffer.ptr =
GetRsrcFactory()->AllocateCmdMemory(GetAgentInfo(), command_buffer_size);
TEST_ASSERT(profile_.command_buffer.ptr != NULL);
TEST_ASSERT((reinterpret_cast<uintptr_t>(profile_.command_buffer.ptr) &
(command_buffer_alignment - 1)) == 0);
// Application is allocating the output buffer
// Allocate(output_buffer_alignment, output_buffer_size,
// MODE_HOST_ACC|MODE_DEV_ACC)
profile_.output_buffer.ptr =
GetRsrcFactory()->AllocateKernArgMemory(GetAgentInfo(), output_buffer_size);
TEST_ASSERT(profile_.output_buffer.ptr != NULL);
// aqlprofile expects the caller to zero the memory
memset(profile_.output_buffer.ptr, 0x0, output_buffer_size);
TEST_ASSERT((reinterpret_cast<uintptr_t>(profile_.output_buffer.ptr) &
(output_buffer_alignment - 1)) == 0);
// Populating the AQL start packet
status = api_->hsa_ven_amd_aqlprofile_start(&profile_, PrePacket());
if (status != HSA_STATUS_SUCCESS) {
const char* str;
api_->hsa_ven_amd_aqlprofile_error_string(&str);
std::cerr << "aqlprofile err: " << str << std::endl;
}
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
if (status != HSA_STATUS_SUCCESS) return false;
// Populating the AQL stop packet
status = api_->hsa_ven_amd_aqlprofile_stop(&profile_, PostPacket());
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
return (status == HSA_STATUS_SUCCESS);
}
private:
// bool BuildPackets() { return true; }
int GetMode() { return MODE; }
bool DumpData() {
std::clog << "TestPGenPmc::DumpData :" << std::endl;
callback_data_t data;
api_->hsa_ven_amd_aqlprofile_iterate_data(&profile_, TestPGenPmcCallback, &data);
for (callback_data_t::iterator it = data.begin(); it != data.end(); ++it) {
std::cout << std::dec << "event(block(" << it->pmc_data.event.block_name << "_"
<< it->pmc_data.event.block_index << "), id(" << it->pmc_data.event.counter_id
<< ")), sample(" << it->sample_id << "), result(" << it->pmc_data.result << ")"
<< std::endl;
}
return true;
}
static const uint32_t buffer_alignment_ = 0x1000; // 4K
hsa_ven_amd_aqlprofile_profile_t profile_;
};
#endif // TEST_PGEN_TEST_PGEN_PMC_H_
+206
Parādīt failu
@@ -0,0 +1,206 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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.
#ifndef TEST_PGEN_TEST_PGEN_SPM_H_
#define TEST_PGEN_TEST_PGEN_SPM_H_
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include "pgen/test_pgen.h"
#include "util/test_assert.h"
typedef std::vector<hsa_ven_amd_aqlprofile_info_data_t> callback_data_t;
hsa_status_t TestPGenSpmCallback(hsa_ven_amd_aqlprofile_info_type_t info_type,
hsa_ven_amd_aqlprofile_info_data_t* info_data,
void* callback_data) {
hsa_status_t status = HSA_STATUS_SUCCESS;
reinterpret_cast<callback_data_t*>(callback_data)->push_back(*info_data);
return status;
}
// Class implements SPM profiling
class TestPGenSpm : public TestPGen {
public:
explicit TestPGenSpm(TestAql* t) : TestPGen(t) {
std::clog << "Test: PGen SPM" << std::endl;
profile_ = hsa_ven_amd_aqlprofile_profile_t{};
}
bool Initialize(int arg_cnt, char** arg_list) {
std::vector<hsa_ven_amd_aqlprofile_event_t> event_vec;
for (int i = 0; i < arg_cnt; ++i) {
unsigned block_id = 0;
unsigned block_index = 0;
unsigned event_id = 0;
sscanf(arg_list[i], "%u:%u:%u", &block_id, &block_index, &event_id);
const hsa_ven_amd_aqlprofile_event_t event = {
static_cast<hsa_ven_amd_aqlprofile_block_name_t>(block_id), block_index, event_id};
event_vec.push_back(event);
}
if (!TestPMgr::Initialize(arg_cnt, arg_list)) return false;
hsa_status_t status;
hsa_agent_t agent;
uint32_t command_buffer_alignment;
uint32_t command_buffer_size;
uint32_t output_buffer_alignment;
uint32_t output_buffer_size;
// GPU identificator
agent = GetAgentInfo()->dev_id;
// Preparing events vector
std::vector<hsa_ven_amd_aqlprofile_event_t> event_vec_filtered;
for (auto it = event_vec.begin(); it != event_vec.end(); ++it) {
bool result = false;
hsa_status_t status = api_->hsa_ven_amd_aqlprofile_validate_event(agent, &(*it), &result);
if (status != HSA_STATUS_SUCCESS) {
const char* str = "";
api_->hsa_ven_amd_aqlprofile_error_string(&str);
std::cerr << "aqlprofile err: " << str << std::endl;
}
if (!result) {
std::cerr << "Bad event: block (" << it->block_name << "_" << it->block_index << ") id ("
<< it->counter_id << ")" << std::endl;
} else {
event_vec_filtered.push_back(*it);
}
}
const size_t event_count = event_vec_filtered.size();
hsa_ven_amd_aqlprofile_event_t* events = new hsa_ven_amd_aqlprofile_event_t[event_count];
for (uint32_t i = 0; i < event_count; ++i) {
events[i] = event_vec_filtered.at(i);
}
// Initialization of the profile
memset(&profile_, 0, sizeof(profile_));
profile_.agent = agent;
profile_.type = HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_TRACE;
// Set sample rate parameter
hsa_ven_amd_aqlprofile_parameter_t parameter;
parameter.parameter_name = HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_SAMPLE_RATE;
parameter.value = spm_sample_rate_;
profile_.parameters = &parameter;
profile_.parameter_count = 1;
// Set enabled events list
profile_.events = events;
profile_.event_count = event_count;
// Profile buffers attributes
command_buffer_alignment = buffer_alignment_;
status = api_->hsa_ven_amd_aqlprofile_get_info(
&profile_, HSA_VEN_AMD_AQLPROFILE_INFO_COMMAND_BUFFER_SIZE, &command_buffer_size);
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
output_buffer_alignment = buffer_alignment_;
output_buffer_size = buffer_size_;
// Application is allocating the command buffer
// AllocateSystem(command_buffer_alignment, command_buffer_size,
// MODE_HOST_ACC|MODE_DEV_ACC|MODE_EXEC_DATA)
profile_.command_buffer.ptr =
GetRsrcFactory()->AllocateCmdMemory(GetAgentInfo(), command_buffer_size);
TEST_ASSERT(profile_.command_buffer.ptr != NULL);
profile_.command_buffer.size = command_buffer_size;
TEST_ASSERT((reinterpret_cast<uintptr_t>(profile_.command_buffer.ptr) &
(command_buffer_alignment - 1)) == 0);
// Application is allocating the output buffer
// AllocateLocal(output_buffer_alignment, output_buffer_size,
// MODE_DEV_ACC)
profile_.output_buffer.ptr =
GetRsrcFactory()->AllocateLocalMemory(GetAgentInfo(), output_buffer_size);
TEST_ASSERT(profile_.output_buffer.ptr != NULL);
profile_.output_buffer.size = output_buffer_size;
TEST_ASSERT((reinterpret_cast<uintptr_t>(profile_.output_buffer.ptr) &
(output_buffer_alignment - 1)) == 0);
// Populating the AQL start packet
status = api_->hsa_ven_amd_aqlprofile_start(&profile_, PrePacket());
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
if (status != HSA_STATUS_SUCCESS) return false;
// Populating the AQL stop packet
status = api_->hsa_ven_amd_aqlprofile_stop(&profile_, PostPacket());
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
return (status == HSA_STATUS_SUCCESS);
}
int GetMode() { return RUN_MODE; }
bool BuildPackets() { return true; }
bool DumpData() {
std::clog << "TestPGenSpm::DumpData :" << std::endl;
callback_data_t data;
api_->hsa_ven_amd_aqlprofile_iterate_data(&profile_, TestPGenSpmCallback, &data);
for (callback_data_t::iterator it = data.begin(); it != data.end(); ++it) {
std::cout << "sample(" << std::dec << it->sample_id << ") size(" << std::dec
<< it->trace_data.size << ") ptr(" << std::hex << it->trace_data.ptr << ")"
<< std::endl;
void* sys_buf = GetRsrcFactory()->AllocateSysMemory(GetAgentInfo(), it->trace_data.size);
TEST_ASSERT(sys_buf != NULL);
if (sys_buf == NULL) return false;
hsa_status_t status = hsa_memory_copy(sys_buf, it->trace_data.ptr, it->trace_data.size);
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
if (status != HSA_STATUS_SUCCESS) return false;
std::string file_name;
file_name.append("spm_dump_");
file_name.append(std::to_string(it->sample_id));
file_name.append(".txt");
std::ofstream out_file;
out_file.open(file_name);
// Write the buffer in terms of shorts (16 bits)
uint16_t* trace_data = reinterpret_cast<uint16_t*>(sys_buf);
for (unsigned i = 0; i < (it->trace_data.size / sizeof(uint16_t)); ++i) {
out_file << std::setw(4) << std::setfill('0') << std::hex << trace_data[i] << "\n";
}
out_file.close();
}
return true;
}
static const uint32_t buffer_alignment_ = 0x1000; // 4K
static const uint32_t buffer_size_ = 0x2000000; // 32M
static const uint32_t spm_sample_rate_ = 10000; // default SPM sample rate
hsa_ven_amd_aqlprofile_profile_t profile_;
};
#endif // TEST_PGEN_TEST_PGEN_SPM_H_
+168
Parādīt failu
@@ -0,0 +1,168 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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.
#ifndef TEST_PGEN_TEST_PGEN_SQTT_H_
#define TEST_PGEN_TEST_PGEN_SQTT_H_
#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>
#include "pgen/test_pgen.h"
#include "util/test_assert.h"
typedef std::vector<hsa_ven_amd_aqlprofile_info_data_t> callback_data_t;
hsa_status_t TestPGenSqttCallback(hsa_ven_amd_aqlprofile_info_type_t info_type,
hsa_ven_amd_aqlprofile_info_data_t* info_data,
void* callback_data) {
hsa_status_t status = HSA_STATUS_SUCCESS;
reinterpret_cast<callback_data_t*>(callback_data)->push_back(*info_data);
return status;
}
// Class implements SQTT profiling
class TestPGenSqtt : public TestPGen {
public:
explicit TestPGenSqtt(TestAql* t) : TestPGen(t) {
std::clog << "Test: PGen SQTT" << std::endl;
profile_ = hsa_ven_amd_aqlprofile_profile_t{};
}
bool Initialize(int arg_cnt, char** arg_list) {
if (!TestPMgr::Initialize(arg_cnt, arg_list)) return false;
hsa_status_t status;
hsa_agent_t agent;
uint32_t command_buffer_size;
// GPU identificator
agent = GetAgentInfo()->dev_id;
// Initialization of the profile
memset(&profile_, 0, sizeof(profile_));
profile_.agent = agent;
profile_.type = HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_TRACE;
// Profile buffers attributes
status = api_->hsa_ven_amd_aqlprofile_get_info(
&profile_, HSA_VEN_AMD_AQLPROFILE_INFO_COMMAND_BUFFER_SIZE, &command_buffer_size);
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
// Application is allocating the command buffer
// AllocateSystem(buffer_alignment_, command_buffer_size,
// MODE_HOST_ACC|MODE_DEV_ACC|MODE_EXEC_DATA)
profile_.command_buffer.ptr =
GetRsrcFactory()->AllocateCmdMemory(GetAgentInfo(), command_buffer_size);
TEST_ASSERT(profile_.command_buffer.ptr != NULL);
profile_.command_buffer.size = command_buffer_size;
TEST_ASSERT((reinterpret_cast<uintptr_t>(profile_.command_buffer.ptr) & buffer_bitmask) == 0);
this->parameters = {
{HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_COMPUTE_UNIT_TARGET, 1},
{HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_SE_MASK, 0x55555555},
{static_cast<hsa_ven_amd_aqlprofile_parameter_name_t>(8), 0x1},
};
profile_.parameters = parameters.data();
profile_.parameter_count = parameters.size();
// Application is allocating the output buffer
// AllocateLocal(buffer_alignment_, buffer_size_, MODE_DEV_ACC)
profile_.output_buffer.ptr = GetRsrcFactory()->AllocateSysMemory(GetAgentInfo(), buffer_size_);
profile_.output_buffer.size = buffer_size_;
TEST_ASSERT(profile_.output_buffer.ptr != NULL);
TEST_ASSERT((reinterpret_cast<uintptr_t>(profile_.output_buffer.ptr) & buffer_bitmask) == 0);
// Populating the AQL start packet
status = api_->hsa_ven_amd_aqlprofile_start(&profile_, PrePacket());
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
if (status != HSA_STATUS_SUCCESS) return false;
// Populating the AQL stop packet
status = api_->hsa_ven_amd_aqlprofile_stop(&profile_, PostPacket());
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
return (status == HSA_STATUS_SUCCESS);
}
int GetMode() { return RUN_MODE; }
bool BuildPackets() { return true; }
bool DumpData() {
std::clog << "TestPGenSqtt::DumpData :" << std::endl;
bool bSomeSECollected = false;
callback_data_t data;
api_->hsa_ven_amd_aqlprofile_iterate_data(&profile_, TestPGenSqttCallback, &data);
for (callback_data_t::iterator it = data.begin(); it != data.end(); ++it) {
std::cout << "sample(" << std::dec << it->sample_id << ") size(" << std::dec
<< it->trace_data.size << ") ptr(" << std::hex << it->trace_data.ptr << ")"
<< std::dec << std::endl;
if (it->trace_data.size == 0) continue;
void* sys_buf = GetRsrcFactory()->AllocateSysMemory(GetAgentInfo(), it->trace_data.size);
TEST_ASSERT(sys_buf != NULL);
if (sys_buf == NULL) return false;
hsa_status_t status = hsa_memory_copy(sys_buf, it->trace_data.ptr, it->trace_data.size);
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
if (status != HSA_STATUS_SUCCESS) return false;
{
std::ofstream out_file("sqtt_dump_" + std::to_string(it->sample_id) + ".txt");
if (out_file.is_open()) {
out_file << std::hex;
// Write the buffer in terms of shorts (16 bits)
uint16_t* trace_data = (uint16_t*)sys_buf;
for (unsigned i = 0; i < (it->trace_data.size / sizeof(uint16_t)); ++i)
out_file << std::setw(4) << std::setfill('0') << trace_data[i] << "\n";
out_file << std::dec;
}
}
{
std::ofstream out_file("sqtt_dump_" + std::to_string(it->sample_id) + ".bin",
std::ios::binary);
if (out_file.is_open())
out_file.write(static_cast<const char*>(sys_buf), it->trace_data.size);
}
GetRsrcFactory()->FreeMemory(sys_buf);
bSomeSECollected = true;
}
TEST_ASSERT(bSomeSECollected == true);
return true;
}
static const uint32_t buffer_alignment_ = 0x1000; // 4K
static const uint32_t buffer_bitmask = buffer_alignment_ - 1; // 0xFFF
static const uint32_t buffer_size_ = 0x2000000; // 32M
std::vector<hsa_ven_amd_aqlprofile_parameter_t> parameters;
hsa_ven_amd_aqlprofile_profile_t profile_;
};
#endif // TEST_PGEN_TEST_PGEN_SQTT_H_
+115
Parādīt failu
@@ -0,0 +1,115 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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 "pgen/test_pmgr.h"
#include <atomic>
#include "util/test_assert.h"
bool TestPMgr::AddPacket(const packet_t* packet) {
GetRsrcFactory()->Submit(GetQueue(), packet);
return true;
}
bool TestPMgr::AddWaitPacket(packet_t* packet, hsa_signal_t signal) {
// Set packet completion signal
packet->completion_signal = signal;
// Submit Dispatch Aql packet
bool result = AddPacket(packet);
// Wait for Dispatch packet to complete
hsa_signal_wait_acquire(signal, HSA_SIGNAL_CONDITION_LT, 1, (uint64_t)-1, HSA_WAIT_STATE_BLOCKED);
hsa_signal_store_relaxed(signal, 1);
return result;
}
bool TestPMgr::Setup() {
// Build Aql Pkts
const int mode = GetMode();
if (mode == SETUP_MODE) {
// Submit Pre-Dispatch Aql packet
AddWaitPacket(&pre_packet_, packet_signal_);
}
Test()->Setup();
if (mode == SETUP_MODE) {
// Submit Post-Dispatch Aql packet
AddWaitPacket(&post_packet_, packet_signal_);
// Dumping profiling data
DumpData();
}
return true;
}
bool TestPMgr::Run() {
// Build Aql Pkts
const int mode = GetMode();
if (mode == RUN_MODE) {
// Submit Pre-Dispatch Aql packet
AddWaitPacket(&pre_packet_, packet_signal_);
}
Test()->Run();
if (getenv("AQLPROFILE_SDMA") != NULL) Test()->RunSdma(0x1000);
if (mode == RUN_MODE) {
// Submit Post-Dispatch Aql packet
AddWaitPacket(&post_packet_, packet_signal_);
// Dumping profiling data
DumpData();
}
return true;
}
bool TestPMgr::Initialize(int argc, char** argv) {
TestAql::Initialize(argc, argv);
hsa_status_t status = hsa_signal_create(1, 0, NULL, &packet_signal_);
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
api_ = HsaRsrcFactory::Instance().AqlProfileApi();
return true;
}
TestPMgr::TestPMgr(TestAql* t) : TestAql(t), api_(NULL) {
memset(&pre_packet_, 0, sizeof(pre_packet_));
memset(&post_packet_, 0, sizeof(post_packet_));
dummy_signal_.handle = 0;
packet_signal_ = dummy_signal_;
}
TestPMgr::~TestPMgr() {
if (packet_signal_.handle != 0) {
hsa_status_t status = hsa_signal_destroy(packet_signal_);
TEST_ASSERT(status == HSA_STATUS_SUCCESS);
}
}
+71
Parādīt failu
@@ -0,0 +1,71 @@
// MIT License
//
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc.
//
// 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.
#ifndef TEST_PGEN_TEST_PMGR_H_
#define TEST_PGEN_TEST_PMGR_H_
#include <hsa/hsa.h>
#include <hsa/hsa_ven_amd_aqlprofile.h>
#include <atomic>
#include "ctrl/test_aql.h"
enum Mode { SETUP_MODE, RUN_MODE, UNKNOWN };
// Class implements profiling manager
class TestPMgr : public TestAql {
public:
typedef hsa_ext_amd_aql_pm4_packet_t packet_t;
explicit TestPMgr(TestAql* t);
~TestPMgr();
bool Setup();
bool Run();
protected:
packet_t pre_packet_;
packet_t post_packet_;
hsa_signal_t dummy_signal_;
hsa_signal_t packet_signal_;
const hsa_ven_amd_aqlprofile_pfn_t* api_;
virtual int GetMode() { return UNKNOWN; }
virtual bool BuildPackets() { return false; }
virtual bool DumpData() { return false; }
virtual bool Initialize(int argc, char** argv);
private:
enum {
SLOT_PM4_SIZE_DW = HSA_VEN_AMD_AQLPROFILE_LEGACY_PM4_PACKET_SIZE / sizeof(uint32_t),
SLOT_PM4_SIZE_AQLP = HSA_VEN_AMD_AQLPROFILE_LEGACY_PM4_PACKET_SIZE / sizeof(packet_t)
};
struct slot_pm4_t {
uint32_t words[SLOT_PM4_SIZE_DW];
};
bool AddPacket(const packet_t* packet);
bool AddWaitPacket(packet_t* packet, hsa_signal_t signal);
};
#endif // TEST_PGEN_TEST_PMGR_H_