• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.8
    All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    SyncPortHelper.hpp
    Go to the documentation of this file.
    1
    2//
    3// Notice
    4// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
    5// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
    6// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
    7// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
    8//
    9// NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
    10// information or for any infringement of patents or other rights of third parties that may
    11// result from its use. No license is granted by implication or otherwise under any patent
    12// or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
    13// expressly authorized by NVIDIA. Details are subject to change without notice.
    14// This code supersedes and replaces all information previously supplied.
    15// NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
    16// components in life support devices or systems without express written approval of
    17// NVIDIA CORPORATION & AFFILIATES.
    18//
    19// SPDX-FileCopyrightText: Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    20// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
    21//
    22// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
    23// property and proprietary rights in and to this material, related
    24// documentation and any modifications thereto. Any use, reproduction,
    25// disclosure or distribution of this material and related documentation
    26// without an express license agreement from NVIDIA CORPORATION or
    27// its affiliates is strictly prohibited.
    28//
    30
    31#ifndef DW_FRAMEWORK_SYNCPORTHELPER_HPP_
    32#define DW_FRAMEWORK_SYNCPORTHELPER_HPP_
    33
    34#include <dw/core/container/HashContainer.hpp>
    36
    37namespace dw
    38{
    39namespace framework
    40{
    41
    42using CycleCountFetcher = dw::core::Function<uint32_t(void)>;
    43
    44// These classes are used to parse and handle indexed packets.
    45// TODO (ajayawardane) Move this logic into a separate port and change
    46// the port type for each pipelined node.
    48{
    49public:
    51 : m_dataSynced(false)
    52 , m_syncCount(0U)
    53 , m_dataOffset(0U)
    54 , m_syncCountRetriever(nullptr)
    55 {
    56 }
    57 void setSyncCount(uint32_t index);
    58 virtual void parseDataSynced(const ChannelParams& params);
    60 dwStatus setSyncRetriever(const CycleCountFetcher& func);
    61
    62protected:
    64 void stampSyncCount(uint32_t& syncCountOut) const;
    65
    67 uint32_t m_syncCount;
    68 uint32_t m_dataOffset;
    70};
    71
    72// There are no specific requirements on the template type
    73// coverity[autosar_cpp14_a14_1_1_violation]
    74template <typename T>
    76{
    77public:
    80 {
    81 }
    82
    83protected:
    85 {
    86 auto syncPacket = genericData.template getData<SyncedPacketPayload>();
    87
    88 if (!syncPacket)
    89 {
    90 throw Exception(DW_INTERNAL_ERROR, "SyncPortHelperOutput extractInternalPacket: packet type mismatch");
    91 }
    92
    93 auto packet = syncPacket->data.template getData<T>();
    94 if (!packet)
    95 {
    96 throw Exception(DW_INTERNAL_ERROR, "SyncPortHelperOutput extractInternalPacket: failed to extract underlying data");
    97 }
    98
    99 m_syncPacketBuf[packet] = syncPacket;
    100 return packet;
    101 }
    102
    104 {
    105 SyncedPacketPayload* syncPacket = m_syncPacketBuf[frame];
    106 if (!syncPacket)
    107 {
    108 throw Exception(DW_INTERNAL_ERROR, "SyncPortHelperOutput getSyncPacket: sync packet not found in packet buffer");
    109 }
    110
    111 stampSyncCount(syncPacket->syncCount);
    112
    113 return syncPacket;
    114 }
    115
    116 void parseDataSynced(const ChannelParams& params) override
    117 {
    119 if (isDataSynced())
    120 {
    121 m_syncPacketBuf = HeapHashMap<T*, SyncedPacketPayload*>(params.getPoolCapacity());
    122 }
    123 }
    124
    125private:
    126 HeapHashMap<T*, SyncedPacketPayload*> m_syncPacketBuf;
    127};
    128
    129// There are no specific requirements on the template type
    130// coverity[autosar_cpp14_a14_1_1_violation]
    131template <typename T>
    133{
    134public:
    137 , m_bufferedPacket()
    138 , m_dataBuffered(false)
    139 {
    140 }
    141
    142protected:
    144 {
    145 if (m_dataBuffered)
    146 {
    147 return true;
    148 }
    149 return false;
    150 }
    151
    153 {
    154 if (!isPacketBuffered())
    155 {
    156 return false;
    157 }
    158
    159 auto packet = m_bufferedPacket.template getData<SyncedPacketPayload>();
    160
    161 if (!packet)
    162 {
    163 throw Exception(DW_INTERNAL_ERROR, "SyncPortHelperInput isValidPacketBuffered: packet type mistmatch");
    164 }
    165 return validatePacket(*packet);
    166 }
    167
    169 {
    170 m_dataBuffered = false;
    171 return m_bufferedPacket;
    172 }
    173
    175 {
    176 auto syncPacket = genericData.template getData<SyncedPacketPayload>();
    177
    178 if (!syncPacket)
    179 {
    180 throw Exception(DW_INTERNAL_ERROR, "SyncPortHelperInput extractInternalPacket: packet type mistmatch");
    181 }
    182
    183 if (validatePacket(*syncPacket))
    184 {
    185 return syncPacket->data.template getData<T>();
    186 }
    187 else
    188 {
    189 m_bufferedPacket = genericData;
    190 m_dataBuffered = true;
    191 return nullptr;
    192 }
    193 }
    194
    195private:
    196 bool validatePacket(SyncedPacketPayload& pkt)
    197 {
    198 // If a producer - consumer pair are across pipeline boundaries, they will
    199 // have non-zero data offsets; however, connections from that producer to
    200 // consumers not across the pipeline boundary must also have sync ports
    201 // (since if a producer is sync, all consumers must be sync). This check
    202 // is in place for cases where producer -> consumer pairs are in the same
    203 // pipeline boundary, and is basically a no-op for synchronization.
    204 if (m_dataOffset == 0)
    205 {
    206 return true;
    207 }
    208
    209 uint32_t syncCount = (m_syncCountRetriever) ? m_syncCountRetriever() : m_syncCount;
    210
    211 // Check if the packet is valid for consumption. The packet sync count represents
    212 // when the packet was produced and the m_syncCount is the current sync count.
    213 // The data offset is the offset between when it was produced and when it is
    214 // available for consumption.
    215 int validOffset = static_cast<int>(syncCount - pkt.syncCount - m_dataOffset);
    216
    217 if (validOffset >= 0)
    218 {
    219 return true;
    220 }
    221
    222 return false;
    223 }
    224
    225 GenericData m_bufferedPacket;
    226 bool m_dataBuffered;
    227};
    228
    229} // namespace framework
    230} // namespace dw
    231
    232#endif // DW_FRAMEWORK_SYNCPORTHELPER_HPP_
    T * extractInternalPacket(GenericData genericData)
    T * extractInternalPacket(GenericData genericData)
    SyncedPacketPayload * getSyncPacket(T *frame)
    void parseDataSynced(const ChannelParams &params) override
    uint32_t ChannelPacketTypeID
    dw::core::Function< uint32_t(void)> CycleCountFetcher
    Definition: Exception.hpp:47
    dwStatus setSyncRetriever(const CycleCountFetcher &func)
    ChannelPacketTypeID getNewPacketID(ChannelPacketTypeID packetTypeID)
    CycleCountFetcher m_syncCountRetriever
    void setSyncCount(uint32_t index)
    virtual void parseDataSynced(const ChannelParams &params)
    void stampSyncCount(uint32_t &syncCountOut) const
    人人超碰97caoporen国产