我刚开始学习一点 CUDA,我在以下行中遇到了这个错误,在一个 <<< >>> 表达式
#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));
}
在里面
blur <<< gridDims, blockDims >>>(dev_input, dev_output, width, height);
行,在其中的第三个<,我遇到了标题中的错误,因此我无法编译代码(其他人说这是一个Intellisense错误,但对其他人来说程序编译了,而我的没有’t)。
当我尝试编译时,我也收到此错误
Severity Code Description Project File Line Suppression State
Error MSB3721 The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin\nvcc.exe" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env --cl-version 2017 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\bin\HostX86\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64\Debug\kernel.cu.obj "C:\Users\Artyomska\Documents\Visual Studio 2017\Projects\ScreenFilter\ScreenFilter\kernel.cu"" exited with code 1. ScreenFilter C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 9.1.targets 707
我正在尝试在 Windows 10、Visual Studio 2017(最新版本,安装了支持 15.4 的工具包,因此我没有收到不兼容的版本错误)上运行该程序。我尝试重新安装 CUDA 9.1.85、VS2017 并创建一个新项目。我在 NVIDIA Toolkit 的依赖项和库中添加了路径,并且该代码存在于 .cu 文件中。
问题是,即使我创建了一个新项目,没有更改任何内容并让 kernel.cu 使用默认设置填充它,它仍然在 <<< >>> 行出现表达式错误。
我应该怎么做才能解决它?谢谢你。
原文由 Artyomska 发布,翻译遵循 CC BY-SA 4.0 许可协议
我发现了问题。最新版本的 VS2017 不支持最新版本的 CUDA,所以解决方案是按照 这里 所说的做。现在一切正常