visual studio .cu file shows syntax error but comp

2019-07-06 06:53发布

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 CUDA 5.0 toolkit installed. Above code compiles successfully but line

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

3rd < gives "expected an expression" error, but code compiles without problems and reaches 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

1条回答
看我几分像从前
2楼-- · 2019-07-06 07:11

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

查看更多
登录 后发表回答