Visual studio .cu文件显示语法错误,但编译成功

visual studio .cu file shows syntax error but compiles successfully

本文关键字:编译 成功 错误 语法 studio cu 文件 显示 Visual      更新时间:2023-10-16

我有以下文件:

// 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 <给出"expected an expression"错误,但代码编译没有问题,到达内核函数

配置属性:

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

IDE (msvc++)和它用于智能感知的编译器前端(自动完成建议,以及"不正确"代码下的红线)不知道CUDA及其特殊语法。VS有一些方法可以理解大多数CUDA代码,但是在CUDA中选择<<< >>>用于块/线程是一个非常不幸的选择,c++编译器前端无法理解(至少,它需要对解析器进行非常广泛的修改)。

总而言之,你必须生活在<<< >>>下面的红色弯弯曲曲的线。