Pass device bitfield when creating SVM alloc

Related-To: NEO-4484
Change-Id: Ie70b6fbd3351615bc15005755f2d7d9b4a3bad32
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-04-23 16:59:18 +02:00
committed by sys_ocldev
parent ff4ec40e27
commit 7ed45adb27
16 changed files with 98 additions and 63 deletions

View File

@@ -4149,7 +4149,7 @@ void *CL_API_CALL clSVMAlloc(cl_context context,
return pAlloc;
}
pAlloc = pContext->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), size, MemObjHelper::getSvmAllocationProperties(flags));
pAlloc = pContext->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), size, MemObjHelper::getSvmAllocationProperties(flags), pDevice->getDeviceBitfield());
if (pContext->isProvidingPerformanceHints()) {
pContext->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_SVM_ALLOC_MEETS_ALIGNMENT_RESTRICTIONS, pAlloc, size);

View File

@@ -9,6 +9,7 @@
#include "shared/test/unit_test/utilities/base_object_utils.h"
#include "opencl/source/context/context.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_platform.h"
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
@@ -213,4 +214,25 @@ TEST_F(clSVMAllocTests, GivenAlignmentTooLargeWhenAllocatingSvmThenSvmIsNotAlloc
auto SVMPtr = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 4096 /* Size */, 4096 /* alignment */);
EXPECT_EQ(nullptr, SVMPtr);
};
TEST(clSvmAllocTest, givenSubDeviceWhenCreatingSvmAllocThenProperDeviceBitfieldIsPassed) {
REQUIRE_SVM_OR_SKIP(defaultHwInfo.get());
UltClDeviceFactory deviceFactory{1, 2};
auto device = deviceFactory.subDevices[1];
auto expectedDeviceBitfield = device->getDeviceBitfield();
auto executionEnvironment = device->getExecutionEnvironment();
auto memoryManager = new MockMemoryManager(*executionEnvironment);
std::unique_ptr<MemoryManager> memoryManagerBackup(memoryManager);
std::swap(memoryManagerBackup, executionEnvironment->memoryManager);
MockContext context(device);
EXPECT_NE(expectedDeviceBitfield, memoryManager->recentlyPassedDeviceBitfield);
auto svmPtr = clSVMAlloc(&context, CL_MEM_READ_WRITE, MemoryConstants::pageSize, MemoryConstants::cacheLineSize);
EXPECT_NE(nullptr, svmPtr);
EXPECT_EQ(expectedDeviceBitfield, memoryManager->recentlyPassedDeviceBitfield);
clSVMFree(&context, svmPtr);
std::swap(memoryManagerBackup, executionEnvironment->memoryManager);
}
} // namespace ULT

View File

@@ -35,9 +35,9 @@ struct EnqueueSvmMemCopyTest : public DeviceFixture,
}
CommandQueueFixture::SetUp(pClDevice, 0);
srcSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
srcSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
ASSERT_NE(nullptr, srcSvmPtr);
dstSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
dstSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
ASSERT_NE(nullptr, dstSvmPtr);
auto srcSvmData = context->getSVMAllocsManager()->getSVMAlloc(srcSvmPtr);
ASSERT_NE(nullptr, srcSvmData);
@@ -312,7 +312,7 @@ struct EnqueueSvmMemCopyHw : public ::testing::Test {
}
context = std::make_unique<MockContext>(device.get());
srcSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
srcSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
ASSERT_NE(nullptr, srcSvmPtr);
dstHostPtr = alignedMalloc(256, 64);
}

View File

@@ -34,7 +34,7 @@ struct EnqueueSvmMemFillTest : public DeviceFixture,
ASSERT_TRUE((0 < patternSize) && (patternSize <= 128));
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.coherent = true;
svmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, svmProperties);
svmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, svmProperties, {});
ASSERT_NE(nullptr, svmPtr);
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(svmPtr);
ASSERT_NE(nullptr, svmData);
@@ -156,7 +156,7 @@ struct EnqueueSvmMemFillHw : public ::testing::Test {
}
context = std::make_unique<MockContext>(device.get());
svmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
svmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
ASSERT_NE(nullptr, svmPtr);
}

