Merge branch 'main' into INT-Benchmarks

This commit is contained in:
VinhTA-Computer-Master 2021-09-08 13:35:16 -07:00 committed by GitHub
commit a6f6478964
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 189 additions and 234 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
gem5/build
llvm-project/build

View File

@ -1,5 +1,11 @@
# CCF 20.04
## Overview
CCF (**C**GRA **C**ompilation **F**ramework) is an end-to-end prototype that generates machine code for CGRAs (Coarse-Grained Reconfigurable Arrays) and simulate their performance. Through CCF, users can benchmark how CGRAs accelerate kernels designed for general-purpose applications. Currently, CCF 20.04 can accelerate over //TODO number of loops from three benchmark suites, Parboil, MiBench, and Rodinia. It is named CCF 20.04 because this framework has been built and verified on Ubuntu 20.04.
This framework can be seen in three parts: Scheduling and Mapping, Instruction Generation, and Simulation. The Scheduling and Mapping part of CCF is built upon the foundations of the cross-compiler LLVM 13, and the Simulation part of CCF is built upon the cycle-accurate computer architecture simulation gem5. Instruction Generation is what bridges the two parts together.
## How to install
### Disclaimer on building from source
@ -7,7 +13,32 @@ CCF 20.04 does not require you to have sudo privileges to install. Because of th
If you have set your environment properly, then you can skip to section "Editing `install.sh`". If not, continue following the instructions below.
//TODO
### How to build from source
In order to build for source, you need to create a directory where you will store the CCF 20.04 binaries. We will assume that you would like to make said directory in your root directory. We will also name that directory as `sw`, and we will create it using the command below.
```
cd ~
mkdir sw
```
After making this directory, we now need to change our environment variables such that BASH (or ZSH) is able to find the binaries installed in the directory. To do this, open the file `~/.bashrc` (or `~/.zshrc`) using your preferred text editor, and add the following lines:
```
export PATH="$SW/bin:$PATH"
expore LD_LIBRARY_PATH="$SW/lib:$LD_LIBRARY_PATH"
```
where `$SW` refers to the **full path** of directory `~/sw`. You can find the full path by running the following commands:
```
cd ~/sw
pwd
```
Once you have edited `~/.bashrc` (or `~/.zshrc`), run `source ~/.bashrc` (or `source ~/.zshrc`).
You have made the necessary changes to your environment and are now able to install CCF 20.04.
### Editing `install.sh`
Open `install.sh` using your preferred text editor, and go to line 5 (e.g the line with `install_path=""`). Add the complete path of where you would like to install your binaries in between the quotation marks. Afterwards, save the file and run the command `bash install.sh`. This should allow you install CCF 20.04.

View File

@ -1,150 +0,0 @@
//#include "snipmath.h"
#include <math.h>
#include <pthread.h>
#include <stdio.h>
/* The printf's may be removed to isolate just the math calculations */
void SolveCubic(double, double, double, double, int*, double*);
void calc();
#define PI ((double)3.14159)
int main(void)
{
double a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
double a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0;
double a3 = 1.0, b3 = -3.5, c3 = 22.0, d3 = -31.0;
double a4 = 1.0, b4 = -13.7, c4 = 1.0, d4 = -35.0;
double x[3];
double X;
int solutions;
int i;
unsigned long l = 0x3fed0169L;
//struct int_sqrt q;
long n = 0;
printf("Creating Calc thread\n");
pthread_t loop_thread;
pthread_create(&loop_thread, NULL, (void*)&calc, NULL);
pthread_join(loop_thread, NULL);
printf("Calc thread done\n");
/* solve soem cubic functions */
//printf("********* CUBIC FUNCTIONS ***********\n");
/* should get 3 solutions: 2, 6 & 2.5 */
/*SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");*/
/* should get 1 solution: 2.5 */
/*SolveCubic(a2, b2, c2, d2, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
SolveCubic(a3, b3, c3, d3, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
SolveCubic(a4, b4, c4, d4, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");*/
/* Now solve some random equations
for(a1=1;a1<10;a1++) {
for(b1=10;b1>0;b1--) {
for(c1=5;c1<15;c1+=0.5) {
for(d1=-1;d1>-11;d1--) {
SolveCubic(a1, b1, c1, d1, &solutions, x);
printf("Solutions:");
for(i=0;i<solutions;i++)
printf(" %f",x[i]);
printf("\n");
}
}
}
}*/
//printf("********* INTEGER SQR ROOTS ***********\n");
/* perform some integer square roots */
/*for (i = 0; i < 1001; ++i)
{
usqrt(i, &q);
// remainder differs on some machines
// printf("sqrt(%3d) = %2d, remainder = %2d\n",
printf("sqrt(%3d) = %2d\n",
i, q.sqrt);
}
usqrt(l, &q);
//printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
printf("\nsqrt(%lX) = %X\n", l, q.sqrt);
printf("********* ANGLE CONVERSION ***********\n");*/
/* convert some rads to degrees */
/*for (X = 0.0; X <= 360.0; X += 1.0)
printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
puts("");
for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180))
printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
*/
return 0;
}
void calc(){
int sol=0;
double x[3];
printf("Calc thread running\n");
for(double a1=1;a1<10;a1++) {
for(double b1=10;b1>0;b1--) {
for(double c1=5;c1<15;c1+=0.5) {
for(double d1=-1;d1>-11;d1--) {
SolveCubic(a1, b1, c1, d1, &sol, x);
printf("Solutions:");
for(int i=0;i<sol;i++)
printf(" %f",x[i]);
printf("\n");
}
}
}
}
}
void SolveCubic(double a,
double b,
double c,
double d,
int *solutions,
double *x)
{
long double a1 = b/a, a2 = c/a, a3 = d/a;
long double Q = (a1*a1 - 3.0*a2)/9.0;
long double R = (2.0*a1*a1*a1 - 9.0*a1*a2 + 27.0*a3)/54.0;
double R2_Q3 = R*R - Q*Q*Q;
double theta;
if (R2_Q3 <= 0)
{
*solutions = 3;
theta = acos(R/sqrt(Q*Q*Q));
x[0] = -2.0*sqrt(Q)*cos(theta/3.0) - a1/3.0;
x[1] = -2.0*sqrt(Q)*cos((theta+2.0*PI)/3.0) - a1/3.0;
x[2] = -2.0*sqrt(Q)*cos((theta+4.0*PI)/3.0) - a1/3.0;
}
else
{
*solutions = 1;
x[0] = pow(sqrt(R2_Q3)+fabs(R), 1/3.0);
x[0] += Q/x[0];
x[0] *= (R < 0.0) ? 1 : -1;
x[0] -= a1/3.0;
}
}

