Commit 5f09c9d9 authored by Anirudh's avatar Anirudh
Browse files

SCuitable plugin

parent 5e72af13
#include "FindGPUMacro.h"
using namespace scpar;
GPUMacro::GPUMacro(int blockIdx, int blockIdy, int blockIdz, int threadIdx, int threadIdy, int threadIdz, int gpuTime, int cpuTime) :
_blockIdx(blockIdx),
_blockIdy(blockIdy),
_blockIdz(blockIdz),
_threadIdx(threadIdx),
_threadIdy(threadIdy),
_threadIdz(threadIdz),
_gpuTime(gpuTime),
_cpuTime(cpuTime){
}
GPUMacro::GPUMacro():
_blockIdx(1),
_blockIdy(1),
_blockIdz(1),
_threadIdx(1),
_threadIdy(1),
_threadIdz(1),
_gpuTime(0),
_cpuTime(0){
}
GPUMacro::~GPUMacro() {
}
int GPUMacro::getBlockIdx(){
return _blockIdx;
}
int GPUMacro::getBlockIdy(){
return _blockIdy;
}
int GPUMacro::getBlockIdz(){
return _blockIdz;
}
int GPUMacro::getThreadIdx(){
return _threadIdx;
}
int GPUMacro::getThreadIdy(){
return _threadIdx;
}
int GPUMacro::getThreadIdz(){
return _threadIdz;
}
int GPUMacro::getCPUTime() {
return _cpuTime;
}
int GPUMacro::getGPUTime() {
return _gpuTime;
}
void GPUMacro::dump(raw_ostream& os) {
os <<"\n Block Ids : " <<_blockIdx<<" " <<_blockIdy<<" " <<_blockIdz;
os <<"\n Thread Ids : " <<_threadIdx<<" " <<_threadIdy<<" " <<_threadIdz;
os <<"\n GPU time : " <<_gpuTime<<" CPU time : " <<_cpuTime;
}
///////////////////////////////////////////////////////
FindGPUMacro::FindGPUMacro(CXXMethodDecl* entryFunction, llvm::raw_ostream& os):
_entryFunction(entryFunction),
_os(os)
{
TraverseDecl(_entryFunction);
}
FindGPUMacro::~FindGPUMacro()
{
}
bool FindGPUMacro::VisitForStmt(ForStmt *fstmt) {
Stmt *body = fstmt->getBody();
int tx = 1, ty = 1, tz = 1 , bx = 1, by = 1, bz = 1, gpu_time = 0, cpu_time = 0;
for (Stmt::child_iterator it = body->child_begin(), eit = body->child_end();
it != eit;
it++) {
Stmt *s = *it;
if (DeclStmt *ds = dyn_cast<DeclStmt>(s)){
if (VarDecl *vd = dyn_cast<VarDecl>(ds->getSingleDecl())){
string className = vd->getTypeSourceInfo()->getType().getBaseTypeIdentifier()->getName();
if (className == "profile_time") {
if (CXXConstructExpr *ce = dyn_cast<CXXConstructExpr>(vd->getInit()->IgnoreImpCasts())) {
IntegerLiteral *x = dyn_cast<IntegerLiteral>(ce->getArg(0));
IntegerLiteral *y = dyn_cast<IntegerLiteral>(ce->getArg(1));
gpu_time = x->getValue().getSExtValue();
cpu_time = y->getValue().getSExtValue();
}
}
if (className == "sc_gpu_thread_hierarchy") {
if (CXXConstructExpr *ce = dyn_cast<CXXConstructExpr>(vd->getInit()->IgnoreImpCasts())) {
IntegerLiteral *x = dyn_cast<IntegerLiteral>(ce->getArg(0));
IntegerLiteral *y = dyn_cast<IntegerLiteral>(ce->getArg(1));
IntegerLiteral *z = dyn_cast<IntegerLiteral>(ce->getArg(2));
tx = x->getValue().getSExtValue();
ty = y->getValue().getSExtValue();
tz = z->getValue().getSExtValue();
}
}
if (className == "sc_gpu_block_hierarchy") {
if (CXXConstructExpr *ce = dyn_cast<CXXConstructExpr>(vd->getInit()->IgnoreImpCasts())) {
IntegerLiteral *x = dyn_cast<IntegerLiteral>(ce->getArg(0));
IntegerLiteral *y = dyn_cast<IntegerLiteral>(ce->getArg(1));
IntegerLiteral *z = dyn_cast<IntegerLiteral>(ce->getArg(2));
bx = x->getValue().getSExtValue();
by = y->getValue().getSExtValue();
bz = z->getValue().getSExtValue();
}
}
}
}
}
if (tx && ty && tz && bx && by && bz && gpu_time && cpu_time) {
GPUMacro *gm = new GPUMacro(bx, by, bz, tx, ty, tz, gpu_time, cpu_time);
_forStmtGPUMacroMap.insert(forStmtGPUMacroPairType(fstmt, gm));
}
return true;
}
FindGPUMacro::forStmtGPUMacroMapType FindGPUMacro::getForStmtGPUMacroMap() {
return _forStmtGPUMacroMap;
}
void FindGPUMacro::dump(){
_os <<"\n For Stmt GPU Macro";
for (forStmtGPUMacroMapType::iterator it = _forStmtGPUMacroMap.begin(), eit = _forStmtGPUMacroMap.end();
it != eit;
it++) {
_os <<"\n For Stmt : " <<it->first;
_os <<"\n GPU kernel parameters \n";
it->second->dump(_os);
}
}
#ifndef __FIND_GPU_MACRO_H
#define __FIND_GPU_MACRO_H
#include "clang/AST/DeclCXX.h"
#include "llvm/Support/raw_ostream.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include <map>
namespace scpar {
using namespace std;
using namespace clang;
class GPUMacro {
public:
GPUMacro(int, int, int, int, int, int, int, int);
GPUMacro();
~GPUMacro();
int getBlockIdx();
int getBlockIdy();
int getBlockIdz();
int getThreadIdx();
int getThreadIdy();
int getThreadIdz();
int getGPUTime();
int getCPUTime();
void dump(raw_ostream&);
private:
int _blockIdx;
int _blockIdy;
int _blockIdz;
int _threadIdx;
int _threadIdy;
int _threadIdz;
int _gpuTime;
int _cpuTime;
};
class FindGPUMacro:public RecursiveASTVisitor <FindGPUMacro> {
public:
typedef pair <ForStmt*, GPUMacro*> forStmtGPUMacroPairType;
typedef map<ForStmt*, GPUMacro*> forStmtGPUMacroMapType;
FindGPUMacro(CXXMethodDecl*, raw_ostream&);
~FindGPUMacro();
// ANI : Need to add other loops as well.....
virtual bool VisitForStmt(ForStmt *);
forStmtGPUMacroMapType getForStmtGPUMacroMap();
void dump();
private:
forStmtGPUMacroMapType _forStmtGPUMacroMap;
CXXMethodDecl* _entryFunction;
raw_ostream& _os;
};
}
#endif
This diff is collapsed.
#ifndef _GLOBAL_SUSPENSION_AUTOMATA_H_
#define _GLOBAL_SUSPENSION_AUTOMATA_H_
#include "Model.h"
#include "FindGPUMacro.h"
namespace scpar {
using namespace clang;
using namespace std;
class GlobalSuspensionAutomata {
public:
GlobalSuspensionAutomata (Model *, raw_ostream &, ASTContext *);
~GlobalSuspensionAutomata();
typedef pair<float, int> timePairType;
typedef vector<Transition*> transitionVectorType;
typedef pair <string, string> instanceEntryFunctionPairType;
typedef pair <instanceEntryFunctionPairType, transitionVectorType> instanceFunctionSautoPairType;
typedef map <instanceEntryFunctionPairType, transitionVectorType> instanceFunctionSautoMapType;
typedef pair <Transition *, timePairType> transitionTimePairType;
typedef map <Transition*, timePairType> transitionTimeMapType;
typedef pair<string, timePairType> eventNotificationTimePairType;
typedef map <string, timePairType> eventNotificationTimeMapType;
typedef pair<State*, vector<Transition*> > stateTransitionsPairType;
typedef map<State*, vector<Transition*> > stateTransitionsMapType;
typedef pair<Transition*, bool> visitTransitionPairType;
typedef map<Transition*, bool> visitTransitionMapType;
typedef pair<EntryFunctionContainer*, FindGPUMacro::forStmtGPUMacroMapType> entryFunctionMacroPairType;
typedef map<EntryFunctionContainer*, FindGPUMacro::forStmtGPUMacroMapType> entryFunctionMacroMapType;
typedef pair<SusCFG*, GPUMacro*> susCFGBlockGPUMacroPairType;
typedef map<SusCFG*, GPUMacro*> susCFGBlockGPUMacroMapType;
typedef pair<timePairType, vector<SusCFG*> > commonTimeDPPairType;
typedef map<timePairType, vector<SusCFG*> > commonTimeDPMapType;
bool updateTransitionTime(Transition*);
void updateEventNotificationTime(Transition*);
void getTransportType();
void annotateTransitionsDPSeg(Transition*);
void initializeGpuMap();
bool GPUMap(float, vector<SusCFG*>, float&);
vector<SusCFG*> arrangeGPUSusCFGBlocks(vector<SusCFG*>);
float maxTime(vector<SusCFG*>, unsigned int);
int max(int, int);
vector<SusCFG*> merge_sort(vector<SusCFG*>, vector<SusCFG*>);
void initialise();
string getArgumentName(Expr *);
bool isNotifyCall(const CFGStmt*);
void genGSauto();
string getNotifyEventName(const CFGStmt *);
void dump();
transitionVectorType getGlobalSauto();
transitionVectorType getTransitionsAtTime(timePairType);
transitionVectorType getOutgoingTransitions(State*);
transitionVectorType getIncomingTransitions(State*);
timePairType getTimeForTransition(Transition*);
instanceFunctionSautoMapType getInstanceFunctionSautoMap();
transitionTimeMapType getTransitionTimeMap();
susCFGBlockGPUMacroMapType getSusCFGBlockGPUMacroMap();
private:
raw_ostream &_os;
ASTContext *_a;
transitionVectorType _globalSauto;
Model * _systemcModel;
Model::moduleMapType _moduleMap;
stateTransitionsMapType _incomingTransitionsMap;
stateTransitionsMapType _outgoingTransitionsMap;
instanceFunctionSautoMapType _instanceFunctionSautoMap;
eventNotificationTimeMapType _eventNotificationTimeMap;
transitionTimeMapType _transitionTimeMap;
FindNotify::notifyCallListType _notifyCalls;
visitTransitionMapType _visitTransitionMap;
entryFunctionMacroMapType _entryFunctionGPUMacroMap;
susCFGBlockGPUMacroMapType _susCFGBlockGPUMacroMap;
commonTimeDPMapType _commonTimeDPMap;
};
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment