Skip to content

Commit

Permalink
Delete TypeSelector helper
Browse files Browse the repository at this point in the history
Change-Id: Iff5fe62d31fa7b07658cfcf81ebd2c12d47e2b3b
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
  • Loading branch information
DziubanMaciejIntel authored and Compute-Runtime-Automation committed Oct 8, 2018
1 parent 2f7158e commit 130a7ac
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 114 deletions.
20 changes: 5 additions & 15 deletions runtime/aub_mem_dump/aub_mem_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ inline void setAddress(CmdServicesMemTraceMemoryCompare &cmd, uint64_t address)
cmd.addressHigh = static_cast<uint32_t>(address >> 32);
}

template <typename TypeTrue, typename TypeFalse, bool is32Bits>
struct TypeSelector {
typedef TypeTrue type;
};

template <typename TypeTrue, typename TypeFalse>
struct TypeSelector<TypeTrue, TypeFalse, false> {
typedef TypeFalse type;
};

union IAPageTableEntry {
struct
{
Expand Down Expand Up @@ -264,11 +254,11 @@ struct AubPageTableHelper64 : public AubPageTableHelper<Traits>, PageTableTraits
};

template <typename TraitsIn>
struct AubDump : public TypeSelector<AubPageTableHelper32<TraitsIn>, AubPageTableHelper64<TraitsIn>, TraitsIn::addressingBits == 32>::type {
typedef TraitsIn Traits;
typedef typename TypeSelector<uint32_t, uint64_t, Traits::addressingBits == 32>::type AddressType;
typedef typename TypeSelector<AubPageTableHelper32<Traits>, AubPageTableHelper64<Traits>, Traits::addressingBits == 32>::type BaseHelper;
typedef typename Traits::Stream Stream;
struct AubDump : public std::conditional<TraitsIn::addressingBits == 32, AubPageTableHelper32<TraitsIn>, AubPageTableHelper64<TraitsIn>>::type {
using Traits = TraitsIn;
using AddressType = typename std::conditional<Traits::addressingBits == 32, uint32_t, uint64_t>::type;
using BaseHelper = typename std::conditional<Traits::addressingBits == 32, AubPageTableHelper32<Traits>, AubPageTableHelper64<Traits>>::type;
using Stream = typename Traits::Stream;

typedef union _MiContextDescriptorReg_ {
struct {
Expand Down
2 changes: 1 addition & 1 deletion runtime/command_stream/aub_command_stream_receiver_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
uint32_t aubDeviceId;
bool standalone;

std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt;
std::unique_ptr<std::conditional<is64bit, PML4, PDPE>::type> ppgtt;
std::unique_ptr<PDPE> ggtt;
// remap CPU VA -> GGTT VA
AddressMapper *gttRemap;
Expand Down
2 changes: 1 addition & 1 deletion runtime/command_stream/aub_command_stream_receiver_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const Hardware
auto physicalAddressAllocator = aubCenter->getPhysicalAddressAllocator();
UNRECOVERABLE_IF(nullptr == physicalAddressAllocator);

ppgtt = std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(physicalAddressAllocator);
ppgtt = std::make_unique<std::conditional<is64bit, PML4, PDPE>::type>(physicalAddressAllocator);
ggtt = std::make_unique<PDPE>(physicalAddressAllocator);

gttRemap = aubCenter->getAddressMapper();
Expand Down
2 changes: 1 addition & 1 deletion runtime/command_stream/tbx_command_stream_receiver_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
bool streamInitialized = false;

std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt;
std::unique_ptr<std::conditional<is64bit, PML4, PDPE>::type> ppgtt;
std::unique_ptr<PDPE> ggtt;
// remap CPU VA -> GGTT VA
AddressMapper gttRemap;
Expand Down
2 changes: 1 addition & 1 deletion runtime/command_stream/tbx_command_stream_receiver_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TbxCommandStreamReceiverHw<GfxFamily>::TbxCommandStreamReceiverHw(const Hardware

physicalAddressAllocator.reset(this->createPhysicalAddressAllocator());

ppgtt = std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(physicalAddressAllocator.get());
ppgtt = std::make_unique<std::conditional<is64bit, PML4, PDPE>::type>(physicalAddressAllocator.get());
ggtt = std::make_unique<PDPE>(physicalAddressAllocator.get());

for (auto &engineInfo : engineInfoTable) {
Expand Down
3 changes: 2 additions & 1 deletion runtime/gen10/aub_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@ template <>
struct AUBFamilyMapper<CNLFamily> {
enum { device = AubMemDump::DeviceValues::Cnl };

typedef AubMemDump::Traits<device, GfxAddressBits::value> AubTraits;
using AubTraits = AubMemDump::Traits<device, MemoryConstants::GfxAddressBits>;

static const AubMemDump::LrcaHelper *csTraits[EngineType::NUM_ENGINES];

Expand Down
3 changes: 2 additions & 1 deletion runtime/gen8/aub_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@ template <>
struct AUBFamilyMapper<BDWFamily> {
enum { device = AubMemDump::DeviceValues::Bdw };

typedef AubMemDump::Traits<device, GfxAddressBits::value> AubTraits;
using AubTraits = AubMemDump::Traits<device, MemoryConstants::GfxAddressBits>;

static const AubMemDump::LrcaHelper *csTraits[EngineType::NUM_ENGINES];

Expand Down
3 changes: 2 additions & 1 deletion runtime/gen9/aub_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@ template <>
struct AUBFamilyMapper<SKLFamily> {
enum { device = AubMemDump::DeviceValues::Skl };

typedef AubMemDump::Traits<device, GfxAddressBits::value> AubTraits;
using AubTraits = AubMemDump::Traits<device, MemoryConstants::GfxAddressBits>;

static const AubMemDump::LrcaHelper *csTraits[EngineType::NUM_ENGINES];

Expand Down
21 changes: 3 additions & 18 deletions runtime/gen_common/aub_mapper_base.h
Original file line number Diff line number Diff line change
@@ -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 <vector>

namespace OCLRT {
Expand All @@ -34,4 +18,5 @@ struct AUBFamilyMapper {

using MMIOPair = std::pair<uint32_t, uint32_t>;
using MMIOList = std::vector<MMIOPair>;

} // namespace OCLRT
1 change: 0 additions & 1 deletion runtime/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 0 additions & 42 deletions runtime/helpers/selectors.h

This file was deleted.

7 changes: 4 additions & 3 deletions runtime/memory_manager/memory_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <cstddef>
#include <limits>

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;
Expand All @@ -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<uintptr_t>::max() & ~MemoryConstants::pageMask;
static const uintptr_t page64kEntryMask = std::numeric_limits<uintptr_t>::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;
Original file line number Diff line number Diff line change
Expand Up @@ -1589,8 +1589,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe
memoryManager.reset(aubCsr->createMemoryManager(false, false));

PhysicalAddressAllocator allocator;
struct PpgttMock : TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type {
PpgttMock(PhysicalAddressAllocator *allocator) : TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type(allocator) {}
struct PpgttMock : std::conditional<is64bit, PML4, PDPE>::type {
PpgttMock(PhysicalAddressAllocator *allocator) : std::conditional<is64bit, PML4, PDPE>::type(allocator) {}

void pageWalk(uintptr_t vm, size_t size, size_t offset, uint64_t entryBits, PageWalker &pageWalker, uint32_t memoryBank) override {
receivedSize = size;
Expand Down
1 change: 0 additions & 1 deletion unit_tests/memory_manager/address_mapper_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 24 additions & 25 deletions unit_tests/memory_manager/page_table_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -75,10 +74,10 @@ class MockPDPE : public MockPageTable<MockPDE, 2, 2> {
}
};

class PPGTTPageTable : public TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type {
class PPGTTPageTable : public std::conditional<is64bit, PML4, PDPE>::type {
public:
const size_t ppgttEntries = IntSelector<512u, 4u, sizeof(void *) == 8>::value;
PPGTTPageTable(PhysicalAddressAllocator *allocator) : TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type(allocator) {
const size_t ppgttEntries = is64bit ? 512u : 4u;
PPGTTPageTable(PhysicalAddressAllocator *allocator) : std::conditional<is64bit, PML4, PDPE>::type(allocator) {
EXPECT_EQ(ppgttEntries, entries.size());
}
bool isEmpty() {
Expand All @@ -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;

Expand Down Expand Up @@ -248,8 +247,8 @@ TEST_F(PageTableTests48, givenBigGpuAddressWhenPageWalkIsCalledThenPageTablesAre
}

TEST_F(PageTableTests48, givenZeroEntryBitsWhenPageWalkIsCalledThenPageTableEntryHasPresentBitSet) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));

uintptr_t gpuVa = 0x1000;

Expand All @@ -266,25 +265,25 @@ TEST_F(PageTableTests48, givenZeroEntryBitsWhenPageWalkIsCalledThenPageTableEntr
EXPECT_EQ(size, walked);
ASSERT_NE(nullptr, pageTable->entries[0]);

PageTableEntryChecker::testEntry<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | 0x1));
PageTableEntryChecker::testEntry<std::conditional<is64bit, MockPML4, MockPDPE>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | 0x1));
}

TEST_F(PageTableTests48, givenZeroEntryBitsWhenMapIsCalledThenPageTableEntryHasPresentBitSet) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));
uintptr_t gpuVa = 0x1000;
size_t size = pageSize;
auto address = allocator.mainAllocator.load();

pageTable->map(gpuVa, size, 0, MemoryBanks::MainBank);
ASSERT_NE(nullptr, pageTable->entries[0]);

PageTableEntryChecker::testEntry<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | 0x1));
PageTableEntryChecker::testEntry<std::conditional<is64bit, MockPML4, MockPDPE>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | 0x1));
}

TEST_F(PageTableTests48, givenEntryBitsWhenPageWalkIsCalledThenEntryBitsArePassedToPageWalker) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));

uintptr_t gpuVa = 0x1000;
size_t size = pageSize;
Expand All @@ -303,8 +302,8 @@ TEST_F(PageTableTests48, givenEntryBitsWhenPageWalkIsCalledThenEntryBitsArePasse
}

TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasDifferentEntryBitsThenEntryIsUpdated) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));

