SWDEV-437702 - implement hipGetProcAddress
This should be used in place of dlsym or GetProcAddress (linux and windows respectively) Change-Id: I5501b538e03892e8e5a2282678d848fcaf21d911
This commit is contained in:
@@ -449,6 +449,7 @@ hipGraphAddMemFreeNode
|
||||
hipGraphMemFreeNodeGetParams
|
||||
hipDrvGraphAddMemcpyNode
|
||||
hipDrvGraphAddMemsetNode
|
||||
hipGetProcAddress
|
||||
hipExtGetLastError
|
||||
hipGraphAddExternalSemaphoresSignalNode
|
||||
hipGraphAddExternalSemaphoresWaitNode
|
||||
|
||||
@@ -761,6 +761,8 @@ hipError_t hipModuleLaunchCooperativeKernelMultiDevice(hipFunctionLaunchParams*
|
||||
hipError_t hipExtGetLastError();
|
||||
hipError_t hipTexRefGetBorderColor(float* pBorderColor, const textureReference* texRef);
|
||||
hipError_t hipTexRefGetArray(hipArray_t* pArray, const textureReference* texRef);
|
||||
hipError_t hipGetProcAddress(const char* symbol, void** pfn, int hipVersion, uint64_t flags,
|
||||
hipDriverProcAddressQueryResult* symbolStatus = NULL);
|
||||
} // namespace hip
|
||||
|
||||
namespace hip {
|
||||
@@ -1234,6 +1236,7 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
|
||||
ptrDispatchTable->hipExtGetLastError_fn = hip::hipExtGetLastError;
|
||||
ptrDispatchTable->hipTexRefGetBorderColor_fn = hip::hipTexRefGetBorderColor;
|
||||
ptrDispatchTable->hipTexRefGetArray_fn = hip::hipTexRefGetArray;
|
||||
ptrDispatchTable->hipGetProcAddress_fn = hip::hipGetProcAddress;
|
||||
}
|
||||
|
||||
#if HIP_ROCPROFILER_REGISTER > 0
|
||||
@@ -1251,7 +1254,7 @@ constexpr auto ComputeTableSize(size_t num_funcs) {
|
||||
return (num_funcs * sizeof(void*)) + sizeof(uint64_t);
|
||||
}
|
||||
|
||||
HIP_DEFINE_DISPATCH_TABLE_INFO(HipDispatchTable, hip, 429)
|
||||
HIP_DEFINE_DISPATCH_TABLE_INFO(HipDispatchTable, hip, 440)
|
||||
HIP_DEFINE_DISPATCH_TABLE_INFO(HipCompilerDispatchTable, hip_compiler, 9)
|
||||
#endif
|
||||
|
||||
@@ -1775,8 +1778,9 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecExternalSemaphoresSignalNodeSetPar
|
||||
HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecExternalSemaphoresWaitNodeSetParams_fn, 436);
|
||||
HIP_ENFORCE_ABI(HipDispatchTable, hipGraphAddNode_fn, 437);
|
||||
HIP_ENFORCE_ABI(HipDispatchTable, hipGraphInstantiateWithParams_fn, 438);
|
||||
HIP_ENFORCE_ABI(HipDispatchTable, hipGetProcAddress_fn, 442)
|
||||
|
||||
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 0,
|
||||
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 1,
|
||||
"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");
|
||||
#endif
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "hip_internal.hpp"
|
||||
#include "hip_mempool_impl.hpp"
|
||||
#include "hip_platform.hpp"
|
||||
|
||||
#undef hipGetDeviceProperties
|
||||
#undef hipDeviceProp_t
|
||||
@@ -584,6 +585,44 @@ hipError_t hipGetDevicePropertiesR0000(hipDeviceProp_tR0000* prop, int device) {
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipGetProcAddress(const char* symbol, void** pfn, int hipVersion, uint64_t flags,
|
||||
hipDriverProcAddressQueryResult* symbolStatus = nullptr) {
|
||||
HIP_INIT_API(hipGetProcAddress, symbol, pfn, hipVersion, flags, symbolStatus);
|
||||
|
||||
std::string symbolString = symbol;
|
||||
if(symbol == nullptr || symbolString == "" || *pfn == nullptr){
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
if (symbolString == "hipGetDeviceProperties"){
|
||||
if (hipVersion >= 600){
|
||||
symbolString = "hipGetDevicePropertiesR0600";
|
||||
}
|
||||
} else if (symbolString == "hipChooseDevice") {
|
||||
if (hipVersion >= 600){
|
||||
symbolString = "hipChooseDeviceR0600";
|
||||
}
|
||||
}
|
||||
|
||||
void* handle = hip::PlatformState::instance().getDynamicLibraryHandle();
|
||||
if (handle == nullptr){
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
*pfn = amd::Os::getSymbol(handle, symbolString.c_str());
|
||||
if (!(*pfn)) {
|
||||
if (symbolStatus != nullptr) {
|
||||
*symbolStatus = HIP_GET_PROC_ADDRESS_SYMBOL_NOT_FOUND;
|
||||
}
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
if (symbolStatus != nullptr) {
|
||||
*symbolStatus = HIP_GET_PROC_ADDRESS_SUCCESS;
|
||||
}
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
} // namespace hip
|
||||
|
||||
extern "C" hipError_t hipGetDeviceProperties(hipDeviceProp_tR0000* props, hipDevice_t device) {
|
||||
|
||||
@@ -551,6 +551,7 @@ local:
|
||||
hip_6.1 {
|
||||
global:
|
||||
hipGraphInstantiateWithParams;
|
||||
hipGetProcAddress;
|
||||
local:
|
||||
*;
|
||||
} hip_6.0;
|
||||
|
||||
@@ -958,4 +958,27 @@ bool PlatformState::CloseUniqueFileHandle(const std::shared_ptr<UniqueFD>& ufd)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void* PlatformState::getDynamicLibraryHandle() {
|
||||
amd::ScopedLock lock(lock_);
|
||||
|
||||
if (dynamicLibraryHandle_ != nullptr) {
|
||||
return dynamicLibraryHandle_;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const char* libName = "amdhip64.dll";
|
||||
#else
|
||||
const char* libName = "libamdhip64.so";
|
||||
#endif
|
||||
|
||||
dynamicLibraryHandle_ = amd::Os::loadLibrary(libName);
|
||||
return dynamicLibraryHandle_;
|
||||
}
|
||||
|
||||
void PlatformState::setDynamicLibraryHandle(void* handle){
|
||||
amd::ScopedLock lock(lock_);
|
||||
dynamicLibraryHandle_ = handle;
|
||||
}
|
||||
|
||||
} //namespace hip
|
||||
|
||||
@@ -96,6 +96,10 @@ class PlatformState {
|
||||
|
||||
hipError_t initStatManagedVarDevicePtr(int deviceId);
|
||||
|
||||
// Load hip dynamic library
|
||||
void* getDynamicLibraryHandle();
|
||||
void setDynamicLibraryHandle(void* handle);
|
||||
|
||||
// Exec Functions
|
||||
void setupArgument(const void* arg, size_t size, size_t offset);
|
||||
void configureCall(dim3 gridDim, dim3 blockDim, size_t sharedMem, hipStream_t stream);
|
||||
@@ -114,5 +118,7 @@ class PlatformState {
|
||||
std::unordered_map<textureReference*, std::pair<hipModule_t, std::string>> texRef_map_;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<UniqueFD>> ufd_map_; //!< Unique File Desc Map
|
||||
|
||||
void* dynamicLibraryHandle_{nullptr};
|
||||
};
|
||||
} // namespace hip
|
||||
|
||||
@@ -18,10 +18,13 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE. */
|
||||
|
||||
#include "thread/thread.hpp"
|
||||
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
#include "thread/thread.hpp"
|
||||
#include "hip_platform.hpp"
|
||||
|
||||
namespace hip {
|
||||
void ihipDestroyDevice();
|
||||
}
|
||||
@@ -46,6 +49,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||
_set_error_mode(_OUT_TO_STDERR);
|
||||
}
|
||||
#endif // DEBUG
|
||||
hip::PlatformState::instance().setDynamicLibraryHandle(static_cast<void*>(hinst));
|
||||
break;
|
||||
case DLL_PROCESS_DETACH: {
|
||||
amd::Thread* thread = amd::Thread::current();
|
||||
|
||||
@@ -1727,3 +1727,9 @@ hipError_t hipTexRefGetBorderColor(float* pBorderColor, const textureReference*
|
||||
hipError_t hipTexRefGetArray(hipArray_t* pArray, const textureReference* texRef) {
|
||||
return hip::GetHipDispatchTable()->hipTexRefGetArray_fn(pArray, texRef);
|
||||
}
|
||||
extern "C" hipError_t hipGetProcAddress(const char* symbol, void** pfn, int hipVersion,
|
||||
uint64_t flags,
|
||||
hipDriverProcAddressQueryResult* symbolStatus = nullptr) {
|
||||
return hip::GetHipDispatchTable()->hipGetProcAddress_fn(symbol, pfn, hipVersion, flags,
|
||||
symbolStatus);
|
||||
}
|
||||
Fai riferimento in un nuovo problema
Block a user