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的更多相关文章

  1. Noxim Overview

    PE+Router= Tile Node Architectural Elements: Buffer.h, Router.h, LocalRoutingTable.h, Tile.h, NoC.h, ...

  2. APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试

    此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...

  3. 关于apue.3e中apue.h的使用

    关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...

  4. YYModel 源码解读(二)之NSObject+YYModel.h (1)

    本篇文章主要介绍 _YYModelPropertyMeta 前边的内容 首先先解释一下前边的辅助函数和枚举变量,在写一个功能的时候,这些辅助的东西可能不是一开始就能想出来的,应该是在后续的编码过程中 ...

  5. YYModel 源码解读(一)之YYModel.h

    #if __has_include(<YYModel/YYModel.h>) FOUNDATION_EXPORT double YYModelVersionNumber; FOUNDATI ...

  6. error RC1015: cannot open include file 'afxres.h' 解决办法

    在为WindowsPhone8程序添加本地化的过程中遇到这个问题: 问题原因就是afxres.h文件缺失,下载它,放到VS安装目录下的VS\include目录下就可以了(选择目录的时候注意对应对版本) ...

  7. afxcomctl32.h与afxcomctl32.inl报错

    afxcomctl32.h与afxcomctl32.inl报错 编译公司一个几年前的老项目,是从VC6.0升级到VS2005的. 1.编译时报缺少头文件,于是附件包含目录,于是出现了以下报错: 1&g ...

  8. C标准头文件<math.h>

    定义域错误可以理解为超出了函数的适用范围,如果发生了定义域错误,设errno为EDOM 如果结果不能表示为double值,则发生值域错误,如果结果上溢,则函数返回HUGE_VAL的值,设errno为E ...

  9. C标准头文件<ctype.h>

    主要包括了一些字符识别和转换函数 字符判断 isalnum() //函数原型 #include<ctype.h> int isalum(int c); 功能:如果输入的字符是字母(alph ...

随机推荐

  1. MySQL8.0.x免安装配置

    目录 概述 下载 配置环境变量 编辑配置文件 初始化MySQL 安装MySQL系统(Windows)服务 初始化MySQL 启动MySQL 修改默认密码 开启远程登录 概述 MySQL从5.7一下子跳 ...

  2. ftp的主动模式和被动模式的配置和区别

    原文链接: https://www.cnblogs.com/lnlvinso/p/8947369.html ftp模式分为主动模式(active mode)和被动模式(passive mode),ft ...

  3. editplus注册码

    EditPlus5.0注册码 注册名 Vovan 注册码 3AG46-JJ48E-CEACC-8E6EW-ECUAW EditPlus3.x注册码 EditPlus注册码生成器链接 http://ww ...

  4. CSS 布局术语

    这一节的知识非常重要,它关系到能否做出漂亮的网站.下面的概念.术语需要好好理解. 构建块:CSS采用盒子模型来处理每个HTML元素.盒子可以是一个“块级”盒子,也可以是一个“内联”盒子. 包含元素:包 ...

  5. yii2.0 引入autoload.php提示Operation not permitted

    open_basedir()配置下就可以了.比如目录是/www/ad/web/yii/就在/usr/local/nginx/conf/fastcgi.conf里面修改下配置 opendir=/www/ ...

  6. c语言:第一次作业,分支,顺序结构

    1.本章学习总结(2分) 1.1 思维导图 1.2 本章学习体会及代码量学习体会 1.2.1 学习体会 学了几节课的c语言了,因为没自学的原因,跟不上进度.对于c语言现在挺有兴趣的,愿意去花时间去弥补 ...

  7. python中reshape重组数据方式

    方法numpy.reshape()是怎么进行数据重新定义shape?先生成一个随机数组 reshape成5行3列,可以看到是把(5,3)中第一行的剩余两列数据作为第二行的前两列,以此类推 reshap ...

  8. pwnable.kr-random-witeup

    看源代码. 可知,在linux下生成个随机数在于输入数异或等于固定值即可,而且吧, 随机数是固定的. 先得出随机数. random=1804289383 OK,接下来用计算器异或就行啦.0xB526F ...

  9. webpack简笔(1)

    1.npm init -> 生成package.json文件 2.npm install webpack --save-dev (不建议全局安装 ,会锁定版本) [ --save-dev 开发环 ...

  10. JavaSE基础知识(5)—面向对象(5.4面向对象三大特征:封装、继承、多态)

    面向对象编程具有三大特征: 封装 继承 多态 一.封装 1.好处 狭义的封装:也就是属性的封装,避免了任意赋值的危险,提高了数据的安全性! ①隐藏一个类中不需要对外提供的实现细节 ②使用者只能通过实现 ...