0

这是代码:

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

我收到以下错误:

TypeError: 'GPUArray' object does not support item assignment

那么有什么方法可以将矩阵分配给 pycuda/scikits.cuda 中的另一个现有矩阵?

4

1 回答 1

1

好的,这不是一个优雅的方式,而是一个解决方案:使用pycuda的ElementwiseKernel:

import from pycuda.elementwise import ElementwiseKernel
ele_assign = ElementwiseKernel("double *a,double *b","a[i] = b[i]","ele_assign")
ele_assign(bg,ag)
于 2014-11-15T08:38:03.620 回答