Add method to get device bitfield from context

Related-To: NEO-4484
Change-Id: I5079c5bff48b552ed5326b2252bcd9401ea66c7d
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-04-28 11:33:39 +02:00
parent 08af6cad48
commit 159c804312
15 changed files with 52 additions and 23 deletions

View File

@ -415,7 +415,16 @@ ClDevice *Context::getSubDeviceByIndex(uint32_t subDeviceIndex) const {
return (foundDeviceIterator != devices.end() ? *foundDeviceIterator : nullptr);
}
AsyncEventsHandler &Context::getAsyncEventsHandler() {
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;
}
} // namespace NEO

View File

@ -7,6 +7,7 @@
#pragma once
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/common_types.h"
#include "shared/source/helpers/vec.h"
#include "opencl/source/cl_device/cl_device_vector.h"
@ -14,8 +15,6 @@
#include "opencl/source/context/driver_diagnostics.h"
#include "opencl/source/helpers/base_object.h"
#include <vector>
namespace NEO {
class AsyncEventsHandler;
@ -144,7 +143,9 @@ class Context : public BaseObject<_cl_context> {
bool isDeviceAssociated(const ClDevice &clDevice) const;
ClDevice *getSubDeviceByIndex(uint32_t subDeviceIndex) const;
AsyncEventsHandler &getAsyncEventsHandler();
AsyncEventsHandler &getAsyncEventsHandler() const;
DeviceBitfield getDeviceBitfieldForAllocation() const;
protected:
Context(void(CL_CALLBACK *pfnNotify)(const char *, const void *, size_t, void *) = nullptr,

View File

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

View File

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

View File

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

View File

@ -63,7 +63,7 @@ Pipe *Pipe::create(Context *context,
true, // allocateMemory
size, GraphicsAllocation::AllocationType::PIPE,
false, // isMultiStorageAllocation
context->getDevice(0)->getHardwareInfo(), context->getDevice(0)->getDeviceBitfield());
context->getDevice(0)->getHardwareInfo(), context->getDeviceBitfieldForAllocation());
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->getDevice(0)->getDeviceBitfield()};
context->getDeviceBitfieldForAllocation()};
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->getDevice(0)->getDeviceBitfield());
context->getDeviceBitfieldForAllocation());
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties,
false);
updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u);
@ -103,7 +103,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->getDevice(0)->getDeviceBitfield());
context->getDeviceBitfieldForAllocation());
allocProperties.allocationType = GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY;
alloc = context->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);

View File

@ -77,7 +77,7 @@ Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_
0u, // size
GraphicsAllocation::AllocationType::SHARED_IMAGE,
false, // isMultiStorageAllocation
context->getDevice(0)->getDeviceBitfield());
context->getDeviceBitfieldForAllocation());
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false);
}
DEBUG_BREAK_IF(!alloc);
@ -147,7 +147,7 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
0u, // size
GraphicsAllocation::AllocationType::SHARED_IMAGE,
false, // isMultiStorageAllocation
context->getDevice(0)->getDeviceBitfield());
context->getDeviceBitfieldForAllocation());
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false);
}
DEBUG_BREAK_IF(!alloc);

View File

@ -141,7 +141,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne
0u, // size
GraphicsAllocation::AllocationType::SHARED_BUFFER,
false, // isMultiStorageAllocation
context->getDevice(0)->getDeviceBitfield()};
context->getDeviceBitfieldForAllocation()};
// 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->getDevice(0)->getDeviceBitfield());
context->getDeviceBitfieldForAllocation());
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false);
if (alloc == nullptr) {

View File

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

View File

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

View File

@ -218,7 +218,6 @@ TEST(clSvmAllocTest, givenSubDeviceWhenCreatingSvmAllocThenProperDeviceBitfieldI
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);
@ -227,6 +226,7 @@ TEST(clSvmAllocTest, givenSubDeviceWhenCreatingSvmAllocThenProperDeviceBitfieldI
std::swap(memoryManagerBackup, executionEnvironment->memoryManager);
MockContext context(device);
auto expectedDeviceBitfield = context.getDeviceBitfieldForAllocation();
EXPECT_NE(expectedDeviceBitfield, memoryManager->recentlyPassedDeviceBitfield);
auto svmPtr = clSVMAlloc(&context, CL_MEM_READ_WRITE, MemoryConstants::pageSize, MemoryConstants::cacheLineSize);
EXPECT_NE(nullptr, svmPtr);

View File

@ -420,3 +420,22 @@ TEST(Context, givenContextWhenIsDeviceAssociatedIsCalledWithNotAssociatedDeviceT
EXPECT_FALSE(context0.isDeviceAssociated(*context1.getDevice(0)));
EXPECT_FALSE(context1.isDeviceAssociated(*context0.getDevice(0)));
}
TEST(Context, givenContextWithSingleDevicesWhenGettingDeviceBitfieldForAllocationThenDeviceBitfieldForDeviceIsReturned) {
UltClDeviceFactory deviceFactory{1, 3};
auto device = deviceFactory.subDevices[1];
auto expectedDeviceBitfield = device->getDeviceBitfield();
MockContext context(device);
EXPECT_EQ(expectedDeviceBitfield.to_ulong(), context.getDeviceBitfieldForAllocation().to_ulong());
}
TEST(Context, givenContextWithMultipleSubDevicesWhenGettingDeviceBitfieldForAllocationThenMergedDeviceBitfieldIsReturned) {
UltClDeviceFactory deviceFactory{1, 3};
cl_int retVal;
cl_device_id devices[]{deviceFactory.subDevices[0], deviceFactory.subDevices[2]};
ClDeviceVector deviceVector(devices, 2);
auto expectedDeviceBitfield = deviceFactory.subDevices[0]->getDeviceBitfield() | 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(expectedDeviceBitfield.to_ulong(), context->getDeviceBitfieldForAllocation().to_ulong());
context->release();
}