Skip to content

Commit a31c446

Browse files
Allocate non USE_HOST_PTR and non-buffer images in preferred pool.
Change-Id: Ia486c7b32932202162d6587d06dc61023e38fff6
1 parent 883822c commit a31c446

File tree

11 files changed

+117
-42
lines changed

11 files changed

+117
-42
lines changed

runtime/mem_obj/image.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "runtime/helpers/string.h"
2424
#include "runtime/helpers/surface_formats.h"
2525
#include "runtime/mem_obj/buffer.h"
26+
#include "runtime/mem_obj/mem_obj_helper.h"
2627
#include "runtime/memory_manager/memory_manager.h"
2728
#include "runtime/os_interface/debug_settings_manager.h"
2829
#include <map>
@@ -227,7 +228,13 @@ Image *Image::create(Context *context,
227228
}
228229

229230
} else {
230-
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr);
231+
MemoryProperties properties = {};
232+
properties.flags = flags;
233+
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(&imgInfo);
234+
DevicesBitfield devices = MemObjHelper::getDevicesBitfield(properties);
235+
236+
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, nullptr);
237+
231238
if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
232239
zeroCopy = true;
233240
}
@@ -324,7 +331,7 @@ Image *Image::create(Context *context,
324331
copyRegion = {{imageWidth, imageHeight, std::max(imageDepth, imageCount)}};
325332
}
326333

