refactor: bind drm context within IoctlHelper::createDrmContext method

Related-To: NEO-6999
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2022-06-28 17:10:24 +02:00 committed by Compute-Runtime-Automation
parent efa19a0b18
commit fffd56d7a6
11 changed files with 23 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -11,6 +11,7 @@
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/mocks/mock_os_context.h"
#include "shared/test/common/test_macros/test.h"
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
@ -43,7 +44,7 @@ struct AUBFixture : public AUBCommandStreamFixture,
template <typename FamilyType>
void testNoopIdXcs(aub_stream::EngineType engineType) {
pCommandStreamReceiver->getOsContext().getEngineType() = engineType;
static_cast<MockOsContext &>(pCommandStreamReceiver->getOsContext()).engineType = engineType;
typedef typename FamilyType::MI_NOOP MI_NOOP;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -22,7 +22,7 @@ struct EngineControl {
CommandStreamReceiver *commandStreamReceiver = nullptr;
OsContext *osContext = nullptr;
aub_stream::EngineType &getEngineType() const { return osContext->getEngineType(); }
const aub_stream::EngineType &getEngineType() const { return osContext->getEngineType(); }
EngineUsage getEngineUsage() const { return osContext->getEngineUsage(); }
};
} // namespace NEO

View File

@ -14,7 +14,7 @@
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/drm_wrappers.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "drm/i915_drm.h"
@ -82,7 +82,7 @@ void IoctlHelper::logExecBuffer(const ExecBuffer &execBuffer, std::stringstream
<< " }\n";
}
uint32_t IoctlHelper::createDrmContext(Drm &drm, const OsContext &osContext, uint32_t drmVmId) {
uint32_t IoctlHelper::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_t drmVmId, uint32_t deviceIndex) {
const auto numberOfCCS = drm.getRootDeviceEnvironment().getHardwareInfo()->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
const bool debuggableContext = drm.isContextDebugSupported() && drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled() && !osContext.isInternalEngine();
@ -103,6 +103,8 @@ uint32_t IoctlHelper::createDrmContext(Drm &drm, const OsContext &osContext, uin
if (drm.isPreemptionSupported() && osContext.isLowPriority()) {
drm.setLowPriorityContextParam(drmContextId);
}
auto engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, osContext.getEngineType(), osContext.isEngineInstanced());
osContext.setEngineFlag(engineFlag);
return drmContextId;
}

View File

@ -20,7 +20,7 @@
namespace NEO {
class Drm;
class OsContext;
class OsContextLinux;
class IoctlHelper;
enum class CacheRegion : uint16_t;
struct HardwareInfo;
@ -114,7 +114,7 @@ class IoctlHelper {
virtual std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo);
uint32_t createDrmContext(Drm &drm, const OsContext &osContext, uint32_t drmVmId);
uint32_t createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_t drmVmId, uint32_t deviceIndex);
std::vector<EngineCapabilities> translateToEngineCaps(const std::vector<uint8_t> &data);
void fillExecObject(ExecObject &execObject, uint32_t handle, uint64_t gpuAddress, uint32_t drmContextId, bool bindInfo, bool isMarkedForCapture);

View File

@ -48,9 +48,8 @@ void OsContextLinux::initializeContext() {
for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) {
if (deviceBitfield.test(deviceIndex)) {
auto drmVmId = drm.getVirtualMemoryAddressSpace(deviceIndex);
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId);
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId, deviceIndex);
this->engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, engineType, isEngineInstanced());
this->drmContextIds.push_back(drmContextId);
if (drm.isPerContextVMRequired()) {

View File

@ -21,6 +21,7 @@ class OsContextLinux : public OsContext {
OsContextLinux(Drm &drm, uint32_t contextId, const EngineDescriptor &engineDescriptor);
unsigned int getEngineFlag() const { return engineFlag; }
void setEngineFlag(unsigned int engineFlag) { this->engineFlag = engineFlag; }
const std::vector<uint32_t> &getDrmContextIds() const { return drmContextIds; }
const std::vector<uint32_t> &getDrmVmIds() const { return drmVmIds; }
void setNewResourceBound(bool value) { this->newResourceBound = value; };

View File

@ -35,7 +35,7 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
uint32_t getNumSupportedDevices() const { return numSupportedDevices; }
DeviceBitfield getDeviceBitfield() const { return deviceBitfield; }
PreemptionMode getPreemptionMode() const { return preemptionMode; }
aub_stream::EngineType &getEngineType() { return engineType; }
const aub_stream::EngineType &getEngineType() const { return engineType; }
EngineUsage getEngineUsage() { return engineUsage; }
bool isRegular() const { return engineUsage == EngineUsage::Regular; }
bool isLowPriority() const { return engineUsage == EngineUsage::LowPriority; }

View File

@ -19,4 +19,5 @@ class MockOsContext : public OsContext {
MockOsContext(uint32_t contextId, const EngineDescriptor &engineDescriptorHelper)
: OsContext(contextId, engineDescriptorHelper) {}
};
static_assert(sizeof(OsContext) == sizeof(MockOsContext));
} // namespace NEO

View File

@ -1120,7 +1120,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
HWTEST_F(AubCommandStreamReceiverTests, WhenBlitBufferIsCalledThenCounterIsCorrectlyIncremented) {
auto aubExecutionEnvironment = getEnvironment<UltAubCommandStreamReceiver<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<UltAubCommandStreamReceiver<FamilyType>>();
aubCsr->osContext->getEngineType() = aub_stream::ENGINE_BCS;
auto osContext = static_cast<MockOsContext *>(aubCsr->osContext);
osContext->engineType = aub_stream::ENGINE_BCS;
EXPECT_EQ(0u, aubCsr->blitBufferCalled);
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0);

View File

@ -431,7 +431,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
gfxAllocation->setDefaultGmm(new Gmm(pDevice->executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true));
auto &csrOsContext = aubCsr.getOsContext();
auto &csrOsContext = static_cast<MockOsContext &>(aubCsr.getOsContext());
{
// Non-BCS engine, BCS dump
@ -458,7 +458,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
{
// BCS engine, Non-BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
csrOsContext.engineType = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, false);
@ -470,7 +470,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
{
// BCS engine, BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
csrOsContext.engineType = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, true);

View File

@ -967,7 +967,7 @@ HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWhenDumpAllocationIsCalle
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
auto &csrOsContext = tbxCsr.getOsContext();
auto &csrOsContext = static_cast<MockOsContext &>(tbxCsr.getOsContext());
{
// Non-BCS engine, BCS dump
EXPECT_FALSE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
@ -993,7 +993,7 @@ HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWhenDumpAllocationIsCalle
{
// BCS engine, Non-BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
csrOsContext.engineType = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, false);
@ -1005,7 +1005,7 @@ HWTEST_F(TbxCommandStreamTests, givenGraphicsAllocationWhenDumpAllocationIsCalle
{
// BCS engine, BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
csrOsContext.engineType = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, true);