Skip to content

Commit b4c55c4

Browse files
committed
accelerator/rocm: add buffer_id
add functionality to retrieve a buffer id. This is required for the rcache module to identify whether a buffer pointer is still the one that has originally been registered. In addition, it seems that I forgot to remove the function declaration when removing the dlopen part of the code. Signed-off-by: Edgar Gabriel <Edgar.Gabriel@amd.com>
1 parent bb150ac commit b4c55c4

File tree

2 files changed

+15
-76
lines changed

2 files changed

+15
-76
lines changed

opal/mca/accelerator/rocm/accelerator_rocm.h

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,9 @@
1515

1616
#include <stdio.h>
1717
#include <hip/hip_runtime_api.h>
18+
#include <hip/hip_version.h>
1819

19-
#include "opal/mca/btl/base/base.h"
20-
21-
typedef hipError_t(*hipMalloc_t)(void **, size_t);
22-
typedef hipError_t(*hipFree_t)(void*);
23-
typedef hipError_t(*hipMemcpy_t)(void*, const void*, size_t, hipMemcpyKind);
24-
typedef hipError_t(*hipMemcpyAsync_t)(void*, const void*, size_t, hipMemcpyKind, hipStream_t);
25-
typedef hipError_t(*hipMemcpy2D_t)(void*, size_t, const void*, size_t, size_t, size_t, hipMemcpyKind);
26-
typedef hipError_t(*hipMemcpy2DAsync_t)(void*, size_t, const void*, size_t, size_t, size_t,
27-
hipMemcpyKind, hipStream_t);
28-
typedef hipError_t(*hipMemGetAddressRange_t)(hipDeviceptr_t*, size_t*, hipDeviceptr_t);
29-
typedef hipError_t(*hipHostRegister_t)(void*, size_t, unsigned int);
30-
typedef hipError_t(*hipHostUnregister_t)(void*);
31-
32-
typedef hipError_t(*hipStreamCreate_t)(hipStream_t*);
33-
typedef hipError_t(*hipStreamDestroy_t)(hipStream_t);
34-
typedef hipError_t(*hipStreamSynchronize_t)(hipStream_t);
35-
36-
typedef const char*(*hipGetErrorString_t)(hipError_t);
37-
typedef hipError_t(*hipPointerGetAttributes_t)(hipPointerAttribute_t *, const void *);
38-
39-
typedef hipError_t(*hipEventCreateWithFlags_t)(hipEvent_t*, unsigned);
40-
typedef hipError_t(*hipEventDestroy_t)(hipEvent_t);
41-
typedef hipError_t(*hipEventRecord_t)(hipEvent_t, hipStream_t);
42-
typedef hipError_t(*hipEventQuery_t)(hipEvent_t);
43-
typedef hipError_t(*hipEventSynchronize_t)(hipEvent_t);
44-
45-
typedef hipError_t(*hipIpcGetMemHandle_t)(hipIpcMemHandle_t*, void*);
46-
typedef hipError_t(*hipIpcOpenMemHandle_t)(void **, hipIpcMemHandle_t, unsigned int);
47-
typedef hipError_t(*hipIpcCloseMemHandle_t)(void*);
48-
49-
typedef hipError_t(*hipGetDevice_t)(int*);
50-
typedef hipError_t(*hipGetDeviceCount_t)(int*);
51-
typedef hipError_t(*hipDeviceCanAccessPeer_t)(int*, int, int);
52-
53-
struct opal_accelerator_rocm_hipFunctionTable_s {
54-
hipError_t (*hipMalloc)(void** pts, size_t size);
55-
hipError_t (*hipFree)(void* ptr);
56-
hipError_t (*hipMemcpy)(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind);
57-
hipError_t (*hipMemcpyAsync)(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
58-
hipStream_t stream);
59-
hipError_t(*hipMemcpy2D)(void* dst, size_t dpitch, const void* src, size_t spitch,
60-
size_t width, size_t height, hipMemcpyKind kind);
61-
hipError_t(*hipMemcpy2DAsync)(void* dst, size_t dpitch, const void* src, size_t spitch,
62-
size_t width, size_t height, hipMemcpyKind kind,
63-
hipStream_t stream);
64-
hipError_t(*hipMemGetAddressRange)(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr);
65-
66-
hipError_t(*hipHostRegister)(void* ptr, size_t size, unsigned int flags);
67-
hipError_t(*hipHostUnregister)(void* ptr);
68-
69-
hipError_t (*hipStreamCreate)(hipStream_t* stream);
70-
hipError_t (*hipStreamDestroy)(hipStream_t stream);
71-
hipError_t (*hipStreamSynchronize)(hipStream_t stream);
72-
const char* (*hipGetErrorString)(hipError_t hipError);
73-
hipError_t (*hipPointerGetAttributes)(hipPointerAttribute_t *attributes, const void *ptr);
74-
75-
hipError_t(*hipEventCreateWithFlags)(hipEvent_t* event, unsigned int flags);
76-
hipError_t(*hipEventDestroy)(hipEvent_t event);
77-
hipError_t(*hipEventRecord)(hipEvent_t event, hipStream_t stream);
78-
hipError_t(*hipEventQuery)(hipEvent_t event);
79-
hipError_t(*hipEventSynchronize)(hipEvent_t event);
80-
81-
hipError_t(*hipIpcGetMemHandle)(hipIpcMemHandle_t* handle, void* devPtr);
82-
hipError_t(*hipIpcOpenMemHandle)(void **devPtr, hipIpcMemHandle_t handle, unsigned int flags);
83-
hipError_t(*hipIpcCloseMemHandle)(void* devPtr);
84-
85-
hipError_t(*hipGetDevice)(int* dev_id);
86-
hipError_t(*hipGetDeviceCount)(int* count);
87-
hipError_t(*hipDeviceCanAccessPeer)(int* canAccess, int dev1, int dev2);
88-
};
89-
typedef struct opal_accelerator_rocm_hipFunctionTable_s opal_accelerator_rocm_hipFunctionTable_t;
90-
20+
#include "opal/mca/accelerator/accelerator.h"
9121

