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
7 changes: 4 additions & 3 deletions examples/BabelStream/functor/babel_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import argparse
from functools import reduce
import sys
import numpy as np


@pk.functor
class KokkosStream:
def __init__(
self, ARRAY_SIZE: int, initA: float, initB: float, initC: float, scalar: float
):
self.a: pk.View1D[pk.double] = pk.View([ARRAY_SIZE], pk.double)
self.b: pk.View1D[pk.double] = pk.View([ARRAY_SIZE], pk.double)
self.c: pk.View1D[pk.double] = pk.View([ARRAY_SIZE], pk.double)
self.a = np.zeros(ARRAY_SIZE, dtype=np.float64)
self.b = np.zeros(ARRAY_SIZE, dtype=np.float64)
self.c = np.zeros(ARRAY_SIZE, dtype=np.float64)

self.initA: float = initA
self.initB: float = initB
Expand Down
9 changes: 5 additions & 4 deletions examples/BabelStream/workload/babel_stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pykokkos as pk
import numpy as np

import argparse
from functools import reduce
Expand All @@ -18,9 +19,9 @@ def __init__(
):
self.array_size: int = ARRAY_SIZE

self.a: pk.View1D[pk.double] = pk.View([ARRAY_SIZE], pk.double)
self.b: pk.View1D[pk.double] = pk.View([ARRAY_SIZE], pk.double)
self.c: pk.View1D[pk.double] = pk.View([ARRAY_SIZE], pk.double)
self.a = np.zeros([ARRAY_SIZE], dtype=np.float64)
self.b = np.zeros([ARRAY_SIZE], dtype=np.float64)
self.c = np.zeros([ARRAY_SIZE], dtype=np.float64)

