Package: kratos-runtime
Kratos Debugger RuntimeThis 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-runtimeThere are a couple ways to install kratos-runtime. You
need a C++17 compatible compiler, such asg++-8to compile the library.
The Python API requires Python3 to run.Install from PyPIIf you're using Linux, the easiest way to install is through pip. Dopipinstallkratos-runtimeAfter installing, dopython-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 callget_ncsim_flag()to get necessary
flags.Build from sourceIf you want the built-in Python tools:$gitclonehttps://github.com/Kuree/kratos-runtime
$cdkratos-runtime
$gitsubmoduleupdate--init--recursive
$pipinstall.If you just want the runtime library, do:$gitclonehttps://github.com/Kuree/kratos-runtime
$cdkratos-runtime
$gitsubmoduleupdate--init--recursive
$mkdirbuild
$cd./build
$cmake..
$make-jAfter that, you can find the library asbuild/src/libkratos-runtime.so. You
can either copy that library to any place you like or simply  use symbolic
link.A note for macOSDue 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-runtimeThe following instruction is based on Linux and tested against Verilator and
ncsim.Generate Kratos-Runtime debug database for your designWhen callingverilog()function, you can supply another argument calleddebug_db_filenameto 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 VerilatorOnce you have compiled the shared library, you can askverialtorto link your test bench withkratos-runtime. Before you do that,
since we need to read the internal signals, we need to injectverilatorspecific info via a pass:kratos.passes.insert_verilator_public(your_design.internal_generator)When invoking theverilatorcommand, you need to specify the kratos runtime
name as well as--vpiswitch, for instance:verilator--ccdesign.svtest_tb.svlibkratos-runtime.so--vpi--exeYou can symbolic linklibkratos-runtime.soinsideobj_dirso that the linker
and find it easily.Once the test bench is compiled, you need to useLD_LIBRARY_PATHto let the
system to load, such as$ LD_LIBRARY_PATH=./obj_dir/ ./obj_dir/VtestOr you can let the linker to fix the shared library path in theverilator,
which is beyond the scope of this tutorial.An alternative is to use the built-in Python helper class.You can usekratos_runtime.VerilatorTesterto run your verilator design.withVerilatorTester(*files,cwd=temp)astester:tester.run()Wherefilesis a list of files. By default therun()is non-blocking, so
you can attach your debugger with the runtime.Using kratos-runtime with NcsimNcsim is much easier to use thanverilator. Once you have the design, simply
tell the simulator that you want to load the vpi and dpi library, such asirun test_tb.sv test.sv -sv_lib libkratos-runtime.so -loadvpi libkratos-runtime.so:initialize_runtime_vpi -access +r-access +ris necessary to allow the runtime to read out simulation variables.You can also usekratos_runtime.NCSimTesterto run your design.withNCSimTester(*files)astester:tester.run()What to do after launch the simulationYou 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 ithereand use it to debug your design.