Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aco paper branch apr2021 #153

Merged
merged 25 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
64d46b1
Replaced some cost fn checks w/ calls to needsSLIL()
paul-mchugh Jan 31, 2021
067a933
Changed DCF(dual cost fn) ACO to use better cost comparisons
paul-mchugh Feb 1, 2021
a6ec1c0
simplified logic and fixed 2 pass bug
paul-mchugh Feb 2, 2021
f491545
WIP fixed bug
paul-mchugh Feb 3, 2021
4428b6b
added compilation checks around expensive ACO debugging statements
paul-mchugh Feb 18, 2021
b6a56bb
Added stalling list scheduler
paul-mchugh Feb 18, 2021
a966992
Previously was impossible to select stalling_list
paul-mchugh Feb 18, 2021
d8b1d0e
Fix I forgot to push to the repo
paul-mchugh Mar 3, 2021
4eb66bf
Fixed up ACO 2 cost fn alogrithm. Added code for assessing ACO schedu…
paul-mchugh Mar 9, 2021
9618d9f
bugfix
paul-mchugh Mar 9, 2021
9e4f6be
I for got to git add this to the to the repo.
paul-mchugh Mar 16, 2021
9320630
Changed update rul to not update in the second pass if rp constraints…
paul-mchugh Apr 12, 2021
f64e623
compile time optimizations
paul-mchugh Apr 12, 2021
d86429f
wip
paul-mchugh Apr 19, 2021
fa7d822
switched variables to use pheromone_t
paul-mchugh Apr 20, 2021
e2d4e03
added back ability to use no heuristic
paul-mchugh Apr 28, 2021
2c8de0c
Fixed first pass deposition issue
paul-mchugh May 20, 2021
4bd33be
Some cleanup of the code before merging
paul-mchugh May 4, 2021
98a2517
Clang formatted and removed irrelevant comments & #if directive
paul-mchugh May 4, 2021
ac35736
changes in response to Justin's PR comments
paul-mchugh May 22, 2021
f370f22
Dealing with a problem that I noticed which would affect cost functio…
paul-mchugh May 22, 2021
ffd2412
fixed typo
paul-mchugh May 22, 2021
f379c35
added a const
paul-mchugh May 22, 2021
92078f5
Merge branch 'master' into aco_paper_branch_apr2021
paul-mchugh May 24, 2021
ff4a61b
formatted
paul-mchugh May 24, 2021
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
9 changes: 6 additions & 3 deletions example/llvm7-CPU2006-cfg/sched.ini
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ LATENCY_PRECISION LLVM
# The scheduler used to find an initial feasible schedule.
# LIST: List scheduler
# SEQ: Sequential list scheduler
# STALLING_LIST: Schedules stalls until instruction with top heuristic score becomes ready
HEUR_SCHED_TYPE LIST

# What circumstances the ACO dual cost algorithm should be applied
Expand All @@ -161,7 +162,7 @@ ACO_DUAL_COST_FN_ENABLE OFF
# The option NONE disables the constraint cost function for the selected pass
# NOTE: If the constraint cost function is SLIL then the cost function must also be SLIL
# NOTE: The value for ACO2P is used in the second pass
ACO_DUAL_COST_FN TARGET
ACO_DUAL_COST_FN SLIL
ACO2P_DUAL_COST_FN NONE

#use 3-tournament
Expand Down Expand Up @@ -199,8 +200,10 @@ ACO_DBG_REGIONS NONE

ACO_DBG_REGIONS_OUT_PATH /home/user/path_to_graph_output_directory/

# The importance of the heuristic in ACO. ACO uses (1/heuristic)^importance, so
# importance of 0 means don't use the heuristic.
# Previously the heuristic was raised to the power of the heuristic importance,
# but this has proved to not be useful, and added an expensive pow operation.
# Now a heuristic importance of 0 disables the heuristic. Any other value leaves the
# heuristic enabled.
ACO_HEURISTIC_IMPORTANCE 1
ACO2P_HEURISTIC_IMPORTANCE 1

