| 1 |
/* |
| 2 |
* Copyright (c) 2025, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
#ifndef __LEVELZERO_INTERFACE_H__ |
| 23 |
#define __LEVELZERO_INTERFACE_H__ |
| 24 |
#include "levelzero_defs.h" |
| 25 |
#include "mos_os.h" |
| 26 |
|
| 27 |
#define L0_PUBLIC_CHK_ZE_STATUS_RETURN(_stmt) \ |
| 28 |
{ \ |
| 29 |
if (_stmt != ZE_RESULT_SUCCESS) \ |
| 30 |
{ \ |
| 31 |
MOS_OS_ASSERTMESSAGE("Level Zero Error %x,", _stmt); \ |
| 32 |
MOS_OS_CHK_STATUS_RETURN(L0Interface::ConvertZeResult(_stmt)) \ |
| 33 |
} \ |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
#define L0_PUBLIC_CHK_ZE_STATUS(_stmt) \ |
| 38 |
{ \ |
| 39 |
if (_stmt != ZE_RESULT_SUCCESS) \ |
| 40 |
{ \ |
| 41 |
MOS_OS_ASSERTMESSAGE("Level Zero Error %x,", _stmt); \ |
| 42 |
} \ |
| 43 |
} |
| 44 |
|
| 45 |
class L0Interface |
| 46 |
{ |
| 47 |
public: |
| 48 |
L0Interface(PMOS_INTERFACE osInterface); |
| 49 |
virtual ~L0Interface(); |
| 50 |
|
| 51 |
static MOS_STATUS Init(L0Interface *l0Interface); |
| 52 |
static MOS_STATUS CreateCmdList(L0Interface *l0Interface, ze_command_list_handle_t &cmdList); |
| 53 |
static MOS_STATUS DestroyCmdList(L0Interface *l0Interface, ze_command_list_handle_t &cmdList); |
| 54 |
static MOS_STATUS CreateFence(L0Interface *l0Interface, ze_fence_handle_t &fence); |
| 55 |
static MOS_STATUS DestroyFence(L0Interface *l0Interface, ze_fence_handle_t &fence); |
| 56 |
static MOS_STATUS WaitFence(L0Interface *l0Interface, ze_fence_handle_t &fence); |
| 57 |
static MOS_STATUS AllocateHostMem(L0Interface *l0Interface, size_t size, void *&ptr); |
| 58 |
static MOS_STATUS FreeHostMem(L0Interface *l0Interface, void *&ptr); |
| 59 |
static MOS_STATUS ExecuteSingle(L0Interface *l0Interface, ze_command_list_handle_t &cmdList, ze_fence_handle_t &fence); |
| 60 |
static MOS_STATUS Execute(L0Interface *l0Interface, std::vector<ze_command_list_handle_t> &cmdLists, ze_fence_handle_t &fence); |
| 61 |
|
| 62 |
MOS_STATUS (*pfnInit) (L0Interface *l0Interface) = Init; |
| 63 |
MOS_STATUS (*pfnCreateCmdList) (L0Interface *l0Interface, ze_command_list_handle_t &cmdList) = CreateCmdList; |
| 64 |
MOS_STATUS (*pfnDestroyCmdList) (L0Interface *l0Interface, ze_command_list_handle_t &cmdList) = DestroyCmdList; |
| 65 |
MOS_STATUS (*pfnCreateFence) (L0Interface *l0Interface, ze_fence_handle_t &fence) = CreateFence; |
| 66 |
MOS_STATUS (*pfnDestroyFence) (L0Interface *l0Interface, ze_fence_handle_t &fence) = DestroyFence; |
| 67 |
MOS_STATUS (*pfnWaitFence) (L0Interface *l0Interface, ze_fence_handle_t &fence) = WaitFence; |
| 68 |
MOS_STATUS (*pfnAllocateHostMem) (L0Interface *l0Interface, size_t size, void *&ptr) = AllocateHostMem; |
| 69 |
MOS_STATUS (*pfnFreeHostMem) (L0Interface *l0Interface, void *&ptr) = FreeHostMem; |
| 70 |
MOS_STATUS (*pfnExecuteSingle) (L0Interface *l0Interface, ze_command_list_handle_t &cmdList, ze_fence_handle_t &fence) = ExecuteSingle; |
| 71 |
MOS_STATUS (*pfnExecute) (L0Interface *l0Interface, std::vector<ze_command_list_handle_t> &cmdLists, ze_fence_handle_t &fence) = Execute; |
| 72 |
|
| 73 |
|
| 74 |
static MOS_STATUS ConvertZeResult(ze_result_t result); |
| 75 |
|
| 76 |
virtual bool Supported() |
| 77 |
{ |
| 78 |
return m_supported; |
| 79 |
} |
| 80 |
virtual bool Initialized() |
| 81 |
{ |
| 82 |
return m_initialized; |
| 83 |
} |
| 84 |
|
| 85 |
protected: |
| 86 |
virtual MOS_STATUS Destroy(); |
| 87 |
virtual MOS_STATUS InitZeFunctions(); |
| 88 |
virtual MOS_STATUS GetDriver() = 0; |
| 89 |
|
| 90 |
protected: |
| 91 |
uint32_t m_zeDdiVersion = 0; |
| 92 |
ZE_LOADER_FUNCTIONS m_zeFunc = {}; |
| 93 |
ze_driver_handle_t m_zeDriver = nullptr; |
| 94 |
ze_device_handle_t m_zeDevice = nullptr; |
| 95 |
ze_context_handle_t m_zeContext = nullptr; |
| 96 |
ze_command_queue_handle_t m_zeCmdQueue = nullptr; |
| 97 |
|
| 98 |
std::atomic<uint32_t> m_ordinal; |
| 99 |
|
| 100 |
PMOS_INTERFACE m_osInterface = nullptr; |
| 101 |
|
| 102 |
bool m_dllLoaded = false; |
| 103 |
bool m_supported = false; |
| 104 |
bool m_initialized = false; |
| 105 |
|
| 106 |
MEDIA_CLASS_DEFINE_END(mhw__LevelZeroInterface) |
| 107 |
}; |
| 108 |
|
| 109 |
#endif |