Skip to content

Commit 35a215a

Browse files
committed
resolve linter errors
Signed-off-by: Wojciech Sipak <[email protected]>
1 parent 8b23ebd commit 35a215a

14 files changed

+663
-274
lines changed

xls/modules/zstd/README.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ decoder's `Memory Interface`.
2828

2929
Once the decoding process is started, the decoder:
3030

31-
1. Reads the configuration from the CSRs,
32-
2. Decodes the Frame Header,
33-
3. Decodes the Block Header,
34-
4. Decodes the Block Data with the correct processing unit picked based on the
35-
Block Type from the Block Header,
36-
5. Aggregates the processing unit results in the correct order into a stream
37-
and routes it to the history buffer,
38-
6. Assembles the data block outputs based on the history buffer contents and
39-
updates the history,
40-
7. Prepares the final output of the decoder and writes it to the memory,
41-
8. (Optional) Calculates checksum and compares it against the checksum read
42-
from the frame.[^2]
31+
1. Reads the configuration from the CSRs,
32+
2. Decodes the Frame Header,
33+
3. Decodes the Block Header,
34+
4. Decodes the Block Data with the correct processing unit picked based on the
35+
Block Type from the Block Header,
36+
5. Aggregates the processing unit results in the correct order into a stream
37+
and routes it to the history buffer,
38+
6. Assembles the data block outputs based on the history buffer contents and
39+
updates the history,
40+
7. Prepares the final output of the decoder and writes it to the memory,
41+
8. (Optional) Calculates checksum and compares it against the checksum read
42+
from the frame.[^2]
4343

4444
![brief data flow diagram of ZstdDecoder](img/ZSTD_decoder.png)
4545

@@ -253,14 +253,14 @@ This stage receives data which is tagged either `literals` or `copy`. This stage
253253
will show the following behavior, depending on the tag:
254254

255255
* `literals`
256-
* Packet contents placed as newest in the history buffer,
257-
* Packet contents copied to the decoder's output,
256+
* Packet contents placed as newest in the history buffer,
257+
* Packet contents copied to the decoder's output,
258258
* `copy`
259-
* Wait for all previous writes to be completed,
260-
* Copy `copy_length` literals starting `offset _length` from the newest in
261-
history buffer to the decoder's output,
262-
* Copy `copy_length` literals starting `offset _length` from the newest in
263-
history buffer to the history buffer as the newest.
259+
* Wait for all previous writes to be completed,
260+
* Copy `copy_length` literals starting `offset _length` from the newest in
261+
history buffer to the decoder's output,
262+
* Copy `copy_length` literals starting `offset _length` from the newest in
263+
history buffer to the history buffer as the newest.
264264

265265
### Compressed block decoder architecture[^1] {#compressed-block-decoder-architecture1}
266266

@@ -360,10 +360,10 @@ FSE decoder or to direct weight extraction.
360360

361361
This stage performs multiple functions.
362362

363-
1. It decodes and builds the FSE distribution table.
364-
2. It stores all remaining bitstream data.
365-
3. After receiving the last byte, it translates the bitstream to Huffman
366-
weights using 2 interleaved FSE streams.
363+
1. It decodes and builds the FSE distribution table.
364+
2. It stores all remaining bitstream data.
365+
3. After receiving the last byte, it translates the bitstream to Huffman
366+
weights using 2 interleaved FSE streams.
367367

368368
##### Direct weight decoder
369369