View File

@ -1,64 +0,0 @@
/* +++Date last modified: 05-Jul-1997 */
/*
** CUBIC.C - Solve a cubic polynomial
** public domain by Ross Cottrell
*/
#include <math.h>
#include <stdlib.h>
#include "snipmath.h"
void SolveCubic(double a,
double b,
double c,
double d,
int *solutions,
double *x)
{
long double a1 = b/a, a2 = c/a, a3 = d/a;
long double Q = (a1*a1 - 3.0*a2)/9.0;
long double R = (2.0*a1*a1*a1 - 9.0*a1*a2 + 27.0*a3)/54.0;
double R2_Q3 = R*R - Q*Q*Q;
double theta;
if (R2_Q3 <= 0)
{
*solutions = 3;
theta = acos(R/sqrt(Q*Q*Q));
x[0] = -2.0*sqrt(Q)*cos(theta/3.0) - a1/3.0;
x[1] = -2.0*sqrt(Q)*cos((theta+2.0*PI)/3.0) - a1/3.0;
x[2] = -2.0*sqrt(Q)*cos((theta+4.0*PI)/3.0) - a1/3.0;
}
else
{
*solutions = 1;
x[0] = pow(sqrt(R2_Q3)+fabs(R), 1/3.0);
x[0] += Q/x[0];
x[0] *= (R < 0.0) ? 1 : -1;
x[0] -= a1/3.0;
}
}
#ifdef TEST
int main(void)
{
double a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
double a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0;
double x[3];
int solutions;
SolveCubic(a1, b1, c1, d1, &solutions, x);
/* should get 3 solutions: 2, 6 & 2.5 */
SolveCubic(a2, b2, c2, d2, &solutions, x);
/* should get 1 solution: 2.5 */
return 0;
}
#endif /* TEST */

View File

