Context implementation (3/N)

Add object creators.

Change-Id: Ic656a1bd3735bce1d995c407011ef7c26eab848e
Signed-off: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2020-07-22 10:40:20 -07:00
parent a6d4cb1a21
commit 63a801ee07
14 changed files with 427 additions and 0 deletions

View File

@@ -52,6 +52,22 @@ struct Context : _ze_context_handle_t {
virtual ze_result_t getMemAllocProperties(const void *ptr,
ze_memory_allocation_properties_t *pMemAllocProperties,
ze_device_handle_t *phDevice) = 0;
virtual ze_result_t createModule(ze_device_handle_t hDevice,
const ze_module_desc_t *desc,
ze_module_handle_t *phModule,
ze_module_build_log_handle_t *phBuildLog) = 0;
virtual ze_result_t createSampler(ze_device_handle_t hDevice,
const ze_sampler_desc_t *pDesc,
ze_sampler_handle_t *phSampler) = 0;
virtual ze_result_t createCommandQueue(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_queue_handle_t *commandQueue) = 0;
virtual ze_result_t createCommandList(ze_device_handle_t hDevice,
const ze_command_list_desc_t *desc,
ze_command_list_handle_t *commandList) = 0;
virtual ze_result_t createCommandListImmediate(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_list_handle_t *commandList) = 0;
static Context *fromHandle(ze_context_handle_t handle) { return static_cast<Context *>(handle); }
inline ze_context_handle_t toHandle() { return this; }

View File

@@ -7,6 +7,8 @@
#include "level_zero/core/source/context/context_imp.h"
#include "level_zero/core/source/device/device.h"
namespace L0 {
ze_result_t ContextImp::destroy() {
@@ -111,4 +113,35 @@ ze_result_t ContextImp::getMemAllocProperties(const void *ptr,
phDevice);
}
ze_result_t ContextImp::createModule(ze_device_handle_t hDevice,
const ze_module_desc_t *desc,
ze_module_handle_t *phModule,
ze_module_build_log_handle_t *phBuildLog) {
return L0::Device::fromHandle(hDevice)->createModule(desc, phModule, phBuildLog);
}
ze_result_t ContextImp::createSampler(ze_device_handle_t hDevice,
const ze_sampler_desc_t *pDesc,
ze_sampler_handle_t *phSampler) {
return L0::Device::fromHandle(hDevice)->createSampler(pDesc, phSampler);
}
ze_result_t ContextImp::createCommandQueue(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_queue_handle_t *commandQueue) {
return L0::Device::fromHandle(hDevice)->createCommandQueue(desc, commandQueue);
}
ze_result_t ContextImp::createCommandList(ze_device_handle_t hDevice,
const ze_command_list_desc_t *desc,
ze_command_list_handle_t *commandList) {
return L0::Device::fromHandle(hDevice)->createCommandList(desc, commandList);
}
ze_result_t ContextImp::createCommandListImmediate(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_list_handle_t *commandList) {
return L0::Device::fromHandle(hDevice)->createCommandListImmediate(desc, commandList);
}
} // namespace L0

View File

@@ -46,6 +46,22 @@ struct ContextImp : Context {
ze_result_t getMemAllocProperties(const void *ptr,
ze_memory_allocation_properties_t *pMemAllocProperties,
ze_device_handle_t *phDevice) override;
ze_result_t createModule(ze_device_handle_t hDevice,
const ze_module_desc_t *desc,
ze_module_handle_t *phModule,
ze_module_build_log_handle_t *phBuildLog) override;
ze_result_t createSampler(ze_device_handle_t hDevice,
const ze_sampler_desc_t *pDesc,
ze_sampler_handle_t *phSampler) override;
ze_result_t createCommandQueue(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_queue_handle_t *commandQueue) override;
ze_result_t createCommandList(ze_device_handle_t hDevice,
const ze_command_list_desc_t *desc,
ze_command_list_handle_t *commandList) override;
ze_result_t createCommandListImmediate(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_list_handle_t *commandList) override;
protected:
DriverHandle *driverHandle = nullptr;

View File

@@ -8,6 +8,7 @@
#pragma once
#include "level_zero/core/source/cmdlist/cmdlist.h"
#include "level_zero/core/source/context/context.h"
#include "level_zero/core/source/kernel/kernel.h"
#include "level_zero/core/source/module/module_build_log.h"
#include <level_zero/ze_api.h>

View File

@@ -93,6 +93,37 @@ struct Mock<Context> : public Context {
ze_ipc_memory_flags_t flags,
void **ptr),
(override));
MOCK_METHOD(ze_result_t,
createModule,
(ze_device_handle_t hDevice,
const ze_module_desc_t *desc,
ze_module_handle_t *phModule,
ze_module_build_log_handle_t *phBuildLog),
(override));
MOCK_METHOD(ze_result_t,
createSampler,
(ze_device_handle_t hDevice,
const ze_sampler_desc_t *pDesc,
ze_sampler_handle_t *phSampler),
(override));
MOCK_METHOD(ze_result_t,
createCommandQueue,
(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_queue_handle_t *commandQueue),
(override));
MOCK_METHOD(ze_result_t,
createCommandList,
(ze_device_handle_t hDevice,
const ze_command_list_desc_t *desc,
ze_command_list_handle_t *commandList),
(override));
MOCK_METHOD(ze_result_t,
createCommandListImmediate,
(ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc,
ze_command_list_handle_t *commandList),
(override));
};
} // namespace ult

