本文介绍了cudaArray简单示例 - 如何分配1D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何分配 cudaArrays ?我特别感兴趣的是分配一维数组。分配后如何访问它的简单元素?我阅读 CUDA 编程指南,但我没有完全。任何人请用示例代码解释。是否使用cuda1Darray?

How to allocate cudaArrays? I'm particularly interested in allocating 1D array. After allocation how to access simple elements of it? I read CUDA programming guide but I'm not getting it fully. Can anybody please explain with sample code. Is using cuda1Darray recommended?

推荐答案

cudaArray是特殊结构,您可以如下分配1D cudaArray:

cudaArrays are special structures, optimized for texture fetching. You can allocate 1D cudaArray as follows:

      cudaArray* arr;

      //Create Channel Descriptor. float is just for example. Change it to required data type.
      cudaChannelFormatDesc channel = cudaCreateChannelDesc<float>();

      //Allocate Memory
      cudaMallocArray(&arr,&channel,Number_Of_Elements, 1,cudaArrayDefault);

宽度和高度是x和y方向上的元素数量。

The width and height is the number of elements in the x and y directions.

在内核中,可以通过使用 tex1D tex2D 函数。 cudaArray只能使用这些函数在设备代码中读取。

In the kernel, the elements of this array can be accessed by using tex1D or tex2D functions. cudaArrays can only be read inside device code using these functions.

这篇关于cudaArray简单示例 - 如何分配1D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 20:01