Skip to content

Commit 913cfcf

Browse files
Pass device to KernelInfo::createKernalAllocation
Related-To: NEO-4722 Change-Id: Ica85fe3e1ff43a158337ff7049fbc8486f8f39fc Signed-off-by: Andrzej Swierczynski <andrzej.swierczynski@intel.com>
1 parent 5c0d563 commit 913cfcf

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

opencl/source/kernel/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ void Kernel::substituteKernelHeap(void *newKernelHeap, size_t newKernelHeapSize)
761761
} else {
762762
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(pKernelInfo->kernelAllocation);
763763
pKernelInfo->kernelAllocation = nullptr;
764-
status = pKernelInfo->createKernelAllocation(device.getRootDeviceIndex(), memoryManager);
764+
status = pKernelInfo->createKernelAllocation(device.getDevice());
765765
}
766766
UNRECOVERABLE_IF(!status);
767767
}

opencl/source/program/kernel_info.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,14 @@ uint32_t KernelInfo::getConstantBufferSize() const {
419419
return patchInfo.dataParameterStream ? patchInfo.dataParameterStream->DataParameterStreamSize : 0;
420420
}
421421

422-
bool KernelInfo::createKernelAllocation(uint32_t rootDeviceIndex, MemoryManager *memoryManager) {
422+
bool KernelInfo::createKernelAllocation(const Device &device) {
423423
UNRECOVERABLE_IF(kernelAllocation);
424424
auto kernelIsaSize = heapInfo.KernelHeapSize;
425-
kernelAllocation = memoryManager->allocateGraphicsMemoryWithProperties({rootDeviceIndex, kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA});
425+
kernelAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(), kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA, device.getDeviceBitfield()});
426426
if (!kernelAllocation) {
427427
return false;
428428
}
429-
return memoryManager->copyMemoryToAllocation(kernelAllocation, heapInfo.pKernelHeap, kernelIsaSize);
429+
return device.getMemoryManager()->copyMemoryToAllocation(kernelAllocation, heapInfo.pKernelHeap, kernelIsaSize);
430430
}
431431

432432
void KernelInfo::apply(const DeviceInfoKernelPayloadConstants &constants) {

opencl/source/program/kernel_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct KernelInfo {
184184
return -1;
185185
}
186186

187-
bool createKernelAllocation(uint32_t rootDeviceIndex, MemoryManager *memoryManager);
187+
bool createKernelAllocation(const Device &device);
188188
void apply(const DeviceInfoKernelPayloadConstants &constants);
189189

190190
std::string name;

opencl/source/program/process_device_binary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ cl_int Program::processProgramInfo(ProgramInfo &src) {
194194
for (auto &kernelInfo : this->kernelInfoArray) {
195195
cl_int retVal = CL_SUCCESS;
196196
if (kernelInfo->heapInfo.KernelHeapSize && this->pDevice) {
197-
retVal = kernelInfo->createKernelAllocation(this->pDevice->getRootDeviceIndex(), this->pDevice->getMemoryManager()) ? CL_SUCCESS : CL_OUT_OF_HOST_MEMORY;
197+
retVal = kernelInfo->createKernelAllocation(*this->pDevice) ? CL_SUCCESS : CL_OUT_OF_HOST_MEMORY;
198198
}
199199

200200
DEBUG_BREAK_IF(kernelInfo->heapInfo.KernelHeapSize && !this->pDevice);

opencl/test/unit_test/gen12lp/device_queue_tests_gen12lp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ GEN12LPTEST_F(DeviceQueueHwTest, givenDeviceQueueWhenRunningOnCCsThenFfidSkipOff
1919
auto device = pContext->getDevice(0);
2020
std::unique_ptr<MockParentKernel> mockParentKernel(MockParentKernel::create(*pContext));
2121
KernelInfo *blockInfo = const_cast<KernelInfo *>(mockParentKernel->mockProgram->blockKernelManager->getBlockKernelInfo(0));
22-
blockInfo->createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager());
22+
blockInfo->createKernelAllocation(device->getDevice());
2323
ASSERT_NE(nullptr, blockInfo->getGraphicsAllocation());
2424
const_cast<SPatchThreadPayload *>(blockInfo->patchInfo.threadPayload)->OffsetToSkipSetFFIDGP = 0x1234;
2525

opencl/test/unit_test/kernel/kernel_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ TEST(KernelTest, givenKernelLocalIdGenerationByRuntimeFalseWhenGettingStartOffse
30393039
threadPayload.OffsetToSkipPerThreadDataLoad = 128u;
30403040
mockKernel.kernelInfo.patchInfo.threadPayload = &threadPayload;
30413041

3042-
mockKernel.kernelInfo.createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager());
3042+
mockKernel.kernelInfo.createKernelAllocation(device->getDevice());
30433043
auto allocationOffset = mockKernel.kernelInfo.getGraphicsAllocation()->getGpuAddressToPatch();
30443044

30453045
mockKernel.mockKernel->setStartOffset(128);
@@ -3057,7 +3057,7 @@ TEST(KernelTest, givenKernelLocalIdGenerationByRuntimeTrueAndLocalIdsUsedWhenGet
30573057
threadPayload.OffsetToSkipPerThreadDataLoad = 128u;
30583058
mockKernel.kernelInfo.patchInfo.threadPayload = &threadPayload;
30593059

3060-
mockKernel.kernelInfo.createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager());
3060+
mockKernel.kernelInfo.createKernelAllocation(device->getDevice());
30613061
auto allocationOffset = mockKernel.kernelInfo.getGraphicsAllocation()->getGpuAddressToPatch();
30623062

30633063
mockKernel.mockKernel->setStartOffset(128);
@@ -3075,7 +3075,7 @@ TEST(KernelTest, givenKernelLocalIdGenerationByRuntimeFalseAndLocalIdsNotUsedWhe
30753075
threadPayload.OffsetToSkipPerThreadDataLoad = 128u;
30763076
mockKernel.kernelInfo.patchInfo.threadPayload = &threadPayload;
30773077

3078-
mockKernel.kernelInfo.createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager());
3078+
mockKernel.kernelInfo.createKernelAllocation(device->getDevice());
30793079
auto allocationOffset = mockKernel.kernelInfo.getGraphicsAllocation()->getGpuAddressToPatch();
30803080

30813081
mockKernel.mockKernel->setStartOffset(128);

opencl/test/unit_test/kernel/substitute_kernel_heap_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeT
2323
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
2424

2525
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
26-
kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), pDevice->getMemoryManager());
26+
kernel.kernelInfo.createKernelAllocation(*pDevice);
2727
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
2828
EXPECT_NE(nullptr, firstAllocation);
2929
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
@@ -53,7 +53,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSameSizeThen
5353
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
5454

5555
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
56-
kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), pDevice->getMemoryManager());
56+
kernel.kernelInfo.createKernelAllocation(*pDevice);
5757
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
5858
EXPECT_NE(nullptr, firstAllocation);
5959
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
@@ -82,7 +82,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSmallerSizeT
8282
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
8383

