Skip to content

Commit

Permalink
Defining sdt::less<CTree*> operator to provide an unique and stable o…
Browse files Browse the repository at this point in the history
…rdering is enough to garanty determinism.
  • Loading branch information
sletz committed Jan 18, 2025
1 parent af30245 commit b92fe3f
Show file tree
Hide file tree
Showing 29 changed files with 255 additions and 257 deletions.
19 changes: 8 additions & 11 deletions compiler/DirectedGraph/DirectedGraph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
// to represent the time dependency between computations.
//===========================================================

template <typename N, typename Comparator = std::less<N>>
template <typename N>
class digraph {
using TWeights = std::set<int>;
using TDestinations = std::map<N, TWeights, Comparator>;
using TDestinations = std::map<N, TWeights>;

static inline const TWeights gEmptyWeights;

Expand All @@ -38,8 +38,8 @@ class digraph {
// have integer values attached.
class internalgraph {
private:
std::set<N, Comparator> fNodes; // {n1,n2,...}
std::map<N, TDestinations, Comparator> fConnections; // {(ni -{d1,d2,...}-> nj),...}
std::set<N> fNodes; // {n1,n2,...}
std::map<N, TDestinations> fConnections; // {(ni -{d1,d2,...}-> nj),...}

public:
#if 0
Expand Down Expand Up @@ -70,13 +70,10 @@ class digraph {
//----------------------------------------------------------------------

// returns the set of nodes of the graph
[[nodiscard]] const std::set<N, Comparator>& nodes() const { return fNodes; }
[[nodiscard]] const std::set<N>& nodes() const { return fNodes; }

// returns the set of nodes of the graph
[[nodiscard]] const std::map<N, TDestinations, Comparator>& connections() const
{
return fConnections;
}
[[nodiscard]] const std::map<N, TDestinations>& connections() const { return fConnections; }

// Returns the destinations of node n in the graph
[[nodiscard]] const TDestinations& destinations(const N& n) const
Expand Down Expand Up @@ -208,10 +205,10 @@ class digraph {
//--------------------------------------------------------------------------

// returns the set of nodes of the graph
[[nodiscard]] const std::set<N, Comparator>& nodes() const { return fContent->nodes(); }
[[nodiscard]] const std::set<N>& nodes() const { return fContent->nodes(); }

// returns the set of nodes of the graph
[[nodiscard]] const std::map<N, TDestinations, Comparator>& connections() const
[[nodiscard]] const std::map<N, TDestinations>& connections() const
{
return fContent->connections();
}
Expand Down
179 changes: 87 additions & 92 deletions compiler/DirectedGraph/DirectedGraphAlgorythm.hh

Large diffs are not rendered by default.

55 changes: 27 additions & 28 deletions compiler/DirectedGraph/Schedule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
*
* @tparam N
*/
template <typename N, typename Comparator = std::less<N>>
template <typename N>
class schedule {
private:
std::vector<N> fElements; // ordered set of elements
std::map<N, int, Comparator>
fOrder; // order of each element (starting at 1, 0 indicates not in schedule)
std::vector<N> fElements; // ordered set of elements
std::map<N, int> fOrder; // order of each element (starting at 1, 0 indicates not in schedule)

public:
// number of elements in the schedule
Expand Down Expand Up @@ -64,7 +63,7 @@ class schedule {
}

// append all the elements of a schedule
schedule& append(const schedule<N, Comparator>& S)
schedule& append(const schedule<N>& S)
{
for (const N& n : S.elements()) {
append(n);
Expand All @@ -81,8 +80,8 @@ class schedule {
* @param S the schedule
* @return std::ostream& the output stream
*/
template <typename N, typename Comparator = std::less<N>>
inline std::ostream& operator<<(std::ostream& file, const schedule<N, Comparator>& S)
template <typename N>
inline std::ostream& operator<<(std::ostream& file, const schedule<N>& S)
{
std::string sep = "";

Expand All @@ -101,11 +100,11 @@ inline std::ostream& operator<<(std::ostream& file, const schedule<N, Comparator
* @param G the graph we want to schedule
* @return schedule<N> the deep first schedule of G
*/
template <typename N, typename Comparator = std::less<N>>
inline schedule<N, Comparator> dfschedule(const digraph<N, Comparator>& G)
template <typename N>
inline schedule<N> dfschedule(const digraph<N>& G)
{
schedule<N, Comparator> S;
std::set<N, Comparator> V; // set of visited nodes
schedule<N> S;
std::set<N> V; // set of visited nodes

// recursive deep first visit (pseudo local function using a lambda)
std::function<void(const N&)> dfvisit = [&](const N& n) {
Expand Down Expand Up @@ -133,11 +132,11 @@ inline schedule<N, Comparator> dfschedule(const digraph<N, Comparator>& G)
* @return schedule<N> the breadth first schedule of G
*/

template <typename N, typename Comparator = std::less<N>>
inline schedule<N, Comparator> bfschedule(const digraph<N, Comparator>& G)
template <typename N>
inline schedule<N> bfschedule(const digraph<N>& G)
{
std::vector<std::vector<N>> P = parallelize(G);
schedule<N, Comparator> S;
schedule<N> S;

for (uint64_t i = 0; i < P.size(); i++) {
for (const N& n : P[i]) {
Expand All @@ -158,8 +157,8 @@ inline schedule<N, Comparator> bfschedule(const digraph<N, Comparator>& G)
* @param S
* @return int
*/
template <typename N, typename Comparator = std::less<N>>
inline int schedulingcost(const digraph<N, Comparator>& G, const schedule<N, Comparator>& S)
template <typename N>
inline int schedulingcost(const digraph<N>& G, const schedule<N>& S)
{
int cost = 0;
for (const N& n : G.nodes()) {
Expand All @@ -180,13 +179,13 @@ inline int schedulingcost(const digraph<N, Comparator>& G, const schedule<N, Com
* @param G the graph we want to schedule
* @return schedule<N> the deep first schedule of G
*/
template <typename N, typename Comparator = std::less<N>>
inline schedule<N, Comparator> dfcyclesschedule(const digraph<N, Comparator>& G)
template <typename N>
inline schedule<N> dfcyclesschedule(const digraph<N>& G)
{
digraph<digraph<N, Comparator>> H = graph2dag(G);
schedule<digraph<N, Comparator>> SH = dfschedule(H);
schedule<N, Comparator> S;
for (const digraph<N, Comparator>& n : SH.elements()) {
digraph<digraph<N>> H = graph2dag(G);
schedule<digraph<N>> SH = dfschedule(H);
schedule<N> S;
for (const digraph<N>& n : SH.elements()) {
S.append(dfschedule(cut(n, 1)));
}
return S;
Expand All @@ -199,13 +198,13 @@ inline schedule<N, Comparator> dfcyclesschedule(const digraph<N, Comparator>& G)
* @param G the graph we want to schedule
* @return schedule<N> the deep first schedule of G
*/
template <typename N, typename Comparator = std::less<N>>
inline schedule<N, Comparator> bfcyclesschedule(const digraph<N, Comparator>& G)
template <typename N>
inline schedule<N> bfcyclesschedule(const digraph<N>& G)
{
digraph<digraph<N, Comparator>> H = graph2dag(G);
schedule<digraph<N, Comparator>> SH = bfschedule(H);
schedule<N, Comparator> S;
for (const digraph<N, Comparator>& n : SH.elements()) {
digraph<digraph<N>> H = graph2dag(G);
schedule<digraph<N>> SH = bfschedule(H);
schedule<N> S;
for (const digraph<N>& n : SH.elements()) {
S.append(dfschedule(cut(n, 1)));
}
return S;
Expand Down
4 changes: 2 additions & 2 deletions compiler/documentator/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ static void printLatexHeader(istream& latexheader, const string& faustversion, o
static void printDocMetadata(const Tree expr, ostream& docout)
{
if (gGlobal->gMetaDataSet.count(expr)) {
string sep = "";
set<Tree, CTreeComparator> mset = gGlobal->gMetaDataSet[expr];
string sep = "";
set<Tree> mset = gGlobal->gMetaDataSet[expr];
for (set<Tree>::iterator j = mset.begin(); j != mset.end(); j++) {
docout << sep << unquote(tree2str(*j));
sep = ", ";
Expand Down
6 changes: 3 additions & 3 deletions compiler/draw/sigToGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

using namespace std;

static void recdraw(Tree sig, set<Tree, CTreeComparator>& drawn, ostream& fout);
static void recdraw(Tree sig, set<Tree>& drawn, ostream& fout);
static string nodeattr(Type t);
static string edgeattr(Type t);
static string sigLabel(Tree sig);
Expand All @@ -48,7 +48,7 @@ static string sigLabel(Tree sig);
*/
void sigToGraph(Tree L, ostream& fout)
{
set<Tree, CTreeComparator> alreadyDrawn;
set<Tree> alreadyDrawn;

fout << "strict digraph loopgraph {\n"
<< " rankdir=LR; node [fontsize=10];" << endl;
Expand All @@ -70,7 +70,7 @@ void sigToGraph(Tree L, ostream& fout)
/**
* Draw recursively a signal
*/
static void recdraw(Tree sig, set<Tree, CTreeComparator>& drawn, ostream& fout)
static void recdraw(Tree sig, set<Tree>& drawn, ostream& fout)
{
// cerr << ++gGlobal->TABBER << "ENTER REC DRAW OF " << sig << "$" << *sig << endl;
tvec subsig;
Expand Down
7 changes: 3 additions & 4 deletions compiler/generator/code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ bool CodeContainer::getLoopProperty(Tree sig, CodeLoop*& l)
return fLoopProperty.get(sig, l);
}

void CodeContainer::listAllLoopProperties(Tree sig, set<CodeLoop*>& L,
set<Tree, CTreeComparator>& visited)
void CodeContainer::listAllLoopProperties(Tree sig, set<CodeLoop*>& L, set<Tree>& visited)
{
if (visited.count(sig) == 0) {
visited.insert(sig);
Expand Down Expand Up @@ -179,8 +178,8 @@ void CodeContainer::closeLoop(Tree sig)
faustassert(fCurLoop);

// fix the missing dependencies
set<CodeLoop*> L;
set<Tree, CTreeComparator> V;
set<CodeLoop*> L;
set<Tree> V;
listAllLoopProperties(sig, L, V);
for (CodeLoop* l : L) {
fCurLoop->fBackwardLoopDependencies.insert(l);
Expand Down
8 changes: 4 additions & 4 deletions compiler/generator/code_container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CodeContainer : public virtual Garbageable {
void printHeader(std::ostream& dst)
{
// defines the metadata we want to print as comments at the begin of in the file
std::set<Tree, CTreeComparator> selectedKeys;
std::set<Tree> selectedKeys;
selectedKeys.insert(tree("name"));
selectedKeys.insert(tree("author"));
selectedKeys.insert(tree("copyright"));
Expand Down Expand Up @@ -280,9 +280,9 @@ class CodeContainer : public virtual Garbageable {

void setLoopProperty(Tree sig, CodeLoop* l); ///< Store the loop used to compute a signal
bool getLoopProperty(Tree sig, CodeLoop*& l); ///< Returns the loop used to compute a signal
void listAllLoopProperties(Tree sig, std::set<CodeLoop*>&,
std::set<Tree, CTreeComparator>&
visited); ///< Returns all the loop used to compute a signal
void listAllLoopProperties(
Tree sig, std::set<CodeLoop*>&,
std::set<Tree>& visited); ///< Returns all the loop used to compute a signal

void printGraphDotFormat(std::ostream& fout);

Expand Down
5 changes: 2 additions & 3 deletions compiler/generator/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static string wdel(const string& s)
void Compiler::generateMetaData()
{
// Add global metadata
for (map<Tree, set<Tree, CTreeComparator>>::iterator i = gGlobal->gMetaDataSet.begin();
for (map<Tree, set<Tree>>::iterator i = gGlobal->gMetaDataSet.begin();
i != gGlobal->gMetaDataSet.end(); i++) {
if (i->first != tree("author")) {
stringstream str1, str2;
Expand All @@ -138,8 +138,7 @@ void Compiler::generateMetaData()
string res2 = unquote(str2.str());
fJSON.declare(res1.c_str(), res2.c_str());
} else {
for (set<Tree, CTreeComparator>::iterator j = i->second.begin(); j != i->second.end();
j++) {
for (set<Tree>::iterator j = i->second.begin(); j != i->second.end(); j++) {
if (j == i->second.begin()) {
stringstream str1, str2;
str1 << *(i->first);
Expand Down
2 changes: 1 addition & 1 deletion compiler/generator/compile_scal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void ScalarCompiler::conditionStatistics(Tree l)

void ScalarCompiler::conditionStatistics(Tree l)
{
map<Tree, int, CTreeComparator>
map<Tree, int>
fConditionStatistics; // used with the new X,Y:enable --> sigEnable(X*Y,Y>0) primitive
for (const auto& p : fConditionProperty) {
for (Tree lc = p.second; !isNil(lc); lc = tl(lc)) {
Expand Down
14 changes: 7 additions & 7 deletions compiler/generator/compile_scal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class ScalarCompiler : public Compiler {
property<std::pair<std::string, std::string> >
fInstanceInitProperty; // property added to solve 20101208 kjetil bug

std::map<Tree, Tree, CTreeComparator>
std::map<Tree, Tree>
fConditionProperty; // used with the new X,Y:enable --> sigControl(X*Y,Y>0) primitive

static std::map<std::string, int> fIDCounters;
Tree fSharingKey;
OccMarkup* fOccMarkup;
int fMaxIota;
std::map<std::string, std::string> fIotaCache;
std::map<Tree, int, CTreeComparator> fScheduleOrder;
static std::map<std::string, int> fIDCounters;
Tree fSharingKey;
OccMarkup* fOccMarkup;
int fMaxIota;
std::map<std::string, std::string> fIotaCache;
std::map<Tree, int> fScheduleOrder;

public:
ScalarCompiler(const std::string& name, const std::string& super, int numInputs, int numOutputs)
Expand Down
2 changes: 1 addition & 1 deletion compiler/generator/instructions_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void InstructionsCompiler::conditionStatistics(Tree l)

void InstructionsCompiler::conditionStatistics(Tree l)
{
map<Tree, int, CTreeComparator>
map<Tree, int>
fConditionStatistics; // used with the new X,Y:enable --> sigEnable(X*Y,Y != 0) primitive
for (const auto& p : fConditionProperty) {
for (Tree lc = p.second; !isNil(lc); lc = tl(lc)) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/generator/instructions_compiler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InstructionsCompiler : public virtual Garbageable {
property<std::pair<std::string, std::string>> fInstanceInitProperty;
property<std::string> fTableProperty;

std::map<Tree, Tree, CTreeComparator>
std::map<Tree, Tree>
fConditionProperty; // used with the new X,Y:enable --> sigControl(X*Y,Y>0) primitive

Tree fSharingKey;
Expand Down
6 changes: 3 additions & 3 deletions compiler/generator/klass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Klass::openLoop(Tree recsymbol, const string& size)
// cerr << "\nOPEN REC LOOP(" << *recsymbol << ", " << size << ") ----> " << fTopLoop << endl;
}

void Klass::listAllLoopProperties(Tree sig, set<Loop*>& L, set<Tree, CTreeComparator>& visited)
void Klass::listAllLoopProperties(Tree sig, set<Loop*>& L, set<Tree>& visited)
{
if (visited.count(sig) == 0) {
visited.insert(sig);
Expand All @@ -115,8 +115,8 @@ void Klass::closeLoop(Tree sig)
faustassert(fTopLoop);

// fix the missing dependencies
set<Loop*> L;
set<Tree, CTreeComparator> V;
set<Loop*> L;
set<Tree> V;
listAllLoopProperties(sig, L, V);
for (Loop* l : L) {
fTopLoop->fBackwardLoopDependencies.insert(l);
Expand Down
6 changes: 3 additions & 3 deletions compiler/generator/klass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class Klass {

void setLoopProperty(Tree sig, Loop* l); ///< Store the loop used to compute a signal
bool getLoopProperty(Tree sig, Loop*& l); ///< Returns the loop used to compute a signal
void listAllLoopProperties(Tree sig, std::set<Loop*>&,
std::set<Tree, CTreeComparator>&
visited); ///< Returns all the loop used to compute a signal
void listAllLoopProperties(
Tree sig, std::set<Loop*>&,
std::set<Tree>& visited); ///< Returns all the loop used to compute a signal

const std::string& getClassName() const
{
Expand Down
8 changes: 4 additions & 4 deletions compiler/generator/occurrences.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class Occurrences : public virtual Garbageable {
* second om.mark(root) then om.retrieve(subtree)
*/
class OccMarkup : public virtual Garbageable {
Tree fRootTree; ///< occurrences computed within this tree
Tree fPropKey; ///< key used to store occurrences property
std::map<Tree, Tree, CTreeComparator> fConditions; ///< condition associated to each tree
Tree fRootTree; ///< occurrences computed within this tree
Tree fPropKey; ///< key used to store occurrences property
std::map<Tree, Tree> fConditions; ///< condition associated to each tree

void incOcc(Tree env, int v, int r, int d, Tree xc,
Tree t); ///< inc the occurrence of t in context v,r
Expand All @@ -67,7 +67,7 @@ class OccMarkup : public virtual Garbageable {

public:
OccMarkup() : fRootTree(nullptr), fPropKey(nullptr) {}
OccMarkup(std::map<Tree, Tree, CTreeComparator> conditions)
OccMarkup(std::map<Tree, Tree> conditions)
: fRootTree(nullptr), fPropKey(nullptr), fConditions(conditions)
{
}
Expand Down
Loading

0 comments on commit b92fe3f

Please sign in to comment.