[Libtorch] when unload caffe2_nvrtc.dll the program will occurred exception

weiqiangguo: <p><strong>When the program runs to the end, it will occur exceptions (FAILURE_BUCKET_ID:  BAD_INSTRUCTION_PTR_c0000005_caffe2_nvrtc.dll!Unloaded).</strong></p>
<p><strong>With windbg attach the program, the STACK_TEXT as follows:</strong></p>
<p>&lt;Unloaded_caffe2_nvrtc.dll&gt;+0x110a<br>
torch!thrust::cuda_cub::core::AgentLauncher&lt;thrust::cuda_cub::__adjacent_difference::AdjacentDifferenceAgent&lt;__int64 * __ptr64,__int64 * __ptr64,__int64,__nv_dl_wrapper_t&lt;__nv_dl_tag&lt;std::tuple<a>at::Tensor,at::Tensor,at::Tensor</a> (__cdecl*)(at::Tensor const &amp; __ptr64,__int64,bool,bool,bool),&amp;at::native::_GLOBAL__N__53_tmpxft_0000159c_00000000_15_Unique_compute_75_cpp1_ii_285fecc2::unique_dim_cuda_template&lt;__int64&gt;,3&gt;,__int64,__int64 * __ptr64&gt; &gt; &gt;::launch_impl&lt;__int64 * __ptr64,__int64 * __ptr64,__int64 * __ptr64,__nv_dl_wrapper_t&lt;__nv_dl_tag&lt;std::tuple<a>at::Tensor,at::Tensor,at::Tensor</a> (__cdecl*)(at::Tensor const &amp; __ptr64,__int64,bool,bool,bool),&amp;at::native::_GLOBAL__N__53_tmpxft_0000159c_00000000_15_Unique_compute_75_cpp1_ii_285fecc2::unique_dim_cuda_template&lt;__int64&gt;,3&gt;,__int64,__int64 * __ptr64&gt;,__int64&gt;+0x100 [c:\program files\nvidia gpu computing toolkit\cuda\v10.0\include\thrust\system\cuda\detail\core\agent_launcher.h @ 958]<br>
torch!thrust::cuda_cub::core::AgentLauncher&lt;thrust::cuda_cub::__adjacent_difference::AdjacentDifferenceAgent&lt;__int64 * __ptr64,__int64 * __ptr64,__int64,thrust::not_equal_to&lt;__int64&gt; &gt; &gt;::launch_impl&lt;__int64 * __ptr64,__int64 * __ptr64,__int64 * __ptr64,thrust::not_equal_to&lt;__int64&gt;,__int64&gt;+0x80 [c:\program files\nvidia gpu computing toolkit\cuda\v10.0\include\thrust\system\cuda\detail\core\agent_launcher.h @ 957]<br>
torch!_<em>device_stub__ZN2at6native26batch_norm_backward_kernelIffxEEvNS_20PackedTensorAccessorIT_Ly3ENS_16DefaultPtrTraitsET1_EES6_S6_NS2_IS3_Ly1ES4_S5_EES7_S7_S7_S7_NS2_IT0_Ly1ES4_S5_EES9_bS8</em>+0xea [c:\users\administrator\appdata\local\temp\tmpxft_00001a40_00000000-9_normalization.compute_75.cudafe1.stub.c @ 603]<br>
torch!_<em>device_stub__ZN2at6native26batch_norm_backward_kernelIffxEEvNS_20PackedTensorAccessorIT_Ly3ENS_16DefaultPtrTraitsET1_EES6_S6_NS2_IS3_Ly1ES4_S5_EES7_S7_S7_S7_NS2_IT0_Ly1ES4_S5_EES9_bS8</em>+0x29a [c:\users\administrator\appdata\local\temp\tmpxft_00001a40_00000000-9_normalization.compute_75.cudafe1.stub.c @ 612]<br>
torch!c10::tryTypeMetaToScalarType+0x2a5 [c:\w\1\s\windows\pytorch\c10\core\scalartype.h @ 139]<br>
torch!cub::DispatchReduce&lt;int * __ptr64,int * __ptr64,int,cub::Max&gt;::InvokePasses&lt;cub::DeviceReducePolicy&lt;int,int,cub::Max&gt;::Policy200,void (__cdecl*)(int * __ptr64,int * __ptr64,int,cub::GridEvenShare,cub::Max),void (__cdecl*)(int * __ptr64,int * __ptr64,int,cub::Max,int)&gt;+0x508 [c:\w\1\s\windows\pytorch\third_party\cub\cub\device\dispatch\dispatch_reduce.cuh @ 572]<br>
ucrtbase!execute_onexit_table+0x103<br>
ucrtbase!register_onexit_function+0xeb<br>
ucrtbase!execute_onexit_table+0x34<br>
torch!cub::DispatchReduce&lt;__int64 const * __ptr64,__int64 * __ptr64,int,cub::Max&gt;::InvokeSingleTile&lt;cub::DeviceReducePolicy&lt;__int64,int,cub::Max&gt;::Policy350,void (__cdecl*)(__int64 const * __ptr64,__int64 * __ptr64,int,cub::Max,__int64)&gt;+0x96 [c:\w\1\s\windows\pytorch\third_party\cub\cub\device\dispatch\dispatch_reduce.cuh @ 458]<br>
torch!cub::DispatchReduce&lt;__int64 const * __ptr64,__int64 * __ptr64,int,cub::Max&gt;::InvokeSingleTile&lt;cub::DeviceReducePolicy&lt;__int64,int,cub::Max&gt;::Policy350,void (__cdecl*)(__int64 const * __ptr64,__int64 * __ptr64,int,cub::Max,__int64)&gt;+0x194 [c:\w\1\s\windows\pytorch\third_party\cub\cub\device\dispatch\dispatch_reduce.cuh @ 469]<br>
ntdll!RtlDeactivateActivationContextUnsafeFast+0x1bf<br>
ntdll!LdrUnloadAlternateResourceModuleEx+0x32d<br>
ntdll!RtlCreateHeap+0x1238<br>
ntdll!RtlCreateHeap+0x13ad<br>
ntdll!RtlCreateHeap+0x13ad<br>
ntdll!LdrUnloadDll+0x113<br>
ntdll!LdrUnloadDll+0x94<br>
KERNELBASE!FreeLibrary+0x1d<br>
00000000<code>0315fec0 00000000</code>59de1d7b : 00000000<code>028a2080 00000000</code>00000000 00000000`0</p>
<p>SYMBOL_STACK_INDEX:  0</p>
<p>SYMBOL_NAME:  caffe2_nvrtc+110a</p>
<p>FOLLOWUP_NAME:  MachineOwner</p>
<p>MODULE_NAME: caffe2_nvrtc</p>
<p>IMAGE_NAME:  caffe2_nvrtc.dll</p>
<p>STACK_COMMAND:  ~8s ; kb</p>
<p>BUCKET_ID:  WRONG_SYMBOLS</p>
<p>FAILURE_BUCKET_ID:  BAD_INSTRUCTION_PTR_c0000005_caffe2_nvrtc.dll!Unloaded</p>
<p>Followup: MachineOwner</p>