Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hip] Optionally enable graph-based command buffer and add tests #16604

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
168 changes: 93 additions & 75 deletions experimental/hip/dynamic_symbol_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,98 @@
// 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)
REQUIRED_IREE_HIP_PFN_DECL(hipCtxSetCurrent, hipCtx_t)
REQUIRED_IREE_HIP_PFN_DECL(hipDeviceGet, hipDevice_t *, int)
REQUIRED_IREE_HIP_PFN_DECL(hipDeviceGetAttribute, int *, hipDeviceAttribute_t,
int)
REQUIRED_IREE_HIP_PFN_DECL(hipDeviceGetName, char *, int, hipDevice_t)
REQUIRED_IREE_HIP_PFN_DECL(hipDeviceGetUuid, hipUUID *, hipDevice_t)
REQUIRED_IREE_HIP_PFN_DECL(hipDevicePrimaryCtxRelease, hipDevice_t)
REQUIRED_IREE_HIP_PFN_DECL(hipDevicePrimaryCtxRetain, hipCtx_t *, hipDevice_t)
OPTIONAL_IREE_HIP_PFN_DECL(hipDrvGraphAddMemcpyNode, hipGraphNode_t *,
hipGraph_t, const hipGraphNode_t *, size_t,
const HIP_MEMCPY3D *, hipCtx_t)
REQUIRED_IREE_HIP_PFN_DECL(hipEventCreate, hipEvent_t *)
REQUIRED_IREE_HIP_PFN_DECL(hipEventCreateWithFlags, hipEvent_t *, unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipEventDestroy, hipEvent_t)
REQUIRED_IREE_HIP_PFN_DECL(hipEventElapsedTime, float *, hipEvent_t, hipEvent_t)
REQUIRED_IREE_HIP_PFN_DECL(hipEventQuery, hipEvent_t)
REQUIRED_IREE_HIP_PFN_DECL(hipEventRecord, hipEvent_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipEventSynchronize, hipEvent_t)
REQUIRED_IREE_HIP_PFN_DECL(hipFree, void *)
REQUIRED_IREE_HIP_PFN_DECL(hipFreeAsync, void *, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipFuncSetAttribute, const void *, hipFuncAttribute,
int)
REQUIRED_IREE_HIP_PFN_DECL(hipGetDeviceCount, int *)
REQUIRED_IREE_HIP_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)
REQUIRED_IREE_HIP_PFN_STR_DECL(hipGetErrorName, hipError_t)
REQUIRED_IREE_HIP_PFN_STR_DECL(hipGetErrorString, hipError_t)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphAddEmptyNode, hipGraphNode_t *, hipGraph_t,
const hipGraphNode_t *, size_t)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphAddKernelNode, hipGraphNode_t *, hipGraph_t,
const hipGraphNode_t *, size_t,
const hipKernelNodeParams *)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphAddMemsetNode, hipGraphNode_t *, hipGraph_t,
const hipGraphNode_t *, size_t,
const hipMemsetParams *)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphCreate, hipGraph_t *, unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphDestroy, hipGraph_t)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphExecDestroy, hipGraphExec_t)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphInstantiate, hipGraphExec_t *, hipGraph_t,
hipGraphNode_t *, char *, size_t)
REQUIRED_IREE_HIP_PFN_DECL(hipGraphLaunch, hipGraphExec_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipHostFree, void *)
REQUIRED_IREE_HIP_PFN_DECL(hipHostGetDevicePointer, void **, void *,
unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipHostMalloc, void **, size_t, unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipHostRegister, void *, size_t, unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipHostUnregister, void *)
REQUIRED_IREE_HIP_PFN_DECL(hipInit, unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipLaunchHostFunc, hipStream_t, hipHostFn_t, void *)
REQUIRED_IREE_HIP_PFN_DECL(hipLaunchKernel, const void *, dim3, dim3, void **,
size_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMalloc, void **, size_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMallocFromPoolAsync, void **, size_t,
hipMemPool_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMallocManaged, hipDeviceptr_t *, size_t,
unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipMemcpy, void *, const void *, size_t,
hipMemcpyKind)
REQUIRED_IREE_HIP_PFN_DECL(hipMemcpyAsync, void *, const void *, size_t,
hipMemcpyKind, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemcpyHtoDAsync, hipDeviceptr_t, void *, size_t,
hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemPoolCreate, hipMemPool_t *,
const hipMemPoolProps *)
REQUIRED_IREE_HIP_PFN_DECL(hipMemPoolDestroy, hipMemPool_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemPoolGetAttribute, hipMemPool_t, hipMemPoolAttr,
void *)
REQUIRED_IREE_HIP_PFN_DECL(hipMemPoolSetAttribute, hipMemPool_t, hipMemPoolAttr,
void *)
REQUIRED_IREE_HIP_PFN_DECL(hipMemPoolTrimTo, hipMemPool_t, size_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemPrefetchAsync, const void *, size_t, int,
hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemset, void *, int, size_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemsetAsync, void *, int, size_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemsetD8Async, void *, char, size_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemsetD16Async, void *, short, size_t,
hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipMemsetD32Async, void *, int, size_t, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipModuleGetFunction, hipFunction_t *, hipModule_t,
const char *)
REQUIRED_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 **)
REQUIRED_IREE_HIP_PFN_DECL(hipModuleLoadData, hipModule_t *, const void *)
REQUIRED_IREE_HIP_PFN_DECL(hipModuleLoadDataEx, hipModule_t *, const void *,
unsigned int, hipJitOption *, void **)
REQUIRED_IREE_HIP_PFN_DECL(hipModuleUnload, hipModule_t)
REQUIRED_IREE_HIP_PFN_DECL(hipStreamCreateWithFlags, hipStream_t *,
unsigned int)
REQUIRED_IREE_HIP_PFN_DECL(hipStreamDestroy, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipStreamSynchronize, hipStream_t)
REQUIRED_IREE_HIP_PFN_DECL(hipStreamWaitEvent, hipStream_t, hipEvent_t,
unsigned int)
18 changes: 13 additions & 5 deletions experimental/hip/dynamic_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "experimental/hip/status_util.h"
#include "iree/base/assert.h"
#include "iree/base/internal/dynamic_library.h"
#include "iree/base/status.h"
#include "iree/base/target_platform.h"
#include "iree/base/tracing.h"

