2010年8月29日 星期日

NetWork on Chip @c

在Bus Architecture 架構下, 有"Bus Matrix", "Share Bus","Net-Work on Chip Bus", 其中以 Share Bus 跟 Net-Work on chip 為主流架構. Share Bus 代表的有 ARM(AMBA), IBM(CoreConnect)...,而Net-Work on chip感覺目前還沒有業界support,一般還是在學術界比較普遍. 當然隨著進入多Cores 的世代 Net-Work on Chip 相對的就更有研究價值. Net-Work on Chip Advantages: 1. Faults recover 解決 Net Work Faults 的問題. 透過周圍有效的 Net 來做communication 如果用 Share Bus 的架構, Fault 會把 Bus 上的 Data tied住, 導致在這條Bus上的傳輸都會有問題. 2.Bandwidth/Performance enhancement利用不同的Nets 來減少 Bus Access dead Lock 時所造成的 latency , 如果是 Share Bus上,要等到Transfer完成 ,Bus usage 被 Release, 才能做下次傳輸.但 Net-Work on chips 可透過周圍有效的Nets 來彌補這個問題. 3. Power enhancement 透過Power Cluster 來動態調整每個 Net-Works 的Status. Disadvantages:1. HW cost 硬體設計的複雜度, 跟 Arbiter 數目 2. Utility 可能有些的Net-Works使用率不高,則有些使用率高. 為了避免dead lock, 如所以每個Node在決定下個Node前.要先判斷Direction是否離 End Node 愈來愈近. 如果沒有就找下個 Node.


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <list>

using namespace std;

#define MAX_NET_NODE 12 
#define BEGIN_NODE 0 
#define END_NODE 3

enum NETSTATUS{
 NET_NXT_OK =0,
 NET_NXT_FAL =1,
 NET_TRACE_OK =2,
 NET_TRACE_FAL =3,
};

struct NetPath {
 int Id;
 int Weight;    //delay
} NetPath;

struct NeNode {
 int x;
 int y;
 int s;
        struct  NetPath  NetPath[MAX_NET_NODE];
}NetNode[MAX_NET_NODE];


 
void SetInitNetNodeTable(){
 // Net_0 set
 NetNode[0].x=0;
 NetNode[0].y=0; 
 NetNode[0].NetPath[0].Id     =1; NetNode[0].NetPath[0].Weight =3; 
        NetNode[0].NetPath[1].Id     =4; NetNode[0].NetPath[1].Weight =5;
  NetNode[0].s=2;
 // Net_1 set
 NetNode[1].x=0;
 NetNode[1].y=1; 
 NetNode[1].NetPath[0].Id     =0; NetNode[1].NetPath[0].Weight =5;
 NetNode[1].NetPath[1].Id     =2; NetNode[1].NetPath[1].Weight =5;
 NetNode[1].NetPath[2].Id     =5; NetNode[1].NetPath[2].Weight =5;
  NetNode[1].s=3;
 // Net_2 set
 NetNode[2].x=0;
 NetNode[2].y=2; 
 NetNode[2].NetPath[0].Id     =1; NetNode[2].NetPath[0].Weight =7;
 NetNode[2].NetPath[1].Id     =3; NetNode[2].NetPath[1].Weight =5;
 NetNode[2].NetPath[2].Id     =6; NetNode[2].NetPath[2].Weight =5;
 NetNode[2].s=3;
 // Net_3 set
 NetNode[3].x=0;
 NetNode[3].y=3; 
 NetNode[3].NetPath[0].Id     =2; NetNode[3].NetPath[0].Weight =4;
 NetNode[3].NetPath[1].Id     =7; NetNode[3].NetPath[1].Weight =3;
 NetNode[3].s=2;
 // Net_4 set
 NetNode[4].x=1;
 NetNode[4].y=0; 
 NetNode[4].NetPath[0].Id     =0; NetNode[4].NetPath[0].Weight =3;
 NetNode[4].NetPath[1].Id     =5; NetNode[4].NetPath[0].Weight =3;
 NetNode[4].NetPath[2].Id     =8; NetNode[4].NetPath[1].Weight =9;
 NetNode[4].s=3;
 // Net_5 set
 NetNode[5].x=1;
 NetNode[5].y=1; 
 NetNode[5].NetPath[0].Id     =1; NetNode[5].NetPath[0].Weight =5;
 NetNode[5].NetPath[1].Id     =4; NetNode[5].NetPath[1].Weight =6;
 NetNode[5].NetPath[2].Id     =6; NetNode[5].NetPath[2].Weight =8;
 NetNode[5].NetPath[3].Id     =9; NetNode[5].NetPath[3].Weight =4;
 NetNode[5].s=4;
 // Net_6 set
 NetNode[6].x=1;
 NetNode[6].y=2; 
 NetNode[6].NetPath[0].Id     =2; NetNode[6].NetPath[0].Weight =5;
 NetNode[6].NetPath[1].Id     =5; NetNode[6].NetPath[1].Weight =5;
 NetNode[6].NetPath[2].Id     =7; NetNode[6].NetPath[2].Weight =5;
 NetNode[6].NetPath[3].Id     =10; NetNode[6].NetPath[3].Weight =5;
 NetNode[6].s=4;
 // Net_7 set
 NetNode[7].x=1;
 NetNode[7].y=3; 
 NetNode[7].NetPath[0].Id     =3; NetNode[7].NetPath[0].Weight =4;
 NetNode[7].NetPath[1].Id     =6; NetNode[7].NetPath[1].Weight =4;
 NetNode[7].NetPath[2].Id     =11; NetNode[7].NetPath[2].Weight =4;
 NetNode[7].s=3;
 // Net_8 set
 NetNode[8].x=2;
 NetNode[8].y=0; 
 NetNode[8].NetPath[0].Id     =4; NetNode[8].NetPath[0].Weight =5;
 NetNode[8].NetPath[1].Id     =9; NetNode[8].NetPath[1].Weight =4;
 NetNode[8].s=2;
 // Net_9 set
 NetNode[9].x=2;
 NetNode[9].y=1; 
 NetNode[9].NetPath[0].Id     =5; NetNode[9].NetPath[0].Weight =5;
 NetNode[9].NetPath[1].Id     =8; NetNode[9].NetPath[1].Weight =7;
 NetNode[9].NetPath[2].Id     =10; NetNode[9].NetPath[2].Weight =6;
 NetNode[9].s=3;
 // Net_10 set
 NetNode[10].x=2;
 NetNode[10].y=2; 
 NetNode[10].NetPath[0].Id     =6; NetNode[10].NetPath[0].Weight =7;
 NetNode[10].NetPath[1].Id     =9; NetNode[10].NetPath[1].Weight =7;
 NetNode[10].NetPath[2].Id     =11; NetNode[10].NetPath[2].Weight =7;
 NetNode[10].s=3;
 // Net_11 set
 NetNode[11].x=2;
 NetNode[11].y=3; 
 NetNode[11].NetPath[0].Id     =6; NetNode[10].NetPath[0].Weight =7;
 NetNode[11].NetPath[1].Id     =11; NetNode[10].NetPath[1].Weight =7;
 NetNode[11].s=2;
}

