|
| 1 | +// Copyright (C) 2024 Intel Corporation |
| 2 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +// See LICENSE.TXT |
| 4 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + |
| 6 | +#include "level_zero/ze_api.h" |
| 7 | +#include "ur_api.h" |
| 8 | +#include "uur/checks.h" |
| 9 | +#include <uur/fixtures.h> |
| 10 | + |
| 11 | +using urLevelZeroKernelNativeHandleTest = uur::urContextTest; |
| 12 | +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urLevelZeroKernelNativeHandleTest); |
| 13 | + |
| 14 | +TEST_P(urLevelZeroKernelNativeHandleTest, OwnedHandleRelease) { |
| 15 | + ze_context_handle_t native_context; |
| 16 | + urContextGetNativeHandle(context, (ur_native_handle_t *)&native_context); |
| 17 | + |
| 18 | + ze_device_handle_t native_device; |
| 19 | + urDeviceGetNativeHandle(device, (ur_native_handle_t *)&native_device); |
| 20 | + |
| 21 | + std::shared_ptr<std::vector<char>> il_binary; |
| 22 | + uur::KernelsEnvironment::instance->LoadSource("foo", il_binary); |
| 23 | + |
| 24 | + auto kernel_name = |
| 25 | + uur::KernelsEnvironment::instance->GetEntryPointNames("foo")[0]; |
| 26 | + |
| 27 | + ze_module_desc_t moduleDesc = {ZE_STRUCTURE_TYPE_MODULE_DESC}; |
| 28 | + moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV; |
| 29 | + moduleDesc.inputSize = il_binary->size(); |
| 30 | + moduleDesc.pInputModule = |
| 31 | + reinterpret_cast<const uint8_t *>(il_binary->data()); |
| 32 | + moduleDesc.pBuildFlags = ""; |
| 33 | + ze_module_handle_t module; |
| 34 | + |
| 35 | + ASSERT_EQ(zeModuleCreate(native_context, native_device, &moduleDesc, |
| 36 | + &module, NULL), |
| 37 | + ZE_RESULT_SUCCESS); |
| 38 | + |
| 39 | + ze_kernel_desc_t kernelDesc = {ZE_STRUCTURE_TYPE_KERNEL_DESC}; |
| 40 | + kernelDesc.pKernelName = kernel_name.c_str(); |
| 41 | + |
| 42 | + ze_kernel_handle_t native_kernel; |
| 43 | + |
| 44 | + ASSERT_EQ(zeKernelCreate(module, &kernelDesc, &native_kernel), |
| 45 | + ZE_RESULT_SUCCESS); |
| 46 | + |
| 47 | + ur_program_native_properties_t pprops = { |
| 48 | + UR_STRUCTURE_TYPE_PROGRAM_NATIVE_PROPERTIES, nullptr, 1}; |
| 49 | + |
| 50 | + ur_program_handle_t program; |
| 51 | + ASSERT_SUCCESS(urProgramCreateWithNativeHandle((ur_native_handle_t)module, |
| 52 | + context, &pprops, &program)); |
| 53 | + |
| 54 | + ur_kernel_native_properties_t kprops = { |
| 55 | + UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES, nullptr, 1}; |
| 56 | + |
| 57 | + ur_kernel_handle_t kernel; |
| 58 | + ASSERT_SUCCESS(urKernelCreateWithNativeHandle( |
| 59 | + (ur_native_handle_t)native_kernel, context, program, &kprops, &kernel)); |
| 60 | + |
| 61 | + ASSERT_SUCCESS(urKernelRelease(kernel)); |
| 62 | + ASSERT_SUCCESS(urProgramRelease(program)); |
| 63 | +} |
0 commit comments