## Overview

Instruction-level simulators allow users to simulate the Coral NPU
processor and test software without the need for physical hardware. The
Coral NPU simulators can be used for system modeling, compiler validation,
and software development.

There are two simulators for Coral NPU:

- Behavioral instruction simulator called MPACT-CoralNPU
- Cycle-accurate Verilator simulator for exact hardware performance emulation (`rvv_core_mini_axi_sim`)

The `rvv_core_mini_axi_sim` Verilator simulator is co-located within the primary
[GitHub repository for Coral NPU](https://github.com/google-coral/coralnpu).

The MPACT-CoralNPU behavioral simulator is housed in a separate GitHub
repository located [here](https://github.com/google-coral/coralnpu-mpact).
It is also available in the main GitHub repository for use in scripting
work flows.

Use the Verilog-based `rvv_core_mini_axi_sim` simulator to obtain precise,
accurate results --- exactly as
would be seen on the Coral NPU hardware. You must model your system
memories correctly to achieve this. This simulator is clock-cycle-accurate
and so you are able to see what signals actually toggle by using the
waveform generation option.

The Verilator simulator executes slowly, however, and so if all you need is
functional equivalence then use the MPACT-CoralNPU simulator. The
MPACT-CoralNPU simulator is much faster and so is ideal for early
experimentation and software development.

MPACT-CoralNPU is primarily focused on optimizing instruction counts and
functional correctness. It is convenient for ensuring ML kernel correctness
because it runs quickly on a desktop PC and features a Python harness for
easy task initiation
(see [Run MobileNet example](https://developers.google.com/coral/guides/software/run-mobilenet.md.txt)).

Both tools facilitate simulation-based ML system testing, optimization, and
benchmarking. The `rvv_core_mini_axi_sim` cycle-accurate simulator is the tool
to use for hardware development and debugging.

MPACT-CoralNPU supports RISC-V scalar, floating-point, and vector
instruction sets.

Google provides the simulator open-source files on GitHub so that users who are
extending the Coral NPU hardware IP can also modify and build the simulators
themselves.

Both Coral NPU simulators accept two input file formats: `.elf` (Executable
and Linkable Format) and `.bin` (binary). The `.elf` files contain extra
information that is helpful in debugging, while flattened `.bin` files are
smaller. Fully compiled `.elf` files are generally preferred for simulation
due to their flexibility with memory configurations and debugging data.

## ELF file format for simulation

An `.elf` file is a standard binary file format used to load and execute
software
on embedded processors within a hardware simulator. It packages the compiled
code, data, and metadata needed for the simulation to function correctly.

The ELF format is the standard binary format used for executables, object code,
and shared libraries in most Unix-based systems, including Linux and BSD.

An `.elf` file provides the initial state for the processor's memory. When the
simulation starts, the hardware's internal memory (block RAM) is loaded with
the code and data from the `.elf` file.

The ELF format allows the file to incorporate debugging
information --- specifically, symbol tables that map the machine code back to the
original source code. This allows a debugger to help you troubleshoot your code
during simulation by setting breakpoints and inspecting variables.

The common workflow when using `.elf` files in hardware simulation is:

- **Software compilation** : Write and compile the source code using a cross-compiler that targets the specific processor in your hardware design. The output is an `.elf` file.
- **Adding the .elf to the project** : Add the generated `.elf` file to your hardware project, often within an integrated design environment (IDE).
- **Associating the .elf** : Link the `.elf` file to a specific processor instance in your hardware design.
- **Simulation** : Run the hardware simulation. The simulator loads the contents of the `.elf` file into the simulated memory of the processor.
- **Debugging**: Using the debugging tools in your IDE, you can interact with the running simulation, stepping through your software and hardware execution in a coordinated manner.

<br />


*** ** * ** ***

<br />