Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
loopy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Ben Sepanski
loopy
Commits
8fcb7ee7
Commit
8fcb7ee7
authored
11 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Factor code generation helper into pytools
parent
47bd9e4f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
loopy/compiled.py
+2
-66
2 additions, 66 deletions
loopy/compiled.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
3 additions
and
66 deletions
loopy/compiled.py
+
2
−
66
View file @
8fcb7ee7
...
...
@@ -28,6 +28,8 @@ import pyopencl.tools # noqa
import
numpy
as
np
from
pytools
import
Record
,
memoize_method
from
loopy.diagnostic
import
ParameterFinderWarning
from
pytools.py_codegen
import
(
Indentation
,
PythonCodeGenerator
,
PythonFunctionGenerator
)
# {{{ object array argument packing
...
...
@@ -112,72 +114,6 @@ class SeparateArrayPackingController(object):
# }}}
# {{{ python code generation helpers
class
Indentation
(
object
):
def
__init__
(
self
,
generator
):
self
.
generator
=
generator
def
__enter__
(
self
):
self
.
generator
.
indent
()
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
generator
.
dedent
()
class
PythonCodeGenerator
(
object
):
def
__init__
(
self
):
self
.
preamble
=
[]
self
.
code
=
[]
self
.
level
=
0
def
extend
(
self
,
sub_generator
):
self
.
code
.
extend
(
sub_generator
.
code
)
def
extend_indent
(
self
,
sub_generator
):
with
Indentation
(
self
):
for
line
in
sub_generator
.
code
:
self
.
write
(
line
)
def
get
(
self
):
result
=
"
\n
"
.
join
(
self
.
code
)
if
self
.
preamble
:
result
=
"
\n
"
.
join
(
self
.
preamble
)
+
"
\n
"
+
result
return
result
def
add_to_preamble
(
self
,
s
):
self
.
preamble
.
append
(
s
)
def
__call__
(
self
,
string
):
self
.
code
.
append
(
"
"
*
(
4
*
self
.
level
)
+
string
)
def
indent
(
self
):
self
.
level
+=
1
def
dedent
(
self
):
if
self
.
level
==
0
:
raise
RuntimeError
(
"
internal error in python code generator
"
)
self
.
level
-=
1
class
PythonFunctionGenerator
(
PythonCodeGenerator
):
def
__init__
(
self
,
name
,
args
):
PythonCodeGenerator
.
__init__
(
self
)
self
.
name
=
name
self
(
"
def %s(%s):
"
%
(
name
,
"
,
"
.
join
(
args
)))
self
.
indent
()
def
get_function
(
self
):
result_dict
=
{}
exec
(
compile
(
self
.
get
(),
"
<generated function %s>
"
%
self
.
name
,
"
exec
"
),
result_dict
)
return
result_dict
[
self
.
name
]
# }}}
# {{{ invoker generation
# /!\ This code runs in a namespace controlled by the user.
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
8fcb7ee7
...
...
@@ -39,6 +39,7 @@ setup(name="loo.py",
],
install_requires
=
[
"
pytools>=2013.5.2
"
,
"
pyopencl>=2013.1
"
,
"
pymbolic>=2013.2
"
,
"
cgen
"
,
...
...
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