From 7459fdd598890f2e48089a98dd5d9570398d9e47 Mon Sep 17 00:00:00 2001 From: Yutaro Date: Thu, 12 Aug 2021 09:57:40 +0200 Subject: [PATCH] Issue #365 fixes --- hls4ml/converters/keras/graph.py | 4 ++-- hls4ml/templates/vivado/build_lib.sh | 3 ++- hls4ml/templates/vivado/nnet_utils/nnet_garnet.h | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hls4ml/converters/keras/graph.py b/hls4ml/converters/keras/graph.py index 75ba6ad1a7..a95d0f2cd4 100644 --- a/hls4ml/converters/keras/graph.py +++ b/hls4ml/converters/keras/graph.py @@ -8,8 +8,8 @@ def parse_garnet_layer(keras_layer, input_names, input_shapes, data_reader, conf if not keras_layer['config']['simplified']: raise Exception('HLS GarNet is compatible only with keras GarNet with simplified=True') - if keras_layer['config']['output_activation'] is not None: - raise Exception('HLS GarNet cannot have output activation') + if not (keras_layer['config']['output_activation'] in [None, 'linear']: + raise Exception('HLS GarNet cannot have nonlinear output activation') layer = parse_default_keras_layer(keras_layer, input_names) diff --git a/hls4ml/templates/vivado/build_lib.sh b/hls4ml/templates/vivado/build_lib.sh index 4409fe4637..4c8b0f9100 100755 --- a/hls4ml/templates/vivado/build_lib.sh +++ b/hls4ml/templates/vivado/build_lib.sh @@ -6,6 +6,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then CFLAGS="-O3 -fPIC -std=c++11" fi +CFLAGS="$CFLAGS -DNO_VIVADO" LDFLAGS= INCFLAGS="-Ifirmware/ap_types/" PROJECT=myproject @@ -14,4 +15,4 @@ LIB_STAMP=mystamp ${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 \ No newline at end of file +rm -f *.o diff --git a/hls4ml/templates/vivado/nnet_utils/nnet_garnet.h b/hls4ml/templates/vivado/nnet_utils/nnet_garnet.h index dfd4ced50a..431fe55588 100644 --- a/hls4ml/templates/vivado/nnet_utils/nnet_garnet.h +++ b/hls4ml/templates/vivado/nnet_utils/nnet_garnet.h @@ -22,7 +22,11 @@ #include "nnet_common.h" #include "hls_stream.h" +#ifdef NO_VIVADO +#include +#else #include "hls_math.h" +#endif namespace nnet { namespace garnet_utils { @@ -45,7 +49,11 @@ namespace nnet { for (unsigned iw = 1; iw < table_size; ++iw) { index = iw; distance.range(CONFIG_T::distance_width - 1, 0) = index.range(CONFIG_T::distance_width - 1, 0); +#ifdef NO_VIVADO + edge_weights_table[iw] = std::exp(-distance.to_double() * distance.to_double()); +#else edge_weights_table[iw] = hls::exp(-distance * distance); +#endif } }