Unable to export lib and, save graph and params to a file


#1

I want to use C++ API to generate executable and for that I need .so, .json and .params files. I were unable to generate these files after compilation. Below are the codes from my python script and makefile. Please make a comment on the issue.

My options inside the python script are:

target = tvm.target.create('llvm -device=arm_cpu -model=bcm2837 -target=arm-linux-gnueabihf-g++ -mattr=+neon')
with relay.build_config(opt_level=3):
    graph, lib, params = relay.build(mod, target=target, params=params)

print("- Saving the TVM files...")

lib.export_library('lib/deploy_lib.so', tvm.contrib.cc.create_shared, cc="/usr/bin/arm-linux-gnueabihf-g++")
with open('lib/deploy_graph.json', "w") as fo:
    fo.write(graph)
with open('lib/deploy_param.params', "wb") as fo:
    fo.write(relay.save_param_dict(params))

My makeflie has configuration as:
CXX = /usr/bin/arm-linux-gnueabihf-g++

PKG_CFLAGS = -std=c++11 -O2 -march=armv7-a -mfloat-abi=hard -mfpu=neon -fPIC\
	-I${TVM_ROOT}/include\
	-I${DMLC_CORE}/include\
	-I${TVM_ROOT}/3rdparty/dlpack/include\

PKG_LDFLAGS = -L${TVM_ROOT}/build -ldl -lpthread

The error which followed:

[06:53:10] /home/ankur/tvm/src/pass/vectorize_loop.cc:371: Detect vector condition in Vectorized Loop, scalarizing...
[06:53:10] /home/ankur/tvm/src/pass/vectorize_loop.cc:371: Detect vector condition in Vectorized Loop, scalarizing...
[06:53:10] /home/ankur/tvm/src/pass/vectorize_loop.cc:371: Detect vector condition in Vectorized Loop, scalarizing...
[06:53:10] /home/ankur/tvm/src/pass/vectorize_loop.cc:371: Detect vector condition in Vectorized Loop, scalarizing...
[06:53:10] /home/ankur/tvm/src/pass/vectorize_loop.cc:371: Detect vector condition in Vectorized Loop, scalarizing...
- Saving the TVM files...
Traceback (most recent call last):

  File "from_tensorflow.py", line 161, in <module>
    lib.export_library('lib/deploy_lib.so', tvm.contrib.cc.create_shared, cc="/usr/bin/arm-linux-gnueabihf-g++")

  File "/home/ankur/tvm/python/tvm/module.py", line 144, in export_library
    fcompile(file_name, files, **kwargs)

  File "/home/ankur/tvm/python/tvm/contrib/cc.py", line 48, in create_shared
    _linux_compile(output, objects, options, cc)

  File "/home/ankur/tvm/python/tvm/contrib/cc.py", line 109, in _linux_compile
    raise RuntimeError(msg)

RuntimeError: Compilation error:
/tmp/tmpw4n1_59l/lib.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

#2

Hi @akssieg

Could you please help me confirm the output/result from following code?

lib.export_library("lib/deploy_lib.so")

many thanks,


#3

@cchung100m
lib.export_library("lib/deploy_lib.so") works without any error but If I do lib.export_library("lib/deploy_lib.so",tvm.contrib.cc.create_shared, cc="/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++") then it shows the following error:
Traceback (most recent call last):

  File "from_tensorflow.py", line 264, in <module>
    save_tvm_files(graph,lib,params,deploy_name='deploy')

  File "from_tensorflow.py", line 223, in save_tvm_files
    lib.export_library("lib/deploy_lib.so",tvm.contrib.cc.create_shared, cc="/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++")

  File "/home/tvm/python/tvm/module.py", line 144, in export_library
    fcompile(file_name, files, **kwargs)

  File "/home/tvm/python/tvm/contrib/cc.py", line 48, in create_shared
    _linux_compile(output, objects, options, cc)

  File "/home/tvm/python/tvm/contrib/cc.py", line 109, in _linux_compile
    raise RuntimeError(msg)

RuntimeError: Compilation error:
/tmp/tmptbnzmpz5/lib.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

#5

I found the solution, the target options were wrong… I corrected it then it started working.