Mentions légales du service

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

Add no_zero argument (default to true) in MatSparse<FPP,GPU2> ctor to allow...

Add no_zero argument (default to true) in MatSparse<FPP,GPU2> ctor to allow not allocating defaultly a zero buffer (nrows+1 size) and avoids possible GPU memory leaks.
parent 136423fc
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,8 @@ namespace Faust ...@@ -35,7 +35,8 @@ 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)*/ const void* stream,/*=nullptr)*/
const bool no_zero/*=false*/)
{ {
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 gp_funcs = GPUModHandler::get_singleton()->gp_funcs(); auto gp_funcs = GPUModHandler::get_singleton()->gp_funcs();
...@@ -47,10 +48,12 @@ namespace Faust ...@@ -47,10 +48,12 @@ namespace Faust
throw std::runtime_error("All GPU buffers or none must be defined to instantiate a MatSparse<FPP,GPU2>."); throw std::runtime_error("All GPU buffers or none must be defined to instantiate a MatSparse<FPP,GPU2>.");
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);
} }
else else if(!no_zero)
{ // no values given, set the matrix as a zero matrix { // no values given, set the matrix as a zero matrix
gpu_mat = spm_funcs->create_zero(nbRow, nbCol); gpu_mat = spm_funcs->create_zero(nbRow, nbCol);
} }
else
gpu_mat = nullptr;
// else gpu_mat = nullptr; // else gpu_mat = nullptr;
gp_funcs->set_dev(cur_dev_id); gp_funcs->set_dev(cur_dev_id);
} }
...@@ -232,7 +235,7 @@ namespace Faust ...@@ -232,7 +235,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>(getNbRow(), getNbCol(), /*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, true);
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);
......
...@@ -29,7 +29,8 @@ namespace Faust ...@@ -29,7 +29,8 @@ 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); const void* stream=nullptr,
const bool nozero=false);
MatSparse(const MatSparse<FPP, Cpu>& mat, MatSparse(const MatSparse<FPP, Cpu>& mat,
const int32_t dev_id=-1, const int32_t dev_id=-1,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment