1 /*
2 * Copyright (C) 2020-2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/device/device.h"
9 #include "shared/source/gmm_helper/gmm_helper.h"
10 #include "shared/test/common/helpers/debug_manager_state_restore.h"
11 #include "shared/test/common/test_macros/test.h"
12
13 #include "opencl/source/cl_device/cl_device.h"
14 #include "opencl/source/mem_obj/buffer.h"
15 #include "opencl/test/unit_test/mocks/mock_context.h"
16
17 using namespace NEO;
18
19 struct BufferTestsTgllp : ::testing::Test {
SetUpBufferTestsTgllp20 void SetUp() override {
21 context = std::make_unique<MockContext>();
22 device = context->getDevice(0);
23 }
24
25 std::unique_ptr<MockContext> context{};
26 ClDevice *device{};
27
28 cl_int retVal = CL_SUCCESS;
29 };
30
GEN12LPTEST_F(BufferTestsTgllp,givenBufferNotReadonlyWhenProgrammingSurfaceStateThenUseL3)31 GEN12LPTEST_F(BufferTestsTgllp, givenBufferNotReadonlyWhenProgrammingSurfaceStateThenUseL3) {
32 auto buffer = std::unique_ptr<Buffer>(Buffer::create(
33 context.get(),
34 CL_MEM_READ_WRITE,
35 MemoryConstants::pageSize,
36 nullptr,
37 retVal));
38 ASSERT_EQ(CL_SUCCESS, retVal);
39
40 typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
41 buffer->setArgStateful(&surfaceState, false, false, false, false, device->getDevice(), false, 1u);
42
43 const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER);
44 const auto actualMocs = surfaceState.getMemoryObjectControlState();
45 EXPECT_EQ(expectedMocs, actualMocs);
46 }
47
GEN12LPTEST_F(BufferTestsTgllp,givenBufferReadonlyWhenProgrammingSurfaceStateThenUseL1)48 GEN12LPTEST_F(BufferTestsTgllp, givenBufferReadonlyWhenProgrammingSurfaceStateThenUseL1) {
49 auto buffer = std::unique_ptr<Buffer>(Buffer::create(
50 context.get(),
51 CL_MEM_READ_WRITE,
52 MemoryConstants::pageSize,
53 nullptr,
54 retVal));
55 ASSERT_EQ(CL_SUCCESS, retVal);
56
57 typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
58 buffer->setArgStateful(&surfaceState, false, false, false, true, context->getDevice(0)->getDevice(), false, 1u);
59
60 const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST);
61 const auto actualMocs = surfaceState.getMemoryObjectControlState();
62 EXPECT_EQ(expectedMocs, actualMocs);
63 }
64
GEN12LPTEST_F(BufferTestsTgllp,givenConstantSurfaceWhenProgrammingSurfaceStateThenUseL1)65 GEN12LPTEST_F(BufferTestsTgllp, givenConstantSurfaceWhenProgrammingSurfaceStateThenUseL1) {
66 auto buffer = std::unique_ptr<Buffer>(Buffer::create(
67 context.get(),
68 CL_MEM_READ_WRITE,
69 MemoryConstants::pageSize,
70 nullptr,
71 retVal));
72 ASSERT_EQ(CL_SUCCESS, retVal);
73 buffer->getGraphicsAllocation(0)->setAllocationType(GraphicsAllocation::AllocationType::CONSTANT_SURFACE);
74
75 typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
76 buffer->setArgStateful(&surfaceState, false, false, false, false, context->getDevice(0)->getDevice(), false, 1u);
77
78 const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST);
79 const auto actualMocs = surfaceState.getMemoryObjectControlState();
80 EXPECT_EQ(expectedMocs, actualMocs);
81 }
82
GEN12LPTEST_F(BufferTestsTgllp,givenL1ForceEnabledWhenProgrammingSurfaceStateThenUseL1)83 GEN12LPTEST_F(BufferTestsTgllp, givenL1ForceEnabledWhenProgrammingSurfaceStateThenUseL1) {
84 DebugManagerStateRestore restore{};
85 DebugManager.flags.ForceL1Caching.set(1);
86
87 auto buffer = std::unique_ptr<Buffer>(Buffer::create(
88 context.get(),
89 CL_MEM_READ_WRITE,
90 MemoryConstants::pageSize,
91 nullptr,
92 retVal));
93 ASSERT_EQ(CL_SUCCESS, retVal);
94
95 typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
96 buffer->setArgStateful(&surfaceState, false, false, false, false, device->getDevice(), false, 1u);
97
98 const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST);
99 const auto actualMocs = surfaceState.getMemoryObjectControlState();
100 EXPECT_EQ(expectedMocs, actualMocs);
101 }
102
GEN12LPTEST_F(BufferTestsTgllp,givenBufferReadonlyL1ForceDisabledWhenProgrammingSurfaceStateThenUseL3)103 GEN12LPTEST_F(BufferTestsTgllp, givenBufferReadonlyL1ForceDisabledWhenProgrammingSurfaceStateThenUseL3) {
104 DebugManagerStateRestore restore{};
105 DebugManager.flags.ForceL1Caching.set(0);
106
107 auto buffer = std::unique_ptr<Buffer>(Buffer::create(
108 context.get(),
109 CL_MEM_READ_WRITE,
110 MemoryConstants::pageSize,
111 nullptr,
112 retVal));
113 ASSERT_EQ(CL_SUCCESS, retVal);
114
115 typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
116 buffer->setArgStateful(&surfaceState, false, false, false, true, device->getDevice(), false, 1u);
117
118 const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER);
119 const auto actualMocs = surfaceState.getMemoryObjectControlState();
120 EXPECT_EQ(expectedMocs, actualMocs);
121 }
122