From c27186667f6304f07c1e7ff21a64fde5f23facc7 Mon Sep 17 00:00:00 2001
From: Reinier van der Walle <walle@astron.nl>
Date: Wed, 2 Dec 2020 15:45:41 +0100
Subject: [PATCH] Processed review comments

---
 .../ta2/bsp/hardware/ta2_unb2b_bsp/flat.qsf   | 27 ++++++++-
 .../ta2_unb2b_bsp/scripts/post_flow_pr.tcl    | 25 ++++++++
 .../ta2_unb2b_bsp/scripts/pre_flow_pr.tcl     | 25 ++++++++
 .../ta2/bsp/hardware/ta2_unb2b_bsp/top.vhd    | 42 ++++++++-----
 .../ta2_unb2b_bsp/top_components_pkg.vhd      | 36 ++++++-----
 .../ta2_unb2b_qsfp_demo/host/src/main.cpp     | 60 ++++++++++++++-----
 applications/ta2/doc/README.txt               | 33 ++++++----
 7 files changed, 189 insertions(+), 59 deletions(-)

diff --git a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/flat.qsf b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/flat.qsf
index a81fc5278b..c3fe092879 100755
--- a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/flat.qsf
+++ b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/flat.qsf
@@ -14,7 +14,32 @@
 # sole purpose of programming logic devices manufactured by Intel and sold by    
 # Intel or its authorized distributors.  Please refer to the applicable          
 # agreement for further details.                                                 
-
+# ##########################################################################
+# Copyright 2020
+# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
+# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ##########################################################################
+
+# ##########################################################################
+# Author:
+# . Reinier vd Walle
+# Purpose:
+# . Quartus settings for OpenCL BSP
+# Description:
+# . " "
+# ##########################################################################
 
 # device.tcl contains settings unique to each device type/board variant (most importantly, the device string for the particular device type)
 source device.tcl
diff --git a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/post_flow_pr.tcl b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/post_flow_pr.tcl
index 568d6f7ba6..4f6fa9be95 100755
--- a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/post_flow_pr.tcl
+++ b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/post_flow_pr.tcl
@@ -14,7 +14,32 @@
 # sole purpose of programming logic devices manufactured by Intel and sold by    
 # Intel or its authorized distributors.  Please refer to the applicable          
 # agreement for further details.                                                 
+# ##########################################################################
+# Copyright 2020
+# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
+# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ##########################################################################
 
+# ##########################################################################
+# Author:
+# . Reinier vd Walle 
+# Purpose:
+# . post-compile script for OpenCL applications
+# Description:
+# . " "
+# ##########################################################################
 post_message "Running post_flow_pr.tcl script"
 
 post_message "Checking for OpenCL SDK installation, environment should have INTELFPGAOCLSDKROOT defined"
diff --git a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/pre_flow_pr.tcl b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/pre_flow_pr.tcl
index 0b1681c124..cb6dd4342a 100755
--- a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/pre_flow_pr.tcl
+++ b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/scripts/pre_flow_pr.tcl
@@ -14,7 +14,32 @@
 # sole purpose of programming logic devices manufactured by Intel and sold by    
 # Intel or its authorized distributors.  Please refer to the applicable          
 # agreement for further details.                                                 
+# ##########################################################################
+# Copyright 2020
+# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
+# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ##########################################################################
 
+# ##########################################################################
+# Author:
+# . Reinier vd Walle
+# Purpose:
+# . pre-compile script for OpenCL applications
+# Description:
+# . " "
+# ##########################################################################
 post_message "Running pre-flow script"
 
 # Make sure OpenCL SDK installation exists
diff --git a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top.vhd b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top.vhd
index d397b273ba..3c62c1dbe2 100644
--- a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top.vhd
+++ b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top.vhd
@@ -1,24 +1,34 @@
--------------------------------------------------------------------------------
---
--- Copyright (C) 2020
+-- --------------------------------------------------------------------------
+-- Copyright 2020
 -- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
--- JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>
 -- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
 --
--- This program is free software: you can redistribute it and/or modify
--- it under the terms of the GNU General Public License as published by
--- the Free Software Foundation, either version 3 of the License, or
--- (at your option) any later version.
---
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
 --
--- You should have received a copy of the GNU General Public License
--- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-- http://www.apache.org/licenses/LICENSE-2.0
 --
--------------------------------------------------------------------------------
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+-- --------------------------------------------------------------------------
+
+-- --------------------------------------------------------------------------
+-- Author:
+-- . Reinier vd Walle
+-- Purpose:
+-- . Top-Level for OpenCL Board Support Package of TA2 applications
+-- Description:
+-- . This BSP makes several IO-channels available to the OpenCL kernel, these
+--   include:
+--   . 40 GbE
+--   . 10 GbE
+--   . ADC
+--   . 1 GbE M&C
+-- --------------------------------------------------------------------------
 
 LIBRARY IEEE, common_lib, unb2b_board_lib, technology_lib, dp_lib, tech_ddr_lib, ta2_unb2b_40GbE_lib, ta2_unb2b_10gbe_lib, ta2_unb2b_1gbe_mc_lib, ta2_unb2b_mm_io_lib, ta2_unb2b_jesd204b_lib ;
 USE IEEE.STD_LOGIC_1164.ALL;
