コード例 #1
0
ファイル: Network.cs プロジェクト: rachmadvwp/NOCulator
        public virtual void setup()
        {
            routers = new Router[Config.N];
            nodes   = new Node[Config.N];
            links   = new List <Link>();
            cache   = new CmpCache();

            endOfTraceBarrier = new bool[Config.N];
            canRewind         = false;

            ParseFinish(Config.finish);

            workload = new Workload(Config.traceFilenames);

            mapping = new NodeMapping_AllCPU_SharedCache();

            // create routers and nodes
            for (int n = 0; n < Config.N; n++)
            {
                Coord c = new Coord(n);
                nodes[n]   = new Node(mapping, c);
                routers[n] = MakeRouter(c);
                nodes[n].setRouter(routers[n]);
                routers[n].setNode(nodes[n]);
                endOfTraceBarrier[n] = false;
            }

            // create the Golden manager
            golden = new Golden();

            if (Config.RouterEvaluation)
            {
                return;
            }

            // connect the network with Links
            for (int n = 0; n < Config.N; n++)
            {
                int x, y;
                Coord.getXYfromID(n, out x, out y);

                // inter-router links
                for (int dir = 0; dir < 4; dir++)
                {
                    int oppDir = (dir + 2) % 4; // direction from neighbor's perspective

                    // determine neighbor's coordinates
                    int x_, y_;
                    switch (dir)
                    {
                    case Simulator.DIR_UP: x_ = x; y_ = y + 1; break;

                    case Simulator.DIR_DOWN: x_ = x; y_ = y - 1; break;

                    case Simulator.DIR_RIGHT: x_ = x + 1; y_ = y; break;

                    case Simulator.DIR_LEFT: x_ = x - 1; y_ = y; break;

                    default: continue;
                    }

                    // If we are a torus, we manipulate x_ and y_
                    if (Config.torus)
                    {
                        if (x_ < 0)
                        {
                            x_ += X;
                        }
                        else if (x_ >= X)
                        {
                            x_ -= X;
                        }

                        if (y_ < 0)
                        {
                            y_ += Y;
                        }
                        else if (y_ >= Y)
                        {
                            y_ -= Y;
                        }
                    }
                    // mesh, not torus: detect edge
                    else if (x_ < 0 || x_ >= X || y_ < 0 || y_ >= Y)
                    {
                        if (Config.edge_loop)
                        {
                            Link edgeL = new Link(Config.router.linkLatency - 1);
                            links.Add(edgeL);

                            routers[Coord.getIDfromXY(x, y)].linkOut[dir] = edgeL;
                            routers[Coord.getIDfromXY(x, y)].linkIn[dir]  = edgeL;
                            routers[Coord.getIDfromXY(x, y)].neighbors++;
                            routers[Coord.getIDfromXY(x, y)].neigh[dir] =
                                routers[Coord.getIDfromXY(x, y)];
                        }

                        continue;
                    }

                    // ensure no duplication by handling a link at the lexicographically
                    // first router
                    if (x_ < x || (x_ == x && y_ < y))
                    {
                        continue;
                    }

                    // Link param is *extra* latency (over the standard 1 cycle)
                    Link dirA = new Link(Config.router.linkLatency - 1);
                    Link dirB = new Link(Config.router.linkLatency - 1);
                    links.Add(dirA);
                    links.Add(dirB);

                    // link 'em up
                    routers[Coord.getIDfromXY(x, y)].linkOut[dir]     = dirA;
                    routers[Coord.getIDfromXY(x_, y_)].linkIn[oppDir] = dirA;

                    routers[Coord.getIDfromXY(x, y)].linkIn[dir]       = dirB;
                    routers[Coord.getIDfromXY(x_, y_)].linkOut[oppDir] = dirB;

                    routers[Coord.getIDfromXY(x, y)].neighbors++;
                    routers[Coord.getIDfromXY(x_, y_)].neighbors++;

                    routers[Coord.getIDfromXY(x, y)].neigh[dir]      = routers[Coord.getIDfromXY(x_, y_)];
                    routers[Coord.getIDfromXY(x_, y_)].neigh[oppDir] = routers[Coord.getIDfromXY(x, y)];

                    if (Config.router.algorithm == RouterAlgorithm.DR_SCARAB)
                    {
                        for (int wireNr = 0; wireNr < Config.nack_nr; wireNr++)
                        {
                            Link nackA = new Link(Config.nack_linkLatency - 1);
                            Link nackB = new Link(Config.nack_linkLatency - 1);
                            links.Add(nackA);
                            links.Add(nackB);
                            ((Router_SCARAB)routers[Coord.getIDfromXY(x, y)]).nackOut[dir * Config.nack_nr + wireNr]     = nackA;
                            ((Router_SCARAB)routers[Coord.getIDfromXY(x_, y_)]).nackIn[oppDir * Config.nack_nr + wireNr] = nackA;

                            ((Router_SCARAB)routers[Coord.getIDfromXY(x, y)]).nackIn[dir * Config.nack_nr + wireNr]       = nackB;
                            ((Router_SCARAB)routers[Coord.getIDfromXY(x_, y_)]).nackOut[oppDir * Config.nack_nr + wireNr] = nackB;
                        }
                    }
                }
            }

            if (Config.torus)
            {
                for (int i = 0; i < Config.N; i++)
                {
                    if (routers[i].neighbors < 4)
                    {
                        throw new Exception("torus construction not successful!");
                    }
                }
            }
        }
