source: icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.hpp @ 4648

Last change on this file since 4648 was 4648, checked in by nmedfort, 4 years ago

Temporary check-in. Using simple trie to collect candidate multiplexing sets.

File size: 3.5 KB
Line 
1#ifndef PABLO_AUTOMULTIPLEXING_HPP
2#define PABLO_AUTOMULTIPLEXING_HPP
3
4#include <pablo/codegenstate.h>
5#include <slab_allocator.h>
6#include <queue>
7#include <boost/graph/adjacency_list.hpp>
8#include <boost/graph/adjacency_matrix.hpp>
9#include <boost/container/flat_map.hpp>
10#include <boost/numeric/ublas/matrix.hpp>
11#include <random>
12#include <stdint.h>
13#include <llvm/ADT/DenseMap.h>
14
15struct DdManager; // forward declare of the CUDD manager
16struct DdNode;
17
18namespace pablo {
19
20class PabloBuilder;
21
22class AutoMultiplexing {
23
24    using CharacterizationMap = llvm::DenseMap<const PabloAST *, DdNode *>;
25    using ConstraintGraph = boost::adjacency_matrix<boost::directedS>;
26    using ConstraintVertex = ConstraintGraph::vertex_descriptor;
27    using RNG = std::mt19937;
28    using IntDistribution = std::uniform_int_distribution<RNG::result_type>;
29    using MultiplexSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
30    using Trie = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::directedS, ConstraintVertex, boost::no_property>;
31    using SubsetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
32    // the Advance pointer, input BDD and the BDD variable of the i-th Advance
33    using AdvanceMap = boost::container::flat_map<const Statement *, unsigned>;
34    using AdvanceVector = std::vector<std::tuple<Advance *, DdNode *, DdNode *>>;
35    using VertexVector = std::vector<ConstraintVertex>;
36    using RecentCharacterizations = std::vector<std::pair<const PabloAST *, DdNode *>>;
37
38public:
39    static bool optimize(const std::vector<Var *> & input, PabloBlock & entry);
40protected:
41    void initialize(PabloBlock & entry);
42    void characterize(PabloBlock &block);
43    DdNode * characterize(Statement * const stmt);
44    DdNode * characterize(Advance * adv, DdNode * input);
45    bool notTransitivelyDependant(const ConstraintVertex i, const ConstraintVertex j) const;
46    bool generateMultiplexSets(RNG & rng, unsigned k = 1);
47    void addCandidateSet(const VertexVector & M, Trie & T, VertexVector & roots) const;
48    void writeCandidateSet(const Trie::vertex_descriptor t, const Trie & T, VertexVector & S);
49    void selectMultiplexSets(RNG &);
50    void applySubsetConstraints();
51    void multiplexSelectedIndependentSets() const;
52    void topologicalSort(PabloBlock & entry) const;
53    inline AutoMultiplexing(const std::vector<Var *> & vars)
54    : mVariables(0)
55    , mConstraintGraph(0)
56    , mBaseVariables(vars)
57    {
58    }
59private:
60
61    DdNode * Zero() const;
62    DdNode * One() const;
63    bool isZero(DdNode * const x) const;
64    DdNode * And(DdNode * const x, DdNode * const y);
65    DdNode * Or(DdNode * const x, DdNode * const y);
66    DdNode * Xor(DdNode * const x, DdNode * const y);
67    DdNode * Not(DdNode * x) const;
68    DdNode * Ite(DdNode * const x, DdNode * const y, DdNode * const z);
69    DdNode * NewVar();
70    void Ref(DdNode * const x);
71    void Deref(DdNode * const x);
72    bool NoSatisfyingAssignment(DdNode * const x);
73    void Shutdown();
74
75private:
76    DdManager *                 mManager;
77    unsigned                    mVariables;
78    CharacterizationMap         mCharacterizationMap;
79    ConstraintGraph             mConstraintGraph;
80    SubsetGraph                 mSubsetGraph;
81    AdvanceMap                  mAdvanceMap;
82    AdvanceVector               mAdvance;
83    MultiplexSetGraph           mMultiplexSetGraph;
84    const std::vector<Var *> &  mBaseVariables;
85    RecentCharacterizations     mRecentCharacterizations;
86};
87
88}
89
90#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.