Question

I'm using C for CUDA on 3.0 computing capability and have to use built-in logarithm function of double precision. I found that for that purpose I should use double log(double x) function (documentation). But, if I pass a really small number within double precision scope (e.g. double x = 6.73E-42), log(x) function returns -Infinity. In Java Math.log() function for the same value returns -94.802. Is this a bug within CUDA math library or am I getting something wrong?

EDIT: Here's the code I'm using in the kernel function

#include "math.h"
extern "C"
__global__ void smallLog(double* in, int n)
{
   int i = blockIdx.x * blockDim.x + threadIdx.x;
   if (i<n){
      double x = in[i];
      in[i] = log(x);
   }
}
Was it helpful?

Solution

Make sure you are compiling for compute capability 3.0 (nvcc -arch sm_30).

By default, nvcc compiles for compute capability 1.0, which is single precision only and (as others have pointed out already) 6.73E-42 is zero in single precision and log(0) = -Infinity.

OTHER TIPS

For your question, the answer should be -94.802.

Try splitting log(6.73E-42) into

log(6.731E-20) + log(1E-22) = [(-44.145)+(-50.66)]=(-94.802)

Or, if you want you can split into more pieces and finally add. Am sorry, my device doesn't support double-precision. That's the answer i can give.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top