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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Julian Hammer
pystencils
Commits
945e6bd3
Commit
945e6bd3
authored
4 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
Make sure that the RNG counter can be substituted during loop cutting
parent
9f966136
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/rng.py
+8
-4
8 additions, 4 deletions
pystencils/rng.py
pystencils_tests/test_random.py
+11
-2
11 additions, 2 deletions
pystencils_tests/test_random.py
with
19 additions
and
6 deletions
pystencils/rng.py
+
8
−
4
View file @
945e6bd3
...
...
@@ -19,9 +19,8 @@ def _get_rng_template(name, data_type, num_vars):
return
template
def
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
time_step
,
offsets
,
keys
,
dim
,
result_symbols
):
parameters
=
[
time_step
]
+
[
LoopOverCoordinate
.
get_loop_counter_symbol
(
i
)
+
offsets
[
i
]
for
i
in
range
(
dim
)]
+
[
0
]
*
(
3
-
dim
)
+
list
(
keys
)
def
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
time_step
,
coordinates
,
keys
,
dim
,
result_symbols
):
parameters
=
[
time_step
]
+
coordinates
+
[
0
]
*
(
3
-
dim
)
+
list
(
keys
)
if
dialect
==
'
cuda
'
or
(
dialect
==
'
c
'
and
vector_instruction_set
is
None
):
return
template
.
format
(
parameters
=
'
,
'
.
join
(
str
(
p
)
for
p
in
parameters
),
...
...
@@ -44,6 +43,7 @@ class RNGBase(CustomCodeNode):
super
().
__init__
(
""
,
symbols_read
=
symbols_read
,
symbols_defined
=
self
.
result_symbols
)
self
.
_time_step
=
time_step
self
.
_offsets
=
offsets
self
.
_coordinates
=
[
LoopOverCoordinate
.
get_loop_counter_symbol
(
i
)
+
offsets
[
i
]
for
i
in
range
(
dim
)]
self
.
headers
=
[
f
'"
{
self
.
_name
}
_rand.h
"'
]
self
.
keys
=
tuple
(
keys
)
self
.
_args
=
sp
.
sympify
((
dim
,
time_step
,
keys
))
...
...
@@ -61,13 +61,17 @@ class RNGBase(CustomCodeNode):
result
.
update
(
loop_counters
)
return
result
def
subs
(
self
,
subs_dict
)
->
None
:
for
i
in
range
(
len
(
self
.
_coordinates
)):
self
.
_coordinates
[
i
]
=
self
.
_coordinates
[
i
].
subs
(
subs_dict
)
def
fast_subs
(
self
,
*
_
):
return
self
# nothing to replace inside this node - would destroy intermediate "dummy" by re-creating them
def
get_code
(
self
,
dialect
,
vector_instruction_set
):
template
=
_get_rng_template
(
self
.
_name
,
self
.
_data_type
,
self
.
_num_vars
)
return
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
self
.
_time_step
,
self
.
_
offset
s
,
self
.
keys
,
self
.
_dim
,
self
.
result_symbols
)
self
.
_time_step
,
self
.
_
coordinate
s
,
self
.
keys
,
self
.
_dim
,
self
.
result_symbols
)
def
__repr__
(
self
):
return
(
"
,
"
.
join
([
'
{}
'
]
*
self
.
_num_vars
)
+
"
\\
leftarrow {}RNG
"
).
format
(
*
self
.
result_symbols
,
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_random.py
+
11
−
2
View file @
945e6bd3
...
...
@@ -3,7 +3,7 @@ import numpy as np
import
pytest
import
pystencils
as
ps
from
pystencils.rng
import
PhiloxFourFloats
,
PhiloxTwoDoubles
,
AESNIFourFloats
,
AESNITwoDoubles
from
pystencils.rng
import
PhiloxFourFloats
,
PhiloxTwoDoubles
,
AESNIFourFloats
,
AESNITwoDoubles
,
random_symbol
# curand_Philox4x32_10(make_uint4(124, i, j, 0), make_uint2(0, 0))
...
...
@@ -99,4 +99,13 @@ def test_aesni_float():
dh
.
run_kernel
(
kernel
,
time_step
=
124
)
dh
.
all_to_cpu
()
arr
=
dh
.
gather_array
(
'
f
'
)
assert
np
.
logical_and
(
arr
<=
1.0
,
arr
>=
0
).
all
()
\ No newline at end of file
assert
np
.
logical_and
(
arr
<=
1.0
,
arr
>=
0
).
all
()
def
test_staggered
():
"""
Make sure that the RNG counter can be substituted during loop cutting
"""
dh
=
ps
.
create_data_handling
((
8
,
8
),
default_ghost_layers
=
0
,
default_target
=
"
cpu
"
)
j
=
dh
.
add_array
(
"
j
"
,
values_per_cell
=
dh
.
dim
,
field_type
=
ps
.
FieldType
.
STAGGERED_FLUX
)
a
=
ps
.
AssignmentCollection
([
ps
.
Assignment
(
j
.
staggered_access
(
n
),
0
)
for
n
in
j
.
staggered_stencil
])
rng_symbol_gen
=
random_symbol
(
a
.
subexpressions
,
dim
=
dh
.
dim
)
a
.
main_assignments
[
0
]
=
ps
.
Assignment
(
a
.
main_assignments
[
0
].
lhs
,
next
(
rng_symbol_gen
))
kernel
=
ps
.
create_staggered_kernel
(
a
,
target
=
dh
.
default_target
).
compile
()
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