Skip to content

Commit

Permalink
Split up compilation units + added functions to query build capabilit…
Browse files Browse the repository at this point in the history
…ies (#14)

- kokkos.get_layout_available(<string|index>)
- kokkos.get_memory_space_available(<string|index>)
- kokkos.get_memory_trait_available(<string|index>)
  • Loading branch information
jrmadsen authored May 12, 2021
1 parent 4fe4421 commit 441849c
Show file tree
Hide file tree
Showing 15 changed files with 1,382 additions and 923 deletions.
19 changes: 16 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,22 @@ IF(ENABLE_THIN_LTO)
SET(PYBIND11_EXTRAS THIN_LTO)
ENDIF()

PYBIND11_ADD_MODULE(libpykokkos MODULE ${PYBIND11_EXTRAS}
SET(libpykokkos_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/libpykokkos.cpp
${CMAKE_CURRENT_LIST_DIR}/include/libpykokkos.hpp)
${CMAKE_CURRENT_LIST_DIR}/src/concrete_view.cpp
${CMAKE_CURRENT_LIST_DIR}/src/dynamic_view.cpp
${CMAKE_CURRENT_LIST_DIR}/src/enumeration.cpp
${CMAKE_CURRENT_LIST_DIR}/src/available.cpp)

SET(libpykokkos_HEADERS
${CMAKE_CURRENT_LIST_DIR}/include/libpykokkos.hpp
${CMAKE_CURRENT_LIST_DIR}/include/common.hpp
${CMAKE_CURRENT_LIST_DIR}/include/traits.hpp
${CMAKE_CURRENT_LIST_DIR}/include/views.hpp)

PYBIND11_ADD_MODULE(libpykokkos MODULE ${PYBIND11_EXTRAS}
${libpykokkos_SOURCES}
${libpykokkos_HEADERS})

# add extra build properties to this target
ADD_LIBRARY(libpykokkos-build-options INTERFACE)
Expand Down Expand Up @@ -150,7 +163,7 @@ FOREACH(_FILE ${PYPACKAGE_FILES})
ENDFOREACH()

# build the examples, not designed to be built stand-alone
IF(BUILD_EXAMPLES)
IF(ENABLE_EXAMPLES)
ADD_SUBDIRECTORY(examples)
ENDIF()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ if __name__ == "__main__":
```console
mkdir build
cd build
cmake -DBUILD_EXAMPLES=ON ..
cmake -DENABLE_EXAMPLES=ON ..
make
python ./ex-numpy.py
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.3
0.0.4
8 changes: 6 additions & 2 deletions cmake/Modules/KokkosPythonOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
ENDIF()

# backwards compat
SET(BUILD_EXAMPLES OFF CACHE BOOL "(deprecated) Use ENABLE_EXAMPLES")
MARK_AS_ADVANCED(BUILD_EXAMPLES)
IF(NOT DEFINED ENABLE_EXAMPLES)
SET(BUILD_EXAMPLES OFF CACHE BOOL "(deprecated) Use ENABLE_EXAMPLES")
MARK_AS_ADVANCED(BUILD_EXAMPLES)
ELSE()
SET(BUILD_EXAMPLES ${ENABLE_EXAMPLES})
ENDIF()

# default to ENABLE_ALL=ON
SET(_ENABLE_ALL_DEFAULT ON)
Expand Down
7 changes: 7 additions & 0 deletions cmake/Modules/KokkosPythonPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ INCLUDE(KokkosPythonUtilities)

# basically just used to get Python3_SITEARCH for installation
FIND_PACKAGE(Python3 REQUIRED COMPONENTS Interpreter Development)
IF(NOT PYTHON_VERSION_STRING)
IF(PYTHON_VERSION_MAJOR AND PYTHON_VERSION_MINOR AND PYTHON_VERSION_PATCH)
SET(PYTHON_VERSION_STRING "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}" CACHE STRING "Python version" FORCE)
ELSEIF(PYTHON_VERSION_MAJOR AND PYTHON_VERSION_MINOR)
SET(PYTHON_VERSION_STRING "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" CACHE STRING "Python version" FORCE)
ENDIF()
ENDIF()
SET(PYBIND11_PYTHON_VERSION "${PYTHON_VERSION_STRING}" CACHE STRING "Python version" FORCE)
ADD_FEATURE(PYBIND11_PYTHON_VERSION "Python version used by PyBind11")
ADD_FEATURE(PYTHON_VERSION_STRING "Python version found")
Expand Down
128 changes: 128 additions & 0 deletions include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 3.0
// Copyright (2020) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott ([email protected])
//
// ************************************************************************
//@HEADER
*/

#pragma once

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

namespace py = pybind11;

#include <array>
#include <cstdint>
#include <cstdio>
#include <initializer_list>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <typeinfo>

#if defined(ENABLE_DEMANGLE)
#include <cxxabi.h>
#endif

//--------------------------------------------------------------------------------------//

template <bool B, typename T = int>
using enable_if_t = typename std::enable_if<B, T>::type;

//--------------------------------------------------------------------------------------//

#define FOLD_EXPRESSION(...) \
::consume_parameters(::std::initializer_list<int>{(__VA_ARGS__, 0)...})

//--------------------------------------------------------------------------------------//

template <typename... Args>
void consume_parameters(Args &&...) {}

//--------------------------------------------------------------------------------------//

inline std::string demangle(const char *_cstr) {
#if defined(ENABLE_DEMANGLE)
// demangling a string when delimiting
int _ret = 0;
char *_demang = abi::__cxa_demangle(_cstr, 0, 0, &_ret);
if (_demang && _ret == 0)
return std::string(const_cast<const char *>(_demang));
else
return _cstr;
#else
return _cstr;
#endif
}

//--------------------------------------------------------------------------------------//

inline std::string demangle(const std::string &_str) {
return demangle(_str.c_str());
}

//--------------------------------------------------------------------------------------//

template <typename Tp>
inline std::string demangle() {
return demangle(typeid(Tp).name());
}

//--------------------------------------------------------------------------------------//
// this is used to mark memory spaces as unavailable
//
template <typename Tp>
struct is_available : std::true_type {};

#define DISABLE_TYPE(TYPE) \
template <> \
struct is_available<TYPE> : std::false_type {};
Loading

0 comments on commit 441849c

Please sign in to comment.