| 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 |
//! |
| 23 |
//! \file npu_cmd_packet.cpp |
| 24 |
//! \brief render packet which used in by mediapipline. |
| 25 |
//! \details render packet provide the structures and generate the cmd buffer which mediapipline will used. |
| 26 |
//! |
| 27 |
|
| 28 |
#include "npu_cmd_packet.h" |
| 29 |
#include "levelzero_npu_interface.h" |
| 30 |
#include "media_utils.h" |
| 31 |
|
| 32 |
#define NPU_CHK_NULL_RETURN(_ptr) \ |
| 33 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_HW, MOS_CODEC_SUBCOMP_PUBLIC, _ptr) |
| 34 |
|
| 35 |
#define NPU_CHK_STATUS_RETURN(_stmt) \ |
| 36 |
MOS_CHK_STATUS_RETURN(MOS_COMPONENT_HW, MOS_CODEC_SUBCOMP_PUBLIC, _stmt) |
| 37 |
|
| 38 |
NpuCmdPacket::NpuCmdPacket(MediaTask *task, PMOS_INTERFACE osInterface) : CmdPacket(task) |
| 39 |
{ |
| 40 |
m_osInterface = osInterface; |
| 41 |
if (osInterface) |
| 42 |
{ |
| 43 |
m_npuInterface = osInterface->npuInterface; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
NpuCmdPacket::~NpuCmdPacket() |
| 48 |
{ |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
MOS_STATUS NpuCmdPacket::Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase) |
| 53 |
{ |
| 54 |
//commandBuffer is no need for npu packet, so it could be nullptr |
| 55 |
NPU_CHK_NULL_RETURN(m_npuInterface); |
| 56 |
NPU_CHK_NULL_RETURN(m_npuParam.context); |
| 57 |
NPU_CHK_NULL_RETURN(m_osInterface); |
| 58 |
NPU_CHK_NULL_RETURN(m_osInterface->pfnSubmitPackage); |
| 59 |
|
| 60 |
NpuCmdPackageSpecific cmdPackage(m_npuInterface, m_npuParam.context); |
| 61 |
|
| 62 |
NPU_CHK_STATUS_RETURN(m_osInterface->pfnSubmitPackage(m_osInterface, cmdPackage)); |
| 63 |
|
| 64 |
return MOS_STATUS_SUCCESS; |
| 65 |
} |
| 66 |
|
| 67 |
MOS_STATUS NpuCmdPacket::Init() |
| 68 |
{ |
| 69 |
NPU_CHK_NULL_RETURN(m_npuInterface); |
| 70 |
|
| 71 |
return MOS_STATUS_SUCCESS; |
| 72 |
} |
| 73 |
|
| 74 |
MOS_STATUS NpuCmdPacket::Prepare() |
| 75 |
{ |
| 76 |
return MOS_STATUS_SUCCESS; |
| 77 |
} |
| 78 |
|
| 79 |
MOS_STATUS NpuCmdPacket::SetGraphParam(NPU_PACKET_PARAM &npuParam) |
| 80 |
{ |
| 81 |
m_npuParam = npuParam; |
| 82 |
|
| 83 |
return MOS_STATUS_SUCCESS; |
| 84 |
} |
| 85 |
|
| 86 |
MOS_STATUS NpuCmdPacket::Destroy() |
| 87 |
{ |
| 88 |
NPU_CHK_STATUS_RETURN(CmdPacket::Destroy()); |
| 89 |
|
| 90 |
return MOS_STATUS_SUCCESS; |
| 91 |
} |
| 92 |
|
| 93 |
MOS_STATUS NpuCmdPackageSpecific::Wait() |
| 94 |
{ |
| 95 |
NPU_CHK_NULL_RETURN(m_npuWLContext); |
| 96 |
NPU_CHK_NULL_RETURN(m_npuWLContext->Fence()); |
| 97 |
NPU_CHK_NULL_RETURN(m_npuInterface); |
| 98 |
NPU_CHK_NULL_RETURN(m_npuInterface->pfnWaitFence) |
| 99 |
|
| 100 |
NPU_CHK_STATUS_RETURN(m_npuInterface->pfnWaitFence(m_npuInterface, m_npuWLContext->Fence())); |
| 101 |
|
| 102 |
return MOS_STATUS_SUCCESS; |
| 103 |
} |
| 104 |
|
| 105 |
MOS_STATUS NpuCmdPackageSpecific::Submit() |
| 106 |
{ |
| 107 |
NPU_CHK_NULL_RETURN(m_npuInterface); |
| 108 |
NPU_CHK_NULL_RETURN(m_npuWLContext); |
| 109 |
NPU_CHK_NULL_RETURN(m_npuInterface->pfnExecute); |
| 110 |
|
| 111 |
std::unique_lock<std::mutex> lock(m_npuWLContext->Mutex()); |
| 112 |
if (m_npuWLContext->Condition().wait_for(lock, std::chrono::milliseconds(m_npuWLContext->GetTimeoutMs()), [=] { return m_npuWLContext->Initialized() || m_npuWLContext->Failed(); })) |
| 113 |
{ |
| 114 |
if (m_npuWLContext->Failed()) |
| 115 |
{ |
| 116 |
MEDIA_ASSERTMESSAGE("Graph Package Initialize Failed, Cannot Continue to Submit Graph List to Queue"); |
| 117 |
return MOS_STATUS_UNINITIALIZED; |
| 118 |
} |
| 119 |
} |
| 120 |
else |
| 121 |
{ |
| 122 |
MEDIA_ASSERTMESSAGE("Timeout %d ms reached, Graph Package still not finish Initialization", m_npuWLContext->GetTimeoutMs()); |
| 123 |
return MOS_STATUS_UNINITIALIZED; |
| 124 |
} |
| 125 |
NPU_CHK_STATUS_RETURN(m_npuInterface->pfnExecute(m_npuInterface, m_npuWLContext->CmdList(), m_npuWLContext->Fence())); |
| 126 |
|
| 127 |
return MOS_STATUS_SUCCESS; |
| 128 |
} |
| 129 |
|
| 130 |
std::unique_ptr<CmdPackage> NpuCmdPackageSpecific::Clone() const |
| 131 |
{ |
| 132 |
return std::make_unique<NpuCmdPackageSpecific>(*this); |
| 133 |
} |