uintptr_t gpuVa = 0x1000;
size_t size = pageSize;
Expand All @@ -328,8 +327,8 @@ TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasDifferentEntryBitsThe
}

TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasNonValidEntryBitsThenEntryIsNotUpdated) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));

uintptr_t gpuVa = 0x1000;
size_t size = pageSize;
Expand Down Expand Up @@ -357,25 +356,25 @@ TEST_F(PageTableTests48, givenTwoPageWalksWhenSecondWalkHasNonValidEntryBitsThen
}

TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasDifferentEntryBitsThenEntryIsUpdated) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));
uintptr_t gpuVa = 0x1000;
size_t size = pageSize;
uint64_t ppgttBits = 0xabc;
auto address = allocator.mainAllocator.load();

pageTable->map(gpuVa, size, ppgttBits, 0);
ASSERT_NE(nullptr, pageTable->entries[0]);
PageTableEntryChecker::testEntry<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));
PageTableEntryChecker::testEntry<std::conditional<is64bit, MockPML4, MockPDPE>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));

ppgttBits = 0x345;
pageTable->map(gpuVa, size, ppgttBits, 0);
PageTableEntryChecker::testEntry<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));
PageTableEntryChecker::testEntry<std::conditional<is64bit, MockPML4, MockPDPE>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));
}

TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasNonValidEntryBitsThenEntryIsNotUpdated) {
std::unique_ptr<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>
pageTable(std::make_unique<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(&allocator));
std::unique_ptr<std::conditional<is64bit, MockPML4, MockPDPE>::type>
pageTable(std::make_unique<std::conditional<is64bit, MockPML4, MockPDPE>::type>(&allocator));
uintptr_t gpuVa = 0x1000;
size_t size = pageSize;
uint64_t ppgttBits = 0xabc;
Expand All @@ -384,12 +383,12 @@ TEST_F(PageTableTests48, givenTwoMapsWhenSecondMapHasNonValidEntryBitsThenEntryI
pageTable->map(gpuVa, size, ppgttBits, 0);
ASSERT_NE(nullptr, pageTable->entries[0]);

PageTableEntryChecker::testEntry<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));
PageTableEntryChecker::testEntry<std::conditional<is64bit, MockPML4, MockPDPE>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));

uint64_t nonValidPpgttBits = PageTableEntry::nonValidBits;
pageTable->map(gpuVa, size, nonValidPpgttBits, 0);

PageTableEntryChecker::testEntry<TypeSelector<MockPML4, MockPDPE, sizeof(void *) == 8>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));
PageTableEntryChecker::testEntry<std::conditional<is64bit, MockPML4, MockPDPE>::type>(pageTable.get(), 1, static_cast<uintptr_t>(address | ppgttBits | 0x1));
}

TEST_F(PageTableTests48, givenPageTableWhenMappingTheSameAddressMultipleTimesThenNumberOfPagesReservedInAllocatorMatchPagesMapped) {
Expand Down

0 comments on commit 130a7ac

Please sign in to comment.