错误。 网中到处都是同样的例子如何使用统一内存。但我得到了那个错误。到处搜寻。 感觉我错过了一些关于cuda设置的东西,需要在设置中改变一些但不知道是什么。
windows 7 x64
visual studio 2013
cuda 7
gtx 970
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void run(unsigned int *a)
{
a[threadIdx.x] = 1;
}
int main()
{
unsigned int* arr;
cudaMallocManaged((void**)&arr, sizeof(unsigned int) * 10);
run << <1, 10 >> >(arr);
cudaDeviceSynchronize();
for (int i = 0; i < 10; i++)
printf("result = %d", arr[i]);
cudaFree(arr);
return 0;
}
1>------ Build started: Project: cudaTest, Configuration: Debug Win32 ------
1> Compiling CUDA source file kernel.cu...
1>
1> C:\Users\Max\documents\visual studio 2013\Projects\cudaTest\cudaTest>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\nvcc.exe" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --use-local-env --cl-version 2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include" -G --keep-dir Debug -maxrregcount=0 --machine 32 --compile -cudart static -g -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o Debug\kernel.cu.obj "C:\Users\Max\documents\visual studio 2013\Projects\cudaTest\cudaTest\kernel.cu"
1> kernel.cu
1> cudaTest.vcxproj -> C:\Users\Max\documents\visual studio 2013\Projects\cudaTest\Debug\cudaTest.exe
1> copy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart*.dll" "C:\Users\Max\documents\visual studio 2013\Projects\cudaTest\Debug\"
1> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart32_70.dll
1> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart64_70.dll
1> Скопировано файлов: 2.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Unhandled exception at 0x00F1149E in cudaTest.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00F1149E in cudaTest.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00F1149E in cudaTest.exe: 0xC0000005: Access violation reading location 0x00000000.
The program '[7104] cudaTest.exe' has exited with code -1073741510 (0xc000013a).