Skip to content

Commit

Permalink
This commit adds the improvements that were made as part of the apr-m…
Browse files Browse the repository at this point in the history
…ay2021 ACO paper.

* Replaced some cost fn checks w/ calls to needsSLIL()

* Changed DCF(dual cost fn) ACO to use better cost comparisons

* simplified logic and fixed 2 pass bug

* added compilation checks around expensive ACO debugging statements

* Added stalling list scheduler

* Previously was impossible to select stalling_list

* Fixed up ACO 2 cost fn alogrithm. Added code for assessing ACO schedule quality

* Changed update rule to not update in the second pass if rp constraints are violated, added profiling print stmts

* compile time optimizations

* switched variables to use pheromone_t

* added back ability to use no heuristic

* Clang formatted and removed irrelevant comments & #if directive

* changes in response to Justin's PR comments

* Dealing with a problem that I noticed which would affect cost functions other than APRP
  • Loading branch information
paul-mchugh authored May 24, 2021
1 parent 2771764 commit 43931a1
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 58 deletions.
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

0 comments on commit 43931a1

Please sign in to comment.