def iddr_rid(queue, m, n, matvect, krank): id_srand = util.setup_rand(queue) blas.setup() dtype = 'float64' clx = cl_array.zeros(queue, m, dtype) rnorms = cl_array.Array(queue, n, dtype) lst = cl_array.Array(queue, n, np.int32) proj = cl_array.Array(queue, (krank+2,n), dtype) l = krank + 2 for i in range(l): id_srand(m, clx) matvect(clx, proj[i,:]) iddr_id(queue, l, n, proj, krank, lst, rnorms) blas.teardown() return lst, proj
rng = np.random.RandomState(1) # change the seed to see different data A[...] = rng.uniform(-1, 1, size=A.shape) x[...] = rng.uniform(-1, 1, size=x.shape) y[...] = rng.uniform(-1, 1, size=y.shape) # allocate OpenCL memory on the device clA = Array(queue, A.shape, A.dtype) clx = Array(queue, x.shape, x.dtype) cly = Array(queue, y.shape, y.dtype) # copy data to device clA.set(A) clx.set(x) # compute a matrix-vector product (gemv) blas.gemv(queue, clA, clx, cly) # check the result print("Expected: ", np.dot(A, x)) print("Actual: ", cly.get()) # try a matrix-vector product with the transpose cly.set(y) blas.gemv(queue, clA, cly, clx, transA=True) print("Expected: ", np.dot(A.T, y)) print("Actual: ", clx.get()) # tidy up the BLAS blas.teardown()