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! Thanks to hgdb.
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.
Async 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
Thanks to the native support of hgdb, you can debug the generated RTL with a professional debugger as if you are debugging Python code. gdb-like console version is also available. Check out hgdb to see how it works!
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
File details
Details for the file kratos-0.1.3.tar.gz
.
File metadata
- Download URL: kratos-0.1.3.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96168b94a0647257f44149f8fde856d49ca77b0b0fb13fc95726513fe4153696 |
|
MD5 | c7b439be4c5374b7da2e53dddf131aee |
|
BLAKE2b-256 | ee8f0e9534f55b2495fe02e6dc706e865e591c3c9b6f3def1c4d10bbcfdfe560 |
File details
Details for the file kratos-0.1.3-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14ce3bcec4dd5c9af51beefdb899d8c8dc6375242d0ead6feb83e76853ea2883 |
|
MD5 | 64f92044028de335590d22f13d062a8a |
|
BLAKE2b-256 | 0308b432b078fedabe11109d469b94bf6aa52ba155fd4620bcc290579e4f0f8e |
File details
Details for the file kratos-0.1.3-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0905cc985d2d9035f2fc9a9ccfc2262bf78eb3feacd22caf06ba8dba197a1617 |
|
MD5 | 43287883d1c6c0dbc6521b25725ce303 |
|
BLAKE2b-256 | 0be323086c5fb31ec52d363db959af509674f02250675c7cbed5adf5f63d463b |
File details
Details for the file kratos-0.1.3-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a03e3361af66dd39b13c875ee490f185e474fa68b2e279f40297002e8c8f16a |
|
MD5 | a3bdcf5e62dce47341eeea0305f113fe |
|
BLAKE2b-256 | 515ad59aaed7ed25d622ad55f67077391de81ce1bf45382e824f269ad6be8a12 |
File details
Details for the file kratos-0.1.3-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ad069197f38ac0eea009701383b1b457d5b79bd759847ccb9faed37a416c91f |
|
MD5 | 2661827278c6a6655c6ad2dbba61406f |
|
BLAKE2b-256 | 970ca81ca3eb5f4cab1ebc55f6e03b0cf76759f669aed9f6d4b4d94ab8ad5aca |
File details
Details for the file kratos-0.1.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2a0970d5c74020c6b811a612d668dc26aa9ad1cb86fff04789cfe20399d70c9 |
|
MD5 | 8106cc4b1743386aaa038471edffd63d |
|
BLAKE2b-256 | 1fc27b6e7048ffdf3ac191a243fe1baa1634a7ccaa547f506d6d718e5de8bb78 |
File details
Details for the file kratos-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7ec2e98d5a0b9055ece74fddd1b4e8636e7698fb7e763bc3b34626e9c441877 |
|
MD5 | 5803459bca9448cd9c7f572763f1b594 |
|
BLAKE2b-256 | 884451d663c88e54849363361989bed537b40c3bcd99ae32f5611e268bbe9e5d |
File details
Details for the file kratos-0.1.3-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16ec743b384ab67919a0d80bf131d605eb51cfe83c84412bfac3da3e4cf84695 |
|
MD5 | c3b8e9a94fd3b86183966eeb7231583e |
|
BLAKE2b-256 | 196f8550746247a63d1d379c86910104bf7507b7f063508ea0ad450ddb79bee2 |
File details
Details for the file kratos-0.1.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfa0344721a28fa91cf094951c51bc8dc3017fcffbd6a2201fa68900343d3f4e |
|
MD5 | 17e0f198c19dbd8d1027b9fb6dbf664a |
|
BLAKE2b-256 | 55daa60fef7d997a7e9c3aa4a1deb3ca0d2de0c7769a71f2358b2e6f8f56b30b |
File details
Details for the file kratos-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92421d853f232543ea55291ef9a0d7aa527c646526cdf73e91b93b98cd8851b8 |
|
MD5 | 6227a1ce600c9d420313a1b330a5084d |
|
BLAKE2b-256 | 30b70d32642a3cc76e205283b504fdb794046680e2930f4ab3f74d6cf03aa352 |
File details
Details for the file kratos-0.1.3-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a14a9e30e92806d7df7562eb1b1db6a122c57fb18a3b0b390be8d3c28d398b1 |
|
MD5 | f45e7a337ef50d8021325691b8cf5112 |
|
BLAKE2b-256 | 752e8c72c88951eb8a1221e4af81ffa7913295395af2caca012dfccaaa2e2305 |
File details
Details for the file kratos-0.1.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8c316b898d47d01d7810bd0f192b6e53198e18d4e57d3e29e04617887b4dc0 |
|
MD5 | 92a670d659786488fab230bc452a7bb8 |
|
BLAKE2b-256 | e0db3711c49b552cafa81785bc5d3d309f9ae4b1d8176edf7629eacad7c8f4a5 |
File details
Details for the file kratos-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d2a640d03494710166cd62c06639017dd0a5bbf5056e99bd422077031357a6b |
|
MD5 | e712c698bdc4ad3b1d3891caac7f5c68 |
|
BLAKE2b-256 | 9d42b7b4fc0a8592625f2798a867dcda0693e365719b084251b059d5f5e47e76 |
File details
Details for the file kratos-0.1.3-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35e63bb877591dfff775f16b3863be81f1f15e5e7eb22e048b3b3643d912b6cf |
|
MD5 | 6fa6b123af31b470286eb3591ebf50d8 |
|
BLAKE2b-256 | 2ad4f463cda2ee341e62cd19cda1424c2b1c22b0c4833e23ef306e7be2e0feca |
File details
Details for the file kratos-0.1.3-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b1194b1e3771d9504936cfdaa8d6a5d11d8cb95860ca1181b61b79f3582c5f |
|
MD5 | 08526642e56f6d981e63da7454556576 |
|
BLAKE2b-256 | d66ee0e0ed1a5838dc0a9d7b10a6a6c85c942e4c43ab07d580dba37308110ece |
File details
Details for the file kratos-0.1.3-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: kratos-0.1.3-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fb26cdba3257baf0a8898ce31ccb2aef1125190055efd75a2cb0ab42a613f95 |
|
MD5 | 576898a5d1a39ec7ea8e87e5ecf3b165 |
|
BLAKE2b-256 | 79a7e87f59897e7e3c05e5eaed85d1d6c1e0a27598dd7389169c03027aa994d2 |