Skip to content
Snippets Groups Projects
Commit f5d3f8d9 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Throw an error when performing GPU operations with SerialDataHandling when pycuda is not available

parent b44b0045
Branches
Tags
1 merge request!164Throw an error when performing GPU operations with SerialDataHandling when pycuda is not available
...@@ -39,3 +39,9 @@ class PyCudaArrayHandler: ...@@ -39,3 +39,9 @@ class PyCudaArrayHandler:
return self.to_gpu(cpu_array) return self.to_gpu(cpu_array)
from_numpy = to_gpu from_numpy = to_gpu
class PyCudaNotAvailableHandler:
def __getattribute__(self, name):
raise NotImplementedError("Unable to initiaize PyCuda! "
"Try to run `import pycuda.autoinit` to check whether PyCuda is working correctly!")
...@@ -6,7 +6,7 @@ import numpy as np ...@@ -6,7 +6,7 @@ import numpy as np
from pystencils.datahandling.blockiteration import SerialBlock from pystencils.datahandling.blockiteration import SerialBlock
from pystencils.datahandling.datahandling_interface import DataHandling from pystencils.datahandling.datahandling_interface import DataHandling
from pystencils.datahandling.pycuda import PyCudaArrayHandler from pystencils.datahandling.pycuda import PyCudaArrayHandler, PyCudaNotAvailableHandler
from pystencils.datahandling.pyopencl import PyOpenClArrayHandler from pystencils.datahandling.pyopencl import PyOpenClArrayHandler
from pystencils.field import ( from pystencils.field import (
Field, FieldType, create_numpy_array_with_layout, layout_string_to_tuple, Field, FieldType, create_numpy_array_with_layout, layout_string_to_tuple,
...@@ -53,7 +53,7 @@ class SerialDataHandling(DataHandling): ...@@ -53,7 +53,7 @@ class SerialDataHandling(DataHandling):
try: try:
self.array_handler = PyCudaArrayHandler() self.array_handler = PyCudaArrayHandler()
except Exception: except Exception:
self.array_handler = None self.array_handler = PyCudaNotAvailableHandler()
if default_target == 'opencl' or opencl_queue: if default_target == 'opencl' or opencl_queue:
self.array_handler = PyOpenClArrayHandler(opencl_queue) self.array_handler = PyOpenClArrayHandler(opencl_queue)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment