texture报错

scalk 2016-04-12 10:21:14
在使用texture声明纹理内存的时候报错

引用

#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
cudaError_t err = cudaSuccess;

template texture<float,3,cudaReadModeElementType> tex_u;
int main(void)
{
///////创建cuda 3d数组
cudaArray *d=0;
cudaExtent extent=make_cudaExtent(256,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;
cudaMemcpy3D(©Params);


//绑定CUDA 三维数组至纹理内存texture memory

tex_u.filterMode=cudaFilterModePoint;
tex_u.normalized=false;
tex_u.channelDesc=channeldesc;
if(cudaBindTextureToArray(tex_u,d,&channeldesc)!=(unsigned int)cuda_Success)
{
printf("error: could not bind texture \n");
return -1;
}




return 0;
}



报错显示texture不是模板。
我看书上都是这么直接声明的,有哪儿不对吗?
...全文
440 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

579

社区成员

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

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