Mentions légales du service

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

Fix outdated sliceMultiply cpp test.

parent da4e1071
Branches
Tags
No related merge requests found
......@@ -11,6 +11,7 @@ using namespace std;
int main()
{
//TODO: refactor as proper unit tests + with assertions
Faust::enable_gpu_mod();
TransformHelper<double, GPU2> th;
auto cpu_mat1 = MatDense<double,Cpu>::randMat(12,24);
......@@ -54,15 +55,25 @@ int main()
cout << "M_cpu.norm() " << M_cpu.norm() << endl;
cout << "M_gpu.norm() " << M_gpu.norm() << endl;
cout << "========== sliceMultiply" << endl;
// N.B.: compile with DEBUG compiler constant defined to see debug messages proving sliceMultiply is called (on GPU and CPU)
// MatDense<FPP, Cpu> sliceMultiply(const Slice s[2], const FPP* X, int X_ncols=1) const;
auto cpu_mat7 = Faust::MatDense<double,Cpu>::randMat(11, 32);
Slice s[2];
s[0] = Slice(0, th2_cpu.getNbRow());
s[1] = Slice(0, 11);
auto M_cpu8 = th2_cpu.sliceMultiply(s, cpu_mat7->getData(), nullptr, cpu_mat7->getNbCol());
auto M_gpu8 = th2.sliceMultiply(s, cpu_mat7->getData(), nullptr, cpu_mat7->getNbCol());
cout << "M_cpu.norm() " << M_cpu.norm() << endl;
cout << "M_gpu.norm() " << M_gpu.norm() << endl;
// can't call sliceMultiply directly (for dimensions reason) so call slice + multiply (which normally calls sliceMultiply)
auto sth2_cpu = th2_cpu.slice(0, th2_cpu.getNbRow(), 0, 11);
auto th2_gpu = new TransformHelper<double, GPU2>(th2_cpu);
auto sth2 = th2_gpu->slice(0, th2.getNbRow(), 0, 11);
MatDense<double, Cpu> M_cpu8(sth2_cpu->getNbRow(), cpu_mat7->getNbCol());
MatDense<double, Cpu> M_gpu8(sth2->getNbRow(), cpu_mat7->getNbCol());
sth2_cpu->multiply(cpu_mat7->getData(), cpu_mat7->getNbCol(), M_cpu8.getData());
sth2->multiply(cpu_mat7->getData(), cpu_mat7->getNbCol(), M_gpu8.getData());
sth2_cpu->display();
sth2->display();
cout << "M_cpu.norm() " << M_cpu8.norm() << endl;
cout << "M_gpu.norm() " << M_gpu8.norm() << endl;
delete th2_gpu;
delete sth2_cpu;
delete sth2;
return EXIT_SUCCESS;
}
......
......@@ -403,8 +403,11 @@ namespace Faust {
template<typename FPP>
void TransformHelper<FPP,Cpu>::multiply(const FPP* A, int A_ncols, FPP* C)
{
if(this->is_sliced && (A_ncols == 1 || this->size() > 1)) // benchmarks have shown that a single factor Faust is less efficient to multiply a marix (A_ncols > 1) with sliceMultiply than using eval_sliced_Transform and multiply
if(this->is_sliced && (A_ncols == 1 || this->size() > 1)) // benchmarks have shown that a single factor Faust is less efficient to multiply a matrix (A_ncols > 1) with sliceMultiply than using eval_sliced_Transform and multiply
{
#if DEBUG
std::cout << "calling sliceMultiply on CPU Faust to mul a matrix" << std::endl;
#endif
#if (EIGEN_WORLD_VERSION >= 3 && EIGEN_MAJOR_VERSION >= 4)
this->sliceMultiply(this->slices, A, C, A_ncols);
#else
......@@ -2012,7 +2015,7 @@ FPP* Faust::TransformHelper<FPP,Cpu>::sliceMultiply(const Slice s[2], const FPP*
// NOTE: Take care if you edit this method, it must avoid any method that calls eval_sliced_Transform or it would become useless or bugged
//TODO: refactor this function (too long)
//TODO: refactor with MatDense/MatSparse/eigenSliceMul, similar to eigenIndexMul
// TODO: MatBSR/MatButterfly/MatPerm::eigenSliceMul (function to rename becaose eigen won't be used for them), add a MatGeneric::sliceMul pure virtual function (likewise for indexMultiply)
// TODO: MatBSR/MatButterfly/MatPerm::eigenSliceMul (function to rename because eigen won't be used for them), add a MatGeneric::sliceMul pure virtual function (likewise for indexMultiply)
using Mat = Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>;
using MatMap = Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>>;
MatMap X_map(const_cast<FPP*>(X), this->getNbCol(), X_ncols); // the const_cast is harmless, no modif. is made
......
......@@ -479,6 +479,9 @@ namespace Faust
{
if(this->is_sliced)
{
#if DEBUG
std::cout << "calling sliceMultiply on GPU Faust" << std::endl;
#endif
this->sliceMultiply(this->slices, cpu_x_buf, cpu_out_buf, x_ncols);
}
else if(this->is_fancy_indexed)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment