├── BinomialModel.pdf ├── BinomialModel.png ├── LICENSE.txt ├── P00_sw ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ ├── sw_hw_config_1_Thread.txt │ └── sw_hw_config_M_Thread.txt ├── P10_hw_Original ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── P11_hw_Original_HostOpt ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── P12_hw_KOpt ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── P13_hw_KOpt_8CU_2DDRs ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── K1.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── P14_hw_KOpt_12CU_3DDRs ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── K1.cpp │ ├── K2.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── Popt_12_step1_DataMove ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── Popt_12_step2_FUNx4 ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── Popt_12_step3_ARRAY_PARTITION ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt ├── Popt_12_step4_UNROLL ├── README.md ├── description.json └── src │ ├── Host.cpp │ ├── K0.cpp │ ├── SW.cpp │ ├── Test_Config_Files │ ├── test_config_FULL.txt │ └── test_config_HW_Emu.txt │ ├── application_arguments.txt │ ├── help_functions.cpp │ ├── help_functions.h │ ├── host_functions.cpp │ ├── host_functions.h │ ├── kernel.h │ └── sw_hw_config.txt └── README.md /BinomialModel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/BinomialModel/2d51f49454a60eda111be30a9d6eac9825c6386d/BinomialModel.pdf -------------------------------------------------------------------------------- /BinomialModel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/BinomialModel/2d51f49454a60eda111be30a9d6eac9825c6386d/BinomialModel.png -------------------------------------------------------------------------------- /P00_sw/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: P00_sw 2 | 3 | This project represents a SW version of the Binomial Model to be run on CPU with a single or multiple threads. The results obtained in this project will be compared against the results obtained by running the application on the Alveo card. 4 | 5 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 6 | 7 | [BinomialModel.pdf]: ../BinomialModel.pdf 8 | -------------------------------------------------------------------------------- /P00_sw/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: P00_sw", 4 | "overview": [ "SW Model" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin sw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config_1_Thread.txt", 11 | "contributors" : [ 12 | { 13 | "group": "Xilinx", 14 | "url" : "http://www.xilinx.com" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /P00_sw/src/K0.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include "kernel.h" 20 | #include "math.h" 21 | 22 | // ============================================================================================================ // 23 | // ------------------------------------------------------------------------------------------------------------ // 24 | // HW Implementation 25 | // ------------------------------------------------------------------------------------------------------------ // 26 | // ============================================================================================================ // 27 | 28 | float hw_calc_p0_0 (t_in_data in_d) { 29 | #pragma HLS INLINE off 30 | #pragma HLS DATA_PACK variable=in_d 31 | 32 | float p[CONST_MAX_TREE_HEIGHT]; 33 | 34 | int T; float S; float K; float r; float sigma; float q; int n; 35 | float deltaT, up, p0, p1, exercise; 36 | 37 | // ------------------------------- 38 | // in_d -> individual variables 39 | // ------------------------------- 40 | T = in_d.T; S = in_d.S; K = in_d.K; r = in_d.r; sigma = in_d.sigma; q = in_d.q; n = in_d.n; 41 | 42 | // ------------------------------- 43 | // Start Calculation 44 | // ------------------------------- 45 | deltaT = (float) T / n; 46 | up = expf(sigma * sqrtf(deltaT)); 47 | 48 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 49 | p1 = expf(-r * deltaT) - p0; 50 | 51 | // ------------------------------- 52 | // initial values at time T 53 | // ------------------------------- 54 | loop_init: for (int i = 0; i < n; i++) { 55 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 56 | 57 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 58 | if (p[i] < 0) p[i] = 0; 59 | } 60 | 61 | // ------------------------------- 62 | // move to earlier times 63 | // ------------------------------- 64 | loop_j: for (int j = n-1; j > 0; j--) { 65 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 66 | 67 | loop_i: for (int i = 0; i < j; i++) { 68 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 69 | 70 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 71 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 72 | if (p[i] < exercise) p[i] = exercise; 73 | } 74 | } 75 | 76 | return(p[0]); 77 | } 78 | 79 | 80 | // ================================================================================ // 81 | 82 | extern "C" { 83 | void K_americanPut_0(t_in_data* IN_Data, float* Res) { 84 | 85 | // ---------------------------------------------------------------------------- // 86 | #pragma HLS INTERFACE s_axilite port=IN_Data bundle=control 87 | #pragma HLS INTERFACE s_axilite port=Res bundle=control 88 | #pragma HLS INTERFACE s_axilite port=return bundle=control 89 | 90 | #pragma HLS INTERFACE m_axi port=IN_Data offset=slave bundle=gmem_0 91 | #pragma HLS INTERFACE m_axi port=Res offset=slave bundle=gmem_1 92 | 93 | #pragma HLS DATA_PACK variable=IN_Data 94 | // ---------------------------------------------------------------------------- // 95 | 96 | 97 | // ------------------------------------- 98 | // Calculate 99 | // ------------------------------------- 100 | Res[0] = hw_calc_p0_0(IN_Data[0]); 101 | 102 | } 103 | } 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /P00_sw/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include "kernel.h" 31 | 32 | using namespace std; 33 | 34 | 35 | typedef struct { 36 | // ------------------------------------------------ 37 | // Binomial settings 38 | // ------------------------------------------------ 39 | string Company_Name; // set in a Test config file 40 | int T; // set in a Test config file 41 | float S, K, r, sigma, q; // set in a Test config file 42 | int n; // set in a Test config file 43 | 44 | // ------------------------------------------------ 45 | // Test Vectors configuration 46 | // ------------------------------------------------ 47 | float K_Step; // set in a Test config file 48 | int NB_OF_TESTS; // set in a Test config file 49 | 50 | // ------------------------------------------------ 51 | // Debug Information 52 | // ------------------------------------------------ 53 | string File_Name; // Config file name 54 | int Line_Nb; // Line Nb in Config file 55 | 56 | } test_config_t; 57 | 58 | 59 | typedef struct { 60 | // ------------------------------------------------ 61 | // SW Resources to be used 62 | // ------------------------------------------------ 63 | int NB_OF_THREADS; // set in a SW_HW_config file 64 | 65 | // ------------------------------------------------ 66 | // Hardware Resources: Available & to be used 67 | // ------------------------------------------------ 68 | int NB_OF_KERNELS; // set in a SW_HW_config file 69 | int NB_OF_CUs_PER_KERNEL; // set in a SW_HW_config file 70 | int NB_OF_PARALLEL_FUNCTIONS_PER_CU; // set in a SW_HW_config file 71 | int MAX_TREE_HEIGHT; // Set during Host Code execution. Max height of a Binomial tree supported by a Kernel (defined during kernel implementation) 72 | int MAX_NB_OF_TESTS; // Set during Host Code execution. Max number of test vectors supported by the application 73 | 74 | // ------------------------------------------------ 75 | // Debug Information 76 | // ------------------------------------------------ 77 | string File_Name; // Config file name 78 | int Line_Nb; // Line Nb in Config file 79 | } sw_hw_config_t; 80 | 81 | 82 | 83 | void read_sw_hw_config_file (const char* SW_HW_Config_File_Name, sw_hw_config_t* SW_HW_Config); 84 | void print_sw_hw_config_info(sw_hw_config_t SW_HW_Config); 85 | 86 | void read_test_config_file (const char* Test_Config_File_Name, vector *Test_Config); 87 | void print_test_config_info(vector *Test_Config); 88 | 89 | void process_configurations(string sw_hw, sw_hw_config_t* SW_HW_Config, vector* Test_Config, int *DEFINED_NB_OF_TESTS, int *ROUNDED_NB_OF_TESTS); 90 | void generate_test_vectors(t_in_data* host_IN_DATA, vector Test_Config, int ROUNDED_NB_OF_TESTS); 91 | 92 | // ======================================================= 93 | // Helper Function: Allocate HOST Memory aligned to 4096 94 | // ======================================================= 95 | template 96 | T* allocate_host_mem(size_t number_of_elements, string mem_name, bool print_message) { 97 | void *ptr=nullptr; 98 | 99 | if (print_message == true) 100 | cout << "HOST-Info: Allocating Host Memory for " << mem_name << " ... " << endl; 101 | 102 | if (posix_memalign(&ptr,4096,number_of_elements*sizeof(T))) { 103 | cout << endl << "HOST-Error: Out of Memory during memory allocation for " << mem_name << " array" << endl << endl; 104 | exit(0); 105 | } 106 | return reinterpret_cast(ptr); 107 | } 108 | 109 | double run_custom_profiling (int Nb_Of_Kernels, int Nb_Of_Memory_Tranfers, cl_event* K_exe_event, cl_event* Mem_op_event,string* list_of_kernel_names); 110 | 111 | int compare_results(float* sw_Res, float* hw_Res, int Nb_of_Results, int Nb_Of_Errors_To_Reports); 112 | int cmp_floats(float val1, float val2); 113 | 114 | void store_results(string SW_HW_Mode, string Out_File_Name, t_in_data* host_IN_DATA, float* hw_res, vector* Test_Config); 115 | #endif 116 | -------------------------------------------------------------------------------- /P00_sw/src/host_functions.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | void ocl_check_status(cl_int err, string error_msg); 20 | 21 | int loadFile2Memory(const char *filename, char **result); 22 | 23 | int select_platform (cl_platform_id *Platform_IDs, cl_platform_id *Target_Platform_ID, const char *Target_Platform_Name); 24 | int select_device (cl_device_id *Device_IDs, cl_device_id *Target_Device_ID, cl_platform_id Target_Platform_ID, const char *Target_Device_Name); 25 | 26 | int create_context(cl_context *Context, cl_device_id Target_Device_ID); 27 | int create_command_queue(cl_context *Context, cl_command_queue *Command_Queue, cl_command_queue_properties Command_Queue_Properties, cl_device_id Target_Device_ID); 28 | 29 | int build_program(cl_program *Program, const char *XCLBIN_File_Name, cl_device_id Target_Device_ID, cl_context Context); 30 | int create_kernel(cl_program Program, cl_kernel *Kernel, const char *Kernel_Name); 31 | 32 | -------------------------------------------------------------------------------- /P00_sw/src/kernel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #ifndef __KERNEL_H__ 20 | #define __KERNEL_H__ 21 | 22 | #define CONST_MAX_TREE_HEIGHT 1024 23 | #define CONST_MAX_NB_OF_TESTS 1024 24 | 25 | typedef struct { 26 | int T; float S; float K; float r; float sigma; float q; int n; 27 | float dummy_val; 28 | } t_in_data; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /P00_sw/src/sw_hw_config_1_Thread.txt: -------------------------------------------------------------------------------- 1 | # /***************************************************************************** 2 | # 3 | # Copyright (c) 2019, Xilinx, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ******************************************************************************/ 18 | 19 | # ----------------------------------------------------------------------------------------------- 20 | # SW Resources || Available HW Resources || 21 | # -----------------++--------------------------------------------------------------------------++ 22 | # NB_OF_THREADS || NB_KERNELS | NB_OF_CUs_PER_KERNEL | NB_OF_PARALLEL_FUNCTIONS_PER_CU || 23 | # -----------------++-------------+------------------------+-----------------------------------++ 24 | 1 1 1 1 25 | # -----------------++-------------+------------------------+-----------------------------------++ 26 | 27 | 28 | # ============================================================================================================== 29 | # Notes: 30 | # ============================================================================================================== 31 | 32 | # IMPORTANT: All values should be >0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /P00_sw/src/sw_hw_config_M_Thread.txt: -------------------------------------------------------------------------------- 1 | # /***************************************************************************** 2 | # 3 | # Copyright (c) 2019, Xilinx, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ******************************************************************************/ 18 | 19 | # ----------------------------------------------------------------------------------------------- 20 | # SW Resources || Available HW Resources || 21 | # -----------------++--------------------------------------------------------------------------++ 22 | # NB_OF_THREADS || NB_KERNELS | NB_OF_CUs_PER_KERNEL | NB_OF_PARALLEL_FUNCTIONS_PER_CU || 23 | # -----------------++-------------+------------------------+-----------------------------------++ 24 | 12 1 1 1 25 | # -----------------++-------------+------------------------+-----------------------------------++ 26 | 27 | 28 | # ============================================================================================================== 29 | # Notes: 30 | # ============================================================================================================== 31 | 32 | # IMPORTANT: All values should be >0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /P10_hw_Original/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: P10_hw_Original 2 | 3 | This project represents the original Binomial Model kernel implementation targeting the Alveo card. In this project the entire application is organized as a purely sequential process: input data transfer from Host to Global Memory, Kernel execution and result transfer from Global to Host memory is done for each single test vector: 4 | 5 | Data 1 (Host->Global) => Kernel => Result 1 (Global -> Host) => Data 2 (Host->Global) => Kernel => Result 2 (Global -> Host) => … 6 | 7 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 8 | 9 | [BinomialModel.pdf]: ../BinomialModel.pdf 10 | -------------------------------------------------------------------------------- /P10_hw_Original/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: P10_hw_Original", 4 | "overview": [ "Original HW Kernel: 1 Compute Unit" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "clflags": "-O2" 20 | } 21 | ] 22 | } 23 | ], 24 | "contributors" : [ 25 | { 26 | "group": "Xilinx", 27 | "url" : "http://www.xilinx.com" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /P10_hw_Original/src/K0.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include "kernel.h" 20 | #include "math.h" 21 | 22 | // ============================================================================================================ // 23 | // ------------------------------------------------------------------------------------------------------------ // 24 | // HW Implementation 25 | // ------------------------------------------------------------------------------------------------------------ // 26 | // ============================================================================================================ // 27 | 28 | float hw_calc_p0_0 (t_in_data in_d) { 29 | #pragma HLS INLINE off 30 | #pragma HLS DATA_PACK variable=in_d 31 | 32 | float p[CONST_MAX_TREE_HEIGHT]; 33 | 34 | int T; float S; float K; float r; float sigma; float q; int n; 35 | float deltaT, up, p0, p1, exercise; 36 | 37 | // ------------------------------- 38 | // in_d -> individual variables 39 | // ------------------------------- 40 | T = in_d.T; S = in_d.S; K = in_d.K; r = in_d.r; sigma = in_d.sigma; q = in_d.q; n = in_d.n; 41 | 42 | // ------------------------------- 43 | // Start Calculation 44 | // ------------------------------- 45 | deltaT = (float) T / n; 46 | up = expf(sigma * sqrtf(deltaT)); 47 | 48 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 49 | p1 = expf(-r * deltaT) - p0; 50 | 51 | // ------------------------------- 52 | // initial values at time T 53 | // ------------------------------- 54 | loop_init: for (int i = 0; i < n; i++) { 55 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 56 | 57 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 58 | if (p[i] < 0) p[i] = 0; 59 | } 60 | 61 | // ------------------------------- 62 | // move to earlier times 63 | // ------------------------------- 64 | loop_j: for (int j = n-1; j > 0; j--) { 65 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 66 | 67 | loop_i: for (int i = 0; i < j; i++) { 68 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 69 | 70 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 71 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 72 | if (p[i] < exercise) p[i] = exercise; 73 | } 74 | } 75 | 76 | return(p[0]); 77 | } 78 | 79 | 80 | // ================================================================================ // 81 | 82 | extern "C" { 83 | void K_americanPut_0(t_in_data* IN_Data, float* Res) { 84 | 85 | // ---------------------------------------------------------------------------- // 86 | #pragma HLS INTERFACE s_axilite port=IN_Data bundle=control 87 | #pragma HLS INTERFACE s_axilite port=Res bundle=control 88 | #pragma HLS INTERFACE s_axilite port=return bundle=control 89 | 90 | #pragma HLS INTERFACE m_axi port=IN_Data offset=slave bundle=gmem_0 91 | #pragma HLS INTERFACE m_axi port=Res offset=slave bundle=gmem_1 92 | 93 | #pragma HLS DATA_PACK variable=IN_Data 94 | // ---------------------------------------------------------------------------- // 95 | 96 | 97 | // ------------------------------------- 98 | // Calculate 99 | // ------------------------------------- 100 | Res[0] = hw_calc_p0_0(IN_Data[0]); 101 | 102 | } 103 | } 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /P10_hw_Original/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include "kernel.h" 31 | 32 | using namespace std; 33 | 34 | 35 | typedef struct { 36 | // ------------------------------------------------ 37 | // Binomial settings 38 | // ------------------------------------------------ 39 | string Company_Name; // set in a Test config file 40 | int T; // set in a Test config file 41 | float S, K, r, sigma, q; // set in a Test config file 42 | int n; // set in a Test config file 43 | 44 | // ------------------------------------------------ 45 | // Test Vectors configuration 46 | // ------------------------------------------------ 47 | float K_Step; // set in a Test config file 48 | int NB_OF_TESTS; // set in a Test config file 49 | 50 | // ------------------------------------------------ 51 | // Debug Information 52 | // ------------------------------------------------ 53 | string File_Name; // Config file name 54 | int Line_Nb; // Line Nb in Config file 55 | 56 | } test_config_t; 57 | 58 | 59 | typedef struct { 60 | // ------------------------------------------------ 61 | // SW Resources to be used 62 | // ------------------------------------------------ 63 | int NB_OF_THREADS; // set in a SW_HW_config file 64 | 65 | // ------------------------------------------------ 66 | // Hardware Resources: Available & to be used 67 | // ------------------------------------------------ 68 | int NB_OF_KERNELS; // set in a SW_HW_config file 69 | int NB_OF_CUs_PER_KERNEL; // set in a SW_HW_config file 70 | int NB_OF_PARALLEL_FUNCTIONS_PER_CU; // set in a SW_HW_config file 71 | int MAX_TREE_HEIGHT; // Set during Host Code execution. Max height of a Binomial tree supported by a Kernel (defined during kernel implementation) 72 | int MAX_NB_OF_TESTS; // Set during Host Code execution. Max number of test vectors supported by the application 73 | 74 | // ------------------------------------------------ 75 | // Debug Information 76 | // ------------------------------------------------ 77 | string File_Name; // Config file name 78 | int Line_Nb; // Line Nb in Config file 79 | } sw_hw_config_t; 80 | 81 | 82 | 83 | void read_sw_hw_config_file (const char* SW_HW_Config_File_Name, sw_hw_config_t* SW_HW_Config); 84 | void print_sw_hw_config_info(sw_hw_config_t SW_HW_Config); 85 | 86 | void read_test_config_file (const char* Test_Config_File_Name, vector *Test_Config); 87 | void print_test_config_info(vector *Test_Config); 88 | 89 | void process_configurations(string sw_hw, sw_hw_config_t* SW_HW_Config, vector* Test_Config, int *DEFINED_NB_OF_TESTS, int *ROUNDED_NB_OF_TESTS); 90 | void generate_test_vectors(t_in_data* host_IN_DATA, vector Test_Config, int ROUNDED_NB_OF_TESTS); 91 | 92 | // ======================================================= 93 | // Helper Function: Allocate HOST Memory aligned to 4096 94 | // ======================================================= 95 | template 96 | T* allocate_host_mem(size_t number_of_elements, string mem_name, bool print_message) { 97 | void *ptr=nullptr; 98 | 99 | if (print_message == true) 100 | cout << "HOST-Info: Allocating Host Memory for " << mem_name << " ... " << endl; 101 | 102 | if (posix_memalign(&ptr,4096,number_of_elements*sizeof(T))) { 103 | cout << endl << "HOST-Error: Out of Memory during memory allocation for " << mem_name << " array" << endl << endl; 104 | exit(0); 105 | } 106 | return reinterpret_cast(ptr); 107 | } 108 | 109 | double run_custom_profiling (int Nb_Of_Kernels, int Nb_Of_Memory_Tranfers, cl_event* K_exe_event, cl_event* Mem_op_event,string* list_of_kernel_names); 110 | 111 | int compare_results(float* sw_Res, float* hw_Res, int Nb_of_Results, int Nb_Of_Errors_To_Reports); 112 | int cmp_floats(float val1, float val2); 113 | 114 | void store_results(string SW_HW_Mode, string Out_File_Name, t_in_data* host_IN_DATA, float* hw_res, vector* Test_Config); 115 | #endif 116 | -------------------------------------------------------------------------------- /P10_hw_Original/src/host_functions.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | void ocl_check_status(cl_int err, string error_msg); 20 | 21 | int loadFile2Memory(const char *filename, char **result); 22 | 23 | int select_platform (cl_platform_id *Platform_IDs, cl_platform_id *Target_Platform_ID, const char *Target_Platform_Name); 24 | int select_device (cl_device_id *Device_IDs, cl_device_id *Target_Device_ID, cl_platform_id Target_Platform_ID, const char *Target_Device_Name); 25 | 26 | int create_context(cl_context *Context, cl_device_id Target_Device_ID); 27 | int create_command_queue(cl_context *Context, cl_command_queue *Command_Queue, cl_command_queue_properties Command_Queue_Properties, cl_device_id Target_Device_ID); 28 | 29 | int build_program(cl_program *Program, const char *XCLBIN_File_Name, cl_device_id Target_Device_ID, cl_context Context); 30 | int create_kernel(cl_program Program, cl_kernel *Kernel, const char *Kernel_Name); 31 | 32 | -------------------------------------------------------------------------------- /P10_hw_Original/src/kernel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #ifndef __KERNEL_H__ 20 | #define __KERNEL_H__ 21 | 22 | #define CONST_MAX_TREE_HEIGHT 1024 23 | #define CONST_MAX_NB_OF_TESTS 1024 24 | 25 | typedef struct { 26 | int T; float S; float K; float r; float sigma; float q; int n; 27 | float dummy_val; 28 | } t_in_data; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /P10_hw_Original/src/sw_hw_config.txt: -------------------------------------------------------------------------------- 1 | # /***************************************************************************** 2 | # 3 | # Copyright (c) 2019, Xilinx, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ******************************************************************************/ 18 | 19 | # ----------------------------------------------------------------------------------------------- 20 | # SW Resources || Available HW Resources || 21 | # -----------------++--------------------------------------------------------------------------++ 22 | # NB_OF_THREADS || NB_KERNELS | NB_OF_CUs_PER_KERNEL | NB_OF_PARALLEL_FUNCTIONS_PER_CU || 23 | # -----------------++-------------+------------------------+-----------------------------------++ 24 | 1 1 1 1 25 | # -----------------++-------------+------------------------+-----------------------------------++ 26 | 27 | 28 | # ============================================================================================================== 29 | # Notes: 30 | # ============================================================================================================== 31 | 32 | # IMPORTANT: All values should be >0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: P11_hw_Original_HostOpt 2 | 3 | In this project, using the same original Binomial Model kernel implementation (represented in P10_hw_Original) we improve the performance by overlapping data transfer with kernel execution (host code optimization). 4 | 5 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 6 | 7 | [BinomialModel.pdf]: ../BinomialModel.pdf 8 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: P11_hw_Original_HostOpt", 4 | "overview": [ "Optimized Host with Original HW Kernel: 1 Compute Unit" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ${project_loc:P10_hw_Original}/${config_name:P11_hw_Original_HostOpt}/binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "contributors" : [ 12 | { 13 | "group": "Xilinx", 14 | "url" : "http://www.xilinx.com" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/src/K0.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include "kernel.h" 20 | #include "math.h" 21 | 22 | // ============================================================================================================ // 23 | // ------------------------------------------------------------------------------------------------------------ // 24 | // HW Implementation 25 | // ------------------------------------------------------------------------------------------------------------ // 26 | // ============================================================================================================ // 27 | 28 | float hw_calc_p0_0 (t_in_data in_d) { 29 | #pragma HLS INLINE off 30 | #pragma HLS DATA_PACK variable=in_d 31 | 32 | float p[CONST_MAX_TREE_HEIGHT]; 33 | 34 | int T; float S; float K; float r; float sigma; float q; int n; 35 | float deltaT, up, p0, p1, exercise; 36 | 37 | // ------------------------------- 38 | // in_d -> individual variables 39 | // ------------------------------- 40 | T = in_d.T; S = in_d.S; K = in_d.K; r = in_d.r; sigma = in_d.sigma; q = in_d.q; n = in_d.n; 41 | 42 | // ------------------------------- 43 | // Start Calculation 44 | // ------------------------------- 45 | deltaT = (float) T / n; 46 | up = expf(sigma * sqrtf(deltaT)); 47 | 48 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 49 | p1 = expf(-r * deltaT) - p0; 50 | 51 | // ------------------------------- 52 | // initial values at time T 53 | // ------------------------------- 54 | loop_init: for (int i = 0; i < n; i++) { 55 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 56 | 57 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 58 | if (p[i] < 0) p[i] = 0; 59 | } 60 | 61 | // ------------------------------- 62 | // move to earlier times 63 | // ------------------------------- 64 | loop_j: for (int j = n-1; j > 0; j--) { 65 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 66 | 67 | loop_i: for (int i = 0; i < j; i++) { 68 | #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 69 | 70 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 71 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 72 | if (p[i] < exercise) p[i] = exercise; 73 | } 74 | } 75 | 76 | return(p[0]); 77 | } 78 | 79 | 80 | // ================================================================================ // 81 | 82 | extern "C" { 83 | void K_americanPut_0(t_in_data* IN_Data, float* Res) { 84 | 85 | // ---------------------------------------------------------------------------- // 86 | #pragma HLS INTERFACE s_axilite port=IN_Data bundle=control 87 | #pragma HLS INTERFACE s_axilite port=Res bundle=control 88 | #pragma HLS INTERFACE s_axilite port=return bundle=control 89 | 90 | #pragma HLS INTERFACE m_axi port=IN_Data offset=slave bundle=gmem_0 91 | #pragma HLS INTERFACE m_axi port=Res offset=slave bundle=gmem_1 92 | 93 | #pragma HLS DATA_PACK variable=IN_Data 94 | // ---------------------------------------------------------------------------- // 95 | 96 | 97 | // ------------------------------------- 98 | // Calculate 99 | // ------------------------------------- 100 | Res[0] = hw_calc_p0_0(IN_Data[0]); 101 | 102 | } 103 | } 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include "kernel.h" 31 | 32 | using namespace std; 33 | 34 | 35 | typedef struct { 36 | // ------------------------------------------------ 37 | // Binomial settings 38 | // ------------------------------------------------ 39 | string Company_Name; // set in a Test config file 40 | int T; // set in a Test config file 41 | float S, K, r, sigma, q; // set in a Test config file 42 | int n; // set in a Test config file 43 | 44 | // ------------------------------------------------ 45 | // Test Vectors configuration 46 | // ------------------------------------------------ 47 | float K_Step; // set in a Test config file 48 | int NB_OF_TESTS; // set in a Test config file 49 | 50 | // ------------------------------------------------ 51 | // Debug Information 52 | // ------------------------------------------------ 53 | string File_Name; // Config file name 54 | int Line_Nb; // Line Nb in Config file 55 | 56 | } test_config_t; 57 | 58 | 59 | typedef struct { 60 | // ------------------------------------------------ 61 | // SW Resources to be used 62 | // ------------------------------------------------ 63 | int NB_OF_THREADS; // set in a SW_HW_config file 64 | 65 | // ------------------------------------------------ 66 | // Hardware Resources: Available & to be used 67 | // ------------------------------------------------ 68 | int NB_OF_KERNELS; // set in a SW_HW_config file 69 | int NB_OF_CUs_PER_KERNEL; // set in a SW_HW_config file 70 | int NB_OF_PARALLEL_FUNCTIONS_PER_CU; // set in a SW_HW_config file 71 | int MAX_TREE_HEIGHT; // Set during Host Code execution. Max height of a Binomial tree supported by a Kernel (defined during kernel implementation) 72 | int MAX_NB_OF_TESTS; // Set during Host Code execution. Max number of test vectors supported by the application 73 | 74 | // ------------------------------------------------ 75 | // Debug Information 76 | // ------------------------------------------------ 77 | string File_Name; // Config file name 78 | int Line_Nb; // Line Nb in Config file 79 | } sw_hw_config_t; 80 | 81 | 82 | 83 | void read_sw_hw_config_file (const char* SW_HW_Config_File_Name, sw_hw_config_t* SW_HW_Config); 84 | void print_sw_hw_config_info(sw_hw_config_t SW_HW_Config); 85 | 86 | void read_test_config_file (const char* Test_Config_File_Name, vector *Test_Config); 87 | void print_test_config_info(vector *Test_Config); 88 | 89 | void process_configurations(string sw_hw, sw_hw_config_t* SW_HW_Config, vector* Test_Config, int *DEFINED_NB_OF_TESTS, int *ROUNDED_NB_OF_TESTS); 90 | void generate_test_vectors(t_in_data* host_IN_DATA, vector Test_Config, int ROUNDED_NB_OF_TESTS); 91 | 92 | // ======================================================= 93 | // Helper Function: Allocate HOST Memory aligned to 4096 94 | // ======================================================= 95 | template 96 | T* allocate_host_mem(size_t number_of_elements, string mem_name, bool print_message) { 97 | void *ptr=nullptr; 98 | 99 | if (print_message == true) 100 | cout << "HOST-Info: Allocating Host Memory for " << mem_name << " ... " << endl; 101 | 102 | if (posix_memalign(&ptr,4096,number_of_elements*sizeof(T))) { 103 | cout << endl << "HOST-Error: Out of Memory during memory allocation for " << mem_name << " array" << endl << endl; 104 | exit(0); 105 | } 106 | return reinterpret_cast(ptr); 107 | } 108 | 109 | double run_custom_profiling (int Nb_Of_Kernels, int Nb_Of_Memory_Tranfers, cl_event* K_exe_event, cl_event* Mem_op_event,string* list_of_kernel_names); 110 | 111 | int compare_results(float* sw_Res, float* hw_Res, int Nb_of_Results, int Nb_Of_Errors_To_Reports); 112 | int cmp_floats(float val1, float val2); 113 | 114 | void store_results(string SW_HW_Mode, string Out_File_Name, t_in_data* host_IN_DATA, float* hw_res, vector* Test_Config); 115 | #endif 116 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/src/host_functions.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | void ocl_check_status(cl_int err, string error_msg); 20 | 21 | int loadFile2Memory(const char *filename, char **result); 22 | 23 | int select_platform (cl_platform_id *Platform_IDs, cl_platform_id *Target_Platform_ID, const char *Target_Platform_Name); 24 | int select_device (cl_device_id *Device_IDs, cl_device_id *Target_Device_ID, cl_platform_id Target_Platform_ID, const char *Target_Device_Name); 25 | 26 | int create_context(cl_context *Context, cl_device_id Target_Device_ID); 27 | int create_command_queue(cl_context *Context, cl_command_queue *Command_Queue, cl_command_queue_properties Command_Queue_Properties, cl_device_id Target_Device_ID); 28 | 29 | int build_program(cl_program *Program, const char *XCLBIN_File_Name, cl_device_id Target_Device_ID, cl_context Context); 30 | int create_kernel(cl_program Program, cl_kernel *Kernel, const char *Kernel_Name); 31 | 32 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/src/kernel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #ifndef __KERNEL_H__ 20 | #define __KERNEL_H__ 21 | 22 | #define CONST_MAX_TREE_HEIGHT 1024 23 | #define CONST_MAX_NB_OF_TESTS 1024 24 | 25 | typedef struct { 26 | int T; float S; float K; float r; float sigma; float q; int n; 27 | float dummy_val; 28 | } t_in_data; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /P11_hw_Original_HostOpt/src/sw_hw_config.txt: -------------------------------------------------------------------------------- 1 | # /***************************************************************************** 2 | # 3 | # Copyright (c) 2019, Xilinx, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ******************************************************************************/ 18 | 19 | # ----------------------------------------------------------------------------------------------- 20 | # SW Resources || Available HW Resources || 21 | # -----------------++--------------------------------------------------------------------------++ 22 | # NB_OF_THREADS || NB_KERNELS | NB_OF_CUs_PER_KERNEL | NB_OF_PARALLEL_FUNCTIONS_PER_CU || 23 | # -----------------++-------------+------------------------+-----------------------------------++ 24 | 1 1 1 1 25 | # -----------------++-------------+------------------------+-----------------------------------++ 26 | 27 | 28 | # ============================================================================================================== 29 | # Notes: 30 | # ============================================================================================================== 31 | 32 | # IMPORTANT: All values should be >0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /P12_hw_KOpt/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: P12_hw_KOpt 2 | 3 | This project contains the same source files used in Popt_12_step4_UNROLL and exclusively used to compile and run the design in a System Run mode. 4 | 5 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 6 | 7 | [BinomialModel.pdf]: ../BinomialModel.pdf 8 | -------------------------------------------------------------------------------- /P12_hw_KOpt/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: P12_hw_KOpt", 4 | "overview": [ "Optimized HW Kernel: 1 Compute Unit" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "clflags": "-O2" 20 | } 21 | ] 22 | } 23 | ], 24 | "contributors" : [ 25 | { 26 | "group": "Xilinx", 27 | "url" : "http://www.xilinx.com" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /P12_hw_KOpt/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include "kernel.h" 31 | 32 | using namespace std; 33 | 34 | 35 | typedef struct { 36 | // ------------------------------------------------ 37 | // Binomial settings 38 | // ------------------------------------------------ 39 | string Company_Name; // set in a Test config file 40 | int T; // set in a Test config file 41 | float S, K, r, sigma, q; // set in a Test config file 42 | int n; // set in a Test config file 43 | 44 | // ------------------------------------------------ 45 | // Test Vectors configuration 46 | // ------------------------------------------------ 47 | float K_Step; // set in a Test config file 48 | int NB_OF_TESTS; // set in a Test config file 49 | 50 | // ------------------------------------------------ 51 | // Debug Information 52 | // ------------------------------------------------ 53 | string File_Name; // Config file name 54 | int Line_Nb; // Line Nb in Config file 55 | 56 | } test_config_t; 57 | 58 | 59 | typedef struct { 60 | // ------------------------------------------------ 61 | // SW Resources to be used 62 | // ------------------------------------------------ 63 | int NB_OF_THREADS; // set in a SW_HW_config file 64 | 65 | // ------------------------------------------------ 66 | // Hardware Resources: Available & to be used 67 | // ------------------------------------------------ 68 | int NB_OF_KERNELS; // set in a SW_HW_config file 69 | int NB_OF_CUs_PER_KERNEL; // set in a SW_HW_config file 70 | int NB_OF_PARALLEL_FUNCTIONS_PER_CU; // set in a SW_HW_config file 71 | int MAX_TREE_HEIGHT; // Set during Host Code execution. Max height of a Binomial tree supported by a Kernel (defined during kernel implementation) 72 | int MAX_NB_OF_TESTS; // Set during Host Code execution. Max number of test vectors supported by the application 73 | 74 | // ------------------------------------------------ 75 | // Debug Information 76 | // ------------------------------------------------ 77 | string File_Name; // Config file name 78 | int Line_Nb; // Line Nb in Config file 79 | } sw_hw_config_t; 80 | 81 | 82 | 83 | void read_sw_hw_config_file (const char* SW_HW_Config_File_Name, sw_hw_config_t* SW_HW_Config); 84 | void print_sw_hw_config_info(sw_hw_config_t SW_HW_Config); 85 | 86 | void read_test_config_file (const char* Test_Config_File_Name, vector *Test_Config); 87 | void print_test_config_info(vector *Test_Config); 88 | 89 | void process_configurations(string sw_hw, sw_hw_config_t* SW_HW_Config, vector* Test_Config, int *DEFINED_NB_OF_TESTS, int *ROUNDED_NB_OF_TESTS); 90 | void generate_test_vectors(t_in_data* host_IN_DATA, vector Test_Config, int ROUNDED_NB_OF_TESTS); 91 | 92 | // ======================================================= 93 | // Helper Function: Allocate HOST Memory aligned to 4096 94 | // ======================================================= 95 | template 96 | T* allocate_host_mem(size_t number_of_elements, string mem_name, bool print_message) { 97 | void *ptr=nullptr; 98 | 99 | if (print_message == true) 100 | cout << "HOST-Info: Allocating Host Memory for " << mem_name << " ... " << endl; 101 | 102 | if (posix_memalign(&ptr,4096,number_of_elements*sizeof(T))) { 103 | cout << endl << "HOST-Error: Out of Memory during memory allocation for " << mem_name << " array" << endl << endl; 104 | exit(0); 105 | } 106 | return reinterpret_cast(ptr); 107 | } 108 | 109 | double run_custom_profiling (int Nb_Of_Kernels, int Nb_Of_Memory_Tranfers, cl_event* K_exe_event, cl_event* Mem_op_event,string* list_of_kernel_names); 110 | 111 | int compare_results(float* sw_Res, float* hw_Res, int Nb_of_Results, int Nb_Of_Errors_To_Reports); 112 | int cmp_floats(float val1, float val2); 113 | 114 | void store_results(string SW_HW_Mode, string Out_File_Name, t_in_data* host_IN_DATA, float* hw_res, vector* Test_Config); 115 | #endif 116 | -------------------------------------------------------------------------------- /P12_hw_KOpt/src/host_functions.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | void ocl_check_status(cl_int err, string error_msg); 20 | 21 | int loadFile2Memory(const char *filename, char **result); 22 | 23 | int select_platform (cl_platform_id *Platform_IDs, cl_platform_id *Target_Platform_ID, const char *Target_Platform_Name); 24 | int select_device (cl_device_id *Device_IDs, cl_device_id *Target_Device_ID, cl_platform_id Target_Platform_ID, const char *Target_Device_Name); 25 | 26 | int create_context(cl_context *Context, cl_device_id Target_Device_ID); 27 | int create_command_queue(cl_context *Context, cl_command_queue *Command_Queue, cl_command_queue_properties Command_Queue_Properties, cl_device_id Target_Device_ID); 28 | 29 | int build_program(cl_program *Program, const char *XCLBIN_File_Name, cl_device_id Target_Device_ID, cl_context Context); 30 | int create_kernel(cl_program Program, cl_kernel *Kernel, const char *Kernel_Name); 31 | 32 | -------------------------------------------------------------------------------- /P12_hw_KOpt/src/kernel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #ifndef __KERNEL_H__ 20 | #define __KERNEL_H__ 21 | 22 | #define CONST_MAX_TREE_HEIGHT 1024 23 | #define CONST_MAX_NB_OF_TESTS 1024 24 | 25 | typedef struct { 26 | int T; float S; float K; float r; float sigma; float q; int n; 27 | float dummy_val; 28 | } t_in_data; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /P12_hw_KOpt/src/sw_hw_config.txt: -------------------------------------------------------------------------------- 1 | # /***************************************************************************** 2 | # 3 | # Copyright (c) 2019, Xilinx, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ******************************************************************************/ 18 | 19 | # ----------------------------------------------------------------------------------------------- 20 | # SW Resources || Available HW Resources || 21 | # -----------------++--------------------------------------------------------------------------++ 22 | # NB_OF_THREADS || NB_KERNELS | NB_OF_CUs_PER_KERNEL | NB_OF_PARALLEL_FUNCTIONS_PER_CU || 23 | # -----------------++-------------+------------------------+-----------------------------------++ 24 | 1 1 1 4 25 | # -----------------++-------------+------------------------+-----------------------------------++ 26 | 27 | 28 | # ============================================================================================================== 29 | # Notes: 30 | # ============================================================================================================== 31 | 32 | # IMPORTANT: All values should be >0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /P13_hw_KOpt_8CU_2DDRs/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: P13_hw_KOpt_8CU_2DDRs 2 | 3 | Another method to further accelerate your application is to instantiate multiple compute units (CU) on Alveo card. In addition, connecting different compute units to different DDR banks can be very beneficial to improve the performance if significant amount of data should be transferred between compute units and Global Memory. 4 | 5 | This project demonstrates the both techniques, by implementing 8 CUs: 4 CUs are connected to the DDR[0] and another 4 CUs are connected to the DDR[3] banks. 6 | 7 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 8 | 9 | [BinomialModel.pdf]: ../BinomialModel.pdf 10 | -------------------------------------------------------------------------------- /P13_hw_KOpt_8CU_2DDRs/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: P13_hw_KOpt_8CU_2DDRs", 4 | "overview": [ "Optimized HW Kernel: 2 Kernels, 8 Compute Units, 2 DDRs" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2 --sp K_americanPut_0_1.IN_Data:DDR[0] --sp K_americanPut_0_1.Res:DDR[0] --sp K_americanPut_0_2.IN_Data:DDR[0] --sp K_americanPut_0_2.Res:DDR[0] --sp K_americanPut_0_3.IN_Data:DDR[0] --sp K_americanPut_0_3.Res:DDR[0] --sp K_americanPut_0_4.IN_Data:DDR[0] --sp K_americanPut_0_4.Res:DDR[0] --sp K_americanPut_1_1.IN_Data:DDR[3] --sp K_americanPut_1_1.Res:DDR[3] --sp K_americanPut_1_2.IN_Data:DDR[3] --sp K_americanPut_1_2.Res:DDR[3] --sp K_americanPut_1_3.IN_Data:DDR[3] --sp K_americanPut_1_3.Res:DDR[3] --sp K_americanPut_1_4.IN_Data:DDR[3] --sp K_americanPut_1_4.Res:DDR[3]", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "num_compute_units": 4, 20 | "clflags": "-O2" 21 | }, 22 | { 23 | "name": "K_americanPut_1", 24 | "location": "src/K1.cpp", 25 | "num_compute_units": 4, 26 | "clflags": "-O2" 27 | } 28 | ] 29 | } 30 | ], 31 | "contributors" : [ 32 | { 33 | "group": "Xilinx", 34 | "url" : "http://www.xilinx.com" 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /P13_hw_KOpt_8CU_2DDRs/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /P14_hw_KOpt_12CU_3DDRs/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: P14_hw_KOpt_12CU_3DDRs 2 | 3 | This project is a modification of the P13_hw_KOpt_8CU_2DDRs one. In this project to further boost the performance, we added 4 addition CUs and connected them to the DDR[2] bank. 4 | 5 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 6 | 7 | [BinomialModel.pdf]: ../BinomialModel.pdf 8 | -------------------------------------------------------------------------------- /P14_hw_KOpt_12CU_3DDRs/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: P14_hw_KOpt_12CU_3DDRs", 4 | "overview": [ "Optimized HW Kernel: 3 Kernels, 12 Compute Units, 3 DDRs" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2 --sp K_americanPut_0_1.IN_Data:DDR[0] --sp K_americanPut_0_1.Res:DDR[0] --sp K_americanPut_0_2.IN_Data:DDR[0] --sp K_americanPut_0_2.Res:DDR[0] --sp K_americanPut_0_3.IN_Data:DDR[0] --sp K_americanPut_0_3.Res:DDR[0] --sp K_americanPut_0_4.IN_Data:DDR[0] --sp K_americanPut_0_4.Res:DDR[0] --sp K_americanPut_1_1.IN_Data:DDR[2] --sp K_americanPut_1_1.Res:DDR[2] --sp K_americanPut_1_2.IN_Data:DDR[2] --sp K_americanPut_1_2.Res:DDR[2] --sp K_americanPut_1_3.IN_Data:DDR[2] --sp K_americanPut_1_3.Res:DDR[2] --sp K_americanPut_1_4.IN_Data:DDR[2] --sp K_americanPut_1_4.Res:DDR[2] --sp K_americanPut_2_1.IN_Data:DDR[3] --sp K_americanPut_2_1.Res:DDR[3] --sp K_americanPut_2_2.IN_Data:DDR[3] --sp K_americanPut_2_2.Res:DDR[3] --sp K_americanPut_2_3.IN_Data:DDR[3] --sp K_americanPut_2_3.Res:DDR[3] --sp K_americanPut_2_4.IN_Data:DDR[3] --sp K_americanPut_2_4.Res:DDR[3] ", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "num_compute_units": 4, 20 | "clflags": "-O2" 21 | }, 22 | { 23 | "name": "K_americanPut_1", 24 | "location": "src/K1.cpp", 25 | "num_compute_units": 4, 26 | "clflags": "-O2" 27 | }, 28 | { 29 | "name": "K_americanPut_2", 30 | "location": "src/K2.cpp", 31 | "num_compute_units": 4, 32 | "clflags": "-O2" 33 | } 34 | ] 35 | } 36 | ], 37 | 38 | "contributors" : [ 39 | { 40 | "group": "Xilinx", 41 | "url" : "http://www.xilinx.com" 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /P14_hw_KOpt_12CU_3DDRs/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /Popt_12_step1_DataMove/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: Popt_12_step1_DataMove 2 | 3 | To achieve significant performance acceleration we need to change the way data is transferred between Host and Global Memory and Global memory and a kernel. Such solution is represented in this project. 4 | 5 | At this step of the tutorial only SW Emulation and HW Emulation steps are used (skipping compilation for System Run). 6 | 7 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 8 | 9 | [BinomialModel.pdf]: ../BinomialModel.pdf 10 | -------------------------------------------------------------------------------- /Popt_12_step1_DataMove/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: Popt_12_step1_DataMove", 4 | "overview": [ "HW Kernel Optimization: Optimize Data Movement (1 Compute Unit)" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "clflags": "-O2" 20 | } 21 | ] 22 | } 23 | ], 24 | "contributors" : [ 25 | { 26 | "group": "Xilinx", 27 | "url" : "http://www.xilinx.com" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /Popt_12_step1_DataMove/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /Popt_12_step2_FUNx4/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: Popt_12_step2_FUNx4 2 | 3 | This project represents a 1st step of a solution allowing to process four (4) test vectors simultanously. 4 | 5 | At this step of the tutorial only SW Emulation and HW Emulation steps are used (skipping compilation for System Run). 6 | 7 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 8 | 9 | [BinomialModel.pdf]: ../BinomialModel.pdf 10 | -------------------------------------------------------------------------------- /Popt_12_step2_FUNx4/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: Popt_12_step2_FUNx4", 4 | "overview": [ "HW Kernel Optimization: Running 4 hw_calc_p0_0 functions in parallel (1 Compute Unit)" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "clflags": "-O2" 20 | } 21 | ] 22 | } 23 | ], 24 | "contributors" : [ 25 | { 26 | "group": "Xilinx", 27 | "url" : "http://www.xilinx.com" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /Popt_12_step2_FUNx4/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /Popt_12_step3_ARRAY_PARTITION/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: Popt_12_step3_ARRAY_PARTITION 2 | 3 | This project represents a 2nd step of a solution allowing to process four (4) test vectors simultaneously. 4 | 5 | At this step of the tutorial only SW Emulation and HW Emulation steps are used (skipping compilation for System Run). 6 | 7 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 8 | 9 | [BinomialModel.pdf]: ../BinomialModel.pdf 10 | -------------------------------------------------------------------------------- /Popt_12_step3_ARRAY_PARTITION/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: Popt_12_step3_ARRAY_PARTITION", 4 | "overview": [ "HW Kernel Optimization: Array Partitionning (1 Compute Unit)" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "clflags": "-O2" 20 | } 21 | ] 22 | } 23 | ], 24 | "contributors" : [ 25 | { 26 | "group": "Xilinx", 27 | "url" : "http://www.xilinx.com" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /Popt_12_step3_ARRAY_PARTITION/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /Popt_12_step4_UNROLL/README.md: -------------------------------------------------------------------------------- 1 | # Binomial Model Project: Popt_12_step4_UNROLL 2 | 3 | This project demonstrates a possibility to further improve the performance by increasing the level of parallelism via partial loop unrolling. 4 | 5 | At this step of the tutorial only SW Emulation and HW Emulation steps are used (skipping compilation for System Run). 6 | 7 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 8 | 9 | [BinomialModel.pdf]: ../BinomialModel.pdf 10 | -------------------------------------------------------------------------------- /Popt_12_step4_UNROLL/description.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtime": ["OpenCL"], 3 | "example": "BinomialModel: Popt_12_step4_UNROLL", 4 | "overview": [ "HW Kernel Optimization: Unrolling Loops (1 Compute Unit)" ], 5 | "key_concepts": [ "SDAccel Optimization", "HLS C Kernel"], 6 | "os": [ 7 | "Linux" 8 | ], 9 | "host_exe": "host", 10 | "cmd_args": "xilinx_u200_xdma_201830_2 ../binary_container_1.xclbin hw ../../src/Test_Config_Files/test_config_FULL.txt ../../src/Test_Config_Files/test_config_HW_Emu.txt ../../src/sw_hw_config.txt", 11 | "containers" : [ 12 | { 13 | "name": "binary_container_1", 14 | "ldclflags": "-O2", 15 | "accelerators": [ 16 | { 17 | "name": "K_americanPut_0", 18 | "location": "src/K0.cpp", 19 | "clflags": "-O2" 20 | } 21 | ] 22 | } 23 | ], 24 | "contributors" : [ 25 | { 26 | "group": "Xilinx", 27 | "url" : "http://www.xilinx.com" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /Popt_12_step4_UNROLL/src/SW.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | Copyright (c) 2019, Xilinx, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ******************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "kernel.h" 24 | #include "help_functions.h" 25 | #include "cmath" 26 | 27 | 28 | // ============================================================================================================ // 29 | // ------------------------------------------------------------------------------------------------------------ // 30 | // SW MODEL 31 | // ------------------------------------------------------------------------------------------------------------ // 32 | // ============================================================================================================ // 33 | 34 | float sw_calc_p0(int T, float S, float K, float r, float sigma, float q, int n) { 35 | // T... expiration time 36 | // S... stock price 37 | // K... strike price 38 | // q... dividend yield 39 | // n... height of the binomial tree 40 | 41 | float deltaT, up, p0, p1, exercise; 42 | float p[CONST_MAX_TREE_HEIGHT]; 43 | 44 | deltaT = (float) T / n; 45 | up = expf(sigma * sqrtf(deltaT)); 46 | 47 | p0 = (up*expf(-q * deltaT) - expf(-r * deltaT)) / (powf(up,2) - 1); // up^2 48 | p1 = expf(-r * deltaT) - p0; 49 | 50 | // initial values at time T 51 | for (int i = 0; i < n; i++) { 52 | p[i] = K - S * powf(up,(2*i - n)); // up^(2*i - n) 53 | if (p[i] < 0) p[i] = 0; 54 | } 55 | 56 | // move to earlier times 57 | for (int j = n-1; j > 0; j--) { 58 | for (int i = 0; i < j; i++) { 59 | p[i] = p0 * p[i+1] + p1 * p[i]; // binomial value 60 | exercise = K - S * powf(up,(2*i - j)); // exercise value // up^(2*i - j) 61 | if (p[i] < exercise) p[i] = exercise; 62 | } 63 | } 64 | 65 | return (p[0]); 66 | } 67 | 68 | 69 | // ============================================================================================================ // 70 | // ------------------------------------------------------------------------------------------------------------ // 71 | // SW MODEL - Multi-threading Implementation 72 | // ------------------------------------------------------------------------------------------------------------ // 73 | // ============================================================================================================ // 74 | void K_americanPut_sw_model_task(t_in_data* host_IN_DATA, float* sw_RES, int Nb_Of_Tests, int Start_Index) { 75 | 76 | for (int i = 0; i0 33 | 34 | # ................................. 35 | # SW Resources 36 | # ................................. 37 | # NB_OF_THREADS type(int) : Nb of Threads to be used during SW model run 38 | 39 | # 40 | # ................................. 41 | # Available HW Resources 42 | # ................................. 43 | # NB_KERNELS type(int) : Number of kernels implemented on Alveo 44 | # NB_OF_CUs_PER_KERNEL type(int) : Number of CUs per a single kernel implemented on Alveo 45 | # (each kernel has the same number of CUs) 46 | # NB_OF_PARALLEL_FUNCTIONS_PER_CU type(int) : Number of parallel K_americanPut_core functions implemented 47 | # in a single CU 48 | 49 | # ============================================================================================================== 50 | 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Binomial Options Pricing Model 2 | 3 | The goal of this reference design (tutorial) is to: 4 | - Demonstrate performance advantage of the Xilinx Alveo-based solution vs. the Intel® Xeon® CPU one and 5 | - Introduce various SDAccel analysis tools and optimization techniques allowing you to significantly improve design performance 6 | 7 | by using a Binomial Options Pricing Model (further referenced as Binomial Model). The original description of the Binomial Model was obtained from [Wikipedia] and is presented on the following figure: 8 | 9 |

10 | 11 |

12 | 13 | This original algorithm was rewritten in a C/C++ programming language by using single precision floating point operations and keeping the coding style as close as possible to the original version. 14 | 15 | At the beginning, you will use the original C/C++ Binomial Model description to target both Xilinx Alveo card and x68 CPU. You will observe that a fully sequential execution of the application on the Alveo card outperforms the single threaded CPU implementation by the factor of 8.9x. 16 | 17 | Then by using various optimization methods you will be able to increase Alveo based performance by the factor of 60.8x. This is represented in the following reduced summary table: 18 | 19 | Design | CPU (ms) | Alveo (ms) | Alveo Gain vs. CPU | 20 | ----------|-------------------:|-----------:|-------------------:| 21 | Original | 1 Thread: 9834.2 | 1106.7 | 8.9x | 22 | Optimized | 12 Threads: 1289.7 | 18.2 | 70.9x | 23 | 24 | This tutorial was validated using 25 | - U200 Alveo card with 2019.1 XRT, deployment and development shells 26 | - SDAccel 2019.1 version 27 | 28 | All results represented in this tutorial were generated by using DELL 8510 Workstation with the following characteristics: 29 | - CPU: Intel® Xeon® E5-1650 v3 @ 3.50 GHz 30 | Treads per core: 6 31 | Cores per socket: 2 32 | - RAM: 64 GB 33 | - OS: CentOS 7.4 34 | 35 | Please refer to the [BinomialModel.pdf] document for detailed information regarding design setup, execution and results comparison. 36 | 37 | 38 | [Wikipedia]: https://en.wikipedia.org/wiki/Binomial_options_pricing_model 39 | [BinomialModel.pdf]: BinomialModel.pdf 40 | --------------------------------------------------------------------------------