Mentions légales du service

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

Add functions to Transform(Helper)<FPP,GPU2>: tocpu, save_mat_file.

parent 2aede5ce
No related branches found
No related tags found
No related merge requests found
......@@ -363,6 +363,22 @@ void test_Transform_get_facts()
cout << "OK" << endl;
}
void test_Transform_tocpu()
{
cout << "void test_Transform_tocpu" << endl;
vector<MatGeneric<double,GPU2>*> gpu_factors;
vector<MatGeneric<double,Cpu>*> cpu_factors;
generate_cpu_gpu_factors(gpu_factors, cpu_factors);
Faust::Transform<double, GPU2> t_gpu(gpu_factors);
Faust::Transform<double, Cpu> t_cpu(cpu_factors);
Faust::Transform<double, Cpu> t_cpu2;
t_gpu.tocpu(t_cpu2);
cout << "t_cpu.norm(): " << t_cpu.normFro() << endl;
cout << "t_cpu2.norm(): " << t_cpu2.normFro() << endl;
free_gpu_factors(gpu_factors);
cout << "OK" << endl;
}
int main()
{
Faust::enable_gpu_mod();
......@@ -383,5 +399,6 @@ int main()
test_Transform_clear();
test_Transform_spectralNorm();
test_Transform_get_facts();
test_Transform_tocpu();
return EXIT_SUCCESS;
}
......@@ -150,14 +150,22 @@ namespace Faust
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(FSFG(0));
return dsm_funcs->norm_frob(gpu_mat);
}
template<>
Faust::MatDense<FSFG, Cpu> Faust::MatDense<FSFG,GPU2>::tocpu(const void* stream/*=nullptr*/) const
void Faust::MatDense<FSFG,GPU2>::tocpu(MatDense<FSFG, Cpu>& cpu_mat, const void* stream/*=nullptr*/) const
{
MatDense<FSFG, Cpu> cpu_mat(getNbRow(), getNbCol());
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(FSFG(0));
cpu_mat.resize(getNbRow(), getNbCol());
dsm_funcs->set_stream(gpu_mat, stream);
dsm_funcs->tocpu(gpu_mat, cpu_mat.getData());
dsm_funcs->set_stream(gpu_mat, nullptr);
}
template<>
Faust::MatDense<FSFG, Cpu> Faust::MatDense<FSFG,GPU2>::tocpu(const void* stream/*=nullptr*/) const
{
MatDense<FSFG, Cpu> cpu_mat(getNbRow(), getNbCol());
this->tocpu(cpu_mat, stream);
return cpu_mat; //TODO: move constructor for MatDense<FPP, Cpu>
}
......
......@@ -98,6 +98,7 @@ namespace Faust
MatDense<FPP, GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr) const;
void move(const int32_t dev_id=-1, const void* stream=nullptr);
MatDense<FPP, Cpu> tocpu(const void* stream=nullptr) const;
void tocpu(MatDense<FPP, Cpu> &cpu_mat, const void* stream=nullptr) const;
void Display() const;
std::string to_string(const bool transpose=false, const bool displaying_small_mat_elts=false) const;
MatType getType() const;
......
......@@ -45,6 +45,8 @@ namespace Faust
void operator=(TransformHelper<FPP,GPU2>& th);
typename Transform<FPP,GPU2>::iterator begin() const;
typename Transform<FPP,GPU2>::iterator end() const;
void tocpu(TransformHelper<FPP,Cpu>& cpu_transf);
void save_mat_file(const char* filename) const;
};
}
#include "faust_TransformHelper_gpu.hpp"
......
......@@ -233,4 +233,19 @@ namespace Faust
this->Fv_mul_mode = th.Fv_mul_mode;
}
template<typename FPP>
void TransformHelper<FPP,GPU2>::save_mat_file(const char* filename) const
{
this->transform->save_mat_file(filename, this->is_transposed, this->is_conjugate);
}
template<typename FPP>
void TransformHelper<FPP,GPU2>::tocpu(TransformHelper<FPP,Cpu>& cpu_transf)
{
auto t = this->transform->tocpu();
for(auto fac: t)
cpu_transf.push_back(fac, false, false);
cpu_transf.display();
}
}
......@@ -464,4 +464,48 @@ namespace Faust
delete static_cast<MatGeneric<@FAUST_SCALAR_FOR_GM@,GPU2>*>(fact);
});
template<>
void Transform<@FAUST_SCALAR_FOR_GM@, GPU2>::tocpu(Transform<@FAUST_SCALAR_FOR_GM@, Cpu>& cpu_transf) const
{
MatDense<@FAUST_SCALAR_FOR_GM@, GPU2>* gpu_mdense = nullptr;
MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>* gpu_msparse = nullptr;
MatDense<@FAUST_SCALAR_FOR_GM@, Cpu>* cpu_mdense = nullptr;
MatSparse<@FAUST_SCALAR_FOR_GM@, Cpu>* cpu_msparse = nullptr;
for(auto gpu_mat: data)
{
if(gpu_mdense = dynamic_cast<MatDense<@FAUST_SCALAR_FOR_GM@, GPU2>*>(gpu_mat))
{
cpu_mdense = new MatDense<@FAUST_SCALAR_FOR_GM@,Cpu>(gpu_mdense->getNbRow(), gpu_mdense->getNbCol());
gpu_mdense->tocpu(*cpu_mdense);
cpu_transf.push_back(cpu_mdense, false, false);
}
else if(gpu_msparse = dynamic_cast<MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>*>(gpu_mat))
{
cpu_msparse = new MatSparse<@FAUST_SCALAR_FOR_GM@,Cpu>();
cpu_msparse->resize(gpu_msparse->getNonZeros(), gpu_msparse->getNbRow(), gpu_msparse->getNbCol());
gpu_msparse->tocpu(*cpu_msparse);
auto msparse2dense = new MatDense<@FAUST_SCALAR_FOR_GM@,Cpu>(*cpu_msparse);
delete cpu_msparse;
//TODO: fix the bug and remove the workaround (MatSparse conversion to MatDense)
cpu_transf.push_back(msparse2dense, false, false, false);
// cpu_transf.push_back(cpu_msparse, false, false, false);
}
else
throw std::runtime_error("Invalid matrix pointer");
}
}
template<>
void Transform<@FAUST_SCALAR_FOR_GM@, GPU2>::save_mat_file(const char* filename, const bool transpose, const bool conjugate) const
{
Transform<@FAUST_SCALAR_FOR_GM@,Cpu> cpu_transf;
this->tocpu(cpu_transf);
cpu_transf.save_mat_file(filename, transpose, conjugate);
}
}
......@@ -54,6 +54,9 @@ namespace Faust
void multiplyLeft(const Transform<FPP,GPU2> & A);
void multiply(const FPP& a);
Real<FPP> spectralNorm(int32_t nb_iter_max, float threshold, int& flag);
void tocpu(Transform<FPP, Cpu>& cpu_transf) const;
Transform<FPP, Cpu> tocpu() const;
void save_mat_file(const char* filename, const bool transpose, const bool conjugate) const;
// using transf_iterator = typename std::vector<MatGeneric<FPP,Cpu>*>::const_iterator;
//
// transf_iterator begin() const;
......@@ -78,7 +81,6 @@ namespace Faust
typename Transform<FPP,GPU2>::iterator begin() const;
typename Transform<FPP,GPU2>::iterator end() const;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment