Generating GPU code in TVM (and check out the generated code)


I’m interested in examining some of generated code by TVM for GPU.

Especially, I’d like to generate the convolution code in Fig 15 (for the ResNet-18 model) in the TVM paper (

I understand that I need to do some automated search in Fig 12 in the paper.

How can I run the automated search that is similar to Fig 12 in the paper? Any of the two models (ML-based model and Blackbox Genetic Algorithm) would work for me.

If anyone could share the code for that, it would be great! (or anything similar, for example, auto-search code for GEMM is also very helpful.


Recently, I found how i do Genetic algorithm based or ML based automated search(‘autotvm’ module), but i still can’t find method about getting generated cuda codes.

If someone answer the question about getting the cuda codes, it will be very helpful!

You can get the source code generated by tvm in the tvm.Module returned by

  • For gpu: source_code = lib.imported_modules[0].get_source()
  • For cpu: source_code = lib.get_source()
    (Where lib is the name of the module returned by
1 Like


I have two more questions

  1. How to specify a customized CUDA codegen when building/compiling the model?
  2. How to output/print the code generated by a customized CUDA codegen?