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 a synchronous mapping API #2704

Merged
merged 5 commits into from Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 24 additions & 7 deletions CMakeLists.txt
Expand Up @@ -915,7 +915,7 @@ endif()
################################################################################
# Set basic search paths for HPX
################################################################################
include_directories("${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
include_directories("${PROJECT_SOURCE_DIR}")
link_directories(${CMAKE_BINARY_DIR}/lib)

################################################################################
Expand Down Expand Up @@ -1546,6 +1546,28 @@ hpx_add_config_define(HPX_HAVE_GIT_COMMIT "\"${HPX_WITH_GIT_COMMIT}\"")
hpx_include(SetOutputPaths)
##############################################################################

################################################################################
# Provide a macro for generating config headers
################################################################################
macro(generate_config_defines_header TARGET_DIRECTORY)
# Generate a defines.hpp to be used in the build directory ...
set(HPX_DEFINES_PREFIX ${HPX_BUILD_PREFIX})
write_config_defines_file(
TEMPLATE "${PROJECT_SOURCE_DIR}/cmake/templates/config_defines.hpp.in"
NAMESPACE default
FILENAME "${TARGET_DIRECTORY}/hpx/config/defines.hpp")
endmacro()

###############################################################################
# Perform the on framework CXX feature tests
###############################################################################
hpx_perform_on_framework_cxx_feature_tests()

################################################################################
# Set basic search paths for the generated HPX headers
################################################################################
include_directories("${CMAKE_BINARY_DIR}")

################################################################################
# Configure compression and other plugins
################################################################################
Expand Down Expand Up @@ -1633,12 +1655,7 @@ add_plugin_modules()
################################################################################
# Configure the header to include all compile definitions
################################################################################
# Generate a defines.hpp to be used in the build directory ...
set(HPX_DEFINES_PREFIX ${HPX_BUILD_PREFIX})
write_config_defines_file(
TEMPLATE "${PROJECT_SOURCE_DIR}/cmake/templates/config_defines.hpp.in"
NAMESPACE default
FILENAME "${CMAKE_BINARY_DIR}/hpx/config/defines.hpp")
generate_config_defines_header(${CMAKE_BINARY_DIR})

# Generate a defines.hpp to be used in the install directory ...
set(HPX_DEFINES_PREFIX ${HPX_PREFIX})
Expand Down
69 changes: 64 additions & 5 deletions cmake/HPX_AddConfigTest.cmake
@@ -1,5 +1,6 @@
# Copyright (c) 2014 Thomas Heller
# Copyright (c) 2011 Bryce Lelbach
# Copyright (c) 2014 Thomas Heller
# Copyright (c) 2017 Denis Blank
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -47,7 +48,7 @@ macro(add_hpx_config_test variable)
set(COMPILE_DEFINITIONS_TMP)
set(CONFIG_TEST_COMPILE_DEFINITIONS)
get_directory_property(COMPILE_DEFINITIONS_TMP COMPILE_DEFINITIONS)
foreach(def ${COMPILE_DEFINITIONS_TMP})
foreach(def IN LISTS COMPILE_DEFINITIONS_TMP ${variable}_COMPILE_DEFINITIONS)
set(CONFIG_TEST_COMPILE_DEFINITIONS "${CONFIG_TEST_COMPILE_DEFINITIONS} -D${def}")
endforeach()
get_property(HPX_TARGET_COMPILE_OPTIONS_VAR GLOBAL PROPERTY HPX_TARGET_COMPILE_OPTIONS)
Expand All @@ -57,10 +58,9 @@ macro(add_hpx_config_test variable)
endif()
endforeach()

set(CONFIG_TEST_INCLUDE_DIRS ${CONFIG_TEST_INCLUDE_DIRS} ${${variable}_INCLUDE_DIRS})
set(CONFIG_TEST_LINK_DIRS ${CONFIG_TEST_LINK_DIRS} ${${variable}_LINK_DIRS})
set(CONFIG_TEST_INCLUDE_DIRS ${CONFIG_TEST_INCLUDE_DIRS} ${${variable}_INCLUDE_DIRECTORIES})
set(CONFIG_TEST_LINK_DIRS ${CONFIG_TEST_LINK_DIRS} ${${variable}_LINK_DIRECTORIES})

set(CONFIG_TEST_COMPILE_DEFINITIONS ${CONFIG_TEST_COMPILE_DEFINITIONS} ${${variable}_COMPILE_DEFINITIONS})
set(CONFIG_TEST_LINK_LIBRARIES ${HPX_LIBRARIES} ${${variable}_LIBRARIES})

if(${variable}_EXECUTE)
Expand Down Expand Up @@ -128,6 +128,58 @@ macro(add_hpx_config_test variable)
endif()
endmacro()

# Makes it possible to provide a feature test that is able to
# test the compiler to build parts of HPX directly when the given definition
# is defined.
macro(add_hpx_in_framework_config_test variable)
# Generate the config only if the test wasn't executed yet
if(NOT DEFINED ${variable})
# Location to generate the config headers to
set(${variable}_GENERATED_DIR
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/config_tests/header-${variable}")
generate_config_defines_header(${${variable}_GENERATED_DIR})
endif()

set(options)
set(one_value_args)
set(multi_value_args DEFINITIONS INCLUDE_DIRECTORIES COMPILE_DEFINITIONS)
cmake_parse_arguments(${variable} "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

# We call the generic feature test method while modifying some
# existing parsed arguments in order to alter the INCLUDE_DIRECTORIES
# and the COMPILE_DEFINITIONS.
# It's important here not to link the config test against an executable
# because otherwise this will result in unresolved references to the
# HPX library, that wasn't built as of now.
add_hpx_config_test(${variable}
${${variable}_UNPARSED_ARGUMENTS}
DEFINITIONS
${${variable}_DEFINITIONS}
COMPILE_DEFINITIONS
${${variable}_COMPILE_DEFINITIONS}
# We add the definitions we test to the
# existing compile definitions.
${${variable}_DEFINITIONS}
# Add HPX_NO_VERSION_CHECK to make header only
# parts of HPX available without requiring to link
# against the HPX sources.
# We can remove this workaround as soon as CMake 3.6
# is the minimal required version and supports:
# CMAKE_TRY_COMPILE_TARGET_TYPE = STATIC_LIBRARY
# when using try_compile to not to throw errors
# on unresolved symbols.
HPX_NO_VERSION_CHECK
INCLUDE_DIRECTORIES
${${variable}_INCLUDE_DIRECTORIES}
# We add the generated headers to the include dirs
${${variable}_GENERATED_DIR})

if(DEFINED ${variable}_GENERATED_DIR)
# Cleanup the generated header
file(REMOVE_RECURSE "${${variable}_GENERATED_DIR}")
endif()
endmacro()

###############################################################################
macro(hpx_cpuid target variable)
add_hpx_config_test(${variable}
Expand Down Expand Up @@ -182,6 +234,13 @@ macro(hpx_check_for_cxx11_sfinae_expression)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_sfinae_expression_complete)
add_hpx_in_framework_config_test(HPX_HAVE_CXX11_SFINAE_EXPRESSION_COMPLETE
SOURCE cmake/tests/cxx11_sfinae_expression_complete.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_defaulted_functions)
add_hpx_config_test(HPX_WITH_CXX11_DEFAULTED_FUNCTIONS
Expand Down
11 changes: 11 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Expand Up @@ -171,3 +171,14 @@ macro(hpx_perform_cxx_feature_tests)
endif()
endmacro()

################################################################################
# C++ feature tests which require 3. party libraries
# and a present config file to work.
#
# This tests are meant for testing the compiler on the capability
# to compile parts of HPX directly without relying on generic feature tests.
################################################################################
macro(hpx_perform_on_framework_cxx_feature_tests)
hpx_check_for_cxx11_sfinae_expression_complete(
DEFINITIONS HPX_HAVE_CXX11_SFINAE_EXPRESSION_COMPLETE)
endmacro()
46 changes: 46 additions & 0 deletions cmake/tests/cxx11_sfinae_expression_complete.cpp
@@ -0,0 +1,46 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 Denis Blank
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#include <hpx/util/pack_traversal.hpp>

#include <type_traits>
#include <utility>
#include <vector>

struct all_map_float
{
template <typename T>
float operator()(T el) const
{
return float(el + 1.f);
}
};

int main(int, char**)
{
auto res = hpx::util::map_pack(all_map_float{},
0,
1.f,
hpx::util::make_tuple(1.f, 3),
std::vector<std::vector<int>>{{1, 2}, {4, 5}},
std::vector<std::vector<float>>{{1.f, 2.f}, {4.f, 5.f}},
2);

auto expected = hpx::util::make_tuple( // ...
1.f,
2.f,
hpx::util::make_tuple(2.f, 4.f),
std::vector<std::vector<float>>{{2.f, 3.f}, {5.f, 6.f}},
std::vector<std::vector<float>>{{2.f, 3.f}, {5.f, 6.f}},
3.f);

static_assert(std::is_same<decltype(res), decltype(expected)>::value,
"Type mismatch!");

(void) res;
(void) expected;
}
1 change: 1 addition & 0 deletions docs/CMakeLists.txt
Expand Up @@ -180,6 +180,7 @@ set(doxygen_dependencies
"${PROJECT_SOURCE_DIR}/hpx/traits/is_execution_policy.hpp"
"${PROJECT_SOURCE_DIR}/hpx/util/invoke.hpp"
"${PROJECT_SOURCE_DIR}/hpx/util/invoke_fused.hpp"
"${PROJECT_SOURCE_DIR}/hpx/util/pack_traversal.hpp"
"${PROJECT_SOURCE_DIR}/hpx/util/unwrapped.hpp"
"${PROJECT_SOURCE_DIR}/hpx/performance_counters/manage_counter_type.hpp")

Expand Down
4 changes: 4 additions & 0 deletions docs/hpx.idx
Expand Up @@ -531,6 +531,10 @@ invoke_r "" "header\.hpx\.util\.invoke_r.*"
invoke_fused "" "header\.hpx\.util\.invoke_fused.*"
invoke_fused_r "" "header\.hpx\.util\.invoke_fused_r.*"

# hpx/util/pack_traversal.hpp
map_pack "" "header\.hpx\.util\.pack_traversal.*"
traverse_pack "" "header\.hpx\.util\.pack_traversal.*"

# hpx/util/unwrapped.hpp
unwrapped "" "header\.hpx\.util\.unwrapped.*"
unwrapped2 "" "header\.hpx\.util\.unwrapped2.*"
Expand Down