Skip to content

Commit 7c94409

Browse files
Change MemoryManager::allocateGraphicsMemoryInPreferredPool() signature.
Remove allocateMemory param. Add AllocationFlags and DeviceIndex params. Change-Id: I3ba048f8ea9840a047a3222dc1e97be2105c2222
1 parent f1e6fb6 commit 7c94409

File tree

16 files changed

+112
-285
lines changed

16 files changed

+112
-285
lines changed

runtime/command_stream/command_stream_receiver_hw.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,6 @@ void CommandStreamReceiverHw<GfxFamily>::handleEventsTimestampPacketTags(LinearS
794794

795795
template <typename GfxFamily>
796796
void CommandStreamReceiverHw<GfxFamily>::createScratchSpaceAllocation(size_t requiredScratchSizeInBytes) {
797-
scratchAllocation = getMemoryManager()->allocateGraphicsMemoryInPreferredPool(true, nullptr, requiredScratchSizeInBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE);
797+
scratchAllocation = getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, requiredScratchSizeInBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE);
798798
}
799799
} // namespace OCLRT

runtime/kernel/kernel.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
/*
2-
* Copyright (c) 2018, Intel Corporation
2+
* Copyright (C) 2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#include "kernel.h"
@@ -270,7 +255,7 @@ cl_int Kernel::initialize() {
270255
retVal = CL_OUT_OF_RESOURCES;
271256
break;
272257
}
273-
privateSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(true, nullptr, static_cast<size_t>(privateSurfaceSize), GraphicsAllocation::AllocationType::PRIVATE_SURFACE);
258+
privateSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, static_cast<size_t>(privateSurfaceSize), GraphicsAllocation::AllocationType::PRIVATE_SURFACE);
274259
if (privateSurface == nullptr) {
275260
retVal = CL_OUT_OF_RESOURCES;
276261
break;

runtime/mem_obj/buffer.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (C) 2017-2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#include "runtime/mem_obj/buffer.h"
9+
#include "runtime/mem_obj/mem_obj_helper.h"
2410
#include "runtime/command_queue/command_queue.h"
2511
#include "runtime/context/context.h"
2612
#include "runtime/device/device.h"
@@ -161,7 +147,10 @@ Buffer *Buffer::create(Context *context,
161147
}
162148

163149
if (!memory) {
164-
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocateMemory, hostPtr, static_cast<size_t>(size), allocationType);
150+
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(flags);
151+
DeviceIndex deviceIndex = MemObjHelper::getDeviceIndex(flags);
152+
allocFlags.flags.allocateMemory = allocateMemory;
153+
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocFlags, deviceIndex, hostPtr, static_cast<size_t>(size), allocationType);
165154
}
166155

167156
if (allocateMemory) {
@@ -176,8 +165,10 @@ Buffer *Buffer::create(Context *context,
176165
allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
177166
zeroCopyAllowed = false;
178167
copyMemoryFromHostPtr = true;
179-
allocateMemory = true;
180-
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocateMemory, nullptr, static_cast<size_t>(size), allocationType);
168+
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(flags);
169+
DeviceIndex deviceIndex = MemObjHelper::getDeviceIndex(flags);
170+
allocFlags.flags.allocateMemory = true;
171+
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocFlags, deviceIndex, nullptr, static_cast<size_t>(size), allocationType);
181172
}
182173
}
183174

runtime/mem_obj/mem_obj_helper.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
/*
2-
* Copyright (c) 2018, Intel Corporation
2+
* Copyright (C) 2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#include "runtime/mem_obj/mem_obj_helper.h"
@@ -28,4 +13,12 @@ bool MemObjHelper::checkExtraMemFlagsForBuffer(cl_mem_flags flags) {
2813
return true;
2914
}
3015

16+
AllocationFlags MemObjHelper::getAllocationFlags(cl_mem_flags flags) {
17+
return AllocationFlags(); // Initialized by default constructor
18+
}
19+
20+
DeviceIndex MemObjHelper::getDeviceIndex(cl_mem_flags flags) {
21+
return DeviceIndex(0);
22+
}
23+
3124
} // namespace OCLRT

runtime/mem_obj/mem_obj_helper.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
/*
2-
* Copyright (c) 2018, Intel Corporation
2+
* Copyright (C) 2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#pragma once
249
#include "CL/cl.h"
2510
#include "runtime/mem_obj/mem_obj.h"
11+
#include "runtime/memory_manager/memory_manager.h"
2612

2713
namespace OCLRT {
2814

@@ -42,6 +28,10 @@ class MemObjHelper {
4228

4329
static bool checkExtraMemFlagsForBuffer(cl_mem_flags flags);
4430

31+
static AllocationFlags getAllocationFlags(cl_mem_flags flags);
32+
33+
static DeviceIndex getDeviceIndex(cl_mem_flags flags);
34+
4535
static bool checkMemFlagsForSubBuffer(cl_mem_flags flags) {
4636
const cl_mem_flags allValidFlags =
4737
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |

runtime/mem_obj/pipe.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (C) 2017-2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#include "runtime/context/context.h"
249
#include "runtime/mem_obj/pipe.h"
10+
#include "runtime/mem_obj/mem_obj_helper.h"
2511
#include "runtime/helpers/get_info.h"
2612
#include "runtime/memory_manager/memory_manager.h"
2713

@@ -62,8 +48,11 @@ Pipe *Pipe::create(Context *context,
6248
DEBUG_BREAK_IF(!memoryManager);
6349

6450
while (true) {
51+
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(flags);
52+
DeviceIndex deviceIndex = MemObjHelper::getDeviceIndex(flags);
53+
allocFlags.flags.allocateMemory = true;
6554
auto size = static_cast<size_t>(packetSize * (maxPackets + 1) + intelPipeHeaderReservedSpace);
66-
GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryInPreferredPool(true, nullptr, size, GraphicsAllocation::AllocationType::PIPE);
55+
GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocFlags, deviceIndex, nullptr, size, GraphicsAllocation::AllocationType::PIPE);
6756
if (!memory) {
6857
errcodeRet = CL_OUT_OF_HOST_MEMORY;
6958
break;

runtime/memory_manager/memory_manager.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (C) 2017-2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#include "runtime/memory_manager/memory_manager.h"
@@ -446,11 +431,11 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, bool alloc
446431
return true;
447432
}
448433

449-
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(bool allocateMemory, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) {
434+
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(AllocationFlags flags, DeviceIndex deviceIndex, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) {
450435
AllocationData allocationData;
451436
AllocationStatus status = AllocationStatus::Error;
452437

453-
getAllocationData(allocationData, allocateMemory, hostPtr, size, type);
438+
getAllocationData(allocationData, flags.flags.allocateMemory, hostPtr, size, type);
454439
UNRECOVERABLE_IF(allocationData.type == GraphicsAllocation::AllocationType::IMAGE || allocationData.type == GraphicsAllocation::AllocationType::SHARED_RESOURCE);
455440
GraphicsAllocation *allocation = nullptr;
456441

runtime/memory_manager/memory_manager.h

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (C) 2017-2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#pragma once
@@ -61,6 +46,35 @@ enum AllocationOrigin {
6146
INTERNAL_ALLOCATION
6247
};
6348

49+
struct AllocationFlags {
50+
union {
51+
struct {
52+
uint32_t allocateMemory : 1;
53+
uint32_t flushL3RequiredForRead : 1;
54+
uint32_t flushL3RequiredForWrite : 1;
55+
uint32_t reserved : 29;
56+
} flags;
57+
uint32_t allFlags;
58+
};
59+
60+
static_assert(sizeof(AllocationFlags::flags) == sizeof(AllocationFlags::allFlags), "");
61+
62+
AllocationFlags() {
63+
allFlags = 0;
64+
flags.flushL3RequiredForRead = 1;
65+
flags.flushL3RequiredForWrite = 1;
66+
}
67+
68+
AllocationFlags(bool allocateMemory) {
69+
allFlags = 0;
70+
flags.flushL3RequiredForRead = 1;
71+
flags.flushL3RequiredForWrite = 1;
72+
flags.allocateMemory = allocateMemory;
73+
}
74+
};
75+
76+
using DeviceIndex = uint32_t;
77+
6478
struct AllocationData {
6579
union {
6680
struct {
@@ -142,7 +156,7 @@ class MemoryManager {
142156

143157
virtual GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) = 0;
144158

145-
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(bool allocateMemory, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type);
159+
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(AllocationFlags flags, DeviceIndex deviceIndex, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type);
146160

147161
GraphicsAllocation *allocateGraphicsMemoryForSVM(size_t size, bool coherent);
148162

runtime/program/printf_handler.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
/*
2-
* Copyright (c) 2017 - 2018, Intel Corporation
2+
* Copyright (C) 2017-2018 Intel Corporation
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
4+
* SPDX-License-Identifier: MIT
105
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
216
*/
227

238
#include "printf_handler.h"
@@ -52,7 +37,7 @@ void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo)
5237
return;
5338
}
5439
kernel = multiDispatchInfo.peekMainKernel();
55-
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(true, nullptr, printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE);
40+
printfSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE);
5641

5742
*reinterpret_cast<uint32_t *>(printfSurface->getUnderlyingBuffer()) = printfSurfaceInitialDataSize;
5843

0 commit comments

Comments
 (0)