JackWM
JackWM

Reputation: 10535

CUDA hello world failed

I am new to CUDA. Here is the first problem I met:

I tested such a piece of code from web:

#include "stdio.h"
__global__ void add(int a, int b, int *c)
{
 *c = a + b;
}
int main()
{
int a,b,c;
int *dev_c;
a=3;
b=4;
cudaMalloc((void**)&dev_c, sizeof(int));
add<<<1,1>>>(a,b,dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
printf("%d + %d is %d\n", a, b, c);
cudaFree(dev_c);
return 0;
}

It gave: 3 + 4 is 1

I compiled: nvcc eg.cu then ran: ./a.out

Anything wrong?

FYI:

evn: Ubuntu 14.04, nvcc 5.5, machine: Nvidia Quadro K600 (Kepler)

Upvotes: 0

Views: 162

Answers (1)

JackWM
JackWM

Reputation: 10535

@LeviBarnes Thanks for that helpful function. It returns "no CUDA-capable device is detected".

Then I installed the latest version (6.5) from CUDA website (run version). Now it works well! (The original version was from apt-get; version 5.5)

Even though I am still not sure the cause of this issue. Version mismatch probably is one.

Upvotes: 1

Related Questions