Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions npbench/benchmarks/azimint_hist/azimint_hist.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import numpy as np


def initialize(N):
def initialize(N, datatype=np.float32):
from numpy.random import default_rng
rng = default_rng(42)
data, radius = rng.random((N, )), rng.random((N, ))
data, radius = rng.random((N, ), dtype=datatype), rng.random((N, ), dtype=datatype)
return data, radius
17 changes: 9 additions & 8 deletions npbench/benchmarks/azimint_hist/azimint_hist_dace.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@

import numpy as np
import dace as dc
from npbench.infrastructure.dace_framework import dc_float

N, bins, npt = (dc.symbol(s, dtype=dc.int64) for s in ('N', 'bins', 'npt'))


@dc.program
def get_bin_edges(a: dc.float64[N], bin_edges: dc.float64[bins + 1]):
def get_bin_edges(a: dc_float[N], bin_edges: dc_float[bins + 1]):
a_min = np.amin(a)
a_max = np.amax(a)
delta = (a_max - a_min) / bins
Expand All @@ -52,15 +53,15 @@ def get_bin_edges(a: dc.float64[N], bin_edges: dc.float64[bins + 1]):


@dc.program
def compute_bin(x: dc.float64, bin_edges: dc.float64[bins + 1]):
def compute_bin(x: dc_float, bin_edges: dc_float[bins + 1]):
# assuming uniform bins for now
a_min = bin_edges[0]
a_max = bin_edges[bins]
return dc.int64(bins * (x - a_min) / (a_max - a_min))


@dc.program
def histogram(a: dc.float64[N], bin_edges: dc.float64[bins + 1]):
def histogram(a: dc_float[N], bin_edges: dc_float[bins + 1]):
hist = np.ndarray((bins, ), dtype=np.int64)
hist[:] = 0
get_bin_edges(a, bin_edges)
Expand All @@ -73,8 +74,8 @@ def histogram(a: dc.float64[N], bin_edges: dc.float64[bins + 1]):


