Debian Codegraph @

media_softlet/agnostic/common/shared/packet/npu_cmd_packet.h

raw
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 __NPU_CMD_PACKET_H__
23 #define __NPU_CMD_PACKET_H__
24 #include "media_cmd_packet.h"
25 #include "levelzero_npu_interface.h"
26
27 class NpuWLContext
28 {
29 public:
30 NpuWLContext(uint32_t timeoutMs) : m_timeoutMs(timeoutMs) {};
31 std::vector<ze_command_list_handle_t>& CmdList()
32 {
33 return m_cmdLists;
34 }
35 ze_fence_handle_t& Fence()
36 {
37 return m_fence;
38 }
39 std::condition_variable& Condition()
40 {
41 return m_cv;
42 }
43 std::mutex& Mutex()
44 {
45 return m_mtx;
46 }
47 std::thread& Thread()
48 {
49 return m_initThread;
50 }
51 bool& Initialized()
52 {
53 return m_initialized;
54 }
55 bool& Failed()
56 {
57 return m_failed;
58 }
59 uint32_t GetTimeoutMs()
60 {
61 return m_timeoutMs;
62 }
63
64 private:
65 //NpuWlContext cannot be copied for it contains condition_variable and mutex
66 std::vector<ze_command_list_handle_t> m_cmdLists = {};
67 ze_fence_handle_t m_fence = nullptr;
68 bool m_initialized = false;
69 bool m_failed = false;
70 std::condition_variable m_cv = {};
71 std::mutex m_mtx = {};
72 uint32_t m_timeoutMs = 0;
73 std::thread m_initThread;
74 };
75
76 struct NPU_PACKET_PARAM
77 {
78 NpuWLContext *context = nullptr;
79 };
80
81 class NpuCmdPackageSpecific : public CmdPackage
82 {
83 public:
84 NpuCmdPackageSpecific(L0NpuInterface *npuInterface, NpuWLContext *npuWLContext) : m_npuInterface(npuInterface), m_npuWLContext(npuWLContext) {};
85 virtual MOS_STATUS Wait() override;
86 virtual MOS_STATUS Submit() override;
87 virtual std::unique_ptr<CmdPackage> Clone() const override;
88 virtual bool IsAsyncExecute() override { return true; };
89
90 private:
91 L0NpuInterface *m_npuInterface = nullptr;
92 NpuWLContext *m_npuWLContext = nullptr;
93 };
94
95 class NpuCmdPacket : virtual public CmdPacket
96 {
97 public:
98 NpuCmdPacket(MediaTask *task, PMOS_INTERFACE osInterface);
99
100 virtual ~NpuCmdPacket();
101
102 MOS_STATUS Init() override;
103
104 MOS_STATUS Destroy() override;
105
106 MOS_STATUS Prepare() override;
107
108 MOS_STATUS Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase = otherPacket) override; // commandBuffer is no need for npu packet
109
110 MOS_STATUS SetGraphParam(NPU_PACKET_PARAM &npuParam);
111
112 protected:
113 NPU_PACKET_PARAM m_npuParam = {};
114 L0NpuInterface *m_npuInterface = nullptr;
115
116 MEDIA_CLASS_DEFINE_END(NpuCmdPacket)
117 };
118 #endif