diff --git a/src/finn/custom_op/fpgadataflow/hlscustomop.py b/src/finn/custom_op/fpgadataflow/hlscustomop.py
index 6692fa4b6066a4ca456dcfcf3d78c5050a950dce..b202e95a28a26de3dabc098c2030bafcf840d164 100644
--- a/src/finn/custom_op/fpgadataflow/hlscustomop.py
+++ b/src/finn/custom_op/fpgadataflow/hlscustomop.py
@@ -410,6 +410,7 @@ class HLSCustomOp(CustomOp):
     Found no codegen dir for this node, did you run the prepare_cppsim transformation?
                 """
                 )
+            target_dir = code_gen_dir
         # create a npy file for each input of the node (in_ind is input index)
         # assuming dynamic inputs start from 0
         for in_ind in range(count):