def rk(alpha, a, beta, c, trans='c'): """Rank-k update of a matrix.""" assert isinstance(a, mic.OffloadArray) assert isinstance(c, mic.OffloadArray) dt = map_dtype(a.dtype) # determine sizes of the matrices am = a.shape[0] ak = np.prod(a.shape[1:]) ck = c.shape[0] cn = np.prod(c.shape[1:]) n, k = am, ak ldc = c.array.strides[0] / c.array.strides[1] if a.dtype in [np.complex]: alpha = complex(alpha) beta = complex(beta) # perform the offload stream.invoke(library.mic_syrk, dt, a, c, n, k, ldc, alpha, beta) stream.sync()
def gemm(alpha, a, b, beta, c, transa='n'): # we want to make sure that we only use OffloadArrays here assert isinstance(a, mic.OffloadArray) assert isinstance(b, mic.OffloadArray) assert isinstance(c, mic.OffloadArray) # determine the datatype and map it to int dt = map_dtype(a.dtype) # determine sizes of the matrices am = a.shape[0] ak = np.prod(a.shape[1:]) bk = b.shape[0] bn = np.prod(b.shape[1:]) cm = c.shape[0] cn = np.prod(c.shape[1:]) # just some safety checks if transa == 'n': assert am == bn assert ak == cn assert bk == cm trans = 0 m, n, k = ak, bk, am lda = a.array.strides[0] / a.array.strides[-1] ldb = b.array.strides[0] / b.array.strides[1] ldc = c.array.strides[0] / c.array.strides[-1] else: assert am == cn assert ak == bn assert bk == cm trans = 1 m, n, k = am, bk, ak lda = k ldb = b.array.strides[0] / b.array.strides[-1] ldc = c.array.strides[0] / c.array.strides[1] if a.dtype in [np.complex]: alpha = complex(alpha) beta = complex(beta) # perform the offload stream.invoke(library.mic_gemm, dt, a, b, c, m, n, k, lda, ldb, ldc, alpha, beta, trans) stream.sync()
def r2k(alpha, a, b, beta, c): """Rank-2k update of a matrix.""" assert isinstance(a, mic.OffloadArray) assert isinstance(b, mic.OffloadArray) assert isinstance(c, mic.OffloadArray) assert (map_dtype(a.dtype) != 2) # determine sizes of the matrices am = a.shape[0] ak = np.prod(a.shape[1:]) bm = b.shape[0] bk = np.prod(b.shape[1:]) ck = c.shape[0] cn = np.prod(c.shape[1:]) n, k = am, ak ldc = c.array.strides[0] / c.array.strides[1] stream.invoke(library.mic_dsyr2k, a, b, c, n, k, ldc, alpha, beta) stream.sync()
def r2k(alpha, a, b, beta, c): """Rank-2k update of a matrix.""" assert isinstance(a, mic.OffloadArray) assert isinstance(b, mic.OffloadArray) assert isinstance(c, mic.OffloadArray) assert(map_dtype(a.dtype) != 2) # determine sizes of the matrices am = a.shape[0] ak = np.prod(a.shape[1:]) bm = b.shape[0] bk = np.prod(b.shape[1:]) ck = c.shape[0] cn = np.prod(c.shape[1:]) n, k = am, ak ldc = c.array.strides[0] / c.array.strides[1] stream.invoke(library.mic_dsyr2k, a, b, c, n, k, ldc, alpha, beta) stream.sync()