From d399613f250eb20eef986584f3e87af54031df27 Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Fri, 29 Jan 2021 22:23:06 +0000 Subject: [PATCH] Add support for L3 cache information Signed-off-by: Slawomir Milczarek --- .../os_interface/linux/CMakeLists.txt | 3 +- .../linux/drm_cache_info_tests.cpp | 18 ++++++++ .../linux/drm_memory_manager_tests.cpp | 45 +++++++++++++++++++ .../unit_test/os_interface/linux/drm_mock.h | 1 + .../os_interface/linux/drm_mock_cache_info.h | 24 ++++++++++ .../source/os_interface/linux/CMakeLists.txt | 2 + shared/source/os_interface/linux/cache_info.h | 31 +++++++++++++ .../os_interface/linux/cache_info_impl.h | 22 +++++++++ .../os_interface/linux/drm_allocation.cpp | 15 ++++++- .../os_interface/linux/drm_allocation.h | 5 ++- .../os_interface/linux/drm_buffer_object.h | 5 +++ shared/source/os_interface/linux/drm_neo.cpp | 2 + shared/source/os_interface/linux/drm_neo.h | 7 +++ .../source/os_interface/linux/drm_query.cpp | 7 ++- .../os_interface/linux/drm_query_dg1.cpp | 7 ++- 15 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 opencl/test/unit_test/os_interface/linux/drm_cache_info_tests.cpp create mode 100644 opencl/test/unit_test/os_interface/linux/drm_mock_cache_info.h create mode 100644 shared/source/os_interface/linux/cache_info.h create mode 100644 shared/source/os_interface/linux/cache_info_impl.h diff --git a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt index baf1dc7b2a..6096a737a3 100644 --- a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018-2020 Intel Corporation +# Copyright (C) 2018-2021 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -14,6 +14,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/device_os_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_cache_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_mm_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_debug_tests.cpp diff --git a/opencl/test/unit_test/os_interface/linux/drm_cache_info_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_cache_info_tests.cpp new file mode 100644 index 0000000000..df2b9a85b1 --- /dev/null +++ b/opencl/test/unit_test/os_interface/linux/drm_cache_info_tests.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2020-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/cache_info_impl.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +TEST(DrmCacheInfoTest, givenCacheInfoCreatedWhenCallingGetCacheRegionThenReturnZero) { + CacheInfoImpl cacheInfo; + + EXPECT_FALSE(cacheInfo.getCacheRegion(1024, CacheRegion::Default)); +} diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index b815c19f86..7cc91d9000 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -40,6 +40,7 @@ #include "opencl/test/unit_test/mocks/mock_gmm.h" #include "opencl/test/unit_test/mocks/mock_platform.h" #include "opencl/test/unit_test/os_interface/linux/drm_mock.h" +#include "opencl/test/unit_test/os_interface/linux/drm_mock_cache_info.h" #include "test.h" #include "drm/i915_drm.h" @@ -4183,4 +4184,48 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC allocation.freeRegisteredBOBindExtHandles(&drm); EXPECT_EQ(2u, drm.unregisterCalledCount); } + +TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + + DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + drm.cacheInfo.reset(new MockCacheInfo()); + + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory); + + EXPECT_FALSE(allocation.setCacheRegion(&drm, 1024, CacheRegion::None)); +} + +TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenReturnTrue) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + + DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + drm.cacheInfo.reset(new MockCacheInfo()); + + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory); + + EXPECT_TRUE(allocation.setCacheRegion(&drm, 1024, CacheRegion::Region1)); +} + +TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSetRegionInBufferObject) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + + DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + drm.cacheInfo.reset(new MockCacheInfo()); + + MockBufferObject bo(&drm, 0, 0, 1); + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory); + allocation.bufferObjects[0] = &bo; + + EXPECT_TRUE(allocation.setCacheRegion(&drm, 1024, CacheRegion::Region1)); + + for (auto bo : allocation.bufferObjects) { + if (bo != nullptr) { + EXPECT_EQ(CacheRegion::Region1, bo->peekCacheRegion()); + } + } +} } // namespace NEO diff --git a/opencl/test/unit_test/os_interface/linux/drm_mock.h b/opencl/test/unit_test/os_interface/linux/drm_mock.h index be032ff85e..b83777ebf8 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_mock.h +++ b/opencl/test/unit_test/os_interface/linux/drm_mock.h @@ -30,6 +30,7 @@ using namespace NEO; class DrmMock : public Drm { public: using Drm::bindAvailable; + using Drm::cacheInfo; using Drm::checkQueueSliceSupport; using Drm::classHandles; using Drm::contextDebugSupported; diff --git a/opencl/test/unit_test/os_interface/linux/drm_mock_cache_info.h b/opencl/test/unit_test/os_interface/linux/drm_mock_cache_info.h new file mode 100644 index 0000000000..16f6ce351d --- /dev/null +++ b/opencl/test/unit_test/os_interface/linux/drm_mock_cache_info.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/os_interface/linux/cache_info.h" + +namespace NEO { + +struct MockCacheInfo : public CacheInfo { + MockCacheInfo() {} + + ~MockCacheInfo() override = default; + + bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) override { + return (regionIndex > CacheRegion::None) ? true : false; + } +}; + +} // namespace NEO diff --git a/shared/source/os_interface/linux/CMakeLists.txt b/shared/source/os_interface/linux/CMakeLists.txt index 9533e70b4e..ede6810094 100644 --- a/shared/source/os_interface/linux/CMakeLists.txt +++ b/shared/source/os_interface/linux/CMakeLists.txt @@ -7,6 +7,8 @@ set(NEO_CORE_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper.h + ${CMAKE_CURRENT_SOURCE_DIR}/cache_info.h + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/cache_info_impl.h ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_allocation.cpp diff --git a/shared/source/os_interface/linux/cache_info.h b/shared/source/os_interface/linux/cache_info.h new file mode 100644 index 0000000000..c778c52132 --- /dev/null +++ b/shared/source/os_interface/linux/cache_info.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include +#include + +namespace NEO { + +enum class CacheRegion : uint16_t { + None = 0, + Region1, + Region2, + Default = None +}; + +struct CacheInfo { + CacheInfo() = default; + virtual ~CacheInfo() = 0; + + virtual bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) = 0; +}; + +inline CacheInfo::~CacheInfo(){}; + +} // namespace NEO diff --git a/shared/source/os_interface/linux/cache_info_impl.h b/shared/source/os_interface/linux/cache_info_impl.h new file mode 100644 index 0000000000..220afed2a3 --- /dev/null +++ b/shared/source/os_interface/linux/cache_info_impl.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/os_interface/linux/cache_info.h" + +namespace NEO { + +struct CacheInfoImpl : public CacheInfo { + CacheInfoImpl() {} + + ~CacheInfoImpl() override = default; + + bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) override { return false; } +}; + +} // namespace NEO diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 5998426687..a94062d075 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,6 +29,19 @@ uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) { return static_cast((static_cast(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex)); } +bool DrmAllocation::setCacheRegion(Drm *drm, size_t regionSize, CacheRegion regionIndex) { + if (!drm->getCacheInfo()->getCacheRegion(regionSize, regionIndex)) { + return false; + } + + for (auto bo : bufferObjects) { + if (bo != nullptr) { + bo->setCacheRegion(regionIndex); + } + } + return true; +} + void DrmAllocation::makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector *bufferObjects, bool bind) { if (this->fragmentsStorage.fragmentCount) { for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) { diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index df2e753f0e..18602f6c97 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,6 +13,7 @@ namespace NEO { class BufferObject; class OsContext; class Drm; +enum class CacheRegion : uint16_t; struct OsHandle { BufferObject *bo = nullptr; @@ -63,6 +64,8 @@ class DrmAllocation : public GraphicsAllocation { uint64_t peekInternalHandle(MemoryManager *memoryManager) override; + bool setCacheRegion(Drm *drm, size_t regionSize, CacheRegion regionIndex); + void *getMmapPtr() { return this->mmapPtr; } void setMmapPtr(void *ptr) { this->mmapPtr = ptr; } size_t getMmapSize() { return this->mmapSize; } diff --git a/shared/source/os_interface/linux/drm_buffer_object.h b/shared/source/os_interface/linux/drm_buffer_object.h index f9ee2c10c3..c540d07eab 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.h +++ b/shared/source/os_interface/linux/drm_buffer_object.h @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/os_interface/linux/cache_info.h" #include "shared/source/utilities/stackvec.h" #include "drm/i915_drm.h" @@ -78,6 +79,8 @@ class BufferObject { bool isMarkedForCapture() { return allowCapture; } + void setCacheRegion(CacheRegion regionIndex) { cacheRegion = regionIndex; } + CacheRegion peekCacheRegion() const { return cacheRegion; } protected: Drm *drm = nullptr; @@ -102,6 +105,8 @@ class BufferObject { uint64_t unmapSize = 0; + CacheRegion cacheRegion = CacheRegion::Default; + std::vector> bindInfo; StackVec bindExtHandles; }; diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 699e200d75..54a72245fb 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -314,6 +314,8 @@ int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWo device->setupHardwareInfo(hwInfo, setupFeatureTableAndWorkaroundTable); + setupCacheInfo(*hwInfo); + return 0; } diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index 48b747ac24..b7c16da734 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -7,6 +7,7 @@ #pragma once #include "shared/source/helpers/basic_math.h" +#include "shared/source/os_interface/linux/cache_info.h" #include "shared/source/os_interface/linux/engine_info.h" #include "shared/source/os_interface/linux/hw_device_id.h" #include "shared/source/os_interface/linux/memory_info.h" @@ -108,6 +109,7 @@ class Drm { int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo); int setupHardwareInfo(DeviceDescriptor *, bool); void setupSystemInfo(HardwareInfo *hwInfo, SystemInfo &sysInfo); + void setupCacheInfo(const HardwareInfo &hwInfo); bool areNonPersistentContextsSupported() const { return nonPersistentContextsSupported; } void checkNonPersistentContextsSupport(); @@ -134,6 +136,10 @@ class Drm { return systemInfo.get(); } + CacheInfo *getCacheInfo() const { + return cacheInfo.get(); + } + MemoryInfo *getMemoryInfo() const { return memoryInfo.get(); } @@ -185,6 +191,7 @@ class Drm { Drm(std::unique_ptr hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment); std::unique_ptr systemInfo; + std::unique_ptr cacheInfo; std::unique_ptr engineInfo; std::unique_ptr memoryInfo; std::vector virtualMemoryIds; diff --git a/shared/source/os_interface/linux/drm_query.cpp b/shared/source/os_interface/linux/drm_query.cpp index 034540bacd..2e42f98a34 100644 --- a/shared/source/os_interface/linux/drm_query.cpp +++ b/shared/source/os_interface/linux/drm_query.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "shared/source/os_interface/linux/cache_info_impl.h" #include "shared/source/os_interface/linux/drm_engine_mapper.h" #include "shared/source/os_interface/linux/engine_info_impl.h" @@ -66,4 +67,8 @@ bool Drm::isVmBindAvailable() { return this->bindAvailable; } +void Drm::setupCacheInfo(const HardwareInfo &hwInfo) { + this->cacheInfo.reset(new CacheInfoImpl()); +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_query_dg1.cpp b/shared/source/os_interface/linux/drm_query_dg1.cpp index 2d27ac13f9..2cf828e646 100644 --- a/shared/source/os_interface/linux/drm_query_dg1.cpp +++ b/shared/source/os_interface/linux/drm_query_dg1.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "shared/source/os_interface/linux/cache_info_impl.h" #include "shared/source/os_interface/linux/drm_engine_mapper.h" #include "shared/source/os_interface/linux/engine_info_impl.h" #include "shared/source/os_interface/linux/memory_info_impl.h" @@ -75,4 +76,8 @@ bool Drm::isVmBindAvailable() { return this->bindAvailable; } +void Drm::setupCacheInfo(const HardwareInfo &hwInfo) { + this->cacheInfo.reset(new CacheInfoImpl()); +} + } // namespace NEO