finn.util.basic (module)¶
-
class
finn.util.basic.CppBuilder¶ Bases:
objectBuilds the g++ compiler command to produces the executable of the c++ code in code_gen_dir which is passed to the function build() of this class.
-
append_includes(library_path)¶ Adds given library path to include_paths list.
-
append_sources(cpp_file)¶ Adds given c++ file to cpp_files list.
-
build(code_gen_dir)¶ Builds the g++ compiler command according to entries in include_paths and cpp_files lists. Saves it in bash script in given folder and executes it.
-
set_executable_path(path)¶ Sets member variable “executable_path” to given path.
-
-
finn.util.basic.calculate_matvec_accumulator_range(matrix, vec_dt)¶ Calculate the minimum and maximum possible result (accumulator) values for a dot product x * A, given matrix A of dims (MW, MH), and vector (1, MW) with datatype vec_dt. Returns (acc_min, acc_max).
-
finn.util.basic.calculate_signed_dot_prod_range(dt_a, dt_b, len)¶ Returns the (min,max) values a dot product between two signed vectors of types dt_a and dt_b of len elements can take.
-
finn.util.basic.gen_finn_dt_tensor(finn_dt, tensor_shape)¶ Generates random tensor in given shape and with given FINN DataType.
-
finn.util.basic.get_by_name(container, name, name_field='name')¶ Return item from container by .name field if it exists, None otherwise. Will throw an Exception if multiple items are found, since this violates the ONNX standard.
-
finn.util.basic.get_execution_error_thresh()¶ Return the max error that is allowed for rounding in FINN execution.
-
finn.util.basic.get_finn_root()¶ Return the root directory that FINN is cloned into.
-
finn.util.basic.get_num_default_workers()¶ Return the number of workers for parallel transformations. Controllable via the NUM_DEFAULT_WORKERS environment variable. If the env.var. is undefined, the default value of 1 is returned.
-
finn.util.basic.get_remote_vivado()¶ Return the address of the remote Vivado synthesis server as set by the, REMOTE_VIVADO environment variable, otherwise return None
-
finn.util.basic.get_rtlsim_trace_depth()¶ Return the trace depth for rtlsim via PyVerilator. Controllable via the RTLSIM_TRACE_DEPTH environment variable. If the env.var. is undefined, the default value of 1 is returned. A trace depth of 1 will only show top-level signals and yield smaller .vcd files.
The following depth values are of interest for whole-network stitched IP rtlsim: - level 1 shows top-level input/output streams - level 2 shows per-layer input/output streams - level 3 shows per full-layer I/O including FIFO count signals
-
finn.util.basic.get_sanitize_quant_tensors()¶ Return whether tensors with quantization annotations should be sanitized. Enabled by default, disabling will yield faster ONNX execution but may give incorrect results. Use with caution.
-
finn.util.basic.interleave_matrix_outer_dim_from_partitions(matrix, n_partitions)¶ Interleave the outermost dimension of a matrix from given partitions (n_partitions).
-
finn.util.basic.make_build_dir(prefix='')¶ Creates a temporary folder with given prefix to be used as a build dir. Use this function instead of tempfile.mkdtemp to ensure any generated files will survive on the host after the FINN Docker container exits.
-
finn.util.basic.pad_tensor_to_multiple_of(ndarray, pad_to_dims, val=0, distr_pad=False)¶ Pad each dimension of given NumPy ndarray using val, so that each dimension is a multiple of the respective value in pad_to_dims. -1 means do not pad that particular dimension. If distr_pad is False, all padding will be inserted after the existing values; otherwise it will be split evenly between before and after the existing values, with one extra value inserted after if the padding amount is not divisible by two.
-
finn.util.basic.random_string(stringLength=6)¶ Randomly generate a string of letters and digits.
-
finn.util.basic.remove_by_name(container, name, name_field='name')¶ Remove item from container by .name field if it exists.
-
finn.util.basic.roundup_to_integer_multiple(x, factor)¶ Round up integer x to the nearest integer multiple of integer factor. Returns x if factor is set to -1. Both x and factor must otherwise be positive.
-
finn.util.basic.sanitize_quant_values(model, node_tensors, execution_context, check_values=False)¶ Sanitize given list of tensors in execution_context by rounding values that are supposed to be integers (as indicated by their quantization annotation). Will raise an assertion if the amount of rounding is too large. Returns the sanitized execution context.
If check_values is specified, an extra DataType.allowed() check will be performed on any rounded tensors.
Background: FINN uses floating point tensors as a carrier data type to represent integers. Floating point arithmetic can introduce rounding errors, e.g. (int_num * float_scale) / float_scale is not always equal to int_num. We use this function to ensure that the values that are supposed to be integers are indeed integers.