Create map for deviceBitfields per rootDeviceIndex

Pass rootDeviceIndex to getDeviceBitfieldForAllocation

Related-To: NEO-4589
Change-Id: Ib325a8bf822351ba36b225d94d4173fd725e8766
Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala
2020-09-28 13:11:58 +02:00
committed by sys_ocldev
parent e28f937683
commit 214342f405
24 changed files with 104 additions and 48 deletions

View File

@@ -3524,7 +3524,7 @@ void *clHostMemAllocINTEL(
cl_mem_flags flags = 0; cl_mem_flags flags = 0;
cl_mem_flags_intel flagsIntel = 0; cl_mem_flags_intel flagsIntel = 0;
cl_mem_alloc_flags_intel allocflags = 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, if (!MemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN, allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
*neoContext)) { *neoContext)) {
@@ -3620,7 +3620,7 @@ void *clSharedMemAllocINTEL(
unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDeviceBitfield(); unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDeviceBitfield();
} else { } else {
neoDevice = neoContext->getDevice(0); 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) { if (size > neoDevice->getSharedDeviceInfo().maxMemAllocSize && !unifiedMemoryProperties.allocationFlags.flags.allowUnrestrictedSize) {
err.set(CL_INVALID_BUFFER_SIZE); err.set(CL_INVALID_BUFFER_SIZE);

View File

@@ -198,6 +198,15 @@ bool Context::createImpl(const cl_context_properties *properties,
} }
this->devices = inputDevices; 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) { if (devices.size() > 0) {
maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>()); maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
@@ -438,13 +447,8 @@ AsyncEventsHandler &Context::getAsyncEventsHandler() const {
return *static_cast<ClExecutionEnvironment *>(devices[0]->getExecutionEnvironment())->getAsyncEventsHandler(); return *static_cast<ClExecutionEnvironment *>(devices[0]->getExecutionEnvironment())->getAsyncEventsHandler();
} }
DeviceBitfield Context::getDeviceBitfieldForAllocation() const { DeviceBitfield Context::getDeviceBitfieldForAllocation(uint32_t rootDeviceIndex) const {
DeviceBitfield deviceBitfield{}; return deviceBitfields.at(rootDeviceIndex);
for (const auto &pDevice : devices) {
deviceBitfield |= pDevice->getDeviceBitfield();
}
return deviceBitfield;
} }
void Context::setupContextType() { void Context::setupContextType() {

View File

@@ -17,6 +17,7 @@
#include "opencl/source/helpers/destructor_callback.h" #include "opencl/source/helpers/destructor_callback.h"
#include <list> #include <list>
#include <map>
#include <set> #include <set>
namespace NEO { namespace NEO {
@@ -148,7 +149,7 @@ class Context : public BaseObject<_cl_context> {
AsyncEventsHandler &getAsyncEventsHandler() const; AsyncEventsHandler &getAsyncEventsHandler() const;
DeviceBitfield getDeviceBitfieldForAllocation() const; DeviceBitfield getDeviceBitfieldForAllocation(uint32_t rootDeviceIndex) const;
bool getResolvesRequiredInKernels() const { bool getResolvesRequiredInKernels() const {
return resolvesRequiredInKernels; return resolvesRequiredInKernels;
} }
@@ -167,6 +168,7 @@ class Context : public BaseObject<_cl_context> {
void setupContextType(); void setupContextType();
std::set<uint32_t> rootDeviceIndices = {}; std::set<uint32_t> rootDeviceIndices = {};
std::map<uint32_t, DeviceBitfield> deviceBitfields;
std::vector<std::unique_ptr<SharingFunctions>> sharingFunctions; std::vector<std::unique_ptr<SharingFunctions>> sharingFunctions;
ClDeviceVector devices; ClDeviceVector devices;
std::list<ContextDestructorCallback *> destructorCallbacks; std::list<ContextDestructorCallback *> destructorCallbacks;

View File

@@ -255,7 +255,7 @@ Buffer *Buffer::create(Context *context,
if (!memory) { if (!memory) {
AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties,
allocateMemory, size, allocationType, context->areMultiStorageAllocationsPreferred(), allocateMemory, size, allocationType, context->areMultiStorageAllocationsPreferred(),
context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation()); context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex));
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr);
} }
@@ -271,7 +271,7 @@ Buffer *Buffer::create(Context *context,
AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties,
true, // allocateMemory true, // allocateMemory
size, allocationType, context->areMultiStorageAllocationsPreferred(), size, allocationType, context->areMultiStorageAllocationsPreferred(),
context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation()); context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex));
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
} }
@@ -326,7 +326,7 @@ Buffer *Buffer::create(Context *context,
false, // allocateMemory false, // allocateMemory
size, GraphicsAllocation::AllocationType::MAP_ALLOCATION, size, GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(rootDeviceIndex)};
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true; properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr);
} }

