Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 2539f3ec authored by Nicolas Bellot's avatar Nicolas Bellot Committed by hhakim
Browse files

wrapper matlab test

parent 08e02835
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,10 @@ INSTALLATION README : ...@@ -4,6 +4,10 @@ INSTALLATION README :
OS : Ubuntu 14.04 (Virtual Machine) OS : Ubuntu 14.04 (Virtual Machine)
prerequi : version cmake recente au moins 3.2.2
le cmake de base fournit par apt-get est seulement à la version 2.8.4
installation librarie en ligne de commande installation librarie en ligne de commande
I-OPENBLAS I-OPENBLAS
II-MATIO II-MATIO
......
...@@ -44,8 +44,7 @@ Ms=6:11; ...@@ -44,8 +44,7 @@ Ms=6:11;
ns=2.^Ms; ns=2.^Ms;
nb_dim=length(Ms); nb_dim=length(Ms);
threshold=10^(-10); threshold=10^(-10);
dense_times=zeros(nb_mult,nb_dim);
faust_times=zeros(nb_mult,nb_dim);
h = waitbar(0,'speed up hadamard : Generation of the data ...'); h = waitbar(0,'speed up hadamard : Generation of the data ...');
Hadamard_matrices=cell(1,nb_dim); Hadamard_matrices=cell(1,nb_dim);
...@@ -66,17 +65,15 @@ for k=1:nb_dim ...@@ -66,17 +65,15 @@ for k=1:nb_dim
end end
close(h); close(h);
% figure,
% for i=1:M
% subplot(2,M,i);
% imagesc(facts{i}); dense_times=zeros(nb_mult,nb_dim);
% axis image faust_times=zeros(nb_mult,nb_dim);
% subplot(2,M,M+i); dense_trans_times=zeros(nb_mult,nb_dim);
% imagesc(cum_Hbis{i}); faust_trans_times=zeros(nb_mult,nb_dim);
% axis image faust_mtimes_trans_times=zeros(nb_mult,nb_dim);
% end
hadamard_faust=matlab_faust(facts);
hadamard_dense=dvp(facts);
h = waitbar(0,'speed up hadamard : multiplication time comparison ...'); h = waitbar(0,'speed up hadamard : multiplication time comparison ...');
for i=1:nb_mult for i=1:nb_mult
...@@ -89,7 +86,11 @@ for i=1:nb_mult ...@@ -89,7 +86,11 @@ for i=1:nb_mult
x=rand(n,1); x=rand(n,1);
ydense=zeros(n,1); ydense=zeros(n,1);
yfaust=zeros(n,1); yfaust=zeros(n,1);
ydense_trans=zeros(n,1);
yfaust_trans=zeros(n,1);
yfaust_mtimes_trans=zeros(n,1);
%% multiplication by the hadamard matrix
tic tic
ydense=hadamard_dense*x; ydense=hadamard_dense*x;
t1=toc; t1=toc;
...@@ -101,10 +102,34 @@ for i=1:nb_mult ...@@ -101,10 +102,34 @@ for i=1:nb_mult
if(norm(ydense-yfaust)>threshold) if(norm(ydense-yfaust)>threshold)
error('speed_up hadamard : multiplication problem'); error('speed_up hadamard : multiplication problem');
end end
%% multiplication by the transpose of the hadamard matrix
tic
ydense_trans=hadamard_dense'*x;
t3=toc;
tic
yfaust_trans=hadamard_faust'*x;
t4=toc;
tic
yfaust_mtimes_trans=mtimes_trans(hadamard_faust,x,'T');
t5=toc;
tic
if (norm(ydense_trans - ydense_trans) > threshold)
error('speed_up hadamard : transpose multiplication problem');
end
if (yfaust_trans ~= yfaust_mtimes_trans)
error('speed_up hadamard : transpose multiplication problem');
end
dense_times(i,k)=t1; dense_times(i,k)=t1;
faust_times(i,k)=t2; faust_times(i,k)=t2;
dense_trans_times(i,k)=t3;
faust_trans_times(i,k)=t4;
faust_mtimes_trans_times(i,k)=t5;
end end
end end
close(h); close(h);
...@@ -112,36 +137,78 @@ close(h); ...@@ -112,36 +137,78 @@ close(h);
mean_dense_t = mean(dense_times); mean_dense_t = mean(dense_times);
mean_faust_t = mean(faust_times); mean_faust_t = mean(faust_times);
speed_up = mean_dense_t ./ mean_faust_t; speed_up = mean_dense_t ./ mean_faust_t;
mean_dense_trans_t = mean(dense_trans_times);
mean_faust_trans_t = mean(faust_trans_times);
mean_faust_mtimes_trans_t = mean(faust_mtimes_trans_times);
speed_up_trans = mean_dense_trans_t ./ mean_faust_trans_t;
speed_up_mtimes_trans = mean_dense_trans_t ./ mean_faust_mtimes_trans_t;
%% Plot the result %% Plot the result
plot_tickness=2.0;
legend_location = 'NorthWest';
f=figure; f=figure;
subplot(1,2,1); subplot(2,2,1);
semilogy(Ms,mean_faust_t,'linewidth',1.5); semilogy(Ms,mean_faust_t,'linewidth',plot_tickness);
hold on hold on
semilogy(Ms,mean_dense_t,'r','linewidth',1.5); semilogy(Ms,mean_dense_t,'r','linewidth',plot_tickness);
ymin=min([mean_dense_t,mean_faust_t]); ymin=min([mean_dense_t,mean_faust_t]);
ymax=max([mean_dense_t,mean_faust_t]); ymax=max([mean_dense_t,mean_faust_t]);
grid on grid on
axis([Ms(1) Ms(end) ymin ymax]); axis([Ms(1) Ms(end) ymin ymax]);
legend('faust','dense'); legend('faust','dense','Location',legend_location);
ylabel('Computed Time (sec)'); ylabel('Computed Time (sec)');
xlabel('log(dim)'); xlabel('log(dim)');
title('Hadamard-vector multiplication'); title('runtime Hadamard A*x');
set(gca,'XTick',Ms); set(gca,'XTick',Ms);
subplot(1,2,2); subplot(2,2,2);
semilogy(Ms,speed_up,'linewidth',1.5); semilogy(Ms,speed_up,'linewidth',plot_tickness);
hold on hold on
semilogy(Ms,ones(1,nb_dim),'g','linewidth',1.5); semilogy(Ms,ones(1,nb_dim),'k','linewidth',plot_tickness);
grid on grid on
axis([Ms(1) Ms(end) min([speed_up,1]) max([speed_up,1])]); axis([Ms(1) Ms(end) min([speed_up,1]) max([speed_up,1])]);
title('Hadamard-vector multiplication'); title('speed-up Hadamard A*x');
xlabel('log(dim)'); xlabel('log(dim)');
ylabel('speedup'); ylabel('speedup');
legend('speed-up','neutral speed-up'); legend('faust','neutral','Location',legend_location);
set(gca,'XTick',Ms); set(gca,'XTick',Ms);
subplot(2,2,3);
semilogy(Ms,mean_faust_trans_t,'linewidth',plot_tickness);
hold on
semilogy(Ms,mean_dense_trans_t,'r','linewidth',plot_tickness);
semilogy(Ms,mean_faust_mtimes_trans_t,'g','linewidth',plot_tickness);
ymin=min([mean_dense_trans_t,mean_faust_trans_t,mean_faust_mtimes_trans_t]);
ymax=max([mean_dense_trans_t,mean_faust_trans_t,mean_faust_mtimes_trans_t]);
grid on
axis([Ms(1) Ms(end) ymin ymax]);
legend('faust','dense','mtimes_trans','Location',legend_location);
ylabel('Computed Time (sec)');
xlabel('log(dim)');
title('runtime Hadamard A''*x');
set(gca,'XTick',Ms);
subplot(2,2,4);
semilogy(Ms,speed_up_trans,'linewidth',plot_tickness);
hold on
semilogy(Ms,ones(1,nb_dim),'k','linewidth',plot_tickness);
semilogy(Ms,speed_up_mtimes_trans,'g','linewidth',plot_tickness);
grid on
axis([Ms(1) Ms(end) min([speed_up_trans,1,speed_up_mtimes_trans]) max([speed_up_trans,1,speed_up_mtimes_trans])]);
title('speed-up Hadamard A''*x');
xlabel('log(dim)');
ylabel('speedup');
legend('faust','neutral','mtimes_trans','Location',legend_location);
set(gca,'XTick',Ms);
f.Name =['Hadamard Faust-vector multiplication']; f.Name =['Hadamard Faust-vector multiplication'];
%% save the figure %% save the figure
runPath=which(mfilename); runPath=which(mfilename);
...@@ -156,3 +223,4 @@ print(figure_name, format_fig); ...@@ -156,3 +223,4 @@ print(figure_name, format_fig);
addpath('');%% access to the mexfunction
addpath('/Users/remi/Devel/faust/trunk/devcpp/misc/demo/tools');%% access to the tools.m function (sparsify toolbox, figure toolbox ...)
addpath('/Users/remi/Devel/faust/trunk/devcpp/misc/data/mat/demoLuc');%% access to the data
addpath('');%% access to matlab_faust.m (interface betwwen faust_core C++ class and matlab class)
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "faust_MatDense.h" #include "faust_MatDense.h"
#include <stdexcept> #include <stdexcept>
#include "faust_constant.h" #include "faust_constant.h"
#include "faust_Timer.h"
// prhs[0] : name of command : // prhs[0] : name of command :
// "delete" to delete the Faust::Transform<FFPP> object dynamically allocated previously // "delete" to delete the Faust::Transform<FFPP> object dynamically allocated previously
// "multiply" to multiply the Faust::Transform<FFPP> object by a vector or a matrix // "multiply" to multiply the Faust::Transform<FFPP> object by a vector or a matrix
...@@ -172,9 +172,20 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -172,9 +172,20 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("transpose : too much output argument"); mexErrMsgTxt("transpose : too much output argument");
else else
{ {
Faust::Transform<FFPP,Cpu>* F = new Faust::Transform<FFPP,Cpu>((*core_ptr)); //Faust::Timer t1,t2,t3;
//t1.start();
Faust::Transform<FFPP,Cpu>* F = new Faust::Transform<FFPP,Cpu>((*core_ptr));
//t1.stop();
//t2.start();
(*F).transpose(); (*F).transpose();
//t2.stop();
//t3.start();
plhs[0]=convertPtr2Mat<Faust::Transform<FFPP,Cpu> >(F); plhs[0]=convertPtr2Mat<Faust::Transform<FFPP,Cpu> >(F);
//t3.stop();
//std::cout<<"t1 new : "<<t1.get_time()<<std::endl;
//std::cout<<"t2 transpose : "<<t2.get_time()<<std::endl;
//std::cout<<"t3 convertPtrMat : "<<t3.get_time()<<std::endl;
} }
return; return;
......
...@@ -63,24 +63,15 @@ classdef matlab_faust < handle ...@@ -63,24 +63,15 @@ classdef matlab_faust < handle
%% Transpose operator %% Transpose operator
function trans=transpose(this) function trans=transpose(this)
%transpose - overloading of the matlab transpose operator (') %transpose - overloading of the matlab transpose operator (.')
if (nargout == 0) trans=ctranspose(this); % currently faust is a real matrix, so the complex transposition is the same as the real one
mexFaust('transpose',this.objectHandle);
else
trans = matlab_faust({});
trans.objectHandle = mexFaust('transpose',this.objectHandle);
end
end end
function trans=ctranspose(this) function trans=ctranspose(this)
if (nargout == 0) %ctranspose - overloading of the matlab transpose operator (')
mexFaust('transpose',this.objectHandle);
else
trans = matlab_faust({}); trans = matlab_faust({});
trans.objectHandle = mexFaust('transpose',this.objectHandle); trans.objectHandle = mexFaust('transpose',this.objectHandle);
end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment