From 93fc48339bf47212d2fd0ef2e1b9d2d4f2e35705 Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Tue, 13 Mar 2018 10:44:35 +0100 Subject: [PATCH] [15/n] Internal 4GB allocator. - Make resident on kernel ISA for blocked and non blocked path. Change-Id: I1fc4948f1abb73c6f7028ae15dccad820101b8dc --- runtime/kernel/kernel.cpp | 11 ++++++++ .../enqueue_copy_buffer_aub_tests.cpp | 2 +- .../enqueue_fill_buffer_aub_tests.cpp | 2 +- .../enqueue_write_buffer_aub_tests.cpp | 2 +- .../command_queue/enqueue_svm_tests.cpp | 6 ++-- unit_tests/fixtures/hello_world_fixture.h | 1 + unit_tests/kernel/kernel_tests.cpp | 18 ++++++++---- unit_tests/program/program_tests.cpp | 28 ++++++++++++------- 8 files changed, 48 insertions(+), 22 deletions(-) diff --git a/runtime/kernel/kernel.cpp b/runtime/kernel/kernel.cpp index fd7ebc8277..5dc6b248f8 100644 --- a/runtime/kernel/kernel.cpp +++ b/runtime/kernel/kernel.cpp @@ -941,6 +941,11 @@ void Kernel::makeResident(CommandStreamReceiver &commandStreamReceiver) { makeArgsResident(commandStreamReceiver); + auto kernelIsaAllocation = this->kernelInfo.kernelAllocation; + if (kernelIsaAllocation) { + commandStreamReceiver.makeResident(*kernelIsaAllocation); + } + gtpinNotifyMakeResident(this, &commandStreamReceiver); } @@ -980,6 +985,12 @@ void Kernel::getResidency(std::vector &dst) { } } + auto kernelIsaAllocation = this->kernelInfo.kernelAllocation; + if (kernelIsaAllocation) { + GeneralSurface *surface = new GeneralSurface(kernelIsaAllocation); + dst.push_back(surface); + } + gtpinNotifyUpdateResidencyList(this, &dst); } diff --git a/unit_tests/aub_tests/command_queue/enqueue_copy_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_copy_buffer_aub_tests.cpp index 0ba7644a5f..18b64bd64d 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_copy_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_copy_buffer_aub_tests.cpp @@ -47,7 +47,7 @@ struct CopyBufferHw typedef CopyBufferHw AUBCopyBuffer; HWTEST_P(AUBCopyBuffer, simple) { - MockContext context; + MockContext context(&pCmdQ->getDevice()); cl_float srcMemory[] = {1.0f, 2.0f, 3.0f, 4.0f}; cl_float dstMemory[] = {0.0f, 0.0f, 0.0f, 0.0f}; diff --git a/unit_tests/aub_tests/command_queue/enqueue_fill_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_fill_buffer_aub_tests.cpp index 3135951fbb..5c7384db32 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_fill_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_fill_buffer_aub_tests.cpp @@ -50,7 +50,7 @@ typedef FillBufferHw AUBFillBuffer; HWTEST_P(AUBFillBuffer, simple) { cl_float destMemory[] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; auto pDestMemory = &destMemory[0]; - MockContext context; + MockContext context(&this->pCmdQ->getDevice()); auto retVal = CL_INVALID_VALUE; auto destBuffer = Buffer::create( &context, diff --git a/unit_tests/aub_tests/command_queue/enqueue_write_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_write_buffer_aub_tests.cpp index ea636297bf..b4103234a0 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_write_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_write_buffer_aub_tests.cpp @@ -48,7 +48,7 @@ struct WriteBufferHw typedef WriteBufferHw AUBWriteBuffer; HWTEST_P(AUBWriteBuffer, simple) { - MockContext context; + MockContext context(&this->pCmdQ->getDevice()); cl_float *srcMemory = new float[1024]; cl_float *destMemory = new float[1024]; diff --git a/unit_tests/command_queue/enqueue_svm_tests.cpp b/unit_tests/command_queue/enqueue_svm_tests.cpp index 067f66cafe..9966cbbebb 100644 --- a/unit_tests/command_queue/enqueue_svm_tests.cpp +++ b/unit_tests/command_queue/enqueue_svm_tests.cpp @@ -472,7 +472,7 @@ TEST_F(EnqueueSvmTest, enqueueTaskWithKernelExecInfo_success) { EXPECT_EQ(1u, kernel->getKernelSvmGfxAllocations().size()); } -TEST_F(EnqueueSvmTest, enqueueTaskWithKernelExecInfoBlockedOnEvent_success) { +TEST_F(EnqueueSvmTest, givenEnqueueTaskBlockedOnUserEventWhenItIsEnqueuedThenSurfacesAreMadeResident) { GraphicsAllocation *pSvmAlloc = context->getSVMAllocsManager()->getSVMAlloc(ptrSVM); EXPECT_NE(nullptr, ptrSVM); @@ -483,7 +483,7 @@ TEST_F(EnqueueSvmTest, enqueueTaskWithKernelExecInfoBlockedOnEvent_success) { std::vector allSurfaces; kernel->getResidency(allSurfaces); - EXPECT_EQ(0u, allSurfaces.size()); + EXPECT_EQ(1u, allSurfaces.size()); kernel->setKernelExecInfo(pSvmAlloc); @@ -503,7 +503,7 @@ TEST_F(EnqueueSvmTest, enqueueTaskWithKernelExecInfoBlockedOnEvent_success) { EXPECT_EQ(CL_SUCCESS, retVal); kernel->getResidency(allSurfaces); - EXPECT_EQ(1u, allSurfaces.size()); + EXPECT_EQ(3u, allSurfaces.size()); for (auto &surface : allSurfaces) delete surface; diff --git a/unit_tests/fixtures/hello_world_fixture.h b/unit_tests/fixtures/hello_world_fixture.h index 2039aecc60..a3f8cc4d5c 100644 --- a/unit_tests/fixtures/hello_world_fixture.h +++ b/unit_tests/fixtures/hello_world_fixture.h @@ -108,6 +108,7 @@ struct HelloWorldFixture : public FixtureFactory::IndirectHeapFixture, } virtual void TearDown() { + pCmdQ->flush(); delete BufferDefaults::context; alignedFree(pSrcMemory); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index a1da6b324d..ae4ce31291 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -1534,12 +1534,17 @@ TEST_F(KernelDefaultDeviceQueueSurfaceTest, givenStatelessKernelWhenDefaultDevic typedef Test KernelResidencyTest; -TEST_F(KernelResidencyTest, test_MakeArgsResident) { +HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenKernelIsaIsMadeResident) { ASSERT_NE(nullptr, pDevice); char pCrossThreadData[64]; // define kernel info - KernelInfo *pKernelInfo = KernelInfo::create(); + std::unique_ptr pKernelInfo(KernelInfo::create()); + auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); + commandStreamReceiver.storeMakeResidentAllocations = true; + + auto memoryManager = commandStreamReceiver.getMemoryManager(); + pKernelInfo->kernelAllocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, MemoryConstants::pageSize); // setup kernel arg offsets KernelArgPatchInfo kernelArgPatchInfo; @@ -1554,15 +1559,16 @@ TEST_F(KernelResidencyTest, test_MakeArgsResident) { pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = 0x30; MockProgram program; - MockKernel *pKernel = new MockKernel(&program, *pKernelInfo, *pDevice); + std::unique_ptr pKernel(new MockKernel(&program, *pKernelInfo, *pDevice)); ASSERT_EQ(CL_SUCCESS, pKernel->initialize()); pKernel->setCrossThreadData(pCrossThreadData, sizeof(pCrossThreadData)); - // Currently just a sandbox for testing + EXPECT_EQ(0u, commandStreamReceiver.makeResidentAllocations.size()); pKernel->makeResident(pDevice->getCommandStreamReceiver()); + EXPECT_EQ(1u, commandStreamReceiver.makeResidentAllocations.size()); + EXPECT_EQ(commandStreamReceiver.makeResidentAllocations.begin()->first, pKernel->getKernelInfo().getGraphicsAllocation()); - delete pKernel; - delete pKernelInfo; + memoryManager->freeGraphicsMemory(pKernelInfo->kernelAllocation); } HWTEST_F(KernelResidencyTest, test_MakeArgsResidentCheckImageFromImage) { diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index bb51b4f0cf..c76509687e 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -1319,11 +1319,14 @@ class CommandStreamReceiverMock : public UltCommandStreamReceiver { residency.erase(graphicsAllocation.getUnderlyingBuffer()); CommandStreamReceiver::makeNonResident(graphicsAllocation); } + ResidencyContainer &getResidencyContainer() { + return this->memoryManager->getResidencyAllocations(); + } std::map residency; }; -HWTEST_F(PatchTokenTests, AllocateConstantSurface) { +HWTEST_F(PatchTokenTests, givenKernelRequiringConstantAllocationWhenMakeResidentIsCalledThenConstantAllocationIsMadeResident) { cl_device_id device = pDevice; CreateProgramFromBinary(pContext, &device, "test_constant_memory"); @@ -1349,11 +1352,7 @@ HWTEST_F(PatchTokenTests, AllocateConstantSurface) { EXPECT_EQ(expected_values[0], constBuff[0]); EXPECT_EQ(expected_values[1], constBuff[1]); - // create a kernel - auto pKernel = Kernel::create( - pProgram, - *pKernelInfo, - &retVal); + std::unique_ptr pKernel(Kernel::create(pProgram, *pKernelInfo, &retVal)); ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_NE(nullptr, pKernel); @@ -1365,7 +1364,18 @@ HWTEST_F(PatchTokenTests, AllocateConstantSurface) { pCommandStreamReceiver->residency.clear(); pKernel->makeResident(*pCommandStreamReceiver); - EXPECT_EQ(1u, pCommandStreamReceiver->residency.size()); + EXPECT_EQ(2u, pCommandStreamReceiver->residency.size()); + + auto &residencyVector = pCommandStreamReceiver->getResidencyContainer(); + + //we expect kernel ISA here and constant allocation + auto kernelIsa = pKernel->getKernelInfo().getGraphicsAllocation(); + auto constantAllocation = pProgram->getConstantSurface(); + + auto element = std::find(residencyVector.begin(), residencyVector.end(), kernelIsa); + EXPECT_NE(residencyVector.end(), element); + element = std::find(residencyVector.begin(), residencyVector.end(), constantAllocation); + EXPECT_NE(residencyVector.end(), element); auto crossThreadData = pKernel->getCrossThreadData(); uint32_t *constBuffGpuAddr = reinterpret_cast(pProgram->getConstantSurface()->getGpuAddressToPatch()); @@ -1379,13 +1389,11 @@ HWTEST_F(PatchTokenTests, AllocateConstantSurface) { std::vector surfaces; pKernel->getResidency(surfaces); - EXPECT_EQ(1u, surfaces.size()); + EXPECT_EQ(2u, surfaces.size()); for (Surface *surface : surfaces) { delete surface; } - - delete pKernel; } TEST_F(PatchTokenTests, DataParamGWS) {