Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/dbe - lz4 encoder and decoder #1079

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dependency_support/pip_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ termcolor==1.1.0
psutil==5.7.0
portpicker==1.3.1
pyyaml==6.0.1
cocotb==1.8.0
cocotb_bus==0.2.1

# Note: numpy and scipy version availability seems to differ between Ubuntu
# versions that we want to support (e.g. 18.04 vs 20.04), so we accept a
Expand Down
8 changes: 4 additions & 4 deletions dependency_support/rules_hdl/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def repo():
],
)

# Commit on 2023-06-13, current as of 2023-06-13.
git_hash = "e6540a5bccbfb124aec0b19deaa9cf855781b3a5"
git_sha256 = "21307b0c14a036f1b4879c8f1d4d50a115053eb87c428307d4d6569c3e7ba859"
# Commit on 2023-07-25, current as of 2023-07-25
git_hash = "b036366bae45a03628d2bc891c97bb700992bb67"
git_sha256 = "70bce281469986440f8b4a09a093a28a2a9b00d83d4f4b2cd47cf5497944ab19"

maybe(
http_archive,
name = "rules_hdl",
sha256 = git_sha256,
strip_prefix = "bazel_rules_hdl-%s" % git_hash,
urls = [
"https://github.com/hdl/bazel_rules_hdl/archive/%s.tar.gz" % git_hash,
"https://github.com/antmicro/bazel_rules_hdl/archive/%s.tar.gz" % git_hash,
],
)
37 changes: 37 additions & 0 deletions xls/build_rules/cocotb_xls_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_hdl//cocotb:cocotb.bzl", "cocotb_test")

def cocotb_xls_test(**kwargs):
name = kwargs["name"]
top = kwargs["hdl_toplevel"]

if "timescale" in kwargs:
timescale = kwargs["timescale"]
timestamp_target = name + "-timescale"
timestamp_verilog = name + "_timescale.v"
native.genrule(
name = timestamp_target,
srcs = [],
cmd = "echo \\`timescale {}/{} > $@".format(
timescale["unit"],
timescale["precission"],
),
outs = [timestamp_verilog],
)
kwargs["verilog_sources"].insert(0, timestamp_verilog)
kwargs.pop("timescale")

cocotb_test(**kwargs)
55 changes: 55 additions & 0 deletions xls/examples/cocotb/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2023 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@xls_pip_deps//:requirements.bzl", "requirement")
load("//xls/build_rules:xls_build_defs.bzl", "xls_dslx_verilog")
load("//xls/build_rules:cocotb_xls_test.bzl", "cocotb_xls_test")

xls_dslx_verilog(
name = "running_counter_verilog",
srcs = ["running_counter.x"],
deps = [],
codegen_args = {
"delay_model": "unit",
"clock_period_ps": "5000",
"reset": "rst",
"module_name": "RunningCounter",
"use_system_verilog": "false",
"streaming_channel_data_suffix": "_data",
},
dslx_top = "RunningCounter",
verilog_file = "running_counter.v",
)

cocotb_xls_test(
name = "running_counter_cocotb",
hdl_toplevel = "RunningCounter",
hdl_toplevel_lang = "verilog",
test_module = [
"cocotb_running_counter.py",
],
verilog_sources = [
"dumpvcd.v",
":running_counter.v",
],
timescale = {
"unit": "1ns",
"precission": "1ps",
},
deps = [
requirement("cocotb"),
requirement("cocotb_bus"),
"//xls/simulation/cocotb:cocotb_xls",
],
)
70 changes: 70 additions & 0 deletions xls/examples/cocotb/cocotb_running_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2023 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cocotb

from cocotb.clock import Clock
from cocotb.triggers import Event, ClockCycles
from cocotb.binary import BinaryValue

from cocotb_bus.scoreboard import Scoreboard
from cocotb_xls import XLSChannelDriver, XLSChannelMonitor

from typing import List, Any


def list_to_binary_value(data: List, n_bits: int = 32, bigEndian=False) -> List[BinaryValue]:
return [BinaryValue(x, n_bits, bigEndian) for x in data]


def init_sim(dut, data_to_send: List[BinaryValue], data_to_recv: List[BinaryValue]):
clock = Clock(dut.clk, 10, units="us")

driver = XLSChannelDriver(dut, "running_counter__base_r", dut.clk)
monitor = XLSChannelMonitor(dut, "running_counter__cnt_s", dut.clk)

scoreboard = Scoreboard(dut, fail_immediately=True)
scoreboard.add_interface(monitor, data_to_recv)

total_of_packets = len(data_to_recv)
terminate = Event("Last packet of data received")

def terminate_cb(transaction):
if monitor.stats.received_transactions == total_of_packets:
terminate.set()

monitor.add_callback(terminate_cb)
monitor.bus.rdy.setimmediatevalue(1)

return (clock, driver, terminate)


@cocotb.coroutine
async def reset(clk, rst, cycles=1):
rst.setimmediatevalue(1)
await ClockCycles(clk, cycles)
rst.value = 0


@cocotb.test(timeout_time=10, timeout_unit="ms")
async def counter_test(dut):
data_to_send = list_to_binary_value([0x100, 0x100, 0x100])
data_to_recv = list_to_binary_value([0x102, 0x103, 0x104])

(clock, driver, terminate) = init_sim(dut, data_to_send, data_to_recv)

cocotb.start_soon(clock.start())
await reset(dut.clk, dut.rst, 10)
await driver.write(data_to_send)
await terminate.wait()
20 changes: 20 additions & 0 deletions xls/examples/cocotb/dumpvcd.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module wavedump();
initial begin
$dumpfile("dump.vcd");
$dumpvars(0, RunningCounter);
end
endmodule
67 changes: 67 additions & 0 deletions xls/examples/cocotb/running_counter.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2023 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import std

proc RunningCounter {
base_r: chan<u32> in;
cnt_s: chan<u32> out;

init { u32:0 }

config(base_r: chan<u32> in, cnt_s: chan<u32> out) {
(base_r, cnt_s)
}

next(tok: token, cnt: u32) {
let (tok, base, base_valid) = recv_non_blocking(tok, base_r, u32:0);
let tok = send_if(tok, cnt_s, base_valid, cnt + base);
let cnt_next = cnt + u32:1;
cnt_next
}
}

#[test_proc]
proc RunningCounterTester {
terminator: chan<bool> out;
base_s: chan<u32> out;
cnt_r: chan<u32> in;

init { u32:0 }

config (terminator: chan<bool> out) {
let (base_s, base_r) = chan<u32>;
let (cnt_s, cnt_r) = chan<u32>;

spawn RunningCounter(base_r, cnt_s);
(terminator, base_s, cnt_r)
}

next(tok: token, recv_cnt: u32) {
let next_state = if (recv_cnt < u32:10) {
let tok = send(tok, base_s, u32:1);
let (tok, cnt) = recv(tok, cnt_r);

trace_fmt!("Received {} cnt", recv_cnt);
assert_lt(u32:1, cnt);

recv_cnt + u32:1
} else {
send(tok, terminator, true);
u32:0
};

(next_state)
}
}
15 changes: 15 additions & 0 deletions xls/examples/cocotb/timescale.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

`timescale 1ns/1ps
Loading