Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor onedal interaction with backend and policies #2168

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6daef75
feat: Introduce BackendManager and PolicyManger
ahuber21 Nov 14, 2024
ec58015
fixup
ahuber21 Nov 23, 2024
1ddcc34
Remove _get_policy() and use queue directly instead
ahuber21 Nov 25, 2024
57155d1
Only use a global queue, which is set by user-facing functions
ahuber21 Nov 26, 2024
f1ec967
remove policy manager
ahuber21 Nov 26, 2024
a360979
wip: fixes related to global queue
ahuber21 Nov 27, 2024
86d1fbd
fixup is_cpu
ahuber21 Nov 27, 2024
6c3b242
fixup dispatch
ahuber21 Nov 27, 2024
2001b48
fixup queue as kwarg, is_gpu
ahuber21 Nov 28, 2024
089d23d
handle SUA interface errors
ahuber21 Nov 28, 2024
aadbd72
fix BackendFucntion in kernel_functions.py
ahuber21 Nov 29, 2024
4239025
undo accidential changes to tests
ahuber21 Nov 29, 2024
44ba5e0
fixup delete _policy.py; fix assert_all_finite from latest main
ahuber21 Nov 29, 2024
1a7dadc
remove utils/__init__.py
ahuber21 Dec 10, 2024
c67fb22
Merge remote-tracking branch 'origin/main' into dev/ahuber/refactor-o…
ahuber21 Dec 10, 2024
81f8285
fix some errors after validation cleanup
ahuber21 Dec 10, 2024
e040cdd
compare only non-cpu devices
ahuber21 Dec 10, 2024
511b44f
fix after merging main
ahuber21 Dec 11, 2024
b39b852
simplify SyclQueue
ahuber21 Dec 11, 2024
a5cb819
further simplify and align SyclQueue handling
ahuber21 Dec 11, 2024
891700f
fix missing return
ahuber21 Dec 11, 2024
a23ea0d
remove intermediate SyclQueue class
ahuber21 Dec 11, 2024
c7eef38
introduce manage_global_queue context manager
ahuber21 Dec 12, 2024
50f6d1b
bring back underscore methods
ahuber21 Dec 12, 2024
d5e9425
kmeans init compute_raw does not support queue
ahuber21 Dec 12, 2024
35a344c
cleanup @support_input_format
ahuber21 Dec 12, 2024
7168aa2
allow for onedal prefix in patching check
ahuber21 Dec 13, 2024
f0ca14b
add missing wraps(func)
ahuber21 Dec 13, 2024
e304dae
Merge remote-tracking branch 'origin/main' into dev/ahuber/refactor-o…
ahuber21 Dec 13, 2024
720e447
fixup
ahuber21 Dec 13, 2024
ff20f76
fix neighbors
ahuber21 Dec 16, 2024
554eb38
Merge remote-tracking branch 'origin/main' into dev/ahuber/refactor-o…
ahuber21 Dec 16, 2024
6307b24
debug print
ahuber21 Dec 17, 2024
e5d109c
debug output
ahuber21 Dec 17, 2024
039d89e
Add new logic for sparse matrix in _copy_to_usm
ahuber21 Dec 17, 2024
2f37e08
only _copy_to_usm with usm_iface
ahuber21 Dec 17, 2024
e40cb3f
lint
ahuber21 Dec 17, 2024
ab0dea4
Merge remote-tracking branch 'origin/main' into dev/ahuber/refactor-o…
ahuber21 Dec 17, 2024
cbf0d35
remove accidental import
ahuber21 Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 64 additions & 24 deletions onedal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@

from daal4py.sklearn._utils import daal_check_version


class Backend:
"""Encapsulates the backend module and provides a unified interface to it together with additional properties about dpc/spmd policies"""

def __init__(self, backend_module, is_dpc, is_spmd):
self.backend = backend_module
self.is_dpc = is_dpc
self.is_spmd = is_spmd

# accessing the instance will return the backend_module
def __getattr__(self, name):
return getattr(self.backend, name)

def __repr__(self) -> str:
return f"Backend({self.backend}, is_dpc={self.is_dpc}, is_spmd={self.is_spmd})"


if "Windows" in platform.system():
import os
import site
Expand All @@ -40,44 +57,67 @@
pass
os.environ["PATH"] = path_to_libs + os.pathsep + os.environ["PATH"]

try:
import onedal._onedal_py_dpc as _backend

_is_dpc_backend = True
except ImportError:
import onedal._onedal_py_host as _backend

_is_dpc_backend = False

_is_spmd_backend = False
try:
# use dpc backend if available
import onedal._onedal_py_dpc

if _is_dpc_backend:
try:
import onedal._onedal_py_spmd_dpc as _spmd_backend
_dpc_backend = Backend(onedal._onedal_py_dpc, is_dpc=True, is_spmd=False)

_is_spmd_backend = True
except ImportError:
_is_spmd_backend = False
_host_backend = None
except ImportError:
# fall back to host backend
_dpc_backend = None

import onedal._onedal_py_host

__all__ = ["covariance", "decomposition", "ensemble", "neighbors", "primitives", "svm"]
_host_backend = Backend(onedal._onedal_py_host, is_dpc=False, is_spmd=False)

if _is_spmd_backend:
__all__.append("spmd")
try:
# also load spmd backend if available
import onedal._onedal_py_spmd_dpc

_spmd_backend = Backend(onedal._onedal_py_spmd_dpc, is_dpc=True, is_spmd=True)

Check warning on line 80 in onedal/__init__.py

View check run for this annotation

Codecov / codecov/patch

onedal/__init__.py#L80

Added line #L80 was not covered by tests
except ImportError:
_spmd_backend = None

# if/elif/else layout required for pylint to realize _default_backend cannot be None
if _dpc_backend is not None:
_default_backend = _dpc_backend
elif _host_backend is not None:
_default_backend = _host_backend
else:
raise ImportError("No oneDAL backend available")

Check warning on line 90 in onedal/__init__.py

View check run for this annotation

Codecov / codecov/patch

onedal/__init__.py#L90

Added line #L90 was not covered by tests

# Core modules to export
__all__ = [
"_host_backend",
"_default_backend",
"_dpc_backend",
"_spmd_backend",
"covariance",
"decomposition",
"ensemble",
"neighbors",
"primitives",
"svm",
]

# Additional features based on version checks
if daal_check_version((2023, "P", 100)):
__all__ += ["basic_statistics", "linear_model"]
if daal_check_version((2023, "P", 200)):
__all__ += ["cluster"]

if _is_spmd_backend:
# Exports if SPMD backend is available
if _spmd_backend is not None:
__all__ += ["spmd"]
if daal_check_version((2023, "P", 100)):

Check warning on line 115 in onedal/__init__.py

View check run for this annotation

Codecov / codecov/patch

onedal/__init__.py#L114-L115

Added lines #L114 - L115 were not covered by tests
__all__ += [
"spmd.basic_statistics",
"spmd.decomposition",
"spmd.linear_model",
"spmd.neighbors",
]

if daal_check_version((2023, "P", 200)):
__all__ += ["cluster"]

if _is_spmd_backend:
if daal_check_version((2023, "P", 200)):

Check warning on line 122 in onedal/__init__.py

View check run for this annotation

Codecov / codecov/patch

onedal/__init__.py#L122

Added line #L122 was not covered by tests
__all__ += ["spmd.cluster"]
Loading
Loading