【问题标题】:Cuda Project Not CompilingCuda 项目未编译
【发布时间】:2013-06-10 23:36:45
【问题描述】:

我使用 Visual Studio 2010 编译了我的 cuda 项目。我反驳了一个错误声明:

student_func.cu(65):错误 C2059:语法错误:'

发生错误的那一行是调用内核函数的时候:

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

这里是 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());
}

【问题讨论】:

  • 包含此代码的文件是否具有.cpp 扩展名?
  • 是的,包含 main 函数的主文件...我认为的问题是项目属性中缺少一些链接,因为我有另一个项目是通过编辑 cuda 示例项目制作的,它工作正常!
  • 同时注释掉这一行可以成功构建项目!

标签: visual-studio-2010 opencv cuda


【解决方案1】:

请先在how to integrate CUDA in a Visual Studio C++ project 上查看本指南。

此外,您应该组织代码以便:

  • .h、.cpp、.c、.hpp 文件不应包含 CUDA 代码(如 __device__ 函数和您的情况下的内核调用)。但是,在这些文件中,您可以调用 CUDA API(例如,cudaMalloccudaMemcpy 等)。这些文件由 NVCC 以外的编译器编译。
  • .cuh、.cu 文件应包含 CUDA 代码。这些文件由 NVCC 编译。

例如,假设有一个基于 GPU 的 FDTD 代码。我通常会执行以下操作(Visual Studio 2010)。

  • ma​​in.cpp 文件,包括 CPU-GPU 内存传输;
  • FDTD.cu,包括一个extern "C" void E_update(...) 函数,其中包含内核&lt;&lt;&lt; &gt;&gt;&gt; 调用;
  • ma​​in.h 文件,包括 extern "C" void E_update(...) 原型;
  • FDTD.cuh,包括__global__ void E_update_kernel(...) 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 2013-03-05
    • 2015-06-24
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    相关资源
    最近更新 更多