Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pyArborX


def run():
num_points = 100

radius = 2.0

# Type alias
ExecutionSpace = pyArborX.ExecutionSpace
Primitives = pyArborX.Kokkos_View_ArborX_Point_1D_Default
Point = pyArborX.Point
BVH = pyArborX.BVH

execution_space = ExecutionSpace()

primitives = Primitives("primitives", num_points)
for i in range(primitives.size()):
primitives[i] = Point(i, i, i)

queries = pyArborX.generateWithinQueries_device(
execution_space,
primitives,
num_points,
radius,
)
# execution_space.fence()

bvh = BVH(execution_space, primitives)

offsets = pyArborX.intView1D("offsets", 0)
indices = pyArborX.intView1D("indices", 0)

bvh.query(execution_space, queries, indices, offsets)

for i in range(offsets.size()-1):
print("[%d]" % i, end="")
for j in range(offsets[i], offsets[i+1]):
print(" %d" % indices[j], end="")
print("")

# As the Python garbage collector does not respect Kokkos finalize at this
# time, explicitly delete all ArborX structures
del bvh
del queries
del primitives
del indices
del offsets


if __name__ == "__main__":
pyArborX.initialize()
pyArborX.printConfig()
run()
pyArborX.finalize()
64 changes: 39 additions & 25 deletions static/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
project(pyArborX_static LANGUAGES CXX)

#choose modules that should be included in the build
# Choose modules to be included
set(pyArborX_STATIC_GEOMETRY_MODULES Point Box Sphere)
set(pyArborX_STATIC_UTILITY_MODULES Experimental)
set(pyArborX_STATIC_UTILITY_MODULES ExecutionSpace Experimental Util BVH)
set(pyArborX_HACKY_VIEWS_MODULES IntersectView intView1D)

# get source files for selected static modules
# Get source files for selected static modules
# NOTE: hacky views are in "config.hpp"
foreach(PY_MODULE IN LISTS pyArborX_STATIC_GEOMETRY_MODULES pyArborX_STATIC_UTILITY_MODULES)
list(APPEND pyArborX_SRC ${PROJECT_SOURCE_DIR}/src/pyArborX_${PY_MODULE}.cpp)
list(APPEND MODULE_INCLUDES "\n#include \"pyArborX_${PY_MODULE}.hpp\"" )
list(APPEND MODULE_GENERATORS "\npyArborX::generate${PY_MODULE}Wrapper(m)")
endforeach()

#generate bindings for views of ArborX types
set(LAYOUTS LayoutLeft LayoutRight)
set(MEMORYSPACES Default HostSpace)
#
# set(MEMORYSPACES Default HostSpace)
set(MEMORYSPACES Default)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/generated_files)

foreach(GEOMETRY IN LISTS pyArborX_STATIC_GEOMETRY_MODULES)
foreach(LAYOUT IN LISTS LAYOUTS)
foreach(MEMORYSPACE IN LISTS MEMORYSPACES)
set(VIEW_NAME "Kokkos_View_ArborX_${GEOMETRY}_1D_${LAYOUT}_${MEMORYSPACE}")
if (MEMORYSPACE STREQUAL Default)
set(VIEW_TYPE "Kokkos::View<ArborX::${GEOMETRY}*,Kokkos::${LAYOUT},Kokkos::${MEMORYSPACE}ExecutionSpace::memory_space>")
else()
set(VIEW_TYPE "Kokkos::View<ArborX::${GEOMETRY}*,Kokkos::${LAYOUT},Kokkos::${MEMORYSPACE}>")
endif()
set(VIEW_BASE_TYPE "ArborX::${GEOMETRY}")
set(VIEW_INCLUDE "\n#include \"pyArborX_${VIEW_NAME}.hpp\"")

configure_file(include/pyArborX_Views.hpp.in generated_files/pyArborX_${VIEW_NAME}.hpp)
configure_file(src/pyArborX_Views.cpp.in generated_files/pyArborX_${VIEW_NAME}.cpp)
list(APPEND pyArborX_SRC ${PROJECT_BINARY_DIR}/generated_files/pyArborX_${VIEW_NAME}.cpp)
list(APPEND MODULE_INCLUDES "\n#include \"pyArborX_${VIEW_NAME}.hpp\"" )
list(APPEND MODULE_GENERATORS "\npyArborX::generate${VIEW_NAME}Wrapper(m)")
endforeach()
foreach(MEMORYSPACE IN LISTS MEMORYSPACES)
set(VIEW_NAME "Kokkos_View_ArborX_${GEOMETRY}_1D_${MEMORYSPACE}")
if (MEMORYSPACE STREQUAL Default)
set(VIEW_TYPE "Kokkos::View<ArborX::${GEOMETRY}*,Kokkos::${MEMORYSPACE}ExecutionSpace::memory_space>")
else()
set(VIEW_TYPE "Kokkos::View<ArborX::${GEOMETRY}*,Kokkos::${MEMORYSPACE}>")
endif()
set(VIEW_BASE_TYPE "ArborX::${GEOMETRY}")
set(VIEW_INCLUDE "\n#include \"pyArborX_${VIEW_NAME}.hpp\"")

