mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 22:12:59 +08:00
[34/N] Internal 4GB allocator.
- Change dirty state helpers to work on IndirectHeaps. - Instead of comparing size in bytes and cpu pointers, compare gpu base address and size of the heap in pages - That allows to not have dirty flag for heaps that are coming from 4GB allocator. Change-Id: I0ff81e3c0945b32e4f872a100cd10b332b27ed24
This commit is contained in:
committed by
sys_ocldev
parent
10e5b71111
commit
621a2dfcd1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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"),
|
||||
@@ -21,15 +21,19 @@
|
||||
*/
|
||||
|
||||
#include "runtime/helpers/dirty_state_helpers.h"
|
||||
#include "runtime/command_stream/linear_stream.h"
|
||||
#include "runtime/indirect_heap/indirect_heap.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
bool HeapDirtyState::updateAndCheck(const LinearStream *heap) {
|
||||
bool dirty = address != heap->getCpuBase() || size != heap->getMaxAvailableSpace();
|
||||
bool HeapDirtyState::updateAndCheck(const IndirectHeap *heap) {
|
||||
if (!heap->getGraphicsAllocation()) {
|
||||
sizeInPages = 0llu;
|
||||
return true;
|
||||
}
|
||||
bool dirty = gpuBaseAddress != heap->getHeapGpuBase() || sizeInPages != heap->getHeapSizeInPages();
|
||||
if (dirty) {
|
||||
address = heap->getCpuBase();
|
||||
size = heap->getMaxAvailableSpace();
|
||||
gpuBaseAddress = heap->getHeapGpuBase();
|
||||
sizeInPages = heap->getHeapSizeInPages();
|
||||
}
|
||||
return dirty;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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"),
|
||||
@@ -22,16 +22,17 @@
|
||||
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
|
||||
namespace OCLRT {
|
||||
class LinearStream;
|
||||
class IndirectHeap;
|
||||
|
||||
class HeapDirtyState {
|
||||
public:
|
||||
bool updateAndCheck(const LinearStream *heap);
|
||||
bool updateAndCheck(const IndirectHeap *heap);
|
||||
|
||||
protected:
|
||||
void *address = nullptr;
|
||||
size_t size = 0u;
|
||||
uint64_t gpuBaseAddress = 0llu;
|
||||
size_t sizeInPages = 0u;
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -654,7 +654,7 @@ HWTEST_P(EnqueueScratchSpaceTests, GivenKernelRequiringScratchWhenItIsEnqueuedWi
|
||||
PARSE::template validateCommand<MEDIA_VFE_STATE *>(cmdList.begin(), itorCmd);
|
||||
|
||||
// Trigger SBA generation
|
||||
LinearStream dirtyDsh;
|
||||
IndirectHeap dirtyDsh(nullptr);
|
||||
csr.dshState.updateAndCheck(&dirtyDsh);
|
||||
|
||||
enqueueKernel<FamilyType>(mockKernel);
|
||||
|
||||
@@ -516,7 +516,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenStateBaseAddressWhenItIsRequi
|
||||
typedef typename FamilyType::STATE_BASE_ADDRESS STATE_BASE_ADDRESS;
|
||||
auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
||||
configureCSRtoNonDirtyState<FamilyType>();
|
||||
ioh.replaceBuffer(ptrOffset(ioh.getCpuBase(), +1u), ioh.getMaxAvailableSpace() - 1);
|
||||
ioh.replaceBuffer(ptrOffset(ioh.getCpuBase(), +1u), ioh.getMaxAvailableSpace() + MemoryConstants::pageSize * 3);
|
||||
|
||||
flushTask(commandStreamReceiver);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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"),
|
||||
@@ -22,82 +22,121 @@
|
||||
|
||||
#include "runtime/helpers/dirty_state_helpers.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/command_stream/linear_stream.h"
|
||||
#include "runtime/indirect_heap/indirect_heap.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <memory>
|
||||
|
||||
namespace OCLRT {
|
||||
namespace DirtyStateHelpers {
|
||||
using namespace OCLRT;
|
||||
size_t getSizeInPages(size_t sizeInBytes) {
|
||||
return (sizeInBytes + MemoryConstants::pageSize) / MemoryConstants::pageSize;
|
||||
}
|
||||
|
||||
void *buffer = reinterpret_cast<void *>(123);
|
||||
constexpr size_t bufferSize = 456;
|
||||
|
||||
struct HeapDirtyStateTests : ::testing::Test {
|
||||
struct MockHeapDirtyState : public HeapDirtyState {
|
||||
using HeapDirtyState::address;
|
||||
using HeapDirtyState::size;
|
||||
using HeapDirtyState::gpuBaseAddress;
|
||||
using HeapDirtyState::sizeInPages;
|
||||
};
|
||||
|
||||
void SetUp() override {
|
||||
stream.reset(new LinearStream(buffer, bufferSize));
|
||||
ASSERT_EQ(buffer, stream->getCpuBase());
|
||||
ASSERT_EQ(bufferSize, stream->getMaxAvailableSpace());
|
||||
stream.reset(new IndirectHeap(&heapAllocation));
|
||||
ASSERT_EQ(heapAllocation.getUnderlyingBuffer(), stream->getCpuBase());
|
||||
ASSERT_EQ(heapAllocation.getUnderlyingBufferSize(), stream->getMaxAvailableSpace());
|
||||
}
|
||||
|
||||
void *buffer = (void *)123;
|
||||
size_t bufferSize = 456;
|
||||
std::unique_ptr<LinearStream> stream;
|
||||
GraphicsAllocation heapAllocation = {buffer, bufferSize};
|
||||
|
||||
std::unique_ptr<IndirectHeap> stream;
|
||||
MockHeapDirtyState mockHeapDirtyState;
|
||||
};
|
||||
|
||||
TEST_F(HeapDirtyStateTests, initialValues) {
|
||||
EXPECT_EQ(0u, mockHeapDirtyState.size);
|
||||
EXPECT_EQ(nullptr, mockHeapDirtyState.address);
|
||||
EXPECT_EQ(0u, mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_EQ(0llu, mockHeapDirtyState.gpuBaseAddress);
|
||||
}
|
||||
|
||||
TEST_F(HeapDirtyStateTests, givenInitializedObjectWhenUpdatedMultipleTimesThenSetValuesAndReturnDirtyOnce) {
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
EXPECT_EQ(bufferSize, mockHeapDirtyState.size);
|
||||
EXPECT_EQ(buffer, mockHeapDirtyState.address);
|
||||
EXPECT_EQ(getSizeInPages(bufferSize), mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_EQ(castToUint64(buffer), mockHeapDirtyState.gpuBaseAddress);
|
||||
|
||||
EXPECT_FALSE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
EXPECT_EQ(bufferSize, mockHeapDirtyState.size);
|
||||
EXPECT_EQ(buffer, mockHeapDirtyState.address);
|
||||
EXPECT_EQ(getSizeInPages(bufferSize), mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_EQ(castToUint64(buffer), mockHeapDirtyState.gpuBaseAddress);
|
||||
}
|
||||
|
||||
TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenAddressChangedThenReturnDirty) {
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
auto newBuffer = ptrOffset(buffer, 1);
|
||||
auto newBuffer = ptrOffset(buffer, MemoryConstants::pageSize + 1);
|
||||
auto graphicsAllocation = stream->getGraphicsAllocation();
|
||||
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, castToUint64(newBuffer));
|
||||
|
||||
stream->replaceBuffer(newBuffer, bufferSize);
|
||||
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
EXPECT_EQ(bufferSize, mockHeapDirtyState.size);
|
||||
EXPECT_EQ(newBuffer, mockHeapDirtyState.address);
|
||||
EXPECT_EQ(1u, mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_EQ(castToUint64(newBuffer), mockHeapDirtyState.gpuBaseAddress);
|
||||
}
|
||||
|
||||
TEST_F(HeapDirtyStateTests, givenIndirectHeapWithoutGraphicsAllocationWhenUpdateAndCheckIsCalledThenSizeIsSetToZero) {
|
||||
IndirectHeap nullHeap(nullptr);
|
||||
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
EXPECT_NE(0llu, mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(&nullHeap));
|
||||
EXPECT_EQ(0llu, mockHeapDirtyState.sizeInPages);
|
||||
}
|
||||
|
||||
TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenSizeChangedThenReturnDirty) {
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
auto newBufferSize = bufferSize + 1;
|
||||
auto newBufferSize = bufferSize + MemoryConstants::pageSize;
|
||||
stream->replaceBuffer(stream->getCpuBase(), newBufferSize);
|
||||
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
EXPECT_EQ(newBufferSize, mockHeapDirtyState.size);
|
||||
EXPECT_EQ(buffer, mockHeapDirtyState.address);
|
||||
EXPECT_EQ(getSizeInPages(newBufferSize), mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_EQ(castToUint64(buffer), mockHeapDirtyState.gpuBaseAddress);
|
||||
}
|
||||
|
||||
TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenSizeAndBufferChangedThenReturnDirty) {
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
auto newBuffer = ptrOffset(buffer, 1);
|
||||
auto newBufferSize = bufferSize + 1;
|
||||
stream->replaceBuffer(newBuffer, newBufferSize);
|
||||
auto newBufferSize = bufferSize + MemoryConstants::pageSize;
|
||||
auto graphicsAllocation = stream->getGraphicsAllocation();
|
||||
graphicsAllocation->setSize(newBufferSize);
|
||||
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, castToUint64(newBuffer));
|
||||
stream->replaceBuffer(stream->getCpuBase(), newBufferSize);
|
||||
|
||||
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
|
||||
|
||||
EXPECT_EQ(newBufferSize, mockHeapDirtyState.size);
|
||||
EXPECT_EQ(newBuffer, mockHeapDirtyState.address);
|
||||
EXPECT_EQ(getSizeInPages(newBufferSize), mockHeapDirtyState.sizeInPages);
|
||||
EXPECT_EQ(castToUint64(newBuffer), mockHeapDirtyState.gpuBaseAddress);
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
TEST(DirtyStateHelpers, givenDirtyStateHelperWhenTwoDifferentIndirectHeapsAreCheckedButWithTheSame4GBbaseThenStateIsNotDirty) {
|
||||
GraphicsAllocation firstHeapAllocation(reinterpret_cast<void *>(0x1234), 4192);
|
||||
GraphicsAllocation secondHeapAllocation(reinterpret_cast<void *>(0x9345), 1234);
|
||||
uint64_t commonBase = 0x8123456;
|
||||
firstHeapAllocation.gpuBaseAddress = commonBase;
|
||||
secondHeapAllocation.gpuBaseAddress = commonBase;
|
||||
|
||||
IndirectHeap firstHeap(&firstHeapAllocation, true);
|
||||
IndirectHeap secondHeap(&secondHeapAllocation, true);
|
||||
|
||||
HeapDirtyState heapChecker;
|
||||
auto dirty = heapChecker.updateAndCheck(&firstHeap);
|
||||
EXPECT_TRUE(dirty);
|
||||
dirty = heapChecker.updateAndCheck(&secondHeap);
|
||||
EXPECT_FALSE(dirty);
|
||||
}
|
||||
|
||||
} // namespace DirtyStateHelpers
|
||||
|
||||
Reference in New Issue
Block a user