Add support for L3 cache information

Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek
2021-01-29 22:23:06 +00:00
committed by Compute-Runtime-Automation
parent e64f3db55c
commit d399613f25
15 changed files with 189 additions and 5 deletions

View File

@ -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

View File

@ -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));
}

View File

@ -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>();
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>();
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>();
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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <stddef.h>
#include <stdint.h>
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

View File

@ -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

View File

@ -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<uint64_t>((static_cast<DrmMemoryManager *>(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<BufferObject *> *bufferObjects, bool bind) {
if (this->fragmentsStorage.fragmentCount) {
for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) {

View File

@ -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; }

View File

@ -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<std::array<bool, EngineLimits::maxHandleCount>> bindInfo;
StackVec<uint32_t, 2> bindExtHandles;
};

View File

@ -314,6 +314,8 @@ int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWo
device->setupHardwareInfo(hwInfo, setupFeatureTableAndWorkaroundTable);
setupCacheInfo(*hwInfo);
return 0;
}

View File

@ -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<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);
std::unique_ptr<SystemInfo> systemInfo;
std::unique_ptr<CacheInfo> cacheInfo;
std::unique_ptr<EngineInfo> engineInfo;
std::unique_ptr<MemoryInfo> memoryInfo;
std::vector<uint32_t> virtualMemoryIds;

View File

@ -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

View File

@ -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