NVIDIA DeepStream SDK API Reference

6.4 Release
Memory.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 
11 #ifndef CVCORE_MEMORY_H
12 #define CVCORE_MEMORY_H
13 
14 #include <cuda_runtime_api.h>
15 
16 #include "Tensor.h"
17 
18 namespace cvcore {
19 
26 void TensorBaseCopy(TensorBase &dst, const TensorBase &src, cudaStream_t stream = 0);
27 
38 void TensorBaseCopy2D(TensorBase &dst, const TensorBase &src, int dstPitch, int srcPitch, int widthInBytes, int height,
39  cudaStream_t stream = 0);
40 
50 template<TensorLayout TL, ChannelCount CC, ChannelType CT,
51  typename std::enable_if<TL != HWC && TL != CHW && TL != NHWC && TL != NCHW>::type * = nullptr>
52 void Copy(Tensor<TL, CC, CT> &dst, const Tensor<TL, CC, CT> &src, cudaStream_t stream = 0)
53 {
54  TensorBaseCopy(dst, src, stream);
55 }
56 
66 template<TensorLayout TL, ChannelCount CC, ChannelType CT, typename std::enable_if<TL == HWC>::type * = nullptr>
67 void Copy(Tensor<TL, CC, CT> &dst, const Tensor<TL, CC, CT> &src, cudaStream_t stream = 0)
68 {
69  TensorBaseCopy2D(dst, src, dst.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT),
70  src.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT),
71  dst.getWidth() * dst.getChannelCount() * GetChannelSize(CT), src.getHeight(), stream);
72 }
73 
83 template<TensorLayout TL, ChannelCount CC, ChannelType CT, typename std::enable_if<TL == NHWC>::type * = nullptr>
84 void Copy(Tensor<TL, CC, CT> &dst, const Tensor<TL, CC, CT> &src, cudaStream_t stream = 0)
85 {
86  TensorBaseCopy2D(dst, src, dst.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT),
87  src.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT),
88  dst.getWidth() * dst.getChannelCount() * GetChannelSize(CT), src.getDepth() * src.getHeight(),
89  stream);
90 }
91 
101 template<TensorLayout TL, ChannelCount CC, ChannelType CT, typename std::enable_if<TL == CHW>::type * = nullptr>
102 void Copy(Tensor<TL, CC, CT> &dst, const Tensor<TL, CC, CT> &src, cudaStream_t stream = 0)
103 {
104  TensorBaseCopy2D(dst, src, dst.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT),
105  src.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT), dst.getWidth() * GetChannelSize(CT),
106  src.getChannelCount() * src.getHeight(), stream);
107 }
108 
118 template<TensorLayout TL, ChannelCount CC, ChannelType CT, typename std::enable_if<TL == NCHW>::type * = nullptr>
119 void Copy(Tensor<TL, CC, CT> &dst, const Tensor<TL, CC, CT> &src, cudaStream_t stream = 0)
120 {
121  TensorBaseCopy2D(dst, src, dst.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT),
122  src.getStride(TensorDimension::HEIGHT) * GetChannelSize(CT), dst.getWidth() * GetChannelSize(CT),
123  src.getDepth() * src.getChannelCount() * src.getHeight(), stream);
124 }
125 
126 } // namespace cvcore
127 
128 #endif // CVCORE_MEMORY_H
cvcore::TensorBaseCopy
void TensorBaseCopy(TensorBase &dst, const TensorBase &src, cudaStream_t stream=0)
Implementation of tensor copy.
cvcore::TensorBaseCopy2D
void TensorBaseCopy2D(TensorBase &dst, const TensorBase &src, int dstPitch, int srcPitch, int widthInBytes, int height, cudaStream_t stream=0)
Implementation of tensor copy for 2D pitch linear tensors.
cvcore
Definition: PnP.h:20
cvcore::Copy
void Copy(Image< NV12 > &dst, const Image< NV12 > &src, cudaStream_t stream=0)
Definition: Image.h:872
cvcore::GetChannelSize
std::size_t GetChannelSize(ChannelType CT)
Function to get element size (in bytes) of a ChannelType.
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: nvbufsurftransform.h:29
cvcore::Tensor
Definition: Tensor.h:704
cvcore::TensorDimension::HEIGHT
@ HEIGHT
height dimension.
Tensor.h
cvcore::ChannelType
ChannelType
An enum.
Definition: Tensor.h:58
cvcore::TensorLayout
TensorLayout
An enum.
Definition: Tensor.h:28
cvcore::ChannelCount
ChannelCount
An enum.
Definition: Tensor.h:45