| 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_NPU_INTERFACE_H__ |
| 23 |
#define __LEVELZERO_NPU_INTERFACE_H__ |
| 24 |
#include "levelzero_interface.h" |
| 25 |
|
| 26 |
#define GRAPH_HANDLE_INITIALIZE_TIMEOUT_MS 20 |
| 27 |
|
| 28 |
class GraphHandle |
| 29 |
{ |
| 30 |
public: |
| 31 |
GraphHandle() : m_timeoutMs(GRAPH_HANDLE_INITIALIZE_TIMEOUT_MS) {}; |
| 32 |
ze_graph_handle_t &Graph() |
| 33 |
{ |
| 34 |
return m_graph; |
| 35 |
} |
| 36 |
std::condition_variable &Condition() |
| 37 |
{ |
| 38 |
return m_cv; |
| 39 |
} |
| 40 |
std::mutex &Mutex() |
| 41 |
{ |
| 42 |
return m_mtx; |
| 43 |
} |
| 44 |
std::thread &Thread() |
| 45 |
{ |
| 46 |
return m_initThread; |
| 47 |
} |
| 48 |
bool &Initialized() |
| 49 |
{ |
| 50 |
return m_initialized; |
| 51 |
} |
| 52 |
bool &Failed() |
| 53 |
{ |
| 54 |
return m_failed; |
| 55 |
} |
| 56 |
uint32_t GetTimeoutMs() |
| 57 |
{ |
| 58 |
return m_timeoutMs; |
| 59 |
} |
| 60 |
|
| 61 |
private: |
| 62 |
ze_graph_handle_t m_graph = nullptr; |
| 63 |
bool m_initialized = false; |
| 64 |
bool m_failed = false; |
| 65 |
std::condition_variable m_cv = {}; |
| 66 |
std::mutex m_mtx = {}; |
| 67 |
uint32_t m_timeoutMs = 0; |
| 68 |
std::thread m_initThread; |
| 69 |
}; |
| 70 |
|
| 71 |
class L0NpuInterface : virtual public L0Interface |
| 72 |
{ |
| 73 |
public: |
| 74 |
L0NpuInterface(PMOS_INTERFACE osInterface); |
| 75 |
|
| 76 |
virtual ~L0NpuInterface(); |
| 77 |
|
| 78 |
static MOS_STATUS BuildGraph(L0NpuInterface *npuInterface, uint8_t *blob, uint32_t size, ze_graph_handle_t &graph); |
| 79 |
static MOS_STATUS AppendGraph(L0NpuInterface *npuInterface, ze_command_list_handle_t &cmdList, ze_graph_handle_t &graph, std::vector<void *> &args); |
| 80 |
static MOS_STATUS DestroyGraph(L0NpuInterface *npuInterface, ze_graph_handle_t &graph); |
| 81 |
|
| 82 |
MOS_STATUS(*pfnBuildGraph) (L0NpuInterface *npuInterface, uint8_t *blob, uint32_t size, ze_graph_handle_t &graph) = BuildGraph; |
| 83 |
MOS_STATUS (*pfnAppendGraph) (L0NpuInterface *npuInterface, ze_command_list_handle_t &cmdList, ze_graph_handle_t &graph, std::vector<void *> &args) = AppendGraph; |
| 84 |
MOS_STATUS(*pfnDestroyGraph) (L0NpuInterface *npuInterface, ze_graph_handle_t &graph) = DestroyGraph; |
| 85 |
|
| 86 |
protected: |
| 87 |
virtual MOS_STATUS GetDriver() override; |
| 88 |
|
| 89 |
ze_graph_dditable_ext_t *m_zeGraphDdiTable = nullptr; |
| 90 |
|
| 91 |
MEDIA_CLASS_DEFINE_END(mhw__LevelZeroNpuInterface) |
| 92 |
}; |
| 93 |
|
| 94 |
#endif |