Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yiiyama committed Aug 12, 2021
1 parent 9c29962 commit 7459fdd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions hls4ml/converters/keras/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion hls4ml/templates/vivado/build_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
rm -f *.o
8 changes: 8 additions & 0 deletions hls4ml/templates/vivado/nnet_utils/nnet_garnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

#include "nnet_common.h"
#include "hls_stream.h"
#ifdef NO_VIVADO
#include <cmath>
#else
#include "hls_math.h"
#endif

namespace nnet {
namespace garnet_utils {
Expand All @@ -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
}
}

Expand Down

0 comments on commit 7459fdd

Please sign in to comment.