Changeset View
Changeset View
Standalone View
Standalone View
extern/hipew/src/hipew.c
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| /* Function definitions. */ | /* Function definitions. */ | ||||
| thipGetErrorName *hipGetErrorName; | thipGetErrorName *hipGetErrorName; | ||||
| thipInit *hipInit; | thipInit *hipInit; | ||||
| thipDriverGetVersion *hipDriverGetVersion; | thipDriverGetVersion *hipDriverGetVersion; | ||||
| thipGetDevice *hipGetDevice; | thipGetDevice *hipGetDevice; | ||||
| thipGetDeviceCount *hipGetDeviceCount; | thipGetDeviceCount *hipGetDeviceCount; | ||||
| thipGetDeviceProperties *hipGetDeviceProperties; | thipGetDeviceProperties *hipGetDeviceProperties; | ||||
| thipDeviceGet* hipDeviceGet; | |||||
| thipDeviceGetName *hipDeviceGetName; | thipDeviceGetName *hipDeviceGetName; | ||||
| thipDeviceGetAttribute *hipDeviceGetAttribute; | thipDeviceGetAttribute *hipDeviceGetAttribute; | ||||
| thipDeviceComputeCapability *hipDeviceComputeCapability; | thipDeviceComputeCapability *hipDeviceComputeCapability; | ||||
| thipDevicePrimaryCtxRetain *hipDevicePrimaryCtxRetain; | thipDevicePrimaryCtxRetain *hipDevicePrimaryCtxRetain; | ||||
| thipDevicePrimaryCtxRelease *hipDevicePrimaryCtxRelease; | thipDevicePrimaryCtxRelease *hipDevicePrimaryCtxRelease; | ||||
| thipDevicePrimaryCtxSetFlags *hipDevicePrimaryCtxSetFlags; | thipDevicePrimaryCtxSetFlags *hipDevicePrimaryCtxSetFlags; | ||||
| thipDevicePrimaryCtxGetState *hipDevicePrimaryCtxGetState; | thipDevicePrimaryCtxGetState *hipDevicePrimaryCtxGetState; | ||||
| thipDevicePrimaryCtxReset *hipDevicePrimaryCtxReset; | thipDevicePrimaryCtxReset *hipDevicePrimaryCtxReset; | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | |||||
| static void hipewHipExit(void) { | static void hipewHipExit(void) { | ||||
| if (hip_lib != NULL) { | if (hip_lib != NULL) { | ||||
| /* Ignore errors. */ | /* Ignore errors. */ | ||||
| dynamic_library_close(hip_lib); | dynamic_library_close(hip_lib); | ||||
| hip_lib = NULL; | hip_lib = NULL; | ||||
| } | } | ||||
| } | } | ||||
| #ifdef _WIN32 | |||||
| static int hipewHasOldDriver(const char *hip_path) { | |||||
| DWORD verHandle = 0; | |||||
| DWORD verSize = GetFileVersionInfoSize(hip_path, &verHandle); | |||||
| int old_driver = 0; | |||||
| if (verSize != 0) { | |||||
| LPSTR verData = (LPSTR)malloc(verSize); | |||||
| if (GetFileVersionInfo(hip_path, verHandle, verSize, verData)) { | |||||
| LPBYTE lpBuffer = NULL; | |||||
| UINT size = 0; | |||||
| if (VerQueryValue(verData, "\\", (VOID FAR * FAR *)&lpBuffer, &size)) { | |||||
| if (size) { | |||||
| VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; | |||||
| /* Magic value from | |||||
| * https://docs.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo */ | |||||
| if (verInfo->dwSignature == 0xfeef04bd) { | |||||
| unsigned int fileVersionLS0 = (verInfo->dwFileVersionLS >> 16) & 0xffff; | |||||
| unsigned int fileversionLS1 = (verInfo->dwFileVersionLS >> 0) & 0xffff; | |||||
| /* Corresponds to versions older than AMD Radeon Pro 21.Q4. */ | |||||
| old_driver = ((fileVersionLS0 < 3354) || (fileVersionLS0 == 3354 && fileversionLS1 < 13)); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| free(verData); | |||||
| } | |||||
| return old_driver; | |||||
| } | |||||
| #endif | |||||
| static int hipewHipInit(void) { | static int hipewHipInit(void) { | ||||
| /* Library paths. */ | /* Library paths. */ | ||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| /* Expected in c:/windows/system or similar, no path needed. */ | /* Expected in c:/windows/system or similar, no path needed. */ | ||||
| const char *hip_paths[] = {"amdhip64.dll", NULL}; | const char *hip_paths[] = {"amdhip64.dll", NULL}; | ||||
| #elif defined(__APPLE__) | #elif defined(__APPLE__) | ||||
| /* Default installation path. */ | /* Default installation path. */ | ||||
| const char *hip_paths[] = {"", NULL}; | const char *hip_paths[] = {"", NULL}; | ||||
| Show All 11 Lines | #endif | ||||
| initialized = 1; | initialized = 1; | ||||
| error = atexit(hipewHipExit); | error = atexit(hipewHipExit); | ||||
| if (error) { | if (error) { | ||||
| result = HIPEW_ERROR_ATEXIT_FAILED; | result = HIPEW_ERROR_ATEXIT_FAILED; | ||||
| return result; | return result; | ||||
| } | } | ||||
| #ifdef _WIN32 | |||||
| /* Test for driver version. */ | |||||
| if(hipewHasOldDriver(hip_paths[0])) { | |||||
| result = HIPEW_ERROR_OLD_DRIVER; | |||||
| return result; | |||||
| } | |||||
| #endif | |||||
| /* Load library. */ | /* Load library. */ | ||||
| hip_lib = dynamic_library_open_find(hip_paths); | hip_lib = dynamic_library_open_find(hip_paths); | ||||
| if (hip_lib == NULL) { | if (hip_lib == NULL) { | ||||
| result = HIPEW_ERROR_OPEN_FAILED; | result = HIPEW_ERROR_OPEN_FAILED; | ||||
| return result; | return result; | ||||
| } | } | ||||
| /* Fetch all function pointers. */ | /* Fetch all function pointers. */ | ||||
| HIP_LIBRARY_FIND_CHECKED(hipGetErrorName); | HIP_LIBRARY_FIND_CHECKED(hipGetErrorName); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipInit); | HIP_LIBRARY_FIND_CHECKED(hipInit); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDriverGetVersion); | HIP_LIBRARY_FIND_CHECKED(hipDriverGetVersion); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipGetDevice); | HIP_LIBRARY_FIND_CHECKED(hipGetDevice); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipGetDeviceCount); | HIP_LIBRARY_FIND_CHECKED(hipGetDeviceCount); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipGetDeviceProperties); | HIP_LIBRARY_FIND_CHECKED(hipGetDeviceProperties); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDeviceGet); | |||||
| HIP_LIBRARY_FIND_CHECKED(hipDeviceGetName); | HIP_LIBRARY_FIND_CHECKED(hipDeviceGetName); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDeviceGetAttribute); | HIP_LIBRARY_FIND_CHECKED(hipDeviceGetAttribute); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDeviceComputeCapability); | HIP_LIBRARY_FIND_CHECKED(hipDeviceComputeCapability); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxRetain); | HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxRetain); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxRelease); | HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxRelease); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxSetFlags); | HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxSetFlags); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxGetState); | HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxGetState); | ||||
| HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxReset); | HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxReset); | ||||
| ▲ Show 20 Lines • Show All 291 Lines • Show Last 20 Lines | |||||