Mentions légales du service

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

Implement set member function in CPU and GPU2 Faust::MatDense and GPU2...

Implement set member function in CPU and GPU2 Faust::MatDense and GPU2 Faust::MatSparse (already defined for CPU's).

Update to gpu_mod@54be9fb1
parent 6766b1ff
No related branches found
No related tags found
No related merge requests found
Subproject commit 01a397796260d3b9d304d478924389ad041ef562 Subproject commit 54be9fb1789fd70a7785ae565713580ad2b7c8b8
...@@ -290,6 +290,8 @@ namespace Faust ...@@ -290,6 +290,8 @@ namespace Faust
FPP* getData(){isZeros=false;this->is_identity=false;return mat.data();} FPP* getData(){isZeros=false;this->is_identity=false;return mat.data();}
const FPP* getData()const{return mat.data();} const FPP* getData()const{return mat.data();}
void setData(const FPP* data, int32_t nrows, int32_t ncols);
bool isEqual(const MatDense<FPP,Cpu> & B) const; bool isEqual(const MatDense<FPP,Cpu> & B) const;
bool isEqual(const MatDense<FPP,Cpu> & B, FPP threshold) const; bool isEqual(const MatDense<FPP,Cpu> & B, FPP threshold) const;
......
...@@ -256,6 +256,14 @@ namespace Faust ...@@ -256,6 +256,14 @@ namespace Faust
isZeros = false; isZeros = false;
} }
template<typename FPP>
void MatDense<FPP,Cpu>::setData(const FPP* data, int32_t nrows, int32_t ncols)
{
if(nrows != this->dim1 || ncols != this->dim2)
resize(nrows, ncols);
memcpy(getData(), data, sizeof(FPP)*nrows*ncols);
}
template<typename FPP> template<typename FPP>
MatDense<FPP,Cpu> MatDense<FPP,Cpu>::eye(faust_unsigned_int nrows, faust_unsigned_int ncols) MatDense<FPP,Cpu> MatDense<FPP,Cpu>::eye(faust_unsigned_int nrows, faust_unsigned_int ncols)
{ {
......
...@@ -256,6 +256,13 @@ namespace Faust ...@@ -256,6 +256,13 @@ namespace Faust
this->is_identity = true; this->is_identity = true;
} }
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::setData(const @FAUST_SCALAR_FOR_GM@* data, int32_t nrows, int32_t ncols)
{
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->cpu_set(gpu_mat, (const @GM_SCALAR@*) reinterpret_cast<const @GM_REINTERPRET_CAST_SCALAR@*>(data), nrows, ncols);
}
template<> template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::move(const int32_t dev_id/*=-1*/, const void* stream/*=nullptr*/) void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::move(const int32_t dev_id/*=-1*/, const void* stream/*=nullptr*/)
{ {
......
...@@ -98,6 +98,7 @@ namespace Faust ...@@ -98,6 +98,7 @@ namespace Faust
void setOnes(); void setOnes();
void setZeros(); void setZeros();
void setEyes(); void setEyes();
void setData(const FPP* data, int32_t nrows, int32_t ncols);
void transpose(); void transpose();
void conjugate(); void conjugate();
void adjoint(); void adjoint();
......
...@@ -255,6 +255,37 @@ namespace Faust ...@@ -255,6 +255,37 @@ namespace Faust
spm_funcs->set_zeros(gpu_mat); spm_funcs->set_zeros(gpu_mat);
} }
template<>
void Faust::MatSparse<@FAUST_SCALAR_FOR_GM@,GPU2>::set(int32_t nnz, int32_t nrows, int32_t ncols, @FAUST_SCALAR_FOR_GM@* values, int32_t* rowptr, int32_t* colids)
{
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs((@FAUST_SCALAR_FOR_GM@)(0));
if(gpu_mat != nullptr)
spm_funcs->cpu_set(gpu_mat, nnz, nrows, ncols, (@GM_SCALAR@*) reinterpret_cast<const @GM_REINTERPRET_CAST_SCALAR@*>(values), rowptr, colids);
}
template<>
void Faust::MatSparse<@FAUST_SCALAR_FOR_GM@,GPU2>::set(int32_t nnz, int32_t nrows, int32_t ncols, @FAUST_SCALAR_FOR_GM@* values, size_t* rowptr, size_t* colids)
{
int32_t* rowptr2 = new int32_t[nrows+1];
int32_t* colids2 = new int32_t[nnz];
for(int32_t i=0;i < nrows+1; i++)
{
//TODO: verify if rowptr[i] is not larger than int32_t capability
// if not raise an exception
rowptr2[i] = (int32_t) rowptr[i];
}
for(int32_t i=0;i < nnz; i++)
{
//TODO: verify if colids[i] is not larger than int32_t capability
colids2[i] = (int32_t) colids[i];
}
set(nnz, nrows, ncols, values, rowptr2, colids2);
delete [] rowptr2;
delete [] colids2;
}
template<typename FPP> template<typename FPP>
MatGeneric<FPP,GPU2>* MatSparse<FPP,GPU2>::Clone(const bool isOptimize /*default value=false*/) const MatGeneric<FPP,GPU2>* MatSparse<FPP,GPU2>::Clone(const bool isOptimize /*default value=false*/) const
{ {
......
...@@ -78,6 +78,8 @@ namespace Faust ...@@ -78,6 +78,8 @@ namespace Faust
void setEyes(); void setEyes();
void setIdentity(int32_t dim); void setIdentity(int32_t dim);
void setZeros(); void setZeros();
void set(int32_t nnz, int32_t nrows, int32_t ncols, FPP* values, int32_t* rowptr, int32_t* colids);
void set(int32_t nnz, int32_t nrows, int32_t ncols, FPP* values, size_t* rowptr, size_t* colids);
MatSparse<FPP, GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr) const; MatSparse<FPP, GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr) const;
MatGeneric<FPP,GPU2>* Clone(const bool isOptimize=false) const; MatGeneric<FPP,GPU2>* Clone(const bool isOptimize=false) const;
void move(const int32_t dev_id=-1, const void* stream=nullptr); void move(const int32_t dev_id=-1, const void* stream=nullptr);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment