From cca8f5731f751bdfb274e07554ef8d762070e6b5 Mon Sep 17 00:00:00 2001 From: Bob Cao Date: Sun, 15 Jan 2023 17:02:36 -0800 Subject: [PATCH 01/10] Create windows_debug.md --- .../articles/contribution/windows_debug.md | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 docs/lang/articles/contribution/windows_debug.md diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md new file mode 100644 index 0000000000000..4679cc073945e --- /dev/null +++ b/docs/lang/articles/contribution/windows_debug.md @@ -0,0 +1,93 @@ +## Prerequisites: +Able to build Taichi from source. (i.e. already have LLVM and related environment variables already setup) +Recommended plugins to install for Visual Studio: +1. Github Co-pilot +2. VS Chromium for Code Search ( https://chromium.github.io/vs-chromium/ ). You might need to go to the release page to find the pre-release version needed for VS2022 + +## Step 1. Turn on msbuild option in our build system: + +This is a new feature in setup.py (introduced in https://github.com/taichi-dev/taichi/pull/6724 ) that enables building Taichi with MSBuild & MSVC, and it generates a Visual Studio Project file to enable coding and seamless debugging through Visual Studio IDE. +To turn it on, create a new environment variable (Type in windows search: environment variable, or set it temporarily with `$Env:` in PowerShell) called TAICHI_USE_MSBUILD, and set its value to 1 or ON. +Now after cleaning up the _skbuild folder (in case the previously used generator is Ninja), run `python setup.py develop` and build Taichi from the source. + +## Step 2. Navigate to the generated Visual Studio Project file +Go to the build folder, in my case it is `_skbuild\win-amd64-3.9\cmake-build`, and double click on `taichi.sln` (Or open this SLN solution file from Visual Studio). This should open Visual Studio IDE with the setup for Taichi. +After Visual Studio launched, you should see something like this (layout might be different, you can reconfigure the layout to one that you like): + +![image13](https://user-images.githubusercontent.com/11663476/212577220-92a8a7cb-f6ff-4365-9808-0a7299be87cd.png) + +## Step 3. Navigating the source code of Taichi in Visual Studio + +The top right red box is the solution explorer, where you can see each submodule of Taichi grouped up by each “object file”, clicking on one will reveal something like this: + +![image10](https://user-images.githubusercontent.com/11663476/212577350-33912d21-0105-459b-8490-2aaee5c88ff6.png) +![image11](https://user-images.githubusercontent.com/11663476/212577355-fec6837a-00fc-4f7b-8cdc-b369bc4bc015.png) + +Or if you prefer navigating the project using its folder structure, you can find the “Source Explorer” module, and it should reveal the normal Taichi source directory structure: + +![image2](https://user-images.githubusercontent.com/11663476/212577382-4ff8e6de-e04b-4502-9dd9-7ebb75697693.png) + +Sometimes, you are quite familiar with the source code already and you know what you are trying to find, or when you are trying to figure out where a particular class is defined, using CodeSearch should be a quicker and easier way to find the source code. (Code Search is provided by the plugin VS Chromium, and you can find it through “View->Other Windows->Code Search”. I recommend keeping this window pinned somewhere so you always have access to it, it’s the greatest source navigation tool ever. +Say we are trying to pin down where we are defining all the pointer statements, just type in CodeSearch: + +![image16](https://user-images.githubusercontent.com/11663476/212577411-61c8ffd9-6b63-4eb9-a38b-b1b4f2a640dc.png) + +You can see here, by default CodeSearch uses the Windows search path wild cards with . ? and *. Here we matched all the pointer statement definitions by using `class *ptrstmt`. Clicking on each one will bring you over to that line in that file: + +![image8](https://user-images.githubusercontent.com/11663476/212577439-6cd6e888-fbd9-48c8-9a81-81cca3d9359f.png) + +(Currently Visual Studio has a bit of trouble parsing our `ir.h`, so ignore these errors related to classes and types it failed to find. Usually this goes away after a while.) + +## Step 4. Debugging Taichi + +To debug Taichi on Windows, you can use two methods. One is to launch a Taichi program from Visual Studio itself and use it like any other IDE, the other is to insert this statement in your Taichi program: +`ti._lib.core.wait_for_debugger()` +When this line of code is executed, the program will pause and now you can attach to this process from Visual Studio. +To setup launching Taichi program from Visual Studio, go to “Debug->ALL_BUILD Debug Properties”, and click on the left side “Debugging”. This will reveal the debug launch settings. You should set “Command” to the python executable file you installed on your system (either in Conda or in other places). Then set the working directory to “..\..\..” where it points to the root of taichi source directory. Then you can set the argument to the python file you want to launch and its related options. Here is an example: + +![image6](https://user-images.githubusercontent.com/11663476/212577472-49959479-e0f5-4f7c-87c0-8b16fb53c07b.png) + +Hit OK or Apply to save this config, and click on the green Run button (says “local windows debugger”) to launch the program. Here you can see we hit a break point set in one of the optimization passes: + +![image5](https://user-images.githubusercontent.com/11663476/212577487-139cea4c-01ee-4589-89ff-f3daa2bdb982.png) + +If you use the other route and put a `wait_for_debugger()` in your python script, you can attach to the waiting process through “Debug->Attach to Process”. After you have attached, the program will resume automatically. + +## Step 5. (CPU) Performance profiling + +After clicking the debugging button (green run button), you might have noticed that a new window popped up called “Diagnostic Tools” that looks like this: + +![image3](https://user-images.githubusercontent.com/11663476/212577500-bb87e5db-e3e8-4ec6-9e61-7580714655b9.png) + +Here you can see two tabs that are useful to us: CPU Usage and Memory Usage. In each of these, we can find a “record CPU profile” button. Once enabled, the CPU timeline turns green and that means we are collecting performance data in this duration. +Now if we hit pause on debugging, we can see the profiling window turns into this: + +![image7](https://user-images.githubusercontent.com/11663476/212577591-d593a3b4-a13b-47f7-ac25-a376f69fcb95.png) + +This is the collected profile of our program. We can select a region on the CPU timeline and only look at performance data in that region: + +![image14](https://user-images.githubusercontent.com/11663476/212577515-ebe3a000-8294-41c9-9355-73f6fe20837a.png) + +Here we can see the “Hot Path” of function calls. If we hit the “Open details” button, we can go into the detailed view containing a few views: “Caller/Callee”, “Call Tree”, “Modules”, “Functions”. Each of these presents performance data in a different way. +In this particular program, we can see that the hot path is within Python, which we can’t do much to help. In this case, if we still want to optimize our part of code, we can go to the “Modules” view: + +![image9](https://user-images.githubusercontent.com/11663476/212577614-9cb2dd9d-18c5-4900-a347-869f10f583e4.png) + +Where we can see that the `taichi_python` module (the C++ source code of Taichi) takes 65% of total CPU time, and then it splits its time down into the kernel and driver libraries etc. Here is the view when we expand our library module: + +![image15](https://user-images.githubusercontent.com/11663476/212577640-87a0503c-72d8-4c4c-9306-1e4ee97e3796.png) + +Let’s say we want to focus on + +![image4](https://user-images.githubusercontent.com/11663476/212577647-116bf750-54df-491b-8719-01e88ef526cd.png) + +We can right click on this line, and click “View in Call Tree”, and then click on “expand hot path”, we get something like this: + +![image1](https://user-images.githubusercontent.com/11663476/212577664-48f91acb-988a-463c-abe4-3f808d3159ad.png) + +Hmmmm, perhaps the Python stack is way too long and we don’t really care about it. Let’s scroll down to `taichi::lang::JITSessionCUDA::add_module`, and right click on “Set Root”, and now we get a much cleaner view where we see the function we care about is now the root of the call tree: + +![image12](https://user-images.githubusercontent.com/11663476/212577676-772d210b-11e8-4959-b573-28a73bbb47d9.png) + +Here we can see which pass takes the most amount of time, we can even see which line of our code corresponds to the most amount of time spent. +Granted in this case, most of the time is spent on LLVM here. We probably can’t do much for this specific case. However, this method applies everywhere and is extremely powerful and clear what performance problems are and gives us potential paths to fix these problems. From 42d0b5ce58c88671f8d3b19bc067eb5cbc475d4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 01:04:25 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/contribution/windows_debug.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index 4679cc073945e..678c18ba1f164 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -43,7 +43,7 @@ You can see here, by default CodeSearch uses the Windows search path wild cards To debug Taichi on Windows, you can use two methods. One is to launch a Taichi program from Visual Studio itself and use it like any other IDE, the other is to insert this statement in your Taichi program: `ti._lib.core.wait_for_debugger()` When this line of code is executed, the program will pause and now you can attach to this process from Visual Studio. -To setup launching Taichi program from Visual Studio, go to “Debug->ALL_BUILD Debug Properties”, and click on the left side “Debugging”. This will reveal the debug launch settings. You should set “Command” to the python executable file you installed on your system (either in Conda or in other places). Then set the working directory to “..\..\..” where it points to the root of taichi source directory. Then you can set the argument to the python file you want to launch and its related options. Here is an example: +To setup launching Taichi program from Visual Studio, go to “Debug->ALL_BUILD Debug Properties”, and click on the left side “Debugging”. This will reveal the debug launch settings. You should set “Command” to the python executable file you installed on your system (either in Conda or in other places). Then set the working directory to “..\..\..” where it points to the root of taichi source directory. Then you can set the argument to the python file you want to launch and its related options. Here is an example: ![image6](https://user-images.githubusercontent.com/11663476/212577472-49959479-e0f5-4f7c-87c0-8b16fb53c07b.png) @@ -77,7 +77,7 @@ Where we can see that the `taichi_python` module (the C++ source code of Taichi) ![image15](https://user-images.githubusercontent.com/11663476/212577640-87a0503c-72d8-4c4c-9306-1e4ee97e3796.png) -Let’s say we want to focus on +Let’s say we want to focus on ![image4](https://user-images.githubusercontent.com/11663476/212577647-116bf750-54df-491b-8719-01e88ef526cd.png) From e9a5f192ae6fac4e8fcd378147c4abb185ff9935 Mon Sep 17 00:00:00 2001 From: Bob Cao Date: Sun, 15 Jan 2023 21:30:23 -0800 Subject: [PATCH 03/10] Apply suggestions from code review Co-authored-by: Lin Jiang Co-authored-by: Zhao Liang --- docs/lang/articles/contribution/windows_debug.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index 678c18ba1f164..eb28de799e75e 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -1,3 +1,9 @@ +--- +sidebar_position: 9 +--- + +# Debugging on Windows + ## Prerequisites: Able to build Taichi from source. (i.e. already have LLVM and related environment variables already setup) Recommended plugins to install for Visual Studio: @@ -10,7 +16,7 @@ This is a new feature in setup.py (introduced in https://github.com/taichi-dev/t To turn it on, create a new environment variable (Type in windows search: environment variable, or set it temporarily with `$Env:` in PowerShell) called TAICHI_USE_MSBUILD, and set its value to 1 or ON. Now after cleaning up the _skbuild folder (in case the previously used generator is Ninja), run `python setup.py develop` and build Taichi from the source. -## Step 2. Navigate to the generated Visual Studio Project file +## Step 2. Navigate to the generated Visual Studio Project file Go to the build folder, in my case it is `_skbuild\win-amd64-3.9\cmake-build`, and double click on `taichi.sln` (Or open this SLN solution file from Visual Studio). This should open Visual Studio IDE with the setup for Taichi. After Visual Studio launched, you should see something like this (layout might be different, you can reconfigure the layout to one that you like): @@ -27,7 +33,7 @@ Or if you prefer navigating the project using its folder structure, you can find ![image2](https://user-images.githubusercontent.com/11663476/212577382-4ff8e6de-e04b-4502-9dd9-7ebb75697693.png) -Sometimes, you are quite familiar with the source code already and you know what you are trying to find, or when you are trying to figure out where a particular class is defined, using CodeSearch should be a quicker and easier way to find the source code. (Code Search is provided by the plugin VS Chromium, and you can find it through “View->Other Windows->Code Search”. I recommend keeping this window pinned somewhere so you always have access to it, it’s the greatest source navigation tool ever. +Sometimes, if you are familiar with the source code already and you know what you are trying to find, or if you are trying to figure out where a particular class is defined, using CodeSearch should be a quicker and easier way to find the source code. (Code Search is provided by the plugin VS Chromium, and you can find it through “View->Other Windows->Code Search”. I recommend keeping this window pinned somewhere so you always have access to it, it’s the greatest source navigation tool ever. Say we are trying to pin down where we are defining all the pointer statements, just type in CodeSearch: ![image16](https://user-images.githubusercontent.com/11663476/212577411-61c8ffd9-6b63-4eb9-a38b-b1b4f2a640dc.png) From e84a23a231457cb5e14070b7479990f6f0bff88d Mon Sep 17 00:00:00 2001 From: Bob Cao Date: Sun, 15 Jan 2023 21:33:02 -0800 Subject: [PATCH 04/10] Apply suggestions from code review Co-authored-by: Olinaaaloompa <106292061+Olinaaaloompa@users.noreply.github.com> --- .../articles/contribution/windows_debug.md | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index eb28de799e75e..a4c2ecf94a2c2 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -5,26 +5,26 @@ sidebar_position: 9 # Debugging on Windows ## Prerequisites: -Able to build Taichi from source. (i.e. already have LLVM and related environment variables already setup) -Recommended plugins to install for Visual Studio: +You should be able to build Taichi from source and already have LLVM and related environment variables configured. +Recommended Visual Studio plugins: 1. Github Co-pilot -2. VS Chromium for Code Search ( https://chromium.github.io/vs-chromium/ ). You might need to go to the release page to find the pre-release version needed for VS2022 +2. [VS Chromium](https://chromium.github.io/vs-chromium/) for Code Search. You might need to go to the release page to find the pre-release version needed for VS2022 ## Step 1. Turn on msbuild option in our build system: -This is a new feature in setup.py (introduced in https://github.com/taichi-dev/taichi/pull/6724 ) that enables building Taichi with MSBuild & MSVC, and it generates a Visual Studio Project file to enable coding and seamless debugging through Visual Studio IDE. +This is a new feature in setup.py, introduced in [PR #6724](https://github.com/taichi-dev/taichi/pull/6724), which enables building Taichi with MSBuild & MSVC. It generates a Visual Studio Project file to enable coding and seamless debugging through Visual Studio IDE. To turn it on, create a new environment variable (Type in windows search: environment variable, or set it temporarily with `$Env:` in PowerShell) called TAICHI_USE_MSBUILD, and set its value to 1 or ON. Now after cleaning up the _skbuild folder (in case the previously used generator is Ninja), run `python setup.py develop` and build Taichi from the source. ## Step 2. Navigate to the generated Visual Studio Project file -Go to the build folder, in my case it is `_skbuild\win-amd64-3.9\cmake-build`, and double click on `taichi.sln` (Or open this SLN solution file from Visual Studio). This should open Visual Studio IDE with the setup for Taichi. -After Visual Studio launched, you should see something like this (layout might be different, you can reconfigure the layout to one that you like): +Go to the build folder, which is `_skbuild\win-amd64-3.9\cmake-build` in the author's case, and double click `taichi.sln`. You can also open this SLN solution file from Visual Studio. This should open Visual Studio IDE with the setup for Taichi. +The following image shows a possible layout after Visual Studio is launched. The layout is open to reconfiguration. ![image13](https://user-images.githubusercontent.com/11663476/212577220-92a8a7cb-f6ff-4365-9808-0a7299be87cd.png) -## Step 3. Navigating the source code of Taichi in Visual Studio +## Step 3. Navigate through the source code of Taichi in Visual Studio -The top right red box is the solution explorer, where you can see each submodule of Taichi grouped up by each “object file”, clicking on one will reveal something like this: +The top right red box is the solution explorer, where you can see each submodule of Taichi grouped up by each “object file”. Click on one, and you will see expanded details as the following images show: ![image10](https://user-images.githubusercontent.com/11663476/212577350-33912d21-0105-459b-8490-2aaee5c88ff6.png) ![image11](https://user-images.githubusercontent.com/11663476/212577355-fec6837a-00fc-4f7b-8cdc-b369bc4bc015.png) @@ -38,30 +38,34 @@ Say we are trying to pin down where we are defining all the pointer statements, ![image16](https://user-images.githubusercontent.com/11663476/212577411-61c8ffd9-6b63-4eb9-a38b-b1b4f2a640dc.png) -You can see here, by default CodeSearch uses the Windows search path wild cards with . ? and *. Here we matched all the pointer statement definitions by using `class *ptrstmt`. Clicking on each one will bring you over to that line in that file: +By default, CodeSearch uses the Windows search path wildcards with . ? and *. Here, we match all pointer statement definitions by using `class *ptrstmt`. Clicking on one of the results brings you over to the particular line in that file: ![image8](https://user-images.githubusercontent.com/11663476/212577439-6cd6e888-fbd9-48c8-9a81-81cca3d9359f.png) -(Currently Visual Studio has a bit of trouble parsing our `ir.h`, so ignore these errors related to classes and types it failed to find. Usually this goes away after a while.) +:::note -## Step 4. Debugging Taichi +Currently, Visual Studio has a bit of trouble parsing `ir.h`. You can ignore the errors reporting a failure to find the classes or types. Usually, they go away after a while. -To debug Taichi on Windows, you can use two methods. One is to launch a Taichi program from Visual Studio itself and use it like any other IDE, the other is to insert this statement in your Taichi program: -`ti._lib.core.wait_for_debugger()` +## Step 4. Debug Taichi + +To debug Taichi on Windows, you can use one of the following two methods. + +- Launch a Taichi program from Visual Studio and use it like any other IDE +- Insert `ti._lib.core.wait_for_debugger()` in your Taichi program to pause the program. You can then attach to this process from Visual Studio. When this line of code is executed, the program will pause and now you can attach to this process from Visual Studio. -To setup launching Taichi program from Visual Studio, go to “Debug->ALL_BUILD Debug Properties”, and click on the left side “Debugging”. This will reveal the debug launch settings. You should set “Command” to the python executable file you installed on your system (either in Conda or in other places). Then set the working directory to “..\..\..” where it points to the root of taichi source directory. Then you can set the argument to the python file you want to launch and its related options. Here is an example: +To launch a Taichi program from Visual Studio, go to**Debug > ALL_BUILD Debug Properties** and click **Debugging** on the left side for the debug launch settings. Set “Command” to the python executable file installed on your system (either in Conda or in other places). Then, set the working directory to **..\..\..**, which points to the root of the Taichi source directory. Finally, set the argument to the python file you want to launch and its related options. For example: ![image6](https://user-images.githubusercontent.com/11663476/212577472-49959479-e0f5-4f7c-87c0-8b16fb53c07b.png) -Hit OK or Apply to save this config, and click on the green Run button (says “local windows debugger”) to launch the program. Here you can see we hit a break point set in one of the optimization passes: +Hit OK or Apply to save this config, and click on the green Run button (says “local windows debugger”) to launch the program. Here, we hit a break point set in one of the optimization passes: ![image5](https://user-images.githubusercontent.com/11663476/212577487-139cea4c-01ee-4589-89ff-f3daa2bdb982.png) -If you use the other route and put a `wait_for_debugger()` in your python script, you can attach to the waiting process through “Debug->Attach to Process”. After you have attached, the program will resume automatically. +If you use the other route and put a `wait_for_debugger()` in your python script, you can attach to the waiting process through **Debug > Attach to Process**. Afterward, the program resumes automatically. ## Step 5. (CPU) Performance profiling -After clicking the debugging button (green run button), you might have noticed that a new window popped up called “Diagnostic Tools” that looks like this: +After the debugger (the green Run button) is enabled, a new window titled “Diagnostic Tools” pops up, as the following image shows: ![image3](https://user-images.githubusercontent.com/11663476/212577500-bb87e5db-e3e8-4ec6-9e61-7580714655b9.png) From cf4314caa8f4aed6c9787397eca31ad188d552ee Mon Sep 17 00:00:00 2001 From: Bob Cao Date: Sun, 15 Jan 2023 21:33:31 -0800 Subject: [PATCH 05/10] Apply suggestions from code review Co-authored-by: Olinaaaloompa <106292061+Olinaaaloompa@users.noreply.github.com> --- .../articles/contribution/windows_debug.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index a4c2ecf94a2c2..cfab2b3d3f4b9 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -69,7 +69,7 @@ After the debugger (the green Run button) is enabled, a new window titled “Dia ![image3](https://user-images.githubusercontent.com/11663476/212577500-bb87e5db-e3e8-4ec6-9e61-7580714655b9.png) -Here you can see two tabs that are useful to us: CPU Usage and Memory Usage. In each of these, we can find a “record CPU profile” button. Once enabled, the CPU timeline turns green and that means we are collecting performance data in this duration. +There are two useful tabs on this window: CPU Usage and Memory Usage. In each of them, you can find a “Record CPU Profile” option. Once you enable the option, the CPU timeline turns green and that means performance data is being collected in this duration. Now if we hit pause on debugging, we can see the profiling window turns into this: ![image7](https://user-images.githubusercontent.com/11663476/212577591-d593a3b4-a13b-47f7-ac25-a376f69fcb95.png) @@ -79,25 +79,27 @@ This is the collected profile of our program. We can select a region on the CPU ![image14](https://user-images.githubusercontent.com/11663476/212577515-ebe3a000-8294-41c9-9355-73f6fe20837a.png) Here we can see the “Hot Path” of function calls. If we hit the “Open details” button, we can go into the detailed view containing a few views: “Caller/Callee”, “Call Tree”, “Modules”, “Functions”. Each of these presents performance data in a different way. -In this particular program, we can see that the hot path is within Python, which we can’t do much to help. In this case, if we still want to optimize our part of code, we can go to the “Modules” view: +In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: ![image9](https://user-images.githubusercontent.com/11663476/212577614-9cb2dd9d-18c5-4900-a347-869f10f583e4.png) -Where we can see that the `taichi_python` module (the C++ source code of Taichi) takes 65% of total CPU time, and then it splits its time down into the kernel and driver libraries etc. Here is the view when we expand our library module: +The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. + + Now, expand the library module: ![image15](https://user-images.githubusercontent.com/11663476/212577640-87a0503c-72d8-4c4c-9306-1e4ee97e3796.png) -Let’s say we want to focus on +Take this particular entry for example. ![image4](https://user-images.githubusercontent.com/11663476/212577647-116bf750-54df-491b-8719-01e88ef526cd.png) -We can right click on this line, and click “View in Call Tree”, and then click on “expand hot path”, we get something like this: +Right click on it and find **View in Call Tree > expand hot path**. The result is shown as below: ![image1](https://user-images.githubusercontent.com/11663476/212577664-48f91acb-988a-463c-abe4-3f808d3159ad.png) -Hmmmm, perhaps the Python stack is way too long and we don’t really care about it. Let’s scroll down to `taichi::lang::JITSessionCUDA::add_module`, and right click on “Set Root”, and now we get a much cleaner view where we see the function we care about is now the root of the call tree: +The Python stack is lengthy. We can scroll down to `taichi::lang::JITSessionCUDA::add_module` and right click on “Set Root” to get a much cleaner view. The function we care about is now the root of the call tree: ![image12](https://user-images.githubusercontent.com/11663476/212577676-772d210b-11e8-4959-b573-28a73bbb47d9.png) -Here we can see which pass takes the most amount of time, we can even see which line of our code corresponds to the most amount of time spent. -Granted in this case, most of the time is spent on LLVM here. We probably can’t do much for this specific case. However, this method applies everywhere and is extremely powerful and clear what performance problems are and gives us potential paths to fix these problems. +We can find out which pass and even which line of code are the most time-consuming. +In this case, LLVM occupies most of the time and leaves limited room for optimization. However, this method applies everywhere and is most helpful to locate performance bottlenecks and facilitate problem-solving. From ec5cde25b6e676674e5b37140149fb2877e77aae Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 05:34:16 +0000 Subject: [PATCH 06/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/contribution/windows_debug.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index cfab2b3d3f4b9..4cf4ef9318095 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -48,7 +48,7 @@ Currently, Visual Studio has a bit of trouble parsing `ir.h`. You can ignore the ## Step 4. Debug Taichi -To debug Taichi on Windows, you can use one of the following two methods. +To debug Taichi on Windows, you can use one of the following two methods. - Launch a Taichi program from Visual Studio and use it like any other IDE - Insert `ti._lib.core.wait_for_debugger()` in your Taichi program to pause the program. You can then attach to this process from Visual Studio. From 15a42a52a43194862a8fea081f063d2aad9d1e00 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 05:35:31 +0000 Subject: [PATCH 07/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/contribution/windows_debug.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index 4cf4ef9318095..05b10bf1300a4 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -79,11 +79,11 @@ This is the collected profile of our program. We can select a region on the CPU ![image14](https://user-images.githubusercontent.com/11663476/212577515-ebe3a000-8294-41c9-9355-73f6fe20837a.png) Here we can see the “Hot Path” of function calls. If we hit the “Open details” button, we can go into the detailed view containing a few views: “Caller/Callee”, “Call Tree”, “Modules”, “Functions”. Each of these presents performance data in a different way. -In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: +In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: ![image9](https://user-images.githubusercontent.com/11663476/212577614-9cb2dd9d-18c5-4900-a347-869f10f583e4.png) -The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. +The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. Now, expand the library module: From 9e6adc3e410050462376b1ae8d65174b2622508e Mon Sep 17 00:00:00 2001 From: Bob Cao Date: Sun, 15 Jan 2023 21:40:16 -0800 Subject: [PATCH 08/10] Update windows_debug.md --- docs/lang/articles/contribution/windows_debug.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index 05b10bf1300a4..24428841debbe 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -5,7 +5,11 @@ sidebar_position: 9 # Debugging on Windows ## Prerequisites: + You should be able to build Taichi from source and already have LLVM and related environment variables configured. + +:::note Here is the ![developer installation guide](https://docs.taichi-lang.org/docs/dev_install). + Recommended Visual Studio plugins: 1. Github Co-pilot 2. [VS Chromium](https://chromium.github.io/vs-chromium/) for Code Search. You might need to go to the release page to find the pre-release version needed for VS2022 @@ -33,12 +37,11 @@ Or if you prefer navigating the project using its folder structure, you can find ![image2](https://user-images.githubusercontent.com/11663476/212577382-4ff8e6de-e04b-4502-9dd9-7ebb75697693.png) -Sometimes, if you are familiar with the source code already and you know what you are trying to find, or if you are trying to figure out where a particular class is defined, using CodeSearch should be a quicker and easier way to find the source code. (Code Search is provided by the plugin VS Chromium, and you can find it through “View->Other Windows->Code Search”. I recommend keeping this window pinned somewhere so you always have access to it, it’s the greatest source navigation tool ever. -Say we are trying to pin down where we are defining all the pointer statements, just type in CodeSearch: +If you are already familiar with the source code or try to locate the definition of a particular class, CodeSearch makes it quicker and easier to find the corresponding source code. Code Search is provided by the plugin VS Chromium, and you can find it by following **View > Other Windows > Code Search**. It is recommended that you keep this window pinned to have easy access to this great source navigation tool. ![image16](https://user-images.githubusercontent.com/11663476/212577411-61c8ffd9-6b63-4eb9-a38b-b1b4f2a640dc.png) -By default, CodeSearch uses the Windows search path wildcards with . ? and *. Here, we match all pointer statement definitions by using `class *ptrstmt`. Clicking on one of the results brings you over to the particular line in that file: +By default, CodeSearch uses the Windows search path wildcards with . ? and *. For example, the following image shows how to pin down where all pointer statements are defined, and clicking on one of the results brings you over to the particular line in that file: ![image8](https://user-images.githubusercontent.com/11663476/212577439-6cd6e888-fbd9-48c8-9a81-81cca3d9359f.png) @@ -70,7 +73,8 @@ After the debugger (the green Run button) is enabled, a new window titled “Dia ![image3](https://user-images.githubusercontent.com/11663476/212577500-bb87e5db-e3e8-4ec6-9e61-7580714655b9.png) There are two useful tabs on this window: CPU Usage and Memory Usage. In each of them, you can find a “Record CPU Profile” option. Once you enable the option, the CPU timeline turns green and that means performance data is being collected in this duration. -Now if we hit pause on debugging, we can see the profiling window turns into this: + +After pausing the debugging, the profiling window shows the following: ![image7](https://user-images.githubusercontent.com/11663476/212577591-d593a3b4-a13b-47f7-ac25-a376f69fcb95.png) @@ -79,11 +83,11 @@ This is the collected profile of our program. We can select a region on the CPU ![image14](https://user-images.githubusercontent.com/11663476/212577515-ebe3a000-8294-41c9-9355-73f6fe20837a.png) Here we can see the “Hot Path” of function calls. If we hit the “Open details” button, we can go into the detailed view containing a few views: “Caller/Callee”, “Call Tree”, “Modules”, “Functions”. Each of these presents performance data in a different way. -In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: +In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: ![image9](https://user-images.githubusercontent.com/11663476/212577614-9cb2dd9d-18c5-4900-a347-869f10f583e4.png) -The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. +The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. Now, expand the library module: From 81f23738091030f1647645a5c1505bfd2acc573e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 05:41:30 +0000 Subject: [PATCH 09/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/contribution/windows_debug.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index 24428841debbe..47f4158515d1f 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -83,11 +83,11 @@ This is the collected profile of our program. We can select a region on the CPU ![image14](https://user-images.githubusercontent.com/11663476/212577515-ebe3a000-8294-41c9-9355-73f6fe20837a.png) Here we can see the “Hot Path” of function calls. If we hit the “Open details” button, we can go into the detailed view containing a few views: “Caller/Callee”, “Call Tree”, “Modules”, “Functions”. Each of these presents performance data in a different way. -In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: +In this particular program, the hot path is within Python, and there is not much we can do to help. To optimize this part of code, go to the “Modules” view: ![image9](https://user-images.githubusercontent.com/11663476/212577614-9cb2dd9d-18c5-4900-a347-869f10f583e4.png) -The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. +The `taichi_python` module (the C++ source code of Taichi) takes 65% of the total CPU time and splits its time down into the kernel and driver libraries. Now, expand the library module: From 7d4c37805d895406cd8fc89cb8c0c6c34379e414 Mon Sep 17 00:00:00 2001 From: Olinaaaloompa <106292061+Olinaaaloompa@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:08:57 +0800 Subject: [PATCH 10/10] Update docs/lang/articles/contribution/windows_debug.md --- docs/lang/articles/contribution/windows_debug.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/lang/articles/contribution/windows_debug.md b/docs/lang/articles/contribution/windows_debug.md index 47f4158515d1f..76ce26b3ae93d 100644 --- a/docs/lang/articles/contribution/windows_debug.md +++ b/docs/lang/articles/contribution/windows_debug.md @@ -49,6 +49,8 @@ By default, CodeSearch uses the Windows search path wildcards with . ? and *. Fo Currently, Visual Studio has a bit of trouble parsing `ir.h`. You can ignore the errors reporting a failure to find the classes or types. Usually, they go away after a while. +::: + ## Step 4. Debug Taichi To debug Taichi on Windows, you can use one of the following two methods.