验证选项 2:HLS 函数库和确认差异 - 2023.2 简体中文

Vitis 高层次综合用户指南 (UG1399)

Document ID
UG1399
Release Date
2023-12-18
Version
2023.2 简体中文

另一个验证选项是将源代码转换为使用 HLS 函数库。对于该选项,C 语言仿真与 C/RTL 协同仿真结果之间并无差异。以下示例显示了如何将以上代码修改为使用 hls_math.h 库。

注释: 该选项仅限在 C++ 中才可用。
  • 包含 hls_math.h 头文件。
  • 将数学函数替换为等效的 hls:: 函数。
    #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);
    }