Skip to content

Commit e2fdb3c

Browse files
Matlab files upload
1 parent 3417997 commit e2fdb3c

40 files changed

+1927
-0
lines changed

Diff for: LUTimplement.m

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function [results] = LUTimplement(N, mode)
2+
%func='sigmf(x,[1 0])';
3+
func='sigmf(x)';
4+
xmin=-8;
5+
xmax=8;
6+
xdt=sfix(16);
7+
xscale=2^-12;
8+
ydt=sfix(16);
9+
yscale=2^-14;
10+
rndmeth='Floor'
11+
nptsmax=N;
12+
spacing=mode;
13+
[xdata,ydata,errworst] = ...
14+
fixpt_look1_func_approx(func,...
15+
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax,spacing);
16+
17+
results=[xdata, ydata];
18+
%figure
19+
%fixpt_look1_func_plot(xdata,ydata,func,xmin,xmax,...
20+
% xdt,xscale,ydt,yscale,rndmeth);

Diff for: LUTimplement_sigmf.m

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function [results] = LUTimplement_sigmf(N, mode)
2+
func='sigmf(x,[1 0])';
3+
xmin=-8;
4+
xmax=8;
5+
xdt=sfix(16);
6+
xscale=2^-12;
7+
ydt=sfix(16);
8+
yscale=2^-14;
9+
rndmeth='Floor'
10+
nptsmax=N;
11+
spacing=mode;
12+
[xdata,ydata,errworst] = ...
13+
fixpt_look1_func_approx(func,...
14+
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax,spacing);
15+
16+
results=[xdata, ydata];
17+
%figure
18+
%fixpt_look1_func_plot(xdata,ydata,func,xmin,xmax,...
19+
% xdt,xscale,ydt,yscale,rndmeth);

Diff for: LUTimplement_tansig.m

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function [results] = LUTimplement_tansig(N, mode)
2+
%func='sigmf(x,[1 0])';
3+
func='tansig(x)';
4+
xmin=-8;
5+
xmax=8;
6+
xdt=sfix(16);
7+
xscale=2^-12;
8+
ydt=sfix(16);
9+
yscale=2^-14;
10+
rndmeth='Floor'
11+
nptsmax=N;
12+
spacing=mode;
13+
[xdata,ydata,errworst] = ...
14+
fixpt_look1_func_approx(func,...
15+
xmin,xmax,xdt,xscale,ydt,yscale,rndmeth,[],nptsmax,spacing);
16+
17+
results=[xdata, ydata];
18+
%figure
19+
%fixpt_look1_func_plot(xdata,ydata,func,xmin,xmax,...
20+
% xdt,xscale,ydt,yscale,rndmeth);

Diff for: LUTimplement_trials.m

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
N=[4 8];
2+
spacing={'pow2','even','unrestricted'};
3+
for i=1:3
4+
for j=1:2
5+
LUTimplement(N(j),char(spacing(i)));
6+
end
7+
end
8+

Diff for: energy_sparsity.m

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
h=128;
2+
d=39;
3+
s1=1;
4+
s2=2;
5+
t1=1;
6+
t2=2;
7+
8+
cm=5.5e-6
9+
ca=2.85e-6
10+
11+
M=4*(h*d+h^2)+3*s1*h+2*t1*h+3*h
12+
A=4*(h*d+h^2+2*h)+3*s2*h+2*t2*h+h
13+
14+
m=(4*(h*d+h^2))/M;
15+
16+
results=[];
17+
18+
n=16;
19+
%E=(1-s)*m*M*cm*n^2+(1-m)*M*cm*n^2+A*ca*n;
20+
21+
nref=16;
22+
Eref=M*cm*nref^2+A*ca*nref;
23+
for s=0:0.1:0.9
24+
E=(1-s)*m*M*cm*n^2+(1-m)*M*cm*n^2+A*ca*n;
25+
Erel=E/Eref;
26+
results=[results; s Erel];
27+
end
28+
29+
figure('Name', 'Accuracy vs LSTM sparsity');
30+
h1=axes
31+
index=100*results(:,1);
32+
r1=100-results(:,2)*100;
33+
plot(index,r1,'m--x','LineWidth',5);
34+
hold on;
35+
%plot(index,r2,'r--*');
36+
37+
grid on;
38+
%title('Accuracy of the TIMIT LSTM');
39+
%axis([0 90 54 101]);
40+
xlabel('Sparsity') % x-axis10 label
41+
ylabel('\%') % y-axis label
42+
43+
%set(h1, 'Xdir', 'reverse')
44+
%axis([2 16 0 101]);
45+
46+
load('../results_sparsity.mat')
47+
index=results_sparsity_LSTMonly(:,1);
48+
r1=100-results_sparsity_LSTMonly(:,3);
49+
r1=(r1/r1(1))*100;
50+
plot(index,r1,'b--o','LineWidth',5);
51+
hold on;
52+
% r2=100-results_sparsity_all(:,3);
53+
% r2=(r2/r2(1))*100;
54+
% plot(index,r2,'r--x','LineWidth',5);
55+
% r3=100-results_sparsity_FConly(:,3);
56+
% r3=(r3/r3(1))*100;
57+
% plot(index,r3,'g--*','LineWidth',5);
58+
grid on;
59+
%title('Accuracy of the TIMIT LSTM');
60+
axis([0 90 0 101]);
61+
legend('Energy Savings', 'LSTM-only pruning relative accuracy','LSTM+FC pruning relative accuracy','FC-only pruning relative accuracy')
62+
set(gca,'FontSize',30)
63+
%set(gca,'fontsize',20);
64+
65+
66+

