Get entire graph in C/LLVM output (not only lib)

Hi,

I am using TVM to obtain either C or LLVM code. In any case, the suggested way (here and in the tutorials) is something like

graph, lib, params = relay.build_module.build(
        mod, target, params=params)

out_file.write(lib.get_source())

This however produces source code for single functions. As I understand, graph contains the information about how they are connected to each other. Is there any way of merging the two types of information, i.e. the implementation of functions from lib and the way they are used from graph?

I used a hack in the tvm code to find the lower ‘c’ or ‘llvm’ code :

In this example code : https://docs.tvm.ai/tutorials/optimize/opt_gemm.html#sphx-glr-tutorials-optimize-opt-gemm-py

Make the following changes :

with tvm.target.cuda():
sg = topi.generic.schedule_reduce(g) print(tvm.lower(sg, [a, b], simple_mode=True))

Hi,
thank you for your answer. Can you expand a bit what the different parameters are?
I am not working on CUDA (but changing the target should not be too difficult), g should be graph in my example? And what about [a,b]?

Yes changing target to llvm should do it.

Also, sg is the output operation to be scheduled
example :

and the [A,B] parameters are the inputs required for that op to be carried out.
example :

k = tvm.reduce_axis((0, K), ‘k’)
A = tvm.placeholder((M, K), name=‘A’)
B = tvm.placeholder((K, N), name=‘B’)
C = tvm.compute( (M, N), lambda x, y: tvm.sum(A[x, k] * B[k, y], axis=k), name=‘C’)

s = tvm.create_schedule(C.op)

print(tvm.lower(s, [A, B, C], simple_mode=True))