int FindNodeId2xy(int id, int *x, int *y){
     switch(id){
       case 0 : *x = 0; *y=0; return NET_TRACE_OK;  break;
       case 1 : *x = 0; *y=1; return NET_TRACE_OK;  break;
       case 2 : *x = 0; *y=2; return NET_TRACE_OK;  break;
       case 3 : *x = 0; *y=3; return NET_TRACE_OK;  break;
       case 4 : *x = 1; *y=0; return NET_TRACE_OK;  break;
       case 5 : *x = 1; *y=1; return NET_TRACE_OK;  break;
       case 6 : *x = 1; *y=2; return NET_TRACE_OK;  break;
       case 7 : *x = 1; *y=3; return NET_TRACE_OK;  break;
       case 8 : *x = 2; *y=0; return NET_TRACE_OK;  break;
       case 9 : *x = 2; *y=1; return NET_TRACE_OK;  break;
       case 10: *x = 2; *y=2; return NET_TRACE_OK;  break;
       case 11: *x = 2; *y=3; return NET_TRACE_OK;  break;
       default:               return NET_TRACE_FAL; break;
   }
}

int xPathCot;
int yPathCot;
list<int> vistlist;

int FindNxtNode(int begin, int end, int xpath, int ypath){
   int i;
   int id;
   int bx,by;
   int tx,ty;
   int ixpath=xpath,iypath=ypath;
   
vistlist.push_back(begin);

 if( begin==end ){  
     for(list<int>::iterator it=vistlist.begin(); it!=vistlist.end(); it++){ cout<<*it<<","; } cout<<endl; 
      vistlist.pop_back();
      return 0; 
} 

 if( FindNodeId2xy(begin, &bx, &by) == NET_TRACE_FAL ){ return -1;} 

    for(i=0; i<NetNode[begin].s; i++){
             id = NetNode[begin].NetPath[i].Id;
         if( FindNodeId2xy(id, &tx, &ty) == NET_TRACE_FAL ){ break; return -1;} 
                 tx -=bx;
                 ty -=by;

                  if( xpath >0 && tx>0 ){ /*printf("a,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/  FindNxtNode(id,end,ixpath-1,iypath); }
             else if( xpath <0 && tx<0 ){ /*printf("b,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/  FindNxtNode(id,end,ixpath+1,iypath); }
             else if( ypath >0 && ty>0 ){ /*printf("c,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/  FindNxtNode(id,end,ixpath  ,iypath-1); }
             else if( ypath <0 && ty<0 ){ /*printf("d,%d,%d,%d,%d\n",begin,id,ixpath,iypath);*/  FindNxtNode(id,end,ixpath  ,iypath+1); }
     }
vistlist.pop_back();
}


int main(int argc,char* argv[]){

SetInitNetNodeTable();

int Beginx,Beginy;
int Endx,Endy;

if( FindNodeId2xy(BEGIN_NODE,&Beginx,&Beginy)==NET_TRACE_FAL ){ printf("@ Begin Node 2 MapTable Error ...\n"); return -1; }
if( FindNodeId2xy(END_NODE,  &Endx,  &Endy  )==NET_TRACE_FAL ){ printf("@ End   Node 2 MapTable Error ...\n"); return -1; }

xPathCot = Endx-Beginx;
yPathCot = Endy-Beginy;

FindNxtNode(BEGIN_NODE,END_NODE,xPathCot,yPathCot);
return 0;
}
Refs: Network On Chip
Network-on-Chip @ Google group
有關 network on chip 的學術文章

沒有留言:

張貼留言