gpt4 book ai didi

c++ - Visual Studio .cu 文件显示语法错误但编译成功

转载 作者:行者123 更新时间:2023-12-02 01:35:25 65 4
gpt4 key购买 nike

我有以下文件:

// 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>>>();

第三个<给出“预期表达式”错误,但代码编译没有问题并到达内核函数。

配置属性:

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

最佳答案

IDE (MSVC++) 及其用于 IntelliSense 的编译器前端(自动完成建议和“不正确”代码下的红线)对 CUDA 及其特殊语法一无所知。 VS 有一些方法可以理解大多数 CUDA 代码,但 <<< >>> 的选择对于 CUDA 中的 block /线程来说,这是一个非常不幸的问题,C++ 编译器前端无法理解(至少,它需要对解析器进行大量修改)。

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

关于c++ - Visual Studio .cu 文件显示语法错误但编译成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15205458/

65 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com