Remove MemObj::rootDeviceEnvironment

Pass Device to Buffer::setArgStateful

Related-To: NEO-4672
Change-Id: I0b7ed3ee578139f250c8470532dc0ae2eb2991e1
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-06-30 17:42:12 +02:00
committed by sys_ocldev
parent 6ba5fe2e86
commit 5bc511b77d
13 changed files with 37 additions and 40 deletions

View File

@@ -139,7 +139,7 @@ void gtpinNotifyKernelSubmit(cl_kernel kernel, void *pCmdQueue) {
void *pSurfaceState = gtpinHelper.getSurfaceState(pKernel, gtpinBTI);
cl_mem buffer = (cl_mem)resource;
auto pBuffer = castToObjectOrAbort<Buffer>(buffer);
pBuffer->setArgStateful(pSurfaceState, false, false, false, false, device.getRootDeviceIndex());
pBuffer->setArgStateful(pSurfaceState, false, false, false, false, device.getDevice());
}
}

View File

@@ -1316,7 +1316,7 @@ cl_int Kernel::setArgBuffer(uint32_t argIndex,
if (requiresSshForBuffers()) {
auto surfaceState = ptrOffset(getSurfaceStateHeap(), kernelArgInfo.offsetHeap);
buffer->setArgStateful(surfaceState, forceNonAuxMode, disableL3, isAuxTranslationKernel, kernelArgInfo.isReadOnly, getDevice().getRootDeviceIndex());
buffer->setArgStateful(surfaceState, forceNonAuxMode, disableL3, isAuxTranslationKernel, kernelArgInfo.isReadOnly, getDevice().getDevice());
}
kernelArguments[argIndex].isStatelessUncacheable = kernelArgInfo.pureStatefulBufferAccess ? false : buffer->isMemObjUncacheable();

View File

@@ -633,7 +633,6 @@ Buffer *Buffer::createBufferHwFromDevice(const Device *device,
}
pBuffer->offset = offset;
pBuffer->executionEnvironment = device->getExecutionEnvironment();
pBuffer->rootDeviceEnvironment = pBuffer->executionEnvironment->rootDeviceEnvironments[device->getRootDeviceIndex()].get();
return pBuffer;
}
@@ -654,7 +653,7 @@ uint32_t Buffer::getMocsValue(bool disableL3Cache, bool isReadOnlyArgument, uint
bool alignedMemObj = isAligned<MemoryConstants::cacheLineSize>(bufferAddress) &&
isAligned<MemoryConstants::cacheLineSize>(bufferSize);
auto gmmHelper = rootDeviceEnvironment->getGmmHelper();
auto gmmHelper = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getGmmHelper();
if (!disableL3Cache && !isMemObjUncacheableForSurfaceState() && (alignedMemObj || readOnlyMemObj || !isMemObjZeroCopy())) {
return gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER);
} else {
@@ -700,7 +699,7 @@ void Buffer::setSurfaceState(const Device *device,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel) {
auto buffer = Buffer::createBufferHwFromDevice(device, flags, flagsIntel, svmSize, svmPtr, svmPtr, gfxAlloc, offset, true, false, false);
buffer->setArgStateful(surfaceState, false, false, false, false, device->getRootDeviceIndex());
buffer->setArgStateful(surfaceState, false, false, false, false, *device);
buffer->graphicsAllocation = nullptr;
delete buffer;
}

View File

@@ -135,7 +135,7 @@ class Buffer : public MemObj {
bool isSubBuffer();
bool isValidSubBufferOffset(size_t offset);
uint64_t setArgStateless(void *memory, uint32_t patchSize, uint32_t rootDeviceIndex, bool set32BitAddressing);
virtual void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) = 0;
virtual void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) = 0;
bool bufferRectPitchSet(const size_t *bufferOrigin,
const size_t *region,
size_t &bufferRowPitch,
@@ -204,8 +204,8 @@ class BufferHw : public Buffer {
: Buffer(context, memoryProperties, flags, flagsIntel, size, memoryStorage, hostPtr, gfxAllocation,
zeroCopy, isHostPtrSVM, isObjectRedescribed) {}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnlyArgument, uint32_t rootDeviceIndex) override;
void appendBufferState(void *memory, Context *context, GraphicsAllocation *gfxAllocation, bool isReadOnlyArgument);
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnlyArgument, const Device &device) override;
void appendBufferState(void *memory, const Device &device, bool isReadOnlyArgument);
void appendSurfaceStateExt(void *memory);
static Buffer *create(Context *context,

View File

@@ -6,6 +6,7 @@
*/
#include "shared/source/command_container/command_encoder.h"
#include "shared/source/device/device.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/gmm.h"
@@ -32,13 +33,16 @@ union SURFACE_STATE_BUFFER_LENGTH {
};
template <typename GfxFamily>
void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnlyArgument, uint32_t rootDeviceIndex) {
void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnlyArgument, const Device &device) {
auto rootDeviceIndex = device.getRootDeviceIndex();
auto graphicsAllocation = multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex);
EncodeSurfaceState<GfxFamily>::encodeBuffer(memory, getBufferAddress(rootDeviceIndex), getSurfaceSize(alignSizeForAuxTranslation, rootDeviceIndex), getMocsValue(disableL3, isReadOnlyArgument, rootDeviceIndex), true);
EncodeSurfaceState<GfxFamily>::encodeExtraBufferParams(multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex),
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getGmmHelper(), memory, forceNonAuxMode, isReadOnlyArgument);
EncodeSurfaceState<GfxFamily>::encodeBuffer(memory, getBufferAddress(rootDeviceIndex),
getSurfaceSize(alignSizeForAuxTranslation, rootDeviceIndex),
getMocsValue(disableL3, isReadOnlyArgument, rootDeviceIndex), true);
EncodeSurfaceState<GfxFamily>::encodeExtraBufferParams(graphicsAllocation,
device.getGmmHelper(), memory, forceNonAuxMode, isReadOnlyArgument);
appendBufferState(memory, context, graphicsAllocation, isReadOnlyArgument);
appendBufferState(memory, device, isReadOnlyArgument);
appendSurfaceStateExt(memory);
}
} // namespace NEO