@@ -468,8 +468,7 @@ Crossbar](https://github.com/alexforencich/verilog-axi).
468468

469469
![diagram of interfaces of decoder and its wrapper](img/ZSTD_decoder_wrapper.png)
470470

471-
**Figure
472-
Zstd decoder wrapper connection diagram.**
471+
**Figure: Zstd decoder wrapper connection diagram.**
473472

474473
Cocotb testbench interacts with the decoder with the help of a
475474
[cocotbext-axi](https://github.com/alexforencich/cocotbext-axi) extension that
@@ -545,19 +544,19 @@ calculated from current `WINDOW_LOG_MAX` (by default in Top Level Proc tests
545544

546545
The `assert!()` or `fail!()` will occur in:
547546

548-
* RawBlockDecoder
549-
* Receive `BlockDataPacket` with `ID` different than the previous packet which
550-
did not have the `last` flag set
551-
* DecoderMux
552-
* At the beginning of the simulation or after receiving
553-
`ExtendedBlockDataPacket` with `last` and `last_block` (decoding new ZSTD
554-
frame) set receive on channels `raw_r`, `rle_r` and `cmp_r`
555-
`ExtendedBlockDataPackets` without any of those having `ID==0`
556-
* Receive `ExtendedBlockDataPacket` with a smaller `ID` than any of the
557-
previously processed packets during the current ZSTD frame decoding
558-
* SequenceExecutor
559-
* Receive `SequenceExecutorPacket` with `msg_type==SEQUENCE` and `content`
560-
field with value: `0`
547+
* RawBlockDecoder
548+
* Receive `BlockDataPacket` with `ID` different than the previous packet
549+
which did not have the `last` flag set
550+
* DecoderMux
551+
* At the beginning of the simulation or after receiving
552+
`ExtendedBlockDataPacket` with `last` and `last_block` (decoding new ZSTD
553+
frame) set receive on channels `raw_r`, `rle_r` and `cmp_r`
554+
`ExtendedBlockDataPackets` without any of those having `ID==0`
555+
* Receive `ExtendedBlockDataPacket` with a smaller `ID` than any of the
556+
previously processed packets during the current ZSTD frame decoding
557+
* SequenceExecutor
558+
* Receive `SequenceExecutorPacket` with `msg_type==SEQUENCE` and `content`
559+
field with value: `0`
561560

562561
There are also several `impossible cases` covered by `fail!()`.
563562
Those are mostly enforced by the type checker for the `match` expressions to

xls/modules/zstd/cocotb/channel.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class XLSChannel(Bus):
3737
_optional_signals = XLS_CHANNEL_OPTIONAL_SIGNALS
3838

3939
def __init__(self, entity, name, clk, *, start_now=False, **kwargs: Any):
40-
super().__init__(entity, name, self._signals, self._optional_signals, **kwargs)
40+
super().__init__(
41+
entity, name, self._signals, self._optional_signals, **kwargs
42+
)
4143
self.clk = clk
4244
if start_now:
4345
self.start_recv_loop()
@@ -58,17 +60,30 @@ class XLSChannelDriver(BusDriver):
5860
_signals = XLS_CHANNEL_SIGNALS
5961
_optional_signals = XLS_CHANNEL_OPTIONAL_SIGNALS
6062

61-
def __init__(self, entity: SimHandleBase, name: str, clock: SimHandleBase, **kwargs: Any):
63+
def __init__(
64+
self,
65+
entity: SimHandleBase,
66+
name: str,
67+
clock: SimHandleBase,
68+
**kwargs: Any
69+
):
6270
BusDriver.__init__(self, entity, name, clock, **kwargs)
6371

6472
self.bus.data.setimmediatevalue(0)
6573
self.bus.vld.setimmediatevalue(0)
6674

67-
async def _driver_send(self, transaction: Transaction, sync: bool = True, **kwargs: Any) -> None:
75+
async def _driver_send(
76+
self,
77+
transaction: Transaction,
78+
sync: bool = True,
79+
**kwargs: Any
80+
) -> None:
6881
if sync:
6982
await RisingEdge(self.clock)
7083

71-
data_to_send = (transaction if isinstance(transaction, Sequence) else [transaction])
84+
data_to_send = (
85+
transaction if isinstance(transaction, Sequence) else [transaction]
86+
)
7287

7388
for word in data_to_send:
7489
self.bus.vld.value = 1
@@ -83,11 +98,18 @@ async def _driver_send(self, transaction: Transaction, sync: bool = True, **kwar
8398

8499

85100
class XLSChannelMonitor(BusMonitor):
86-
"""Monitors and decodes transactions on an XLS channel."""
101+
"""Monitors and decodes transactions on an XLS channel."""
87102
_signals = XLS_CHANNEL_SIGNALS
88103
_optional_signals = XLS_CHANNEL_OPTIONAL_SIGNALS
89104

90-
def __init__(self, entity: SimHandleBase, name: str, clock: SimHandleBase, struct: Type[XLSStruct], **kwargs: Any):
105+
def __init__(
106+
self,
107+
entity: SimHandleBase,
108+
name: str,
109+
clock: SimHandleBase,
110+
struct: Type[XLSStruct],
111+
**kwargs: Any
112+
):
91113
BusMonitor.__init__(self, entity, name, clock, **kwargs)
92114
self.struct = struct
93115

xls/modules/zstd/cocotb/data_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import zstandard
2323

2424
class BlockType(enum.Enum):
25+
"""Enum encoding of ZSTD block types."""
26+
2527
RAW = 0
2628
RLE = 1
2729
COMPRESSED = 2
@@ -38,7 +40,9 @@ def from_string(s):
3840
raise ValueError(str(e)) from e
3941

4042
def CallDecodecorpus(args):
41-
decodecorpus = pathlib.Path(runfiles.get_path("decodecorpus", repository = "zstd"))
43+
decodecorpus = pathlib.Path(
44+
runfiles.get_path("decodecorpus", repository = "zstd")
45+
)
4246
cmd = args
4347
cmd.insert(0, str(decodecorpus))
4448
cmd_concat = " ".join(cmd)

xls/modules/zstd/cocotb/memory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
Extensions of the cocotb AXI RAM models that initialize
17-
memory contents from a binary file.
16+
Extensions of the cocotb AXI RAM models to memory contents from a binary file.
1817
"""
1918

2019
import os

xls/modules/zstd/cocotb/scoreboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _current_cycle(self):
6060
def _req_callback(self, transaction: XLSStruct):
6161
self.pending_req.put(LatencyQueueItem(transaction, self._current_cycle()))
6262

63-
def _resp_callback(self, _transaction: XLSStruct):
63+
def _resp_callback(self, unused_transaction: XLSStruct):
6464
latency_item = self.pending_req.get()
6565
self.results.append(self._current_cycle() - latency_item.timestamp)
6666

xls/modules/zstd/cocotb/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626

2727

2828
def setup_com_iverilog():
29-
iverilog_path = pathlib.Path(runfiles.get_path("iverilog", repository = "com_icarus_iverilog"))
30-
vvp_path = pathlib.Path(runfiles.get_path("vvp", repository = "com_icarus_iverilog"))
29+
iverilog_path = pathlib.Path(
30+
runfiles.get_path("iverilog", repository = "com_icarus_iverilog")
31+
)
32+
vvp_path = pathlib.Path(
33+
runfiles.get_path("vvp", repository = "com_icarus_iverilog")
34+
)
3135
os.environ["PATH"] += os.pathsep + str(iverilog_path.parent)
3236
os.environ["PATH"] += os.pathsep + str(vvp_path.parent)
3337
build_dir = pathlib.Path(os.environ['BUILD_WORKING_DIRECTORY'], "sim_build")

xls/modules/zstd/cocotb/xlsstruct.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
"""
1818

1919
import random
20-
from dataclasses import asdict
21-
from dataclasses import astuple
22-
from dataclasses import dataclass
23-
from dataclasses import fields
20+
import dataclasses
2421

2522
from cocotb.binary import BinaryValue
2623

@@ -42,21 +39,23 @@ class MyStruct(XLSStruct):
4239
Returns:
4340
type: The dataclass-decorated class with repr disabled.
4441
"""
45-
return dataclass(cls, repr=False)
42+
return dataclasses.dataclass(cls, repr=False)
4643

47-
@dataclass
44+
@dataclasses.dataclass
4845
class XLSStruct:
49-
"""
50-
Represents XLS struct on the Python side, allowing serialization/deserialization
51-
to/from common formats and usage with XLS{Driver, Monitor}.
46+
"""Represents XLS struct on the Python side.
47+
48+
Allows serialization/deserialization to/from common formats and usage with
49+
XLS{Driver, Monitor}.
5250
53-
The intended way to use this class is to inherit from it, specify the fields with
54-
<field>: <width> [= <default value>] syntax and decorate the inheriting class with
55-
@XLSDataclass. Objects of this class can be instantiated and used like usual
56-
dataclass objects, with a few extra methods and properties available. They can also
57-
be passed as arguments to XLSChannelDriver.send and will be serialized to expected
58-
bit vector. Class can be passed to XLSChannelMonitor ``struct`` constructor argument
59-
to automatically deserialize all transfers to the provided struct.
51+
The intended way to use this class is to inherit from it, specify the fields
52+
with <field>: <width> [= <default value>] syntax and decorate the inheriting
53+
class with @XLSDataclass. Objects of this class can be instantiated and used
54+
like usual dataclass objects, with a few extra methods and properties
55+
available. They can also be passed as arguments to XLSChannelDriver.send and
56+
will be serialized to expected bit vector. Class can be passed to
57+
XLSChannelMonitor ``struct`` constructor argument to automatically
58+
deserialize all transfers to the provided struct.
6059
6160
Example:
6261
@@ -88,7 +87,7 @@ def _masks(cls):
8887
returns [2'b11, 3'b111, 4'b1111].
8988
"""
9089
masks = []
91-
for field in fields(cls):
90+
for field in dataclasses.fields(cls):
9291
width = field.type
9392
masks += [(1 << width) - 1]
9493
return masks
@@ -101,7 +100,7 @@ def _positions(cls):
101100
returns [20, 18, 15, 11, 6, 0]
102101
"""
103102
positions = []
104-
for i, field in enumerate(fields(cls)):
103+
for i, field in enumerate(dataclasses.fields(cls)):
105104
width = field.type
106105
if i == 0:
107106
positions += [cls.total_width - width]
@@ -113,17 +112,18 @@ def _positions(cls):
113112
@property
114113
def total_width(cls):
115114
"""Returns total bit width of the struct."""
116-
return sum(field.type for field in fields(cls))
115+
return sum(field.type for field in dataclasses.fields(cls))
117116

118117
@property
119118
def value(self):
120119
"""Returns struct's value as a Python integer."""
121120
value = 0
122121
masks = self._masks()
123122
positions = self._positions()
124-
for field_val, mask, pos in zip(astuple(self), masks, positions):
123+
for field_val, mask, pos in zip(
124+
dataclasses.astuple(self), masks, positions):
125125
if field_val > mask:
126-
raise TruncationError(f"Signal value is wider than its bit width")
126+
raise TruncationError("Signal value is wider than its bit width")
127127
value |= (field_val & mask) << pos
128128
return value
129129

@@ -151,15 +151,15 @@ def from_int(cls, value):
151151
instance = {}
152152
masks = cls._masks()
153153
positions = cls._positions()
154-
for field, mask, pos in zip(fields(cls), masks, positions):
154+
for field, mask, pos in zip(dataclasses.fields(cls), masks, positions):
155155
instance[field.name] = (value >> pos) & mask
156156
return cls(**instance)
157157

158158
@classmethod
159159
def randomize(cls):
160160
"""Returns an instance of the struct with all fields' values randomized."""
161161
instance = {}
162-
for field in fields(cls):
162+
for field in dataclasses.fields(cls):
163163
instance[field.name] = random.randrange(0, 2**field.type)
164164
return cls(**instance)
165165

@@ -168,5 +168,7 @@ def __str__(self):
168168

169169
def __repr__(self):
170170
classname = self.__class__.__name__
171-
class_fields = [f"{name}={hex(value)}" for name, value in asdict(self).items()]
171+
class_fields = [
172+
f"{name}={hex(value)}" for name, value in dataclasses.asdict(self).items()
173+
]
172174
return f"{classname}({', '.join(class_fields)})"

0 commit comments

Comments
 (0)