Skip to content

Commit

Permalink
add debug print (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
StRigaud committed Nov 21, 2024
1 parent 9ff0fda commit 41c61f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pyclesperanto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@

from ._interroperability import * # isort:skip

print(f"pyclesperanto version: {__version__}")

default_initialisation()
12 changes: 11 additions & 1 deletion pyclesperanto/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def select_device(device_id: Union[str, int] = "", device_type: str = "all") ->
-------
device : Device
"""
print("\t\tselecting device ...")
if isinstance(device_id, str):
device = BackendManager.get_backend().getDeviceFromName(device_id, device_type)
elif isinstance(device_id, int):
Expand All @@ -54,6 +55,7 @@ def select_device(device_id: Union[str, int] = "", device_type: str = "all") ->
if _current_device._instance and device == _current_device._instance:
return _current_device._instance
_current_device._instance = device
print("\t\tdone!")
return device


Expand Down Expand Up @@ -92,12 +94,14 @@ def list_available_backends() -> list:
-------
name list : list[str]
"""
print("\tlist available backends ...")
back_list = list(BackendManager.get_backends_list())
if not back_list:
warnings.warn(
"No backend available. Please install either OpenCL or CUDA on your system.",
RuntimeWarning,
)
print("\tdone!")
return back_list


Expand All @@ -112,7 +116,7 @@ def select_backend(backend: str = "opencl") -> str:
type : str, default = "opencl"
determine the backend to use between opencl and cuda
"""

print("\tset backend ...")
# enforce lowercase for backend_type
backend = backend.lower()
# is backend_type is different than "cuda" or "opencl", raise an error
Expand All @@ -121,8 +125,11 @@ def select_backend(backend: str = "opencl") -> str:
f"'{backend}' is not a supported Backend. Please use either 'opencl' or 'cuda'."
)
BackendManager.set_backend(backend=backend)
print("\tdone!")
# reset current device to default one
print("\tset default device ...")
select_device()
print("\tdone!")
return f"{BackendManager.get_backend()} selected."


Expand All @@ -148,12 +155,15 @@ def wait_for_kernel_to_finish(wait: bool = True, device: Device = None):

def default_initialisation():
"""Set default backend and device"""

try:
print("Initialising pyclesperanto...")
backends = list_available_backends()
if backends:
_ = select_backend(backends[-1])
else:
raise RuntimeError("No backend available.")
print("done!")
except Exception as e:
warnings.warn(
f"Error while initialising pyclesperanto: {e}\n\n"
Expand Down

0 comments on commit 41c61f7

Please sign in to comment.