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
Markus Holzer
pystencils
Commits
ada89c01
Commit
ada89c01
authored
7 months ago
by
Markus Holzer
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-gpu-islices' into 'master'
Fix width-one iteration slices on GPU See merge request
!422
parents
3c0c4329
e3622192
Branches
master
No related tags found
No related merge requests found
Pipeline
#69934
passed
7 months ago
Stage: pretest
Stage: test
Stage: docs
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils/gpu/kernelcreation.py
+2
-1
2 additions, 1 deletion
src/pystencils/gpu/kernelcreation.py
tests/test_sliced_iteration.py
+89
-12
89 additions, 12 deletions
tests/test_sliced_iteration.py
with
91 additions
and
13 deletions
src/pystencils/gpu/kernelcreation.py
+
2
−
1
View file @
ada89c01
...
@@ -66,7 +66,8 @@ def create_cuda_kernel(assignments: NodeCollection, config: CreateKernelConfig):
...
@@ -66,7 +66,8 @@ def create_cuda_kernel(assignments: NodeCollection, config: CreateKernelConfig):
iteration_space
=
normalize_slice
(
iteration_slice
,
common_shape
)
iteration_space
=
normalize_slice
(
iteration_slice
,
common_shape
)
else
:
else
:
iteration_space
=
normalize_slice
(
iteration_slice
,
common_shape
)
iteration_space
=
normalize_slice
(
iteration_slice
,
common_shape
)
iteration_space
=
tuple
([
s
if
isinstance
(
s
,
slice
)
else
slice
(
s
,
s
,
1
)
for
s
in
iteration_space
])
iteration_space
=
tuple
([
s
if
isinstance
(
s
,
slice
)
else
slice
(
s
,
s
+
1
,
1
)
for
s
in
iteration_space
])
loop_counter_symbols
=
[
LoopOverCoordinate
.
get_loop_counter_symbol
(
i
)
for
i
in
range
(
len
(
iteration_space
))]
loop_counter_symbols
=
[
LoopOverCoordinate
.
get_loop_counter_symbol
(
i
)
for
i
in
range
(
len
(
iteration_space
))]
...
...
This diff is collapsed.
Click to expand it.
tests/test_sliced_iteration.py
+
89
−
12
View file @
ada89c01
import
numpy
as
np
import
numpy
as
np
import
sympy
as
sp
import
sympy
as
sp
import
pytest
from
pystencils
import
Assignment
,
Field
,
TypedSymbol
,
create_kernel
,
make_slice
from
pystencils
import
(
Assignment
,
Field
,
TypedSymbol
,
create_kernel
,
make_slice
,
Target
,
create_data_handling
,
)
from
pystencils.simp
import
sympy_cse_on_assignment_list
from
pystencils.simp
import
sympy_cse_on_assignment_list
def
test_sliced_iteration
():
@pytest.mark.parametrize
(
"
target
"
,
[
Target
.
CPU
,
Target
.
GPU
])
def
test_sliced_iteration
(
target
):
if
target
==
Target
.
GPU
:
pytest
.
importorskip
(
"
cupy
"
)
size
=
(
4
,
4
)
size
=
(
4
,
4
)
src_arr
=
np
.
ones
(
size
)
dst_arr
=
np
.
zeros_like
(
src_arr
)
dh
=
create_data_handling
(
size
,
default_target
=
target
,
default_ghost_layers
=
0
)
src_field
=
Field
.
create_from_numpy_array
(
'
src
'
,
src_arr
)
dst_field
=
Field
.
create_from_numpy_array
(
'
dst
'
,
dst_arr
)
src_field
=
dh
.
add_array
(
"
src
"
,
1
)
dst_field
=
dh
.
add_array
(
"
dst
"
,
1
)
dh
.
fill
(
src_field
.
name
,
1.0
,
ghost_layers
=
True
)
dh
.
fill
(
dst_field
.
name
,
0.0
,
ghost_layers
=
True
)
a
,
b
=
sp
.
symbols
(
"
a b
"
)
a
,
b
=
sp
.
symbols
(
"
a b
"
)
update_rule
=
Assignment
(
dst_field
[
0
,
0
],
update_rule
=
Assignment
(
(
a
*
src_field
[
0
,
1
]
+
a
*
src_field
[
0
,
-
1
]
+
dst_field
[
0
,
0
],
b
*
src_field
[
1
,
0
]
+
b
*
src_field
[
-
1
,
0
])
/
4
)
(
a
*
src_field
[
0
,
1
]
+
a
*
src_field
[
0
,
-
1
]
+
b
*
src_field
[
1
,
0
]
+
b
*
src_field
[
-
1
,
0
]
)
/
4
,
)
s
=
make_slice
[
1
:
3
,
1
]
kernel
=
create_kernel
(
sympy_cse_on_assignment_list
([
update_rule
]),
iteration_slice
=
s
,
target
=
target
).
compile
()
if
target
==
Target
.
GPU
:
dh
.
all_to_gpu
()
dh
.
run_kernel
(
kernel
,
a
=
1.0
,
b
=
1.0
)
if
target
==
Target
.
GPU
:
dh
.
all_to_cpu
()
expected_result
=
np
.
zeros
(
size
)
expected_result
[
1
:
3
,
1
]
=
1
np
.
testing
.
assert_almost_equal
(
dh
.
gather_array
(
dst_field
.
name
),
expected_result
)
@pytest.mark.parametrize
(
"
target
"
,
[
Target
.
CPU
,
Target
.
GPU
])
def
test_symbols_in_slice
(
target
):
if
target
==
Target
.
GPU
:
pytest
.
xfail
(
"
Iteration slices including arbitrary symbols are currently broken on GPU
"
)
size
=
(
4
,
4
)
dh
=
create_data_handling
(
size
,
default_target
=
target
,
default_ghost_layers
=
0
)
src_field
=
dh
.
add_array
(
"
src
"
,
1
)
dst_field
=
dh
.
add_array
(
"
dst
"
,
1
)
dh
.
fill
(
src_field
.
name
,
1.0
,
ghost_layers
=
True
)
dh
.
fill
(
dst_field
.
name
,
0.0
,
ghost_layers
=
True
)
a
,
b
=
sp
.
symbols
(
"
a b
"
)
update_rule
=
Assignment
(
dst_field
[
0
,
0
],
(
a
*
src_field
[
0
,
1
]
+
a
*
src_field
[
0
,
-
1
]
+
b
*
src_field
[
1
,
0
]
+
b
*
src_field
[
-
1
,
0
]
)
/
4
,
)
x_end
=
TypedSymbol
(
"
x_end
"
,
"
int
"
)
x_end
=
TypedSymbol
(
"
x_end
"
,
"
int
"
)
s
=
make_slice
[
1
:
x_end
,
1
]
s
=
make_slice
[
1
:
x_end
,
1
]
x_end_value
=
size
[
1
]
-
1
x_end_value
=
size
[
1
]
-
1
kernel
=
create_kernel
(
sympy_cse_on_assignment_list
([
update_rule
]),
iteration_slice
=
s
).
compile
()
kernel
=
create_kernel
(
sympy_cse_on_assignment_list
([
update_rule
]),
iteration_slice
=
s
,
target
=
target
).
compile
()
if
target
==
Target
.
GPU
:
dh
.
all_to_gpu
()
dh
.
run_kernel
(
kernel
,
a
=
1.0
,
b
=
1.0
,
x_end
=
x_end_value
)
kernel
(
src
=
src_arr
,
dst
=
dst_arr
,
a
=
1.0
,
b
=
1.0
,
x_end
=
x_end_value
)
if
target
==
Target
.
GPU
:
dh
.
all_to_cpu
()
expected_result
=
np
.
zeros
(
size
)
expected_result
=
np
.
zeros
(
size
)
expected_result
[
1
:
x_end_value
,
1
]
=
1
expected_result
[
1
:
x_end_value
,
1
]
=
1
np
.
testing
.
assert_almost_equal
(
expected_result
,
dst_arr
)
np
.
testing
.
assert_almost_equal
(
dh
.
gather_array
(
dst_field
.
name
),
expected_result
)
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