diff --git a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top_components_pkg.vhd b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top_components_pkg.vhd
index a843397810..2196157cf8 100644
--- a/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top_components_pkg.vhd
+++ b/applications/ta2/bsp/hardware/ta2_unb2b_bsp/top_components_pkg.vhd
@@ -1,25 +1,29 @@
--------------------------------------------------------------------------------
---
--- Copyright (C) 2020
+-- --------------------------------------------------------------------------
+-- Copyright 2020
 -- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
--- JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>
 -- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
 --
--- This program is free software: you can redistribute it and/or modify
--- it under the terms of the GNU General Public License as published by
--- the Free Software Foundation, either version 3 of the License, or
--- (at your option) any later version.
---
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
 --
--- You should have received a copy of the GNU General Public License
--- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-- http://www.apache.org/licenses/LICENSE-2.0
 --
--------------------------------------------------------------------------------
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+-- --------------------------------------------------------------------------
 
+-- --------------------------------------------------------------------------
+-- Author:
+-- . Reinier vd Walle
+-- Purpose:
+-- . VHDL package for top.vhd
+-- Description:
+-- . Contains components instantiated by top.vhd
+-- --------------------------------------------------------------------------
 LIBRARY IEEE;
 USE IEEE.STD_LOGIC_1164.ALL;
 
diff --git a/applications/ta2/designs/ta2_unb2b_qsfp_demo/host/src/main.cpp b/applications/ta2/designs/ta2_unb2b_qsfp_demo/host/src/main.cpp
index 3dcd159a7b..0aa76d704d 100644
--- a/applications/ta2/designs/ta2_unb2b_qsfp_demo/host/src/main.cpp
+++ b/applications/ta2/designs/ta2_unb2b_qsfp_demo/host/src/main.cpp
@@ -1,4 +1,31 @@
-
+/* *************************************************************************
+* Copyright 2020
+* ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
+* P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* *********************************************************************** */
+
+/* *************************************************************************
+* Author:
+* . Reinier vd Walle
+* Purpose:
+* . Test the ta2_unb2b_qsfp_demo OpenCL application in emulator
+* Description:
+* . Run: -> make ta2_unb2b_qsfp_demo
+* . Navigate to -> cd $RADIOHDL_WORK/unb2b/OpenCL/ta2_unb2b_qsfp_demo/bin
+* . Execute -> CL_CONTEXT_EMULATOR_DEVICE_INTELFPGA=1 ./host
+* *********************************************************************** */
 #include <CL/cl_ext_intelfpga.h>
 #include <iostream>
 #include <fstream>
@@ -43,27 +70,28 @@ int main(int argc, char **argv)
     try {
         queues[0].enqueueTask(writer40gbeKernel, nullptr, &computeDoneA);
         queues[1].enqueueTask(writer10gbeKernel, nullptr, &computeDoneB);
+
+
+        computeDoneA.wait();
+        cl_ulong start = computeDoneA.getProfilingInfo<CL_PROFILING_COMMAND_START>();
+        cl_ulong stop  = computeDoneA.getProfilingInfo<CL_PROFILING_COMMAND_END>();
+    
+        double milliseconds = (stop - start) / 1e6;
+        cout << "runtime 40GbE= " << milliseconds << " ms, " << endl;
+    
+        computeDoneB.wait();
+        start = computeDoneB.getProfilingInfo<CL_PROFILING_COMMAND_START>();
+        stop  = computeDoneB.getProfilingInfo<CL_PROFILING_COMMAND_END>();
+    
+        milliseconds = (stop - start) / 1e6;
+        cout << "runtime 10GbE= " << milliseconds << " ms, " << endl;
+
     } catch (cl::Error &error) {
         cerr << "Error launching kernel: " << error.what() << endl;
         exit(EXIT_FAILURE);
     }
 
 
-    computeDoneA.wait();
-    cl_ulong start = computeDoneA.getProfilingInfo<CL_PROFILING_COMMAND_START>();
-    cl_ulong stop  = computeDoneA.getProfilingInfo<CL_PROFILING_COMMAND_END>();
-
-    double milliseconds = (stop - start) / 1e6;
-    cout << "runtime 40GbE= " << milliseconds << " ms, " << endl;
-
-    computeDoneB.wait();
-    start = computeDoneB.getProfilingInfo<CL_PROFILING_COMMAND_START>();
-    stop  = computeDoneB.getProfilingInfo<CL_PROFILING_COMMAND_END>();
-
-    milliseconds = (stop - start) / 1e6;
-    cout << "runtime 10GbE= " << milliseconds << " ms, " << endl;
-
-
 // process 40 GbE output, removing the flag data
     const string inputFileA = "kernel_output_40GbE";
 