Expand Down
9 changes: 6 additions & 3 deletions example/optsched-cfg/sched.ini
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ LATENCY_PRECISION LLVM
# The scheduler used to find an initial feasible schedule.
# LIST: List scheduler
# SEQ: Sequential list scheduler
# STALLING_LIST: Schedules stalls until instruction with top heuristic score becomes ready
HEUR_SCHED_TYPE LIST

# What circumstances the ACO dual cost algorithm should be applied
Expand All @@ -161,7 +162,7 @@ ACO_DUAL_COST_FN_ENABLE OFF
# The option NONE disables the constraint cost function for the selected pass
# NOTE: If the constraint cost function is SLIL then the cost function must also be SLIL
# NOTE: The value for ACO2P is used in the second pass
ACO_DUAL_COST_FN TARGET
ACO_DUAL_COST_FN SLIL
ACO2P_DUAL_COST_FN NONE

#use 3-tournament
Expand Down Expand Up @@ -199,8 +200,10 @@ ACO_DBG_REGIONS NONE

ACO_DBG_REGIONS_OUT_PATH /home/user/path_to_graph_output_directory/

# The importance of the heuristic in ACO. ACO uses (1/heuristic)^importance, so
# importance of 0 means don't use the heuristic.
# Previously the heuristic was raised to the power of the heuristic importance,
# but this has proved to not be useful, and added an expensive pow operation.
# Now a heuristic importance of 0 disables the heuristic. Any other value leaves the
# heuristic enabled.
ACO_HEURISTIC_IMPORTANCE 1
ACO2P_HEURISTIC_IMPORTANCE 1

Expand Down
10 changes: 6 additions & 4 deletions include/opt-sched/Scheduler/aco.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Last Update: Jan. 2020
#include <map>
#include <memory>
#include <utility>

