def test_gufunc(self): gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)', target=self.target) gufunc.add((float32[:, :], float32[:, :], float32[:, :])) gufunc = gufunc.build_ufunc() self.check_matmul_gufunc(gufunc)
def test_ufunc_like(self): # Test problem that the stride of "scalar" gufunc argument not properly # handled when the actual argument is an array, # causing the same value (first value) being repeated. gufunc = GUVectorize(axpy, '(), (), () -> ()', target=self.target) gufunc.add('(intp, intp, intp, intp[:])') gufunc = gufunc.build_ufunc() x = np.arange(10, dtype=np.intp) out = gufunc(x, x, x) np.testing.assert_equal(out, x * x + x)
def test_gufunc(self): gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)', target='cpu') gufunc.add(argtypes=[float32[:, :], float32[:, :], float32[:, :]]) gufunc = gufunc.build_ufunc() matrix_ct = 1001 # an odd number to test thread/block division in CUDA A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4) B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5) C = gufunc(A, B) Gold = ut.matrix_multiply(A, B) self.assertTrue(np.allclose(C, Gold))
def wrap(func): guvec = GUVectorize(func, sig, nopython=True) for t in coretypes: guvec.add(t) g = guvec.build_ufunc() def h(*args, **kwargs): out = g(*args, **kwargs) view = xnd.from_buffer(out) ret = xnd.empty(view.type) np.copyto(np.array(ret, copy=False), out) return ret return h
def test_gufunc(self): gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)', target=self.target) gufunc.add((float32[:, :], float32[:, :], float32[:, :])) gufunc = gufunc.build_ufunc() matrix_ct = 1001 A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4) B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5) C = gufunc(A, B) Gold = ut.matrix_multiply(A, B) self.assertTrue(np.allclose(C, Gold))
def test_gufunc(self, target='cpu'): gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)', target=self.target) gufunc.add((float32[:, :], float32[:, :], float32[:, :])) gufunc = gufunc.build_ufunc() matrix_ct = 1001 A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4) B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5) C = gufunc(A, B) Gold = ut.matrix_multiply(A, B) self.assertTrue(np.allclose(C, Gold))