Skip to content

Commit a1d826b

Browse files
authored
Merge pull request #224 from IntelPython/feature/dtpye-precision-selection
Select dtype precision through configs
2 parents 69ff7d9 + 7b3c1f2 commit a1d826b

24 files changed

+291
-54
lines changed

dpbench/benchmarks/black_scholes/black_scholes_initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
def initialize(nopt, seed):
6+
def initialize(nopt, seed, types_dict):
77
import numpy as np
88
import numpy.random as default_rng
99

10-
dtype = np.float64
10+
dtype = types_dict["float"]
1111
S0L = 10.0
1212
S0H = 50.0
1313
XL = 10.0

dpbench/benchmarks/dbscan/dbscan_initialize.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
def initialize(n_samples, n_features, centers, seed):
6+
def initialize(n_samples, n_features, centers, seed, types_dict):
77
from typing import NamedTuple
88

99
import numpy as np
@@ -12,7 +12,6 @@ def initialize(n_samples, n_features, centers, seed):
1212

1313
DEFAULT_EPS = 0.6
1414
DEFAULT_MINPTS = 20
15-
dtype = np.float64
1615

1716
class DataSize(NamedTuple):
1817
n_samples: int
@@ -66,7 +65,7 @@ class Params(NamedTuple):
6665
)
6766

6867
return (
69-
X.flatten().astype(dtype),
68+
X.flatten().astype(types_dict["float"]),
7069
params.eps,
7170
params.minpts,
7271
)

dpbench/benchmarks/gpairs/gpairs_initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def _generate_rbins(dtype, nbins, rmax, rmin):
1111
return (rbins**2).astype(dtype)
1212

1313

14-
def initialize(nopt, seed, nbins, rmax, rmin):
14+
def initialize(nopt, seed, nbins, rmax, rmin, types_dict):
1515
import numpy.random as default_rng
1616

1717
default_rng.seed(seed)
18-
dtype = np.float32
18+
dtype = types_dict["float"]
1919
x1 = np.random.randn(nopt).astype(dtype)
2020
y1 = np.random.randn(nopt).astype(dtype)
2121
z1 = np.random.randn(nopt).astype(dtype)

dpbench/benchmarks/kmeans/kmeans_initialize.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
def initialize(npoints, niters, seed, ndims, ncentroids):
6+
def initialize(npoints, niters, seed, ndims, ncentroids, types_dict):
77
import numpy as np
88
import numpy.random as default_rng
99

10-
dtype = np.float64
10+
f_dtype = types_dict["float"]
11+
i_dtype = types_dict["int"]
1112
XL = 1.0
1213
XH = 5.0
1314

1415
default_rng.seed(seed)
1516

16-
arrayP = default_rng.uniform(XL, XH, (npoints, ndims)).astype(dtype)
17-
arrayPclusters = np.ones(npoints, dtype=np.int64)
18-
arrayC = np.ones((ncentroids, ndims), dtype=dtype)
19-
arrayCsum = np.ones((ncentroids, ndims), dtype=dtype)
20-
arrayCnumpoint = np.ones(ncentroids, dtype=np.int64)
17+
arrayP = default_rng.uniform(XL, XH, (npoints, ndims)).astype(f_dtype)
18+
arrayPclusters = np.ones(npoints, dtype=i_dtype)
19+
arrayC = np.ones((ncentroids, ndims), dtype=f_dtype)
20+
arrayCsum = np.ones((ncentroids, ndims), dtype=f_dtype)
21+
arrayCnumpoint = np.ones(ncentroids, dtype=i_dtype)
2122

2223
return (arrayP, arrayPclusters, arrayC, arrayCsum, arrayCnumpoint)

dpbench/benchmarks/knn/knn_initialize.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55

66
def initialize(
7-
test_size, train_size, data_dim, classes_num, seed_test, seed_train
7+
test_size,
8+
train_size,
9+
data_dim,
10+
classes_num,
11+
seed_test,
12+
seed_train,
13+
types_dict,
814
):
915
import numpy as np
1016
import numpy.random as default_rng
1117

12-
dtype = np.float64
18+
dtype = types_dict["float"]
1319

1420
def _gen_data_x(ip_size, data_dim, seed, dtype):
1521
default_rng.seed(seed)
@@ -34,7 +40,7 @@ def _gen_test_data(test_size, data_dim, seed_test, dtype):
3440
train_size, data_dim, classes_num, seed_train, dtype
3541
)
3642
x_test = _gen_test_data(test_size, data_dim, seed_test, dtype)
37-
predictions = np.empty(test_size, np.int64)
43+
predictions = np.empty(test_size, types_dict["int"])
3844
votes_to_classes = np.zeros((test_size, classes_num))
3945

4046
return (x_train, y_train, x_test, predictions, votes_to_classes)

dpbench/benchmarks/l2_norm/l2_norm_initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
def initialize(npoints, dims, seed):
6+
def initialize(npoints, dims, seed, types_dict):
77
import numpy as np
88
import numpy.random as default_rng
99

10-
dtype = np.float64
10+
dtype = types_dict["float"]
1111

1212
default_rng.seed(seed)
1313

dpbench/benchmarks/pairwise_distance/pairwise_distance_initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
def initialize(npoints, dims, seed):
6+
def initialize(npoints, dims, seed, types_dict):
77
import numpy as np
88
import numpy.random as default_rng
99

10-
dtype = np.float64
10+
dtype = types_dict["float"]
1111

1212
default_rng.seed(seed)
1313

dpbench/benchmarks/rambo/rambo_initialize.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
def initialize(nevts, nout):
6+
def initialize(nevts, nout, types_dict):
77
import numpy as np
88

9-
C1 = np.empty((nevts, nout))
10-
F1 = np.empty((nevts, nout))
11-
Q1 = np.empty((nevts, nout))
9+
dtype = types_dict["float"]
10+
11+
C1 = np.empty((nevts, nout), dtype=dtype)
12+
F1 = np.empty((nevts, nout), dtype=dtype)
13+
Q1 = np.empty((nevts, nout), dtype=dtype)
1214

1315
np.random.seed(777)
1416
for i in range(nevts):

dpbench/config/benchmark.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Init:
1919
func_name: str = ""
2020
package_path: str = ""
2121
module_name: str = ""
22+
types_dict_name: str = ""
23+
precision: str = ""
2224
input_args: List[str] = field(default_factory=list)
2325
output_args: List[str] = field(default_factory=list)
2426

@@ -28,10 +30,18 @@ def from_dict(obj: Any) -> "Init":
2830
_func_name = str(obj.get("func_name") or "")
2931
_package_path = str(obj.get("package_path") or "")
3032
_module_name = str(obj.get("module_name") or "")
33+
_types_dict_name = str(obj.get("types_dict_name") or "")
34+
_precision = str(obj.get("precision") or "")
3135
_input_args = obj.get("input_args")
3236
_output_args = obj.get("output_args")
3337
return Init(
34-
_func_name, _package_path, _module_name, _input_args, _output_args
38+
_func_name,
39+
_package_path,
40+
_module_name,
41+
_types_dict_name,
42+
_precision,
43+
_input_args,
44+
_output_args,
3545
)
3646

3747
def __post_init__(self):

dpbench/config/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ class Config:
1818
frameworks: list[Framework]
1919
benchmarks: list[Benchmark]
2020
implementations: list[Implementation]
21+
dtypes: dict[str, dict[str, str]]

0 commit comments

Comments
 (0)