hsa-runtime integration
Change-Id: I48968966ffe164218ebff88d0e3a1268e96bf1dd
Bu işleme şunda yer alıyor:
işlemeyi yapan:
Evgeny Shcherbakov
ebeveyn
c533229bc1
işleme
4174f07fd1
@@ -51,12 +51,14 @@ namespace core {
|
||||
|
||||
static const uint32_t HSA_EXT_FINALIZER_API_TABLE_ID = 0;
|
||||
static const uint32_t HSA_EXT_IMAGE_API_TABLE_ID = 1;
|
||||
static const uint32_t HSA_EXT_AQLPROFILE_API_TABLE_ID = 2;
|
||||
|
||||
::HsaApiTable hsa_api;
|
||||
::CoreApiTable core_api;
|
||||
::AmdExtTable amd_ext_api;
|
||||
::FinalizerExtTable finalizer_api;
|
||||
::ImageExtTable image_api;
|
||||
::AqlProfileExtTable aqlprofile_api;
|
||||
|
||||
HsaApiTable();
|
||||
void Init();
|
||||
|
||||
@@ -65,10 +65,14 @@ class ExtensionEntryPoints {
|
||||
// Table of function pointers for Hsa Extension Finalizer
|
||||
FinalizerExtTable finalizer_api;
|
||||
|
||||
// Table of function pointers for Hsa Extension AqlProfiler
|
||||
AqlProfileExtTable aqlprofile_api;
|
||||
|
||||
ExtensionEntryPoints();
|
||||
|
||||
bool LoadFinalizer(std::string library_name);
|
||||
bool LoadImage(std::string library_name);
|
||||
bool LoadAqlProfileApi(std::string library_name);
|
||||
void Unload();
|
||||
|
||||
private:
|
||||
@@ -83,6 +87,9 @@ class ExtensionEntryPoints {
|
||||
// Initialize table for HSA Image Extension Api's
|
||||
void InitImageExtTable();
|
||||
|
||||
// Initialize table for HSA AqlProfile Extension Api's
|
||||
void InitAqlProfileExtTable();
|
||||
|
||||
// Initialize Amd Ext table for Api related to Images
|
||||
void InitAmdExtTable();
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
#include "core/inc/interrupt_signal.h"
|
||||
#include "core/inc/amd_loader_context.hpp"
|
||||
#include "inc/hsa_ven_amd_loader.h"
|
||||
#include "inc/hsa_ven_amd_aqlprofile.h"
|
||||
#include "core/inc/hsa_ext_amd_impl.h"
|
||||
|
||||
using namespace amd::hsa;
|
||||
@@ -230,6 +231,9 @@ hsa_status_t hsa_extension_get_name(uint16_t extension, const char** name) {
|
||||
case HSA_EXTENSION_AMD_LOADER:
|
||||
*name = "HSA_EXTENSION_AMD_LOADER";
|
||||
break;
|
||||
case HSA_EXTENSION_AMD_AQLPROFILE:
|
||||
*name = "HSA_EXTENSION_AMD_AQLPROFILE";
|
||||
break;
|
||||
default:
|
||||
*name = "HSA_EXTENSION_INVALID";
|
||||
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
@@ -293,6 +297,12 @@ hsa_status_t hsa_system_major_extension_supported(uint16_t extension, uint16_t v
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if ((extension == HSA_EXTENSION_AMD_AQLPROFILE) && (version_major == 1)) {
|
||||
*version_minor = 0;
|
||||
*result = true;
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
*result = false;
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -306,7 +316,8 @@ static size_t get_extension_table_length(uint16_t extension, uint16_t major, uin
|
||||
static sizes_t sizes[] = {
|
||||
{"hsa_ext_images_1_00_pfn_t", sizeof(hsa_ext_images_1_00_pfn_t)},
|
||||
{"hsa_ext_finalizer_1_00_pfn_t", sizeof(hsa_ext_finalizer_1_00_pfn_t)},
|
||||
{"hsa_ven_amd_loader_1_00_pfn_t", sizeof(hsa_ven_amd_loader_1_00_pfn_t)}};
|
||||
{"hsa_ven_amd_loader_1_00_pfn_t", sizeof(hsa_ven_amd_loader_1_00_pfn_t)},
|
||||
{"hsa_ven_amd_aqlprofile_1_00_pfn_t", sizeof(hsa_ven_amd_aqlprofile_1_00_pfn_t)}};
|
||||
static const size_t num_tables = sizeof(sizes) / sizeof(sizes_t);
|
||||
|
||||
if (minor > 99) return 0;
|
||||
@@ -332,6 +343,9 @@ static size_t get_extension_table_length(uint16_t extension, uint16_t major, uin
|
||||
case HSA_EXTENSION_AMD_LOADER:
|
||||
name = "hsa_ven_amd_loader_";
|
||||
break;
|
||||
case HSA_EXTENSION_AMD_AQLPROFILE:
|
||||
name = "hsa_ven_amd_aqlprofile_";
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -361,7 +375,11 @@ hsa_status_t hsa_system_get_major_extension_table(uint16_t extension, uint16_t v
|
||||
if (table_length == 0) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
if (extension == HSA_EXTENSION_IMAGES) {
|
||||
if (version_major > 1) return HSA_STATUS_ERROR;
|
||||
if (version_major !=
|
||||
core::Runtime::runtime_singleton_->extensions_.image_api.version.major_id) {
|
||||
return HSA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
hsa_ext_images_1_pfn_t ext_table;
|
||||
ext_table.hsa_ext_image_clear = hsa_ext_image_clear;
|
||||
ext_table.hsa_ext_image_copy = hsa_ext_image_copy;
|
||||
@@ -383,7 +401,11 @@ hsa_status_t hsa_system_get_major_extension_table(uint16_t extension, uint16_t v
|
||||
}
|
||||
|
||||
if (extension == HSA_EXTENSION_FINALIZER) {
|
||||
if (version_major > 1) return HSA_STATUS_ERROR;
|
||||
if (version_major !=
|
||||
core::Runtime::runtime_singleton_->extensions_.finalizer_api.version.major_id) {
|
||||
return HSA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
hsa_ext_finalizer_1_00_pfn_t ext_table;
|
||||
ext_table.hsa_ext_program_add_module = hsa_ext_program_add_module;
|
||||
ext_table.hsa_ext_program_create = hsa_ext_program_create;
|
||||
@@ -410,6 +432,26 @@ hsa_status_t hsa_system_get_major_extension_table(uint16_t extension, uint16_t v
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (extension == HSA_EXTENSION_AMD_AQLPROFILE) {
|
||||
if (version_major !=
|
||||
core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.version.major_id) {
|
||||
return HSA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
hsa_ven_amd_aqlprofile_1_00_pfn_t ext_table;
|
||||
ext_table.hsa_ven_amd_aqlprofile_error_string = hsa_ven_amd_aqlprofile_error_string;
|
||||
ext_table.hsa_ven_amd_aqlprofile_validate_event = hsa_ven_amd_aqlprofile_validate_event;
|
||||
ext_table.hsa_ven_amd_aqlprofile_start = hsa_ven_amd_aqlprofile_start;
|
||||
ext_table.hsa_ven_amd_aqlprofile_stop = hsa_ven_amd_aqlprofile_stop;
|
||||
ext_table.hsa_ven_amd_aqlprofile_legacy_get_pm4 = hsa_ven_amd_aqlprofile_legacy_get_pm4;
|
||||
ext_table.hsa_ven_amd_aqlprofile_get_info = hsa_ven_amd_aqlprofile_get_info;
|
||||
ext_table.hsa_ven_amd_aqlprofile_iterate_data = hsa_ven_amd_aqlprofile_iterate_data;
|
||||
|
||||
memcpy(table, &ext_table, Min(sizeof(ext_table), table_length));
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return HSA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
|
||||
#include "core/inc/hsa_ext_interface.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/inc/runtime.h"
|
||||
|
||||
namespace core {
|
||||
@@ -169,6 +171,7 @@ static T0 hsa_amd_null(T1, T2, T3, T4, T5, T6) {
|
||||
ExtensionEntryPoints::ExtensionEntryPoints() {
|
||||
InitFinalizerExtTable();
|
||||
InitImageExtTable();
|
||||
InitAqlProfileExtTable();
|
||||
InitAmdExtTable();
|
||||
}
|
||||
|
||||
@@ -212,6 +215,21 @@ void ExtensionEntryPoints::InitImageExtTable() {
|
||||
image_api.hsa_ext_image_create_with_layout_fn = hsa_ext_null;
|
||||
}
|
||||
|
||||
void ExtensionEntryPoints::InitAqlProfileExtTable() {
|
||||
// Initialize Version of Api Table
|
||||
aqlprofile_api.version.major_id = 0x00;
|
||||
aqlprofile_api.version.minor_id = 0x00;
|
||||
aqlprofile_api.version.step_id = 0x00;
|
||||
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_error_string_fn = hsa_ext_null;
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_validate_event_fn = hsa_ext_null;
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_start_fn = hsa_ext_null;
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_stop_fn = hsa_ext_null;
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_legacy_get_pm4_fn = hsa_ext_null;
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_get_info_fn = hsa_ext_null;
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_iterate_data_fn = hsa_ext_null;
|
||||
}
|
||||
|
||||
// Initialize Amd Ext table for Api related to Images
|
||||
void ExtensionEntryPoints::InitAmdExtTable() {
|
||||
hsa_api_table_.amd_ext_api.hsa_amd_image_create_fn = hsa_ext_null;
|
||||
@@ -485,6 +503,81 @@ bool ExtensionEntryPoints::LoadFinalizer(std::string library_name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExtensionEntryPoints::LoadAqlProfileApi(std::string library_name) {
|
||||
os::LibHandle lib = os::LoadLib(library_name);
|
||||
if (lib == NULL) {
|
||||
return false;
|
||||
}
|
||||
libs_.push_back(lib);
|
||||
|
||||
void* ptr;
|
||||
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_error_string");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_error_string_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_error_string)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_error_string_fn = (decltype(::hsa_ven_amd_aqlprofile_error_string)*)ptr;
|
||||
}
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_validate_event");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_validate_event_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_validate_event)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_validate_event_fn = (decltype(::hsa_ven_amd_aqlprofile_validate_event)*)ptr;
|
||||
}
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_start");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_start_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_start)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_start_fn = (decltype(::hsa_ven_amd_aqlprofile_start)*)ptr;
|
||||
}
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_stop");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_stop_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_stop)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_stop_fn = (decltype(::hsa_ven_amd_aqlprofile_stop)*)ptr;
|
||||
}
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_legacy_get_pm4");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_legacy_get_pm4_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_legacy_get_pm4)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_legacy_get_pm4_fn = (decltype(::hsa_ven_amd_aqlprofile_legacy_get_pm4)*)ptr;
|
||||
}
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_get_info");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_get_info_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_get_info)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_get_info_fn = (decltype(::hsa_ven_amd_aqlprofile_get_info)*)ptr;
|
||||
}
|
||||
ptr = os::GetExportAddress(lib, "hsa_ven_amd_aqlprofile_iterate_data");
|
||||
if (ptr != NULL) {
|
||||
assert(aqlprofile_api.hsa_ven_amd_aqlprofile_iterate_data_fn ==
|
||||
(decltype(::hsa_ven_amd_aqlprofile_iterate_data)*)hsa_ext_null &&
|
||||
"Duplicate load of extension import.");
|
||||
aqlprofile_api.hsa_ven_amd_aqlprofile_iterate_data_fn = (decltype(::hsa_ven_amd_aqlprofile_iterate_data)*)ptr;
|
||||
}
|
||||
|
||||
// Initialize Version of Api Table
|
||||
aqlprofile_api.version.major_id = HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION;
|
||||
aqlprofile_api.version.minor_id = sizeof(::AqlProfileExtTable);
|
||||
aqlprofile_api.version.step_id = HSA_AQLPROFILE_API_TABLE_STEP_VERSION;
|
||||
|
||||
// Update handle of table of HSA extensions
|
||||
hsa_internal_api_table_.CloneExts(&aqlprofile_api,
|
||||
core::HsaApiTable::HSA_EXT_AQLPROFILE_API_TABLE_ID);
|
||||
|
||||
ptr = os::GetExportAddress(lib, "Load");
|
||||
if (ptr != NULL) {
|
||||
((Load_t)ptr)(&core::hsa_internal_api_table_.hsa_api);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
|
||||
@@ -655,6 +748,57 @@ hsa_status_t hsa_ext_image_create_with_layout(
|
||||
image);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_error_string(
|
||||
const char** str) // [out] pointer on the error string
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_error_string_fn(str);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_validate_event(
|
||||
hsa_agent_t agent, // HSA handle for the profiling GPU
|
||||
const hsa_ven_amd_aqlprofile_event_t* event, // [in] Pointer on validated event
|
||||
bool* result) // [out] True if the event valid, False otherwise
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_validate_event_fn(agent, event, result);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_start(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile contex object
|
||||
hsa_ext_amd_aql_pm4_packet_t* aql_start_packet) // [out] profile start AQL packet
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_start_fn(profile, aql_start_packet);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_stop(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile contex object
|
||||
hsa_ext_amd_aql_pm4_packet_t* aql_stop_packet) // [out] profile stop AQL packet
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_stop_fn(profile, aql_stop_packet);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_legacy_get_pm4(
|
||||
const hsa_ext_amd_aql_pm4_packet_t* aql_packet, // [in] AQL packet
|
||||
void* data) // [out] PM4 packet blob
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_legacy_get_pm4_fn(aql_packet, data);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_get_info(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile context object
|
||||
hsa_ven_amd_aqlprofile_info_type_t attribute, // [in] requested profile attribute
|
||||
void* value) // [in/out] returned value
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_get_info_fn(profile, attribute, value);
|
||||
}
|
||||
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_iterate_data(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile context object
|
||||
hsa_ven_amd_aqlprofile_data_callback_t callback, // [in] callback to iterate the output data
|
||||
void* data) // [in/out] data passed to the callback
|
||||
{
|
||||
return core::Runtime::runtime_singleton_->extensions_.aqlprofile_api.hsa_ven_amd_aqlprofile_iterate_data_fn(profile, callback, data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
// Stubs for internal extension functions
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
@@ -1038,11 +1038,15 @@ void Runtime::LoadExtensions() {
|
||||
"libhsa-ext-finalize64.so.1"};
|
||||
static const std::string kImageLib[] = {"hsa-ext-image64.dll",
|
||||
"libhsa-ext-image64.so.1"};
|
||||
static const std::string kAqlProfileLib[] = {"hsa-amd-aqlprofile64.dll",
|
||||
"libhsa-amd-aqlprofile64.so.1"};
|
||||
#else
|
||||
static const std::string kFinalizerLib[] = {"hsa-ext-finalize.dll",
|
||||
"libhsa-ext-finalize.so.1"};
|
||||
static const std::string kImageLib[] = {"hsa-ext-image.dll",
|
||||
"libhsa-ext-image.so.1"};
|
||||
static const std::string kAqlProfileLib[] = {"hsa-amd-aqlprofile.dll",
|
||||
"libhsa-amd-aqlprofile.so.1"};
|
||||
#endif
|
||||
|
||||
// Update Hsa Api Table with handle of Image extension Apis
|
||||
@@ -1054,6 +1058,9 @@ void Runtime::LoadExtensions() {
|
||||
extensions_.LoadImage(kImageLib[os_index(os::current_os)]);
|
||||
hsa_api_table_.LinkExts(&extensions_.image_api,
|
||||
core::HsaApiTable::HSA_EXT_IMAGE_API_TABLE_ID);
|
||||
|
||||
// Update Hsa Api Table with handle of AqlProfile extension Apis
|
||||
extensions_.LoadAqlProfileApi(kAqlProfileLib[os_index(os::current_os)]);
|
||||
}
|
||||
|
||||
void Runtime::UnloadExtensions() { extensions_.Unload(); }
|
||||
|
||||
@@ -535,10 +535,14 @@ typedef enum {
|
||||
* Loader extension.
|
||||
*/
|
||||
HSA_EXTENSION_AMD_LOADER = 0x201,
|
||||
/**
|
||||
* AqlProfile extension.
|
||||
*/
|
||||
HSA_EXTENSION_AMD_AQLPROFILE = 0x202,
|
||||
/**
|
||||
* Last AMD extension.
|
||||
*/
|
||||
HSA_AMD_LAST_EXTENSION = 0x201
|
||||
HSA_AMD_LAST_EXTENSION = 0x202
|
||||
} hsa_extension_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,10 +48,12 @@
|
||||
#include "hsa_ext_image.h"
|
||||
#include "hsa_ext_amd.h"
|
||||
#include "hsa_ext_finalize.h"
|
||||
#include "hsa_ven_amd_aqlprofile.h"
|
||||
#else
|
||||
#include "inc/hsa_ext_image.h"
|
||||
#include "inc/hsa_ext_amd.h"
|
||||
#include "inc/hsa_ext_finalize.h"
|
||||
#include "inc/hsa_ven_amd_aqlprofile.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@@ -64,6 +66,7 @@
|
||||
#define HSA_AMD_EXT_API_TABLE_MAJOR_VERSION 0x01
|
||||
#define HSA_FINALIZER_API_TABLE_MAJOR_VERSION 0x01
|
||||
#define HSA_IMAGE_API_TABLE_MAJOR_VERSION 0x01
|
||||
#define HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION 0x01
|
||||
|
||||
// Step Ids of the Api tables exported by Hsa Core Runtime
|
||||
#define HSA_API_TABLE_STEP_VERSION 0x00
|
||||
@@ -71,6 +74,7 @@
|
||||
#define HSA_AMD_EXT_API_TABLE_STEP_VERSION 0x00
|
||||
#define HSA_FINALIZER_API_TABLE_STEP_VERSION 0x00
|
||||
#define HSA_IMAGE_API_TABLE_STEP_VERSION 0x00
|
||||
#define HSA_AQLPROFILE_API_TABLE_STEP_VERSION 0x00
|
||||
|
||||
// Min function used to copy Api Tables
|
||||
static inline uint32_t Min(const uint32_t a, const uint32_t b) {
|
||||
@@ -116,6 +120,18 @@ struct ImageExtTable {
|
||||
decltype(hsa_ext_image_create_with_layout)* hsa_ext_image_create_with_layout_fn;
|
||||
};
|
||||
|
||||
// Table to export HSA AqlProfile AMD specific Extension Apis
|
||||
struct AqlProfileExtTable {
|
||||
ApiTableVersion version;
|
||||
decltype(hsa_ven_amd_aqlprofile_error_string)* hsa_ven_amd_aqlprofile_error_string_fn;
|
||||
decltype(hsa_ven_amd_aqlprofile_validate_event)* hsa_ven_amd_aqlprofile_validate_event_fn;
|
||||
decltype(hsa_ven_amd_aqlprofile_start)* hsa_ven_amd_aqlprofile_start_fn;
|
||||
decltype(hsa_ven_amd_aqlprofile_stop)* hsa_ven_amd_aqlprofile_stop_fn;
|
||||
decltype(hsa_ven_amd_aqlprofile_legacy_get_pm4)* hsa_ven_amd_aqlprofile_legacy_get_pm4_fn;
|
||||
decltype(hsa_ven_amd_aqlprofile_get_info)* hsa_ven_amd_aqlprofile_get_info_fn;
|
||||
decltype(hsa_ven_amd_aqlprofile_iterate_data)* hsa_ven_amd_aqlprofile_iterate_data_fn;
|
||||
};
|
||||
|
||||
// Table to export AMD Extension Apis
|
||||
struct AmdExtTable {
|
||||
ApiTableVersion version;
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2017 ADVANCED MICRO DEVICES, INC.
|
||||
//
|
||||
// AMD is granting you permission to use this software and documentation(if any)
|
||||
// (collectively, the "Materials") pursuant to the terms and conditions of the
|
||||
// Software License Agreement included with the Materials.If you do not have a
|
||||
// copy of the Software License Agreement, contact your AMD representative for a
|
||||
// copy.
|
||||
//
|
||||
// You agree that you will not reverse engineer or decompile the Materials, in
|
||||
// whole or in part, except as allowed by applicable law.
|
||||
//
|
||||
// WARRANTY DISCLAIMER : THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND.AMD DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY,
|
||||
// INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE, NON - INFRINGEMENT, THAT THE
|
||||
// SOFTWARE WILL RUN UNINTERRUPTED OR ERROR - FREE OR WARRANTIES ARISING FROM
|
||||
// CUSTOM OF TRADE OR COURSE OF USAGE.THE ENTIRE RISK ASSOCIATED WITH THE USE OF
|
||||
// THE SOFTWARE IS ASSUMED BY YOU.Some jurisdictions do not allow the exclusion
|
||||
// of implied warranties, so the above exclusion may not apply to You.
|
||||
//
|
||||
// LIMITATION OF LIABILITY AND INDEMNIFICATION : AMD AND ITS LICENSORS WILL NOT,
|
||||
// UNDER ANY CIRCUMSTANCES BE LIABLE TO YOU FOR ANY PUNITIVE, DIRECT,
|
||||
// INCIDENTAL, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM USE OF
|
||||
// THE SOFTWARE OR THIS AGREEMENT EVEN IF AMD AND ITS LICENSORS HAVE BEEN
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.In no event shall AMD's total
|
||||
// liability to You for all damages, losses, and causes of action (whether in
|
||||
// contract, tort (including negligence) or otherwise) exceed the amount of $100
|
||||
// USD. You agree to defend, indemnify and hold harmless AMD and its licensors,
|
||||
// and any of their directors, officers, employees, affiliates or agents from
|
||||
// and against any and all loss, damage, liability and other expenses (including
|
||||
// reasonable attorneys' fees), resulting from Your use of the Software or
|
||||
// violation of the terms and conditions of this Agreement.
|
||||
//
|
||||
// U.S.GOVERNMENT RESTRICTED RIGHTS : The Materials are provided with
|
||||
// "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is
|
||||
// subject to the restrictions as set forth in FAR 52.227 - 14 and DFAR252.227 -
|
||||
// 7013, et seq., or its successor.Use of the Materials by the Government
|
||||
// constitutes acknowledgement of AMD's proprietary rights in them.
|
||||
//
|
||||
// EXPORT RESTRICTIONS: The Materials may be subject to export restrictions as
|
||||
// stated in the Software License Agreement.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef OPENSRC_HSA_RUNTIME_INC_HSA_VEN_AMD_AQLPROFILE_H_
|
||||
#define OPENSRC_HSA_RUNTIME_INC_HSA_VEN_AMD_AQLPROFILE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <hsa.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Library API:
|
||||
// The library provides helper methods for instantiation of
|
||||
// the profile context object and for populating of the start
|
||||
// and stop AQL packets. The profile object contains a profiling
|
||||
// events list and needed for profiling buffers descriptors,
|
||||
// a command buffer and an output data buffer. To check if there
|
||||
// was an error the library methods return a status code. Also
|
||||
// the library provides methods for querying required buffers
|
||||
// attributes, to validate the event attributes and to get profiling
|
||||
// output data.
|
||||
//
|
||||
// Returned status:
|
||||
// hsa_status_t – HSA status codes are used from hsa.h header
|
||||
//
|
||||
// Supported profiling features:
|
||||
//
|
||||
// Supported profiling events
|
||||
typedef enum {
|
||||
HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_PMC,
|
||||
HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_SQTT
|
||||
} hsa_ven_amd_aqlprofile_event_type_t;
|
||||
|
||||
// Supported performance counters (PMC) blocks
|
||||
// The block ID is the same for a block instances set, for example
|
||||
// each block instance from the TCC block set, TCC0, TCC1, …, TCCN
|
||||
// will have the same block ID HSA_VEN_AMD_AQLPROFILE_BLOCKS_TCC.
|
||||
typedef enum {
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_CB,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_CPF,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_DB,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_GRBM,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_GRBMSE,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_PASU,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_PASC,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SPI,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQ,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQES,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQGS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQVS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQPS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQLS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQHS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SQCS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SX,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_TA,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_TCA,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_TCC,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_TD,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_TCP,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_GDS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_VGT,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_IA,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_MC,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_SRBM,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_TCS,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_WD,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_CPG,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCK_NAME_CPC,
|
||||
HSA_VEN_AMD_AQLPROFILE_BLOCKS_NUMBER
|
||||
} hsa_ven_amd_aqlprofile_block_name_t;
|
||||
|
||||
// PMC event object structure
|
||||
// ‘counter_id’ value is specified in GFXIPs perfcounter user guides
|
||||
// which is the counters select value, “Performance Counters Selection”
|
||||
// chapter.
|
||||
typedef struct {
|
||||
hsa_ven_amd_aqlprofile_block_name_t block_name;
|
||||
uint32_t block_index;
|
||||
uint32_t counter_id;
|
||||
} hsa_ven_amd_aqlprofile_event_t;
|
||||
|
||||
// Check if event is valid for the specific GPU
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_validate_event(
|
||||
hsa_agent_t agent, // HSA handle for the profiling GPU
|
||||
const hsa_ven_amd_aqlprofile_event_t* event, // [in] Pointer on validated event
|
||||
bool* result); // [out] True if the event valid, False otherwise
|
||||
|
||||
// Profiling parameters
|
||||
// All parameters are generic and if not applicable for a specific
|
||||
// profile configuration then error status will be returned.
|
||||
typedef enum {
|
||||
// SQTT applicable parameters
|
||||
HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_COMPUTE_UNIT_TARGET,
|
||||
HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_VM_ID_MASK,
|
||||
HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_MASK,
|
||||
HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_TOKEN_MASK,
|
||||
HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_TOKEN_MASK2
|
||||
} hsa_ven_amd_aqlprofile_parameter_name_t;
|
||||
|
||||
// Profile parameter object
|
||||
typedef struct {
|
||||
hsa_ven_amd_aqlprofile_parameter_name_t parameter_name;
|
||||
uint32_t value;
|
||||
} hsa_ven_amd_aqlprofile_parameter_t;
|
||||
|
||||
//
|
||||
// Profile context object:
|
||||
// The library provides a profile object structure which contains
|
||||
// the events array, a buffer for the profiling start/stop commands
|
||||
// and a buffer for the output data.
|
||||
// The buffers are specified by the buffer descriptors and allocated
|
||||
// by the application. The buffers allocation attributes, the command
|
||||
// buffer size, the PMC output buffer size as well as profiling output
|
||||
// data can be get using the generic get profile info helper _get_info.
|
||||
//
|
||||
// Buffer descriptor
|
||||
typedef struct {
|
||||
void* ptr;
|
||||
uint32_t size;
|
||||
} hsa_ven_amd_aqlprofile_descriptor_t;
|
||||
|
||||
// Profile context object structure, contains profiling events list and
|
||||
// needed for profiling buffers descriptors, a command buffer and
|
||||
// an output data buffer
|
||||
typedef struct {
|
||||
hsa_agent_t agent; // GFXIP handle
|
||||
hsa_ven_amd_aqlprofile_event_type_t type; // Events type
|
||||
const hsa_ven_amd_aqlprofile_event_t* events; // Events array
|
||||
uint32_t event_count; // Events count
|
||||
const hsa_ven_amd_aqlprofile_parameter_t* parameters; // Parameters array
|
||||
uint32_t parameter_count; // Parameters count
|
||||
hsa_ven_amd_aqlprofile_descriptor_t output_buffer; // Output buffer
|
||||
hsa_ven_amd_aqlprofile_descriptor_t command_buffer; // PM4 commands
|
||||
} hsa_ven_amd_aqlprofile_profile_t;
|
||||
|
||||
//
|
||||
// AQL packets populating methods:
|
||||
// The helper methods to populate provided by the application START and
|
||||
// STOP AQL packets which the application is required to submit before and
|
||||
// after profiled GPU task packets respectively.
|
||||
//
|
||||
// AQL Vendor Specific packet which carries a PM4 command
|
||||
typedef struct {
|
||||
uint16_t header;
|
||||
uint16_t pm4_command[27];
|
||||
hsa_signal_t completion_signal;
|
||||
} hsa_ext_amd_aql_pm4_packet_t;
|
||||
|
||||
// Method to populate the provided AQL packet with profiling start commands
|
||||
// Only 'pm4_command' fields of the packet are set and the application
|
||||
// is responsible to set Vendor Specific header type a completion signal
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_start(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile contex object
|
||||
hsa_ext_amd_aql_pm4_packet_t* aql_start_packet); // [out] profile start AQL packet
|
||||
|
||||
// Method to populate the provided AQL packet with profiling stop commands
|
||||
// Only 'pm4_command' fields of the packet are set and the application
|
||||
// is responsible to set Vendor Specific header type and a completion signal
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_stop(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile contex object
|
||||
hsa_ext_amd_aql_pm4_packet_t* aql_stop_packet); // [out] profile stop AQL packet
|
||||
|
||||
// Legacy devices, PM4 profiling packet size
|
||||
const unsigned HSA_VEN_AMD_AQLPROFILE_LEGACY_PM4_PACKET_SIZE = 192;
|
||||
// Legacy devices, converting the profiling AQL packet to PM4 packet blob
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_legacy_get_pm4(
|
||||
const hsa_ext_amd_aql_pm4_packet_t* aql_packet, // [in] AQL packet
|
||||
void* data); // [out] PM4 packet blob
|
||||
|
||||
//
|
||||
// Get profile info:
|
||||
// Generic method for getting various profile info including profile buffers
|
||||
// attributes like the command buffer size and the profiling PMC results.
|
||||
// It’s implied that all counters are 64bit values.
|
||||
//
|
||||
// Profile generic output data:
|
||||
typedef struct {
|
||||
uint32_t sample_id; // PMC sample of SQTT buffer index
|
||||
union {
|
||||
struct {
|
||||
hsa_ven_amd_aqlprofile_event_t event; // PMC event
|
||||
uint64_t result; // PMC result
|
||||
} pmc_data;
|
||||
hsa_ven_amd_aqlprofile_descriptor_t sqtt_data; // SQTT output data descriptor
|
||||
};
|
||||
} hsa_ven_amd_aqlprofile_info_data_t;
|
||||
|
||||
// Profile attributes
|
||||
typedef enum {
|
||||
HSA_VEN_AMD_AQLPROFILE_INFO_COMMAND_BUFFER_SIZE, // get_info returns uint32_t value
|
||||
HSA_VEN_AMD_AQLPROFILE_INFO_PMC_DATA_SIZE, // get_info returns uint32_t value
|
||||
HSA_VEN_AMD_AQLPROFILE_INFO_PMC_DATA, // get_info returns PMC uint64_t value
|
||||
// in info_data object
|
||||
HSA_VEN_AMD_AQLPROFILE_INFO_SQTT_DATA // get_info returns SQTT buffer ptr/size
|
||||
// in info_data object
|
||||
} hsa_ven_amd_aqlprofile_info_type_t;
|
||||
|
||||
// Definition of output data iterator callback
|
||||
typedef hsa_status_t (*hsa_ven_amd_aqlprofile_data_callback_t)(
|
||||
hsa_ven_amd_aqlprofile_info_type_t info_type, // [in] data type, PMC or SQTT data
|
||||
hsa_ven_amd_aqlprofile_info_data_t* info_data, // [in] info_data object
|
||||
void* callback_data); // [in/out] data passed to the callback
|
||||
|
||||
// Method for getting the profile info
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_get_info(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile context object
|
||||
hsa_ven_amd_aqlprofile_info_type_t attribute, // [in] requested profile attribute
|
||||
void* value); // [in/out] returned value
|
||||
|
||||
// Method for iterating the events output data
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_iterate_data(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile, // [in] profile context object
|
||||
hsa_ven_amd_aqlprofile_data_callback_t callback, // [in] callback to iterate the output data
|
||||
void* data); // [in/out] data passed to the callback
|
||||
|
||||
// Return error string
|
||||
hsa_status_t hsa_ven_amd_aqlprofile_error_string(
|
||||
const char** str); // [out] pointer on the error string
|
||||
|
||||
/**
|
||||
* @brief Extension version.
|
||||
*/
|
||||
#define hsa_ven_amd_aqlprofile 001000
|
||||
|
||||
/**
|
||||
* @brief Extension function table.
|
||||
*/
|
||||
typedef struct hsa_ven_amd_aqlprofile_1_00_pfn_s {
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_error_string)(const char** str);
|
||||
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_validate_event)(hsa_agent_t agent,
|
||||
const hsa_ven_amd_aqlprofile_event_t* event,
|
||||
bool* result);
|
||||
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_start)(const hsa_ven_amd_aqlprofile_profile_t* profile,
|
||||
hsa_ext_amd_aql_pm4_packet_t* aql_start_packet);
|
||||
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_stop)(const hsa_ven_amd_aqlprofile_profile_t* profile,
|
||||
hsa_ext_amd_aql_pm4_packet_t* aql_start_packet);
|
||||
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_legacy_get_pm4)(
|
||||
const hsa_ext_amd_aql_pm4_packet_t* aql_packet, void* data);
|
||||
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_get_info)(const hsa_ven_amd_aqlprofile_profile_t* profile,
|
||||
hsa_ven_amd_aqlprofile_info_type_t attribute,
|
||||
void* value);
|
||||
|
||||
hsa_status_t (*hsa_ven_amd_aqlprofile_iterate_data)(
|
||||
const hsa_ven_amd_aqlprofile_profile_t* profile,
|
||||
hsa_ven_amd_aqlprofile_data_callback_t callback, void* data);
|
||||
} hsa_ven_amd_aqlprofile_1_00_pfn_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OPENSRC_HSA_RUNTIME_INC_HSA_VEN_AMD_AQLPROFILE_H_
|
||||
Yeni konuda referans
Bir kullanıcı engelle