Hello,

I recently began a project using PyCUDA and I'm encountering some
strange behavior that I cannot figure out the source of. Before I
continue, I will preface this with a big disclaimer: I'm not a
particularly good C/C++ programmer, and it's possible the heart of
matter is just that. That said, my problem is as follows:

Floats returned from the GPU are just... not the values they should
be. This problem arose in the process of writing a much more
complicated routine, but I've been able to duplicate it in the minimal
example below.


import numpy as np
import pycuda.driver as drv
import pycuda.autoinit
from pycuda.compiler import SourceModule


mod = SourceModule(
"""
__global__ void min_example(float *a, float b)
{
    const int i = threadIdx.x;
    a[i] = b;
}
"""
)

example = mod.get_function("min_example")
aa = np.ones(512)
example(drv.InOut(aa),np.float32(1.0),block = (512,1,1))
print aa[0]  #Prints 0.0078125. What?


In the case shown, rather than 1.0, the array contains "0.0078125"
after running the kernel. Oddly enough, for b = 2.0, the output is
actually correct, or correct enough, "2.00000047684". For 3.0, I get
something like 32, for 4.0, "512.000123024", and for 5.0, 2048ish.
Now, I do see a pattern here, but what's causing it is really beyond
me. Any help would be tremendously appreciated.

Thanks,

Hugh Owens

_______________________________________________
PyCUDA mailing list
PyCUDA@tiker.net
http://lists.tiker.net/listinfo/pycuda

Reply via email to