Skip to content

Commit 616c960

Browse files
authored
Adding skeleton AMDGPU buffer handle and handle pool. (iree-org#21044)
The driver will implement two buffer types to start (or more?): `iree_hal_amdgpu_external_buffer_t` and `iree_hal_amdgpu_transient_buffer_t`. The external buffer will be used for imported buffers and synchronous allocations (probably), while the transient buffer is used for all asynchronous allocations. The transient buffer maintains a reference to a device-accessible `iree_hal_amdgpu_device_allocation_handle_t` that stores the allocated pointer. The device-side allocator will update the handle as it allocates/deallocates and anyone resolving buffer pointers (e.g. `iree_hal_amdgpu_device_buffer_ref_resolve`) fetches the current pointer from the handle. The pointer is only valid between alloca/dealloca ops (which will set/reset the pointer). `iree_hal_amdgpu_device_buffer_ref_t` is a variant that allows binding tables and command buffer ops to reference typed buffers. Most code can dereference device pointers (synchronously allocated buffers, imported buffers, etc) and the transient buffer handles. Command buffers can reference binding table slots with a relative offset/length. `iree_hal_amdgpu_device_workgroup_count_buffer_ref_t` is a special case for indirect dispatches (where the length is always known) as it packs better into space-constrained structs. A simple `iree_hal_amdgpu_buffer_pool_t` handles both the host `iree_hal_buffer_t` instances and device allocation handles. The device allocation handles can be stored in device memory to avoid additional bus traffic on each dereference. In the steady state of invocations with alloca/dealloca the pool should remove all host/device allocations.
1 parent fd69ba3 commit 616c960

File tree

10 files changed

+1586
-5
lines changed

10 files changed

+1586
-5
lines changed

runtime/src/iree/hal/drivers/amdgpu/BUILD.bazel

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library")
7+
load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library", "iree_runtime_cc_test")
88

99
package(
1010
default_visibility = ["//visibility:public"],
@@ -18,10 +18,10 @@ iree_runtime_cc_library(
1818
srcs = [
1919
# "allocator.c",
2020
# "allocator.h",
21-
# "buffer.c",
22-
# "buffer.h",
23-
# "buffer_pool.c",
24-
# "buffer_pool.h",
21+
"buffer.c",
22+
"buffer.h",
23+
"buffer_pool.c",
24+
"buffer_pool.h",
2525
"channel.c",
2626
"channel.h",
2727
# "command_buffer.c",
@@ -73,3 +73,59 @@ iree_runtime_cc_library(
7373
"//runtime/src/iree/schemas:executable_debug_info_c_fbs",
7474
],
7575
)
76+
77+
# Provided for tests and tools that may reach in.
78+
# These headers are not part of the public API and should not be depended on.
79+
iree_runtime_cc_library(
80+
name = "headers",
81+
hdrs = [
82+
# "allocator.h",
83+
"buffer.h",
84+
"buffer_pool.h",
85+
"channel.h",
86+
# "command_buffer.h",
87+
"driver.h",
88+
"event.h",
89+
"executable.h",
90+
"executable_cache.h",
91+
# "host_worker.h",
92+
"logical_device.h",
93+
"physical_device.h",
94+
# "queue.h",
95+
# "semaphore.h",
96+
# "semaphore_pool.h",
97+
"system.h",
98+
# "trace_buffer.h",
99+
],
100+
deps = [
101+
"//runtime/src/iree/base",
102+
"//runtime/src/iree/base/internal",
103+
"//runtime/src/iree/base/internal:arena",
104+
"//runtime/src/iree/hal",
105+
"//runtime/src/iree/hal/drivers/amdgpu/device:binaries",
106+
"//runtime/src/iree/hal/drivers/amdgpu/device:headers",
107+
"//runtime/src/iree/hal/drivers/amdgpu/util",
108+
"//runtime/src/iree/hal/drivers/amdgpu/util:libhsa",
109+
"//runtime/src/iree/hal/drivers/amdgpu/util:topology",
110+
],
111+
)
112+
113+
iree_runtime_cc_test(
114+
name = "buffer_pool_test",
115+
srcs = ["buffer_pool_test.cc"],
116+
tags = [
117+
"driver=amdgpu",
118+
"nodocker",
119+
],
120+
deps = [
121+
":amdgpu",
122+
":headers",
123+
"//runtime/src/iree/base",
124+
"//runtime/src/iree/hal/drivers/amdgpu/device:headers",
125+
"//runtime/src/iree/hal/drivers/amdgpu/util",
126+
"//runtime/src/iree/hal/drivers/amdgpu/util:libhsa",
127+
"//runtime/src/iree/hal/drivers/amdgpu/util:topology",
128+
"//runtime/src/iree/testing:gtest",
129+
"//runtime/src/iree/testing:gtest_main",
130+
],
131+
)

runtime/src/iree/hal/drivers/amdgpu/CMakeLists.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ iree_cc_library(
1616
HDRS
1717
"api.h"
1818
SRCS
19+
"buffer.c"
20+
"buffer.h"
21+
"buffer_pool.c"
22+
"buffer_pool.h"
1923
"channel.c"
2024
"channel.h"
2125
"driver.c"
@@ -52,4 +56,51 @@ iree_cc_library(
5256
PUBLIC
5357
)
5458

59+
iree_cc_library(
60+
NAME
61+
headers
62+
HDRS
63+
"buffer.h"
64+
"buffer_pool.h"
65+
"channel.h"
66+
"driver.h"
67+
"event.h"
68+
"executable.h"
69+
"executable_cache.h"
70+
"logical_device.h"
71+
"physical_device.h"
72+
"system.h"
73+
DEPS
74+
iree::base
75+
iree::base::internal
76+
iree::base::internal::arena
77+
iree::hal
78+
iree::hal::drivers::amdgpu::device::binaries
79+
iree::hal::drivers::amdgpu::device::headers
80+
iree::hal::drivers::amdgpu::util
81+
iree::hal::drivers::amdgpu::util::libhsa
82+
iree::hal::drivers::amdgpu::util::topology
83+
PUBLIC
84+
)
85+
86+
iree_cc_test(
87+
NAME
88+
buffer_pool_test
89+
SRCS
90+
"buffer_pool_test.cc"
91+
DEPS
92+
::amdgpu
93+
::headers
94+
iree::base
95+
iree::hal::drivers::amdgpu::device::headers
96+
iree::hal::drivers::amdgpu::util
97+
iree::hal::drivers::amdgpu::util::libhsa
98+
iree::hal::drivers::amdgpu::util::topology
99+
iree::testing::gtest
100+
iree::testing::gtest_main
101+
LABELS
102+
"driver=amdgpu"
103+
"nodocker"
104+
)
105+
55106
### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###

0 commit comments

Comments
 (0)