diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 128c6655c1..1663ab8673 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -103,7 +103,7 @@ void CommandStreamReceiver::makeSurfacePackNonResident(ResidencyContainer &alloc void CommandStreamReceiver::makeResidentHostPtrAllocation(GraphicsAllocation *gfxAllocation) { makeResident(*gfxAllocation); - if (!gfxAllocation->isL3Capable()) { + if (!isL3Capable(*gfxAllocation)) { setDisableL3Cache(true); } } diff --git a/runtime/helpers/cache_policy.cpp b/runtime/helpers/cache_policy.cpp index 7b6a890af1..9f4b083447 100644 --- a/runtime/helpers/cache_policy.cpp +++ b/runtime/helpers/cache_policy.cpp @@ -8,6 +8,9 @@ #include "runtime/helpers/cache_policy.h" #include "runtime/helpers/aligned_memory.h" +#include "runtime/memory_manager/graphics_allocation.h" + +namespace OCLRT { bool isL3Capable(void *ptr, size_t size) { if (alignUp(ptr, MemoryConstants::cacheLineSize) == ptr && @@ -15,4 +18,11 @@ bool isL3Capable(void *ptr, size_t size) { return true; } return false; -} \ No newline at end of file +} + +bool isL3Capable(const OCLRT::GraphicsAllocation &graphicsAllocation) { + auto ptr = ptrOffset(graphicsAllocation.getUnderlyingBuffer(), static_cast(graphicsAllocation.allocationOffset)); + return isL3Capable(ptr, graphicsAllocation.getUnderlyingBufferSize()); +} + +} // namespace OCLRT diff --git a/runtime/helpers/cache_policy.h b/runtime/helpers/cache_policy.h index b734cf1e20..aeb776f477 100644 --- a/runtime/helpers/cache_policy.h +++ b/runtime/helpers/cache_policy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,4 +14,8 @@ constexpr uint32_t l3CacheOff = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGN constexpr uint32_t unknownMocs = GMM_RESOURCE_USAGE_UNKNOWN; } // namespace CacheSettings -bool isL3Capable(void *ptr, size_t size); \ No newline at end of file +namespace OCLRT { +class GraphicsAllocation; +bool isL3Capable(void *ptr, size_t size); +bool isL3Capable(const GraphicsAllocation &graphicsAllocation); +} // namespace OCLRT diff --git a/runtime/memory_manager/graphics_allocation.cpp b/runtime/memory_manager/graphics_allocation.cpp index fe26751b6a..fb80678f82 100644 --- a/runtime/memory_manager/graphics_allocation.cpp +++ b/runtime/memory_manager/graphics_allocation.cpp @@ -17,14 +17,6 @@ void GraphicsAllocation::setAllocationType(AllocationType allocationType) { this->allocationType = allocationType; } -bool GraphicsAllocation::isL3Capable() { - auto ptr = ptrOffset(cpuPtr, static_cast(this->allocationOffset)); - if (alignUp(ptr, MemoryConstants::cacheLineSize) == ptr && alignUp(this->size, MemoryConstants::cacheLineSize) == this->size) { - return true; - } - return false; -} - GraphicsAllocation::GraphicsAllocation(AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) : gpuBaseAddress(baseAddress), diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 5a08cf843a..735293916c 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -127,7 +127,6 @@ class GraphicsAllocation : public IDNode { bool isMemObjectsAllocationWithWritableFlags() const { return memObjectsAllocationWithWritableFlags; } void setMemObjectsAllocationWithWritableFlags(bool newValue) { memObjectsAllocationWithWritableFlags = newValue; } - bool isL3Capable(); void setEvictable(bool evictable) { this->evictable = evictable; } bool peekEvictable() const { return evictable; } diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index ae41f6e097..c1c7d05bdb 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -7,6 +7,7 @@ #include "runtime/command_stream/preemption.h" #include "runtime/event/event.h" +#include "runtime/helpers/cache_policy.h" #include "runtime/helpers/dispatch_info.h" #include "runtime/helpers/kernel_commands.h" #include "runtime/mem_obj/image.h" @@ -225,7 +226,7 @@ TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndCacheAlignedSizeWhenAskedForL3 auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr); - EXPECT_TRUE(graphicsAllocation->isL3Capable()); + EXPECT_TRUE(isL3Capable(*graphicsAllocation)); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -236,7 +237,7 @@ TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndNotCacheAlignedSizeWhenAskedFo auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr); - EXPECT_FALSE(graphicsAllocation->isL3Capable()); + EXPECT_FALSE(isL3Capable(*graphicsAllocation)); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -247,7 +248,7 @@ TEST_F(MemoryAllocatorTest, GivenMisAlignedHostPtrAndNotCacheAlignedSizeWhenAske auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr); - EXPECT_FALSE(graphicsAllocation->isL3Capable()); + EXPECT_FALSE(isL3Capable(*graphicsAllocation)); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -258,7 +259,7 @@ TEST_F(MemoryAllocatorTest, GivenHostPtrAlignedToCacheLineWhenAskedForL3Allowanc auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr); - EXPECT_TRUE(graphicsAllocation->isL3Capable()); + EXPECT_TRUE(isL3Capable(*graphicsAllocation)); memoryManager->freeGraphicsMemory(graphicsAllocation); }