Launch the kernel (<<<, > are CUDA runtime.
这里为.cu文件 # include "cuda_runtime.h" # include "device_launch_parameters.h" # include "opencv2/core.hpp" //#include # include "opencv2/highgui.hpp" # include "opencv2/imgproc.hpp" # include # include # include # include "resize. DimBlock(4,8,8) // 256 threads per (3D) block sizet SharedMemBytes 64 // 64 bytes of shared memory. Unsigned int resize_w unsigned int resize_h ĮlementType *resize_image } *P # endif // !_RESIZE_H 这里为resize.h文件 # pragma once # ifndef _RESIZE_H # define _RESIZE_H typedef unsigned char ElementType typedef struct resize 使用cudaDestroyTextureObject() cudaDestroyTextureObject (tex ) 代码示例(CUDA+Opencv) Dim3 note: Dim3 is used to manage how you want to access blocks and grids i. Type tex2D (texture texRef, float x, float y ) 纹理对象销毁 shared memory is block level i.e only threads in the same block can access it S is of type cudaStreamt and specifies the associated stream S is an optional argument which defaults to 0. In a 1D block, you can set 1024 threads at most in the x axis, but in a 2D block, if you set 2 as the size of y, you cannot exceed 512 for the x For example, dim3 threadsPerBlock(1024, 1, 1) is allowed, as well as dim3 threadsPerBlock(512, 2, 1), but not dim3 threadsPerBlock(256, 3, 2). Type tex1D (texture texRef, float x ) template 接着使用cudaCreateTextureObject()函数创建纹理对象 //创建纹理对象ĬudaTextureObject_t tex = 0 cudaCreateTextureObject ( &tex, &resDesc, &texDesc, NULL ) 访问纹理内存 readMode = cudaReadModeElementType //若选用cudaFilterModeLinear,则readMode=cudaReadModeNormalizedFloat ![]() filterMode = cudaFilterModePoint //最近邻插值法 ![]() If grid is type(dim3), the value of each component must be equal to or greater than one, and the product is usually limited by the compute capability of the device. array = cuArray //CUDA数组 对应的赋值形式 //纹理描述符ĬudaTextureDesc texDesc memset ( &texDesc, 0, sizeof (texDesc ) ) grid and block are either integer expressions (for one-dimensional grids and thread blocks), or are type(dim3), for one- or two-dimensional grids and thread blocks. ![]() 这里我们需要定义cudaResourceDesc资源描述符和cudaTextureDesc纹理描述符。ĬudaResourceDesc resDesc memset ( &resDesc, 0, sizeof (resDesc ) ) //初始化 1)创建纹理对象,cudaCreateTextureObject() cudaCreateTextureObject (cudaTextureObject_t *pTexObject, const struct cudaResourceDesc *pResDesc, const struct cudaTextureDesc *pTexDesc, const struct cudaResourceViewDesc *pResViewDesc )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |