cuda中的编译错误
Posted
技术标签:
【中文标题】cuda中的编译错误【英文标题】:Compile error in cuda 【发布时间】:2016-12-16 07:19:36 【问题描述】:我在 cuda 中有一个编译错误,我想知道为什么会发生这个错误? 我想知道我的 cuda 是否会在 2DArray 中运行以进行图像处理
我的代码是
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<cuda.h>
#include<cuda_runtime.h>
#include "device_launch_parameters.h"
#include<iostream>
using namespace std ;
#define BLOCK_WIDTH 16
__global__ void kernel(int *d_A, size_t pitch, int rows, int cols)
//compute the row
int r = blockIdx.y*blockDim.y+threadIdx.y;
//compute the column
int c = blockIdx.x*blockDim.x+threadIdx.x;
if((r < rows) && (c < cols))
// // update the pointer to point to the beginning of the row
//int *Row = (int*)((char*)d_A + r*pitch);
int *Row = (int*)((char*)d_A);
int elem = Row[c];
printf("%d ", elem);
void test(int **A, int rows, int cols)
int *d_A;
size_t pitch;
cudaMallocPitch((void**)&d_A, &pitch, sizeof(int)*cols, rows);
cudaMemcpy2D(d_A, pitch, A, sizeof(int)*cols, sizeof(int)*cols, rows, cudaMemcpyHostToDevice);
//Define grid and block size
int Yblocks = rows / BLOCK_WIDTH;
if(rows % BLOCK_WIDTH) Yblocks++;
int Xblocks = cols / BLOCK_WIDTH;
if(cols % BLOCK_WIDTH) Xblocks++;
// cout << Yblocks << "," << Xblocks << endl;
dim3 dimGrid(Yblocks, Xblocks, 1);
dim3 dimBlock(BLOCK_WIDTH, BLOCK_WIDTH, 1);
//Run kernel
kernel<<<dimGrid, dimBlock>>>(d_A, pitch, rows, cols);
cudaMemcpy2D(A, sizeof(int)*cols, d_A, pitch, sizeof(int)*cols, rows, cudaMemcpyDeviceToHost);
cudaFree(&d_A);
int main()
int rows = 2;
int cols = 2;
int **A;
A = new int*[rows];
for(int i = 0; i < rows; ++i)
A[i] = new int[cols];
for(int j = 0; j < cols; ++j)
A[i][j] = i+2;
test(A, rows, cols);
for(int i = 0; i < rows; ++i)
for(int j = 0; j < cols; ++j)
cout << A[i][j] << " ";
cout << "\n";
for(int i = 0; i < rows; ++i) delete[] A[i];
delete[] A;
return 0;
我的笔记本电脑里有: NVIDIA CUDA 示例 7.5 , NVIDIA CUDA 工具包 7.5 , NVIDIA CUDA 工具包 v5(64), NVIDIA CUDA 工具 SDK v4.0 , NVIDIA GPU 计算 SDK 4 , NVIDIA 显卡驱动 306.94 , NVIDIA Nsigth 视觉工作室版 5.1.0.10602, 视觉工作室 2010 , 英伟达 GeForce 9300M GS , 驱动器型号:WDDM 1.1, DDI 版本:10 , 窗户 7
我有这个错误
1>------ Build started: Project: 2Dexample, Configuration: Debug Win32 --
1>Build started 8/10/2016 6:29:45 AM.
1>InitializeBuildStatus:
1> Touching "Debug\2Dexample.unsuccessfulbuild".
1>AddCudaCompileDeps:
1>Skipping target "AddCudaCompileDeps" because all output files are up- to-date with respect to the input files.
1>AddCudaCompilePropsDeps:
1>Skipping target "AddCudaCompilePropsDeps" because all output files are up-to-date with respect to the input files.
1>CudaBuild:
1> Compiling CUDA source file kernel.cu...
1>
1> C:\Users\Amany\Documents\Visual Studio 2010\Projects\2Dexample\2Dexample>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" - I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G -maxrregcount=0 --machine 32 --compile -1 -g -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o "Debug\kernel.cu.obj" "C:\Users\Amany\Documents\Visual Studio 2010\Projects\2Dexample\2Dexample\kernel.cu"
1>nvcc : fatal error : Unknown option '1'
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.0.targets(592,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G -maxrregcount=0 --machine 32 --compile -1 -g -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o "Debug\kernel.cu.obj" "C:\Users\Amany\Documents\Visual Studio 2010\Projects\2Dexample\2Dexample\kernel.cu"" exited with code -1.
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.29
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
我尝试了很多东西,但没有成功:
How to Compile CUDA App is Visual Studio 2010?
https://devtalk.nvidia.com/default/topic/577900/error-msb3721-with-cuda-5-5-and-vs-2010-professional/
https://devtalk.nvidia.com/default/topic/577900/error-msb3721-with-cuda-5-5-and-vs-2010-professional/
但不工作
【问题讨论】:
【参考方案1】:我觉得可能和这个奇怪的值有关
nvcc.exe ....... --compile -1 .......
nvcc : fatal error : Unknown option '1'
【讨论】:
那么我应该怎么做才能修复它??plz以上是关于cuda中的编译错误的主要内容,如果未能解决你的问题,请参考以下文章