// Copyright (c) 2009-2013, Tor M. Aamodt, Dongdong Li, Ali Bakhoda // The University of British Columbia // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // Redistributions in binary form must reproduce the above copyright notice, this // list of conditions and the following disclaimer in the documentation and/or // other materials provided with the distribution. // Neither the name of The University of British Columbia nor the names of its // contributors may be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include #include #include #include #include #include "local_interconnect.h" #include "mem_fetch.h" xbar_router::xbar_router(unsigned router_id, unsigned n_shader, unsigned n_mem, unsigned m_in_buffer_limit, unsigned m_out_buffer_limit) { m_id=router_id; _n_mem = n_mem; _n_shader = n_shader; total_nodes = n_shader+n_mem; in_buffers.resize(total_nodes); out_buffers.resize(total_nodes); next_node=0; in_buffer_limit = m_in_buffer_limit; out_buffer_limit = m_out_buffer_limit; cycles = 0; conflicts= 0; out_buffer_full=0; packets_num=0; } xbar_router::~xbar_router() { } void xbar_router::Push(unsigned input_deviceID, unsigned output_deviceID, void* data, unsigned int size) { assert(input_deviceID < total_nodes); in_buffers[input_deviceID].push(Packet(data, output_deviceID)); packets_num++; } void* xbar_router::Pop(unsigned ouput_deviceID) { assert(ouput_deviceID < total_nodes); void* data = NULL; if(!out_buffers[ouput_deviceID].empty()) { data = out_buffers[ouput_deviceID].front().data; out_buffers[ouput_deviceID].pop(); } return data; } bool xbar_router::Has_Buffer_In(unsigned input_deviceID, unsigned size) const{ assert(input_deviceID < total_nodes); return (in_buffers[input_deviceID].size() + size <= in_buffer_limit); } bool xbar_router::Has_Buffer_Out(unsigned output_deviceID, unsigned size) const{ return (out_buffers[output_deviceID].size() + size <= out_buffer_limit); } void xbar_router::Advance() { cycles++; vector issued(total_nodes, false); for(unsigned i=0; iHas_Buffer_In(input_deviceID, 1)); net[subnet]->Push(input_deviceID, output_deviceID, data, size); } void* LocalInterconnect::Pop(unsigned ouput_deviceID){ // 0-_n_shader-1 indicates reply(network 1), otherwise request(network 0) int subnet = 0; if (ouput_deviceID < n_shader) subnet = 1; return net[subnet]->Pop(ouput_deviceID); } void LocalInterconnect::Advance(){ for (unsigned i = 0; i < n_subnets; ++i) { net[i]->Advance(); } } bool LocalInterconnect::Busy() const{ for (unsigned i = 0; i < n_subnets; ++i) { if(net[i]->Busy()) return true; } return false; } bool LocalInterconnect::HasBuffer(unsigned deviceID, unsigned int size) const{ bool has_buffer = false; has_buffer = net[0]->Has_Buffer_In(deviceID, size); if ((n_subnets>1) && deviceID >= n_shader) // deviceID is memory node has_buffer = net[1]->Has_Buffer_In(deviceID, size); return has_buffer; } void LocalInterconnect::DisplayStats() const{ cout<<"Req_Network_injected_packets_num = "<packets_num<