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

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

More work on multiplexing

File size: 2.4 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 <pablo/analysis/bdd/bdd.hpp>
8#include <boost/graph/adjacency_list.hpp>
9#include <boost/graph/adjacency_matrix.hpp>
10#include <boost/graph/edge_list.hpp>
11#include <boost/container/flat_map.hpp>
12#include <boost/numeric/ublas/matrix.hpp>
13#include <random>
14#include <stdint.h>
15
16namespace pablo {
17
18class AutoMultiplexing {
19
20    using CharacterizationMap = boost::container::flat_map<PabloAST *, bdd::BDD>;
21    using ConstraintGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::directedS>;
22    using PathGraph = boost::adjacency_matrix<boost::undirectedS>;
23    using SubsetGraph = boost::edge_list<std::pair<unsigned, unsigned>>;
24    using MultiplexSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
25    using IndependentSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::undirectedS, unsigned>;
26    using Advances = std::vector<Advance *>;
27    using TopologicalSortGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::directedS, PabloAST *>;
28    using TopologicalSortQueue = std::queue<TopologicalSortGraph::vertex_descriptor>;
29
30    using RNG = std::mt19937;
31    using RNGDistribution = std::uniform_int_distribution<RNG::result_type>;
32
33    using Vertex = ConstraintGraph::vertex_descriptor;
34
35    using IndependentSet = std::vector<Vertex>;
36
37public:
38    static void optimize(PabloBlock & block);
39protected:
40    bdd::Engine initialize(const std::vector<Var *> & vars, const PabloBlock & entry);
41    void characterize(bdd::Engine & engine, const PabloBlock & entry);
42    void createMultiplexSetGraph();
43    bool generateMultiplexSets(RNG & rng);   
44    void addMultiplexSet(const IndependentSet & set);
45    void approxMaxWeightIndependentSet(RNG & rng);
46    void applySubsetConstraints();
47    void multiplexSelectedIndependentSets();
48    void topologicalSort(PabloBlock & entry) const;
49    void topologicalSort(TopologicalSortGraph & G, TopologicalSortQueue & Q) const;
50
51private:
52    AutoMultiplexing();
53
54    CharacterizationMap     mCharacterizationMap;
55    PathGraph               mPathGraph;
56    ConstraintGraph         mConstraintGraph;
57    SubsetGraph             mSubsetGraph;
58    Advances                mAdvance;
59    MultiplexSetGraph       mMultiplexSetGraph;
60};
61
62}
63
64#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.