From 075db0aa5b2d58cf6db2e85c76d195ef3a528f80 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Fri, 18 Dec 2020 14:12:41 -0800 Subject: [PATCH] Removing iree/hal/cts/ for now until it can be ported to C. Issue #3934 is tracking this. --- iree/hal/cts/BUILD | 108 -------- iree/hal/cts/CMakeLists.txt | 108 -------- iree/hal/cts/allocator_test.cc | 89 ------ iree/hal/cts/buffer_test.cc | 407 ---------------------------- iree/hal/cts/command_buffer_test.cc | 251 ----------------- iree/hal/cts/command_queue_test.cc | 158 ----------- iree/hal/cts/cts_test_base.h | 135 --------- iree/hal/cts/driver_test.cc | 46 ---- iree/hal/cts/semaphore_test.cc | 151 ----------- 9 files changed, 1453 deletions(-) delete mode 100644 iree/hal/cts/BUILD delete mode 100644 iree/hal/cts/CMakeLists.txt delete mode 100644 iree/hal/cts/allocator_test.cc delete mode 100644 iree/hal/cts/buffer_test.cc delete mode 100644 iree/hal/cts/command_buffer_test.cc delete mode 100644 iree/hal/cts/command_queue_test.cc delete mode 100644 iree/hal/cts/cts_test_base.h delete mode 100644 iree/hal/cts/driver_test.cc delete mode 100644 iree/hal/cts/semaphore_test.cc diff --git a/iree/hal/cts/BUILD b/iree/hal/cts/BUILD deleted file mode 100644 index babb000a448f..000000000000 --- a/iree/hal/cts/BUILD +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright 2019 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Conformance Test Suite (CTS) for HAL implementations. - -package( - default_visibility = ["//visibility:public"], - features = ["layering_check"], - licenses = ["notice"], # Apache 2.0 -) - -cc_library( - name = "cts_test_base", - testonly = True, - hdrs = ["cts_test_base.h"], - data = [ - # For AddressSanitizer when using Vulkan + a local Nvidia GPU - "//iree/tools:sanitizer_suppressions.txt", - ], - deps = [ - "//iree/base:status", - "//iree/hal", - "//iree/hal:api", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - ], -) - -cc_test( - name = "allocator_test", - srcs = ["allocator_test.cc"], - deps = [ - ":cts_test_base", - "//iree/base:status", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - "//iree/testing:gtest_main", - ], -) - -cc_test( - name = "buffer_test", - srcs = ["buffer_test.cc"], - deps = [ - ":cts_test_base", - "//iree/base:status", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - "//iree/testing:gtest_main", - ], -) - -cc_test( - name = "command_buffer_test", - srcs = ["command_buffer_test.cc"], - deps = [ - ":cts_test_base", - "//iree/base:status", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - "//iree/testing:gtest_main", - ], -) - -cc_test( - name = "command_queue_test", - srcs = ["command_queue_test.cc"], - deps = [ - ":cts_test_base", - "//iree/base:status", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - "//iree/testing:gtest_main", - ], -) - -cc_test( - name = "driver_test", - srcs = ["driver_test.cc"], - deps = [ - ":cts_test_base", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - "//iree/testing:gtest_main", - ], -) - -cc_test( - name = "semaphore_test", - srcs = ["semaphore_test.cc"], - deps = [ - ":cts_test_base", - "//iree/hal/testing:driver_registry", - "//iree/testing:gtest", - "//iree/testing:gtest_main", - ], -) diff --git a/iree/hal/cts/CMakeLists.txt b/iree/hal/cts/CMakeLists.txt deleted file mode 100644 index 3589b1b9d39a..000000000000 --- a/iree/hal/cts/CMakeLists.txt +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -iree_add_all_subdirs() - -iree_cc_library( - NAME - cts_test_base - HDRS - "cts_test_base.h" - DATA - iree::tools::sanitizer_suppressions.txt - DEPS - iree::base::status - iree::hal - iree::hal::api - iree::hal::testing::driver_registry - iree::testing::gtest - TESTONLY - PUBLIC -) - -iree_cc_test( - NAME - allocator_test - SRCS - "allocator_test.cc" - DEPS - ::cts_test_base - iree::base::status - iree::hal::testing::driver_registry - iree::testing::gtest - iree::testing::gtest_main -) - -iree_cc_test( - NAME - buffer_test - SRCS - "buffer_test.cc" - DEPS - ::cts_test_base - iree::base::status - iree::hal::testing::driver_registry - iree::testing::gtest - iree::testing::gtest_main -) - -iree_cc_test( - NAME - command_buffer_test - SRCS - "command_buffer_test.cc" - DEPS - ::cts_test_base - iree::base::status - iree::hal::testing::driver_registry - iree::testing::gtest - iree::testing::gtest_main -) - -iree_cc_test( - NAME - command_queue_test - SRCS - "command_queue_test.cc" - DEPS - ::cts_test_base - iree::base::status - iree::hal::testing::driver_registry - iree::testing::gtest - iree::testing::gtest_main -) - -iree_cc_test( - NAME - driver_test - SRCS - "driver_test.cc" - DEPS - ::cts_test_base - iree::hal::testing::driver_registry - iree::testing::gtest - iree::testing::gtest_main -) - -iree_cc_test( - NAME - semaphore_test - SRCS - "semaphore_test.cc" - DEPS - ::cts_test_base - iree::hal::testing::driver_registry - iree::testing::gtest - iree::testing::gtest_main -) diff --git a/iree/hal/cts/allocator_test.cc b/iree/hal/cts/allocator_test.cc deleted file mode 100644 index f1dded8be85b..000000000000 --- a/iree/hal/cts/allocator_test.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "iree/base/status.h" -#include "iree/hal/cts/cts_test_base.h" -#include "iree/hal/testing/driver_registry.h" -#include "iree/testing/gtest.h" -#include "iree/testing/status_matchers.h" - -namespace iree { -namespace hal { -namespace cts { - -class AllocatorTest : public CtsTestBase { - protected: - virtual void SetUp() { - CtsTestBase::SetUp(); - - if (!device_) { - return; - } - - allocator_ = device_->allocator(); - } - - Allocator* allocator_ = nullptr; -}; - -TEST_P(AllocatorTest, CanAllocate) { - EXPECT_TRUE(allocator_->CanAllocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_MAPPING, 1024)); - EXPECT_TRUE(allocator_->CanAllocate( - IREE_HAL_MEMORY_TYPE_HOST_VISIBLE | IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL, - IREE_HAL_BUFFER_USAGE_MAPPING, 1024)); - - // TODO(scotttodd): Minimum memory types and buffer usages necessary for use - // TODO(scotttodd): Test upper limits of memory size for allocations (1GB+)? -} - -TEST_P(AllocatorTest, Allocate) { - MemoryType memory_type = - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE; - iree_hal_buffer_usage_t usage = IREE_HAL_BUFFER_USAGE_MAPPING; - size_t allocation_size = 1024; - - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, allocator_->Allocate(memory_type, usage, allocation_size)); - - EXPECT_EQ(allocator_, buffer->allocator()); - // At a mimimum, the requested memory type should be respected. - // Additional bits may be optionally set depending on the allocator. - EXPECT_TRUE((buffer->memory_type() & memory_type) == memory_type); - EXPECT_TRUE((buffer->usage() & usage) == usage); - EXPECT_GE(buffer->allocation_size(), allocation_size); // Larger is okay. -} - -TEST_P(AllocatorTest, CanUseBufferLike) { - MemoryType memory_type = - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE; - iree_hal_buffer_usage_t usage = IREE_HAL_BUFFER_USAGE_MAPPING; - size_t allocation_size = 1024; - - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, allocator_->Allocate(memory_type, usage, allocation_size)); - // Using the buffer for its original requested purpose should be fine. - EXPECT_TRUE( - allocator_->CanUseBufferLike(allocator_, memory_type, usage, usage)); -} - -INSTANTIATE_TEST_SUITE_P( - AllDrivers, AllocatorTest, - ::testing::ValuesIn(testing::EnumerateAvailableDrivers()), - GenerateTestName()); - -} // namespace cts -} // namespace hal -} // namespace iree diff --git a/iree/hal/cts/buffer_test.cc b/iree/hal/cts/buffer_test.cc deleted file mode 100644 index cef7b9ba6252..000000000000 --- a/iree/hal/cts/buffer_test.cc +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "iree/base/status.h" -#include "iree/hal/cts/cts_test_base.h" -#include "iree/hal/testing/driver_registry.h" -#include "iree/testing/gtest.h" -#include "iree/testing/status_matchers.h" - -namespace iree { -namespace hal { -namespace cts { - -using ::testing::_; -using ::testing::ElementsAre; -using ::testing::Eq; - -// Note: this file only covers hal::Buffer APIs that can be overridden by -// subclasses. Errors caught by hal::Buffer's common validations are not -// covered as they are already tested in iree/hal/buffer_test.cc. - -class BufferTest : public CtsTestBase {}; - -TEST_P(BufferTest, Allocate) { - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 14)); - - EXPECT_NE(nullptr, buffer->allocator()); - EXPECT_EQ(IREE_HAL_MEMORY_ACCESS_ALL, buffer->allowed_access()); - EXPECT_EQ( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - buffer->memory_type()); - EXPECT_EQ(IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - buffer->usage()); - - EXPECT_LE(14, buffer->allocation_size()); - EXPECT_EQ(0, buffer->byte_offset()); - EXPECT_EQ(14, buffer->byte_length()); -} - -TEST_P(BufferTest, AllocateZeroLength) { - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 0)); - EXPECT_LE(0, buffer->allocation_size()); -} - -TEST_P(BufferTest, Fill8) { - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 5)); - - std::vector actual_data(buffer->allocation_size()); - - // Fill with a sentinel. - IREE_EXPECT_OK(buffer->Fill8(0, buffer->allocation_size(), 0x33u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x33, 0x33, 0x33, 0x33, 0x33)); - - // Zero fills are fine. - IREE_EXPECT_OK(buffer->Fill8(0, 0, 0x44u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x33, 0x33, 0x33, 0x33, 0x33)); - - // Fill the remaining parts of the buffer by using IREE_WHOLE_BUFFER. - IREE_EXPECT_OK(buffer->Fill8(2, IREE_WHOLE_BUFFER, 0x55u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x33, 0x33, 0x55, 0x55, 0x55)); - - // Fill a small region of the buffer. - IREE_EXPECT_OK(buffer->Fill8(1, 1, 0x66u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x33, 0x66, 0x55, 0x55, 0x55)); - - // Whole buffer helper. - IREE_EXPECT_OK(buffer->Fill8(0x99u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x99, 0x99, 0x99, 0x99, 0x99)); -} - -TEST_P(BufferTest, Fill16) { - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 9)); - - std::vector actual_data(buffer->allocation_size()); - - // Fill with a sentinel. - IREE_EXPECT_OK(buffer->Fill16(0, 4, 0x1122u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x22, 0x11, 0x22, 0x11, 0, 0, 0, 0, 0)); - - // Zero fills are fine. - IREE_EXPECT_OK(buffer->Fill16(0, 0, 0x5566u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0x22, 0x11, 0x22, 0x11, 0, 0, 0, 0, 0)); - - // Fill the remaining parts of the buffer by using IREE_WHOLE_BUFFER. - IREE_ASSERT_OK_AND_ASSIGN( - auto aligned_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 8)); - IREE_EXPECT_OK(aligned_buffer->Fill16(4, IREE_WHOLE_BUFFER, 0x5566u)); - std::vector aligned_actual_data(aligned_buffer->allocation_size()); - IREE_EXPECT_OK(aligned_buffer->ReadData(0, aligned_actual_data.data(), - aligned_actual_data.size())); - EXPECT_THAT(aligned_actual_data, - ElementsAre(0, 0, 0, 0, 0x66, 0x55, 0x66, 0x55)); - - // Whole buffer helper. - IREE_EXPECT_OK(aligned_buffer->Fill16(0x5566u)); - IREE_EXPECT_OK(aligned_buffer->ReadData(0, aligned_actual_data.data(), - aligned_actual_data.size())); - EXPECT_THAT(aligned_actual_data, - ElementsAre(0x66, 0x55, 0x66, 0x55, 0x66, 0x55, 0x66, 0x55)); -} - -TEST_P(BufferTest, Fill32) { - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 9)); - - std::vector actual_data(buffer->allocation_size()); - - // Fill with a sentinel. - IREE_EXPECT_OK(buffer->Fill32(0, 8, 0x11223344u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, - ElementsAre(0x44, 0x33, 0x22, 0x11, 0x44, 0x33, 0x22, 0x11, 0)); - - // Zero fills are fine. - IREE_EXPECT_OK(buffer->Fill32(0, 0, 0x55667788u)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, - ElementsAre(0x44, 0x33, 0x22, 0x11, 0x44, 0x33, 0x22, 0x11, 0)); - - // Fill the remaining parts of the buffer by using IREE_WHOLE_BUFFER. - IREE_ASSERT_OK_AND_ASSIGN( - auto aligned_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 8)); - IREE_EXPECT_OK(aligned_buffer->Fill32(4, IREE_WHOLE_BUFFER, 0x55667788u)); - std::vector aligned_actual_data(aligned_buffer->allocation_size()); - IREE_EXPECT_OK(aligned_buffer->ReadData(0, aligned_actual_data.data(), - aligned_actual_data.size())); - EXPECT_THAT(aligned_actual_data, - ElementsAre(0, 0, 0, 0, 0x88, 0x77, 0x66, 0x55)); - - // Whole buffer helper. - IREE_EXPECT_OK(aligned_buffer->Fill32(0x55667788u)); - IREE_EXPECT_OK(aligned_buffer->ReadData(0, aligned_actual_data.data(), - aligned_actual_data.size())); - EXPECT_THAT(aligned_actual_data, - ElementsAre(0x88, 0x77, 0x66, 0x55, 0x88, 0x77, 0x66, 0x55)); -} - -TEST_P(BufferTest, ReadWriteData) { - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, 4)); - - std::vector actual_data(4); - - // Write over the entire buffer. - std::vector new_data = {10, 20, 30, 40}; - IREE_EXPECT_OK(buffer->WriteData(0, new_data.data(), new_data.size())); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, Eq(new_data)); - - // Writing zero bytes is valid. - std::vector zero_data; - IREE_EXPECT_OK(buffer->WriteData(0, zero_data.data(), 0)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, Eq(new_data)); - - // Write over a portion of the buffer. - std::vector partial_data = {99}; - IREE_EXPECT_OK( - buffer->WriteData(1, partial_data.data(), partial_data.size())); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(10, 99, 30, 40)); -} - -TEST_P(BufferTest, CopyData) { - std::vector src_data = {0, 1, 2, 3}; - IREE_ASSERT_OK_AND_ASSIGN( - auto src_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - src_data.size())); - IREE_EXPECT_OK(src_buffer->WriteData(0, src_data.data(), src_data.size())); - - std::vector dst_data = {0, 1, 2, 3, 4}; - IREE_ASSERT_OK_AND_ASSIGN( - auto dst_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - dst_data.size())); - IREE_EXPECT_OK(dst_buffer->WriteData(0, dst_data.data(), dst_data.size())); - - // Copy of length 0 should not change the dest buffer. - IREE_EXPECT_OK(dst_buffer->CopyData(0, src_buffer.get(), 0, 0)); - std::vector actual_data(dst_data.size()); - IREE_EXPECT_OK( - dst_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, Eq(dst_data)); - - // Copy a subrange of the buffer. - IREE_EXPECT_OK(dst_buffer->CopyData(1, src_buffer.get(), 2, 2)); - IREE_EXPECT_OK( - dst_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0, 2, 3, 3, 4)); - - // Copy the entire buffer using IREE_WHOLE_BUFFER. This will adjust sizes - // to ensure that the min buffer is taken. We test both src and dst buffer - // offset/length calculations (note that some may end up as 0 copies). - IREE_EXPECT_OK( - dst_buffer->CopyData(3, src_buffer.get(), 0, IREE_WHOLE_BUFFER)); - IREE_EXPECT_OK( - dst_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0, 2, 3, 0, 1)); - IREE_EXPECT_OK( - dst_buffer->CopyData(0, src_buffer.get(), 2, IREE_WHOLE_BUFFER)); - IREE_EXPECT_OK( - dst_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(2, 3, 3, 0, 1)); - IREE_EXPECT_OK( - dst_buffer->CopyData(0, src_buffer.get(), 3, IREE_WHOLE_BUFFER)); - IREE_EXPECT_OK( - dst_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(3, 3, 3, 0, 1)); - IREE_EXPECT_OK( - dst_buffer->CopyData(4, src_buffer.get(), 0, IREE_WHOLE_BUFFER)); - IREE_EXPECT_OK( - dst_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(3, 3, 3, 0, 0)); -} - -TEST_P(BufferTest, MapMemory) { - std::vector src_data = {0, 1, 2, 3, 4, 5, 6}; - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - src_data.size())); - IREE_EXPECT_OK(buffer->WriteData(0, src_data.data(), src_data.size())); - - // 0-length mappings are valid. - IREE_ASSERT_OK_AND_ASSIGN( - auto mapping, - buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ, 0, 0)); - EXPECT_TRUE(mapping.empty()); - EXPECT_EQ(0, mapping.size()); - EXPECT_EQ(0, mapping.byte_length()); - EXPECT_NE(nullptr, mapping.data()); - IREE_ASSERT_OK_AND_ASSIGN(auto span, mapping.Subspan()); - EXPECT_TRUE(span.empty()); - mapping.reset(); - - // Map the whole buffer for reading. - IREE_ASSERT_OK_AND_ASSIGN( - mapping, buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ, 0, - IREE_WHOLE_BUFFER)); - EXPECT_EQ(src_data.size(), mapping.size()); - IREE_ASSERT_OK_AND_ASSIGN(span, mapping.Subspan()); - EXPECT_THAT(span, ElementsAre(0, 1, 2, 3, 4, 5, 6)); - mapping.reset(); - - // Map a portion of the buffer for reading. - IREE_ASSERT_OK_AND_ASSIGN( - mapping, buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ, 1, 2)); - EXPECT_EQ(2, mapping.size()); - IREE_ASSERT_OK_AND_ASSIGN(span, mapping.Subspan()); - EXPECT_THAT(span, ElementsAre(1, 2)); - mapping.reset(); -} - -TEST_P(BufferTest, MapMemoryNonByte) { - std::vector src_data = {0, 1, 2, 3, 4, 5, 6}; - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - src_data.size())); - IREE_EXPECT_OK(buffer->WriteData(0, src_data.data(), src_data.size())); - - // Map the buffer as non-byte values. - // Note that we'll round down to the number of valid elements at the - // alignment. - IREE_ASSERT_OK_AND_ASSIGN( - auto mapping16, buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ)); - EXPECT_EQ(3, mapping16.size()); - EXPECT_LE(6, mapping16.byte_length()); - IREE_ASSERT_OK_AND_ASSIGN(auto span16, mapping16.Subspan()); - EXPECT_THAT(span16, ElementsAre(0x0100, 0x0302, 0x0504)); - mapping16.reset(); -} - -TEST_P(BufferTest, MapMemoryWrite) { - std::vector src_data = {0, 1, 2, 3, 4, 5, 6}; - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - src_data.size())); - IREE_EXPECT_OK(buffer->WriteData(0, src_data.data(), src_data.size())); - - // Map and modify the data. We should see it when we read back. - IREE_ASSERT_OK_AND_ASSIGN( - auto mapping, - buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_WRITE, 1, 2)); - auto mutable_data = mapping.mutable_data(); - mutable_data[0] = 0xAA; - mutable_data[1] = 0xBB; - mapping.reset(); - std::vector actual_data(src_data.size()); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0, 0xAA, 0xBB, 3, 4, 5, 6)); -} - -TEST_P(BufferTest, MapMemoryDiscard) { - std::vector src_data = {0, 1, 2, 3, 4, 5, 6}; - IREE_ASSERT_OK_AND_ASSIGN( - auto buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - src_data.size())); - IREE_EXPECT_OK(buffer->WriteData(0, src_data.data(), src_data.size())); - - // Map for discard. Note that we can't really rely on the value of the data - // so we just trust that it's been discarded. It's a hint, anyway. We can be - // sure that the data we didn't want to discard is the same though. - std::vector actual_data(src_data.size()); - IREE_ASSERT_OK_AND_ASSIGN( - auto mapping, - buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_DISCARD_WRITE, 1, 2)); - IREE_EXPECT_OK(buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0, _, _, 3, 4, 5, 6)); - mapping.reset(); -} - -TEST_P(BufferTest, MapMemorySubspan) { - std::vector src_data = {0, 1, 2, 3, 4, 5, 6}; - IREE_ASSERT_OK_AND_ASSIGN( - auto parent_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - src_data.size())); - IREE_EXPECT_OK(parent_buffer->WriteData(0, src_data.data(), src_data.size())); - - IREE_ASSERT_OK_AND_ASSIGN(auto subspan_buffer, - Buffer::Subspan(parent_buffer, 1, 3)); - IREE_ASSERT_OK_AND_ASSIGN(auto mapping, - subspan_buffer->MapMemory( - IREE_HAL_MEMORY_ACCESS_DISCARD_WRITE, 1, 2)); - auto* mutable_data = mapping.mutable_data(); - mutable_data[0] = 0xCC; - mutable_data[1] = 0xDD; - mapping.reset(); - - std::vector actual_data(src_data.size()); - IREE_EXPECT_OK( - parent_buffer->ReadData(0, actual_data.data(), actual_data.size())); - EXPECT_THAT(actual_data, ElementsAre(0, 1, 0xCC, 0xDD, 4, 5, 6)); -} - -INSTANTIATE_TEST_SUITE_P( - AllDrivers, BufferTest, - ::testing::ValuesIn(testing::EnumerateAvailableDrivers()), - GenerateTestName()); - -} // namespace cts -} // namespace hal -} // namespace iree diff --git a/iree/hal/cts/command_buffer_test.cc b/iree/hal/cts/command_buffer_test.cc deleted file mode 100644 index 89e8fec30106..000000000000 --- a/iree/hal/cts/command_buffer_test.cc +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "iree/base/status.h" -#include "iree/hal/cts/cts_test_base.h" -#include "iree/hal/testing/driver_registry.h" -#include "iree/testing/gtest.h" -#include "iree/testing/status_matchers.h" - -namespace iree { -namespace hal { -namespace cts { - -using ::testing::ContainerEq; - -class CommandBufferTest : public CtsTestBase { - protected: - static constexpr iree_device_size_t kBufferNumBytes = 16; - - void SubmitAndWait(CommandQueue* command_queue, - CommandBuffer* command_buffer) { - IREE_ASSERT_OK_AND_ASSIGN(auto signal_semaphore, - device_->CreateSemaphore(0ull)); - - IREE_ASSERT_OK(command_queue->Submit( - {{}, {command_buffer}, {{signal_semaphore.get(), 1ull}}})); - IREE_ASSERT_OK(signal_semaphore->Wait(1ull, InfiniteFuture())); - } -}; - -TEST_P(CommandBufferTest, Create) { - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_DISPATCH)); - - EXPECT_TRUE( - (command_buffer->mode() & IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT) == - IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT); - EXPECT_TRUE((command_buffer->command_categories() & - IREE_HAL_COMMAND_CATEGORY_DISPATCH) == - IREE_HAL_COMMAND_CATEGORY_DISPATCH); - EXPECT_FALSE(command_buffer->is_recording()); -} - -TEST_P(CommandBufferTest, BeginEnd) { - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_DISPATCH)); - - EXPECT_FALSE(command_buffer->is_recording()); - IREE_EXPECT_OK(command_buffer->Begin()); - EXPECT_TRUE(command_buffer->is_recording()); - IREE_EXPECT_OK(command_buffer->End()); - EXPECT_FALSE(command_buffer->is_recording()); -} - -TEST_P(CommandBufferTest, FillBufferWithRepeatedBytes) { - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_TRANSFER)); - - IREE_ASSERT_OK_AND_ASSIGN( - auto device_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL | IREE_HAL_MEMORY_TYPE_HOST_VISIBLE, - IREE_HAL_BUFFER_USAGE_ALL, kBufferNumBytes)); - - std::vector reference_buffer(kBufferNumBytes); - - IREE_EXPECT_OK(command_buffer->Begin()); - - // Fill the device buffer with segments of different values so that we can - // test both fill and offset/size. - - uint8_t val1 = 0x07; - IREE_EXPECT_OK(command_buffer->FillBuffer(device_buffer.get(), - /*target_offset=*/0, - /*length=*/kBufferNumBytes / 4, - &val1, - /*pattern_length=*/1)); - std::memset(reference_buffer.data(), val1, kBufferNumBytes / 4); - - uint8_t val2 = 0xbe; - IREE_EXPECT_OK( - command_buffer->FillBuffer(device_buffer.get(), - /*target_offset=*/kBufferNumBytes / 4, - /*length=*/kBufferNumBytes / 4, &val2, - /*pattern_length=*/1)); - std::memset(reference_buffer.data() + kBufferNumBytes / 4, val2, - kBufferNumBytes / 4); - - uint8_t val3 = 0x54; - IREE_EXPECT_OK( - command_buffer->FillBuffer(device_buffer.get(), - /*target_offset=*/kBufferNumBytes / 2, - /*length=*/kBufferNumBytes / 2, &val3, - /*pattern_length=*/1)); - std::memset(reference_buffer.data() + kBufferNumBytes / 2, val3, - kBufferNumBytes / 2); - - IREE_EXPECT_OK(command_buffer->End()); - - SubmitAndWait(device_->transfer_queues()[0], command_buffer.get()); - - // Read back the device buffer. - IREE_ASSERT_OK_AND_ASSIGN( - auto mapped_memory, - device_buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ)); - IREE_EXPECT_OK(mapped_memory.Invalidate()); - - std::vector actual_data(mapped_memory.data(), - mapped_memory.data() + kBufferNumBytes); - EXPECT_THAT(actual_data, ContainerEq(reference_buffer)); -} - -TEST_P(CommandBufferTest, CopyWholeBuffer) { - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_TRANSFER)); - - // Create a host buffer. - IREE_ASSERT_OK_AND_ASSIGN( - auto host_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_VISIBLE | IREE_HAL_MEMORY_TYPE_HOST_CACHED | - IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_ALL, kBufferNumBytes)); - - // Fill the host buffer. - uint8_t i8_val = 0x55; - IREE_EXPECT_OK(host_buffer->Fill8(0, IREE_WHOLE_BUFFER, i8_val)); - IREE_ASSERT_OK_AND_ASSIGN( - auto host_mapped_memory, - // Cannot use kDiscard here given we filled in the above. - host_buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_WRITE)); - IREE_EXPECT_OK(host_mapped_memory.Flush()); - - std::vector reference_buffer(kBufferNumBytes); - std::memset(reference_buffer.data(), i8_val, kBufferNumBytes); - - // Create a device buffer. - IREE_ASSERT_OK_AND_ASSIGN( - auto device_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL | IREE_HAL_MEMORY_TYPE_HOST_VISIBLE, - IREE_HAL_BUFFER_USAGE_ALL, kBufferNumBytes)); - - // Copy the host buffer to the device buffer. - IREE_EXPECT_OK(command_buffer->Begin()); - IREE_EXPECT_OK( - command_buffer->CopyBuffer(host_buffer.get(), /*source_offset=*/0, - device_buffer.get(), /*target_offset=*/0, - /*length=*/kBufferNumBytes)); - IREE_EXPECT_OK(command_buffer->End()); - - SubmitAndWait(device_->transfer_queues()[0], command_buffer.get()); - - // Read back the device buffer. - IREE_ASSERT_OK_AND_ASSIGN( - auto device_mapped_memory, - device_buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ)); - IREE_EXPECT_OK(device_mapped_memory.Invalidate()); - - std::vector actual_data( - device_mapped_memory.data(), - device_mapped_memory.data() + kBufferNumBytes); - EXPECT_THAT(actual_data, ContainerEq(reference_buffer)); -} - -TEST_P(CommandBufferTest, CopySubBuffer) { - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_TRANSFER)); - // Create a device buffer. - IREE_ASSERT_OK_AND_ASSIGN( - auto device_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_DEVICE_LOCAL | IREE_HAL_MEMORY_TYPE_HOST_VISIBLE, - IREE_HAL_BUFFER_USAGE_ALL, kBufferNumBytes)); - - // Create another host buffer with a smaller size. - IREE_ASSERT_OK_AND_ASSIGN( - auto host_buffer, - device_->allocator()->Allocate( - IREE_HAL_MEMORY_TYPE_HOST_VISIBLE | IREE_HAL_MEMORY_TYPE_HOST_CACHED | - IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - IREE_HAL_BUFFER_USAGE_ALL, kBufferNumBytes / 2)); - - // Fill the host buffer. - uint8_t i8_val = 0x88; - IREE_EXPECT_OK(host_buffer->Fill8(0, IREE_WHOLE_BUFFER, i8_val)); - IREE_ASSERT_OK_AND_ASSIGN( - auto host_mapped_memory, - // Cannot use kDiscard here given we filled in the above. - host_buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_WRITE)); - IREE_EXPECT_OK(host_mapped_memory.Flush()); - - std::vector reference_buffer(kBufferNumBytes); - std::memset(reference_buffer.data() + 8, i8_val, kBufferNumBytes / 2 - 4); - - // Copy the host buffer to the device buffer. - IREE_EXPECT_OK(command_buffer->Begin()); - IREE_EXPECT_OK( - command_buffer->CopyBuffer(host_buffer.get(), /*source_offset=*/4, - device_buffer.get(), /*target_offset=*/8, - /*length=*/kBufferNumBytes / 2 - 4)); - IREE_EXPECT_OK(command_buffer->End()); - - SubmitAndWait(device_->transfer_queues()[0], command_buffer.get()); - - // Read back the device buffer. - IREE_ASSERT_OK_AND_ASSIGN( - auto device_mapped_memory, - device_buffer->MapMemory(IREE_HAL_MEMORY_ACCESS_READ)); - IREE_EXPECT_OK(device_mapped_memory.Invalidate()); - - std::vector actual_data( - device_mapped_memory.data(), - device_mapped_memory.data() + kBufferNumBytes); - EXPECT_THAT(actual_data, ContainerEq(reference_buffer)); -} - -// TODO(scotttodd): UpdateBuffer, Dispatch, Sync, etc. - -INSTANTIATE_TEST_SUITE_P( - AllDrivers, CommandBufferTest, - ::testing::ValuesIn(testing::EnumerateAvailableDrivers()), - GenerateTestName()); - -} // namespace cts -} // namespace hal -} // namespace iree diff --git a/iree/hal/cts/command_queue_test.cc b/iree/hal/cts/command_queue_test.cc deleted file mode 100644 index c774323ca447..000000000000 --- a/iree/hal/cts/command_queue_test.cc +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "iree/base/status.h" -#include "iree/hal/cts/cts_test_base.h" -#include "iree/hal/testing/driver_registry.h" -#include "iree/testing/gtest.h" -#include "iree/testing/status_matchers.h" - -namespace iree { -namespace hal { -namespace cts { -namespace { - -using ::iree::testing::status::IsOkAndHolds; -using ::testing::Eq; - -class CommandQueueTest : public CtsTestBase {}; - -TEST_P(CommandQueueTest, EnumerateDeviceQueues) { - // Log how many queues we have so future test cases have more context. - // Most tests just use the first queue, but supporting multiple queues may be - // relevant on some implementations. - - absl::Span dispatch_queues = device_->dispatch_queues(); - IREE_LOG(INFO) << "Device has " << dispatch_queues.size() - << " dispatch queue(s)"; - EXPECT_GE(dispatch_queues.size(), 1); - for (auto* dispatch_queue : dispatch_queues) { - EXPECT_TRUE(dispatch_queue->can_dispatch()); - } - - absl::Span transfer_queues = device_->transfer_queues(); - IREE_LOG(INFO) << "Device has " << transfer_queues.size() - << " transfer queue(s)"; - EXPECT_GE(transfer_queues.size(), 1); - for (auto* transfer_queue : transfer_queues) { - EXPECT_TRUE(transfer_queue->can_transfer()); - } -} - -// Tests that waiting for idle is a no-op when nothing is queued. -TEST_P(CommandQueueTest, WaitIdleWhileIdle) { - for (auto* dispatch_queue : device_->dispatch_queues()) { - IREE_EXPECT_OK(dispatch_queue->WaitIdle()); - } - for (auto* transfer_queue : device_->transfer_queues()) { - IREE_EXPECT_OK(transfer_queue->WaitIdle()); - } -} - -// Tests that submitting a command buffer and immediately waiting will not -// deadlock. -// Note: this test never completes with Vulkan timeline semaphore emulation. -TEST_P(CommandQueueTest, BlockingSubmit) { - auto command_queue = device_->dispatch_queues()[0]; - - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_DISPATCH)); - IREE_ASSERT_OK_AND_ASSIGN(auto semaphore, device_->CreateSemaphore(0ull)); - - IREE_ASSERT_OK(command_queue->Submit( - {{}, {command_buffer.get()}, {{semaphore.get(), 1ull}}})); - IREE_ASSERT_OK(semaphore->Wait(1ull, InfiniteFuture())); -} - -// Tests waiting while work is pending/in-flight. -// Note: this test never completes with Vulkan timeline semaphore emulation. -TEST_P(CommandQueueTest, WaitTimeout) { - auto command_queue = device_->dispatch_queues()[0]; - - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_DISPATCH)); - IREE_ASSERT_OK_AND_ASSIGN(auto wait_semaphore, - device_->CreateSemaphore(0ull)); - IREE_ASSERT_OK_AND_ASSIGN(auto signal_semaphore, - device_->CreateSemaphore(0ull)); - - IREE_ASSERT_OK(command_queue->Submit({{{wait_semaphore.get(), 1ull}}, - {command_buffer.get()}, - {{signal_semaphore.get(), 1ull}}})); - - // Work shouldn't start until the wait semaphore reaches its payload value. - EXPECT_THAT(signal_semaphore->Query(), IsOkAndHolds(Eq(0ull))); - EXPECT_TRUE(IsDeadlineExceeded(command_queue->WaitIdle(Milliseconds(100)))); - - // Signal the wait semaphore, work should begin and complete. - IREE_ASSERT_OK(wait_semaphore->Signal(1ull)); - IREE_ASSERT_OK(signal_semaphore->Wait(1ull, InfiniteFuture())); -} - -// Tests using multiple wait and signal semaphores. -TEST_P(CommandQueueTest, WaitMultiple) { - auto command_queue = device_->dispatch_queues()[0]; - - IREE_ASSERT_OK_AND_ASSIGN( - auto command_buffer, - device_->CreateCommandBuffer(IREE_HAL_COMMAND_BUFFER_MODE_ONE_SHOT, - IREE_HAL_COMMAND_CATEGORY_DISPATCH)); - IREE_ASSERT_OK_AND_ASSIGN(auto wait_semaphore_1, - device_->CreateSemaphore(0ull)); - IREE_ASSERT_OK_AND_ASSIGN(auto wait_semaphore_2, - device_->CreateSemaphore(0ull)); - IREE_ASSERT_OK_AND_ASSIGN(auto signal_semaphore_1, - device_->CreateSemaphore(0ull)); - IREE_ASSERT_OK_AND_ASSIGN(auto signal_semaphore_2, - device_->CreateSemaphore(0ull)); - - IREE_ASSERT_OK(command_queue->Submit( - {{{wait_semaphore_1.get(), 1ull}, {wait_semaphore_2.get(), 1ull}}, - {command_buffer.get()}, - {{signal_semaphore_1.get(), 1ull}, {signal_semaphore_2.get(), 1ull}}})); - - // Work shouldn't start until the wait semaphore reaches its payload value. - EXPECT_THAT(signal_semaphore_1->Query(), IsOkAndHolds(Eq(0ull))); - EXPECT_THAT(signal_semaphore_2->Query(), IsOkAndHolds(Eq(0ull))); - // Note: This fails with Vulkan timeline semaphore emulation (returns OK) - EXPECT_TRUE(IsDeadlineExceeded(command_queue->WaitIdle(Milliseconds(100)))); - - // Signal the wait semaphores, work should only begin after each is set. - IREE_ASSERT_OK(wait_semaphore_1->Signal(1ull)); - EXPECT_THAT(signal_semaphore_1->Query(), IsOkAndHolds(Eq(0ull))); - EXPECT_THAT(signal_semaphore_2->Query(), IsOkAndHolds(Eq(0ull))); - IREE_ASSERT_OK(wait_semaphore_2->Signal(1ull)); - - IREE_ASSERT_OK(command_queue->WaitIdle()); -} - -INSTANTIATE_TEST_SUITE_P( - AllDrivers, CommandQueueTest, - ::testing::ValuesIn( - // Disabled on Vulkan until tests pass with - // timeline semaphore emulation. - testing::RemoveDriverByName(testing::EnumerateAvailableDrivers(), - "vulkan")), - GenerateTestName()); - -} // namespace -} // namespace cts -} // namespace hal -} // namespace iree diff --git a/iree/hal/cts/cts_test_base.h b/iree/hal/cts/cts_test_base.h deleted file mode 100644 index 1aa33c3149cf..000000000000 --- a/iree/hal/cts/cts_test_base.h +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef IREE_HAL_CTS_CTS_TEST_BASE_H_ -#define IREE_HAL_CTS_CTS_TEST_BASE_H_ - -#include -#include -#include - -#include "iree/base/status.h" -#include "iree/hal/api.h" -#include "iree/testing/gtest.h" -#include "iree/testing/status_matchers.h" - -// TODO(3934): rebase this all on the C API. -#include "iree/hal/driver.h" - -namespace iree { -namespace hal { -namespace cts { - -// Common setup for tests parameterized across all registered drivers. -class CtsTestBase : public ::testing::TestWithParam { - protected: - // Per-test-suite set-up. This is called before the first test in this test - // suite. We use it to set up drivers that must be reused between test cases - // to work around issues with driver lifetimes (specifically SwiftShader for - // Vulkan). - // - // TODO(#3933): this is a very nasty hack that indicates a serious issue. If - // we have to do it here in our test suite it means that every user of IREE - // will also have to do something like it. We should be reusing all drivers - // across tests in a suite (removing the vulkan-specific behavior here) but - // ALSO need a test that tries to create a driver twice. - static void SetUpTestSuite() { - iree_hal_driver_t* driver = NULL; - iree_status_t status = iree_hal_driver_registry_try_create_by_name( - iree_hal_driver_registry_default(), iree_make_cstring_view("vulkan"), - iree_allocator_system(), &driver); - if (iree_status_consume_code(status) == IREE_STATUS_OK) { - shared_drivers_["vulkan"] = - assign_ref(reinterpret_cast(driver)); - } - } - - // Per-test-suite tear-down. This is called after the last test in this test - // suite. We use it to destruct driver handles before program exit. This - // avoids us to rely on static object destruction happening after main(). It - // can cause unexpected problems when the driver also want to perform clean up - // at that time. - static void TearDownTestSuite() { shared_drivers_.clear(); } - - static std::map> shared_drivers_; - - virtual void SetUp() { - const std::string& driver_name = GetParam(); - - // Get driver with the given name and create its default device. - // Skip drivers that are (gracefully) unavailable, fail if creation fails. - auto driver_or = GetDriver(driver_name); - if (IsUnavailable(driver_or.status())) { - IREE_LOG(WARNING) << "Skipping test as driver is unavailable: " - << driver_or.status(); - GTEST_SKIP(); - return; - } - IREE_ASSERT_OK_AND_ASSIGN(driver_, std::move(driver_or)); - IREE_LOG(INFO) << "Creating default device..."; - IREE_ASSERT_OK_AND_ASSIGN(device_, driver_->CreateDefaultDevice()); - IREE_LOG(INFO) << "Created device '" << device_->info().name() << "'"; - } - - ref_ptr driver_; - ref_ptr device_; - - private: - // Gets a HAL driver with the provided name, if available. - static StatusOr> GetDriver(const std::string& driver_name) { - static std::set unavailable_driver_names; - - // If creation failed before, don't try again. - if (unavailable_driver_names.find(driver_name) != - unavailable_driver_names.end()) { - return UnavailableErrorBuilder(IREE_LOC) << "Driver unavailable"; - } - - // Reuse an existing driver if possible. - auto found_it = shared_drivers_.find(driver_name); - if (found_it != shared_drivers_.end()) { - IREE_LOG(INFO) << "Reusing existing driver '" << driver_name << "'..."; - return add_ref(found_it->second); - } - - // No existing driver, attempt to create. - IREE_LOG(INFO) << "Creating driver '" << driver_name << "'..."; - iree_hal_driver_t* driver = NULL; - iree_status_t status = iree_hal_driver_registry_try_create_by_name( - iree_hal_driver_registry_default(), - iree_make_string_view(driver_name.data(), driver_name.size()), - iree_allocator_system(), &driver); - if (iree_status_is_unavailable(status)) { - unavailable_driver_names.insert(driver_name); - } - IREE_RETURN_IF_ERROR(status); - return assign_ref(reinterpret_cast(driver)); - } -}; - -std::map> CtsTestBase::shared_drivers_; - -struct GenerateTestName { - template - std::string operator()( - const ::testing::TestParamInfo& info) const { - return info.param; - } -}; - -} // namespace cts -} // namespace hal -} // namespace iree - -#endif // IREE_HAL_CTS_CTS_TEST_BASE_H_ diff --git a/iree/hal/cts/driver_test.cc b/iree/hal/cts/driver_test.cc deleted file mode 100644 index 3a7b757eaa9b..000000000000 --- a/iree/hal/cts/driver_test.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "iree/hal/cts/cts_test_base.h" -#include "iree/hal/testing/driver_registry.h" -#include "iree/testing/gtest.h" -#include "iree/testing/status_matchers.h" - -namespace iree { -namespace hal { -namespace cts { - -class DriverTest : public CtsTestBase {}; - -TEST_P(DriverTest, CreateDefaultDevice) { - IREE_LOG(INFO) << "Device details:\n" << device_->DebugString(); -} - -TEST_P(DriverTest, EnumerateAndCreateAvailableDevices) { - IREE_ASSERT_OK_AND_ASSIGN(auto devices, driver_->EnumerateAvailableDevices()); - - for (iree_host_size_t i = 0; i < devices.size(); ++i) { - IREE_ASSERT_OK_AND_ASSIGN(auto device, driver_->CreateDevice(devices[i])); - IREE_LOG(INFO) << "Device #" << i << " details:\n" << device->DebugString(); - } -} - -INSTANTIATE_TEST_SUITE_P( - AllDrivers, DriverTest, - ::testing::ValuesIn(testing::EnumerateAvailableDrivers()), - GenerateTestName()); - -} // namespace cts -} // namespace hal -} // namespace iree diff --git a/iree/hal/cts/semaphore_test.cc b/iree/hal/cts/semaphore_test.cc deleted file mode 100644 index 385590c56a38..000000000000 --- a/iree/hal/cts/semaphore_test.cc +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "iree/hal/cts/cts_test_base.h" -#include "iree/hal/testing/driver_registry.h" -#include "iree/testing/gtest.h" - -namespace iree { -namespace hal { -namespace cts { - -class SemaphoreTest : public CtsTestBase {}; - -// Tests that a semaphore that is unused properly cleans itself up. -TEST_P(SemaphoreTest, NoOp) { - IREE_ASSERT_OK_AND_ASSIGN(auto semaphore, device_->CreateSemaphore(123u)); - IREE_ASSERT_OK_AND_ASSIGN(uint64_t value, semaphore->Query()); - EXPECT_EQ(123u, value); -} - -// Tests that a semaphore will accept new values as it is signaled. -TEST_P(SemaphoreTest, NormalSignaling) { - IREE_ASSERT_OK_AND_ASSIGN(auto semaphore, device_->CreateSemaphore(2u)); - EXPECT_EQ(2u, semaphore->Query().value()); - IREE_EXPECT_OK(semaphore->Signal(3u)); - EXPECT_EQ(3u, semaphore->Query().value()); - IREE_EXPECT_OK(semaphore->Signal(40u)); - EXPECT_EQ(40u, semaphore->Query().value()); -} - -// Note: Behavior is undefined when signaling with decreasing values, so we -// can't reliably test it across backends. Some backends may return errors, -// while others may accept the new, decreasing, values. - -// Tests that a semaphore that has failed will remain in a failed state. -TEST_P(SemaphoreTest, Failure) { - IREE_ASSERT_OK_AND_ASSIGN(auto semaphore, device_->CreateSemaphore(2u)); - // Signal to 3. - IREE_EXPECT_OK(semaphore->Signal(3u)); - EXPECT_EQ(3u, semaphore->Query().value()); - - // Fail now. - semaphore->Fail(UnknownErrorBuilder(IREE_LOC)); - EXPECT_TRUE(IsUnknown(semaphore->Query().status())); - - // Signaling again is undefined behavior. Some backends may return a - // sticky failure status while others may silently process new signal values. -} - -// Tests waiting on no semaphores. -TEST_P(SemaphoreTest, EmptyWait) { - IREE_EXPECT_OK(device_->WaitAllSemaphores({}, InfiniteFuture())); -} - -// Tests waiting on a semaphore that has already been signaled. -TEST_P(SemaphoreTest, WaitAlreadySignaled) { - IREE_ASSERT_OK_AND_ASSIGN(auto semaphore, device_->CreateSemaphore(2u)); - // Test both previous and current values. - IREE_EXPECT_OK( - device_->WaitAllSemaphores({{semaphore.get(), 1u}}, InfiniteFuture())); - IREE_EXPECT_OK( - device_->WaitAllSemaphores({{semaphore.get(), 2u}}, InfiniteFuture())); -} - -// Tests waiting on a semaphore that has not been signaled. -TEST_P(SemaphoreTest, WaitUnsignaled) { - IREE_ASSERT_OK_AND_ASSIGN(auto semaphore, device_->CreateSemaphore(2u)); - // NOTE: we don't actually block here because otherwise we'd lock up. - // Result status is undefined - some backends may return DeadlineExceededError - // while others may return success. - device_->WaitAllSemaphores({{semaphore.get(), 3u}}, InfinitePast()) - .IgnoreError(); -} - -// Waiting on a failed semaphore is undefined behavior. Some backends may -// return UnknownError while others may succeed. - -// Waiting all semaphores but not all are signaled. -TEST_P(SemaphoreTest, WaitAllButNotAllSignaled) { - IREE_ASSERT_OK_AND_ASSIGN(auto a, device_->CreateSemaphore(0u)); - IREE_ASSERT_OK_AND_ASSIGN(auto b, device_->CreateSemaphore(1u)); - // NOTE: we don't actually block here because otherwise we'd lock up. - // Result status is undefined - some backends may return DeadlineExceededError - // while others may return success. - device_->WaitAllSemaphores({{a.get(), 1u}, {b.get(), 1u}}, InfinitePast()) - .IgnoreError(); -} - -// Waiting all semaphores and all are signaled. -TEST_P(SemaphoreTest, WaitAllAndAllSignaled) { - IREE_ASSERT_OK_AND_ASSIGN(auto a, device_->CreateSemaphore(1u)); - IREE_ASSERT_OK_AND_ASSIGN(auto b, device_->CreateSemaphore(1u)); - IREE_ASSERT_OK(device_->WaitAllSemaphores({{a.get(), 1u}, {b.get(), 1u}}, - InfiniteFuture())); -} - -// Waiting any semaphore to signal. -TEST_P(SemaphoreTest, WaitAny) { - // TODO: fix this. - if (driver_->name() == "dylib" || driver_->name() == "vmla" || - driver_->name() == "vulkan") { - GTEST_SKIP(); - } - - IREE_ASSERT_OK_AND_ASSIGN(auto a, device_->CreateSemaphore(0u)); - IREE_ASSERT_OK_AND_ASSIGN(auto b, device_->CreateSemaphore(1u)); - IREE_ASSERT_OK(device_->WaitAnySemaphore({{a.get(), 1u}, {b.get(), 1u}}, - InfiniteFuture())); -} - -// Tests threading behavior by ping-ponging between the test main thread and -// a little thread. -TEST_P(SemaphoreTest, PingPong) { - IREE_ASSERT_OK_AND_ASSIGN(auto a2b, device_->CreateSemaphore(0u)); - IREE_ASSERT_OK_AND_ASSIGN(auto b2a, device_->CreateSemaphore(0u)); - std::thread thread([&]() { - // Should advance right past this because the value is already set. - IREE_ASSERT_OK( - device_->WaitAllSemaphores({{a2b.get(), 0u}}, InfiniteFuture())); - IREE_ASSERT_OK(b2a->Signal(1u)); - // Jump ahead. - IREE_ASSERT_OK( - device_->WaitAllSemaphores({{a2b.get(), 4u}}, InfiniteFuture())); - }); - IREE_ASSERT_OK( - device_->WaitAllSemaphores({{b2a.get(), 1u}}, InfiniteFuture())); - IREE_ASSERT_OK(a2b->Signal(4u)); - thread.join(); -} - -INSTANTIATE_TEST_SUITE_P( - AllDrivers, SemaphoreTest, - ::testing::ValuesIn(testing::EnumerateAvailableDrivers()), - GenerateTestName()); - -} // namespace cts -} // namespace hal -} // namespace iree