Error when save lib with Python+Win10:clang: error: unable to execute command: program not executable

Env:

  • Windows10
  • Python3.6.2
  • LLVM 11.0.0, Clang 11.0.0
  • VS2017

Description:

I want to save optimized module(include graph, lib and params) with Python, and load module with C++.

I can build module:

with tvm.transform.PassContext(opt_level=3):
    graph, lib, params = relay.build(mod=mod, target=target, target_host=target_host,  params=params, mod_name='default')

and can save graph and params:

    with open(osp.join(save_dir, 'deploy_graph.json'), 'w') as f:
        f.write(graph)

    with open(osp.join(save_dir, 'deploy_param.params'), 'wb') as f:
        f.write(tvm.relay.save_param_dict(params))

but error occured when save lib:

    lib.export_library(osp.join(save_dir, 'deploy_lib.dll'))

The error info:


Connected to pydev debugger (build 191.7479.30)
******************
 (1, 3, 224, 224)
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:root:Attribute momentum is ignored in relay.sym.batch_norm
WARNING:autotvm:Cannot find config for target=cuda -keys=cuda,gpu -max_num_threads=1024 -thread_warp_size=32, workload=('dense_small_batch.cuda', ('TENSOR', (1, 512), 'float32'), ('TENSOR', (1000, 512), 'float32'), None, 'float32'). A fallback configuration is used, which may bring great performance regression.
Traceback (most recent call last):
  File "D:\software\install\PyCharm 2019.1.3\helpers\pydev\pydevd.py", line 1758, in <module>
    main()
  File "D:\software\install\PyCharm 2019.1.3\helpers\pydev\pydevd.py", line 1752, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "D:\software\install\PyCharm 2019.1.3\helpers\pydev\pydevd.py", line 1147, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\software\install\PyCharm 2019.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/yangshuai/code/mmclassification/tools/ToTVM.py", line 127, in <module>
    save_compiled_module(graph, lib, params, './')
  File "D:/yangshuai/code/mmclassification/tools/ToTVM.py", line 58, in save_compiled_module
    lib.export_library(osp.join(save_dir, 'deploy_lib.dll'),
  File "D:\yangshuai\code\tvm\tvm\python\tvm\runtime\module.py", line 351, in export_library
    fcompile(file_name, files, **kwargs)
  File "D:\yangshuai\code\tvm\tvm\python\tvm\contrib\cc.py", line 50, in create_shared
    _windows_shared(output, objects, options)
  File "D:\yangshuai\code\tvm\tvm\python\tvm\contrib\cc.py", line 245, in _windows_shared
    raise RuntimeError(msg)
RuntimeError: Compilation error:
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1 Like

execute clang -v in Windows PowerShell:

clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\yangshuai\code\tvm\llvm-11.0.0.src\build\Release\bin

The same Python code can run, and load module succeed with C++, in Ubuntu.

I can save succeed on another win10 machine, but I do not compile LLVM with Clang. It seems that you can choose which compiler to use. How to do that?

I had same problem. The reason is absense of lld-link tool, - looks like it is not included in windows llvm make by default. To solve, rebuild llvm with -DLLVM_ENABLE_PROJECTS=lld (as here Getting Started: Building and Running lld — lld 13 documentation).