Closed zyddnys closed 3 years ago
It looks like the SAI backend defines a new IR instruction named IntMod, which clashes with the IntMod instruction defined by the BMv2 back-end. Unfortunately at this point all these classes live in the same namespace. It could be useful to have some kind of name mangling rules for these IR classes to enable them to co-exist. The SAI compilation instructions suggest disabling the other back-ends. Have you tried that?
I tried disabling all other backends with cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_BMV2=OFF -DENABLE_EBPF=OFF -DENABLE_P4TEST=OFF -DENABLE_P4C_GRAPHS=OFF ..
, but now I am getting complication errors:
Output of make
[ 0%] Built target linkp4cdpdk
[ 0%] Built target linksai
[ 0%] Built target update_includes
[ 0%] Built target linkp4cubpf
[ 1%] Building CXX object lib/CMakeFiles/p4ctoolkit.dir/unified_libp4ctoolkit_srcs_1.cpp.o
[ 1%] Built target mkv1dirs
[ 1%] Built target mkP4configdir
[ 1%] Built target mkp4dirs
[ 2%] Building CXX object test/CMakeFiles/gtest.dir/frameworks/gtest/googletest/src/gtest-all.cc.o
[ 3%] Copying p4c driver
[ 3%] Built target p4c_driver
In file included from /home/unknown/p4/p4c/build/lib/unified_libp4ctoolkit_srcs_1.cpp:5:
/home/unknown/p4/p4c/lib/crash.cpp: In function ‘const char* addr2line(void*, const char*)’:
/home/unknown/p4/p4c/lib/crash.cpp:141:17: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
141 | (void) write(to_child, buffer, p-buffer);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 3%] Linking CXX static library libgtest.a
[ 3%] Built target gtest
[ 4%] Linking CXX static library libp4ctoolkit.a
[ 4%] Built target p4ctoolkit
[ 6%] [BISON][IRgenParser] Building parser with bison 3.5.1
[ 6%] [FLEX][IRgenLexer] Building scanner with flex 2.6.4
ir-generator.ypp:95.1-14: warning: deprecated directive: ‘%error-verbose’, use ‘%define parse.error verbose’ [-Wdeprecated]
95 | %error-verbose
| ^~~~~~~~~~~~~~
| %define parse.error verbose
ir-generator.ypp: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
[ 8%] Building CXX object tools/ir-generator/CMakeFiles/irgenerator.dir/ir-generator.cpp.o
[ 8%] Building CXX object tools/ir-generator/CMakeFiles/irgenerator.dir/unified_irgenerator_srcs_1.cpp.o
[ 8%] Linking CXX executable irgenerator
[ 8%] Built target irgenerator
[ 9%] Generating IR class files
[ 9%] Built target genIR
[ 10%] [BISON][v1Parser] Building parser with bison 3.5.1
parsers/v1/v1parser.ypp:24.1-36: warning: deprecated directive: ‘%define parser_class_name {V1Parser}’, use ‘%define api.parser.class {V1Parser}’ [-Wdeprecated]
24 | %define parser_class_name {V1Parser}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| %define api.parser.class {V1Parser}
parsers/v1/v1parser.ypp:34.1-14: warning: deprecated directive: ‘%error-verbose’, use ‘%define parse.error verbose’ [-Wdeprecated]
34 | %error-verbose
| ^~~~~~~~~~~~~~
| %define parse.error verbose
[ 12%] Building CXX object ir/CMakeFiles/ir.dir/unified_ir_srcs_1.cpp.o
[ 13%] Building CXX object midend/CMakeFiles/midend.dir/unified_midend_srcs_1.cpp.o
[ 14%] Building CXX object extensions/sai/CMakeFiles/saibackend.dir/json_stage/action.cpp.o
parsers/v1/v1parser.ypp: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
[ 15%] [BISON][p4Parser] Building parser with bison 3.5.1
parsers/p4/p4parser.ypp:24.1-36: warning: deprecated directive: ‘%define parser_class_name {P4Parser}’, use ‘%define api.parser.class {P4Parser}’ [-Wdeprecated]
24 | %define parser_class_name {P4Parser}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| %define api.parser.class {P4Parser}
parsers/p4/p4parser.ypp:34.1-14: warning: deprecated directive: ‘%error-verbose’, use ‘%define parse.error verbose’ [-Wdeprecated]
34 | %error-verbose
| ^~~~~~~~~~~~~~
| %define parse.error verbose
parsers/p4/p4parser.ypp: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
[ 16%] Running Flex on parsers/v1
[ 17%] Running Flex on parsers/p4
[ 18%] Building CXX object frontends/CMakeFiles/frontend.dir/parsers/p4/p4lexer.cc.o
In file included from /home/unknown/p4/p4c/extensions/sai/json_stage/expression.h:29,
from /home/unknown/p4/p4c/extensions/sai/json_stage/backend.h:22,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:16:
/home/unknown/p4/p4c/extensions/sai/json_stage/helpers.h:74:20: error: ‘mpz_class’ was not declared in this scope; did you mean ‘mpz_clears’?
74 | cstring stringRepr(mpz_class value, unsigned bytes = 0);
| ^~~~~~~~~
| mpz_clears
/home/unknown/p4/p4c/extensions/sai/json_stage/helpers.h:74:37: error: expected primary-expression before ‘unsigned’
74 | cstring stringRepr(mpz_class value, unsigned bytes = 0);
| ^~~~~~~~
In file included from /home/unknown/p4/p4c/extensions/sai/json_stage/backend.h:36,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:16:
/home/unknown/p4/p4c/extensions/sai/json_stage/saiSwitch.h: In constructor ‘SAI::SaiSwitch::SaiSwitch()’:
/home/unknown/p4/p4c/extensions/sai/json_stage/saiSwitch.h:122:39: error: no matching function for call to ‘Model::Model::Model(const char [4])’
122 | SaiSwitch() : ::Model::Model("0.2") {}
| ^
In file included from /home/unknown/p4/p4c/frontends/p4/coreLibrary.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/expression.h:25,
from /home/unknown/p4/p4c/extensions/sai/json_stage/backend.h:22,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:16:
/home/unknown/p4/p4c/frontends/common/model.h:61:7: note: candidate: ‘constexpr Model::Model::Model()’
61 | class Model {};
| ^~~~~
/home/unknown/p4/p4c/frontends/common/model.h:61:7: note: candidate expects 0 arguments, 1 provided
/home/unknown/p4/p4c/frontends/common/model.h:61:7: note: candidate: ‘constexpr Model::Model::Model(const Model::Model&)’
/home/unknown/p4/p4c/frontends/common/model.h:61:7: note: no known conversion for argument 1 from ‘const char [4]’ to ‘const Model::Model&’
/home/unknown/p4/p4c/frontends/common/model.h:61:7: note: candidate: ‘constexpr Model::Model::Model(Model::Model&&)’
/home/unknown/p4/p4c/frontends/common/model.h:61:7: note: no known conversion for argument 1 from ‘const char [4]’ to ‘Model::Model&&’
/home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp: In member function ‘void SAI::ConvertActions::convertActionBody(const IR::Vector<IR::StatOrDecl>*, Util::JsonArray*)’:
/home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:78:63: error: cannot convert ‘const IR::Argument* const’ to ‘const IR::Expression*’
78 | auto arg = conv->convert(mc->arguments->at(0));
| ~~~~~~~~~~~~~~~~~^~~
| |
| const IR::Argument* const
In file included from /home/unknown/p4/p4c/extensions/sai/json_stage/backend.h:22,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:16:
/home/unknown/p4/p4c/extensions/sai/json_stage/expression.h:93:48: note: initializing argument 1 of ‘Util::IJson* SAI::ExpressionConverter::convert(const IR::Expression*, bool, bool, bool)’
93 | Util::IJson* convert(const IR::Expression* e, bool doFixup = true,
| ~~~~~~~~~~~~~~~~~~~~~~^
/home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:83:63: error: cannot convert ‘const IR::Argument* const’ to ‘const IR::Expression*’
83 | auto arg = conv->convert(mc->arguments->at(0));
| ~~~~~~~~~~~~~~~~~^~~
| |
| const IR::Argument* const
In file included from /home/unknown/p4/p4c/extensions/sai/json_stage/backend.h:22,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:16:
/home/unknown/p4/p4c/extensions/sai/json_stage/expression.h:93:48: note: initializing argument 1 of ‘Util::IJson* SAI::ExpressionConverter::convert(const IR::Expression*, bool, bool, bool)’
93 | Util::IJson* convert(const IR::Expression* e, bool doFixup = true,
| ~~~~~~~~~~~~~~~~~~~~~~^
/home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:108:63: error: cannot convert ‘const IR::Argument* const’ to ‘const IR::Expression*’
108 | auto obj = conv->convert(mc->arguments->at(i));
| ~~~~~~~~~~~~~~~~~^~~
| |
| const IR::Argument* const
In file included from /home/unknown/p4/p4c/extensions/sai/json_stage/backend.h:22,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.h:21,
from /home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:16:
/home/unknown/p4/p4c/extensions/sai/json_stage/expression.h:93:48: note: initializing argument 1 of ‘Util::IJson* SAI::ExpressionConverter::convert(const IR::Expression*, bool, bool, bool)’
93 | Util::IJson* convert(const IR::Expression* e, bool doFixup = true,
| ~~~~~~~~~~~~~~~~~~~~~~^
/home/unknown/p4/p4c/extensions/sai/json_stage/action.cpp:101:22: warning: unused variable ‘extrn’ [-Wunused-variable]
101 | auto extrn = mi->to<P4::ExternFunction>();
| ^~~~~
make[2]: *** [extensions/sai/CMakeFiles/saibackend.dir/build.make:76: extensions/sai/CMakeFiles/saibackend.dir/json_stage/action.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:938: extensions/sai/CMakeFiles/saibackend.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
These look like issues in the SAI back end. You may have more luck filing an issue there. The instruction mention to checkout a specific commit:
git clone https://github.com/p4lang/p4c.git
git checkout 6d265b2d15b927db522c08f36a60fe23784e8357
git submodule update --init --recursive
That commit is very old, so it is likely that many things have changed since then.
Yes, it looks like the code you are trying to compile has not been maintained to keep pace with changes in the compiler Your best bet is to ask for help from the original maintainer of the SAI code. If you are interested to bring it up to date and maintain it you can fork that repository and we can probably help you figure out what needs to be changed.
Well, it seems that SAI backend is no longer maintained, I wonder what would happen to all the P4 programmable switches running SONiC, how people are going to program them without using SAI. Is their any other SAI backend implementations p4c currently supports?
I do not know the details (but can find out if there is interest), but most of the work to get SONiC and SAI working on a P4 programmable switch is getting the right control plane software running on top of it, not anything special in the P4 compiler (that I am aware of -- but could be ignorant of precisely what is done there). Intel's Tofino can run under SONiC if the P4 program has the right set of tables included that are compatible with the part of the SAI API being used.
I see, thank you guys for helping me out here, I know what to do now.
I was trying to compile p4c with SAI extension by creating a soft link p4c/extensions/sai to SAI/flexsai/p4/backend/. However compilation failed with
IntMod: Duplicate class name
. Here is the full log ofmake -j32
:Here is the full log of
cmake -DCMAKE_BUILD_TYPE=Release ..
:I tried to switch to branch 6d265b2d15b927db522c08f36a60fe23784e8357, it also failed because no p4_14include folder was found.