Mentions légales du service

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

Update C++ gpu_mod wrapper to compute 'toarray' of transpose and adjoint of a Faust.

[skip ci]
parent b4ceb2fb
Branches
Tags
No related merge requests found
......@@ -67,6 +67,21 @@ namespace Faust {
template<typename FPP,FDevice DEVICE> class MatDense;
template<typename FPP,FDevice DEVICE> class MatGeneric;
enum FaustMulMode
{
DEFAULT,
ORDER_ALL_ENDS,
ORDER_1ST_BEST,
ORDER_ALL_BEST_CONVDENSE,
ORDER_ALL_BEST_MIXED,
PAR_SUBPRODS_CPP,
PAR_SUBPRODS_OMP,
TORCH_CPU,
TORCH_CPU_BEST_ORDER,
TORCH_CPU_DENSE_ROW_TO_TORCH,
GPU_MOD
};
enum RandFaustType {
DENSE,
SPARSE,
......@@ -121,7 +136,7 @@ namespace Faust {
// MatDense<FPP,Cpu> multiply(const MatDense<FPP,Cpu> A) const;
MatDense<FPP, Cpu> multiply(const MatDense<FPP,Cpu> A, const bool transpose=false, const bool conjugate=false);
void update_total_nnz();
void set_mul_order_opt_mode(const int mul_order_opt_mode);
void set_mul_order_opt_mode(const int mul_order_opt_mode, const bool silent=false);
void set_Fv_mul_mode(const int mode);
int get_mul_order_opt_mode() const;
......
......@@ -116,6 +116,7 @@ namespace Faust {
this->is_conjugate = conjugate?!th->is_conjugate:th->is_conjugate;
this->mul_order_opt_mode = th->mul_order_opt_mode;
this->Fv_mul_mode = th->Fv_mul_mode;
this->gpu_faust = th->gpu_faust;
}
template<typename FPP>
......@@ -227,7 +228,7 @@ namespace Faust {
// it would besides simplify the wrapper code
int tmp = mul_order_opt_mode;
set_mul_order_opt_mode(Fv_mul_mode, true);
auto vm = multiply(Faust::MatDense<FPP,Cpu>(x.getData(), this->getNbCol(), 1), transpose, conjugate);
auto vm = multiply(Faust::MatDense<FPP,Cpu>(x.getData(), x.size(), 1), transpose, conjugate);
set_mul_order_opt_mode(tmp, true);
// convert the way around
return Faust::Vect<FPP,Cpu>(vm.getNbRow(), vm.getData());
......@@ -1140,7 +1141,7 @@ namespace Faust {
#ifdef USE_GPU_MOD
case 10:
if(nullptr != gpu_faust)
return gpu_faust->get_product();
return gpu_faust->get_product(is_transposed, is_conjugate);
#endif
default:
//TODO: avoid to add one factor for all methods if possible
......
......@@ -24,8 +24,8 @@ namespace Faust
FaustGPU(std::vector<Faust::MatGeneric<FPP,Cpu>*>&);
~FaustGPU();
MatDense<FPP, Cpu> get_product();
MatDense<FPP, Cpu> multiply(const Faust::MatGeneric<FPP,Cpu>*);
MatDense<FPP, Cpu> get_product(const bool transpose = false, const bool conjugate = false);
MatDense<FPP, Cpu> multiply(const Faust::MatGeneric<FPP,Cpu>*, const bool transpose = false, const bool conjugate = false );
static void* init_gpu_mod(const std::string& libpath = "libgm.so", const bool silent = false, void* gm_handle = nullptr);
static void check_gpu_mod_loaded();
......
......@@ -48,13 +48,19 @@ namespace Faust
}
template <>
MatDense<@FAUST_SCALAR_FOR_GM@,Cpu> FaustGPU<@FAUST_SCALAR_FOR_GM@>::get_product()
MatDense<@FAUST_SCALAR_FOR_GM@,Cpu> FaustGPU<@FAUST_SCALAR_FOR_GM@>::get_product(const bool transpose /* = false */, const bool conjugate /* = false */)
{
gm_Op op = OP_NOTRANSP;
if(transpose)
if(conjugate)
op = OP_CONJTRANSP;
else
op = OP_TRANSP;
gm_DenseMatFunc_@GM_SCALAR@* dsm_funcs = (gm_DenseMatFunc_@GM_SCALAR@*) this->dsm_funcs;
gm_MatArrayFunc_@GM_SCALAR@* marr_funcs = (gm_MatArrayFunc_@GM_SCALAR@*) this->marr_funcs;
@GM_SCALAR@ one;
set_one<@GM_SCALAR@>(&one);
auto gpu_prod_mat_dense = marr_funcs->chain_matmul(gpu_mat_arr, one, OP_NOTRANSP);
auto gpu_prod_mat_dense = marr_funcs->chain_matmul(gpu_mat_arr, one, op);
int32_t nrows, ncols;
dsm_funcs->info(gpu_prod_mat_dense, &nrows, &ncols);
MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> gpu2cpu_mat(nrows, ncols);
......@@ -64,7 +70,7 @@ namespace Faust
}
template <>
MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> FaustGPU<@FAUST_SCALAR_FOR_GM@>::multiply(const MatGeneric<@FAUST_SCALAR_FOR_GM@,Cpu>* A)
MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> FaustGPU<@FAUST_SCALAR_FOR_GM@>::multiply(const MatGeneric<@FAUST_SCALAR_FOR_GM@,Cpu>* A, const bool transpose, const bool conjugate)
{
const MatSparse<@FAUST_SCALAR_FOR_GM@, Cpu>* sp_mat;
const MatDense<@FAUST_SCALAR_FOR_GM@, Cpu>* ds_mat;
......@@ -82,7 +88,9 @@ namespace Faust
// std::cout << "FaustGPU::multiply(MatDense): " << ds_mat->getNbRow() << " " << ds_mat->getNbCol()<< " " << ds_mat->getNonZeros()<< std::endl;
marr_funcs->togpu_dsm(gpu_mat_arr, ds_mat->getNbRow(), ds_mat->getNbCol(), (@GM_SCALAR@*) reinterpret_cast<@GM_REINTERPRET_CAST_SCALAR@*>(const_cast<@FAUST_SCALAR_FOR_GM@*>(ds_mat->getData())));
}
auto M = this->get_product();
marr_funcs->erase_at(gpu_mat_arr, size);
return M;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment