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

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

问题描述

我有以下文件:

  // Main.cpp 
#includekernel_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
#includekernel_util.cuh
#includekernel.curnel

#define thread 16

void call_kernel(){

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

dim3 threads(thread,thread);

kernel<<<块,线程>>>();
}

// kernel.curnel
#ifndef KERNEL
#define KERNEL

#include< cuda_runtime.h>

__global__ void kernel(){

}

#endif

我有Visual Studio 2010与64位编译器和Cuda5.0工具包安装。上述代码已成功编译,但行

 内核<<<< blocks,threads>> 

3rd<给出期望的表达式错误,但代码编译没有问题,并达到内核函数。



配置属性:



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


解决方案

IDE(MSVC ++)和编译器前端用于IntelliSense(自动完成建议,不正确的代码)不知道CUDA及其特殊语法。有一些方法让VS了解大多数CUDA代码,但是选择<<<对于CUDA中的块/线程来说,C ++编译器前端无法理解(至少,它需要对解析器进行大量的修改)。< / p >

总而言之,你必须生活在<<< >>>


I have the following files:

// 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

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

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

3rd "<" gives "expected an expression" error, but code compiles with no problem and reach kernel function.

configuration properties:

cpp file item type c/c++ compiler cu file item type cuda c/c++ cuh file item type Does not participate in build curnel file item type Does not participate in build

解决方案

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天全站免登陆