8484
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
85-
kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), pDevice->getMemoryManager());
85+
kernel.kernelInfo.createKernelAllocation(*pDevice);
8686
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
8787
EXPECT_NE(nullptr, firstAllocation);
8888
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
@@ -113,7 +113,7 @@ TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKe
113113
const size_t initialHeapSize = 0x40;
114114
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
115115

116-
kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), memoryManager);
116+
kernel.kernelInfo.createKernelAllocation(*pDevice);
117117
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
118118

119119
uint32_t notReadyTaskCount = *commandStreamReceiver.getTagAddress() + 1u;

opencl/test/unit_test/program/kernel_info_tests.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77

88
#include "shared/source/execution_environment/execution_environment.h"
9+
#include "shared/test/unit_test/mocks/ult_device_factory.h"
910

1011
#include "opencl/source/memory_manager/os_agnostic_memory_manager.h"
1112
#include "opencl/source/program/kernel_arg_info.h"
1213
#include "opencl/source/program/kernel_info.h"
1314
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
1415
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
16+
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
1517

1618
#include "gtest/gtest.h"
1719

@@ -106,8 +108,8 @@ TEST(KernelInfo, decodeImageKernelArgument) {
106108

107109
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKernelHeapToKernelAllocation) {
108110
KernelInfo kernelInfo;
109-
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
110-
OsAgnosticMemoryManager memoryManager(executionEnvironment);
111+
auto factory = UltDeviceFactory{1, 0};
112+
auto device = factory.rootDevices[0];
111113
const size_t heapSize = 0x40;
112114
char heap[heapSize];
113115
kernelInfo.heapInfo.KernelHeapSize = heapSize;
@@ -117,12 +119,12 @@ TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKerne
117119
heap[i] = static_cast<char>(i);
118120
}
119121

120-
auto retVal = kernelInfo.createKernelAllocation(0, &memoryManager);
122+
auto retVal = kernelInfo.createKernelAllocation(*device);
121123
EXPECT_TRUE(retVal);
122124
auto allocation = kernelInfo.kernelAllocation;
123125
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), heap, heapSize));
124126
EXPECT_EQ(heapSize, allocation->getUnderlyingBufferSize());
125-
memoryManager.checkGpuUsageAndDestroyGraphicsAllocations(allocation);
127+
device->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(allocation);
126128
}
127129

128130
class MyMemoryManager : public OsAgnosticMemoryManager {
@@ -133,9 +135,10 @@ class MyMemoryManager : public OsAgnosticMemoryManager {
133135

134136
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) {
135137
KernelInfo kernelInfo;
136-
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
137-
MyMemoryManager memoryManager(executionEnvironment);
138-
auto retVal = kernelInfo.createKernelAllocation(0, &memoryManager);
138+
auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get());
139+
executionEnvironment->memoryManager.reset(new MyMemoryManager(*executionEnvironment));
140+
auto device = std::unique_ptr<Device>(Device::create<RootDevice>(executionEnvironment, mockRootDeviceIndex));
141+
auto retVal = kernelInfo.createKernelAllocation(*device);
139142
EXPECT_FALSE(retVal);
140143
}
141144

@@ -234,7 +237,7 @@ TEST_F(KernelInfoMultiRootDeviceTests, kernelAllocationHasCorrectRootDeviceIndex
234237
kernelInfo.heapInfo.KernelHeapSize = heapSize;
235238
kernelInfo.heapInfo.pKernelHeap = &heap;
236239

237-
auto retVal = kernelInfo.createKernelAllocation(expectedRootDeviceIndex, mockMemoryManager);
240+
auto retVal = kernelInfo.createKernelAllocation(device->getDevice());
238241
EXPECT_TRUE(retVal);
239242
auto allocation = kernelInfo.kernelAllocation;
240243
ASSERT_NE(nullptr, allocation);

0 commit comments

Comments
 (0)