Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions include/opt-sched/Scheduler/bb_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Last Update: Jan. 2022
#include <mutex>
#include <atomic>
#include <stack>

#include <fstream>
namespace llvm {
namespace opt_sched {

Expand Down Expand Up @@ -87,12 +87,31 @@ class InstPool {
inline int getSortMethod() {return SortMethod_;}
inline void setDepth(int Depth) {Depth_ = Depth;}
};
class BBWorker;
class StopRequestBuffer {

private:

//make mail boxes 64 bytes in size for better caching
struct MailBox {
unsigned long long cost; //8bytes
CostHistEnumTreeNode* history; //8bytes
unsigned long long padding[6]; //48bytes
};

vector<vector<MailBox>> requestBuffer;

void clear(InstCount readerID);

public:

StopRequestBuffer();
~StopRequestBuffer();
void resize(InstCount numSolvers);
EnumTreeNode* read(InstCount readerID, EnumTreeNode* currentNode, BBWorker* bbt_);
void write(CostHistEnumTreeNode* history, InstCount cost, InstCount writerID, InstCount readerID);

};

class InstPool2 {
private:
Expand Down Expand Up @@ -222,7 +241,7 @@ class BBThread {
uint64_t OtherInfsbl = 0;
// Global Pool Nodes explored
uint64_t GlobalPoolNodes = 0;

// Allocate register structures needed to track cost
void setupForSchdulng();
// Initialize cost and register information (e.g register pressure)
Expand Down Expand Up @@ -564,7 +583,7 @@ class BBWorker : public BBThread {

vector<InstPool3 *> localPools_;
std::mutex **localPoolLocks_;

std::string filename;
// References to the locks on shared data
std::mutex **HistTableLock_;
std::mutex *GlobalPoolLock_;
Expand All @@ -573,16 +592,18 @@ class BBWorker : public BBThread {
std::mutex *ImprvmntCntLock_;
std::mutex *RegionSchedLock_;
std::mutex *InactiveThreadLock_;

std::mutex *fileLock_;
StopRequestBuffer* stopRequestBuffer_;
int *IdleTime_;
int *InactiveThreads_;
uint64_t *nodeCounts_;

std::ofstream ofs;
bool WorkSteal_;
bool *WorkStealOn_;
int64_t **subspaceLwrBounds_;
EnumTreeNode *stolenNode_ {nullptr};

bool* stopRequestIssued_;
std::atomic<int>* numStopRequests_;
bool IsTimeoutPerInst_;
int timeoutToMemblock_;

Expand Down Expand Up @@ -622,7 +643,8 @@ class BBWorker : public BBThread {
vector<FUNC_RESULT> *resAddr, int *idleTimes, int NumSolvers, std::vector<InstPool3 *> localPools,
std::mutex **localPoolLocks, int *inactiveThreads, std::mutex *inactiveThreadLock,
int LocalPoolSize, bool WorkSteal, bool *WorkStealOn, bool IsTimeoutPerInst, uint64_t *nodeCounts,
int timeoutToMemblock, int64_t **subspaceLwrBounds);
int timeoutToMemblock, int64_t **subspaceLwrBounds, std::mutex* fileLock,
std::atomic<int>* numStopRequests, bool* stopRequestIssued, StopRequestBuffer* stopRequestBuffer);

~BBWorker();
/*
Expand All @@ -645,7 +667,7 @@ class BBWorker : public BBThread {
void allocSched_();

inline void destroy() {Enumrtr_->destroy();}

void write(const string s);
void setBestSched(InstSchedule *sched);
void setCrntSched(InstSchedule *sched);

Expand All @@ -665,6 +687,8 @@ class BBWorker : public BBThread {
Enumrtr_->appendToRdyLst(lst);
}

void writeStopRequest(CostHistEnumTreeNode* historyNode, InstCount cost, InstCount SolverID);
EnumTreeNode* readStopRequest(EnumTreeNode* node);
inline void setRootRdyLst() {Enumrtr_->setRootRdyLst();}

bool generateStateFromNode(EnumTreeNode *GlobalPoolNode, bool isGlobalPoolNode = true);
Expand Down Expand Up @@ -745,8 +769,11 @@ class BBMaster : public BBInterfacer {
private:
vector<BBWorker *> Workers;
vector<std::thread> ThreadManager;
StopRequestBuffer stopRequestBuffer_;
InstPool4 *GlobalPool;
int firstLevelSize_;
bool stopRequestIssued_;
std::atomic<int> numStopRequests_;
int NumThreads_;
int MinNodesAsMultiple_,MinSplittingDepth_, MaxSplittingDepth_;
uint64_t MasterNodeCount_;
Expand All @@ -762,7 +789,7 @@ class BBMaster : public BBInterfacer {
std::mutex ImprvCountLock;
std::mutex RegionSchedLock;
std::mutex InactiveThreadLock;

std::mutex fileLock;
int64_t HistTableSize_;

int *idleTimes;
Expand Down Expand Up @@ -795,7 +822,9 @@ class BBMaster : public BBInterfacer {
vector<FUNC_RESULT> *results, int *idleTimes,
int NumSolvers, std::vector<InstPool3 *> localPools, std::mutex **localPoolLocks,
int *InactiveThreads_, std::mutex *InactiveThreadLock, int LocalPoolSize, bool WorkSteal,
bool *WorkStealOn, bool IsTimeoutPerInst, uint64_t *nodeCounts, int timeoutToMemblock, int64_t **subspaceLwrBounds);
bool *WorkStealOn, bool IsTimeoutPerInst, uint64_t *nodeCounts, int timeoutToMemblock,
int64_t **subspaceLwrBounds, std::mutex* fileLock, std::atomic<int>* numStopRequests,
bool* stopRequestIssued_, StopRequestBuffer* stopRequestBuffer);


bool initGlobalPool();
Expand Down
2 changes: 1 addition & 1 deletion include/opt-sched/Scheduler/enumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ class Enumerator : public ConstrainedScheduler {
InstCount minUnschduldTplgclOrdr_;

BinHashTable<HistEnumTreeNode> *exmndSubProbs_;

EnumTreeNode* parentOfDominatedNode_;
// A list of insts whose lower bounds have been tightened to be used for
// efficient untightening
LinkedList<SchedInstruction> *tightndLst_;
Expand Down
1 change: 1 addition & 0 deletions include/opt-sched/Scheduler/gen_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class ConstrainedScheduler : public InstScheduler {
// Calculates the schedule and returns it in the passed argument.
virtual FUNC_RESULT FindSchedule(InstSchedule *sched, SchedRegion *rgn) = 0;

BBThread* getSolver() {return bbt_;}
protected:
// The data dependence graph to be scheduled.
DataDepGraph *dataDepGraph_;
Expand Down
7 changes: 6 additions & 1 deletion include/opt-sched/Scheduler/hist_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class HistEnumTreeNode {

inline void setInserted(bool inserted) {isInserted_ = inserted;}

inline void addSolverToHistoryNode(InstCount SolverID) { solversActive_ |= (1 << (SolverID - 2)); }
inline void removeSolverOnHistoryNode(InstCount SolverID) { solversActive_ ^= (1 << (SolverID - 2)); }
inline unsigned int getSolversOnHistoryNode() { return solversActive_; }
inline void clearSolvers() { solversActive_ = 0; }
protected:
HistEnumTreeNode *prevNode_;

Expand All @@ -91,7 +95,8 @@ class HistEnumTreeNode {
InstCount time_;

SchedInstruction *inst_;


unsigned int solversActive_;
bool fullyExplored_ = false;
bool totalCostIsUseable_ = false;
bool archived_ = false;
Expand Down
Loading