|
| 1 | +Get Started with the |onedpl_long| |
| 2 | +################################## |
| 3 | + |
| 4 | +|onedpl_long| (|onedpl_short|) works with the |
| 5 | +`Intel® oneAPI DPC++/C++ Compiler <https://software.intel.com/content/www/us/en/develop/documentation/get-started-with-dpcpp-compiler/top.html>`_ |
| 6 | +to provide high-productivity APIs to developers, which can minimize SYCL* |
| 7 | +programming efforts across devices for high performance parallel applications. |
| 8 | + |
| 9 | +|onedpl_short| consists of the following components: |
| 10 | + |
| 11 | +* Parallel API |
| 12 | +* API for SYCL Kernels |
| 13 | +* Macros |
| 14 | + |
| 15 | + |
| 16 | +For general information about |onedpl_short|, visit the `oneDPL GitHub* repository <https://github.com/oneapi-src/oneDPL>`_, |
| 17 | +or visit the `Intel® oneAPI DPC++ Library Guide <https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top.html>`_ |
| 18 | +and the `Intel® oneAPI DPC++ Library main page <https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/dpc-library.html>`_. |
| 19 | + |
| 20 | +Before You Begin |
| 21 | +================ |
| 22 | + |
| 23 | +Visit the |onedpl_short| `Release Notes |
| 24 | +<https://software.intel.com/content/www/us/en/develop/articles/intel-oneapi-dpcpp-library-release-notes.html>`_ |
| 25 | +page for: |
| 26 | + |
| 27 | +* Where to Find the Release |
| 28 | +* Overview |
| 29 | +* New Features |
| 30 | +* Fixed Issues |
| 31 | +* Known Issues and Limitations |
| 32 | + |
| 33 | +Install the `Intel® oneAPI Base Toolkit (Base Kit) <https://software.intel.com/en-us/oneapi/base-kit>`_ |
| 34 | +to use |onedpl_short|. |
| 35 | + |
| 36 | +To use Parallel API, include the corresponding header files in your source code. |
| 37 | + |
| 38 | +All |onedpl_short| header files are in the ``oneapi/dpl`` directory. Use ``#include <oneapi/dpl/…>`` to include them. |
| 39 | +|onedpl_short| uses the namespace ``oneapi::dpl`` for most its classes and functions. |
| 40 | + |
| 41 | +To use tested C++ standard APIs, you need to include the corresponding C++ standard header files |
| 42 | +and use the ``std`` namespace. |
| 43 | + |
| 44 | + |
| 45 | +pkg-config Support |
| 46 | +================== |
| 47 | + |
| 48 | +The pkg-config program is used to retrieve information about your installed libraries, and |
| 49 | +to compile and link against one or more libraries. |
| 50 | + |
| 51 | +Use pkg-config with |onedpl_short| |
| 52 | +---------------------------------- |
| 53 | + |
| 54 | +Use pkg-config with the ``--cflags`` flag to get the include path to the oneDPL directory: |
| 55 | + |
| 56 | +.. code:: cpp |
| 57 | +
|
| 58 | + dpcpp test.cpp $(pkg-config --cflags dpl) |
| 59 | + |
| 60 | +The ``--msvc-syntax`` flag is required when you use a Microsoft Visual C++* compiler. |
| 61 | +This flag converts your compiling and linking flags to the appropriate form: |
| 62 | + |
| 63 | +.. code:: cpp |
| 64 | +
|
| 65 | + dpcpp test.cpp $(pkg-config --msvc-syntax --cflags dpl) |
| 66 | +
|
| 67 | +.. note:: |
| 68 | + Use the pkg-config tool to get rid of large hard-coded paths and make compilation more portable. |
| 69 | + |
| 70 | + |
| 71 | +Usage Examples |
| 72 | +============== |
| 73 | + |
| 74 | +|onedpl_short| sample code is available from the |
| 75 | +`oneAPI GitHub samples repository <https://github.com/oneapi-src/oneAPI-samples/tree/master/Libraries/oneDPL>`_. |
| 76 | +Each sample includes a readme with build instructions. |
| 77 | + |
| 78 | +\<oneapi/dpl/random\> Header Usage Example |
| 79 | +------------------------------------------ |
| 80 | + |
| 81 | +This example illustrates |onedpl_short| random number generator usage. |
| 82 | +The sample below shows you how to create an random number generator engine object (the source of pseudo-randomness), |
| 83 | +a distribution object (specifying the desired probability distribution), and how to generate |
| 84 | +the random numbers themselves. Random number generation is performed in a vectorized manner |
| 85 | +to improve the speed of your computations. |
| 86 | + |
| 87 | +This example performs its computations on your default SYCL device. You can set the |
| 88 | +``SYCL_DEVICE_TYPE`` environment variable to CPU or GPU. |
| 89 | + |
| 90 | +.. code:: cpp |
| 91 | +
|
| 92 | + template<int VecSize> |
| 93 | + void random_fill(float* usmptr, std::size_t n) { |
| 94 | + auto zero = oneapi::dpl::counting_iterator<std::size_t>(0); |
| 95 | +
|
| 96 | + std::for_each(oneapi::dpl::execution::dpcpp_default, |
| 97 | + zero, zero + n/VecSize, |
| 98 | + [usmptr](std::size_t i) { |
| 99 | + auto offset = i * VecSize; |
| 100 | +
|
| 101 | + oneapi::dpl::minstd_rand_vec<VecSize> engine(seed, offset); |
| 102 | + oneapi::dpl::uniform_real_distribution<sycl::vec<float, VecSize>> distr; |
| 103 | +
|
| 104 | + auto res = distr(engine); |
| 105 | + res.store(i, sycl::global_ptr<float>(usmptr)); |
| 106 | + }); |
| 107 | + } |
| 108 | +
|
| 109 | +Pi Benchmark Usage Example |
| 110 | +-------------------------- |
| 111 | + |
| 112 | +This example uses a Monte Carlo method to estimate the value of π. |
| 113 | +The basic idea is to generate random points within a square, and to check what |
| 114 | +fraction of these random points lie in a quarter-circle inscribed within that square. |
| 115 | +The expected value is the ratio of the areas of the quarter-circle and the square (π/4). |
| 116 | +You can take the observed fraction of points in the quarter-circle as an estimate of π/4. |
| 117 | + |
| 118 | +This example shows you how to create an random number generator engine object (the source of pseudo-randomness), |
| 119 | +a distribution object (specifying the desired probability distribution), generate the |
| 120 | +random numbers themselves, and then perform a reduction to count quantity of points that |
| 121 | +fit into the square *S*. Random number generation is performed in scalar manner to simplify your code. |
| 122 | + |
| 123 | + |
| 124 | +.. figure:: images/pi_benchmark.png |
| 125 | + :alt: An image of pi chart. |
| 126 | + |
| 127 | +.. code:: cpp |
| 128 | +
|
| 129 | + float estimated_pi; |
| 130 | + { |
| 131 | + sycl::queue q(sycl::gpu_selector{}); |
| 132 | + auto policy = oneapi::dpl::execution::make_device_policy(q); |
| 133 | +
|
| 134 | + float sum = std::transform_reduce( policy, |
| 135 | + oneapi::dpl::counting_iterator<int>(0), |
| 136 | + oneapi::dpl::counting_iterator<int>(N), |
| 137 | + 0.0f, |
| 138 | + std::plus<float>{}, |
| 139 | + [=](int n){ |
| 140 | + float local_sum = 0.0f; |
| 141 | + oneapi::dpl::minstd_rand engine(SEED, n * ITER * 2); |
| 142 | + oneapi::dpl::uniform_real_distribution<float> distr; |
| 143 | + for(int i = 0; i < ITER; ++i) { |
| 144 | + float x = distr(engine); |
| 145 | + float y = distr(engine); |
| 146 | + if (x * x + y * y <= 1.0) |
| 147 | + local_sum += 1.0; |
| 148 | + } |
| 149 | + return local_sum / (float)ITER; |
| 150 | + } |
| 151 | + ); |
| 152 | + estimated_pi = 4.0f * (float)sum / N; |
| 153 | + } |
| 154 | +
|
| 155 | +
|
| 156 | +Find More |
| 157 | +========= |
| 158 | + |
| 159 | +.. list-table:: |
| 160 | + :widths: 50 50 |
| 161 | + :header-rows: 1 |
| 162 | + |
| 163 | + * - Resource Link |
| 164 | + - Description |
| 165 | + * - `Intel® oneAPI DPC++ Library Guide <https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top.html>`_ |
| 166 | + - Refer to the |onedpl_short| guide for more in depth information. |
| 167 | + * - `System Requirements <https://software.intel.com/content/www/us/en/develop/articles/intel-oneapi-dpcpp-system-requirements.html>`_ |
| 168 | + - Check system requirements before you install |onedpl_short|. |
| 169 | + * - `Intel® oneAPI DPC++ Library Release Notes <https://software.intel.com/content/www/us/en/develop/articles/intel-oneapi-dpcpp-library-release-notes.html>`_ |
| 170 | + - Check the release notes to learn about updates in the latest release. |
| 171 | + * - `oneDPL Samples <https://github.com/oneapi-src/oneAPI-samples/tree/master/Libraries/oneDPL>`_ |
| 172 | + - Learn how to use |onedpl_short| with samples. |
| 173 | + * - `Layers for Yocto* Project <https://www.intel.com/content/www/us/en/develop/documentation/get-started-with-intel-oneapi-iot-linux/top/adding-oneapi-components-to-yocto-project-builds.html>`_ |
| 174 | + - Add oneAPI components to a Yocto project build using the meta-intel layers. |
0 commit comments