|
| 1 | +.. |
| 2 | + Copyright (c) 2025 The STE||AR-Group |
| 3 | +
|
| 4 | + SPDX-License-Identifier: BSL-1.0 |
| 5 | + Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | + |
| 8 | +.. _modules_thrust: |
| 9 | + |
| 10 | +====== |
| 11 | +thrust |
| 12 | +====== |
| 13 | + |
| 14 | +The thrust module integrates |hpx| parallel algorithms with NVIDIA Thrust, |
| 15 | +enabling GPU acceleration using familiar |hpx| algorithm syntax. |
| 16 | + |
| 17 | +Execution Policies |
| 18 | +================== |
| 19 | + |
| 20 | +``hpx::thrust::thrust_host_policy`` |
| 21 | + CPU execution using optimized parallel implementations |
| 22 | + |
| 23 | +``hpx::thrust::thrust_device_policy`` |
| 24 | + Synchronous GPU execution |
| 25 | + |
| 26 | +``hpx::thrust::thrust_task_policy`` |
| 27 | + Asynchronous GPU execution returning |hpx| futures |
| 28 | + |
| 29 | +Policy Mappings |
| 30 | +=============== |
| 31 | + |
| 32 | +The |hpx| thrust policies map directly to Thrust execution policies: |
| 33 | + |
| 34 | +.. code-block:: c++ |
| 35 | + |
| 36 | + // Policy mappings |
| 37 | + hpx::thrust::thrust_host_policy -> thrust::host |
| 38 | + hpx::thrust::thrust_device_policy -> thrust::device |
| 39 | + hpx::thrust::thrust_task_policy -> thrust::par_nosync |
| 40 | + |
| 41 | +Usage |
| 42 | +===== |
| 43 | + |
| 44 | +Synchronous Device Execution |
| 45 | +----------------------------- |
| 46 | + |
| 47 | +.. code-block:: c++ |
| 48 | + |
| 49 | + #include <hpx/thrust/policy.hpp> |
| 50 | + #include <hpx/thrust/algorithms.hpp> |
| 51 | + #include <thrust/device_vector.h> |
| 52 | + |
| 53 | + hpx::thrust::thrust_device_policy device{}; |
| 54 | + thrust::device_vector<int> d_vec(1000, 0); |
| 55 | + |
| 56 | + hpx::fill(device, d_vec.begin(), d_vec.end(), 42); |
| 57 | + int sum = hpx::reduce(device, d_vec.begin(), d_vec.end(), 0); |
| 58 | + |
| 59 | +Asynchronous Execution with Futures |
| 60 | +------------------------------------ |
| 61 | + |
| 62 | +.. code-block:: c++ |
| 63 | + |
| 64 | + #include <hpx/thrust/policy.hpp> |
| 65 | + #include <hpx/async_cuda/cuda_polling_helper.hpp> |
| 66 | + |
| 67 | + int hpx_main() { |
| 68 | + // Required for async operations |
| 69 | + hpx::cuda::experimental::enable_user_polling polling_guard("default"); |
| 70 | + |
| 71 | + hpx::thrust::thrust_task_policy task{}; |
| 72 | + thrust::device_vector<int> d_vec(1000, 1); |
| 73 | + |
| 74 | + auto fill_future = hpx::fill(task, d_vec.begin(), d_vec.end(), 42); |
| 75 | + fill_future.get(); // Standard HPX future operations |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | +Build Requirements |
| 80 | +================== |
| 81 | + |
| 82 | +* CUDA Toolkit 12.4.0+ |
| 83 | +* |hpx| with ``HPX_WITH_CUDA=ON`` |
| 84 | +* Enable with: ``cmake -DHPX_WITH_CUDA=ON ...`` |
| 85 | + |
| 86 | +See Also |
| 87 | +======== |
| 88 | + |
| 89 | +* :ref:`modules_async_cuda` - CUDA integration |
| 90 | +* :ref:`modules_execution` - |hpx| execution policies |
0 commit comments