apache / tvm

Open deep learning compiler stack for cpu, gpu and specialized accelerators
https://tvm.apache.org/
Apache License 2.0
11.73k stars 3.46k forks source link

Dump module to llvm ir #5804

Closed chaozju closed 4 years ago

chaozju commented 4 years ago

Is there a way to dump the Module to llvm ir into a .s file which can be later built to standalone executable by clang ?

where I am:

scripted_model = torch.jit.trace(model, input_data).eval() mod, params = relay.frontend.from_pytorch(scripted_model,shape_list)

with relay.build_config(opt_level=3): graph, lib, params = relay.build(mod,target='llvm',target_host='llvm',params=params)

with open('/home/chao/tvm-playground/tvm-project/a.s','w') as f: f.write(lib.get_source())


- assembling and linking with llvm backend
```bash
llvm-as -o a.bc a.s
llc -o a.o a.bc
as a.o -o a.as
cp ~/tvm/build/libtvm*.so ./
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD
ld -L "./libtvm.so" "./libtvm_runtime.so" "./libtvm_topi.so" -o a.out a.as
tqchen commented 4 years ago

Move discussion to https://discuss.tvm.ai/t/dump-module-to-llvm-ir/6966/8