Improve OsContext construction

Change-Id: Ibf9293344cc5c0ae1b2cc011e87d9e3626f3a066
This commit is contained in:
Dunajski, Bartosz
2019-02-27 11:17:17 +01:00
committed by sys_ocldev
parent 10a25e405a
commit 86dabbf6d5
38 changed files with 227 additions and 203 deletions

View File

@@ -182,7 +182,7 @@ bool MemoryManager::isMemoryBudgetExhausted() const {
OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver, EngineInstanceT engineType,
uint32_t numSupportedDevices, PreemptionMode preemptionMode) {
auto contextId = ++latestContextId;
auto osContext = new OsContext(executionEnvironment.osInterface.get(), contextId, numSupportedDevices, engineType, preemptionMode);
auto osContext = OsContext::create(executionEnvironment.osInterface.get(), contextId, numSupportedDevices, engineType, preemptionMode);
osContext->incRefInternal();
registeredEngines.emplace_back(commandStreamReceiver, osContext);

View File

@@ -45,7 +45,7 @@ DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(const HardwareInfo
template <typename GfxFamily>
FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
unsigned int engineFlag = osContext->get()->getEngineFlag();
unsigned int engineFlag = static_cast<OsContextLinux *>(osContext)->getEngineFlag();
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
DEBUG_BREAK_IF(!alloc);
@@ -70,7 +70,7 @@ FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
bb->exec(static_cast<uint32_t>(alignUp(batchBuffer.usedSize - batchBuffer.startOffset, 8)),
alignedStart, engineFlag | I915_EXEC_NO_RELOC,
batchBuffer.requiresCoherency,
osContext->get()->getDrmContextId());
static_cast<OsContextLinux *>(osContext)->getDrmContextId());
bb->getResidency()->clear();

View File

@@ -211,7 +211,8 @@ OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t si
void DrmMemoryManager::emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const {
if (forcePinEnabled && pinBB != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) {
pinBB->pin(&bo, 1, getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId());
auto &osContextLinux = static_cast<OsContextLinux &>(getDefaultCommandStreamReceiver(0)->getOsContext());
pinBB->pin(&bo, 1, osContextLinux.getDrmContextId());
}
}
@@ -624,7 +625,8 @@ MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStor
}
if (validateHostPtrMemory) {
int result = pinBB->pin(allocatedBos, numberOfBosAllocated, getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId());
auto &osContextLinux = static_cast<OsContextLinux &>(getDefaultCommandStreamReceiver(0)->getOsContext());
int result = pinBB->pin(allocatedBos, numberOfBosAllocated, osContextLinux.getDrmContextId());
if (result == EFAULT) {
for (uint32_t i = 0; i < numberOfBosAllocated; i++) {

View File

@@ -14,16 +14,18 @@
namespace OCLRT {
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode)
: contextId(contextId), numDevicesSupported(numDevicesSupported), engineType(engineType) {
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode) {
if (osInterface) {
osContextImpl = std::make_unique<OsContextLinux>(*osInterface->get()->getDrm(), engineType);
return new OsContextLinux(*osInterface->get()->getDrm(), contextId, numDevicesSupported, engineType, preemptionMode);
}
return new OsContext(contextId, numDevicesSupported, engineType, preemptionMode);
}
OsContext::~OsContext() = default;
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode)
: OsContext(contextId, numDevicesSupported, engineType, preemptionMode), drm(drm) {
OsContextLinux::OsContextImpl(Drm &drm, EngineInstanceT engineType) : drm(drm) {
engineFlag = DrmEngineMapper::engineNodeMap(engineType.type);
this->drmContextId = drm.createDrmContext();
if (drm.isPreemptionSupported() &&
@@ -33,7 +35,7 @@ OsContextLinux::OsContextImpl(Drm &drm, EngineInstanceT engineType) : drm(drm) {
}
}
OsContextLinux::~OsContextImpl() {
OsContextLinux::~OsContextLinux() {
drm.destroyDrmContext(drmContextId);
}
} // namespace OCLRT

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Intel Corporation
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -9,12 +9,14 @@
namespace OCLRT {
class Drm;
using OsContextLinux = OsContext::OsContextImpl;
class OsContext::OsContextImpl {
class OsContextLinux : public OsContext {
public:
~OsContextImpl();
OsContextImpl(Drm &drm, EngineInstanceT engineType);
OsContextLinux() = delete;
~OsContextLinux() override;
OsContextLinux(Drm &drm, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode);
unsigned int getEngineFlag() const { return engineFlag; }
uint32_t getDrmContextId() const { return drmContextId; }

View File

@@ -18,21 +18,21 @@ class OSInterface;
class OsContext : public ReferenceTrackedObject<OsContext> {
public:
class OsContextImpl;
OsContext(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode);
~OsContext() override;
OsContextImpl *get() const {
return osContextImpl.get();
};
OsContext() = delete;
static OsContext *create(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode);
uint32_t getContextId() const { return contextId; }
uint32_t getNumDevicesSupported() const { return numDevicesSupported; }
PreemptionMode getPreemptionMode() const { return preemptionMode; }
EngineInstanceT &getEngineType() { return engineType; }
protected:
std::unique_ptr<OsContextImpl> osContextImpl;
OsContext(uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode)
: contextId(contextId), numDevicesSupported(numDevicesSupported), preemptionMode(preemptionMode), engineType(engineType){};
const uint32_t contextId;
const uint32_t numDevicesSupported;
const PreemptionMode preemptionMode;
EngineInstanceT engineType = {EngineType::ENGINE_RCS, 0};
};
} // namespace OCLRT

View File

@@ -14,10 +14,9 @@
namespace OCLRT {
class OsContextWin;
class Wddm;
using OsContextWin = OsContext::OsContextImpl;
class DeferrableDeletionImpl : public DeferrableDeletion {
public:
DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);

View File

@@ -110,7 +110,7 @@ bool setupArbSyncObject(GLSharingFunctions &sharing, OSInterface &osInterface, C
}
void signalArbSyncObject(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {
auto osContextWin = osContext.get();
auto osContextWin = static_cast<OsContextWin *>(&osContext);
UNRECOVERABLE_IF(!osContextWin);
auto wddm = osContextWin->getWddm();
@@ -127,7 +127,7 @@ void signalArbSyncObject(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {
}
D3DKMT_SIGNALSYNCHRONIZATIONOBJECT signalSubmissionSyncInfo = {0};
signalSubmissionSyncInfo.hContext = osContext.get()->getContext();
signalSubmissionSyncInfo.hContext = osContextWin->getContext();
signalSubmissionSyncInfo.Flags.SignalAtSubmission = 1; // Don't wait for GPU to complete processing command buffer
signalSubmissionSyncInfo.ObjectHandleArray[0] = glSyncInfo.submissionSynchronizationObject;
signalSubmissionSyncInfo.ObjectCount = 1;

View File

@@ -13,32 +13,36 @@
namespace OCLRT {
OsContextWin::OsContextImpl(Wddm &wddm, uint32_t osContextId, EngineInstanceT engineType, PreemptionMode preemptionMode) : wddm(wddm), residencyController(wddm, osContextId) {
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode) {
if (osInterface) {
return new OsContextWin(*osInterface->get()->getWddm(), contextId, numDevicesSupported, engineType, preemptionMode);
}
return new OsContext(contextId, numDevicesSupported, engineType, preemptionMode);
}
OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode)
: OsContext(contextId, numDevicesSupported, engineType, preemptionMode), wddm(wddm), residencyController(wddm, contextId) {
UNRECOVERABLE_IF(!wddm.isInitialized());
auto wddmInterface = wddm.getWddmInterface();
if (!wddm.createContext(context, engineType, preemptionMode)) {
return;
}
if (wddmInterface->hwQueuesSupported()) {
if (!wddmInterface->createHwQueue(preemptionMode, *this)) {
if (!wddmInterface->createHwQueue(*this)) {
return;
}
}
initialized = wddmInterface->createMonitoredFence(this->residencyController);
this->residencyController.registerCallback();
initialized = wddmInterface->createMonitoredFence(residencyController);
residencyController.registerCallback();
};
OsContextWin::~OsContextImpl() {
OsContextWin::~OsContextWin() {
wddm.getWddmInterface()->destroyHwQueue(hwQueueHandle);
wddm.destroyContext(context);
}
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode)
: contextId(contextId), numDevicesSupported(numDevicesSupported), engineType(engineType) {
if (osInterface) {
osContextImpl = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), contextId, engineType, preemptionMode);
}
}
OsContext::~OsContext() = default;
} // namespace OCLRT

View File

@@ -12,12 +12,14 @@
namespace OCLRT {
class Wddm;
using OsContextWin = OsContext::OsContextImpl;
class OsContext::OsContextImpl {
class OsContextWin : public OsContext {
public:
OsContextImpl() = delete;
OsContextImpl(Wddm &wddm, uint32_t osContextId, EngineInstanceT engineType, PreemptionMode preemptionMode);
~OsContextImpl();
OsContextWin() = delete;
~OsContextWin() override;
OsContextWin(Wddm &wddm, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode);
D3DKMT_HANDLE getContext() const {
return context;
}

View File

@@ -22,6 +22,7 @@ class Gdi;
class Gmm;
class GmmMemory;
class GmmPageTableMngr;
class OsContextWin;
class SettingsReader;
class WddmAllocation;
class WddmInterface;
@@ -35,8 +36,6 @@ struct OsHandleStorage;
enum class HeapIndex : uint32_t;
using OsContextWin = OsContext::OsContextImpl;
enum class EvictionStatus {
SUCCESS,
FAILED,

View File

@@ -14,7 +14,7 @@
using namespace OCLRT;
bool WddmInterface20::createHwQueue(PreemptionMode preemptionMode, OsContextWin &osContext) {
bool WddmInterface20::createHwQueue(OsContextWin &osContext) {
return false;
}
void WddmInterface20::destroyHwQueue(D3DKMT_HANDLE hwQueue) {}
@@ -66,7 +66,7 @@ bool WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *commandH
return STATUS_SUCCESS == status;
}
bool WddmInterface23::createHwQueue(PreemptionMode preemptionMode, OsContextWin &osContext) {
bool WddmInterface23::createHwQueue(OsContextWin &osContext) {
D3DKMT_CREATEHWQUEUE createHwQueue = {};
if (!wddm.getGdi()->setupHwQueueProcAddresses()) {
@@ -74,7 +74,7 @@ bool WddmInterface23::createHwQueue(PreemptionMode preemptionMode, OsContextWin
}
createHwQueue.hHwContext = osContext.getContext();
if (preemptionMode >= PreemptionMode::MidBatch) {
if (osContext.getPreemptionMode() >= PreemptionMode::MidBatch) {
createHwQueue.Flags.DisableGpuTimeout = wddm.readEnablePreemptionRegKey();
}

View File

@@ -17,16 +17,15 @@
namespace OCLRT {
class Gdi;
class Wddm;
class OsContextWin;
class WddmResidencyController;
using OsContextWin = OsContext::OsContextImpl;
class WddmInterface {
public:
WddmInterface(Wddm &wddm) : wddm(wddm){};
virtual ~WddmInterface() = default;
WddmInterface() = delete;
virtual bool createHwQueue(PreemptionMode preemptionMode, OsContextWin &osContext) = 0;
virtual bool createHwQueue(OsContextWin &osContext) = 0;
virtual void destroyHwQueue(D3DKMT_HANDLE hwQueue) = 0;
bool createMonitoredFence(WddmResidencyController &residencyController);
virtual const bool hwQueuesSupported() = 0;
@@ -37,7 +36,7 @@ class WddmInterface {
class WddmInterface20 : public WddmInterface {
public:
using WddmInterface::WddmInterface;
bool createHwQueue(PreemptionMode preemptionMode, OsContextWin &osContext) override;
bool createHwQueue(OsContextWin &osContext) override;
void destroyHwQueue(D3DKMT_HANDLE hwQueue) override;
const bool hwQueuesSupported() override;
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) override;
@@ -46,7 +45,7 @@ class WddmInterface20 : public WddmInterface {
class WddmInterface23 : public WddmInterface {
public:
using WddmInterface::WddmInterface;
bool createHwQueue(PreemptionMode preemptionMode, OsContextWin &osContext) override;
bool createHwQueue(OsContextWin &osContext) override;
void destroyHwQueue(D3DKMT_HANDLE hwQueue) override;
const bool hwQueuesSupported() override;
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) override;

View File

@@ -99,9 +99,10 @@ FlushStamp WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
this->kmDafLockAllocations(allocationsForResidency);
}
wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContext->get());
auto osContextWin = static_cast<OsContextWin *>(osContext);
wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContextWin);
return osContext->get()->getResidencyController().getMonitoredFence().lastSubmittedFence;
return osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence;
}
template <typename GfxFamily>
@@ -121,13 +122,13 @@ void WddmCommandStreamReceiver<GfxFamily>::makeResident(GraphicsAllocation &gfxA
template <typename GfxFamily>
void WddmCommandStreamReceiver<GfxFamily>::processResidency(ResidencyContainer &allocationsForResidency) {
bool success = osContext->get()->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency);
bool success = static_cast<OsContextWin *>(osContext)->getResidencyController().makeResidentResidencyAllocations(allocationsForResidency);
DEBUG_BREAK_IF(!success);
}
template <typename GfxFamily>
void WddmCommandStreamReceiver<GfxFamily>::processEviction() {
osContext->get()->getResidencyController().makeNonResidentEvictionAllocations(this->getEvictionAllocations());
static_cast<OsContextWin *>(osContext)->getResidencyController().makeNonResidentEvictionAllocations(this->getEvictionAllocations());
this->getEvictionAllocations().clear();
}
@@ -143,7 +144,7 @@ MemoryManager *WddmCommandStreamReceiver<GfxFamily>::createMemoryManager(bool en
template <typename GfxFamily>
bool WddmCommandStreamReceiver<GfxFamily>::waitForFlushStamp(FlushStamp &flushStampToWait) {
return wddm->waitFromCpu(flushStampToWait, osContext->get()->getResidencyController().getMonitoredFence());
return wddm->waitFromCpu(flushStampToWait, static_cast<OsContextWin *>(osContext)->getResidencyController().getMonitoredFence());
}
template <typename GfxFamily>

View File

@@ -293,7 +293,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
DEBUG_BREAK_IF(!validateAllocation(input));
for (auto &engine : this->registeredEngines) {
auto &residencyController = engine.osContext->get()->getResidencyController();
auto &residencyController = static_cast<OsContextWin *>(engine.osContext)->getResidencyController();
auto lock = residencyController.acquireLock();
residencyController.removeFromTrimCandidateListIfUsed(input, true);
}
@@ -345,7 +345,7 @@ bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t alloc
bool WddmMemoryManager::isMemoryBudgetExhausted() const {
for (auto &engine : this->registeredEngines) {
if (engine.osContext->get()->getResidencyController().isMemoryBudgetExhausted()) {
if (static_cast<OsContextWin *>(engine.osContext)->getResidencyController().isMemoryBudgetExhausted()) {
return true;
}
}

View File

@@ -20,10 +20,9 @@
namespace OCLRT {
class Gmm;
class OsContextWin;
class Wddm;
using OsContextWin = OsContext::OsContextImpl;
class WddmMemoryManager : public MemoryManager {
public:
~WddmMemoryManager() override;

View File

@@ -20,6 +20,7 @@
#include "unit_tests/mocks/mock_graphics_allocation.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_mdi.h"
#include "unit_tests/mocks/mock_os_context.h"
using namespace OCLRT;
@@ -202,7 +203,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenOsContextIsSetThenCreateH
uint32_t engineIndex = 2;
uint32_t deviceIndex = 3;
OsContext osContext(nullptr, 0, 1, allEngineInstances[engineIndex], PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, allEngineInstances[engineIndex], PreemptionMode::Disabled);
std::string fileName = "file_name.aub";
MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, fileName, CommandStreamReceiverType::CSR_AUB);
@@ -222,7 +223,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenOsContextIsSetThenCreateH
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenLowPriorityOsContextIsSetThenDontCreateHardwareContext) {
OsContext osContext(nullptr, 0, 1, lowPriorityGpgpuEngine, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, lowPriorityGpgpuEngine, PreemptionMode::Disabled);
std::string fileName = "file_name.aub";
MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, fileName, CommandStreamReceiverType::CSR_AUB);
@@ -288,7 +289,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl
executionEnvironment.aubCenter.reset(new AubCenter());
auto engineInstance = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0];
OsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled);
auto aubCsr1 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto aubCsr2 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
@@ -802,7 +803,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenOsContextWithMultipleDevicesSupport
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
uint32_t numSupportedDevices = 3;
OsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(*platformDevices[0], "", true, *pDevice->executionEnvironment);
aubCsr->setupContext(osContext);
@@ -1114,7 +1115,7 @@ TEST_F(HardwareContextContainerTests, givenDeviceIndexWhenOsContextWithMultipleD
MockAubManager aubManager;
uint32_t numSupportedDevices = 2;
uint32_t deviceIndex = 1;
OsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
EXPECT_THROW(HardwareContextController(aubManager, osContext, deviceIndex, 0, 0), std::exception);
}
@@ -1122,7 +1123,7 @@ TEST_F(HardwareContextContainerTests, givenDeviceIndexWhenOsContextWithMultipleD
TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupportedThenInitialzeHwContextsWithValidIndexes) {
MockAubManager aubManager;
uint32_t numSupportedDevices = 2;
OsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
HardwareContextController hwContextControler(aubManager, osContext, 0, 0);
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextControler.hardwareContexts[0].get());
@@ -1134,7 +1135,7 @@ TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupported
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseAllContexts) {
MockAubManager aubManager;
uint32_t numSupportedDevices = 2;
OsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
HardwareContextController hwContextContainer(aubManager, osContext, numSupportedDevices, 0);
EXPECT_EQ(numSupportedDevices, hwContextContainer.hardwareContexts.size());
@@ -1173,7 +1174,7 @@ TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCa
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseFirstContext) {
MockAubManager aubManager;
uint32_t numSupportedDevices = 2;
OsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 1, numSupportedDevices, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
HardwareContextController hwContextContainer(aubManager, osContext, 2, 0);
EXPECT_EQ(numSupportedDevices, hwContextContainer.hardwareContexts.size());

View File

@@ -23,6 +23,7 @@
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_mdi.h"
#include "unit_tests/mocks/mock_os_context.h"
#include "third_party/aub_stream/headers/options.h"
@@ -479,7 +480,7 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh
executionEnvironment.memoryManager.reset(memoryManager);
auto engineInstance = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0];
OsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled);
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(*platformDevices[0], "", true, executionEnvironment));
aubCsr->setupContext(osContext);
@@ -713,7 +714,7 @@ HWTEST_F(AubCommandStreamReceiverTests, whenAubCommandStreamReceiverIsCreatedThe
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenEngineIsInitializedThenDumpHandleIsGenerated) {
executionEnvironment.aubCenter.reset(new AubCenter());
auto engineInstance = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0];
OsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled);
auto aubCsr = std::make_unique<MockAubCsrToTestDumpContext<FamilyType>>(**platformDevices, "", true, executionEnvironment);
EXPECT_NE(nullptr, aubCsr);
@@ -886,7 +887,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
@@ -913,7 +914,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
@@ -941,7 +942,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNonWritableWhenDu
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
@@ -970,7 +971,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNotDumpableWhenDu
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
@@ -1000,7 +1001,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());

View File

@@ -17,6 +17,7 @@
#include "unit_tests/mocks/mock_aub_file_stream.h"
#include "unit_tests/mocks/mock_aub_manager.h"
#include "unit_tests/mocks/mock_graphics_allocation.h"
#include "unit_tests/mocks/mock_os_context.h"
#include "driver_version.h"
@@ -261,7 +262,7 @@ HWTEST_F(AubFileStreamTests, givenNewTasksAndHardwareContextPresentWhenCallingPo
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto hardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
aubCsr.stream = aubStream.get();
@@ -281,7 +282,7 @@ HWTEST_F(AubFileStreamTests, givenNoNewTasksAndHardwareContextPresentWhenCalling
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto hardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
aubCsr.stream = aubStream.get();
@@ -364,7 +365,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenI
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
aubCsr.stream = aubStream.get();
@@ -393,7 +394,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledWithZ
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
aubCsr.stream = aubStream.get();
@@ -417,7 +418,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCall
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
@@ -433,7 +434,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryEqualI
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
@@ -449,7 +450,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqu
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());

View File

@@ -18,6 +18,7 @@
#include "unit_tests/mocks/mock_allocation_properties.h"
#include "unit_tests/mocks/mock_aub_center.h"
#include "unit_tests/mocks/mock_aub_manager.h"
#include "unit_tests/mocks/mock_os_context.h"
using namespace OCLRT;
@@ -129,7 +130,7 @@ HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenCsrWithAubDumpWhenSett
ExecutionEnvironment executionEnvironment;
CommandStreamReceiverWithAUBDump<UltCommandStreamReceiver<FamilyType>> csrWithAubDump(*platformDevices[0], "aubfile", executionEnvironment);
OsContext osContext(nullptr, 0, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
MockOsContext osContext(nullptr, 0, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
csrWithAubDump.setupContext(osContext);
EXPECT_EQ(&osContext, &csrWithAubDump.getOsContext());

View File

@@ -25,6 +25,7 @@
#include "unit_tests/mocks/mock_aub_manager.h"
#include "unit_tests/mocks/mock_execution_environment.h"
#include "unit_tests/mocks/mock_graphics_allocation.h"
#include "unit_tests/mocks/mock_os_context.h"
#include "unit_tests/mocks/mock_tbx_csr.h"
#include "tbx_command_stream_fixture.h"
@@ -351,7 +352,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockTbxCsr<FamilyType> tbxCsr(**platformDevices, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
tbxCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(tbxCsr.hardwareContextController->hardwareContexts[0].get());
@@ -381,7 +382,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverInBatchedModeWhenFl
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockTbxCsr<FamilyType> tbxCsr(**platformDevices, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
tbxCsr.setupContext(osContext);
auto commandBuffer = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
@@ -403,7 +404,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledWi
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockTbxCsr<FamilyType> tbxCsr(**platformDevices, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
tbxCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(tbxCsr.hardwareContextController->hardwareContexts[0].get());
@@ -425,7 +426,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentIsC
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockTbxCsr<FamilyType> tbxCsr(**platformDevices, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
tbxCsr.setupContext(osContext);
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
@@ -441,7 +442,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeCoherentIsC
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
MockTbxCsr<FamilyType> tbxCsr(**platformDevices, *pDevice->executionEnvironment);
OsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
tbxCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(tbxCsr.hardwareContextController->hardwareContexts[0].get());
@@ -465,7 +466,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenHardwareContextIsCreatedThenTbxSt
}
HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenOsContextIsSetThenCreateHardwareContext) {
OsContext osContext(nullptr, 0, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionMode::Disabled);
MockOsContext osContext(nullptr, 0, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionMode::Disabled);
std::string fileName = "";
MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, fileName, CommandStreamReceiverType::CSR_TBX);

View File

@@ -35,6 +35,7 @@
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_mdi.h"
#include "unit_tests/mocks/mock_memory_manager.h"
#include "unit_tests/mocks/mock_os_context.h"
#include <future>
#include <type_traits>
@@ -1556,8 +1557,8 @@ TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenIt
MockResidencyData residency;
OsContext osContext(nullptr, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
OsContext osContext2(nullptr, 1u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[1], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
MockOsContext osContext(nullptr, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
MockOsContext osContext2(nullptr, 1u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[1], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
auto lastFenceValue = 45llu;
auto lastFenceValue2 = 23llu;
@@ -1616,9 +1617,10 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenAllocationWasNotUnlockedThenItIsUn
EXPECT_EQ(1u, memoryManager.unlockResourceCalled);
}
TEST(OsContextTest, givenOsContextWithNumberOfSupportedDevicesWhenConstructingThenUsePassedValue) {
OsContext osContext(nullptr, 5, 7, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
TEST(OsContextTest, givenOsContextWithNumberOfSupportedDevicesAndPreemptiomModeWhenConstructingThenUsePassedValue) {
MockOsContext osContext(nullptr, 5, 7, {EngineType::ENGINE_RCS, 0}, PreemptionMode::MidThread);
EXPECT_EQ(7u, osContext.getNumDevicesSupported());
EXPECT_EQ(PreemptionMode::MidThread, osContext.getPreemptionMode());
}
TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {

View File

@@ -55,6 +55,7 @@ set(IGDRCL_SRCS_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/mock_lrca_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_context.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_ostime.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_physical_address_allocator.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_program.h

View File

@@ -0,0 +1,18 @@
/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/os_interface/os_context.h"
namespace OCLRT {
class MockOsContext : public OsContext {
public:
MockOsContext(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported,
EngineInstanceT engineType, PreemptionMode preemptionMode)
: OsContext(contextId, numDevicesSupported, engineType, preemptionMode) {}
};
} // namespace OCLRT

View File

@@ -14,9 +14,9 @@ class WddmMockInterface23 : public WddmInterface23 {
public:
using WddmInterface23::WddmInterface23;
bool createHwQueue(PreemptionMode preemptionMode, OsContextWin &osContext) override {
bool createHwQueue(OsContextWin &osContext) override {
createHwQueueCalled++;
createHwQueueResult = forceCreateHwQueueFail ? false : WddmInterface23::createHwQueue(preemptionMode, osContext);
createHwQueueResult = forceCreateHwQueueFail ? false : WddmInterface23::createHwQueue(osContext);
return createHwQueueResult;
}

View File

@@ -42,7 +42,7 @@ class DrmCommandStreamFixture {
executionEnvironment.osInterface = std::make_unique<OSInterface>();
executionEnvironment.osInterface->get()->setDrm(mock.get());
osContext = std::make_unique<OsContext>(executionEnvironment.osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
osContext = std::make_unique<OsContextLinux>(*mock, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
csr = new DrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], executionEnvironment,
gemCloseWorkerMode::gemCloseWorkerActive);
@@ -79,7 +79,7 @@ class DrmCommandStreamFixture {
static const uint64_t alignment = MemoryConstants::allocationAlignment;
DebugManagerStateRestore dbgState;
ExecutionEnvironment executionEnvironment;
std::unique_ptr<OsContext> osContext;
std::unique_ptr<OsContextLinux> osContext;
};
typedef Test<DrmCommandStreamFixture> DrmCommandStreamTest;
@@ -254,8 +254,8 @@ TEST_F(DrmCommandStreamTest, givenDrmContextIdWhenFlushingThenSetIdToAllExecBuff
.WillRepeatedly(::testing::Return(0))
.RetiresOnSaturation();
osContext = std::make_unique<OsContext>(executionEnvironment.osInterface.get(), 1, 1,
HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
osContext = std::make_unique<OsContextLinux>(*mock, 1, 1,
HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
csr->setupContext(*osContext);
auto &cs = csr->getCS();
@@ -800,7 +800,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr
int ioctlExecCnt = 1;
int ioctlUserPtrCnt = 2;
auto engineFlag = csr->getOsContext().get()->getEngineFlag();
auto engineFlag = static_cast<OsContextLinux &>(csr->getOsContext()).getEngineFlag();
EXPECT_EQ(ioctlExecCnt + ioctlUserPtrCnt, this->mock->ioctl_cnt.total);
EXPECT_EQ(ioctlExecCnt, this->mock->ioctl_cnt.execbuffer2);

View File

@@ -228,7 +228,8 @@ TEST_F(DrmMemoryManagerTest, givenDrmContextIdWhenAllocationIsCreatedThenPinWith
mock->ioctl_expected.gemClose = 2;
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
auto drmContextId = memoryManager->getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId();
auto &osContextLinux = static_cast<OsContextLinux &>(memoryManager->getDefaultCommandStreamReceiver(0)->getOsContext());
auto drmContextId = osContextLinux.getDrmContextId();
ASSERT_NE(nullptr, memoryManager->getPinBB());
EXPECT_NE(0u, drmContextId);

View File

@@ -9,7 +9,7 @@
#include "runtime/helpers/options.h"
#include "runtime/os_interface/device_factory.h"
#include "runtime/os_interface/linux/os_context_linux.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/os_interface/linux/os_interface.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/os_interface/linux/drm_mock.h"
@@ -151,18 +151,20 @@ constexpr EngineInstanceT defaultEngine{ENGINE_RCS, 0};
TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) {
DrmMock drmMock;
uint32_t drmContextId1 = 123;
uint32_t drmContextId2 = 456;
{
drmMock.StoredCtxId = drmContextId1;
OsContextLinux osContext1(drmMock, defaultEngine);
OsContextLinux osContext1(drmMock, 0u, 1, defaultEngine, PreemptionMode::Disabled);
EXPECT_EQ(drmContextId1, osContext1.getDrmContextId());
EXPECT_EQ(0u, drmMock.receivedDestroyContextId);
{
drmMock.StoredCtxId = drmContextId2;
OsContextLinux osContext2(drmMock, defaultEngine);
OsContextLinux osContext2(drmMock, 0u, 1, defaultEngine, PreemptionMode::Disabled);
EXPECT_EQ(drmContextId2, osContext2.getDrmContextId());
EXPECT_EQ(0u, drmMock.receivedDestroyContextId);
}
@@ -178,16 +180,17 @@ TEST(DrmTest, givenDrmPreemptionEnabledAndLowPriorityEngineWhenCreatingOsContext
drmMock.StoredCtxId = 123;
drmMock.preemptionSupported = false;
OsContextLinux osContext1(drmMock, defaultEngine);
OsContextLinux osContext2(drmMock, lowPriorityGpgpuEngine);
OsContextLinux osContext1(drmMock, 0u, 1, defaultEngine, PreemptionMode::Disabled);
OsContextLinux osContext2(drmMock, 0u, 1, lowPriorityGpgpuEngine, PreemptionMode::Disabled);
EXPECT_EQ(0u, drmMock.receivedContextParamRequestCount);
drmMock.preemptionSupported = true;
OsContextLinux osContext3(drmMock, defaultEngine);
OsContextLinux osContext3(drmMock, 0u, 1, defaultEngine, PreemptionMode::Disabled);
EXPECT_EQ(0u, drmMock.receivedContextParamRequestCount);
OsContextLinux osContext4(drmMock, lowPriorityGpgpuEngine);
OsContextLinux osContext4(drmMock, 0u, 1, lowPriorityGpgpuEngine, PreemptionMode::Disabled);
EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount);
EXPECT_EQ(drmMock.StoredCtxId, drmMock.receivedContextParamRequest.ctx_id);
EXPECT_EQ(static_cast<uint64_t>(I915_CONTEXT_PARAM_PRIORITY), drmMock.receivedContextParamRequest.param);

View File

@@ -24,12 +24,4 @@ TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsRetu
EXPECT_EQ(0u, osInterface.getDeviceHandle());
}
TEST(OsContextTest, givenDrmWhenOsContextIsCreatedThenImplIsAvailable) {
DrmMock drmMock;
OSInterface osInterface;
osInterface.get()->setDrm(&drmMock);
auto osContext = std::make_unique<OsContext>(&osInterface, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
EXPECT_NE(nullptr, osContext->get());
}
} // namespace OCLRT

View File

@@ -188,7 +188,7 @@ TEST_F(WddmCommandStreamTest, Flush) {
EXPECT_EQ(1u, wddm->submitResult.called);
EXPECT_TRUE(wddm->submitResult.success);
EXPECT_EQ(flushStamp, csr->getOsContext().get()->getResidencyController().getMonitoredFence().lastSubmittedFence);
EXPECT_EQ(flushStamp, static_cast<OsContextWin &>(csr->getOsContext()).getResidencyController().getMonitoredFence().lastSubmittedFence);
memoryManager->freeGraphicsMemory(commandBuffer);
}
@@ -247,7 +247,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf
std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(hwInfo[0], *executionEnvironment));
executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false));
executionEnvironment->commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
OsContext osContext(executionEnvironment->osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo));
OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo));
executionEnvironment->commandStreamReceivers[0][0]->setupContext(osContext);
auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
@@ -272,7 +272,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn
*executionEnvironment));
executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false));
executionEnvironment->commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch);
OsContext osContext(executionEnvironment->osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo));
OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo));
executionEnvironment->commandStreamReceivers[0][0]->setupContext(osContext);
auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
@@ -550,7 +550,7 @@ TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidate
csr->processEviction();
EXPECT_EQ(2u, csr->getOsContext().get()->getResidencyController().peekTrimCandidateList().size());
EXPECT_EQ(2u, static_cast<OsContextWin &>(csr->getOsContext()).getResidencyController().peekTrimCandidateList().size());
memoryManager->freeGraphicsMemory(allocation);
memoryManager->freeGraphicsMemory(allocation2);

View File

@@ -326,14 +326,14 @@ TEST_F(GlArbSyncEventOsTest, GivenCallToSignalArbSyncObjectWhenSignalSynchroniza
FailSignalSyncObjectMock::reset();
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
wddm->init(preemptionMode);
OsContext osContext(&osInterface, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
OsContextWin osContext(*osInterface.get()->getWddm(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
CL_GL_SYNC_INFO syncInfo = {};
syncInfo.serverSynchronizationObject = 0x5cU;
syncInfo.clientSynchronizationObject = 0x6cU;
gdi->signalSynchronizationObject.mFunc = FailSignalSyncObjectMock::signal;
FailSignalSyncObjectMock::getExpectedContextHandle() = osContext.get()->getContext();
FailSignalSyncObjectMock::getExpectedContextHandle() = osContext.getContext();
FailSignalSyncObjectMock::getExpectedSynchHandle0() = syncInfo.serverSynchronizationObject;
FailSignalSyncObjectMock::getExpectedSynchHandle1() = syncInfo.clientSynchronizationObject;
@@ -385,13 +385,13 @@ TEST_F(GlArbSyncEventOsTest, GivenCallToSignalArbSyncObjectWhenSignalSynchroniza
FailSignalSyncObjectMock::reset();
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
wddm->init(preemptionMode);
OsContext osContext(&osInterface, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
OsContextWin osContext(*osInterface.get()->getWddm(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
CL_GL_SYNC_INFO syncInfo = {};
syncInfo.submissionSynchronizationObject = 0x7cU;
gdi->signalSynchronizationObject.mFunc = FailSignalSyncObjectMock::signal;
FailSignalSyncObjectMock::getExpectedContextHandle() = osContext.get()->getContext();
FailSignalSyncObjectMock::getExpectedContextHandle() = osContext.getContext();
FailSignalSyncObjectMock::getExpectedSynchHandle0() = syncInfo.submissionSynchronizationObject;
signalArbSyncObject(osContext, syncInfo);

View File

@@ -30,7 +30,7 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextBeforeInitWddmThenOsContextIsNot
auto wddm = new WddmMock;
OSInterface osInterface;
osInterface.get()->setWddm(wddm);
EXPECT_THROW(auto osContext = std::make_unique<OsContext>(&osInterface, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])), std::exception);
EXPECT_THROW(auto osContext = std::make_unique<OsContextWin>(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])), std::exception);
}
TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitializedAndTrimCallbackIsRegistered) {
@@ -40,15 +40,8 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
wddm->init(preemptionMode);
EXPECT_EQ(0u, wddm->registerTrimCallbackResult.called);
auto osContext = std::make_unique<OsContext>(&osInterface, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
EXPECT_NE(nullptr, osContext->get());
EXPECT_TRUE(osContext->get()->isInitialized());
EXPECT_EQ(osContext->get()->getWddm(), wddm);
auto osContext = std::make_unique<OsContextWin>(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
EXPECT_TRUE(osContext->isInitialized());
EXPECT_EQ(osContext->getWddm(), wddm);
EXPECT_EQ(1u, wddm->registerTrimCallbackResult.called);
}
TEST(OsContextTest, whenCreateOsContextWithoutOsInterfaceThenOsContextImplIsNotAvailable) {
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
auto osContext = std::make_unique<OsContext>(nullptr, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
EXPECT_EQ(nullptr, osContext->get());
}

View File

@@ -164,7 +164,7 @@ TEST(Wddm20EnumAdaptersTest, givenUnknownPlatformWhenEnumAdapterIsCalledThenFals
}
TEST_F(Wddm20Tests, whenInitializeWddmThenContextIsCreated) {
auto context = osContextWin->getContext();
auto context = osContext->getContext();
EXPECT_TRUE(context != static_cast<D3DKMT_HANDLE>(0));
}
@@ -179,7 +179,7 @@ TEST_F(Wddm20Tests, allocation) {
EXPECT_EQ(STATUS_SUCCESS, status);
EXPECT_TRUE(allocation.handle != 0);
auto error = wddm->destroyAllocation(&allocation, osContextWin);
auto error = wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_TRUE(error);
delete gmm;
@@ -209,7 +209,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz
EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages);
EXPECT_NE(underlyingPages, getLastCallMapGpuVaArgFcn()->SizeInPages);
ret = wddm->destroyAllocation(&allocation, osContextWin);
ret = wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_TRUE(ret);
delete gmm;
@@ -278,7 +278,7 @@ TEST_F(Wddm20Tests, createAllocation32bit) {
EXPECT_LE(heap32baseAddress, allocation.gpuPtr);
EXPECT_GT(heap32baseAddress + heap32Size, allocation.gpuPtr);
auto success = wddm->destroyAllocation(&allocation, osContextWin);
auto success = wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_TRUE(success);
delete gmm;
@@ -354,7 +354,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) {
EXPECT_TRUE(error);
EXPECT_TRUE(allocation.gpuPtr == 0);
error = wddm->destroyAllocation(&allocation, osContextWin);
error = wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_TRUE(error);
delete gmm;
mm.freeSystemMemory(allocation.getUnderlyingBuffer());
@@ -402,12 +402,12 @@ TEST_F(Wddm20Tests, makeResidentNonResident) {
error = wddm->evict(&allocation.handle, 1, sizeToTrim);
EXPECT_TRUE(error);
auto monitoredFence = osContextWin->getResidencyController().getMonitoredFence();
auto monitoredFence = osContext->getResidencyController().getMonitoredFence();
UINT64 fenceValue = 100;
monitoredFence.cpuAddress = &fenceValue;
monitoredFence.currentFenceValue = 101;
error = wddm->destroyAllocation(&allocation, osContextWin);
error = wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_TRUE(error);
delete gmm;
@@ -579,7 +579,7 @@ TEST_F(Wddm20WithMockGdiDllTests, whenCreateContextIsCalledThenDisableHwQueues)
}
TEST_F(Wddm20Tests, whenCreateHwQueueIsCalledThenAlwaysReturnFalse) {
EXPECT_FALSE(wddm->wddmInterface->createHwQueue(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), *osContextWin));
EXPECT_FALSE(wddm->wddmInterface->createHwQueue(*osContext.get()));
}
TEST_F(Wddm20Tests, whenWddmIsInitializedThenGdiDoesntHaveHwQueueDDIs) {
@@ -657,10 +657,10 @@ TEST_F(Wddm20Tests, makeNonResidentCallsEvict) {
TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedToDestroyAllocation) {
WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, (void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull, false);
allocation.getResidencyData().updateCompletionData(10, osContext.get()->getContextId());
allocation.getResidencyData().updateCompletionData(10, osContext->getContextId());
allocation.handle = ALLOCATION_HANDLE;
*osContextWin->getResidencyController().getMonitoredFence().cpuAddress = 10;
*osContext->getResidencyController().getMonitoredFence().cpuAddress = 10;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
@@ -674,7 +674,7 @@ TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedTo
gdi->getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi->getDestroyArg().phAllocationList = nullptr;
wddm->destroyAllocation(&allocation, osContextWin);
wddm->destroyAllocation(&allocation, osContext.get());
EXPECT_EQ(wddm->getDevice(), gdi->getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi->getDestroyArg().AllocationCount);
@@ -683,10 +683,10 @@ TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedTo
TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) {
WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, (void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull, false);
allocation.getResidencyData().updateCompletionData(10, osContext.get()->getContextId());
allocation.getResidencyData().updateCompletionData(10, osContext->getContextId());
allocation.handle = ALLOCATION_HANDLE;
*osContextWin->getResidencyController().getMonitoredFence().cpuAddress = 10;
*osContext->getResidencyController().getMonitoredFence().cpuAddress = 10;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
@@ -694,7 +694,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle
gdi->getWaitFromCpuArg().ObjectCount = 0;
gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr;
auto status = wddm->waitFromCpu(10, osContextWin->getResidencyController().getMonitoredFence());
auto status = wddm->waitFromCpu(10, osContext->getResidencyController().getMonitoredFence());
EXPECT_TRUE(status);
@@ -706,10 +706,10 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle
TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) {
WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, (void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull, false);
allocation.getResidencyData().updateCompletionData(10, osContext.get()->getContextId());
allocation.getResidencyData().updateCompletionData(10, osContext->getContextId());
allocation.handle = ALLOCATION_HANDLE;
*osContextWin->getResidencyController().getMonitoredFence().cpuAddress = 10;
*osContext->getResidencyController().getMonitoredFence().cpuAddress = 10;
gdi->getWaitFromCpuArg().FenceValueArray = nullptr;
gdi->getWaitFromCpuArg().Flags.Value = 0;
@@ -717,7 +717,7 @@ TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) {
gdi->getWaitFromCpuArg().ObjectCount = 0;
gdi->getWaitFromCpuArg().ObjectHandleArray = nullptr;
auto status = wddm->waitFromCpu(20, osContextWin->getResidencyController().getMonitoredFence());
auto status = wddm->waitFromCpu(20, osContext->getResidencyController().getMonitoredFence());
EXPECT_TRUE(status);
@@ -732,10 +732,10 @@ TEST_F(Wddm20Tests, createMonitoredFenceIsInitializedWithFenceValueZeroAndCurren
gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300;
wddm->wddmInterface->createMonitoredFence(osContextWin->getResidencyController());
wddm->wddmInterface->createMonitoredFence(osContext->getResidencyController());
EXPECT_EQ(0u, gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue);
EXPECT_EQ(1u, osContextWin->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue);
}
NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) {

View File

@@ -38,8 +38,7 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, publi
void init() {
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
EXPECT_TRUE(wddm->init(preemptionMode));
osContext = std::make_unique<OsContext>(osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
osContextWin = osContext->get();
osContext = std::make_unique<OsContextWin>(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
}
void TearDown() override {
@@ -48,8 +47,7 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, publi
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<OsContext> osContext;
OsContextWin *osContextWin = nullptr;
std::unique_ptr<OsContextWin> osContext;
WddmMock *wddm = nullptr;
WddmMockInterface23 *wddmMockInterface = nullptr;
};
@@ -68,28 +66,32 @@ TEST_F(Wddm23Tests, whenCreateContextIsCalledThenEnableHwQueues) {
}
TEST_F(Wddm23Tests, givenPreemptionModeWhenCreateHwQueueCalledThenSetGpuTimeoutIfEnabled) {
wddm->wddmInterface->createHwQueue(PreemptionMode::Disabled, *osContextWin);
auto defaultEngine = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0];
OsContextWin osContextWithoutPreemption(*osInterface->get()->getWddm(), 0u, 1, defaultEngine, PreemptionMode::Disabled);
OsContextWin osContextWithPreemption(*osInterface->get()->getWddm(), 0u, 1, defaultEngine, PreemptionMode::MidBatch);
wddm->wddmInterface->createHwQueue(osContextWithoutPreemption);
EXPECT_EQ(0u, getCreateHwQueueDataFcn()->Flags.DisableGpuTimeout);
wddm->wddmInterface->createHwQueue(PreemptionMode::MidBatch, *osContextWin);
wddm->wddmInterface->createHwQueue(osContextWithPreemption);
EXPECT_EQ(1u, getCreateHwQueueDataFcn()->Flags.DisableGpuTimeout);
}
TEST_F(Wddm23Tests, whenDestroyHwQueueCalledThenPassExistingHandle) {
D3DKMT_HANDLE hwQueue = 123;
osContextWin->setHwQueue(hwQueue);
wddmMockInterface->destroyHwQueue(osContextWin->getHwQueue());
osContext->setHwQueue(hwQueue);
wddmMockInterface->destroyHwQueue(osContext->getHwQueue());
EXPECT_EQ(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue);
hwQueue = 0;
osContextWin->setHwQueue(hwQueue);
wddmMockInterface->destroyHwQueue(osContextWin->getHwQueue());
osContext->setHwQueue(hwQueue);
wddmMockInterface->destroyHwQueue(osContext->getHwQueue());
EXPECT_NE(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue); // gdi not called when 0
}
TEST_F(Wddm23Tests, whenObjectIsDestructedThenDestroyHwQueue) {
D3DKMT_HANDLE hwQueue = 123;
osContextWin->setHwQueue(hwQueue);
osContext->setHwQueue(hwQueue);
osContext.reset();
EXPECT_EQ(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue);
}
@@ -97,35 +99,35 @@ TEST_F(Wddm23Tests, whenObjectIsDestructedThenDestroyHwQueue) {
TEST_F(Wddm23Tests, givenCmdBufferWhenSubmitCalledThenSetAllRequiredFiledsAndUpdateMonitoredFence) {
uint64_t cmdBufferAddress = 123;
size_t cmdSize = 456;
auto hwQueue = osContextWin->getHwQueue();
auto hwQueue = osContext->getHwQueue();
COMMAND_BUFFER_HEADER cmdBufferHeader = {};
EXPECT_EQ(1u, osContextWin->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_EQ(0u, osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence);
EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_EQ(0u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence);
wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContextWin);
wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContext);
EXPECT_EQ(cmdBufferAddress, getSubmitCommandToHwQueueDataFcn()->CommandBuffer);
EXPECT_EQ(static_cast<UINT>(cmdSize), getSubmitCommandToHwQueueDataFcn()->CommandLength);
EXPECT_EQ(hwQueue, getSubmitCommandToHwQueueDataFcn()->hHwQueue);
EXPECT_EQ(osContextWin->getResidencyController().getMonitoredFence().fenceHandle, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId);
EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().fenceHandle, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId);
EXPECT_EQ(&cmdBufferHeader, getSubmitCommandToHwQueueDataFcn()->pPrivateDriverData);
EXPECT_EQ(static_cast<UINT>(MemoryConstants::pageSize), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize);
EXPECT_EQ(osContextWin->getResidencyController().getMonitoredFence().gpuAddress, cmdBufferHeader.MonitorFenceVA);
EXPECT_EQ(osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence, cmdBufferHeader.MonitorFenceValue);
EXPECT_EQ(2u, osContextWin->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_EQ(1u, osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence);
EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().gpuAddress, cmdBufferHeader.MonitorFenceVA);
EXPECT_EQ(osContext->getResidencyController().getMonitoredFence().lastSubmittedFence, cmdBufferHeader.MonitorFenceValue);
EXPECT_EQ(2u, osContext->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence);
}
TEST_F(Wddm23Tests, whenMonitoredFenceIsCreatedThenSetupAllRequiredFields) {
wddm->wddmInterface->createMonitoredFence(osContextWin->getResidencyController());
wddm->wddmInterface->createMonitoredFence(osContext->getResidencyController());
EXPECT_NE(nullptr, osContextWin->getResidencyController().getMonitoredFence().cpuAddress);
EXPECT_EQ(1u, osContextWin->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_NE(static_cast<D3DKMT_HANDLE>(0), osContextWin->getResidencyController().getMonitoredFence().fenceHandle);
EXPECT_NE(static_cast<D3DGPU_VIRTUAL_ADDRESS>(0), osContextWin->getResidencyController().getMonitoredFence().gpuAddress);
EXPECT_EQ(0u, osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence);
EXPECT_NE(nullptr, osContext->getResidencyController().getMonitoredFence().cpuAddress);
EXPECT_EQ(1u, osContext->getResidencyController().getMonitoredFence().currentFenceValue);
EXPECT_NE(static_cast<D3DKMT_HANDLE>(0), osContext->getResidencyController().getMonitoredFence().fenceHandle);
EXPECT_NE(static_cast<D3DGPU_VIRTUAL_ADDRESS>(0), osContext->getResidencyController().getMonitoredFence().gpuAddress);
EXPECT_EQ(0u, osContext->getResidencyController().getMonitoredFence().lastSubmittedFence);
}
TEST_F(Wddm23Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhenSubmitCalledThenCallWaitOnGpu) {
@@ -135,11 +137,11 @@ TEST_F(Wddm23Tests, givenCurrentPendingFenceValueGreaterThanPendingFenceValueWhe
*wddm->pagingFenceAddress = 1;
wddm->currentPagingFenceValue = 1;
wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContextWin);
wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContext);
EXPECT_EQ(0u, wddm->waitOnGPUResult.called);
wddm->currentPagingFenceValue = 2;
wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContextWin);
wddm->submit(cmdBufferAddress, cmdSize, &cmdBufferHeader, *osContext);
EXPECT_EQ(1u, wddm->waitOnGPUResult.called);
}
@@ -159,7 +161,7 @@ TEST_F(Wddm23TestsWithoutWddmInit, whenInitCalledThenInitializeNewGdiDDIsAndCall
TEST_F(Wddm23TestsWithoutWddmInit, whenCreateHwQueueFailedThenReturnFalseFromInit) {
wddmMockInterface->forceCreateHwQueueFail = true;
init();
EXPECT_FALSE(osContextWin->isInitialized());
EXPECT_FALSE(osContext->isInitialized());
}
TEST_F(Wddm23TestsWithoutWddmInit, givenFailureOnGdiInitializationWhenCreatingHwQueueThenReturnFailure) {
@@ -171,7 +173,7 @@ TEST_F(Wddm23TestsWithoutWddmInit, givenFailureOnGdiInitializationWhenCreatingHw
auto myMockGdi = new MyMockGdi();
wddm->gdi.reset(myMockGdi);
init();
EXPECT_FALSE(osContextWin->isInitialized());
EXPECT_FALSE(osContext->isInitialized());
EXPECT_EQ(1u, wddmMockInterface->createHwQueueCalled);
EXPECT_FALSE(wddmMockInterface->createHwQueueResult);
}

View File

@@ -10,6 +10,7 @@
#include "runtime/command_stream/preemption.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/os_interface/windows/gdi_interface.h"
#include "runtime/os_interface/windows/os_context_win.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "test.h"
#include "unit_tests/fixtures/gmm_environment_fixture.h"
@@ -30,8 +31,7 @@ struct WddmFixture : public GmmEnvironmentFixture {
wddm->gdi.reset(gdi);
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
wddm->init(preemptionMode);
osContext = std::make_unique<OsContext>(osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
osContextWin = osContext->get();
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1u, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
ASSERT_TRUE(wddm->isInitialized());
}
@@ -41,8 +41,7 @@ struct WddmFixture : public GmmEnvironmentFixture {
WddmMock *wddm = nullptr;
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<OsContext> osContext;
OsContextWin *osContextWin = nullptr;
std::unique_ptr<OsContextWin> osContext;
MockGdi *gdi = nullptr;
};
@@ -59,8 +58,7 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi
void init() {
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]);
EXPECT_TRUE(wddm->init(preemptionMode));
osContext = std::make_unique<OsContext>(osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
osContextWin = osContext->get();
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
ASSERT_TRUE(wddm->isInitialized());
}
@@ -71,8 +69,7 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi
WddmMock *wddm = nullptr;
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<OsContext> osContext;
OsContextWin *osContextWin = nullptr;
std::unique_ptr<OsContextWin> osContext;
};
struct WddmInstrumentationGmmFixture : public GmmEnvironmentFixture {

View File

@@ -22,6 +22,7 @@
#include "unit_tests/mocks/mock_deferred_deleter.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_memory_manager.h"
#include "unit_tests/mocks/mock_os_context.h"
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
#include "unit_tests/utilities/base_object_utils.h"
@@ -69,7 +70,7 @@ constexpr EngineInstanceT defaultRcsEngine{ENGINE_RCS, 0};
TEST(WddmAllocationTest, givenAllocationIsTrimCandidateInOneOsContextWhenGettingTrimCandidatePositionThenReturnItsPositionAndUnusedPositionInOtherContexts) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
OsContext osContext(nullptr, 1u, 1, defaultRcsEngine, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
MockOsContext osContext(nullptr, 1u, 1, defaultRcsEngine, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
allocation.setTrimCandidateListPosition(osContext.getContextId(), 700u);
EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(0u));
EXPECT_EQ(700u, allocation.getTrimCandidateListPosition(1u));
@@ -1263,7 +1264,8 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWithRegisteredOsContextWithE
memoryManager->createAndRegisterOsContext(nullptr, defaultRcsEngine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
memoryManager->createAndRegisterOsContext(nullptr, defaultRcsEngine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
memoryManager->createAndRegisterOsContext(nullptr, defaultRcsEngine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
memoryManager->getRegisteredEngines()[1].osContext->get()->getResidencyController().setMemoryBudgetExhausted();
auto osContext = static_cast<OsContextWin *>(memoryManager->getRegisteredEngines()[1].osContext);
osContext->getResidencyController().setMemoryBudgetExhausted();
EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted());
}

View File

@@ -36,8 +36,7 @@ class WddmPreemptionTests : public Test<WddmFixtureWithMockGdiDll> {
regReader->forceRetValue = forceReturnPreemptionRegKeyValue;
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest);
wddm->init(preemptionMode);
osContext = std::make_unique<OsContext>(osInterface.get(), 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
osContextWin = osContext->get();
osContext = std::make_unique<OsContextWin>(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], preemptionMode);
}
DebugManagerStateRestore *dbgRestorer = nullptr;

View File

@@ -95,7 +95,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT
osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, preemptionMode);
osContext->incRefInternal();
residencyController = &osContext->get()->getResidencyController();
residencyController = &static_cast<OsContextWin *>(osContext)->getResidencyController();
}
void TearDown() {
@@ -127,7 +127,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test {
osContext->incRefInternal();
residencyController = &osContext->get()->getResidencyController();
residencyController = &static_cast<OsContextWin *>(osContext)->getResidencyController();
}
void TearDown() {