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
Commits
c989d8ae
Commit
c989d8ae
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Simplify boundary handling with OpenCL
parent
d08987c1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pystencils/boundaries/boundaryhandling.py
+19
-38
19 additions, 38 deletions
pystencils/boundaries/boundaryhandling.py
with
19 additions
and
38 deletions
pystencils/boundaries/boundaryhandling.py
+
19
−
38
View file @
c989d8ae
...
...
@@ -87,26 +87,25 @@ class BoundaryHandling:
fi
=
flag_interface
self
.
flag_interface
=
fi
if
fi
is
not
None
else
FlagInterface
(
data_handling
,
name
+
"
Flags
"
)
gpu
=
self
.
_target
in
self
.
_data_handling
.
_GPU_LIKE_TARGETS
def
to_cpu
(
gpu_version
,
cpu_version
):
gpu_version
=
gpu_version
.
boundary_object_to_index_list
cpu_version
=
cpu_version
.
boundary_object_to_index_list
for
obj
,
cpu_arr
in
cpu_version
.
items
():
gpu_version
[
obj
].
get
(
cpu_arr
)
def
to_gpu
(
gpu_version
,
cpu_version
):
gpu_version
=
gpu_version
.
boundary_object_to_index_list
cpu_version
=
cpu_version
.
boundary_object_to_index_list
for
obj
,
cpu_arr
in
cpu_version
.
items
():
if
obj
not
in
gpu_version
or
gpu_version
[
obj
].
shape
!=
cpu_arr
.
shape
:
gpu_version
[
obj
]
=
self
.
data_handling
.
array_handler
.
to_gpu
(
cpu_arr
)
else
:
self
.
data_handling
.
array_handler
.
upload
(
gpu_version
[
obj
],
cpu_arr
)
class_
=
self
.
IndexFieldBlockData
if
self
.
_target
==
'
opencl
'
:
def
opencl_to_device
(
gpu_version
,
cpu_version
):
from
pyopencl
import
array
gpu_version
=
gpu_version
.
boundary_object_to_index_list
cpu_version
=
cpu_version
.
boundary_object_to_index_list
for
obj
,
cpu_arr
in
cpu_version
.
items
():
if
obj
not
in
gpu_version
or
gpu_version
[
obj
].
shape
!=
cpu_arr
.
shape
:
from
pystencils.opencl.opencljit
import
get_global_cl_queue
queue
=
self
.
_data_handling
.
_opencl_queue
or
get_global_cl_queue
()
gpu_version
[
obj
]
=
array
.
to_device
(
queue
,
cpu_arr
)
else
:
gpu_version
[
obj
].
set
(
cpu_arr
)
class_
=
type
(
'
opencl_class
'
,
(
self
.
IndexFieldBlockData
,),
{
'
to_gpu
'
:
opencl_to_device
})
data_handling
.
add_custom_class
(
self
.
_index_array_name
,
class_
,
cpu
=
True
,
gpu
=
gpu
)
class_
.
to_cpu
=
to_cpu
class_
.
to_gpu
=
to_gpu
data_handling
.
add_custom_class
(
self
.
_index_array_name
,
class_
)
@property
def
data_handling
(
self
):
...
...
@@ -330,7 +329,7 @@ class BoundaryHandling:
self
.
kernel
=
kernel
class
IndexFieldBlockData
:
def
__init__
(
self
,
*
_1
,
**
_2
):
def
__init__
(
self
):
self
.
boundary_object_to_index_list
=
{}
self
.
boundary_object_to_data_setter
=
{}
...
...
@@ -338,24 +337,6 @@ class BoundaryHandling:
self
.
boundary_object_to_index_list
.
clear
()
self
.
boundary_object_to_data_setter
.
clear
()
@staticmethod
def
to_cpu
(
gpu_version
,
cpu_version
):
gpu_version
=
gpu_version
.
boundary_object_to_index_list
cpu_version
=
cpu_version
.
boundary_object_to_index_list
for
obj
,
cpu_arr
in
cpu_version
.
items
():
gpu_version
[
obj
].
get
(
cpu_arr
)
@staticmethod
def
to_gpu
(
gpu_version
,
cpu_version
):
from
pycuda
import
gpuarray
gpu_version
=
gpu_version
.
boundary_object_to_index_list
cpu_version
=
cpu_version
.
boundary_object_to_index_list
for
obj
,
cpu_arr
in
cpu_version
.
items
():
if
obj
not
in
gpu_version
or
gpu_version
[
obj
].
shape
!=
cpu_arr
.
shape
:
gpu_version
[
obj
]
=
gpuarray
.
to_gpu
(
cpu_arr
)
else
:
gpu_version
[
obj
].
set
(
cpu_arr
)
class
BoundaryDataSetter
:
...
...
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