RAM-Based Shift Register (ALTSHIFT_TAPS) IP Core-实现3X3像素阵列存储
最近想要实现CNN的FPGA加速处理,首先明确在CNN计算的过程中,因为卷积运算是最耗时间的,因此只要将卷积运算在FPGA上并行实现,即可完成部分运算的加速
那么对于卷积的FPGA实现首先要考虑的是卷积子模板具体如何实现,我们在matlab或者c实现比如3X3的子模板的时候,只要用一个数组即可将模板的数据存储起来,而在FPGA的话有以下三种方法:
- 用2个或3个RAM存储3X3像素阵列
- 用2个或3个FIFO存储3X3像素阵列
- 用shift_RAM移位存储3X3像素阵列
而shift_RAM好像就是为了阵列的实现量身定做的一般。
shift_RAM的配置参数主要有以下几个:

手册中可以参考理解的一个非常形象的图如下:

进一步的进行单独一个IP核的仿真后得到:

其中上述参数设置分别为8,2,3,上述仿真图中,相当于把一个矩阵A通过移位寄存的方法通过row3_data送入到RAM,然后分三行输出,在游标所示处就可以开始输出3X3矩阵
0,56,-122
92,50,-57
-58,-13,-61
以下部分是加入了对视频信号处理控制后的代码实现过程:
/*----------------------------------------------------------------------- CONFIDENTIAL IN CONFIDENCE
This confidential and proprietary software may be only used as authorized
by a licensing agreement from CrazyBingo (Thereturnofbingo).
In the event of publication, the following notice is applicable:
Copyright (C) 2011-20xx CrazyBingo Corporation
The entire notice above must be reproduced on all authorized copies.
Author : CrazyBingo
Technology blogs : http://blog.chinaaet.com/crazybingo
Email Address : thereturnofbingo@gmail.com
Filename : VIP_Matrix_Generate_3X3_8Bit.v
Data : 2014-03-19
Description : Generate 8Bit 3X3 Matrix for Video Image Processor.
Give up the 1th and 2th row edge data caculate for simple process
Give up the 1th and 2th point of 1 line for simple process
Modification History :
Data By Version Change Description
=========================================================================
13/05/26 CrazyBingo 1.0 Original
14/03/16 CrazyBingo 2.0 Modification
-*/ `timescale 1ns/1ns
module VIP_Matrix_Generate_3X3_8Bit
#(
parameter [:] IMG_HDISP = 'd640, //640*480
parameter [:] IMG_VDISP = 'd480
)
(
//global clock
input clk, //cmos video pixel clock
input rst_n, //global reset //Image data prepred to be processd
input per_frame_vsync, //Prepared Image data vsync valid signal
input per_frame_href, //Prepared Image data href vaild signal
input per_frame_clken, //Prepared Image data output/capture enable clock
input [:] per_img_Y, //Prepared Image brightness input //Image data has been processd
output matrix_frame_vsync, //Prepared Image data vsync valid signal
output matrix_frame_href, //Prepared Image data href vaild signal
output matrix_frame_clken, //Prepared Image data output/capture enable clock
output reg [:] matrix_p11, matrix_p12, matrix_p13, //3X3 Matrix output
output reg [:] matrix_p21, matrix_p22, matrix_p23,
output reg [:] matrix_p31, matrix_p32, matrix_p33
); //Generate 3*3 matrix
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//sync row3_data with per_frame_clken & row1_data & raw2_data
wire [:] row1_data; //frame data of the 1th row
wire [:] row2_data; //frame data of the 2th row
reg [:] row3_data; //frame data of the 3th row
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
row3_data <= ;
else
begin
if(per_frame_clken)
row3_data <= per_img_Y;
else
row3_data <= row3_data;
end
end //---------------------------------------
//module of shift ram for raw data
wire shift_clk_en = per_frame_clken;
Line_Shift_RAM_8Bit
#(
.RAM_Length (IMG_HDISP)
)
u_Line_Shift_RAM_8Bit
(
.clock (clk),
.clken (shift_clk_en), //pixel enable clock
// .aclr (1'b0), .shiftin (row3_data), //Current data input
.taps0x (row2_data), //Last row data
.taps1x (row1_data), //Up a row data
.shiftout ()
); //------------------------------------------
//lag 2 clocks signal sync 因为数据存储耗费了一个时钟,因此3*3阵列读取使能和时钟要偏移一个时钟
reg [:] per_frame_vsync_r;
reg [:] per_frame_href_r;
reg [:] per_frame_clken_r;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
per_frame_vsync_r <= ;
per_frame_href_r <= ;
per_frame_clken_r <= ;
end
else
begin
per_frame_vsync_r <= {per_frame_vsync_r[], per_frame_vsync};
per_frame_href_r <= {per_frame_href_r[], per_frame_href};
per_frame_clken_r <= {per_frame_clken_r[], per_frame_clken};
end
end
//Give up the 1th and 2th row edge data caculate for simple process
//Give up the 1th and 2th point of 1 line for simple process
wire read_frame_href = per_frame_href_r[]; //RAM read href sync signal
wire read_frame_clken = per_frame_clken_r[]; //RAM read enable
//将存储RAM以及阵列生成两个步骤需要的时钟都去掉
assign matrix_frame_vsync = per_frame_vsync_r[];
assign matrix_frame_href = per_frame_href_r[];
assign matrix_frame_clken = per_frame_clken_r[]; //----------------------------------------------------------------------------
//----------------------------------------------------------------------------
/******************************************************************************
---------- Convert Matrix ----------
[ P31 -> P32 -> P33 -> ] ---> [ P11 P12 P13 ]
[ P21 -> P22 -> P23 -> ] ---> [ P21 P22 P23 ]
[ P11 -> P12 -> P11 -> ] ---> [ P31 P32 P33 ]
******************************************************************************/
//---------------------------------------------------------------------------
//---------------------------------------------------
/***********************************************
(1) Read data from Shift_RAM
(2) Caculate the Sobel
(3) Steady data after Sobel generate
************************************************/
//wire [23:0] matrix_row1 = {matrix_p11, matrix_p12, matrix_p13}; //Just for test
//wire [23:0] matrix_row2 = {matrix_p21, matrix_p22, matrix_p23};
//wire [23:0] matrix_row3 = {matrix_p31, matrix_p32, matrix_p33};
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
{matrix_p11, matrix_p12, matrix_p13} <= 'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 'h0;
end
else if(read_frame_href)
begin
if(read_frame_clken) //Shift_RAM data read clock enable
begin
{matrix_p11, matrix_p12, matrix_p13} <= {matrix_p12, matrix_p13, row1_data}; //1th shift input
{matrix_p21, matrix_p22, matrix_p23} <= {matrix_p22, matrix_p23, row2_data}; //2th shift input
{matrix_p31, matrix_p32, matrix_p33} <= {matrix_p32, matrix_p33, row3_data}; //3th shift input
end
else
begin
{matrix_p11, matrix_p12, matrix_p13} <= {matrix_p11, matrix_p12, matrix_p13};
{matrix_p21, matrix_p22, matrix_p23} <= {matrix_p21, matrix_p22, matrix_p23};
{matrix_p31, matrix_p32, matrix_p33} <= {matrix_p31, matrix_p32, matrix_p33};
end
end
else
begin
{matrix_p11, matrix_p12, matrix_p13} <= 'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 'h0;
end
end endmodule
//注意这里得到的每一行得第一第二的像素都没有用到,而且最后一行的像素没有被运算。
RAM-Based Shift Register (ALTSHIFT_TAPS) IP Core-实现3X3像素阵列存储的更多相关文章
- 阅读 RAM-Based Shift Register(ALTSHIFT_TAPS) IP Core User Guide
阅读 RAM-Based Shift Register(ALTSHIFT_TAPS) IP Core User Guide 说明:本文档自带测试工程: DE_ALTSHIFT_TAPS.zip 1.支 ...
- Modelsim独立仿真Vivado Clocking Wizard IP Core
工欲善其事,必先利其器.在使用Vivado自带的仿真软件仿真的时候,相对于更优秀的仿真工具Modelsim,效率低了很多,为了更高效的开发,我尝试着用Vivado级联Modelsim仿真,但是级联后还 ...
- 在EDK里面添加ISE IP core的方法
(1)在ISE下,使用core generator,可以得到xilinx的IP的*.v和*.ngc 文件,将这两个文件拷贝出来: (2)在EDK下使用“Create or Import Periphe ...
- 使用xilinx ip core FIFO First- World First-Through (FWFT)模式的注意事项
也许很多人知道xilinx ip core 中的fifo可以配成standard 模式和FWFT模式,并知道两者的区别是:standard模式下,当rd为高时,fifo会延时一个时钟输出数据(时序逻辑 ...
- IP Core 分类
IP(Intelligent Property)核是具有知识产权核的集成电路芯核总称,是经过反复验证过的.具有特定功能的宏模块,与芯片制造工艺无关,可以移植到不同的半导体工艺中.到了SOC阶段,IP核 ...
- H.265 Video Encoder IP Core
复制: 开源H.265硬件视频编码器H.265 Video Encoder IP Core是开源的H.265硬件视频编码器,实现了H.265(或叫HEVC)的大部分功能. 它由复旦大学专用集成电路与系 ...
- Vivado 2017封装自定义IP Core
使用Vivado2017.3自定义IP Core.通常情况下,我们做设计采用模块化设计,对于已经设计好的一部分模块功能,就可以直接拿来调用,IP Core就是这样来的,一般来说我们看不到IP Core ...
- Xilinx 7系列例化MIG IP core DDR3读写
昨晚找了一下,发现DDR3读写在工程上多是通过例化MIG,调用生成IPcore的HDL Functional Model.我说嘛,自己哪能写出那么繁琐的,不过DDR读写数据可以用到状态机,后期再添砖加 ...
- Shift Register(Using Submodule)
/*************************************************** / Shift Register module by Submodule / Progra ...
随机推荐
- Java基础查漏补缺(2)
Java基础查漏补缺(2) apache和spring都提供了BeanUtils的深度拷贝工具包 +=具有隐形的强制转换 object类的equals()方法容易抛出空指针异常 String a=nu ...
- Vuex 是什么
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集成到 Vue 的官方调试工具 ...
- POJ 1013:Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42028 Accepted: 13 ...
- nodejs(8) 使用ejs渲染动态页面
使用ejs渲染动态页面 步骤: 安装 ejs 模板引擎npm i ejs -S 使用 app.set() 配置默认的模板引擎 app.set('view engine', 'ejs') 使用 app. ...
- UVA 127 链表和栈的使用
刘汝佳的题目感觉都是比较难以处理的,就像这道题目,一看数据简直觉得头大...加上这个英文我也看的想死 最后看别人博客的题意讲解才知道原来是要移牌. 然后如果熟练的使用stack和手写链表的话,这个题目 ...
- Python D9 学习
Python 设置环境 当安装好Python 后 在计算机的属性里面 高级语言设置 环境变量. 环境变量里面的path 更改为Python的 树目录 可以从计算机直接下达命令 打开Pytho ...
- 使用cropper插件裁剪并上传图片(Spring mvc)
cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. cropper有两种方式上传截 ...
- php速成_day4
一.微信公众平台概述 1.微信发展史 1)2011年1月21日,腾讯推出微信应用程序.(张小龙) 2)2012年8月20日,腾讯推出微信公众平台功能,同年11月开放第三方接口 3)2013年11月注册 ...
- 收藏基本Java项目开发的书
一.Java项目开发全程实录 第1章 进销存管理系统(Swing+SQL Server2000实现) 第2章企业内部通信系统(Swing+JavaDB实现) 第3章 企业人事管理系统( Swing+H ...
- Android Studio 停靠模式(Docked Mode)
如果之前选了任务一种模式,先全都取消了 然后点击Window -->Active Tool Window-->这个时候就可以选择Docked Mode了