# 2024-NTU-SPAAHLS This is my journal "Special Project on Application Acceleration with High-Level-Synthesis" course in year 2024. This course provides training in two disciplines: HLS and/or SoC design, and I participate in the HLS part. My work is in github: https://github.com/asdshawn/2024-NTU-SPAAHLS ## Dynamic memory allocation in C v.s. Memory buffer in HLS 1. Dynamic Memory Usage * Memory allocation: malloc(), alloc() and free() * User-defined macro NO_SYNTH ```cpp= #include "malloc_removed.h" #include <stdlib.h> // #define NO_SYNTH dout_t malloc_removed(din_t din[N], dsel_t width) { #ifdef NO_SYNTH long long *out_accum = malloc (sizeof(long long)); int* array_local = malloc (64 * sizeof(int)); #else long long _out_accum; long long *out_accum = &_out_accum; int _array_local[64]; int* array_local = &_array_local[0]; #endif ...... } ``` 3. Memory Buffer Explained ![image](https://hackmd.io/_uploads/rkWGo83B1g.png) 5. Pointer Limitation * General Pointer Casting * Not support general pointer casting. * Support pointer casting between native C/C++ types. * Pointer Arrays * Support pointer array to a scalar or an array of scalars. * Not support array of pointers point to additional pointers. * Function Pointer – not supported ## Explain how double buffering improves performance * Host Code Timeline ![image](https://hackmd.io/_uploads/HJLsh82BJe.png) * Improved Timeline ![image](https://hackmd.io/_uploads/S1KlaUnHye.png) ## Compute & Memory Exchange * Compression and Decompression By compressing the weights of neural networks, we reduce the memory footprint. When needed, decompressing allows us to use those weights in computations. This reduces the memory requirement but at the cost of additional computation to decompress the data. * Lookup Tables (LUTs) For repetitive calculations like sin and cos functions, pre-calculating these values and storing them in memory (LUTs) is an efficient way to reduce computation. Here, memory is used to store precomputed values, which speeds up the process at the cost of increased memory usage. ## Explain how data forwarding reduces II and how to write the C-code to implement data forwarding * Original ![image](https://hackmd.io/_uploads/r15RJP2rJg.png) * Prefix-Sum ![image](https://hackmd.io/_uploads/ryQxeDhrkl.png)