コード例 #2
0
        public override int mapCache(int node, ulong block)
        {
            int cx, cy;

            Coord.getXYfromID(node, out cx, out cy);

            if (Config.overlapping_squares != -1)
            {
                // stripe based on block
                int stripe = (int)(block % (ulong)(Config.overlapping_squares * Config.overlapping_squares));

                int nx = cx - Config.overlapping_squares / 2 + (stripe % Config.overlapping_squares),
                    ny = cy - Config.overlapping_squares / 2 + (stripe / Config.overlapping_squares);

                if (nx < 0)
                {
                    nx = -nx;
                }
                if (nx >= Config.network_nrX)
                {
                    nx = Config.network_nrX - nx;
                }
                if (ny < 0)
                {
                    ny = -ny;
                }
                if (ny >= Config.network_nrY)
                {
                    ny = Config.network_nrY - ny;
                }

                return(Coord.getIDfromXY(nx, ny));
            }

            if (Config.neighborhood_locality != -1)
            {
                // get top-left corner of neighborhood
                int neigh_x = cx - (cx % Config.neighborhood_locality), neigh_y = cy - (cy % Config.neighborhood_locality);

                // stripe based on block
                int stripe = (int)(block % (ulong)(Config.neighborhood_locality * Config.neighborhood_locality));

                int nx = neigh_x + (stripe % Config.neighborhood_locality);
                int ny = neigh_y + (stripe / Config.neighborhood_locality);

                return(Coord.getIDfromXY(nx, ny));
            }

            double dist = 0;

            if (Config.bounded_locality != -1)
            {
                dist = Math.Ceiling(Simulator.rand.NextDouble() * Config.bounded_locality);
            }
            else
            {
                // simple exponential with lambda either Config.simplemap_lambda or per-node lambda from Config.lambdas
                // quantile function is F(lambda,p) = -ln(1-p) / lambda
                dist = -Math.Log(1 - Simulator.rand.NextDouble()) / lambdas[node];
            }

            double angle = 2 * Math.PI * Simulator.rand.NextDouble();

            double x = dist * Math.Cos(angle);
            double y = dist * Math.Sin(angle);

            if (Config.torus)
            {
                if (x >= Config.network_nrX / 2)
                {
                    x = Config.network_nrX / 2;
                }
                if (x <= -Config.network_nrX / 2)
                {
                    x = -Config.network_nrX / 2;
                }
                if (y >= Config.network_nrY / 2)
                {
                    y = Config.network_nrY / 2;
                }
                if (y <= -Config.network_nrY / 2)
                {
                    y = -Config.network_nrY / 2;
                }
                cx = (int)(cx + x);
                cy = (int)(cy + y);
                if (cx < 0)
                {
                    cx += Config.network_nrX;
                }
                if (cx >= Config.network_nrX)
                {
                    cx -= Config.network_nrX;
                }
                if (cy < 0)
                {
                    cy += Config.network_nrY;
                }
                if (cy >= Config.network_nrY)
                {
                    cy -= Config.network_nrY;
                }
                return(Coord.getIDfromXY(cx, cy));
            }
            else
            {
                if ((int)(cx + x) >= Config.network_nrX)
                {
                    x = -x;
                }
                if ((int)(cx + x) < 0)
                {
                    x = -x;
                }
                if ((int)(cy + y) >= Config.network_nrY)
                {
                    y = -y;
                }
                if ((int)(cy + y) < 0)
                {
                    y = -y;
                }
                cx = (int)(cx + x);
                cy = (int)(cy + y);
                if (cx < 0)
                {
                    cx = 0;
                }
                if (cx >= Config.network_nrX)
                {
                    cx = Config.network_nrX - 1;
                }
                if (cy < 0)
                {
                    cy = 0;
                }
                if (cy >= Config.network_nrY)
                {
                    cy = Config.network_nrY - 1;
                }
                return(Coord.getIDfromXY(cx, cy));
            }
        }
