How to get C code after GEMM optimization python code, on TVM


#1

I wanted to get some C-code from TVM for a given graph for GEMM optimization.
I followed and ran the code in this example given :
https://docs.tvm.ai/tutorials/optimize/opt_gemm.html#sphx-glr-tutorials-optimize-opt-gemm-py

Can I get a function which can produce the C code after the given the python code executes on TVM?

Thanks!


#2

AFAIK, you cannot get a gcc-compilable C code from TVM. TVM generates LLVM IR instead of C code when the target is CPU. Although TVM codegen does have a C code generation, it is an abstract class that was inherited and implemented by the OpenCL codegen for CPU/GPU. Alternatively, you could have two workarounds:

  1. Generate OpenCL code first by binding one axis to thread ID, and manually recover the thread ID back to a loop as well as the miner syntax differences.

  2. Hack TVM by making the abstract C codegen runnable.


#3

codegen_c.cc will translate TVM IR into C code which then can be compiled using a C compiler, etc

in this post , it seems it is possible to have C code as output somewhere in the code_gen folders , which can be accessed.

Can one get to access the C code which is being compiled by TVM ? I wanted to see the C code output that codegen generates from TVM IR