namespace llvm {
namespace opt_sched {

Expand All @@ -32,7 +31,7 @@ enum class DCF_OPT {

struct Choice {
SchedInstruction *inst;
double heuristic; // range 1 to 2
pheromone_t heuristic; // range 1 to 2
InstCount readyOn; // number of cycles until this instruction becomes ready
};

Expand All @@ -51,7 +50,7 @@ class ACOScheduler : public ConstrainedScheduler {
private:
pheromone_t &Pheromone(SchedInstruction *from, SchedInstruction *to);
pheromone_t &Pheromone(InstCount from, InstCount to);
double Score(SchedInstruction *from, Choice choice);
pheromone_t Score(SchedInstruction *from, Choice choice);
bool shouldReplaceSchedule(InstSchedule *OldSched, InstSchedule *NewSched,
bool IsGlobal);
DCF_OPT ParseDCFOpt(const std::string &opt);
Expand All @@ -78,7 +77,7 @@ class ACOScheduler : public ConstrainedScheduler {
Choice SelectInstruction(const llvm::ArrayRef<Choice> &ready,
SchedInstruction *lastInst);
void UpdatePheromone(InstSchedule *schedule);
std::unique_ptr<InstSchedule> FindOneSchedule();
std::unique_ptr<InstSchedule> FindOneSchedule(InstCount TargetRPCost);
llvm::SmallVector<pheromone_t, 0> pheromone_;
pheromone_t initialValue_;
bool use_fixed_bias;
Expand All @@ -90,6 +89,8 @@ class ACOScheduler : public ConstrainedScheduler {
double local_decay;
double decay_factor;
int ants_per_iteration;
int ants_per_iteration1p;
int ants_per_iteration2p;
int noImprovementMax;
bool print_aco_trace;
std::unique_ptr<InstSchedule> InitialSchedule;
Expand All @@ -99,6 +100,7 @@ class ACOScheduler : public ConstrainedScheduler {
pheromone_t ScRelMax;
DCF_OPT DCFOption;
SPILL_COST_FUNCTION DCFCostFn;
int localCmp = 0, localCmpRej = 0, globalCmp = 0, globalCmpRej = 0;
};

} // namespace opt_sched
Expand Down
4 changes: 4 additions & 0 deletions include/opt-sched/Scheduler/bb_spill.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class BBWithSpill : public SchedRegion {
InstCount totSpillCost_;
InstCount slilSpillCost_;
bool trackLiveRangeLngths_;
bool NeedsComputeSLIL;

// Virtual Functions:
// Given a schedule, compute the cost function value
Expand Down Expand Up @@ -127,6 +128,8 @@ class BBWithSpill : public SchedRegion {
// cost of the schedule using Scf whenever the spill cost updates
void addRecordedCost(SPILL_COST_FUNCTION Scf);
void storeExtraCost(InstSchedule *sched, SPILL_COST_FUNCTION Scf);
InstCount getUnnormalizedIncrementalRPCost() const;

void CmputAndSetCostLwrBound();
int cmputSpillCostLwrBound();

Expand All @@ -149,6 +152,7 @@ class BBWithSpill : public SchedRegion {
InstCount slotNum, EnumTreeNode *trgtNode);
void SetSttcLwrBounds(EnumTreeNode *node);
bool ChkInstLglty(SchedInstruction *inst);
bool needsSLIL() const;
void InitForSchdulng();

protected:
Expand Down
2 changes: 1 addition & 1 deletion include/opt-sched/Scheduler/data_dep.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ class InstSchedule {
InstCount NormSpillCost;

// Stores the spill cost of other spill cost functions
InstCount storedSC[MAX_SCHED_PRIRTS];
InstCount storedSC[MAX_SCF_TYPES];

// An array of peak reg pressures for all reg types in the schedule
InstCount *peakRegPressures_;
Expand Down
4 changes: 3 additions & 1 deletion include/opt-sched/Scheduler/gen_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ enum SchedulerType {
// List scheduler.
SCHED_LIST,
// Sequential list scheduler.
SCHED_SEQ
SCHED_SEQ,
// Stalling list scheduler
SCHED_STALLING_LIST,
};

// Forward declarations used to reduce the number of #includes.
Expand Down
14 changes: 14 additions & 0 deletions include/opt-sched/Scheduler/list_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ class SequentialListScheduler : public ListScheduler {
bool ChkInstLglty_(SchedInstruction *inst) const override;
};

// A list scheduler that schedules the instruction with the top heuristic value
// Unalike ListScheduler this class considers instructions that are ready
// in terms of data dependencies, but not in terms of latencies.
// If the instruction with the top heuristic is not ready in terms of latency
// Then stalls will be inserted until it is ready
class StallSchedulingListScheduler : public ListScheduler {
public:
StallSchedulingListScheduler(DataDepGraph *dataDepGraph,
MachineModel *machMdl, InstCount schedUprBound,
SchedPriorities prirts);

SchedInstruction *PickInst() const;
};

} // namespace opt_sched
} // namespace llvm

Expand Down
2 changes: 2 additions & 0 deletions include/opt-sched/Scheduler/sched_basic_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ enum SPILL_COST_FUNCTION {
SCF_TARGET
};

#define MAX_SCF_TYPES 10

// The type of instruction signatures, used by the enumerator's history table to
// keep track of partial schedules.
typedef UDT_HASHKEY InstSignature;
Expand Down
4 changes: 4 additions & 0 deletions include/opt-sched/Scheduler/sched_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class SchedRegion {
// Get the number of simulated spills code added for this block.
inline int GetSimSpills() { return totalSimSpills_; }

// Gets the un-normalized incremental RP cost for the region(used by ACO)
virtual InstCount getUnnormalizedIncrementalRPCost() const = 0;
// Get schedLength for best-so-far sched
inline InstCount getBestSchedLength() { return bestSchedLngth_; }

Expand Down Expand Up @@ -312,6 +314,8 @@ class SchedRegion {

virtual bool EnableEnum_() = 0;

virtual bool needsSLIL() const = 0;

// Prepares the region for being scheduled.
virtual void SetupForSchdulng_() = 0;

Expand Down
Loading