View File

@@ -275,7 +275,7 @@ Image *Image::create(Context *context,
AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
false, // allocateMemory false, // allocateMemory
memoryProperties, context->getDevice(0)->getHardwareInfo(), memoryProperties, context->getDevice(0)->getHardwareInfo(),
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(rootDeviceIndex));
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr);
@@ -293,7 +293,7 @@ Image *Image::create(Context *context,
false, // allocateMemory false, // allocateMemory
imgInfo.size, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE, imgInfo.size, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}, context->getDeviceBitfieldForAllocation(rootDeviceIndex)},
hostPtr); hostPtr);
memory->setDefaultGmm(gmm); memory->setDefaultGmm(gmm);
zeroCopy = true; zeroCopy = true;
@@ -303,7 +303,7 @@ Image *Image::create(Context *context,
false, // allocateMemory false, // allocateMemory
hostPtrMinSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION, hostPtrMinSize, GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(rootDeviceIndex)};
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true; properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr);
} }
@@ -311,7 +311,7 @@ Image *Image::create(Context *context,
AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
true, // allocateMemory true, // allocateMemory
memoryProperties, context->getDevice(0)->getHardwareInfo(), memoryProperties, context->getDevice(0)->getHardwareInfo(),
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(rootDeviceIndex));
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) { if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {

View File

@@ -371,7 +371,7 @@ void *MemObj::getBasePtrForMap(uint32_t rootDeviceIndex) {
false, // allocateMemory false, // allocateMemory
getSize(), GraphicsAllocation::AllocationType::MAP_ALLOCATION, getSize(), GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, //isMultiStorageAllocation false, //isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(rootDeviceIndex)};
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, memory); auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, memory);
setMapAllocation(allocation); setMapAllocation(allocation);

View File

@@ -64,7 +64,7 @@ Pipe *Pipe::create(Context *context,
true, // allocateMemory true, // allocateMemory
size, GraphicsAllocation::AllocationType::PIPE, size, GraphicsAllocation::AllocationType::PIPE,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation()); context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation(rootDeviceIndex));
GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
if (!memory) { if (!memory) {
errcodeRet = CL_OUT_OF_HOST_MEMORY; errcodeRet = CL_OUT_OF_HOST_MEMORY;

View File

@@ -44,7 +44,7 @@ class D3DBuffer : public D3DSharing<D3D> {
0, // size 0, // size
GraphicsAllocation::AllocationType::SHARED_BUFFER, GraphicsAllocation::AllocationType::SHARED_BUFFER,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())};
auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true); auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true);
auto d3dBufferObj = new D3DBuffer<D3D>(context, d3dBuffer, bufferStaging, sharedResource); auto d3dBufferObj = new D3DBuffer<D3D>(context, d3dBuffer, bufferStaging, sharedResource);

View File

@@ -86,7 +86,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo
0u, // size 0u, // size
GraphicsAllocation::AllocationType::SHARED_IMAGE, GraphicsAllocation::AllocationType::SHARED_IMAGE,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(rootDeviceIndex));
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties, alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties,
false); false);
updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u); 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, AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
true, // allocateMemory true, // allocateMemory
memoryProperties, context->getDevice(0)->getHardwareInfo(), memoryProperties, context->getDevice(0)->getHardwareInfo(),
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(rootDeviceIndex));
allocProperties.allocationType = GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY; allocProperties.allocationType = GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY;
alloc = context->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); alloc = context->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);

View File

@@ -82,7 +82,7 @@ Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_
0u, // size 0u, // size
GraphicsAllocation::AllocationType::SHARED_IMAGE, GraphicsAllocation::AllocationType::SHARED_IMAGE,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(rootDeviceIndex));
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) {
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false); alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false);
} else { } else {
@@ -167,7 +167,7 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
0u, // size 0u, // size
GraphicsAllocation::AllocationType::SHARED_IMAGE, GraphicsAllocation::AllocationType::SHARED_IMAGE,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(rootDeviceIndex));
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) {
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false); alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false);
} else { } else {

View File

@@ -148,7 +148,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne
0u, // size 0u, // size
GraphicsAllocation::AllocationType::SHARED_BUFFER, GraphicsAllocation::AllocationType::SHARED_BUFFER,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())};
// couldn't find allocation for reuse - create new // couldn't find allocation for reuse - create new
graphicsAllocation = graphicsAllocation =
context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true); context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true);

View File

@@ -55,7 +55,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl
0u, // size 0u, // size
GraphicsAllocation::AllocationType::SHARED_IMAGE, GraphicsAllocation::AllocationType::SHARED_IMAGE,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex()));
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false);
if (alloc == nullptr) { if (alloc == nullptr) {
@@ -124,7 +124,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl
GraphicsAllocation *mcsAlloc = nullptr; GraphicsAllocation *mcsAlloc = nullptr;
if (texInfo.globalShareHandleMCS) { 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); mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false);
if (texInfo.pGmmResInfoMCS) { if (texInfo.pGmmResInfoMCS) {
DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr); DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr);

View File

@@ -45,7 +45,7 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U
0u, // size 0u, // size
allocationType, allocationType,
false, // isMultiStorageAllocation false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())};
return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false); return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false);
} }
default: default:

View File

@@ -109,7 +109,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
AllocationProperties properties(context->getDevice(0)->getRootDeviceIndex(), AllocationProperties properties(context->getDevice(0)->getRootDeviceIndex(),
false, // allocateMemory false, // allocateMemory
imgInfo, GraphicsAllocation::AllocationType::SHARED_IMAGE, imgInfo, GraphicsAllocation::AllocationType::SHARED_IMAGE,
context->getDeviceBitfieldForAllocation()); context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex()));
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false);

View File

@@ -244,7 +244,7 @@ TEST(clSvmAllocTest, givenSubDeviceWhenCreatingSvmAllocThenProperDeviceBitfieldI
std::swap(memoryManagerBackup, executionEnvironment->memoryManager); std::swap(memoryManagerBackup, executionEnvironment->memoryManager);
MockContext context(device); MockContext context(device);
auto expectedDeviceBitfield = context.getDeviceBitfieldForAllocation(); auto expectedDeviceBitfield = context.getDeviceBitfieldForAllocation(device->getRootDeviceIndex());
EXPECT_NE(expectedDeviceBitfield, memoryManager->recentlyPassedDeviceBitfield); EXPECT_NE(expectedDeviceBitfield, memoryManager->recentlyPassedDeviceBitfield);
auto svmPtr = clSVMAlloc(&context, CL_MEM_READ_WRITE, MemoryConstants::pageSize, MemoryConstants::cacheLineSize); auto svmPtr = clSVMAlloc(&context, CL_MEM_READ_WRITE, MemoryConstants::pageSize, MemoryConstants::cacheLineSize);
EXPECT_NE(nullptr, svmPtr); EXPECT_NE(nullptr, svmPtr);

View File

@@ -221,4 +221,4 @@ TEST(ContextMultiDevice, givenRootDeviceAndSubsetOfSubdevicesWhenCreatingContext
EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context2.get()); EXPECT_NE(nullptr, context2.get());
EXPECT_EQ(ContextType::CONTEXT_TYPE_UNRESTRICTIVE, context2->peekContextType()); EXPECT_EQ(ContextType::CONTEXT_TYPE_UNRESTRICTIVE, context2->peekContextType());
} }

View File

