Skip to content

Commit

Permalink
[refactor] Remove PyTaichi.compiled_functions (taichi-dev#7867)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and quadpixels committed May 13, 2023
1 parent 382e868 commit 749182e
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 240 deletions.
9 changes: 6 additions & 3 deletions python/taichi/lang/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ class PyTaichi:
def __init__(self, kernels=None):
self.materialized = False
self.prog = None
self.compiled_functions = {}
self.src_info_stack = []
self.inside_kernel = False
self.compiling_callable = None # pointer to instance of lang::Kernel/Function
Expand All @@ -336,7 +335,8 @@ def initialize_fields_builder(self, builder):
self.unfinalized_fields_builder[builder] = get_traceback(2)

def clear_compiled_functions(self):
self.compiled_functions.clear()
for k in self.kernels:
k.compiled_kernels.clear()

def finalize_fields_builder(self, builder):
self.unfinalized_fields_builder.pop(builder)
Expand All @@ -351,7 +351,10 @@ def validate_fields_builder(self):
)

def get_num_compiled_functions(self):
return len(self.compiled_functions)
count = 0
for k in self.kernels:
count += len(k.compiled_kernels)
return count

def src_info_guard(self, info):
return SrcInfoGuard(self.src_info_stack, info)
Expand Down
Loading

0 comments on commit 749182e

Please sign in to comment.