• <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
    IChannelPacket.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) 2020-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_ICHANNEL_PACKET_HPP_
    32#define DW_FRAMEWORK_ICHANNEL_PACKET_HPP_
    33
    34#include <typeinfo>
    35#include <cstddef>
    36#include <dwcgf/Types.hpp>
    39#include <nvscibuf.h>
    40#include <nvscisync.h>
    41#include <dw/core/language/Function.hpp>
    42
    43namespace dw
    44{
    45namespace framework
    46{
    47
    48// Virtual functions for the channel to interact with packets opaquely
    50{
    51public:
    52 // Enable ownership via this interface
    53 virtual ~IChannelPacket() = default;
    54 // Deserialize metadata at provided pointer
    56
    57 // Callbacks needed for socket channel
    59 {
    60 public:
    61 // Get a pointer to the payload
    62 virtual uint8_t* getBuffer() = 0;
    63 // Get size of serialized data buffer
    64 virtual size_t getBufferSize() = 0;
    65 // Serialize the packet to internal buffer
    66 virtual size_t serialize() = 0;
    67 // Deserialize the packet from internal buffer
    68 virtual void deserialize(size_t) = 0;
    69 };
    70
    71 // Callbacks needed for nvsci channel
    73 {
    74 public:
    75 // Init time callbacks
    76
    77 // Get size of the metadata
    78 virtual uint32_t getNumBuffers() const = 0;
    79 // Get size of serialized data buffer
    80 virtual void fillNvSciBufAttributes(uint32_t bufferIndex, NvSciBufAttrList& attrList) const = 0;
    81 // Initialize the packet from the given NvSciBufObjs
    82 virtual void initializeFromNvSciBufObjs(dw::core::span<NvSciBufObj> bufs) = 0;
    83
    84 // Runtime callbacks
    85
    86 // Pack the API data type into the NvSciBufObjs
    87 virtual void pack() = 0;
    88 // Unpack the API data type from the NvSciBufObjs
    89 virtual void unpack() = 0;
    90 };
    91
    92 // Get interface for channel socket, throws if not enabled or supported
    94 {
    95 if (auto* ptr = dynamic_cast<SocketCallbacks*>(this))
    96 {
    97 return *ptr;
    98 }
    99 else
    100 {
    101 throw Exception(DW_NOT_SUPPORTED, "This packet interface does not implement socket callbacks");
    102 }
    103 }
    104
    106 {
    107 if (auto* ptr = dynamic_cast<NvSciCallbacks*>(this))
    108 {
    109 return *ptr;
    110 }
    111 else
    112 {
    113 throw Exception(DW_NOT_SUPPORTED, "This packet interface does not implement nvsci callbacks");
    114 }
    115 }
    116};
    117
    118// TODO(chale): this should be made private to the framework once external entities no longer create
    119// Channel packets
    121{
    122public:
    124 : m_typeSize(typeSize)
    125 , m_buffer(new uint8_t[m_typeSize]())
    126 , m_data{m_buffer.get(), m_typeSize}
    127 {
    128 }
    129
    131 {
    132 return m_data;
    133 }
    134
    135protected:
    137 std::unique_ptr<uint8_t[]> m_buffer;
    139};
    140
    142{
    143public:
    144 ChannelPacketDefault(size_t typeSize)
    145 : ChannelPacketDefaultBase(typeSize)
    146 {
    147 }
    148
    149 uint8_t* getBuffer() final
    150 {
    151 return m_buffer.get();
    152 }
    153
    154 size_t getBufferSize() final
    155 {
    156 return m_typeSize;
    157 }
    158
    159 size_t serialize() final
    160 {
    161 return m_typeSize;
    162 }
    163
    164 void deserialize(size_t) final
    165 {
    166 }
    167};
    168
    170{
    171 static constexpr char LOG_TAG[] = "ChannelNvSciPacketDefault";
    172
    173public:
    175 : m_typeSize{typeSize}
    176 {
    177 }
    178
    179 uint32_t getNumBuffers() const final
    180 {
    181 return 1U;
    182 }
    183
    184 void fillNvSciBufAttributes(uint32_t bufferIndex, NvSciBufAttrList& attrList) const final
    185 {
    186 if (bufferIndex != 0U)
    187 {
    188 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciPacketDefault: invalid buffer index");
    189 }
    190
    191 fillCpuPacketDataAttributes(attrList);
    192 }
    193
    194 void initializeFromNvSciBufObjs(dw::core::span<NvSciBufObj> bufs)
    195 {
    196 if (bufs.size() != getNumBuffers())
    197 {
    198 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciPacketDefault: wrong number of buffers passed");
    199 }
    200
    201 FRWK_CHECK_NVSCI_ERROR(NvSciBufObjGetCpuPtr(bufs[0], &m_data));
    202 }
    203
    204 void pack() final
    205 {
    206 // noop
    207 }
    208
    209 void unpack() final
    210 {
    211 // noop
    212 }
    213
    215 {
    216 return GenericData(m_data, m_typeSize);
    217 }
    218
    219private:
    220 void fillCpuPacketDataAttributes(NvSciBufAttrList& output) const
    221 {
    222 const NvSciBufType bufferType = NvSciBufType_RawBuffer;
    223 const bool cpuAccessFlag = true;
    224 const uint64_t rawAlign = 4;
    225 const NvSciBufAttrValAccessPerm permissions = NvSciBufAccessPerm_ReadWrite;
    226
    227 dw::core::Array<NvSciBufAttrKeyValuePair, 5> rawBufferAttributes =
    228 {{{NvSciBufGeneralAttrKey_Types, &bufferType, sizeof(bufferType)},
    229 {NvSciBufGeneralAttrKey_NeedCpuAccess, &cpuAccessFlag, sizeof(cpuAccessFlag)},
    230 {NvSciBufGeneralAttrKey_RequiredPerm, &permissions, sizeof(permissions)},
    231 {NvSciBufRawBufferAttrKey_Align, &rawAlign, sizeof(rawAlign)},
    232 {NvSciBufRawBufferAttrKey_Size, &m_typeSize, sizeof(m_typeSize)}}};
    233
    234 FRWK_CHECK_NVSCI_ERROR(NvSciBufAttrListSetAttrs(output,
    235 rawBufferAttributes.data(),
    236 rawBufferAttributes.size()));
    237 }
    238
    239 size_t m_typeSize{};
    240 void* m_data{};
    241};
    242
    244{
    245public:
    246 virtual std::unique_ptr<IChannelPacket> makePacket(ChannelPacketTypeID id, ChannelType channelType, GenericData ref) = 0;
    247};
    248using ChannelPacketFactoryPtr = std::shared_ptr<IChannelPacketFactory>;
    249
    250} // namespace framework
    251} // namespace dw
    252
    253#endif // DW_FRAMEWORK_ICHANNEL_PACKET_HPP_
    #define FRWK_CHECK_NVSCI_ERROR(e)
    Definition: Exception.hpp:373
    void initializeFromNvSciBufObjs(dw::core::span< NvSciBufObj > bufs)
    void fillNvSciBufAttributes(uint32_t bufferIndex, NvSciBufAttrList &attrList) const final
    std::unique_ptr< uint8_t[]> m_buffer
    virtual std::unique_ptr< IChannelPacket > makePacket(ChannelPacketTypeID id, ChannelType channelType, GenericData ref)=0
    virtual void initializeFromNvSciBufObjs(dw::core::span< NvSciBufObj > bufs)=0
    virtual uint32_t getNumBuffers() const =0
    virtual void fillNvSciBufAttributes(uint32_t bufferIndex, NvSciBufAttrList &attrList) const =0
    SocketCallbacks & getSocketCallbacks()
    virtual GenericData getGenericData()=0
    virtual ~IChannelPacket()=default
    NvSciCallbacks & getNvSciCallbacks()
    std::shared_ptr< IChannelPacketFactory > ChannelPacketFactoryPtr
    enum ChannelType :uint8_t { DW_CHANNEL_TYPE_SHMEM_LOCAL=0, DW_CHANNEL_TYPE_SHMEM_REMOTE=1, DW_CHANNEL_TYPE_EGLSTREAM=2, DW_CHANNEL_TYPE_SOCKET=3, DW_CHANNEL_TYPE_DDS=4, DW_CHANNEL_TYPE_NVSCI=5, } ChannelType
    uint32_t ChannelPacketTypeID
    Definition: Exception.hpp:47
    人人超碰97caoporen国产