mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-11 16:45:25 +08:00
Move methods from DriverHandle to Device
allocateMemoryFromHostPtr allocateManagedMemoryFromHostPtr add mock driver handle Related-To: NEO-3691 Change-Id: Iee8a167e248871b3b5fc495bd79b3b5654fb1bbc Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
a7e4ad4eba
commit
c294747979
@@ -720,7 +720,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopyRegion(void *d
|
||||
bool hostPointerNeedsFlush = false;
|
||||
bool dstAllocFound = device->getDriverHandle()->findAllocationDataForRange(alignedDstPtr, dstSize, &allocData);
|
||||
if (dstAllocFound == false) {
|
||||
auto dstAlloc = device->getDriverHandle()->allocateManagedMemoryFromHostPtr(device, alignedDstPtr, dstSize, this);
|
||||
auto dstAlloc = device->allocateManagedMemoryFromHostPtr(alignedDstPtr, dstSize, this);
|
||||
commandContainer.getDeallocationContainer().push_back(dstAlloc);
|
||||
hostPointerNeedsFlush = true;
|
||||
} else {
|
||||
@@ -733,7 +733,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopyRegion(void *d
|
||||
bool srcAllocFound = device->getDriverHandle()->findAllocationDataForRange(alignedSrcPtr,
|
||||
srcSize, nullptr);
|
||||
if (srcAllocFound == false) {
|
||||
auto srcAlloc = device->getDriverHandle()->allocateManagedMemoryFromHostPtr(device, alignedSrcPtr, dstSize, this);
|
||||
auto srcAlloc = device->allocateManagedMemoryFromHostPtr(alignedSrcPtr, dstSize, this);
|
||||
commandContainer.getDeallocationContainer().push_back(srcAlloc);
|
||||
}
|
||||
|
||||
@@ -937,9 +937,8 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryFill(void *ptr,
|
||||
} else {
|
||||
builtinFunction = device->getBuiltinFunctionsLib()->getFunction(Builtin::FillBufferSSHOffset);
|
||||
|
||||
auto patternAlloc = device->getDriverHandle()->allocateManagedMemoryFromHostPtr(device,
|
||||
reinterpret_cast<void *>(srcPtr),
|
||||
srcOffset + patternSize, this);
|
||||
auto patternAlloc = device->allocateManagedMemoryFromHostPtr(reinterpret_cast<void *>(srcPtr),
|
||||
srcOffset + patternSize, this);
|
||||
if (patternAlloc == nullptr) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
@@ -1047,7 +1046,7 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
|
||||
bool hostPointerNeedsFlush = false;
|
||||
|
||||
if (srcAllocFound == false) {
|
||||
alloc = device->getDriverHandle()->allocateMemoryFromHostPtr(device, buffer, bufferSize);
|
||||
alloc = device->allocateMemoryFromHostPtr(buffer, bufferSize);
|
||||
hostPtrMap.insert(std::make_pair(buffer, alloc));
|
||||
|
||||
alignedPtr = static_cast<uintptr_t>(alloc->getGpuAddress() - offset);
|
||||
|
||||
@@ -116,6 +116,11 @@ struct Device : _ze_device_handle_t {
|
||||
return getNEODevice() ? reinterpret_cast<NEO::SourceLevelDebugger *>(getNEODevice()->getDebugger()) : nullptr;
|
||||
}
|
||||
virtual NEO::GraphicsAllocation *getDebugSurface() const = 0;
|
||||
|
||||
virtual NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(void *buffer,
|
||||
size_t size, struct CommandList *commandList) = 0;
|
||||
|
||||
virtual NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size) = 0;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -462,8 +462,8 @@ ze_result_t DeviceImp::registerCLMemory(cl_context context, cl_mem mem, void **p
|
||||
NEO::GraphicsAllocation *graphicsAllocation = memObj->getGraphicsAllocation();
|
||||
DEBUG_BREAK_IF(graphicsAllocation == nullptr);
|
||||
|
||||
auto allocation = getDriverHandle()->allocateManagedMemoryFromHostPtr(
|
||||
this, graphicsAllocation->getUnderlyingBuffer(),
|
||||
auto allocation = allocateManagedMemoryFromHostPtr(
|
||||
graphicsAllocation->getUnderlyingBuffer(),
|
||||
graphicsAllocation->getUnderlyingBufferSize(), nullptr);
|
||||
|
||||
*ptr = allocation->getUnderlyingBuffer();
|
||||
@@ -622,4 +622,74 @@ const NEO::DeviceInfo &DeviceImp::getDeviceInfo() const {
|
||||
NEO::Device *DeviceImp::getNEODevice() {
|
||||
return neoDevice;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *DeviceImp::allocateManagedMemoryFromHostPtr(void *buffer, size_t size, struct CommandList *commandList) {
|
||||
char *baseAddress = reinterpret_cast<char *>(buffer);
|
||||
NEO::GraphicsAllocation *allocation = nullptr;
|
||||
bool allocFound = false;
|
||||
std::vector<NEO::SvmAllocationData *> allocDataArray = driverHandle->findAllocationsWithinRange(buffer, size, &allocFound);
|
||||
if (allocFound) {
|
||||
return allocDataArray[0]->gpuAllocation;
|
||||
}
|
||||
|
||||
if (!allocDataArray.empty()) {
|
||||
UNRECOVERABLE_IF(commandList == nullptr);
|
||||
for (auto allocData : allocDataArray) {
|
||||
allocation = allocData->gpuAllocation;
|
||||
char *allocAddress = reinterpret_cast<char *>(allocation->getGpuAddress());
|
||||
size_t allocSize = allocData->size;
|
||||
|
||||
driverHandle->getSvmAllocsManager()->getSVMAllocs()->remove(*allocData);
|
||||
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
|
||||
commandList->eraseDeallocationContainerEntry(allocation);
|
||||
commandList->eraseResidencyContainerEntry(allocation);
|
||||
|
||||
if (allocAddress < baseAddress) {
|
||||
buffer = reinterpret_cast<void *>(allocAddress);
|
||||
baseAddress += size;
|
||||
size = ptrDiff(baseAddress, allocAddress);
|
||||
baseAddress = reinterpret_cast<char *>(buffer);
|
||||
} else {
|
||||
allocAddress += allocSize;
|
||||
baseAddress += size;
|
||||
if (allocAddress > baseAddress) {
|
||||
baseAddress = reinterpret_cast<char *>(buffer);
|
||||
size = ptrDiff(allocAddress, baseAddress);
|
||||
} else {
|
||||
baseAddress = reinterpret_cast<char *>(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allocation = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
|
||||
{getRootDeviceIndex(), false, size, NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, false},
|
||||
buffer);
|
||||
|
||||
if (allocation == nullptr) {
|
||||
return allocation;
|
||||
}
|
||||
|
||||
NEO::SvmAllocationData allocData;
|
||||
allocData.gpuAllocation = allocation;
|
||||
allocData.cpuAllocation = nullptr;
|
||||
allocData.size = size;
|
||||
allocData.memoryType = InternalMemoryType::NOT_SPECIFIED;
|
||||
allocData.device = nullptr;
|
||||
driverHandle->getSvmAllocsManager()->getSVMAllocs()->insert(allocData);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *DeviceImp::allocateMemoryFromHostPtr(const void *buffer, size_t size) {
|
||||
NEO::AllocationProperties properties = {getRootDeviceIndex(), false, size, NEO::GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, false};
|
||||
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
|
||||
auto allocation = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties,
|
||||
buffer);
|
||||
|
||||
UNRECOVERABLE_IF(allocation == nullptr);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -80,6 +80,8 @@ struct DeviceImp : public Device {
|
||||
NEO::GraphicsAllocation *getDebugSurface() const override { return debugSurface; }
|
||||
void setDebugSurface(NEO::GraphicsAllocation *debugSurface) { this->debugSurface = debugSurface; };
|
||||
~DeviceImp() override;
|
||||
NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(void *buffer, size_t size, struct CommandList *commandList) override;
|
||||
NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size) override;
|
||||
|
||||
NEO::Device *neoDevice = nullptr;
|
||||
bool isSubdevice = false;
|
||||
|
||||
@@ -51,9 +51,6 @@ struct DriverHandle : _ze_driver_handle_t {
|
||||
ze_event_pool_handle_t *phEventPool) = 0;
|
||||
virtual ze_result_t openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc, ze_event_pool_handle_t *phEventPool) = 0;
|
||||
virtual ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) = 0;
|
||||
virtual NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(Device *device, void *buffer,
|
||||
size_t size, struct CommandList *commandList) = 0;
|
||||
virtual NEO::GraphicsAllocation *allocateMemoryFromHostPtr(Device *device, const void *buffer, size_t size) = 0;
|
||||
virtual bool findAllocationDataForRange(const void *buffer,
|
||||
size_t size,
|
||||
NEO::SvmAllocationData **allocData) = 0;
|
||||
|
||||
@@ -213,76 +213,6 @@ std::vector<NEO::SvmAllocationData *> DriverHandleImp::findAllocationsWithinRang
|
||||
return allocDataArray;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *DriverHandleImp::allocateManagedMemoryFromHostPtr(Device *device, void *buffer,
|
||||
size_t size, struct CommandList *commandList) {
|
||||
char *baseAddress = reinterpret_cast<char *>(buffer);
|
||||
NEO::GraphicsAllocation *allocation = nullptr;
|
||||
bool allocFound = false;
|
||||
std::vector<NEO::SvmAllocationData *> allocDataArray = findAllocationsWithinRange(buffer, size, &allocFound);
|
||||
if (allocFound) {
|
||||
return allocDataArray[0]->gpuAllocation;
|
||||
}
|
||||
|
||||
if (!allocDataArray.empty()) {
|
||||
UNRECOVERABLE_IF(commandList == nullptr);
|
||||
for (auto allocData : allocDataArray) {
|
||||
allocation = allocData->gpuAllocation;
|
||||
char *allocAddress = reinterpret_cast<char *>(allocation->getGpuAddress());
|
||||
size_t allocSize = allocData->size;
|
||||
|
||||
device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->remove(*allocData);
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
commandList->eraseDeallocationContainerEntry(allocation);
|
||||
commandList->eraseResidencyContainerEntry(allocation);
|
||||
|
||||
if (allocAddress < baseAddress) {
|
||||
buffer = reinterpret_cast<void *>(allocAddress);
|
||||
baseAddress += size;
|
||||
size = ptrDiff(baseAddress, allocAddress);
|
||||
baseAddress = reinterpret_cast<char *>(buffer);
|
||||
} else {
|
||||
allocAddress += allocSize;
|
||||
baseAddress += size;
|
||||
if (allocAddress > baseAddress) {
|
||||
baseAddress = reinterpret_cast<char *>(buffer);
|
||||
size = ptrDiff(allocAddress, baseAddress);
|
||||
} else {
|
||||
baseAddress = reinterpret_cast<char *>(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allocation = memoryManager->allocateGraphicsMemoryWithProperties(
|
||||
{0u, false, size, NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, false},
|
||||
buffer);
|
||||
|
||||
if (allocation == nullptr) {
|
||||
return allocation;
|
||||
}
|
||||
|
||||
NEO::SvmAllocationData allocData;
|
||||
allocData.gpuAllocation = allocation;
|
||||
allocData.cpuAllocation = nullptr;
|
||||
allocData.size = size;
|
||||
allocData.memoryType = InternalMemoryType::NOT_SPECIFIED;
|
||||
allocData.device = nullptr;
|
||||
svmAllocsManager->getSVMAllocs()->insert(allocData);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *DriverHandleImp::allocateMemoryFromHostPtr(Device *device, const void *buffer, size_t size) {
|
||||
NEO::AllocationProperties properties = {0u, false, size, NEO::GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, false};
|
||||
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
|
||||
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties,
|
||||
buffer);
|
||||
|
||||
UNRECOVERABLE_IF(allocation == nullptr);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::createEventPool(const ze_event_pool_desc_t *desc,
|
||||
uint32_t numDevices,
|
||||
ze_device_handle_t *phDevices,
|
||||
|
||||
@@ -50,9 +50,6 @@ struct DriverHandleImp : public DriverHandle {
|
||||
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
|
||||
NEO::SVMAllocsManager *getSvmAllocsManager() override;
|
||||
ze_result_t initialize(std::vector<std::unique_ptr<NEO::Device>> devices);
|
||||
NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(Device *device, void *buffer,
|
||||
size_t size, struct CommandList *commandList) override;
|
||||
NEO::GraphicsAllocation *allocateMemoryFromHostPtr(Device *device, const void *buffer, size_t size) override;
|
||||
bool findAllocationDataForRange(const void *buffer,
|
||||
size_t size,
|
||||
NEO::SvmAllocationData **allocData) override;
|
||||
|
||||
@@ -16,6 +16,8 @@ set(L0_MOCKS_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.cpp
|
||||
)
|
||||
|
||||
@@ -109,6 +109,8 @@ struct Mock<Device> : public Device {
|
||||
MOCK_METHOD0(getNEODevice, NEO::Device *());
|
||||
MOCK_METHOD0(activateMetricGroups, void());
|
||||
MOCK_CONST_METHOD0(getDebugSurface, NEO::GraphicsAllocation *());
|
||||
MOCK_METHOD3(allocateManagedMemoryFromHostPtr, NEO::GraphicsAllocation *(void *buffer, size_t size, struct L0::CommandList *commandList));
|
||||
MOCK_METHOD2(allocateMemoryFromHostPtr, NEO::GraphicsAllocation *(const void *buffer, size_t size));
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
107
level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp
Normal file
107
level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mock_driver_handle.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using MockDriverHandle = Mock<L0::ult::DriverHandle>;
|
||||
using namespace testing;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Return;
|
||||
|
||||
Mock<DriverHandle>::Mock() {
|
||||
EXPECT_CALL(*this, getDevice)
|
||||
.WillRepeatedly(testing::Invoke(this, &MockDriverHandle::doGetDevice));
|
||||
EXPECT_CALL(*this, getMemoryManager)
|
||||
.WillRepeatedly(Invoke(this, &MockDriverHandle::doGetMemoryManager));
|
||||
EXPECT_CALL(*this, getSvmAllocsManager)
|
||||
.WillRepeatedly(Invoke(this, &MockDriverHandle::doGetSvmAllocManager));
|
||||
EXPECT_CALL(*this, allocHostMem)
|
||||
.WillRepeatedly(Invoke(this, &MockDriverHandle::doAllocHostMem));
|
||||
EXPECT_CALL(*this, allocDeviceMem)
|
||||
.WillRepeatedly(Invoke(this, &MockDriverHandle::doAllocDeviceMem));
|
||||
EXPECT_CALL(*this, freeMem)
|
||||
.WillRepeatedly(Invoke(this, &MockDriverHandle::doFreeMem));
|
||||
};
|
||||
|
||||
NEO::MemoryManager *Mock<DriverHandle>::doGetMemoryManager() {
|
||||
return memoryManager;
|
||||
}
|
||||
|
||||
NEO::SVMAllocsManager *Mock<DriverHandle>::doGetSvmAllocManager() {
|
||||
return svmAllocsManager;
|
||||
}
|
||||
|
||||
ze_result_t Mock<DriverHandle>::doGetDevice(uint32_t *pCount, ze_device_handle_t *phDevices) {
|
||||
if (*pCount == 0) { // User wants to know number of devices
|
||||
*pCount = this->num_devices;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
if (phDevices == nullptr) // User is expected to allocate space
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
phDevices[0] = &this->device;
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t Mock<DriverHandle>::doAllocHostMem(ze_host_mem_alloc_flag_t flags, size_t size, size_t alignment,
|
||||
void **ptr) {
|
||||
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY);
|
||||
|
||||
auto allocation = svmAllocsManager->createUnifiedMemoryAllocation(0u, size, unifiedMemoryProperties);
|
||||
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
*ptr = allocation;
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t Mock<DriverHandle>::doAllocDeviceMem(ze_device_handle_t hDevice, ze_device_mem_alloc_flag_t flags, size_t size, size_t alignment, void **ptr) {
|
||||
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY);
|
||||
|
||||
auto allocation = svmAllocsManager->createUnifiedMemoryAllocation(0u, size, unifiedMemoryProperties);
|
||||
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
|
||||
*ptr = allocation;
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t Mock<DriverHandle>::doFreeMem(const void *ptr) {
|
||||
auto allocation = svmAllocsManager->getSVMAllocs()->get(ptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
svmAllocsManager->freeSVMAlloc(const_cast<void *>(ptr));
|
||||
if (svmAllocsManager->getSvmMapOperation(ptr)) {
|
||||
svmAllocsManager->removeSvmMapOperation(ptr);
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void Mock<DriverHandle>::setupDevices(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
|
||||
this->numDevices = static_cast<uint32_t>(neoDevices.size());
|
||||
for (auto &neoDevice : neoDevices) {
|
||||
auto device = Device::create(this, neoDevice.release());
|
||||
this->devices.push_back(device);
|
||||
}
|
||||
}
|
||||
|
||||
Mock<DriverHandle>::~Mock(){};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
76
level_zero/core/test/unit_tests/mocks/mock_driver_handle.h
Normal file
76
level_zero/core/test/unit_tests/mocks/mock_driver_handle.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
#endif
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <>
|
||||
struct WhiteBox<::L0::DriverHandleImp> : public ::L0::DriverHandleImp {
|
||||
};
|
||||
|
||||
using DriverHandle = WhiteBox<::L0::DriverHandleImp>;
|
||||
|
||||
template <>
|
||||
struct Mock<DriverHandle> : public DriverHandleImp {
|
||||
Mock();
|
||||
~Mock() override;
|
||||
|
||||
MOCK_METHOD2(getDevice, ze_result_t(uint32_t *pCount, ze_device_handle_t *phDevices));
|
||||
MOCK_METHOD1(getProperties, ze_result_t(ze_driver_properties_t *properties));
|
||||
MOCK_METHOD1(getApiVersion, ze_result_t(ze_api_version_t *version));
|
||||
MOCK_METHOD1(getIPCProperties, ze_result_t(ze_driver_ipc_properties_t *pIPCProperties));
|
||||
MOCK_METHOD3(getMemAllocProperties, ze_result_t(const void *ptr,
|
||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||
ze_device_handle_t *phDevice));
|
||||
|
||||
MOCK_METHOD0(getMemoryManager, NEO::MemoryManager *());
|
||||
MOCK_METHOD1(setMemoryManager, void(NEO::MemoryManager *));
|
||||
MOCK_METHOD3(getMemAddressRange, ze_result_t(const void *ptr, void **pBase, size_t *pSize));
|
||||
MOCK_METHOD2(getIpcMemHandle, ze_result_t(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle));
|
||||
MOCK_METHOD1(closeIpcMemHandle, ze_result_t(const void *ptr));
|
||||
MOCK_METHOD4(openIpcMemHandle, ze_result_t(ze_device_handle_t hDevice, ze_ipc_mem_handle_t handle,
|
||||
ze_ipc_memory_flag_t flags, void **ptr));
|
||||
MOCK_METHOD4(createEventPool, ze_result_t(const ze_event_pool_desc_t *desc,
|
||||
uint32_t numDevices,
|
||||
ze_device_handle_t *phDevices,
|
||||
ze_event_pool_handle_t *phEventPool));
|
||||
MOCK_METHOD4(allocHostMem, ze_result_t(ze_host_mem_alloc_flag_t flags, size_t size, size_t alignment, void **ptr));
|
||||
MOCK_METHOD5(allocDeviceMem, ze_result_t(ze_device_handle_t hDevice, ze_device_mem_alloc_flag_t flags, size_t size, size_t alignment, void **ptr));
|
||||
MOCK_METHOD1(freeMem, ze_result_t(const void *ptr));
|
||||
|
||||
MOCK_METHOD0(getSvmAllocsManager, NEO::SVMAllocsManager *());
|
||||
uint32_t num_devices = 1;
|
||||
Mock<Device> device;
|
||||
|
||||
void setupDevices(std::vector<std::unique_ptr<NEO::Device>> devices);
|
||||
|
||||
ze_result_t doFreeMem(const void *ptr);
|
||||
ze_result_t doGetDevice(uint32_t *pCount, ze_device_handle_t *phDevices);
|
||||
NEO::MemoryManager *doGetMemoryManager();
|
||||
NEO::SVMAllocsManager *doGetSvmAllocManager();
|
||||
ze_result_t doAllocHostMem(ze_host_mem_alloc_flag_t flags, size_t size, size_t alignment, void **ptr);
|
||||
ze_result_t doAllocDeviceMem(ze_device_handle_t hDevice, ze_device_mem_alloc_flag_t flags, size_t size, size_t alignment, void **ptr);
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_device.cpp
|
||||
)
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_device.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
struct DeviceTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), rootDeviceIndex);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
}
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
|
||||
NEO::Device *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
const uint32_t rootDeviceIndex = 1u;
|
||||
const uint32_t numRootDevices = 2u;
|
||||
};
|
||||
|
||||
TEST_F(DeviceTest, givenEmptySVmAllocStorageWhenAllocateManagedMemoryFromHostPtrThenBufferHostAllocationIsCreated) {
|
||||
int data;
|
||||
auto allocation = device->allocateManagedMemoryFromHostPtr(&data, sizeof(data), nullptr);
|
||||
EXPECT_NE(nullptr, allocation);
|
||||
EXPECT_EQ(NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, allocation->getAllocationType());
|
||||
EXPECT_EQ(rootDeviceIndex, allocation->getRootDeviceIndex());
|
||||
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DeviceTest, givenEmptySVmAllocStorageWhenAllocateMemoryFromHostPtrThenValidExternalHostPtrAllocationIsCreated) {
|
||||
DebugManager.flags.EnableHostPtrTracking.set(0);
|
||||
constexpr auto dataSize = 1024u;
|
||||
auto data = std::make_unique<int[]>(dataSize);
|
||||
|
||||
constexpr auto allocationSize = sizeof(int) * dataSize;
|
||||
|
||||
auto allocation = device->allocateMemoryFromHostPtr(data.get(), allocationSize);
|
||||
EXPECT_NE(nullptr, allocation);
|
||||
EXPECT_EQ(NEO::GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, allocation->getAllocationType());
|
||||
EXPECT_EQ(rootDeviceIndex, allocation->getRootDeviceIndex());
|
||||
|
||||
auto alignedPtr = alignDown(data.get(), MemoryConstants::pageSize);
|
||||
auto offsetInPage = ptrDiff(data.get(), alignedPtr);
|
||||
|
||||
EXPECT_EQ(allocation->getAllocationOffset(), offsetInPage);
|
||||
EXPECT_EQ(allocation->getUnderlyingBufferSize(), allocationSize);
|
||||
EXPECT_EQ(allocation->isFlushL3Required(), true);
|
||||
|
||||
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user