View File

@@ -14,6 +14,7 @@
#include "test.h"
#include "level_zero/core/source/builtin/builtin_functions_lib_impl.h"
#include "level_zero/core/source/context/context.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/image/image_hw.h"
#include "level_zero/core/source/kernel/kernel_imp.h"
@@ -25,6 +26,31 @@
namespace L0 {
namespace ult {
using ContextCommandListCreate = Test<ContextFixture>;
TEST_F(ContextCommandListCreate, whenCreatingCommandListFromContextThenSuccessIsReturned) {
ze_command_list_desc_t desc = {};
ze_command_list_handle_t hCommandList = {};
ze_result_t result = context->createCommandList(device, &desc, &hCommandList);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
L0::CommandList *commandList = L0::CommandList::fromHandle(hCommandList);
commandList->destroy();
}
TEST_F(ContextCommandListCreate, whenCreatingCommandListImmediateFromContextThenSuccessIsReturned) {
ze_command_queue_desc_t desc = {};
ze_command_list_handle_t hCommandList = {};
ze_result_t result = context->createCommandListImmediate(device, &desc, &hCommandList);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
L0::CommandList *commandList = L0::CommandList::fromHandle(hCommandList);
commandList->destroy();
}
using CommandListCreate = Test<DeviceFixture>;
TEST(zeCommandListCreateImmediate, redirectsToObject) {

View File

@@ -13,6 +13,7 @@
#include "test.h"
#include "level_zero/core/source/context/context.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h"
@@ -420,5 +421,21 @@ HWTEST_F(CommandQueueIndirectAllocations, givenCommandQueueWhenExecutingCommandL
commandQueue->destroy();
}
using ContextCreateCommandQueueTest = Test<ContextFixture>;
TEST_F(ContextCreateCommandQueueTest, givenCallToContextCreateCommandQueueThenCallSucceeds) {
ze_command_queue_desc_t desc = {};
desc.version = ZE_COMMAND_QUEUE_DESC_VERSION_CURRENT;
desc.ordinal = 0u;
ze_command_queue_handle_t commandQueue = {};
ze_result_t res = context->createCommandQueue(device, &desc, &commandQueue);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_NE(nullptr, commandQueue);
L0::CommandQueue::fromHandle(commandQueue)->destroy();
}
} // namespace ult
} // namespace L0

View File

@@ -9,8 +9,10 @@
#include "test.h"
#include "level_zero/core/source/context/context.h"
#include "level_zero/core/source/kernel/kernel_imp.h"
#include "level_zero/core/source/module/module_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_module.h"
@@ -283,5 +285,32 @@ HWTEST_F(MultiDeviceModuleSetArgBufferTest,
}
}
using ContextModuleCreateTest = Test<ContextFixture>;
HWTEST_F(ContextModuleCreateTest, givenCallToCreateModuleThenModuleIsReturned) {
std::string testFile;
retrieveBinaryKernelFilename(testFile, "test_kernel_", ".bin");
size_t size = 0;
auto src = loadDataFromFile(testFile.c_str(), size);
ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
ze_module_desc_t moduleDesc = {ZE_MODULE_DESC_VERSION_CURRENT};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
ze_module_handle_t hModule;
ze_device_handle_t hDevice = device->toHandle();
ze_result_t res = context->createModule(hDevice, &moduleDesc, &hModule, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::Module *pModule = L0::Module::fromHandle(hModule);
res = pModule->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
} // namespace ult
} // namespace L0

View File

@@ -151,5 +151,28 @@ INSTANTIATE_TEST_CASE_P(SamplerDescCombinations, SamplerCreateTest,
samplerFilterMode,
samplerIsNormalized));
using ContextCreateSamplerTest = Test<ContextFixture>;
HWTEST2_F(ContextCreateSamplerTest, givenDifferentDescriptorValuesThenSamplerIsCorrectlyCreated, SamplerCreateSupport) {
ze_sampler_address_mode_t addressMode = ZE_SAMPLER_ADDRESS_MODE_NONE;
ze_sampler_filter_mode_t filterMode = ZE_SAMPLER_FILTER_MODE_LINEAR;
ze_bool_t isNormalized = false;
ze_sampler_desc_t desc = {};
desc.version = ZE_SAMPLER_DESC_VERSION_CURRENT;
desc.addressMode = addressMode;
desc.filterMode = filterMode;
desc.isNormalized = isNormalized;
ze_sampler_handle_t hSampler;
ze_result_t res = context->createSampler(device, &desc, &hSampler);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
auto sampler = reinterpret_cast<L0::SamplerImp *>(L0::Sampler::fromHandle(hSampler));
EXPECT_NE(nullptr, sampler);
sampler->destroy();
}
} // namespace ult
} // namespace L0