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_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);

View File

@@ -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<uint32_t const>());
@@ -438,13 +447,8 @@ AsyncEventsHandler &Context::getAsyncEventsHandler() const {
return *static_cast<ClExecutionEnvironment *>(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() {

View File

@@ -17,6 +17,7 @@
#include "opencl/source/helpers/destructor_callback.h"
#include <list>
#include <map>
#include <set>
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<uint32_t> rootDeviceIndices = {};
std::map<uint32_t, DeviceBitfield> deviceBitfields;
std::vector<std::unique_ptr<SharingFunctions>> sharingFunctions;
ClDeviceVector devices;
std::list<ContextDestructorCallback *> destructorCallbacks;

View File

@@ -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);
}

View File

@@ -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())) {

View File

@@ -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);

View File

@@ -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;

View File

@@ -44,7 +44,7 @@ class D3DBuffer : public D3DSharing<D3D> {
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<D3D>(context, d3dBuffer, bufferStaging, sharedResource);

View File

@@ -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);

View File

@@ -82,7 +82,7 @@ Image *D3DTexture<D3D>::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<D3D>::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 {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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:

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<Context>(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<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();
}

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, {}, context->getDeviceBitfieldForAllocation());
void *svmPtr = context->getSVMAllocsManager()->createSVMAlloc(0, 256, {}, context->getDeviceBitfieldForAllocation(0));
pCmdQ->enqueueSVMMap(CL_FALSE, 0, svmPtr, 256, 0, nullptr, nullptr, false);

View File

@@ -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<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());
}
const uint32_t expectedRootDeviceIndex = 1;
DebugManagerStateRestore restorer;
std::unique_ptr<MockClDevice> device;
std::unique_ptr<MockClDevice> device2;
std::unique_ptr<MockContext> context;
MockMemoryManager *mockMemoryManager;
};

View File

@@ -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);

View File

@@ -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);

View File

@@ -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> 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);

View File

@@ -43,6 +43,9 @@ MockContext::MockContext(
specialQueue = nullptr;
defaultDeviceQueue = nullptr;
driverDiagnostics = nullptr;
rootDeviceIndices = {};
maxRootDeviceIndex = std::numeric_limits<uint32_t>::max();
deviceBitfields = {};
}
MockContext::~MockContext() {
@@ -91,10 +94,24 @@ std::unique_ptr<AsyncEventsHandler> &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<uint32_t const>());
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);

View File

@@ -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(