ProcessingElement.h
processing element模块
#ifndef __NOXIMPROCESSINGELEMENT_H__
#define __NOXIMPROCESSINGELEMENT_H__ #include <queue>
#include <systemc.h> #include "DataStructs.h"
#include "GlobalTrafficTable.h"
#include "Utils.h" using namespace std; SC_MODULE(ProcessingElement)
{
............................
};
#endif
// I/O Ports
sc_in_clk clock; // The input clock for the PE
sc_in < bool > reset; // The reset signal for the PE,清除信号 sc_in < Flit > flit_rx; // The input channel
sc_in < bool > req_rx; // The request associated with the input channel
sc_out < bool > ack_rx; // The outgoing ack signal associated with the input channel sc_out < Flit > flit_tx; // The output channel
sc_out < bool > req_tx; // The request associated with the output channel
sc_in < bool > ack_tx; // The outgoing ack signal associated with the output channel sc_in < int > free_slots_neighbor; //获取相邻Router中空闲VC的数目,类似credit?
// Registers
int local_id; // Unique identification number
bool current_level_rx; // Current level for Alternating Bit Protocol (ABP)交替位协议
bool current_level_tx; // Current level for Alternating Bit Protocol (ABP)
queue < Packet > packet_queue; // Local queue of packets
bool transmittedAtPreviousCycle; // Used for distributions with memory
ABP具有比特差错的丢包信道的可靠数据传输, 因为分组序号在0和1之间交替,因此有时被称为比特交替协议。
//Receiving and transmitting process
void rxProcess(); // The receiving process
void txProcess(); // The transmitting process
bool canShot(Packet & packet); // True when the packet must be shot
Flit nextFlit(); // Take the next flit of the current packet
//<-------receive packet
void ProcessingElement::rxProcess()
{
if (reset.read()) {//停止receive packet
ack_rx.write();//表示0已收到
current_level_rx = ;
}
else {//开始receive packet
if (req_rx.read() == - current_level_rx) {
Flit flit_tmp = flit_rx.read();
current_level_rx = - current_level_rx; // Negate the old value for Alternating Bit Protocol (ABP)
}
ack_rx.write(current_level_rx);
}
}
rxProcess()
//------->transmit packet
void ProcessingElement::txProcess()
{
if (reset.read()) {//停止transmit packet
req_tx.write();
current_level_tx = ;
transmittedAtPreviousCycle = false;
}
else {//开始transmit packet
Packet packet; if (canShot(packet)) {// True when the packet must be shot
packet_queue.push(packet);
transmittedAtPreviousCycle = true;// Used for distributions with memory
} else
transmittedAtPreviousCycle = false; if (ack_tx.read() == current_level_tx) {
if (!packet_queue.empty()) {
Flit flit = nextFlit(); // Generate a new flit
flit_tx->write(flit); // Send the generated flit
current_level_tx = - current_level_tx; // Negate the old value for Alternating Bit Protocol (ABP)
req_tx.write(current_level_tx);
}
}
}
}
txProcess()
bool ProcessingElement::canShot(Packet & packet)
{
#ifdef DEADLOCK_AVOIDANCE//条件编译
if (local_id % == )
return false;
#endif
bool shot;
double threshold; double now = sc_time_stamp().to_double() / GlobalParams::clock_period_ps; if (GlobalParams::traffic_distribution != TRAFFIC_TABLE_BASED) {
if (!transmittedAtPreviousCycle)
threshold = GlobalParams::packet_injection_rate;
else
threshold = GlobalParams::probability_of_retransmission; shot = (((double) rand()) / RAND_MAX < threshold);
if (shot) {
if (GlobalParams::traffic_distribution == TRAFFIC_RANDOM)
packet = trafficRandom();
else if (GlobalParams::traffic_distribution == TRAFFIC_TRANSPOSE1)
packet = trafficTranspose1();
else if (GlobalParams::traffic_distribution == TRAFFIC_TRANSPOSE2)
packet = trafficTranspose2();
else if (GlobalParams::traffic_distribution == TRAFFIC_BIT_REVERSAL)
packet = trafficBitReversal();
else if (GlobalParams::traffic_distribution == TRAFFIC_SHUFFLE)
packet = trafficShuffle();
else if (GlobalParams::traffic_distribution == TRAFFIC_BUTTERFLY)
packet = trafficButterfly();
else if (GlobalParams::traffic_distribution == TRAFFIC_LOCAL)
packet = trafficLocal();
else if (GlobalParams::traffic_distribution == TRAFFIC_ULOCAL)
packet = trafficULocal();
else
assert(false);//调用abort函数,结束程序执行
}
} else { // Table based communication traffic
if (never_transmit)
return false; bool use_pir = (transmittedAtPreviousCycle == false);
vector < pair < int, double > > dst_prob;
double threshold =
traffic_table->getCumulativePirPor(local_id, (int) now,
use_pir, dst_prob); double prob = (double) rand() / RAND_MAX;
shot = (prob < threshold);
if (shot) {
for (unsigned int i = ; i < dst_prob.size(); i++) {
if (prob < dst_prob[i].second) {
packet.make(local_id, dst_prob[i].first, now,
getRandomSize());
break;
}
}
}
}
return shot;
}
canShot(Packet & packet)
Flit ProcessingElement::nextFlit()
{
Flit flit;
Packet packet = packet_queue.front(); flit.src_id = packet.src_id;
flit.dst_id = packet.dst_id;
flit.timestamp = packet.timestamp;// Unix timestamp at packet generation
flit.sequence_no = packet.size - packet.flit_left;// The sequence number of the flit inside the packet
flit.sequence_length = packet.size;
flit.hop_no = ;// Current number of hops from source to destination
// flit.payload = DEFAULT_PAYLOAD; if (packet.size == packet.flit_left)
flit.flit_type = FLIT_TYPE_HEAD;
else if (packet.flit_left == )
flit.flit_type = FLIT_TYPE_TAIL;
else
flit.flit_type = FLIT_TYPE_BODY; packet_queue.front().flit_left--;
if (packet_queue.front().flit_left == )
packet_queue.pop(); return flit;
}
nextFlit()
//Traffic patterns
Packet trafficTest(); // used for testing traffic
Packet trafficRandom(); // Random destination distribution
Packet trafficTranspose1(); // Transpose 1 destination distribution
Packet trafficTranspose2(); // Transpose 2 destination distribution
Packet trafficBitReversal(); // Bit-reversal destination distribution
Packet trafficShuffle(); // Shuffle destination distribution
Packet trafficButterfly(); // Butterfly destination distribution
Packet trafficLocal(); // Random with locality
Packet trafficULocal(); // Random with locality
GlobalTrafficTable *traffic_table; // Reference to the Global traffic Table
bool never_transmit; // true if the PE does not transmit any packet
// (valid only for the table based traffic)
void fixRanges(const Coord, Coord &); // Fix the ranges of the destination
int randInt(int min, int max); // Extracts a random integer number between min and max
int getRandomSize(); // Returns a random size in flits for the packet
void setBit(int &x, int w, int v);
int getBit(int x, int w);
double log2ceil(double x); int roulett();
int findRandomDestination(int local_id,int hops);
int ProcessingElement::randInt(int min, int max)
{
//rand()返回一随机数值的范围在0至RAND_MAX 间
//rand() / (RAND_MAX + 1.0)产生一个概率
return min + (int) ((double) (max - min + ) * rand() / (RAND_MAX + 1.0));
}
randInt(int min, int max)
//Fix the ranges of the destination
void ProcessingElement::fixRanges(const Coord src, Coord & dst)
{
// Fix ranges
if (dst.x < )
dst.x = ;
if (dst.y < )
dst.y = ; if (dst.x >= GlobalParams::mesh_dim_x)
dst.x = GlobalParams::mesh_dim_x - ; if (dst.y >= GlobalParams::mesh_dim_y)
dst.y = GlobalParams::mesh_dim_y - ;
}
fixRanges(const Coord src, Coord & dst)
int ProcessingElement::getRandomSize()
{
return randInt(GlobalParams::min_packet_size, GlobalParams::max_packet_size);
}
getRandomSize()
//将x二进制倒数第w位设置为v
void ProcessingElement::setBit(int &x, int w, int v)
{
int mask = << w;//1左移w位 if (v == )
x = x | mask;//将x二进制中倒数第w位设置为1
else if (v == )
x = x & ~mask;//将x二进制中倒数第w位设置为0
else
assert(false);
}
setBit(int &x, int w, int v)
//获取x二进制倒数第w位
int ProcessingElement::getBit(int x, int w)
{
return (x >> w) & ;
}
getBit(int x, int w)
//返回大于或者等于log_x(2)的最小整数
inline double ProcessingElement::log2ceil(double x)
{
return ceil(log(x) / log(2.0));
}
log2ceil(double x)
// Constructor
SC_CTOR(ProcessingElement) {
SC_METHOD(rxProcess);//描述组合逻辑,由输入信号的变化触发
sensitive << reset;
sensitive << clock.pos();//clock.pos()表示在时钟上升沿触发,反之使用neg() SC_METHOD(txProcess);
sensitive << reset;//只要reset和clock.pos()的值发生变化, 进程txProcess就完整执行一遍
sensitive << clock.pos();
}
ProcessingElement.h的更多相关文章
- Noxim Overview
PE+Router= Tile Node Architectural Elements: Buffer.h, Router.h, LocalRoutingTable.h, Tile.h, NoC.h, ...
- APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试
此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...
- 关于apue.3e中apue.h的使用
关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...
- YYModel 源码解读(二)之NSObject+YYModel.h (1)
本篇文章主要介绍 _YYModelPropertyMeta 前边的内容 首先先解释一下前边的辅助函数和枚举变量,在写一个功能的时候,这些辅助的东西可能不是一开始就能想出来的,应该是在后续的编码过程中 ...
- YYModel 源码解读(一)之YYModel.h
#if __has_include(<YYModel/YYModel.h>) FOUNDATION_EXPORT double YYModelVersionNumber; FOUNDATI ...
- error RC1015: cannot open include file 'afxres.h' 解决办法
在为WindowsPhone8程序添加本地化的过程中遇到这个问题: 问题原因就是afxres.h文件缺失,下载它,放到VS安装目录下的VS\include目录下就可以了(选择目录的时候注意对应对版本) ...
- afxcomctl32.h与afxcomctl32.inl报错
afxcomctl32.h与afxcomctl32.inl报错 编译公司一个几年前的老项目,是从VC6.0升级到VS2005的. 1.编译时报缺少头文件,于是附件包含目录,于是出现了以下报错: 1&g ...
- C标准头文件<math.h>
定义域错误可以理解为超出了函数的适用范围,如果发生了定义域错误,设errno为EDOM 如果结果不能表示为double值,则发生值域错误,如果结果上溢,则函数返回HUGE_VAL的值,设errno为E ...
- C标准头文件<ctype.h>
主要包括了一些字符识别和转换函数 字符判断 isalnum() //函数原型 #include<ctype.h> int isalum(int c); 功能:如果输入的字符是字母(alph ...
随机推荐
- cookies,sessionstorage,localstorage的区别?
请描述一下 cookies,sessionStorage 和 localStorage 的区别? sessionStorage 和 localStorage 是HTML5 Web Storage AP ...
- Java_监听器监听文件夹变动
package demo4; import java.io.IOException;import java.nio.file.FileSystems;import java.nio.file.Path ...
- jquery如何阻止子元素继承父元素的事件(又称事件冒泡)
非常简单,子元素上添加如下代码即可 $('a').click(function(e){ e.stopPropagation(); }); 老版本为event,现在用e就行
- 代码详解:TensorFlow Core带你探索深度神经网络“黑匣子”
来源商业新知网,原标题:代码详解:TensorFlow Core带你探索深度神经网络“黑匣子” 想学TensorFlow?先从低阶API开始吧~某种程度而言,它能够帮助我们更好地理解Tensorflo ...
- 【转】未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
“/xxxxx”应用程序中的服务器错误. ------------------------------------------------------------------------------- ...
- day 09
内存管理 引用计数:垃圾回收机制的依据 当变量的值被引用的时,变量值的引用计数+1,当变量名被解除绑定时该值的引用计数减少一. 当引用计数变成0的时候会被垃圾回收机制回收. 引用计数会出现循环引用问题 ...
- step_by_step_Angularjs-UI-Grid使用简介
了解 Angularjs UI-Grid 起因:项目需要一个可以固定列和表头的表格,因为表格要显示很多列,当水平滚动条拉至后边时可能无法看到前边的某些信息. 以前在angularjs 1.x 中一直都 ...
- linux搭建
1.安装rpm包 [root@lixiaojie lixiaojie]# rpm -ivh openfire-3.9.3-1.i386.rpm Preparing... ############### ...
- java第三章多态
多态: 多态不仅可以减少代码量,还可以提高代码的扩展和可维护性 (通过一个方法可以对所有所需方法一个运用)多态具体表现多种形态能力的特征,同一个实现接口使用不同实例而执行不同的操作 实现多态的三个条件 ...
- MMU二级页表
https://blog.csdn.net/forDreamYue/article/details/78887035