Problem while exporting tvm library in windows

Hi @tqchen @srkreddy1238 i am trying to export tvm library in windows i am face below issue, but i am able to compile and run models in windows.

lib.export_library(“D:\NNVM\deploy_lib.dll”)
Traceback (most recent call last):

File “”, line 1, in
lib.export_library(path_lib)

File “C:\Anaconda3\lib\site-packages\tvm-0.6.dev0-py3.6-win-amd64.egg\tvm\module.py”, line 144, in export_library
fcompile(file_name, files, **kwargs)

File “C:\Anaconda3\lib\site-packages\tvm-0.6.dev0-py3.6-win-amd64.egg\tvm\contrib\cc.py”, line 51, in create_shared
_windows_shared(output, objects, options)

File “C:\Anaconda3\lib\site-packages\tvm-0.6.dev0-py3.6-win-amd64.egg\tvm\contrib\cc.py”, line 141, in _windows_shared
raise RuntimeError(msg)

RuntimeError: Compilation error:
Microsoft ® C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright © Microsoft Corporation. All rights reserved.

cl : Command line warning D9024 : unrecognized source file type ‘C:\Users\700001~1\AppData\Local\Temp\1\tmpbw46pq3a\lib.o’, object file assumed
cl : Command line warning D9027 : source file ‘C:\Users\700001~1\AppData\Local\Temp\1\tmpbw46pq3a\lib.o’ ignored
dllmain.cc
C:\Users\700001~1\AppData\Local\Temp\1\tmp1zdsdg6a\dllmain.cc(1): warning C4067: unexpected tokens following preprocessor directive - expected a newline
C:\Users\700001~1\AppData\Local\Temp\1\tmp1zdsdg6a\dllmain.cc(1): fatal error C1034: windows.h: no include path set

1 Like

Hi @myproject24, I solved this problem by initializing the necessary variables before the execution of python script. In my system with Visual Studio 2019, I had to execute vcvars64.bat located at C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat before running the python script.

Please note that initializing 32bit variables might lead to errors.

Hi @r4ghu Thanks for the response, I have tried your solution but still I am getting the same error.

  • Is it possible to share your python script?
  • Do you installed any other compiler such as MinGW or only VS2019?

I ran the relay_quick_start.py script for testing my installation. Few things that I did which might help you:

  1. I built LLVM from scratch in windows before building the tvm.
  2. I added all the necessary dll dependencies’ paths for tvm.dll in System Environment Variables.
  3. I added the path to cl.exe to System Environment variables because nvcc by default uses cl.exe in Windows to compile the *.cu scripts.(Additional comments, I tried running nvcc with clang/clang++ but no luck)
  4. After doing all these I landed into the above problem of Windows.h not found error. It is because we need to initialize some system variables before running the python script.
  5. I initialized my Anaconda environment and then ran the vcvars64.bat followed by python relay_quick_start.py.
  6. Now I got a new error related to LLVM compiler. The script needed a certain file which was not built during my custom build operation of LLVM before tvm build phase. So, I had to download LLVM from their webpage and install it. At this point, I have my custom built LLVM at C:\Program Files(x86) and LLVM binaries downloaded from internet at C:\Program Files\.
  7. I added the path to the LLVM\bin (internet version) to system PATH. And I got my code working without errors.
1 Like

Hi @r4ghu I have tried your solution still I am facing the same problem, did you change anything in this script relay_quick_start.py because I have modified export function like

temp = util.tempdir()
path_lib = temp.relpath(“D:\tvm\tvm\nnvm\python\deploy_lib.dll”)
lib.export_library(path_lib)
with open(temp.relpath(“D:\tvm\tvm\nnvm\python\deploy_graph.json”), “w”) as fo:
fo.write(graph.json())
with open(temp.relpath(“D:\tvm\tvm\nnvm\python\deploy_param.params”), “wb”) as fo:
fo.write(nnvm.compiler.save_param_dict(params))

is this correct? here I am saving tvm library as .dll.

Oh! I think this execution is wrong.
You might want to leave it as it is:

  • temp = util.tempdir() : Creates a temporary directory in C:\temp\ with a random name generator.
  • temp.relpath(<rel_loc>) will generate relative paths with respect to the C:\temp\<random_dir_name>\<rel_loc>.
  • in the later part of the code, these files are being fetched with respect to the temp object.

NOTE - temp is an object not a string variable.

No even I tried with

temp = util.tempdir()
path_lib = temp.relpath(“deploy_lib.dll”)
lib.export_library(path_lib)
with open(temp.relpath(“deploy_graph.json”), “w”) as fo:
fo.write(graph.json())
with open(temp.relpath(“deploy_param.params”), “wb”) as fo:
fo.write(nnvm.compiler.save_param_dict(params))

Are you using Anaconda environment or virtualenv? And did you initialize the variables by running vcvars64.bat before running the python script?

yes, I am using Anaconda environment, and i ran C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat batch file also.

Same problem, I’ve ran the vcvars64.bat already.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Aster\Anaconda3\envs\tvm\lib\tvm\module.py", line 144, in export_library
    fcompile(file_name, files, **kwargs)
  File "C:\Users\Aster\Anaconda3\envs\tvm\lib\tvm\contrib\cc.py", line 51, in create_shared
    _windows_shared(output, objects, options)
  File "C:\Users\Aster\Anaconda3\envs\tvm\lib\tvm\contrib\cc.py", line 141, in _windows_shared
    raise RuntimeError(msg)
RuntimeError: Compilation error:
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.22.27905 版
版权所有(C) Microsoft Corporation。保留所有权利。
cl: 命令行 warning D9024 :无法识别的源文件类型“C:\Users\Aster\AppData\Local\Temp\tmpsfmibzqv\lib.o”,假定为对象文件
cl: 命令行 warning D9027 :源文件“C:\Users\Aster\AppData\Local\Temp\tmpsfmibzqv\lib.o”被忽略
dllmain.cc
C:\Users\Aster\AppData\Local\Temp\tmpyz8jvmog\dllmain.cc(1): warning C4067: 预处理器指令后有意外标记 - 应输入换行符
C:\Users\Aster\AppData\Local\Temp\tmpyz8jvmog\dllmain.cc(1): fatal error C1034: windows.h: 不包括路径集

it’s really helpful. thanks.