327-
if (isTilingAllowed) {
334+
if (isTilingAllowed || !MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
328335
auto cmdQ = context->getSpecialQueue();
329336

330337
if (IsNV12Image(&image->getImageFormat())) {

runtime/mem_obj/mem_obj_helper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel fl
3737
return AllocationProperties(allocateMemory, size, type);
3838
}
3939

40+
AllocationProperties MemObjHelper::getAllocationProperties(ImageInfo *imgInfo) {
41+
return AllocationProperties(imgInfo);
42+
}
43+
4044
DevicesBitfield MemObjHelper::getDevicesBitfield(const MemoryProperties &properties) {
4145
return DevicesBitfield(0);
4246
}

runtime/mem_obj/mem_obj_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class MemObjHelper {
5151
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
5252

5353
static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type);
54+
static AllocationProperties getAllocationProperties(ImageInfo *imgInfo);
5455

5556
static DevicesBitfield getDevicesBitfield(const MemoryProperties &properties);
5657

runtime/memory_manager/memory_manager.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "runtime/event/event.h"
1111
#include "runtime/event/hw_timestamps.h"
1212
#include "runtime/event/perf_counter.h"
13+
#include "runtime/gmm_helper/gmm.h"
1314
#include "runtime/helpers/aligned_memory.h"
1415
#include "runtime/helpers/basic_math.h"
1516
#include "runtime/helpers/kernel_commands.h"
@@ -273,6 +274,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
273274
allocationData.type = properties.allocationType;
274275
allocationData.devicesBitfield = devicesBitfield;
275276
allocationData.alignment = properties.alignment ? properties.alignment : MemoryConstants::preferredAlignment;
277+
allocationData.imgInfo = properties.imgInfo;
276278

277279
if (allocationData.flags.allocateMemory) {
278280
allocationData.hostPtr = nullptr;
@@ -285,7 +287,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(Allocat
285287
AllocationStatus status = AllocationStatus::Error;
286288

287289
getAllocationData(allocationData, properties, devicesBitfield, hostPtr);
288-
UNRECOVERABLE_IF(allocationData.type == GraphicsAllocation::AllocationType::IMAGE || allocationData.type == GraphicsAllocation::AllocationType::SHARED_RESOURCE);
290+
UNRECOVERABLE_IF(allocationData.type == GraphicsAllocation::AllocationType::SHARED_RESOURCE);
289291
GraphicsAllocation *allocation = nullptr;
290292

291293
allocation = allocateGraphicsMemoryInDevicePool(allocationData, status);
@@ -295,10 +297,16 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(Allocat
295297
if (allocation) {
296298
allocation->setAllocationType(properties.allocationType);
297299
}
300+
298301
return allocation;
299302
}
300303

301304
GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &allocationData) {
305+
if (allocationData.type == GraphicsAllocation::AllocationType::IMAGE) {
306+
UNRECOVERABLE_IF(allocationData.imgInfo == nullptr);
307+
return allocateGraphicsMemoryForImage(*allocationData.imgInfo, allocationData.hostPtr);
308+
}
309+
302310
if (force32bitAllocations && allocationData.flags.allow32Bit && is64bit) {
303311
return allocate32BitGraphicsMemory(allocationData.size, allocationData.hostPtr, AllocationOrigin::EXTERNAL_ALLOCATION);
304312
}

runtime/memory_manager/memory_manager.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
#include <vector>
1818

1919
namespace OCLRT {
20+
class CommandStreamReceiver;
2021
class DeferredDeleter;
2122
class ExecutionEnvironment;
23+
class Gmm;
2224
class GraphicsAllocation;
2325
class HostPtrManager;
24-
class CommandStreamReceiver;
2526
class OsContext;
27+
struct ImageInfo;
28+
2629
enum class PreemptionMode : uint32_t;
2730

2831
using CsrContainer = std::vector<std::array<std::unique_ptr<CommandStreamReceiver>, EngineInstanceConstants::numGpgpuEngineInstances>>;
@@ -54,6 +57,7 @@ struct AllocationProperties {
5457
size_t size = 0;
5558
size_t alignment = 0;
5659
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::UNKNOWN;
60+
ImageInfo *imgInfo = nullptr;
5761

5862
AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(true, size, allocationType) {}
5963
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType) : size(size), allocationType(allocationType) {
@@ -62,6 +66,13 @@ struct AllocationProperties {
6266
flags.flushL3RequiredForWrite = 1;
6367
flags.allocateMemory = allocateMemory;
6468
}
69+
AllocationProperties(ImageInfo *imgInfo) : allocationType(GraphicsAllocation::AllocationType::IMAGE) {
70+
allFlags = 0;
71+
flags.flushL3RequiredForRead = 1;
72+
flags.flushL3RequiredForWrite = 1;
73+
flags.allocateMemory = 1;
74+
this->imgInfo = imgInfo;
75+
}
6576
};
6677

6778
struct AlignedMallocRestrictions {
@@ -70,9 +81,6 @@ struct AlignedMallocRestrictions {
7081

7182
constexpr size_t paddingBufferSize = 2 * MemoryConstants::megaByte;
7283

73-
class Gmm;
74-
struct ImageInfo;
75-
7684
class MemoryManager {
7785
public:
7886
enum AllocationStatus {
@@ -114,8 +122,6 @@ class MemoryManager {
114122

115123
virtual GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, const void *hostPtr) = 0;
116124

117-
GraphicsAllocation *allocateGraphicsMemoryForImageFromHostPtr(ImageInfo &imgInfo, const void *hostPtr);
118-
119125
GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr);
120126

121127
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) = 0;
@@ -213,6 +219,7 @@ class MemoryManager {
213219
size_t size = 0;
214220
size_t alignment = 0;
215221
DevicesBitfield devicesBitfield = 0;
222+
ImageInfo *imgInfo = nullptr;
216223
};
217224

218225
static bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const DevicesBitfield devicesBitfield,
@@ -237,6 +244,7 @@ class MemoryManager {
237244
status = AllocationStatus::RetryInNonDevicePool;
238245
return nullptr;
239246
}
247+
GraphicsAllocation *allocateGraphicsMemoryForImageFromHostPtr(ImageInfo &imgInfo, const void *hostPtr);
240248

241249
bool force32bitAllocations = false;
242250
bool virtualPaddingAvailable = false;

unit_tests/mem_obj/buffer_tests.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,6 @@ INSTANTIATE_TEST_CASE_P(
9494
BufferReadOnlyTest,
9595
testing::ValuesIn(nonReadOnlyFlags));
9696

97-
class GMockMemoryManagerFailFirstAllocation : public MockMemoryManager {
98-
public:
99-
GMockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast<ExecutionEnvironment &>(executionEnvironment)){};
100-
101-
MOCK_METHOD2(allocateGraphicsMemoryInDevicePool, GraphicsAllocation *(const AllocationData &, AllocationStatus &));
102-
GraphicsAllocation *baseAllocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
103-
return OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
104-
}
105-
GraphicsAllocation *allocateNonSystemGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
106-
auto allocation = baseAllocateGraphicsMemoryInDevicePool(allocationData, status);
107-
if (!allocation) {
108-
allocation = allocateGraphicsMemory(allocationData);
109-
}
110-
static_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
111-
return allocation;
112-
}
113-
};
114-
11597
TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsThenBufferHasAllocatedNewMemoryStorageAndBufferIsNotZeroCopy) {
11698
void *memory = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize);
11799
ASSERT_NE(nullptr, memory);
@@ -505,7 +487,7 @@ TEST_F(RenderCompressedBuffersTests, givenSvmAllocationWhenCreatingBufferThenFor
505487
struct RenderCompressedBuffersCopyHostMemoryTests : public RenderCompressedBuffersTests {
506488
void SetUp() override {
507489
RenderCompressedBuffersTests::SetUp();
508-
device->injectMemoryManager(new MockMemoryManager(true));
490+
device->injectMemoryManager(new MockMemoryManager(true, false));
509491
context->setMemoryManager(device->getMemoryManager());
510492
mockCmdQ = new MockCommandQueue();
511493
context->setSpecialQueue(mockCmdQ);

unit_tests/mem_obj/image_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,47 @@ TEST(ImageTest, givenForcedLinearImages3DImageAndProperDescriptorValuesWhenIsCop
12921292
alignedFree(hostPtr);
12931293
}
12941294

1295+
TEST(ImageTest, givenClMemCopyHostPointerPassedToImageCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteImage) {
1296+
ExecutionEnvironment executionEnvironment;
1297+
executionEnvironment.incRefInternal();
1298+
1299+
auto *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>(executionEnvironment);
1300+
executionEnvironment.memoryManager.reset(memoryManager);
1301+
EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_))
1302+
.WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool));
1303+
1304+
std::unique_ptr<MockDevice> device(MockDevice::create<MockDevice>(*platformDevices, &executionEnvironment, 0));
1305+
1306+
MockContext ctx(device.get());
1307+
EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_))
1308+
.WillOnce(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::allocateNonSystemGraphicsMemoryInDevicePool))
1309+
.WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool));
1310+
1311+
char memory[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1312+
auto taskCount = device->getCommandStreamReceiver().peekLatestFlushedTaskCount();
1313+
1314+
cl_int retVal = 0;
1315+
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR;
1316+
1317+
cl_image_desc imageDesc{};
1318+
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
1319+
imageDesc.image_width = 1;
1320+
imageDesc.image_height = 1;
1321+
imageDesc.image_row_pitch = sizeof(memory);
1322+
1323+
cl_image_format imageFormat = {};
1324+
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;
1325+
imageFormat.image_channel_order = CL_R;
1326+
1327+
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
1328+
1329+
std::unique_ptr<Image> image(Image::create(&ctx, flags, surfaceFormat, &imageDesc, memory, retVal));
1330+
EXPECT_NE(nullptr, image);
1331+
1332+
auto taskCountSent = device->getCommandStreamReceiver().peekLatestFlushedTaskCount();
1333+
EXPECT_LT(taskCount, taskCountSent);
1334+
}
1335+
12951336
typedef ::testing::TestWithParam<uint32_t> MipLevelCoordinateTest;
12961337

