Mentions légales du service

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

Add MatGeneric<FPP,GPU2> abstract parent class for MatSparse/Dense<FPP,GPU2>...

Add MatGeneric<FPP,GPU2> abstract parent class for MatSparse/Dense<FPP,GPU2> and implement getNbRow/Col() in child classes.
parent ec4c4f4f
No related branches found
No related tags found
No related merge requests found
Showing with 108 additions and 70 deletions
Subproject commit e4f1060e5e2973fb2ac4b59520c158c03ec60116 Subproject commit f73ff0267aac9210fa6d235b550d27db036872cd
...@@ -61,7 +61,7 @@ namespace Faust ...@@ -61,7 +61,7 @@ namespace Faust
void insert(const Faust::MatGeneric<FPP,Cpu>* M, int32_t id); void insert(const Faust::MatGeneric<FPP,Cpu>* M, int32_t id);
/** TODO: this function should be deleted because it definitely slower than the version 2 */ /** TODO: this function should be deleted because it is definitely slower than the version 2 */
FPP power_iteration(int32_t max_iter, Real<FPP> threshold, int& flag); FPP power_iteration(int32_t max_iter, Real<FPP> threshold, int& flag);
/** This version differs from power_iteration in the way it computes F'Fv in this order F'(Fv) /** This version differs from power_iteration in the way it computes F'Fv in this order F'(Fv)
......
...@@ -18,6 +18,7 @@ bool Faust::FaustGPU<FPP>::are_cpu_mat_all_known(const std::vector<MatGeneric<FP ...@@ -18,6 +18,7 @@ bool Faust::FaustGPU<FPP>::are_cpu_mat_all_known(const std::vector<MatGeneric<FP
namespace Faust namespace Faust
{ {
//TODO: these functions have to move elsewhere more appropriate or simply disappear
template<> template<>
void set_one<double>(double* scal) void set_one<double>(double* scal)
{ {
......
...@@ -200,7 +200,7 @@ namespace Faust ...@@ -200,7 +200,7 @@ namespace Faust
Faust::RefManager FaustGPU<@FAUST_SCALAR_FOR_GM@>::ref_man([](void *fact) Faust::RefManager FaustGPU<@FAUST_SCALAR_FOR_GM@>::ref_man([](void *fact)
{ {
auto gp_funcs = GPUModHandler::get_singleton()->gp_funcs(); auto gp_funcs = GPUModHandler::get_singleton()->gp_funcs();
//normally cpu_gpu_map must contains a the key fac if ref_man knew it (see ctor) //normally cpu_gpu_map must contain the fact key if ref_man knew it (see ctor)
gp_funcs->free_mat(Faust::FaustGPU<@FAUST_SCALAR_FOR_GM@>::cpu_gpu_map[fact]); gp_funcs->free_mat(Faust::FaustGPU<@FAUST_SCALAR_FOR_GM@>::cpu_gpu_map[fact]);
Faust::FaustGPU<@FAUST_SCALAR_FOR_GM@>::cpu_gpu_map.erase(fact); Faust::FaustGPU<@FAUST_SCALAR_FOR_GM@>::cpu_gpu_map.erase(fact);
}); });
......
...@@ -2,18 +2,17 @@ ...@@ -2,18 +2,17 @@
#define __FAUST_MATDENSE_GPU2__ #define __FAUST_MATDENSE_GPU2__
#ifdef USE_GPU_MOD #ifdef USE_GPU_MOD
#include "faust_MatDense.h" #include "faust_MatDense.h"
#include "faust_MatGeneric_gpu.h"
#include "faust_gpu_mod_utils.h" #include "faust_gpu_mod_utils.h"
namespace Faust namespace Faust
{ {
template<typename FPP,FDevice DEVICE>
class MatDense;
template <typename FPP> template <typename FPP>
void gemm(const MatDense<FPP, GPU2> &A, const MatDense<FPP, GPU2> &B, MatDense<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB); void gemm(const MatDense<FPP, GPU2> &A, const MatDense<FPP, GPU2> &B, MatDense<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB);
template<typename FPP> template<typename FPP>
class MatDense<FPP, GPU2> : MatDense<FPP, Cpu> class MatDense<FPP, GPU2> : public MatGeneric<FPP,GPU2>
{ {
friend void gemm<>(const MatDense<FPP, GPU2> &A, const MatDense<FPP, GPU2> &B, MatDense<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB); friend void gemm<>(const MatDense<FPP, GPU2> &A, const MatDense<FPP, GPU2> &B, MatDense<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB);
...@@ -86,11 +85,14 @@ namespace Faust ...@@ -86,11 +85,14 @@ namespace Faust
MatDense<FPP, Cpu> tocpu(const void* stream=nullptr) const; MatDense<FPP, Cpu> tocpu(const void* stream=nullptr) const;
void Display() const; void Display() const;
std::string to_string(const bool transpose=false, const bool displaying_small_mat_elts=false) const; std::string to_string(const bool transpose=false, const bool displaying_small_mat_elts=false) const;
int32_t getNbRow() const;
int32_t getNbCol() const;
private: private:
gm_DenseMat_t gpu_mat; gm_DenseMat_t gpu_mat;
}; };
};
}
#include "faust_MatDense_gpu_double.hpp" #include "faust_MatDense_gpu_double.hpp"
#endif #endif
#endif #endif
//TODO: move to CPP //TODO: move to CPP
namespace Faust namespace Faust
{ {
template<>
int32_t Faust::MatDense<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbRow() const
{
int32_t nrows;
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->info(gpu_mat, &nrows, nullptr);
return nrows;
}
template<>
int32_t Faust::MatDense<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbCol() const
{
int32_t ncols;
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->info(gpu_mat, nullptr, &ncols);
return ncols;
}
template<> template<>
Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::MatDense( Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::MatDense(
const faust_unsigned_int nbRow, const faust_unsigned_int nbRow,
...@@ -8,10 +26,8 @@ namespace Faust ...@@ -8,10 +26,8 @@ namespace Faust
const @FAUST_SCALAR_FOR_GM@* data/*=nullptr*/, const @FAUST_SCALAR_FOR_GM@* data/*=nullptr*/,
const bool no_alloc/*= false*/, const bool no_alloc/*= false*/,
const int32_t dev_id/*=-1*/, const int32_t dev_id/*=-1*/,
const void* stream/*=nullptr*/) const void* stream/*=nullptr*/) : MatGeneric<@FAUST_SCALAR_FOR_GM@,GPU2>()
{ {
this->dim1 = nbRow;
this->dim2 = nbCol;
auto gp_funcs = GPUModHandler::get_singleton()->gp_funcs(); auto gp_funcs = GPUModHandler::get_singleton()->gp_funcs();
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
// create the matrix in the device dev_id memory // create the matrix in the device dev_id memory
...@@ -45,18 +61,17 @@ namespace Faust ...@@ -45,18 +61,17 @@ namespace Faust
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, other.gpu_mat, other.gpu_mat, OP_NOTRANSP, OP_NOTRANSP); dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, other.gpu_mat, other.gpu_mat, OP_NOTRANSP, OP_NOTRANSP);
//TODO: update dims (in transpose/adjoint case) //TODO: update dims (in transpose/adjoint case)
other.dim1 = dim1;
} }
template<> template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> &other, const char op_this) void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> &other, const char op_this)
{ {
// other = this * other // other = this * other
//TODO: update dims (in transpose/adjoint case)
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
MatDense<@FAUST_SCALAR_FOR_GM@, GPU2> other_gpu_mat(other.dim1, other.dim2,other.getData()); MatDense<@FAUST_SCALAR_FOR_GM@, GPU2> other_gpu_mat(other.getNbRow(), other.getNbCol(), other.getData());
other.resize(this->getNbRow(), other.getNbCol());
dsm_funcs->mul_gpu_dsm_tocpu_ext(this->gpu_mat, other_gpu_mat.gpu_mat, other.getData(), OP_NOTRANSP, OP_NOTRANSP); dsm_funcs->mul_gpu_dsm_tocpu_ext(this->gpu_mat, other_gpu_mat.gpu_mat, other.getData(), OP_NOTRANSP, OP_NOTRANSP);
//TODO: update dims (in transpose/adjoint case)
other.dim1 = dim1;
} }
template<> template<>
...@@ -64,7 +79,7 @@ namespace Faust ...@@ -64,7 +79,7 @@ namespace Faust
{ {
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
MatDense<@FAUST_SCALAR_FOR_GM@, GPU2> gpu_vec(vec.size(), 1, vec.getData()); MatDense<@FAUST_SCALAR_FOR_GM@, GPU2> gpu_vec(vec.size(), 1, vec.getData());
Faust::Vect<@FAUST_SCALAR_FOR_GM@, Cpu> out_v(dim2); Faust::Vect<@FAUST_SCALAR_FOR_GM@, Cpu> out_v(getNbCol());
dsm_funcs->mul_gpu_dsm_tocpu_ext(this->gpu_mat, gpu_vec.gpu_mat, out_v.getData(), OP_NOTRANSP, OP_NOTRANSP); dsm_funcs->mul_gpu_dsm_tocpu_ext(this->gpu_mat, gpu_vec.gpu_mat, out_v.getData(), OP_NOTRANSP, OP_NOTRANSP);
return out_v; return out_v;
} }
...@@ -113,7 +128,7 @@ namespace Faust ...@@ -113,7 +128,7 @@ namespace Faust
template<> template<>
Faust::MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::tocpu(const void* stream/*=nullptr*/) const Faust::MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::tocpu(const void* stream/*=nullptr*/) const
{ {
MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> cpu_mat(dim1, dim2); MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> cpu_mat(getNbRow(), getNbCol());
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->set_stream(gpu_mat, stream); dsm_funcs->set_stream(gpu_mat, stream);
dsm_funcs->tocpu(gpu_mat, cpu_mat.getData()); dsm_funcs->tocpu(gpu_mat, cpu_mat.getData());
...@@ -125,12 +140,12 @@ namespace Faust ...@@ -125,12 +140,12 @@ namespace Faust
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::resize(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol) void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::resize(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol)
{ {
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->resize(gpu_mat, nbRow, nbCol); dsm_funcs->resize(gpu_mat, getNbRow(), getNbCol());
this->dim1 = nbRow; #ifndef NDEBUG
this->dim2 = nbCol;
int32_t new_nrows, new_ncols; int32_t new_nrows, new_ncols;
dsm_funcs->info(gpu_mat, &new_nrows, &new_ncols); dsm_funcs->info(gpu_mat, &new_nrows, &new_ncols);
assert(nbRow == new_nrows && new_ncols == nbCol); assert(getNbRow() == new_nrows && new_ncols == getNbCol());
#endif
} }
template<> template<>
...@@ -145,7 +160,7 @@ namespace Faust ...@@ -145,7 +160,7 @@ namespace Faust
{ {
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->setzeros(gpu_mat); dsm_funcs->setzeros(gpu_mat);
this->isZeros = true; this->is_zeros = true;
} }
template<> template<>
...@@ -177,7 +192,7 @@ namespace Faust ...@@ -177,7 +192,7 @@ namespace Faust
// use a stream (nullptr means default) // use a stream (nullptr means default)
dsm_funcs->set_stream(this->gpu_mat, stream); dsm_funcs->set_stream(this->gpu_mat, stream);
auto gpu_mat = dsm_funcs->clone(this->gpu_mat); auto gpu_mat = dsm_funcs->clone(this->gpu_mat);
auto clone_mat = new Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>(dim1, dim2, nullptr, /*no_alloc*/true, dev_id); auto clone_mat = new Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>(getNbRow(), getNbCol(), nullptr, /*no_alloc*/true, dev_id);
clone_mat->gpu_mat = gpu_mat; clone_mat->gpu_mat = gpu_mat;
// return to previous device // return to previous device
gp_funcs->set_dev(cur_dev_id); gp_funcs->set_dev(cur_dev_id);
...@@ -191,9 +206,6 @@ namespace Faust ...@@ -191,9 +206,6 @@ namespace Faust
{ {
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->transpose(this->gpu_mat); dsm_funcs->transpose(this->gpu_mat);
auto tmp = dim1;
dim1 = dim2;
dim2 = tmp;
} }
template<> template<>
...@@ -201,9 +213,6 @@ namespace Faust ...@@ -201,9 +213,6 @@ namespace Faust
{ {
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->adjoint(this->gpu_mat); dsm_funcs->adjoint(this->gpu_mat);
auto tmp = dim1;
dim1 = dim2;
dim2 = tmp;
} }
template<> template<>
...@@ -332,12 +341,11 @@ namespace Faust ...@@ -332,12 +341,11 @@ namespace Faust
// other = this * other // other = this * other
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, A.gpu_mat, this->gpu_mat, OP_NOTRANSP, OP_NOTRANSP); dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, A.gpu_mat, this->gpu_mat, OP_NOTRANSP, OP_NOTRANSP);
Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2> new_this(dim1, A.dim2, nullptr); Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2> new_this(getNbRow(), A.getNbCol(), nullptr);
dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, A.gpu_mat, new_this.gpu_mat, OP_NOTRANSP, OP_NOTRANSP); dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, A.gpu_mat, new_this.gpu_mat, OP_NOTRANSP, OP_NOTRANSP);
auto tmp = this->gpu_mat; auto tmp = this->gpu_mat;
this->gpu_mat = new_this.gpu_mat; this->gpu_mat = new_this.gpu_mat;
new_this.gpu_mat = tmp; new_this.gpu_mat = tmp;
this->dim2 = A.dim2;
} }
template<> template<>
...@@ -346,12 +354,11 @@ namespace Faust ...@@ -346,12 +354,11 @@ namespace Faust
// this = this * other // this = this * other
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
MatDense<@FAUST_SCALAR_FOR_GM@,GPU2> gpuA(A.getNbRow(), A.getNbCol(), A.getData()); MatDense<@FAUST_SCALAR_FOR_GM@,GPU2> gpuA(A.getNbRow(), A.getNbCol(), A.getData());
Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2> new_this(dim1, A.dim2, nullptr); Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2> new_this(getNbRow(), A.getNbCol(), nullptr);
dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, gpuA.gpu_mat, new_this.gpu_mat, OP_NOTRANSP, OP_NOTRANSP); dsm_funcs->mul_gpu_dsm_ext(this->gpu_mat, gpuA.gpu_mat, new_this.gpu_mat, OP_NOTRANSP, OP_NOTRANSP);
auto tmp = this->gpu_mat; auto tmp = this->gpu_mat;
this->gpu_mat = new_this.gpu_mat; this->gpu_mat = new_this.gpu_mat;
new_this.gpu_mat = tmp; new_this.gpu_mat = tmp;
this->dim2 = A.dim2;
} }
template<> template<>
...@@ -371,8 +378,9 @@ namespace Faust ...@@ -371,8 +378,9 @@ namespace Faust
{ {
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs(@FAUST_SCALAR_FOR_GM@(0));
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
if(isZeros) if(is_zeros)
{ {
resize(S.getNbRow(), getNbCol());
setZeros(); setZeros();
} }
else else
...@@ -383,7 +391,6 @@ namespace Faust ...@@ -383,7 +391,6 @@ namespace Faust
dsm_funcs->free(this->gpu_mat); dsm_funcs->free(this->gpu_mat);
spm_funcs->free(gpu_S); spm_funcs->free(gpu_S);
this->gpu_mat = gpu_out; this->gpu_mat = gpu_out;
this->dim1 = S.getNbRow();
} }
} }
...@@ -392,9 +399,7 @@ namespace Faust ...@@ -392,9 +399,7 @@ namespace Faust
{ {
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0)); auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dim1 = A.getNbRow(); auto gpu_mat = dsm_funcs->togpu(getNbRow(), getNbCol(), const_cast<@FAUST_SCALAR_FOR_GM@*>(A.getData()));
dim2 = A.getNbCol();
auto gpu_mat = dsm_funcs->togpu(dim1, dim2, const_cast<@FAUST_SCALAR_FOR_GM@*>(A.getData()));
dsm_funcs->free(this->gpu_mat); dsm_funcs->free(this->gpu_mat);
this->gpu_mat = gpu_mat; this->gpu_mat = gpu_mat;
} }
...@@ -413,8 +418,6 @@ namespace Faust ...@@ -413,8 +418,6 @@ namespace Faust
auto gpu_mat = dsm_funcs->clone(A.gpu_mat); auto gpu_mat = dsm_funcs->clone(A.gpu_mat);
dsm_funcs->free(this->gpu_mat); dsm_funcs->free(this->gpu_mat);
this->gpu_mat = gpu_mat; this->gpu_mat = gpu_mat;
this->dim1 = A.dim1;
this->dim2 = A.dim2;
} }
template <> template <>
...@@ -456,4 +459,6 @@ namespace Faust ...@@ -456,4 +459,6 @@ namespace Faust
{ {
std::cout << this->to_string(); std::cout << this->to_string();
} }
}; };
#ifndef __FAUST_MATGENERIC_GPU__
#define __FAUST_MATGENERIC_GPU__
namespace Faust
{
//TODO: this class is temporary, ideally MatSparse<FPP,GPU2> and MatDense<FPP,GPU2> should extend the MatGeneric<FPP, Device> class
//TODO: keep this class until MatSparse<FPP,GPU2> and MatDense<FPP,GPU2> fully implement the MatGeneric<FPP, Device> methods
// The interest of this class is mostly to make Transform capable of storing generic matrix
template<typename FPP>
class MatGeneric<FPP, GPU2>
{
protected:
bool is_identity;
bool is_zeros;
public:
virtual int32_t getNbRow() const=0;
virtual int32_t getNbCol() const=0;
MatGeneric();
virtual ~MatGeneric();
};
}
#include "faust_MatGeneric_gpu.hpp"
#endif
namespace Faust
{
template<typename FPP>
MatGeneric<FPP,GPU2>::~MatGeneric()
{
}
template<typename FPP>
MatGeneric<FPP,GPU2>::MatGeneric() : is_zeros(false), is_identity(false)
{
}
}
...@@ -3,15 +3,12 @@ ...@@ -3,15 +3,12 @@
#ifdef USE_GPU_MOD #ifdef USE_GPU_MOD
#include "faust_gpu_mod_utils.h" #include "faust_gpu_mod_utils.h"
#include "faust_constant.h" #include "faust_constant.h"
#include "faust_MatGeneric_gpu.h"
namespace Faust namespace Faust
{ {
template<typename FPP,FDevice DEVICE>
class MatSparse;
template<typename FPP> template<typename FPP>
class MatSparse<FPP, GPU2> class MatSparse<FPP, GPU2> : public MatGeneric<FPP,GPU2>
{ {
public: public:
...@@ -66,8 +63,8 @@ namespace Faust ...@@ -66,8 +63,8 @@ namespace Faust
void setZeros(); void setZeros();
MatSparse<FPP, GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr); MatSparse<FPP, GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr);
void move(const int32_t dev_id=-1, const void* stream=nullptr); void move(const int32_t dev_id=-1, const void* stream=nullptr);
int32_t getNbRow(); int32_t getNbRow() const;
int32_t getNbCol(); int32_t getNbCol() const;
int32_t getNonZeros(); int32_t getNonZeros();
int32_t getDevice() const; int32_t getDevice() const;
void Display() const; void Display() const;
...@@ -75,8 +72,6 @@ namespace Faust ...@@ -75,8 +72,6 @@ namespace Faust
~MatSparse(); ~MatSparse();
private: private:
int32_t nbRow;
int32_t nbCol;
gm_SparseMat_t gpu_mat; gm_SparseMat_t gpu_mat;
}; };
......
//TODO: move to cpp.in //TODO: move to cpp.in
namespace Faust namespace Faust
{ {
template<>
int32_t Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbRow() const
{
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0));
int32_t nbRow;
spm_funcs->info(gpu_mat, &nbRow, nullptr, nullptr); //TODO gpu_mod: add get_nnz, get_nrows, get_ncols
return nbRow;
}
template<>
int32_t Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbCol() const
{
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0));
int32_t nbCol;
spm_funcs->info(gpu_mat, nullptr, &nbCol, nullptr); //TODO gpu_mod: add get_nnz, get_nrows, get_ncols
return nbCol;
}
template<> template<>
...@@ -12,7 +29,7 @@ namespace Faust ...@@ -12,7 +29,7 @@ namespace Faust
const int32_t* rowptr, /*= nullptr,*/ const int32_t* rowptr, /*= nullptr,*/
const int32_t* colinds, /*= nullptr,*/ const int32_t* colinds, /*= nullptr,*/
const int32_t dev_id,/*=-1,*/ const int32_t dev_id,/*=-1,*/
const void* stream)/*=nullptr)*/ : nbRow(nbRow), nbCol(nbCol) const void* stream)/*=nullptr)*/
{ {
if(values != nullptr) if(values != nullptr)
{ {
...@@ -24,7 +41,6 @@ namespace Faust ...@@ -24,7 +41,6 @@ namespace Faust
gp_funcs->set_dev(dev_id); gp_funcs->set_dev(dev_id);
gpu_mat = spm_funcs->togpu_stream(nbRow, nbCol, nnz, rowptr, colinds, values, stream); gpu_mat = spm_funcs->togpu_stream(nbRow, nbCol, nnz, rowptr, colinds, values, stream);
gp_funcs->set_dev(cur_dev_id); gp_funcs->set_dev(cur_dev_id);
spm_funcs->info(gpu_mat, &this->nbRow, &this->nbCol, /*nnz*/ nullptr); //normally useless (bcause dims are already initialized), but init from GPU again just in case of inconsistency that would show up in tests
} }
else gpu_mat = nullptr; else gpu_mat = nullptr;
} }
...@@ -62,8 +78,6 @@ namespace Faust ...@@ -62,8 +78,6 @@ namespace Faust
{ {
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0)); auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0));
spm_funcs->copy(mat.gpu_mat, gpu_mat); spm_funcs->copy(mat.gpu_mat, gpu_mat);
nbRow = mat.nbRow;
nbCol = mat.nbCol;
} }
template<> template<>
...@@ -114,8 +128,6 @@ namespace Faust ...@@ -114,8 +128,6 @@ namespace Faust
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0)); auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0));
spm_funcs->free(this->gpu_mat); spm_funcs->free(this->gpu_mat);
this->gpu_mat = gmat.gpu_mat; this->gpu_mat = gmat.gpu_mat;
this->nbRow = gmat.nbRow;
this->nbCol = gmat.nbCol;
gmat.gpu_mat = nullptr; // to avoid freeing the new gpu_mat when leaving this scope gmat.gpu_mat = nullptr; // to avoid freeing the new gpu_mat when leaving this scope
} }
...@@ -171,8 +183,6 @@ namespace Faust ...@@ -171,8 +183,6 @@ namespace Faust
template<> template<>
void Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::resize(int32_t nnz, int32_t nrows, int32_t ncols) void Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::resize(int32_t nnz, int32_t nrows, int32_t ncols)
{ {
nbRow = nrows;
nbCol = ncols;
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0)); auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0));
spm_funcs->resize(gpu_mat, nnz, nrows, ncols); spm_funcs->resize(gpu_mat, nnz, nrows, ncols);
} }
...@@ -204,7 +214,7 @@ namespace Faust ...@@ -204,7 +214,7 @@ namespace Faust
// use a stream (nullptr means default) // use a stream (nullptr means default)
spm_funcs->set_stream(this->gpu_mat, stream); spm_funcs->set_stream(this->gpu_mat, stream);
auto gpu_mat = spm_funcs->clone(this->gpu_mat); auto gpu_mat = spm_funcs->clone(this->gpu_mat);
auto clone_mat = new Faust::MatSparse<@FAUST_SCALAR_FOR_GM@,GPU2>(nbRow, nbCol, /*nnz*/ 0, /*values*/ nullptr, /*rowptr */ nullptr, /*colinds*/ nullptr, dev_id, stream); auto clone_mat = new Faust::MatSparse<@FAUST_SCALAR_FOR_GM@,GPU2>(getNbRow(), getNbCol(), /*nnz*/ 0, /*values*/ nullptr, /*rowptr */ nullptr, /*colinds*/ nullptr, dev_id, stream);
clone_mat->gpu_mat = gpu_mat; clone_mat->gpu_mat = gpu_mat;
// return to previous device // return to previous device
gp_funcs->set_dev(cur_dev_id); gp_funcs->set_dev(cur_dev_id);
...@@ -223,17 +233,6 @@ namespace Faust ...@@ -223,17 +233,6 @@ namespace Faust
spm_funcs->set_stream(gpu_mat, nullptr); spm_funcs->set_stream(gpu_mat, nullptr);
} }
template<>
int32_t Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbRow()
{
return nbRow;
}
template<>
int32_t Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbCol()
{
return nbCol;
}
template<> template<>
int32_t Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::getNonZeros() int32_t Faust::MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::getNonZeros()
......
...@@ -216,6 +216,7 @@ namespace Faust ...@@ -216,6 +216,7 @@ namespace Faust
faust_unsigned_int dim2; faust_unsigned_int dim2;
bool is_ortho; bool is_ortho;
bool is_identity; bool is_identity;
//TODO: add is_zeros
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment