|
1 | 1 | #define __HIP_PLATFORM_AMD__
|
2 |
| -// clang-format off |
3 |
| -// hip_depreated.h needs definitions from hip_runtime.h. |
4 | 2 | #include <hip/hip_runtime.h>
|
5 |
| -#include <hip/hip_deprecated.h> |
6 |
| -// clang-format on |
| 3 | +#include <hip/hip_runtime_api.h> |
7 | 4 | #define PY_SSIZE_T_CLEAN
|
8 | 5 | #include <Python.h>
|
9 | 6 | #include <dlfcn.h>
|
|
14 | 11 | // code should substitute the search path placeholder.
|
15 | 12 | static const char *hipLibSearchPaths[] = {"/*py_libhip_search_path*/"};
|
16 | 13 |
|
17 |
| -// The list of HIP dynamic library symbols and their signature we are interested |
18 |
| -// in this file. |
19 |
| -// |FOR_EACH_ERR_FN| is a macro to process APIs that return hipError_t; |
20 |
| -// |FOR_EACH_STR_FN| is a macro to process APIs that return const char *. |
21 |
| -// |
22 |
| -// HIP 6.0 introduced an updated hipGetDeviceProperties API under a new symbol, |
23 |
| -// hipGetDevicePropertiesR0600. However, the associated hipDeviceProp_t was |
24 |
| -// directly updated with breaking changes to match hipGetDevicePropertiesR0600 |
25 |
| -// in the header file. We include the header file from HIP 6.0. So here if we |
26 |
| -// use hipGetDeviceProperties together with hipDeviceProp_t we will use the |
27 |
| -// old API with a new struct definition and mess up the interpretation. |
28 |
| -// |
29 |
| -// This is a known issue: https://github.com/ROCm/ROCm/issues/2728. |
30 |
| -// |
31 |
| -// For now explicitly defer to the old hipDeviceProp_t struct. This should work |
32 |
| -// for both 5.x and 6.x. In the long term we need to switch to use |
33 |
| -// hipGetProcAddress once available: |
34 |
| -// https://github.com/ROCm/clr/commit/0479cdb3dd30ef58718cad44e424bd793c394cc0 |
35 | 14 | #define HIP_SYMBOL_LIST(FOR_EACH_ERR_FN, FOR_EACH_STR_FN) \
|
36 | 15 | FOR_EACH_STR_FN(hipGetErrorString, hipError_t hipError) \
|
37 |
| - FOR_EACH_ERR_FN(hipGetDeviceProperties, hipDeviceProp_tR0000 *prop, \ |
38 |
| - int deviceId) \ |
| 16 | + FOR_EACH_ERR_FN(hipGetDeviceProperties, hipDeviceProp_t *prop, int deviceId) \ |
39 | 17 | FOR_EACH_ERR_FN(hipModuleLoadDataEx, hipModule_t *module, const void *image, \
|
40 | 18 | unsigned int numOptions, hipJitOption *options, \
|
41 | 19 | void **optionValues) \
|
@@ -80,15 +58,34 @@ bool initSymbolTable() {
|
80 | 58 | return false;
|
81 | 59 | }
|
82 | 60 |
|
83 |
| - // Resolve all symbols we are interested in. |
| 61 | + typedef hipError_t (*hipGetProcAddress_fn)( |
| 62 | + const char *symbol, void **pfn, int hipVersion, uint64_t hipFlags, |
| 63 | + hipDriverProcAddressQueryResult *symbolStatus); |
| 64 | + hipGetProcAddress_fn hipGetProcAddress; |
84 | 65 | dlerror(); // Clear existing errors
|
85 | 66 | const char *error = NULL;
|
| 67 | + *(void **)&hipGetProcAddress = dlsym(lib, "hipGetProcAddress"); |
| 68 | + error = dlerror(); |
| 69 | + if (error) { |
| 70 | + PyErr_SetString(PyExc_RuntimeError, |
| 71 | + "cannot query 'hipGetProcAddress' from libamdhip64.so"); |
| 72 | + dlclose(lib); |
| 73 | + return false; |
| 74 | + } |
| 75 | + |
| 76 | + // Resolve all symbols we are interested in. |
| 77 | + int hipVersion = HIP_VERSION; |
| 78 | + uint64_t hipFlags = 0; |
| 79 | + hipDriverProcAddressQueryResult symbolStatus; |
| 80 | + hipError_t status = hipSuccess; |
86 | 81 | #define QUERY_EACH_FN(hipSymbolName, ...) \
|
87 |
| - *(void **)&hipSymbolTable.hipSymbolName = dlsym(lib, #hipSymbolName); \ |
88 |
| - error = dlerror(); \ |
89 |
| - if (error) { \ |
| 82 | + status = hipGetProcAddress(#hipSymbolName, \ |
| 83 | + (void **)&hipSymbolTable.hipSymbolName, \ |
| 84 | + hipVersion, hipFlags, &symbolStatus); \ |
| 85 | + if (status != hipSuccess) { \ |
90 | 86 | PyErr_SetString(PyExc_RuntimeError, \
|
91 |
| - "cannot query " #hipSymbolName " from libamdhip64.so"); \ |
| 87 | + "cannot get address for '" #hipSymbolName \ |
| 88 | + "' from libamdhip64.so"); \ |
92 | 89 | dlclose(lib); \
|
93 | 90 | return false; \
|
94 | 91 | }
|
@@ -127,7 +124,7 @@ static PyObject *getDeviceProperties(PyObject *self, PyObject *args) {
|
127 | 124 | if (!PyArg_ParseTuple(args, "i", &device_id))
|
128 | 125 | return NULL;
|
129 | 126 |
|
130 |
| - hipDeviceProp_tR0000 props; |
| 127 | + hipDeviceProp_t props; |
131 | 128 | HIP_CHECK(hipSymbolTable.hipGetDeviceProperties(&props, device_id));
|
132 | 129 |
|
133 | 130 | // create a struct to hold device properties
|
|
0 commit comments