Skip to content

Commit 35cb9f3

Browse files
authored
Merge pull request #30 from tongzhou80/main
Added new framework APPy, and its implementation for one benchmark go_fast
2 parents bbba077 + bbac87b commit 35cb9f3

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

framework_info/appy.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"framework": {
3+
"simple_name": "appy",
4+
"full_name": "APPy",
5+
"prefix": "ap",
6+
"postfix": "appy",
7+
"class": "APPyFramework",
8+
"arch": "gpu"
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://numba.readthedocs.io/en/stable/user/5minguide.html
2+
3+
import torch
4+
import appy
5+
6+
@appy.jit
7+
def go_fast(a):
8+
trace = torch.zeros(1, dtype=a.dtype)
9+
#pragma parallel for
10+
for i in range(a.shape[0]):
11+
#pragma atomic
12+
trace[0] += torch.tanh(a[i, i])
13+
return a + trace

npbench/infrastructure/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
from .legate_framework import *
1111
from .numba_framework import *
1212
from .pythran_framework import *
13+
from .appy_framework import *
1314
from .jax_framework import *
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
2+
import pkg_resources
3+
4+
from npbench.infrastructure import Benchmark, Framework
5+
from typing import Any, Callable, Dict
6+
7+
8+
class APPyFramework(Framework):
9+
""" A class for reading and processing framework information. """
10+
11+
def __init__(self, fname: str):
12+
""" Reads framework information.
13+
:param fname: The framework name.
14+
"""
15+
16+
super().__init__(fname)
17+
18+
def version(self) -> str:
19+
""" Return the framework version. """
20+
return 0.1
21+
22+
# def copy_func(self) -> Callable:
23+
# """ Returns the copy-method that should be used
24+
# for copying the benchmark arguments. """
25+
# import cupy
26+
# return cupy.asarray
27+
28+
def copy_func(self) -> Callable:
29+
import torch
30+
torch.set_default_device('cuda')
31+
def inner(arr):
32+
copy = torch.from_numpy(arr).to('cuda')
33+
return copy
34+
return inner
35+
36+
def imports(self) -> Dict[str, Any]:
37+
import torch
38+
import appy
39+
return {'torch': torch}
40+
41+
def exec_str(self, bench: Benchmark, impl: Callable = None):
42+
""" Generates the execution-string that should be used to call
43+
the benchmark implementation.
44+
:param bench: A benchmark.
45+
:param impl: A benchmark implementation.
46+
"""
47+
48+
arg_str = self.arg_str(bench, impl)
49+
# param_str = self.param_str(bench, impl)
50+
main_exec_str = "__npb_result = __npb_impl({a})".format(a=arg_str)
51+
sync_str = "torch.cuda.synchronize()"
52+
return main_exec_str + "; " + sync_str

0 commit comments

Comments
 (0)