Skip to content

Commit 54fdc11

Browse files
faisale-xilinxGitHub Enterprise
authored andcommitted
New Tutorial: AIE/D/15-farrow_filter
1 parent eefcca2 commit 54fdc11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+11509
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Author: Faisal El-Shabani
6+
7+
ECHO = @echo
8+
export TARGET ?= hw_emu
9+
10+
export AIE_SIM_ONLY := false
11+
12+
# Platform Selection...
13+
VERSAL_VITIS_PLATFORM = xilinx_vck190_base_202320_1
14+
VITIS_PLATFORM_DIR = ${PLATFORM_REPO_PATHS}/${VERSAL_VITIS_PLATFORM}
15+
export VITIS_PLATFORM_XPFM = ${VITIS_PLATFORM_DIR}/${VERSAL_VITIS_PLATFORM}.xpfm
16+
17+
# Set SysRoot, RootFS and Image
18+
export VITIS_SYSROOTS = ${COMMON_IMAGE_VERSAL}/sysroots/cortexa72-cortexa53-xilinx-linux
19+
export SDKTARGETSYSROOT = ${VITIS_SYSROOTS}
20+
export KERNEL_IMAGE = ${COMMON_IMAGE_VERSAL}/Image
21+
export ROOTFS = ${COMMON_IMAGE_VERSAL}/rootfs.ext4
22+
export XLNX_VERSAL = ${COMMON_IMAGE_VERSAL}
23+
export PLATFORM = ${VITIS_PLATFORM_XPFM}
24+
export SYSROOT = ${SDKTARGETSYSROOT}
25+
26+
##############
27+
# Build Flow #
28+
##############
29+
.PHONY: clean help gen_vectors
30+
31+
help::
32+
$(ECHO) "Makefile Usage:"
33+
$(ECHO) " make all"
34+
$(ECHO) " Command to generate everything for this design"
35+
$(ECHO) ""
36+
$(ECHO) " make clean"
37+
$(ECHO) " Command to remove all the generated files."
38+
39+
gen_vectors:
40+
matlab -batch "gen_vectors"
41+
42+
all: farrow_design
43+
44+
farrow_design:
45+
$(MAKE) compile -C aie/farrow_final
46+
$(MAKE) all -C hls/farrow_dma_snk
47+
$(MAKE) all -C hls/farrow_dma_src
48+
$(MAKE) all -C ps_apps/hw_emu
49+
$(MAKE) all -C vitis
50+
51+
clean:
52+
$(MAKE) clean -C aie/farrow_final
53+
$(MAKE) clean -C hls/farrow_dma_snk
54+
$(MAKE) clean -C hls/farrow_dma_src
55+
$(MAKE) clean -C ps_apps/hw_emu
56+
$(MAKE) clean -C vitis
57+
@/bin/rm -rf .crashReporter*

AI_Engine_Development/AIE/Design_Tutorials/15-farrow_filter/README.md

