我遇到了一个非常奇怪的问题:Mu 9800 GT 似乎根本不计算。
我已经尝试了在互联网上找到的所有 hello-worlds,这是其中之一:
该程序在主机上创建 1..100 数组,将其发送到设备,计算每个值的平方,将其返回到主机,打印结果。
#include "stdafx.h"
#include <stdio.h>
#include <cuda.h>
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N) a[idx] = a[idx] * a[idx];
}
// main routine that executes on the host
int main(void)
{
float *a_h, *a_d; // Pointer to host & device arrays
const int N = 100; // Number of elements in arrays
size_t size = N * sizeof(float);
a_h = (float *)malloc(size); // Allocate array on host
cudaMalloc((void **) &a_d, size); // Allocate array on device
// Initialize host array and copy it to CUDA device
for (int i=0; i<N; i++) a_h[i] = (float)i;
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
// Do calculation on device:
int block_size = 4;
int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);
square_array <<< n_blocks, block_size >>> (a_d, N);
// Retrieve result from device and store it in host array
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
// Print results
for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);
// Cleanup
free(a_h); cudaFree(a_d);
}
所以输出预计为:
1 1.000
2 4.000
3 9.000
4 16.000
..
我发誓在 2009 年它运行得非常完美(vista 32、deviceemu)
现在我得到输出:
1 1.000
2 2.000
3 3.000
4 4.000
所以我的卡没有做任何事情。可能是什么问题?
配置是:
win7x64
视觉工作室 2010 32 位
cuda工具包3.2 64位
编译设置:cuda 3.2 工具包、32 位目标平台、deviceemu 与否 - 没关系,结果是一样的。
我也在我的vmware xp(32位) Visual Studio 2008上尝试过。结果是一样的。
请帮助我,我几乎没有编译程序,现在我需要它工作。
您还可以查看我的项目及其所需的一切(2.7 KB)
谢谢,伊利亚