Changeset df8a9a37 in OpenModelica


Ignore:
Timestamp:
2014-05-23T11:30:54+02:00 (10 years ago)
Author:
Volker Waurich <volker3189@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
3d977ef8
Parents:
57668fe2
Message:
  • tds schedule using cluster compaction

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20787 f25d12d1-65f4-0310-ae8a-bbce733d8d8e

Location:
Compiler/BackEnd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Compiler/BackEnd/HpcOmScheduler.mo

    rf5c5366b rdf8a9a37  
    15761576  output HpcOmSimCode.Schedule oSchedule;
    15771577protected
    1578   Integer size,numClusters;
     1578  Integer size;
    15791579  list<Integer> queue;
    15801580  list<Real> levels;
    1581   array<Real> estArray,lastArray,ectArray,lactArray,tdsLevelArray,alap,asap;
     1581  array<Real> ectArray,tdsLevelArray;
    15821582  array<Integer> fpredArray;
    15831583  list<list<Integer>> initClusters;
    1584 algorithm
    1585   HpcOmTaskGraph.printTaskGraph(iTaskGraph);
    1586   HpcOmTaskGraph.printTaskGraphMeta(iTaskGraphMeta);
     1584  HpcOmTaskGraph.TaskGraph taskGraphT;
     1585algorithm
     1586  //HpcOmTaskGraph.printTaskGraph(iTaskGraph);
     1587  //HpcOmTaskGraph.printTaskGraphMeta(iTaskGraphMeta);
    15871588  //compute the necessary node parameters
    15881589  size := arrayLength(iTaskGraph);
    1589   (asap,estArray,ectArray) := computeGraphValuesBottomUp(iTaskGraph,iTaskGraphMeta);
    1590   (alap,lastArray,lactArray,tdsLevelArray) := computeGraphValuesTopDown(iTaskGraph,iTaskGraphMeta);
    1591 
    1592   //printRealArray(estArray,"est");
     1590  taskGraphT := BackendDAEUtil.transposeMatrix(iTaskGraph,size);
     1591  (_,_,ectArray) := computeGraphValuesBottomUp(iTaskGraph,iTaskGraphMeta);
     1592  (_,_,_,tdsLevelArray) := computeGraphValuesTopDown(iTaskGraph,iTaskGraphMeta);
    15931593  //printRealArray(ectArray,"ect");
    1594   //printRealArray(lastArray,"last");
    1595   //printRealArray(lactArray,"lact");
    1596   printRealArray(tdsLevelArray,"tdsLevel");
    1597   //printRealArray(alap,"alap");
    1598   //printRealArray(asap,"asap");
    1599 
     1594  //printRealArray(tdsLevelArray,"tdsLevel");
    16001595  fpredArray := computeFavouritePred(iTaskGraph,iTaskGraphMeta,ectArray); //the favourite predecessor of each node
    1601   printRealArray(Util.arrayMap(fpredArray,intReal),"fpred");
    1602 
     1596  //printRealArray(Util.arrayMap(fpredArray,intReal),"fpred");
    16031597  (levels,queue) := quicksortWithOrder(arrayList(tdsLevelArray));
    1604   print("queue "+&stringDelimitList(List.map(queue,intString)," ; ")+&"\n");
    1605 
    16061598  initClusters := createTDSInitialCluster(iTaskGraph,iTaskGraphMeta,fpredArray,queue);
    1607   print("initClusters:\n"+&stringDelimitList(List.map(initClusters,intListString),"\n")+&"\n");
    1608   numClusters := listLength(initClusters);
    1609 
    1610   oSchedule := HpcOmSimCode.EMPTYSCHEDULE();
     1599  //print("initClusters:\n"+&stringDelimitList(List.map(initClusters,intListString),"\n")+&"\n");
     1600  oSchedule := createTDSschedule1(initClusters,iTaskGraph,taskGraphT,iTaskGraphMeta,tdsLevelArray,numProc,iSccSimEqMapping);
    16111601end createTDSschedule;
     1602
     1603protected function createTDSschedule1
     1604  input list<list<Integer>> clustersIn;
     1605  input HpcOmTaskGraph.TaskGraph iTaskGraph;
     1606  input HpcOmTaskGraph.TaskGraph iTaskGraphT;
     1607  input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
     1608  input array<Real> TDSLevel;
     1609  input Integer numProc;
     1610  input array<list<Integer>> iSccSimEqMapping;
     1611  output HpcOmSimCode.Schedule oSchedule;
     1612algorithm
     1613  oSchedule := matchcontinue(clustersIn,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,numProc,iSccSimEqMapping)
     1614    local
     1615      Integer size, numSfLocks;
     1616      array<Integer> taskAss;
     1617      array<list<Integer>> procAss;
     1618      list<Integer> order;
     1619      list<list<Integer>> clusters;
     1620      HpcOmSimCode.Schedule schedule;
     1621      array<list<HpcOmSimCode.Task>> threadTask;
     1622      list<HpcOmSimCode.Task> removeLocks;
     1623    case(_,_,_,_,_,_,_)
     1624      equation
     1625        // we need cluster duplication, repeat until numProc=num(clusters)
     1626        true = listLength(clustersIn) < numProc;
     1627        print("There are less initial clusters than processors. we need duplication, but since this is a rare case, it is not done. Less processors are used.\n");
     1628        clusters = List.map(clustersIn,listReverse);
     1629        Flags.setConfigInt(Flags.NUM_PROC,listLength(clustersIn));
     1630        schedule = createTDSschedule1(clusters,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,listLength(clustersIn),iSccSimEqMapping);
     1631      then
     1632        schedule;
     1633    case(_,_,_,_,_,_,_)
     1634      equation
     1635        // we need cluster compaction, repeat until numProc=num(clusters)
     1636        true = listLength(clustersIn) > numProc;
     1637        clusters = createTDSCompactClusters(clustersIn,iTaskGraph,iTaskGraphMeta,TDSLevel,numProc);
     1638        schedule = createTDSschedule1(clusters,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,numProc,iSccSimEqMapping);
     1639      then
     1640        schedule;
     1641    case(_,_,_,_,_,_,_)
     1642      equation
     1643        // the clusters can be scheduled, build assignments
     1644        true = listLength(clustersIn) == numProc;
     1645        clusters = List.map1(clustersIn,createTDSSortCompactClusters,TDSLevel);
     1646        //print("clusters:\n"+&stringDelimitList(List.map(clusters,intListString),"\n")+&"\n");
     1647        procAss = listArray(clusters);
     1648        size = arrayLength(iTaskGraph);
     1649        taskAss = arrayCreate(size,-1);
     1650        List.map2_0(List.intRange(arrayLength(procAss)),getTaskAssignmentTDS,procAss,taskAss);  // update the task assignments
     1651        (_,order) = quicksortWithOrder(arrayList(TDSLevel));
     1652        order = listReverse(order);
     1653        //create schedule from assignments
     1654        threadTask = arrayCreate(numProc,{});
     1655        schedule = HpcOmSimCode.THREADSCHEDULE(threadTask,{});
     1656        (schedule,removeLocks) = createScheduleFromAssignments(taskAss,procAss,SOME(order),iTaskGraph,iTaskGraphT,iTaskGraphMeta,iSccSimEqMapping,{},order,schedule);
     1657        // remove superfluous locks
     1658        numSfLocks = intDiv(listLength(removeLocks),2);
     1659        Debug.fcall(Flags.HPCOM_DUMP,print,"number of removed superfluous locks: "+&intString(numSfLocks)+&"\n");
     1660        schedule = traverseAndUpdateThreadsInSchedule(schedule,removeLocksFromThread,removeLocks);
     1661        schedule = updateLockIdcsInThreadschedule(schedule,removeLocksFromLockIds,removeLocks);
     1662      then
     1663        schedule;
     1664    else
     1665      equation
     1666        print("createTDSschedule1 failed!\n");
     1667      then fail();
     1668  end matchcontinue;
     1669end createTDSschedule1;
     1670
     1671protected function getTaskAssignmentTDS"sets the assigned processor for each task.
     1672author:Waurich TUD 2014-05"
     1673  input Integer procIdx;
     1674  input array<list<Integer>> clusterArrayIn;
     1675  input array<Integer> taskAssIn;
     1676protected
     1677  array<Integer> taskAss;
     1678  list<Integer> procTasks;
     1679algorithm
     1680  procTasks := arrayGet(clusterArrayIn,procIdx);
     1681  List.map2_0(procTasks,Util.arrayUpdateIndexFirst,procIdx,taskAssIn);
     1682end getTaskAssignmentTDS;
     1683
     1684protected function createTDSCompactClusters"performs compaction to the cluster set. the least crowded (lowest exe costs) cluster is marged with the crowded cluster and so on.
     1685author:Waurich TUD 2015-05"
     1686  input list<list<Integer>> clustersIn;
     1687  input HpcOmTaskGraph.TaskGraph iTaskGraph;
     1688  input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
     1689  input array<Real> TDSLevel;
     1690  input Integer numProc;
     1691  output list<list<Integer>> clustersOut;
     1692protected
     1693  Integer numMergeClusters;
     1694  list<Real> clusterExeCosts;
     1695  list<Integer> clusterOrder;
     1696  list<list<Integer>> firstClusters,lastClusters, middleCluster,clusters, mergedClusters;
     1697algorithm
     1698  clusterExeCosts := List.map1(clustersIn,createTDScomputeClusterCosts,iTaskGraphMeta);
     1699  (_,clusterOrder) := quicksortWithOrder(clusterExeCosts);
     1700  clusterOrder := listReverse(clusterOrder);
     1701  clusters := List.map1(clusterOrder,List.getIndexFirst,clustersIn);  // the clusters, sorted in descending order of their accumulated execution costs
     1702  numMergeClusters := intMin(intDiv(listLength(clustersIn),2),intSub(listLength(clustersIn),numProc));
     1703  (firstClusters,lastClusters) := List.split(clusters,numMergeClusters);
     1704  (middleCluster,lastClusters) := List.split(lastClusters,intSub(listLength(lastClusters),numMergeClusters));
     1705  lastClusters := listReverse(lastClusters);
     1706  mergedClusters := List.threadMap(firstClusters,lastClusters,listAppend);
     1707  clustersOut := listAppend(mergedClusters,middleCluster);
     1708  //print("mergedClustersOut:\n"+&stringDelimitList(List.map(clustersOut,intListString),"\n")+&"\n");
     1709end createTDSCompactClusters;
     1710
     1711protected function createTDSSortCompactClusters"sorts the tasks in the cluster to descending order of their tds level value.
     1712author:Waurich TUD 2014-05"
     1713  input list<Integer> clusterIn;
     1714  input array<Real> tdsLevelIn;
     1715  output list<Integer> clusterOut;
     1716protected
     1717  list<Integer> order;
     1718  list<Real> tdsLevels;
     1719algorithm
     1720  tdsLevels := List.map1(clusterIn,Util.arrayGetIndexFirst,tdsLevelIn);
     1721  (_,order) := quicksortWithOrder(tdsLevels);
     1722  order := listReverse(order);
     1723  clusterOut :=List.map1(order,List.getIndexFirst,clusterIn);
     1724end createTDSSortCompactClusters;
     1725
     1726protected function createTDScomputeClusterCosts"accumulates the execution costs of all tasks in one cluster.
     1727author:Waurich TUD 2014-05"
     1728  input list<Integer> clusters;
     1729  input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
     1730  output Real costs;
     1731protected
     1732  list<Real> nodeCosts;
     1733algorithm
     1734  nodeCosts := List.map1(clusters,HpcOmTaskGraph.getExeCostReqCycles,iTaskGraphMeta);
     1735  costs := List.fold(nodeCosts,realAdd,0.0);
     1736end createTDScomputeClusterCosts;
    16121737
    16131738protected function createTDSInitialCluster"creates the initial Clusters for the task duplication scheduler.
     
    16481773    case(_,_,_,_,_,_,{},_)
    16491774      equation
    1650         clusters = List.map(clustersIn,listReverse);
     1775        clusters = List.filterOnTrue(clustersIn,List.isNotEmpty);
     1776        clusters = List.map(clusters,listReverse);
    16511777      then clusters;
    16521778    case(_,_,_,_,_,_,front::rest,_)
  • Compiler/BackEnd/HpcOmSimCodeMain.mo

    r233bf0b8 rdf8a9a37  
    250250      (numProc,numFixed) = setNumProc(numProc,cpCostsWoC,taskGraphDataOde);
    251251      schedule = createSchedule(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,numProc);
     252      numProc = Flags.getConfigInt(Flags.NUM_PROC);
    252253      (schedule,numProc) = repeatScheduleWithOtherNumProc(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,cpCostsWoC,schedule,numProc,numFixed);
    253254      criticalPathInfo = HpcOmScheduler.analyseScheduledTaskGraph(schedule,numProc,taskGraph1,taskGraphData1);
Note: See TracChangeset for help on using the changeset viewer.