日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

VisionWorks学习之OpenVX到VPI的迁移

發布時間:2024/1/1 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VisionWorks学习之OpenVX到VPI的迁移 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

openVX到VPI的遷移

  • 第一部分 Data Object Differences
    • VPI Images
      • 創建一個Image
      • image使用示例
    • VPI pyramids
      • 創建一個pyramid
      • VPI arrays
      • 創建一個array
  • 第二部分 OpenVX和VPI Primitives
    • 執行模型比較
      • OpenVX
      • VPI模式
      • VPI執行模型例子
    • 目標分配比較
    • Border Mode 比較
      • VPI 目標指定

本文主要介紹一下openVX遷移到VPI的一些注意事項,主要包含一些數據結構,以及如何初始化這些數據結構。數據結構包含object,images,pyramids,arrays

第一部分 Data Object Differences

OpenVx objects是半透明的,應用程序可以獲取對不透明數據對象的引用,openvx實現管理object memory (數據內容可以在給定時間駐留在系統中的任何位置),并且顯式地請求的對象的數據內容可以直接訪問。
VPI objects是以C結構體的方式對外展示的。應用程序分配和初始化object控制結構和Cuda內存,應用程序管理 CPU-GPU之間的同步。
下面顯示VX-VPI數據類型對應關系。

下面看一下VPI API 復雜數據對象的方法

Data ObjectDescription
nvxcu__t是基類,包含一些共有的信息
nvxcu_<object> _<property>_t子類,我們要實例化的就是這些,

cv基元函數使用指向基結構的指針作為參數。不需要前綴/后綴原語函數,因為單個函數可以支持同一類的多種類型的數據對象。原語很容易擴展。說白了就是定義的函數使用的參數都是父類,使用的時候可以傳入子類作為參數。
例如:

<primitive>(nvxcu_<object>_t *input, nvxcu_<object>_t *output)

VPI Images

下面來看一下nvxcu_image_t這個基類里面包含哪些共有的數據參數:

參數描述
image_type指定image變體類型
format指定image類型
width,height指定圖像的大小

nv_cv_pitch_linear_image_t是使用pitch linear的cuda buffer實現的一個image,有以下成員:

成員描述
baseThe base image structure (nvxcu_image_t)base.image.type must be NVXCU_PITCH_LINEAR_IMAGE.
planesPlan descriptor array. Must be consistent with base.format.
dev_ptrCUDA buffer的指針
pitch_in_bytesSpecifies the pitch of the CUDA buffer, in bytes.

nvxcu__uniform_image_t實現所有像素值相同的圖像。它有以下成員:

MemberDescription
baseThe base image structure (nvxcu_image_t). base.image.type must be NVXCU_UNIFORM_IMAGE.
uniform_valueSpecifies the value of the pixel (nvxcu_pixel_value_t). Must be consistent with base.format.

創建一個Image

使用openVX創建:

vx_image im = vxCreateImage(context, 1920,1080, VX_DF_IMAGE_U8);

使用VPI創建一個image:

void *dev_ptr = NULL; size_t pitch =0; cudaMallocPitch(&dev_ptr,&pitch, 1920*sizeof(uint8_t),1080); nvxcu_pitch_linear_image_t image; image.base.image_type = NVXCU_PITCH_LINEAR_IMAGE; image.base.format = NVXCU_DF_IMAGE_U8; image.base.width = 1920; image.base.height = 1080; image.planes[0].dev_ptr = dev_ptr; image.planes[0].pitch_in_bytes = pitch;

看一下VPI創建還是比較麻煩的,不過為了效率也不要怕麻煩,畢竟人家快。

image使用示例

下面比較OpenVX和VPI之間的圖像使用情況OpenVX中的圖像使用

vx_image in = vxCreateImage(...); vx_image_out = vxCreateImage(...); vxuBox3x3(context, in, out);

使用VPI使用image usage

nvxcu_pitch_linear_image_t in = { ... } ; nvxcu_pitch_linear_image_t out = { ... } ; nvxcu_border_t border_mode = { ... } ; nvxcu_stream_exec_target_t target = { ... } ; nvxcuBox3x3(&in.base, &out.base, &border_mode, &target.base);

VPI pyramids

nvxcu_pyramid_t 包含以下參數:

ParameterDescription
pyramid_type指定金字塔變體類型.
num_levels指定 金字塔有幾層.
scale指定層級間的縮放因子.

nvxcu_pitch_linear_pyramid_t 使用pitch linear的cuda buffer實現的一個pyramid.

MemberDescription
baseThe base pyramid structure (nvxcu_pyramid_t). base.pyramid_type must be NVXCU_PITCH_LINEAR_PYRAMID.
levelsA pointer to an array of base.num_levels image descriptors of type nvxcu_pitch_linear_image_t. Images must be consistent in terms of type and dimensions. levels[0] is the base of the pyramid (largest dimension).

創建一個pyramid

使用openVX創建一個pyramid

vx_pyramid pyr = vxCreatePyramid(context, num_levels, VX_SCALE_PYRAMID_HALF, 1920, 1080, VX_DF_IMAGE_U8);

使用VPI創建一個VPI:

nvxcu_pitch_linear_pyramid_t pyr; pyr.base.pyramid_type = NVXCU_PITCH_LINEAR_PYRAMID; pyr.base.num_levels = num_levels; pyr.base.scale = NVXCU_SCALE_PYRAMID_HALF; pyr.levels = malloc(num_levels * sizeof(nxcu_pitch_linear_image_t)); uint32_t cur_width = width, cur_height = height; float cur_scale = NVXCU_SCALE_PYRAMID_HALF; for (uint32_t i = 0; i < num_levels; ++i) {cudaMallocPitch(&pyr.levels[i].planes[0].dev_ptr,&pyr.levels[i].planes[0].pitch_in_bytes,cur_width * sizeof(uint8_t), cur_height);pyr.levels[i].base.image_type = NVXCU_PITCH_LINEAR_IMAGE; pyr.levels[i].base.format = NVXCU_DF_IMAGE_U8; pyr.levels[i].base.width = cur_width; pyr.levels[i].base.height = cur_height;cur_scale *= pyr.base.scale; cur_width = (uint32_t)ceilf(width * cur_scale); cur_height = (uint32_t)ceilf(height * cur_scale); }

