Skip to content

Commit

Permalink
Add Stdexec to the build system
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorostsa committed Feb 8, 2024
1 parent 9c53b99 commit 1798cbc
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 1 deletion.
48 changes: 47 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,49 @@ if(HPX_WITH_CUDA AND HPX_WITH_HIP)
)
endif()

# ##
# HPX STDEXEC configuration
# ##

hpx_option(
HPX_WITH_STDEXEC
BOOL
"Use STDEXEC executors instead of native HPX.(default: OFF)"
OFF
CATEGORY "Executor"
ADVANCED
)

hpx_option(
HPX_WITH_FETCH_STDEXEC
BOOL
"Use FetchContent to fetch STDEXEC.(default: OFF)"
OFF
CATEGORY "Executor"
ADVANCED
)

# if STDEXEC_ROOT was provided, HPX_WITH_STDEXEC is set to ON
if(STDEXEC_ROOT OR HPX_WITH_FETCH_STDEXEC)
set(HPX_WITH_STDEXEC ON)

hpx_add_config_define(HPX_HAVE_STDEXEC)
elseif(HPX_WITH_STDEXEC)
hpx_error(
"HPX_WITH_STDEXEC is set to ON, but STDEXEC_ROOT is not provided. Please provide STDEXEC_ROOT or set HPX_WITH_FETCH_STDEXEC to ON."
)
endif()

if(HPX_WITH_STDEXEC)
# need cxx20 and over
if(HPX_WITH_CXX_STANDARD LESS 20)
hpx_error(
"HPX_WITH_STDEXEC is set to ON, but HPX_WITH_CXX_STANDARD is less than 20. Please set HPX_WITH_CXX_STANDARD to 20 or higher."
)
endif()
hpx_info("STDEXEC is enabled.")
endif()

# ##############################################################################
# HPX SYCL configuration
# ##############################################################################
Expand Down Expand Up @@ -1308,7 +1351,7 @@ if(HPX_WITH_NETWORKING AND HPX_WITH_PARCELPORT_LCI)
endif()
endif()

# External libraries/frameworks used by sme of the examples and benchmarks
# External libraries/frameworks used by some of the examples and benchmarks
hpx_option(
HPX_WITH_EXAMPLES_OPENMP BOOL
"Enable examples requiring OpenMP support (default: OFF)." OFF
Expand Down Expand Up @@ -2228,6 +2271,9 @@ if(HPX_WITH_CUDA OR HPX_WITH_HIP)
hpx_add_config_define(HPX_HAVE_GPU_SUPPORT)
endif()

# Setup NVIDIA's stdexec if requested
include(HPX_SetupStdexec)

if(HPX_WITH_SANITIZERS)
hpx_add_config_define(HPX_HAVE_SANITIZERS)
endif()
Expand Down
36 changes: 36 additions & 0 deletions cmake/FindStdexec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

if(NOT TARGET STDEXEC::stdexec)
if (STDEXEC_ROOT AND NOT Stdexec_ROOT)
set(Stdexec_ROOT ${STDEXEC_ROOT} CACHE PATH "stdexec base directory")
unset(STDEXEC_ROOT CACHE)
endif()

find_path(
Stdexec_INCLUDE_DIR
stdexec
HINTS ${Stdexec_ROOT}
)

if (Stdexec_INCLUDE_DIR)
file(TO_CMAKE_PATH ${Stdexec_INCLUDE_DIR} Stdexec_INCLUDE_DIR)
else()
message(FATAL_ERROR "stdexec not found")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Stdexec
REQUIRED_VARS Stdexec_INCLUDE_DIR
FOUND_VAR Stdexec_FOUND
VERSION_VAR Stdexec_VERSION
FAIL_MESSAGE "stdexec not found"
)

add_library(STDEXEC::stdexec INTERFACE IMPORTED)
target_include_directories(STDEXEC::stdexec SYSTEM INTERFACE ${Stdexec_INCLUDE_DIR})




mark_as_advanced(Stdexec_INCLUDE_DIR Stdexec_ROOT)
endif()
34 changes: 34 additions & 0 deletions cmake/HPX_SetupStdexec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if(STDEXEC_ROOT AND NOT Stdexec_ROOT)
set(Stdexec_ROOT
${STDEXEC_ROOT}
CACHE PATH "STDEXEC base directory"
)
unset(STDEXEC_ROOT CACHE)
endif()

if(HPX_WITH_FETCH_STDEXEC AND NOT Stdexec_ROOT)
hpx_info(
"HPX_WITH_FETCH_STDEXEC=${HPX_WITH_FETCH_STDEXEC}, Stdexec will be fetched using CMake's FetchContent."
)
if(UNIX)
include(FetchContent)
FetchContent_Declare(
Stdexec
GIT_REPOSITORY https://github.com/NVIDIA/stdexec.git
GIT_TAG main
)
FetchContent_MakeAvailable(Stdexec)
endif()

add_library(STDEXEC::stdexec INTERFACE IMPORTED)
target_include_directories(STDEXEC::stdexec INTERFACE ${stdexec_SOURCE_DIR}/include)
target_link_libraries(STDEXEC::stdexec INTERFACE ${Stdexec_LIBRARY})
elseif(HPX_WITH_STDEXEC)
find_package(Stdexec REQUIRED)

if(NOT Stdexec_FOUND)
hpx_error(
"Stdexec could not be found, please specify Stdexec_ROOT to point to the correct location"
)
endif()
endif()
5 changes: 5 additions & 0 deletions libs/core/execution_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# 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)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(execution_base_headers
hpx/execution_base/agent_base.hpp
hpx/execution_base/agent_ref.hpp
Expand All @@ -19,6 +21,7 @@ set(execution_base_headers
hpx/execution_base/receiver.hpp
hpx/execution_base/resource_base.hpp
hpx/execution_base/sender.hpp
hpx/execution_base/stdexec_forward.hpp
hpx/execution_base/this_thread.hpp
hpx/execution_base/traits/is_executor.hpp
hpx/execution_base/traits/is_executor_parameters.hpp
Expand Down Expand Up @@ -52,6 +55,8 @@ add_hpx_module(
SOURCES ${execution_base_sources}
HEADERS ${execution_base_headers}
COMPAT_HEADERS ${execution_base_compat_headers}
DEPENDENCIES
STDEXEC::stdexec
MODULE_DEPENDENCIES
hpx_assertion
hpx_config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2023 Isidoros Tsaousis-Seiras
//
// SPDX-License-Identifier: BSL-1.0
// 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)

#pragma once

#if defined(HPX_HAVE_STDEXEC)
#include <stdexec/execution.hpp>

namespace hpx::execution::experimental {
using namespace stdexec;
}
#endif
1 change: 1 addition & 0 deletions libs/core/execution_base/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(tests
execution_context
get_env
execute_may_block_caller
stdexec
)

if(HPX_WITH_CXX20_COROUTINES)
Expand Down
24 changes: 24 additions & 0 deletions libs/core/execution_base/tests/unit/stdexec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023 Isidoros Tsaousis-Seiras
//
// SPDX-License-Identifier: BSL-1.0
// 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/init.hpp>
#include <hpx/execution_base/stdexec_forward.hpp>

#include <hpx/modules/testing.hpp>

#include <utility>

using namespace hpx::execution::experimental;

int main() {
auto x = just(42);

auto [a] = sync_wait(std::move(x)).value();

HPX_TEST(a == 42);

return hpx::util::report_errors();
}

0 comments on commit 1798cbc

Please sign in to comment.