Mentions légales du service

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

Update FaustGPU: cpu_gpu_map is only used when RefManager is enabled.

parent 403f3e97
Branches
Tags
No related merge requests found
......@@ -24,7 +24,7 @@ namespace Faust
static void* dsm_funcs;
static void* gp_funcs;
gm_MatArray_t gpu_mat_arr;
std::vector<void*> cpu_mat_ptrs; // addresses stored in gpu_mat_arr
std::vector<void*> cpu_mat_ptrs; // cpu mat addresses for which gpu copies are stored in gpu_mat_arr
size_t size;
// this map is used to retrieve a cpu mat addr from a gpu mat addr
......
......@@ -101,7 +101,10 @@ namespace Faust
{
// release all gpu mats
for(auto m: cpu_mat_ptrs)
ref_man.release(m);
{
if(ref_man.contains(m)) //TODO: remove when the bug of nonsense factor is corrected
ref_man.release(m);
}
}
marr_funcs->free(gpu_mat_arr, ! use_ref_man); // delete used mats only if it doesn't use ref_man
if(gm_users <= 0)
......@@ -163,21 +166,22 @@ namespace Faust
for(auto m: factors)
{
if(cpu_gpu_map.find(m) != cpu_gpu_map.end())
if(use_ref_man && cpu_gpu_map.find(m) != cpu_gpu_map.end())
{
// already known cpu, gpu mats
if(use_ref_man)
{
ref_man.acquire(m);
// add the gpu matrix to gpu mat list
if(dynamic_cast<MatDense<@FAUST_SCALAR_FOR_GM@,Cpu>*>(m))
marr_funcs->addgpu_dsm(gpu_mat_arr, cpu_gpu_map[m]);
else
// m is sparse
marr_funcs->addgpu_spm(gpu_mat_arr, cpu_gpu_map[m]);
cpu_mat_ptrs.push_back(m);
continue;
}
// add the gpu matrix to gpu mat list
if(dynamic_cast<MatDense<@FAUST_SCALAR_FOR_GM@,Cpu>*>(m))
marr_funcs->addgpu_dsm(gpu_mat_arr, cpu_gpu_map[m]);
else
// m is sparse
marr_funcs->addgpu_spm(gpu_mat_arr, cpu_gpu_map[m]);
cpu_mat_ptrs.push_back(m);
ref_man.acquire(m);
continue;
}
if(sp_mat = dynamic_cast<MatSparse<@FAUST_SCALAR_FOR_GM@,Cpu>*>(m))
......@@ -194,44 +198,41 @@ namespace Faust
}
size++;
cpu_gpu_map[m] = gpu_ref;
cpu_mat_ptrs.push_back(m);
if(use_ref_man)
{
cpu_gpu_map[m] = gpu_ref;
ref_man.acquire(m);
}
}
}
// this def. must be located after called ctor and class dtor to avoid error of type "specialization after instantiation"
// template<>
// FaustGPU<@FAUST_SCALAR_FOR_GM@>::FaustGPU(const Transform<@FAUST_SCALAR_FOR_GM@,Cpu>* src_t) : FaustGPU<@FAUST_SCALAR_FOR_GM@>(src_t->data)
// {
// }
template <>
void FaustGPU<@FAUST_SCALAR_FOR_GM@>::update(const Faust::MatGeneric<@FAUST_SCALAR_FOR_GM@,Cpu>* M, int32_t id)
{
MatGeneric<@FAUST_SCALAR_FOR_GM@,Cpu>* M_ = const_cast<MatGeneric<@FAUST_SCALAR_FOR_GM@,Cpu>*>(M);
// I promise I won't touch M_ data!
if(cpu_gpu_map.find(M_) == cpu_gpu_map.end())
throw std::runtime_error("It's not authorized to update from an unknown host matrix.");
if(M != cpu_mat_ptrs[id])
throw std::runtime_error("It's not authorized to update from another cpu matrix than the original one.");
gm_MatArrayFunc_@GM_SCALAR@* marr_funcs = (gm_MatArrayFunc_@GM_SCALAR@*) this->marr_funcs;
MatSparse<@FAUST_SCALAR_FOR_GM@, Cpu>* sp_mat;
MatDense<@FAUST_SCALAR_FOR_GM@, Cpu>* ds_mat;
void* gpu_ref;
// if the dims are not equal between M_ and the gpu mat, an exception will be raised by gpu_mod
if(sp_mat = dynamic_cast<MatSparse<@FAUST_SCALAR_FOR_GM@,Cpu>*>(M_))
{
// std::cout << "FaustGPU::update(): " << sp_mat->getNbRow() << " " << sp_mat->getNbCol()<< " " << sp_mat->getNonZeros()<< std::endl;
/* gpu_ref = */marr_funcs->cpu_set_spm_at(gpu_mat_arr, sp_mat->getNbRow(), sp_mat->getNbCol(), sp_mat->getNonZeros(), sp_mat->getOuterIndexPtr(), sp_mat->getInnerIndexPtr(), (@GM_SCALAR@*) reinterpret_cast<@GM_REINTERPRET_CAST_SCALAR@*>(sp_mat->getValuePtr()), id);
gpu_ref = marr_funcs->cpu_set_spm_at(gpu_mat_arr, sp_mat->getNbRow(), sp_mat->getNbCol(), sp_mat->getNonZeros(), sp_mat->getOuterIndexPtr(), sp_mat->getInnerIndexPtr(), (@GM_SCALAR@*) reinterpret_cast<@GM_REINTERPRET_CAST_SCALAR@*>(sp_mat->getValuePtr()), id);
}
else if(ds_mat = dynamic_cast<MatDense<@FAUST_SCALAR_FOR_GM@,Cpu>*>(M_))
{
// std::cout << "FaustGPU::update(): " << ds_mat->getNbRow() << " " << ds_mat->getNbCol()<< " " << ds_mat->getNonZeros()<< std::endl;
/* gpu_ref = */ marr_funcs->cpu_set_dsm_at(gpu_mat_arr, ds_mat->getNbRow(), ds_mat->getNbCol(), (@GM_SCALAR@*) reinterpret_cast<@GM_REINTERPRET_CAST_SCALAR@*>(ds_mat->getData()), id);
gpu_ref = marr_funcs->cpu_set_dsm_at(gpu_mat_arr, ds_mat->getNbRow(), ds_mat->getNbCol(), (@GM_SCALAR@*) reinterpret_cast<@GM_REINTERPRET_CAST_SCALAR@*>(ds_mat->getData()), id);
}
// gpu_ref is not recorded because this is an assignment, so the pointers don't change
// gpu_ref is not recorded because this is an assignment of data but the pointers don't change
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment