diff --git a/runtime/hsa-runtime/core/inc/thunk_loader.h b/runtime/hsa-runtime/core/inc/thunk_loader.h index 6743af5fae..d7b549a291 100644 --- a/runtime/hsa-runtime/core/inc/thunk_loader.h +++ b/runtime/hsa-runtime/core/inc/thunk_loader.h @@ -46,6 +46,10 @@ #include #include "hsakmt/hsakmttypes.h" +class DtifPlatform; +typedef DtifPlatform* (DtifCreateFunc)(const char*); +typedef void (DtifDestroyFunc)(); + namespace rocr { namespace core { @@ -356,6 +360,8 @@ class ThunkLoader { ~ThunkLoader(); void LoadThunkApiTable(); + bool CreateThunkInstance(); + bool DestroyThunkInstance(); HSAKMT_DEF(hsaKmtOpenKFD)* HSAKMT_PFN(hsaKmtOpenKFD); HSAKMT_DEF(hsaKmtCloseKFD)* HSAKMT_PFN(hsaKmtCloseKFD); diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index 49f4c6711c..4fe5316d3c 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -2044,6 +2044,10 @@ hsa_status_t Runtime::Load() { thunkLoader_ = new ThunkLoader(); thunkLoader_->LoadThunkApiTable(); + if (!thunkLoader_->CreateThunkInstance()) { + return HSA_STATUS_ERROR_NOT_INITIALIZED; + } + g_use_interrupt_wait = flag_.enable_interrupt(); g_use_mwaitx = flag_.check_mwaitx(cpuinfo.mwaitx); @@ -2140,6 +2144,8 @@ void Runtime::Unload() { DestroyDrivers(); + thunkLoader_->DestroyThunkInstance(); + delete thunkLoader_; } diff --git a/runtime/hsa-runtime/core/runtime/thunk_loader.cpp b/runtime/hsa-runtime/core/runtime/thunk_loader.cpp index 91a02ef4b2..f82a6067cd 100644 --- a/runtime/hsa-runtime/core/runtime/thunk_loader.cpp +++ b/runtime/hsa-runtime/core/runtime/thunk_loader.cpp @@ -485,5 +485,37 @@ ERROR: } } + bool ThunkLoader::CreateThunkInstance() { + if (!core::Runtime::runtime_singleton_->flag().enable_dtif()) + return true; + + DtifCreateFunc* pfnDtifCreate = (DtifCreateFunc*)dlsym(dtif_handle, "DtifCreate"); + if (pfnDtifCreate != NULL) { + if (pfnDtifCreate("HSA") != NULL) { + debug_print("DtifCreate OK!\n"); + return true; + } else { + debug_print("DtifCreate failed!\n"); + return false; + } + } + return false; + } + + bool ThunkLoader::DestroyThunkInstance() { + if (!core::Runtime::runtime_singleton_->flag().enable_dtif()) + return true; + + if (dtif_handle == NULL) + return false; + + DtifDestroyFunc* pfnDtifDestroy = (DtifDestroyFunc*)dlsym(dtif_handle, "DtifDestroy"); + if (pfnDtifDestroy != NULL) { + pfnDtifDestroy(); + debug_print("DtifDestroy OK!\n"); + return true; + } + return false; + } } // namespace core } // namespace rocr