コード例 #3
0
ファイル: Network.cs プロジェクト: hirous/test
        public void ftflySetup()
        {
            if (Config.router.algorithm != RouterAlgorithm.DR_FLIT_SWITCHED_OLDEST_FIRST &&
                Config.router.algorithm != RouterAlgorithm.DR_AFC &&
                Config.router.algorithm != RouterAlgorithm.DR_FLIT_SWITCHED_CALF)
            {
                throw new Exception(String.Format("Flattened butteryfly network does not support {0}", Config.router.algorithm));
            }

            routers = new Router[Config.N];
            nodes   = new Node[Config.N];
            links   = new List <Link>();
            cache   = new CmpCache();

            ParseFinish(Config.finish);

            workload = new Workload(Config.traceFilenames);

            mapping = new NodeMapping_AllCPU_SharedCache();

            // create routers and nodes
            for (int n = 0; n < Config.N; n++)
            {
                Coord c = new Coord(n);
                nodes[n]   = new Node(mapping, c);
                routers[n] = MakeRouter(c);
                nodes[n].setRouter(routers[n]);
                routers[n].setNode(nodes[n]);
            }

            // create the Golden manager
            golden = new Golden();

            if (Config.RouterEvaluation)
            {
                return;
            }

            // connect the network with Links
            for (int n = 0; n < Config.N; n++)
            {
                int x, y;
                Coord.getXYfromID(n, out x, out y);
#if DEBUG
                Console.WriteLine("NETWORK SETUP: coord ({0},{1}) ID {2}", x, y, n);
#endif
                // inter-router links
                for (int dir = 0; dir < 8; dir++)
                {
                    //if same coordinates
                    if (dir == x)
                    {
                        continue;
                    }
                    if (dir >= 4 && dir % 4 == y)
                    {
                        continue;
                    }

                    int oppDir = (dir < 4)?(x):(4 + y);// direction from neighbor's perspective

                    // determine neighbor's coordinates
                    int x_, y_;
                    switch (dir)
                    {
                    case Simulator.DIR_Y_0: x_ = x; y_ = 0; break;

                    case Simulator.DIR_Y_1: x_ = x; y_ = 1; break;

                    case Simulator.DIR_Y_2: x_ = x; y_ = 2; break;

                    case Simulator.DIR_Y_3: x_ = x; y_ = 3; break;

                    case Simulator.DIR_X_0: x_ = 0; y_ = y; break;

                    case Simulator.DIR_X_1: x_ = 1; y_ = y; break;

                    case Simulator.DIR_X_2: x_ = 2; y_ = y; break;

                    case Simulator.DIR_X_3: x_ = 3; y_ = y; break;

                    default: continue;
                    }
                    // mesh, not torus: detect edge
                    // This part is for torus setup
                    if (x_ < 0 || x_ >= X || y_ < 0 || y_ >= Y)
                    {
                        if (Config.edge_loop)
                        {
                            Link edgeL = new Link(Config.router.linkLatency - 1, n, dir);
                            links.Add(edgeL);

                            routers[Coord.getIDfromXY(x, y)].linkOut[dir] = edgeL;
                            routers[Coord.getIDfromXY(x, y)].linkIn[dir]  = edgeL;
                            routers[Coord.getIDfromXY(x, y)].neighbors++;
                            throw new Exception("FTFLY shouldn't hit a torus network setup(edge_loop=true).");
                        }

                        continue;
                    }

                    // ensure no duplication by handling a link at the lexicographically
                    // first router
                    // for flattened butterfly, it's fine cuz it's going to overwrite it
                    if (x_ < x || (x_ == x && y_ < y))
                    {
                        continue;
                    }

                    //Console.WriteLine("dst ({0},{1})",x_,y_);

                    /* The setup is row wise going upward */
                    int link_lat = Config.router.linkLatency - 1;

                    // Extra latency to links that have longer hops.
                    if (Math.Abs(x - x_) > 1)
                    {
                        link_lat += Math.Abs(x - x_);
                    }
                    if (Math.Abs(y - y_) > 1)
                    {
                        link_lat += Math.Abs(y - y_);
                    }

                    // an extra cycle on router b/c of higher radix routers
                    // for bless. However, this extra cycle is modeled in
                    // chipper by having a larger sorting network.
                    if (Config.router.algorithm != RouterAlgorithm.DR_FLIT_SWITCHED_CALF)
                    {
                        link_lat++;
                    }

                    Link dirA = new Link(link_lat, n, dir);
                    Link dirB = new Link(link_lat, n, dir);
                    links.Add(dirA);
                    links.Add(dirB);

                    // link 'em up
                    routers[Coord.getIDfromXY(x, y)].linkOut[dir]     = dirA;
                    routers[Coord.getIDfromXY(x_, y_)].linkIn[oppDir] = dirA;

                    routers[Coord.getIDfromXY(x, y)].linkIn[dir]       = dirB;
                    routers[Coord.getIDfromXY(x_, y_)].linkOut[oppDir] = dirB;

                    routers[Coord.getIDfromXY(x, y)].neighbors++;
                    routers[Coord.getIDfromXY(x_, y_)].neighbors++;

                    routers[Coord.getIDfromXY(x, y)].neigh[dir]      = routers[Coord.getIDfromXY(x_, y_)];
                    routers[Coord.getIDfromXY(x_, y_)].neigh[oppDir] = routers[Coord.getIDfromXY(x, y)];

                    // DONE CARE for ftfly
                    if (Config.router.algorithm == RouterAlgorithm.DR_SCARAB)
                    {
                        for (int wireNr = 0; wireNr < Config.nack_nr; wireNr++)
                        {
                            Link nackA = new Link(Config.nack_linkLatency - 1, n, dir);
                            Link nackB = new Link(Config.nack_linkLatency - 1, n, dir);
                            links.Add(nackA);
                            links.Add(nackB);
                            ((Router_SCARAB)routers[Coord.getIDfromXY(x, y)]).nackOut[dir * Config.nack_nr + wireNr]     = nackA;
                            ((Router_SCARAB)routers[Coord.getIDfromXY(x_, y_)]).nackIn[oppDir * Config.nack_nr + wireNr] = nackA;

                            ((Router_SCARAB)routers[Coord.getIDfromXY(x, y)]).nackIn[dir * Config.nack_nr + wireNr]       = nackB;
                            ((Router_SCARAB)routers[Coord.getIDfromXY(x_, y_)]).nackOut[oppDir * Config.nack_nr + wireNr] = nackB;
                        }
                    }
                }
            }
            for (int n = 0; n < Config.N; n++)
            {
                int x, y;
                Coord.getXYfromID(n, out x, out y);
                //Console.WriteLine("router {0}-({1},{2}):{3}",n,x,y,routers[n].neighbors);
            }
        }