Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pytato
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Klöckner
pytato
Commits
256a357a
Commit
256a357a
authored
2 years ago
by
Kaushik Kulkarni
Committed by
Andreas Klöckner
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add pt.analysis.get_num_call_sites
parent
edac8c3b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pytato/analysis/__init__.py
+58
-0
58 additions, 0 deletions
pytato/analysis/__init__.py
with
58 additions
and
0 deletions
pytato/analysis/__init__.py
+
58
−
0
View file @
256a357a
...
@@ -31,9 +31,11 @@ from pytato.array import (Array, IndexLambda, Stack, Concatenate, Einsum,
...
@@ -31,9 +31,11 @@ from pytato.array import (Array, IndexLambda, Stack, Concatenate, Einsum,
DictOfNamedArrays
,
NamedArray
,
DictOfNamedArrays
,
NamedArray
,
IndexBase
,
IndexRemappingBase
,
InputArgumentBase
,
IndexBase
,
IndexRemappingBase
,
InputArgumentBase
,
ShapeType
)
ShapeType
)
from
pytato.function
import
FunctionDefinition
,
Call
from
pytato.transform
import
Mapper
,
ArrayOrNames
,
CachedWalkMapper
from
pytato.transform
import
Mapper
,
ArrayOrNames
,
CachedWalkMapper
from
pytato.loopy
import
LoopyCall
from
pytato.loopy
import
LoopyCall
from
pymbolic.mapper.optimize
import
optimize_mapper
from
pymbolic.mapper.optimize
import
optimize_mapper
from
pytools
import
memoize_method
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
pytato.distributed.nodes
import
DistributedRecv
,
DistributedSendRefHolder
from
pytato.distributed.nodes
import
DistributedRecv
,
DistributedSendRefHolder
...
@@ -47,6 +49,8 @@ __doc__ = """
...
@@ -47,6 +49,8 @@ __doc__ = """
.. autofunction:: get_num_nodes
.. autofunction:: get_num_nodes
.. autofunction:: get_num_call_sites
.. autoclass:: DirectPredecessorsGetter
.. autoclass:: DirectPredecessorsGetter
"""
"""
...
@@ -388,3 +392,57 @@ def get_num_nodes(outputs: Union[Array, DictOfNamedArrays]) -> int:
...
@@ -388,3 +392,57 @@ def get_num_nodes(outputs: Union[Array, DictOfNamedArrays]) -> int:
return
ncm
.
count
return
ncm
.
count
# }}}
# }}}
# {{{ CallSiteCountMapper
@optimize_mapper
(
drop_args
=
True
,
drop_kwargs
=
True
,
inline_get_cache_key
=
True
)
class
CallSiteCountMapper
(
CachedWalkMapper
):
"""
Counts the number of :class:`~pytato.Call` nodes in a DAG.
.. attribute:: count
The number of nodes.
"""
def
__init__
(
self
)
->
None
:
super
().
__init__
()
self
.
count
=
0
# type-ignore-reason: dropped the extra `*args, **kwargs`.
def
get_cache_key
(
self
,
expr
:
ArrayOrNames
)
->
int
:
# type: ignore[override]
return
id
(
expr
)
@memoize_method
def
map_function_definition
(
self
,
/
,
expr
:
FunctionDefinition
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
None
:
if
not
self
.
visit
(
expr
):
return
new_mapper
=
self
.
clone_for_callee
()
for
subexpr
in
expr
.
returns
.
values
():
new_mapper
(
subexpr
,
*
args
,
**
kwargs
)
self
.
count
+=
new_mapper
.
count
self
.
post_visit
(
expr
,
*
args
,
**
kwargs
)
# type-ignore-reason: dropped the extra `*args, **kwargs`.
def
post_visit
(
self
,
expr
:
Any
)
->
None
:
# type: ignore[override]
if
isinstance
(
expr
,
Call
):
self
.
count
+=
1
def
get_num_call_sites
(
outputs
:
Union
[
Array
,
DictOfNamedArrays
])
->
int
:
"""
Returns the number of nodes in DAG *outputs*.
"""
from
pytato.codegen
import
normalize_outputs
outputs
=
normalize_outputs
(
outputs
)
cscm
=
CallSiteCountMapper
()
cscm
(
outputs
)
return
cscm
.
count
# }}}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment