texture报错

scalk scalk 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在使用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不是模板。
我看书上都是这么直接声明的,有哪儿不对吗?
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
scalk
CUDA 591 成员 2,925 内容