Lines changed: 401 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
#
5+
# Author: Faisal El-Shabani
6+
7+
AIE_SIM_ONLY ?= true
8+
9+
PLATFORM_USE := xilinx_vck190_base_202320_1
10+
PLATFORM := ${PLATFORM_REPO_PATHS}/${PLATFORM_USE}/${PLATFORM_USE}.xpfm
11+
12+
MY_APP = farrow_app.cpp
13+
MY_SOURCES = ${MY_APP} farrow_graph.h farrow_kernel1.cpp farrow_kernel1.h farrow_kernel2.cpp farrow_kernel2.h
14+
LOG_FILE = log
15+
OTHER_OPTS = --aie.pl-freq=625.0 --aie.Xchess="-std=c++17"
16+
ALL_INCLUDE := --include=${PWD}
17+
AIE_FLAGS := --aie.verbose ${ALL_INCLUDE} ${MY_APP} ${OTHER_OPTS} --platform=${PLATFORM} --aie.Xmapper=BufferOptLevel9 --aie.xlopt=1
18+
19+
ifeq (${AIE_SIM_ONLY},true)
20+
AIE_FLAGS := ${AIE_FLAGS} --aie.Xpreproc="-DAIE_SIM_ONLY"
21+
endif
22+
23+
.PHONY: clean help compile sim
24+
25+
help::
26+
@echo "Makefile Usage:"
27+
@echo " make all"
28+
@echo " Command to generate everything for this design"
29+
@echo ""
30+
@echo " make compile"
31+
@echo " Run AIE compiler and build the design"
32+
@echo ""
33+
@echo " make sim"
34+
@echo " Run AIE simulator"
35+
@echo ""
36+
@echo " make clean"
37+
@echo " Command to remove all the generated files."
38+
39+
all : compile sim get_II check_sim_output_aie
40+
41+
x86all : x86compile x86sim check_sim_output_x86
42+
43+
compile: ${MY_SOURCES}
44+
v++ -c --mode aie --target=hw ${AIE_FLAGS} 2>&1 | tee ${LOG_FILE}
45+
46+
x86compile:
47+
v++ -c --mode aie --target=x86sim ${AIE_FLAGS} 2>&1 | tee ${LOG_FILE}
48+
49+
sim:
50+
aiesimulator --profile --online -wdb -text -i=../.. 2>&1 | tee -a ${LOG_FILE}
51+
52+
x86sim:
53+
x86simulator 2>&1 -i=../.. | tee -a ${LOG_FILE}
54+
55+
check_sim_output_aie:
56+
matlab -batch "check_sim_output('hw')"
57+
58+
check_sim_output_x86:
59+
matlab -batch "check_sim_output('x86sim')"
60+
61+
throughput:
62+
@../../scripts/throughput.py aiesimulator_output/data/sig_o.txt --iscomplex
63+
64+
get_II:
65+
@../../scripts/get_loop_II.py Work/aie/
66+
67+
clean:
68+
@rm -rf Work* .Xil function_wdb_dir .crashReporter .AIE_SIM_CMD_LINE_OPTIONS AIECompiler.log xcd.log log aiesimulator_output x86simulator_output diff_output pl_sample_count* tmp vitis_analyzer.* xsc_report.log diag_report.log libadf.a sol.db t.txt Map_Report.csv AIESimulator.log
69+
@rm -rf ISS_RPC_SERVER_PORT system_flat.wcfg system.wcfg system.wdb tmp.vcd.vcd trdata.aiesim vcdanalyze.log vitis_analyzer_pid* logs VCDAnalyze.log
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%
2+
% Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
3+
% SPDX-License-Identifier: MIT
4+
%
5+
% Author: Faisal El-Shabani
6+
7+
function check_sim_output(TARGET)
8+
%% Read golden output
9+
fileID = fopen('../../data/sig_o.txt','r');
10+
formatSpec = '%f %f %f %f';
11+
[sig_g] = fscanf(fileID,formatSpec).';
12+
fclose(fileID);
13+
sig_g = [complex(sig_g(1:4:end),sig_g(2:4:end));complex(sig_g(3:4:end),sig_g(4:4:end))];
14+
sig_g = sig_g(:).';
15+
16+
if (TARGET=="hw")
17+
fileID = fopen('aiesimulator_output/data/sig_o.txt','r');
18+
txt = textscan(fileID,'%s','delimiter','\n');
19+
fclose(fileID);
20+
txt{1}(strcmp(txt{1},'TLAST'))=[];
21+
tmp = zeros(1,size(txt{1},1));
22+
for i=2:2:size(txt{1},1)
23+
x = strsplit(txt{1}{i},' ');
24+
tmp(i-1) = complex(str2double(x{1}),str2double(x{2}));
25+
tmp(i) = complex(str2double(x{3}),str2double(x{4}));
26+
end
27+
sig_o_sim = tmp;
28+
29+
y1 = strsplit(txt{1}{1},' ');
30+
if strcmp(y1(end),'ns') factor = 1; elseif strcmp(y1(end),'us') factor = 1000; elseif strcmp(y1(end),'ps') factor = 1/1000; end
31+
y1 = str2num(y1{2})*factor;
32+
y2 = strsplit(txt{1}{end-1},' ');
33+
if strcmp(y2(end),'ns') factor = 1; elseif strcmp(y2(end),'us') factor = 1000; elseif strcmp(y2(end),'ps') factor = 1/1000; end
34+
y2 = str2num(y2{2})*factor;
35+
throughput = round(size(sig_o_sim,2)/(y2-y1)*1000,1);
36+
fprintf('Raw Throughput = %.1f MSPS\n',throughput);
37+
elseif (TARGET=="x86sim")
38+
fileID = fopen('x86simulator_output/data/sig_o.txt','r');
39+
formatSpec = '%f %f %f %f';
40+
[sig_o_sim] = fscanf(fileID,formatSpec).';
41+
fclose(fileID);
42+
sig_o_sim = [complex(sig_o_sim(1:4:end),sig_o_sim(2:4:end));complex(sig_o_sim(3:4:end),sig_o_sim(4:4:end))];
43+
sig_o_sim = sig_o_sim(:).';
44+
end
45+
fprintf('Max error LSB = %d\n',max(max(real(sig_g-sig_o_sim)),max(imag(sig_g-sig_o_sim))));
46+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
3+
// SPDX-License-Identifier: MIT
4+
//
5+
// Author: Faisal El-Shabani
6+
7+
#include "farrow_graph.h"
8+
9+
using namespace adf;
10+
11+
class dut_graph : public graph {
12+
farrow_graph farrow;
13+
public:
14+
std::array< input_plio,1> sig_i;
15+
std::array< input_plio,1> del_i;
16+
std::array<output_plio,1> sig_o;
17+
dut_graph( void )
18+
{
19+
#ifdef AIE_SIM_ONLY
20+
sig_i[0] = input_plio::create("PLIO_i_0",plio_64_bits,"data/sig_i.txt");
21+
del_i[0] = input_plio::create("PLIO_i_1",plio_64_bits,"data/del_i_optimized.txt");
22+
sig_o[0] = output_plio::create("PLIO_o_0",plio_64_bits,"data/sig_o.txt");
23+
#else
24+
sig_i[0] = input_plio::create("PLIO_i_0",plio_64_bits);
25+
del_i[0] = input_plio::create("PLIO_i_1",plio_64_bits);
26+
sig_o[0] = output_plio::create("PLIO_o_0",plio_64_bits);
27+
#endif
28+
connect<stream>(sig_i[0].out[0],farrow.sig_i[0]);
29+
connect<stream>(del_i[0].out[0],farrow.del_i[0]);
30+
connect<stream>(farrow.sig_o[0],sig_o[0].in[0]);
31+
}
32+
};
33+
34+
// Instantiate AIE graph:
35+
dut_graph aie_dut;
36+
37+
// Initialize and run the graph:
38+
int main(void)
39+
{
40+
aie_dut.init();
41+
aie_dut.run(4);
42+
aie_dut.end();
43+
44+
return 0;
45+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
3+
// SPDX-License-Identifier: MIT
4+
//
5+
// Author: Faisal El-Shabani
6+
7+
#pragma once
8+
9+
#include <adf.h>
10+
#include "farrow_kernel1.h"
11+
#include "farrow_kernel2.h"
12+
13+
using namespace adf;
14+
15+
// ------------------------------------------------------------
16+
// Top Level Graph
17+
// ------------------------------------------------------------
18+
19+
class farrow_graph : public graph {
20+
public:
21+
// Declare Kernels
22+
kernel farrow_kernel1_ins;
23+
kernel farrow_kernel2_ins;
24+
25+
std::array<port<input>,1> sig_i;
26+
std::array<port<input>,1> del_i;
27+
std::array<port<output>,1> sig_o;
28+
29+
farrow_graph( void )
30+
{
31+
farrow_kernel1_ins = kernel::create_object<farrow_kernel1>();
32+
source(farrow_kernel1_ins) = "farrow_kernel1.cpp";
33+
runtime<ratio>(farrow_kernel1_ins) = 0.9;
34+
35+
farrow_kernel2_ins = kernel::create_object<farrow_kernel2>();
36+
source(farrow_kernel2_ins) = "farrow_kernel2.cpp";
37+
runtime<ratio>(farrow_kernel2_ins) = 0.9;
38+
39+
location<stack>(farrow_kernel1_ins) = location<kernel>(farrow_kernel1_ins);
40+
location<stack>(farrow_kernel2_ins) = location<kernel>(farrow_kernel2_ins);
41+
42+
// Connect inputs:
43+
connect<> ( sig_i[0], farrow_kernel1_ins.in[0] );
44+
connect<> ( del_i[0], farrow_kernel2_ins.in[0] );
45+
46+
connect<> ( farrow_kernel1_ins.out[0], farrow_kernel2_ins.in[1] );
47+
connect<> ( farrow_kernel1_ins.out[1], farrow_kernel2_ins.in[2] );
48+
connect<> ( farrow_kernel1_ins.out[2], farrow_kernel2_ins.in[3] );
49+
connect<> ( farrow_kernel1_ins.out[3], farrow_kernel2_ins.in[4] );
50+
51+
// Connect outputs:
52+
connect<>( farrow_kernel2_ins.out[0], sig_o[0] );
53+
}
54+
};
55+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
3+
// SPDX-License-Identifier: MIT
4+
//
5+
// Author: Faisal El-Shabani
6+
7+
#include <adf.h>
8+
#include <aie_api/aie.hpp>
9+
10+
#include "farrow_kernel1.h"
11+
12+
#include <aie_api/utils.hpp>
13+
// ------------------------------------------------------------
14+
// Constructor
15+
// ------------------------------------------------------------
16+
17+
farrow_kernel1::farrow_kernel1( void )
18+
{
19+
aie::set_rounding(aie::rounding_mode::symmetric_inf);
20+
aie::set_saturation(aie::saturation_mode::saturate);
21+
for(int i=0;i<STATE_LEN;i++)
22+
{
23+
f_state[i] = (cint16){0,0};
24+
}
25+
}
26+
27+
// ------------------------------------------------------------
28+
// Run
29+
// ------------------------------------------------------------
30+
31+
void farrow_kernel1::run( input_buffer<TT_SIG,adf::extents<BUFFER_SIZE>>& __restrict sig_i,
32+
output_buffer<TT_SIG,adf::extents<BUFFER_SIZE>>& __restrict y3,
33+
output_buffer<TT_SIG,adf::extents<BUFFER_SIZE>>& __restrict y2,
34+
output_buffer<TT_SIG,adf::extents<BUFFER_SIZE>>& __restrict y1,
35+
output_buffer<TT_SIG,adf::extents<BUFFER_SIZE>>& __restrict y0)
36+
{
37+
aie::accum<TT_ACC,8> acc_f3;
38+
aie::accum<TT_ACC,8> acc_f2;
39+
aie::accum<TT_ACC,8> acc_f1;
40+
aie::accum<TT_ACC,8> acc_f0;
41+
42+
aie::vector<cint16,16> v_buff;
43+
v_buff.insert(1,aie::load_v<8>( f_state ) );
44+
aie::vector<int16,16> f_coeffs = aie::load_v<16>(f_taps);
45+
46+
auto p_sig_i = aie::begin_vector<8>(sig_i);
47+
auto p_y3 = aie::begin_vector<8>(y3);
48+
auto p_y2 = aie::begin_vector<8>(y2);
49+
auto p_y1 = aie::begin_vector<8>(y1);
50+
auto p_y0 = aie::begin_vector<8>(y0);
51+
52+
// Loop over some samples:
53+
for ( unsigned rr=0; rr < BUFFER_SIZE/16; rr++)
54+
chess_loop_range(1,0)
55+
chess_prepare_for_pipelining
56+
{
57+
v_buff.insert(0,*p_sig_i++);
58+
acc_f3 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_antisym(f_coeffs,0,v_buff,9);
59+
*p_y3++ = acc_f3.to_vector<TT_SIG>(DNSHIFT);
60+
acc_f2 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_sym(f_coeffs,4,v_buff,9);
61+
*p_y2++ = acc_f2.to_vector<TT_SIG>(DNSHIFT);
62+
acc_f1 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_antisym(f_coeffs,8,v_buff,9);
63+
*p_y1++ = acc_f1.to_vector<TT_SIG>(DNSHIFT);
64+
acc_f0 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_sym(f_coeffs,12,v_buff,9);
65+
*p_y0++ = acc_f0.to_vector<TT_SIG>(DNSHIFT);
66+
67+
v_buff.insert(1,*p_sig_i++);
68+
acc_f3 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_antisym(f_coeffs,0,v_buff,1);
69+
*p_y3++ = acc_f3.to_vector<TT_SIG>(DNSHIFT);
70+
acc_f2 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_sym(f_coeffs,4,v_buff,1);
71+
*p_y2++ = acc_f2.to_vector<TT_SIG>(DNSHIFT);
72+
acc_f1 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_antisym(f_coeffs,8,v_buff,1);
73+
*p_y1++ = acc_f1.to_vector<TT_SIG>(DNSHIFT);
74+
acc_f0 = aie::sliding_mul_sym_xy_ops<8,8,1,1,int16,cint16>::mul_sym(f_coeffs,12,v_buff,1);
75+
*p_y0++ = acc_f0.to_vector<TT_SIG>(DNSHIFT);
76+
}
77+
*(v8cint16*)f_state = v_buff.extract<8>(1);
78+
79+
}

0 commit comments

Comments
 (0)