9222
typedef struct {
9323
opal_accelerator_base_component_t super;
@@ -96,8 +26,6 @@ typedef struct {
9626
OPAL_DECLSPEC extern opal_accelerator_rocm_component_t mca_accelerator_rocm_component;
9727
OPAL_DECLSPEC extern opal_accelerator_base_module_t opal_accelerator_rocm_module;
9828

99-
OPAL_DECLSPEC extern opal_accelerator_rocm_hipFunctionTable_t opal_accelerator_hip_funcs;
100-
10129
struct opal_accelerator_rocm_stream_t {
10230
opal_accelerator_stream_t base;
10331
};
@@ -110,8 +38,6 @@ struct opal_accelerator_rocm_event_t {
11038
typedef struct opal_accelerator_rocm_event_t opal_accelerator_rocm_event_t;
11139
OBJ_CLASS_DECLARATION(opal_accelerator_rocm_event_t);
11240

113-
#define HIP_FUNCS opal_accelerator_hip_funcs
114-
11541
OPAL_DECLSPEC extern hipStream_t opal_accelerator_rocm_MemcpyStream;
11642
OPAL_DECLSPEC extern int opal_accelerator_rocm_memcpy_async;
11743
OPAL_DECLSPEC extern int opal_accelerator_rocm_verbose;

opal/mca/accelerator/rocm/accelerator_rocm_module.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "accelerator_rocm.h"
1313
#include "opal/mca/accelerator/base/base.h"
14+
#include "opal/constants.h"
15+
#include "opal/util/output.h"
1416

1517
/* Accelerator API's */
1618
static int mca_accelerator_rocm_check_addr(const void *addr, int *dev_id, uint64_t *flags);
@@ -491,5 +493,16 @@ static int mca_accelerator_rocm_device_can_access_peer(int *access, int dev1, in
491493
static int mca_accelerator_rocm_get_buffer_id(int dev_id, const void *addr, opal_accelerator_buffer_id_t *buf_id)
492494
{
493495
*buf_id = 0;
496+
497+
#if HIP_VERSION >= 50120531
498+
hipError_t result = hipPointerGetAttribute((unsigned long long *)&buf_id, HIP_POINTER_ATTRIBUTE_BUFFER_ID,
499+
(hipDeviceptr_t)addr);
500+
if (hipSuccess != result) {
501+
opal_output_verbose(10, opal_accelerator_base_framework.framework_output,
502+
"error in hipPointerGetAttribute, could not retrieve buffer_id");
503+
return OPAL_ERROR;
504+
}
505+
#endif
506+
494507
return OPAL_SUCCESS;
495508
}

0 commit comments

Comments
 (0)