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 6, 2024
1 parent 9c53b99 commit 634cb7b
Show file tree
Hide file tree
Showing 7 changed files with 155 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
32 changes: 32 additions & 0 deletions cmake/FindStdexec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

if(NOT TARGET STDEXEC::stdexec)
find_path(
Stdexec_INCLUDE_DIR
stdexec
HINTS ${Stdexec_ROOT}
PATH_SUFFIXES include
)

message(STATUS "Stdexec_INCLUDE_DIR: ${Stdexec_INCLUDE_DIR}")

# set(Stdexec_INCLUDE_DIR ${Stdexec_INCLUDE_DIR})

if (NOT Stdexec_INCLUDE_DIR)
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 INTERFACE ${Stdexec_INCLUDE_DIR})
target_link_libraries(STDEXEC::stdexec INTERFACE stdexec)

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()
2 changes: 2 additions & 0 deletions libs/core/execution_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ add_hpx_module(
hpx_lock_registration
hpx_timing
hpx_type_support
DEPENDENCIES
STDEXEC::stdexec
CMAKE_SUBDIRS examples tests
)
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 634cb7b

Please sign in to comment.