@@ -433,7 +433,7 @@ TEST(Context, givenContextWithSingleDevicesWhenGettingDeviceBitfieldForAllocatio
auto device = deviceFactory.subDevices[1]; auto device = deviceFactory.subDevices[1];
auto expectedDeviceBitfield = device->getDeviceBitfield(); auto expectedDeviceBitfield = device->getDeviceBitfield();
MockContext context(device); 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) { TEST(Context, givenContextWithMultipleSubDevicesWhenGettingDeviceBitfieldForAllocationThenMergedDeviceBitfieldIsReturned) {
UltClDeviceFactory deviceFactory{1, 3}; UltClDeviceFactory deviceFactory{1, 3};
@@ -444,7 +444,29 @@ TEST(Context, givenContextWithMultipleSubDevicesWhenGettingDeviceBitfieldForAllo
auto context = Context::create<Context>(0, deviceVector, nullptr, nullptr, retVal); auto context = Context::create<Context>(0, deviceVector, nullptr, nullptr, retVal);
EXPECT_NE(nullptr, context); EXPECT_NE(nullptr, context);
EXPECT_EQ(CL_SUCCESS, retVal); 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<Context>(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(); context->release();
} }

View File

@@ -664,7 +664,7 @@ TEST_P(PerformanceHintEnqueueMapTest, GivenZeroCopyFlagWhenEnqueueUnmapIsCalling
TEST_F(PerformanceHintEnqueueTest, GivenSVMPointerWhenEnqueueSVMMapIsCallingThenContextProvidesProperHint) { TEST_F(PerformanceHintEnqueueTest, GivenSVMPointerWhenEnqueueSVMMapIsCallingThenContextProvidesProperHint) {
REQUIRE_SVM_OR_SKIP(pPlatform->getClDevice(0)); 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); pCmdQ->enqueueSVMMap(CL_FALSE, 0, svmPtr, 256, 0, nullptr, nullptr, false);

View File

@@ -17,15 +17,22 @@ namespace NEO {
class MultiRootDeviceFixture : public ::testing::Test { class MultiRootDeviceFixture : public ::testing::Test {
public: public:
void SetUp() override { void SetUp() override {
DebugManager.flags.CreateMultipleRootDevices.set(2 * expectedRootDeviceIndex); DebugManager.flags.CreateMultipleRootDevices.set(3 * expectedRootDeviceIndex);
device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr, expectedRootDeviceIndex)); device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr, expectedRootDeviceIndex));
context.reset(new MockContext(device.get())); device2 = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr, 2u));
cl_device_id devices[] = {
device.get(), device2.get()};
context.reset(new MockContext(ClDeviceVector(devices, 2)));
mockMemoryManager = reinterpret_cast<MockMemoryManager *>(device->getMemoryManager()); mockMemoryManager = reinterpret_cast<MockMemoryManager *>(device->getMemoryManager());
} }
const uint32_t expectedRootDeviceIndex = 1; const uint32_t expectedRootDeviceIndex = 1;
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
std::unique_ptr<MockClDevice> device; std::unique_ptr<MockClDevice> device;
std::unique_ptr<MockClDevice> device2;
std::unique_ptr<MockContext> context; std::unique_ptr<MockContext> context;
MockMemoryManager *mockMemoryManager; MockMemoryManager *mockMemoryManager;
}; };

View File

@@ -1623,7 +1623,7 @@ HWTEST_F(HwImageTest, givenImageHwWithUnifiedSurfaceAndMcsWhenSettingParamsForMu
cl_image_format format = {}; cl_image_format format = {};
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); 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); auto graphicsAllocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);

View File

@@ -326,7 +326,7 @@ HWTEST_P(MemObjSyncDestructionTest, givenMemObjWithMapAllocationWhenAsyncDestruc
MemoryConstants::pageSize, MemoryConstants::pageSize,
GraphicsAllocation::AllocationType::MAP_ALLOCATION, GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, false,
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())};
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr);
memObj->setMapAllocation(mapAllocation); memObj->setMapAllocation(mapAllocation);
@@ -365,7 +365,7 @@ HWTEST_P(MemObjSyncDestructionTest, givenMemObjWithMapAllocationWhenAsyncDestruc
MemoryConstants::pageSize, MemoryConstants::pageSize,
GraphicsAllocation::AllocationType::MAP_ALLOCATION, GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, false,
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())};
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr);
memObj->setMapAllocation(mapAllocation); memObj->setMapAllocation(mapAllocation);
@@ -396,7 +396,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenMemObjWithMapAllocationWithoutMemUseHo
MemoryConstants::pageSize, MemoryConstants::pageSize,
GraphicsAllocation::AllocationType::MAP_ALLOCATION, GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, false,
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())};
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr);
memObj->setMapAllocation(mapAllocation); memObj->setMapAllocation(mapAllocation);
@@ -436,7 +436,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenMemObjWithMapAllocationWithMemUseHostP
MemoryConstants::pageSize, MemoryConstants::pageSize,
GraphicsAllocation::AllocationType::MAP_ALLOCATION, GraphicsAllocation::AllocationType::MAP_ALLOCATION,
false, false,
context->getDeviceBitfieldForAllocation()}; context->getDeviceBitfieldForAllocation(device->getRootDeviceIndex())};
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr);
memObj->setMapAllocation(mapAllocation); memObj->setMapAllocation(mapAllocation);

View File