View File

@@ -10,7 +10,7 @@
namespace NEO {
template <typename GfxFamily>
void BufferHw<GfxFamily>::appendBufferState(void *memory, Context *context, GraphicsAllocation *gfxAllocation, bool isReadOnly) {
void BufferHw<GfxFamily>::appendBufferState(void *memory, const Device &device, bool isReadOnly) {
}
} // namespace NEO

View File

@@ -35,7 +35,7 @@ void ImageHw<GfxFamily>::setImageArg(void *memory, bool setAsMediaBlockImage, ui
auto graphicsAllocation = multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex);
auto gmm = graphicsAllocation->getDefaultGmm();
auto gmmHelper = rootDeviceEnvironment->getGmmHelper();
auto gmmHelper = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getGmmHelper();
auto imageDescriptor = Image::convertDescriptor(getImageDesc());
ImageInfo imgInfo;
@@ -135,7 +135,7 @@ void ImageHw<GfxFamily>::setMediaImageArg(void *memory, uint32_t rootDeviceIndex
SURFACE_FORMAT surfaceFormat = MEDIA_SURFACE_STATE::SURFACE_FORMAT_Y8_UNORM_VA;
auto graphicsAllocation = multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex);
auto gmmHelper = rootDeviceEnvironment->getGmmHelper();
auto gmmHelper = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getGmmHelper();
auto surfaceState = reinterpret_cast<MEDIA_SURFACE_STATE *>(memory);
MEDIA_SURFACE_STATE state = GfxFamily::cmdInitMediaSurfaceState;

View File

@@ -49,7 +49,6 @@ MemObj::MemObj(Context *context,
memoryManager = context->getMemoryManager();
auto device = context->getDevice(0);
executionEnvironment = device->getExecutionEnvironment();
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[device->getRootDeviceIndex()].get();
}
if (graphicsAllocation) {
multiGraphicsAllocation.addAllocation(graphicsAllocation);

View File

@@ -24,7 +24,6 @@
namespace NEO {
class ExecutionEnvironment;
struct RootDeviceEnvironment;
class GraphicsAllocation;
struct KernelInfo;
class MemoryManager;
@@ -151,7 +150,6 @@ class MemObj : public BaseObject<_cl_mem> {
MemObj *associatedMemObject = nullptr;
cl_uint refCount = 0;
ExecutionEnvironment *executionEnvironment = nullptr;
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
bool isZeroCopy;
bool isHostPtrSVM;
bool isObjectRedescribed;

View File

@@ -79,7 +79,7 @@ class MockObject : public MockObjectBase<BaseType> {};
template <>
class MockObject<Buffer> : public MockObjectBase<Buffer> {
public:
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) override {}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override {}
};
template <>
@@ -293,7 +293,7 @@ class MockBuffer : public MockBufferStorage, public Buffer {
CL_MEM_USE_HOST_PTR, 0, sizeof(data), &data, &data, &mockGfxAllocation, true, false, false) {
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) override {
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override {
}
};

View File

@@ -2674,7 +2674,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferSetSurfaceThatAddressIsForcedTo32bitW
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE surfaceState = {};
buffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
auto surfBaseAddress = surfaceState.getSurfaceBaseAddress();
auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress();
@@ -2710,7 +2710,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferWithOffsetWhenSetArgStatefulIsCalledT
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE surfaceState = {};
subBuffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
subBuffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
auto surfBaseAddress = surfaceState.getSurfaceBaseAddress();
auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress();
@@ -2725,7 +2725,6 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferWithOffsetWhenSetArgStatefulIsCalledT
HWTEST_F(BufferSetSurfaceTests, givenBufferWhenSetArgStatefulWithL3ChacheDisabledIsCalledThenL3CacheShouldBeOffAndSizeIsAlignedTo512) {
MockContext context;
auto rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex();
auto size = 128;
auto retVal = CL_SUCCESS;
@@ -2740,7 +2739,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferWhenSetArgStatefulWithL3ChacheDisable
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
RENDER_SURFACE_STATE surfaceState = {};
buffer->setArgStateful(&surfaceState, false, true, true, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, true, true, false, context.getDevice(0)->getDevice());
auto mocs = surfaceState.getMemoryObjectControlState();
auto gmmHelper = device->getGmmHelper();
@@ -2768,7 +2767,7 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferThatIsMisalignedButIsAReadOnlyArgumen
buffer->getGraphicsAllocation(rootDeviceIndex)->setSize(127);
buffer->setArgStateful(&surfaceState, false, false, false, true, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, true, context.getDevice(0)->getDevice());
auto mocs = surfaceState.getMemoryObjectControlState();
auto gmmHelper = device->getGmmHelper();
@@ -2779,7 +2778,6 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferThatIsMisalignedButIsAReadOnlyArgumen
HWTEST_F(BufferSetSurfaceTests, givenAlignedCacheableReadOnlyBufferThenChoseOclBufferPolicy) {
MockContext context;
auto rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex();
const auto size = MemoryConstants::pageSize;
const auto ptr = (void *)alignedMalloc(size * 2, MemoryConstants::pageSize);
const auto flags = CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY;
@@ -2794,7 +2792,7 @@ HWTEST_F(BufferSetSurfaceTests, givenAlignedCacheableReadOnlyBufferThenChoseOclB
EXPECT_EQ(CL_SUCCESS, retVal);
typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
buffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER);
const auto actualMocs = surfaceState.getMemoryObjectControlState();
@@ -2805,7 +2803,6 @@ HWTEST_F(BufferSetSurfaceTests, givenAlignedCacheableReadOnlyBufferThenChoseOclB
HWTEST_F(BufferSetSurfaceTests, givenAlignedCacheableNonReadOnlyBufferThenChooseOclBufferPolicy) {
MockContext context;
auto rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex();
const auto size = MemoryConstants::pageSize;
const auto ptr = (void *)alignedMalloc(size * 2, MemoryConstants::pageSize);
const auto flags = CL_MEM_USE_HOST_PTR;
@@ -2820,7 +2817,7 @@ HWTEST_F(BufferSetSurfaceTests, givenAlignedCacheableNonReadOnlyBufferThenChoose
EXPECT_EQ(CL_SUCCESS, retVal);
typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
buffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
const auto expectedMocs = device->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER);
const auto actualMocs = surfaceState.getMemoryObjectControlState();
@@ -2845,14 +2842,14 @@ HWTEST_F(BufferSetSurfaceTests, givenRenderCompressedGmmResourceWhenSurfaceState
graphicsAllocation->setDefaultGmm(gmm);
gmm->isRenderCompressed = true;
buffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
EXPECT_EQ(0u, surfaceState.getAuxiliarySurfaceBaseAddress());
EXPECT_TRUE(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E == surfaceState.getAuxiliarySurfaceMode());
EXPECT_TRUE(RENDER_SURFACE_STATE::COHERENCY_TYPE_GPU_COHERENT == surfaceState.getCoherencyType());
graphicsAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
buffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
EXPECT_TRUE(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE == surfaceState.getAuxiliarySurfaceMode());
}
@@ -2870,7 +2867,7 @@ HWTEST_F(BufferSetSurfaceTests, givenNonRenderCompressedGmmResourceWhenSurfaceSt
buffer->getGraphicsAllocation(rootDeviceIndex)->setDefaultGmm(gmm);
gmm->isRenderCompressed = false;
buffer->setArgStateful(&surfaceState, false, false, false, false, rootDeviceIndex);
buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice());
EXPECT_EQ(0u, surfaceState.getAuxiliarySurfaceBaseAddress());
EXPECT_TRUE(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE == surfaceState.getAuxiliarySurfaceMode());

View File

@@ -48,8 +48,8 @@ class MockBuffer : public MockBufferStorage, public Buffer {
this->graphicsAllocation = &this->mockGfxAllocation;
}
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) override {
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), 0, (externalAlloc != nullptr) ? externalAlloc : &mockGfxAllocation, 0, 0);
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override {
Buffer::setSurfaceState(this->device.get(), memory, getSize(), getCpuAddress(), 0, (externalAlloc != nullptr) ? externalAlloc : &mockGfxAllocation, 0, 0);
}
GraphicsAllocation *externalAlloc = nullptr;
};
@@ -61,8 +61,8 @@ class AlignedBuffer : public MockBufferStorage, public Buffer {
}
AlignedBuffer(GraphicsAllocation *gfxAllocation) : MockBufferStorage(), Buffer(nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), gfxAllocation, true, false, false) {
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) override {
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0);
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override {
Buffer::setSurfaceState(this->device.get(), memory, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0);
}
};
@@ -73,8 +73,8 @@ class UnalignedBuffer : public MockBufferStorage, public Buffer {
}
UnalignedBuffer(GraphicsAllocation *gfxAllocation) : MockBufferStorage(true), Buffer(nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), gfxAllocation, false, false, false) {
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) override {
Buffer::setSurfaceState(device.get(), memory, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0);
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override {
Buffer::setSurfaceState(this->device.get(), memory, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0);
}
};

View File

@@ -1447,7 +1447,7 @@ class DrmMockBuffer : public Buffer {
gfxAllocation(alloc) {
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, uint32_t rootDeviceIndex) override {
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override {
}
protected: