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 ...
随机推荐
- C#进阶系列——WebApi 跨域问题解决方案:CORS(转载)
C#进阶系列——WebApi 跨域问题解决方案:CORS 阅读目录 一.跨域问题的由来 二.跨域问题解决原理 三.跨域问题解决细节 1.场景描述 2.场景测试 四.总结 正文 前言:上篇总结了下W ...
- ArcGIS案例教程-通过点坐标生成圆
ArcGIS案例教程-通过点坐标生成圆 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 功能:以点坐标为中心,通过指定半径,生成圆 成果形式:绿色工具,免安装,不限版 ...
- 机器学习--Xgboost调参
Xgboost参数 'booster':'gbtree', 'objective': 'multi:softmax', 多分类的问题 'num_class':10, 类别数,与 multisoftma ...
- Charles篡改后台数据
1.打开Charles找到相对应的接口 2.在接口上右键选择Breakpoints打断点. 3.重新请求截断接口,Charles会多弹出一个截断窗口如下图(第一个修改请求的,第二图是修改返回的) 点击 ...
- 软件工程Ⅱ:Git的安装与使用
作业要求来自于https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 1.下载安装配置用户名和邮箱. (1) 安装Git软件. (2) ...
- airTest 使用体验
airTest是国内网易自研的一套基于图像识别进行UI自动化测试的框架,目前已经可以支持andriod,ios,web端的UI测试,在google开发者大会上得到了google的高度认可. 最近在学习 ...
- “菜”鸟理解.NET Framework(CLI,CLS,CTS,CLR,FCL,BCL)
既然要学.NET,就要先认识认识她,我不喜欢大段大段文字的东西,自己通过理解,画个图,来看看.NET的沉鱼落雁,闭月羞花之容. 最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基 ...
- Unity 3D 如何修改新建脚本中的 C# 默认创建的 Script 脚本格式
首先在Unity的安装路径下找到 Unity5\Editor\Data\Resources\ScriptTemplates路径的(81-C# Script-NewBehaviourScript.cs. ...
- Xcode9模拟器隐藏边框
选中模拟器,在Mac顶部菜单栏找到Window-->Show Device Bezeles 取消勾选代表去除黑边,勾选代表展示黑边,根据个人喜好设置吧
- 通过PHP调用微信JSSDK实例
JSSDK使用步骤: 1. 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 2. 采用http GET方式请求获得access_token(有效期7200秒). 3. ...