我在Visual Studio Community 2015中使用了CUDA Toolkit 8.當我嘗試使用NVidia的PDF手冊添加簡單向量時(減去錯誤檢查我沒有* .h's),它總會返回作爲未定義的值,這意味着輸出數組從未被填充。當我預先用0填充時,這就是我最後得到的結果。CUDA內核不會返回任何內容
其他人有這個問題,有些人說這是由編譯錯誤的計算能力造成的。不過,我使用的是NVidia GTX 750 Ti,它應該是Compute Capability 5.我已經嘗試編譯Compute Capability 2.0(我的SDK的最低版本)和5.0。
我也無法使任何預編譯的示例工作,如vectoradd.exe,它說,「無法分配設備向量A(錯誤代碼初始化錯誤)!」和oceanfft.exe說,「錯誤無法找到GLSL頂點和片段着色器!」這是沒有意義的,因爲GLSL和片段着色是非常基本的功能。
我的驅動程序版本是361.43,其他應用程序如CUDA模式下的Blender Cycles和Stellarium完美工作。
這裏是應該工作代碼:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
#include <algorithm>
#define N 10
__global__ void add(int *a, int *b, int *c) {
int tid = blockIdx.x; // handle the data at this index
if (tid < N)
c[tid] = a[tid] + b[tid];
}
int main(void) {
int a[N], b[N], c[N];
int *dev_a, *dev_b, *dev_c;
// allocate the memory on the GPU
cudaMalloc((void**)&dev_a, N * sizeof(int));
cudaMalloc((void**)&dev_b, N * sizeof(int));
cudaMalloc((void**)&dev_c, N * sizeof(int));
// fill the arrays 'a' and 'b' on the CPU
for (int i = 0; i<N; i++) {
a[i] = -i;
b[i] = i * i;
}
// copy the arrays 'a' and 'b' to the GPU
cudaMemcpy(dev_a, a, N * sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(dev_b, b, N * sizeof(int),cudaMemcpyHostToDevice);
add << <N, 1 >> >(dev_a, dev_b, dev_c);
// copy the array 'c' back from the GPU to the CPU
cudaMemcpy(c, dev_c, N * sizeof(int),cudaMemcpyDeviceToHost);
// display the results
for (int i = 0; i<N; i++) {
printf("%d + %d = %d\n", a[i], b[i], c[i]);
}
// free the memory allocated on the GPU
cudaFree(dev_a);
cudaFree(dev_b);
cudaFree(dev_c);
return 0;
}
我試圖開發CUDA的應用,因此任何幫助,將不勝感激。
可以確認代碼應工作。 – Mikhail
您的CUDA安裝似乎已損壞。 361.43不是隨CUDA 8 Windows安裝程序一起提供的驅動程序,並且您應該使用該驅動程序,直到您獲得一個操作系統。我的建議是[下載最新的安裝程序](https://developer.nvidia.com/cuda-downloads),然後重新安裝CUDA 8,請仔細閱讀[Windows CUDA安裝指南]中的說明(http:// docs .nvidia.com/CUDA/CUDA的安裝導微軟窗口/ index.html中#抽象)。 –
好吧,我正在下載並嘗試最新的CUDA 8.0.61工具包,並將選擇驅動程序安裝。我已經有了一個顯示驅動程序,我必須跳過工具包的驅動程序,因爲我看不到需要安裝在當前的驅動程序上。 –