diff --git a/applications/ta2/doc/README.txt b/applications/ta2/doc/README.txt
index cd72c208df..9edf518126 100644
--- a/applications/ta2/doc/README.txt
+++ b/applications/ta2/doc/README.txt
@@ -1,6 +1,20 @@
+Title: How to use OpenCL with UNB2b
+
 Author: Reinier vd Walle
 
-OVERVIEW
+
+INDEX
+1. OVERVIEW
+2. SETUP ONCE
+3. COMPILING EXAMPLE OPENCL APPLICATION FOR EMULATION
+4. COMPILING EXAMPLE OPENCL APPLICATION FOR UNB2B
+5. CREATING NEW OPENCL APPLICATION
+6. FLASH SOF TO FPGA
+7. FLASH RBF TO FPGA
+8. CREATING A NEW BSP
+
+
+1. OVERVIEW
 The ta2 project folder contains 4 sub-folders:
 - doc
     . The folder that contains this file.
@@ -13,7 +27,7 @@ The ta2 project folder contains 4 sub-folders:
     . This folder contains VHDL libraries that are used in BSPs
 
 
-SETUP ONCE
+2. SETUP ONCE
 - Install Quartus 19.2 with arria10 dependencies and OpenCL dependencies. A later Quartus version may be used 
   for OpenCL compilation. However, the current BSPs are created for 19.2.
 - Aquire the RadioHDL library from GIT or other source.
@@ -50,7 +64,7 @@ SETUP ONCE
     -> generate_ip_libs unb2b
 
 
-COMPILING EXAMPLE OPENCL APPLICATION FOR EMULATION
+3. COMPILING EXAMPLE OPENCL APPLICATION FOR EMULATION
 The example application used is "ta2_unb2b_qsfp_demo", this application generates UDP packets and outputs them 
 to 40GbE and 10GbE. In emulation, this design is verified by comparing the 10GbE and 40GbE outputs to check if 
 the data is identical. If that is the case, the output will state "PASSED".
@@ -66,7 +80,8 @@ the data is identical. If that is the case, the output will state "PASSED".
     -> CL_CONTEXT_EMULATOR_DEVICE_INTELFPGA=1 ./host
 - At the end of the application output you should see "PASSED".
   
-COMPILING EXAMPLE OPENCL APPLICATION FOR UNB2B
+
+4. COMPILING EXAMPLE OPENCL APPLICATION FOR UNB2B
 The example application used is "ta2_unb2b_qsfp_demo", this application generates UDP packets and outputs them 
 to 40GbE and 10GbE. On hardware, you can verify the design by connecting a PC to the 40GbE (QSFP1) or 
 10GbE (QSFP0) output and check for incoming packets using tcpdump.
@@ -80,7 +95,7 @@ to 40GbE and 10GbE. On hardware, you can verify the design by connecting a PC to
   ta2_unb2b_qsfp_demo.rbf in the current directory.
 
 
-CREATING NEW OPENCL APPLICATION
+5. CREATING NEW OPENCL APPLICATION
 - Start by copying the example application located in $RADIOHDL_WORK/applications/ta2/designs/ta2_unb2b_qsfp_demo
 - rename the folder and ta2_unb2b_qsfp_demo.cl
 - If you need to use a specific OpenCL BSP, open the Makefile and change the BSP Name into the name of the BSP 
@@ -97,7 +112,7 @@ CREATING NEW OPENCL APPLICATION
 - For emulation, you need to modify the host code located in host/src/main.cpp to fit your design. 
 
 
-FLASH SOF TO FPGA
+6. FLASH SOF TO FPGA
 The quickest way to program the FPGA is to use a JTAG connection and program the FPGA with the Quartus
 programmer, writing the .sof file.
 - To configure a jtagserver you can use the command:
@@ -116,13 +131,13 @@ Multiple FPGAs can be targeted simultaniously for example, programming FPGAs 1,2
 quartus_pgm -c USB-BLASTERII -m jtag -o p\;my_app.sof@1 -o p\;my_app.sof@2 -o p\;my_app.sof@4
 
 
-FLASH RBF TO FPGA
+7. FLASH RBF TO FPGA
 If a JTAG connection is not available or you want your application to stay in flash, the application can be 
 written using the .rbf file over a 1GbE connection. This is achieved by running the util_unb2.py peripheral 
 script in $UPE_GEAR/peripherals
 
 
-CREATING A NEW BSP
+8. CREATING A NEW BSP
 - BSPs are located in "$AOCL_BOARD_PACKAGE_ROOT/hardware" which is defined as
   "$RADIOHDL_WORK/applications/ta2/bsp/hardware"
 - To create a new BSP it is easiest to copy an existing one. In this example we would make a copy of the 
@@ -153,5 +168,3 @@ CREATING A NEW BSP
 
 
 
-
-
-- 
GitLab