Skip to content

Commit

Permalink
Add required packages to frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzEeKkAa committed May 3, 2024
1 parent ee1357c commit 583ee26
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dpbench/config/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import tomli

from dpbench.infrastructure.frameworks.fabric import get_framework_class

from .benchmark import Benchmark, BenchmarkImplementation, Presets
from .config import Config
from .framework import Framework
Expand Down Expand Up @@ -117,7 +119,7 @@ def read_configs( # noqa: C901: TODO: move modules into config
for framework in config.frameworks:
config.implementations += framework.postfixes

if implementations is None:
if implementations is None or len(implementations) == 0:
implementations = {impl.postfix for impl in config.implementations}

if load_implementations:
Expand Down Expand Up @@ -228,6 +230,15 @@ def read_frameworks(
if len(framework.postfixes) == 0:
continue

cls = get_framework_class(framework)
unavailable_pkgs = cls.get_missing_required_packages()
if len(unavailable_pkgs) > 0:
logging.warning(
f"Framework {framework.simple_name} unavailable "
+ f"due to missing packages {unavailable_pkgs}"
)
continue

config.frameworks.append(framework)


Expand Down
4 changes: 4 additions & 0 deletions dpbench/infrastructure/frameworks/cupy_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):

super().__init__(fname, config)

@staticmethod
def required_packages() -> list[str]:
return ["cupy"]

def copy_to_func(self) -> Callable:
"""Returns the copy-method that should be used
for copying the benchmark arguments."""
Expand Down
4 changes: 4 additions & 0 deletions dpbench/infrastructure/frameworks/dpnp_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
)
raise sdce

@staticmethod
def required_packages() -> list[str]:
return ["dpnp"]

def device_filter_string(self) -> str:
"""Returns the sycl device's filter string if the framework has an
associated sycl device."""
Expand Down
7 changes: 6 additions & 1 deletion dpbench/infrastructure/frameworks/fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def build_framework_map() -> dict[str, Framework]:
return result


def build_framework(framework_config: cfg.Framework) -> Framework:
def get_framework_class(framework_config: cfg.Framework) -> Framework:
available_classes = [
Framework,
DpcppFramework,
Expand All @@ -61,4 +61,9 @@ def build_framework(framework_config: cfg.Framework) -> Framework:
)
constructor = Framework

return constructor


def build_framework(framework_config: cfg.Framework) -> Framework:
constructor = get_framework_class(framework_config)
return constructor(config=framework_config)
15 changes: 15 additions & 0 deletions dpbench/infrastructure/frameworks/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: BSD-3-Clause

import logging
from importlib.util import find_spec
from typing import Any, Callable, Dict, final

import pkg_resources
Expand Down Expand Up @@ -45,6 +46,20 @@ def __init__(

self.device_info = cpuinfo.get_cpu_info().get("brand_raw")

@staticmethod
def required_packages() -> list[str]:
return []

@classmethod
def get_missing_required_packages(cls) -> None:
unavailable_packages = []
for pkg in cls.required_packages():
spec = find_spec(pkg)
if spec is None:
unavailable_packages.append(pkg)

return unavailable_packages

def device_filter_string(self) -> str:
"""Returns the sycl device's filter string if the framework has an
associated sycl device."""
Expand Down
4 changes: 4 additions & 0 deletions dpbench/infrastructure/frameworks/numba_cuda_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):

super().__init__(fname, config)

@staticmethod
def required_packages() -> list[str]:
return ["cupy"]

def copy_to_func(self) -> Callable:
"""Returns the copy-method that should be used
for copying the benchmark arguments."""
Expand Down
4 changes: 4 additions & 0 deletions dpbench/infrastructure/frameworks/numba_dpex_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
)
raise sdce

@staticmethod
def required_packages() -> list[str]:
return ["numba_dpex"]

def device_filter_string(self) -> str:
"""Returns the sycl device's filter string if the framework has an
associated sycl device."""
Expand Down
4 changes: 4 additions & 0 deletions dpbench/infrastructure/frameworks/numba_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):
"""

super().__init__(fname, config)

@staticmethod
def required_packages() -> list[str]:
return ["numba"]
4 changes: 4 additions & 0 deletions dpbench/infrastructure/frameworks/numba_mlir_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self, fname: str = None, config: cfg.Framework = None):

self.device_info = dpctl.SyclDevice(self.sycl_device).name

@staticmethod
def required_packages() -> list[str]:
return ["numba_mlir"]

def copy_to_func(self) -> Callable:
"""Returns the copy-method that should be used
for copying the benchmark arguments to device."""
Expand Down

0 comments on commit 583ee26

Please sign in to comment.