@dc.program
def histogram_weights(a: dc.float64[N], bin_edges: dc.float64[bins + 1],
weights: dc.float64[N]):
def histogram_weights(a: dc_float[N], bin_edges: dc_float[bins + 1],
weights: dc_float[N]):
hist = np.ndarray((bins, ), dtype=weights.dtype)
hist[:] = 0
get_bin_edges(a, bin_edges)
Expand All @@ -87,11 +88,11 @@ def histogram_weights(a: dc.float64[N], bin_edges: dc.float64[bins + 1],


@dc.program
def azimint_hist(data: dc.float64[N], radius: dc.float64[N]):
def azimint_hist(data: dc_float[N], radius: dc_float[N]):
# histu = np.histogram(radius, npt)[0]
bin_edges_u = np.ndarray((npt + 1, ), dtype=np.float64)
bin_edges_u = np.ndarray((npt + 1, ), dtype=dc_float)
histu = histogram(radius, bin_edges_u)
# histw = np.histogram(radius, npt, weights=data)[0]
bin_edges_w = np.ndarray((npt + 1, ), dtype=np.float64)
bin_edges_w = np.ndarray((npt + 1, ), dtype=dc_float)
histw = histogram_weights(radius, bin_edges_w, data)
return histw / histu
4 changes: 2 additions & 2 deletions npbench/benchmarks/azimint_naive/azimint_naive.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.


def initialize(N):
def initialize(N, datatype):
from numpy.random import default_rng
rng = default_rng(42)
data, radius = rng.random((N, )), rng.random((N, ))
data, radius = rng.random((N, ), dtype=datatype), rng.random((N, ), dtype=datatype)
return data, radius
7 changes: 4 additions & 3 deletions npbench/benchmarks/azimint_naive/azimint_naive_dace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

import numpy as np
import dace as dc
from npbench.infrastructure.dace_framework import dc_float

N, npt = (dc.symbol(s, dtype=dc.int64) for s in ('N', 'npt'))


@dc.program
def azimint_naive(data: dc.float64[N], radius: dc.float64[N]):
def azimint_naive(data: dc_float[N], radius: dc_float[N]):
# rmax = radius.max()
rmax = np.amax(radius)
res = np.zeros((npt, ), dtype=np.float64) # Fix in np.full
res = np.zeros((npt, ), dtype=dc_float) # Fix in np.full
for i in range(npt):
# for i in dc.map[0:npt]: # Optimization
r1 = rmax * i / npt
Expand All @@ -27,7 +28,7 @@ def azimint_naive(data: dc.float64[N], radius: dc.float64[N]):
# values_r12 = data[mask_r12]
# res[i] = np.mean(values_r12)
on_values = 0
tmp = np.float64(0)
tmp = dc_float(0)
for j in dc.map[0:N]:
if mask_r12[j]:
tmp += data[j]
Expand Down
8 changes: 4 additions & 4 deletions npbench/benchmarks/cavity_flow/cavity_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np


def initialize(ny, nx):
u = np.zeros((ny, nx), dtype=np.float64)
v = np.zeros((ny, nx), dtype=np.float64)
p = np.zeros((ny, nx), dtype=np.float64)
def initialize(ny, nx, datatype=np.float32):
u = np.zeros((ny, nx), dtype=datatype)
v = np.zeros((ny, nx), dtype=datatype)
p = np.zeros((ny, nx), dtype=datatype)
dx = 2 / (nx - 1)
dy = 2 / (ny - 1)
dt = .1 / ((nx - 1) * (ny - 1))
Expand Down
19 changes: 10 additions & 9 deletions npbench/benchmarks/cavity_flow/cavity_flow_dace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

import numpy as np
import dace as dc
from npbench.infrastructure.dace_framework import dc_float

nx, ny, nit = (dc.symbol(s, dc.int64) for s in ('nx', 'ny', 'nit'))


@dc.program
def build_up_b(b: dc.float64[ny, nx], rho: dc.float64, dt: dc.float64,
u: dc.float64[ny, nx], v: dc.float64[ny, nx], dx: dc.float64,
dy: dc.float64):
def build_up_b(b: dc_float[ny, nx], rho: dc_float, dt: dc_float,
u: dc_float[ny, nx], v: dc_float[ny, nx], dx: dc_float,
dy: dc_float):

b[1:-1,
1:-1] = (rho * (1 / dt * ((u[1:-1, 2:] - u[1:-1, 0:-2]) / (2 * dx) +
Expand All @@ -28,8 +29,8 @@ def build_up_b(b: dc.float64[ny, nx], rho: dc.float64, dt: dc.float64,


@dc.program
def pressure_poisson(p: dc.float64[ny, nx], dx: dc.float64, dy: dc.float64,
b: dc.float64[ny, nx]):
def pressure_poisson(p: dc_float[ny, nx], dx: dc_float, dy: dc_float,
b: dc_float[ny, nx]):
pn = np.empty_like(p)
pn[:] = p.copy()

Expand All @@ -47,10 +48,10 @@ def pressure_poisson(p: dc.float64[ny, nx], dx: dc.float64, dy: dc.float64,


@dc.program
def cavity_flow(nt: dc.int64, nit: dc.int64, u: dc.float64[ny, nx],
v: dc.float64[ny, nx], dt: dc.float64, dx: dc.float64,
dy: dc.float64, p: dc.float64[ny, nx], rho: dc.float64,
nu: dc.float64):
def cavity_flow(nt: dc.int64, nit: dc.int64, u: dc_float[ny, nx],
v: dc_float[ny, nx], dt: dc_float, dx: dc_float,
dy: dc_float, p: dc_float[ny, nx], rho: dc_float,
nu: dc_float):
un = np.empty_like(u)
vn = np.empty_like(v)
b = np.zeros((ny, nx))
Expand Down
14 changes: 7 additions & 7 deletions npbench/benchmarks/channel_flow/channel_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import numpy as np


def initialize(ny, nx):
u = np.zeros((ny, nx), dtype=np.float64)
v = np.zeros((ny, nx), dtype=np.float64)
p = np.ones((ny, nx), dtype=np.float64)
dx = 2 / (nx - 1)
dy = 2 / (ny - 1)
dt = .1 / ((nx - 1) * (ny - 1))
def initialize(ny, nx, datatype=np.float32):
u = np.zeros((ny, nx), dtype=datatype)
v = np.zeros((ny, nx), dtype=datatype)
p = np.ones((ny, nx), dtype=datatype)
dx = datatype(2 / (nx - 1))
dy = datatype(2 / (ny - 1))
dt = datatype(.1 / ((nx - 1) * (ny - 1)))
return u, v, p, dx, dy, dt
17 changes: 9 additions & 8 deletions npbench/benchmarks/channel_flow/channel_flow_dace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

import numpy as np
import dace as dc
from npbench.infrastructure.dace_framework import dc_float

nx, ny, nit = (dc.symbol(s, dc.int64) for s in ('nx', 'ny', 'nit'))


@dc.program
def build_up_b(rho: dc.float64, dt: dc.float64, dx: dc.float64, dy: dc.float64,
u: dc.float64[ny, nx], v: dc.float64[ny, nx]):
def build_up_b(rho: dc_float, dt: dc_float, dx: dc_float, dy: dc_float,
u: dc_float[ny, nx], v: dc_float[ny, nx]):
b = np.zeros_like(u)
b[1:-1,
1:-1] = (rho * (1 / dt * ((u[1:-1, 2:] - u[1:-1, 0:-2]) / (2 * dx) +
Expand Down Expand Up @@ -45,8 +46,8 @@ def build_up_b(rho: dc.float64, dt: dc.float64, dx: dc.float64, dy: dc.float64,


@dc.program
def pressure_poisson_periodic(p: dc.float64[ny, nx], dx: dc.float64,
dy: dc.float64, b: dc.float64[ny, nx]):
def pressure_poisson_periodic(p: dc_float[ny, nx], dx: dc_float,
dy: dc_float, b: dc_float[ny, nx]):
pn = np.empty_like(p)

for q in range(nit):
Expand Down Expand Up @@ -74,10 +75,10 @@ def pressure_poisson_periodic(p: dc.float64[ny, nx], dx: dc.float64,


@dc.program
def channel_flow(nit: dc.int64, u: dc.float64[ny, nx], v: dc.float64[ny, nx],
dt: dc.float64, dx: dc.float64, dy: dc.float64,
p: dc.float64[ny, nx], rho: dc.float64, nu: dc.float64,
F: dc.float64):
def channel_flow(nit: dc.int64, u: dc_float[ny, nx], v: dc_float[ny, nx],
dt: dc_float, dx: dc_float, dy: dc_float,
p: dc_float[ny, nx], rho: dc_float, nu: dc_float,
F: dc_float):
udiff = 1.0
stepcount = 0

Expand Down
3 changes: 2 additions & 1 deletion npbench/benchmarks/compute/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import numpy as np


def initialize(M, N):
def initialize(M, N, datatype):
from numpy.random import default_rng
rng = default_rng(42)
# we ignore the datatype and always use int64
array_1 = rng.uniform(0, 1000, size=(M, N)).astype(np.int64)
array_2 = rng.uniform(0, 1000, size=(M, N)).astype(np.int64)
a = np.int64(4)
Expand Down
12 changes: 6 additions & 6 deletions npbench/benchmarks/contour_integral/contour_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import numpy as np


def rng_complex(shape, rng):
return (rng.random(shape) + rng.random(shape) * 1j)
def rng_complex(shape, rng, datatype):
return (rng.random(shape, dtype=datatype) + rng.random(shape, dtype=datatype) * 1j)


def initialize(NR, NM, slab_per_bc, num_int_pts):
def initialize(NR, NM, slab_per_bc, num_int_pts, datatype=np.float32):
from numpy.random import default_rng
rng = default_rng(42)
Ham = rng_complex((slab_per_bc + 1, NR, NR), rng)
int_pts = rng_complex((num_int_pts, ), rng)
Y = rng_complex((NR, NM), rng)
Ham = rng_complex((slab_per_bc + 1, NR, NR), rng, datatype)
int_pts = rng_complex((num_int_pts, ), rng, datatype)
Y = rng_complex((NR, NM), rng, datatype)
return Ham, int_pts, Y
12 changes: 7 additions & 5 deletions npbench/benchmarks/contour_integral/contour_integral_dace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import numpy as np
import dace as dc

from npbench.infrastructure.dace_framework import dc_complex_float

NR, NM, slab_per_bc = (dc.symbol(s, dtype=dc.int64)
for s in ('NR', 'NM', 'slab_per_bc'))


@dc.program
def contour_integral(Ham: dc.complex128[slab_per_bc + 1, NR, NR],
int_pts: dc.complex128[32], Y: dc.complex128[NR, NM]):
P0 = np.zeros((NR, NM), dtype=np.complex128)
P1 = np.zeros((NR, NM), dtype=np.complex128)
def contour_integral(Ham: dc_complex_float[slab_per_bc + 1, NR, NR],
int_pts: dc_complex_float[32], Y: dc_complex_float[NR, NM]):
P0 = np.zeros((NR, NM), dtype=dc_complex_float)
P1 = np.zeros((NR, NM), dtype=dc_complex_float)
for idx in range(32):
z = int_pts[idx]
Tz = np.zeros((NR, NR), dtype=np.complex128)
Tz = np.zeros((NR, NR), dtype=dc_complex_float)
for n in range(slab_per_bc + 1):
zz = np.power(z, slab_per_bc / 2 - n)
Tz += zz * Ham[n]
Expand Down
2 changes: 1 addition & 1 deletion npbench/benchmarks/crc16/crc16.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np


def initialize(N):
def initialize(N, datatype):
from numpy.random import default_rng
rng = default_rng(42)
data = rng.integers(0, 256, size=(N, ), dtype=np.uint8)
Expand Down
8 changes: 4 additions & 4 deletions npbench/benchmarks/deep_learning/conv2d_bias/conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import numpy as np


def initialize(C_in, C_out, H, K, N, W):
def initialize(C_in, C_out, H, K, N, W, datatype=np.float32):
from numpy.random import default_rng
rng = default_rng(42)
# NHWC data layout
input = rng.random((N, H, W, C_in), dtype=np.float32)
input = rng.random((N, H, W, C_in), dtype=datatype)
# Weights
weights = rng.random((K, K, C_in, C_out), dtype=np.float32)
bias = rng.random((C_out, ), dtype=np.float32)
weights = rng.random((K, K, C_in, C_out), dtype=datatype)
bias = rng.random((C_out, ), dtype=datatype)
return input, weights, bias
11 changes: 6 additions & 5 deletions npbench/benchmarks/deep_learning/conv2d_bias/conv2d_dace.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import numpy as np
import dace as dc
from npbench.infrastructure.dace_framework import dc_float

C_in, C_out, H, K, N, W = (dc.symbol(s, dc.int64)
for s in ('C_in', 'C_out', 'H', 'K', 'N', 'W'))


# Deep learning convolutional operator (stride = 1)
@dc.program
def conv2d(input: dc.float32[N, H, W, C_in], weights: dc.float32[K, K, C_in,
def conv2d(input: dc_float[N, H, W, C_in], weights: dc_float[K, K, C_in,
C_out]):
# K = weights.shape[0] # Assuming square kernel
# N = input.shape[0]
# H_out = input.shape[1] - K + 1
# W_out = input.shape[2] - K + 1
# C_out = weights.shape[3]
# output = np.empty((N, H_out, W_out, C_out), dtype=np.float32)
output = np.ndarray((N, H - K + 1, W - K + 1, C_out), dtype=np.float32)
output = np.ndarray((N, H - K + 1, W - K + 1, C_out), dtype=dc_float)

# Loop structure adapted from https://github.com/SkalskiP/ILearnDeepLearning.py/blob/ba0b5ba589d4e656141995e8d1a06d44db6ce58d/01_mysteries_of_neural_networks/06_numpy_convolutional_neural_net/src/layers/convolutional.py#L88
# for i, j in dc.map[0:H-K+1, 0:W-K+1]:
Expand All @@ -31,7 +32,7 @@ def conv2d(input: dc.float32[N, H, W, C_in], weights: dc.float32[K, K, C_in,


@dc.program
def conv2d_bias(input: dc.float32[N, H, W, C_in],
weights: dc.float32[K, K, C_in,
C_out], bias: dc.float32[C_out]):
def conv2d_bias(input: dc_float[N, H, W, C_in],
weights: dc_float[K, K, C_in,
C_out], bias: dc_float[C_out]):
return conv2d(input, weights) + bias
24 changes: 12 additions & 12 deletions npbench/benchmarks/deep_learning/lenet/lenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np


def initialize(N, H, W):
def initialize(N, H, W, datatype=np.float32):
from numpy.random import default_rng
rng = default_rng(42)

Expand All @@ -18,18 +18,18 @@ def initialize(N, H, W):
C_before_fc1 = 16 * H_pool2 * W_pool2

# NHWC data layout
input = rng.random((N, H, W, 1), dtype=np.float32)
input = rng.random((N, H, W, 1), dtype=datatype)
# Weights
conv1 = rng.random((5, 5, 1, 6), dtype=np.float32)
conv1bias = rng.random((6, ), dtype=np.float32)
conv2 = rng.random((5, 5, 6, 16), dtype=np.float32)
conv2bias = rng.random((16, ), dtype=np.float32)
fc1w = rng.random((C_before_fc1, 120), dtype=np.float32)
fc1b = rng.random((120, ), dtype=np.float32)
fc2w = rng.random((120, 84), dtype=np.float32)
fc2b = rng.random((84, ), dtype=np.float32)
fc3w = rng.random((84, 10), dtype=np.float32)
fc3b = rng.random((10, ), dtype=np.float32)
conv1 = rng.random((5, 5, 1, 6), dtype=datatype)
conv1bias = rng.random((6, ), dtype=datatype)
conv2 = rng.random((5, 5, 6, 16), dtype=datatype)
conv2bias = rng.random((16, ), dtype=datatype)
fc1w = rng.random((C_before_fc1, 120), dtype=datatype)
fc1b = rng.random((120, ), dtype=datatype)
fc2w = rng.random((120, 84), dtype=datatype)
fc2b = rng.random((84, ), dtype=datatype)
fc3w = rng.random((84, 10), dtype=datatype)
fc3b = rng.random((10, ), dtype=datatype)

return (input, conv1, conv1bias, conv2, conv2bias, fc1w, fc1b, fc2w, fc2b,
fc3w, fc3b, C_before_fc1)
Loading