2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-03 17:01:43 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-17 20:03:37 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/device_binary_format/patchtokens_decoder.h"
|
|
|
|
#include "shared/source/helpers/basic_math.h"
|
2023-02-02 22:25:08 +08:00
|
|
|
#include "shared/source/helpers/compiler_product_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/file_io.h"
|
|
|
|
#include "shared/source/helpers/hash.h"
|
|
|
|
#include "shared/source/memory_manager/surface.h"
|
2021-04-07 07:52:24 +08:00
|
|
|
#include "shared/source/memory_manager/unified_memory_manager.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2023-08-03 01:33:48 +08:00
|
|
|
#include "shared/source/pin/pin.h"
|
2022-08-08 23:09:46 +08:00
|
|
|
#include "shared/test/common/device_binary_format/patchtokens_tests.h"
|
2021-10-21 22:50:10 +08:00
|
|
|
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
2021-04-07 07:52:24 +08:00
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
2021-10-06 19:43:42 +08:00
|
|
|
#include "shared/test/common/helpers/kernel_binary_helper.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/test_files.h"
|
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2022-08-17 18:17:02 +08:00
|
|
|
#include "shared/test/common/mocks/mock_cpu_page_fault_manager.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
2023-08-03 01:33:48 +08:00
|
|
|
#include "shared/test/common/mocks/mock_io_functions.h"
|
2021-10-05 20:54:33 +08:00
|
|
|
#include "shared/test/common/mocks/mock_memory_manager.h"
|
2023-03-07 18:41:07 +08:00
|
|
|
#include "shared/test/common/mocks/mock_modules_zebin.h"
|
2023-08-03 01:33:48 +08:00
|
|
|
#include "shared/test/common/mocks/mock_os_library.h"
|
2022-06-30 03:17:47 +08:00
|
|
|
#include "shared/test/common/test_macros/hw_test.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/api/api.h"
|
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
#include "opencl/source/gtpin/gtpin_defs.h"
|
2023-01-24 22:29:15 +08:00
|
|
|
#include "opencl/source/gtpin/gtpin_gfx_core_helper.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/gtpin/gtpin_helpers.h"
|
|
|
|
#include "opencl/source/gtpin/gtpin_init.h"
|
|
|
|
#include "opencl/source/gtpin/gtpin_notify.h"
|
2021-10-13 02:58:51 +08:00
|
|
|
#include "opencl/source/helpers/cl_validators.h"
|
2023-01-12 01:04:14 +08:00
|
|
|
#include "opencl/source/helpers/task_information.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
|
|
|
#include "opencl/source/program/create.inl"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/context_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/fixtures/platform_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_buffer.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_kernel.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
|
|
|
#include "opencl/test/unit_test/program/program_tests.h"
|
2020-08-27 22:11:44 +08:00
|
|
|
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
#include <deque>
|
|
|
|
#include <vector>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
using namespace gtpin;
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-02-08 23:00:20 +08:00
|
|
|
extern std::deque<gtpinkexec_t> kernelExecQueue;
|
2023-02-02 21:55:54 +08:00
|
|
|
extern GTPinGfxCoreHelperCreateFunctionType gtpinGfxCoreHelperFactory[IGFX_MAX_CORE];
|
2021-04-07 07:52:24 +08:00
|
|
|
} // namespace NEO
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
namespace ULT {
|
|
|
|
|
2018-01-03 17:54:31 +08:00
|
|
|
int ContextCreateCallbackCount = 0;
|
|
|
|
int ContextDestroyCallbackCount = 0;
|
2018-01-24 20:26:46 +08:00
|
|
|
int KernelCreateCallbackCount = 0;
|
2018-02-08 23:00:20 +08:00
|
|
|
int KernelSubmitCallbackCount = 0;
|
|
|
|
int CommandBufferCreateCallbackCount = 0;
|
|
|
|
int CommandBufferCompleteCallbackCount = 0;
|
2018-06-04 15:09:04 +08:00
|
|
|
uint32_t kernelOffset = 0;
|
2018-05-28 14:32:47 +08:00
|
|
|
bool returnNullResource = false;
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
context_handle_t currContext = nullptr;
|
|
|
|
|
|
|
|
std::deque<resource_handle_t> kernelResources;
|
2020-02-24 21:35:50 +08:00
|
|
|
platform_info_t platformInfo;
|
2018-01-03 17:54:31 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
void onContextCreate(context_handle_t context, platform_info_t *platformInfo, igc_init_t **igcInit) {
|
2020-02-24 21:35:50 +08:00
|
|
|
ULT::platformInfo.gen_version = platformInfo->gen_version;
|
2018-02-08 23:00:20 +08:00
|
|
|
currContext = context;
|
|
|
|
kernelResources.clear();
|
2018-01-03 17:54:31 +08:00
|
|
|
ContextCreateCallbackCount++;
|
2018-08-06 19:19:32 +08:00
|
|
|
*igcInit = reinterpret_cast<igc_init_t *>(0x1234);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
void onContextDestroy(context_handle_t context) {
|
2018-02-08 23:00:20 +08:00
|
|
|
currContext = nullptr;
|
|
|
|
EXPECT_EQ(0u, kernelResources.size());
|
|
|
|
kernelResources.clear();
|
2018-01-03 17:54:31 +08:00
|
|
|
ContextDestroyCallbackCount++;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
void onKernelCreate(context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) {
|
2018-01-24 20:26:46 +08:00
|
|
|
paramsOut->inst_kernel_binary = const_cast<uint8_t *>(paramsIn->orig_kernel_binary);
|
|
|
|
paramsOut->inst_kernel_size = paramsIn->orig_kernel_size;
|
|
|
|
paramsOut->kernel_id = paramsIn->igc_hash_id;
|
|
|
|
KernelCreateCallbackCount++;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
void onKernelSubmit(command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {
|
2018-02-08 23:00:20 +08:00
|
|
|
resource_handle_t currResource = nullptr;
|
|
|
|
ASSERT_NE(nullptr, currContext);
|
2018-05-28 14:32:47 +08:00
|
|
|
if (!returnNullResource) {
|
|
|
|
GTPIN_DI_STATUS st = gtpinCreateBuffer(currContext, (uint32_t)256, &currResource);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, st);
|
|
|
|
EXPECT_NE(nullptr, currResource);
|
|
|
|
|
|
|
|
uint8_t *bufAddress = nullptr;
|
|
|
|
st = gtpinMapBuffer(currContext, currResource, &bufAddress);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, st);
|
|
|
|
EXPECT_NE(nullptr, bufAddress);
|
|
|
|
}
|
2018-06-04 15:09:04 +08:00
|
|
|
*entryOffset = kernelOffset;
|
2018-02-08 23:00:20 +08:00
|
|
|
*resource = currResource;
|
|
|
|
kernelResources.push_back(currResource);
|
|
|
|
|
|
|
|
KernelSubmitCallbackCount++;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
void onCommandBufferCreate(context_handle_t context, command_buffer_handle_t cb) {
|
2018-02-08 23:00:20 +08:00
|
|
|
CommandBufferCreateCallbackCount++;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
void onCommandBufferComplete(command_buffer_handle_t cb) {
|
2018-02-08 23:00:20 +08:00
|
|
|
ASSERT_NE(nullptr, currContext);
|
|
|
|
resource_handle_t currResource = kernelResources[0];
|
|
|
|
EXPECT_NE(nullptr, currResource);
|
|
|
|
GTPIN_DI_STATUS st = gtpinUnmapBuffer(currContext, currResource);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, st);
|
|
|
|
|
|
|
|
st = gtpinFreeBuffer(currContext, currResource);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, st);
|
|
|
|
kernelResources.pop_front();
|
|
|
|
|
|
|
|
CommandBufferCompleteCallbackCount++;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-07-18 15:48:21 +08:00
|
|
|
|
|
|
|
class MockMemoryManagerWithFailures : public OsAgnosticMemoryManager {
|
|
|
|
public:
|
2021-07-14 21:54:25 +08:00
|
|
|
using OsAgnosticMemoryManager::pageFaultManager;
|
2019-03-15 17:22:35 +08:00
|
|
|
MockMemoryManagerWithFailures(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(executionEnvironment){};
|
2018-07-18 15:48:21 +08:00
|
|
|
|
2018-12-06 22:03:06 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override {
|
|
|
|
if (failAllAllocationsInDevicePool) {
|
|
|
|
failAllAllocationsInDevicePool = false;
|
2018-07-18 15:48:21 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-12-06 22:03:06 +08:00
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
|
2018-07-18 15:48:21 +08:00
|
|
|
}
|
2018-12-06 22:03:06 +08:00
|
|
|
bool failAllAllocationsInDevicePool = false;
|
2018-07-18 15:48:21 +08:00
|
|
|
};
|
2021-07-14 21:54:25 +08:00
|
|
|
struct MockResidentTestsPageFaultManager : public MockPageFaultManager {
|
|
|
|
void moveAllocationToGpuDomain(void *ptr) override {
|
|
|
|
moveAllocationToGpuDomainCalledTimes++;
|
|
|
|
migratedAddress = ptr;
|
|
|
|
}
|
|
|
|
uint32_t moveAllocationToGpuDomainCalledTimes = 0;
|
|
|
|
void *migratedAddress = nullptr;
|
|
|
|
};
|
2018-07-18 15:48:21 +08:00
|
|
|
|
2017-12-29 17:53:39 +08:00
|
|
|
class GTPinFixture : public ContextFixture, public MemoryManagementFixture {
|
2022-08-16 22:51:17 +08:00
|
|
|
using ContextFixture::setUp;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
public:
|
2022-08-12 22:24:49 +08:00
|
|
|
void setUp() {
|
2021-04-07 07:52:24 +08:00
|
|
|
DebugManager.flags.GTPinAllocateBufferInSharedMemory.set(false);
|
2022-05-10 01:40:30 +08:00
|
|
|
setUpImpl();
|
2021-04-07 07:52:24 +08:00
|
|
|
}
|
|
|
|
|
2022-05-10 01:40:30 +08:00
|
|
|
void setUpImpl() {
|
2020-09-01 18:38:50 +08:00
|
|
|
platformsImpl->clear();
|
2022-08-12 22:24:49 +08:00
|
|
|
MemoryManagementFixture::setUp();
|
2018-06-26 22:15:48 +08:00
|
|
|
constructPlatform();
|
2017-12-21 07:45:38 +08:00
|
|
|
pPlatform = platform();
|
2018-10-01 22:10:54 +08:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
2019-11-15 16:59:48 +08:00
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
2023-01-03 18:27:35 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get());
|
2022-06-08 16:23:02 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
|
2018-10-01 22:10:54 +08:00
|
|
|
memoryManager = new MockMemoryManagerWithFailures(*executionEnvironment);
|
2021-07-14 21:54:25 +08:00
|
|
|
memoryManager->pageFaultManager.reset(new MockResidentTestsPageFaultManager());
|
2018-07-16 22:37:17 +08:00
|
|
|
executionEnvironment->memoryManager.reset(memoryManager);
|
2020-02-15 00:36:30 +08:00
|
|
|
initPlatform();
|
2020-01-14 21:32:11 +08:00
|
|
|
pDevice = pPlatform->getClDevice(0);
|
2020-11-24 02:01:38 +08:00
|
|
|
rootDeviceIndex = pDevice->getRootDeviceIndex();
|
|
|
|
cl_device_id device = pDevice;
|
2022-08-16 22:51:17 +08:00
|
|
|
ContextFixture::setUp(1, &device);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
driverServices.bufferAllocate = nullptr;
|
|
|
|
driverServices.bufferDeallocate = nullptr;
|
|
|
|
driverServices.bufferMap = nullptr;
|
|
|
|
driverServices.bufferUnMap = nullptr;
|
|
|
|
|
|
|
|
gtpinCallbacks.onContextCreate = nullptr;
|
|
|
|
gtpinCallbacks.onContextDestroy = nullptr;
|
|
|
|
gtpinCallbacks.onKernelCreate = nullptr;
|
|
|
|
gtpinCallbacks.onKernelSubmit = nullptr;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = nullptr;
|
2018-01-12 22:00:36 +08:00
|
|
|
gtpinCallbacks.onCommandBufferComplete = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
NEO::isGTPinInitialized = false;
|
2018-06-04 15:09:04 +08:00
|
|
|
kernelOffset = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-08-12 22:24:49 +08:00
|
|
|
void tearDown() {
|
2022-08-16 22:51:17 +08:00
|
|
|
ContextFixture::tearDown();
|
2020-09-01 18:38:50 +08:00
|
|
|
platformsImpl->clear();
|
2022-08-12 22:24:49 +08:00
|
|
|
MemoryManagementFixture::tearDown();
|
2019-03-26 18:59:46 +08:00
|
|
|
NEO::isGTPinInitialized = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Platform *pPlatform = nullptr;
|
2020-01-14 21:32:11 +08:00
|
|
|
ClDevice *pDevice = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
GTPIN_DI_STATUS retFromGtPin = GTPIN_DI_SUCCESS;
|
|
|
|
driver_services_t driverServices;
|
2018-01-12 22:00:36 +08:00
|
|
|
gtpin::ocl::gtpin_events_t gtpinCallbacks;
|
2018-07-18 15:48:21 +08:00
|
|
|
MockMemoryManagerWithFailures *memoryManager = nullptr;
|
2020-11-24 02:01:38 +08:00
|
|
|
uint32_t rootDeviceIndex = std::numeric_limits<uint32_t>::max();
|
2021-04-07 07:52:24 +08:00
|
|
|
DebugManagerStateRestore restore;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2022-08-12 22:24:49 +08:00
|
|
|
typedef Test<GTPinFixture> GTPinTests;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInvalidArgumentsThenGTPinInitFails) {
|
2018-02-08 23:00:20 +08:00
|
|
|
bool isInitialized = false;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(nullptr, nullptr, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2018-02-08 23:00:20 +08:00
|
|
|
isInitialized = gtpinIsGTPinInitialized();
|
|
|
|
EXPECT_FALSE(isInitialized);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, nullptr, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2018-02-08 23:00:20 +08:00
|
|
|
isInitialized = gtpinIsGTPinInitialized();
|
|
|
|
EXPECT_FALSE(isInitialized);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(nullptr, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2018-02-08 23:00:20 +08:00
|
|
|
isInitialized = gtpinIsGTPinInitialized();
|
|
|
|
EXPECT_FALSE(isInitialized);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenIncompleteArgumentsThenGTPinInitFails) {
|
2018-08-06 19:19:32 +08:00
|
|
|
interface_version_t ver;
|
|
|
|
ver.common = 0;
|
|
|
|
ver.specific = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, &ver);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INVALID_ARGUMENT, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInvalidArgumentsWhenVersionArgumentIsProvidedThenGTPinInitReturnsDriverVersion) {
|
2018-08-06 19:19:32 +08:00
|
|
|
interface_version_t ver;
|
|
|
|
ver.common = 0;
|
|
|
|
ver.specific = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(nullptr, nullptr, &ver);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2018-08-06 19:19:32 +08:00
|
|
|
EXPECT_EQ(gtpin::ocl::GTPIN_OCL_INTERFACE_VERSION, ver.specific);
|
|
|
|
EXPECT_EQ(gtpin::GTPIN_COMMON_INTERFACE_VERSION, ver.common);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, nullptr, &ver);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2018-08-06 19:19:32 +08:00
|
|
|
EXPECT_EQ(gtpin::ocl::GTPIN_OCL_INTERFACE_VERSION, ver.specific);
|
|
|
|
EXPECT_EQ(gtpin::GTPIN_COMMON_INTERFACE_VERSION, ver.common);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(nullptr, &driverServices, &ver);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2018-08-06 19:19:32 +08:00
|
|
|
EXPECT_EQ(gtpin::ocl::GTPIN_OCL_INTERFACE_VERSION, ver.specific);
|
|
|
|
EXPECT_EQ(gtpin::GTPIN_COMMON_INTERFACE_VERSION, ver.common);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenValidAndCompleteArgumentsThenGTPinInitSucceeds) {
|
2018-02-08 23:00:20 +08:00
|
|
|
bool isInitialized = false;
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
EXPECT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2018-02-08 23:00:20 +08:00
|
|
|
isInitialized = gtpinIsGTPinInitialized();
|
|
|
|
EXPECT_TRUE(isInitialized);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenValidAndCompleteArgumentsWhenGTPinIsAlreadyInitializedThenGTPinInitFails) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
EXPECT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_INSTANCE_ALREADY_CREATED, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInvalidArgumentsThenBufferAllocateFails) {
|
|
|
|
resource_handle_t res;
|
2017-12-29 17:53:39 +08:00
|
|
|
uint32_t buffSize = 400u;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
ASSERT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)(nullptr, buffSize, &res);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)((gtpin::context_handle_t)ctxt, buffSize, nullptr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInvalidArgumentsThenBufferDeallocateFails) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
EXPECT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-29 17:53:39 +08:00
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)(nullptr, nullptr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, nullptr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, (gtpin::resource_handle_t)ctxt);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInvalidArgumentsThenBufferMapFails) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
EXPECT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-29 17:53:39 +08:00
|
|
|
|
|
|
|
uint8_t *mappedPtr;
|
|
|
|
retFromGtPin = (*driverServices.bufferMap)(nullptr, nullptr, &mappedPtr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
retFromGtPin = (*driverServices.bufferMap)((gtpin::context_handle_t)ctxt, nullptr, &mappedPtr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferMap)((gtpin::context_handle_t)ctxt, (gtpin::resource_handle_t)ctxt, &mappedPtr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInvalidArgumentsThenBufferUnMapFails) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
EXPECT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
ASSERT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-29 17:53:39 +08:00
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferUnMap)(nullptr, nullptr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
retFromGtPin = (*driverServices.bufferUnMap)((gtpin::context_handle_t)ctxt, nullptr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferUnMap)((gtpin::context_handle_t)ctxt, (gtpin::resource_handle_t)ctxt);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenValidRequestForHugeMemoryAllocationThenBufferAllocateFails) {
|
2017-12-29 17:53:39 +08:00
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
for (auto &allocationInUSMShared : ::testing::Bool()) {
|
|
|
|
DebugManager.flags.GTPinAllocateBufferInSharedMemory.set(allocationInUSMShared);
|
|
|
|
InjectedFunction allocBufferFunc = [this](size_t failureIndex) {
|
|
|
|
resource_handle_t res;
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
uint32_t hugeSize = 400u; // Will be handled as huge memory allocation
|
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)((gtpin::context_handle_t)ctxt, hugeSize, &res);
|
|
|
|
if (MemoryManagement::nonfailingAllocation != failureIndex) {
|
|
|
|
EXPECT_EQ(GTPIN_DI_ERROR_ALLOCATION_FAILED, retFromGtPin);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, res);
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
isGTPinInitialized = false;
|
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
ASSERT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
|
|
|
|
|
|
|
injectFailures(allocBufferFunc);
|
|
|
|
}
|
2017-12-29 17:53:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenValidRequestForMemoryAllocationThenBufferAllocateAndDeallocateSucceeds) {
|
2017-12-21 07:45:38 +08:00
|
|
|
resource_handle_t res;
|
2017-12-29 17:53:39 +08:00
|
|
|
uint32_t buffSize = 400u;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
ASSERT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
EXPECT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-29 17:53:39 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)((gtpin::context_handle_t)ctxt, buffSize, &res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, res);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2017-12-29 17:53:39 +08:00
|
|
|
TEST_F(GTPinTests, givenValidArgumentsForBufferMapWhenCallSequenceIsCorrectThenBufferMapSucceeds) {
|
2017-12-21 07:45:38 +08:00
|
|
|
resource_handle_t res;
|
2017-12-29 17:53:39 +08:00
|
|
|
uint32_t buffSize = 400u;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-21 07:45:38 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
2017-12-29 17:53:39 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
ASSERT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)((gtpin::context_handle_t)ctxt, buffSize, &res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, res);
|
|
|
|
|
|
|
|
uint8_t *mappedPtr = nullptr;
|
|
|
|
retFromGtPin = (*driverServices.bufferMap)((gtpin::context_handle_t)ctxt, res, &mappedPtr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, mappedPtr);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenMissingReturnArgumentForBufferMapWhenCallSequenceIsCorrectThenBufferMapFails) {
|
|
|
|
resource_handle_t res;
|
|
|
|
uint32_t buffSize = 400u;
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
ASSERT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
EXPECT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-29 17:53:39 +08:00
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)((gtpin::context_handle_t)ctxt, buffSize, &res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, res);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferMap)((gtpin::context_handle_t)ctxt, res, nullptr);
|
|
|
|
EXPECT_NE(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenValidArgumentsForBufferUnMapWhenCallSequenceIsCorrectThenBufferUnMapSucceeds) {
|
|
|
|
resource_handle_t res;
|
|
|
|
uint32_t buffSize = 400u;
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2019-03-26 18:59:46 +08:00
|
|
|
ASSERT_EQ(&NEO::gtpinCreateBuffer, driverServices.bufferAllocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinFreeBuffer, driverServices.bufferDeallocate);
|
|
|
|
ASSERT_EQ(&NEO::gtpinMapBuffer, driverServices.bufferMap);
|
|
|
|
ASSERT_EQ(&NEO::gtpinUnmapBuffer, driverServices.bufferUnMap);
|
2017-12-29 17:53:39 +08:00
|
|
|
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
retFromGtPin = (*driverServices.bufferAllocate)((gtpin::context_handle_t)ctxt, buffSize, &res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, res);
|
|
|
|
|
|
|
|
uint8_t *mappedPtr = nullptr;
|
|
|
|
retFromGtPin = (*driverServices.bufferMap)((gtpin::context_handle_t)ctxt, res, &mappedPtr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
EXPECT_NE(nullptr, mappedPtr);
|
|
|
|
|
|
|
|
retFromGtPin = (*driverServices.bufferUnMap)((gtpin::context_handle_t)ctxt, res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2017-12-29 17:53:39 +08:00
|
|
|
retFromGtPin = (*driverServices.bufferDeallocate)((gtpin::context_handle_t)ctxt, res);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-03 17:54:31 +08:00
|
|
|
TEST_F(GTPinTests, givenUninitializedGTPinInterfaceThenGTPinContextCallbackIsNotCalled) {
|
|
|
|
int prevCount = ContextCreateCallbackCount;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
auto context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(ContextCreateCallbackCount, prevCount);
|
|
|
|
|
|
|
|
prevCount = ContextDestroyCallbackCount;
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(ContextDestroyCallbackCount, prevCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenContextCreationArgumentsAreInvalidThenGTPinContextCallbackIsNotCalled) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-01-03 17:54:31 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
int prevCount = ContextCreateCallbackCount;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0};
|
2018-01-10 16:36:06 +08:00
|
|
|
auto context = clCreateContext(invalidProperties, 1, &device, nullptr, nullptr, &retVal);
|
2018-01-03 17:54:31 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_PLATFORM, retVal);
|
2018-01-10 16:36:06 +08:00
|
|
|
EXPECT_EQ(nullptr, context);
|
2018-01-03 17:54:31 +08:00
|
|
|
EXPECT_EQ(ContextCreateCallbackCount, prevCount);
|
|
|
|
|
2018-01-10 16:36:06 +08:00
|
|
|
context = clCreateContextFromType(invalidProperties, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal);
|
2018-01-03 17:54:31 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_PLATFORM, retVal);
|
2018-01-10 16:36:06 +08:00
|
|
|
EXPECT_EQ(nullptr, context);
|
2018-01-03 17:54:31 +08:00
|
|
|
EXPECT_EQ(ContextCreateCallbackCount, prevCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceThenGTPinContextCallbackIsCalled) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-01-03 17:54:31 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
int prevCount = ContextCreateCallbackCount;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
auto context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(ContextCreateCallbackCount, prevCount + 1);
|
|
|
|
|
|
|
|
prevCount = ContextDestroyCallbackCount;
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(ContextDestroyCallbackCount, prevCount + 1);
|
|
|
|
|
|
|
|
prevCount = ContextCreateCallbackCount;
|
|
|
|
context = clCreateContextFromType(nullptr, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(ContextCreateCallbackCount, prevCount + 1);
|
|
|
|
|
|
|
|
prevCount = ContextDestroyCallbackCount;
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(ContextDestroyCallbackCount, prevCount + 1);
|
|
|
|
}
|
|
|
|
|
2018-01-24 20:26:46 +08:00
|
|
|
TEST_F(GTPinTests, givenUninitializedGTPinInterfaceThenGTPinKernelCreateCallbackIsNotCalled) {
|
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-01-24 20:26:46 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-01-24 20:26:46 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-01-24 20:26:46 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
(cl_context)((Context *)pContext),
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-01-24 20:26:46 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount = KernelCreateCallbackCount;
|
|
|
|
kernel = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount, KernelCreateCallbackCount);
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
// Cleanup
|
2018-01-24 20:26:46 +08:00
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2020-02-24 21:35:50 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenContextIsCreatedThenCorrectVersionIsSet) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2020-02-24 21:35:50 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_device_id device = static_cast<cl_device_id>(pDevice);
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2020-02-24 21:35:50 +08:00
|
|
|
EXPECT_EQ(ULT::platformInfo.gen_version, static_cast<gtpin::GTPIN_GEN_VERSION>(gtpinHelper.getGenVersion()));
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelIsExecutedThenGTPinCallbacksAreCalled) {
|
2022-08-18 22:11:45 +08:00
|
|
|
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-01-24 20:26:46 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
cl_kernel kernel1 = nullptr;
|
|
|
|
cl_kernel kernel2 = nullptr;
|
2018-01-24 20:26:46 +08:00
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
2018-02-08 23:00:20 +08:00
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
2018-01-24 20:26:46 +08:00
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-01-24 20:26:46 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-01-24 20:26:46 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-01-24 20:26:46 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
2018-02-08 23:00:20 +08:00
|
|
|
context,
|
2018-01-24 20:26:46 +08:00
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-01-24 20:26:46 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
// Create and submit first instance of "CopyBuffer" kernel
|
|
|
|
int prevCount11 = KernelCreateCallbackCount;
|
|
|
|
kernel1 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount11 + 1, KernelCreateCallbackCount);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel1 = static_cast<MultiDeviceKernel *>(kernel1);
|
|
|
|
Kernel *pKernel1 = pMultiDeviceKernel1->getKernel(rootDeviceIndex);
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &kInfo1 = pKernel1->getKernelInfo();
|
|
|
|
uint64_t gtpinKernelId1 = pKernel1->getKernelId();
|
2020-05-26 15:36:04 +08:00
|
|
|
EXPECT_EQ(kInfo1.shaderHashCode, gtpinKernelId1);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
constexpr size_t n = 256;
|
|
|
|
auto buff10 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
auto buff11 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel1, 0, sizeof(cl_mem), &buff10);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel1, 1, sizeof(cl_mem), &buff11);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount12 = KernelSubmitCallbackCount;
|
|
|
|
int prevCount13 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount14 = CommandBufferCompleteCallbackCount;
|
|
|
|
cl_uint workDim = 1;
|
|
|
|
size_t globalWorkOffset[3] = {0, 0, 0};
|
|
|
|
size_t globalWorkSize[3] = {n, 1, 1};
|
|
|
|
size_t localWorkSize[3] = {1, 1, 1};
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clEnqueueNDRangeKernel(cmdQ, pMultiDeviceKernel1, workDim, globalWorkOffset, globalWorkSize, localWorkSize, 0, nullptr, nullptr);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount12 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount13 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
|
|
|
|
// Create and submit second instance of "CopyBuffer" kernel
|
|
|
|
int prevCount21 = KernelCreateCallbackCount;
|
|
|
|
kernel2 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
// Verify that GT-Pin Kernel Create callback is not called multiple times for the same kernel
|
|
|
|
EXPECT_EQ(prevCount21, KernelCreateCallbackCount);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel2 = static_cast<MultiDeviceKernel *>(kernel2);
|
|
|
|
Kernel *pKernel2 = pMultiDeviceKernel2->getKernel(rootDeviceIndex);
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &kInfo2 = pKernel2->getKernelInfo();
|
|
|
|
uint64_t gtpinKernelId2 = pKernel2->getKernelId();
|
2020-05-26 15:36:04 +08:00
|
|
|
EXPECT_EQ(kInfo2.shaderHashCode, gtpinKernelId2);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
auto buff20 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
auto buff21 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel2, 0, sizeof(cl_mem), &buff20);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel2, 1, sizeof(cl_mem), &buff21);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount22 = KernelSubmitCallbackCount;
|
|
|
|
int prevCount23 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount24 = CommandBufferCompleteCallbackCount;
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clEnqueueNDRangeKernel(cmdQ, pMultiDeviceKernel2, workDim, globalWorkOffset, globalWorkSize, localWorkSize, 0, nullptr, nullptr);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount22 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount23 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
|
|
|
|
retVal = clFinish(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(prevCount14 + 2, CommandBufferCompleteCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount24 + 2, CommandBufferCompleteCallbackCount);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
retVal = clReleaseKernel(kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseKernel(kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
pSource.reset();
|
|
|
|
|
|
|
|
retVal = clReleaseMemObject(buff10);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff11);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff20);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff21);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelINTELIsExecutedThenGTPinCallbacksAreCalled) {
|
2022-08-18 22:11:45 +08:00
|
|
|
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2019-11-19 23:54:47 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_kernel kernel1 = nullptr;
|
|
|
|
cl_kernel kernel2 = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2019-11-19 23:54:47 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-11-19 23:54:47 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
const char *sources[1] = {pSource.get()};
|
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
|
|
|
sources,
|
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Create and submit first instance of "CopyBuffer" kernel
|
|
|
|
int prevCount11 = KernelCreateCallbackCount;
|
|
|
|
kernel1 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount11 + 1, KernelCreateCallbackCount);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel1 = static_cast<MultiDeviceKernel *>(kernel1);
|
|
|
|
Kernel *pKernel1 = pMultiDeviceKernel1->getKernel(rootDeviceIndex);
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &kInfo1 = pKernel1->getKernelInfo();
|
|
|
|
uint64_t gtpinKernelId1 = pKernel1->getKernelId();
|
2020-05-26 15:36:04 +08:00
|
|
|
EXPECT_EQ(kInfo1.shaderHashCode, gtpinKernelId1);
|
2019-11-19 23:54:47 +08:00
|
|
|
|
|
|
|
cl_uint workDim = 1;
|
|
|
|
size_t localWorkSize[3] = {1, 1, 1};
|
2020-10-06 22:21:46 +08:00
|
|
|
CommandQueue *commandQueue = nullptr;
|
2022-05-16 22:06:56 +08:00
|
|
|
withCastToInternal(cmdQ, &commandQueue);
|
2021-08-17 02:24:13 +08:00
|
|
|
size_t n = 100;
|
2019-11-19 23:54:47 +08:00
|
|
|
auto buff10 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
auto buff11 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel1, 0, sizeof(cl_mem), &buff10);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel1, 1, sizeof(cl_mem), &buff11);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount12 = KernelSubmitCallbackCount;
|
|
|
|
int prevCount13 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount14 = CommandBufferCompleteCallbackCount;
|
|
|
|
size_t globalWorkOffset[3] = {0, 0, 0};
|
|
|
|
size_t workgroupCount[3] = {n, 1, 1};
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clEnqueueNDCountKernelINTEL(cmdQ, pMultiDeviceKernel1, workDim, globalWorkOffset, workgroupCount, localWorkSize, 0, nullptr, nullptr);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount12 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount13 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
|
|
|
|
// Create and submit second instance of "CopyBuffer" kernel
|
|
|
|
int prevCount21 = KernelCreateCallbackCount;
|
|
|
|
kernel2 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
// Verify that GT-Pin Kernel Create callback is not called multiple times for the same kernel
|
|
|
|
EXPECT_EQ(prevCount21, KernelCreateCallbackCount);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel2 = static_cast<MultiDeviceKernel *>(kernel2);
|
|
|
|
Kernel *pKernel2 = pMultiDeviceKernel2->getKernel(rootDeviceIndex);
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &kInfo2 = pKernel2->getKernelInfo();
|
|
|
|
uint64_t gtpinKernelId2 = pKernel2->getKernelId();
|
2020-05-26 15:36:04 +08:00
|
|
|
EXPECT_EQ(kInfo2.shaderHashCode, gtpinKernelId2);
|
2019-11-19 23:54:47 +08:00
|
|
|
|
|
|
|
auto buff20 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
auto buff21 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel2, 0, sizeof(cl_mem), &buff20);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel2, 1, sizeof(cl_mem), &buff21);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount22 = KernelSubmitCallbackCount;
|
|
|
|
int prevCount23 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount24 = CommandBufferCompleteCallbackCount;
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clEnqueueNDCountKernelINTEL(cmdQ, pMultiDeviceKernel2, workDim, globalWorkOffset, workgroupCount, localWorkSize, 0, nullptr, nullptr);
|
2019-11-19 23:54:47 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount22 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount23 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
|
|
|
|
retVal = clFinish(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(prevCount14 + 2, CommandBufferCompleteCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount24 + 2, CommandBufferCompleteCallbackCount);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
retVal = clReleaseKernel(kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseKernel(kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
pSource.reset();
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
retVal = clReleaseMemObject(buff10);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff11);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff20);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff21);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenTheSameKerneIsExecutedTwiceThenGTPinCreateKernelCallbackIsCalledOnce) {
|
2022-08-18 22:11:45 +08:00
|
|
|
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-02-08 23:00:20 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_kernel kernel1 = nullptr;
|
|
|
|
cl_kernel kernel2 = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-02-08 23:00:20 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-02-08 23:00:20 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-02-08 23:00:20 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Kernel "CopyBuffer" - called for the first time
|
|
|
|
int prevCount11 = KernelCreateCallbackCount;
|
|
|
|
kernel1 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount11 + 1, KernelCreateCallbackCount);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel1 = static_cast<MultiDeviceKernel *>(kernel1);
|
|
|
|
Kernel *pKernel1 = pMultiDeviceKernel1->getKernel(rootDeviceIndex);
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &kInfo1 = pKernel1->getKernelInfo();
|
|
|
|
uint64_t gtpinKernelId1 = pKernel1->getKernelId();
|
2020-05-26 15:36:04 +08:00
|
|
|
EXPECT_EQ(kInfo1.shaderHashCode, gtpinKernelId1);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
constexpr size_t n = 256;
|
|
|
|
auto buff10 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
auto buff11 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel1, 0, sizeof(cl_mem), &buff10);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel1, 1, sizeof(cl_mem), &buff11);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
cl_event userEvent = clCreateUserEvent(context, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount12 = KernelSubmitCallbackCount;
|
|
|
|
int prevCount13 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount14 = CommandBufferCompleteCallbackCount;
|
|
|
|
cl_uint workDim = 1;
|
|
|
|
size_t globalWorkOffset[3] = {0, 0, 0};
|
|
|
|
size_t globalWorkSize[3] = {n, 1, 1};
|
|
|
|
size_t localWorkSize[3] = {1, 1, 1};
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clEnqueueNDRangeKernel(cmdQ, pMultiDeviceKernel1, workDim, globalWorkOffset, globalWorkSize, localWorkSize, 1, &userEvent, nullptr);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount12 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount13 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount14, CommandBufferCompleteCallbackCount);
|
|
|
|
|
|
|
|
// The same kernel "CopyBuffer" - called second time
|
|
|
|
int prevCount21 = KernelCreateCallbackCount;
|
|
|
|
kernel2 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
// Verify that Kernel Create callback was not called now
|
|
|
|
EXPECT_EQ(prevCount21, KernelCreateCallbackCount);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel2 = static_cast<MultiDeviceKernel *>(kernel2);
|
|
|
|
Kernel *pKernel2 = pMultiDeviceKernel2->getKernel(rootDeviceIndex);
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &kInfo2 = pKernel2->getKernelInfo();
|
|
|
|
uint64_t gtpinKernelId2 = pKernel2->getKernelId();
|
2020-05-26 15:36:04 +08:00
|
|
|
EXPECT_EQ(kInfo2.shaderHashCode, gtpinKernelId2);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
auto buff20 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
auto buff21 = clCreateBuffer(context, 0, n * sizeof(unsigned int), nullptr, nullptr);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel2, 0, sizeof(cl_mem), &buff20);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clSetKernelArg(pMultiDeviceKernel2, 1, sizeof(cl_mem), &buff21);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
int prevCount22 = KernelSubmitCallbackCount;
|
|
|
|
int prevCount23 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount24 = CommandBufferCompleteCallbackCount;
|
|
|
|
EXPECT_EQ(prevCount14, prevCount24);
|
2021-03-09 18:30:21 +08:00
|
|
|
retVal = clEnqueueNDRangeKernel(cmdQ, pMultiDeviceKernel2, workDim, globalWorkOffset, globalWorkSize, localWorkSize, 0, nullptr, nullptr);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount22 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount23 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount14, CommandBufferCompleteCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount24, CommandBufferCompleteCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount14, prevCount24);
|
|
|
|
|
|
|
|
clSetUserEventStatus(userEvent, CL_COMPLETE);
|
|
|
|
|
|
|
|
retVal = clFinish(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
// Verify that both kernel instances were completed
|
|
|
|
EXPECT_EQ(prevCount14 + 2, CommandBufferCompleteCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount24 + 2, CommandBufferCompleteCallbackCount);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
retVal = clReleaseKernel(kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseKernel(kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
pSource.reset();
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
retVal = clReleaseMemObject(buff10);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff11);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff20);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(buff21);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseEvent(userEvent);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2018-07-18 16:56:11 +08:00
|
|
|
TEST_F(GTPinTests, givenMultipleKernelSubmissionsWhenOneOfGtpinSurfacesIsNullThenOnlyNonNullSurfacesAreMadeResident) {
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-05-28 14:32:47 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
cl_kernel kernel1 = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-05-28 14:32:47 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-05-28 14:32:47 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-05-28 14:32:47 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-05-28 14:32:47 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
kernel1 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
MultiDeviceKernel *pMultiDeviceKernel1 = static_cast<MultiDeviceKernel *>(kernel1);
|
|
|
|
Kernel *pKernel1 = pMultiDeviceKernel1->getKernel(rootDeviceIndex);
|
2018-05-28 14:32:47 +08:00
|
|
|
returnNullResource = true;
|
|
|
|
|
|
|
|
auto pCmdQueue = castToObject<CommandQueue>(cmdQ);
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
gtpinNotifyKernelSubmit(pMultiDeviceKernel1, pCmdQueue);
|
2022-08-18 22:11:45 +08:00
|
|
|
|
|
|
|
ASSERT_NE(0u, kernelExecQueue.size());
|
2018-07-18 16:56:11 +08:00
|
|
|
EXPECT_EQ(nullptr, kernelExecQueue[0].gtpinResource);
|
2018-05-28 14:32:47 +08:00
|
|
|
|
2019-07-15 20:28:09 +08:00
|
|
|
CommandStreamReceiver &csr = pCmdQueue->getGpgpuCommandStreamReceiver();
|
2018-05-28 14:32:47 +08:00
|
|
|
gtpinNotifyMakeResident(pKernel1, &csr);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isResourceResident);
|
|
|
|
|
|
|
|
std::vector<Surface *> residencyVector;
|
|
|
|
gtpinNotifyUpdateResidencyList(pKernel1, &residencyVector);
|
|
|
|
EXPECT_EQ(0u, residencyVector.size());
|
|
|
|
|
2018-07-18 16:56:11 +08:00
|
|
|
returnNullResource = false;
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
gtpinNotifyKernelSubmit(pMultiDeviceKernel1, pCmdQueue);
|
2018-07-18 16:56:11 +08:00
|
|
|
EXPECT_NE(nullptr, kernelExecQueue[1].gtpinResource);
|
|
|
|
gtpinNotifyMakeResident(pKernel1, &csr);
|
|
|
|
EXPECT_TRUE(kernelExecQueue[1].isResourceResident);
|
|
|
|
cl_mem gtpinBuffer1 = kernelExecQueue[1].gtpinResource;
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
gtpinNotifyKernelSubmit(pMultiDeviceKernel1, pCmdQueue);
|
2018-07-18 16:56:11 +08:00
|
|
|
EXPECT_NE(nullptr, kernelExecQueue[2].gtpinResource);
|
|
|
|
gtpinNotifyUpdateResidencyList(pKernel1, &residencyVector);
|
|
|
|
EXPECT_EQ(1u, residencyVector.size());
|
|
|
|
EXPECT_TRUE(kernelExecQueue[2].isResourceResident);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isResourceResident);
|
|
|
|
|
|
|
|
GeneralSurface *pSurf = static_cast<GeneralSurface *>(residencyVector[0]);
|
|
|
|
delete pSurf;
|
|
|
|
residencyVector.clear();
|
|
|
|
|
|
|
|
cl_mem gtpinBuffer2 = kernelExecQueue[2].gtpinResource;
|
|
|
|
|
|
|
|
gtpinUnmapBuffer(reinterpret_cast<context_handle_t>(context), reinterpret_cast<resource_handle_t>(gtpinBuffer1));
|
|
|
|
gtpinFreeBuffer(reinterpret_cast<context_handle_t>(context), reinterpret_cast<resource_handle_t>(gtpinBuffer1));
|
|
|
|
|
|
|
|
gtpinUnmapBuffer(reinterpret_cast<context_handle_t>(context), reinterpret_cast<resource_handle_t>(gtpinBuffer2));
|
|
|
|
gtpinFreeBuffer(reinterpret_cast<context_handle_t>(context), reinterpret_cast<resource_handle_t>(gtpinBuffer2));
|
|
|
|
|
2018-05-28 14:32:47 +08:00
|
|
|
retVal = clFinish(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
returnNullResource = false;
|
|
|
|
kernelResources.clear();
|
|
|
|
retVal = clReleaseKernel(kernel1);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
pSource.reset();
|
2018-05-28 14:32:47 +08:00
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelIsCreatedThenAllKernelSubmitRelatedNotificationsAreCalled) {
|
2022-08-18 22:11:45 +08:00
|
|
|
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-02-08 23:00:20 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
kernelExecQueue.clear();
|
|
|
|
|
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-02-08 23:00:20 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-02-08 23:00:20 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-02-08 23:00:20 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Create kernel
|
|
|
|
int prevCount1 = KernelCreateCallbackCount;
|
|
|
|
kernel = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
ASSERT_NE(nullptr, kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount1 + 1, KernelCreateCallbackCount);
|
|
|
|
|
|
|
|
// Simulate that created kernel was sent for execution
|
2021-03-09 18:30:21 +08:00
|
|
|
auto pMultiDeviceKernel = castToObject<MultiDeviceKernel>(kernel);
|
|
|
|
auto pKernel = pMultiDeviceKernel->getKernel(rootDeviceIndex);
|
2018-02-08 23:00:20 +08:00
|
|
|
auto pCmdQueue = castToObject<CommandQueue>(cmdQ);
|
|
|
|
ASSERT_NE(nullptr, pKernel);
|
|
|
|
EXPECT_EQ(0u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(0u, kernelResources.size());
|
|
|
|
int prevCount2 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount3 = KernelSubmitCallbackCount;
|
|
|
|
gtpinNotifyKernelSubmit(kernel, pCmdQueue);
|
|
|
|
EXPECT_EQ(prevCount2 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount3 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(1u, kernelResources.size());
|
|
|
|
EXPECT_EQ(pKernel, kernelExecQueue[0].pKernel);
|
|
|
|
EXPECT_EQ(kernelResources[0], (resource_handle_t)kernelExecQueue[0].gtpinResource);
|
|
|
|
EXPECT_EQ(pCmdQueue, kernelExecQueue[0].pCommandQueue);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isResourceResident);
|
|
|
|
|
|
|
|
// Verify that if kernel unknown to GT-Pin is about to be flushed
|
|
|
|
// then its residency vector does not obtain GT-Pin resource
|
|
|
|
std::vector<Surface *> residencyVector;
|
|
|
|
EXPECT_EQ(0u, residencyVector.size());
|
|
|
|
gtpinNotifyUpdateResidencyList(nullptr, &residencyVector);
|
|
|
|
EXPECT_EQ(0u, residencyVector.size());
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isResourceResident);
|
|
|
|
|
|
|
|
// Verify that if kernel known to GT-Pin is about to be flushed
|
|
|
|
// then its residency vector obtains GT-Pin resource
|
|
|
|
EXPECT_EQ(0u, residencyVector.size());
|
|
|
|
gtpinNotifyUpdateResidencyList(pKernel, &residencyVector);
|
|
|
|
EXPECT_EQ(1u, residencyVector.size());
|
|
|
|
GeneralSurface *pSurf = (GeneralSurface *)residencyVector[0];
|
|
|
|
delete pSurf;
|
|
|
|
residencyVector.clear();
|
|
|
|
EXPECT_TRUE(kernelExecQueue[0].isResourceResident);
|
|
|
|
kernelExecQueue[0].isResourceResident = false;
|
|
|
|
|
|
|
|
// Create second kernel ...
|
|
|
|
cl_kernel kernel2 = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
ASSERT_NE(nullptr, kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
// ... and simulate that it was sent for execution
|
2021-03-09 18:30:21 +08:00
|
|
|
auto pMultiDeviceKernel2 = castToObject<MultiDeviceKernel>(kernel2);
|
|
|
|
auto pKernel2 = pMultiDeviceKernel2->getKernel(rootDeviceIndex);
|
2018-02-08 23:00:20 +08:00
|
|
|
ASSERT_NE(nullptr, pKernel2);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(1u, kernelResources.size());
|
|
|
|
int prevCount22 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount23 = KernelSubmitCallbackCount;
|
|
|
|
gtpinNotifyKernelSubmit(kernel2, pCmdQueue);
|
|
|
|
EXPECT_EQ(prevCount22 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount23 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(2u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(2u, kernelResources.size());
|
|
|
|
EXPECT_EQ(pKernel2, kernelExecQueue[1].pKernel);
|
|
|
|
EXPECT_EQ(kernelResources[1], (resource_handle_t)kernelExecQueue[1].gtpinResource);
|
|
|
|
EXPECT_EQ(pCmdQueue, kernelExecQueue[1].pCommandQueue);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[1].isTaskCountValid);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[1].isResourceResident);
|
|
|
|
|
|
|
|
// Verify that correct GT-Pin resource is made resident
|
|
|
|
cl_mem gtpinBuffer0 = kernelExecQueue[0].gtpinResource;
|
|
|
|
auto pBuffer0 = castToObject<Buffer>(gtpinBuffer0);
|
2020-06-09 01:17:23 +08:00
|
|
|
GraphicsAllocation *pGfxAlloc0 = pBuffer0->getGraphicsAllocation(pDevice->getRootDeviceIndex());
|
2018-02-08 23:00:20 +08:00
|
|
|
cl_mem gtpinBuffer1 = kernelExecQueue[1].gtpinResource;
|
|
|
|
auto pBuffer1 = castToObject<Buffer>(gtpinBuffer1);
|
2020-06-09 01:17:23 +08:00
|
|
|
GraphicsAllocation *pGfxAlloc1 = pBuffer1->getGraphicsAllocation(pDevice->getRootDeviceIndex());
|
2019-07-15 20:28:09 +08:00
|
|
|
CommandStreamReceiver &csr = pCmdQueue->getGpgpuCommandStreamReceiver();
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_FALSE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_FALSE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
gtpinNotifyMakeResident(pKernel, &csr);
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_TRUE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_FALSE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
// Cancel information about second submitted kernel
|
|
|
|
kernelExecQueue.pop_back();
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
kernelResources.pop_back();
|
|
|
|
EXPECT_EQ(1u, kernelResources.size());
|
|
|
|
gtpinUnmapBuffer((context_handle_t)context, (resource_handle_t)gtpinBuffer1);
|
|
|
|
gtpinFreeBuffer((context_handle_t)context, (resource_handle_t)gtpinBuffer1);
|
|
|
|
retVal = clReleaseKernel(kernel2);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Verify that if flush occurs on another queue then our kernel is not flushed to CSR
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType taskCount = 11;
|
2018-02-08 23:00:20 +08:00
|
|
|
gtpinNotifyPreFlushTask(nullptr);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
gtpinNotifyFlushTask(taskCount);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
|
|
|
|
// Verify that if flush occurs on current queue then our kernel is flushed to CSR
|
|
|
|
gtpinNotifyPreFlushTask(pCmdQueue);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
gtpinNotifyFlushTask(taskCount);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_TRUE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
EXPECT_EQ(taskCount, kernelExecQueue[0].taskCount);
|
|
|
|
|
|
|
|
// Verify that if previous task was completed then it does not affect our kernel
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType taskCompleted = taskCount - 1;
|
2018-02-08 23:00:20 +08:00
|
|
|
int prevCount4 = CommandBufferCompleteCallbackCount;
|
|
|
|
gtpinNotifyTaskCompletion(taskCompleted);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(1u, kernelResources.size());
|
|
|
|
EXPECT_EQ(prevCount4, CommandBufferCompleteCallbackCount);
|
|
|
|
|
|
|
|
// Verify that if current task was completed then it is our kernel
|
|
|
|
gtpinNotifyTaskCompletion(taskCompleted + 1);
|
|
|
|
EXPECT_EQ(0u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(0u, kernelResources.size());
|
|
|
|
EXPECT_EQ(prevCount4 + 1, CommandBufferCompleteCallbackCount);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
pSource.reset();
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenOneKernelIsSubmittedSeveralTimesThenCorrectBuffersAreMadeResident) {
|
2022-08-18 22:11:45 +08:00
|
|
|
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-02-08 23:00:20 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
kernelExecQueue.clear();
|
|
|
|
|
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-02-08 23:00:20 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-02-08 23:00:20 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-02-08 23:00:20 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Create kernel
|
|
|
|
int prevCount1 = KernelCreateCallbackCount;
|
|
|
|
kernel = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
ASSERT_NE(nullptr, kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(prevCount1 + 1, KernelCreateCallbackCount);
|
|
|
|
|
|
|
|
// Simulate that created kernel was sent for execution two times in a row
|
2021-03-09 18:30:21 +08:00
|
|
|
auto pMultiDeviceKernel = castToObject<MultiDeviceKernel>(kernel);
|
|
|
|
auto pKernel = pMultiDeviceKernel->getKernel(rootDeviceIndex);
|
2018-02-08 23:00:20 +08:00
|
|
|
auto pCmdQueue = castToObject<CommandQueue>(cmdQ);
|
|
|
|
ASSERT_NE(nullptr, pKernel);
|
|
|
|
EXPECT_EQ(0u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(0u, kernelResources.size());
|
|
|
|
int prevCount2 = CommandBufferCreateCallbackCount;
|
|
|
|
int prevCount3 = KernelSubmitCallbackCount;
|
|
|
|
// First kernel submission
|
|
|
|
gtpinNotifyKernelSubmit(kernel, pCmdQueue);
|
|
|
|
EXPECT_EQ(prevCount2 + 1, CommandBufferCreateCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount3 + 1, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(1u, kernelResources.size());
|
|
|
|
EXPECT_EQ(pKernel, kernelExecQueue[0].pKernel);
|
|
|
|
EXPECT_EQ(kernelResources[0], (resource_handle_t)kernelExecQueue[0].gtpinResource);
|
|
|
|
EXPECT_EQ(pCmdQueue, kernelExecQueue[0].pCommandQueue);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isResourceResident);
|
|
|
|
// Second kernel submission
|
|
|
|
gtpinNotifyKernelSubmit(kernel, pCmdQueue);
|
|
|
|
EXPECT_EQ(prevCount2 + 2, CommandBufferCreateCallbackCount);
|
|
|
|
EXPECT_EQ(prevCount3 + 2, KernelSubmitCallbackCount);
|
|
|
|
EXPECT_EQ(2u, kernelExecQueue.size());
|
|
|
|
EXPECT_EQ(2u, kernelResources.size());
|
|
|
|
EXPECT_EQ(pKernel, kernelExecQueue[0].pKernel);
|
|
|
|
EXPECT_EQ(kernelResources[0], (resource_handle_t)kernelExecQueue[0].gtpinResource);
|
|
|
|
EXPECT_EQ(pCmdQueue, kernelExecQueue[0].pCommandQueue);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[0].isResourceResident);
|
|
|
|
EXPECT_EQ(pKernel, kernelExecQueue[1].pKernel);
|
|
|
|
EXPECT_EQ(kernelResources[1], (resource_handle_t)kernelExecQueue[1].gtpinResource);
|
|
|
|
EXPECT_EQ(pCmdQueue, kernelExecQueue[1].pCommandQueue);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[1].isTaskCountValid);
|
|
|
|
EXPECT_FALSE(kernelExecQueue[1].isResourceResident);
|
|
|
|
|
|
|
|
// Verify that correct GT-Pin resource is made resident.
|
|
|
|
// This simulates enqueuing non-blocked kernels
|
|
|
|
cl_mem gtpinBuffer0 = kernelExecQueue[0].gtpinResource;
|
|
|
|
auto pBuffer0 = castToObject<Buffer>(gtpinBuffer0);
|
2020-06-09 01:17:23 +08:00
|
|
|
GraphicsAllocation *pGfxAlloc0 = pBuffer0->getGraphicsAllocation(pDevice->getRootDeviceIndex());
|
2018-02-08 23:00:20 +08:00
|
|
|
cl_mem gtpinBuffer1 = kernelExecQueue[1].gtpinResource;
|
|
|
|
auto pBuffer1 = castToObject<Buffer>(gtpinBuffer1);
|
2020-06-09 01:17:23 +08:00
|
|
|
GraphicsAllocation *pGfxAlloc1 = pBuffer1->getGraphicsAllocation(pDevice->getRootDeviceIndex());
|
2019-07-15 20:28:09 +08:00
|
|
|
CommandStreamReceiver &csr = pCmdQueue->getGpgpuCommandStreamReceiver();
|
2018-02-08 23:00:20 +08:00
|
|
|
// Make resident resource of first submitted kernel
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_FALSE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_FALSE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
gtpinNotifyMakeResident(pKernel, &csr);
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_TRUE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_FALSE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
// Make resident resource of second submitted kernel
|
|
|
|
gtpinNotifyMakeResident(pKernel, &csr);
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_TRUE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_TRUE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
// Verify that correct GT-Pin resource is added to residency list.
|
|
|
|
// This simulates enqueuing blocked kernels
|
|
|
|
kernelExecQueue[0].isResourceResident = false;
|
|
|
|
kernelExecQueue[1].isResourceResident = false;
|
2019-01-07 16:29:49 +08:00
|
|
|
pGfxAlloc0->releaseResidencyInOsContext(csr.getOsContext().getContextId());
|
|
|
|
pGfxAlloc1->releaseResidencyInOsContext(csr.getOsContext().getContextId());
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_FALSE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_FALSE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
std::vector<Surface *> residencyVector;
|
|
|
|
EXPECT_EQ(0u, residencyVector.size());
|
|
|
|
// Add to residency list resource of first submitted kernel
|
|
|
|
gtpinNotifyUpdateResidencyList(pKernel, &residencyVector);
|
|
|
|
EXPECT_EQ(1u, residencyVector.size());
|
|
|
|
// Make resident first resource on residency list
|
|
|
|
GeneralSurface *pSurf1 = (GeneralSurface *)residencyVector[0];
|
|
|
|
pSurf1->makeResident(csr);
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_TRUE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_FALSE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
// Add to residency list resource of second submitted kernel
|
|
|
|
gtpinNotifyUpdateResidencyList(pKernel, &residencyVector);
|
|
|
|
EXPECT_EQ(2u, residencyVector.size());
|
|
|
|
// Make resident second resource on residency list
|
|
|
|
GeneralSurface *pSurf2 = (GeneralSurface *)residencyVector[1];
|
|
|
|
pSurf2->makeResident(csr);
|
2018-12-03 17:05:36 +08:00
|
|
|
EXPECT_TRUE(pGfxAlloc0->isResident(csr.getOsContext().getContextId()));
|
|
|
|
EXPECT_TRUE(pGfxAlloc1->isResident(csr.getOsContext().getContextId()));
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
delete pSurf1;
|
|
|
|
delete pSurf2;
|
|
|
|
residencyVector.clear();
|
|
|
|
|
|
|
|
kernelExecQueue.pop_back();
|
|
|
|
EXPECT_EQ(1u, kernelExecQueue.size());
|
|
|
|
kernelResources.pop_back();
|
|
|
|
EXPECT_EQ(1u, kernelResources.size());
|
|
|
|
gtpinUnmapBuffer((context_handle_t)context, (resource_handle_t)gtpinBuffer1);
|
|
|
|
gtpinFreeBuffer((context_handle_t)context, (resource_handle_t)gtpinBuffer1);
|
|
|
|
|
|
|
|
kernelExecQueue.pop_back();
|
|
|
|
EXPECT_EQ(0u, kernelExecQueue.size());
|
|
|
|
kernelResources.pop_back();
|
|
|
|
EXPECT_EQ(0u, kernelResources.size());
|
|
|
|
gtpinUnmapBuffer((context_handle_t)context, (resource_handle_t)gtpinBuffer0);
|
|
|
|
gtpinFreeBuffer((context_handle_t)context, (resource_handle_t)gtpinBuffer0);
|
|
|
|
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
pSource.reset();
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenKernelWithSSHThenVerifyThatSSHResizeWorksWell) {
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-11-30 22:28:39 +08:00
|
|
|
if (compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2022-08-18 22:11:45 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-02-08 23:00:20 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-02-08 23:00:20 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-02-08 23:00:20 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Create kernel
|
|
|
|
kernel = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
ASSERT_NE(nullptr, kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
auto pMultiDeviceKernel = castToObject<MultiDeviceKernel>(kernel);
|
|
|
|
auto pKernel = pMultiDeviceKernel->getKernel(rootDeviceIndex);
|
2018-02-08 23:00:20 +08:00
|
|
|
ASSERT_NE(nullptr, pKernel);
|
|
|
|
|
2021-03-22 19:06:23 +08:00
|
|
|
size_t numBTS1 = pKernel->getNumberOfBindingTableStates();
|
2021-03-24 20:07:20 +08:00
|
|
|
EXPECT_LE(2u, numBTS1);
|
2021-03-22 23:26:03 +08:00
|
|
|
size_t sizeSurfaceStates1 = pKernel->getSurfaceStateHeapSize();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, sizeSurfaceStates1);
|
2021-03-22 19:06:23 +08:00
|
|
|
size_t offsetBTS1 = pKernel->getBindingTableOffset();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, offsetBTS1);
|
|
|
|
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2021-03-22 23:26:03 +08:00
|
|
|
void *pSS1 = gtpinHelper.getSurfaceState(pKernel, 0);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(nullptr, pSS1);
|
|
|
|
|
|
|
|
// Enlarge SSH by one SURFACE STATE element
|
2023-03-08 06:43:53 +08:00
|
|
|
gtpinHelper.addSurfaceState(pKernel);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
2021-03-22 19:06:23 +08:00
|
|
|
size_t numBTS2 = pKernel->getNumberOfBindingTableStates();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(numBTS1 + 1, numBTS2);
|
2021-03-22 23:26:03 +08:00
|
|
|
size_t sizeSurfaceStates2 = pKernel->getSurfaceStateHeapSize();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_GT(sizeSurfaceStates2, sizeSurfaceStates1);
|
2021-03-22 19:06:23 +08:00
|
|
|
size_t offsetBTS2 = pKernel->getBindingTableOffset();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_GT(offsetBTS2, offsetBTS1);
|
|
|
|
|
2021-03-22 23:26:03 +08:00
|
|
|
void *pSS2 = gtpinHelper.getSurfaceState(pKernel, 0);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(pSS2, pSS1);
|
|
|
|
|
2021-03-22 23:26:03 +08:00
|
|
|
pSS2 = gtpinHelper.getSurfaceState(pKernel, numBTS2);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(nullptr, pSS2);
|
|
|
|
|
|
|
|
// Remove kernel's SSH
|
2021-03-22 19:06:23 +08:00
|
|
|
pKernel->resizeSurfaceStateHeap(nullptr, 0, 0, 0);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
2021-03-22 19:06:23 +08:00
|
|
|
size_t numBTS3 = pKernel->getNumberOfBindingTableStates();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(0u, numBTS3);
|
2021-03-22 23:26:03 +08:00
|
|
|
size_t sizeSurfaceStates3 = pKernel->getSurfaceStateHeapSize();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(0u, sizeSurfaceStates3);
|
2021-03-22 19:06:23 +08:00
|
|
|
size_t offsetBTS3 = pKernel->getBindingTableOffset();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(0u, offsetBTS3);
|
2021-03-22 23:26:03 +08:00
|
|
|
void *pSS3 = gtpinHelper.getSurfaceState(pKernel, 0);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(nullptr, pSS3);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2023-03-08 06:43:53 +08:00
|
|
|
TEST_F(GTPinTests, givenKernelWithoutAllocatedSSHThenGTPinStillCanAllocateNewSSHAndProperlyAddNewSurfaceState) {
|
|
|
|
auto kernelInfo = std::make_unique<MockKernelInfo>();
|
|
|
|
ASSERT_EQ(nullptr, kernelInfo->heapInfo.pSsh);
|
2023-04-28 17:38:31 +08:00
|
|
|
ASSERT_EQ(0u, kernelInfo->heapInfo.surfaceStateHeapSize);
|
2023-03-08 06:43:53 +08:00
|
|
|
|
|
|
|
MockContext context(pDevice);
|
|
|
|
MockProgram program(&context, false, toClDeviceVector(*pDevice));
|
|
|
|
auto kernel = std::make_unique<MockKernel>(&program, *kernelInfo, *pDevice);
|
|
|
|
kernel->localBindingTableOffset = kernelInfo->kernelDescriptor.payloadMappings.bindingTable.tableOffset;
|
|
|
|
ASSERT_FALSE(isValidOffset<SurfaceStateHeapOffset>(static_cast<SurfaceStateHeapOffset>(kernel->localBindingTableOffset)));
|
|
|
|
|
|
|
|
const auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
|
|
|
gtpinHelper.addSurfaceState(kernel.get());
|
|
|
|
|
|
|
|
auto numBts = kernel->getNumberOfBindingTableStates();
|
|
|
|
EXPECT_EQ(1u, numBts);
|
|
|
|
auto sshSize = kernel->getSurfaceStateHeapSize();
|
|
|
|
EXPECT_GT(sshSize, 0u);
|
|
|
|
auto offsetBTS = static_cast<SurfaceStateHeapOffset>(kernel->getBindingTableOffset());
|
|
|
|
EXPECT_TRUE(isValidOffset<SurfaceStateHeapOffset>(offsetBTS));
|
|
|
|
}
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
TEST_F(GTPinTests, givenKernelThenVerifyThatKernelCodeSubstitutionWorksWell) {
|
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
2020-02-12 17:10:28 +08:00
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
2018-02-08 23:00:20 +08:00
|
|
|
testFile.append(clFiles);
|
2020-02-12 17:10:28 +08:00
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
2019-08-29 21:10:51 +08:00
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
const char *sources[1] = {pSource.get()};
|
2018-02-08 23:00:20 +08:00
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
2019-08-29 21:10:51 +08:00
|
|
|
sources,
|
2018-02-08 23:00:20 +08:00
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
// Create kernel
|
|
|
|
kernel = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
ASSERT_NE(nullptr, kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2021-03-09 18:30:21 +08:00
|
|
|
auto pMultiDeviceKernel = castToObject<MultiDeviceKernel>(kernel);
|
|
|
|
auto pKernel = pMultiDeviceKernel->getKernel(rootDeviceIndex);
|
2018-02-08 23:00:20 +08:00
|
|
|
ASSERT_NE(nullptr, pKernel);
|
|
|
|
|
2021-03-22 23:26:03 +08:00
|
|
|
bool isKernelCodeSubstituted = pKernel->isKernelHeapSubstituted();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_FALSE(isKernelCodeSubstituted);
|
|
|
|
|
|
|
|
// Substitute new kernel code
|
|
|
|
constexpr size_t newCodeSize = 64;
|
2018-04-05 01:02:07 +08:00
|
|
|
uint8_t newCode[newCodeSize] = {0x0, 0x1, 0x2, 0x3, 0x4};
|
2021-03-24 01:11:41 +08:00
|
|
|
pKernel->substituteKernelHeap(&newCode[0], newCodeSize);
|
2018-02-08 23:00:20 +08:00
|
|
|
|
|
|
|
// Verify that substitution went properly
|
2021-03-22 23:26:03 +08:00
|
|
|
isKernelCodeSubstituted = pKernel->isKernelHeapSubstituted();
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_TRUE(isKernelCodeSubstituted);
|
2021-03-22 23:26:03 +08:00
|
|
|
uint8_t *pBin2 = reinterpret_cast<uint8_t *>(const_cast<void *>(pKernel->getKernelHeap()));
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_EQ(pBin2, &newCode[0]);
|
|
|
|
|
2021-03-22 23:26:03 +08:00
|
|
|
auto kernelIsa = pKernel->getKernelInfo().kernelAllocation->getUnderlyingBuffer();
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(0, memcmp(kernelIsa, newCode, newCodeSize));
|
|
|
|
|
2018-02-08 23:00:20 +08:00
|
|
|
// Cleanup
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
TEST_F(GTPinTests, WhenCreateGtPinGfxCoreHelperThenValidPointerIsReturned) {
|
2019-05-08 22:00:24 +08:00
|
|
|
GFXCORE_FAMILY genFamily = pDevice->getHardwareInfo().platform.eRenderCoreFamily;
|
2023-02-02 21:55:54 +08:00
|
|
|
auto pGTPinHelper = GTPinGfxCoreHelper::create(genFamily);
|
2018-02-08 23:00:20 +08:00
|
|
|
EXPECT_NE(nullptr, pGTPinHelper);
|
2018-01-24 20:26:46 +08:00
|
|
|
}
|
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
TEST(GTPinTestsCreate, WhenCreateGtPinGfxCoreHelperWithUnknownCoreThenNullptrIsReturned) {
|
|
|
|
EXPECT_EQ(nullptr, GTPinGfxCoreHelper::create(IGFX_UNKNOWN_CORE));
|
|
|
|
}
|
|
|
|
|
2018-03-23 01:46:09 +08:00
|
|
|
TEST(GTPinOfflineTests, givenGtPinInDisabledStateWhenCallbacksFromEnqueuePathAreCalledThenNothingHappens) {
|
|
|
|
ASSERT_FALSE(gtpinIsGTPinInitialized());
|
|
|
|
auto dummyKernel = reinterpret_cast<cl_kernel>(0x1000);
|
|
|
|
auto dummyQueue = reinterpret_cast<void *>(0x1000);
|
|
|
|
uint32_t dummyCompletedTask = 0u;
|
|
|
|
|
2022-08-18 22:11:45 +08:00
|
|
|
// now call gtpin function with dummy data, this must not crash
|
2018-03-23 01:46:09 +08:00
|
|
|
gtpinNotifyKernelSubmit(dummyKernel, dummyQueue);
|
|
|
|
gtpinNotifyPreFlushTask(dummyQueue);
|
|
|
|
gtpinNotifyTaskCompletion(dummyCompletedTask);
|
|
|
|
gtpinNotifyFlushTask(dummyCompletedTask);
|
|
|
|
EXPECT_FALSE(gtpinIsGTPinInitialized());
|
|
|
|
}
|
2018-06-04 15:09:04 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenOnKernelSubitIsCalledThenCorrectOffsetisSetInKernel) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-06-04 15:09:04 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
VariableBackup<bool> returnNullResourceBckp(&returnNullResource);
|
|
|
|
VariableBackup<uint32_t> kernelOffsetBckp(&kernelOffset);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
char surfaceStateHeap[0x80];
|
|
|
|
std::unique_ptr<MockContext> context(new MockContext(pDevice));
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2018-08-16 20:28:58 +08:00
|
|
|
auto pKernelInfo = std::make_unique<KernelInfo>();
|
2018-06-04 15:09:04 +08:00
|
|
|
pKernelInfo->heapInfo.pSsh = surfaceStateHeap;
|
2023-04-28 17:38:31 +08:00
|
|
|
pKernelInfo->heapInfo.surfaceStateHeapSize = sizeof(surfaceStateHeap);
|
2018-06-04 15:09:04 +08:00
|
|
|
|
2020-10-16 21:00:28 +08:00
|
|
|
auto pProgramm = std::make_unique<MockProgram>(context.get(), false, toClDeviceVector(*pDevice));
|
2021-07-23 18:36:36 +08:00
|
|
|
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(context.get(), pDevice, nullptr, false));
|
2021-03-16 19:32:40 +08:00
|
|
|
std::unique_ptr<MultiDeviceKernel> pMultiDeviceKernel(MockMultiDeviceKernel::create<MockKernel>(pProgramm.get(), MockKernel::toKernelInfoContainer(*pKernelInfo, rootDeviceIndex)));
|
|
|
|
auto pKernel = static_cast<MockKernel *>(pMultiDeviceKernel->getKernel(rootDeviceIndex));
|
2018-06-04 15:09:04 +08:00
|
|
|
|
2021-03-22 19:06:23 +08:00
|
|
|
pKernel->setSshLocal(nullptr, sizeof(surfaceStateHeap));
|
2018-06-04 15:09:04 +08:00
|
|
|
|
|
|
|
kernelOffset = 0x1234;
|
|
|
|
EXPECT_NE(pKernel->getStartOffset(), kernelOffset);
|
|
|
|
returnNullResource = true;
|
2021-03-09 18:30:21 +08:00
|
|
|
cl_context ctxt = context.get();
|
2018-06-04 15:09:04 +08:00
|
|
|
currContext = (gtpin::context_handle_t)ctxt;
|
2021-03-09 18:30:21 +08:00
|
|
|
gtpinNotifyKernelSubmit(pMultiDeviceKernel.get(), cmdQ.get());
|
2018-06-04 15:09:04 +08:00
|
|
|
EXPECT_EQ(pKernel->getStartOffset(), kernelOffset);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
kernelResources.clear();
|
|
|
|
}
|
2018-08-06 19:19:32 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenOnContextCreateIsCalledThenGtpinInitIsSet) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2018-08-06 19:19:32 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
auto context = std::make_unique<MockContext>();
|
|
|
|
gtpinNotifyContextCreate(context.get());
|
|
|
|
EXPECT_NE(gtpinGetIgcInit(), nullptr);
|
|
|
|
}
|
|
|
|
|
2020-01-12 01:25:26 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenOnKernelCreateIsCalledWithNullptrThenCallIsIgnored) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2020-01-12 01:25:26 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
auto prevCreateCount = KernelCreateCallbackCount;
|
|
|
|
gtpinNotifyKernelCreate(nullptr);
|
|
|
|
EXPECT_EQ(prevCreateCount, KernelCreateCallbackCount);
|
2018-08-06 19:19:32 +08:00
|
|
|
}
|
2020-01-12 01:25:26 +08:00
|
|
|
|
2021-05-21 22:08:01 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelDoesNotHaveDebugDataThenPassNullPtrToOnKernelCreate) {
|
|
|
|
static void *debugDataPtr = nullptr;
|
|
|
|
static size_t debugDataSize = 0;
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
2021-05-21 22:08:01 +08:00
|
|
|
gtpinCallbacks.onKernelCreate = [](context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) {
|
|
|
|
paramsOut->inst_kernel_binary = const_cast<uint8_t *>(paramsIn->orig_kernel_binary);
|
|
|
|
paramsOut->inst_kernel_size = paramsIn->orig_kernel_size;
|
|
|
|
paramsOut->kernel_id = paramsIn->igc_hash_id;
|
|
|
|
debugDataPtr = const_cast<void *>(paramsIn->debug_data);
|
|
|
|
debugDataSize = paramsIn->debug_data_size;
|
|
|
|
};
|
|
|
|
gtpinCallbacks.onKernelSubmit = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {};
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2021-05-21 22:08:01 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
|
|
|
mockKernel.kernelInfo.kernelDescriptor.external.debugData.reset();
|
|
|
|
mockKernel.kernelInfo.createKernelAllocation(pDevice->getDevice(), false);
|
|
|
|
gtpinNotifyKernelCreate(static_cast<cl_kernel>(mockKernel.mockKernel->getMultiDeviceKernel()));
|
|
|
|
EXPECT_EQ(debugDataPtr, nullptr);
|
|
|
|
EXPECT_EQ(debugDataSize, 0u);
|
|
|
|
pDevice->getMemoryManager()->freeGraphicsMemory(mockKernel.kernelInfo.kernelAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelHasDebugDataThenCorrectDebugDataIsSet) {
|
|
|
|
static void *debugDataPtr = nullptr;
|
|
|
|
static size_t debugDataSize = 0;
|
|
|
|
void *dummyDebugData = reinterpret_cast<void *>(0x123456);
|
|
|
|
size_t dummyDebugDataSize = 0x2245;
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
2021-05-21 22:08:01 +08:00
|
|
|
gtpinCallbacks.onKernelCreate = [](context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) {
|
|
|
|
paramsOut->inst_kernel_binary = const_cast<uint8_t *>(paramsIn->orig_kernel_binary);
|
|
|
|
paramsOut->inst_kernel_size = paramsIn->orig_kernel_size;
|
|
|
|
paramsOut->kernel_id = paramsIn->igc_hash_id;
|
|
|
|
debugDataPtr = const_cast<void *>(paramsIn->debug_data);
|
|
|
|
debugDataSize = paramsIn->debug_data_size;
|
|
|
|
};
|
|
|
|
gtpinCallbacks.onKernelSubmit = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {};
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2021-05-21 22:08:01 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
|
|
|
mockKernel.kernelInfo.kernelDescriptor.external.debugData.reset(new DebugData());
|
2021-06-15 23:01:16 +08:00
|
|
|
mockKernel.kernelInfo.debugData.vIsa = reinterpret_cast<char *>(dummyDebugData);
|
|
|
|
mockKernel.kernelInfo.debugData.vIsaSize = static_cast<uint32_t>(dummyDebugDataSize);
|
2021-05-21 22:08:01 +08:00
|
|
|
mockKernel.kernelInfo.createKernelAllocation(pDevice->getDevice(), false);
|
|
|
|
gtpinNotifyKernelCreate(static_cast<cl_kernel>(mockKernel.mockKernel->getMultiDeviceKernel()));
|
|
|
|
EXPECT_EQ(debugDataPtr, dummyDebugData);
|
|
|
|
EXPECT_EQ(debugDataSize, dummyDebugDataSize);
|
|
|
|
pDevice->getMemoryManager()->freeGraphicsMemory(mockKernel.kernelInfo.kernelAllocation);
|
|
|
|
}
|
|
|
|
|
2023-03-07 18:41:07 +08:00
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenInstrumentedBinaryIsZebinThenReturnDebugZebinOnCallback) {
|
|
|
|
static void *debugDataPtr = nullptr;
|
|
|
|
static size_t debugDataSize = 0;
|
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = [](context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) {
|
|
|
|
debugDataPtr = const_cast<void *>(paramsIn->debug_data);
|
|
|
|
debugDataSize = paramsIn->debug_data_size;
|
|
|
|
};
|
|
|
|
gtpinCallbacks.onKernelSubmit = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {};
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
|
|
|
ASSERT_EQ(nullptr, mockKernel.kernelInfo.debugData.vIsa);
|
|
|
|
ASSERT_EQ(0u, mockKernel.kernelInfo.debugData.vIsaSize);
|
|
|
|
|
|
|
|
ZebinTestData::ValidEmptyProgram zebin;
|
|
|
|
std::unique_ptr<char[]> src = makeCopy(zebin.storage.data(), zebin.storage.size());
|
|
|
|
mockKernel.kernelInfo.kernelDescriptor.kernelMetadata.kernelName = zebin.kernelName;
|
|
|
|
mockKernel.mockProgram->replaceDeviceBinary(std::move(src), zebin.storage.size(), rootDeviceIndex);
|
|
|
|
|
|
|
|
mockKernel.kernelInfo.createKernelAllocation(pDevice->getDevice(), false);
|
|
|
|
auto &buildInfo = mockKernel.mockProgram->buildInfos[pDevice->getRootDeviceIndex()];
|
|
|
|
buildInfo.kernelInfoArray.push_back(&mockKernel.kernelInfo);
|
|
|
|
mockKernel.mockProgram->createDebugZebin(pDevice->getRootDeviceIndex());
|
|
|
|
|
|
|
|
gtpinNotifyKernelCreate(static_cast<cl_kernel>(mockKernel.mockKernel->getMultiDeviceKernel()));
|
|
|
|
EXPECT_EQ(buildInfo.debugData.get(), debugDataPtr);
|
|
|
|
EXPECT_EQ(buildInfo.debugDataSize, debugDataSize);
|
|
|
|
|
|
|
|
pDevice->getMemoryManager()->freeGraphicsMemory(mockKernel.kernelInfo.kernelAllocation);
|
|
|
|
mockKernel.mockProgram->buildInfos[pDevice->getRootDeviceIndex()].kernelInfoArray.clear();
|
|
|
|
}
|
|
|
|
|
2020-02-19 23:32:40 +08:00
|
|
|
HWTEST_F(GTPinTests, givenGtPinInitializedWhenSubmittingKernelCommandThenFlushedTaskCountIsNotified) {
|
|
|
|
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(pContext, pDevice, nullptr);
|
|
|
|
|
|
|
|
auto onKernelSubmitFnc = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) { return; };
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
2020-02-19 23:32:40 +08:00
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmitFnc;
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2020-02-19 23:32:40 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
IndirectHeap *ih1 = nullptr, *ih2 = nullptr, *ih3 = nullptr;
|
2022-01-26 18:59:30 +08:00
|
|
|
mockCmdQ->allocateHeapMemory(IndirectHeap::Type::DYNAMIC_STATE, 128, ih1);
|
|
|
|
mockCmdQ->allocateHeapMemory(IndirectHeap::Type::INDIRECT_OBJECT, 128, ih2);
|
|
|
|
mockCmdQ->allocateHeapMemory(IndirectHeap::Type::SURFACE_STATE, 128, ih3);
|
2020-02-19 23:32:40 +08:00
|
|
|
|
|
|
|
PreemptionMode preemptionMode = pDevice->getPreemptionMode();
|
2022-02-04 21:59:01 +08:00
|
|
|
auto cmdStream = new LinearStream(pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), 128, AllocationType::COMMAND_BUFFER, pDevice->getDeviceBitfield()}));
|
2020-02-19 23:32:40 +08:00
|
|
|
|
|
|
|
std::vector<Surface *> surfaces;
|
|
|
|
auto kernelOperation = std::make_unique<KernelOperation>(cmdStream, *mockCmdQ->getGpgpuCommandStreamReceiver().getInternalAllocationStorage());
|
|
|
|
MockKernelWithInternals kernel(*pDevice);
|
|
|
|
kernelOperation->setHeaps(ih1, ih2, ih3);
|
|
|
|
|
|
|
|
bool flushDC = false;
|
|
|
|
bool slmUsed = false;
|
|
|
|
bool ndRangeKernel = false;
|
|
|
|
|
2021-03-09 18:30:21 +08:00
|
|
|
gtpinNotifyKernelSubmit(kernel.mockMultiDeviceKernel, mockCmdQ.get());
|
2020-02-19 23:32:40 +08:00
|
|
|
|
2023-01-20 00:11:39 +08:00
|
|
|
std::unique_ptr<Command> command(new CommandComputeKernel(*mockCmdQ, kernelOperation, surfaces, flushDC, slmUsed, ndRangeKernel, nullptr, preemptionMode, kernel, 1, nullptr));
|
2020-02-19 23:32:40 +08:00
|
|
|
CompletionStamp stamp = command->submit(20, false);
|
|
|
|
|
|
|
|
ASSERT_EQ(1u, kernelExecQueue.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(kernelExecQueue[0].isTaskCountValid);
|
|
|
|
EXPECT_EQ(kernelExecQueue[0].taskCount, stamp.taskCount);
|
|
|
|
}
|
|
|
|
|
2021-04-07 07:52:24 +08:00
|
|
|
class GTPinFixtureWithLocalMemory : public GTPinFixture {
|
|
|
|
public:
|
2022-08-12 22:24:49 +08:00
|
|
|
void setUp() {
|
2021-04-07 07:52:24 +08:00
|
|
|
DebugManager.flags.EnableLocalMemory.set(true);
|
|
|
|
DebugManager.flags.GTPinAllocateBufferInSharedMemory.set(true);
|
2022-05-10 01:40:30 +08:00
|
|
|
GTPinFixture::setUpImpl();
|
2021-04-07 07:52:24 +08:00
|
|
|
}
|
2022-08-12 22:24:49 +08:00
|
|
|
void tearDown() {
|
|
|
|
GTPinFixture::tearDown();
|
2021-04-07 07:52:24 +08:00
|
|
|
}
|
|
|
|
DebugManagerStateRestore restore;
|
|
|
|
};
|
|
|
|
|
2022-08-12 22:24:49 +08:00
|
|
|
using GTPinTestsWithLocalMemory = Test<GTPinFixtureWithLocalMemory>;
|
2021-04-07 07:52:24 +08:00
|
|
|
|
|
|
|
TEST_F(GTPinTestsWithLocalMemory, whenPlatformHasNoSvmSupportThenGtPinBufferCantBeAllocatedInSharedMemory) {
|
|
|
|
DebugManager.flags.GTPinAllocateBufferInSharedMemory.set(-1);
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2021-04-07 07:52:24 +08:00
|
|
|
auto canUseSharedAllocation = gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo());
|
|
|
|
if (!pDevice->getHardwareInfo().capabilityTable.ftrSvm) {
|
|
|
|
EXPECT_FALSE(canUseSharedAllocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
HWTEST_F(GTPinTests, givenGtPinWithSupportForSharedAllocationWhenGtPinHelperFunctionsAreCalledThenCheckIfSharedAllocationCanBeUsed) {
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2021-04-29 00:11:12 +08:00
|
|
|
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-12-08 20:22:35 +08:00
|
|
|
class MockGTPinGfxCoreHelperHw : public GTPinGfxCoreHelperHw<FamilyType> {
|
2021-04-29 00:11:12 +08:00
|
|
|
public:
|
|
|
|
bool canUseSharedAllocation(const HardwareInfo &hwInfo) const override {
|
|
|
|
canUseSharedAllocationCalled = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mutable bool canUseSharedAllocationCalled = false;
|
|
|
|
};
|
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
auto backup = std::unique_ptr<GTPinGfxCoreHelper>(new MockGTPinGfxCoreHelperHw());
|
|
|
|
auto *mockGTPinGfxCoreHelperHw = static_cast<MockGTPinGfxCoreHelperHw *>(backup.get());
|
|
|
|
pDevice->gtpinGfxCoreHelper.swap(backup);
|
2021-04-29 00:11:12 +08:00
|
|
|
|
|
|
|
resource_handle_t resource = nullptr;
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpin::context_handle_t gtPinContext = reinterpret_cast<gtpin::context_handle_t>(static_cast<cl_context>(pContext));
|
2021-04-29 00:11:12 +08:00
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled = false;
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpinCreateBuffer(gtPinContext, 256, &resource);
|
2023-02-02 21:55:54 +08:00
|
|
|
EXPECT_TRUE(mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled);
|
2021-04-29 00:11:12 +08:00
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled = false;
|
2021-04-29 00:11:12 +08:00
|
|
|
uint8_t *address = nullptr;
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpinMapBuffer(gtPinContext, resource, &address);
|
2023-02-02 21:55:54 +08:00
|
|
|
EXPECT_TRUE(mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled);
|
2021-04-29 00:11:12 +08:00
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled = false;
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpinUnmapBuffer(gtPinContext, resource);
|
2023-02-02 21:55:54 +08:00
|
|
|
EXPECT_TRUE(mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled);
|
2021-04-29 00:11:12 +08:00
|
|
|
|
2023-02-02 21:55:54 +08:00
|
|
|
mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled = false;
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpinFreeBuffer(gtPinContext, resource);
|
2023-02-02 21:55:54 +08:00
|
|
|
EXPECT_TRUE(mockGTPinGfxCoreHelperHw->canUseSharedAllocationCalled);
|
|
|
|
|
|
|
|
pDevice->gtpinGfxCoreHelper.swap(backup);
|
2021-04-29 00:11:12 +08:00
|
|
|
}
|
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
TEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBufferIsCreatedThenAllocateBufferInSharedMemory) {
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2021-04-07 07:52:24 +08:00
|
|
|
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
|
|
|
resource_handle_t resource = nullptr;
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpin::context_handle_t gtPinContext = reinterpret_cast<gtpin::context_handle_t>(static_cast<cl_context>(pContext));
|
2021-04-07 07:52:24 +08:00
|
|
|
GTPIN_DI_STATUS status = GTPIN_DI_SUCCESS;
|
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
status = gtpinCreateBuffer(gtPinContext, 256, &resource);
|
2021-04-07 07:52:24 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
EXPECT_NE(nullptr, resource);
|
|
|
|
|
|
|
|
auto allocData = reinterpret_cast<SvmAllocationData *>(resource);
|
|
|
|
|
|
|
|
auto cpuAllocation = allocData->cpuAllocation;
|
|
|
|
ASSERT_NE(nullptr, cpuAllocation);
|
2022-02-04 21:59:01 +08:00
|
|
|
EXPECT_NE(AllocationType::UNIFIED_SHARED_MEMORY, cpuAllocation->getAllocationType());
|
2021-04-07 07:52:24 +08:00
|
|
|
|
|
|
|
auto gpuAllocation = allocData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
|
|
|
|
ASSERT_NE(nullptr, gpuAllocation);
|
2022-02-04 21:59:01 +08:00
|
|
|
EXPECT_NE(AllocationType::UNIFIED_SHARED_MEMORY, gpuAllocation->getAllocationType());
|
2021-04-07 07:52:24 +08:00
|
|
|
|
|
|
|
uint8_t *address = nullptr;
|
2023-04-19 20:12:05 +08:00
|
|
|
status = gtpinMapBuffer(gtPinContext, resource, &address);
|
2021-04-07 07:52:24 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
EXPECT_EQ(allocData->cpuAllocation->getUnderlyingBuffer(), address);
|
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
status = gtpinUnmapBuffer(gtPinContext, resource);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
|
|
|
|
status = gtpinFreeBuffer(gtPinContext, resource);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBufferIsCreatedInSingleStorageThenAllocateBufferWithoutCpuAllocation) {
|
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(0);
|
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
|
|
|
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
|
|
|
resource_handle_t resource = nullptr;
|
|
|
|
gtpin::context_handle_t gtPinContext = reinterpret_cast<gtpin::context_handle_t>(static_cast<cl_context>(pContext));
|
|
|
|
GTPIN_DI_STATUS status = GTPIN_DI_SUCCESS;
|
|
|
|
|
|
|
|
status = gtpinCreateBuffer(gtPinContext, 256, &resource);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
EXPECT_NE(nullptr, resource);
|
|
|
|
|
|
|
|
auto allocData = reinterpret_cast<SvmAllocationData *>(resource);
|
|
|
|
|
|
|
|
auto cpuAllocation = allocData->cpuAllocation;
|
|
|
|
EXPECT_EQ(nullptr, cpuAllocation);
|
|
|
|
|
|
|
|
auto gpuAllocation = allocData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
|
|
|
|
ASSERT_NE(nullptr, gpuAllocation);
|
|
|
|
EXPECT_NE(AllocationType::UNIFIED_SHARED_MEMORY, gpuAllocation->getAllocationType());
|
|
|
|
|
|
|
|
uint8_t *address = nullptr;
|
|
|
|
status = gtpinMapBuffer(gtPinContext, resource, &address);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
EXPECT_EQ(gpuAllocation->getGpuAddress(), castToUint64(address));
|
|
|
|
|
|
|
|
status = gtpinUnmapBuffer(gtPinContext, resource);
|
2021-04-07 07:52:24 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
status = gtpinFreeBuffer(gtPinContext, resource);
|
2021-04-07 07:52:24 +08:00
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBufferIsAllocatedInSharedMemoryThenSetSurfaceStateForTheBufferAndMakeItResident) {
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2023-01-03 17:01:43 +08:00
|
|
|
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
|
2022-08-18 22:11:45 +08:00
|
|
|
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo()) ||
|
2022-11-30 22:28:39 +08:00
|
|
|
compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
|
2021-04-07 07:52:24 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2021-04-07 07:52:24 +08:00
|
|
|
|
|
|
|
GTPIN_DI_STATUS status = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
|
|
|
|
|
|
|
cl_kernel kernel = nullptr;
|
|
|
|
cl_program pProgram = nullptr;
|
|
|
|
cl_device_id device = (cl_device_id)pDevice;
|
|
|
|
size_t sourceSize = 0;
|
|
|
|
std::string testFile;
|
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
cl_queue_properties properties = 0;
|
|
|
|
cl_context context = nullptr;
|
|
|
|
|
|
|
|
KernelBinaryHelper kbHelper("CopyBuffer_simd16", false);
|
|
|
|
testFile.append(clFiles);
|
|
|
|
testFile.append("CopyBuffer_simd16.cl");
|
|
|
|
auto pSource = loadDataFromFile(testFile.c_str(), sourceSize);
|
|
|
|
EXPECT_NE(0u, sourceSize);
|
|
|
|
EXPECT_NE(nullptr, pSource);
|
|
|
|
|
|
|
|
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
|
|
|
|
cmdQ = clCreateCommandQueue(context, device, properties, &retVal);
|
|
|
|
ASSERT_NE(nullptr, cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
const char *sources[1] = {pSource.get()};
|
|
|
|
pProgram = clCreateProgramWithSource(
|
|
|
|
context,
|
|
|
|
1,
|
|
|
|
sources,
|
|
|
|
&sourceSize,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = clBuildProgram(
|
|
|
|
pProgram,
|
|
|
|
1,
|
|
|
|
&device,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
kernel = clCreateKernel(pProgram, "CopyBuffer", &retVal);
|
|
|
|
EXPECT_NE(nullptr, kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto pMultiDeviceKernel = static_cast<MultiDeviceKernel *>(kernel);
|
|
|
|
auto pKernel = pMultiDeviceKernel->getKernel(rootDeviceIndex);
|
|
|
|
auto pCmdQueue = castToObject<CommandQueue>(cmdQ);
|
|
|
|
auto &csr = pCmdQueue->getGpgpuCommandStreamReceiver();
|
|
|
|
|
|
|
|
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
|
|
|
|
constexpr size_t renderSurfaceSize = sizeof(RENDER_SURFACE_STATE);
|
|
|
|
|
|
|
|
size_t gtpinBTI = pKernel->getNumberOfBindingTableStates() - 1;
|
|
|
|
void *pSurfaceState = gtpinHelper.getSurfaceState(pKernel, gtpinBTI);
|
|
|
|
EXPECT_NE(nullptr, pSurfaceState);
|
|
|
|
|
|
|
|
RENDER_SURFACE_STATE *surfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(pSurfaceState);
|
|
|
|
memset(pSurfaceState, 0, renderSurfaceSize);
|
|
|
|
gtpinNotifyKernelSubmit(kernel, pCmdQueue);
|
|
|
|
|
|
|
|
auto allocData = reinterpret_cast<SvmAllocationData *>(kernelExecQueue[0].gtpinResource);
|
|
|
|
EXPECT_NE(nullptr, allocData);
|
|
|
|
auto gpuAllocation = allocData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
|
|
|
EXPECT_NE(nullptr, gpuAllocation);
|
|
|
|
|
|
|
|
RENDER_SURFACE_STATE expectedSurfaceState;
|
|
|
|
memset(&expectedSurfaceState, 0, renderSurfaceSize);
|
|
|
|
{
|
|
|
|
void *addressToPatch = gpuAllocation->getUnderlyingBuffer();
|
|
|
|
size_t sizeToPatch = gpuAllocation->getUnderlyingBufferSize();
|
|
|
|
Buffer::setSurfaceState(&pDevice->getDevice(), &expectedSurfaceState, false, false,
|
|
|
|
sizeToPatch, addressToPatch, 0, gpuAllocation, 0, 0,
|
|
|
|
pKernel->getKernelInfo().kernelDescriptor.kernelAttributes.flags.useGlobalAtomics, pContext->getNumDevices());
|
|
|
|
}
|
|
|
|
EXPECT_EQ(0, memcmp(&expectedSurfaceState, surfaceState, renderSurfaceSize));
|
|
|
|
|
|
|
|
EXPECT_FALSE(gpuAllocation->isResident(csr.getOsContext().getContextId()));
|
|
|
|
gtpinNotifyMakeResident(pKernel, &csr);
|
|
|
|
EXPECT_TRUE(gpuAllocation->isResident(csr.getOsContext().getContextId()));
|
|
|
|
|
|
|
|
kernelExecQueue[0].isTaskCountValid = true;
|
|
|
|
gtpinNotifyTaskCompletion(kernelExecQueue[0].taskCount);
|
|
|
|
|
|
|
|
retVal = clReleaseKernel(kernel);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseProgram(pProgram);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseCommandQueue(cmdQ);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
2021-07-14 21:54:25 +08:00
|
|
|
HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtpinNotifyKernelSubmitThenMoveToAllocationDomainCalled) {
|
2023-02-01 23:00:54 +08:00
|
|
|
auto >pinHelper = pDevice->getGTPinGfxCoreHelper();
|
2021-07-14 21:54:25 +08:00
|
|
|
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
2022-12-08 20:22:35 +08:00
|
|
|
class MockGTPinGfxCoreHelperHw : public GTPinGfxCoreHelperHw<FamilyType> {
|
2021-07-14 21:54:25 +08:00
|
|
|
public:
|
2023-02-01 23:00:54 +08:00
|
|
|
void *getSurfaceState(Kernel *pKernel, size_t bti) const override {
|
|
|
|
return const_cast<void *>(static_cast<const void *>(data));
|
2021-07-14 21:54:25 +08:00
|
|
|
}
|
|
|
|
uint8_t data[128];
|
|
|
|
};
|
|
|
|
static std::unique_ptr<SvmAllocationData> allocDataHandle;
|
|
|
|
static std::unique_ptr<MockGraphicsAllocation> mockGAHandle;
|
2023-02-02 21:55:54 +08:00
|
|
|
|
|
|
|
auto backup = std::unique_ptr<GTPinGfxCoreHelper>(new MockGTPinGfxCoreHelperHw());
|
|
|
|
pDevice->gtpinGfxCoreHelper.swap(backup);
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
2021-07-14 21:54:25 +08:00
|
|
|
gtpinCallbacks.onKernelSubmit = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {
|
|
|
|
auto allocData = std::make_unique<SvmAllocationData>(0);
|
|
|
|
auto mockGA = std::make_unique<MockGraphicsAllocation>();
|
|
|
|
allocData->gpuAllocations.addAllocation(mockGA.get());
|
|
|
|
*resource = reinterpret_cast<resource_handle_t>(allocData.get());
|
|
|
|
allocDataHandle = std::move(allocData);
|
|
|
|
mockGAHandle = std::move(mockGA);
|
|
|
|
};
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2021-07-14 21:54:25 +08:00
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
for (auto &allocateDualStorageUSM : ::testing::Bool()) {
|
|
|
|
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(allocateDualStorageUSM);
|
|
|
|
isGTPinInitialized = false;
|
|
|
|
if (allocateDualStorageUSM) {
|
|
|
|
memoryManager->pageFaultManager = std::make_unique<MockResidentTestsPageFaultManager>();
|
|
|
|
} else {
|
|
|
|
memoryManager->pageFaultManager.reset();
|
|
|
|
}
|
2021-07-14 21:54:25 +08:00
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
GTPIN_DI_STATUS status = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, status);
|
2021-07-14 21:54:25 +08:00
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
MockKernelWithInternals mockkernel(*pDevice);
|
|
|
|
MockCommandQueue mockCmdQueue;
|
|
|
|
cl_context ctxt = (cl_context)((Context *)pContext);
|
|
|
|
currContext = (gtpin::context_handle_t)(ctxt);
|
|
|
|
mockCmdQueue.device = pDevice;
|
2021-07-14 21:54:25 +08:00
|
|
|
|
2023-04-19 20:12:05 +08:00
|
|
|
gtpinNotifyKernelSubmit(mockkernel.mockMultiDeviceKernel, &mockCmdQueue);
|
|
|
|
if (allocateDualStorageUSM) {
|
|
|
|
EXPECT_EQ(static_cast<MockResidentTestsPageFaultManager *>(pDevice->getExecutionEnvironment()->memoryManager->getPageFaultManager())->moveAllocationToGpuDomainCalledTimes, 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
mockCmdQueue.device = nullptr;
|
|
|
|
mockGAHandle.reset();
|
|
|
|
allocDataHandle.reset();
|
|
|
|
}
|
2023-02-02 21:55:54 +08:00
|
|
|
|
|
|
|
pDevice->gtpinGfxCoreHelper.swap(backup);
|
2021-07-14 21:54:25 +08:00
|
|
|
}
|
2021-08-31 23:44:43 +08:00
|
|
|
|
|
|
|
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenGtpinRemoveCommandQueueIsCalledThenAllKernelsFromCmdQueueAreRemoved) {
|
2022-05-16 22:06:56 +08:00
|
|
|
gtpinCallbacks.onContextCreate = onContextCreate;
|
|
|
|
gtpinCallbacks.onContextDestroy = onContextDestroy;
|
|
|
|
gtpinCallbacks.onKernelCreate = onKernelCreate;
|
|
|
|
gtpinCallbacks.onKernelSubmit = onKernelSubmit;
|
|
|
|
gtpinCallbacks.onCommandBufferCreate = onCommandBufferCreate;
|
|
|
|
gtpinCallbacks.onCommandBufferComplete = onCommandBufferComplete;
|
2021-08-31 23:44:43 +08:00
|
|
|
retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr);
|
|
|
|
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
|
|
|
|
|
|
|
|
kernelExecQueue.clear();
|
|
|
|
|
|
|
|
CommandQueue *cmdQ1 = reinterpret_cast<CommandQueue *>(1);
|
|
|
|
CommandQueue *cmdQ2 = reinterpret_cast<CommandQueue *>(2);
|
|
|
|
Kernel *kernel1 = reinterpret_cast<Kernel *>(1);
|
|
|
|
Kernel *kernel2 = reinterpret_cast<Kernel *>(2);
|
|
|
|
Kernel *kernel3 = reinterpret_cast<Kernel *>(3);
|
|
|
|
Kernel *kernel4 = reinterpret_cast<Kernel *>(4);
|
|
|
|
|
|
|
|
gtpinkexec_t kExec;
|
|
|
|
kExec.pKernel = kernel1;
|
|
|
|
kExec.pCommandQueue = cmdQ1;
|
|
|
|
kernelExecQueue.push_back(kExec);
|
|
|
|
|
|
|
|
kExec.pKernel = kernel2;
|
|
|
|
kExec.pCommandQueue = cmdQ1;
|
|
|
|
kernelExecQueue.push_back(kExec);
|
|
|
|
|
|
|
|
kExec.pKernel = kernel3;
|
|
|
|
kExec.pCommandQueue = cmdQ2;
|
|
|
|
kernelExecQueue.push_back(kExec);
|
|
|
|
|
|
|
|
kExec.pKernel = kernel4;
|
|
|
|
kExec.pCommandQueue = cmdQ2;
|
|
|
|
kernelExecQueue.push_back(kExec);
|
|
|
|
EXPECT_EQ(4u, kernelExecQueue.size());
|
|
|
|
|
|
|
|
gtpinRemoveCommandQueue(cmdQ1);
|
|
|
|
EXPECT_EQ(2u, kernelExecQueue.size());
|
|
|
|
|
|
|
|
gtpinRemoveCommandQueue(cmdQ2);
|
|
|
|
EXPECT_EQ(0u, kernelExecQueue.size());
|
|
|
|
}
|
|
|
|
|
2023-08-03 01:33:48 +08:00
|
|
|
uint32_t gtpinInitTimesCalled = 0u;
|
|
|
|
|
|
|
|
TEST(GTPinInitNotifyTests, givenAvailablePlatformsAndNoEnvironmentVariableSetWhenTryingToNotifyGtpinInitializationThenGtpinDoesNotGetNotified) {
|
|
|
|
platformsImpl->clear();
|
|
|
|
constructPlatform();
|
|
|
|
ASSERT_FALSE(platformsImpl->empty());
|
|
|
|
|
|
|
|
VariableBackup<uint32_t> gtpinCounterBackup(>pinInitTimesCalled, 0u);
|
|
|
|
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { gtpinInitTimesCalled++; return 0; };
|
|
|
|
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
|
|
|
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
|
|
|
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
|
|
|
|
|
|
|
gtPinTryNotifyInit();
|
|
|
|
EXPECT_EQ(0u, gtpinInitTimesCalled);
|
|
|
|
platformsImpl->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GTPinInitNotifyTests, givenNoPlatformsAvailableAndEnvironmentVariableSetWhenTryingToNotifyGtpinInitializationThenGtpinDoesNotGetNotified) {
|
|
|
|
platformsImpl->clear();
|
|
|
|
ASSERT_TRUE(platformsImpl->empty());
|
|
|
|
|
|
|
|
VariableBackup<uint32_t> gtpinCounterBackup(>pinInitTimesCalled, 0u);
|
|
|
|
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
|
|
|
|
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_INSTRUMENTATION", "1"}};
|
|
|
|
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
|
|
|
|
|
|
|
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { gtpinInitTimesCalled++; return 0; };
|
|
|
|
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
|
|
|
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
|
|
|
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
|
|
|
|
|
|
|
gtPinTryNotifyInit();
|
|
|
|
EXPECT_EQ(0u, gtpinInitTimesCalled);
|
|
|
|
platformsImpl->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GTPinInitNotifyTests, givenAvailablePlatformsAndEnvironmentVariableSetWhenTryingToNotifyGtpinInitializationThenGtpinGetsNotified) {
|
|
|
|
platformsImpl->clear();
|
|
|
|
constructPlatform();
|
|
|
|
ASSERT_FALSE(platformsImpl->empty());
|
|
|
|
|
|
|
|
VariableBackup<uint32_t> gtpinCounterBackup(>pinInitTimesCalled, 0u);
|
|
|
|
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
|
|
|
|
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_INSTRUMENTATION", "1"}};
|
|
|
|
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
|
|
|
|
|
|
|
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { gtpinInitTimesCalled++; return 0; };
|
|
|
|
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
|
|
|
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
|
|
|
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
|
|
|
|
|
|
|
gtPinTryNotifyInit();
|
|
|
|
EXPECT_EQ(1u, gtpinInitTimesCalled);
|
|
|
|
platformsImpl->clear();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace ULT
|