Diff for: energy_wordlength.m

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
h=128;
2+
d=39;
3+
s1=1;
4+
s2=1;
5+
t1=1;
6+
t2=1;
7+
8+
cm=5.5e-6
9+
ca=2.85e-6
10+
11+
M=4*(h*d+h^2)+3*s1*h+2*t1*h+3*h
12+
A=4*(h*d+h^2+2*h)+3*s2*h+2*t2*h+h
13+
results=[];
14+
15+
16+
nref=16;
17+
Eref=M*cm*nref^2+A*ca*nref;
18+
for n=2:16
19+
E=M*cm*n^2+A*ca*n;
20+
Erel=E/Eref;
21+
results=[results; n Erel];
22+
end
23+
n=5;
24+
figure('Name', 'Accuracy vs LSTM sparsity');
25+
h1=axes
26+
index=results(:,1);
27+
r1=100-results(:,2)*100;
28+
plot(index,r1,'m--o','LineWidth',5);
29+
hold on;
30+
load('../results_quantization.mat');
31+
index=results_quantize_all_dynamic(:,1);
32+
r2=100-results_quantize_lstm_dynamic(:,2);
33+
baseline_accuracy=100-baseline_80;
34+
r2=(r2/baseline_accuracy)*100;
35+
plot(index,r2,'r--*','LineWidth',5);
36+
37+
r3=100-results_quantize_all_dynamic(:,2);
38+
r3=(r3/baseline_accuracy)*100;
39+
plot(index,r3,'b--x','LineWidth',5);
40+
set(gca,'FontSize',30)
41+
42+
grid on;
43+
%title('Accuracy of the TIMIT LSTM');
44+
%axis([0 90 54 101]);
45+
xlabel('Word length') % x-axis10 label
46+
ylabel('\%') % y-axis label
47+
legend('Energy Savings', 'Accuracy (LSTM-only Quantized)','Accuracy (LSTM-only Quantized)' )
48+
49+
set(h1, 'Xdir', 'reverse')
50+
axis([2 16 0 101]);
51+
52+
% xmarkers = [6 7 8]
53+
% ymarkers = [r1(6-1) r1(7-1) r1(8-1)];
54+
55+
% plot(xmarkers,ymarkers,'r*')
56+
57+
58+
59+

Diff for: fixed_point_plots.m

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
%requires fixed_point_trials
2+
%data is always quantized
3+
set(0,'defaulttextinterpreter','latex')
4+
load('results_quantization.mat');
5+
baseline=baseline_80;
6+
baseline_accuracy=100-baseline;
7+
%%%%Dynamic FP only quantization
8+
figure('Name', 'Accuracy - Word Length');
9+
h1=axes
10+
index=results_quantize_all_dynamic(:,1);
11+
r1=100-results_quantize_lstm_dynamic(:,2);
12+
r1=(r1/baseline_accuracy)*100;
13+
plot(index,r1,'b--o','LineWidth',5);
14+
grid on;
15+
hold on;
16+
17+
r2=100-results_quantize_all_dynamic(:,2);
18+
r2=(r2/baseline_accuracy)*100;
19+
plot(index,r2,'r--x','LineWidth',5);
20+
21+
space=2:32
22+
plot(space, (100)*ones(size(space)),'g-*','LineWidth',5);
23+
xlabel('Word Length (bits)') % x-axis label
24+
ylabel('Relative Accuracy \%') % y-axis label
25+
%title('Dynamic Fixed-point quantization')
26+
legend('LSTM only quantization','All layers quantization','32-bit floating point non-quantized')
27+
%set(gca,'fontsize',20)
28+
set(h1, 'Xdir', 'reverse')
29+
axis([2 16 0 100]);
30+
set(gca,'FontSize',30)
31+
%%%%%%
32+
33+
%Naive
34+
% figure('Name', 'Accuracy - Word Length');
35+
% h1=axes
36+
% index=results_quantize_all_naive(:,1);
37+
% r1=100-results_quantize_all_naive(:,2);
38+
% r1=(r1/r1(1))*100;
39+
% plot(index,r1,'b--o');
40+
% grid on;
41+
% hold on;
42+
%
43+
% r2=100-results_quantize_all_dynamic(:,2);
44+
% r2=(r2/r2(1))*100;
45+
% plot(index,r2,'r--x');
46+
%
47+
% space=2:32
48+
% plot(space, (100)*ones(size(space)),'g-*');
49+
% xlabel('Word Length (bits)') % x-axis label
50+
% ylabel('Relative Accuracy %') % y-axis label
51+
% title('LSTM+FC quantization')
52+
%
53+
% legend('Q.WL/2.WL/2','Dynamic Fixed Point','32-bit floating point')
54+
% %set(gca,'fontsize',20)
55+
% set(h1, 'Xdir', 'reverse')
56+
% axis([2 16 30 100]);
57+
% %%%%%%
58+
%
59+
%

Diff for: fixed_point_trials.m

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
%File logging
2+
filename=datestr(datetime);
3+
filename=strrep(filename,' ','_');
4+
filename=strcat('matlab_experiment_',filename);
5+
full_filename=strcat(filename,'.log');
6+
FILE=fopen(full_filename,'a');
7+
results=[];
8+
% for WL=32:-1:2
9+
% WL
10+
% r=forward_pass_fixed_naive(FILE, WL,ceil(WL/2));
11+
%
12+
% results=[results; [WL r ]]
13+
% end
14+
% full_filename=strcat(filename,'.mat')
15+
% save(full_filename,'results');
16+
17+
18+
%====Better version with dynamic quantization
19+
for WL=32:-1:2
20+
WL
21+
r=forward_pass_fixed_dynamic(FILE, WL);
22+
23+
results=[results; [WL r ]]
24+
end
25+
full_filename=strcat(filename,'.mat')
26+
save(full_filename,'results');

0 commit comments

Comments
 (0)