Skip to content

Kdtree #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: executor-integration
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,19 @@ set(kissfft_srcs
src/fft/kiss_fftr.c
)

set(executor_incs
include/pcl/experimental/executor/type_trait.h
include/pcl/experimental/executor/property.h
include/pcl/experimental/executor/executor.h
)

set(executor_srcs
include/pcl/experimental/executor/blocking.cpp
)

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${kissfft_srcs} ${incs} ${common_incs} ${impl_incs} ${tools_incs} ${kissfft_incs} ${common_incs_impl} ${range_image_incs} ${range_image_incs_impl})
PCL_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${kissfft_srcs} ${executor_srcs} ${incs} ${common_incs} ${impl_incs} ${tools_incs} ${kissfft_incs} ${common_incs_impl} ${range_image_incs} ${range_image_incs_impl} ${executor_incs})

if(MSVC AND NOT (MSVC_VERSION LESS 1915))
# MSVC resolved a byte alignment issue in compiler version 15.9
Expand All @@ -193,3 +203,4 @@ PCL_ADD_INCLUDES("${SUBSYS_NAME}" impl ${impl_incs})
PCL_ADD_INCLUDES("${SUBSYS_NAME}" console ${tools_incs})
PCL_ADD_INCLUDES("${SUBSYS_NAME}" range_image ${range_image_incs})
PCL_ADD_INCLUDES("${SUBSYS_NAME}" range_image/impl ${range_image_incs_impl})
PCL_ADD_INCLUDES("${SUBSYS_NAME}" execution ${executor_incs})
15 changes: 15 additions & 0 deletions common/include/pcl/experimental/executor/blocking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author(s): Shrijit Singh <[email protected]>
*
*/
#include <pcl/experimental/executor/property.h>

namespace executor {
constexpr blocking_t::possibly_t blocking_t::possibly;
constexpr blocking_t::always_t blocking_t::always;
constexpr blocking_t::never_t blocking_t::never;
} // namespace executor
17 changes: 17 additions & 0 deletions common/include/pcl/experimental/executor/default/base_executor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#include <pcl/experimental/executor/property.h>

#include <array>
#include <pcl/experimental/executor/trait/is_executor_available.hpp>
#include <pcl/experimental/executor/trait/is_instance_of_base.hpp>
#include <string>
93 changes: 93 additions & 0 deletions common/include/pcl/experimental/executor/default/cuda_executor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#ifdef CUDA
#include <cuda_runtime_api.h>
#endif

#include <pcl/experimental/executor/default/base_executor.hpp>
#include <pcl/experimental/executor/default/inline_executor.hpp>

namespace executor {

#ifdef CUDA
template <typename F>
__global__ void global_kernel(F f) {
f();
}
#endif

template <typename Blocking, typename ProtoAllocator>
struct cuda_executor;

#ifdef CUDA
template <>
struct is_executor_available<cuda_executor> : std::true_type {};
#endif

template <typename Blocking = blocking_t::always_t,
typename ProtoAllocator = std::allocator<void>>
struct cuda_executor {
using shape_type = typename std::array<int, 6>;

template <typename Executor, instance_of_base<cuda_executor, Executor> = 0>
friend bool operator==(const cuda_executor& lhs,
const Executor& rhs) noexcept {
return std::is_same<cuda_executor, Executor>::value;
}

template <typename Executor, instance_of_base<cuda_executor, Executor> = 0>
friend bool operator!=(const cuda_executor& lhs,
const Executor& rhs) noexcept {
return !operator==(lhs, rhs);
}

template <typename F>
void execute(F& f) const {
#ifdef CUDA
void* global_kernel_args[] = {static_cast<void*>(&f)};
cudaLaunchKernel(reinterpret_cast<void*>(global_kernel<F>), 1, 1,
global_kernel_args, 0, nullptr);
cudaDeviceSynchronize();
#endif
}

// Temporary fix for unit test compilation
template <typename F>
void bulk_execute(F& f, std::size_t n) const {
bulk_execute(f, std::array<int, 6>{1, 1, 1, static_cast<int>(n), 1, 1});
}

// Passing rvalue reference of function doesn't currently work with CUDA for
// some reason
template <typename F>
void bulk_execute(F& f, shape_type shape) const {
#ifdef CUDA
void* global_kernel_args[] = {static_cast<void*>(&f)};
dim3 grid_size(shape[0], shape[1], shape[2]);
dim3 block_size(shape[3], shape[4], shape[5]);
cudaLaunchKernel(reinterpret_cast<void*>(global_kernel<F>), grid_size,
block_size, global_kernel_args, 0, nullptr);
cudaDeviceSynchronize();
#endif
}

static constexpr auto query(blocking_t) noexcept { return Blocking{}; }

cuda_executor<blocking_t::always_t, ProtoAllocator> require(
const blocking_t::always_t&) const {
return {};
}

static constexpr auto name() { return "cuda"; }
};

} // namespace executor
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#include <pcl/experimental/executor/default/base_executor.hpp>

