Skip to main content

Kratos runtime for debugging

Project description

Kratos Debugger Runtime

This is the runtime library required to debug Kratos hardware designs. It offers realtime interaction between the simulator and a debugger, which can either be Visual Studio Code, or any debugger that talks HTTP REST protocol.

This library also ships with a Python API which you can use in your Python code to control the simulator. It does not implement the full-feature of all the protocols the runtime supports, but it's a good place to start if you are going to implement your own debugger to interface the runtime.

How to install kratos-runtime

There are a couple ways to install kratos-runtime. You need a C++17 compatible compiler, such as g++-8 to compile the library. The Python API requires Python3 to run.

Install from PyPI

If you're using Linux, the easiest way to install is through pip. Do

pip install kratos-runtime

After installing, do

python -c "from kratos_runtime import get_lib_path; print(get_lib_path())"

which will tell you where the pre-built library is and you can use that to link to your design. You can also call get_ncsim_flag() to get necessary flags.

Build from source

If you want the built-in Python tools:

$ git clone https://github.com/Kuree/kratos-runtime
$ cd kratos-runtime
$ git submodule update --init --recursive
$ pip install .

If you just want the runtime library, do:

$ git clone https://github.com/Kuree/kratos-runtime
$ cd kratos-runtime
$ git submodule update --init --recursive
$ mkdir build
$ cd ./build
$ cmake ..
$ make -j

After that, you can find the library as build/src/libkratos-runtime.so. You can either copy that library to any place you like or simply use symbolic link.

A note for macOS

Due to the restriction of macOS, all symbols have to be resolved during the linking time, which means all the VPI calls need to have actual symbol when linked as the final shared object. However, this is not doable in our case since the actual VPI implementation is offered by the vendor. As a result, you cannot use this project, even if you have Verilator working on macOS.

How to use kratos-runtime

The following instruction is based on Linux and tested against Verilator and ncsim.

Generate Kratos-Runtime debug database for your design

When calling verilog() function, you can supply another argument called debug_db_filename to specify the location where kratos can output the debug files,

verilog(your_design, debug_db_filename="debug.db", insert_debug_info=True)

Using Kratos-runtime with Verilator

Once you have compiled the shared library, you can ask verialtor to link your test bench with kratos-runtime. Before you do that, since we need to read the internal signals, we need to inject verilator specific info via a pass:

kratos.passes.insert_verilator_public(your_design.internal_generator)

When invoking the verilator command, you need to specify the kratos runtime name as well as --vpi switch, for instance:

verilator --cc design.sv test_tb.sv libkratos-runtime.so --vpi --exe

You can symbolic link libkratos-runtime.so inside obj_dir so that the linker and find it easily.

Once the test bench is compiled, you need to use LD_LIBRARY_PATH to let the system to load, such as

$ LD_LIBRARY_PATH=./obj_dir/ ./obj_dir/Vtest

Or you can let the linker to fix the shared library path in the verilator, which is beyond the scope of this tutorial.

An alternative is to use the built-in Python helper class.

You can use kratos_runtime.VerilatorTester to run your verilator design.

with VerilatorTester(*files, cwd=temp) as tester:
    tester.run()

Where files is a list of files. By default the run() is non-blocking, so you can attach your debugger with the runtime.

Using kratos-runtime with Ncsim

Ncsim is much easier to use than verilator. Once you have the design, simply tell the simulator that you want to load the vpi and dpi library, such as

irun test_tb.sv test.sv -sv_lib libkratos-runtime.so -loadvpi libkratos-runtime.so:initialize_runtime_vpi -access +r

-access +r is necessary to allow the runtime to read out simulation variables.

You can also use kratos_runtime.NCSimTester to run your design.

with NCSimTester(*files) as tester:
    tester.run()

What to do after launch the simulation

You can now use any debugger that's compatible with the Kratos debug protocol. Kratos has provide an open-source version of debugger extension inside VS Code. You can install it here and use it to debug your design.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file kratos_runtime-0.0.8-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: kratos_runtime-0.0.8-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for kratos_runtime-0.0.8-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 390d96dd7fbf9060487fdf2e05d461278c4fcbde580fe0f9ecee81fcb8f3d0a4
MD5 e8f728ab30fbc168a9fb12e5eea938d9
BLAKE2b-256 d859d7881f83ea4747981bf752b06efab2adf9dd55b014951221ce0a727ded5e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page