12971338
TEST_P(MipLevelCoordinateTest, givenMipmappedImageWhenValidateRegionAndOriginIsCalledThenAdditionalOriginCoordinateIsAnalyzed) {

unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, given64kbAllow
120120
MockMemoryManager::getAllocationData(allocData, properties, 0, nullptr);
121121
bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
122122
EXPECT_TRUE(allocData.flags.allow64kbPages);
123-
MockMemoryManager mockMemoryManager(true);
123+
MockMemoryManager mockMemoryManager(true, false);
124124
auto allocation = mockMemoryManager.allocateGraphicsMemory(allocData);
125125

126126
EXPECT_TRUE(mockMemoryManager.allocation64kbPageCreated);
@@ -245,7 +245,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryA
245245
}
246246

247247
TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbPagesFlagsIsAllocatedThenNon64kbAllocationIsReturned) {
248-
MockMemoryManager memoryManager(true);
248+
MockMemoryManager memoryManager(true, false);
249249
AllocationData allocData;
250250
AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER);
251251

@@ -261,7 +261,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbP
261261
}
262262

263263
TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThenNon64kbAllocationIsReturned) {
264-
MockMemoryManager memoryManager(false);
264+
MockMemoryManager memoryManager(false, false);
265265
AllocationData allocData;
266266
AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
267267

@@ -315,7 +315,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHo
315315
}
316316

317317
TEST(MemoryManagerTest, givenMemoryManagerWhenGraphicsMemoryAllocationInDevicePoolFailsThenFallbackAllocationIsReturned) {
318-
MockMemoryManager memoryManager(false);
318+
MockMemoryManager memoryManager(false, true);
319319

320320
memoryManager.failInDevicePool = true;
321321

@@ -328,15 +328,15 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGraphicsMemoryAllocationInDevicePo
328328
}
329329

330330
TEST(MemoryManagerTest, givenMemoryManagerWhenBufferTypeIsPassedThenAllocateGraphicsMemoryInPreferredPoolCanAllocateInDevicePool) {
331-
MockMemoryManager memoryManager(false);
331+
MockMemoryManager memoryManager(false, true);
332332

333333
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
334334
EXPECT_NE(nullptr, allocation);
335335
memoryManager.freeGraphicsMemory(allocation);
336336
}
337337

338338
TEST(MemoryManagerTest, givenMemoryManagerWhenBufferTypeIsPassedAndAllocateInDevicePoolFailsWithErrorThenAllocateGraphicsMemoryInPreferredPoolReturnsNullptr) {
339-
MockMemoryManager memoryManager(false);
339+
MockMemoryManager memoryManager(false, true);
340340

341341
memoryManager.failInDevicePoolWithError = true;
342342

@@ -386,7 +386,7 @@ TEST(MemoryManagerTest, givenTimestampTagBufferTypeWhenGetAllocationDataIsCalled
386386
}
387387

388388
TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
389-
MockMemoryManager memoryManager(false);
389+
MockMemoryManager memoryManager(false, false);
390390
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
391391
properties.flags.shareable = true;
392392

@@ -400,7 +400,7 @@ TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAll
400400
}
401401

