Kratos is a fast hardware design language embedded in Python
Project description
Kratos is a hardware design language written in C++/Python. It differentiates itself from other DSL with the following design philosophy:
Fully debuggable: debug hardware just like debugging Python code!
Highly efficient: Python frontend powered by Modern C++ binding. Designed with multi-processing in mind.
Human-readable verilog: we know how difficult it is to read machine generated verilog. kratos has multiple passes to produce nice-looking verilog.
Generator of generators: every python object is a generator that can be modified at any time, even after instantiation. This allows complex passes on the generators without ripping old structure apart.
Keep the good parts of SystemVerilog, such as always_ff, always_comb, interface, and unique case. Users control how and when to generate these semantics.
Single source of truth: kratos encourages users to infuse generator information inside generator itself. This makes debugging and verification much easier.
Static elaboration: kratos allows user to write parametrized code, even in the always block, all in Python.
Type checking: kratos check the variable types for each assignment to make sure there is no implicit conversion.
Install
pip install kratos
Pre-built wheels support all Python 3.6+ on Linux, Windows, and OSX. To build it from scratch, you need a C++17 compatible compiler, such as g++-8 or clang-8.
Documentation and Examples
You can check the documentation at Read the Docs.
Here are some examples to showcase the ability of kratos.
Asnyc Reset Register
Python code that parametrizes based on the width. Notice that we specify the sensitivity of the always_ff block when defining seq_code_block.
class AsyncReg(Generator):
def __init__(self, width):
super().__init__("register")
# define inputs and outputs
self._in = self.input("in", width)
self._out = self.output("out", width)
self._clk = self.clock("clk")
self._rst = self.reset("rst")
# add combination and sequential blocks
self.add_code(self.seq_code_block)
@always_ff((posedge, "clk"), (posedge, "rst"))
def seq_code_block(self):
if self._rst:
self._out = 0
else:
self._out = self._in
Here is the generated SystemVerilog
module register (
input logic clk,
input logic [15:0] in,
output logic [15:0] out,
input logic rst
);
always_ff @(posedge clk, posedge rst) begin
if (rst) begin
out <= 16'h0;
end
else out <= in;
end
endmodule // register
Fanout module
This is another example to showcase the kratos’ ability to produce high-quality SystemVerilog. In practice we would not write it this way.
class PassThrough(Generator):
def __init__(self, num_loop):
super().__init__("PassThrough")
self.in_ = self.input("in", 1)
self.out_ = self.output("out", num_loop)
self.num_loop = num_loop
self.add_code(self.code)
@always_comb
def code(self):
if self.in_:
for i in range(self.num_loop):
self.out_[i] = 1
else:
for i in range(self.num_loop):
self.out_[i] = 0
Here is generated SystemVerilog. Notice that the iteration variable i has been properly checked and resized to avoid index out of range.
module PassThrough (
input logic in,
output logic [3:0] out
);
always_comb begin
if (in) begin
for (int unsigned i = 0; i < 4; i += 1) begin
out[2'(i)] = 1'h1;
end
end
else begin
for (int unsigned i = 0; i < 4; i += 1) begin
out[2'(i)] = 1'h0;
end
end
end
endmodule // PassThrough
How to debug
Because Python is quite slow, By default the debug option is off. You can turn on debugging for individual modules. See tests/test_generator.py for more details).
Use an IDE Debugger
Check out the kratos ecosystem below to see how to use an IDE to debug kratos design with ncsim/VCS!
Ecosystem
Kratos has its own ecosystem to program behavioral verilog in Python. Most of them are plugins that will help users to debug, prototype, and testing.
kratos is a programming model for building hardware. The main abstraction in kratos in a Generator. Generator can be modified at any time through passes.
kratos-debug is a GUI for user to view generated verilog. It offers a source viewer to see the line mapping that kratos provides.
kratos-dpi is a DPI plugin that allows users to run arbitrary Python code to emulate a SystemVerilog function. This is extremely helpful for rapid prototyping and testing.
kratos-runtime is a necessary component if you want to debug kratos with standard simulators. It supports value inspection and breakpoints.
kratos-vscode is a Visual Studio Code extension that allows user to debug with Kratos. The simulator has to be loaded with kratos-runtime.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for kratos-0.0.28-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ae242a99878821c3a33524447dd655d03e4da5cd33226563d86b955f3b85021 |
|
MD5 | 49c46efa34f407cb7f5e614cbc03d8ca |
|
BLAKE2b-256 | 148e3431a1f37ab1d004d75f8e91c8fc8d74b79c16f745687d1f33d7256ce63d |
Hashes for kratos-0.0.28-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a7bd9106ab1b7098dc10158e084b44a786e03b04b1178e65de190cd300b208 |
|
MD5 | b604f5203edc38dc15934ec20a654c0d |
|
BLAKE2b-256 | a4aa15fbc4d752e59556519c0ee09594f31fdea0f9739f4eb8f291034cabfd78 |
Hashes for kratos-0.0.28-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88bcae4a0fb6c1eeb14d4b6cd75149f4c1d52a0dab682e647bbca08e540bac11 |
|
MD5 | 038dd88fd011784bfa1716f16eafd6b3 |
|
BLAKE2b-256 | 702af2cdaf84a4cb950582f548857519262a378e01fbbc94de31d1db425e976d |
Hashes for kratos-0.0.28-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b9cfd7ee2ebe64e25806246eed7dc25d44103022eaab0e133369dc2131d0782 |
|
MD5 | f2abd2e799866452dd23d7b47f057f2d |
|
BLAKE2b-256 | 6261c8b0a70b7df33eaf0b3d11f84fa47caf331adad626a718796da6d0e79b88 |
Hashes for kratos-0.0.28-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 533182be18391909fc44de8b61c088a34a2b084f7b40c060134042dd17633d29 |
|
MD5 | 57c0f1a0105d77cb08be65948498ffee |
|
BLAKE2b-256 | 8693c2ce1274384975dbe7b0929e4db4161d4d699b26bc1cbb515e9b18edc1e4 |
Hashes for kratos-0.0.28-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af5d91a107ee63b1cac1e41bdbc5abd06d7576215ce7d59c2509adaa3c220304 |
|
MD5 | 84f294a521ebf9f35c1f9f81676148b0 |
|
BLAKE2b-256 | 52eac1106d6e4f90004bcab4a91516709dd07be657e3a40809530c5ca8682dfa |
Hashes for kratos-0.0.28-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c3d211ad699b2f7604933cdc46ae6834e8c4f29b9072c5371003d35029fb08 |
|
MD5 | f9a3d08352251850735f674eda9bb164 |
|
BLAKE2b-256 | 37de35fd337dd51c701ad56b32002d20af46e08cbe7a2a93f4370f32a0abf719 |
Hashes for kratos-0.0.28-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2db274e1ddf59aa64071c41e0eaba2621b334d06760b3db020fbe5b0f2eba32b |
|
MD5 | a4c2adea8ca3e5faf936bb57ef4236a7 |
|
BLAKE2b-256 | 88710420b1f2599b244f774fa845cdf6ce7ab1034b33e862e7cedb308c1ba5fc |
Hashes for kratos-0.0.28-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fb7ed5bcfad6f63ce3893064cef28853ccfa38a7b8f645a94bf6e2b8dc19dcf |
|
MD5 | e5805b0299524987bc51812edc6fe08d |
|
BLAKE2b-256 | df2d1a2571ee82cdc09229930ef7d549771dfcc2a311f5cdc88108f81f753b19 |