1. Jetson 的 zero-copy 机制与 PC 机显卡的区别
一般而言,针对 PC 机的资料关于 zero-copy 内存,即 CPU/GPU 共享内存,的说法是,这部分内存肯定是在 host 主机中的,GPU 可以通过映射的方式读取这个块内存。每次访问都要通过 PCIe 传送,GPU 并不会自动保存曾经传送的数据,所以,建议只在一次性访问的场合用共享内存。因为多次访问,就要多次从 CPU 内存向 GPU 内存传送。
Jetson 中,CPU 内存和 GPU 内存本来在物理上就是在一起的,因此,不存在 PCIe 通道传送问题。这种情况下,zero-copy 技术就很有用了。因此,Jetson C++ 开发包中,提供了 videoSource 和 videoOutput 类,基于 zero-copy 技术,避免了数据在内存里传来传去。
2. 关于 videoSource 和 videoOutput
在 videoSource 和 videoOutput 源代码注释中,明确指出视频数据只能存放在 CPU/GPU 共享内存,或者 GPU 内存,不会仅仅存放在 CPU 的独立内存。
- 如果此接口的videoOptions:zeroCopy标志设置为true,则内存在映射的CPU/GPU内存中分配,可以从CPU和CUDA访问。否则,只能从CUDA访问。
- 这里说的接口,就是抽象类 videoSource,因为 C++ 抽象类就是其他编程语言里的接口。这个说明给出了视频解码存放位置,只有两种情况:一种是CPU/GPU共享内存,另一种是GPU内存。在 Jetson 中,videoSource 不会把视频帧保存到 CPU 的独享内存。
videoSource 源代码
class videoSource
{
public:
static videoSource* Create( const videoOptions& options );
static videoSource* Create( const char* URI, const videoOptions& options=videoOptions() );
static videoSource* Create( const char* URI, const commandLine& cmdLine );
static videoSource* Create( const char* URI, const int argc, char** argv );
static videoSource* Create( const int argc, char** argv, int positionArg=-1 );
static videoSource* Create( const commandLine& cmdLine, int positionArg=-1 );
virtual ~videoSource();
static inline const char* Usage() {
return VIDEO_SOURCE_USAGE_STRING; }
template<typename T> bool Capture( T** image, uint64_t timeout=UINT64_MAX ) {
return Capture((void**)image, imageFormatFromType<T>(), timeout); }
virtual bool Capture( void** image, imageFormat format, uint64_t timeout=UINT64_MAX ) = 0;
virtual bool Open();
virtual void Close();