Build Error with tensorized call_packed in AutoTVM

Hi there,

I ran into a build-error in autoTVM, when using call_packed and a custom python function for tensorization.
This is the used python function:

    @tvm.register_func("tvm.contrib.gemv_update")
    def gemv_update(c, a, b, m, l, stride):
        C = c.asnumpy()
        B = b.asnumpy()
        A = a.asnumpy()
        C = A.dot(B.T)
        c.copyfrom(C)
        return 0

and changed the call from tensorize.py to :

ib.emit(tvm.call_packed("tvm.contrib.gemv_update",cc,aa,bb,m,l,bb.strides[0])

Without AutoTVM, this approach builds and runs successfully.

However, If I use this code in AutoTVM (I added the code to tune_simple_template.py ) , the following error appears when running the tuner:

(RuntimeError('Except caught from RPC call: TVMCall CFunc Error:
    Traceback (most recent call last):  File "/home/rid2rng/tvm/tvm/python/tvm/_ffi/_ctypes/function.py", line 55, in cfun
    rv = local_pyfunc(*pyargs)
    File "/home/rid2rng/tvm/tvm/python/tvm/rpc/server.py", line 50, in load_module
        m = _load_module(path)
        File "/home/rid2rng/tvm/tvm/python/tvm/module.py", line 241, in load
            _cc.create_shared(path + ".so", files)
              File "/home/rid2rng/tvm/tvm/python/tvm/contrib/cc.py", line 33, in create_shared
                  _linux_shared(output, objects, options, cc)
                    File "/home/rid2rng/tvm/tvm/python/tvm/contrib/cc.py", line 58, in _linux_shared
                        raise RuntimeError(msg)\nRuntimeError: Compilation error:
                        /usr/bin/ld: /tmp/tmpt5frypyt/lib.o: relocation R_X86_64_32S against `.rodata.cst16\' can not be used when making a shared object; recompile with -fPIC
                        /usr/bin/ld: final link failed: Nonrepresentable section on output\ncollect2: error: ld returned 1 exit status\n\n',),), error_no=4,

The error Message appears in the AutoTVM tuning log print, in MeasureResults(costs=,…)
It looks like the object file used by LocalBuild in AutoTVM isn’t built with the -fPIC flag.
Is this fixable by adding the -fPIC flag to build of the object? If so, where would I have to do this?

You might be able to modify the AutoTVM build function to see if a change there can support your needs (e.g., compare it with building without AutoTVM to see what changes) https://github.com/dmlc/tvm/blob/master/python/tvm/autotvm/measure/measure_methods.py#L352. Have you configured some different build options when building without AutoTVM?

The build options with and without AutoTVM are the same and the target is llvm for both builds. I also realized that embedding the “tensorization.py” tutorial into “tune_simple_template.py” will also fail, resulting in exactly the same error message. Is there a verified example of combining AutoTVM and and tensorize?

I don’t know of any examples of combining tensorization and AutoTVM in the past (though it may be used in VTA without any documentation). However, this is an interesting problem and a use case that we should cover. Currently I am wondering if this issue is a result of AutoTVM itself or an artifact of some other part of the build process e.g., how we export/import modules.

Concretely, one way to debug this is to just compare the outputs commands of cc.py to check if there is a mismatch. Can you share what these look like to rule out the issue being a different command being issued here?

I compared the outputs of cc.py for tune_simple_template.py and my version with tensorization.
Original:

['g++', '-shared', '-fPIC', '-o', '/tmp/tmp8dv4bqeo/tmp_func_a42e465cef1a9a85.tar.so', '/tmp/tmpza7pyr3_/lib.o']

tensorized:

['g++', '-shared', '-fPIC', '-o', '/tmp/tmpmnkpdbs2/tmp_func_617b44656cfdac39.tar.so', '/tmp/tmp83ihok0m/lib.o']

There is no visible difference. Corresponding to the error message from the initial post, the problem seems to be the missing -fPIC flag while generating /tmp/tmp83ihok0m/lib.o. However, the generation of this lib.o seems to happen somewhere in the C++ part of TVM.

I looked through tvm/codegen, but I couldn’t pinpoint the place where exactly I could add the flag to build command. Could you hint me to right place, @eqy?

I do not have much experience with this stage of the build process, but my guess is that the llvm build happens somewhere around here: https://github.com/dmlc/tvm/blob/master/src/codegen/llvm/llvm_module.cc

Thanks for the advice, appreciate it! @tqchen, could you weigh in on this issues? According to git, you contributed a major of the build process. It would be enough to know the location where the flags for the llvm build are defined.

Hi @dsr91, I’m not familiar with auto tvm part, but the relocations defines while creating a llvm::TargetMachine


hope, it might be helpful.

2 Likes