namespace executor {

template <typename Blocking, typename ProtoAllocator>
struct inline_executor;

template <>
struct is_executor_available<inline_executor> : std::true_type {};

template <typename Blocking = blocking_t::always_t,
typename ProtoAllocator = std::allocator<void>>
struct inline_executor {
using shape_type = std::size_t;

template <typename Executor, instance_of_base<inline_executor, Executor> = 0>
friend bool operator==(const inline_executor& lhs,
const Executor& rhs) noexcept {
return std::is_same<inline_executor, Executor>::value;
}

template <typename Executor, instance_of_base<inline_executor, Executor> = 0>
friend bool operator!=(const inline_executor& lhs,
const Executor& rhs) noexcept {
return !operator==(lhs, rhs);
}

template <typename F>
void execute(F&& f) const {
f();
}

template <typename F, typename... Args>
void bulk_execute(F&& f, Args&&... args, std::size_t n) const {
for (std::size_t i = 0; i < n; ++i) {
f(std::forward<Args>(args)..., i);
}
}

static constexpr auto query(blocking_t) noexcept { return Blocking{}; }

inline_executor<blocking_t::always_t, ProtoAllocator> require(
const blocking_t::always_t&) const {
return {};
}

static constexpr auto name() { return "inline"; }
};

} // namespace executor
68 changes: 68 additions & 0 deletions common/include/pcl/experimental/executor/default/omp_executor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#ifdef _OPENMP
#include <omp.h>
#endif

#include <pcl/experimental/executor/default/base_executor.hpp>

namespace executor {

template <typename Blocking, typename ProtoAllocator>
struct omp_executor;

#ifdef _OPENMP
template <>
struct is_executor_available<omp_executor> : std::true_type {};
#endif

template <typename Blocking = blocking_t::always_t,
typename ProtoAllocator = std::allocator<void>>
struct omp_executor {
using shape_type = std::size_t;

template <typename Executor, instance_of_base<omp_executor, Executor> = 0>
friend bool operator==(const omp_executor& lhs,
const Executor& rhs) noexcept {
return std::is_same<omp_executor, Executor>::value;
}

template <typename Executor, instance_of_base<omp_executor, Executor> = 0>
friend bool operator!=(const omp_executor& lhs,
const Executor& rhs) noexcept {
return !operator==(lhs, rhs);
}

template <typename F>
void execute(F&& f) const {
std::forward<F>(f)();
}

template <typename F>
void bulk_execute(F&& f, shape_type n) const {
#ifdef _OPENMP
#pragma omp parallel for num_threads(n)
for (int i = 0; i < n; ++i) std::forward<F>(f)(omp_get_thread_num());
#endif
}

static constexpr auto query(blocking_t) noexcept { return Blocking{}; }

omp_executor<blocking_t::always_t, ProtoAllocator> require(
const blocking_t::always_t&) const {
return {};
}

static constexpr auto name() { return "omp"; }
};

} // namespace executor
64 changes: 64 additions & 0 deletions common/include/pcl/experimental/executor/default/sse_executor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#include <pcl/experimental/executor/default/base_executor.hpp>

namespace executor {

template <typename Blocking, typename ProtoAllocator>
struct sse_executor;

#ifdef __SSE__
template <>
struct is_executor_available<sse_executor> : std::true_type {};
#endif

template <typename Blocking = blocking_t::always_t,
typename ProtoAllocator = std::allocator<void>>
struct sse_executor {
using shape_type = std::size_t;

template <typename Executor, instance_of_base<sse_executor, Executor> = 0>
friend bool operator==(const sse_executor& lhs,
const Executor& rhs) noexcept {
return std::is_same<sse_executor, Executor>::value;
}

template <typename Executor, instance_of_base<sse_executor, Executor> = 0>
friend bool operator!=(const sse_executor& lhs,
const Executor& rhs) noexcept {
return !operator==(lhs, rhs);
}

template <typename F>
void execute(F&& f) const {
std::forward<F>(f)();
}

template <typename F>
void bulk_execute(F&& f, shape_type n) const {
#pragma simd
for (std::size_t i = 0; i < n; ++i) {
std::forward<F>(f)(i);
}
}

static constexpr auto query(blocking_t) noexcept { return Blocking{}; }

sse_executor<blocking_t::always_t, ProtoAllocator> require(
const blocking_t::always_t&) const {
return {};
}

static constexpr auto name() { return "sse"; }
};

} // namespace executor
22 changes: 22 additions & 0 deletions common/include/pcl/experimental/executor/executor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#include <pcl/experimental/executor/default/cuda_executor.hpp>
#include <pcl/experimental/executor/default/inline_executor.hpp>
#include <pcl/experimental/executor/default/omp_executor.hpp>
#include <pcl/experimental/executor/default/sse_executor.hpp>
#include <pcl/experimental/executor/trait/can_prefer.hpp>
#include <pcl/experimental/executor/trait/can_query.hpp>
#include <pcl/experimental/executor/trait/can_require.hpp>

namespace executor {
using best_fit = executor::inline_executor<>;
}
14 changes: 14 additions & 0 deletions common/include/pcl/experimental/executor/property.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Author: Shrijit Singh <[email protected]>
*
*/

#pragma once

#include <pcl/experimental/executor/property/allocator.hpp>
#include <pcl/experimental/executor/property/blocking.hpp>
#include <pcl/experimental/executor/property/shape.hpp>
Loading