📄 chipdef.java
字号:
schedule, the "cost" of a certain array to memory aljlocation. The cost depends on the number of cycles necessary to do all memory accesses on these arrays and considering the latencies of the instructions. */ public int cost(BlockGraph bGraph) { int cost = -9999; for (Iterator vIt = new HashSet(bGraph.getAllNodes()).iterator(); vIt.hasNext();) { BlockNode bNode = (BlockNode) vIt.next(); cost = Math.max(cost, _arrayToBlockMap.cost(bNode)); } return cost; } public int trueCost(BlockGraph bGraph) { int cost = -9999; for (Iterator vIt = new HashSet(bGraph.getAllNodes()).iterator(); vIt.hasNext();) { BlockNode bNode = (BlockNode) vIt.next(); cost = Math.max(cost, _arrayToBlockMap.trueCost(bNode)); } return cost; } public void saveBestArrayAlloc(BlockGraph bGraph) { if(_bestArrayToBlockMap == null) { _bestArrayToBlockMap = new ArrayToMemMap(); _bestArrayToBlockMap.putAll((HashMap)_arrayToBlockMap.clone()); _bestArrayAllocCost = trueCost(bGraph); } else { int currentAllocCost = trueCost(bGraph); if(currentAllocCost < _bestArrayAllocCost) { _bestArrayToBlockMap = new ArrayToMemMap(); _bestArrayToBlockMap.putAll((HashMap)_arrayToBlockMap.clone()); //_bestArrayToBlockMap = (ArrayToMemMap)_arrayToBlockMap.clone(); _bestArrayAllocCost = currentAllocCost; } } } public void changeToBestArrayAlloc() { for (Iterator arrs = ((ArrayToMemMap)_arrayToBlockMap.clone()).keySet().iterator(); arrs.hasNext(); ) { ArrayToArrayInfoMap.ArrayInfo array = (ArrayToArrayInfoMap.ArrayInfo)arrs.next(); Memory mBlock = _arrayToBlockMap.get(array); deAllocateArray(mBlock, array); mBlock.addSpace(array.arraySize); } for (Iterator arrs = _bestArrayToBlockMap.keySet().iterator(); arrs.hasNext(); ) { ArrayToArrayInfoMap.ArrayInfo array = (ArrayToArrayInfoMap.ArrayInfo)arrs.next(); Memory mBlock = _bestArrayToBlockMap.get(array); allocate(mBlock, array); mBlock.subSpace(array.arraySize); } } public void deallocateAll() { for (Iterator arrs = ((ArrayToMemMap)_arrayToBlockMap.clone()).keySet().iterator(); arrs.hasNext(); ) { ArrayToArrayInfoMap.ArrayInfo array = (ArrayToArrayInfoMap.ArrayInfo)arrs.next(); Memory mBlock = _arrayToBlockMap.get(array); deAllocateArray(mBlock, array); } resetArrayToBlockMap(); } public void resetArrToArrInfo() { _arrToArrInfoMap = new ArrayToArrayInfoMap(); } public void resetArrayToBlockMap() { _arrayToBlockMap = new ArrayToMemMap(); } public void resetPorts() { //if(_isDummyBoard) return; for (Iterator itsMem = _memoryBlocks.iterator(); itsMem.hasNext(); ) { Memory memBlock = (Memory)itsMem.next(); memBlock.resetPorts(); } } /** for testing an array to memory allocation assuming all aloads and astores are scheduled at the same time */ public int calcLoad(BlockNode bNode, ArrayList instList) { HashMap memBlockLoadCost = new HashMap(); HashMap memBlockStoreCost = new HashMap(); int maxCost = 0; for (Iterator it1 = instList.iterator(); it1.hasNext();) { Instruction inst = (Instruction)it1.next(); if(AStore.conforms(inst)) { Operand array = AStore.getPrimalDestination(inst); Memory mBlock = findMemoryBlock(array); int cost = mBlock.addStoreCnt(bNode, 0, array); maxCost = Math.max(maxCost, cost); } if(ALoad.conforms(inst)) { Operand array = ALoad.getPrimalSource(inst); Memory mBlock = findMemoryBlock(array); int cost = mBlock.addLoadCnt(bNode, 0, array); maxCost = Math.max(maxCost, cost); } } return maxCost; } /** This method looks for the slowest memory, so that its aload and astore instructions can be used by the preliminary schedule. */ private class MemBlockPairStore { public Memory slowestReadMBlock = null; public Memory slowestWriteMBlock = null; } public MemBlockPairStore findSlowestMem() { MemBlockPairStore memBlockPairStore = new MemBlockPairStore(); Memory slowestReadMBlock = null; int slowesReadtLat = -9999; //slowest mem has the largest latency Memory slowestWriteMBlock = null; int slowesWritetLat = -9999; //slowest mem has the largest latency for (Iterator itsMem = _memoryBlocks.iterator(); itsMem.hasNext(); ) { Memory memBlock = (Memory)itsMem.next(); int memReadLat = memBlock.findSlowestReadLat(); if(memReadLat > slowesReadtLat) { slowesReadtLat = memReadLat; slowestReadMBlock = memBlock; } int memWriteLat = memBlock.findSlowestWriteLat(); if(memWriteLat > slowesWritetLat) { slowesWritetLat = memWriteLat; slowestWriteMBlock = memBlock; } } memBlockPairStore.slowestReadMBlock = slowestReadMBlock; memBlockPairStore.slowestWriteMBlock = slowestWriteMBlock; return memBlockPairStore; } public void setInstructions(ArrayList instList) { MemBlockPairStore memBlockPairStore = findSlowestMem(); for (Iterator it1 = instList.iterator(); it1.hasNext();) { Instruction inst = (Instruction)it1.next(); if(AStore.conforms(inst)) { inst.operator = memBlockPairStore.slowestWriteMBlock.getAStoreOp(); Operand array = AStore.getPrimalDestination(inst); ArrayToArrayInfoMap.ArrayInfo arr = _arrToArrInfoMap.get(array); //_arrayToBlockMap.saveArray(arr, memBlockPairStore.slowestWriteMBlock); //memBlockPairStore.slowestWriteMBlock.allocateArray(arr, // _arrToArrInfoMap); allocate(memBlockPairStore.slowestWriteMBlock, arr); } if(ALoad.conforms(inst)) { inst.operator = memBlockPairStore.slowestReadMBlock.getALoadOp(); Operand array = ALoad.getPrimalSource(inst); ArrayToArrayInfoMap.ArrayInfo arr = _arrToArrInfoMap.get(array); //_arrayToBlockMap.saveArray(arr, memBlockPairStore.slowestReadMBlock); //memBlockPairStore.slowestReadMBlock.allocateArray(arr, // _arrToArrInfoMap); allocate(memBlockPairStore.slowestReadMBlock, arr); } } } //old stuff: /** "@param cntTmp * * @param cntTmp */ public void setOpCntsAvailable(HashMap cntTmp) { _opCntsAvailable = (HashMap)cntTmp.clone(); } public HashMap getOpCntsAvailable() { return _opCntsAvailable; } /** "@param cntTmp */ public void setOpCntsNeeded(HashMap cntTmp) { _opCntsNeeded = (HashMap)cntTmp.clone(); } public void setOpList(ArrayList listTmp) { _opList = (ArrayList)listTmp.clone(); } public ArrayList getOpList() { return _opList; } public int getNumNeededForOp(Operator op_Operator) { return ((Integer)(_opCntsNeeded.get(op_Operator))).intValue(); } /** "@param op_Operator */ public int getNumAvailableForOp(Operator op_Operator){ return ((Integer)(_opCntsAvailable.get(op_Operator))).intValue(); } /** searches through memories to see if a given primal operand has been * allocated to them. When they are found, they are saved to * _arrayVarsMemBlock so that they can be accessed quicker. This method * returns the memory block if it was found. If it wasn't found, then * null is returned. * * @param p array name * @return Returns the mem blk if it is in memory and null otherwise. */ public Memory findMemoryBlock(Operand p) { ArrayToArrayInfoMap.ArrayInfo array = _arrToArrInfoMap.get(p); return _arrayToBlockMap.get(array); } /** checks if there would be hardware conflicts if this instruction were to be * scheduled at this time. * * @param instr instruction to schedule * @param cycle desired time to schedule it * @return true=no prob; false = please, try again later */ public boolean analyzeHardwareUse(BlockNode bNode, Instruction instr, int cycle) { Operator operator = instr.operator(); //check for too many writes: if(AStore.conforms(instr)) { Operand array = AStore.getPrimalDestination(instr); Memory mBlock = findMemoryBlock(array); /*System.out.println("looking at store conflicts"); //displayMemsArrs(); System.out.println("instr " + instr); System.out.println("cycle " + cycle); System.out.println("array " + array); System.out.println("bNode " + bNode); System.out.println("mBlock " + mBlock.getChipName()); System.out.println("mBlock.addStoreTestCnt(bNode, cycle, array) " + mBlock.addStoreTestCnt(bNode, cycle, array));*/ if(mBlock.addStoreTestCnt(bNode, cycle, array) > 1) return false; } //check for too many reads: if(ALoad.conforms(instr)) { Operand array = ALoad.getPrimalSource(instr); Memory mBlock = findMemoryBlock(array); /*System.out.println("looking at load conflicts"); //displayMemsArrs(); System.out.println("instr " + instr); System.out.println("cycle " + cycle); System.out.println("array " + array); System.out.println("bNode " + bNode); System.out.println("mBlock " + mBlock.getChipName()); System.out.println("mBlock.addLoadTestCnt(bNode, cycle, array) " + mBlock.addLoadTestCnt(bNode, cycle, array));*/ if(mBlock.addLoadTestCnt(bNode, cycle, array) > 1) return false; } if(_isDummyBoard) return true; //check for too many uses of an operator: //initialize if necessary: if(!(((HashMap)_opUseCntHM.get(_node)).containsKey(new Integer(cycle)))) ((HashMap)_opUseCntHM.get(_node)).put(new Integer(cycle), new HashMap()); if(!(((HashMap)(((HashMap)_opUseCntHM.get(_node)).get(new Integer(cycle)))).containsKey(operator))) ((HashMap)(((HashMap)_opUseCntHM.get(_node)).get(new Integer(cycle)))).put(operator, new Integer(0)); //find old usage: int opUseCnt = ((Integer)(((HashMap)(((HashMap)_opUseCntHM.get(_node)) .get(new Integer(cycle)))) .get(operator))).intValue(); HashMap operatorCntsAtTime = ((HashMap)(((HashMap)_opUseCntHM.get(_node)).get(new Integer(cycle)))); if(opUseCnt+1 > getNumAvailableForOp(operator)) { return false; } //if all the tests passed, then there are no hardware probs return true; } public HashSet killConflictingInstrucs(BlockNode bNode, Instruction instr, int cycle, MSchedHash schedule) { HashSet unscheduled = new HashSet(); Operator operator = instr.operator(); //check for too many writes: if(AStore.conforms(instr)) { Operand array = AStore.getPrimalDestination(instr); Memory mBlock = findMemoryBlock(array); if(mBlock.addStoreTestCnt(bNode, cycle, array) > 1) { HashSet list = schedule.getAllAtTime((float)cycle); for (Iterator it1 = ((HashSet)list.clone()).iterator(); it1.hasNext();) { MSchedHash.MSchedInstObject instObj = (MSchedHash.MSchedInstObject)it1.next(); if(AStore.conforms(instObj.inst)) { Operand prim = AStore.getPrimalDestination(instr); Memory otherMem = findMemoryBlock(prim); if(mBlock == otherMem) { schedule.unscheduleInst(instObj); unscheduled.add(instObj);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -