Skip to content

Commit aed4237

Browse files
committed
Merge branch 'main' into multi_gpu
2 parents 1539ae1 + b8694f5 commit aed4237

10 files changed

+209
-8
lines changed

.github/workflows/linux-ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: [3.6, 3.7, 3.8, 3.9, 'pypy-3.6', 'pypy-3.7']
17+
python-version: [3.7, 3.8, 3.9, 'pypy-3.6', 'pypy-3.7']
1818
kokkos-branch: ['master', 'develop']
1919

2020
steps:
@@ -82,7 +82,7 @@ jobs:
8282
runs-on: ubuntu-latest
8383
strategy:
8484
matrix:
85-
python-version: [3.6, 3.7, 3.8, 3.9, 'pypy-3.6', 'pypy-3.7']
85+
python-version: [3.7, 3.8, 3.9, 'pypy-3.6', 'pypy-3.7']
8686
kokkos-branch: ['master']
8787

8888
steps:
@@ -144,7 +144,7 @@ jobs:
144144
runs-on: ubuntu-latest
145145
strategy:
146146
matrix:
147-
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11.0-rc.1"]
147+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
148148
kokkos-branch: ['develop']
149149

150150
steps:
@@ -163,7 +163,7 @@ jobs:
163163
python -m pip install 'cmake==3.20.2'
164164

165165
- name: Install Kokkos
166-
if: ${{ matrix.python-version != '3.6' && matrix.python-version != '3.7' }}
166+
if: ${{ matrix.python-version != '3.7' }}
167167
run:
168168
git clone -b ${{ matrix.kokkos-branch }} https://github.com/kokkos/kokkos.git /tmp/kokkos-source &&
169169
cmake -B /tmp/kokkos-build

.github/workflows/python-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: [3.6, 3.7, 3.8, 3.9]
17+
python-version: [3.7, 3.8, 3.9]
1818

1919
steps:
2020
- uses: actions/checkout@v2

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ SET(libpykokkos_SOURCES
5656
${CMAKE_CURRENT_LIST_DIR}/src/enumeration.cpp
5757
${CMAKE_CURRENT_LIST_DIR}/src/available.cpp
5858
${CMAKE_CURRENT_LIST_DIR}/src/common.cpp
59-
${CMAKE_CURRENT_LIST_DIR}/src/tools.cpp)
59+
${CMAKE_CURRENT_LIST_DIR}/src/tools.cpp
60+
${CMAKE_CURRENT_LIST_DIR}/src/execution_spaces.cpp)
6061

6162
SET(libpykokkos_HEADERS
6263
${CMAKE_CURRENT_LIST_DIR}/include/libpykokkos.hpp
@@ -66,7 +67,8 @@ SET(libpykokkos_HEADERS
6667
${CMAKE_CURRENT_LIST_DIR}/include/common.hpp
6768
${CMAKE_CURRENT_LIST_DIR}/include/traits.hpp
6869
${CMAKE_CURRENT_LIST_DIR}/include/views.hpp
69-
${CMAKE_CURRENT_LIST_DIR}/include/fwd.hpp)
70+
${CMAKE_CURRENT_LIST_DIR}/include/fwd.hpp
71+
${CMAKE_CURRENT_LIST_DIR}/include/execution_spaces.hpp)
7072