@ -21,11 +21,13 @@ LIB="";
#Check if file exists
if [ ! -f ./simplified.ll ]; then
clang++ -L/home/mahesh/git_repos/ccf/llvm/build/include/ -w -O3 -g -fno-unroll-loops -fno-slp-vectorize -fno-vectorize --target=armv7a-linux-eabi -isystem /usr/arm-linux-gnueabi/include $ccf_root/scripts/CGRALib/cgra.cpp -S -o - -emit-llvm -o from_clang.ll
opt -loop-simplify -redundant-dbg-inst-elim from_clang.ll -o simplified.bc
llvm-dis -f simplified.bc -o simplified.ll
clang++ -L${ccf_root}/llvm-project/build/include/ -w -O3 -g -fno-unroll-loops -fno-slp-vectorize -fno-vectorize --target=armv7a-linux-eabi -isystem /usr/arm-linux-gnueabi/include $ccf_root/scripts/CGRALib/cgra.cpp -S -o - -emit-llvm -o from_clang.ll
opt -loop-simplify -redundant-dbg-inst-elim from_clang.ll -o simplified.bc
llvm-dis -f simplified.bc -o simplified.ll
fi
cp simplified.ll combinedIR.ll
j=1;
for i in "$@"
do
@ -87,7 +89,7 @@ else
srcIR+=" -o temp.ll"
fi
$srcIR
llvm-link temp.ll simplified.ll -S -o combinedIR.ll
llvm-link temp.ll combinedIR.ll -S -o combinedIR.ll
exit
fi
@ -125,7 +127,7 @@ then
srcNew+=" $i"
srcNew+=" -o temp.ll"
$srcNew
llvm-link temp.ll combinedIR.ll -S -o combinedIR.ll
llvm-link temp.ll combinedIR.ll -S -o combinedIR.ll
fi
done
else
@ -154,6 +156,11 @@ fi
$ccf_root/scripts/opt.sh combinedIR.ll ${install_path} ${ccf_root}
if [ ! -d "CGRAExec" ]; then
echo "Loop was not compiled for CGRA"
exit 1
fi
llvm-dis CGRAGen.bc -o CGRAGen.ll
llc -march="arm" CGRAGen.ll

View File

@ -3,6 +3,9 @@
#include "cgra.h"
#include <string.h>
#include <limits.h>
#ifdef __cplusplus
#include <iostream>
#endif
#define DEBUG 1

View File

@ -13154,6 +13154,7 @@ void CGRA::Prolog(DFG* myDFG, int highest_distance, int node_with_highest_distan
prologFile.close();
}
void CGRA::EPIlog(DFG* myDFG)
{
@ -13411,10 +13412,97 @@ bool CGRA::Compatible2(MappingPair* mp1, MappingPair* mp2, DFG* &myDFG)
//|| (connected_Nodes(mp2->getNode(), mp1->getNode()) && connectedPEs(mp2->getPE(), mp1->getPE())))
return false;
int II = kernelsize/(XDim*YDim);
int epiLength = episize/(XDim*YDim);
int prolength = prosize/(XDim*YDim);
*(initCGRA + 7*(loopID-1) + 2) = II;
*(initCGRA + 7*(loopID-1) + 3) = epiLength;
*(initCGRA + 7*(loopID-1) + 4) = prolength;
*(initCGRA + 7*(loopID-1) + 6) = livevar_st_size/(XDim*YDim);
fclose(epi);
fclose(pro);
fclose(kern);
fclose(count);
char loopitfile[40] = "";
strcat(loopitfile,directoryPath);
strcat(loopitfile,"/kernel_count.txt");
int kernelCount = 0;
count=fopen(loopitfile,"r");
fscanf(count, "%d", &kernelCount);
fclose(count);
printf("Loop Count: %d\n",kernelCount);
*(initCGRA + 7*(loopID-1) + 5) = kernelCount;
printf("From FILE: PROLOGPC= %lx, EPILOGPC=%lx, KernelPC=%lx\n",(unsigned long)prolog,(unsigned long)epilog,(unsigned long)kernel);
prologPtr[loopID-1] = (unsigned long long) prolog;
epilogPtr[loopID-1] = (unsigned long long) epilog;
kernelPtr[loopID-1] = (unsigned long long) kernel;
//printf("Exiting cgra.c Initialize Parameters\n");
return 0;
}
int configureCGRA(unsigned int loopID)
{
//printf("Entering cgra.c configureCGRA\n");
unsigned int i=0;
int kernelCount = *(initCGRA + 7*(loopID-1) + 5);
FILE* count;
char loopno[25];
char directoryPath[20] = "./CGRAExec/L";
sprintf(loopno,"%d",loopID);
strcat(directoryPath,loopno);
if(kernelCount <= 0)
{
int newTC = kernelCount + dynamicTCVal;
*(initCGRA + 7*(loopID-1) + 5) = newTC;
}
char initCGRAfile[40] = "./CGRAExec/L1";
strcat(initCGRAfile,"/initCGRA.txt");
count = fopen(initCGRAfile, "wb");
for(i=0; i<7; i++)
fprintf(count, "%d\n", *(initCGRA + 7*(loopID-1) + i));
fprintf(count, "%ld\n", (unsigned long long) epilogPtr[loopID-1]);
fprintf(count, "%ld\n", (unsigned long long) prologPtr[loopID-1]);
fprintf(count, "%ld\n", (unsigned long long) kernelPtr[loopID-1]);
fclose(count);
//printf("Exiting cgra.c configureCGRA\n");
return 0;
}
void checkTotalLoops( )
{
//printf("Entering cgra.c checkTotalLoops\n");
char myfile[40] = "./CGRAExec/total_loops.txt";
FILE* count;
count = fopen(myfile, "r");
fscanf(count, "%u", &totalLoops);
fclose(count);
//printf("Exiiting cgra.c checkTotalLoops\n");
}
void* runOnCGRA(void)
{
printf("\n\nrunOnCGRA\n");
asm("mov r11,%[value]" : :[value]"r" (activate_CGRA):);
return NULL;
}
int CGRA::Compatible(MappingPair* mp1, MappingPair* mp2, DFG* &myDFG)
{
if (mp1->getNode()->get_ID() == mp2->getNode()->get_ID() || mp1->getPE() == mp2->getPE())
return 0;
else
@ -13476,6 +13564,15 @@ int CGRA::Compatible(MappingPair* mp1, MappingPair* mp2, DFG* &myDFG)
if (mp1->getPE()->getIndexI()!=mp2->getPE()->getIndexI())
return 0;
}
printf("\n\naccelerateOnCGRA\n");
int result = 0;
int configure = configureCGRA(loopNo);
//if(DEBUG) printf("configure = %d, loopNo = %d\n", configure, loopNo);
if(configure == -1)
{
printf("Error in configuring CGRA:\n");
}
}
@ -13567,6 +13664,16 @@ void CGRA::CalcPEUtil(float &PEUtil)
}
}
PEUtil = ((float)(busyPEs))/((float)II);
// thread_cond_cpu = 0;
//thread_cond_cgra = 1;
runOnCGRA();
//while(thread_cond_cpu != 1) {
// usleep(1);
// }
//printf("Exiting Accelerate on CGRA\n");
}
bool CGRA::IsCompatible(int node1, int node2)
@ -13630,6 +13737,7 @@ void CGRA::makeRFTable()
}
}
}
printf("\ndeleting cgra\n");
}
void CGRA::getMinMaxReg(int &Rmin, int &Rmax)
@ -13700,4 +13808,33 @@ void CGRA::UpdateNeedToLoadConstants(DFG* myDFG)
table[index4 * tableSize + index1] += currentNode->hasLargeConst;
}
}
if(DEBUG) printf("createCGRA\n");
int result = 0;
unsigned i=1;
checkTotalLoops();
initCGRA = (int *)malloc(sizeof(int)*7*totalLoops);
prologPtr = (int *)malloc(sizeof(int)*totalLoops);
kernelPtr = (int *)malloc(sizeof(int)*totalLoops);
epilogPtr = (int *)malloc(sizeof(int)*totalLoops);
//pthread_mutex_init(&mutex, NULL);
//pthread_mutex_lock(&mutex);
//result = pthread_create(&pth, NULL, (void*) &runOnCGRA, NULL);
for(i = 1; i <= totalLoops; i++)
{
initializeParameters(i);
}
//pthread_mutex_init(&mutex, NULL);
printf("Main thread calling CGRA thread...\n");
//asm("mov r8,%[value]" : :[value]"r" (CPU_idle):);
//printf("ASM CPU_IDLE Instruction completed\n");
//result = pthread_create(&pth, NULL, (void*) &runOnCGRA, NULL);
//printf("\n\nresult = %d\n\n", result);
//fflush(NULL);
}

