Change-Id: I48968966ffe164218ebff88d0e3a1268e96bf1dd
Этот коммит содержится в:
Evgeny
2017-06-23 17:54:27 -05:00
коммит произвёл Evgeny Shcherbakov
родитель c533229bc1
Коммит 4174f07fd1
120 изменённых файлов: 1300 добавлений и 918 удалений
+45 -3
Просмотреть файл
@@ -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;
}
+144
Просмотреть файл
@@ -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
//---------------------------------------------------------------------------//
+7
Просмотреть файл
@@ -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(); }