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

[Squeeze] Introduce Squeeze and Unsqueeze hardware operators #1153

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
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
57 changes: 57 additions & 0 deletions finn-rtllib/passthru/rtl/passthru_axi.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/******************************************************************************
* Copyright (C) 2024, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Thomas B. Preußer <[email protected]>
* @brief Wiring-only pass-thru AXI-Stream connector.
*/

module passthru_axi #(
int unsigned DATA_WIDTH
)(
// Global Control - NOT USED
input logic ap_clk,
input logic ap_rst_n,

// Input Stream
input logic [DATA_WIDTH-1:0] s_axis_tdata,
input logic s_axis_tvalid,
output logic s_axis_tready,

// Output Stream
output logic [DATA_WIDTH-1:0] m_axis_tdata,
output logic m_axis_tvalid,
input logic m_axis_tready
);
// Simple pass-through Connection
assign m_axis_tdata = s_axis_tdata;
assign m_axis_tvalid = s_axis_tvalid;
assign s_axis_tready = m_axis_tready;

endmodule : passthru_axi
62 changes: 62 additions & 0 deletions finn-rtllib/passthru/rtl/passthru_template_wrapper.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******************************************************************************
* Copyright (C) 2024, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Thomas B. Preußer <[email protected]>
* @brief Verilog wrapper for IP packaging.
*/

module $MODULE_NAME_AXI_WRAPPER$ #(
int unsigned DATA_WIDTH = $DATA_WIDTH$
)(
// Global Control - NOT USED
(* X_INTERFACE_PARAMETER = "ASSOCIATED_BUSIF s_axis:m_axis, ASSOCIATED_RESET ap_rst_n" *)
(* X_INTERFACE_INFO = "xilinx.com:signal:clock:1.0 ap_clk CLK" *)
input ap_clk,
(* X_INTERFACE_PARAMETER = "POLARITY ACTIVE_LOW" *)
input ap_rst_n,

// Input Stream
input logic [DATA_BITS-1:0] s_axis_tdata,
input logic s_axis_tvalid,
output logic s_axis_tready,

// Output Stream
output logic [DATA_BITS-1:0] m_axis_tdata,
output logic m_axis_tvalid,
input logic m_axis_tready
);

passthru_axi #(.DATA_BITS(DATA_BITS)) core (
.ap_clk(ap_clk), .ap_rst_n(ap_rst_n),
.s_axis_tdata(s_axis_tdata), .s_axis_tvalid(s_axis_tvalid), .s_axis_tready(s_axis_tready),
.m_axis_tdata(m_axis_tdata), .m_axis_tvalid(m_axis_tvalid), .m_axis_tready(m_axis_tready)
);

endmodule // $MODULE_NAME_AXI_WRAPPER$
32 changes: 30 additions & 2 deletions src/finn/custom_op/fpgadataflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# The base class of all generic custom operations before specializing to either
# HLS or RTL backend
from finn.custom_op.fpgadataflow.hwcustomop import HWCustomOp

# Dictionary of HWCustomOp implementations
custom_op = dict()


# Registers a class into the custom_op dictionary
# Note: This must be defined first, before importing any custom op
# implementation to avoid "importing partially initialized module" issues.
def register_custom_op(cls):
# The class must actually implement HWCustomOp
assert issubclass(cls, HWCustomOp), f"{cls} must subclass {HWCustomOp}"
# Insert the class into the custom_op dictionary by its name
custom_op[cls.__name__] = cls # noqa: Some weird type annotation issue?
# Pass through the class unmodified
return cls


# flake8: noqa
# Disable linting from here, as all import will be flagged E402 and maybe F401


# Import the submodule containing the Squeeze operation
# Note: This will automatically register all decorated classes into this domain
import finn.custom_op.fpgadataflow.squeeze
# Import the submodule containing the Unsqueeze operation
import finn.custom_op.fpgadataflow.unsqueeze

from finn.custom_op.fpgadataflow.addstreams import AddStreams
from finn.custom_op.fpgadataflow.channelwise_op import ChannelwiseOp
from finn.custom_op.fpgadataflow.concat import StreamingConcat
Expand Down Expand Up @@ -55,8 +85,6 @@
from finn.custom_op.fpgadataflow.upsampler import UpsampleNearestNeighbour
from finn.custom_op.fpgadataflow.vectorvectoractivation import VVAU

custom_op = dict()

# make sure new HLSCustomOp subclasses are imported here so that they get
# registered and plug in correctly into the infrastructure
custom_op["MVAU"] = MVAU
Expand Down
36 changes: 34 additions & 2 deletions src/finn/custom_op/fpgadataflow/hls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# The base class of all HWCustomOp specializations to HLS backend implementation
from finn.custom_op.fpgadataflow.hlsbackend import HLSBackend

# The base class of all generic custom operations before specializing to either
# HLS or RTL backend
from finn.custom_op.fpgadataflow.hwcustomop import HWCustomOp

# Dictionary of HLSBackend implementations
custom_op = dict()


# Registers a class into the custom_op dictionary
# Note: This must be defined first, before importing any custom op
# implementation to avoid "importing partially initialized module" issues.
def register_custom_op(cls):
# The class must actually implement HWCustomOp
assert issubclass(cls, HWCustomOp), f"{cls} must subclass {HWCustomOp}"
# The class must also implement the HLSBackend
assert issubclass(cls, HLSBackend), f"{cls} must subclass {HLSBackend}"
# Insert the class into the custom_op dictionary by its name
custom_op[cls.__name__] = cls # noqa: Some weird type annotation issue?
# Pass through the class unmodified
return cls


# flake8: noqa
# Disable linting from here, as all import will be flagged E402 and maybe F401

# Import the submodule containing the specialization of the Squeeze operation
# Note: This will automatically register all decorated classes into this domain
import finn.custom_op.fpgadataflow.hls.squeeze_hls
# Import the submodule containing the specialization of the Unsqueeze operation
import finn.custom_op.fpgadataflow.hls.unsqueeze_hls

from finn.custom_op.fpgadataflow.hls.addstreams_hls import AddStreams_hls
from finn.custom_op.fpgadataflow.hls.channelwise_op_hls import ChannelwiseOp_hls
from finn.custom_op.fpgadataflow.hls.checksum_hls import CheckSum_hls
Expand Down Expand Up @@ -53,8 +87,6 @@
from finn.custom_op.fpgadataflow.hls.upsampler_hls import UpsampleNearestNeighbour_hls
from finn.custom_op.fpgadataflow.hls.vectorvectoractivation_hls import VVAU_hls

custom_op = dict()

# make sure new HLSCustomOp subclasses are imported here so that they get
# registered and plug in correctly into the infrastructure
custom_op["AddStreams_hls"] = AddStreams_hls
Expand Down
Loading
Loading