From 130a7ac8b86fcad670154e935b4416bca4dfc2fb Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Thu, 27 Sep 2018 15:08:57 +0200 Subject: [PATCH] Delete TypeSelector helper Change-Id: Iff5fe62d31fa7b07658cfcf81ebd2c12d47e2b3b Signed-off-by: Maciej Dziuban --- runtime/aub_mem_dump/aub_mem_dump.h | 20 ++------ .../aub_command_stream_receiver_hw.h | 2 +- .../aub_command_stream_receiver_hw.inl | 2 +- .../tbx_command_stream_receiver_hw.h | 2 +- .../tbx_command_stream_receiver_hw.inl | 2 +- runtime/gen10/aub_mapper.h | 3 +- runtime/gen8/aub_mapper.h | 3 +- runtime/gen9/aub_mapper.h | 3 +- runtime/gen_common/aub_mapper_base.h | 21 ++------ runtime/helpers/CMakeLists.txt | 1 - runtime/helpers/selectors.h | 42 ---------------- runtime/memory_manager/memory_constants.h | 7 +-- .../aub_command_stream_receiver_tests.cpp | 4 +- .../memory_manager/address_mapper_tests.cpp | 1 - .../memory_manager/page_table_tests.cpp | 49 +++++++++---------- 15 files changed, 48 insertions(+), 114 deletions(-) delete mode 100644 runtime/helpers/selectors.h diff --git a/runtime/aub_mem_dump/aub_mem_dump.h b/runtime/aub_mem_dump/aub_mem_dump.h index 549a68f92a..13d6671b15 100644 --- a/runtime/aub_mem_dump/aub_mem_dump.h +++ b/runtime/aub_mem_dump/aub_mem_dump.h @@ -35,16 +35,6 @@ inline void setAddress(CmdServicesMemTraceMemoryCompare &cmd, uint64_t address) cmd.addressHigh = static_cast(address >> 32); } -template -struct TypeSelector { - typedef TypeTrue type; -}; - -template -struct TypeSelector { - typedef TypeFalse type; -}; - union IAPageTableEntry { struct { @@ -264,11 +254,11 @@ struct AubPageTableHelper64 : public AubPageTableHelper, PageTableTraits }; template -struct AubDump : public TypeSelector, AubPageTableHelper64, TraitsIn::addressingBits == 32>::type { - typedef TraitsIn Traits; - typedef typename TypeSelector::type AddressType; - typedef typename TypeSelector, AubPageTableHelper64, Traits::addressingBits == 32>::type BaseHelper; - typedef typename Traits::Stream Stream; +struct AubDump : public std::conditional, AubPageTableHelper64>::type { + using Traits = TraitsIn; + using AddressType = typename std::conditional::type; + using BaseHelper = typename std::conditional, AubPageTableHelper64>::type; + using Stream = typename Traits::Stream; typedef union _MiContextDescriptorReg_ { struct { diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 2119eb1ea4..55b733e94f 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -92,7 +92,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::type> ppgtt; + std::unique_ptr::type> ppgtt; std::unique_ptr ggtt; // remap CPU VA -> GGTT VA AddressMapper *gttRemap; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 470c1621b6..95b8739cc5 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -42,7 +42,7 @@ AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const Hardware auto physicalAddressAllocator = aubCenter->getPhysicalAddressAllocator(); UNRECOVERABLE_IF(nullptr == physicalAddressAllocator); - ppgtt = std::make_unique::type>(physicalAddressAllocator); + ppgtt = std::make_unique::type>(physicalAddressAllocator); ggtt = std::make_unique(physicalAddressAllocator); gttRemap = aubCenter->getAddressMapper(); diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index 9a36ba01ee..9a91ea9daa 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -80,7 +80,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw physicalAddressAllocator; - std::unique_ptr::type> ppgtt; + std::unique_ptr::type> ppgtt; std::unique_ptr ggtt; // remap CPU VA -> GGTT VA AddressMapper gttRemap; diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index b979bd325e..9ba0ae8bb6 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -28,7 +28,7 @@ TbxCommandStreamReceiverHw::TbxCommandStreamReceiverHw(const Hardware physicalAddressAllocator.reset(this->createPhysicalAddressAllocator()); - ppgtt = std::make_unique::type>(physicalAddressAllocator.get()); + ppgtt = std::make_unique::type>(physicalAddressAllocator.get()); ggtt = std::make_unique(physicalAddressAllocator.get()); for (auto &engineInfo : engineInfoTable) { diff --git a/runtime/gen10/aub_mapper.h b/runtime/gen10/aub_mapper.h index c7515da2b2..465d9edf5e 100644 --- a/runtime/gen10/aub_mapper.h +++ b/runtime/gen10/aub_mapper.h @@ -7,6 +7,7 @@ #pragma once #include "runtime/gen_common/aub_mapper_base.h" +#include "runtime/memory_manager/memory_constants.h" namespace OCLRT { struct CNLFamily; @@ -15,7 +16,7 @@ template <> struct AUBFamilyMapper { enum { device = AubMemDump::DeviceValues::Cnl }; - typedef AubMemDump::Traits AubTraits; + using AubTraits = AubMemDump::Traits; static const AubMemDump::LrcaHelper *csTraits[EngineType::NUM_ENGINES]; diff --git a/runtime/gen8/aub_mapper.h b/runtime/gen8/aub_mapper.h index 7c5291cc98..c646f4a491 100644 --- a/runtime/gen8/aub_mapper.h +++ b/runtime/gen8/aub_mapper.h @@ -7,6 +7,7 @@ #pragma once #include "runtime/gen_common/aub_mapper_base.h" +#include "runtime/memory_manager/memory_constants.h" namespace OCLRT { struct BDWFamily; @@ -15,7 +16,7 @@ template <> struct AUBFamilyMapper { enum { device = AubMemDump::DeviceValues::Bdw }; - typedef AubMemDump::Traits AubTraits; + using AubTraits = AubMemDump::Traits; static const AubMemDump::LrcaHelper *csTraits[EngineType::NUM_ENGINES]; diff --git a/runtime/gen9/aub_mapper.h b/runtime/gen9/aub_mapper.h index 232491b732..2eb4f86c82 100644 --- a/runtime/gen9/aub_mapper.h +++ b/runtime/gen9/aub_mapper.h @@ -7,6 +7,7 @@ #pragma once #include "runtime/gen_common/aub_mapper_base.h" +#include "runtime/memory_manager/memory_constants.h" namespace OCLRT { struct SKLFamily; @@ -15,7 +16,7 @@ template <> struct AUBFamilyMapper { enum { device = AubMemDump::DeviceValues::Skl }; - typedef AubMemDump::Traits AubTraits; + using AubTraits = AubMemDump::Traits; static const AubMemDump::LrcaHelper *csTraits[EngineType::NUM_ENGINES]; diff --git a/runtime/gen_common/aub_mapper_base.h b/runtime/gen_common/aub_mapper_base.h index 679e24b40c..1aea62c5a7 100644 --- a/runtime/gen_common/aub_mapper_base.h +++ b/runtime/gen_common/aub_mapper_base.h @@ -1,29 +1,13 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (C) 2017-2018 Intel Corporation * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: + * SPDX-License-Identifier: MIT * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. */ #pragma once #include "runtime/aub_mem_dump/aub_mem_dump.h" #include "runtime/helpers/completion_stamp.h" -#include "runtime/helpers/selectors.h" #include namespace OCLRT { @@ -34,4 +18,5 @@ struct AUBFamilyMapper { using MMIOPair = std::pair; using MMIOList = std::vector; + } // namespace OCLRT diff --git a/runtime/helpers/CMakeLists.txt b/runtime/helpers/CMakeLists.txt index cb2e53cecf..9199e1b885 100644 --- a/runtime/helpers/CMakeLists.txt +++ b/runtime/helpers/CMakeLists.txt @@ -65,7 +65,6 @@ set(RUNTIME_SRCS_HELPERS_BASE ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/queue_helpers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/queue_helpers.h ${CMAKE_CURRENT_SOURCE_DIR}/sampler_helpers.h - ${CMAKE_CURRENT_SOURCE_DIR}/selectors.h ${CMAKE_CURRENT_SOURCE_DIR}/state_base_address.h ${CMAKE_CURRENT_SOURCE_DIR}/state_base_address.inl ${CMAKE_CURRENT_SOURCE_DIR}/stdio.h diff --git a/runtime/helpers/selectors.h b/runtime/helpers/selectors.h deleted file mode 100644 index 99fdd02501..0000000000 --- a/runtime/helpers/selectors.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#pragma once - -template -struct TypeSelector { - typedef TypeTrue type; -}; - -template -struct TypeSelector { - typedef TypeFalse type; -}; - -template -struct IntSelector { - enum { - value = expression ? valueTrue : valueFalse - }; -}; - -typedef IntSelector<32, 48, sizeof(void *) == sizeof(char[4])> GfxAddressBits; \ No newline at end of file diff --git a/runtime/memory_manager/memory_constants.h b/runtime/memory_manager/memory_constants.h index 0bf02a2479..cdc636a75c 100644 --- a/runtime/memory_manager/memory_constants.h +++ b/runtime/memory_manager/memory_constants.h @@ -10,6 +10,9 @@ #include #include +constexpr bool is32bit = (sizeof(void *) == 4); +constexpr bool is64bit = (sizeof(void *) == 8); + namespace MemoryConstants { static const uint64_t zoneHigh = ~(uint64_t)0xFFFFFFFF; static const uint64_t kiloByte = 1024; @@ -33,7 +36,5 @@ static const uint64_t max32BitAddress = ((1ULL << 32) - 1); static const uint64_t max48BitAddress = ((1ULL << 48) - 1); static const uintptr_t page4kEntryMask = std::numeric_limits::max() & ~MemoryConstants::pageMask; static const uintptr_t page64kEntryMask = std::numeric_limits::max() & ~MemoryConstants::page64kMask; +static const int GfxAddressBits = is64bit ? 48 : 32; } // namespace MemoryConstants - -const bool is32bit = (sizeof(void *) == 4) ? true : false; -const bool is64bit = (sizeof(void *) == 8) ? true : false; diff --git a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp index aa878061b6..b67a453296 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -1589,8 +1589,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe memoryManager.reset(aubCsr->createMemoryManager(false, false)); PhysicalAddressAllocator allocator; - struct PpgttMock : TypeSelector::type { - PpgttMock(PhysicalAddressAllocator *allocator) : TypeSelector::type(allocator) {} + struct PpgttMock : std::conditional::type { + PpgttMock(PhysicalAddressAllocator *allocator) : std::conditional::type(allocator) {} void pageWalk(uintptr_t vm, size_t size, size_t offset, uint64_t entryBits, PageWalker &pageWalker, uint32_t memoryBank) override { receivedSize = size; diff --git a/unit_tests/memory_manager/address_mapper_tests.cpp b/unit_tests/memory_manager/address_mapper_tests.cpp index 2da51fb245..37655dbbd9 100644 --- a/unit_tests/memory_manager/address_mapper_tests.cpp +++ b/unit_tests/memory_manager/address_mapper_tests.cpp @@ -6,7 +6,6 @@ */ #include "runtime/helpers/aligned_memory.h" -#include "runtime/helpers/selectors.h" #include "runtime/memory_manager/address_mapper.h" #include "test.h" #include "gtest/gtest.h" diff --git a/unit_tests/memory_manager/page_table_tests.cpp b/unit_tests/memory_manager/page_table_tests.cpp index 6603b7b424..417afcb995 100644 --- a/unit_tests/memory_manager/page_table_tests.cpp +++ b/unit_tests/memory_manager/page_table_tests.cpp @@ -7,7 +7,6 @@ #include "runtime/aub_mem_dump/page_table_entry_bits.h" #include "runtime/helpers/ptr_math.h" -#include "runtime/helpers/selectors.h" #include "runtime/memory_manager/memory_banks.h" #include "runtime/memory_manager/page_table.h" #include "runtime/memory_manager/page_table.inl" @@ -75,10 +74,10 @@ class MockPDPE : public MockPageTable { } }; -class PPGTTPageTable : public TypeSelector::type { +class PPGTTPageTable : public std::conditional::type { public: - const size_t ppgttEntries = IntSelector<512u, 4u, sizeof(void *) == 8>::value; - PPGTTPageTable(PhysicalAddressAllocator *allocator) : TypeSelector::type(allocator) { + const size_t ppgttEntries = is64bit ? 512u : 4u; + PPGTTPageTable(PhysicalAddressAllocator *allocator) : std::conditional::type(allocator) { EXPECT_EQ(ppgttEntries, entries.size()); } bool isEmpty() { @@ -105,7 +104,7 @@ class GGTTPageTable : public PDPE { class PageTableFixture { protected: const size_t pageSize = 1 << 12; - const uintptr_t refAddr = (uintptr_t(1) << IntSelector<46, 31, is64Bit>::value); + const uintptr_t refAddr = uintptr_t(1) << (is64Bit ? 46 : 31); MockPhysicalAddressAllocator allocator; uint64_t startAddress = 0x1000; @@ -248,8 +247,8 @@ TEST_F(PageTableTests48, givenBigGpuAddressWhenPageWalkIsCalledThenPageTablesAre } TEST_F(PageTableTests48, givenZeroEntryBitsWhenPageWalkIsCalledThenPageTableEntryHasPresentBitSet) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; @@ -266,12 +265,12 @@ TEST_F(PageTableTests48, givenZeroEntryBitsWhenPageWalkIsCalledThenPageTableEntr EXPECT_EQ(size, walked); ASSERT_NE(nullptr, pageTable->entries[0]); - PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | 0x1)); + PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | 0x1)); } TEST_F(PageTableTests48, givenZeroEntryBitsWhenMapIsCalledThenPageTableEntryHasPresentBitSet) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; size_t size = pageSize; auto address = allocator.mainAllocator.load(); @@ -279,12 +278,12 @@ TEST_F(PageTableTests48, givenZeroEntryBitsWhenMapIsCalledThenPageTableEntryHasP pageTable->map(gpuVa, size, 0, MemoryBanks::MainBank); ASSERT_NE(nullptr, pageTable->entries[0]); - PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | 0x1)); + PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | 0x1)); } TEST_F(PageTableTests48, givenEntryBitsWhenPageWalkIsCalledThenEntryBitsArePassedToPageWalker) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; size_t size = pageSize; @@ -303,8 +302,8 @@ TEST_F(PageTableTests48, givenEntryBitsWhenPageWalkIsCalledThenEntryBitsArePasse } TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasDifferentEntryBitsThenEntryIsUpdated) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; size_t size = pageSize; @@ -328,8 +327,8 @@ TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasDifferentEntryBitsThe } TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasNonValidEntryBitsThenEntryIsNotUpdated) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; size_t size = pageSize; @@ -357,8 +356,8 @@ TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasNonValidEntryBitsThen } TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasDifferentEntryBitsThenEntryIsUpdated) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; size_t size = pageSize; uint64_t ppgttBits = 0xabc; @@ -366,16 +365,16 @@ TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasDifferentEntryBitsThenEntry pageTable->map(gpuVa, size, ppgttBits, 0); ASSERT_NE(nullptr, pageTable->entries[0]); - PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); + PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); ppgttBits = 0x345; pageTable->map(gpuVa, size, ppgttBits, 0); - PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); + PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); } TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasNonValidEntryBitsThenEntryIsNotUpdated) { - std::unique_ptr::type> - pageTable(std::make_unique::type>(&allocator)); + std::unique_ptr::type> + pageTable(std::make_unique::type>(&allocator)); uintptr_t gpuVa = 0x1000; size_t size = pageSize; uint64_t ppgttBits = 0xabc; @@ -384,12 +383,12 @@ TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasNonValidEntryBitsThenEntryI pageTable->map(gpuVa, size, ppgttBits, 0); ASSERT_NE(nullptr, pageTable->entries[0]); - PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); + PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); uint64_t nonValidPpgttBits = PageTableEntry::nonValidBits; pageTable->map(gpuVa, size, nonValidPpgttBits, 0); - PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); + PageTableEntryChecker::testEntry::type>(pageTable.get(), 1, static_cast(address | ppgttBits | 0x1)); } TEST_F(PageTableTests48, givenPageTableWhenMappingTheSameAddressMultipleTimesThenNumberOfPagesReservedInAllocatorMatchPagesMapped) {