Expand All @@ -29,17 +30,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 REQUIRED_IREE_HIP_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 REQUIRED_IREE_HIP_PFN_STR_DECL(hip_symbol_name, ...) \
REQUIRED_IREE_HIP_PFN_DECL(hip_symbol_name, ...)
#define OPTIONAL_IREE_HIP_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 REQUIRED_IREE_HIP_PFN_DECL
#undef REQUIRED_IREE_HIP_PFN_STR_DECL
#undef OPTIONAL_IREE_HIP_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 REQUIRED_IREE_HIP_PFN_DECL(hipSymbolName, ...) \
hipError_t (*hipSymbolName)(__VA_ARGS__);
#define IREE_HIP_PFN_STR_DECL(hipSymbolName, ...) \
#define REQUIRED_IREE_HIP_PFN_STR_DECL(hipSymbolName, ...) \
const char* (*hipSymbolName)(__VA_ARGS__);
#define OPTIONAL_IREE_HIP_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 REQUIRED_IREE_HIP_PFN_DECL
#undef REQUIRED_IREE_HIP_PFN_STR_DECL
#undef OPTIONAL_IREE_HIP_PFN_DECL
} iree_hal_hip_dynamic_symbols_t;

// Initializes |out_syms| in-place with dynamically loaded HIP symbols.
Expand Down
19 changes: 11 additions & 8 deletions experimental/hip/graph_command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "experimental/hip/pipeline_layout.h"
#include "experimental/hip/status_util.h"
#include "iree/base/api.h"
#include "iree/base/status.h"
#include "iree/hal/utils/resource_set.h"

// The maximal number of HIP graph nodes that can run concurrently between
Expand Down Expand Up @@ -359,11 +360,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_NOT_FOUND,
"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 +416,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_NOT_FOUND,
"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 +473,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
Loading