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

**URL:** <https://discuss.tvm.apache.org/t/tvm-makes-python-to-crash-in-windows-while-llvm-and-open-cl-enabled/165>\
**Category:** Application\
**Created:** [May 11, 2018, 12:07pm UTC](https://discuss.tvm.apache.org/t/tvm-makes-python-to-crash-in-windows-while-llvm-and-open-cl-enabled/165 "2018-05-11T12:07:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hrgraj](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/h/8491ac/32.png) [@hrgraj](https://discuss.tvm.apache.org/u/hrgraj)\
**Post date:** [May 11, 2018, 12:07pm UTC](https://discuss.tvm.apache.org/t/tvm-makes-python-to-crash-in-windows-while-llvm-and-open-cl-enabled/165/1 "2018-05-11T12:07:54Z")

</div>

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](https://pastebin.com/nBFAyN7e)

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](https://pastebin.com/PE2eabf2)

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 !

---

<div class="post-metadata">

**Author:** ![hrgraj](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/h/8491ac/32.png) [@hrgraj](https://discuss.tvm.apache.org/u/hrgraj)\
**Post date:** [May 14, 2018, 5:50am UTC](https://discuss.tvm.apache.org/t/tvm-makes-python-to-crash-in-windows-while-llvm-and-open-cl-enabled/165/2 "2018-05-14T05:50:54Z")

</div>

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(R) OpenCL ’ [11:49:16] C:\NNVM\NNVM\master\nnvm\tvm\src\runtime\opencl\opencl\_device\_api.cc:259: opencl(0)='Intel(R) 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 [[OpenCL segmentation fault when execute tvm.cl or tvm.build OpenCL program using Intel Device · Issue #429 · apache/tvm · GitHub](https://github.com/dmlc/tvm/issues/429)] .but looks like it is closed . Is there any Fix for this ?
