X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fcell%2FCellMapping.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fcell%2FCellMapping.java;h=d5421c5ca5a5703552b92e6cb3fcba126505afa9;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/cell/CellMapping.java b/dol/src/dol/visitor/cell/CellMapping.java new file mode 100644 index 0000000..d5421c5 --- /dev/null +++ b/dol/src/dol/visitor/cell/CellMapping.java @@ -0,0 +1,324 @@ +package dol.visitor.cell; + +import java.util.ArrayList; +import java.util.Vector; + +import dol.datamodel.architecture.Architecture; +import dol.datamodel.mapping.ComputationBinding; +import dol.datamodel.mapping.Mapping; +import dol.datamodel.pn.Process; +import dol.datamodel.pn.ProcessNetwork; +import dol.main.UserInterface; +import dol.parser.xml.archischema.ArchiXmlParser; +import dol.parser.xml.mapschema.MapXmlParser; + +public class CellMapping { + + /** + * Constructor + * @param pn + */ + CellMapping(ProcessNetwork pn, String mapping, boolean ppu, int nrSPU) { + _pn = pn; + + _maxSPU = nrSPU; + + // Select the mapping + + // Structural mapping + if (mapping.compareTo("structural") == 0) { + System.out.println("Cell: use structural mapping"); + structuralMapping(pn, ppu); + } + + // Random mapping + else if (mapping.compareTo("random") == 0) { + System.out.println("Cell: use random mapping"); + randomMapping(pn, ppu); + } + + // Predefined + else if (mapping.compareTo("predefined") == 0) { + System.out.println("Cell: Use predefined mapping."); + System.out.println(" All other parameters are ignored."); + predefinedMapping(pn); + + _maxSPU = _SPUList.size(); + ppu = this._PPU.size() == 0 ? false : true; + } + + // All to PPU + else if (mapping.compareTo("ppu") == 0) { + System.out.println("Cell: Map all processes to the PPU"); + allPPUMapping(pn); + } + + // Default mapping + else { + System.out.println("WARNING: Cell: use default mapping"); + structuralMapping(pn, ppu); + } + + System.out.println("Cell: Nr of SPE is " + _maxSPU); + + if (ppu) { + System.out.println("Cell: Mapped some processes to the PPE"); + } + } + + /** + * Returns a list which process is mapped to which spu + * + * @return the process list + */ + public ArrayList> getSPUList() { + return _SPUList; + } + + /** + * Returns list of all processes which are mapped to an spu + */ + public Vector getAllSpuProcess() { + Vector processList = new Vector(); + + for (Vector spu : _SPUList) { + for (Process p : spu) { + processList.add(p); + } + } + return processList; + } + + /** + * Returns a list of all base processes which occur on the spu's + */ + public Vector getAllSpuBaseProcess() { + Vector pList = new Vector(); + Vector pListName = new Vector(); + for (Process process : getAllSpuProcess()) { + String basename = process.getBasename(); + if (!pListName.contains(basename)) { + pList.add(process); + pListName.add(basename); + } + } + return pList; + } + + /** + * Returns a list of all processes which are mapped to the ppu + */ + public Vector getPPU() { + return _PPU; + } + + /** + * Returns a list of all base processes which occur on the ppu + */ + public Vector getAllPPUBaseProcess() { + Vector pList = new Vector(); + Vector pListName = new Vector(); + for (Process process : _PPU) { + String basename = process.getBasename(); + if (!pListName.contains(basename)) { + pList.add(process); + pListName.add(basename); + } + } + return pList; + } + + /** + * Return the number of processes which are mapped to the ppu + */ + public int getNrPPUProcess() { + return _PPU.size(); + } + + /** + * Returns the number of processes which are mapped to the SPU + */ + public int getNrSPUProcess() { + return getAllSpuProcess().size(); + } + + /** + * Returns the number of SPU which are used + */ + public int getNrSPE() { + return _SPUList.size(); + } + + /** + * Performs a random mapping of the processes + * + * @param x + * the process network + * @param ppu_choose + * true if the sinks and sources should be mapped to the PPU + */ + protected void randomMapping(ProcessNetwork x, boolean ppu_choose) { + ArrayList> spu = new ArrayList>(); + Vector ppu = new Vector(); + + int addSPU = 0; + for (Process p : x.getProcessList()) { + // A process to map to the PPU + if ((p.getNumOfInports() == 0 || p.getNumOfOutports() == 0) + && ppu_choose) { + ppu.add(p); + } + + // A process to map to the SPU + else { + // As long as there is a free SPU, add the process to this SPU + if (addSPU < _maxSPU) { + Vector pList = new Vector(); + pList.add(p); + spu.add(pList); + } + + // Have to add the process to an already used SPU + else { + spu.get(addSPU % _maxSPU).add(p); + } + + addSPU++; + } + } + + _SPUList = spu; + _PPU = ppu; + } + + /** + * Performs a structural mapping of the processes. That means that the + * function tries to keep the structural order of the process network. The + * order is given depending on the occurrence of the process in the + * structure file. + * + * @param x + * the process network + * @param ppu_choose + * true if the sinks and sources should be mapped to the PPU + */ + protected void structuralMapping(ProcessNetwork x, boolean ppu_choose) { + ArrayList> spu = new ArrayList>(); + Vector ppu = new Vector(); + + Vector spu_temp = new Vector(); + + // Each process is allocated to the PPE or the SPE (as general) + for (Process p : x.getProcessList()) { + // A process to map to the PPU + if ((p.getNumOfInports() == 0 || p.getNumOfOutports() == 0) + && ppu_choose) { + ppu.add(p); + } + + // A process to map to the SPU + else { + spu_temp.add(p); + } + } + + System.out.println("Total processes: " + spu_temp.size()); + + // Do the structural mapping for all the SPE processes + int nrSPUProcess = spu_temp.size(); + for (int i = 0; i < _maxSPU; i++) { + + if (spu_temp.size() <= 0) + break; + + Vector pList = new Vector(); + for (int j = 0; j < Math.ceil(((double) (nrSPUProcess - i)) + / _maxSPU); j++) { + pList.add(spu_temp.remove(0)); + } + + spu.add(pList); + } + + System.out.println("End Total processes: " + spu_temp.size()); + + _SPUList = spu; + _PPU = ppu; + } + + /** + * Maps the processes depending on the architectural and mapping files + * + * @param x + */ + protected void predefinedMapping(ProcessNetwork x) { + // The SPUs + ArrayList> spu = new ArrayList>(); + + // The PPU + Vector ppu = new Vector(); + + ArchiXmlParser archParser = new ArchiXmlParser(); + //System.out.println(_ui.getPlatformFileName()); + Architecture arch = archParser.doParse(_ui.getPlatformFileName()); + MapXmlParser mappingParser = new MapXmlParser(x, arch); + Mapping mapping = mappingParser.doParse(_ui.getMappingFileName()); + + // Go through all process and check where to add + for (Process p : x.getProcessList()) { + for (ComputationBinding b : mapping.getCompBindList()) { + if (b.getProcess().getName().equals(p.getName())) { + // Mapping to PPU + if (b.getProcessor().getName().equals("ppu")) { + System.out.println("Mapped process " + p.getName() + + " to the PPU"); + ppu.add(p); + } + // Maps to one of the SPU, they are written in the format + // spu_0, spu_1, ... + else { + int index = Integer.valueOf(b.getProcessor() + .getName().replaceAll(".*_", "")); + + while (spu.size() <= index) { + Vector spu_temp = new Vector(); + spu.add(spu_temp); + } + + spu.get(index).add(p); + System.out.println("Mapped process " + p.getName() + + " to the SPU_" + index); + } + } + } + } + + _SPUList = spu; + _PPU = ppu; + } + + + /** + * Performs a mapping of all processes to the PPU. + * + * @param x the process network + */ + protected void allPPUMapping(ProcessNetwork x) { + ArrayList> spu = new ArrayList>(); + Vector ppu = new Vector(); + + // Each process is allocated to the PPE or the SPE (as general) + for (Process p : x.getProcessList()) { + ppu.add(p); + } + + _SPUList = spu; + _PPU = ppu; + } + + protected ArrayList> _SPUList = null; + protected Vector _PPU = null; + protected ProcessNetwork _pn; + protected int _maxSPU = 6; + protected UserInterface _ui = UserInterface.getInstance(); +}