cuda错误error C2059: 语法错误:“<”

pengu8130 2016-12-03 10:18:22
在vs2010中进行cuda编程,这是建立的第一个cuda工程,按照如下进行了配置:
首先新建一个win32空项目,进行如下设置:
1、右键源文件文件夹->新建项->选择cuda c/c++->新建一个以.cu结尾的文件
2、右键工程-》生成自定义-》选择cuda生成
3、右键test.cu-》属性-》选择cuda c/c++编译器
4、右键工程-》属性-》链接器-》常规-》附加库目录-》添加目录 $(CUDA_PATH_V5_5)\lib\$(Platform);
5、在链接器-》输入中添加 cudart.lib
6、在工具-》选项-》文本编辑器-》文件扩展名-》添加cu \cuh两个文件扩展名

现在编译出错:
错误 1 error C2059: 语法错误:“<” f:\code_test\cudavs\cudavs\add.cu 56
2 IntelliSense: 应输入表达式 f:\code_test\cudavs\cudavs\add.cu 56

我只下载了cuda_8.0.44_windows.exe安装了默认路径,其他的都没有下载,这个是只包含toolkit 吗
另,很多博主说可能是没有用nvcc编译?右键test.cu-》属性-》选择cuda c/c++编译器是这步操作吗?求各位大侠帮忙

源代码如下:自己加了两个头文件

#include <stdio.h>
//#include <assert.h>
#include <stdlib.h>
#include <conio.h>
// CUDA runtime
//#include<cuda.h>
#include <cuda_runtime.h>//自己加
#include<device_launch_parameters.h>//自己加

// Helper functions and utilities to work with CUDA
//#include <helper_cuda.h>
__global__ void what_is_my_id(unsigned int *const block,unsigned int * const thread,unsigned int *const warp,unsigned int * const calc_thread)
{
const unsigned int thread_idx=(blockIdx.x * blockDim.x)+ threadIdx.x;

block[thread_idx]=blockIdx.x;
block[thread_idx]=threadIdx.x;

warp[thread_idx]=threadIdx.x/warpSize;

calc_thread[thread_idx]=thread_idx;

}
#define ARRAY_SIZE 128
#define ARRAY_SIZE_IN_BYTES (sizeof(unsigned int )*(ARRAY_SIZE))

unsigned int cpu_block[ARRAY_SIZE];

unsigned int cpu_thread[ARRAY_SIZE];

unsigned int cpu_warp[ARRAY_SIZE];

unsigned int cpu_calc_thread[ARRAY_SIZE];

int main(void)
{
const unsigned int num_blocks=2;
const unsigned int num_threads=64;
dim3 grid(2,1);
dim3 block(8,8);

char ch;

unsigned int *gpu_block;
unsigned int *gpu_thread;
unsigned int *gpu_warp;
unsigned int *gpu_calc_thread;

unsigned int i;
cudaMalloc((void**)&gpu_block,ARRAY_SIZE_IN_BYTES);
cudaMalloc((void**)&gpu_thread,ARRAY_SIZE_IN_BYTES);
cudaMalloc((void**)&gpu_warp,ARRAY_SIZE_IN_BYTES);
cudaMalloc((void**)&gpu_calc_thread,ARRAY_SIZE_IN_BYTES);

what_is_my_id<<<num_blocks,num_threads>>>(gpu_block,gpu_thread,gpu_warp,gpu_calc_thread);

cudaMemcpy(cpu_block,gpu_block,ARRAY_SIZE_IN_BYTES,cudaMemcpyDeviceToHost);
cudaMemcpy(cpu_thread,gpu_thread,ARRAY_SIZE_IN_BYTES,cudaMemcpyDeviceToHost);
cudaMemcpy(cpu_warp,gpu_warp,ARRAY_SIZE_IN_BYTES,cudaMemcpyDeviceToHost);
cudaMemcpy(cpu_calc_thread,gpu_calc_thread,ARRAY_SIZE_IN_BYTES,cudaMemcpyDeviceToHost);

cudaFree(gpu_block);
cudaFree(gpu_thread);
cudaFree(gpu_warp);
cudaFree(gpu_calc_thread);

for(i=0;i<ARRAY_SIZE;i++)
{
printf("calculated thread:%3u -block:%2u -warp%2u -thread %3u\n",cpu_calc_thread[i],cpu_block[i],cpu_warp[i],cpu_thread[i]);
}
//ch=getch();
return 0;
}



谢过各位大侠了!
...全文
1558 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

579

社区成员

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

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