CUDA C ++:期望在kernel.cu文件中有一个表达式

时间:2018-01-09 14:21:34

标签: c++ cuda

我刚开始学习一点CUDA,我在下一行遇到了这个错误,在<<< >>>表达

MouseArea

#include "kernels.h"
#include "helpers.h"
#include <iostream>
#include <cmath>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
__global__
void blur(unsigned char* input_image, unsigned char* output_image, int width, int height) {

    const unsigned int offset = blockIdx.x*blockDim.x + threadIdx.x;
    int x = offset % width;
    int y = (offset - x) / width;
    int fsize = 5; // Filter size
    if (offset < width*height) {

        float output_red = 0;
        float output_green = 0;
        float output_blue = 0;
        int hits = 0;
        for (int ox = -fsize; ox < fsize + 1; ++ox) {
            for (int oy = -fsize; oy < fsize + 1; ++oy) {
                if ((x + ox) > -1 && (x + ox) < width && (y + oy) > -1 && (y + oy) < height) {
                    const int currentoffset = (offset + ox + oy * width) * 3;
                    output_red += input_image[currentoffset];
                    output_green += input_image[currentoffset + 1];
                    output_blue += input_image[currentoffset + 2];
                    hits++;
                }
            }
        }
        output_image[offset * 3] = output_red / hits;
        output_image[offset * 3 + 1] = output_green / hits;
        output_image[offset * 3 + 2] = output_blue / hits;
    }
}


void filter(unsigned char* input_image, unsigned char* output_image, int width, int height) {

    unsigned char* dev_input;
    unsigned char* dev_output;
    getError(cudaMalloc((void**)&dev_input, width*height * 3 * sizeof(unsigned char)));
    getError(cudaMemcpy(dev_input, input_image, width*height * 3 * sizeof(unsigned char), cudaMemcpyHostToDevice));

    getError(cudaMalloc((void**)&dev_output, width*height * 3 * sizeof(unsigned char)));

    dim3 blockDims(512, 1, 1);
    dim3 gridDims((unsigned int)ceil((double)(width*height * 3 / blockDims.x)), 1, 1);

    blur <<< gridDims, blockDims >>>(dev_input, dev_output, width, height);


    getError(cudaMemcpy(output_image, dev_output, width*height * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost));

    getError(cudaFree(dev_input));
    getError(cudaFree(dev_output));
}

行,第三个&lt;在其中,我遇到了标题中的错误,因此我无法编译代码(其他人说这是一个Intellisense错误,但是对于其他人来说,程序是编译的,而我的不是)。

当我尝试编译

时,我也收到此错误
blur <<< gridDims, blockDims >>>(dev_input, dev_output, width, height);

我正在尝试在Windows 10上运行该程序,Visual Studio 2017(最新版本,安装了15.4支持的工具包,因此我没有收到不兼容的版本错误)。我尝试重新安装CUDA 9.1.85,VS2017并创建一个新项目。我将依赖项和库中的路径添加到NVIDIA Toolkit中,并且该代码存在于.cu文件中。

问题在于,即使我创建了一个新项目,而没有更改任何内容并让kernel.cu使用默认设置填充它,它仍然在&lt;&lt;&lt;&lt;&lt;&lt; &GT;&GT;&GT;线。

我该怎么做才能解决它?谢谢。

3 个答案:

答案 0 :(得分:1)

我发现了问题。最新版本的VS2017并不支持最新版本的CUDA,因此解决方案就是按照here中的说法进行操作。现在一切正常

答案 1 :(得分:0)

由于我多次遇到此错误,因此我只想补充一点,如果您看到此错误与任何其他错误一起显示,请确保先处理其他错误。尽管此错误可能显示为错误列表中的第一个错误,但该错误很可能不是编译失败的实际原因。

答案 2 :(得分:-1)

我有相同的编译时错误。右键单击Visual Studio中的文件->“属性”->“配置属性”->“项目类型”(将其设置为CUDA C / C ++)