+/pykokkos

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

Joseph RyanRework function call translation3b7b538

master
919 B37 linesraw
1import pykokkos
2from pykokkos.views import View2D
3from pykokkos.workload import KokkosWorkload, work_unit
4
5
6class MatrixSum(KokkosWorkload):
7    def __init__(self, r, c):
8        self.r = r
9        self.c = c
10        self.mat = View2D(r, c)
11
12        for i in range(r):
13            self.mat[i] = list(range(c * i, c * (i + 1)))
14
15        for row in self.mat:
16            print(row)
17        print(f"Initialized {r}x{c} array")
18
19    def run_work_units(self):
20        pykokkos.parallel_for(self.r, self.sum_row)
21        self.total = pykokkos.parallel_reduce(self.r, self.final_sum)
22
23    def use_results(self):
24        print("Total =", self.total)
25
26    @work_unit
27    def sum_row(self, i):
28        for j in range(1, self.c):
29            self.mat[i][0] += self.mat[i][j]
30
31    @work_unit
32    def final_sum(self, i, accumulator):
33        accumulator += self.mat[i][0]
34
35
36if __name__ == "__main__":
37    MatrixSum(5, 10).execute()