Verification Option 2: HLS Math Library and Validate Differences - 2024.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2024-07-03
Version
2024.1 English

An alternative verification option is to convert the source code to use the HLS math library. With this option, there are no differences between the C simulation and C/RTL co-simulation results. The following example shows how the code above is modified to use the hls_math.h library.

Note: This option is only available in C++.
  • Include the hls_math.h header file.
  • Replace the math functions with the equivalent hls:: function.
    #include <cmath>
    #include "hls_math.h"
    #include <fstream>
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    using namespace std;
    
    typedef float data_t;
    
    data_t cpp_math(data_t angle) {
     data_t s = hls::sinf(angle);
     data_t c = hls::cosf(angle);
     return hls::sqrtf(s*s+c*c);
    }