views:

72

answers:

1

Hi everyone. I'm encountering a very strange problem: Mu 9800GT doesnt seem to calculate at all. I've tried all hello-worlds i've found in the internet, here's one of them:

this program creates 1..100 array on hosts, sends it to device, calculates a square of each value, returns it to host, prints the results.

#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);
}

so the output is expected to be:

1 1.000

2 4.000

3 9.000

4 16.000

.. I swear back in 2009 it worked perfectly (vista 32, deviceemu)

now i get output:

1 1.000

2 2.000

3 3.000

4 4.000

so my card doesnt do anything. What can be the problem? Configuration is: win7x64 visual studio 2010 32bit cuda toolkit 3.2 64bit

compilation settings: cuda 3.2 toolkit, 32-bit target platform, deviceemu or not - doesnt matter, the results are the same.

i also tried it on my vmware xp(32bit) visual studio 2008. the result is the same.

Please help me, i barely made the programe to compile, now i need it to work.

You can also view my project with all it needs from my post at nvidia forums ( 2.7 kb)

Thanks, Ilya

+2  A: 

Your code produces the intended results on my Linux system so I would suggest checking the error codes returned by cudaMalloc and cudaMemcpy to ensure there are no silent driver/runtime errors. For example

cudaError_t error = cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
printf("error status: %s\n", cudaGetErrorString(error));

should print

error status: no error

if the call is successful.

Also, I believe device emulation was deprecated in CUDA 3.0 and removed entirely in CUDA 3.1. I don't know if that's related to your problem though.

To compile several files you'd just do something like this

$nvcc -c foo.cu
$nvcc -c bar.cu
$nvcc -o foobar foo.o bar.o

alternatively, you can do the linking in the last step with g++ like so

$g++ -o foobar foo.o bar.o -L/usr/local/cuda/lib64 -lcudart
wnbell
yep, figured that out myself :) error cudaErrorInsufficientDriver = CUDA runtime is newer than driver. will now remove all drivers, reboot and install them from scratch
portland
please post your g++ compilation string here and i'll mark this as an answer. (I actually need it to be run under ubuntu, but have no idea how to compile more than 1 file :))
portland