Received from Mike Tischler on Thu, Mar 24, 2011 at 06:30:20PM EDT:
> Lev,
>
> Thanks for the explanation...that definitely helps. But how does the
> indexing
> work for a 2d case?
>
> z1 = numpy.zeros((1024)).astype(numpy.float32)
> kernel1(drv.Out(z1),block=(16,16,1),grid=(2,2))
>
> int idx=??
> int idy =??
>
> Thanks!
> Mike
There are a variety of ways. I have attached an example that accesses
a 2D array as a 1D array.
L.G.
#!/usr/bin/env python
import pycuda.autoinit
import pycuda.driver as drv
import pycuda.gpuarray as gpuarray
from pycuda.compiler import SourceModule
import numpy as np
rows = 4
cols = 256
a = np.zeros((rows, cols), np.int32)
func_str = """
// y is the row, x is the column, c is the number of columns
#define INDEX(y, x, c) (y*c+x)
__global__ void func(int *a, int rows, int cols) {
int ix = blockIdx.x*blockDim.x+threadIdx.x;
int iy = blockIdx.y;
if (iy < rows && ix < cols)
a[INDEX(iy, ix, cols)] = INDEX(iy, ix, cols);
}
"""
func_mod = SourceModule(func_str)
func = func_mod.get_function('func')
func(drv.Out(a), np.int32(rows), np.int32(cols),
block=(256, 1, 1), grid=(4, 1))
print a
_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda