Snurka Bill
Snurka Bill

Reputation: 983

multiplication two floats variables on CUDA

I have really interesting problem, but I am solving it for 3 hours and I just can't figure out what is going on and why it isn't working. I tried google it, but with no results.

I am coding program on CUDA. I have this really simple piece of code:

__global__ void calcErrorOutputLayer_kernel(*arguments...*)
{

   int idx = blockIdx.x * blockDim.x + threadIdx.x;
   float gradient;
   float derivation;
   derivation = pow((2/(pow(euler, neuron_device[startIndex + idx].outputValue) +
                pow(euler, -neuron_device[startIndex + idx].outputValue))), 2);
   gradient = (backVector_device[idx] - neuron_device[startIndex + idx].outputValue);

   gradient = gradient * derivation;   //this line doesn't work   
   gradient = gradient * 2.0;          //this line works

ok, so gradient is calculated correctly and also derivation. but when comes line, where should be these two variables multiplicated with each other nothing happens (value of gradient isn't changed) and on next line CUDA debugger tells me that: " 'derivation' has no value at the target location "

gradient * 2.0 works correctly and it change value of gradient 2 times.

Can anyone help me please?

Upvotes: 4

Views: 1255

Answers (1)

dreamcrash
dreamcrash

Reputation: 51433

a = pow(euler, neuron_device[startIndex + idx].outputValue);
b = pow(euler, -neuron_device[startIndex + idx].outputValue);
derivation = pow((2/(a + b),2);

Pow gives an error when:

  • the base is negative and exponent is not an integral value, or
  • the base is zero and the exponent is negative, a domain error occurs, setting the global variable errno to the value EDOM.

I guess that you are facing precision problems, and both 'a' and 'b' are 0. You probably are getting derivation = 0 or "inf".

Can you change floats to doubles?

Upvotes: 4

Related Questions