diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 9a83677cae..f986392abc 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -3524,7 +3524,7 @@ void *clHostMemAllocINTEL( cl_mem_flags flags = 0; cl_mem_flags_intel flagsIntel = 0; cl_mem_alloc_flags_intel allocflags = 0; - unifiedMemoryProperties.subdeviceBitfield = neoContext->getDeviceBitfieldForAllocation(); + unifiedMemoryProperties.subdeviceBitfield = neoContext->getDeviceBitfieldForAllocation(neoContext->getDevice(0)->getRootDeviceIndex()); if (!MemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel, allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN, *neoContext)) { @@ -3620,7 +3620,7 @@ void *clSharedMemAllocINTEL( unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDeviceBitfield(); } else { neoDevice = neoContext->getDevice(0); - unifiedMemoryProperties.subdeviceBitfield = neoContext->getDeviceBitfieldForAllocation(); + unifiedMemoryProperties.subdeviceBitfield = neoContext->getDeviceBitfieldForAllocation(neoContext->getDevice(0)->getRootDeviceIndex()); } if (size > neoDevice->getSharedDeviceInfo().maxMemAllocSize && !unifiedMemoryProperties.allocationFlags.flags.allowUnrestrictedSize) { err.set(CL_INVALID_BUFFER_SIZE); diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index a33545be20..104ec6ab87 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -198,6 +198,15 @@ bool Context::createImpl(const cl_context_properties *properties, } this->devices = inputDevices; + for (auto &rootDeviceIndex : rootDeviceIndices) { + DeviceBitfield deviceBitfield{}; + for (const auto &pDevice : devices) { + if (pDevice->getRootDeviceIndex() == rootDeviceIndex) { + deviceBitfield |= pDevice->getDeviceBitfield(); + } + } + deviceBitfields.insert({rootDeviceIndex, deviceBitfield}); + } if (devices.size() > 0) { maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less()); @@ -438,13 +447,8 @@ AsyncEventsHandler &Context::getAsyncEventsHandler() const { return *static_cast(devices[0]->getExecutionEnvironment())->getAsyncEventsHandler(); } -DeviceBitfield Context::getDeviceBitfieldForAllocation() const { - DeviceBitfield deviceBitfield{}; - for (const auto &pDevice : devices) { - deviceBitfield |= pDevice->getDeviceBitfield(); - } - - return deviceBitfield; +DeviceBitfield Context::getDeviceBitfieldForAllocation(uint32_t rootDeviceIndex) const { + return deviceBitfields.at(rootDeviceIndex); } void Context::setupContextType() { diff --git a/opencl/source/context/context.h b/opencl/source/context/context.h index 232463edb2..ed339fafd1 100644 --- a/opencl/source/context/context.h +++ b/opencl/source/context/context.h @@ -17,6 +17,7 @@ #include "opencl/source/helpers/destructor_callback.h" #include +#include #include namespace NEO { @@ -148,7 +149,7 @@ class Context : public BaseObject<_cl_context> { AsyncEventsHandler &getAsyncEventsHandler() const; - DeviceBitfield getDeviceBitfieldForAllocation() const; + DeviceBitfield getDeviceBitfieldForAllocation(uint32_t rootDeviceIndex) const; bool getResolvesRequiredInKernels() const { return resolvesRequiredInKernels; } @@ -167,6 +168,7 @@ class Context : public BaseObject<_cl_context> { void setupContextType(); std::set rootDeviceIndices = {}; + std::map deviceBitfields; std::vector> sharingFunctions; ClDeviceVector devices; std::list destructorCallbacks; diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index e843ba73fa..6a49f03362 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -255,7 +255,7 @@ Buffer *Buffer::create(Context *context, if (!memory) { AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, allocateMemory, size, allocationType, context->areMultiStorageAllocationsPreferred(), - context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation()); + context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex)); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); } @@ -271,7 +271,7 @@ Buffer *Buffer::create(Context *context, AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, true, // allocateMemory size, allocationType, context->areMultiStorageAllocationsPreferred(), - context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation()); + context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex)); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); } @@ -326,7 +326,7 @@ Buffer *Buffer::create(Context *context, false, // allocateMemory size, GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(rootDeviceIndex)}; properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true; mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); } diff --git a/opencl/source/mem_obj/image.cpp b/opencl/source/mem_obj/image.cpp index 8e7193d090..f45f3fc815 100644 --- a/opencl/source/mem_obj/image.cpp +++ b/opencl/source/mem_obj/image.cpp @@ -275,7 +275,7 @@ Image *Image::create(Context *context, AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, false, // allocateMemory memoryProperties, context->getDevice(0)->getHardwareInfo(), - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(rootDeviceIndex)); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); @@ -293,7 +293,7 @@ Image *Image::create(Context *context, false, // allocateMemory imgInfo.size, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}, + context->getDeviceBitfieldForAllocation(rootDeviceIndex)}, hostPtr); memory->setDefaultGmm(gmm); zeroCopy = true; @@ -303,7 +303,7 @@ Image *Image::create(Context *context, false, // allocateMemory hostPtrMinSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(rootDeviceIndex)}; properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true; mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); } @@ -311,7 +311,7 @@ Image *Image::create(Context *context, AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, true, // allocateMemory memoryProperties, context->getDevice(0)->getHardwareInfo(), - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(rootDeviceIndex)); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) { diff --git a/opencl/source/mem_obj/mem_obj.cpp b/opencl/source/mem_obj/mem_obj.cpp index ff00ce0046..ee991a52a8 100644 --- a/opencl/source/mem_obj/mem_obj.cpp +++ b/opencl/source/mem_obj/mem_obj.cpp @@ -371,7 +371,7 @@ void *MemObj::getBasePtrForMap(uint32_t rootDeviceIndex) { false, // allocateMemory getSize(), GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, //isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(rootDeviceIndex)}; auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, memory); setMapAllocation(allocation); diff --git a/opencl/source/mem_obj/pipe.cpp b/opencl/source/mem_obj/pipe.cpp index 5c65de3d54..56405b9ab4 100644 --- a/opencl/source/mem_obj/pipe.cpp +++ b/opencl/source/mem_obj/pipe.cpp @@ -64,7 +64,7 @@ Pipe *Pipe::create(Context *context, true, // allocateMemory size, GraphicsAllocation::AllocationType::PIPE, false, // isMultiStorageAllocation - context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation()); + context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex)); GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); if (!memory) { errcodeRet = CL_OUT_OF_HOST_MEMORY; diff --git a/opencl/source/sharings/d3d/d3d_buffer.h b/opencl/source/sharings/d3d/d3d_buffer.h index 9091f61f9b..6a7cb15923 100644 --- a/opencl/source/sharings/d3d/d3d_buffer.h +++ b/opencl/source/sharings/d3d/d3d_buffer.h @@ -44,7 +44,7 @@ class D3DBuffer : public D3DSharing { 0, // size GraphicsAllocation::AllocationType::SHARED_BUFFER, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true); auto d3dBufferObj = new D3DBuffer(context, d3dBuffer, bufferStaging, sharedResource); diff --git a/opencl/source/sharings/d3d/d3d_surface.cpp b/opencl/source/sharings/d3d/d3d_surface.cpp index d5acbff790..ea0cd13146 100644 --- a/opencl/source/sharings/d3d/d3d_surface.cpp +++ b/opencl/source/sharings/d3d/d3d_surface.cpp @@ -86,7 +86,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo 0u, // size GraphicsAllocation::AllocationType::SHARED_IMAGE, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(rootDeviceIndex)); alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties, false); updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u); @@ -104,7 +104,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, true, // allocateMemory memoryProperties, context->getDevice(0)->getHardwareInfo(), - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(rootDeviceIndex)); allocProperties.allocationType = GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY; alloc = context->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); diff --git a/opencl/source/sharings/d3d/d3d_texture.cpp b/opencl/source/sharings/d3d/d3d_texture.cpp index 1e0f70a745..26fff456e3 100644 --- a/opencl/source/sharings/d3d/d3d_texture.cpp +++ b/opencl/source/sharings/d3d/d3d_texture.cpp @@ -82,7 +82,7 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ 0u, // size GraphicsAllocation::AllocationType::SHARED_IMAGE, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(rootDeviceIndex)); if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false); } else { @@ -167,7 +167,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ 0u, // size GraphicsAllocation::AllocationType::SHARED_IMAGE, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(rootDeviceIndex)); if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false); } else { diff --git a/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp b/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp index 99b733f3cf..e6f96531d3 100644 --- a/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp @@ -148,7 +148,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne 0u, // size GraphicsAllocation::AllocationType::SHARED_BUFFER, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; // couldn't find allocation for reuse - create new graphicsAllocation = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true); diff --git a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp index 5ece955e84..2cc18d8126 100644 --- a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp @@ -55,7 +55,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl 0u, // size GraphicsAllocation::AllocationType::SHARED_IMAGE, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false); if (alloc == nullptr) { @@ -124,7 +124,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl GraphicsAllocation *mcsAlloc = nullptr; if (texInfo.globalShareHandleMCS) { - AllocationProperties allocProperties(context->getDevice(0)->getRootDeviceIndex(), 0, GraphicsAllocation::AllocationType::MCS, context->getDeviceBitfieldForAllocation()); + AllocationProperties allocProperties(context->getDevice(0)->getRootDeviceIndex(), 0, GraphicsAllocation::AllocationType::MCS, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false); if (texInfo.pGmmResInfoMCS) { DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr); diff --git a/opencl/source/sharings/unified/unified_sharing.cpp b/opencl/source/sharings/unified/unified_sharing.cpp index 8e3b0bed79..4cde2a8a36 100644 --- a/opencl/source/sharings/unified/unified_sharing.cpp +++ b/opencl/source/sharings/unified/unified_sharing.cpp @@ -45,7 +45,7 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U 0u, // size allocationType, false, // isMultiStorageAllocation - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false); } default: diff --git a/opencl/source/sharings/va/va_surface.cpp b/opencl/source/sharings/va/va_surface.cpp index f2fb61d848..d1816851b8 100644 --- a/opencl/source/sharings/va/va_surface.cpp +++ b/opencl/source/sharings/va/va_surface.cpp @@ -109,7 +109,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh AllocationProperties properties(context->getDevice(0)->getRootDeviceIndex(), false, // allocateMemory imgInfo, GraphicsAllocation::AllocationType::SHARED_IMAGE, - context->getDeviceBitfieldForAllocation()); + context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); diff --git a/opencl/test/unit_test/api/cl_svm_alloc_tests.inl b/opencl/test/unit_test/api/cl_svm_alloc_tests.inl index b6b6f4503c..1f5157d0f2 100644 --- a/opencl/test/unit_test/api/cl_svm_alloc_tests.inl +++ b/opencl/test/unit_test/api/cl_svm_alloc_tests.inl @@ -244,7 +244,7 @@ TEST(clSvmAllocTest, givenSubDeviceWhenCreatingSvmAllocThenProperDeviceBitfieldI std::swap(memoryManagerBackup, executionEnvironment->memoryManager); MockContext context(device); - auto expectedDeviceBitfield = context.getDeviceBitfieldForAllocation(); + auto expectedDeviceBitfield = context.getDeviceBitfieldForAllocation(device->getRootDeviceIndex()); EXPECT_NE(expectedDeviceBitfield, memoryManager->recentlyPassedDeviceBitfield); auto svmPtr = clSVMAlloc(&context, CL_MEM_READ_WRITE, MemoryConstants::pageSize, MemoryConstants::cacheLineSize); EXPECT_NE(nullptr, svmPtr); diff --git a/opencl/test/unit_test/context/context_multi_device_tests.cpp b/opencl/test/unit_test/context/context_multi_device_tests.cpp index 03d0dc3645..09652c532f 100644 --- a/opencl/test/unit_test/context/context_multi_device_tests.cpp +++ b/opencl/test/unit_test/context/context_multi_device_tests.cpp @@ -221,4 +221,4 @@ TEST(ContextMultiDevice, givenRootDeviceAndSubsetOfSubdevicesWhenCreatingContext EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_NE(nullptr, context2.get()); EXPECT_EQ(ContextType::CONTEXT_TYPE_UNRESTRICTIVE, context2->peekContextType()); -} \ No newline at end of file +} diff --git a/opencl/test/unit_test/context/context_tests.cpp b/opencl/test/unit_test/context/context_tests.cpp index 932024761a..c676f9805b 100644 --- a/opencl/test/unit_test/context/context_tests.cpp +++ b/opencl/test/unit_test/context/context_tests.cpp @@ -433,7 +433,7 @@ TEST(Context, givenContextWithSingleDevicesWhenGettingDeviceBitfieldForAllocatio auto device = deviceFactory.subDevices[1]; auto expectedDeviceBitfield = device->getDeviceBitfield(); MockContext context(device); - EXPECT_EQ(expectedDeviceBitfield.to_ulong(), context.getDeviceBitfieldForAllocation().to_ulong()); + EXPECT_EQ(expectedDeviceBitfield.to_ulong(), context.getDeviceBitfieldForAllocation(device->getRootDeviceIndex()).to_ulong()); } TEST(Context, givenContextWithMultipleSubDevicesWhenGettingDeviceBitfieldForAllocationThenMergedDeviceBitfieldIsReturned) { UltClDeviceFactory deviceFactory{1, 3}; @@ -444,7 +444,29 @@ TEST(Context, givenContextWithMultipleSubDevicesWhenGettingDeviceBitfieldForAllo auto context = Context::create(0, deviceVector, nullptr, nullptr, retVal); EXPECT_NE(nullptr, context); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(expectedDeviceBitfield.to_ulong(), context->getDeviceBitfieldForAllocation().to_ulong()); + EXPECT_EQ(expectedDeviceBitfield.to_ulong(), context->getDeviceBitfieldForAllocation(deviceFactory.rootDevices[0]->getRootDeviceIndex()).to_ulong()); + context->release(); +} + +TEST(MultiDeviceContextTest, givenContextWithTwoDifferentSubDevicesFromDifferentRootDevicesWhenGettingDeviceBitfieldForAllocationThenSeparatedDeviceBitfieldsAreReturned) { + DebugManagerStateRestore restorer; + + DebugManager.flags.EnableMultiRootDeviceContexts.set(true); + UltClDeviceFactory deviceFactory{2, 2}; + cl_int retVal; + cl_device_id devices[]{deviceFactory.subDevices[1], deviceFactory.subDevices[2]}; + ClDeviceVector deviceVector(devices, 2); + + auto expectedDeviceBitfieldForRootDevice0 = deviceFactory.subDevices[1]->getDeviceBitfield(); + auto expectedDeviceBitfieldForRootDevice1 = deviceFactory.subDevices[2]->getDeviceBitfield(); + + auto context = Context::create(0, deviceVector, nullptr, nullptr, retVal); + EXPECT_NE(nullptr, context); + EXPECT_EQ(CL_SUCCESS, retVal); + + EXPECT_EQ(expectedDeviceBitfieldForRootDevice0.to_ulong(), context->getDeviceBitfieldForAllocation(deviceFactory.rootDevices[0]->getRootDeviceIndex()).to_ulong()); + EXPECT_EQ(expectedDeviceBitfieldForRootDevice1.to_ulong(), context->getDeviceBitfieldForAllocation(deviceFactory.rootDevices[1]->getRootDeviceIndex()).to_ulong()); + context->release(); } diff --git a/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp b/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp index dc89d73b49..70bb33e067 100644 --- a/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp +++ b/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp @@ -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, {}, context->getDeviceBitfieldForAllocation()); + void *svmPtr = context->getSVMAllocsManager()->createSVMAlloc(0, 256, {}, context->getDeviceBitfieldForAllocation(0)); pCmdQ->enqueueSVMMap(CL_FALSE, 0, svmPtr, 256, 0, nullptr, nullptr, false); diff --git a/opencl/test/unit_test/fixtures/multi_root_device_fixture.h b/opencl/test/unit_test/fixtures/multi_root_device_fixture.h index 05d33baf5e..30bb3dfd4b 100644 --- a/opencl/test/unit_test/fixtures/multi_root_device_fixture.h +++ b/opencl/test/unit_test/fixtures/multi_root_device_fixture.h @@ -17,15 +17,22 @@ namespace NEO { class MultiRootDeviceFixture : public ::testing::Test { public: void SetUp() override { - DebugManager.flags.CreateMultipleRootDevices.set(2 * expectedRootDeviceIndex); + DebugManager.flags.CreateMultipleRootDevices.set(3 * expectedRootDeviceIndex); + device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr, expectedRootDeviceIndex)); - context.reset(new MockContext(device.get())); + device2 = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr, 2u)); + + cl_device_id devices[] = { + device.get(), device2.get()}; + + context.reset(new MockContext(ClDeviceVector(devices, 2))); mockMemoryManager = reinterpret_cast(device->getMemoryManager()); } const uint32_t expectedRootDeviceIndex = 1; DebugManagerStateRestore restorer; std::unique_ptr device; + std::unique_ptr device2; std::unique_ptr context; MockMemoryManager *mockMemoryManager; }; diff --git a/opencl/test/unit_test/mem_obj/image_tests.cpp b/opencl/test/unit_test/mem_obj/image_tests.cpp index fd24f96927..1c09fe6efb 100644 --- a/opencl/test/unit_test/mem_obj/image_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tests.cpp @@ -1623,7 +1623,7 @@ HWTEST_F(HwImageTest, givenImageHwWithUnifiedSurfaceAndMcsWhenSettingParamsForMu cl_image_format format = {}; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, {}, context.getDevice(0)->getHardwareInfo(), context.getDeviceBitfieldForAllocation()); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, {}, context.getDevice(0)->getHardwareInfo(), context.getDeviceBitfieldForAllocation(0)); auto graphicsAllocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); diff --git a/opencl/test/unit_test/mem_obj/mem_obj_destruction_tests.cpp b/opencl/test/unit_test/mem_obj/mem_obj_destruction_tests.cpp index e22135a04b..506047aef2 100644 --- a/opencl/test/unit_test/mem_obj/mem_obj_destruction_tests.cpp +++ b/opencl/test/unit_test/mem_obj/mem_obj_destruction_tests.cpp @@ -326,7 +326,7 @@ HWTEST_P(MemObjSyncDestructionTest, givenMemObjWithMapAllocationWhenAsyncDestruc MemoryConstants::pageSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())}; mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); memObj->setMapAllocation(mapAllocation); @@ -365,7 +365,7 @@ HWTEST_P(MemObjSyncDestructionTest, givenMemObjWithMapAllocationWhenAsyncDestruc MemoryConstants::pageSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())}; mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); memObj->setMapAllocation(mapAllocation); @@ -396,7 +396,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenMemObjWithMapAllocationWithoutMemUseHo MemoryConstants::pageSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())}; mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); memObj->setMapAllocation(mapAllocation); @@ -436,7 +436,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenMemObjWithMapAllocationWithMemUseHostP MemoryConstants::pageSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION, false, - context->getDeviceBitfieldForAllocation()}; + context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())}; mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); memObj->setMapAllocation(mapAllocation); diff --git a/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp b/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp index 9436baa5af..db769a831d 100644 --- a/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp +++ b/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp @@ -540,28 +540,28 @@ TEST_F(MemObjMultiRootDeviceTests, WhenMemObjIsCreatedWithMultiGraphicsAllocatio } TEST_F(MemObjMultiRootDeviceTests, WhenMemObjMapAreCreatedThenAllAllocationAreDestroyedProperly) { - auto allocation0 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, MemoryConstants::pageSize}); + auto allocation0 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{2, MemoryConstants::pageSize}); auto allocation1 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1, MemoryConstants::pageSize}); - auto multiGraphicsAllocation = MultiGraphicsAllocation(1); + auto multiGraphicsAllocation = MultiGraphicsAllocation(2); multiGraphicsAllocation.addAllocation(allocation0); multiGraphicsAllocation.addAllocation(allocation1); - auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context->getDevice(0)->getDevice()); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context->getDevice(1)->getDevice()); std::unique_ptr memObj( new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0, 1, nullptr, nullptr, multiGraphicsAllocation, true, false, false)); - auto mapAllocation0 = memObj->getMapAllocation(0); + auto mapAllocation0 = memObj->getMapAllocation(2); auto mapAllocation1 = memObj->getMapAllocation(1); EXPECT_EQ(nullptr, mapAllocation0); EXPECT_EQ(nullptr, mapAllocation1); - EXPECT_NE(nullptr, memObj->getBasePtrForMap(0)); - EXPECT_EQ(memObj->getBasePtrForMap(0), memObj->getBasePtrForMap(1)); + EXPECT_NE(nullptr, memObj->getBasePtrForMap(2)); + EXPECT_EQ(memObj->getBasePtrForMap(2), memObj->getBasePtrForMap(1)); - mapAllocation0 = memObj->getMapAllocation(0); + mapAllocation0 = memObj->getMapAllocation(2); mapAllocation1 = memObj->getMapAllocation(1); ASSERT_NE(nullptr, mapAllocation0); diff --git a/opencl/test/unit_test/mocks/mock_context.cpp b/opencl/test/unit_test/mocks/mock_context.cpp index b939c19b03..9b206a6686 100644 --- a/opencl/test/unit_test/mocks/mock_context.cpp +++ b/opencl/test/unit_test/mocks/mock_context.cpp @@ -43,6 +43,9 @@ MockContext::MockContext( specialQueue = nullptr; defaultDeviceQueue = nullptr; driverDiagnostics = nullptr; + rootDeviceIndices = {}; + maxRootDeviceIndex = std::numeric_limits::max(); + deviceBitfields = {}; } MockContext::~MockContext() { @@ -91,10 +94,24 @@ std::unique_ptr &MockContext::getAsyncEventsHandlerUniquePtr void MockContext::initializeWithDevices(const ClDeviceVector &devices, bool noSpecialQueue) { for (auto &pClDevice : devices) { pClDevice->incRefInternal(); + rootDeviceIndices.insert(pClDevice->getRootDeviceIndex()); } + maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less()); + this->devices = devices; memoryManager = devices[0]->getMemoryManager(); svmAllocsManager = new SVMAllocsManager(memoryManager); + + for (auto &rootDeviceIndex : rootDeviceIndices) { + DeviceBitfield deviceBitfield{}; + for (const auto &pDevice : devices) { + if (pDevice->getRootDeviceIndex() == rootDeviceIndex) { + deviceBitfield |= pDevice->getDeviceBitfield(); + } + } + deviceBitfields.insert({rootDeviceIndex, deviceBitfield}); + } + cl_int retVal; if (!noSpecialQueue) { auto commandQueue = CommandQueue::create(this, devices[0], nullptr, false, retVal); diff --git a/opencl/test/unit_test/mocks/mock_context.h b/opencl/test/unit_test/mocks/mock_context.h index 1c10769cb4..6c0b065c94 100644 --- a/opencl/test/unit_test/mocks/mock_context.h +++ b/opencl/test/unit_test/mocks/mock_context.h @@ -19,13 +19,17 @@ class AsyncEventsHandler; class MockContext : public Context { public: using Context::contextType; + using Context::deviceBitfields; using Context::driverDiagnostics; + using Context::maxRootDeviceIndex; using Context::memoryManager; using Context::preferD3dSharedResources; using Context::resolvesRequiredInKernels; + using Context::rootDeviceIndices; using Context::setupContextType; using Context::sharingFunctions; using Context::svmAllocsManager; + MockContext(ClDevice *pDevice, bool noSpecialQueue = false); MockContext(const ClDeviceVector &clDeviceVector); MockContext(