cuda texture和cudaBindTextureToArray 函数使用问题

scalk 2016-04-13 11:18:48
引用


#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include "string.h"
//#define N 256*500*256
#define w 256
#define h 500
#define z 256


//struct textureReference{
// int normalized;
// enum cudaTextureFilterMode filterMode;
// enum cudaTextureAddressMode addressMode[3];
// struct cudaChannelFormatDesc channelDesc;
//}

texture<float,3,cudaReadModeElementType>tex;
int main(void)
{
///////创建cuda 3d数组
cudaArray *d=0;
cudaExtent extent=make_cudaExtent(256*sizeof(float),500,256);
cudaChannelFormatDesc channeldesc=cudaCreateChannelDesc(32,0,0,0,cudaChannelFormatKindFloat);
//extent.width=w;
//extent.height=h;
//extent.depth=z;

cudaMalloc3DArray(&d,&channeldesc,extent);



//////读取raw格式体数据
float u[w][h][z]={0};
FILE *fp=NULL;
fp=fopen("D:\\3\\liziba256500256_f.raw","r+");
if(NULL==fp)
{
printf("file open false!");
return -1;
}

//将所读取数据导入三维数组中
fread((void*)u,sizeof(float),256*500*256,fp);
//int x,y,k;
//for(x=0;x<256;x++)
//{
// for(y=0;y<500;y++)
// {
// for(k=0;k<256;k++)
// {

// printf("%f\n",u[x][y][k]);

// }
// }
//}

//复制数据至cudaArray(cuda 3D 数组)
cudaMemcpy3DParms copyParams={0};
copyParams.srcPtr=make_cudaPitchedPtr((void*)u,extent.width*sizeof(float),extent.width,extent.height);
copyParams.dstArray=d;
copyParams.extent=extent;
copyParams.kind=cudaMemcpyHostToHost;
cudaMemcpy3D(©Params);


//绑定CUDA 三维数组至纹理内存texture memory
tex.normalized=true;
tex.filterMode=cudaFilterModeLinear;
tex.channelDesc=channeldesc;
if(cudaBindTextureToArray(tex,d,channeldesc)!=(unsigned int)cudaSuccess)
{
printf("error: could not bind texture \n");
return -1;
}

return 0;
}



报错信息:
139 IntelliSense: texture 不是模板 c:\users\think\documents\visual studio 2010\projects\cuda\cuda\kernel.cu 19 1 cuda
140 IntelliSense: 不存在从 "cudaChannelFormatDesc" 到 "const cudaChannelFormatDesc *" 的适当转换函数 c:\users\think\documents\visual studio 2010\projects\cuda\cuda\kernel.cu 73 34 cuda

我看网上texture函数都是这么写的啊,还有cudaBindTextureToArray也是那么用的,这样使用有什么不对吗?
...全文
362 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

579

社区成员

发帖
与我相关
我的任务
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
  • CUDA编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