self.initA: pk.double = initA
self.initB: pk.double = initB
Expand All @@ -30,7 +31,7 @@ def __init__(
self.sum: pk.double = 0

self.runtime: float = 0
self.runtimes: pk.View2D[pk.double] = pk.View([5, num_times], pk.double)
self.runtimes = np.zeros([5, num_times], dtype=np.float64)

@pk.main
def run(self):
Expand Down
33 changes: 21 additions & 12 deletions examples/ExaMiniMD/standalone/src/force_types/force_lj_cell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List
import numpy as np

import pykokkos as pk

Expand Down Expand Up @@ -37,24 +38,32 @@ def init_scalar(self, x_: int, y_: int, z_: int) -> t_scalar3:

@pk.workload
class ForceLJCell(Force):
class t_fparams(pk.View2D):
def __init__(self, x: int = 0, y: int = 0, data_type: pk.DataType = pk.double):
super().__init__(x, y, data_type)
@staticmethod
def t_fparams(x: int = 0, y: int = 0, data_type: pk.DataType = pk.double):
import numpy as np

if data_type == pk.double:
np_dtype = np.float64
elif data_type == pk.int32:
np_dtype = np.int32
else:
np_dtype = np.float64
return np.zeros([x, y], dtype=np_dtype)

def __init__(self, args: List[str], system: System, half_neigh: bool):
super().__init__(args, system, half_neigh)

self.lj1: pk.View2D[pk.double] = self.t_fparams(system.ntypes, system.ntypes)
self.lj2: pk.View2D[pk.double] = self.t_fparams(system.ntypes, system.ntypes)
self.cutsq: pk.View2D[pk.double] = self.t_fparams(system.ntypes, system.ntypes)
self.lj1 = self.t_fparams(system.ntypes, system.ntypes)
self.lj2 = self.t_fparams(system.ntypes, system.ntypes)
self.cutsq = self.t_fparams(system.ntypes, system.ntypes)

self.bin_offsets: pk.View3D[pk.int32] = pk.View([0, 0, 0], pk.int32)
self.bin_count: pk.View3D[pk.int32] = pk.View([0, 0, 0], pk.int32)
self.permute_vector: pk.View1D[pk.int32] = pk.View([0], pk.int32)
self.bin_offsets = np.zeros([0, 0, 0], dtype=np.int32)
self.bin_count = np.zeros([0, 0, 0], dtype=np.int32)
self.permute_vector = np.zeros([0], dtype=np.int32)

self.x: pk.View2D[pk.double] = pk.View([0, 0], pk.double)
self.type: pk.View1D[pk.int32] = pk.View([0], pk.int32)
self.f: pk.View2D[pk.double] = pk.View([0, 0], pk.double)
self.x = np.zeros([0, 0], dtype=np.float64)
self.type = np.zeros([0], dtype=np.int32)
self.f = np.zeros([0, 0], dtype=np.float64)

self.N_local: int = 0
self.nbinx: int = 0
Expand Down
110 changes: 61 additions & 49 deletions examples/ExaMiniMD/standalone/src/force_types/force_lj_neigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
@pk.workunit
def fullneigh_for(
i: int,
rnd_lj1: pk.View2D[float],
rnd_lj2: pk.View2D[float],
rnd_cutsq: pk.View2D[float],
num_neighs_view: pk.View1D[int],
neighs_view: pk.View2D[int],
x: pk.View2D[float],
f: pk.View2D[float],
type: pk.View1D[int],
rnd_lj1,
rnd_lj2,
rnd_cutsq,
num_neighs_view,
neighs_view,
x,
f,
type,
) -> None:
x_i: float = x[i][0]
y_i: float = x[i][1]
Expand Down Expand Up @@ -62,14 +62,14 @@ def fullneigh_for(
@pk.workunit
def halfneigh_for(
i: int,
rnd_lj1: pk.View2D[float],
rnd_lj2: pk.View2D[float],
rnd_cutsq: pk.View2D[float],
num_neighs_view: pk.View1D[int],
neighs_view: pk.View2D[int],
x: pk.View2D[float],
f: pk.View2D[float],
type: pk.View1D[int],
rnd_lj1,
rnd_lj2,
rnd_cutsq,
num_neighs_view,
neighs_view,
x,
f,
type,
use_stackparams: bool,
) -> None:
x_i: float = x[i][0]
Expand Down Expand Up @@ -135,14 +135,14 @@ def halfneigh_for(
def fullneigh_reduce(
i: int,
PE: pk.Acc[float],
rnd_lj1: pk.View2D[float],
rnd_lj2: pk.View2D[float],
rnd_cutsq: pk.View2D[float],
num_neighs_view: pk.View1D[int],
neighs_view: pk.View2D[int],
x: pk.View2D[float],
f: pk.View2D[float],
type: pk.View1D[int],
rnd_lj1,
rnd_lj2,
rnd_cutsq,
num_neighs_view,
neighs_view,
x,
f,
type,
use_stackparams: bool,
) -> None:
x_i: float = x[i][0]
Expand Down Expand Up @@ -195,15 +195,15 @@ def fullneigh_reduce(
def halfneigh_reduce(
i: int,
PE: pk.Acc[float],
rnd_lj1: pk.View2D[float],
rnd_lj2: pk.View2D[float],
rnd_cutsq: pk.View2D[float],
rnd_lj1,
rnd_lj2,
rnd_cutsq,
N_local: int,
num_neighs_view: pk.View1D[int],
neighs_view: pk.View2D[int],
x: pk.View2D[float],
f: pk.View2D[float],
type: pk.View1D[int],
num_neighs_view,
neighs_view,
x,
f,
type,
use_stackparams: bool,
) -> None:
x_i: float = x[i][0]
Expand Down Expand Up @@ -259,17 +259,29 @@ def halfneigh_reduce(


class ForceLJNeigh(Force):
class t_fparams(pk.View):
def __init__(
self, x: int = 0, y: int = 0, data_type: pk.DataTypeClass = pk.double
):
super().__init__([x, y], data_type)

class t_fparams_rnd(pk.View):
def __init__(
self, x: int = 0, y: int = 0, data_type: pk.DataTypeClass = pk.double
):
super().__init__([x, y], data_type)
@staticmethod
def t_fparams(x: int = 0, y: int = 0, data_type: pk.DataTypeClass = pk.double):
import numpy as np

if data_type == pk.double:
np_dtype = np.float64
elif data_type == pk.int32:
np_dtype = np.int32
else:
np_dtype = np.float64
return np.zeros([x, y], dtype=np_dtype)

@staticmethod
def t_fparams_rnd(x: int = 0, y: int = 0, data_type: pk.DataTypeClass = pk.double):
import numpy as np

if data_type == pk.double:
np_dtype = np.float64
elif data_type == pk.int32:
np_dtype = np.int32
else:
np_dtype = np.float64
return np.zeros([x, y], dtype=np_dtype)

def __init__(self, args: List[str], system: System, half_neigh: bool):
super().__init__(args, system, half_neigh)
Expand All @@ -280,18 +292,18 @@ def __init__(self, args: List[str], system: System, half_neigh: bool):
self.use_stackparams: bool = False
# self.use_stackparams: bool = self.ntypes <= MAX_TYPES_STACKPARAMS

self.lj1: pk.View2D[pk.double] = self.t_fparams()
self.lj2: pk.View2D[pk.double] = self.t_fparams()
self.cutsq: pk.View2D[pk.double] = self.t_fparams()
self.lj1 = self.t_fparams()
self.lj2 = self.t_fparams()
self.cutsq = self.t_fparams()

if not self.use_stackparams:
self.lj1 = self.t_fparams(self.ntypes, self.ntypes)
self.lj2 = self.t_fparams(self.ntypes, self.ntypes)
self.cutsq = self.t_fparams(self.ntypes, self.ntypes)

self.rnd_lj1: pk.View2D[pk.double] = self.t_fparams()
self.rnd_lj2: pk.View2D[pk.double] = self.t_fparams()
self.rnd_cutsq: pk.View2D[pk.double] = self.t_fparams()
self.rnd_lj1 = self.t_fparams()
self.rnd_lj2 = self.t_fparams()
self.rnd_cutsq = self.t_fparams()

self.step: int = 0

Expand Down
7 changes: 4 additions & 3 deletions examples/ParRes/standalone/nstream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pykokkos as pk
import numpy as np

import argparse
import sys
Expand Down Expand Up @@ -44,9 +45,9 @@ def run() -> None:
print("Vector length = ", length)
print("Offset = ", offset)

A: pk.View1D = pk.View([length], pk.double)
B: pk.View1D = pk.View([length], pk.double)
C: pk.View1D = pk.View([length], pk.double)
A = np.zeros([length], dtype=np.float64)
B = np.zeros([length], dtype=np.float64)
C = np.zeros([length], dtype=np.float64)

p = pk.RangePolicy(pk.ExecutionSpace.OpenMP, 0, length)

Expand Down
40 changes: 31 additions & 9 deletions examples/kokkos-benchmarks/functor/bytes_and_flops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,45 @@
from typing import Tuple

import pykokkos as pk
import numpy as np

try:
import cupy as cp

cupy_available = True
except ImportError:
cupy_available = False


def get_array_module(space: pk.ExecutionSpace):
"""Return numpy or cupy module based on execution space"""
if cupy_available and space in (pk.ExecutionSpace.Cuda, pk.ExecutionSpace.HIP):
return cp
return np


@pk.functor
# use double type and unroll=8
class Benchmark_double_8:
def __init__(self, N: int, K: int, R: int, D: int, F: int, T: int, S: int):
def __init__(
self,
N: int,
K: int,
R: int,
D: int,
F: int,
T: int,
S: int,
space: pk.ExecutionSpace,
):
self.K: int = K
self.R: int = R
self.F: int = F

self.A: pk.View3D[pk.double] = pk.View([N, K, D], pk.double)
self.B: pk.View3D[pk.double] = pk.View([N, K, D], pk.double)
self.C: pk.View3D[pk.double] = pk.View([N, K, D], pk.double)

self.A.fill(1.5)
self.B.fill(2.5)
self.C.fill(3.5)
xp = get_array_module(space)
self.A = xp.full((N, K, D), 1.5, dtype=np.float64)
self.B = xp.full((N, K, D), 2.5, dtype=np.float64)
self.C = xp.full((N, K, D), 3.5, dtype=np.float64)

@pk.workunit
def benchmark(self, team: pk.TeamMember):
Expand Down Expand Up @@ -111,7 +133,7 @@ def run() -> None:
pk.set_default_space(space)

r = pk.TeamPolicy(N, T)
w = Benchmark_double_8(N, K, R, args.D, F, T, S)
w = Benchmark_double_8(N, K, R, args.D, F, T, S, space)

timer = pk.Timer()
pk.parallel_for(r, w.benchmark)
Expand Down
Loading
Loading