+/pykokkos

git clone https://git.julia.blue/+/pykokkos

Joseph RyanAdd math functions and constantsd1c116e

master
778 B34 linesraw
1import pykokkos
2from pykokkos.views import View1D
3from pykokkos.workload import KokkosWorkload, work_unit
4
5import math
6
7
8class Math(KokkosWorkload):
9    def __init__(self, n):
10        self.N = n
11        self.a = View1D(n)
12
13        for i in range(self.N):
14            self.a[i] = math.sqrt(math.tau)
15
16        print("Initialized view:", self.a)
17
18    def run_work_units(self):
19        pykokkos.parallel_for(self.N, self.my_calculation)
20
21    def use_results(self):
22        print("Results: ", self.a)
23
24    @work_unit
25    def my_calculation(self, i):
26        pykokkos.printf("Running index %d\n", i)
27        self.a[i] += (
28            math.cos(self.a[i]) + 2 ** i - math.pi / math.fabs(self.a[(i + 1) % self.N])
29        )
30
31
32if __name__ == "__main__":
33    n = 10
34    Math(n).execute()