Skip to content

Merging the HAL rewrite branch to main #4571

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

Merged
merged 66 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d8281b2
Removing unused HAL files/functions/types.
benvanik Dec 18, 2020
31e578b
Removing last use of HAL C++ from the HAL VM module.
benvanik Dec 18, 2020
a0c456a
Swapping many C++ HAL types/enums for C ones.
benvanik Dec 18, 2020
4f2ee16
Removing iree/base/bitfield.h.
benvanik Dec 18, 2020
075db0a
Removing iree/hal/cts/ for now until it can be ported to C.
benvanik Dec 18, 2020
f51a0be
Moving HAL C++ types to iree/hal/cc/.
benvanik Dec 19, 2020
bd93b19
Removing C++ command buffer validation as it'll be moved into C.
benvanik Dec 24, 2020
b13586e
Porting the HAL C++ API to C.
benvanik Dec 24, 2020
3a9e46e
Fixing quoting on cmake variables that *must* be quoted. (#4404)
benvanik Jan 6, 2021
2c8c59c
Removing unused iree/hal/testing/ mock types.
benvanik Dec 24, 2020
b7724ba
Adding a new arena type with a shared thread-safe block pool.
benvanik Jan 6, 2021
f4471f7
Fixing tracing macro errors with the latest VC++.
benvanik Jan 11, 2021
150d00a
Porting a majority of Vulkan/Metal to C.
benvanik Dec 31, 2020
8237bc3
Removing Metal backend until it can be replaced.
benvanik Jan 4, 2021
1837384
Removing iree/base/time.h now that no C++ remains using it.
benvanik Jan 11, 2021
95a85ad
Windows ptr atomics fix (needs test coverage, obviously).
benvanik Jan 14, 2021
d8b0292
Ensure wait handles are zero-initialized.
benvanik Jan 13, 2021
3a65c80
Removing unused status results.
benvanik Jan 13, 2021
4a3fc6b
Adding support for cleaning up tasks when retired/discarded.
benvanik Jan 13, 2021
7952bee
Making call and dispatch task closures independent types.
benvanik Jan 14, 2021
b792b1c
Adding batch task submission enqueuing.
benvanik Jan 15, 2021
4bbeac8
Fixing executables with multiple pipelines in Vulkan.
benvanik Jan 15, 2021
3a3ef4d
Disabling executable linking until it can be fixed #4536.
benvanik Jan 15, 2021
3dbaae0
Revive the HAL CTS using the C API. (#4498)
ScottTodd Jan 19, 2021
b4f954f
Allowing iree_task_barrier_t to be initialized in two steps.
benvanik Jan 18, 2021
b904112
Improving `iree_task_post_batch_select_worker`.
benvanik Jan 15, 2021
e120608
Working around crap _mktemp behavior.
benvanik Jan 15, 2021
66d8e0c
Adding a new iree/hal/local/ path as the local CPU driver.
benvanik Dec 24, 2020
75e9779
Porting both the dylib and vmla drivers to use iree/hal/local.
benvanik Dec 24, 2020
7147dc9
Removing iree/hal/host/ now that it is unused.
benvanik Dec 24, 2020
de58a3a
Moving VMLA VM module to iree/modules/vmla/.
benvanik Dec 28, 2020
1c3d2d7
Fixing temp file path cleanup. Can't wait to remove this code.
benvanik Jan 20, 2021
d3c3a8f
Making IREE_EXPECT_OK/IREE_ASSERT_OK print better messages.
benvanik Jan 21, 2021
c9fb159
Removing unused line to remove warning.
benvanik Jan 21, 2021
c1b8009
Tweaking iree_atomic_* macros to better check types and adding a test.
benvanik Jan 21, 2021
952956f
Fixing a type typo in the python bindings.
benvanik Jan 21, 2021
0b39fd5
Fixing third_party/half bazel-to-cmake mapping.
benvanik Jan 21, 2021
c29cc34
Fixing a race where threads start prior to their handle being assigned.
benvanik Jan 22, 2021
02c9a97
Treating push constants offset/length as bytes in the API.
benvanik Jan 22, 2021
47564ef
Making iree_status_t a non-void type to get better warnings on misuse.
benvanik Jan 22, 2021
0b58591
Force mapping on hal.allocator.wrap.byte_buffer (today).
benvanik Jan 22, 2021
fc5c903
Cleanup of compile-time detection of sanitizers to enable TSAN/MSAN.
benvanik Jan 22, 2021
cf5428e
Making threads join on shutdown (for sanity).
benvanik Jan 22, 2021
0d07572
Fixing push constants not being included in executable layout caching.
benvanik Jan 23, 2021
e5cb846
Adding iree_task_pool_t tests.
benvanik Jan 23, 2021
03b0df8
Adding iree_task_queue_t tests.
benvanik Jan 23, 2021
193d212
Adding iree_task_scope_t tests.
benvanik Jan 23, 2021
78849af
Adding iree_task_list_discard test.
benvanik Jan 23, 2021
6ef8473
Adding iree_task_topology_t tests and simplifying allocation.
benvanik Jan 23, 2021
cf5a2ef
Removing HAL backend implementations of fill/read/write/copy.
benvanik Jan 23, 2021
26120d9
Better error status when drivers are not registered.
benvanik Jan 24, 2021
32b3101
Split iree/tools/test/simple.mlir as it was a PITA all as one.
benvanik Jan 24, 2021
d4a83c5
Fix Vulkan GUI sample after HAL C changes. (#4603)
ScottTodd Jan 26, 2021
5c7b233
More fixes after HAL C changes. (#4604)
ScottTodd Jan 26, 2021
9cc1cb6
Properly handling nop tasks in the task system.
benvanik Jan 25, 2021
a3a1ac6
Adding tests for the various iree_task_t types.
benvanik Jan 26, 2021
ea1422c
Temporarily disabling failing task system wait test.
benvanik Jan 26, 2021
be902d0
Fixing off-by-one in minilcg128.
benvanik Jan 26, 2021
381188a
Fixing scope name length truncation.
benvanik Jan 27, 2021
2a0f6a3
Fixing ubsan-flagged potential undefined shift right behavior.
benvanik Jan 27, 2021
55a3af4
Android build fixes for HAL rewrite branch. (#4622)
ScottTodd Jan 27, 2021
b82f588
Fixing ubsan discovery in topology tests on large machines.
benvanik Jan 28, 2021
e8162c6
Add missing device release in CTS.
benvanik Jan 28, 2021
9ee31d6
Disabling TaskWaitTest IssueSignaled for now.
benvanik Jan 28, 2021
d434fa9
Fixing shutdown race where scopes were deleted while going idle.
benvanik Jan 29, 2021
6de6fdf
Add fallbacks for 0 cpuinfo queries.
benvanik Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ endif()
# List of all HAL drivers to be built by default:
set(IREE_ALL_HAL_DRIVERS
DyLib
Metal
VMLA
Vulkan
)
Expand All @@ -126,9 +125,6 @@ if(IREE_HAL_DRIVERS_TO_BUILD STREQUAL "all")
# For Apple platforms we need to use Metal instead of Vulkan.
if(APPLE)
list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD Vulkan)
else()
# And Metal isn't available on non-Apple platforms for sure.
list(REMOVE_ITEM IREE_HAL_DRIVERS_TO_BUILD Metal)
endif()
endif()
message(STATUS "Building HAL drivers: ${IREE_HAL_DRIVERS_TO_BUILD}")
Expand Down
19 changes: 10 additions & 9 deletions bindings/python/pyiree/rt/function_abi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ void FunctionAbi::RawUnpack(absl::Span<const Description> descs,
throw RaiseValueError(
"Could not deref result buffer view (wrong type?)");
}
iree_hal_buffer* raw_buffer = iree_hal_buffer_view_buffer(buffer_view);
iree_hal_buffer_t* raw_buffer =
iree_hal_buffer_view_buffer(buffer_view);
if (!raw_buffer) {
throw RaiseValueError("Could not deref result buffer (wrong type?)");
}
Expand Down Expand Up @@ -675,10 +676,10 @@ void FunctionAbi::AllocateResults(absl::Span<const Description> descs,
kScalarTypeToHalElementType[static_cast<unsigned>(
desc.scalar.type)]);
iree_hal_buffer_view_t* buffer_view;
CheckApiStatus(iree_hal_buffer_view_create(
raw_buffer, dims.data(), dims.size(), element_type,
iree_allocator_system(), &buffer_view),
"Error allocating buffer_view");
CheckApiStatus(
iree_hal_buffer_view_create(raw_buffer, dims.data(), dims.size(),
element_type, &buffer_view),
"Error allocating buffer_view");
iree_hal_buffer_release(raw_buffer);
iree_vm_ref_t buffer_view_ref =
iree_hal_buffer_view_move_ref(buffer_view);
Expand Down Expand Up @@ -763,10 +764,10 @@ void FunctionAbi::PackBuffer(const RawSignatureParser::Description& desc,
absl::InlinedVector<int, 5> dims(py_view.ndim);
std::copy(py_view.shape, py_view.shape + py_view.ndim, dims.begin());
iree_hal_buffer_view_t* buffer_view;
CheckApiStatus(iree_hal_buffer_view_create(
raw_buffer, dims.data(), dims.size(), element_type,
iree_allocator_system(), &buffer_view),
"Error allocating buffer_view");
CheckApiStatus(
iree_hal_buffer_view_create(raw_buffer, dims.data(), dims.size(),
element_type, &buffer_view),
"Error allocating buffer_view");
iree_hal_buffer_release(raw_buffer);
iree_vm_ref_t buffer_view_ref = iree_hal_buffer_view_move_ref(buffer_view);
CheckApiStatus(iree_vm_list_push_ref_move(f_args.raw_ptr(), &buffer_view_ref),
Expand Down
17 changes: 7 additions & 10 deletions bindings/python/pyiree/rt/hal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ namespace {

class HalMappedMemory {
public:
HalMappedMemory(iree_hal_mapped_memory_t mapped_memory,
HalMappedMemory(iree_hal_buffer_mapping_t mapped_memory,
iree_hal_buffer_view_t* bv)
: mapped_memory_(mapped_memory), bv_(bv) {
iree_hal_buffer_view_retain(bv_);
}
~HalMappedMemory() {
if (bv_) {
iree_hal_buffer_t* buffer = iree_hal_buffer_view_buffer(bv_);
IREE_CHECK_OK(iree_hal_buffer_unmap(buffer, &mapped_memory_));
iree_hal_buffer_unmap_range(&mapped_memory_);
iree_hal_buffer_view_release(bv_);
}
}
Expand All @@ -44,10 +44,10 @@ class HalMappedMemory {
static HalMappedMemory Create(HalBufferView& bv) {
iree_hal_buffer_t* buffer = iree_hal_buffer_view_buffer(bv.raw_ptr());
iree_device_size_t byte_length = iree_hal_buffer_byte_length(buffer);
iree_hal_mapped_memory_t mapped_memory;
CheckApiStatus(iree_hal_buffer_map(buffer, IREE_HAL_MEMORY_ACCESS_READ,
0 /* element_offset */, byte_length,
&mapped_memory),
iree_hal_buffer_mapping_t mapped_memory;
CheckApiStatus(iree_hal_buffer_map_range(
buffer, IREE_HAL_MEMORY_ACCESS_READ,
0 /* element_offset */, byte_length, &mapped_memory),
"Could not map memory");
return HalMappedMemory(mapped_memory, bv.raw_ptr());
}
Expand Down Expand Up @@ -81,7 +81,7 @@ class HalMappedMemory {
}

private:
iree_hal_mapped_memory_t mapped_memory_;
iree_hal_buffer_mapping_t mapped_memory_;
iree_hal_buffer_view_t* bv_;
};

Expand Down Expand Up @@ -167,9 +167,6 @@ void SetupHalBindings(pybind11::module m) {
py::class_<HalMappedMemory>(m, "MappedMemory", py::buffer_protocol())
.def_buffer(&HalMappedMemory::ToBufferInfo);
py::class_<HalBuffer>(m, "HalBuffer")
.def_static("allocate_heap", &HalBuffer::AllocateHeapBuffer,
py::arg("memory_type"), py::arg("usage"),
py::arg("allocation_size"))
.def("fill_zero", &HalBuffer::FillZero, py::arg("byte_offset"),
py::arg("byte_length"))
.def("create_view", &HalBuffer::CreateView, py::arg("shape"),
Expand Down
14 changes: 1 addition & 13 deletions bindings/python/pyiree/rt/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,6 @@ class HalBufferView

class HalBuffer : public ApiRefCounted<HalBuffer, iree_hal_buffer_t> {
public:
static HalBuffer AllocateHeapBuffer(int32_t memory_type, int32_t usage,
iree_host_size_t allocation_size) {
iree_hal_buffer_t* buffer = nullptr;
CheckApiStatus(
iree_hal_heap_buffer_allocate(
static_cast<iree_hal_memory_type_t>(memory_type),
static_cast<iree_hal_buffer_usage_t>(usage), allocation_size,
iree_allocator_system(), iree_allocator_system(), &buffer),
"Error allocating heap buffer");
return HalBuffer::CreateRetained(buffer);
}

iree_device_size_t byte_length() const {
return iree_hal_buffer_byte_length(raw_ptr());
}
Expand All @@ -121,7 +109,7 @@ class HalBuffer : public ApiRefCounted<HalBuffer, iree_hal_buffer_t> {
IREE_HAL_ELEMENT_TYPE_NONE, element_size * 8);
CheckApiStatus(
iree_hal_buffer_view_create(raw_ptr(), shape.s.data(), shape.s.size(),
element_type, iree_allocator_system(), &bv),
element_type, &bv),
"Error creating buffer view");
return HalBufferView::CreateRetained(bv);
}
Expand Down
21 changes: 0 additions & 21 deletions bindings/python/pyiree/rt/hal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,6 @@ def testEnums(self):
logging.info("MemoryType: %s", rt.MemoryType)
logging.info("HOST_VISIBLE: %s", int(rt.MemoryType.HOST_VISIBLE))

def testAllocateHeap(self):
b = rt.HalBuffer.allocate_heap(memory_type=int(rt.MemoryType.HOST_LOCAL),
usage=int(rt.BufferUsage.ALL),
allocation_size=4096)
self.assertIsNot(b, None)
b.fill_zero(0, 4096)
shape = rt.Shape([1, 1024])
unused_bv = b.create_view(shape, 4)

def testStrideCalculation(self):
b = rt.HalBuffer.allocate_heap(memory_type=int(rt.MemoryType.HOST_LOCAL),
usage=int(rt.BufferUsage.ALL),
allocation_size=4096)
self.assertIsNot(b, None)
b.fill_zero(0, 4096)
shape = rt.Shape([16, 1, 8, 4, 2])
bv = b.create_view(shape, 4)
self.assertEqual(
np.array(bv.map()).strides,
(1 * 8 * 4 * 2 * 4, 8 * 4 * 2 * 4, 4 * 2 * 4, 2 * 4, 4))


if __name__ == "__main__":
absltest.main()
11 changes: 5 additions & 6 deletions bindings/python/pyiree/rt/host_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,14 @@ class PyMappedMemory {
}
};

PyMappedMemory(Description desc, iree_hal_mapped_memory_t mapped_memory,
PyMappedMemory(Description desc, iree_hal_buffer_mapping_t mapped_memory,
HalBuffer buffer)
: desc_(std::move(desc)),
mapped_memory_(mapped_memory),
buf_(std::move(buffer)) {}
~PyMappedMemory() {
if (buf_) {
CheckApiStatus(iree_hal_buffer_unmap(buf_.raw_ptr(), &mapped_memory_),
"Error unmapping memory");
iree_hal_buffer_unmap_range(&mapped_memory_);
}
}
PyMappedMemory(PyMappedMemory&& other)
Expand All @@ -139,8 +138,8 @@ class PyMappedMemory {
HalBuffer buffer) {
iree_device_size_t byte_length =
iree_hal_buffer_byte_length(buffer.raw_ptr());
iree_hal_mapped_memory_t mapped_memory;
CheckApiStatus(iree_hal_buffer_map(
iree_hal_buffer_mapping_t mapped_memory;
CheckApiStatus(iree_hal_buffer_map_range(
buffer.raw_ptr(), IREE_HAL_MEMORY_ACCESS_READ,
0 /* element_offset */, byte_length, &mapped_memory),
"Could not map memory");
Expand All @@ -160,7 +159,7 @@ class PyMappedMemory {

private:
Description desc_;
iree_hal_mapped_memory_t mapped_memory_;
iree_hal_buffer_mapping_t mapped_memory_;
HalBuffer buf_;
};

Expand Down
50 changes: 39 additions & 11 deletions build_tools/bazel/iree.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,54 @@ build:macos_clang --per_file_copt=tensorflow,iree_tf_compiler@-Wno-range-loop-an
# https://github.com/google/sanitizers/wiki/AddressSanitizer
###############################################################################

# Turn on asan. Some toolchains make use of the asan feature and we'll directly
# set the appropriate opts.
# ASAN (address sanitizer)
# https://clang.llvm.org/docs/AddressSanitizer.html
build:asan --config=sanitizer
build:asan --features=asan
build:asan --copt=-fsanitize=address
build:asan --copt=-fsanitize-address-use-after-scope
build:asan --linkopt=-fsanitize=address
build:asan --cc_output_directory_tag=asan
build:asan --copt=-DADDRESS_SANITIZER

# MSAN (memory sanitizer)
# https://clang.llvm.org/docs/MemorySanitizer.html
build:msan --config=sanitizer
build:msan --features=msan
build:msan --copt=-fsanitize=memory
build:msan --copt=-fsanitize-memory-track-origins
build:msan --linkopt=-fsanitize=memory
build:msan --cc_output_directory_tag=msan
build:msan --copt=-DMEMORY_SANITIZER

# TSAN (thread sanitizer)
# https://clang.llvm.org/docs/ThreadSanitizer.html
build:tsan --config=sanitizer
build:tsan --features=tsan
build:tsan --copt=-fsanitize=thread
build:tsan --linkopt=-fsanitize=thread
build:tsan --cc_output_directory_tag=tsan
build:tsan --copt=-DTHREAD_SANITIZER

# UBSAN (undefined behavior sanitizer)
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
build:ubsan --config=sanitizer
build:ubsan --features=ubsan
build:ubsan --copt=-fsanitize=undefined
build:ubsan --linkopt=-fsanitize=undefined
build:ubsan --linkopt=-lubsan
build:ubsan --cc_output_directory_tag=ubsan

# Don't strip debug info
build:asan --strip=never
build:sanitizer --strip=never
# Ignore settings of `linkopts = ["-static"]` which can screw up the sanitizer.
# We don't use this in IREE (that's what linkstatic is for), but it could show
# up in dependencies.
build:asan --force_ignore_dash_static
# asan tests tend to take longer, so increase the timeouts
build:asan --test_timeout=120,600,1800,-1
# Make the outputs easy to find
build:asan --cc_output_directory_tag=asan
build:sanitizer --force_ignore_dash_static
# sanitizer tests tend to take longer, so increase the timeouts
build:sanitizer --test_timeout=120,600,1800,-1
# Get better stack traces
build:asan --copt=-fno-omit-frame-pointer
# This macro define is used by absl
build:asan --copt=-DADDRESS_SANITIZER
build:sanitizer --copt=-fno-omit-frame-pointer

###############################################################################
# Architecture specific options
Expand Down
2 changes: 1 addition & 1 deletion build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@renderdoc_api//:renderdoc_app": ["renderdoc_api::renderdoc_app"],
"@pffft": ["pffft"],
"@cpuinfo//:cpuinfo": ["cpuinfo"],
"@half//:half": ["half"],
"@half//:includes": ["half::includes"],
"@vulkan_memory_allocator//:impl_header_only": ["vulkan_memory_allocator"],
}

Expand Down
4 changes: 2 additions & 2 deletions build_tools/cmake/iree_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ function(iree_add_test_environment_properties TEST_NAME)
#
# Tests which only depend on a compiler target backend or a runtime HAL
# driver, but not both, should generally use a different method of filtering.
if(NOT ${IREE_TARGET_BACKEND_VULKAN-SPIRV} OR NOT ${IREE_HAL_DRIVER_VULKAN})
if(NOT "${IREE_TARGET_BACKEND_VULKAN-SPIRV}" OR NOT "${IREE_HAL_DRIVER_VULKAN}")
set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "IREE_VULKAN_DISABLE=1")
endif()
if(NOT ${IREE_TARGET_BACKEND_DYLIB-LLVM-AOT} OR NOT ${IREE_HAL_DRIVER_DYLIB})
if(NOT "${IREE_TARGET_BACKEND_DYLIB-LLVM-AOT}" OR NOT "${IREE_HAL_DRIVER_DYLIB}")
set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "IREE_LLVMAOT_DISABLE=1")
endif()
endfunction()
Loading