测试BufSurface分配
#include <cstdio>
#include <cuda_runtime_api.h>
#include <nvbufsurface.h>
int main() {NvBufSurface* hst_surf = nullptr;NvBufSurfaceCreateParams buf_params = {0};int status = -1;buf_params.width = 1920;buf_params.height = 1080;buf_params.gpuId = 0;//buf_params.memType = NVBUF_MEM_CUDA_UNIFIED;//buf_params.memType = NVBUF_MEM_CUDA_DEVICE;buf_params.memType = NVBUF_MEM_DEFAULT;buf_params.colorFormat = NVBUF_COLOR_FORMAT_RGB;status = NvBufSurfaceCreate(&hst_surf, 2, &buf_params);if (status < 0) {printf ("Error(%d) in buffer allocation\n", status);return false;}printf("xx\n");return 0;
}
编译:gcc -o 1 1.cpp -I/usr/local/cuda-12.2/include -I/opt/nvidia/deepstream/deepstream/sources/includes -lcudart -lnvbufsurface -lnvbufsurftransform -L/usr/local/cuda-12.2/lib64 -L/opt/nvidia/deepstream/deepstream/lib
运行: export LD_LIBRARY_PATH=/opt/nvidia/deepstream/deepstream/lib/:$LD_LIBRARY_PATH && ./1
测试内存分配
#include <cstdio>
#include <cuda_runtime_api.h>#define CHECK(status) \
{ \if (status != 0) \{ \printf ("Cuda failure: status=%d\n", status); \} \
}int main() {cudaSetDevice(0);void* m_Buf = nullptr;CHECK(cudaMallocManaged(&m_Buf,1000*sizeof(int)));CHECK(cudaMalloc(&m_Buf,1000*sizeof(int)));printf("xx\n");return 0;
}
编译:gcc -o 2 2.cpp -I/usr/local/cuda-12.2/include -lcudart -L/usr/local/cuda-12.2/lib64