diff --git a/framework_info/appy.json b/framework_info/appy.json new file mode 100644 index 0000000..4a3ba86 --- /dev/null +++ b/framework_info/appy.json @@ -0,0 +1,10 @@ +{ + "framework": { + "simple_name": "appy", + "full_name": "APPy", + "prefix": "ap", + "postfix": "appy", + "class": "APPyFramework", + "arch": "gpu" + } +} diff --git a/npbench/benchmarks/go_fast/go_fast_appy.py b/npbench/benchmarks/go_fast/go_fast_appy.py new file mode 100644 index 0000000..794f7fd --- /dev/null +++ b/npbench/benchmarks/go_fast/go_fast_appy.py @@ -0,0 +1,13 @@ +# https://numba.readthedocs.io/en/stable/user/5minguide.html + +import torch +import appy + +@appy.jit +def go_fast(a): + trace = torch.zeros(1, dtype=a.dtype) + #pragma parallel for + for i in range(a.shape[0]): + #pragma atomic + trace[0] += torch.tanh(a[i, i]) + return a + trace diff --git a/npbench/infrastructure/__init__.py b/npbench/infrastructure/__init__.py index ac403b7..d5ddd96 100644 --- a/npbench/infrastructure/__init__.py +++ b/npbench/infrastructure/__init__.py @@ -10,3 +10,4 @@ from .legate_framework import * from .numba_framework import * from .pythran_framework import * +from .appy_framework import * \ No newline at end of file diff --git a/npbench/infrastructure/appy_framework.py b/npbench/infrastructure/appy_framework.py new file mode 100644 index 0000000..8dd4b7c --- /dev/null +++ b/npbench/infrastructure/appy_framework.py @@ -0,0 +1,52 @@ +# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved. +import pkg_resources + +from npbench.infrastructure import Benchmark, Framework +from typing import Any, Callable, Dict + + +class APPyFramework(Framework): + """ A class for reading and processing framework information. """ + + def __init__(self, fname: str): + """ Reads framework information. + :param fname: The framework name. + """ + + super().__init__(fname) + + def version(self) -> str: + """ Return the framework version. """ + return 0.1 + + # def copy_func(self) -> Callable: + # """ Returns the copy-method that should be used + # for copying the benchmark arguments. """ + # import cupy + # return cupy.asarray + + def copy_func(self) -> Callable: + import torch + torch.set_default_device('cuda') + def inner(arr): + copy = torch.from_numpy(arr).to('cuda') + return copy + return inner + + def imports(self) -> Dict[str, Any]: + import torch + import appy + return {'torch': torch} + + def exec_str(self, bench: Benchmark, impl: Callable = None): + """ Generates the execution-string that should be used to call + the benchmark implementation. + :param bench: A benchmark. + :param impl: A benchmark implementation. + """ + + arg_str = self.arg_str(bench, impl) + # param_str = self.param_str(bench, impl) + main_exec_str = "__npb_result = __npb_impl({a})".format(a=arg_str) + sync_str = "torch.cuda.synchronize()" + return main_exec_str + "; " + sync_str