SWDEV-443561 - Add tools dispatch table

Change-Id: I3445554e486ab7b94592571f52c1530cb918d021
Este commit está contenido en:
Aidan Belton-Schure
2024-11-25 15:34:47 +00:00
cometido por Aidan Belton-Schure
padre 8c9e6d0fa5
commit 152cee3737
Se han modificado 5 ficheros con 85 adiciones y 2 borrados
@@ -52,6 +52,7 @@
// DO NOT REMOVE IT.
#define HIP_API_TABLE_MAJOR_VERSION 0
#define HIP_COMPILER_API_TABLE_MAJOR_VERSION 0
#define HIP_TOOLS_API_TABLE_MAJOR_VERSION 0
#define HIP_RUNTIME_API_TABLE_MAJOR_VERSION 0
// The step version number should be changed whenever the size of the API table struct(s) change.
@@ -61,9 +62,11 @@
// - Reset any of the *_STEP_VERSION defines to zero if the corresponding *_MAJOR_VERSION increases
#define HIP_API_TABLE_STEP_VERSION 0
#define HIP_COMPILER_API_TABLE_STEP_VERSION 0
#define HIP_TOOLS_API_TABLE_STEP_VERSION 0
#define HIP_RUNTIME_API_TABLE_STEP_VERSION 8
// HIP API interface
// HIP compiler dispatch functions
typedef hipError_t (*t___hipPopCallConfiguration)(dim3* gridDim, dim3* blockDim, size_t* sharedMem,
hipStream_t* stream);
typedef hipError_t (*t___hipPushCallConfiguration)(dim3 gridDim, dim3 blockDim, size_t sharedMem,
@@ -83,6 +86,10 @@ typedef void (*t___hipRegisterVar)(void** modules, void* var, char* hostVar,
char* deviceVar, int ext, size_t size, int constant, int global);
typedef void (*t___hipUnregisterFatBinary)(void** modules);
// HIP tools dispatch functions
typedef void (*t___hipReportDevices)(size_t numDevices, const hipUUID* uuids);
// HIP runtime dispatch functions
typedef const char* (*t_hipApiName)(uint32_t id);
typedef hipError_t (*t_hipArray3DCreate)(hipArray_t* array,
const HIP_ARRAY3D_DESCRIPTOR* pAllocateArray);
@@ -1558,3 +1565,26 @@ struct HipDispatchTable {
// 5) ADD "DO NOT EDIT ABOVE!" COMMENT
// ******************************************************************************************* //
};
// HIP Tools dispatch table
struct HipToolsDispatchTable {
// HIP_TOOLS_API_TABLE_STEP_VERSION == 0
size_t size;
t___hipReportDevices __hipReportDevices_fn;
// DO NOT EDIT ABOVE!
// HIP_TOOLS_API_TABLE_STEP_VERSION == 1
// ******************************************************************************************* //
//
// READ BELOW
//
// ******************************************************************************************* //
// KEEP AT END OF STRUCT
// 1) DO NOT REORDER ANY EXIST MEMBERS
// 2) INCREASE STEP VERSION DEFINE BEFORE ADDING NEW MEMBERS
// 3) INSERT NEW MEMBERS UNDER APPROPRIATE STEP VERSION COMMENT
// 4) GENERATE COMMENT FOR NEXT STEP VERSION
// 5) ADD "DO NOT EDIT ABOVE!" COMMENT
// ******************************************************************************************* //
};
+30 -2
Ver fichero
@@ -36,6 +36,7 @@
ROCPROFILER_REGISTER_DEFINE_IMPORT(hip, HIP_ROCP_REG_VERSION)
ROCPROFILER_REGISTER_DEFINE_IMPORT(hip_compiler, HIP_ROCP_REG_VERSION)
ROCPROFILER_REGISTER_DEFINE_IMPORT(hip_tools, HIP_ROCP_REG_VERSION)
#elif !defined(HIP_ROCPROFILER_REGISTER)
#define HIP_ROCPROFILER_REGISTER 0
#endif
@@ -829,6 +830,11 @@ void UpdateDispatchTable(HipCompilerDispatchTable* ptrCompilerDispatchTable) {
ptrCompilerDispatchTable->__hipUnregisterFatBinary_fn = hip::__hipUnregisterFatBinary;
}
void UpdateDispatchTable(HipToolsDispatchTable* ptrToolsDispatchTable) {
ptrToolsDispatchTable->size = sizeof(HipToolsDispatchTable);
ptrToolsDispatchTable->__hipReportDevices_fn = nullptr;
}
void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
ptrDispatchTable->size = sizeof(HipDispatchTable);
ptrDispatchTable->hipApiName_fn = hip::hipApiName;
@@ -1331,9 +1337,10 @@ constexpr auto ComputeTableSize(size_t num_funcs) {
HIP_DEFINE_DISPATCH_TABLE_INFO(HipDispatchTable, hip)
HIP_DEFINE_DISPATCH_TABLE_INFO(HipCompilerDispatchTable, hip_compiler)
HIP_DEFINE_DISPATCH_TABLE_INFO(HipToolsDispatchTable, hip_tools)
#endif
template <typename Tp> void ToolInit(Tp* table) {
template <typename Tp> void ToolsInit(Tp* table) {
#if HIP_ROCPROFILER_REGISTER > 0
auto table_array = std::array<void*, 1>{static_cast<void*>(table)};
auto lib_id = rocprofiler_register_library_indentifier_t{};
@@ -1360,7 +1367,7 @@ template <typename Tp> Tp& GetDispatchTableImpl() {
UpdateDispatchTable(&dispatch_table);
// Profiler Registration, may wrap the function pointers
ToolInit(&dispatch_table);
ToolsInit(&dispatch_table);
return dispatch_table;
}
@@ -1385,6 +1392,10 @@ GetHipCompilerDispatchTable() {
static auto* _v = &GetDispatchTableImpl<HipCompilerDispatchTable>();
return _v;
}
const HipToolsDispatchTable* GetHipToolsDispatchTable() {
static auto* _v = &GetDispatchTableImpl<HipToolsDispatchTable>();
return _v;
}
} // namespace hip
#if !defined(_WIN32)
@@ -1441,6 +1452,23 @@ static_assert(HIP_COMPILER_API_TABLE_MAJOR_VERSION == 0 && HIP_COMPILER_API_TABL
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "
"pointers and then update this check so it is true");
// These ensure that function pointers are not re-ordered
// HIP_TOOLS_API_TABLE_STEP_VERSION == 0
HIP_ENFORCE_ABI(HipToolsDispatchTable, __hipReportDevices_fn, 0)
// HIP_TOOLS_API_TABLE_STEP_VERSION == 1
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
//
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
//
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
HIP_ENFORCE_ABI_VERSIONING(HipToolsDispatchTable, 1)
static_assert(HIP_TOOLS_API_TABLE_MAJOR_VERSION == 0 && HIP_TOOLS_API_TABLE_STEP_VERSION == 0,
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "
"pointers and then update this check so it is true");
// These ensure that function pointers are not re-ordered
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 0
HIP_ENFORCE_ABI(HipDispatchTable, hipApiName_fn, 0)
+23
Ver fichero
@@ -25,6 +25,11 @@
#include "rocclr/utils/flags.hpp"
#include "rocclr/utils/versions.hpp"
#include <hip/amd_detail/hip_api_trace.hpp>
namespace hip {
const HipToolsDispatchTable* GetHipToolsDispatchTable();
} // namespace hip
namespace hip {
std::once_flag g_ihipInitialized;
@@ -65,6 +70,24 @@ void init(bool* status) {
amd::RuntimeTearDown::RegisterObject(device);
}
if (hip::GetHipToolsDispatchTable()->__hipReportDevices_fn != nullptr) {
size_t numDevices = g_devices.size();
std::vector<hipUUID> uuids(numDevices);
int i = 0;
for (const auto& dev : g_devices) {
auto* deviceHandle = dev->devices()[0];
const auto& info = deviceHandle->info();
memcpy(uuids[i].bytes, info.uuid_, sizeof(info.uuid_));
// if assert fails, the memcpy bytes param needs to be addressed
static_assert(sizeof(info.uuid_) == sizeof(uuids[0].bytes), "error ABI issue");
++i;
}
hip::GetHipToolsDispatchTable()->__hipReportDevices_fn(numDevices, uuids.data());
}
amd::Context* hContext = new amd::Context(devices, amd::Context::Info());
if (!hContext) {
*status = false;
+1
Ver fichero
@@ -23,6 +23,7 @@
namespace hip {
const HipDispatchTable* GetHipDispatchTable();
const HipCompilerDispatchTable* GetHipCompilerDispatchTable();
const HipToolsDispatchTable* GetHipToolsDispatchTable();
} // namespace hip
extern "C" hipError_t __hipPopCallConfiguration(dim3* gridDim, dim3* blockDim, size_t* sharedMem,
+1
Ver fichero
@@ -23,6 +23,7 @@
namespace hip {
const HipDispatchTable* GetHipDispatchTable();
const HipCompilerDispatchTable* GetHipCompilerDispatchTable();
const HipToolsDispatchTable* GetHipToolsDispatchTable();
} // namespace hip
#ifdef _WIN32