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
Stephan Seitz
pystencils
Compare revisions
master to ConditionalFieldAccess
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
seitz/pystencils
Select target project
No results found
ConditionalFieldAccess
Select Git revision
Branches
AssignmentCollection.__str__
AssignmentCollection.free-bound_fields
AssignmentCollection.has_exclusive_writes
ConditionalFieldAccess
Datahandling.add_arrays
Field.__repr__
Field.hashable_contents
InterpolatorAccess.__getnewargs__
KernelFunction.field_read
KernelFuntion.fields_read
KernelWrapper
LoopCounterSymbols-nonnegative
NotIterable
RecursiveDotDict
SerialDataHandling.run_kernel-kwargs
SympyAssignment.__hash__
TextureDeclaration.__str__
WIP
WIP2
add-AssignmentCollection.free-bound_fields
add-Field.itemsize
add-arrays-ext
add-dependency-jinja2
add-pystencils-autodiff
always-use-codegen.rewriting.optimize
append-assignments-to-ast
assert-cast_func-arg-is-type
assertion-headers
assumptions-cast_func
astnodes-for-interpolation
astnodes-for-interpolation-rebased
auto-for-assignments
auto-optimizations
autodiff
bugfix-avoid-east-and-west-const
bugfix-collate-types-for-boolean-function
bugfix-fields_accessed-for-InterpolatorAccess
bugfix-ghostlayers-gpu
bugfix-textures
c11-printer
cast_func-assumptions
complex-numbers
complex-numbers-with-type-interference
create_boundary_kwargs
create_type_in_cast_func
csqrt
cuda-array-interface
cuda-autotune
cuda.TextureReference.set_array
custom-fields-different-size-in-transformations
dark-mode
destructuring-field-binding
documentation-for-json-backend
dtype-for-add_arrays
dtype-from-fields
eliminate-usage-of-equation-collection
extra-asserts-sympy-issue
fix-ParallelDataHandling-bug!
fix-TypedImaginaryUnit.__getnewargs__
fix-arrayhandlers
fix-custom-fields-cudakernel
fix-dirichlet
fix-documentation
fix-free/defined-symbols-for-non-Assignments
fix-kerncraft
fix-llvm-gpu
fix-opencl
fix-opencl-extra-in-readme
fix-opencl-llvm-gpu
fix-rotate_weights_and_apply
fix-trailing-whitespace-in-rng.py
foo
function-call-printing
functional_coordinate_transform
gpu_liveness_opts
graph-datahandling
graph-datahandling-tom
graphviz
graphviz-01_tutorial
hyteg
improved_comm
infer-symbol-types-from-definition
infinity
infocomp_hacked
interpolation-24.0.9
interpolation-refactoring
kernel-wrapper-typeannotations
krasser-feature-branch
llvm-experiments
make_python_function
make_python_function-rebased
master
matrix-symbols
mlir
no-cuda-for-doc/lint
not-unify-shapes-branch
omit-globals-when-printing-c-code
opencl-datahandling
opencl-to-spirv
original_assignment-hack
Tags
1.0
release/0.2.1
release/0.2.2
release/0.2.3
release/0.2.4
release/0.2.6
release/0.2.7
release/1.0
release/1.0.1
release/1.1
release/1.1.1
v1.0
v1.1
113 results
Swap
Target
pycodegen/pystencils
Select target project
anirudh.jonnalagadda/pystencils
hyteg/pystencils
jbadwaik/pystencils
jngrad/pystencils
itischler/pystencils
ob28imeq/pystencils
hoenig/pystencils
Bindgen/pystencils
hammer/pystencils
da15siwa/pystencils
holzer/pystencils
alexander.reinauer/pystencils
ec93ujoh/pystencils
Harke/pystencils
seitz/pystencils
pycodegen/pystencils
16 results
master
Select Git revision
Branches
66-absolute-access-is-probably-not-copied-correctly-after-_eval_subs
const_fix
fhennig/cpu-jit
fhennig/v2.0-deprecations
fma
gpu_bufferfield_fix
gpu_liveness_opts
holzer-master-patch-46757
hyteg
improved_comm
master
rangersbach/fix-gpu-atomics
target_dh_refactoring
v2.0-dev
vectorization_sqrt_fix
zikeliml/124-rework-tutorials
zikeliml/Task-96-dotExporterForAST
Tags
last/Kerncraft
last/LLVM
last/OpenCL
release/0.2.1
release/0.2.10
release/0.2.11
release/0.2.12
release/0.2.13
release/0.2.14
release/0.2.15
release/0.2.2
release/0.2.3
release/0.2.4
release/0.2.6
release/0.2.7
release/0.2.8
release/0.2.9
release/0.3.0
release/0.3.1
release/0.3.2
release/0.3.3
release/0.3.4
release/0.4.0
release/0.4.1
release/0.4.2
release/0.4.3
release/0.4.4
release/1.0
release/1.0.1
release/1.1
release/1.1.1
release/1.2
release/1.3
release/1.3.1
release/1.3.2
release/1.3.3
release/1.3.4
release/1.3.5
release/1.3.6
release/1.3.7
release/2.0.dev0
58 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Add ConditionalFieldAccess (Field.Access after out-of-bounds check)
· 8dfe844c
Stephan Seitz
authored
5 years ago
8dfe844c
Merge branch 'master' into 'ConditionalFieldAccess'
· 800eaf6c
Martin Bauer
authored
5 years ago
# Conflicts: # pystencils/data_types.py
800eaf6c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/astnodes.py
+25
-0
25 additions, 0 deletions
pystencils/astnodes.py
pystencils/backends/cbackend.py
+3
-0
3 additions, 0 deletions
pystencils/backends/cbackend.py
pystencils_tests/test_conditional_field_access.py
+69
-0
69 additions, 0 deletions
pystencils_tests/test_conditional_field_access.py
with
97 additions
and
0 deletions
pystencils/astnodes.py
View file @
800eaf6c
...
@@ -744,3 +744,28 @@ class EmptyLine(Node):
...
@@ -744,3 +744,28 @@ class EmptyLine(Node):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
self
.
__str__
()
return
self
.
__str__
()
class
ConditionalFieldAccess
(
sp
.
Function
):
"""
:class:`pystencils.Field.Access` that is only executed if a certain condition is met.
Can be used, for instance, for out-of-bound checks.
"""
def
__new__
(
cls
,
field_access
,
outofbounds_condition
,
outofbounds_value
=
0
):
return
sp
.
Function
.
__new__
(
cls
,
field_access
,
outofbounds_condition
,
sp
.
S
(
outofbounds_value
))
@property
def
access
(
self
):
return
self
.
args
[
0
]
@property
def
outofbounds_condition
(
self
):
return
self
.
args
[
1
]
@property
def
outofbounds_value
(
self
):
return
self
.
args
[
2
]
def
__getnewargs__
(
self
):
return
self
.
access
,
self
.
outofbounds_condition
,
self
.
outofbounds_value
This diff is collapsed.
Click to expand it.
pystencils/backends/cbackend.py
View file @
800eaf6c
...
@@ -426,6 +426,9 @@ class CustomSympyPrinter(CCodePrinter):
...
@@ -426,6 +426,9 @@ class CustomSympyPrinter(CCodePrinter):
)
)
return
code
return
code
def
_print_ConditionalFieldAccess
(
self
,
node
):
return
self
.
_print
(
sp
.
Piecewise
((
node
.
outofbounds_value
,
node
.
outofbounds_condition
),
(
node
.
access
,
True
)))
_print_Max
=
C89CodePrinter
.
_print_Max
_print_Max
=
C89CodePrinter
.
_print_Max
_print_Min
=
C89CodePrinter
.
_print_Min
_print_Min
=
C89CodePrinter
.
_print_Min
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_conditional_field_access.py
0 → 100644
View file @
800eaf6c
# -*- coding: utf-8 -*-
#
# Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
#
# Distributed under terms of the GPLv3 license.
"""
"""
import
itertools
import
numpy
as
np
import
pytest
import
sympy
as
sp
import
pystencils
as
ps
from
pystencils
import
Field
,
x_vector
from
pystencils.astnodes
import
ConditionalFieldAccess
from
pystencils.simp
import
sympy_cse
def
add_fixed_constant_boundary_handling
(
assignments
,
with_cse
):
common_shape
=
next
(
iter
(
set
().
union
(
itertools
.
chain
.
from_iterable
(
[
a
.
atoms
(
Field
.
Access
)
for
a
in
assignments
]
)))).
field
.
spatial_shape
ndim
=
len
(
common_shape
)
def
is_out_of_bound
(
access
,
shape
):
return
sp
.
Or
(
*
[
sp
.
Or
(
a
<
0
,
a
>=
s
)
for
a
,
s
in
zip
(
access
,
shape
)])
safe_assignments
=
[
ps
.
Assignment
(
assignment
.
lhs
,
assignment
.
rhs
.
subs
({
a
:
ConditionalFieldAccess
(
a
,
is_out_of_bound
(
sp
.
Matrix
(
a
.
offsets
)
+
x_vector
(
ndim
),
common_shape
))
for
a
in
assignment
.
rhs
.
atoms
(
Field
.
Access
)
if
not
a
.
is_absolute_access
}))
for
assignment
in
assignments
.
all_assignments
]
subs
=
[{
a
:
ConditionalFieldAccess
(
a
,
is_out_of_bound
(
sp
.
Matrix
(
a
.
offsets
)
+
x_vector
(
ndim
),
common_shape
))
for
a
in
assignment
.
rhs
.
atoms
(
Field
.
Access
)
if
not
a
.
is_absolute_access
}
for
assignment
in
assignments
.
all_assignments
]
print
(
subs
)
if
with_cse
:
safe_assignments
=
sympy_cse
(
ps
.
AssignmentCollection
(
safe_assignments
))
return
safe_assignments
else
:
return
ps
.
AssignmentCollection
(
safe_assignments
)
@pytest.mark.parametrize
(
'
with_cse
'
,
(
False
,
'
with_cse
'
))
def
test_boundary_check
(
with_cse
):
f
,
g
=
ps
.
fields
(
"
f, g : [2D]
"
)
stencil
=
ps
.
Assignment
(
g
[
0
,
0
],
(
f
[
1
,
0
]
+
f
[
-
1
,
0
]
+
f
[
0
,
1
]
+
f
[
0
,
-
1
])
/
4
)
f_arr
=
np
.
random
.
rand
(
1000
,
1000
)
g_arr
=
np
.
zeros_like
(
f_arr
)
# kernel(f=f_arr, g=g_arr)
assignments
=
add_fixed_constant_boundary_handling
(
ps
.
AssignmentCollection
([
stencil
]),
with_cse
)
print
(
assignments
)
kernel_checked
=
ps
.
create_kernel
(
assignments
,
ghost_layers
=
0
).
compile
()
print
(
ps
.
show_code
(
kernel_checked
))
# No SEGFAULT, please!!
kernel_checked
(
f
=
f_arr
,
g
=
g_arr
)
This diff is collapsed.
Click to expand it.