Skip to content

Commit

Permalink
[HIP] Adds buffer and allocator implementations (iree-org#15791)
Browse files Browse the repository at this point in the history
This patch adds buffer, allocator, and memory pool implementation for
the new HIP backend.

Progress towards iree-org#15790
  • Loading branch information
nithinsubbiah authored and ramiro050 committed Dec 19, 2023
1 parent f366140 commit d3ce3b0
Show file tree
Hide file tree
Showing 9 changed files with 1,304 additions and 6 deletions.
8 changes: 7 additions & 1 deletion experimental/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ iree_cc_library(
"api.h"
SRCS
"api.h"
"hip_allocator.c"
"hip_allocator.h"
"hip_buffer.c"
"hip_buffer.h"
"hip_driver.c"
"memory_pools.c"
"memory_pools.h"
INCLUDES
"${HIP_API_HEADERS_ROOT}"
DEPS
Expand All @@ -47,8 +53,8 @@ iree_cc_library(
TEXTUAL_HDRS
"dynamic_symbol_tables.h"
SRCS
"hip_headers.h"
"dynamic_symbols.c"
"hip_headers.h"
"status_util.c"
INCLUDES
"${HIP_API_HEADERS_ROOT}"
Expand Down
23 changes: 23 additions & 0 deletions experimental/hip/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@
extern "C" {
#endif // __cplusplus

//===----------------------------------------------------------------------===//
// iree_hal_hip_device_t
//===----------------------------------------------------------------------===//

// Parameters defining a hipMemPool_t.
typedef struct iree_hal_hip_memory_pool_params_t {
// Minimum number of bytes to keep in the pool when trimming with
// iree_hal_device_trim.
uint64_t minimum_capacity;
// Soft maximum number of bytes to keep in the pool.
// When more than this is allocated the extra will be freed at the next
// device synchronization in order to remain under the threshold.
uint64_t release_threshold;
} iree_hal_hip_memory_pool_params_t;

// Parameters for each hipMemPool_t used for queue-ordered allocations.
typedef struct iree_hal_hip_memory_pooling_params_t {
// Used exclusively for DEVICE_LOCAL allocations.
iree_hal_hip_memory_pool_params_t device_local;
// Used for any host-visible/host-local memory types.
iree_hal_hip_memory_pool_params_t other;
} iree_hal_hip_memory_pooling_params_t;

//===----------------------------------------------------------------------===//
// iree_hal_hip_driver_t
//===----------------------------------------------------------------------===//
Expand Down
18 changes: 13 additions & 5 deletions experimental/hip/dynamic_symbol_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
//===----------------------------------------------------------------------===//
// HIP symbols
//===----------------------------------------------------------------------===//
IREE_HIP_PFN_DECL(hipCtxCreate, hipCtx_t *, unsigned int, hipDevice_t)
IREE_HIP_PFN_DECL(hipCtxDestroy, hipCtx_t)
IREE_HIP_PFN_DECL(hipCtxGetDevice, hipDevice_t *)
IREE_HIP_PFN_DECL(hipCtxSetCurrent, hipCtx_t)

IREE_HIP_PFN_DECL(hipDeviceGet, hipDevice_t *, int)
IREE_HIP_PFN_DECL(hipDeviceGetAttribute, int *, hipDeviceAttribute_t, int)
IREE_HIP_PFN_DECL(hipDeviceGetName, char *, int, hipDevice_t)
Expand All @@ -24,6 +21,7 @@ IREE_HIP_PFN_DECL(hipEventQuery, hipEvent_t)
IREE_HIP_PFN_DECL(hipEventRecord, hipEvent_t, hipStream_t)
IREE_HIP_PFN_DECL(hipEventSynchronize, hipEvent_t)
IREE_HIP_PFN_DECL(hipFree, void *)
IREE_HIP_PFN_DECL(hipFreeAsync, void *, hipStream_t)
IREE_HIP_PFN_DECL(hipFuncSetAttribute, const void *, hipFuncAttribute, int)
IREE_HIP_PFN_DECL(hipGetDeviceCount, int *)
IREE_HIP_PFN_DECL(hipGetDeviceProperties, hipDeviceProp_t *, int)
Expand All @@ -33,13 +31,23 @@ IREE_HIP_PFN_STR_DECL(hipGetErrorName, hipError_t)
IREE_HIP_PFN_STR_DECL(hipGetErrorString, hipError_t)
IREE_HIP_PFN_DECL(hipHostFree, void *)
IREE_HIP_PFN_DECL(hipHostGetDevicePointer, void **, void *, unsigned int)
IREE_HIP_PFN_DECL(hipHostMalloc, void **, size_t, unsigned int)
IREE_HIP_PFN_DECL(hipHostRegister, void *, size_t, unsigned int)
IREE_HIP_PFN_DECL(hipHostUnregister, void *)
IREE_HIP_PFN_DECL(hipInit, unsigned int)
IREE_HIP_PFN_DECL(hipMalloc, void **, size_t)
IREE_HIP_PFN_DECL(hipMallocFromPoolAsync, void **, size_t, hipMemPool_t,
hipStream_t)
IREE_HIP_PFN_DECL(hipMallocManaged, hipDeviceptr_t *, size_t, unsigned int)
IREE_HIP_PFN_DECL(hipMemAllocHost, void **, size_t, unsigned int)
IREE_HIP_PFN_DECL(hipMemcpy, void *, const void *, size_t, hipMemcpyKind)
IREE_HIP_PFN_DECL(hipMemcpyAsync, void *, const void *, size_t, hipMemcpyKind,
hipStream_t)
IREE_HIP_PFN_DECL(hipMemPoolCreate, hipMemPool_t *, const hipMemPoolProps *)
IREE_HIP_PFN_DECL(hipMemPoolDestroy, hipMemPool_t)
IREE_HIP_PFN_DECL(hipMemPoolGetAttribute, hipMemPool_t, hipMemPoolAttr, void *)
IREE_HIP_PFN_DECL(hipMemPoolSetAttribute, hipMemPool_t, hipMemPoolAttr, void *)
IREE_HIP_PFN_DECL(hipMemPoolTrimTo, hipMemPool_t, size_t)
IREE_HIP_PFN_DECL(hipMemPrefetchAsync, const void *, size_t, int, hipStream_t)
IREE_HIP_PFN_DECL(hipMemset, void *, int, size_t)
IREE_HIP_PFN_DECL(hipMemsetAsync, void *, int, size_t, hipStream_t)
IREE_HIP_PFN_DECL(hipMemsetD8Async, void *, char, size_t, hipStream_t)
Expand Down
Loading

0 comments on commit d3ce3b0

Please sign in to comment.