Changes to be committed:

modified:   README.md
	modified:   scripts/CGRALib/cgra++
	modified:   scripts/CGRALib/cgra.c
	modified:   scripts/CGRALib/cgra.cpp
	deleted:    scripts/CGRALib/cgra_Arkan.c
	deleted:    scripts/CGRALib/cgra_Vinh.c
	modified:   scripts/CGRALib/cgracc
	deleted:    scripts/CGRALib/diff.out
This commit is contained in:
ArkanDH 2021-06-22 17:12:20 -07:00
parent 46b328b71a
commit 5571769d0b
8 changed files with 74 additions and 753 deletions

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

@ -21,9 +21,9 @@ 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
j=1;
@ -125,7 +125,7 @@ then
srcNew+=" $i"
srcNew+=" -o temp.ll"
$srcNew
llvm-link temp.ll combinedIR.ll -S -o combinedIR.ll
llvm-link temp.ll simplified.ll -S -o combinedIR.ll
fi
done
else

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

@ -167,77 +167,77 @@ void checkTotalLoops( )
}
void* runOnCGRA(void* arg)
void* runOnCGRA(void)
{
//printf("Entering cgra.c runOnCGRA\n");
while(1) {
while(thread_cond_cgra != 1) usleep(1);
if(thread_exit == 1) {
asm("mov r11,%[value]" : :[value]"r" (deactivate_CGRA):);
break;
}
thread_cond_cgra = 0;
asm("mov r11,%[value]" : :[value]"r" (activate_CGRA):);
usleep(1);
thread_cond_cpu = 1;
}
//printf("Entering cgra.c runOnCGRA\n");
return NULL;
printf("\n\nrunOnCGRA\n");
asm("mov r11,%[value]" : :[value]"r" (activate_CGRA):);
return NULL;
}
void accelerateOnCGRA(unsigned int loopNo)
{
//printf("Entering cgra.c accelerateOnCGRA\n");
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");
printf("Error in configuring CGRA:\n");
}
printf("Core will execute loop %u on CGRA\n",loopNo);
thread_cond_cpu = 0;
thread_cond_cgra = 1;
// thread_cond_cpu = 0;
//thread_cond_cgra = 1;
while(thread_cond_cpu != 1) usleep(1);
runOnCGRA();
//while(thread_cond_cpu != 1) {
// usleep(1);
// }
//printf("Exiting Accelerate on CGRA\n");
}
void deleteCGRA()
{
//printf("deleting cgra\n");
printf("\ndeleting cgra\n");
/*
thread_exit = 1;
thread_cond_cgra = 1;
printf("Main thread calling join w/ CGRA thread\n");
pthread_join(pth, NULL);
// printf("Exiting cgra.c deleteCGRA\n");
//pthread_join(pth, NULL);
//printf("Exiting cgra.c deleteCGRA\n"); */
}
void createCGRA()
{
//printf("Entering cgra.c createCGRA\n");
if(DEBUG) printf("createCGRA\n");
int result = 0;
unsigned i=1;
checkTotalLoops();
initCGRA = (int *)malloc(sizeof(int)*7*totalLoops);
prologPtr = (unsigned long long *)malloc(sizeof(unsigned long long)*totalLoops);
kernelPtr = (unsigned long long *)malloc(sizeof(unsigned long long)*totalLoops);
epilogPtr = (unsigned long long *)malloc(sizeof(unsigned long long)*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):);
result = pthread_create(&pth, NULL, runOnCGRA, NULL);
//printf("Exiting cgra.c createCGRA\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

