Hide/change FPGA task code during Mercurium binary compilationΒΆ

At some undesirable point, one could need to hide some application code to Mercurium but not to HLS tools from FPGA vendor. To this end, Mercurium defines the __HLS_AUTOMATIC_MCXX__ compiler preprocessor variable. Note that does not make sense to directly use this in the task source code. Because it will be handled by Mercurium (during the HLS intermediate files generation) and the protected code will be removed. Instead, it could be used in a .fpga.h or .fpga.hpp header file, which are still included in the HLS intermediate files. However, the functions must be self-contained to avoid further dependencies and circular dependencies.

task.cpp example:

#include "task.fpga.hpp"

#pragma omp task device(fpga)
#pragma omp task in([LEN]array) out([1]reduction)
void array_reduction(const long long int *array, long long int *reduction) {
    my_longer_type_t acum = 0;
    for (int i=0; i<LEN; i++) acum += array[i];
    *reduction = acum/LEN;
}

task.fpga.hpp example:

#ifdef __HLS_AUTOMATIC_MCXX__
    #include <ap_int.h>
    typedef apint<100> my_longer_type_t;
#else
    typedef long long int my_longer_type_t;
#endif