1

I recently started working with Pycuda. I tried executing some codes, but I get the similar kind of error for all of the codes that I have tried executing.

import pycuda.autoinit
import pycuda.driver as cuda
from pycuda.compiler import SourceModule
mod = SourceModule("""
__gloabal__ void adder(float * h_a,float * h_b,float * h_c)
{
    const int idx= blockDim.x*blockIdx.x+threadIdx.x;
    const int idy= blockDim.y*blockIdx.y+threadIdx.y;
    h_c[idx][idy]=h_a[idx][idy]+h_b[idx][idy];    
}
""")
adder=mod.get_function("adder")
h_a=numpy.random.randn(64,64)
h_a=h_a.astype(numpy.float32)
h_b=numpy.random.randn(64,64)
h_b=h_b.astype(numpy.float32)
h_c=numpy.zeros_like(h_a)
d_a=cuda.memalloc(h_a.nbytes)
d_b=cuda.memalloc(h_b.nbytes)
d_c=cuda.memalloc(h_c.nbytes)
cuda.memcpy_htod(d_a,h_a)
cuda.memcpy_htod(d_b,h_b)
adder(d_a,d_b,d_c,block=(64,64,1),grid=(1,1))
cuda.memcpy_dtoh(h_c,d_c)
print h_c

enter image description here

enter image description here

Sayali Sonawane
  • 12,289
  • 5
  • 46
  • 47
Sai Kalyan
  • 49
  • 1
  • 3
  • Is `__gloabal__` a spelling mistake in this post only, or is it actually a typo in your code? –  Jan 18 '17 at 12:55
  • __global__ is not a spelling mistake. It's the syntax of C code for running it on GPU – Sai Kalyan Nov 17 '17 at 14:55

0 Answers0