402402
TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
403-
MockMemoryManager memoryManager(false);
403+
MockMemoryManager memoryManager(false, false);
404404
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
405405
properties.flags.shareable = false;
406406

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ TEST(OsAgnosticMemoryManager, givenEnabledLocalMemoryWhenAllocateGraphicsMemoryF
581581

582582
TEST(OsAgnosticMemoryManager, givenHostPointerNotRequiringCopyWhenAllocateGraphicsMemoryForImageFromHostPtrIsCalledThenGraphicsAllocationIsReturned) {
583583
ExecutionEnvironment executionEnvironment;
584-
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
584+
MockMemoryManager memoryManager(false, false, executionEnvironment);
585585
executionEnvironment.initGmm(*platformDevices);
586586

587587
cl_image_desc imgDesc = {};
@@ -616,7 +616,7 @@ TEST(OsAgnosticMemoryManager, givenHostPointerNotRequiringCopyWhenAllocateGraphi
616616

617617
TEST(OsAgnosticMemoryManager, givenHostPointerRequiringCopyWhenAllocateGraphicsMemoryForImageFromHostPtrIsCalledThenNullptrIsReturned) {
618618
ExecutionEnvironment executionEnvironment;
619-
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
619+
MockMemoryManager memoryManager(false, false, executionEnvironment);
620620
executionEnvironment.initGmm(*platformDevices);
621621

622622
cl_image_desc imgDesc = {};

unit_tests/mocks/mock_allocation_properties.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
namespace OCLRT {
1212
struct MockAllocationProperties : public AllocationProperties {
1313
public:
14-
using AllocationProperties::AllocationProperties;
15-
14+
MockAllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(size, allocationType) {}
1615
MockAllocationProperties(size_t size) : AllocationProperties(size, GraphicsAllocation::AllocationType::UNDECIDED) {}
1716
MockAllocationProperties(bool allocateMemory, size_t size) : AllocationProperties(allocateMemory, size, GraphicsAllocation::AllocationType::UNDECIDED) {}
1817
};

unit_tests/mocks/mock_memory_manager.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ class MockMemoryManager : public OsAgnosticMemoryManager {
2222
using MemoryManager::AllocationData;
2323
using MemoryManager::getAllocationData;
2424
using MemoryManager::registeredOsContexts;
25+
using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr;
2526
using OsAgnosticMemoryManager::OsAgnosticMemoryManager;
26-
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) {
27+
28+
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MockMemoryManager(false, executionEnvironment) {}
29+
30+
MockMemoryManager(bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, enableLocalMemory, executionEnvironment) {
2731
hostPtrManager.reset(new MockHostPtrManager);
2832
};
33+
2934
MockMemoryManager() : MockMemoryManager(*(new ExecutionEnvironment)) {
3035
mockExecutionEnvironment.reset(&executionEnvironment);
3136
};
32-
MockMemoryManager(bool enable64pages) : OsAgnosticMemoryManager(enable64pages, false, *(new ExecutionEnvironment)) {
37+
MockMemoryManager(bool enable64pages, bool enableLocalMemory) : OsAgnosticMemoryManager(enable64pages, enableLocalMemory, *(new ExecutionEnvironment)) {
3338
mockExecutionEnvironment.reset(&executionEnvironment);
3439
}
3540
GraphicsAllocation *allocateGraphicsMemory64kb(AllocationData allocationData) override;
@@ -152,4 +157,24 @@ class FailMemoryManager : public MockMemoryManager {
152157
}
153158
int32_t failedAllocationsCount = 0;
154159
};
160+
161+
class GMockMemoryManagerFailFirstAllocation : public MockMemoryManager {
162+
public:
163+
GMockMemoryManagerFailFirstAllocation(bool enableLocalMemory, const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(enableLocalMemory, const_cast<ExecutionEnvironment &>(executionEnvironment)){};
164+
GMockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : GMockMemoryManagerFailFirstAllocation(false, executionEnvironment){};
165+
166+
MOCK_METHOD2(allocateGraphicsMemoryInDevicePool, GraphicsAllocation *(const AllocationData &, AllocationStatus &));
167+
GraphicsAllocation *baseAllocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
168+
return OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
169+
}
170+
GraphicsAllocation *allocateNonSystemGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
171+
auto allocation = baseAllocateGraphicsMemoryInDevicePool(allocationData, status);
172+
if (!allocation) {
173+
allocation = allocateGraphicsMemory(allocationData);
174+
}
175+
static_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
176+
return allocation;
177+
}
178+
};
179+
155180
} // namespace OCLRT

0 commit comments

Comments
 (0)