-
Notifications
You must be signed in to change notification settings - Fork 174
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 [DSLX code only] #1092
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce041d7
modules/dbe: add lz4 encoder and decoder
rdob-ant d7e8145
modules/dbe: Lz4 encoder - use abstract RAM interface
rdob-ant becfb46
examples/ram: make SimultaneousReadWriteBehavior public
rdob-ant 3156707
modules/dbe: simplify Lz4 encoder, improve naming
rdob-ant ac43f07
modules/dbe: add documentation for LZ4 encoder
rdob-ant cbce752
modules/dbe: add round-trip test, refactor tests
rdob-ant 9e02abb
modules/dbe: update docs
rdob-ant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
# 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. | ||
|
||
# Build rules for XLS DBE/LZ4 algorithm implementation. | ||
|
||
load( | ||
"//xls/build_rules:xls_build_defs.bzl", | ||
"xls_dslx_library", | ||
"xls_dslx_ir", | ||
"xls_ir_opt_ir", | ||
"xls_ir_verilog", | ||
"xls_dslx_test", | ||
) | ||
|
||
package( | ||
default_applicable_licenses = ["//:license"], | ||
default_visibility = ["//xls:xls_users"], | ||
licenses = ["notice"], | ||
) | ||
|
||
# --------------------------------------------------------------------------- | ||
# Common | ||
# --------------------------------------------------------------------------- | ||
|
||
xls_dslx_library( | ||
name = "dbe_common_dslx", | ||
srcs = [ | ||
"common.x", | ||
], | ||
) | ||
|
||
xls_dslx_library( | ||
name = "dbe_common_test_dslx", | ||
srcs = [ | ||
"common_test.x", | ||
], | ||
deps = [ | ||
":dbe_common_dslx", | ||
], | ||
) | ||
|
||
# --------------------------------------------------------------------------- | ||
# LZ4 decoder | ||
# --------------------------------------------------------------------------- | ||
|
||
xls_dslx_library( | ||
name = "dbe_lz4_decoder_dslx", | ||
srcs = [ | ||
"lz4_decoder.x" | ||
], | ||
deps = [ | ||
":dbe_common_dslx", | ||
"//xls/examples:ram_dslx", | ||
], | ||
) | ||
|
||
xls_dslx_library( | ||
name = "dbe_lz4_decoder_test_dslx", | ||
srcs = [ | ||
"lz4_decoder_test.x" | ||
], | ||
deps = [ | ||
":dbe_common_test_dslx", | ||
":dbe_lz4_decoder_dslx", | ||
], | ||
) | ||
|
||
xls_dslx_test( | ||
name = "dbe_lz4_decoder_dslx_test", | ||
dslx_test_args = { | ||
"compare": "none", | ||
}, | ||
library = ":dbe_lz4_decoder_test_dslx", | ||
) | ||
|
||
xls_dslx_ir( | ||
name = "dbe_lz4_decoder_ir", | ||
dslx_top = "decoder", | ||
library = "dbe_lz4_decoder_dslx", | ||
ir_file = "dbe_lz4_decoder_ir.ir", | ||
) | ||
|
||
xls_ir_opt_ir( | ||
name = "dbe_lz4_decoder_opt_ir", | ||
src = "dbe_lz4_decoder_ir.ir", | ||
top = "__lz4_decoder__decoder__decoder_base_0__16_16_8_next", | ||
ram_rewrites = [ | ||
":lz4_decoder_ram1r1w_rewrites.textproto", | ||
], | ||
) | ||
|
||
xls_ir_verilog( | ||
name = "dbe_lz4_decoder_verilog", | ||
src = "dbe_lz4_decoder_opt_ir.opt.ir", | ||
verilog_file = "dbe_lz4_decoder.v", | ||
codegen_args = { | ||
"module_name": "dbe_lz4_decoder", | ||
"delay_model": "unit", | ||
"pipeline_stages": "3", | ||
"reset": "rst", | ||
"use_system_verilog": "false", | ||
"streaming_channel_data_suffix": "_data", | ||
"ram_configurations": "ram_hb:1R1W:{rd_req}:{rd_resp}:{wr_req}:{wr_comp}".format( | ||
rd_req = "ram_hb_read_req", | ||
rd_resp = "ram_hb_read_resp", | ||
wr_req = "ram_hb_write_req", | ||
wr_comp = "ram_hb_write_completion", | ||
), | ||
}, | ||
) | ||
|
||
# --------------------------------------------------------------------------- | ||
# LZ4 encoder | ||
# --------------------------------------------------------------------------- | ||
|
||
xls_dslx_library( | ||
name = "dbe_lz4_encoder_dslx", | ||
srcs = [ | ||
"lz4_encoder.x" | ||
], | ||
deps = [ | ||
":dbe_common_dslx", | ||
"//xls/examples:ram_dslx", | ||
], | ||
) | ||
|
||
xls_dslx_library( | ||
name = "dbe_lz4_encoder_test_dslx", | ||
srcs = [ | ||
"lz4_encoder_test.x" | ||
], | ||
deps = [ | ||
":dbe_common_test_dslx", | ||
":dbe_lz4_encoder_dslx", | ||
], | ||
) | ||
|
||
xls_dslx_test( | ||
name = "dbe_lz4_encoder_dslx_test", | ||
dslx_test_args = { | ||
"compare": "none", | ||
}, | ||
library = ":dbe_lz4_encoder_test_dslx", | ||
) | ||
|
||
#8K hash specialization | ||
xls_dslx_ir( | ||
name = "dbe_lz4_encoder_8k_ir", | ||
dslx_top = "encoder_8k", | ||
library = "dbe_lz4_encoder_dslx", | ||
ir_file = "dbe_lz4_encoder_8k_ir.ir", | ||
) | ||
|
||
xls_ir_opt_ir( | ||
name = "dbe_lz4_encoder_8k_opt_ir", | ||
src = "dbe_lz4_encoder_8k_ir.ir", | ||
top = "__lz4_encoder__encoder_8k__encoder__encoder_base_0__1_4_13_16_16_8_next", | ||
ram_rewrites = [ | ||
":lz4_encoder_8k_ram1r1w_rewrites.textproto", | ||
], | ||
) | ||
|
||
xls_ir_verilog( | ||
name = "dbe_lz4_encoder_8k_verilog", | ||
src = "dbe_lz4_encoder_8k_opt_ir.opt.ir", | ||
verilog_file = "dbe_lz4_encoder_8k.v", | ||
codegen_args = { | ||
"module_name": "dbe_lz4_encoder", | ||
"delay_model": "unit", | ||
"pipeline_stages": "3", | ||
"worst_case_throughput": "3", | ||
"reset": "rst", | ||
"use_system_verilog": "false", | ||
"streaming_channel_data_suffix": "_data", | ||
"ram_configurations": ",".join([ | ||
"ram_hb:1R1W:{rd_req}:{rd_resp}:{wr_req}:{wr_comp}".format( | ||
rd_req = "ram_hb_read_req", | ||
rd_resp = "ram_hb_read_resp", | ||
wr_req = "ram_hb_write_req", | ||
wr_comp = "ram_hb_write_completion", | ||
), | ||
"ram_ht:1R1W:{rd_req}:{rd_resp}:{wr_req}:{wr_comp}".format( | ||
rd_req = "ram_ht_read_req", | ||
rd_resp = "ram_ht_read_resp", | ||
wr_req = "ram_ht_write_req", | ||
wr_comp = "ram_ht_write_completion", | ||
), | ||
]), | ||
}, | ||
) | ||
|
||
# --------------------------------------------------------------------------- | ||
# Round-trip test | ||
# --------------------------------------------------------------------------- | ||
|
||
xls_dslx_test( | ||
name = "dbe_lz4_round_trip_dslx_test", | ||
dslx_test_args = { | ||
"compare": "none", | ||
}, | ||
srcs = [ | ||
"lz4_round_trip_test.x" | ||
], | ||
deps = [ | ||
":dbe_lz4_encoder_test_dslx", | ||
":dbe_lz4_decoder_test_dslx", | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// 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 | ||
|
||
pub enum Mark : u4 { | ||
// Default initialization value used when marker field is not needed | ||
NONE = 0, | ||
// Signals end of sequence/block | ||
END = 1, | ||
// Requests reset of the processing chain | ||
RESET = 2, | ||
|
||
_ERROR_FIRST = 8, | ||
// Only error marks have values >= __ERROR_FIRST | ||
ERROR_BAD_MARK = 8, | ||
ERROR_INVAL_CP = 9, | ||
} | ||
|
||
pub fn is_error(mark: Mark) -> bool { | ||
(mark as u32) >= (Mark::_ERROR_FIRST as u32) | ||
} | ||
|
||
pub enum TokenKind : u2 { | ||
UNMATCHED_SYMBOL = 0, | ||
MATCHED_SYMBOL = 1, | ||
MATCH = 2, | ||
MARKER = 3, | ||
} | ||
|
||
pub struct Token< | ||
SYMBOL_WIDTH: u32, MATCH_OFFSET_WIDTH: u32, MATCH_LENGTH_WIDTH: u32 | ||
>{ | ||
kind: TokenKind, | ||
symbol: uN[SYMBOL_WIDTH], | ||
match_offset: uN[MATCH_OFFSET_WIDTH], | ||
match_length: uN[MATCH_LENGTH_WIDTH], | ||
mark: Mark | ||
} | ||
|
||
pub struct PlainData<DATA_WIDTH: u32> { | ||
is_marker: bool, | ||
data: uN[DATA_WIDTH], | ||
mark: Mark, | ||
} | ||
|
||
/// Parameters of a classic LZ4 algorithm | ||
/// NOTE: CPU LZ4 implementations do not have match length limited to 16 bits, | ||
/// but 16 bits are more than enough for most real-life use cases, since | ||
/// matches of more than 64KB are very uncommon. | ||
pub const LZ4_SYMBOL_WIDTH = u32:8; | ||
pub const LZ4_MATCH_OFFSET_WIDTH = u32:16; | ||
pub const LZ4_MATCH_LENGTH_WIDTH = u32:16; | ||
pub const LZ4_HASH_SYMBOLS = u32:4; | ||
/// Different hash table sizes | ||
pub const LZ4_HASH_WIDTH_4K = u32:12; | ||
pub const LZ4_HASH_WIDTH_8K = u32:13; | ||
pub const LZ4_HASH_WIDTH_16K = u32:14; | ||
|
||
pub type Lz4Token = Token< | ||
LZ4_SYMBOL_WIDTH, | ||
LZ4_MATCH_OFFSET_WIDTH, | ||
LZ4_MATCH_LENGTH_WIDTH | ||
>; | ||
|
||
pub type Lz4Data = PlainData<LZ4_SYMBOL_WIDTH>; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the dslx is using an abstract ram model, suggest adding the transforms to a real ran model in both the opt_ir and then in codegen -- following https://github.com/google/xls/blob/main/xls/contrib/xlscc/examples/BUILD#L152
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will look into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hongted Hm, I'm a bit confused here. I see that code that targets XLScc (which I haven't looked into at all till today) indeed represents RAM as an abstract object with array-like semantics, which has to be then rewritten to map onto a real-world 1RW or 1R1W RAM core.
Contrary to that, my DSLX code, as well as existing DSLX example code in e.g. xls/examples/delay.x is written with a specific RAM core in mind from the beginning - there is a protocol for 1R1W core (4 channels: 2x output for rd & wr requests, 2x input for rd & wr responses) and a protocol for 1RW core (2 channels: 1x output for combined rd or wr request, 1x input for combined rd or wr response).
If there a way to write DSLX code to target 'abstract' RAM and then rewrite it at opt_ir stage like in case of XLScc, do you know if there's example code that shows this, or at least some file with DSLX struct definitions for the abstract protocol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the example is XLSCC, both XLSCC and DSLX are translated to a common IR.
The idea here is to use to target an an abstract ram model so that we can easily retarget the implementation to whatever ram is available. Whether it's 1RW, 1R1W, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to reply: this was addressed, now there's a configuration for IR optimizer to rewrite the RAM interface.