TVM makes python to crash in Windows while LLVM and OPEN CL enabled


#1

On Windows 10 (1709) ,
LLVM setup:
LLVM 6.0 source is compiled .
Installed Intel SDK for Open CL 2017
Then i compiled TVM with LLVM and OPENCL options enabled sucessfully .
After compilation ,the respective python bindings were done .
Once i started the OPEN CL part of “getstarted.py” code ,after execution the Python crashed .

here is the demo code for open cl :

from future import absolute_import, print_function
import tvm
import numpy as np

tgt_host=“llvm”

tgt=“opencl”
n = tvm.var(“n”)
A = tvm.placeholder((n,), name=‘A’)
B = tvm.placeholder((n,), name=‘B’)
C = tvm.compute(A.shape, lambda i: A[i] + B[i], name=“C”)
print(type©)

s = tvm.create_schedule(C.op)
bx, tx = s[C].split(C.op.axis[0], factor=64)

s[C].bind(bx, tvm.thread_axis(“blockIdx.x”))
s[C].bind(tx, tvm.thread_axis(“threadIdx.x”))

fadd_cl = tvm.build(s, [A, B, C], “opencl”, name=“myadd”)

print("------tvm gen code------")
print(fadd_cl.get_source());

print("------opencl code------")
print(fadd_cl.imported_modules[0].get_source())

ctx = tvm.cl(0)
n = 1024
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
fadd_cl(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())

OUTPUT: in the link
console out

from the console output ,i think it generates llvm based IR and finally generates the opencl code . But upon reaching end of execution ,i get a popup “Python stopped working” .
Once i try to debug the crash in visual studio 2015 ,i see in the call stack , that the crash was triggered from " tvm.dll -->IntelOpenCL64.dll ".

Test 2:
Compiled TVM without LLVM and Only OpenCL enabled :
ran the same example program . executed without any crash!! .
From the console output below ,i think tvm used inbuilt stackvm .

no crash

Is there any Incompatability with TVM - LLVM ??
I tried with both version of LLVM 6.0 & 4.0.1 sources ,but unfortunately the open cl is crashing !


#2

Update:
env:: Intel integrated graphics and Intel sdk for OpenCL2017

Looks like tvm crashes upon destruction of OpenCLworkspace(void) :

I wonder why this exceptions triggers only when i compile tvm with LLVM enabled !!
here is a simple program to reproduce the issue ;

C:\WINDOWS\system32>python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import tvm
cl= tvm.cl(0)
cl.exist
[11:49:16] C:\NNVM\NNVM\master\nnvm\tvm\src\runtime\opencl\opencl_device_api.cc:231: Multiple OpenCL platforms matched, use the first one …
[11:49:16] C:\NNVM\NNVM\master\nnvm\tvm\src\runtime\opencl\opencl_device_api.cc:234: Initialize OpenCL platform 'Intel® OpenCL ’
[11:49:16] C:\NNVM\NNVM\master\nnvm\tvm\src\runtime\opencl\opencl_device_api.cc:259: opencl(0)='Intel® HD Graphics 4600 ’ cl_device_id=000001E676EBCC50
True

exit()

Now python crashes … on debug :

call stack:

IntelOpenCL64.dll!00007ffa3e552ba8()	Unknown
IntelOpenCL64.dll!00007ffa3e54d291()	Unknown
IntelOpenCL64.dll!00007ffa3e534062()	Unknown
IntelOpenCL64.dll!00007ffa3e521f63()	Unknown
tvm.dll!tvm::runtime::cl::OpenCLWorkspace::~OpenCLWorkspace(void)	C++
tvm.dll!`dmlc::ThreadLocalStore<class tvm::runtime::cl::OpenCLThreadEntry>::Get(void)'::`2'::`dynamic atexit destructor for 'inst''(void)	C++
ucrtbase.dll!<lambda>(void)()	Unknown
ucrtbase.dll!__crt_seh_guarded_call<int>::operator()<<lambda_7777bce6b2f8c936911f934f8298dc43>,<lambda>(void) & __ptr64,<lambda_3883c3dff614d5e0c5f61bb1ac94921c> >()	Unknown
ucrtbase.dll!_execute_onexit_table()	Unknown
tvm.dll!dllmain_crt_process_detach(const bool is_terminating) Line 109	C++
tvm.dll!dllmain_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 207	C++
ntdll.dll!LdrpCallInitRoutine()	Unknown
ntdll.dll!LdrShutdownProcess()	Unknown
ntdll.dll!RtlExitUserProcess()	Unknown
kernel32.dll!ExitProcessImplementation()	Unknown
ucrtbase.dll!exit_or_terminate_process()	Unknown
ucrtbase.dll!common_exit()	Unknown
python.exe!__scrt_common_main_seh() Line 266	C++
kernel32.dll!BaseThreadInitThunk()	Unknown
ntdll.dll!RtlUserThreadStart()	Unknown

similar issue i found in [https://github.com/dmlc/tvm/issues/429] .but looks like it is closed .
Is there any Fix for this ?