Mentions légales du service

Skip to content
Snippets Groups Projects
Commit cc9b7879 authored by hhakim's avatar hhakim
Browse files

Add support of the Faust-by-csr_matrix mul. to GPU pyfaust.

parent 6e8d628e
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,7 @@ class FaustCoreCppGPU: public FaustCoreCpp<FPP, GPU2>
void get_product(FPP* y_data, int y_nrows, int y_ncols);
FaustCoreCppGPU<FPP>* mul_faust_gpu(FaustCoreCppGPU<FPP>* right);
FaustCoreCppGPU<FPP>* mul_scal_gpu(const FPP& scal);
void multiply_gpu(FPP* y_data, int y_nrows, int y_ncols, FPP* x_data, int* x_row_ptr, int* x_id_col, int x_nnz, int x_nrows, int x_ncols);
FaustCoreCppGPU<FPP>* normalize_gpu(int ord) const;
FaustCoreCppGPU<FPP>* left_gpu(const faust_unsigned_int) const;
FaustCoreCppGPU<FPP>* right_gpu(const faust_unsigned_int) const;
......
......@@ -156,4 +156,15 @@ FaustCoreCppGPU<FPP>* FaustCoreCppGPU<FPP>::fancy_idx_gpu(unsigned long int* row
{
return (FaustCoreCppGPU<FPP>*) FaustCoreCpp<FPP, GPU2>::fancy_idx(row_ids, num_rows, col_ids, num_cols);
}
template<typename FPP>
void FaustCoreCppGPU<FPP>::multiply_gpu(FPP* y_data, int y_nrows, int y_ncols, FPP* x_data, int* x_row_ptr, int* x_id_col, int x_nnz, int x_nrows, int x_ncols)
{
Faust::MatSparse<FPP, GPU2> X(x_nrows, x_ncols, x_nnz, x_data, x_row_ptr, x_id_col);
Faust::MatDense<FPP, GPU2> Y;
Y = this->transform->multiply(X);
Faust::MatDense<FPP, Cpu> Y_cpu;
Y.tocpu(Y_cpu);
memcpy(y_data, Y_cpu.getData(), sizeof(FPP)*y_ncols*y_nrows);
}
#endif
......@@ -5,6 +5,7 @@ cdef extern from "FaustCoreCpp.h":
void push_back(FPP* valueMat,unsigned int nbrow,unsigned int nbcol, bool optimizedCopy)
void multiply(FPP* value_y,int nbrow_y,int nbcol_y,FPP* value_x,
int nbrow_x, int nbcol_x);#,bool isTranspose*/);
void multiply_gpu(FPP* y_data, int y_nrows, int y_ncols, FPP* x_data, int* x_row_ptr, int* x_id_col, int x_nnz, int x_nrows, int x_ncols);
FaustCoreCppGPU[FPP]* normalize_gpu(int ord) const
@staticmethod
......
......@@ -727,3 +727,48 @@ cdef class FaustCoreGPU:
raise Exception("Failed to save the file: "+filepath)
PyMem_Free(cfilepath)
def multiply_csr_mat(self, X):
cdef double [:] x_data1d
cdef int [:] x_indices
cdef int [:] x_indptr
cdef complex [:] x_data_cplx
cdef double [:,:] y_data
cdef complex [:,:] y_data_cplx
# X is supposed to be a csr_matrix
x_indices = X.indices
x_indptr = X.indptr
x_nnz = X.nnz
nbcol = X.shape[1]
e = Exception("Dimensions must agree")
if(X.dtype in [ 'float', 'float128',
'float16', 'float32',
'float64', 'double']):
x_data1d = X.data
nbrow = self.core_faust_dbl.getNbRow()
if(self.core_faust_dbl.getNbCol() != X.shape[0]): raise e
y_data_arr = np.empty((nbrow,nbcol), dtype=np.double, order='F') # we don't know beforehand Y nnz
y_data = y_data_arr
if(self._isReal):
self.core_faust_dbl.multiply_gpu(&y_data[0,0], nbrow, nbcol,
&x_data1d[0], &x_indptr[0],
&x_indices[0],
x_nnz, X.shape[0], X.shape[1])
else:
raise("x must be real if Faust is.")
# shouldn't happen normally (avoided by calling function)
# else:
# x_data_cplx = X.data
# nbrow = self.core_faust_cplx.getNbRow()
# if(self.core_faust_cplx.getNbCol() != X.shape[0]): raise e
# y_data_arr = np.empty((nbrow,nbcol), dtype=np.complex, order='F') # we don't know beforehand Y nnz
# y_data_cplx = y_data_arr
# if(not self._isReal):
# self.core_faust_cplx.multiply_gpu(&y_data_cplx[0,0], nbrow, nbcol,
# &x_data_cplx[0], &x_indptr[0],
# &x_indices[0],
# x_nnz, X.shape[0], X.shape[1])
# else:
# raise("x must be complex if Faust is")
# # shouldn't happen normally (avoided by calling function)
return y_data_arr
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment