Skip to content
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

Add omp and inline executor support for functor filter #4371

Open
wants to merge 3 commits into
base: master
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
2 changes: 1 addition & 1 deletion .dev/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

format() {
# don't use a directory with whitespace
local whitelist="apps/3d_rec_framework apps/modeler 2d ml octree simulation stereo tracking"
local whitelist="apps/3d_rec_framework apps/modeler common/include/pcl/experimental 2d ml octree simulation stereo tracking"

local PCL_DIR="${2}"
local formatter="${1}"
Expand Down
39 changes: 38 additions & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ set(common_incs
include/pcl/common/point_tests.h
include/pcl/common/synchronizer.h
include/pcl/common/utils.h
include/pcl/common/tuple.h
include/pcl/common/geometry.h
include/pcl/common/gaussian.h
include/pcl/common/spring.h
Expand Down Expand Up @@ -171,9 +172,42 @@ set(kissfft_srcs
src/fft/kiss_fftr.c
)

set(executor_incs
include/pcl/experimental/executor/executor.h
include/pcl/experimental/executor/property.h
include/pcl/experimental/executor/type_trait.h
include/pcl/experimental/executor/cuda_executor.hpp
include/pcl/experimental/executor/omp_executor.hpp
include/pcl/experimental/executor/inline_executor.hpp
include/pcl/experimental/executor/sse_executor.hpp
include/pcl/experimental/executor/best_fit.hpp
)

set(executor_property_incs_impl
include/pcl/experimental/executor/property/base_property.hpp
include/pcl/experimental/executor/property/allocator.hpp
include/pcl/experimental/executor/property/blocking.hpp
)

set(executor_trait_incs_impl
include/pcl/experimental/executor/trait/common_traits.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
include/pcl/experimental/executor/trait/is_executor.hpp
include/pcl/experimental/executor/trait/is_executor_available.hpp
include/pcl/experimental/executor/trait/index.hpp
include/pcl/experimental/executor/trait/shape.hpp
)


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})

if(MSVC AND NOT (MSVC_VERSION LESS 1915))
# MSVC resolved a byte alignment issue in compiler version 15.9
Expand All @@ -193,3 +227,6 @@ 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}" experimental/executor ${executor_incs})
PCL_ADD_INCLUDES("${SUBSYS_NAME}" experimental/executor/property ${executor_property_incs_impl})
PCL_ADD_INCLUDES("${SUBSYS_NAME}" experimental/executor/trait ${executor_trait_incs_impl})
151 changes: 151 additions & 0 deletions common/include/pcl/common/tuple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2020-, Open Perception, Inc.
*
*/

#pragma once

#include <pcl/type_traits.h>

#include <type_traits>
#include <tuple>

namespace pcl {

namespace detail {
template <typename Tuple, typename Function>
void
for_each_until_true(
Tuple&&,
Function,
std::integral_constant<
std::size_t,
std::tuple_size<typename std::remove_reference<Tuple>::type>::value>)
{}

template <
typename Tuple,
typename Function,
std::size_t I,
typename = typename std::enable_if<
I != std::tuple_size<typename std::remove_reference<Tuple>::type>::value>::type>
void
for_each_until_true(Tuple&& t, Function f, std::integral_constant<size_t, I>)
{
bool exit = f(std::get<I>(std::forward<Tuple>(t)));

if (!exit)
for_each_until_true(
std::forward<Tuple>(t), f, std::integral_constant<size_t, I + 1>());
}
} // namespace detail

/**
* \brief Iterates over all elements of tuples until the function called returns true
*
* \tparam Tuple The tuple to iterate through
* \tparam Function A callable that is invoked for every tuple element and returns a
* boolean indicating whether to continue iteration or not
*
* \remark Implementation taken from
* https://stackoverflow.com/questions/26902633/how-to-iterate-over-a-stdtuple-in-c-11
*/
template <typename Tuple, typename Function>
void
for_each_until_true(Tuple&& t, Function f)
{
detail::for_each_until_true(std::forward<Tuple>(t), f, std::integral_constant<size_t, 0>());
}

namespace detail {

template <typename T, typename Tuple>
struct tuple_contains_type_impl;

template <typename T, typename... Us>
struct tuple_contains_type_impl<T, std::tuple<Us...>>
: pcl::disjunction<std::is_same<T, Us>...> {};

} // namespace detail

/**
* \brief If the \Tuple contains the type \p T then provides the member constant value
* equal true. For any other type, value is false.
* *
* \tparam T a type to check
* \tparam Tuple a tuple in which to check for the type
*
*/
template <typename T, typename Tuple>
using tuple_contains_type = detail::tuple_contains_type_impl<T, Tuple>;

template <typename T, typename Tuple>
constexpr bool tuple_contains_type_v = detail::tuple_contains_type_impl<T, Tuple>::value;

static_assert(tuple_contains_type_v<int, std::tuple<int, float, double, unsigned>>,
"Failed to check type in tuple");

namespace detail {

template <template <typename...> class Predicate, typename... TupleElements>
struct filter_tuple_values_impl {
using type = decltype(std::tuple_cat(
typename std::conditional<Predicate<TupleElements>::value, std::tuple<TupleElements>, std::tuple<>>::
type()...));

/**
* \brief Checks whether a tuple contains a specified type
*
* \tparam TupleElements the elements of the tuple you want to filter
* \param std::tuple<TupleElements...> a tuple of the elements you want to filter
* \return a tuple containing the filtered elements
*
*/
auto
operator()(const std::tuple<TupleElements...>& in)
{
return (*this)(in, type{});
}

private:
// Utility function to fetch the types we're interest in outputting
template <typename... To>
auto
operator()(const std::tuple<TupleElements...>& in, std::tuple<To...>)
{
return std::make_tuple(std::get<To>(in)...);
}
};

} // namespace detail

/**
* \brief Filters elements of \p Tuple based on the provided predicate/condition
*
* \tparam Predicate A trait which takes a tuple element as parameter and defines a
* static boolean member \p value which dictates whether to filter the tuple element or not
* \tparam Tuple a tuple to filter
*
*/
template <template <typename...> class Predicate, typename Tuple>
struct filter_tuple_values;

template <template <typename...> class Predicate, typename... TupleElements>
struct filter_tuple_values<Predicate, std::tuple<TupleElements...>>
: detail::filter_tuple_values_impl<Predicate, TupleElements...> {};

template <template <typename...> class Predicate, typename... TupleElements>
struct filter_tuple_values<Predicate, const std::tuple<TupleElements...>>
: detail::filter_tuple_values_impl<Predicate, TupleElements...> {};

static_assert(
std::is_same<
std::tuple<float, double>,
filter_tuple_values<std::is_floating_point,
std::tuple<int, float, double, unsigned>>::type>::value,
"Filtered types do not match");

} // namespace pcl
Loading