@@ -540,28 +540,28 @@ TEST_F(MemObjMultiRootDeviceTests, WhenMemObjIsCreatedWithMultiGraphicsAllocatio
} }
TEST_F(MemObjMultiRootDeviceTests, WhenMemObjMapAreCreatedThenAllAllocationAreDestroyedProperly) { 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 allocation1 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1, MemoryConstants::pageSize});
auto multiGraphicsAllocation = MultiGraphicsAllocation(1); auto multiGraphicsAllocation = MultiGraphicsAllocation(2);
multiGraphicsAllocation.addAllocation(allocation0); multiGraphicsAllocation.addAllocation(allocation0);
multiGraphicsAllocation.addAllocation(allocation1); 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> memObj( std::unique_ptr<MemObj> memObj(
new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0, new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
1, nullptr, nullptr, multiGraphicsAllocation, true, false, false)); 1, nullptr, nullptr, multiGraphicsAllocation, true, false, false));
auto mapAllocation0 = memObj->getMapAllocation(0); auto mapAllocation0 = memObj->getMapAllocation(2);
auto mapAllocation1 = memObj->getMapAllocation(1); auto mapAllocation1 = memObj->getMapAllocation(1);
EXPECT_EQ(nullptr, mapAllocation0); EXPECT_EQ(nullptr, mapAllocation0);
EXPECT_EQ(nullptr, mapAllocation1); EXPECT_EQ(nullptr, mapAllocation1);
EXPECT_NE(nullptr, memObj->getBasePtrForMap(0)); EXPECT_NE(nullptr, memObj->getBasePtrForMap(2));
EXPECT_EQ(memObj->getBasePtrForMap(0), memObj->getBasePtrForMap(1)); EXPECT_EQ(memObj->getBasePtrForMap(2), memObj->getBasePtrForMap(1));
mapAllocation0 = memObj->getMapAllocation(0); mapAllocation0 = memObj->getMapAllocation(2);
mapAllocation1 = memObj->getMapAllocation(1); mapAllocation1 = memObj->getMapAllocation(1);
ASSERT_NE(nullptr, mapAllocation0); ASSERT_NE(nullptr, mapAllocation0);

View File

@@ -43,6 +43,9 @@ MockContext::MockContext(
specialQueue = nullptr; specialQueue = nullptr;
defaultDeviceQueue = nullptr; defaultDeviceQueue = nullptr;
driverDiagnostics = nullptr; driverDiagnostics = nullptr;
rootDeviceIndices = {};
maxRootDeviceIndex = std::numeric_limits<uint32_t>::max();
deviceBitfields = {};
} }
MockContext::~MockContext() { MockContext::~MockContext() {
@@ -91,10 +94,24 @@ std::unique_ptr<AsyncEventsHandler> &MockContext::getAsyncEventsHandlerUniquePtr
void MockContext::initializeWithDevices(const ClDeviceVector &devices, bool noSpecialQueue) { void MockContext::initializeWithDevices(const ClDeviceVector &devices, bool noSpecialQueue) {
for (auto &pClDevice : devices) { for (auto &pClDevice : devices) {
pClDevice->incRefInternal(); pClDevice->incRefInternal();
rootDeviceIndices.insert(pClDevice->getRootDeviceIndex());
} }
maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
this->devices = devices; this->devices = devices;
memoryManager = devices[0]->getMemoryManager(); memoryManager = devices[0]->getMemoryManager();
svmAllocsManager = new SVMAllocsManager(memoryManager); 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; cl_int retVal;
if (!noSpecialQueue) { if (!noSpecialQueue) {
auto commandQueue = CommandQueue::create(this, devices[0], nullptr, false, retVal); auto commandQueue = CommandQueue::create(this, devices[0], nullptr, false, retVal);

View File

@@ -19,13 +19,17 @@ class AsyncEventsHandler;
class MockContext : public Context { class MockContext : public Context {
public: public:
using Context::contextType; using Context::contextType;
using Context::deviceBitfields;
using Context::driverDiagnostics; using Context::driverDiagnostics;
using Context::maxRootDeviceIndex;
using Context::memoryManager; using Context::memoryManager;
using Context::preferD3dSharedResources; using Context::preferD3dSharedResources;
using Context::resolvesRequiredInKernels; using Context::resolvesRequiredInKernels;
using Context::rootDeviceIndices;
using Context::setupContextType; using Context::setupContextType;
using Context::sharingFunctions; using Context::sharingFunctions;
using Context::svmAllocsManager; using Context::svmAllocsManager;
MockContext(ClDevice *pDevice, bool noSpecialQueue = false); MockContext(ClDevice *pDevice, bool noSpecialQueue = false);
MockContext(const ClDeviceVector &clDeviceVector); MockContext(const ClDeviceVector &clDeviceVector);
MockContext( MockContext(