(self, A, B, C, alpha=1.0, beta=0.0)
Matrix multiplication using cublas library. Intended for use on Kepler
        GPUs where maxas kernels are not supported.

        C = alpha * (AB) + beta * C

        Arguments:
            A (Tensor): Input tensor
            B (Tensor): Input tensor
            C (Tensor): Output tensor
            alpha (float): Scalar for AB
            beta (float): Scalar for C
Matrix multiplication using cublas library. Intended for use on Kepler
        GPUs where maxas kernels are not supported.
Matrix multiplication using cublas library . Intended for use on Kepler GPUs where maxas kernels are not supported .
def cublas_dot(self, A, B, C, alpha=1.0, beta=0.0):
        """
        Matrix multiplication using cublas library. Intended for use on Kepler
        GPUs where maxas kernels are not supported.

        C = alpha * (AB) + beta * C

        Arguments:
            A (Tensor): Input tensor
            B (Tensor): Input tensor
            C (Tensor): Output tensor
            alpha (float): Scalar for AB
            beta (float): Scalar for C
        """
        lda = max(A.strides)
        ldb = max(B.strides)
        ldc = max(C.strides)

        opA = 't' if A.is_trans else 'n'
        opB = 't' if B.is_trans else 'n'

        m = A.shape[0]
        n = B.shape[1]
        k = A.shape[1]

        # Swap A and B to map from C order to Fortran
        if A.dtype == np.float32 or (A.dtype == np.float16 and get_compute_capability() >= 5.2):
            if n != 1 or (opA == 't' and opB == 'n'):
                cublas.cublasSgemm(self.cublas_handle, opB, opA, n, m, k, alpha, B.gpudata,
                                   ldb, A.gpudata, lda, beta, C.gpudata, ldc)
            else:
                cublas.cublasSgemv(self.cublas_handle, 't', k, m, alpha, A.gpudata,
                                   k, B.gpudata, ldb, beta, C.gpudata, ldc)

        elif A.dtype == np.float16:
            #fp16 gemm not supported by cublas until 7.5, so do conversion
            A_temp = self._buf_malloc((A.shape[0], A.shape[1] * 2))
            B_temp = self._buf_malloc((B.shape[0], B.shape[1] * 2))
            C_temp = self._buf_malloc((C.shape[0], C.shape[1] * 2))

            A_fp32 = GPUTensor(self, A.shape, dtype=np.float32, gpudata=A_temp.gpudata,
                               strides=A.strides, is_trans=A.is_trans)
            B_fp32 = GPUTensor(self, B.shape, dtype=np.float32, gpudata=B_temp.gpudata,
                               strides=B.strides, is_trans=B.is_trans)
            C_fp32 = GPUTensor(self, C.shape, dtype=np.float32, gpudata=C_temp.gpudata,
                               strides=C.strides, is_trans=C.is_trans)

            A_fp32[:] = A
            B_fp32[:] = B
            C_fp32[:] = C

            if n != 1 or (opA == 't' and opB == 'n'):
                cublas.cublasSgemm(self.cublas_handle, opB, opA, n, m, k, alpha,
                                   B_fp32.gpudata, ldb, A_fp32.gpudata, lda, beta,
                                   C_fp32.gpudata, ldc)
            else:
                cublas.cublasSgemv(self.cublas_handle, 't', k, m, alpha, A_fp32.gpudata,
                                   k, B_fp32.gpudata, ldb, beta, C_fp32.gpudata, ldc)

            C[:] = C_fp32

            self._buf_free()
        else:
            raise TypeError("Unsupported type for cublas gemm")
def cublas_dot ( self , A , B , C , alpha = 1.0 , beta = 0.0 ) : lda = max ( A . strides ) ldb = max ( B . strides ) ldc = max ( C . strides ) opA = 't' if A . is_trans else 'n' opB = 't' if B . is_trans else 'n' m = A . shape [ 0 ] n = B . shape [ 1 ] k = A . shape [ 1 ] # Swap A and B to map from C order to Fortran if A . dtype == np . float32 or ( A . dtype == np . float16 and get_compute_capability ( ) >= 5.2 ) : if n != 1 or ( opA == 't' and opB == 'n' ) : cublas . cublasSgemm ( self . cublas_handle , opB , opA , n , m , k , alpha , B . gpudata , ldb , A . gpudata , lda , beta , C . gpudata , ldc ) else : cublas . cublasSgemv ( self . cublas_handle , 't' , k , m , alpha , A . gpudata , k , B . gpudata , ldb , beta , C . gpudata , ldc ) elif A . dtype == np . float16 : #fp16 gemm not supported by cublas until 7.5, so do conversion A_temp = self . _buf_malloc ( ( A . shape [ 0 ] , A . shape [ 1 ] * 2 ) ) B_temp = self . _buf_malloc ( ( B . shape [ 0 ] , B . shape [ 1 ] * 2 ) ) C_temp = self . _buf_malloc ( ( C . shape [ 0 ] , C . shape [ 1 ] * 2 ) ) A_fp32 = GPUTensor ( self , A . shape , dtype = np . float32 , gpudata = A_temp . gpudata , strides = A . strides , is_trans = A . is_trans ) B_fp32 = GPUTensor ( self , B . shape , dtype = np . float32 , gpudata = B_temp . gpudata , strides = B . strides , is_trans = B . is_trans ) C_fp32 = GPUTensor ( self , C . shape , dtype = np . float32 , gpudata = C_temp . gpudata , strides = C . strides , is_trans = C . is_trans ) A_fp32 [ : ] = A B_fp32 [ : ] = B C_fp32 [ : ] = C if n != 1 or ( opA == 't' and opB == 'n' ) : cublas . cublasSgemm ( self . cublas_handle , opB , opA , n , m , k , alpha , B_fp32 . gpudata , ldb , A_fp32 . gpudata , lda , beta , C_fp32 . gpudata , ldc ) else : cublas . cublasSgemv ( self . cublas_handle , 't' , k , m , alpha , A_fp32 . gpudata , k , B_fp32 . gpudata , ldb , beta , C_fp32 . gpudata , ldc ) C [ : ] = C_fp32 self . _buf_free ( ) else : raise TypeError ( "Unsupported type for cublas gemm" )