Debian Codegraph @

media_softlet/agnostic/common/vp/hal/feature_manager/vp_graph_manager.h

raw
1 /* Copyright (c) 2025, Intel Corporation
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 */
21 //!
22 //! \file vp_graph_manager.h
23 //! \brief The header file of the base class of graph set
24 //! \details The graph set will include graph generation from binary.
25 //! It's responsible for setting up HW states and generating the SFC
26 //! commands.
27 //!
28 #ifndef __VP_GRAPH_MANAGER_H__
29 #define __VP_GRAPH_MANAGER_H__
30
31 #include "vp_pipeline_common.h"
32 #include "vp_allocator.h"
33 #include "vp_graphset.h"
34 #include "vp_ai_kernel_pipe.h"
35 #include "levelzero_npu_interface.h"
36 #include "npu_cmd_packet.h"
37
38 namespace vp
39 {
40
41 #define GRAPH_PACKAGE_INITIALIZE_TIMEOUT_MS 100 // first frame need initialize graph timing
42
43 class GraphPackage
44 {
45 public:
46 GraphPackage() : m_npuWLContext(GRAPH_PACKAGE_INITIALIZE_TIMEOUT_MS) {};
47 NpuWLContext &GetNpuWLContext()
48 {
49 return m_npuWLContext;
50 }
51 std::map<SurfaceType, PVP_SURFACE> &IntermiedateSurfaces()
52 {
53 return m_intermediateSurfaces;
54 }
55
56 private:
57 // GraphPackage cannot be copied for it contains a non-copiable member m_npuWLContext
58 std::map<SurfaceType, PVP_SURFACE> m_intermediateSurfaces = {};
59 NpuWLContext m_npuWLContext;
60 };
61
62 class VpGraphManager
63 {
64 public:
65 VpGraphManager(VpGraphSet *graphset, PMOS_INTERFACE osInterface, VpAllocator *allocator);
66 ~VpGraphManager() { Destroy(); };
67
68 MOS_STATUS GetGraphPackage(std::vector<AI_SINGLE_NPU_GRAPH_SETTING> &graphSettings, SwFilterPipe &executingPipe, GraphPackage *&graphPackage);
69
70 private:
71 MOS_STATUS Destroy();
72
73 private:
74 std::map<VpGraphIDList, GraphPackage> m_graphPackages = {};
75 VpGraphSet *m_graphset = nullptr;
76 PMOS_INTERFACE m_osInterface = nullptr;
77 L0NpuInterface *m_npuInterface = nullptr;
78 VpAllocator *m_allocator = nullptr;
79
80 MEDIA_CLASS_DEFINE_END(vp__VpGraphManager)
81 };
82
83 class InitGraphListCmdPackage : public CmdPackage
84 {
85 public:
86 InitGraphListCmdPackage(L0NpuInterface *npuInterface, GraphPackage *graphPackage) : m_npuInterface(npuInterface), m_graphPackage(graphPackage) {};
87 virtual MOS_STATUS Submit();
88 virtual MOS_STATUS Wait() { return MOS_STATUS_SUCCESS; };
89 virtual std::unique_ptr<CmdPackage> Clone() const;
90 virtual bool Releaseable() override { return m_releaseable; };
91 virtual MOS_STATUS AddGraphHandle(GraphHandle *grapHandle)
92 {
93 m_graphHandles.push_back(grapHandle);
94 return MOS_STATUS_SUCCESS;
95 }
96 virtual MOS_STATUS AddSingleLayerGraphArgs(std::vector<void *> &singleLayerGraphArgs)
97 {
98 m_multiLayerGraphArgs.push_back(singleLayerGraphArgs);
99 return MOS_STATUS_SUCCESS;
100 }
101
102 private:
103 L0NpuInterface *m_npuInterface = nullptr;
104 GraphPackage *m_graphPackage = nullptr;
105 std::vector<GraphHandle *> m_graphHandles = {};
106 std::vector<std::vector<void *>> m_multiLayerGraphArgs = {};
107 bool m_releaseable = false;
108 };
109
110 } // namespace vp
111
112 #endif //__VP_GRAPH_SET_H__