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

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

More work on multiplexing.

File size: 2.7 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<const PabloAST *, bdd::BDD>;
21    using ConstraintGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
22    using PathGraph = boost::adjacency_matrix<boost::undirectedS>;
23    using MultiplexSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
24    using IndependentSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::undirectedS, unsigned>;
25    using SubsetGraph = std::vector<std::pair<MultiplexSetGraph::vertex_descriptor, MultiplexSetGraph::vertex_descriptor>>;
26    using Advances = std::vector<Advance *>;
27    using TopologicalSortGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS, Statement *>;
28    using TopologicalSortQueue = std::queue<TopologicalSortGraph::vertex_descriptor>;
29    using TopologicalSortMap = boost::container::flat_map<PabloAST *, TopologicalSortGraph::vertex_descriptor>;
30
31    using RNG = std::mt19937;
32    using RNGDistribution = std::uniform_int_distribution<RNG::result_type>;
33
34    using Vertex = ConstraintGraph::vertex_descriptor;
35
36    using IndependentSet = std::vector<Vertex>;
37
38public:
39    static void optimize(const std::vector<Var *> & input, PabloBlock & entry);
40protected:
41    bdd::Engine initialize(const std::vector<Var *> & vars, const PabloBlock & entry);
42    void characterize(bdd::Engine & engine, PabloBlock &entry);
43    void createMultiplexSetGraph();
44    bool generateMultiplexSets(RNG & rng);   
45    void addMultiplexSet(const IndependentSet & set);
46    void approxMaxWeightIndependentSet(RNG & rng);
47    void applySubsetConstraints();
48    void multiplexSelectedIndependentSets();
49    void topologicalSort(PabloBlock & entry) const;
50    void topologicalSort(TopologicalSortGraph & G, TopologicalSortQueue & Q, TopologicalSortMap & M, Statement * ip, Statement * first) const;
51
52private:
53    AutoMultiplexing();
54
55    CharacterizationMap     mCharacterizationMap;
56    PathGraph               mPathGraph;
57    ConstraintGraph         mConstraintGraph;
58    SubsetGraph             mSubsetGraph;
59    Advances                mAdvance;
60    MultiplexSetGraph       mMultiplexSetGraph;
61};
62
63}
64
65#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.