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

Contributing Intel Tofino compiler backend to p4c #4964

Merged
merged 40 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0c01e47
Add licenses and top level scripts
hanw Oct 16, 2024
424e24b
Add files in top level directory
hanw Oct 16, 2024
4bd5839
Add files under backends/tofino/bf-p4c/arch for handling tna/t2na/v1m…
hanw Oct 16, 2024
d2a4990
Add files under backends/tofino/bf-p4c/arch/psa for handling psa to t…
hanw Oct 16, 2024
b89242c
Add files under backends/tofino/bf-p4c/arch/tna
hanw Oct 16, 2024
c24ff75
Add files under backends/tofino/bf-p4c/common
hanw Oct 16, 2024
d375d80
Add files under backends/tofino/bf-p4c/pragma
hanw Oct 16, 2024
5374a21
Add files under backends/tofino/bf-p4c/control-plane for bfrt support
hanw Oct 16, 2024
6356667
Add files under backends/tofino/bf-p4c/driver for compiler driver
hanw Oct 16, 2024
014db9d
Add files under backends/tofino/bf-p4c/ir for tofino-specific IR
hanw Oct 16, 2024
cdb1a0e
Add files under backends/tofino/bf-p4c/lib
hanw Oct 16, 2024
5338661
Add files under backends/tofino/bf-p4c/logging
hanw Oct 16, 2024
5d2243e
Add files under backends/tofino/bf-p4c/mau
hanw Oct 16, 2024
43003fe
Add files under backends/tofino/bf-p4c/p4include
hanw Oct 16, 2024
2beba19
Add files under backends/tofino/bf-p4c/parde
hanw Oct 16, 2024
b806699
Add files under backends/tofino/bf-p4c/parde/clot
hanw Oct 16, 2024
0fc931f
Add files under backends/tofino/bf-p4c/parde/lowered, common and mirror
hanw Oct 16, 2024
c453a32
Add files under backends/tofino/bf-p4c/parde/phv (part 1)
hanw Oct 16, 2024
72c95a2
Add files under backends/tofino/bf-p4c/parde/phv/analysis (part 2)
hanw Oct 16, 2024
5c05614
Add files under backends/tofino/bf-p4c/parde/phv/pragma (part 3)
hanw Oct 16, 2024
20a4fef
Add files under backends/tofino/bf-p4c/parde/phv/* (part 4)
hanw Oct 16, 2024
46746b4
Add files under backends/tofino/bf-p4c/parde/phv/v2 (part 5)
hanw Oct 16, 2024
fa591ce
Add files under backends/tofino/bf-p4c/test/gtest
hanw Oct 16, 2024
baa1624
Add files under backends/tofino/bf-utils for dynamic_hash library
hanw Oct 16, 2024
7f9ed98
Add files under backends/tofino/compiler-interfaces
hanw Oct 16, 2024
8084bc1
Add files under backends/tofino/scripts for misc scripts
hanw Oct 16, 2024
9f48981
Changes to other backend to fix compilation error
hanw Oct 16, 2024
2c5b518
Changes to top level CMakeLists.txt to add tofino backend
hanw Oct 16, 2024
a93e1d3
fix compilation issues
Oct 18, 2024
9398575
CI script fixes
hanw Oct 18, 2024
0381de3
Fixes for coding-style issues
Oct 19, 2024
e53889d
switch ENABLE_TOFINO to OFF by default
hanw Oct 18, 2024
73ccba1
try 20.04 build
Oct 19, 2024
a64e6b1
add FindZ3.cmake for bf-p4c
Oct 19, 2024
3f789ff
Fix p4c driver issues
Oct 19, 2024
439d803
Addressing review comments
Oct 21, 2024
6663b2d
Update licenses to Apache 2.0
hanw Oct 22, 2024
5e3ba6c
Create new test runner for tofino backend
Oct 23, 2024
cd439da
reenable driver tests
Oct 23, 2024
0e0c88e
address review comments
hanw Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 33 additions & 0 deletions .github/workflows/ci-test-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,39 @@ jobs:
run: sudo -E ctest --output-on-failure --schedule-random
working-directory: ./build

# Build with GCC and test Tofino backend on Ubuntu 22.04.
test-ubuntu22-tofino:
runs-on: ubuntu-22.04
env:
CTEST_PARALLEL_LEVEL: 4
IMAGE_TYPE: test
BUILD_GENERATOR: Ninja
ENABLE_GTESTS: ON
ENABLE_TOFINO: ON
ENABLE_BMV2: OFF
ENABLE_EBPF: OFF
ENABLE_UBPF: OFF
ENABLE_DPDK: OFF
ENABLE_P4TC: OFF
ENABLE_P4FMT: OFF
ENABLE_P4TEST: OFF
ENABLE_P4C_GRAPHS: OFF
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: test-${{ runner.os }}-gcc
max-size: 1000M

- name: Build (Ubuntu 22.04, GCC)
run: |
tools/ci-build.sh

# Build with GCC and test P4C on Ubuntu 20.04.
test-ubuntu20:
name: test-ubuntu20 (Unity ${{ matrix.unity }}, GTest ${{ matrix.gtest }})
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ docs/doxygen/p4c-doxygen-warn.log

# Local Documentation build theme files
docs/doxygen/awesome_css/

# thirdparty
backends/tofino/third_party/
32 changes: 19 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Copyright 2013-present Barefoot Networks, Inc.
#
# 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.
# Copyright (C) 2024 Intel Corporation
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

# This is the CMake version supplied by Ubuntu 20.04.
cmake_minimum_required (VERSION 3.16.3 FATAL_ERROR)
Expand Down Expand Up @@ -39,6 +40,7 @@ OPTION (ENABLE_BMV2 "Build the BMV2 backend (required for the full test suite)"
OPTION (ENABLE_EBPF "Build the EBPF backend (required for the full test suite)" ON)
OPTION (ENABLE_UBPF "Build the uBPF backend (required for the full test suite)" ON)
OPTION (ENABLE_DPDK "Build the DPDK backend (required for the full test suite)" ON)
OPTION (ENABLE_TOFINO "Build the TOFINO backend (required for the full test suite)" OFF)
OPTION (ENABLE_P4TC "Build the P4TC backend" ON)
OPTION (ENABLE_P4FMT "Build the P4FMT backend" ON)
OPTION (ENABLE_P4TEST "Build the P4Test backend (required for the full test suite)" ON)
Expand Down Expand Up @@ -374,6 +376,7 @@ include_directories (
${P4C_SOURCE_DIR}
${P4C_BINARY_DIR}
${P4C_SOURCE_DIR}/extensions
${P4C_SOURCE_DIR}/backends/tofino ## FIXME
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing this refers to fixing the include paths?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should not be needed -- but I guess just removing it currently breaks things? If it is needed, it should probably be in backends/tofino/CMakeLists.txt, but I'm unsure how cmake nesting works in general.

add_definitions (-DCONFIG_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_definitions (-DCONFIG_PKGDATADIR="${CMAKE_INSTALL_PREFIX}/${P4C_ARTIFACTS_OUTPUT_DIRECTORY}")
Expand Down Expand Up @@ -487,6 +490,9 @@ endif ()
if (ENABLE_UBPF)
add_subdirectory (backends/ubpf)
endif ()
if (ENABLE_TOFINO)
add_subdirectory (backends/tofino)
endif ()
if (ENABLE_GTESTS)
add_subdirectory (test)
endif ()
Expand Down
1 change: 1 addition & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ filter=-runtime/references
filter=-readability/todo
filter=-readability/function
filter=-readability/casting
filter=-readability/fn_size
linelength=100
# Do not use 'p4c' as the cpp header guard prefix.
root=.
Expand Down
8 changes: 6 additions & 2 deletions backends/common/psaProgramStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ limitations under the License.

namespace P4 {

enum gress_t { INGRESS, EGRESS };
enum psa_gress_t {
INGRESS,
EGRESS,
};

enum block_t {
PARSER,
PIPELINE,
Expand All @@ -32,7 +36,7 @@ enum block_t {
class PsaProgramStructure : public PortableProgramStructure {
public:
/// Architecture related information.
ordered_map<const IR::Node *, std::pair<gress_t, block_t>> block_type;
ordered_map<const IR::Node *, std::pair<psa_gress_t, block_t>> block_type;

public:
PsaProgramStructure(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
Expand Down
68 changes: 0 additions & 68 deletions backends/p4tools/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,3 @@ function(add_p4tools_executable target source)
install(TARGETS ${target} RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
endfunction(add_p4tools_executable)

macro(p4tools_obtain_z3)
option(TOOLS_USE_PREINSTALLED_Z3 "Look for a preinstalled version of Z3 instead of installing a prebuilt binary using FetchContent." OFF)

if(TOOLS_USE_PREINSTALLED_Z3)
# We need a fairly recent version of Z3.
set(Z3_MIN_VERSION "4.8.14")
# But 4.12+ is currently broken with libGC
set(Z3_MAX_VERSION_EXCL "4.12")
find_package(Z3 ${Z3_MIN_VERSION} REQUIRED)

if(NOT DEFINED Z3_VERSION_STRING OR ${Z3_VERSION_STRING} VERSION_LESS ${Z3_MIN_VERSION})
message(FATAL_ERROR "The minimum required Z3 version is ${Z3_MIN_VERSION}. Has ${Z3_VERSION_STRING}.")
endif()
if(${Z3_VERSION_STRING} VERSION_GREATER_EQUAL ${Z3_MAX_VERSION_EXCL})
message(FATAL_ERROR "The Z3 version has to be lower than ${Z3_MAX_VERSION_EXCL} (the latter currently does no work with libGC). Has ${Z3_VERSION_STRING}.")
endif()
# Set variables for later consumption.
set(P4TOOLS_Z3_LIB z3::z3)
set(P4TOOLS_Z3_INCLUDE_DIR ${Z3_INCLUDE_DIR})
else()
# Pull in a specific version of Z3 and link against it.
set(P4TOOLS_Z3_VERSION "4.11.2")
message("Fetching Z3 version ${P4TOOLS_Z3_VERSION} for P4Tools...")

# Determine platform to fetch pre-built Z3
if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(Z3_ARCH "x64")
if (APPLE)
set(Z3_PLATFORM_SUFFIX "osx-10.16")
set(Z3_ZIP_HASH "a56b6c40d9251a963aabe1f15731dd88ad1cb801d0e7b16e45f8b232175e165c")
elseif (UNIX)
set(Z3_PLATFORM_SUFFIX "glibc-2.31")
set(Z3_ZIP_HASH "9d0f70e61e82b321f35e6cad1343615d2dead6f2c54337a24293725de2900fb6")
else()
message(FATAL_ERROR "Unsupported system platform")
endif()
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(Z3_ARCH "arm64")
if (APPLE)
set(Z3_PLATFORM_SUFFIX "osx-11.0")
set(Z3_ZIP_HASH "c021f381fa3169b1f7fb3b4fae81a1d1caf0dd8aa4aa773f4ab9d5e28c6657a4")
else()
message(FATAL_ERROR "Unsupported system platform")
endif()
else()
message(FATAL_ERROR "Unsupported system processor")
endif()

# Print out download state while setting up Z3.
set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET})
set(FETCHCONTENT_QUIET OFF)
fetchcontent_declare(
z3
URL https://github.com/Z3Prover/z3/releases/download/z3-${P4TOOLS_Z3_VERSION}/z3-${P4TOOLS_Z3_VERSION}-${Z3_ARCH}-${Z3_PLATFORM_SUFFIX}.zip
URL_HASH SHA256=${Z3_ZIP_HASH}
USES_TERMINAL_DOWNLOAD TRUE
GIT_PROGRESS TRUE
)
fetchcontent_makeavailable(z3)
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV})
message("Done with setting up Z3 for P4Tools.")

# Other projects may also pull in Z3.
# We have to make sure we only include our local version with P4Tools.
set(P4TOOLS_Z3_LIB ${z3_SOURCE_DIR}/bin/libz3${CMAKE_STATIC_LIBRARY_SUFFIX})
set(P4TOOLS_Z3_INCLUDE_DIR ${z3_SOURCE_DIR}/include)
endif()
endmacro(p4tools_obtain_z3)
1 change: 1 addition & 0 deletions backends/p4tools/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Handle the Z3 installation with this macro. Users have the option to supply their own Z3.
include(${P4C_SOURCE_DIR}/cmake/Z3.cmake)
p4tools_obtain_z3()

# Generate version information.
Expand Down
Loading
Loading