@@ -25,31 +25,39 @@ def generate_data(function, input_shape):
25
25
26
26
27
27
# TODO: include latency strategy with flat_distribution when it can be made to pass
28
- @pytest .mark .parametrize ('strategy,function,input_shape,io_type' , [#('latency', flat_distribution, (8,), 'io_parallel'),
29
- #('latency', flat_distribution, (8, 8, 3), 'io_stream'),
30
- ('stable' , flat_distribution , (8 ,), 'io_parallel' ),
31
- ('stable' , high_accuracy_distribution , (8 ,), 'io_parallel' ),
32
- ('stable' , flat_distribution , (8 ,), 'io_stream' ),
33
- ('stable' , high_accuracy_distribution , (8 ,), 'io_stream' ),
34
- # Multi-dimensional tests, only for io_stream for now
35
- ('stable' , flat_distribution , (8 , 8 , 3 ), 'io_stream' ),
36
- ('stable' , high_accuracy_distribution , (8 , 8 , 3 ), 'io_stream' )])
37
- def test_softmax (strategy , generate_data , input_shape , io_type ):
28
+ @pytest .mark .parametrize ('backend,strategy,function,input_shape,io_type' , [
29
+ #('latency', flat_distribution, (8,), 'io_parallel'),
30
+ #('latency', flat_distribution, (8, 8, 3), 'io_stream'),
31
+ ('Vivado' , 'stable' , flat_distribution , (8 ,), 'io_parallel' ),
32
+ ('Vivado' , 'stable' , high_accuracy_distribution , (8 ,), 'io_parallel' ),
33
+ ('Quartus' , 'resource' , flat_distribution , (8 ,), 'io_parallel' ),
34
+ ('Quartus' , 'resource' , high_accuracy_distribution , (8 ,), 'io_parallel' ),
35
+ ('Vivado' , 'stable' , flat_distribution , (8 ,), 'io_stream' ),
36
+ ('Vivado' , 'stable' , high_accuracy_distribution , (8 ,), 'io_stream' ),
37
+ # Multi-dimensional tests, only for io_stream for now
38
+ ('Vivado' , 'stable' , flat_distribution , (8 , 8 , 3 ), 'io_stream' ),
39
+ ('Vivado' , 'stable' , high_accuracy_distribution , (8 , 8 , 3 ), 'io_stream' )
40
+
41
+ ])
42
+ def test_softmax (backend , strategy , generate_data , input_shape , io_type ):
38
43
X = generate_data
39
44
model = tf .keras .models .Sequential ()
40
45
model .add (tf .keras .layers .Activation (input_shape = input_shape , activation = 'softmax' , name = 'softmax' ))
41
46
model .compile ()
47
+
48
+ f_type = 'ac_fixed<18,8,true,AC_RND,AC_SAT>' if backend == 'Quartus' else 'ap_fixed<18,8,AP_RND,AP_SAT>'
42
49
cfg = hls4ml .utils .config_from_keras_model (model , granularity = 'name' )
43
50
cfg ['LayerName' ]['softmax' ]['Strategy' ] = strategy
44
- cfg ['LayerName' ]['softmax' ]['inv_table_t' ] = 'ap_fixed<18,8,AP_RND,AP_SAT>'
45
- cfg ['LayerName' ]['softmax' ]['exp_table_t' ] = 'ap_fixed<18,8,AP_RND,AP_SAT>'
51
+ cfg ['LayerName' ]['softmax' ]['inv_table_t' ] = f_type
52
+ cfg ['LayerName' ]['softmax' ]['exp_table_t' ] = f_type
53
+
46
54
odir = str (test_root_path / 'hls4mlprj_softmax_{}' .format (strategy ))
47
55
hls_model = hls4ml .converters .convert_from_keras_model (model , hls_config = cfg , io_type = io_type ,
48
- output_dir = odir )
56
+ output_dir = odir , backend = backend )
49
57
hls_model .compile ()
58
+
50
59
y_keras = model .predict (X )
51
60
y_hls4ml = hls_model .predict (X ).reshape (y_keras .shape )
52
-
53
61
acc_hls4ml = accuracy_score (np .argmax (y_keras , axis = - 1 ).ravel (), np .argmax (y_hls4ml , axis = - 1 ).ravel ())
54
62
55
63
print ('Accuracy hls4ml relative to keras: {}' .format (acc_hls4ml ))
0 commit comments