How to do element-wise assignment in pycuda / scikits.cuda?

322 views Asked by At

Here's the code:

import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import pycuda.driver as drv
import numpy as np

import scikits.cuda.linalg as culinalg
import scikits.cuda.misc as cumisc
culinalg.init()

ag = gpuarray.to_gpu(np.random.rand(1000,1000))
bg = gpuarray.to_gpu(np.zeros((1000,1000))
bg[:,:] = ag

I got the following error:

TypeError: 'GPUArray' object does not support item assignment

So any way to assign a matrix to another existing matrix in pycuda/ scikits.cuda ?

1

There are 1 answers

0
Xing Shi On BEST ANSWER

Ok, this is not an elegant way, but a solution: Use the ElementwiseKernel of pycuda:

import from pycuda.elementwise import ElementwiseKernel
ele_assign = ElementwiseKernel("double *a,double *b","a[i] = b[i]","ele_assign")
ele_assign(bg,ag)