Visual Studio .cu文件显示语法错误,但编译成功 [英] visual studio .cu file shows syntax error but compiles successfully

查看:531
本文介绍了Visual Studio .cu文件显示语法错误,但编译成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下文件:

// Main.cpp
#include "kernel_util.cuh"

int main()
{
    call_kernel();
}

// kernel_util.cuh
#ifndef KERNEL_UTIL
#define KERNEL_UTIL

#include <cuda_runtime.h>

void call_kernel();

#endif

// kernel_util.cu
#include "kernel_util.cuh"
#include "kernel.curnel"

#define thread 16

void call_kernel() {

    dim3 blocks( ( width + thread - 1 ) / thread, ( height + thread - 1 ) / thread );

    dim3 threads( thread, thread );

    kernel<<<blocks, threads>>>();
}

// kernel.curnel
#ifndef KERNEL
#define KERNEL

#include <cuda_runtime.h>

__global__ void kernel() {

}

#endif

我安装了带有64位编译器和CUDA 5.0工具包的Visual Studio 2010.上面的代码编译成功,但是行

I have Visual Studio 2010 with 64 bit compiler and CUDA 5.0 toolkit installed. Above code compiles successfully but line

kernel<<<blocks, threads>>>();

第3个<给出期望的表达式"错误,但代码编译没有问题并达到了内核功能.

3rd < gives "expected an expression" error, but code compiles without problems and reaches kernel function.

配置属性:

  • cpp文件项类型c/c ++编译器
  • cu文件项目类型cuda c/c ++
  • cuh文件项类型不参与构建
  • curnel文件项类型不参与构建

推荐答案

IDE(MSVC ++)及其用于IntelliSense的编译器前端(自动完成建议和不正确"代码下的红线)没有关于CUDA及其特殊语法的想法. VS有一些方法可以理解大多数CUDA代码,但是对于CUDA中的块/线程,选择<<< >>>是C ++编译器前端无法理解的一种非常不幸的方式(至少,它需要进行大量的修改)到解析器).

The IDE (MSVC++) and the compiler front-end used by it for IntelliSense (the autocomplete suggestions, and the red lines under 'incorrect' code) have no idea about CUDA and its peculiar syntax. There are some ways for VS to make sense of most CUDA code, but the choice of <<< >>> for blocks/threads in CUDA is a very unfortunate one that C++ compiler frontends cannot make sense of (at least, it would require very extensive modifications to the parser).

总而言之,您必须忍受<<< >>>下的红色波浪线.

All in all, you have to live with the red squiggly lines below <<< >>>.

这篇关于Visual Studio .cu文件显示语法错误,但编译成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