简体   繁体   中英

Cuda Project Not Compiling

I have compiled my cuda project using visual studio 2010. I have countered an error stated:

student_func.cu(65): error C2059: syntax error : '<'

The line where error occurs is when the kernel function is called:

rgba_to_greyscale<<< gridSize, blockSize >>>(d_rgbaImage, d_greyImage, numRows, numCols);

and here is the code for student_func.cu:

#include "reference_calc.cpp"
#include "utils.h"
#include <stdio.h>



__global__ 
void rgba_to_greyscale(const uchar4* const rgbaImage,
                   unsigned char* const greyImage,
                   int numRows, int numCols)
{

}


void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage, uchar4 * const d_rgbaImage,
                        unsigned char* const d_greyImage, size_t numRows, size_t numCols)
{
    //You must fill in the correct sizes for the blockSize and gridSize
    //currently only one block with one thread is being launched
    const dim3 blockSize(1, 1, 1);  //TODO
    const dim3 gridSize( 1, 1, 1);  //TODO
    rgba_to_greyscale<<< gridSize, blockSize >>>(d_rgbaImage, d_greyImage, numRows, numCols);

    cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
}

Please, have first a look at this guide on how to integrate CUDA in a Visual Studio C++ project .

Also, you should organize the code so that:

  • .h, .cpp, .c, .hpp files should not contain CUDA code (like __device__ functions and the kernel call in your case). However, in these files you can call CUDA APIs (for example, cudaMalloc , cudaMemcpy , etc.). These files are compiled by a compiler other than NVCC.
  • .cuh, .cu files should contain the CUDA code. These files are compiled by NVCC.

As an example, suppose to have a GPU-based FDTD code. I usually do the following (Visual Studio 2010).

  • main.cpp file, including CPU-GPU memory transfers;
  • FDTD.cu , including an extern "C" void E_update(...) function which contains the kernel <<< >>> call;
  • main.h file, including the extern "C" void E_update(...) prototype;
  • FDTD.cuh , including the __global__ void E_update_kernel(...) function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM