我刚刚开始学习一些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);的第三行尝试编译时也会收到此错误Severity Code Description Project File Line Suppression StateError 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设置默认设置的方式,它在>>行中仍然存在表达式错误。我该怎么办才能解决?谢谢。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 我发现了问题。 VS2017的最新版本不支持CUDA的最新版本,因此解决方案是按照here中的说明进行操作。现在一切正常 (adsbygoogle = window.adsbygoogle || []).push({});
10-07 13:34
查看更多