Add support for ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2021-03-13 01:07:50 +00:00
committed by Compute-Runtime-Automation
parent 88a1593913
commit 6a81edfbe1
4 changed files with 239 additions and 14 deletions

View File

@@ -93,6 +93,7 @@ struct DriverHandleImp : public DriverHandle {
std::vector<Device *> devices;
// Spec extensions
const std::vector<std::pair<std::string, uint32_t>> extensionsSupported = {
{ZE_RELAXED_ALLOCATION_LIMITS_EXP_NAME, ZE_RELAXED_ALLOCATION_LIMITS_EXP_VERSION_CURRENT},
{ZE_MODULE_PROGRAM_EXP_NAME, ZE_MODULE_PROGRAM_EXP_VERSION_CURRENT},
{ZE_GLOBAL_OFFSET_EXP_NAME, ZE_GLOBAL_OFFSET_EXP_VERSION_CURRENT}};

View File

@@ -133,11 +133,8 @@ ze_result_t DriverHandleImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDe
ze_result_t DriverHandleImp::allocDeviceMem(ze_device_handle_t hDevice, const ze_device_mem_alloc_desc_t *deviceDesc,
size_t size, size_t alignment, void **ptr) {
if (size > this->devices[0]->getNEODevice()->getHardwareCapabilities().maxMemAllocSize) {
*ptr = nullptr;
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
}
bool relaxedSizeAllowed = false;
if (deviceDesc->pNext) {
const ze_base_desc_t *extendedDesc = reinterpret_cast<const ze_base_desc_t *>(deviceDesc->pNext);
if (extendedDesc->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_DESC) {
@@ -160,9 +157,22 @@ ze_result_t DriverHandleImp::allocDeviceMem(ze_device_handle_t hDevice, const ze
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
return ZE_RESULT_SUCCESS;
} else if (extendedDesc->stype == ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC) {
const ze_relaxed_allocation_limits_exp_desc_t *relaxedLimitsDesc =
reinterpret_cast<const ze_relaxed_allocation_limits_exp_desc_t *>(extendedDesc);
if (!(relaxedLimitsDesc->flags & ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE)) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
relaxedSizeAllowed = true;
}
}
if (relaxedSizeAllowed == false &&
(size > this->devices[0]->getNEODevice()->getHardwareCapabilities().maxMemAllocSize)) {
*ptr = nullptr;
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
}
auto neoDevice = Device::fromHandle(hDevice)->getNEODevice();
auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
auto deviceBitfields = this->deviceBitfields;
@@ -192,6 +202,25 @@ ze_result_t DriverHandleImp::allocSharedMem(ze_device_handle_t hDevice, const ze
size_t size,
size_t alignment,
void **ptr) {
bool relaxedSizeAllowed = false;
if (deviceDesc->pNext) {
const ze_base_desc_t *extendedDesc = reinterpret_cast<const ze_base_desc_t *>(deviceDesc->pNext);
if (extendedDesc->stype == ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC) {
const ze_relaxed_allocation_limits_exp_desc_t *relaxedLimitsDesc =
reinterpret_cast<const ze_relaxed_allocation_limits_exp_desc_t *>(extendedDesc);
if (!(relaxedLimitsDesc->flags & ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE)) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
relaxedSizeAllowed = true;
}
}
if (relaxedSizeAllowed == false &&
(size > this->devices[0]->getNEODevice()->getHardwareCapabilities().maxMemAllocSize)) {
*ptr = nullptr;
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
}
auto neoDevice = this->devices[0]->getNEODevice();
auto deviceBitfields = this->deviceBitfields;
@@ -210,11 +239,6 @@ ze_result_t DriverHandleImp::allocSharedMem(ze_device_handle_t hDevice, const ze
unifiedMemoryProperties.allocationFlags.flags.locallyUncachedResource = 1;
}
if (size > neoDevice->getDeviceInfo().maxMemAllocSize) {
*ptr = nullptr;
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
}
auto usmPtr =
svmAllocsManager->createSharedUnifiedMemoryAllocation(size,
unifiedMemoryProperties,

View File

@@ -88,6 +88,206 @@ TEST_F(MemoryTest, whenAllocatingSharedMemoryWithUncachedFlagThenLocallyUncached
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
}
struct SVMAllocsManagerRelaxedSizeMock : public NEO::SVMAllocsManager {
SVMAllocsManagerRelaxedSizeMock(MemoryManager *memoryManager) : NEO::SVMAllocsManager(memoryManager, false) {}
void *createUnifiedMemoryAllocation(size_t size,
const UnifiedMemoryProperties &svmProperties) override {
return alignedMalloc(4096u, 4096u);
}
void *createSharedUnifiedMemoryAllocation(size_t size,
const UnifiedMemoryProperties &svmProperties,
void *cmdQ) override {
return alignedMalloc(4096u, 4096u);
}
};
struct DriverHandleRelaxedSizeMock : public DriverHandleImp {
ze_result_t freeMem(const void *ptr) override {
alignedFree(const_cast<void *>(ptr));
return ZE_RESULT_SUCCESS;
}
};
struct MemoryRelaxedSizeTests : public ::testing::Test {
void SetUp() override {
neoDevice =
NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
auto mockBuiltIns = new MockBuiltins();
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleRelaxedSizeMock>();
driverHandle->initialize(std::move(devices));
prevSvmAllocsManager = driverHandle->svmAllocsManager;
currSvmAllocsManager = new SVMAllocsManagerRelaxedSizeMock(driverHandle->memoryManager);
driverHandle->svmAllocsManager = currSvmAllocsManager;
device = driverHandle->devices[0];
}
void TearDown() override {
driverHandle->svmAllocsManager = prevSvmAllocsManager;
delete currSvmAllocsManager;
}
NEO::SVMAllocsManager *prevSvmAllocsManager;
NEO::SVMAllocsManager *currSvmAllocsManager;
std::unique_ptr<DriverHandleRelaxedSizeMock> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
};
TEST_F(MemoryRelaxedSizeTests,
givenCallToDeviceAllocWithAllowedSizeAndWithoutRelaxedFlagThenAllocationIsMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize - 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_result_t result = driverHandle->allocDeviceMem(device->toHandle(),
&deviceDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
result = driverHandle->freeMem(ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToDeviceAllocWithLargerThanAllowdSizeAndWithoutRelaxedFlagThenAllocationIsNotMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_result_t result = driverHandle->allocDeviceMem(device->toHandle(),
&deviceDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_SIZE, result);
EXPECT_EQ(nullptr, ptr);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToDeviceAllocWithLargerThanAllowdSizeAndRelaxedFlagThenAllocationIsMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
ze_relaxed_allocation_limits_exp_desc_t relaxedSizeDesc = {};
relaxedSizeDesc.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC;
relaxedSizeDesc.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE;
deviceDesc.pNext = &relaxedSizeDesc;
ze_result_t result = driverHandle->allocDeviceMem(device->toHandle(),
&deviceDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
result = driverHandle->freeMem(ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToDeviceAllocWithLargerThanAllowdSizeAndRelaxedFlagWithIncorrectFlagThenAllocationIsNotMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
ze_relaxed_allocation_limits_exp_desc_t relaxedSizeDesc = {};
relaxedSizeDesc.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC;
relaxedSizeDesc.flags = static_cast<ze_relaxed_allocation_limits_exp_flag_t>(ZE_BIT(1));
deviceDesc.pNext = &relaxedSizeDesc;
ze_result_t result = driverHandle->allocDeviceMem(device->toHandle(),
&deviceDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
EXPECT_EQ(nullptr, ptr);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToSharedAllocWithAllowedSizeAndWithoutRelaxedFlagThenAllocationIsMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize - 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
ze_result_t result = driverHandle->allocSharedMem(device->toHandle(),
&deviceDesc,
&hostDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
result = driverHandle->freeMem(ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToSharedAllocWithLargerThanAllowedSizeAndWithoutRelaxedFlagThenAllocationIsNotMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
ze_result_t result = driverHandle->allocSharedMem(device->toHandle(),
&deviceDesc,
&hostDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_SIZE, result);
EXPECT_EQ(nullptr, ptr);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToSharedAllocWithLargerThanAllowdSizeAndRelaxedFlagThenAllocationIsMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
ze_relaxed_allocation_limits_exp_desc_t relaxedSizeDesc = {};
relaxedSizeDesc.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC;
relaxedSizeDesc.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE;
deviceDesc.pNext = &relaxedSizeDesc;
ze_host_mem_alloc_desc_t hostDesc = {};
ze_result_t result = driverHandle->allocSharedMem(device->toHandle(),
&deviceDesc,
&hostDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, ptr);
result = driverHandle->freeMem(ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(MemoryRelaxedSizeTests,
givenCallToSharedAllocWithLargerThanAllowdSizeAndRelaxedFlagWithIncorrectFlagThenAllocationIsNotMade) {
size_t size = device->getNEODevice()->getHardwareCapabilities().maxMemAllocSize + 1;
size_t alignment = 1u;
void *ptr = nullptr;
ze_device_mem_alloc_desc_t deviceDesc = {};
deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
ze_relaxed_allocation_limits_exp_desc_t relaxedSizeDesc = {};
relaxedSizeDesc.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC;
relaxedSizeDesc.flags = static_cast<ze_relaxed_allocation_limits_exp_flag_t>(ZE_BIT(1));
deviceDesc.pNext = &relaxedSizeDesc;
ze_host_mem_alloc_desc_t hostDesc = {};
ze_result_t result = driverHandle->allocSharedMem(device->toHandle(),
&deviceDesc,
&hostDesc,
size, alignment, &ptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
EXPECT_EQ(nullptr, ptr);
}
struct DriverHandleGetFdMock : public DriverHandleImp {
void *importFdHandle(ze_device_handle_t hDevice, uint64_t handle) override {
if (mockFd == allocationMap.second) {