View File

@@ -43,7 +43,7 @@ struct EnqueueSvmTest : public DeviceFixture,
REQUIRE_SVM_OR_SKIP(defaultHwInfo);
DeviceFixture::SetUp();
CommandQueueFixture::SetUp(pClDevice, 0);
ptrSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
ptrSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
}
void TearDown() override {
@@ -251,7 +251,7 @@ TEST_F(EnqueueSvmTest, GivenNullDstPtrWhenCopyingMemoryThenInvalidVaueErrorIsRet
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableAsyncEventsHandler.set(false);
void *pDstSVM = nullptr;
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
retVal = this->pCmdQ->enqueueSVMMemcpy(
false, // cl_bool blocking_copy
pDstSVM, // void *dst_ptr
@@ -496,7 +496,7 @@ TEST_F(EnqueueSvmTest, givenDstHostPtrAndSrcHostPtrAndSizeZeroWhenEnqueueSVMMemc
HWTEST_F(EnqueueSvmTest, givenSvmToSvmCopyTypeWhenEnqueueNonBlockingSVMMemcpyThenSvmMemcpyCommandIsEnqueued) {
void *pDstSVM = ptrSVM;
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
MockCommandQueueHw<FamilyType> myCmdQ(context, pClDevice, 0);
retVal = myCmdQ.enqueueSVMMemcpy(
false, // cl_bool blocking_copy
@@ -526,7 +526,7 @@ HWTEST_F(EnqueueSvmTest, givenSvmToSvmCopyTypeWhenEnqueueNonBlockingSVMMemcpyThe
TEST_F(EnqueueSvmTest, givenSvmToSvmCopyTypeWhenEnqueueBlockingSVMMemcpyThenSuccessIsReturned) {
void *pDstSVM = ptrSVM;
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
retVal = this->pCmdQ->enqueueSVMMemcpy(
true, // cl_bool blocking_copy
pDstSVM, // void *dst_ptr
@@ -542,7 +542,7 @@ TEST_F(EnqueueSvmTest, givenSvmToSvmCopyTypeWhenEnqueueBlockingSVMMemcpyThenSucc
TEST_F(EnqueueSvmTest, GivenValidParamsWhenCopyingMemoryWithBlockingThenSuccessisReturned) {
void *pDstSVM = ptrSVM;
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
auto uEvent = make_releaseable<UserEvent>();
cl_event eventWaitList[] = {uEvent.get()};
retVal = this->pCmdQ->enqueueSVMMemcpy(
@@ -563,7 +563,7 @@ TEST_F(EnqueueSvmTest, GivenCoherencyWhenCopyingMemoryThenSuccessIsReturned) {
void *pDstSVM = ptrSVM;
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.coherent = true;
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, svmProperties);
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, svmProperties, {});
retVal = this->pCmdQ->enqueueSVMMemcpy(
false, // cl_bool blocking_copy
pDstSVM, // void *dst_ptr
@@ -581,7 +581,7 @@ TEST_F(EnqueueSvmTest, GivenCoherencyWhenCopyingMemoryWithBlockingThenSuccessIsR
void *pDstSVM = ptrSVM;
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.coherent = true;
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, svmProperties);
void *pSrcSVM = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, svmProperties, {});
auto uEvent = make_releaseable<UserEvent>();
cl_event eventWaitList[] = {uEvent.get()};
retVal = this->pCmdQ->enqueueSVMMemcpy(
@@ -806,7 +806,7 @@ TEST_F(EnqueueSvmTest, GivenMultipleThreasWhenAllocatingSvmThenOnlyOneAllocation
auto allocSvm = [&](uint32_t from, uint32_t to) {
for (uint32_t i = from; i <= to; i++) {
svmPtrs[i] = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 1, {});
svmPtrs[i] = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 1, {}, {});
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(svmPtrs[i]);
ASSERT_NE(nullptr, svmData);
auto ga = svmData->gpuAllocation;
@@ -882,7 +882,7 @@ TEST(CreateSvmAllocTests, givenVariousSvmAllocationPropertiesWhenAllocatingSvmTh
svmAllocationProperties.readOnly = isReadOnly;
svmAllocationProperties.hostPtrReadOnly = isHostPtrReadOnly;
auto ptrSVM = mockContext->getSVMAllocsManager()->createSVMAlloc(mockDevice->getRootDeviceIndex(), 256, svmAllocationProperties);
auto ptrSVM = mockContext->getSVMAllocsManager()->createSVMAlloc(mockDevice->getRootDeviceIndex(), 256, svmAllocationProperties, {});
EXPECT_NE(nullptr, ptrSVM);
mockContext->getSVMAllocsManager()->freeSVMAlloc(ptrSVM);
}
@@ -900,7 +900,7 @@ struct EnqueueSvmTestLocalMemory : public DeviceFixture,
DeviceFixture::SetUp();
context = std::make_unique<MockContext>(pClDevice, true);
size = 256;
svmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), size, {});
svmPtr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), size, {}, {});
ASSERT_NE(nullptr, svmPtr);
mockSvmManager = reinterpret_cast<MockSVMAllocsManager *>(context->getSVMAllocsManager());
}
@@ -1423,7 +1423,7 @@ TEST_F(EnqueueSvmTest, givenPageFaultManagerWhenEnqueueMemcpyThenAllocIsDecommit
mockMemoryManager->pageFaultManager.reset(new MockPageFaultManager());
auto memoryManager = context->getMemoryManager();
context->memoryManager = mockMemoryManager.get();
auto srcSvm = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
auto srcSvm = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
mockMemoryManager->getPageFaultManager()->insertAllocation(srcSvm, 256, context->getSVMAllocsManager(), context->getSpecialQueue());
mockMemoryManager->getPageFaultManager()->insertAllocation(ptrSVM, 256, context->getSVMAllocsManager(), context->getSpecialQueue());
EXPECT_EQ(static_cast<MockPageFaultManager *>(mockMemoryManager->getPageFaultManager())->transferToCpuCalled, 2);

View File

@@ -782,8 +782,8 @@ HWTEST_F(ZeroSizeEnqueueHandlerTest, GivenZeroSizeEnqueueIsDetectedWhenCopyingSv
REQUIRE_SVM_OR_SKIP(pDevice);
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(&context, pClDevice, 0));
void *pSrcSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pDstSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSrcSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
void *pDstSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
size_t zeroSize = 0;
mockCmdQ->enqueueSVMMemcpy(false, pSrcSVM, pDstSVM, zeroSize, 0, nullptr, nullptr);
EXPECT_EQ(static_cast<cl_command_type>(CL_COMMAND_MARKER), mockCmdQ->lastCommandType);
@@ -797,8 +797,8 @@ HWTEST_F(ZeroSizeEnqueueHandlerTest, GivenZeroSizeEnqueueIsDetectedWhenCopyingSv
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(&context, pClDevice, 0));
cl_event event;
void *pSrcSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pDstSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSrcSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
void *pDstSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
size_t zeroSize = 0;
mockCmdQ->enqueueSVMMemcpy(false, pSrcSVM, pDstSVM, zeroSize, 0, nullptr, &event);
EXPECT_EQ(static_cast<cl_command_type>(CL_COMMAND_MARKER), mockCmdQ->lastCommandType);
@@ -820,7 +820,7 @@ HWTEST_F(ZeroSizeEnqueueHandlerTest, GivenZeroSizeEnqueueIsDetectedWhenFillingSv
REQUIRE_SVM_OR_SKIP(pDevice);
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(&context, pClDevice, 0));
void *pSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
const float pattern[1] = {1.2345f};
size_t zeroSize = 0;
mockCmdQ->enqueueSVMMemFill(pSVM, &pattern, sizeof(pattern), zeroSize, 0, nullptr, nullptr);
@@ -834,7 +834,7 @@ HWTEST_F(ZeroSizeEnqueueHandlerTest, GivenZeroSizeEnqueueIsDetectedWhenFillingSv
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(&context, pClDevice, 0));
cl_event event;
void *pSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *pSVM = context.getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
const float pattern[1] = {1.2345f};
size_t zeroSize = 0;
mockCmdQ->enqueueSVMMemFill(pSVM, &pattern, sizeof(pattern), zeroSize, 0, nullptr, &event);

View File

@@ -1437,7 +1437,7 @@ HWTEST_F(BcsTests, givenNonZeroCopySvmAllocationWhenConstructingBlitPropertiesFo
SVMAllocsManager svmAllocsManager(&mockMemoryManager);
auto svmAllocationProperties = MemObjHelper::getSvmAllocationProperties(CL_MEM_READ_WRITE);
auto svmAlloc = svmAllocsManager.createSVMAlloc(csr.getRootDeviceIndex(), 1, svmAllocationProperties);
auto svmAlloc = svmAllocsManager.createSVMAlloc(csr.getRootDeviceIndex(), 1, svmAllocationProperties, {});
auto svmData = svmAllocsManager.getSVMAlloc(svmAlloc);
EXPECT_NE(nullptr, svmData->gpuAllocation);
@@ -1480,7 +1480,7 @@ HWTEST_F(BcsTests, givenSvmAllocationWhenBlitCalledThenUsePassedPointers) {
SVMAllocsManager svmAllocsManager(&mockMemoryManager);
auto svmAllocationProperties = MemObjHelper::getSvmAllocationProperties(CL_MEM_READ_WRITE);
auto svmAlloc = svmAllocsManager.createSVMAlloc(csr.getRootDeviceIndex(), 1, svmAllocationProperties);
auto svmAlloc = svmAllocsManager.createSVMAlloc(csr.getRootDeviceIndex(), 1, svmAllocationProperties, {});
auto svmData = svmAllocsManager.getSVMAlloc(svmAlloc);
EXPECT_NE(nullptr, svmData->gpuAllocation);

View File

@@ -664,7 +664,7 @@ TEST_P(PerformanceHintEnqueueMapTest, GivenZeroCopyFlagWhenEnqueueUnmapIsCalling
TEST_F(PerformanceHintEnqueueTest, GivenSVMPointerWhenEnqueueSVMMapIsCallingThenContextProvidesProperHint) {
REQUIRE_SVM_OR_SKIP(pPlatform->getClDevice(0));
void *svmPtr = context->getSVMAllocsManager()->createSVMAlloc(0, 256, {});
void *svmPtr = context->getSVMAllocsManager()->createSVMAlloc(0, 256, {}, {});
pCmdQ->enqueueSVMMap(CL_FALSE, 0, svmPtr, 256, 0, nullptr, nullptr, false);

View File

@@ -512,7 +512,7 @@ TEST_F(CloneKernelTest, GivenArgImmediateWhenCloningKernelThenKernelInfoIsCorrec
TEST_F(CloneKernelTest, GivenExecInfoWhenCloningKernelThenSvmAllocationIsCorrect) {
REQUIRE_SVM_OR_SKIP(pDevice);
void *ptrSVM = pContext->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *ptrSVM = pContext->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
ASSERT_NE(nullptr, ptrSVM);
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSVM);

View File

@@ -291,7 +291,7 @@ TEST_F(BufferSetArgTest, clSetKernelArgBuffer) {
TEST_F(BufferSetArgTest, clSetKernelArgSVMPointer) {
REQUIRE_SVM_OR_SKIP(pDevice);
void *ptrSVM = pContext->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {});
void *ptrSVM = pContext->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 256, {}, {});
EXPECT_NE(nullptr, ptrSVM);
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSVM);

View File

@@ -611,7 +611,7 @@ struct RenderCompressedBuffersSvmTests : public RenderCompressedBuffersTests {
TEST_F(RenderCompressedBuffersSvmTests, givenSvmAllocationWhenCreatingBufferThenForceDisableCompression) {
hwInfo->capabilityTable.ftrRenderCompressedBuffers = true;
auto svmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), sizeof(uint32_t), {});
auto svmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), sizeof(uint32_t), {}, {});
auto expectedAllocationType = context->getSVMAllocsManager()->getSVMAlloc(svmPtr)->gpuAllocation->getAllocationType();
buffer.reset(Buffer::create(context.get(), CL_MEM_USE_HOST_PTR, sizeof(uint32_t), svmPtr, retVal));
EXPECT_EQ(expectedAllocationType, buffer->getGraphicsAllocation()->getAllocationType());
@@ -979,7 +979,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenDstHostPtrWhenEnqueueSVMMemcpyThenEnqueu
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(bcsMockContext.get(), device.get(), nullptr));
auto pDstSVM = std::make_unique<char[]>(1);
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 1, {});
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 1, {}, {});
cmdQ->enqueueSVMMemcpy(true, pDstSVM.get(), pSrcSVM, 1, 0, nullptr, nullptr);
@@ -1000,7 +1000,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenSrcHostPtrWhenEnqueueSVMMemcpyThenEnqueu
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(bcsMockContext.get(), device.get(), nullptr));
auto pSrcSVM = std::make_unique<char[]>(1);
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 1, {});
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 1, {}, {});
cmdQ->enqueueSVMMemcpy(true, pDstSVM, pSrcSVM.get(), 1, 0, nullptr, nullptr);
@@ -1657,7 +1657,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingSVMMemcpyAndEnqueuReadBufferIsCa
myMockCsr->gpgpuCsr = &gpgpuCsr;
auto pDstSVM = std::make_unique<char[]>(256);
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
cmdQ->enqueueSVMMemcpy(false, pDstSVM.get(), pSrcSVM, 256, 0, nullptr, nullptr);
EXPECT_EQ(0u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled);
@@ -1690,7 +1690,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenSrcHostPtrBlockingEnqueueSVMMemcpyAndEnq
myMockCsr->gpgpuCsr = &gpgpuCsr;
auto pSrcSVM = std::make_unique<char[]>(256);
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
cmdQ->enqueueSVMMemcpy(false, pDstSVM, pSrcSVM.get(), 256, 0, nullptr, nullptr);
EXPECT_EQ(0u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled);
@@ -1744,8 +1744,8 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenSvmToSvmCopyWhenEnqueueSVMMemcpyThenSvmM
using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(bcsMockContext.get(), device.get(), nullptr));
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
cmdQ->enqueueSVMMemcpy(false, pDstSVM, pSrcSVM, 256, 0, nullptr, nullptr);
@@ -1776,8 +1776,8 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenSvmToSvmCopyTypeWhenEnqueueNonBlockingSV
auto &gpgpuCsr = cmdQ->getGpgpuCommandStreamReceiver();
myMockCsr->gpgpuCsr = &gpgpuCsr;
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {});
auto pDstSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
auto pSrcSVM = bcsMockContext->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), 256, {}, {});
cmdQ->enqueueSVMMemcpy(false, pDstSVM, pSrcSVM, 256, 0, nullptr, nullptr);
EXPECT_EQ(0u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled);
@@ -2174,7 +2174,7 @@ TEST_P(ValidHostPtr, failedAllocationInjection) {
TEST_P(ValidHostPtr, SvmHostPtr) {
const ClDeviceInfo &devInfo = pClDevice->getDeviceInfo();
if (devInfo.svmCapabilities != 0) {
auto ptr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 64, {});
auto ptr = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 64, {}, {});
auto bufferSvm = Buffer::create(context.get(), CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, 64, ptr, retVal);
EXPECT_NE(nullptr, bufferSvm);

View File

@@ -2141,24 +2141,30 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGetReservedMemoryIsCalledManyTimes
class MemoryManagerWithFailure : public MockMemoryManager {
public:
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
recentlyPassedDeviceBitfield = properties.subDevicesBitfield;
return nullptr;
}
};
TEST(MemoryManagerTest, whenMemoryManagerReturnsNullptrThenAllocateGlobalsSurfaceAlsoReturnsNullptr) {
MockClDevice device{new MockDevice};
std::unique_ptr<MemoryManager> memoryManager(new MemoryManagerWithFailure());
device.injectMemoryManager(memoryManager.release());
auto deviceBitfield = device.getDeviceBitfield();
auto memoryManager = new MemoryManagerWithFailure();
device.injectMemoryManager(memoryManager);
WhiteBox<NEO::LinkerInput> linkerInput;
linkerInput.traits.exportsGlobalConstants = true;
linkerInput.traits.exportsGlobalVariables = true;
memoryManager->recentlyPassedDeviceBitfield = {};
GraphicsAllocation *allocation = allocateGlobalsSurface(nullptr, device.getDevice(), 1024, false, &linkerInput, nullptr);
EXPECT_EQ(nullptr, allocation);
EXPECT_EQ(deviceBitfield, memoryManager->recentlyPassedDeviceBitfield);
auto svmAllocsManager = std::make_unique<SVMAllocsManager>(device.getMemoryManager());
memoryManager->recentlyPassedDeviceBitfield = {};
allocation = allocateGlobalsSurface(svmAllocsManager.get(), device.getDevice(), 1024, false, &linkerInput, nullptr);
EXPECT_EQ(nullptr, allocation);
EXPECT_EQ(deviceBitfield, memoryManager->recentlyPassedDeviceBitfield);
}
HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenEnableHostPtrTrackingFlagIsSetTo0ThenHostPointerTrackingIsDisabled) {

View File

@@ -53,7 +53,7 @@ using SVMMemoryAllocatorTest = Test<SVMMemoryAllocatorFixture<false>>;
using SVMLocalMemoryAllocatorTest = Test<SVMMemoryAllocatorFixture<true>>;
TEST_F(SVMMemoryAllocatorTest, whenCreateZeroSizedSVMAllocationThenReturnNullptr) {
auto ptr = svmManager->createSVMAlloc(0, 0, {});
auto ptr = svmManager->createSVMAlloc(0, 0, {}, {});
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
EXPECT_EQ(ptr, nullptr);
@@ -65,7 +65,7 @@ TEST_F(SVMMemoryAllocatorTest, whenRequestSVMAllocsThenReturnNonNullptr) {
}
TEST_F(SVMMemoryAllocatorTest, whenSVMAllocationIsFreedThenCannotBeGotAgain) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
@@ -83,7 +83,7 @@ TEST_F(SVMMemoryAllocatorTest, whenSVMAllocationIsFreedThenCannotBeGotAgain) {
}
TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromReturnedPointerAreaThenReturnSameAllocation) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
@@ -102,7 +102,7 @@ TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromReturnedPointerAreaThenRe
}
TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPointerAreaThenDontReturnThisAllocation) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
@@ -123,7 +123,7 @@ TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPointerA
TEST_F(SVMMemoryAllocatorTest, whenCouldNotAllocateInMemoryManagerThenReturnsNullAndDoesNotChangeAllocsMap) {
FailMemoryManager failMemoryManager(executionEnvironment);
svmManager->memoryManager = &failMemoryManager;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
svmManager->freeSVMAlloc(ptr);
@@ -144,7 +144,7 @@ TEST_F(SVMMemoryAllocatorTest, whenCouldNotAllocateInMemoryManagerThenCreateUnif
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedWhenAllocatingSvmMemoryThenDontPreferRenderCompression) {
MockMemoryManager memoryManager64Kb(true, false, executionEnvironment);
svmManager->memoryManager = &memoryManager64Kb;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_FALSE(memoryManager64Kb.preferRenderCompressedFlagPassed);
svmManager->freeSVMAlloc(ptr);
}
@@ -152,13 +152,13 @@ TEST_F(SVMMemoryAllocatorTest, given64kbAllowedWhenAllocatingSvmMemoryThenDontPr
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedwhenAllocatingSvmMemoryThenAllocationIsIn64kbPagePool) {
MockMemoryManager memoryManager64Kb(true, false, executionEnvironment);
svmManager->memoryManager = &memoryManager64Kb;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_EQ(MemoryPool::System64KBPages, svmManager->getSVMAlloc(ptr)->gpuAllocation->getMemoryPool());
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, given64kbDisallowedWhenAllocatingSvmMemoryThenAllocationIsIn4kbPagePool) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_EQ(MemoryPool::System4KBPages, svmManager->getSVMAlloc(ptr)->gpuAllocation->getMemoryPool());
svmManager->freeSVMAlloc(ptr);
}
@@ -166,7 +166,7 @@ TEST_F(SVMMemoryAllocatorTest, given64kbDisallowedWhenAllocatingSvmMemoryThenAll
TEST_F(SVMMemoryAllocatorTest, whenCoherentFlagIsPassedThenAllocationIsCoherent) {
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.coherent = true;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, svmProperties);
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, svmProperties, {});
EXPECT_TRUE(svmManager->getSVMAlloc(ptr)->gpuAllocation->isCoherent());
svmManager->freeSVMAlloc(ptr);
}
@@ -389,7 +389,7 @@ TEST(SvmAllocationPropertiesTests, givenDifferentMemFlagsWhenGettingSvmAllocatio
TEST_F(SVMMemoryAllocatorTest, whenReadOnlySvmAllocationCreatedThenGraphicsAllocationHasWriteableFlagFalse) {
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.readOnly = true;
void *svm = svmManager->createSVMAlloc(0, 4096, svmProperties);
void *svm = svmManager->createSVMAlloc(0, 4096, svmProperties, {});
EXPECT_NE(nullptr, svm);
auto svmData = svmManager->getSVMAlloc(svm);
@@ -402,7 +402,7 @@ TEST_F(SVMMemoryAllocatorTest, whenReadOnlySvmAllocationCreatedThenGraphicsAlloc
}
TEST_F(SVMLocalMemoryAllocatorTest, whenAllocatingSvmThenExpectCpuAllocationWithPointerAndGpuAllocationWithSameGpuAddress) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
@@ -418,7 +418,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenAllocatingSvmThenExpectCpuAllocationWith
}
TEST_F(SVMLocalMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPointerAreaThenDontReturnThisAllocation) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
@@ -439,7 +439,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPoi
TEST_F(SVMLocalMemoryAllocatorTest, whenCouldNotAllocateCpuAllocationInMemoryManagerThenReturnsNullAndDoesNotChangeAllocsMap) {
FailMemoryManager failMemoryManager(false, true, executionEnvironment);
svmManager->memoryManager = &failMemoryManager;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
svmManager->freeSVMAlloc(ptr);
@@ -448,7 +448,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenCouldNotAllocateCpuAllocationInMemoryMan
TEST_F(SVMLocalMemoryAllocatorTest, whenCouldNotAllocateGpuAllocationInMemoryManagerThenReturnsNullAndDoesNotChangeAllocsMap) {
FailMemoryManager failMemoryManager(1, executionEnvironment, true);
svmManager->memoryManager = &failMemoryManager;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
svmManager->freeSVMAlloc(ptr);
@@ -456,7 +456,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenCouldNotAllocateGpuAllocationInMemoryMan
TEST_F(SVMLocalMemoryAllocatorTest, whenCouldNotReserveCpuAddressRangeInMemoryManagerThenReturnsNullAndDoesNotChangeAllocsMap) {
memoryManager->failReserveAddress = true;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {});
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, {});
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
}

View File

@@ -90,15 +90,17 @@ void SVMAllocsManager::makeInternalAllocationsResident(CommandStreamReceiver &co
SVMAllocsManager::SVMAllocsManager(MemoryManager *memoryManager) : memoryManager(memoryManager) {
}
void *SVMAllocsManager::createSVMAlloc(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties svmProperties) {
void *SVMAllocsManager::createSVMAlloc(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties svmProperties, const DeviceBitfield &deviceBitfield) {
if (size == 0)
return nullptr;
std::unique_lock<SpinLock> lock(mtx);
if (!memoryManager->isLocalMemorySupported(rootDeviceIndex)) {
return createZeroCopySvmAllocation(rootDeviceIndex, size, svmProperties);
return createZeroCopySvmAllocation(rootDeviceIndex, size, svmProperties, deviceBitfield);
} else {
return createUnifiedAllocationWithDeviceStorage(rootDeviceIndex, size, svmProperties, {});
UnifiedMemoryProperties unifiedMemoryProperties{};
unifiedMemoryProperties.subdeviceBitfield = deviceBitfield;
return createUnifiedAllocationWithDeviceStorage(rootDeviceIndex, size, svmProperties, unifiedMemoryProperties);
}
}
@@ -196,8 +198,13 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
return false;
}
void *SVMAllocsManager::createZeroCopySvmAllocation(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties &svmProperties) {
AllocationProperties properties{rootDeviceIndex, size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY};
void *SVMAllocsManager::createZeroCopySvmAllocation(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties &svmProperties, const DeviceBitfield &deviceBitfield) {
AllocationProperties properties{rootDeviceIndex,
true, // allocateMemory
size,
GraphicsAllocation::AllocationType::SVM_ZERO_COPY,
false, // isMultiStorageAllocation
deviceBitfield};
MemoryPropertiesParser::fillCachePolicyInProperties(properties, false, svmProperties.readOnly, false);
GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
if (!allocation) {

View File

@@ -82,7 +82,7 @@ class SVMAllocsManager {
};
SVMAllocsManager(MemoryManager *memoryManager);
void *createSVMAlloc(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties svmProperties);
void *createSVMAlloc(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties svmProperties, const DeviceBitfield &deviceBitfield);
void *createUnifiedMemoryAllocation(uint32_t rootDeviceIndex, size_t size, const UnifiedMemoryProperties &svmProperties);
void *createSharedUnifiedMemoryAllocation(uint32_t rootDeviceIndex, size_t size, const UnifiedMemoryProperties &svmProperties, void *cmdQ);
SvmAllocationData *getSVMAlloc(const void *ptr);
@@ -100,7 +100,7 @@ class SVMAllocsManager {
void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData);
protected:
void *createZeroCopySvmAllocation(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties &svmProperties);
void *createZeroCopySvmAllocation(uint32_t rootDeviceIndex, size_t size, const SvmAllocationProperties &svmProperties, const DeviceBitfield &deviceBitfield);
void freeZeroCopySvmAllocation(SvmAllocationData *svmData);

View File

@@ -28,7 +28,7 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
svmProps.coherent = false;
svmProps.readOnly = constant;
svmProps.hostPtrReadOnly = constant;
auto ptr = svmAllocManager->createSVMAlloc(device.getRootDeviceIndex(), size, svmProps);
auto ptr = svmAllocManager->createSVMAlloc(device.getRootDeviceIndex(), size, svmProps, device.getDeviceBitfield());
DEBUG_BREAK_IF(ptr == nullptr);
if (ptr == nullptr) {
return nullptr;