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

PHV allocation issue in Tofino compiler #5046

Open
komaljai opened this issue Dec 3, 2024 · 5 comments
Open

PHV allocation issue in Tofino compiler #5046

komaljai opened this issue Dec 3, 2024 · 5 comments
Labels
question This is a topic requesting clarification. tofino Topics related to the Tofino switch and back end.

Comments

@komaljai
Copy link
Contributor

komaljai commented Dec 3, 2024

struct ingress_metadata_t
{
    bit<32> first_tunnel_id;
    bit<32> first_ip;
    bit <32> shift_bits;
    bit<32> temp_ip_result;
    bit<32> temp_ipv6_lowest_word;
 }
header vxlan_t {
	bit<8> flags;
	bit<24> reserved;
        bit<24> vni;
	bit<8> reserved2;
}
header ipv4_t {
    bit<32> srcAddr;
    bit<32> dstAddr;
}
action subtraction_ipv4(){
        ig_md.temp_ip_result = hdr.ipv4.srcAddr - ig_md.first_ip;
}
action typecast_tunnel_id_vxlan(){
        hdr.outer_vxlan.vni = (bit<24>)ig_md.temp_ip_result;
}

I have a query about how to change the action 'typecast_tunnel_id_vxlan' to make successful PHV allocation in Tofino2?

Here, ig_md.temp_ip_result is allocated in two 16 bit container
ingress::hdr.outer_vxlan.vni[23:16] |[-1r, 6w] |MB6
ingress::hdr.outer_vxlan.vni[15:0] |[-1r, 6w] |MH19

hdr.ipv4.srcAddr is allocated in one container of 32 bits
ingress::hdr.ipv4.srcAddr |[-1r, 6w] |MW1

The allocation of ig_md.temp_ip_result is the question.
Scenario 1 : If I comment subtraction_ipv4 action, ig_md.temp_ip_result is allocated at 4 8 bits container.
Scenario 2 : If I comment typecast_tunnel_id_vxlan action, ig_md.temp_ip_result is allocated as 32 bit container.

Having both actions give PHV allocation not successful error, how can I rewrite the action or add any annotation for compiler to make this work?

@komaljai
Copy link
Contributor Author

komaljai commented Dec 3, 2024

@ChrisDodd , @grg @hanw Could you help?

@komaljai komaljai added question This is a topic requesting clarification. tofino Topics related to the Tofino switch and back end. labels Dec 3, 2024
@vgurevich
Copy link

@komaljai ,

The first thing you need to know is that pretty much any issue involving Tofino P4 compiler must be accompanied by the full source code of the corresponding program. The reason is that everything is so intertwined that even minor changes in the code in one part of the program can drastically affect the compilation of another, seemingly unrelated part.

Second, it is also critically important to specify the version of the compiler you are using.

@vgurevich
Copy link

I would also argue that fitting issues with any specific program should not be filed against the compiler unless the submitter can actually prove that this is a compiler issue, e.g. by providing a manual working allocation that the compiler fails to find.

Doing otherwise would not be that different than filing an issue every time GCC (or any other compiler) compiles a function while using more than N instructions or using more than M words on a stack.

@komaljai
Copy link
Contributor Author

komaljai commented Dec 4, 2024

@komaljai ,

The first thing you need to know is that pretty much any issue involving Tofino P4 compiler must be accompanied by the full source code of the corresponding program. The reason is that everything is so intertwined that even minor changes in the code in one part of the program can drastically affect the compilation of another, seemingly unrelated part.

Second, it is also critically important to specify the version of the compiler you are using.

I will attach the program.

@hanw
Copy link
Contributor

hanw commented Dec 4, 2024

Can you try this compiler option: --alt-phv-alloc. I wonder if that makes a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This is a topic requesting clarification. tofino Topics related to the Tofino switch and back end.
Projects
None yet
Development

No branches or pull requests

3 participants