1
1
# pykokkos-base
2
2
3
+ This package contains the minimal set of bindings for [ Kokkos] ( https://github.com/kokkos/kokkos )
4
+ interoperability with Python:
5
+
6
+ - ` Kokkos::initialize(...) `
7
+ - ` Kokkos::finalize() `
8
+ - ` Kokkos::View<...> `
9
+ - ` Kokkos::DynRankView<...> `
10
+
11
+ By importing this package in Python, you can pass the supported Kokkos Views and DynRankViews
12
+ from C++ to Python and vice-versa. Furthermore, in Python, these bindings provide interoperability
13
+ with numpy and cupy arrays:
14
+
15
+ ``` python
16
+ import kokkos
17
+ import numpy as np
18
+
19
+ view = kokkos.view([2 , 2 ], dtype = kokkos.double, space = kokkos.CudaUVMSpace,
20
+ layout = Kokkos.LayoutRight, trait = kokkos.RandomAccess,
21
+ dynamic = False )
22
+
23
+ arr = np.array(view, copy = False )
24
+ ```
25
+
26
+ > This package depends on a pre-existing installation of Kokkos
27
+
28
+ ## Writing Kokkos in Python
29
+
30
+ In order to write native Kokkos in Python, see [ pykokkos] ( https://github.com/kokkos/pykokkos ) .
31
+
32
+ ## Installation
33
+
34
+ You can install this package via CMake or Python's ` setup.py ` . There are two important cmake options:
35
+
36
+ - ` ENABLE_LAYOUTS `
37
+ - ` ENABLE_MEMORY_TRAITS `
38
+
39
+ By default, CMake will enable these options if the Kokkos installation was not built with CUDA support.
40
+ If Kokkos was built with CUDA support, these options will be disabled by default due to unreasonable
41
+ compilation times (> 1 hour).
42
+
43
+ ### Configuring Options via CMake
44
+
45
+ ``` console
46
+ cmake -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF /path/to/source`
47
+ ```
48
+
49
+ ### Configuring Options via ` setup.py `
50
+
51
+ There are three ways to configure the options:
52
+
53
+ 1 . Via the Python argparse options ` --enable-<option> ` and ` --disable-<option> `
54
+ 2 . Setting the ` PYKOKKOS_BASE_SETUP_ARGS ` environment variable to the CMake options
55
+ 3 . Passing in the CMake options after a ` -- `
56
+
57
+ All three lines below are equivalent:
58
+
59
+ ``` console
60
+ python setup.py install --enable-layouts --disable-memory-traits
61
+ PYKOKKOS_BASE_SETUP_ARGS="-DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF" python setup.py install
62
+ python setup.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF
63
+ ```
64
+
65
+ ### Configuring Options via ` pip `
66
+
67
+ Pip does not handle build options well. Thus, it is recommended to use the ` PYKOKKOS_BASE_SETUP_ARGS `
68
+ environment variable noted above. However, using the ` --install-option ` for pip is possible but
69
+ each "space" must have it's own ` --install-option ` , e.g. all of the following are equivalent:
70
+ All three lines below are equivalent:
71
+
72
+ ``` console
73
+ pip install pykokkos-base --install-option=--enable-layouts --install-option=--disable-memory-traits
74
+ pip install pykokkos-base --install-option=-- --install-option=-DENABLE_LAYOUTS=ON --install-option=-DENABLE_MEMORY_TRAITS=OFF
75
+ pip install pykokkos-base --install-option={--enable-layouts,--disable-memory-traits}
76
+ pip install pykokkos-base --install-option={--,-DENABLE_LAYOUTS=ON,-DENABLE_MEMORY_TRAITS=OFF}
77
+ ```
78
+
79
+ > ` pip install pykokkos-base ` will build against the latest release in the PyPi repository.
80
+ > In order to pip install from this repository, use ` pip install --user -e . `
81
+
3
82
## Example
4
83
5
84
### Overview
@@ -17,7 +96,7 @@ This example is designed to emulate a work-flow where the user has code using Ko
17
96
- This is the implementation of the user's code which returns a ` Kokkos::View<double**, Kokkos::HostSpace> `
18
97
- [ ex-numpy.py] ( https://github.com/kokkos/kokkos-python/blob/main/examples/ex-numpy.py )
19
98
- This is the "main"
20
-
99
+
21
100
#### ex-numpy.py
22
101
23
102
``` python
0 commit comments