View File

@ -20,8 +20,6 @@ LIB="";
zero=0
echo cgracc
#-fno-unroll-loops
#Check if file exists
if [ ! -f ./combinedIR.ll ]; then
@ -30,7 +28,6 @@ if [ ! -f ./combinedIR.ll ]; then
llvm-dis -f simplified.bc -o combinedIR.ll
fi
j=1;
for i in "$@"
do
@ -132,7 +129,8 @@ then
srcNew+=" $i"
srcNew+=" -o temp.ll"
$srcNew
llvm-link temp.ll combinedIR.ll -S -o combinedIR.ll
llvm-link temp.ll combinedIR.ll -S -o combinedIR.ll
fi
done
else
@ -162,28 +160,19 @@ fi
$ccf_root/scripts/opt.sh combinedIR.ll ${install_path} ${ccf_root}
llvm-dis CGRAGen.bc -o CGRAGen.ll
if [ ! -f "CGRAGen.ll" ]; then
exit 1
fi
echo "passed dis"
llvm-dis CGRAGen.bc -o CGRAGen.ll
llc -march="arm" CGRAGen.ll
if [ ! -f "CGRAGen.s" ]; then
exit 1
fi
echo "passed llc"
#apply remaining optimizations here such as vectoirize
clang -w -O3 -static -fno-unroll-loops -fno-slp-vectorize -fno-vectorize -target armv7a-none-linux-eabi CGRAGen.s -o $obj -lm
echo "passed clang"
#Delete temporary files
rm *.s *.bc #*.ll