p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
682 stars 446 forks source link

p4c-dpdk back end does not support 128-bit arithmetic #4174

Open jafingerhut opened 1 year ago

jafingerhut commented 1 year ago

With commit #4952, p4c-dpdk supports many operations on 128-bit values.

The one known remaining omission is that it does not support 128-bit constant literal values, which are used by the current DASH program, and seem likely to be desirable to use in many P4 programs that manipulate 128-bit values.

The text of the original issue from 2023-Sep-23 is given below, for historical reference:

With this p4c commit https://github.com/p4lang/p4c/pull/4171 the p4c-dpdk back end at least usually correctly reports when it does not support a P4 program that uses arithmetic operations on operands larger than 64 bits in size.

This issue is meant to track one possible enhancement that would enable a larger class of useful P4 programs to compile and run on P4-DPDK, which is: implement arithmetic on operands up to 128 bits in size in the P4-DPDK software switch, and then modify the p4c-dpdk back end compiler to take advantage of these operations.

Motivation: IPv6 addresses are commonly manipulated data values in P4 programs, and often arithmetic operations are performed on these values, especially these operations:

I believe that implementing at least the operations above would enable the DASH P4 code to compile without changes. For example, see the commands in issue https://github.com/p4lang/p4c/issues/4156

I have attempted to modify the P4 code mentioned there to work with the current p4c-dpdk back end and P4-DPDK software switch as of 2023-Sep-23, but I do not think this is feasible. It is necessary to at least be able to do an lpm match kind in a table key on a full 128-bit IPv6 address, and also to compare a 128-bit value to 0, and to do bit-wise AND, OR, and XOR. There is no practical way in P4 to do an lpm match on two 64-bit fields that works the same way as a 128-bit lpm match.

I would recommend that the P4-DPDK back end be enhanced to support all of the following operations, too, on any values up to 128 bits wide:

Sosutha commented 1 month ago

PR for supporting 128 bitwise operations on dpdk compiler backend. https://github.com/p4lang/p4c/pull/4952

KrisNey-MSFT commented 3 weeks ago

Looks like 4952 in p4lang/p4c is Merged. Can this one be updated?

fruffy commented 3 weeks ago

The failures are not completely resolved yet and the program is still marked XFail: https://github.com/p4lang/p4c/blob/main/backends/dpdk/DpdkXfail.cmake#L29

https://github.com/p4lang/p4c/pull/4952#issuecomment-2432751386 describes the remaining work to do.

jafingerhut commented 3 weeks ago

For anyone looking for the gory details, basically the PR https://github.com/p4lang/p4c/pull/4952 did add a lot of support for 128-bit operations in p4lang/p4c DPDK back end. However, even with that PR it still does not support 128-bit constant values in the P4 source program, which the DASH program does use some of. The bad news is that there are still 2 error messages (shown below) with a 2024-Oct-31 version of p4c source code. The good news is that the number of error messages is down from something-over-20 down to 2 with the changes in PR https://github.com/p4lang/p4c/pull/4952

$ git clone https://github.com/sonic-net/DASH
$ cd DASH
$ git log -n 1 | head -n 3
commit ee1fa2350a444409e20ad825b13fafdf67010e41
Author: Shaofeng Wu <69145577+ShaofengWu123@users.noreply.github.com>
Date:   Tue Nov 5 17:24:32 2024 +0800

$ cd dash-pipeline/bmv2
$ mkdir -p output
$ $HOME/forks/p4c/build/p4c-dpdk \
    -DTARGET_DPDK_PNA -DPNA_CONNTRACK \
    --arch pna \
    --p4runtime-files output/dash_pipeline.p4info.txtpb \
    --bf-rt-schema output/dash_pipeline.bfrt.json \
    -o output/dash_pipeline.spec \
    --pp output/dash_pipeline.pp.p4 \
    dash_pipeline.p4

[ ... many warning messages omitted ... ]

[--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit
[--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit
stages/../dash_routing_types.p4(173): [--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit
    inout metadata_t meta,
                     ^^^^
KrisNey-MSFT commented 3 weeks ago

Nice work!!! (error message decrease) 😊

From: Andy Fingerhut @.> Sent: Tuesday, November 5, 2024 4:11 PM To: p4lang/p4c @.> Cc: Kristina Moore @.>; Comment @.> Subject: Re: [p4lang/p4c] p4c-dpdk back end does not support 128-bit arithmetic (Issue #4174)

For anyone looking for the gory details, basically the PR #4952https://github.com/p4lang/p4c/pull/4952 did add a lot of support for 128-bit operations in p4lang/p4c DPDK back end. However, even with that PR it still does not support 128-bit constant values in the P4 source program, which the DASH program does use some of. The bad news is the 2 error messages shown below with a 2024-Oct-31 version of p4c source code. The good news is that the number of error messages is down from something-over-20 down to 2 with the changes in PR #4952https://github.com/p4lang/p4c/pull/4952

$ git clone https://github.com/sonic-net/DASH

$ cd DASH

$ git log -n 1 | head -n 3

commit ee1fa2350a444409e20ad825b13fafdf67010e41

Author: Shaofeng Wu @.**@.>>

Date: Tue Nov 5 17:24:32 2024 +0800

$ cd dash-pipeline/bmv2

$ mkdir -p output

$ $HOME/forks/p4c/build/p4c-dpdk \

-DTARGET_DPDK_PNA -DPNA_CONNTRACK \

--arch pna \

--p4runtime-files output/dash_pipeline.p4info.txtpb \

--bf-rt-schema output/dash_pipeline.bfrt.json \

-o output/dash_pipeline.spec \

--pp output/dash_pipeline.pp.p4 \

dash_pipeline.p4

[ ... many warning messages omitted ... ]

[--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit

[--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit

stages/../dash_routing_types.p4(173): [--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit

inout metadata_t meta,

                 ^^^^

— Reply to this email directly, view it on GitHubhttps://github.com/p4lang/p4c/issues/4174#issuecomment-2458383553, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFJSI6DZABYRFYTATTVCTJTZ7FGBVAVCNFSM6AAAAABPTYEHQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJYGM4DGNJVGM. You are receiving this because you commented.Message ID: @.**@.>>