-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jianyi Cheng
committed
Sep 12, 2019
1 parent
db6b069
commit a56c1dd
Showing
39 changed files
with
986 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Benchmark: BNNKernel | ||
FileName: bnn.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "bnn.h" | ||
|
||
void bnn(int addr_in[10000],int alpha, int w[10000], int addr_out[10000], int data[10000], int in[10000], int mean[10000]){ | ||
|
||
int lut, m,i,j,k, x, y, z, temp; | ||
|
||
for (i=0; i<100; i++){ | ||
g1(alpha, in, i, w, addr_in, data); | ||
// for (j=0;j<100;j++){ | ||
// x = i*100+j; | ||
// lut=in[x]^w[x]; | ||
// data[addr_in[x]] += lut*alpha; | ||
// } | ||
|
||
if (i == 99){ | ||
// An if condition in the loop causes irregular computation. | ||
// Static scheduler reserves time slot for each iteration | ||
// causing unnecessary pipeline stalls. | ||
g2(mean, i, addr_out, data); | ||
// for(k=0; k<100; k++){ | ||
// y=i*100+k; | ||
// m=mean[y]; | ||
// temp = data[addr_out[y]]; | ||
// if (temp > 0) | ||
// z = temp -m; | ||
// else | ||
// z = temp +m; | ||
// data[addr_out[y]] = z; | ||
// } | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Benchmark: BNNKernel | ||
FileName: bnn.h | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
void bnn(int addr_in[10000], int alpha, int w[10000], int addr_out[10000], int data[10000], int in[10000], int mean[10000]); | ||
void inlined(int addr_in[10000], int alpha, int w[10000], int addr_out[10000], int data[10000], int in[10000], int mean[10000]); | ||
void g1(int alpha, int in[10000], int i, int w[10000], int addr_in[10000], int data[10000]); | ||
void g2(int mean[10000], int i, int addr_out[10000], int data[10000]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Benchmark: BNNKernel | ||
FileName: bnn_tb.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "bnn.h" | ||
|
||
int main(){ | ||
|
||
int addr_in[10000], alpha, w[10000], addr_out[10000], data[10000], gold[10000],in[10000], mean[10000]; | ||
|
||
for (int i=0; i<10000; i++){ | ||
addr_in[i] = i; | ||
addr_out[i] = i; | ||
in[i] = 1; | ||
data[i] = 0; | ||
gold[i] = 0; | ||
mean[i] = 1; | ||
w[i] = 1; | ||
} | ||
|
||
alpha = 2; | ||
|
||
bnn(addr_in, alpha, w, addr_out, data, in, mean); | ||
inlined(addr_in, alpha, w, addr_out, gold, in, mean); | ||
|
||
int count = 0; | ||
for(int i=0;i<10000; i++) | ||
count += (data[i] == gold[i]); | ||
|
||
if (count == 10000) | ||
return 0; | ||
else | ||
return 1; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Benchmark: BNNKernel | ||
FileName: g1.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
void g1(int alpha, int in[10000], int i, int w[10000], int addr_in[10000], int data[10000]){ | ||
#pragma SS II=1 | ||
|
||
int j, x, lut; | ||
|
||
for (j=0;j<100;j++){ | ||
x = i*100+j; | ||
lut=in[x]^w[x]; | ||
data[addr_in[x]] += lut*alpha; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Benchmark: BNNKernel | ||
FileName: g2.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
void g2(int mean[10000], int i, int addr_out[10000], int data[10000]){ | ||
#pragma SS II=1 | ||
|
||
int temp, m, k, y, z; | ||
|
||
for(k=0; k<100; k++){ | ||
y=i*100+k; | ||
m=mean[y]; | ||
temp = data[addr_out[y]]; | ||
if (temp > 0) | ||
z = temp -m; | ||
else | ||
z = temp +m; | ||
data[addr_out[y]] = z; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Benchmark: BNNKernel | ||
FileName: inlined.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "bnn.h" | ||
|
||
void inlined(int addr_in[10000], int alpha, int w[10000], int addr_out[10000], int data[10000], int in[10000], int mean[10000]){ | ||
int lut, m,i,j,k, x, y, z, temp; | ||
|
||
for (i=0; i<100; i++){ | ||
for (j=0;j<100;j++){ | ||
x = i*100+j; | ||
lut=in[x]^w[x]; | ||
data[x] += lut*alpha; | ||
} | ||
|
||
if (i==99){ | ||
for(k=0; k<100; k++){ | ||
y=i*100+k; | ||
m=mean[y]; | ||
temp = data[y]; | ||
if (temp > 0) | ||
z = temp -m; | ||
else | ||
z = temp +m; | ||
data[y] = z; | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Benchmark: gSum | ||
FileName: g.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "gSum.h" | ||
|
||
double g(double i){ | ||
#pragma SS II=1 | ||
|
||
return (((((i+0.64)*i+0.7)*i+0.21)*i+0.33)*i+0.25)*i+0.125; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Benchmark: gSum | ||
FileName: gSum.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "gSum.h" | ||
|
||
double gSum(double A[1000], double B[1000]){ | ||
double d, s = 0.0; | ||
int i; | ||
|
||
for (i=0; i<1000; i++){ | ||
d = A[i] + B[i]; | ||
if (d >= 0) | ||
// An if condition in the loop causes irregular computation. | ||
// Static scheduler reserves time slot for each iteration | ||
// causing unnecessary pipeline stalls. | ||
s += g(d); | ||
// s += (((((d+0.64)*d+0.7)*d+0.21)*d+0.33)*d+0.25)*d+0.125; | ||
} | ||
return s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Benchmark: gSum | ||
FileName: gSum.h | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
double gSum(double A[1000], double B[1000]); | ||
|
||
double g(double i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Benchmark: gSum | ||
FileName: gSum_tb.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include <iostream> | ||
#include "gSum.h" | ||
#define K 100 | ||
|
||
int main(){ | ||
double A[1000], B[1000], accum = 0.0, res, k, i; | ||
|
||
for (int j=0; j<1000; j++) | ||
{ | ||
A[j] = (double)j+1.0; | ||
if (j % K == 0) | ||
B[j] = -A[j] + 1.0; | ||
else | ||
B[j] = -A[j] - 1.0; | ||
|
||
i = A[j] + B[j]; | ||
if (i >= 0){ | ||
accum += (((((i+0.25)*i+0.5)*i+0.125)*i+0.25)*i+0.5)*i+0.25; | ||
} | ||
} | ||
|
||
res = gSum(A, B); | ||
|
||
if (res == accum) | ||
return 0; | ||
else{ | ||
std::cout << "actual res = " << res << ", gold = " << accum << "\n"; | ||
return 1; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Benchmark: gSumIf | ||
FileName: g.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "gSumIf.h" | ||
|
||
double g(double i){ | ||
#pragma SS II =5 | ||
|
||
if (i > 5) | ||
return (((((i+0.25)*i+0.5)*i+0.125)*i+0.25)*i+0.5)*i+0.25; | ||
else | ||
return (((((i+0.64)*i+0.7)*i+0.21)*i+0.33)*i+0.25)*i+0.125; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Benchmark: gSumIf | ||
FileName: gSumIf.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include "gSumIf.h" | ||
|
||
double gSumIf(double A[1000], double B[1000]){ | ||
|
||
double d, s = 0.0; | ||
int i; | ||
|
||
for (i=0; i<1000; i++){ | ||
d = A[i] + B[i]; | ||
if (d >= 0) | ||
// An if condition in the loop causes irregular computation. | ||
// Static scheduler reserves time slot for each iteration | ||
// causing unnecessary pipeline stalls. | ||
s += g(d); | ||
// s = d > 5? s+(((((d+0.25)*d+0.5)*d+0.125)*d+0.25)*d+0.5)*d+0.25 : s+(((((d+0.64)*d+0.7)*d+0.21)*d+0.33)*d+0.25)*d+0.125; | ||
} | ||
return s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Benchmark: gSumIf | ||
FileName: gSumIf.h | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
double gSumIf(double A[1000], double B[1000]); | ||
|
||
double g(double i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Benchmark: gSumIf | ||
FileName: gSumIf_tb.cpp | ||
Author: Jianyi Cheng | ||
Date: 12 Sep 2019 | ||
*/ | ||
|
||
#include <iostream> | ||
#include "gSumIf.h" | ||
#define K 100 | ||
|
||
int main(){ | ||
double A[1000], B[1000], accum = 0.0, res, k, i; | ||
|
||
for (int j=0; j<1000; j++) | ||
{ | ||
A[j] = (double)j+1.0; | ||
if (j % K == 0) | ||
B[j] = -A[j] + 1.0; | ||
else | ||
B[j] = -A[j] - 1.0; | ||
|
||
i = A[j] + B[j]; | ||
if (i >= 0){ | ||
accum += (((((i+0.25)*i+0.5)*i+0.125)*i+0.25)*i+0.5)*i+0.25; | ||
} | ||
} | ||
|
||
res = gSum(A, B); | ||
|
||
if (res == accum) | ||
return 0; | ||
else{ | ||
std::cout << "actual res = " << res << ", gold = " << accum << "\n"; | ||
return 1; | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.