Skip to content

Commit

Permalink
[hip] Optionally enable graph command buffer and tests (#16604)
Browse files Browse the repository at this point in the history
This commit made `hipDrvGraphAddMemcpyNode` as an optional
symbol so that even when we are missing it we can still build the hip
HAL driver without problem. Instead it will error out at runtime.
This allows us to start testing the hip graph based command buffer.
For that, tests are registered.
  • Loading branch information
antiagainst authored Feb 29, 2024
1 parent 42232b5 commit 24bf0ac
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 94 deletions.
26 changes: 26 additions & 0 deletions experimental/hip/cts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,29 @@ iree_hal_cts_test_suite(
LABELS
driver=hip
)

iree_hal_cts_test_suite(
DRIVER_NAME
hip
VARIANT_SUFFIX
graph
DRIVER_REGISTRATION_HDR
"experimental/hip/registration/driver_module.h"
DRIVER_REGISTRATION_FN
"iree_hal_hip_driver_module_register"
COMPILER_TARGET_BACKEND
"rocm"
EXECUTABLE_FORMAT
"\"HSACO\""
COMPILER_FLAGS
${IREE_HIP_TEST_COMPILER_FLAGS}
ARGS
"--hip_use_streams=false"
DEPS
iree::experimental::hip::registration
EXCLUDED_TESTS
# HAL event is unimplemented for now.
"event"
LABELS
driver=hip
)
174 changes: 99 additions & 75 deletions experimental/hip/dynamic_symbol_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,104 @@
// HIP symbols
//===----------------------------------------------------------------------===//

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)
IREE_HIP_PFN_DECL(hipDeviceGetUuid, hipUUID *, hipDevice_t)
IREE_HIP_PFN_DECL(hipDevicePrimaryCtxRelease, hipDevice_t)
IREE_HIP_PFN_DECL(hipDevicePrimaryCtxRetain, hipCtx_t *, hipDevice_t)
IREE_HIP_PFN_DECL(hipEventCreate, hipEvent_t *)
IREE_HIP_PFN_DECL(hipEventCreateWithFlags, hipEvent_t *, unsigned int)
IREE_HIP_PFN_DECL(hipEventDestroy, hipEvent_t)
IREE_HIP_PFN_DECL(hipEventElapsedTime, float *, hipEvent_t, hipEvent_t)
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)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipCtxSetCurrent, hipCtx_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipDeviceGet, hipDevice_t *, int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipDeviceGetAttribute, int *,
hipDeviceAttribute_t, int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipDeviceGetName, char *, int, hipDevice_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipDeviceGetUuid, hipUUID *, hipDevice_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipDevicePrimaryCtxRelease, hipDevice_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipDevicePrimaryCtxRetain, hipCtx_t *,
hipDevice_t)
IREE_HAL_HIP_OPTIONAL_PFN_DECL(hipDrvGraphAddMemcpyNode, hipGraphNode_t *,
hipGraph_t, const hipGraphNode_t *, size_t,
const HIP_MEMCPY3D *, hipCtx_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventCreate, hipEvent_t *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventCreateWithFlags, hipEvent_t *,
unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventDestroy, hipEvent_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventElapsedTime, float *, hipEvent_t,
hipEvent_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventQuery, hipEvent_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventRecord, hipEvent_t, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipEventSynchronize, hipEvent_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipFree, void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipFreeAsync, void *, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipFuncSetAttribute, const void *,
hipFuncAttribute, int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGetDeviceCount, int *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGetDeviceProperties, hipDeviceProp_t *, int)
// hipGetErrorName(hipError_t) and hipGetErrorString(hipError_t) return
// const char* instead of hipError_t so it uses a different macro.
IREE_HIP_PFN_STR_DECL(hipGetErrorName, hipError_t)
IREE_HIP_PFN_STR_DECL(hipGetErrorString, hipError_t)
IREE_HIP_PFN_DECL(hipGraphAddEmptyNode, hipGraphNode_t *, hipGraph_t,
const hipGraphNode_t *, size_t)
IREE_HIP_PFN_DECL(hipGraphAddKernelNode, hipGraphNode_t *, hipGraph_t,
const hipGraphNode_t *, size_t, const hipKernelNodeParams *)
IREE_HIP_PFN_DECL(hipGraphAddMemsetNode, hipGraphNode_t *, hipGraph_t,
const hipGraphNode_t *, size_t, const hipMemsetParams *)
IREE_HIP_PFN_DECL(hipGraphCreate, hipGraph_t *, unsigned int)
IREE_HIP_PFN_DECL(hipGraphDestroy, hipGraph_t)
IREE_HIP_PFN_DECL(hipGraphExecDestroy, hipGraphExec_t)
IREE_HIP_PFN_DECL(hipGraphInstantiate, hipGraphExec_t *, hipGraph_t,
hipGraphNode_t *, char *, size_t)
IREE_HIP_PFN_DECL(hipGraphLaunch, hipGraphExec_t, hipStream_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(hipLaunchHostFunc, hipStream_t, hipHostFn_t, void *)
IREE_HIP_PFN_DECL(hipLaunchKernel, const void *, dim3, dim3, void **, size_t,
hipStream_t)
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(hipMemcpy, void *, const void *, size_t, hipMemcpyKind)
IREE_HIP_PFN_DECL(hipMemcpyAsync, void *, const void *, size_t, hipMemcpyKind,
hipStream_t)
IREE_HIP_PFN_DECL(hipMemcpyHtoDAsync, hipDeviceptr_t, void *, size_t,
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)
IREE_HIP_PFN_DECL(hipMemsetD16Async, void *, short, size_t, hipStream_t)
IREE_HIP_PFN_DECL(hipMemsetD32Async, void *, int, size_t, hipStream_t)
IREE_HIP_PFN_DECL(hipModuleGetFunction, hipFunction_t *, hipModule_t,
const char *)
IREE_HIP_PFN_DECL(hipModuleLaunchKernel, hipFunction_t, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, hipStream_t, void **, void **)
IREE_HIP_PFN_DECL(hipModuleLoadData, hipModule_t *, const void *)
IREE_HIP_PFN_DECL(hipModuleLoadDataEx, hipModule_t *, const void *,
unsigned int, hipJitOption *, void **)
IREE_HIP_PFN_DECL(hipModuleUnload, hipModule_t)
IREE_HIP_PFN_DECL(hipStreamCreateWithFlags, hipStream_t *, unsigned int)
IREE_HIP_PFN_DECL(hipStreamDestroy, hipStream_t)
IREE_HIP_PFN_DECL(hipStreamSynchronize, hipStream_t)
IREE_HIP_PFN_DECL(hipStreamWaitEvent, hipStream_t, hipEvent_t, unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_STR_DECL(hipGetErrorName, hipError_t)
IREE_HAL_HIP_REQUIRED_PFN_STR_DECL(hipGetErrorString, hipError_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphAddEmptyNode, hipGraphNode_t *,
hipGraph_t, const hipGraphNode_t *, size_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphAddKernelNode, hipGraphNode_t *,
hipGraph_t, const hipGraphNode_t *, size_t,
const hipKernelNodeParams *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphAddMemsetNode, hipGraphNode_t *,
hipGraph_t, const hipGraphNode_t *, size_t,
const hipMemsetParams *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphCreate, hipGraph_t *, unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphDestroy, hipGraph_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphExecDestroy, hipGraphExec_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphInstantiate, hipGraphExec_t *,
hipGraph_t, hipGraphNode_t *, char *, size_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipGraphLaunch, hipGraphExec_t, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipHostFree, void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipHostGetDevicePointer, void **, void *,
unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipHostMalloc, void **, size_t, unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipHostRegister, void *, size_t, unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipHostUnregister, void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipInit, unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipLaunchHostFunc, hipStream_t, hipHostFn_t,
void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipLaunchKernel, const void *, dim3, dim3,
void **, size_t, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMalloc, void **, size_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMallocFromPoolAsync, void **, size_t,
hipMemPool_t, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMallocManaged, hipDeviceptr_t *, size_t,
unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemcpy, void *, const void *, size_t,
hipMemcpyKind)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemcpyAsync, void *, const void *, size_t,
hipMemcpyKind, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemcpyHtoDAsync, hipDeviceptr_t, void *,
size_t, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemPoolCreate, hipMemPool_t *,
const hipMemPoolProps *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemPoolDestroy, hipMemPool_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemPoolGetAttribute, hipMemPool_t,
hipMemPoolAttr, void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemPoolSetAttribute, hipMemPool_t,
hipMemPoolAttr, void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemPoolTrimTo, hipMemPool_t, size_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemPrefetchAsync, const void *, size_t, int,
hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemset, void *, int, size_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemsetAsync, void *, int, size_t, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemsetD8Async, void *, char, size_t,
hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemsetD16Async, void *, short, size_t,
hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipMemsetD32Async, void *, int, size_t,
hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipModuleGetFunction, hipFunction_t *,
hipModule_t, const char *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipModuleLaunchKernel, hipFunction_t,
unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int,
unsigned int, hipStream_t, void **, void **)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipModuleLoadData, hipModule_t *, const void *)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipModuleLoadDataEx, hipModule_t *, const void *,
unsigned int, hipJitOption *, void **)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipModuleUnload, hipModule_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipStreamCreateWithFlags, hipStream_t *,
unsigned int)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipStreamDestroy, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipStreamSynchronize, hipStream_t)
IREE_HAL_HIP_REQUIRED_PFN_DECL(hipStreamWaitEvent, hipStream_t, hipEvent_t,
unsigned int)
20 changes: 13 additions & 7 deletions experimental/hip/dynamic_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include <string.h>

#include "experimental/hip/status_util.h"
#include "iree/base/assert.h"
#include "iree/base/api.h"
#include "iree/base/internal/dynamic_library.h"
#include "iree/base/target_platform.h"
#include "iree/base/tracing.h"

//===----------------------------------------------------------------------===//
// HIP dynamic symbols
Expand All @@ -29,17 +28,24 @@ static const char* iree_hal_hip_dylib_names[] = {
// Resolves all HIP dynamic symbols in `dynamic_symbol_tables.h`
static iree_status_t iree_hal_hip_dynamic_symbols_resolve_all(
iree_hal_hip_dynamic_symbols_t* syms) {
#define IREE_HIP_PFN_DECL(hip_symbol_name, ...) \
#define IREE_HAL_HIP_REQUIRED_PFN_DECL(hip_symbol_name, ...) \
{ \
static const char* name = #hip_symbol_name; \
IREE_RETURN_IF_ERROR(iree_dynamic_library_lookup_symbol( \
syms->dylib, name, (void**)&syms->hip_symbol_name)); \
}
#define IREE_HIP_PFN_STR_DECL(hip_symbol_name, ...) \
IREE_HIP_PFN_DECL(hip_symbol_name, ...)
#define IREE_HAL_HIP_REQUIRED_PFN_STR_DECL(hip_symbol_name, ...) \
IREE_HAL_HIP_REQUIRED_PFN_DECL(hip_symbol_name, ...)
#define IREE_HAL_HIP_OPTIONAL_PFN_DECL(hip_symbol_name, ...) \
{ \
static const char* name = #hip_symbol_name; \
IREE_IGNORE_ERROR(iree_dynamic_library_lookup_symbol( \
syms->dylib, name, (void**)&syms->hip_symbol_name)); \
}
#include "experimental/hip/dynamic_symbol_tables.h" // IWYU pragma: keep
#undef IREE_HIP_PFN_DECL
#undef IREE_HIP_PFN_STR_DECL
#undef IREE_HAL_HIP_REQUIRED_PFN_DECL
#undef IREE_HAL_HIP_REQUIRED_PFN_STR_DECL
#undef IREE_HAL_HIP_OPTIONAL_PFN_DECL
return iree_ok_status();
}

Expand Down
11 changes: 7 additions & 4 deletions experimental/hip/dynamic_symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ typedef struct iree_hal_hip_dynamic_symbols_t {
iree_dynamic_library_t* dylib;

// Concrete HIP symbols defined by including the `dynamic_symbol_tables.h`.
#define IREE_HIP_PFN_DECL(hipSymbolName, ...) \
#define IREE_HAL_HIP_REQUIRED_PFN_DECL(hipSymbolName, ...) \
hipError_t (*hipSymbolName)(__VA_ARGS__);
#define IREE_HIP_PFN_STR_DECL(hipSymbolName, ...) \
#define IREE_HAL_HIP_REQUIRED_PFN_STR_DECL(hipSymbolName, ...) \
const char* (*hipSymbolName)(__VA_ARGS__);
#define IREE_HAL_HIP_OPTIONAL_PFN_DECL(hipSymbolName, ...) \
hipError_t (*hipSymbolName)(__VA_ARGS__);
#include "experimental/hip/dynamic_symbol_tables.h" // IWYU pragma: export
#undef IREE_HIP_PFN_DECL
#undef IREE_HIP_PFN_STR_DECL
#undef IREE_HAL_HIP_REQUIRED_PFN_DECL
#undef IREE_HAL_HIP_REQUIRED_PFN_STR_DECL
#undef IREE_HAL_HIP_OPTIONAL_PFN_DECL
} iree_hal_hip_dynamic_symbols_t;

// Initializes |out_syms| in-place with dynamically loaded HIP symbols.
Expand Down
18 changes: 10 additions & 8 deletions experimental/hip/graph_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,13 @@ static iree_status_t iree_hal_hip_graph_command_buffer_update_buffer(
iree_hal_command_buffer_t* base_command_buffer, const void* source_buffer,
iree_host_size_t source_offset, iree_hal_buffer_t* target_buffer,
iree_device_size_t target_offset, iree_device_size_t length) {
return iree_make_status(IREE_STATUS_UNIMPLEMENTED,
"update buffer not yet implemented");
/*
iree_hal_hip_graph_command_buffer_t* command_buffer =
iree_hal_hip_graph_command_buffer_cast(base_command_buffer);
if (command_buffer->symbols->hipDrvGraphAddMemcpyNode == NULL) {
return iree_make_status(IREE_STATUS_UNAVAILABLE,
"missing hipDrvGraphAddMemcpyNode symbol; "
"cannot use graph-based command buffer");
}
IREE_TRACE_ZONE_BEGIN(z0);

// Allocate scratch space in the arena for the data and copy it in.
Expand Down Expand Up @@ -413,19 +415,20 @@ static iree_status_t iree_hal_hip_graph_command_buffer_update_buffer(

IREE_TRACE_ZONE_END(z0);
return iree_ok_status();
*/
}

static iree_status_t iree_hal_hip_graph_command_buffer_copy_buffer(
iree_hal_command_buffer_t* base_command_buffer,
iree_hal_buffer_t* source_buffer, iree_device_size_t source_offset,
iree_hal_buffer_t* target_buffer, iree_device_size_t target_offset,
iree_device_size_t length) {
return iree_make_status(IREE_STATUS_UNIMPLEMENTED,
"copy buffer not yet implemented");
/*
iree_hal_hip_graph_command_buffer_t* command_buffer =
iree_hal_hip_graph_command_buffer_cast(base_command_buffer);
if (command_buffer->symbols->hipDrvGraphAddMemcpyNode == NULL) {
return iree_make_status(IREE_STATUS_UNAVAILABLE,
"missing hipDrvGraphAddMemcpyNode symbol; "
"cannot use graph-based command buffer");
}
IREE_TRACE_ZONE_BEGIN(z0);

const iree_hal_buffer_t* buffers[2] = {source_buffer, target_buffer};
Expand Down Expand Up @@ -469,7 +472,6 @@ static iree_status_t iree_hal_hip_graph_command_buffer_copy_buffer(

IREE_TRACE_ZONE_END(z0);
return iree_ok_status();
*/
}

static iree_status_t iree_hal_hip_graph_command_buffer_collective(
Expand Down
Loading

0 comments on commit 24bf0ac

Please sign in to comment.