Add typed MockContexts

Change-Id: I51e52e54b397ccd7afbbb3c21c9b2f0bbbc3704f
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski 2020-04-02 10:52:00 +02:00 committed by sys_ocldev
parent 05951d3a9e
commit 5146503dcf
2 changed files with 80 additions and 25 deletions

View File

@ -22,23 +22,15 @@
namespace NEO { namespace NEO {
MockContext::MockContext(ClDevice *device, bool noSpecialQueue) { MockContext::MockContext(ClDevice *pDevice, bool noSpecialQueue) {
memoryManager = device->getMemoryManager(); cl_device_id deviceId = pDevice;
devices.push_back(device); initializeWithDevices(ClDeviceVector{&deviceId, 1}, noSpecialQueue);
svmAllocsManager = new SVMAllocsManager(memoryManager);
cl_int retVal;
if (!specialQueue && !noSpecialQueue) {
auto commandQueue = CommandQueue::create(this, device, nullptr, false, retVal);
assert(retVal == CL_SUCCESS);
overrideSpecialQueueAndDecrementRefCount(commandQueue);
}
device->incRefInternal();
} }
MockContext::MockContext( MockContext::MockContext(
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *), void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
void *data) { void *data) {
device = nullptr; pDevice = nullptr;
properties = nullptr; properties = nullptr;
numProperties = 0; numProperties = 0;
contextCallback = funcNotify; contextCallback = funcNotify;
@ -54,23 +46,17 @@ MockContext::~MockContext() {
specialQueue->release(); specialQueue->release();
specialQueue = nullptr; specialQueue = nullptr;
} }
if (memoryManager->isAsyncDeleterEnabled()) { if (memoryManager && memoryManager->isAsyncDeleterEnabled()) {
memoryManager->getDeferredDeleter()->removeClient(); memoryManager->getDeferredDeleter()->removeClient();
} }
memoryManager = nullptr; memoryManager = nullptr;
} }
MockContext::MockContext() { MockContext::MockContext() {
device = new MockClDevice{MockClDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)}; pDevice = new MockClDevice{MockClDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)};
devices.push_back(device); cl_device_id deviceId = pDevice;
memoryManager = device->getMemoryManager(); initializeWithDevices(ClDeviceVector{&deviceId, 1}, false);
svmAllocsManager = new SVMAllocsManager(memoryManager); pDevice->decRefInternal();
cl_int retVal;
if (!specialQueue) {
auto commandQueue = CommandQueue::create(this, device, nullptr, false, retVal);
assert(retVal == CL_SUCCESS);
overrideSpecialQueueAndDecrementRefCount(commandQueue);
}
} }
void MockContext::setSharingFunctions(SharingFunctions *sharingFunctions) { void MockContext::setSharingFunctions(SharingFunctions *sharingFunctions) {
@ -98,4 +84,42 @@ std::unique_ptr<AsyncEventsHandler> &MockContext::getAsyncEventsHandlerUniquePtr
return static_cast<MockClExecutionEnvironment *>(devices[0]->getExecutionEnvironment())->asyncEventsHandler; return static_cast<MockClExecutionEnvironment *>(devices[0]->getExecutionEnvironment())->asyncEventsHandler;
} }
void MockContext::initializeWithDevices(const ClDeviceVector &devices, bool noSpecialQueue) {
for (auto &pClDevice : devices) {
pClDevice->incRefInternal();
}
this->devices = devices;
memoryManager = devices[0]->getMemoryManager();
svmAllocsManager = new SVMAllocsManager(memoryManager);
cl_int retVal;
if (!noSpecialQueue) {
auto commandQueue = CommandQueue::create(this, devices[0], nullptr, false, retVal);
assert(retVal == CL_SUCCESS);
overrideSpecialQueueAndDecrementRefCount(commandQueue);
}
}
MockDefaultContext::MockDefaultContext() : MockContext(nullptr, nullptr) {
pRootDevice0 = ultClDeviceFactory.rootDevices[0];
pRootDevice1 = ultClDeviceFactory.rootDevices[1];
cl_device_id deviceIds[] = {pRootDevice0, pRootDevice1};
initializeWithDevices(ClDeviceVector{deviceIds, 2}, true);
}
MockSpecializedContext::MockSpecializedContext() : MockContext(nullptr, nullptr) {
pRootDevice = ultClDeviceFactory.rootDevices[0];
pSubDevice0 = ultClDeviceFactory.subDevices[0];
pSubDevice1 = ultClDeviceFactory.subDevices[1];
cl_device_id deviceIds[] = {pSubDevice0, pSubDevice1};
initializeWithDevices(ClDeviceVector{deviceIds, 2}, true);
}
MockUnrestrictiveContext::MockUnrestrictiveContext() : MockContext(nullptr, nullptr) {
auto pRootDevice = ultClDeviceFactory.rootDevices[0];
auto pSubDevice0 = ultClDeviceFactory.subDevices[0];
auto pSubDevice1 = ultClDeviceFactory.subDevices[1];
cl_device_id deviceIds[] = {pRootDevice, pSubDevice0, pSubDevice1};
initializeWithDevices(ClDeviceVector{deviceIds, 3}, true);
}
} // namespace NEO } // namespace NEO

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "opencl/source/context/context.h" #include "opencl/source/context/context.h"
#include "opencl/source/sharings/sharing_factory.h" #include "opencl/source/sharings/sharing_factory.h"
#include "opencl/test/unit_test/mocks/ult_cl_device_factory.h"
#include <memory> #include <memory>
@ -23,7 +24,7 @@ class MockContext : public Context {
using Context::preferD3dSharedResources; using Context::preferD3dSharedResources;
using Context::sharingFunctions; using Context::sharingFunctions;
using Context::svmAllocsManager; using Context::svmAllocsManager;
MockContext(ClDevice *device, bool noSpecialQueue = false); MockContext(ClDevice *pDevice, bool noSpecialQueue = false);
MockContext( MockContext(
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *), void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
void *data); void *data);
@ -37,7 +38,37 @@ class MockContext : public Context {
void registerSharingWithId(SharingFunctions *sharing, SharingType sharingId); void registerSharingWithId(SharingFunctions *sharing, SharingType sharingId);
std::unique_ptr<AsyncEventsHandler> &getAsyncEventsHandlerUniquePtr(); std::unique_ptr<AsyncEventsHandler> &getAsyncEventsHandlerUniquePtr();
protected:
void initializeWithDevices(const ClDeviceVector &devices, bool noSpecialQueue);
private: private:
ClDevice *device = nullptr; ClDevice *pDevice = nullptr;
}; };
struct MockDefaultContext : MockContext {
MockDefaultContext();
UltClDeviceFactory ultClDeviceFactory{2, 0};
MockClDevice *pRootDevice0;
MockClDevice *pRootDevice1;
};
struct MockSpecializedContext : MockContext {
MockSpecializedContext();
UltClDeviceFactory ultClDeviceFactory{1, 2};
MockClDevice *pRootDevice;
ClDevice *pSubDevice0 = nullptr;
ClDevice *pSubDevice1 = nullptr;
};
struct MockUnrestrictiveContext : MockContext {
MockUnrestrictiveContext();
UltClDeviceFactory ultClDeviceFactory{1, 2};
MockClDevice *pRootDevice;
ClDevice *pSubDevice0 = nullptr;
ClDevice *pSubDevice1 = nullptr;
};
} // namespace NEO } // namespace NEO