From 32f7a41a532a4190f990682e6392f7f7256c5646 Mon Sep 17 00:00:00 2001 From: auphelia <jakobapk@web.de> Date: Fri, 6 Mar 2020 15:45:12 +0000 Subject: [PATCH] [Source code] Make copy of array before saved to .npy file --- src/finn/core/remote_exec.py | 2 ++ src/finn/custom_op/fpgadataflow/__init__.py | 4 +++- src/finn/custom_op/fpgadataflow/convolutioninputgenerator.py | 2 ++ src/finn/util/data_packing.py | 2 ++ tests/util/test_data_packing.py | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/finn/core/remote_exec.py b/src/finn/core/remote_exec.py index 190bb857a..e78f07b9f 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 7f13b43d5..ef784b8ac 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 14016ce9c..bfc252b55 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 ae98d312e..1c08ac4fc 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 495ec6096..28f1d56d0 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 -- GitLab