Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
a3843b10
Commit
a3843b10
authored
1 year ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
slightly extended typifier
parent
03affb6c
No related branches found
No related tags found
No related merge requests found
Pipeline
#60440
failed
1 year ago
Stage: pretest
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils/nbackend/kernelcreation/domain_kernels.py
+5
-1
5 additions, 1 deletion
src/pystencils/nbackend/kernelcreation/domain_kernels.py
src/pystencils/nbackend/kernelcreation/typification.py
+35
-2
35 additions, 2 deletions
src/pystencils/nbackend/kernelcreation/typification.py
with
40 additions
and
3 deletions
src/pystencils/nbackend/kernelcreation/domain_kernels.py
+
5
−
1
View file @
a3843b10
...
...
@@ -9,8 +9,11 @@ from ..ast import PsBlock
from
.context
import
KernelCreationContext
,
FullIterationSpace
from
.freeze
import
FreezeExpressions
from
.typification
import
Typifier
# flake8: noqa
def
create_domain_kernel
(
assignments
:
AssignmentCollection
):
# TODO: Assemble configuration
...
...
@@ -46,7 +49,8 @@ def create_domain_kernel(assignments: AssignmentCollection):
# 5. Typify
# Also the same for both types of kernels
# determine_types(kernel_body)
typify
=
Typifier
(
ctx
)
kernel_body
=
typify
(
kernel_body
)
# Up to this point, all was target-agnostic, but now the target becomes relevant.
# Here we might hand off the compilation to a target-specific part of the compiler
...
...
This diff is collapsed.
Click to expand it.
src/pystencils/nbackend/kernelcreation/typification.py
+
35
−
2
View file @
a3843b10
from
__future__
import
annotations
from
typing
import
TypeVar
import
pymbolic.primitives
as
pb
from
pymbolic.mapper
import
Mapper
from
.context
import
KernelCreationContext
from
..types
import
PsAbstractType
from
..typed_expressions
import
PsTypedVariable
from
..ast
import
PsAstNode
,
PsExpression
,
PsAssignment
class
TypificationException
(
Exception
):
"""
Indicates a fatal error during typification.
"""
NodeT
=
TypeVar
(
"
NodeT
"
,
bound
=
PsAstNode
)
class
Typifier
(
Mapper
):
def
__init__
(
self
,
ctx
:
KernelCreationContext
):
self
.
_ctx
=
ctx
def
__call__
(
self
,
expr
:
pb
.
Expression
)
->
tuple
[
pb
.
Expression
,
PsAbstractType
]:
return
self
.
rec
(
expr
)
def
__call__
(
self
,
node
:
NodeT
)
->
NodeT
:
match
node
:
case
PsExpression
(
expr
):
node
.
expression
,
_
=
self
.
rec
(
expr
)
case
PsAssignment
(
lhs
,
rhs
):
lhs
,
lhs_dtype
=
self
.
rec
(
lhs
)
rhs
,
rhs_dtype
=
self
.
rec
(
rhs
)
if
lhs_dtype
!=
rhs_dtype
:
# todo: (optional) automatic cast insertion?
raise
TypificationException
(
"
Mismatched types in assignment:
\n
"
f
"
{
lhs
}
<-
{
rhs
}
\n
"
f
"
dtype(lhs) =
{
lhs_dtype
}
\n
"
f
"
dtype(rhs) =
{
rhs_dtype
}
\n
"
)
node
.
lhs
=
lhs
node
.
rhs
=
rhs
case
unknown
:
raise
NotImplementedError
(
f
"
Don
'
t know how to typify
{
unknown
}
"
)
return
node
def
map_variable
(
self
,
var
:
pb
.
Variable
)
->
tuple
[
pb
.
Expression
,
PsAbstractType
]:
dtype
=
NotImplemented
# determine variable type
...
...
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