【问题标题】:visual studio .cu file shows syntax error but compiles successfullyvisual studio .cu 文件显示语法错误但编译成功
【发布时间】:2013-02-18 18:30:44
【问题描述】:

我有以下文件:

// 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。上面的代码编译成功但是行

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

3rd &lt; 给出“expected an expression”错误,但代码编译没有问题并到达内核函数。

配置属性:

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

【问题讨论】:

  • 我认为问题出现在 Intellisense 中?
  • 你这是什么意思。你能说得更具体点吗??
  • 你从哪里得到错误?显然不是在编译时,正如你所说的代码编译干净。因此,唯一可能出现错误的其他区域是 VS 中的后台语法检查,即 Intellisense。

标签: c++ visual-studio syntax cuda


【解决方案1】:

IDE (MSVC++) 和它用于 IntelliSense 的编译器前端(自动完成建议和“不正确”代码下的红线)不知道 CUDA 及其特殊语法。 VS 有一些方法可以理解大多数 CUDA 代码,但是对于 CUDA 中的块/线程选择 &lt;&lt;&lt; &gt;&gt;&gt; 是非常不幸的,C++ 编译器前端无法理解(至少,它需要非常广泛的修改到解析器)。

总而言之,你必须忍受&lt;&lt;&lt; &gt;&gt;&gt;下方的红色波浪线。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-01
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 2011-07-01
  • 1970-01-01
  • 2013-02-09
相关资源
最近更新 更多