Skip to content

Commit d399613

Browse files
Add support for L3 cache information
Signed-off-by: Slawomir Milczarek <[email protected]>
1 parent e64f3db commit d399613

File tree

15 files changed

+189
-5
lines changed

15 files changed

+189
-5
lines changed

opencl/test/unit_test/os_interface/linux/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2018-2020 Intel Corporation
2+
# Copyright (C) 2018-2021 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -14,6 +14,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux
1414
${CMAKE_CURRENT_SOURCE_DIR}/device_os_tests.cpp
1515
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp
1616
${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object_tests.cpp
17+
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_cache_info_tests.cpp
1718
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_mm_tests.cpp
1819
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests.cpp
1920
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_debug_tests.cpp
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2020-2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/linux/cache_info_impl.h"
9+
10+
#include "gtest/gtest.h"
11+
12+
using namespace NEO;
13+
14+
TEST(DrmCacheInfoTest, givenCacheInfoCreatedWhenCallingGetCacheRegionThenReturnZero) {
15+
CacheInfoImpl cacheInfo;
16+
17+
EXPECT_FALSE(cacheInfo.getCacheRegion(1024, CacheRegion::Default));
18+
}

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "opencl/test/unit_test/mocks/mock_gmm.h"
4141
#include "opencl/test/unit_test/mocks/mock_platform.h"
4242
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
43+
#include "opencl/test/unit_test/os_interface/linux/drm_mock_cache_info.h"
4344
#include "test.h"
4445

4546
#include "drm/i915_drm.h"
@@ -4183,4 +4184,48 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC
41834184
allocation.freeRegisteredBOBindExtHandles(&drm);
41844185
EXPECT_EQ(2u, drm.unregisterCalledCount);
41854186
}
4187+
4188+
TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) {
4189+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4190+
executionEnvironment->prepareRootDeviceEnvironments(1);
4191+
4192+
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
4193+
drm.cacheInfo.reset(new MockCacheInfo());
4194+
4195+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
4196+
4197+
EXPECT_FALSE(allocation.setCacheRegion(&drm, 1024, CacheRegion::None));
4198+
}
4199+
4200+
TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenReturnTrue) {
4201+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4202+
executionEnvironment->prepareRootDeviceEnvironments(1);
4203+
4204+
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
4205+
drm.cacheInfo.reset(new MockCacheInfo());
4206+
4207+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
4208+
4209+
EXPECT_TRUE(allocation.setCacheRegion(&drm, 1024, CacheRegion::Region1));
4210+
}
4211+
4212+
TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSetRegionInBufferObject) {
4213+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4214+
executionEnvironment->prepareRootDeviceEnvironments(1);
4215+
4216+
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
4217+
drm.cacheInfo.reset(new MockCacheInfo());
4218+
4219+
MockBufferObject bo(&drm, 0, 0, 1);
4220+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
4221+
allocation.bufferObjects[0] = &bo;
4222+
4223+
EXPECT_TRUE(allocation.setCacheRegion(&drm, 1024, CacheRegion::Region1));
4224+
4225+
for (auto bo : allocation.bufferObjects) {
4226+
if (bo != nullptr) {
4227+
EXPECT_EQ(CacheRegion::Region1, bo->peekCacheRegion());
4228+
}
4229+
}
4230+
}
41864231
} // namespace NEO

opencl/test/unit_test/os_interface/linux/drm_mock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using namespace NEO;
3030
class DrmMock : public Drm {
3131
public:
3232
using Drm::bindAvailable;
33+
using Drm::cacheInfo;
3334
using Drm::checkQueueSliceSupport;
3435
using Drm::classHandles;
3536
using Drm::contextDebugSupported;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "shared/source/os_interface/linux/cache_info.h"
11+
12+
namespace NEO {
13+
14+
struct MockCacheInfo : public CacheInfo {
15+
MockCacheInfo() {}
16+
17+
~MockCacheInfo() override = default;
18+
19+
bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) override {
20+
return (regionIndex > CacheRegion::None) ? true : false;
21+
}
22+
};
23+
24+
} // namespace NEO

shared/source/os_interface/linux/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
set(NEO_CORE_OS_INTERFACE_LINUX
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
99
${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper.h
10+
${CMAKE_CURRENT_SOURCE_DIR}/cache_info.h
11+
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/cache_info_impl.h
1012
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.cpp
1113
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_linux.h
1214
${CMAKE_CURRENT_SOURCE_DIR}/drm_allocation.cpp
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include <stddef.h>
11+
#include <stdint.h>
12+
13+
namespace NEO {
14+
15+
enum class CacheRegion : uint16_t {
16+
None = 0,
17+
Region1,
18+
Region2,
19+
Default = None
20+
};
21+
22+
struct CacheInfo {
23+
CacheInfo() = default;
24+
virtual ~CacheInfo() = 0;
25+
26+
virtual bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) = 0;
27+
};
28+
29+
inline CacheInfo::~CacheInfo(){};
30+
31+
} // namespace NEO
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "shared/source/os_interface/linux/cache_info.h"
11+
12+
namespace NEO {
13+
14+
struct CacheInfoImpl : public CacheInfo {
15+
CacheInfoImpl() {}
16+
17+
~CacheInfoImpl() override = default;
18+
19+
bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) override { return false; }
20+
};
21+
22+
} // namespace NEO

shared/source/os_interface/linux/drm_allocation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -29,6 +29,19 @@ uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
2929
return static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex));
3030
}
3131

32+
bool DrmAllocation::setCacheRegion(Drm *drm, size_t regionSize, CacheRegion regionIndex) {
33+
if (!drm->getCacheInfo()->getCacheRegion(regionSize, regionIndex)) {
34+
return false;
35+
}
36+
37+
for (auto bo : bufferObjects) {
38+
if (bo != nullptr) {
39+
bo->setCacheRegion(regionIndex);
40+
}
41+
}
42+
return true;
43+
}
44+
3245
void DrmAllocation::makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
3346
if (this->fragmentsStorage.fragmentCount) {
3447
for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) {

shared/source/os_interface/linux/drm_allocation.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -13,6 +13,7 @@ namespace NEO {
1313
class BufferObject;
1414
class OsContext;
1515
class Drm;
16+
enum class CacheRegion : uint16_t;
1617

1718
struct OsHandle {
1819
BufferObject *bo = nullptr;
@@ -63,6 +64,8 @@ class DrmAllocation : public GraphicsAllocation {
6364

6465
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
6566

67+
bool setCacheRegion(Drm *drm, size_t regionSize, CacheRegion regionIndex);
68+
6669
void *getMmapPtr() { return this->mmapPtr; }
6770
void setMmapPtr(void *ptr) { this->mmapPtr = ptr; }
6871
size_t getMmapSize() { return this->mmapSize; }

0 commit comments

Comments
 (0)