-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor kernel compilation #7002
Labels
refactor
Refactor of API or codebases
Comments
This was referenced Dec 28, 2022
This was referenced Jan 4, 2023
Merged
PGZXB
added a commit
that referenced
this issue
Jan 5, 2023
feisuzhu
pushed a commit
to feisuzhu/taichi
that referenced
this issue
Jan 5, 2023
PGZXB
added a commit
that referenced
this issue
Jan 5, 2023
PGZXB
added a commit
to PGZXB/taichi
that referenced
this issue
Jan 5, 2023
PGZXB
added a commit
that referenced
this issue
Jan 5, 2023
This was referenced Jan 6, 2023
PGZXB
added a commit
that referenced
this issue
Jan 9, 2023
PGZXB
added a commit
that referenced
this issue
Jan 9, 2023
PGZXB
added a commit
that referenced
this issue
Jan 9, 2023
Issue: #7002 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
PGZXB
added a commit
that referenced
this issue
Jan 10, 2023
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…vm backends codegen (taichi-dev#7153) Issue: taichi-dev#7002 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…pass::constant_fold (taichi-dev#7159) Issue: taichi-dev#7002 ### Brief Summary 1. The dependencies on `Program::this_thread_config()` in `irpass::constant_fold` were removed; 2. The race condition of `Program::config` (concurrent write) was killed, so we can remove the multi-thread version `Program::this_thread_config()`. I will do it in next PR; 3. The `Program::compile(Kernel *kernel)` was refactored to `Program::compile(const CompileConfig &compile_config, Kernel *kernel)`, which is a temporary solution because I will introduce new classes to provide compilation interfaces (see taichi-dev#7002 for more information). Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…taichi-dev#7199) Issue: taichi-dev#7002 Removed multi-thread version `Program::this_thread_config()` (see taichi-dev#7159 (comment)) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…hi-dev#7209) Issue: taichi-dev#7002 ### Brief Summary Removed dependencies on `Program::this_thread_config()` in `lang::Function` compilation (AST->IR part) * Push off the compilation of `lang::Function`: Introduce the `irpass::compile_called_function(IRNode *root, const CompileConfig &config)`, which compiles the AST/IR of `Function`s called in `root` to the final IR.
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…ichi-dev#7243) Issue: taichi-dev#7002, taichi-dev#7159 (comment) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…rt2) (taichi-dev#7253) Issue: taichi-dev#7002 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…ed_offline_cache_key (taichi-dev#7287) Issue: taichi-dev#7286 * taichi-dev#7286: Part of taichi-dev#7002 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
… in KernelCodeGen (taichi-dev#7289) Issue: taichi-dev#7286 * This PR: Part of removing `KernelCodeGen::prog` * removing `KernelCodeGen::prog`: Part of taichi-dev#7286 * taichi-dev#7286: Part of taichi-dev#7002 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…Graph::run (taichi-dev#7288) Issue: taichi-dev#7286 * taichi-dev#7286: Part of taichi-dev#7002 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…#7391) Issue: taichi-dev#7002 ### Brief Summary Disable `ASTSerializer::allow_undefined_visitor`: 1. Enabling `ASTSerializer::allow_undefined_visitor` is dangerous; 2. Prepare for introducing `KernelCompilationManager`.
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…er (taichi-dev#7371) Issue: taichi-dev#7002 ### Brief Summary * Impl `spirv::CompilerKernelData` * Introduce `lang::KernelCompiler` & Impl `spirv::KernelCompiler` p.s. The `KernelCompiler` is not used now. Next PR, I will introduce `KernelCompilatonManager`, which depends on the `CompilerKernelData` and `KernelCompiler` --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002, taichi-dev#4401 ### Brief Summary This PR: 1. Introduced `KernelCompilationManager` to unify implementation of the Offline Cache; 2. Used `KernelCompilationManager` re-impl JIT, Offline Cache on gfx backends (vulkan, metal, dx11, opengl); 3. Removed the `gfx::CacheManager`. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary The member was used by old implementation of offline cache, which is unnecessary now.
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…aichi-dev#7426) Issue: taichi-dev#7002 ### Brief Summary Support cleaning `.tic` files.
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…chi-dev#7425) Issue: taichi-dev#7002 ### Brief Summary The functions were used by old implementation of offline cache, which are unnecessary now.
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary #### Fixed bug reported by https://github.com/taichi-dev/taichi/actions/runs/4346468687/jobs/7592576659 : ``` Error in atexit._run_exitfuncs: Traceback (most recent call last): File "tests/run_tests.py", line 233, in print_and_remove os.listdir(os.path.join(tmp_cache_file_path, subdir))) NotADirectoryError: [Errno 20] Not a directory: '/var/folders/1r/fk_r0s1d4ss8m19rg11bq1j80000gp/T/tmpcnyh7mz1/Tbdbfefe5b5fe6db167e250d15bb1c4cc797b2beee4fa7a09be9a6cff8c060101-metal.tic' ``` #### Quick repro on master: `python run_tests.py -v -t4 -a vulkan,cpu abs --with-offline-cache` ``` ... Error in atexit._run_exitfuncs: Traceback (most recent call last): File "..\taichi\tests\run_tests.py", line 233, in print_and_remove os.listdir(os.path.join(tmp_cache_file_path, subdir))) NotADirectoryError: [WinError 267] The directory name is invalid. : 'C:\\Users\\xxx\\AppData\\Local\\Temp\\tmpcs7z9cpq\\T1571a996babd2f9b7a24eeba9d8450fd767cf939b8d717941f629550302d6408-vulkan.tic' ``` #### On this branch (fixed the bug): `python run_tests.py -v -t4 -a vulkan,cpu abs --with-offline-cache` ``` ... Summary of testing the offline cache: Simple statistics: {'llvm': 19, '*.tic': 18} Size of cache files: 646.04 KB ```
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…() (taichi-dev#7540) Issue: taichi-dev#7002 ### Brief Summary It is challenging to implement the function `CompiledKernelData::size()`, particularly for the `llvm::CompiledKernelData` class, as it is not possible to obtain the size of the `llvm::Module` without dumping it.
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…LlvmAotModuleBuilder (taichi-dev#7714) Issue: taichi-dev#7002 ### Brief Summary --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at f2ee059</samp> Improve kernel compilation manager efficiency by avoiding redundant cache loading. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at f2ee059</samp> * Add a check for existing kernel data to avoid redundant loading ([link](https://github.com/taichi-dev/taichi/pull/7741/files?diff=unified&w=0#diff-b7662dbf5bcf20f4b99048f4f2405316c0ba037c0722273522efaad72d256ef0L219-R228))
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8d2c768</samp> This pull request improves the error handling and debugging of the kernel compilation and caching process using the LLVM backend. It adds a `check` function to the `CompiledKernelData` class that verifies the LLVM module and tasks, and uses it to assert and report the status of the data. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8d2c768</samp> * Add a new error enum value and message for the case when the CompiledKernelData is broken ([link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-5e2472488f9620231c8e3d6a2c0413742e2b42424691991f4a85af81832af3f4R95), [link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-70ec30330946b7543dcf0b458091cfc6128a5cb5460041db64144b84722de4abR184-R185)) * Implement a check function for the CompiledKernelData class that verifies the LLVM module and the tasks stored in the data using the LLVM verifier ([link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-3986d4b2137cab0463bb950113c0ddc44cfdf3baff237da6286c42c478309c3bR3), [link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-3986d4b2137cab0463bb950113c0ddc44cfdf3baff237da6286c42c478309c3bR30-R43), [link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-e54a1ed2c2d35f9357e4dfbbbc1224e70a95280b43d4a59f0017dc2c6163dca0R55-R56)) * Add assertions and checks for the result of the check function after compiling or loading a kernel using the LLVM backend, and modify the debug message to include the cache filename ([link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-b7662dbf5bcf20f4b99048f4f2405316c0ba037c0722273522efaad72d256ef0R178), [link](https://github.com/taichi-dev/taichi/pull/7743/files?diff=unified&w=0#diff-b7662dbf5bcf20f4b99048f4f2405316c0ba037c0722273522efaad72d256ef0L266-R275))
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
…gfx::AotModuleBuilderImpl (taichi-dev#7715) Issue: taichi-dev#7002, taichi-dev#6520 (comment) ### Brief Summary
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 618302d</samp> This pull request introduces a mechanism to assign unique ids to each offloaded task in different backends, enabling asynchronous execution of kernels on various devices. It modifies the constructors and methods of several codegen classes to accept and pass task ids, and simplifies the task id generation for kernels by using local counters. It mainly affects the files `taichi/codegen/*` and `taichi/program/kernel.h`. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 618302d</samp> * Add an `id` parameter to the constructors of `TaskCodeGenLLVM` and its subclasses (`TaskCodeGenAMDGPU`, `TaskCodeGenCPU`, `TaskCodeGenCUDA`, `TaskCodeGenLLVMDX12`) to pass a unique identifier for each task codegen instance ([link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-f45ad00d5bebbc900cf84ab5b4f0b634fe8ca7a99770788c2cb5b055612c1e85L30-R35), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-b6e86fbdf536db46b321f67942f66d809c213a4142ceb9f5f81d016684c2d5c8L30-R35), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-50537ad5ea3b900c0d55a088f3cc285986340ad68c9b96fea481187c4dce49eaL44-R49), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-b26bcd66b9334fe882df039d1c619f16f0f91f6c43c3872b6cbb2688b8e7b749L24-R29), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-3c663c78745adcd3f6a7ac81fe99e628decc3040f292ea1e20ecd4b85a7f4313L306-R307), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-aebc3d71bb555fba77f1d303d5c29ac7e07d392440b0e54cf556ff5a10a81d0aL73-R78)) * Add an `task_codegen_id` parameter to the `compile_task` methods of `KernelCodeGen` and its subclasses (`KernelCodeGenAMDGPU`, `KernelCodeGenCPU`, `KernelCodeGenCUDA`, `KernelCodeGenDX12`) to pass the task codegen id to the task codegen constructors ([link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-f45ad00d5bebbc900cf84ab5b4f0b634fe8ca7a99770788c2cb5b055612c1e85L486-R492), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-2dca4a15a3c5e43017b458e9a19d8edabade6e4489c719aea88819e9dc34c285R22), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-54b0d16247300543741692be7cec4b05993efa661e71ad3d69d5da85fcbc7782L91-R91), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-75d426482e598b420f6f3bed213844bbfcca397be6d3a3371c9ff8128275a6fdR63), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-b6e86fbdf536db46b321f67942f66d809c213a4142ceb9f5f81d016684c2d5c8L288-R293), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-9bc17077ecc24636db6f9c92d14d55bdcdb87c18379d72a06a9e84486d20b060R24), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-50537ad5ea3b900c0d55a088f3cc285986340ad68c9b96fea481187c4dce49eaL743-R749), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-15ab2a7729595aeafa4c5a77a6c97e9a7e9d43ffd49210b86d940b6394e58475R22), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-b26bcd66b9334fe882df039d1c619f16f0f91f6c43c3872b6cbb2688b8e7b749L246-R247), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-b26bcd66b9334fe882df039d1c619f16f0f91f6c43c3872b6cbb2688b8e7b749L263-R269), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-d4ff49adc577edb7d11d8e69b2fb1e97162aaf01ef896e588a35cc8a20e061b1R29)) * Use the `task_codegen_id` and a local `task_counter` to generate unique task ids for each offloaded statement in the `init_offloaded_task_function` method of `TaskCodeGenLLVM`, instead of using a shared atomic counter in the `Kernel` class ([link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-3c663c78745adcd3f6a7ac81fe99e628decc3040f292ea1e20ecd4b85a7f4313L1956-R1958), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-3c663c78745adcd3f6a7ac81fe99e628decc3040f292ea1e20ecd4b85a7f4313R316), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-aebc3d71bb555fba77f1d303d5c29ac7e07d392440b0e54cf556ff5a10a81d0aR66-R69), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-5831927e99f989a5c80bace0ae3a103f99fb5849cf6e591a22a8bb83d3a14c3fL68-L71), [link](https://github.com/taichi-dev/taichi/pull/7751/files?diff=unified&w=0#diff-5831927e99f989a5c80bace0ae3a103f99fb5849cf6e591a22a8bb83d3a14c3fL95-R91)) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary `Program::compile()` => `Program::compile_kernel()` + `Program::launch_kernel()`
quadpixels
pushed a commit
to quadpixels/taichi
that referenced
this issue
May 13, 2023
Issue: taichi-dev#7002 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 5923f65</samp> Refactor compiled function management for kernels in `PyTaichi`. Use `compiled_kernels` attribute of each kernel instead of `compiled_functions` attribute of `PyTaichi`. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 5923f65</samp> * Remove the `compiled_functions` attribute from the `PyTaichi` class and use the `compiled_kernels` attribute of each kernel instead ([link](https://github.com/taichi-dev/taichi/pull/7867/files?diff=unified&w=0#diff-99744c5ae5f6a754d6f68408fdc64fb0d6097216518a7f3d1ef43ffe12599577L316)) * Update the `clear_compiled_functions` method of the `PyTaichi` class to clear the `compiled_kernels` attribute of each kernel ([link](https://github.com/taichi-dev/taichi/pull/7867/files?diff=unified&w=0#diff-99744c5ae5f6a754d6f68408fdc64fb0d6097216518a7f3d1ef43ffe12599577L339-R339)) * Update the `get_num_compiled_functions` method of the `PyTaichi` class to sum up the lengths of the `compiled_kernels` attribute of each kernel ([link](https://github.com/taichi-dev/taichi/pull/7867/files?diff=unified&w=0#diff-99744c5ae5f6a754d6f68408fdc64fb0d6097216518a7f3d1ef43ffe12599577L354-R357)) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(This is part of Refactor kernel compilation and launch, which aims to split kernel compilation and kernel launching totally.)
Brief Introduction
lang::Kernel
.lang::CompileConfig
per compilation instead oflang::CompileConfig
perlang::Program
.lang::CompiledKernelData
,lang::KernelCompiler
to unify the compilation result and the interfaces of kernel compilation.lang::KernelCompilationManager
to unify the implementation of cache on ALL backends, including online cache and offline cachePrototype
Provide
@ti.pkernel
@ti.pkernel
=@ti.kernel
+CompileConfig
, which allows the user to specify different compile configuration options for each kernel.Implementation
Example
To-Do List
Move Kernel::compile and Kernel::operator() outside, see prototype: b5d6bebRefactor Kernel::get_ret*, see prototype: d87a8ba; 80bea89; 732b4a3; 0920501; 0f2a0b5; 7eb13d5TaichiLLVMContext
#7311PyTaichi.compiled_functions
)Remove lang::Callable::program #7286const CompileConfig *
to const CompileConfig &`Related work
The text was updated successfully, but these errors were encountered: