Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianyi Cheng committed Sep 12, 2019
1 parent db6b069 commit a56c1dd
Show file tree
Hide file tree
Showing 39 changed files with 986 additions and 0 deletions.
Binary file added DSS/BNNKernel/src/a.out
Binary file not shown.
42 changes: 42 additions & 0 deletions DSS/BNNKernel/src/bnn.cpp
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;
// }

}
}
}
13 changes: 13 additions & 0 deletions DSS/BNNKernel/src/bnn.h
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]);
40 changes: 40 additions & 0 deletions DSS/BNNKernel/src/bnn_tb.cpp
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;

}
21 changes: 21 additions & 0 deletions DSS/BNNKernel/src/g1.cpp
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;
}

}
26 changes: 26 additions & 0 deletions DSS/BNNKernel/src/g2.cpp
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;
}

}
38 changes: 38 additions & 0 deletions DSS/BNNKernel/src/inlined.cpp
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 added DSS/gSum/src/a.out
Binary file not shown.
16 changes: 16 additions & 0 deletions DSS/gSum/src/g.cpp
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;
}
26 changes: 26 additions & 0 deletions DSS/gSum/src/gSum.cpp
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;
}
12 changes: 12 additions & 0 deletions DSS/gSum/src/gSum.h
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);
39 changes: 39 additions & 0 deletions DSS/gSum/src/gSum_tb.cpp
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 added DSS/gSumIf/src/a.out
Binary file not shown.
20 changes: 20 additions & 0 deletions DSS/gSumIf/src/g.cpp
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;

}
27 changes: 27 additions & 0 deletions DSS/gSumIf/src/gSumIf.cpp
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;
}
12 changes: 12 additions & 0 deletions DSS/gSumIf/src/gSumIf.h
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);
39 changes: 39 additions & 0 deletions DSS/gSumIf/src/gSumIf_tb.cpp
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 added DSS/getTanh/src/a.out
Binary file not shown.
Loading

0 comments on commit a56c1dd

Please sign in to comment.