configure_file(include/pyArborX_Views.hpp.in generated_files/pyArborX_${VIEW_NAME}.hpp)
configure_file(src/pyArborX_Views.cpp.in generated_files/pyArborX_${VIEW_NAME}.cpp)
list(APPEND pyArborX_SRC ${PROJECT_BINARY_DIR}/generated_files/pyArborX_${VIEW_NAME}.cpp)
list(APPEND MODULE_INCLUDES "\n#include \"pyArborX_${VIEW_NAME}.hpp\"" )
list(APPEND MODULE_GENERATORS "\npyArborX::generate${VIEW_NAME}Wrapper(m)")
endforeach()
endforeach()
foreach(PY_VIEW IN LISTS pyArborX_HACKY_VIEWS_MODULES)
foreach(MEMORYSPACE IN LISTS MEMORYSPACES)
set(VIEW_NAME ${PY_VIEW})
set(VIEW_TYPE ${PY_VIEW}Type)
set(VIEW_BASE_TYPE ${PY_VIEW}BaseType)
set(VIEW_INCLUDE "\n#include \"pyArborX_${PY_VIEW}.hpp\"")

configure_file(include/pyArborX_Views.hpp.in generated_files/pyArborX_${PY_VIEW}.hpp)
configure_file(src/pyArborX_Views.cpp.in generated_files/pyArborX_${PY_VIEW}.cpp)

list(APPEND pyArborX_SRC ${PROJECT_BINARY_DIR}/generated_files/pyArborX_${VIEW_NAME}.cpp)
list(APPEND MODULE_INCLUDES "\n#include \"pyArborX_${VIEW_NAME}.hpp\"" )
list(APPEND MODULE_GENERATORS "\npyArborX::generate${VIEW_NAME}Wrapper(m)")
endforeach()
endforeach()

Expand All @@ -45,6 +59,6 @@ configure_file(pyArborX_static.cpp.in generated_files/pyArborX_static.cpp)
PYBIND11_ADD_MODULE(pyArborX_static generated_files/pyArborX_static.cpp ${pyArborX_SRC})
target_include_directories(pyArborX_static PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(pyArborX_static PUBLIC ${PROJECT_BINARY_DIR}/generated_files)
target_link_libraries(pyArborX_static PUBLIC ArborX::ArborX)
target_link_libraries(pyArborX_static PUBLIC ArborX::ArborX INTERFACE Kokkos::kokkos)
set_target_properties(pyArborX_static PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pyArborX)
36 changes: 36 additions & 0 deletions static/include/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef PYARBORX_CONFIG_H
#define PYARBORX_CONFIG_H

#include <ArborX_Point.hpp>
#include <ArborX_Predicates.hpp>
#include <ArborX_SpaceFillingCurves.hpp>
#include <ArborX_Sphere.hpp>

#include <Kokkos_Core.hpp>

namespace pyArborX
{

// instantiation of all template arguments by hand, as there is no interface for
// these ... for now
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = ExecutionSpace::memory_space;
// using MemorySpace = Kokkos::CudaUVMSpace;

using intView1DBaseType = int;
using intView1DType = Kokkos::View<int *, MemorySpace>;

using PointViewBaseType = ArborX::Point;
using PointViewType = Kokkos::View<PointViewBaseType *, MemorySpace>;

using IntersectViewBaseType = decltype(ArborX::intersects(ArborX::Sphere{}));
using IntersectViewType = Kokkos::View<IntersectViewBaseType *, MemorySpace>;

using Primitives = PointViewType;
using Predicates = IntersectViewType;

using SpaceFillingCurve = ArborX::Experimental::Morton64;

} // namespace pyArborX

#endif
16 changes: 16 additions & 0 deletions static/include/pyArborX_BVH.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef PYARBORX_BVH_HPP
#define PYARBORX_BVH_HPP

#include <ArborX_LinearBVH.hpp>

#include "config.hpp"
#include <pybind11/pybind11.h>

namespace pyArborX
{

void generateBVHWrapper(pybind11::module &m);

}

#endif
8 changes: 4 additions & 4 deletions static/include/pyArborX_Box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include <ArborX_Box.hpp>

#include <pybind11/pybind11.h>
#include <string.h>
#include <string>

namespace py = pybind11;
#include <pybind11/pybind11.h>

namespace pyArborX
{
Expand All @@ -15,7 +14,8 @@ namespace helper
std::string pyPrintBox(ArborX::Box const &b);
}

void generateBoxWrapper(py::module &m);
void generateBoxWrapper(pybind11::module &m);

} // namespace pyArborX

#endif
13 changes: 13 additions & 0 deletions static/include/pyArborX_ExecutionSpace.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef PYARBORX_EXECUTION_SPACE_HPP
#define PYARBORX_EXECUTION_SPACE_HPP

#include <pybind11/pybind11.h>

namespace pyArborX
{

void generateExecutionSpaceWrapper(pybind11::module &m);

}

#endif
5 changes: 2 additions & 3 deletions static/include/pyArborX_Experimental.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace pyArborX
{

void generateExperimentalWrapper(py::module &m);
void generateExperimentalWrapper(pybind11::module &m);

} // namespace pyArborX

#endif
7 changes: 3 additions & 4 deletions static/include/pyArborX_Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include <ArborX_Point.hpp>

#include <pybind11/pybind11.h>
#include <string.h>
#include <string>

namespace py = pybind11;
#include <pybind11/pybind11.h>

namespace pyArborX
{
Expand All @@ -15,7 +14,7 @@ namespace helper
std::string pyPrintPoint(ArborX::Point const &p);
}

void generatePointWrapper(py::module &m);
void generatePointWrapper(pybind11::module &m);
} // namespace pyArborX

#endif
7 changes: 3 additions & 4 deletions static/include/pyArborX_Sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include <ArborX_Sphere.hpp>

#include <pybind11/pybind11.h>
#include <string.h>
#include <string>

namespace py = pybind11;
#include <pybind11/pybind11.h>

namespace pyArborX
{
Expand All @@ -15,7 +14,7 @@ namespace helper
std::string pyPrintSphere(ArborX::Sphere const &s);
}

void generateSphereWrapper(py::module &m);
void generateSphereWrapper(pybind11::module &m);
} // namespace pyArborX

#endif
21 changes: 21 additions & 0 deletions static/include/pyArborX_Util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PYARBORX_UTIL_HPP
#define PYARBORX_UTIL_HPP

#include "config.hpp"
#include <pybind11/pybind11.h>

namespace pyArborX
{

namespace helper
{
Predicates generateWithinQueries_device(ExecutionSpace execution_space,
Primitives query_pts_view,
int n_queries, float radius);
}

void generateUtilWrapper(pybind11::module &m);

} // namespace pyArborX

#endif
4 changes: 1 addition & 3 deletions static/include/pyArborX_Views.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace pyArborX
{

void generate@VIEW_NAME@Wrapper(py::module & m);
void generate@VIEW_NAME@Wrapper(pybind11::module &m);

}
#endif
23 changes: 23 additions & 0 deletions static/include/pyArborX_Views_Util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef PYARBORX_VIEW_UTIL_HPP
#define PYARBORX_VIEW_UTIL_HPP

#include <Kokkos_Core.hpp>

namespace pyArborX
{

template <typename ViewType>
auto create_mirror_view(ViewType const &source)
{
return Kokkos::create_mirror_view(source);
}

template <typename ViewDest, typename ViewSrc>
auto deep_copy(ViewDest const &dest, ViewSrc const &src)
{
return Kokkos::deep_copy(dest, src);
}

} // namespace pyArborX

#endif
11 changes: 6 additions & 5 deletions static/pyArborX_static.cpp.in
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <Kokkos_Core.hpp>

#include <pybind11/pybind11.h>

@MODULE_INCLUDES@


namespace py = pybind11;

PYBIND11_MODULE(pyArborX_static, m) {
PYBIND11_MODULE(pyArborX_static, m)
{
m.attr("__name__") = "pyArborX_static";

m.def("initialize", []() { Kokkos::initialize(); });
m.def("printConfig", []() { Kokkos::print_configuration(std::cout); });
m.def("finalize", &Kokkos::finalize);

@MODULE_GENERATORS@;

}
Loading