赞
踩
指定向FPGA硬件资源映射时的资源类型#
#pragma HLS RESOURCE variable =<temp>core =<Xilinxcore>
Examples :
a = b + c;
# pragma HLS RESOURCE variable =a core =AddSub_DSP
intA[1024];
# pragma HLS RESOURCE variable =A core =RAM_T2P_BRAM
#pragma HLS array _partition variable =<name><type>factor =<int>dim =<int>
Type :complete ,cyclic ,block
dim=1,2,3(dim=0)
不同TYPE:
complete: 完全打散为N个数
Block: 打散为几个块
cycle: factor 取模的方式进行划分,如奇偶性
任务级流水化
#pragma HLS dataflow
管线优化
#pragma HLS PIPELINE
任务级流水化粒度更大,作用于不同的子函数,后面的代码只能包含函数调用和中间变量声明。
pipeline作用于循环的不同iteration
数据类型: hls::stream<stream_type>
以高性能FIFO替代高资源占用的double-buffered RAM
指令:#pragma HLS stream variable =<variable>depth =<int>dim=<int>
#pragma HLS INLINE(off)
一般循环次数为定值,否则综合后无法获得性能估计(Latency=?)
#pragma HLS loop_tripcount min = <int> max = <int> avg =<int>
手动展开或使用指令
#pragma HLS UNROLL(factor = <int>)
E.g., #pragma HLS UNROLL factor=2
过分了可能综合时间过长和失败
可以存储于为片上的存储单元/Buffer/Scratchpad Memory
设计利用数据局部性提高重复访问数据的访问效率
头文件: ap_int.h,ap_fixed.h
支持任意精度、任意位宽的有/无符号数据类型:
精度处理
其实说人话就是加法的精度取决于原来误差较大的,乘法则是原来的相乘
在综合过程中定义生成的硬件接口
常用有
源码如下
void test() { float In[CHin][Rin][Cin]; float Out[CHout][R][C]; float W[CHout][CHin][K][K]; Output_Channel: for(int cho=0; cho<CHout; cho++) { Input_Channel: for(int chi=0; chi<CHin; chi++) { Row: for(int r=0; r<R; r++) { Column: for(int c=0; c<C; c++) { Kernel_Row: for(int kr=0; kr<K; kr++) { Kernel_Column: for(int kc=0; kc<K; kc++) { Out[cho][r][c] += In[chi][r+kr][c+kc] * W[cho][chi][kr][kc]; } } } } } } return; }
void test() { float In[CHin][Rin][Cin]; #pragma HLS array_partition variable=In complete dim=1 float Out[CHout][R][C]; #pragma HLS array_partition variable=Out complete dim=1 float W[CHout][CHin][K][K]; #pragma HLS array_partition variable=W complete dim=1 #pragma HLS array_partition variable=W complete dim=2 Row: for(int r=0; r<R; r++) { Column: for(int c=0; c<C; c++) { Kernel_Row: for(int kr=0; kr<K; kr++) { Kernel_Column: for(int kc=0; kc<K; kc++) { Output_Channel: for(int cho=0; cho<CHout; cho++) { #pragma HLS UNROLL Input_Channel: for(int chi=0; chi<CHin; chi++) { #pragma HLS UNROLL Out[cho][r][c] += In[chi][r+kr][c+kc] * W[cho][chi][kr][kc]; } } } } } } return; }
void test() { float In[CHin][Rin][Cin]; #pragma HLS array_partition variable=In complete dim=1 float Out[CHout][R][C]; #pragma HLS array_partition variable=Out complete dim=1 float W[CHout][CHin][K][K]; #pragma HLS array_partition variable=W complete dim=1 #pragma HLS array_partition variable=W complete dim=2 Row: for(int r=0; r<R; r++) { Column: for(int c=0; c<C; c++) { Kernel_Row: for(int kr=0; kr<K; kr++) { Kernel_Column: for(int kc=0; kc<K; kc++) { #pragma HLS PIPELINE Output_Channel: for(int cho=0; cho<CHout; cho++) { Input_Channel: for(int chi=0; chi<CHin; chi++) { Out[cho][r][c] += In[chi][r+kr][c+kc] * W[cho][chi][kr][kc]; } } } } } } return; }
void test() { float In[CHin][Rin][Cin]; #pragma HLS array_partition variable=In complete dim=1 float Out[CHout][R][C]; #pragma HLS array_partition variable=Out complete dim=1 float W[CHout][CHin][K][K]; #pragma HLS array_partition variable=W complete dim=1 #pragma HLS array_partition variable=W complete dim=2 Kernel_Row: for(int kr=0; kr<K; kr++) { Kernel_Column: for(int kc=0; kc<K; kc++) { Row: for(int r=0; r<R; r++) { Column: for(int c=0; c<C; c++) { #pragma HLS PIPELINE Output_Channel: for(int cho=0; cho<CHout; cho++) { Input_Channel: for(int chi=0; chi<CHin; chi++) { Out[cho][r][c] += In[chi][r+kr][c+kc] * W[cho][chi][kr][kc]; } } } } } } return; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。