taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.52k stars 2.28k forks source link

Windows Deug Env #8601

Open xuanranxiaoshi opened 1 day ago

xuanranxiaoshi commented 1 day ago

Hi everyone, I now want to develop and debug the Taichi project on Windows through Visual Studio 2022. After I built the project using the debug configuration documentation on the Taichi website: https://docs.taichi-lang.cn/docs/windows_debug, a puzzling exception appeared in Step 4.

The project was successfully built at run time without error, but the debugging did not break at the breakpoint, but directly exited.

11:16:57:106    “python.exe”(Win32): 已加载“D:\development\anaconda\python.exe”。已加载符号。
11:16:57:106    “python.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”。
11:16:57:106    “python.exe”(Win32): 已加载“C:\Windows\System32\kernel32.dll”。
11:16:57:106    “python.exe”(Win32): 已加载“C:\Windows\System32\KernelBase.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\ucrtbase.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“D:\development\anaconda\python39.dll”。已加载符号。
11:16:57:610    “python.exe”(Win32): 已加载“D:\development\anaconda\vcruntime140.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\ws2_32.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\rpcrt4.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\version.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\msvcrt.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\advapi32.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\sechost.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\cryptsp.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\rsaenh.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\cryptbase.dll”。
11:16:57:610    “python.exe”(Win32): 已加载“C:\Windows\System32\bcryptprimitives.dll”。
11:16:57:648    “python.exe”(Win32): 已加载“C:\Windows\System32\kernel.appcore.dll”。
11:16:57:648    线程 49892 已退出,返回值为 1 (0x1)。
11:16:57:648    线程 13100 已退出,返回值为 1 (0x1)。
11:16:57:648    线程 29124 已退出,返回值为 1 (0x1)。
11:16:57:648    程序“[1776] python.exe”已退出,返回值为 1 (0x1)。

Is there something wrong with my process of building Taichi? Here's how I built from the source code:

The LLVM Debug build process is as follows:

cmake ..\llvm\ -G "Visual Studio 17 2022" -A x64 -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" -DLLVM_ENABLE_ASSERTIONS=ON -Thost=x64 -DLLVM_BUILD_TESTS:BOOL=OFF -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_CXX_STANDARD=17
git clone --recursive https://github.com/taichi-dev/taichi  

cd taichi  

$env:TAICHI_CMAKE_ARGS += " -DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_CUDA:BOOL=ON"  

$env:DEBUG = 1 # Uncomment it if you wish to keep debug information.  

$env:TAICHI_USE_MSBUILD = 1

python build.py --shell  

# 指定自己生成 LLVM Debug 版本路径后执行

python setup.py develop

Then I open ... /taichi/_skbuild/win-amd64-3.9/cmake-build/taichi. sln, the debugging environment is as follows:

image

The result is above!

xuanranxiaoshi commented 1 day ago

I found a new problem.

After building Taichi in the above way, I execute it directly on the command line:

python tiDemo.py

(tiDemo.py is a simple taichi sample program)

Generate an error:

Share object taichi_python import failed, check this page for possible solutions:
https://docs.taichi-lang.org/docs/install
Traceback (most recent call last):
  File "E:\Code\Cplusplus\TrnasTest\TransTest01\taichi\tiDemo.py", line 1, in <module>
    import taichi as ti
  File "e:\code\cplusplus\taichi\python\taichi\__init__.py", line 1, in <module>
    from taichi._funcs import *
  File "e:\code\cplusplus\taichi\python\taichi\_funcs.py", line 3, in <module>
    from taichi.lang import impl, ops
  File "e:\code\cplusplus\taichi\python\taichi\lang\__init__.py", line 1, in <module>
    from taichi.lang import impl, simt
  File "e:\code\cplusplus\taichi\python\taichi\lang\impl.py", line 6, in <module>
    from taichi._lib import core as _ti_core
  File "e:\code\cplusplus\taichi\python\taichi\_lib\__init__.py", line 1, in <module>
    from taichi._lib.utils import ti_python_core as core
  File "e:\code\cplusplus\taichi\python\taichi\_lib\utils.py", line 110, in <module>
    ti_python_core = import_ti_python_core()
  File "e:\code\cplusplus\taichi\python\taichi\_lib\utils.py", line 57, in import_ti_python_core
    raise e from None
  File "e:\code\cplusplus\taichi\python\taichi\_lib\utils.py", line 46, in import_ti_python_core
    from taichi._lib.core import taichi_python as core  # pylint: disable=C0415
ImportError: DLL load failed while importing taichi_python: 找不到指定的模块。
Consider installing Microsoft Visual C++ Redistributable: https://aka.ms/vs/16/release/vc_redist.x64.exe

I installed 'vc_redis.x64.exe' but still did not solve the problem.

I'm wondering how compiling Taichi in this way can be imported by a Python program?

xuanranxiaoshi commented 14 hours ago

Now I have solved the problem: ImportError: DLL load failed while importing taichi_python: The specified module could not be found.

Instead of compiling Taichi in Debug mode, I set the environment variable to 0;

However, debugging in VS 2022 still reported an error: the python.c source file could not be found.

image