Add function to create devices bitfield based on allocation properties

Change-Id: Ic70443b1fb6106186efcff318690e434dc1db625
Signed-off-by: Jablonski, Mateusz <mateusz.jablonski@intel.com>
This commit is contained in:
Jablonski, Mateusz
2019-02-20 14:03:04 +01:00
committed by sys_ocldev
parent ce77425428
commit 798137e4bb
10 changed files with 53 additions and 5 deletions

View File

@@ -215,7 +215,7 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) {
GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(minRequiredSize, allocationType).release(); GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(minRequiredSize, allocationType).release();
if (!allocation) { if (!allocation) {
allocation = memoryManager->allocateGraphicsMemoryWithProperties({minRequiredSize, allocationType}); allocation = memoryManager->allocateGraphicsMemoryWithProperties({true, minRequiredSize, allocationType, getCommandStreamReceiver().isMultiOsContextCapable()});
} }
// Deallocate the old block, if not null // Deallocate the old block, if not null

View File

@@ -121,6 +121,10 @@ MemoryManager *CommandStreamReceiver::getMemoryManager() const {
return executionEnvironment.memoryManager.get(); return executionEnvironment.memoryManager.get();
} }
bool CommandStreamReceiver::isMultiOsContextCapable() const {
return executionEnvironment.specialCommandStreamReceiver.get() == this;
}
LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
if (commandStream.getAvailableSpace() < minRequiredSize) { if (commandStream.getAvailableSpace() < minRequiredSize) {
// Make sure we have enough room for a MI_BATCH_BUFFER_END and any padding. // Make sure we have enough room for a MI_BATCH_BUFFER_END and any padding.
@@ -133,7 +137,7 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER; auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER;
auto allocation = internalAllocationStorage->obtainReusableAllocation(minRequiredSize, allocationType).release(); auto allocation = internalAllocationStorage->obtainReusableAllocation(minRequiredSize, allocationType).release();
if (!allocation) { if (!allocation) {
allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({minRequiredSize, allocationType}); allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({true, minRequiredSize, allocationType, isMultiOsContextCapable()});
} }
//pass current allocation to reusable list //pass current allocation to reusable list

View File

@@ -173,6 +173,7 @@ class CommandStreamReceiver {
void setDisableL3Cache(bool val) { void setDisableL3Cache(bool val) {
disableL3Cache = val; disableL3Cache = val;
} }
bool isMultiOsContextCapable() const;
protected: protected:
void cleanupResources(); void cleanupResources();

View File

@@ -62,7 +62,7 @@ void ExperimentalCommandBuffer::getCS(size_t minRequiredSize) {
auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER; auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER;
GraphicsAllocation *allocation = storageWithAllocations->obtainReusableAllocation(requiredSize, allocationType).release(); GraphicsAllocation *allocation = storageWithAllocations->obtainReusableAllocation(requiredSize, allocationType).release();
if (!allocation) { if (!allocation) {
allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, allocationType}); allocation = memoryManager->allocateGraphicsMemoryWithProperties({true, minRequiredSize, allocationType, commandStreamReceiver->isMultiOsContextCapable()});
} }
// Deallocate the old block, if not null // Deallocate the old block, if not null
auto oldAllocation = currentStream->getGraphicsAllocation(); auto oldAllocation = currentStream->getGraphicsAllocation();

View File

@@ -14,6 +14,7 @@ set(RUNTIME_SRCS_MEMORY_MANAGER
${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion.h ${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion.h
${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.h ${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.h
${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/devices_bitfield.cpp
${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/devices_bitfield.h ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/devices_bitfield.h
${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation.h

View File

@@ -0,0 +1,14 @@
/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/memory_manager/graphics_allocation.h"
namespace OCLRT {
DevicesBitfield GraphicsAllocation::createBitfieldFromProperties(const AllocationProperties &properties) {
return {};
}
} // namespace OCLRT

View File

@@ -44,6 +44,7 @@ constexpr auto nonSharedResource = 0u;
} }
class Gmm; class Gmm;
struct AllocationProperties;
class GraphicsAllocation : public IDNode<GraphicsAllocation> { class GraphicsAllocation : public IDNode<GraphicsAllocation> {
public: public:
@@ -165,6 +166,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER || allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER ||
allocationType == AllocationType::COMMAND_BUFFER; allocationType == AllocationType::COMMAND_BUFFER;
} }
static DevicesBitfield createBitfieldFromProperties(const AllocationProperties &properties);
protected: protected:
constexpr static uint32_t objectNotResident = (uint32_t)-1; constexpr static uint32_t objectNotResident = (uint32_t)-1;

View File

@@ -60,11 +60,14 @@ struct AllocationProperties {
AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType)
: AllocationProperties(true, size, allocationType) {} : AllocationProperties(true, size, allocationType) {}
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType) AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType)
: AllocationProperties(allocateMemory, size, allocationType, false) {}
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType, bool multiOsContextCapable)
: size(size), allocationType(allocationType) { : size(size), allocationType(allocationType) {
allFlags = 0; allFlags = 0;
flags.flushL3RequiredForRead = 1; flags.flushL3RequiredForRead = 1;
flags.flushL3RequiredForWrite = 1; flags.flushL3RequiredForWrite = 1;
flags.allocateMemory = allocateMemory; flags.allocateMemory = allocateMemory;
flags.multiOsContextCapable = multiOsContextCapable;
} }
AllocationProperties(ImageInfo *imgInfo, bool allocateMemory) : AllocationProperties(allocateMemory, 0, GraphicsAllocation::AllocationType::IMAGE) { AllocationProperties(ImageInfo *imgInfo, bool allocateMemory) : AllocationProperties(allocateMemory, 0, GraphicsAllocation::AllocationType::IMAGE) {
this->imgInfo = imgInfo; this->imgInfo = imgInfo;
@@ -95,11 +98,11 @@ class MemoryManager {
virtual void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) = 0; virtual void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) = 0;
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) { MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) {
return allocateGraphicsMemoryInPreferredPool(properties, {}, nullptr); return allocateGraphicsMemoryInPreferredPool(properties, GraphicsAllocation::createBitfieldFromProperties(properties), nullptr);
} }
virtual GraphicsAllocation *allocateGraphicsMemory(const AllocationProperties &properties, const void *ptr) { virtual GraphicsAllocation *allocateGraphicsMemory(const AllocationProperties &properties, const void *ptr) {
return allocateGraphicsMemoryInPreferredPool(properties, {}, ptr); return allocateGraphicsMemoryInPreferredPool(properties, GraphicsAllocation::createBitfieldFromProperties(properties), ptr);
} }
GraphicsAllocation *allocateGraphicsMemoryForHostPtr(size_t size, void *ptr, bool fullRangeSvm, bool requiresL3Flush) { GraphicsAllocation *allocateGraphicsMemoryForHostPtr(size_t size, void *ptr, bool fullRangeSvm, bool requiresL3Flush) {

View File

@@ -49,6 +49,15 @@ struct CommandStreamReceiverTest : public DeviceFixture,
CommandStreamReceiver *commandStreamReceiver; CommandStreamReceiver *commandStreamReceiver;
}; };
TEST_F(CommandStreamReceiverTest, whenCommandStreamReceiverIsSetAsSpecialCommandStreamReceiverInExecutionEnvironmentThenItIsMulitOsContextCapable) {
EXPECT_FALSE(commandStreamReceiver->isMultiOsContextCapable());
auto executionEnvironment = pDevice->getExecutionEnvironment();
executionEnvironment->specialCommandStreamReceiver.reset(commandStreamReceiver);
EXPECT_TRUE(commandStreamReceiver->isMultiOsContextCapable());
executionEnvironment->specialCommandStreamReceiver.release();
}
HWTEST_F(CommandStreamReceiverTest, testCtor) { HWTEST_F(CommandStreamReceiverTest, testCtor) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
EXPECT_EQ(0u, csr.peekTaskLevel()); EXPECT_EQ(0u, csr.peekTaskLevel());

View File

@@ -80,6 +80,20 @@ TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesCommandStrea
EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0].get()); EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0].get());
} }
TEST(ExecutionEnvironment, whenPlatformIsInitializedThenOnlySpecialCommandStreamReceiverIsMultiOsContextCapable) {
Platform platform;
auto executionEnvironment = platform.peekExecutionEnvironment();
platform.initialize();
for (auto &csrContainer : executionEnvironment->commandStreamReceivers) {
for (auto &csr : csrContainer) {
EXPECT_FALSE(csr->isMultiOsContextCapable());
}
}
if (executionEnvironment->specialCommandStreamReceiver) {
EXPECT_TRUE(executionEnvironment->specialCommandStreamReceiver->isMultiOsContextCapable());
}
}
TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManagerInExecutionEnvironment) { TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManagerInExecutionEnvironment) {
Platform platform; Platform platform;
auto executionEnvironment = platform.peekExecutionEnvironment(); auto executionEnvironment = platform.peekExecutionEnvironment();