diff --git a/src/finn/core/remote_exec.py b/src/finn/core/remote_exec.py index 190bb857ad6e5448d49a6b742adc888f2bca79d2..e78f07b9f1097ee6e1042846a91c2a0ff80d12d0 100644 --- a/src/finn/core/remote_exec.py +++ b/src/finn/core/remote_exec.py @@ -43,6 +43,8 @@ def remote_exec(model, execution_context): pynq_target_dir = model.get_metadata_prop("pynq_target_dir") deployment_dir = model.get_metadata_prop("pynq_deploy_dir") inp = execution_context[model.graph.input[0].name] + # make copy of array before saving it + inp = inp.copy() np.save(os.path.join(deployment_dir, "input.npy"), inp) # extracting last folder of absolute path (deployment_dir) deployment_folder = os.path.basename(os.path.normpath(deployment_dir)) diff --git a/src/finn/custom_op/fpgadataflow/__init__.py b/src/finn/custom_op/fpgadataflow/__init__.py index 7f13b43d57d9fe2f6de5e5ed9bb52214611f1098..ef784b8ac29ca9e937fcd4ea22a8dfd6e1a7a470 100644 --- a/src/finn/custom_op/fpgadataflow/__init__.py +++ b/src/finn/custom_op/fpgadataflow/__init__.py @@ -207,9 +207,11 @@ Found no codegen dir for this node, did you run the codegen_npysim transformatio # assuming dynamic inputs start from 0 for in_ind in range(count): current_input_name = node.input[in_ind] + # make copy before saving array + input_array = context[current_input_name].copy() np.save( os.path.join(code_gen_dir, "input_{}.npy".format(in_ind)), - context[current_input_name], + input_array, ) def npy_to_dynamic_output(self, context): diff --git a/src/finn/custom_op/fpgadataflow/convolutioninputgenerator.py b/src/finn/custom_op/fpgadataflow/convolutioninputgenerator.py index 14016ce9ce22c729ad3279fb90dc900f88fda8ba..bfc252b557ac3e384cf8a3585c5bc9a8b5b7632b 100644 --- a/src/finn/custom_op/fpgadataflow/convolutioninputgenerator.py +++ b/src/finn/custom_op/fpgadataflow/convolutioninputgenerator.py @@ -123,6 +123,8 @@ class ConvolutionInputGenerator(HLSCustomOp): ), """Input shape doesn't match expected shape (1, ifm_ch, ifm_dim, ifm_dim).""" reshaped_inp = inp.transpose(0, 2, 3, 1) + # make copy before saving array + reshaped_inp = reshaped_inp.copy() np.save(os.path.join(code_gen_dir, "input_0.npy"), reshaped_inp) # execute the precompiled model super().exec_precompiled_singlenode_model() diff --git a/src/finn/util/data_packing.py b/src/finn/util/data_packing.py index ae98d312e7c5923a572f918430aececf29f3e094..1c08ac4fc7a9eedcc45deab824d7ec036941f808 100644 --- a/src/finn/util/data_packing.py +++ b/src/finn/util/data_packing.py @@ -297,6 +297,8 @@ def rtlsim_output_to_npy( out_array = unpack_innermost_dim_from_hex_string( output, dtype, shape, packedBits=packedBits, reverse_inner=reverse_inner ) + # make copy before saving the array + out_array = out_array.copy() np.save(path, out_array) return out_array diff --git a/tests/util/test_data_packing.py b/tests/util/test_data_packing.py index 495ec60966ef67f3bf7b99c63cc70e133859d087..28f1d56d0dbc5451ccad3d36b4b1d4c6bed4f63e 100644 --- a/tests/util/test_data_packing.py +++ b/tests/util/test_data_packing.py @@ -104,6 +104,8 @@ g++ -o test_npy2apintstream test.cpp /workspace/cnpy/cnpy.cpp \ ["sh", "compile.sh"], stdout=subprocess.PIPE, cwd=test_dir ) (stdout, stderr) = compile.communicate() + # make copy before saving the array + ndarray = ndarray.copy() np.save(npy_in, ndarray) execute = subprocess.Popen( "./test_npy2apintstream", stdout=subprocess.PIPE, cwd=test_dir