python - 如何解决 hls4ml 的这个问题?
问题描述
我正在尝试运行hls4ml 文档页面上显示的示例代码,但在运行以下命令时:
import hls4ml
#Fetch a keras model from our example repository
#This will download our example model to your working directory and return an example configuration file
config = hls4ml.utils.fetch_example_model('KERAS_3layer.json')
print(config) #You can print it to see some default parameters
#Convert it to a hls project
hls_model = hls4ml.converters.keras_to_hls(config)
#Use Vivado HLS to synthesize the model
#This might take several minutes
hls_model.build()
#Print out the report if you want
hls4ml.report.read_vivado_report('my-hls-test')
输出是
Downloading example model files ...
{'OutputDir': 'my-hls-test', 'ProjectName': 'myproject', 'XilinxPart': 'xcku115-flvb2104-2-i', 'ClockPeriod': 5, 'Backend': 'Vivado', 'IOType': 'io_parallel', 'HLSConfig': {'Model': {'Precision': 'ap_fixed<16,6>', 'ReuseFactor': '1'}}, 'KerasJson': 'KERAS_3layer.json', 'KerasH5': 'KERAS_3layer_weights.h5'}
Interpreting Model
Topology:
Layer name: input_1, layer type: InputLayer, current shape: [[None, 16]]
Layer name: fc1_relu, layer type: Dense, current shape: [[None, 16]]
Layer name: fc2_relu, layer type: Dense, current shape: [[None, 64]]
Layer name: fc3_relu, layer type: Dense, current shape: [[None, 32]]
Layer name: output_softmax, layer type: Dense, current shape: [[None, 32]]
Creating HLS model
Synthesis report not found.
Found 1 solution(s) in my-hls-test/myproject_prj.
Reports for solution "solution1":
C SIMULATION RESULT:
INFO: [SIM 2] *************** CSIM start ***************
INFO: [SIM 4] CSIM will launch GCC as the compiler.
make: 'csim.exe' is up to date.
INFO: Unable to open input/predictions file, using default input.
0.0292969 0.756836 0.0546875 0.139648 0.0371094
INFO: Saved inference results to file: tb_data/csim_results.log
INFO: [SIM 1] CSim done with 0 errors.
INFO: [SIM 3] *************** CSIM finish ***************
Synthesis report not found.
Co-simulation report not found.
请注意,最后两行指的是构建过程和报告的返回。
我通过 Anaconda Navigator 在 Jupyter Notebook (6.0.3) 上运行它,Python 版本是 3.6.9,hls4ml 版本是 0.5.0
我不明白这是由于安装错误还是由于代码等。
关于导致这种情况的任何想法?
我认为这是 hls4ml 特有的,但遗憾的是它在 StackOverflow 中不作为标签存在。
更新
我遇到的最初问题(即我的目录中有' '
一个非法字符的空格)让我运行vivado_hls -f build_prj.tcl "csim=1 synth=1 cosim=1 export=1"
,这向我展示了一系列新问题。即,我收到这些错误:
***** C/RTL SYNTHESIS *****
INFO: [SCHED 204-61] Option 'relax_ii_for_timing' is enabled, will increase II to preserve clock frequency constraints.
INFO: [HLS 200-10] Analyzing design file 'firmware/myproject.cpp' ...
ERROR: [HLS 200-70] Compilation errors found: In file included from firmware/myproject.cpp:1:
In file included from firmware/myproject.cpp:19:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\iostream:39:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\ostream:39:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\ios:39:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\exception:151:
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\exception_ptr.h:132:13: error: unknown type name 'type_info'
const type_info*
^
In file included from firmware/myproject.cpp:1:
In file included from firmware/myproject.cpp:19:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\iostream:39:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\ostream:39:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\ios:39:
In file included from D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\exception:151:
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:62:5: error: the parameter for this explicitly-defaulted copy constructor is const, but a member or base requires it to be non-const
nested_exception(const nested_exception&) = default;
^
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:64:23: error: the parameter for this explicitly-defaulted copy assignment operator is const, but a member or base requires it to be non-const
nested_exception& operator=(const nested_exception&) = default;
^
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:77:28: error: exception specification in declaration does not match previous declaration
inline nested_exception::~nested_exception() = default;
^
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:66:20: note: previous declaration is here
inline virtual ~nested_exception();
^
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:122:61: error: redefinition of default argument
__throw_with_nested(_Ex&& __ex, const nested_exception* = 0)
^ ~
D:/Tools/Xilinx/Vivado/2019.2/win64/tools/clang/bin\..\lib\clang\3.1/../../../include/c++/4.5.2\nested_exception.h:110:56: note: previous definition is here
__throw_with_nested(_Ex&&, const nested_exception* = 0)
^ ~
In file included from firmware/myproject.cpp:1:
In file included from firmware/myproject.cpp:21:
In file included from firmware/myproject.h:23:
In file included from D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_int.h:367:
In file included from D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed.h:55:
D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed_base.h:838:13: warning: shift count is negative [-Wshift-count-negative]
ret.V <<= (_AP_I - _AP_W);
^ ~~~~~~~~~~~~~~~
D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed_base.h:869:69: note: in instantiation of member function 'ap_fixed_base<50, 40, true, 5, 3, 0>::to_ap_int_base' requested here
inline __attribute__((always_inline)) int to_int() const { return to_ap_int_base().to_int(); }
^
D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed_base.h:1042:71: note: in instantiation of member function 'ap_fixed_base<50, 40, true, 5, 3, 0>::to_int' requested here
inline __attribute__((always_inline)) operator int() const { return to_int(); }
^
firmware/nnet_utils/nnet_activation.h:389:17: note: in instantiation of member function 'ap_fixed_base<50, 40, true, 5, 3, 0>::operator int' requested here
data_round = (data_cache[jj]-data_cache[ii])*CONFIG_T::table_size/16;
^
firmware/nnet_utils/nnet_activation.h:421:9: note: in instantiation of function template specialization 'nnet::softmax_legacy<ap_fixed<16, 6, 5, 3, 0>, ap_fixed<16, 6, 5, 3, 0>, softmax_config9>' requested here
softmax_legacy<data_T, res_T, CONFIG_T>(data, res);
^
firmware/myproject.cpp:90:5: note: in instantiation of function template specialization 'nnet::softmax<ap_fixed<16, 6, 5, 3, 0>, ap_fixed<16, 6, 5, 3, 0>, softmax_config9>' requested here
nnet::softmax<layer8_t, result_t, softmax_config9>(layer8_out, layer9_out);
^
In file included from firmware/myproject.cpp:1:
In file included from firmware/myproject.cpp:21:
In file included from firmware/myproject.h:23:
In file included from D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_int.h:367:
In file included from D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed.h:55:
D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed_base.h:838:13: warning: shift count is negative [-Wshift-count-negative]
ret.V <<= (_AP_I - _AP_W);
^ ~~~~~~~~~~~~~~~
D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed_base.h:869:69: note: in instantiation of member function 'ap_fixed_base<51, 41, true, 5, 3, 0>::to_ap_int_base' requested here
inline __attribute__((always_inline)) int to_int() const { return to_ap_int_base().to_int(); }
^
D:/Tools/Xilinx/Vivado/2019.2/common/technology/autopilot\ap_fixed_base.h:1042:71: note: in instantiation of member function 'ap_fixed_base<51, 41, true, 5, 3, 0>::to_int' requested here
inline __attribute__((always_inline)) operator int() const { return to_int(); }
^
firmware/nnet_utils/nnet_activation.h:401:27: note: in instantiation of member function 'ap_fixed_base<51, 41, true, 5, 3, 0>::operator int' requested here
int exp_res_index = exp_res[ii]*CONFIG_T::table_size/64;
^
firmware/nnet_utils/nnet_activation.h:421:9: note: in instantiation of function template specialization 'nnet::softmax_legacy<ap_fixed<16, 6, 5, 3, 0>, ap_fixed<16, 6, 5, 3, 0>, softmax_config9>' requested here
softmax_legacy<data_T, res_T, CONFIG_T>(data, res);
^
firmware/myproject.cpp:90:5: note: in instantiation of function template specialization 'nnet::softmax<ap_fixed<16, 6, 5, 3, 0>, ap_fixed<16, 6, 5, 3, 0>, softmax_config9>' requested here
nnet::softmax<layer8_t, result_t, softmax_config9>(layer8_out, layer9_out);
^
2 warnings and 5 errors generated.
Failed during preprocessing.
while executing
"source build_prj.tcl"
("uplevel" body line 1)
invoked from within
"uplevel \#0 [list source $arg] "
INFO: [Common 17-206] Exiting vivado_hls at Fri Apr 2 16:14:58 2021...
我在新旧版本的 Vivado HLS 上都遇到过这个问题。我该如何解决这个问题?
解决方案
我有同样的问题,hls4ml 是 Linux 的后端 Vivado(截至目前)。在 Ubuntu 中这不是问题。不支持 Windows,有一个文件专门在合成前验证操作系统。
如果您转到构建 hls 模型的目录,则在build_lib.sh
文件中
我不知道为什么它不工作,但他们在这里根据操作系统设置 C++ 编译器
#!/bin/bash
CC=g++
if [[ "$OSTYPE" == "linux-gnu" ]]; then
CFLAGS="-O3 -fPIC -std=c++11 -fno-gnu-unique"
elif [[ "$OSTYPE" == "darwin"* ]]; then
CFLAGS="-O3 -fPIC -std=c++11"
fi
LDFLAGS=
INCFLAGS="-Ifirmware/ap_types/"
PROJECT=myproject
LIB_STAMP=1F075F4e
${CC} ${CFLAGS} ${INCFLAGS} -c firmware/${PROJECT}.cpp -o ${PROJECT}.o
${CC} ${CFLAGS} ${INCFLAGS} -c ${PROJECT}_bridge.cpp -o ${PROJECT}_bridge.o
${CC} ${CFLAGS} ${INCFLAGS} -shared ${PROJECT}.o ${PROJECT}_bridge.o -o firmware/${PROJECT}-${LIB_STAMP}.so
rm -f *.o
推荐阅读
- spring-boot - 如何配置一个端口以使用“位置”部署不同的 Java Web 应用程序?
- c++ - 如何在一个 cmake 项目中混合动态和静态 boost 库?
- python - OSMNX 无法在 /api/status 响应中无速率限制地工作
- python - (Pygame) 玩家不动
- coq - 如何调试匹配目标分支中的战术失败?
- azure - Azure B2C 自定义流添加字段以登录
- perl - Perl Tk 画布,窗口标题栏与画布重叠,overrideredirect(1)
- r - Flextable 在 R 中显示空白的白色图像
- ios - iOS Swift - 按枚举模式排序数组
- plot - 如何为ggpubr中的分组箱形图添加内部和内部比较的统计信息?