VPI arrays

nvxcu_array_t is the base image structure. It includes the following parameters:

ParameterDescription
array_typeSpecifies the variant of the array.
item_typeSpecifies the type of elements in the array.
capacitySpecifies the maximum number of elements in the array.

nvxcu_plan_array_t array implementation uses plain linear CUDA memory. It has the following members:

MemberDescription
baseThe base array structure (nvxcu_array_t). base.array_type must be NVXCU_PLAIN_ARRAY.
dev_ptrA pointer to a CUDA buffer that can store at least base.capacity elements.
num_items_dev_ptrA pointer to the element counter in CUDA memory.

創建一個array

使用openVX:

vx_array array = vxCreateArray(context, NVX_TYPE_POINT2F, 1000);

使用VPI:

void * dev_ptr = NULL; cudaMalloc(&dev_ptr, 1000 * sizeof(nvxcu_point2f_t)); uint32_t * num_items_dev_ptr = NULL; cudaMalloc((void **)&num_items_dev_ptr, sizeof(uint32_t)); cudaMemset(num_items_dev_ptr, 0, sizeof(uint32_t)); nvxcu_plain_array_t array; array.base.array_type = NVXCU_PLAIN_ARRAY; array.base.item_type = NVXCU_TYPE_POINT2F; array.base.capacity = 1000; array.dev_ptr = dev_ptr; array.num_items_dev_ptr = num_items_dev_ptr;

第二部分 OpenVX和VPI Primitives

提供一個OpenVX和VPI執行模型,target assignments和border mode

執行模型比較

下面看一下OpenVX和VPI執行模型的比較

OpenVX

openVX提供兩個可選的執行模型。

  • 立即執行模式
    立即模式有一個類似于opencv的同步執行模型。這一切都是在運行時完成的,包括臨時內存分配。
  • vx_status status = vxu<Primitive>(context, <params>);
  • Graph模式
    在圖形模式下,先把如參數檢查、內存分配和優化等先于執行。它執行異步節點執行和同步圖形執行。
  • // Ahead of time vx_graph vxCreateCraph(context); vx_node node = vx<Primitive>Node(graph, <params>); vx_status verif_status = vxVerifyGraph(graph); // Data process time vx_status exec_status = vxProcessGraph(graph);

    VPI模式

    VPI執行模型包含三步:

  • 查詢臨時內存中的需求(僅限復雜原語)。
  • nvxcu_tmp_buf_size_t tmp_size; tmp_size = nvxcu<Primitive> GetBuff(<param metadata>, const struct cudaDeviceProp*);
  • 分配臨時內存這可以是CUDA和主機內存,并且可以提前完成
  • nvxcu_tmp_buf_t tmp_buf = {NULL, NULL}; cudaMalloc(&tmp_buf.dev_ptr, tmp_size.dev_buf_size); cudaMallocHost(&tmp_buf.host_ptr, tmp_size.host_buf_size);
  • 異步原語執行
  • nvxcu_tmp_buf_size_t tmp_size; tmp_size = nvxcu<Primitive>(<params, including tmp bufs>);

    VPI執行模型例子

    nvxcu_border_t border = { ... } ; nvxcu_stream_exec_target_t target = { ... } ; // Query for needed temporary memory nvxcu_tmp_buf_size_t gauss_pyr_buf_size_ = nvxcuGaussianPyramid_GetBufSize(width, height, nb_levels, &border, &exec_target_.dev_prop); // Allocate required buffers nvxcu_tmp_buf_t tmp_buf = {NULL, NULL}; if (tmp_size.dev_buf_size > 0)cudaMalloc(&tmp_buf.dev_ptr, tmp_size.dev_buf_size); if (tmp_size.host_buf_size > 0)cudaMallocHost(&tmp_buf.host_ptr, tmp_size.host_buf_size) // Process data nvxcu_pitch_linear_pyramid_t pyr = { /* must be width x height with nb_levels*/ } nvxcuGaussianPyramid(&pyr.base, tmp_buf, &border, &exec_target_.base) ); // Synchronize the stream to get results cudaStreamSynchronize(exec_target_.stream)

    目標分配比較

    Border Mode 比較

    openvx中的目標分配是可選的,默認情況下是自動分配的。您可以使用以下選項手動將原語分配給GPU或CPU:

    vxSetNodeTarget, vxSetImmediateModeTarget(...)

    VPI中的運行在哪個設備上是固定好的,必須在每個基元執行調用(nvxcu_exec_target_t參數)處提供目標CUDA流

    VPI 目標指定

    nvxcu_exec_target_t是基本執行目標結構,包括以下參數:

    ParameterDescription
    exec_target_type這是當前支持的唯一CUDA流目標。

    nvxcu_stream_exec_target_t array實現使用普通線性CUDA內存它包括下列成員:

    MemberDescription
    baseThe base target structure (nvxcu_exec_target_t). base.exec_target_type must be NVXCU_STREAM_EXEC_TARGET.
    streamSpecifies the CUDA stream.
    dev_propSpecifies the CUDA device property for the stream (cudaDeviceProp).

    總結

    以上是生活随笔為你收集整理的VisionWorks学习之OpenVX到VPI的迁移的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。