• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.10
    All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    Buffer.hpp
    Go to the documentation of this file.
    1
    2// This code contains NVIDIA Confidential Information and is disclosed
    3// under the Mutual Non-Disclosure Agreement.
    4//
    5// Notice
    6// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
    7// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
    8// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
    9// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
    10//
    11// NVIDIA Corporation assumes no responsibility for the consequences of use of such
    12// information or for any infringement of patents or other rights of third parties that may
    13// result from its use. No license is granted by implication or otherwise under any patent
    14// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless
    15// expressly authorized by NVIDIA. Details are subject to change without notice.
    16// This code supersedes and replaces all information previously supplied.
    17// NVIDIA Corporation products are not authorized for use as critical
    18// components in life support devices or systems without express written approval of
    19// NVIDIA Corporation.
    20//
    21// Copyright (c) 2021-2022 NVIDIA Corporation. All rights reserved.
    22//
    23// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
    24// rights in and to this software and related documentation and any modifications thereto.
    25// Any use, reproduction, disclosure or distribution of this software and related
    26// documentation without an express license agreement from NVIDIA Corporation is
    27// strictly prohibited.
    28//
    30
    31#ifndef DW_FRAMEWORK_BUFFER_HPP_
    32#define DW_FRAMEWORK_BUFFER_HPP_
    33
    34#include <cstddef>
    35#include <nvscibuf.h>
    36#include <dw/core/language/Optional.hpp>
    37#include <dw/cuda/misc/DevicePtr.hpp>
    38
    39namespace dw
    40{
    41namespace framework
    42{
    43
    44enum class BufferBackendType : uint32_t
    45{
    46 CPU = 0,
    47 CUDA = 1,
    48 // Add others as appropriate
    49};
    50
    51using BufferFlags = uint32_t;
    52
    54{
    55 return (static_cast<uint32_t>(flags) & (1U << static_cast<uint32_t>(type))) != 0U;
    56}
    57
    59{
    60 flags |= (1U << static_cast<uint32_t>(type));
    61}
    62
    64{
    66 size_t byteSize;
    67};
    68
    70{
    71public:
    72 static constexpr char LOG_TAG[] = "Buffer";
    73
    75
    76 virtual ~BufferBase() = default;
    77
    79
    80 virtual void bindNvSciBufObj(NvSciBufObj bufObj);
    81
    82 void fillNvSciBufAttrs(NvSciBufAttrList attrList) const;
    83
    84 NvSciBufObj getNvSci();
    85
    86protected:
    88 NvSciBufObj m_bufObj{};
    89};
    90
    91class BufferCPU final : public BufferBase
    92{
    93public:
    94 explicit BufferCPU(BufferProperties properties);
    95
    96 void fillSpecificAttributes(NvSciBufAttrList attrList) const;
    97
    98 void bindNvSciBufObj(NvSciBufObj bufObj) override;
    99
    100 void* getCpuPtr(size_t offset);
    101
    102private:
    103 void* m_ptr;
    104};
    105
    106// BufferCUDA class encapsulates API mapping operations on single nvscibuf for cuda.
    107// @note - If a buffer needs to be mapped for multiple cuda devices, multiple instances of this class
    108// should be used and the appropriate device must be set as current before calling into each instance.
    109class BufferCUDA final : public BufferBase
    110{
    111public:
    112 explicit BufferCUDA(BufferProperties properties);
    113
    114 ~BufferCUDA() final;
    115
    116 void fillSpecificAttributes(NvSciBufAttrList attrList) const;
    117
    118 void bindNvSciBufObj(NvSciBufObj bufObj) override;
    119
    120 core::DevicePtr<void> getCudaPtr(size_t offset);
    121
    122private:
    123 cudaExternalMemory_t m_cudaHandle{};
    124 void* m_ptr{};
    125};
    126
    127// Buffer class encapsulates API mapping operations on single nvscibuf.
    128// @note - If a buffer needs to be mapped for multiple cuda devices, multiple instances of this class
    129// should be used and the appropriate device must be set as current before calling into each instance.
    130class Buffer final : public BufferBase
    131{
    132
    133public:
    134 explicit Buffer(BufferProperties properties);
    135
    136 void bindNvSciBufObj(NvSciBufObj bufObj) override;
    137
    138 void fillNvSciBufAttrs(NvSciBufAttrList attrList) const;
    139
    140 void* getCpuPtr(size_t offset);
    141
    142 core::DevicePtr<void> getCudaPtr(size_t offset);
    143
    144private:
    145 dw::core::Optional<BufferCPU> m_bufferCpu{};
    146 dw::core::Optional<BufferCUDA> m_bufferCuda{};
    147};
    148
    149} // namespace framework
    150} // namespace dw
    151
    152#endif // DW_FRAMEWORK_BUFFER_HPP_
    const BufferProperties & getProperties() const
    virtual ~BufferBase()=default
    void fillNvSciBufAttrs(NvSciBufAttrList attrList) const
    NvSciBufObj m_bufObj
    Definition: Buffer.hpp:88
    BufferBase(BufferProperties properties)
    virtual void bindNvSciBufObj(NvSciBufObj bufObj)
    static constexpr char LOG_TAG[]
    Definition: Buffer.hpp:72
    BufferProperties m_properties
    Definition: Buffer.hpp:87
    BufferCPU(BufferProperties properties)
    void * getCpuPtr(size_t offset)
    void bindNvSciBufObj(NvSciBufObj bufObj) override
    void fillSpecificAttributes(NvSciBufAttrList attrList) const
    void fillSpecificAttributes(NvSciBufAttrList attrList) const
    core::DevicePtr< void > getCudaPtr(size_t offset)
    void bindNvSciBufObj(NvSciBufObj bufObj) override
    BufferCUDA(BufferProperties properties)
    void * getCpuPtr(size_t offset)
    void bindNvSciBufObj(NvSciBufObj bufObj) override
    void fillNvSciBufAttrs(NvSciBufAttrList attrList) const
    Buffer(BufferProperties properties)
    core::DevicePtr< void > getCudaPtr(size_t offset)
    void BufferFlagsEnableBackend(BufferFlags &flags, BufferBackendType type)
    Definition: Buffer.hpp:58
    bool BufferFlagsBackendEnabled(BufferFlags flags, BufferBackendType type)
    Definition: Buffer.hpp:53
    uint32_t BufferFlags
    Definition: Buffer.hpp:51
    Definition: Buffer.hpp:40
    人人超碰97caoporen国产