Skip to content
Snippets Groups Projects

Opencl datahandling

Merged Stephan Seitz requested to merge seitz/pystencils:opencl-datahandling into master
1 file
+ 19
38
Compare changes
  • Side-by-side
  • Inline
@@ -87,26 +87,25 @@ class BoundaryHandling:
@@ -87,26 +87,25 @@ class BoundaryHandling:
fi = flag_interface
fi = flag_interface
self.flag_interface = fi if fi is not None else FlagInterface(data_handling, name + "Flags")
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
class_ = self.IndexFieldBlockData
if self._target == 'opencl':
class_.to_cpu = to_cpu
def opencl_to_device(gpu_version, cpu_version):
class_.to_gpu = to_gpu
from pyopencl import array
data_handling.add_custom_class(self._index_array_name, class_)
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)
@property
@property
def data_handling(self):
def data_handling(self):
@@ -330,7 +329,7 @@ class BoundaryHandling:
@@ -330,7 +329,7 @@ class BoundaryHandling:
self.kernel = kernel
self.kernel = kernel
class IndexFieldBlockData:
class IndexFieldBlockData:
def __init__(self, *_1, **_2):
def __init__(self):
self.boundary_object_to_index_list = {}
self.boundary_object_to_index_list = {}
self.boundary_object_to_data_setter = {}
self.boundary_object_to_data_setter = {}
@@ -338,24 +337,6 @@ class BoundaryHandling:
@@ -338,24 +337,6 @@ class BoundaryHandling:
self.boundary_object_to_index_list.clear()
self.boundary_object_to_index_list.clear()
self.boundary_object_to_data_setter.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:
class BoundaryDataSetter:
Loading