diff --git a/opencl/source/kernel/kernel.cpp b/opencl/source/kernel/kernel.cpp index b9d267d7fa..aa9d2e4cf9 100644 --- a/opencl/source/kernel/kernel.cpp +++ b/opencl/source/kernel/kernel.cpp @@ -761,7 +761,7 @@ void Kernel::substituteKernelHeap(void *newKernelHeap, size_t newKernelHeapSize) } else { memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(pKernelInfo->kernelAllocation); pKernelInfo->kernelAllocation = nullptr; - status = pKernelInfo->createKernelAllocation(device.getRootDeviceIndex(), memoryManager); + status = pKernelInfo->createKernelAllocation(device.getDevice()); } UNRECOVERABLE_IF(!status); } diff --git a/opencl/source/program/kernel_info.cpp b/opencl/source/program/kernel_info.cpp index 8a59cd9b88..b5840f94cd 100644 --- a/opencl/source/program/kernel_info.cpp +++ b/opencl/source/program/kernel_info.cpp @@ -419,14 +419,14 @@ uint32_t KernelInfo::getConstantBufferSize() const { return patchInfo.dataParameterStream ? patchInfo.dataParameterStream->DataParameterStreamSize : 0; } -bool KernelInfo::createKernelAllocation(uint32_t rootDeviceIndex, MemoryManager *memoryManager) { +bool KernelInfo::createKernelAllocation(const Device &device) { UNRECOVERABLE_IF(kernelAllocation); auto kernelIsaSize = heapInfo.KernelHeapSize; - kernelAllocation = memoryManager->allocateGraphicsMemoryWithProperties({rootDeviceIndex, kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA}); + kernelAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(), kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA, device.getDeviceBitfield()}); if (!kernelAllocation) { return false; } - return memoryManager->copyMemoryToAllocation(kernelAllocation, heapInfo.pKernelHeap, kernelIsaSize); + return device.getMemoryManager()->copyMemoryToAllocation(kernelAllocation, heapInfo.pKernelHeap, kernelIsaSize); } void KernelInfo::apply(const DeviceInfoKernelPayloadConstants &constants) { diff --git a/opencl/source/program/kernel_info.h b/opencl/source/program/kernel_info.h index 80ca59901a..b07e52d2b5 100644 --- a/opencl/source/program/kernel_info.h +++ b/opencl/source/program/kernel_info.h @@ -184,7 +184,7 @@ struct KernelInfo { return -1; } - bool createKernelAllocation(uint32_t rootDeviceIndex, MemoryManager *memoryManager); + bool createKernelAllocation(const Device &device); void apply(const DeviceInfoKernelPayloadConstants &constants); std::string name; diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 9c2daf1ad7..4c58304780 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -194,7 +194,7 @@ cl_int Program::processProgramInfo(ProgramInfo &src) { for (auto &kernelInfo : this->kernelInfoArray) { cl_int retVal = CL_SUCCESS; if (kernelInfo->heapInfo.KernelHeapSize && this->pDevice) { - retVal = kernelInfo->createKernelAllocation(this->pDevice->getRootDeviceIndex(), this->pDevice->getMemoryManager()) ? CL_SUCCESS : CL_OUT_OF_HOST_MEMORY; + retVal = kernelInfo->createKernelAllocation(*this->pDevice) ? CL_SUCCESS : CL_OUT_OF_HOST_MEMORY; } DEBUG_BREAK_IF(kernelInfo->heapInfo.KernelHeapSize && !this->pDevice); diff --git a/opencl/test/unit_test/gen12lp/device_queue_tests_gen12lp.cpp b/opencl/test/unit_test/gen12lp/device_queue_tests_gen12lp.cpp index daa2024317..d2c0492ca5 100644 --- a/opencl/test/unit_test/gen12lp/device_queue_tests_gen12lp.cpp +++ b/opencl/test/unit_test/gen12lp/device_queue_tests_gen12lp.cpp @@ -19,7 +19,7 @@ GEN12LPTEST_F(DeviceQueueHwTest, givenDeviceQueueWhenRunningOnCCsThenFfidSkipOff auto device = pContext->getDevice(0); std::unique_ptr mockParentKernel(MockParentKernel::create(*pContext)); KernelInfo *blockInfo = const_cast(mockParentKernel->mockProgram->blockKernelManager->getBlockKernelInfo(0)); - blockInfo->createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager()); + blockInfo->createKernelAllocation(device->getDevice()); ASSERT_NE(nullptr, blockInfo->getGraphicsAllocation()); const_cast(blockInfo->patchInfo.threadPayload)->OffsetToSkipSetFFIDGP = 0x1234; diff --git a/opencl/test/unit_test/kernel/kernel_tests.cpp b/opencl/test/unit_test/kernel/kernel_tests.cpp index 85253fa8d8..54954fb806 100644 --- a/opencl/test/unit_test/kernel/kernel_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_tests.cpp @@ -3039,7 +3039,7 @@ TEST(KernelTest, givenKernelLocalIdGenerationByRuntimeFalseWhenGettingStartOffse threadPayload.OffsetToSkipPerThreadDataLoad = 128u; mockKernel.kernelInfo.patchInfo.threadPayload = &threadPayload; - mockKernel.kernelInfo.createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager()); + mockKernel.kernelInfo.createKernelAllocation(device->getDevice()); auto allocationOffset = mockKernel.kernelInfo.getGraphicsAllocation()->getGpuAddressToPatch(); mockKernel.mockKernel->setStartOffset(128); @@ -3057,7 +3057,7 @@ TEST(KernelTest, givenKernelLocalIdGenerationByRuntimeTrueAndLocalIdsUsedWhenGet threadPayload.OffsetToSkipPerThreadDataLoad = 128u; mockKernel.kernelInfo.patchInfo.threadPayload = &threadPayload; - mockKernel.kernelInfo.createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager()); + mockKernel.kernelInfo.createKernelAllocation(device->getDevice()); auto allocationOffset = mockKernel.kernelInfo.getGraphicsAllocation()->getGpuAddressToPatch(); mockKernel.mockKernel->setStartOffset(128); @@ -3075,7 +3075,7 @@ TEST(KernelTest, givenKernelLocalIdGenerationByRuntimeFalseAndLocalIdsNotUsedWhe threadPayload.OffsetToSkipPerThreadDataLoad = 128u; mockKernel.kernelInfo.patchInfo.threadPayload = &threadPayload; - mockKernel.kernelInfo.createKernelAllocation(device->getRootDeviceIndex(), device->getMemoryManager()); + mockKernel.kernelInfo.createKernelAllocation(device->getDevice()); auto allocationOffset = mockKernel.kernelInfo.getGraphicsAllocation()->getGpuAddressToPatch(); mockKernel.mockKernel->setStartOffset(128); diff --git a/opencl/test/unit_test/kernel/substitute_kernel_heap_tests.cpp b/opencl/test/unit_test/kernel/substitute_kernel_heap_tests.cpp index 282201bff5..77e66d7d46 100644 --- a/opencl/test/unit_test/kernel/substitute_kernel_heap_tests.cpp +++ b/opencl/test/unit_test/kernel/substitute_kernel_heap_tests.cpp @@ -23,7 +23,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeT kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize; EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation); - kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), pDevice->getMemoryManager()); + kernel.kernelInfo.createKernelAllocation(*pDevice); auto firstAllocation = kernel.kernelInfo.kernelAllocation; EXPECT_NE(nullptr, firstAllocation); auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize(); @@ -53,7 +53,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSameSizeThen kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize; EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation); - kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), pDevice->getMemoryManager()); + kernel.kernelInfo.createKernelAllocation(*pDevice); auto firstAllocation = kernel.kernelInfo.kernelAllocation; EXPECT_NE(nullptr, firstAllocation); auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize(); @@ -82,7 +82,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSmallerSizeT kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize; EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation); - kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), pDevice->getMemoryManager()); + kernel.kernelInfo.createKernelAllocation(*pDevice); auto firstAllocation = kernel.kernelInfo.kernelAllocation; EXPECT_NE(nullptr, firstAllocation); auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize(); @@ -113,7 +113,7 @@ TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKe const size_t initialHeapSize = 0x40; kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize; - kernel.kernelInfo.createKernelAllocation(pDevice->getRootDeviceIndex(), memoryManager); + kernel.kernelInfo.createKernelAllocation(*pDevice); auto firstAllocation = kernel.kernelInfo.kernelAllocation; uint32_t notReadyTaskCount = *commandStreamReceiver.getTagAddress() + 1u; diff --git a/opencl/test/unit_test/program/kernel_info_tests.cpp b/opencl/test/unit_test/program/kernel_info_tests.cpp index ff2054efd0..689fac9a84 100644 --- a/opencl/test/unit_test/program/kernel_info_tests.cpp +++ b/opencl/test/unit_test/program/kernel_info_tests.cpp @@ -6,12 +6,14 @@ */ #include "shared/source/execution_environment/execution_environment.h" +#include "shared/test/unit_test/mocks/ult_device_factory.h" #include "opencl/source/memory_manager/os_agnostic_memory_manager.h" #include "opencl/source/program/kernel_arg_info.h" #include "opencl/source/program/kernel_info.h" #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" #include "opencl/test/unit_test/mocks/mock_execution_environment.h" +#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h" #include "gtest/gtest.h" @@ -106,8 +108,8 @@ TEST(KernelInfo, decodeImageKernelArgument) { TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKernelHeapToKernelAllocation) { KernelInfo kernelInfo; - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - OsAgnosticMemoryManager memoryManager(executionEnvironment); + auto factory = UltDeviceFactory{1, 0}; + auto device = factory.rootDevices[0]; const size_t heapSize = 0x40; char heap[heapSize]; kernelInfo.heapInfo.KernelHeapSize = heapSize; @@ -117,12 +119,12 @@ TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKerne heap[i] = static_cast(i); } - auto retVal = kernelInfo.createKernelAllocation(0, &memoryManager); + auto retVal = kernelInfo.createKernelAllocation(*device); EXPECT_TRUE(retVal); auto allocation = kernelInfo.kernelAllocation; EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), heap, heapSize)); EXPECT_EQ(heapSize, allocation->getUnderlyingBufferSize()); - memoryManager.checkGpuUsageAndDestroyGraphicsAllocations(allocation); + device->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(allocation); } class MyMemoryManager : public OsAgnosticMemoryManager { @@ -133,9 +135,10 @@ class MyMemoryManager : public OsAgnosticMemoryManager { TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) { KernelInfo kernelInfo; - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - MyMemoryManager memoryManager(executionEnvironment); - auto retVal = kernelInfo.createKernelAllocation(0, &memoryManager); + auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get()); + executionEnvironment->memoryManager.reset(new MyMemoryManager(*executionEnvironment)); + auto device = std::unique_ptr(Device::create(executionEnvironment, mockRootDeviceIndex)); + auto retVal = kernelInfo.createKernelAllocation(*device); EXPECT_FALSE(retVal); } @@ -234,7 +237,7 @@ TEST_F(KernelInfoMultiRootDeviceTests, kernelAllocationHasCorrectRootDeviceIndex kernelInfo.heapInfo.KernelHeapSize = heapSize; kernelInfo.heapInfo.pKernelHeap = &heap; - auto retVal = kernelInfo.createKernelAllocation(expectedRootDeviceIndex, mockMemoryManager); + auto retVal = kernelInfo.createKernelAllocation(device->getDevice()); EXPECT_TRUE(retVal); auto allocation = kernelInfo.kernelAllocation; ASSERT_NE(nullptr, allocation);