p4lang / behavioral-model

The reference P4 software switch
Apache License 2.0
545 stars 329 forks source link

Does bmv2 support some hardware features (e.g., VLIW)? #901

Closed wtao0221 closed 4 years ago

wtao0221 commented 4 years ago

Hi,

Here is a general discussion question. I am wondering whether bmv2 supports some hardware features like VLIW?

If no, is there any way to extend bmv2 to support those HW features? Do I need to also extend the p4c for bmv2 backend?

Thanks in advance.

jafingerhut commented 4 years ago

Are you asking whether bmv2, when running as a process on, for example, a modern Intel or AMD processor, does it take advantage of fancy SIMD or vector instructions?

My guess is that the answer is "almost certainly no, unless the g++ compiler happens to be smart enough to emit them in certain situations".

"is there any way to extend bmv2 to support those HW features?" There are multiple ways to modify bmv2 to make this happen, but I doubt any of them are quick 10-line changes. Most fields in P4 programs are 48 bits or less, and fit within a single 64-bit register, so individual operations on one or two such fields could not get a performance increase by using such instructions. It would require analyzing larger sequences of operations in a P4 program and looking for cases where such operations would improve performance, and I suspect a lot of P4 programs as they are typically written would not make an optimizing compiler's job straightforward in this regard, just as it is not easy to do this automatically for C code that was not written with such instructions in mind.

If you had a different question in mind than what I guessed, please try to clarify your question.

wtao0221 commented 4 years ago

Thanks for your reply.

By "HW features", I mean the hardware features of the target (e.g., Tofino). Or should I say does bmv2 backend considers such hardware features (e.g., VLIW) in its design?

antoninbas commented 4 years ago

bmv2 and Tofino are separate targets. They don't have anything in common besides overlap in the P4 programs they support (they both support the v1model architecture, even though it is not always trivial to run the exact same P4 program on both) and the fact that they both support P4Runtime as a control-plane API.

bmv2 is certainly not a register-accurate simulator of Tofino and there is no concept of VLIW in bmv2.

wtao0221 commented 4 years ago

Thanks for elaboration.