Define Neural Network in C++ and Print its SSA IR

Hello Everyone
I am new to TVM and I am looking for how to define a neural network (that consists of common neural network ops such as Convolution) within C++ and print its IR.

So far I have seen this example on defining networks using Python frontend, and printing its SSA, e.g., (from this link):

However, I can’t find a similar example in C++.

Thanks!

1 Like

Most of the documentation and utilities for Relay are exposed in Python, there is an open PR for adding a C++ frontend to Relay. It should hopefully be merged soon: https://github.com/dmlc/tvm/issues/2685.

Thanks @jroesch. I went through the PR and it seems really helpful.
However, I haven’t found a C++ equivalent to astext() to print the SSA IR in the PR. Is there a way to do that?

Nvm… I think I found it: RelayPrint() function defined in \src\relay\ir\pretty_printer.cc

Yes I was about to send it, I opened an issue to unify API names.

Thanks @jroesch!
However, when I tried to add RelayPrint to one of the unit tests, I got a linking error when building it:

I used nm command to find RelayPrint in the .so libraries but I couldn’t find it.
Looking at the CMakeLists.txt it seems that it should be defined in libtvm.so.

Never mind :slight_smile:
I found the solution: need to add TVM_DLL before the declaration of the function (i.e., RelayPrint) to make it invokable.