7173
ADD_LIBRARY(libpykokkos-core OBJECT
7274
${libpykokkos_SOURCES}

examples/user.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Kokkos_Core.hpp"
55

66
#include <cstdint>
7+
#include <iostream>
78

89
struct InitView {
910
explicit InitView(view_type _v) : m_view(_v) {}

external/kokkos

Submodule kokkos updated 70 files

include/execution_spaces.hpp

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
//@HEADER
3+
// ************************************************************************
4+
//
5+
// Kokkos v. 3.0
6+
// Copyright (2020) National Technology & Engineering
7+
// Solutions of Sandia, LLC (NTESS).
8+
//
9+
// Under the terms of Contract DE-NA0003525 with NTESS,
10+
// the U.S. Government retains certain rights in this software.
11+
//
12+
// Redistribution and use in source and binary forms, with or without
13+
// modification, are permitted provided that the following conditions are
14+
// met:
15+
//
16+
// 1. Redistributions of source code must retain the above copyright
17+
// notice, this list of conditions and the following disclaimer.
18+
//
19+
// 2. Redistributions in binary form must reproduce the above copyright
20+
// notice, this list of conditions and the following disclaimer in the
21+
// documentation and/or other materials provided with the distribution.
22+
//
23+
// 3. Neither the name of the Corporation nor the names of the
24+
// contributors may be used to endorse or promote products derived from
25+
// this software without specific prior written permission.
26+
//
27+
// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
//
39+
// Questions? Contact Christian R. Trott ([email protected])
40+
//
41+
// ************************************************************************
42+
//@HEADER
43+
*/
44+
45+
#pragma once
46+
47+
#include "common.hpp"
48+
#include "concepts.hpp"
49+
#include "pools.hpp"
50+
#include "traits.hpp"
51+
52+
#include <Kokkos_Core.hpp>
53+
54+
namespace Common {
55+
template <typename Sp, size_t SpaceIdx>
56+
void generate_execution_space_init(py::class_<Sp> &,
57+
enable_if_t<SpaceIdx == Serial_Backend, int> = 0) {}
58+
59+
template <typename Sp, size_t SpaceIdx>
60+
void generate_execution_space_init(py::class_<Sp> &,
61+
enable_if_t<SpaceIdx == Threads_Backend, int> = 0) {}
62+
63+
template <typename Sp, size_t SpaceIdx>
64+
void generate_execution_space_init(py::class_<Sp> &,
65+
enable_if_t<SpaceIdx == OpenMP_Backend, int> = 0) {}
66+
67+
template <typename Sp, size_t SpaceIdx>
68+
void generate_execution_space_init(py::class_<Sp> &_space,
69+
enable_if_t<SpaceIdx == Cuda_Backend, int> = 0) {
70+
#if defined(KOKKOS_ENABLE_CUDA) && defined(__CUDACC__)
71+
_space.def(py::init([](uint64_t stream_ptr, bool manage_stream) {
72+
cudaStream_t s = reinterpret_cast<cudaStream_t>(stream_ptr);
73+
return new Sp{s, manage_stream};
74+
}));
75+
#endif
76+
}
77+
78+
template <typename Sp, size_t SpaceIdx>
79+
void generate_execution_space_init(py::class_<Sp> &_space,
80+
enable_if_t<SpaceIdx == HIP_Backend, int> = 0) {
81+
#if defined(KOKKOS_ENABLE_HIP) && defined(__HIPCC__)
82+
_space.def(py::init([](uint64_t stream_ptr, bool manage_stream) {
83+
hipStream_t s = reinterpret_cast<hipStream_t>(stream_ptr);
84+
return new Sp{s, manage_stream};
85+
}));
86+
#endif
87+
}
88+
89+
template <typename Sp, size_t SpaceIdx>
90+
void generate_execution_space(py::module &_mod, const std::string &_name,
91+
const std::string &_msg) {
92+
if (debug_output())
93+
std::cerr << "Registering " << _msg << " as python class '" << _name
94+
<< "'..." << std::endl;
95+
96+
py::class_<Sp> _space(_mod, _name.c_str());
97+
_space.def(py::init([]() { return new Sp{}; }));
98+
99+
// Add other constructors with arguments if they exist
100+
generate_execution_space_init<Sp, SpaceIdx>(_space);
101+
}
102+
} // namespace Common
103+
104+
namespace Space {
105+
namespace SpaceDim {
106+
107+
template <size_t SpaceIdx>
108+
void generate_execution_space(py::module &_mod) {
109+
using space_spec_t = ExecutionSpaceSpecialization<SpaceIdx>;
110+
using Sp = typename space_spec_t::type;
111+
112+
auto name = join("_", "KokkosExecutionSpace", space_spec_t::label());
113+
114+
Common::generate_execution_space<Sp, SpaceIdx>(_mod, name, demangle<Sp>());
115+
}
116+
} // namespace SpaceDim
117+
118+
template <size_t SpaceIdx>
119+
void generate_execution_space(
120+
py::module &,
121+
std::enable_if_t<!is_available<execution_space_t<SpaceIdx>>::value, int> =
122+
0) {}
123+
124+
template <size_t SpaceIdx>
125+
void generate_execution_space(
126+
py::module &_mod,
127+
std::enable_if_t<is_available<execution_space_t<SpaceIdx>>::value, int> =
128+
0) {
129+
SpaceDim::generate_execution_space<SpaceIdx>(_mod);
130+
}
131+
} // namespace Space
132+
133+
template <size_t... SpaceIdx>
134+
void generate_execution_spaces(py::module &_mod,
135+
std::index_sequence<SpaceIdx...>) {
136+
FOLD_EXPRESSION(Space::generate_execution_space<SpaceIdx>(_mod));
137+
}

include/libpykokkos.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ void generate_view_variants(py::module& kokkos);
5959
void generate_atomic_variants(py::module& kokkos);
6060
void generate_backend_versions(py::module& kokkos);
6161
void generate_pool_variants(py::module& kokkos);
62+
void generate_execution_spaces(py::module& kokkos);
6263
void destroy_callbacks();

include/views.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ void generate_view(py::module &_mod, const std::string &_name,
414414
"dynamic", [](ViewT &) { return Kokkos::is_dyn_rank_view<ViewT>::value; },
415415
"Whether the rank is dynamic");
416416

417+
_view.def_property_readonly(
418+
"cpp_type", [=](ViewT &) { return _msg; },
419+
"Underlying C++ type as string");
420+
417421
// support []
418422
generate_view_access<Tp>(_view, std::index_sequence<Idx...>{});
419423
}

src/execution_spaces.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
//@HEADER
3+
// ************************************************************************
4+
//
5+
// Kokkos v. 3.0
6+
// Copyright (2020) National Technology & Engineering
7+
// Solutions of Sandia, LLC (NTESS).
8+
//
9+
// Under the terms of Contract DE-NA0003525 with NTESS,
10+
// the U.S. Government retains certain rights in this software.
11+
//
12+
// Redistribution and use in source and binary forms, with or without
13+
// modification, are permitted provided that the following conditions are
14+
// met:
15+
//
16+
// 1. Redistributions of source code must retain the above copyright
17+
// notice, this list of conditions and the following disclaimer.
18+
//
19+
// 2. Redistributions in binary form must reproduce the above copyright
20+
// notice, this list of conditions and the following disclaimer in the
21+
// documentation and/or other materials provided with the distribution.
22+
//
23+
// 3. Neither the name of the Corporation nor the names of the
24+
// contributors may be used to endorse or promote products derived from
25+
// this software without specific prior written permission.
26+
//
27+
// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
//
39+
// Questions? Contact Christian R. Trott ([email protected])
40+
//
41+
// ************************************************************************
42+
//@HEADER
43+
*/
44+
45+
#include "execution_spaces.hpp"
46+
47+
#include "common.hpp"
48+
#include "defines.hpp"
49+
#include "fwd.hpp"
50+
#include "traits.hpp"
51+
52+
void generate_execution_spaces(py::module &kokkos) {
53+
generate_execution_spaces(kokkos,
54+
std::make_index_sequence<ExecutionSpacesEnd>{});
55+
}

src/libpykokkos.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,5 @@ PYBIND11_MODULE(libpykokkos, kokkos) {
116116
generate_atomic_variants(kokkos);
117117
generate_backend_versions(kokkos);
118118
generate_pool_variants(kokkos);
119+
generate_execution_spaces(kokkos);
119120
}

0 commit comments

Comments
 (0)