@ -1,310 +0,0 @@
// Author: Shail Dave
#include "cgra.h"
#include <string.h>
#include <limits.h>
#define DEBUG 1
#define usleep(time) myusleep(time)
pthread_mutex_t mutex;
void myusleep(unsigned long time){
printf("Myusleep()\n");
struct timespec req;
req.tv_nsec = time*1000;
thrd_sleep(&(struct timespec){.tv_sec=1}, NULL);
printf("Done sleeping\n");
}
int initializeParameters(unsigned int loopID)
{
if(DEBUG) printf("from cgra.c Initialize Parameters\n");
unsigned int i=0;
*(initCGRA + 7*(loopID-1)) = 0x77e00000;
*(initCGRA + 7*(loopID-1) + 1) = 0x77e00000; //1st instruction, 0xe7e00000 is the opcode for no operation
*(initCGRA + 7*(loopID-1) + 2) = 0; //II
*(initCGRA + 7*(loopID-1) + 3) = 0; //Epilog length
*(initCGRA + 7*(loopID-1) + 4) = 0; //Prolog length
*(initCGRA + 7*(loopID-1) + 5) = 0; //KERNEL COUNTER
*(initCGRA + 7*(loopID-1) + 6) = 0; //Live-Variable Store Epilog Lenth
FILE* epi,*pro,*kern, *count, *config;
char loopno[25];
char directoryPath[20] = "./CGRAExec/L";
sprintf(loopno,"%d",loopID);
strcat(directoryPath,loopno);
char epifile[40] = "";
char profile[40] = "";
char kernfile[40] = "";
char liveOutfile[40] = "";
char configfile[40] = "";
strcat(epifile,directoryPath);
strcat(epifile,"/epilog_ins.bin");
strcat(profile,directoryPath);
strcat(profile,"/prolog_ins.bin");
strcat(kernfile,directoryPath);
strcat(kernfile,"/kernel_ins.bin");
strcat(configfile,directoryPath);
strcat(configfile,"/CGRA_config.txt");
//Make some error checking for fopen and fread
epi=fopen(epifile,"rb");
pro=fopen(profile,"rb");
kern=fopen(kernfile,"rb");
config=fopen(configfile, "r");
int episize,prosize,kernelsize, livevar_st_size;
fread(&episize,sizeof(int),1,epi);
fread(&prosize,sizeof(int),1,pro);
fread(&kernelsize,sizeof(int),1,kern);
printf("\n**********EPISIZE %d*********\n",episize);
printf("\n**********PROSIZE %d*********\n",prosize);
printf("\n**********KERNSIZE %d*********\n",kernelsize);
printf("\n******SIZE OF UNSIGNED LONG%d*****\n",sizeof(unsigned long));
printf("\n******SIZE OF UNSIGNED LONG LONG%d*****\n",sizeof(unsigned long long));
epilog=(unsigned long long*)malloc(episize*sizeof(unsigned long long));
prolog=(unsigned long long*)malloc(prosize*sizeof(unsigned long long));
kernel=(unsigned long long*)malloc(kernelsize*sizeof(unsigned long long));
fread(epilog,sizeof(unsigned long long),episize,epi);
fread(prolog,sizeof(unsigned long long),prosize,pro);
fread(kernel,sizeof(unsigned long long),kernelsize,kern);
strcat(liveOutfile,directoryPath);
strcat(liveOutfile,"/livevar_st_ins_count.txt");
count=fopen(liveOutfile,"r");
fscanf(count, "%d", &livevar_st_size);
char line[256];
int XDim=0, YDim=0;
int iter=0;
printf("\n*******************before while loop**************\n");
while(fgets(line, sizeof(line), config))
{
iter++;
if(iter==1)
XDim = atoi(line);
else if(iter==2)
YDim = atoi(line);
else
break;
}
printf("\n************XDIM and YDim are %d, %d\n", XDim, YDim);
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);
fclose(config);
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)
{
if(DEBUG) printf("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(DEBUG) printf("\nloopno = %s\n", 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( )
{
if(DEBUG) printf("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* arg)
{
if(DEBUG) printf("\n\nrunOnCGRA\n");
pthread_mutex_lock(&mutex);
fflush(NULL);
pthread_mutex_unlock(&mutex);
while(1) {
pthread_mutex_lock(&mutex);
printf("run: mutex lock\n");
while(thread_cond_cgra != 1){
pthread_mutex_unlock(&mutex);
printf("run: waiting\n");
pthread_mutex_lock(&mutex);
}
printf("run: thread_cond_cgra = 1\n");
//if(thread_cond_cgra != 1) pthread_mutex_unlock(&mutex);
//pthread_mutex_lock(&mutex);
//printf("run: mutex lock\n");
if(thread_exit == 1) {
printf("Before DEACTIVE CGRA Instruciton\n");
asm("mov r11,%[value]" : :[value]"r" (deactivate_CGRA):);
printf("After DEACTIVE CGRA Instruciton\n");
pthread_mutex_unlock(&mutex);
break;
}
thread_cond_cgra = 0;
printf("Before Activate CGRA Instruciton\n");
asm("mov r11,%[value]" : :[value]"r" (activate_CGRA):);
printf("After Activate CGRA Instruciton\n");
for(int i = 0; i < 1000; i++);
thread_cond_cpu = 1;
for(int i = 0; i < 1000; i++);
printf("run: thread_cond_cpu is %d\n", thread_cond_cpu);
pthread_mutex_unlock(&mutex);
}
//printf("Entering cgra.c runOnCGRA\n");
//pthread_mutex_unlock(&mutex);
return NULL;
}
void accelerateOnCGRA(unsigned int loopNo)
{
//pthread_mutex_lock(&mutex);
//printf("acc: mutex lock\n");
if(DEBUG) 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");
}
printf("Core will execute loop %u on CGRA\n",loopNo);
thread_cond_cpu = 0;
thread_cond_cgra = 1;
//printf("Syscall clock_nano_sleep_time64: %u\n", __NR_clock_nanosleep_time64);
printf("acc: mutex unlock\n");
pthread_mutex_unlock(&mutex);
while(thread_cond_cpu != 1) {
pthread_mutex_lock(&mutex);
if(thread_cond_cpu) {
printf("acc: thread_cond_cpu is %d\n", thread_cond_cpu);
pthread_mutex_unlock(&mutex);
break;
}
printf("acc out of if: thread_cond_cpu is %d\n", thread_cond_cpu);
printf("Waiting\n");
pthread_mutex_unlock(&mutex);
}
printf("acc: done cpu exec\n");
//if(thread_cond_cpu != 1) pthread_mutex_unlock(&mutex);
//printf("Exiting Accelerate on CGRA\n");
}
void deleteCGRA()
{
pthread_mutex_lock(&mutex);
if(DEBUG) printf("deleting cgra\n");
thread_exit = 1;
thread_cond_cgra = 1;
pthread_mutex_unlock(&mutex);
printf("Main thread calling join w/ CGRA thread\n");
pthread_join(pth, NULL);
if(DEBUG) printf("Exiting cgra.c deleteCGRA\n");
}
void createCGRA()
{
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);
//accelerateOnCGRA(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);
//printf("Exiting cgra.c createCGRA\n");
}

View File

@ -1,298 +0,0 @@
// Author: Shail Dave
#include "cgra.h"
#include <string.h>
#include <limits.h>
#define DEBUG 1
#define usleep(time) myusleep(time)
pthread_mutex_t mutex;
void myusleep(unsigned long time){
printf("Myusleep()\n");
struct timespec req;
req.tv_nsec = time*1000;
thrd_sleep(&(struct timespec){.tv_sec=1}, NULL);
printf("Done sleeping\n");
}
int initializeParameters(unsigned int loopID)
{
if(DEBUG) printf("from cgra.c Initialize Parameters\n");
unsigned int i=0;
*(initCGRA + 7*(loopID-1)) = 0x77e00000;
*(initCGRA + 7*(loopID-1) + 1) = 0x77e00000; //1st instruction, 0xe7e00000 is the opcode for no operation
*(initCGRA + 7*(loopID-1) + 2) = 0; //II
*(initCGRA + 7*(loopID-1) + 3) = 0; //Epilog length
*(initCGRA + 7*(loopID-1) + 4) = 0; //Prolog length
*(initCGRA + 7*(loopID-1) + 5) = 0; //KERNEL COUNTER
*(initCGRA + 7*(loopID-1) + 6) = 0; //Live-Variable Store Epilog Lenth
FILE* epi,*pro,*kern, *count, *config;
char loopno[25];
char directoryPath[20] = "./CGRAExec/L";
sprintf(loopno,"%d",loopID);
strcat(directoryPath,loopno);
char epifile[40] = "";
char profile[40] = "";
char kernfile[40] = "";
char liveOutfile[40] = "";
char configfile[40] = "";
strcat(epifile,directoryPath);
strcat(epifile,"/epilog_ins.bin");
strcat(profile,directoryPath);
strcat(profile,"/prolog_ins.bin");
strcat(kernfile,directoryPath);
strcat(kernfile,"/kernel_ins.bin");
strcat(configfile,directoryPath);
strcat(configfile,"/CGRA_config.txt");
//Make some error checking for fopen and fread
epi=fopen(epifile,"rb");
pro=fopen(profile,"rb");
kern=fopen(kernfile,"rb");
config=fopen(configfile, "r");
int episize,prosize,kernelsize, livevar_st_size;
fread(&episize,sizeof(int),1,epi);
fread(&prosize,sizeof(int),1,pro);
fread(&kernelsize,sizeof(int),1,kern);
printf("\n**********EPISIZE %d*********\n",episize);
printf("\n**********PROSIZE %d*********\n",prosize);
printf("\n**********KERNSIZE %d*********\n",kernelsize);
printf("\n******SIZE OF UNSIGNED LONG%d*****\n",sizeof(unsigned long));
printf("\n******SIZE OF UNSIGNED LONG LONG%d*****\n",sizeof(unsigned long long));
epilog=(unsigned long long*)malloc(episize*sizeof(unsigned long long));
prolog=(unsigned long long*)malloc(prosize*sizeof(unsigned long long));
kernel=(unsigned long long*)malloc(kernelsize*sizeof(unsigned long long));
fread(epilog,sizeof(unsigned long long),episize,epi);
fread(prolog,sizeof(unsigned long long),prosize,pro);
fread(kernel,sizeof(unsigned long long),kernelsize,kern);
strcat(liveOutfile,directoryPath);
strcat(liveOutfile,"/livevar_st_ins_count.txt");
count=fopen(liveOutfile,"r");
fscanf(count, "%d", &livevar_st_size);
char line[256];
int XDim=0, YDim=0;
int iter=0;
printf("\n*******************before while loop**************\n");
while(fgets(line, sizeof(line), config))
{
iter++;
if(iter==1)
XDim = atoi(line);
else if(iter==2)
YDim = atoi(line);
else
break;
}
printf("\n************XDIM and YDim are %d, %d\n", XDim, YDim);
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);
fclose(config);
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)
{
if(DEBUG) printf("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(DEBUG) printf("\nloopno = %s\n", 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( )
{
if(DEBUG) printf("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)
{
pthread_mutex_lock(&mutex);
printf("\n\nrunOnCGRA\n");
pthread_mutex_unlock(&mutex);
while(1) {
pthread_mutex_lock(&mutex);
printf("run: mutex lock\n");
while(thread_cond_cgra != 1){ pthread_mutex_unlock(&mutex); pthread_mutex_lock(&mutex);}
printf("run: thread_cond_cgra = %d\n", thread_cond_cgra);
if(thread_exit == 1) {
printf("\n***Before DEACTIVE CGRA Instruciton\n");
asm("mov r11,%[value]" : :[value]"r" (deactivate_CGRA):);
printf("***After DEACTIVE CGRA Instruciton***\n\n");
pthread_mutex_unlock(&mutex);
break;
}
thread_cond_cgra = 0;
printf("\n***Before Activate CGRA Instruciton***\n");
asm("mov r11,%[value]" : :[value]"r" (activate_CGRA):);
printf("***After Activate CGRA Instruciton***\n\n");
//usleep(1);
for(int i=0; i<1000; i++);
thread_cond_cpu = 1;
//printf("run: thread_cond_cpu = %d\n", thread_cond_cpu);
pthread_mutex_unlock(&mutex);
}
//printf("Entering cgra.c runOnCGRA\n");
//pthread_mutex_unlock(&mutex);
pthread_exit(0);
return NULL;
}
void accelerateOnCGRA(unsigned int loopNo)
{
//pthread_mutex_lock(&mutex);
//printf("acc: mutex lock\n");
if(DEBUG) 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");
}
printf("Core will execute loop %u on CGRA\n",loopNo);
thread_cond_cpu = 0;
thread_cond_cgra = 1;
//printf("Syscall clock_nano_sleep_time64: %u\n", __NR_clock_nanosleep_time64);
printf("acc: mutex unlock\n");
pthread_mutex_unlock(&mutex);
while(thread_cond_cpu != 1) {
pthread_mutex_lock(&mutex);
printf("acc: Waiting\nacc: thread_cond_cpu = %d\n", thread_cond_cpu);
pthread_mutex_unlock(&mutex);
}
//printf("acc: done cpu exec\n");
//if(thread_cond_cpu != 1) pthread_mutex_unlock(&mutex);
//printf("Exiting Accelerate on CGRA\n");
}
void deleteCGRA()
{
if(DEBUG) printf("deleting cgra\n");
thread_exit = 1;
thread_cond_cgra = 1;
printf("Main thread calling join w/ CGRA thread\n");
pthread_join(pth, NULL);
if(DEBUG) printf("Exiting cgra.c deleteCGRA\n");
}
void createCGRA()
{
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);
//accelerateOnCGRA(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);
//printf("Exiting cgra.c createCGRA\n");
}

View File

@ -20,8 +20,6 @@ LIB="";
zero=0
echo cgracc
#-fno-unroll-loops
#Check if file exists
if [ ! -f ./simplified.ll ]; then
@ -160,29 +158,13 @@ fi
$ccf_root/scripts/opt.sh combinedIR.ll ${install_path} ${ccf_root}
echo "passed opt"
llvm-dis CGRAGen.bc -o CGRAGen.ll
if [ ! -f "CGRAGen.ll" ]; then
exit 1
fi
echo "passed dis"
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 -pthread -target armv7a-none-linux-eabi CGRAGen.s -o $obj -lm
echo "passed clang"
#Delete temporary files
rm *.s *.bc #*.ll

View File

@ -1,87 +0,0 @@
--- cgra.c 2021-05-27 00:52:43.926844403 -0700
+++ cgra_Arkan.c 2021-05-27 00:47:48.621098565 -0700
@@ -192,9 +192,13 @@
pthread_mutex_unlock(&mutex);
while(1) {
pthread_mutex_lock(&mutex);
- printf("run: mutex lock\n");
- while(thread_cond_cgra != 1){ pthread_mutex_unlock(&mutex); pthread_mutex_lock(&mutex);}
- printf("run: thread_cond_cgra = 1\n");
+ printf("run: mutex lock\n");
+ while(thread_cond_cgra != 1){
+ pthread_mutex_unlock(&mutex);
+ printf("run: waiting\n");
+ pthread_mutex_lock(&mutex);
+ }
+ printf("run: thread_cond_cgra = 1\n");
//if(thread_cond_cgra != 1) pthread_mutex_unlock(&mutex);
//pthread_mutex_lock(&mutex);
//printf("run: mutex lock\n");
@@ -202,18 +206,19 @@
printf("Before DEACTIVE CGRA Instruciton\n");
asm("mov r11,%[value]" : :[value]"r" (deactivate_CGRA):);
printf("After DEACTIVE CGRA Instruciton\n");
- pthread_mutex_unlock(&mutex);
- break;
+ pthread_mutex_unlock(&mutex);
+ break;
}
thread_cond_cgra = 0;
printf("Before Activate CGRA Instruciton\n");
asm("mov r11,%[value]" : :[value]"r" (activate_CGRA):);
printf("After Activate CGRA Instruciton\n");
- //usleep(1);
- for(int i=0; i<100; i++){}
- thread_cond_cpu = 1;
- pthread_mutex_unlock(&mutex);
+ for(int i = 0; i < 1000; i++);
+ thread_cond_cpu = 1;
+ for(int i = 0; i < 1000; i++);
+ printf("run: thread_cond_cpu is %d\n", thread_cond_cpu);
+ pthread_mutex_unlock(&mutex);
}
//printf("Entering cgra.c runOnCGRA\n");
//pthread_mutex_unlock(&mutex);
@@ -241,7 +246,17 @@
//printf("Syscall clock_nano_sleep_time64: %u\n", __NR_clock_nanosleep_time64);
printf("acc: mutex unlock\n");
pthread_mutex_unlock(&mutex);
- while(thread_cond_cpu != 1) {printf("Waiting\n"); pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex);}
+ while(thread_cond_cpu != 1) {
+ pthread_mutex_lock(&mutex);
+ if(thread_cond_cpu) {
+ printf("acc: thread_cond_cpu is %d\n", thread_cond_cpu);
+ pthread_mutex_unlock(&mutex);
+ break;
+ }
+ printf("acc out of if: thread_cond_cpu is %d\n", thread_cond_cpu);
+ printf("Waiting\n");
+ pthread_mutex_unlock(&mutex);
+ }
printf("acc: done cpu exec\n");
//if(thread_cond_cpu != 1) pthread_mutex_unlock(&mutex);
@@ -250,14 +265,15 @@
void deleteCGRA()
{
- if(DEBUG) printf("deleting cgra\n");
-
- thread_exit = 1;
- thread_cond_cgra = 1;
+ pthread_mutex_lock(&mutex);
+ if(DEBUG) printf("deleting cgra\n");
- printf("Main thread calling join w/ CGRA thread\n");
- pthread_join(pth, NULL);
- if(DEBUG) printf("Exiting cgra.c deleteCGRA\n");
+ thread_exit = 1;
+ thread_cond_cgra = 1;
+ pthread_mutex_unlock(&mutex);
+ printf("Main thread calling join w/ CGRA thread\n");
+ pthread_join(pth, NULL);
+ if(DEBUG) printf("Exiting cgra.c deleteCGRA\n");
}