-
-
Notifications
You must be signed in to change notification settings - Fork 491
Integrating thrust into HPX #6744
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
adityacodes30
wants to merge
14
commits into
STEllAR-GROUP:master
Choose a base branch
from
adityacodes30:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,091
−5
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9cbfc1b
thrust policy and algorithm dipsatch
adityacodes30 4885a83
add algorithm map to molularise code
adityacodes30 6b6ab66
Async execution policy and refactor
adityacodes30 c81e6db
Move to independent directory and address feedback
adityacodes30 a5b04f9
Add docs, examples , algorithms
adityacodes30 9cecd6e
refactor : address feedback
adityacodes30 dcf58e2
cleanup and refactoring
adityacodes30 dfb9673
fix formatting and add cmake option
adityacodes30 3eb496e
Merge branch 'master' into master
adityacodes30 cf89016
restore unintended changes
adityacodes30 9c853f0
Update libs/core/thrust/include/hpx/thrust/algorithms.hpp
adityacodes30 c93a97a
Update libs/core/thrust/include/hpx/thrust/algorithms.hpp
adityacodes30 a591b3c
add copyright headers
adityacodes30 8e2b2a7
use bool-cpp20 concepts in tag_invoke
adityacodes30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) 2025 The STE||AR-Group | ||
| # | ||
| # 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) | ||
|
|
||
| if(NOT (HPX_WITH_CUDA AND HPX_WITH_THRUST)) | ||
| return() | ||
| endif() | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
|
||
| set(thrust_headers | ||
| hpx/thrust/policy.hpp | ||
| hpx/thrust/algorithms.hpp | ||
| hpx/thrust/detail/algorithm_map.hpp | ||
| ) | ||
|
|
||
| # cmake-format: off | ||
| set(thrust_compat_headers) | ||
| # cmake-format: on | ||
|
|
||
| set(thrust_sources) | ||
|
|
||
| include(HPX_AddModule) | ||
| add_hpx_module( | ||
| core thrust | ||
| GLOBAL_HEADER_GEN ON | ||
| SOURCES ${thrust_sources} | ||
| HEADERS ${thrust_headers} | ||
| COMPAT_HEADERS ${thrust_compat_headers} | ||
| MODULE_DEPENDENCIES | ||
| hpx_algorithms | ||
| hpx_concepts | ||
| hpx_execution | ||
| hpx_execution_base | ||
| hpx_functional | ||
| hpx_futures | ||
| hpx_async_cuda | ||
| CMAKE_SUBDIRS examples tests | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| .. | ||
| Copyright (c) 2025 The STE||AR-Group | ||
|
|
||
| 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) | ||
|
|
||
| .. _modules_thrust: | ||
|
|
||
| ====== | ||
| thrust | ||
| ====== | ||
|
|
||
| The thrust module integrates |hpx| parallel algorithms with NVIDIA Thrust, | ||
| enabling GPU acceleration using familiar |hpx| algorithm syntax. | ||
|
|
||
| Execution Policies | ||
| ================== | ||
|
|
||
| ``hpx::thrust::thrust_host_policy`` | ||
| CPU execution using optimized parallel implementations | ||
|
|
||
| ``hpx::thrust::thrust_device_policy`` | ||
| Synchronous GPU execution | ||
|
|
||
| ``hpx::thrust::thrust_task_policy`` | ||
| Asynchronous GPU execution returning |hpx| futures | ||
|
|
||
| Policy Mappings | ||
| =============== | ||
|
|
||
| The |hpx| thrust policies map directly to Thrust execution policies: | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| // Policy mappings | ||
| hpx::thrust::thrust_host_policy -> thrust::host | ||
| hpx::thrust::thrust_device_policy -> thrust::device | ||
| hpx::thrust::thrust_task_policy -> thrust::par_nosync | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| Synchronous Device Execution | ||
| ----------------------------- | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| #include <hpx/thrust/policy.hpp> | ||
| #include <hpx/thrust/algorithms.hpp> | ||
| #include <thrust/device_vector.h> | ||
|
|
||
| hpx::thrust::thrust_device_policy device{}; | ||
| thrust::device_vector<int> d_vec(1000, 0); | ||
|
|
||
| hpx::fill(device, d_vec.begin(), d_vec.end(), 42); | ||
| int sum = hpx::reduce(device, d_vec.begin(), d_vec.end(), 0); | ||
|
|
||
| Asynchronous Execution with Futures | ||
| ------------------------------------ | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| #include <hpx/thrust/policy.hpp> | ||
| #include <hpx/async_cuda/cuda_polling_helper.hpp> | ||
|
|
||
| int hpx_main() { | ||
| // Required for async operations | ||
| hpx::cuda::experimental::enable_user_polling polling_guard("default"); | ||
|
|
||
| hpx::thrust::thrust_task_policy task{}; | ||
| thrust::device_vector<int> d_vec(1000, 1); | ||
|
|
||
| auto fill_future = hpx::fill(task, d_vec.begin(), d_vec.end(), 42); | ||
| fill_future.get(); // Standard HPX future operations | ||
|
|
||
| } | ||
|
|
||
| Build Requirements | ||
| ================== | ||
|
|
||
| * CUDA Toolkit 12.4.0+ | ||
| * |hpx| with ``HPX_WITH_CUDA=ON`` | ||
| * Enable with: ``cmake -DHPX_WITH_CUDA=ON ...`` | ||
|
|
||
| See Also | ||
| ======== | ||
|
|
||
| * :ref:`modules_async_cuda` - CUDA integration | ||
| * :ref:`modules_execution` - |hpx| execution policies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright (c) 2025 Aditya Sapra | ||
| # | ||
| # 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) | ||
|
|
||
| if(HPX_WITH_EXAMPLES) | ||
| add_hpx_pseudo_target(examples.modules.thrust) | ||
| add_hpx_pseudo_dependencies(examples.modules examples.modules.thrust) | ||
| if(HPX_WITH_CUDA AND HPX_WITH_THRUST) | ||
| set(thrust_examples device_fill host_fill device_copy device_transform async_fill_n reverse_reduce) | ||
|
|
||
| foreach(example ${thrust_examples}) | ||
| set(source ${example}.cu) | ||
| source_group("Source Files" FILES ${source}) | ||
|
|
||
| add_hpx_executable( | ||
| ${example} INTERNAL_FLAGS | ||
| SOURCES ${source} | ||
| EXCLUDE_FROM_ALL | ||
| HPX_PREFIX ${HPX_BUILD_PREFIX} | ||
| FOLDER "Examples/Modules/Core/Thrust" | ||
| ) | ||
|
|
||
| add_hpx_pseudo_dependencies(examples.modules.thrust ${example}) | ||
| endforeach() | ||
| endif() | ||
| if(HPX_WITH_TESTS AND HPX_WITH_TESTS_EXAMPLES) | ||
| add_hpx_pseudo_target(tests.examples.modules.thrust) | ||
| add_hpx_pseudo_dependencies( | ||
| tests.examples.modules tests.examples.modules.thrust | ||
| ) | ||
| endif() | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) 2025 Aditya Sapra | ||
| // | ||
| // 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/algorithm.hpp> | ||
adityacodes30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <hpx/execution.hpp> | ||
| #include <hpx/init.hpp> | ||
|
|
||
| #include <hpx/thrust/algorithms.hpp> | ||
| #include <hpx/thrust/policy.hpp> | ||
|
|
||
| #include <hpx/async_cuda/cuda_polling_helper.hpp> | ||
| #include <hpx/modules/async_cuda.hpp> | ||
| #include <thrust/device_vector.h> | ||
|
|
||
| int hpx_main(int, char**) | ||
| { | ||
| // Enable CUDA event polling on the "default" pool for HPX <-> CUDA future bridging | ||
| hpx::cuda::experimental::enable_user_polling polling_guard("default"); | ||
|
|
||
| hpx::thrust::thrust_task_policy task{}; | ||
| thrust::device_vector<int> v(1024, 0); | ||
| auto f = hpx::fill_n(task, v.begin(), 512, 9); | ||
| f.get(); | ||
| return hpx::local::finalize(); | ||
| } | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| hpx::local::init_params init_args; | ||
| return hpx::local::init(hpx_main, argc, argv, init_args); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) 2025 Aditya Sapra | ||
| // | ||
| // 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/algorithm.hpp> | ||
adityacodes30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <hpx/execution.hpp> | ||
| #include <hpx/init.hpp> | ||
|
|
||
| #include <hpx/thrust/algorithms.hpp> | ||
| #include <hpx/thrust/policy.hpp> | ||
|
|
||
| #include <thrust/device_vector.h> | ||
|
|
||
| int hpx_main(int, char**) | ||
| { | ||
| hpx::thrust::thrust_device_policy device{}; | ||
| thrust::device_vector<int> src(1024, 5); | ||
| thrust::device_vector<int> dst(1024, 0); | ||
| hpx::copy(device, src.begin(), src.end(), dst.begin()); | ||
| return hpx::local::finalize(); | ||
| } | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| hpx::local::init_params init_args; | ||
| return hpx::local::init(hpx_main, argc, argv, init_args); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) 2025 Aditya Sapra | ||
| // | ||
| // 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/algorithm.hpp> | ||
adityacodes30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <hpx/execution.hpp> | ||
| #include <hpx/init.hpp> | ||
|
|
||
| #include <hpx/thrust/algorithms.hpp> | ||
| #include <hpx/thrust/policy.hpp> | ||
|
|
||
| #include <thrust/device_vector.h> | ||
|
|
||
| int hpx_main(int, char**) | ||
| { | ||
| hpx::thrust::thrust_device_policy device{}; | ||
| thrust::device_vector<int> v(1024, 0); | ||
| hpx::fill(device, v.begin(), v.end(), 1); | ||
| return hpx::local::finalize(); | ||
| } | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| hpx::local::init_params init_args; | ||
| return hpx::local::init(hpx_main, argc, argv, init_args); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright (c) 2025 Aditya Sapra | ||
| // | ||
| // 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/algorithm.hpp> | ||
adityacodes30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <hpx/execution.hpp> | ||
| #include <hpx/init.hpp> | ||
|
|
||
| #include <hpx/thrust/algorithms.hpp> | ||
| #include <hpx/thrust/policy.hpp> | ||
|
|
||
| #include <thrust/device_vector.h> | ||
|
|
||
| int hpx_main(int, char**) | ||
| { | ||
| hpx::thrust::thrust_device_policy device{}; | ||
| thrust::device_vector<int> a(1024, 2); | ||
| thrust::device_vector<int> b(1024, 3); | ||
| thrust::device_vector<int> out(1024, 0); | ||
|
|
||
| hpx::transform(device, a.begin(), a.end(), b.begin(), out.begin(), | ||
| [] __device__(int x, int y) { return x + y; }); | ||
| return hpx::local::finalize(); | ||
| } | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| hpx::local::init_params init_args; | ||
| return hpx::local::init(hpx_main, argc, argv, init_args); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) 2025 Aditya Sapra | ||
| // | ||
| // 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/algorithm.hpp> | ||
adityacodes30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <hpx/execution.hpp> | ||
| #include <hpx/init.hpp> | ||
|
|
||
| #include <hpx/thrust/algorithms.hpp> | ||
| #include <hpx/thrust/policy.hpp> | ||
|
|
||
| #include <vector> | ||
|
|
||
| int hpx_main(int, char**) | ||
| { | ||
| hpx::thrust::thrust_host_policy host{}; | ||
| std::vector<int> v(1024, 0); | ||
| hpx::fill(host, v.begin(), v.end(), 42); | ||
| return hpx::local::finalize(); | ||
| } | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| hpx::local::init_params init_args; | ||
| return hpx::local::init(hpx_main, argc, argv, init_args); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.