Skip to content

Commit c17a95c

Browse files
authored
[RNG][rocRAND][hipSYCL] Add the rocRAND backend to the RNG domain (#197)
* [RNG][hipSYCL] Add rocRAND backend
1 parent 9f3059f commit c17a95c

20 files changed

+2515
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ option(ENABLE_CUSOLVER_BACKEND "" OFF)
5252

5353
option(ENABLE_ROCBLAS_BACKEND "" OFF)
5454
option(ENABLE_CURAND_BACKEND "" OFF)
55+
option(ENABLE_ROCRAND_BACKEND "" OFF)
5556
option(ENABLE_NETLIB_BACKEND "" OFF)
5657
set(ONEMKL_SYCL_IMPLEMENTATION "dpc++" CACHE STRING "Name of the SYCL compiler")
5758

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ oneMKL is part of [oneAPI](https://oneapi.io).
1818
</thead>
1919
<tbody>
2020
<tr>
21-
<td rowspan=7 align="center">oneMKL interface</td>
22-
<td rowspan=7 align="center">oneMKL selector</td>
21+
<td rowspan=8 align="center">oneMKL interface</td>
22+
<td rowspan=8 align="center">oneMKL selector</td>
2323
<td align="center"><a href="https://software.intel.com/en-us/oneapi/onemkl">Intel(R) oneAPI Math Kernel Library</a> for x86 CPU</td>
2424
<td align="center">x86 CPU</td>
2525
</tr>
@@ -47,6 +47,10 @@ oneMKL is part of [oneAPI](https://oneapi.io).
4747
<td align="center"><a href="https://rocblas.readthedocs.io/en/rocm-4.5.2/"> AMD rocBLAS</a> for AMD GPU </td>
4848
<td align="center">AMD GPU</td>
4949
</tr>
50+
<tr>
51+
<td align="center"><a href="https://github.com/ROCmSoftwarePlatform/rocRAND"> AMD rocRAND</a> for AMD GPU </td>
52+
<td align="center">AMD GPU</td>
53+
</tr>
5054
</tbody>
5155
</table>
5256

@@ -184,11 +188,11 @@ Supported domains: BLAS, LAPACK, RNG
184188
<td align="center">LLVM*</td>
185189
</tr>
186190
<tr>
187-
<td rowspan=3 align="center">RNG</td>
191+
<td rowspan=4 align="center">RNG</td>
188192
<td align="center">x86 CPU</td>
189193
<td rowspan=2 align="center">Intel(R) oneAPI Math Kernel Library</td>
190194
<td align="center">Dynamic, Static</td>
191-
<td align="center">DPC++, LLVM*</td>
195+
<td align="center">DPC++, LLVM*, hipSYCL</td>
192196
</tr>
193197
<tr>
194198
<td align="center">Intel GPU</td>
@@ -201,6 +205,12 @@ Supported domains: BLAS, LAPACK, RNG
201205
<td align="center">Dynamic, Static</td>
202206
<td align="center">LLVM*</td>
203207
</tr>
208+
<tr>
209+
<td align="center">AMD GPU</td>
210+
<td align="center">AMD rocRAND</td>
211+
<td align="center">Dynamic, Static</td>
212+
<td align="center">hipSYCL</td>
213+
</tr>
204214
</tbody>
205215
</table>
206216

@@ -403,6 +413,7 @@ Python | 3.6 or higher | No | *N/A* | *Pre-installed or Installed by user* | [PS
403413
[Intel(R) oneAPI Math Kernel Library](https://software.intel.com/en-us/oneapi/onemkl) | latest | Yes | apt | /opt/intel/inteloneapi/mkl | [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license)
404414
[NVIDIA CUDA SDK](https://developer.nvidia.com/cublas) | 10.2 | No | *N/A* | *Installed by user* |[End User License Agreement](https://docs.nvidia.com/cuda/eula/index.html)
405415
[AMD rocBLAS](https://rocblas.readthedocs.io/en/rocm-4.5.2/) | 4.5 | No | *N/A* | *Installed by user* |[AMD License](https://github.com/ROCmSoftwarePlatform/rocBLAS/blob/develop/LICENSE.md)
416+
[AMD rocRAND](https://github.com/ROCmSoftwarePlatform/rocRAND) | 5.1.0 | No | *N/A* | *Installed by user* |[AMD License](https://github.com/ROCmSoftwarePlatform/rocRAND/blob/develop/LICENSE.txt)
406417
[NETLIB LAPACK](https://www.netlib.org/) | 3.7.1 | Yes | conan-community | ~/.conan/data or $CONAN_USER_HOME/.conan/data | [BSD like license](http://www.netlib.org/lapack/LICENSE.txt)
407418
[Sphinx](https://www.sphinx-doc.org/en/master/) | 2.4.4 | Yes | pip | ~/.local/bin (or similar user local directory) | [BSD License](https://github.com/sphinx-doc/sphinx/blob/3.x/LICENSE)
408419

include/oneapi/mkl/detail/backend_selector_predicates.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ inline void backend_selector_precondition<backend::rocblas>(sycl::queue& queue)
107107
#endif
108108
}
109109

110+
template <>
111+
inline void backend_selector_precondition<backend::rocrand>(sycl::queue& queue) {
112+
#ifndef ONEMKL_DISABLE_PREDICATES
113+
unsigned int vendor_id =
114+
static_cast<unsigned int>(queue.get_device().get_info<sycl::info::device::vendor_id>());
115+
if (!(queue.get_device().is_gpu() && vendor_id == AMD_ID)) {
116+
throw unsupported_device("",
117+
"backend_selector<backend::" + backend_map[backend::rocrand] + ">",
118+
queue.get_device());
119+
}
120+
#endif
121+
}
122+
110123
} // namespace mkl
111124
} // namespace oneapi
112125

include/oneapi/mkl/detail/backends.hpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,26 @@
2626
namespace oneapi {
2727
namespace mkl {
2828

29-
enum class backend { mklcpu, mklgpu, cublas, cusolver, curand, netlib, rocblas, unsupported };
29+
enum class backend {
30+
mklcpu,
31+
mklgpu,
32+
cublas,
33+
cusolver,
34+
curand,
35+
netlib,
36+
rocblas,
37+
rocrand,
38+
unsupported
39+
};
3040

3141
typedef std::map<backend, std::string> backendmap;
3242

3343
static backendmap backend_map = {
34-
{ backend::mklcpu, "mklcpu" }, { backend::mklgpu, "mklgpu" },
35-
{ backend::cublas, "cublas" }, { backend::cusolver, "cusolver" },
36-
{ backend::curand, "curand" }, { backend::netlib, "netlib" },
37-
{ backend::rocblas, "rocblas" }, { backend::unsupported, "unsupported" }
44+
{ backend::mklcpu, "mklcpu" }, { backend::mklgpu, "mklgpu" },
45+
{ backend::cublas, "cublas" }, { backend::cusolver, "cusolver" },
46+
{ backend::curand, "curand" }, { backend::netlib, "netlib" },
47+
{ backend::rocblas, "rocblas" }, { backend::rocrand, "rocrand" },
48+
{ backend::unsupported, "unsupported" }
3849
};
3950

4051
} //namespace mkl

include/oneapi/mkl/detail/backends_table.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ static std::map<domain, std::map<device, std::vector<const char*>>> libraries =
100100
{
101101
#ifdef ENABLE_MKLGPU_BACKEND
102102
LIB_NAME("rng_mklgpu")
103+
#endif
104+
} },
105+
{ device::amdgpu,
106+
{
107+
#ifdef ENABLE_ROCRAND_BACKEND
108+
LIB_NAME("rng_rocrand")
103109
#endif
104110
} },
105111
{ device::nvidiagpu,

include/oneapi/mkl/rng/detail/engine_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "oneapi/mkl/detail/get_device_id.hpp"
2828

2929
#include "oneapi/mkl/rng/distributions.hpp"
30+
#include "oneapi/mkl/types.hpp"
3031

3132
namespace oneapi {
3233
namespace mkl {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2022 Heidelberg University, Engineering Mathematics and Computing Lab (EMCL)
3+
* and Computing Centre (URZ)
4+
* cuRAND back-end Copyright (c) 2021, The Regents of the University of
5+
* California, through Lawrence Berkeley National Laboratory (subject to receipt
6+
* of any required approvals from the U.S. Dept. of Energy). All rights
7+
* reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* (1) Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
*
15+
* (2) Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
*
19+
* (3) Neither the name of the University of California, Lawrence Berkeley
20+
* National Laboratory, U.S. Dept. of Energy nor the names of its contributors
21+
* may be used to endorse or promote products derived from this software
22+
* without specific prior written permission.
23+
*
24+
*
25+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* You are under no obligation whatsoever to provide any bug fixes, patches,
38+
* or upgrades to the features, functionality or performance of the source
39+
* code ("Enhancements") to anyone; however, if you choose to make your
40+
* Enhancements available either publicly, or directly to Lawrence Berkeley
41+
* National Laboratory, without imposing a separate written license agreement
42+
* for such Enhancements, then you hereby grant the following license: a
43+
* non-exclusive, royalty-free perpetual license to install, use, modify,
44+
* prepare derivative works, incorporate into other computer software,
45+
* distribute, and sublicense such enhancements or derivative works thereof,
46+
* in binary and source code form.
47+
*
48+
* If you have questions about your rights to use or distribute this software,
49+
* please contact Berkeley Lab's Intellectual Property Office at
50+
* IPO@lbl.gov.
51+
*
52+
* NOTICE. This Software was developed under funding from the U.S. Department
53+
* of Energy and the U.S. Government consequently retains certain rights. As
54+
* such, the U.S. Government has been granted for itself and others acting on
55+
* its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
56+
* Software to reproduce, distribute copies to the public, prepare derivative
57+
* works, and perform publicly and display publicly, and to permit others to do
58+
* so.
59+
******************************************************************************/
60+
61+
#ifndef _ONEMKL_RNG_ROCRAND_HPP_
62+
#define _ONEMKL_RNG_ROCRAND_HPP_
63+
64+
#include <CL/sycl.hpp>
65+
#include <cstdint>
66+
67+
#include "oneapi/mkl/detail/export.hpp"
68+
#include "oneapi/mkl/rng/detail/engine_impl.hpp"
69+
70+
namespace oneapi {
71+
namespace mkl {
72+
namespace rng {
73+
namespace rocrand {
74+
75+
ONEMKL_EXPORT oneapi::mkl::rng::detail::engine_impl* create_philox4x32x10(sycl::queue queue,
76+
std::uint64_t seed);
77+
78+
ONEMKL_EXPORT oneapi::mkl::rng::detail::engine_impl* create_philox4x32x10(
79+
sycl::queue queue, std::initializer_list<std::uint64_t> seed);
80+
81+
ONEMKL_EXPORT oneapi::mkl::rng::detail::engine_impl* create_mrg32k3a(sycl::queue queue,
82+
std::uint32_t seed);
83+
84+
ONEMKL_EXPORT oneapi::mkl::rng::detail::engine_impl* create_mrg32k3a(
85+
sycl::queue queue, std::initializer_list<std::uint32_t> seed);
86+
87+
} // namespace rocrand
88+
} // namespace rng
89+
} // namespace mkl
90+
} // namespace oneapi
91+
92+
#endif //_ONEMKL_RNG_ROCRAND_HPP_

include/oneapi/mkl/rng/engines.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
#ifdef ENABLE_CURAND_BACKEND
4141
#include "oneapi/mkl/rng/detail/curand/onemkl_rng_curand.hpp"
4242
#endif
43+
#ifdef ENABLE_ROCRAND_BACKEND
44+
#include "oneapi/mkl/rng/detail/rocrand/onemkl_rng_rocrand.hpp"
45+
#endif
4346

4447
namespace oneapi {
4548
namespace mkl {
@@ -87,6 +90,14 @@ class philox4x32x10 {
8790
std::initializer_list<std::uint64_t> seed)
8891
: pimpl_(curand::create_philox4x32x10(selector.get_queue(), seed)) {}
8992
#endif
93+
#ifdef ENABLE_ROCRAND_BACKEND
94+
philox4x32x10(backend_selector<backend::rocrand> selector, std::uint64_t seed = default_seed)
95+
: pimpl_(rocrand::create_philox4x32x10(selector.get_queue(), seed)) {}
96+
97+
philox4x32x10(backend_selector<backend::rocrand> selector,
98+
std::initializer_list<std::uint64_t> seed)
99+
: pimpl_(rocrand::create_philox4x32x10(selector.get_queue(), seed)) {}
100+
#endif
90101

91102
philox4x32x10(const philox4x32x10& other) {
92103
pimpl_.reset(other.pimpl_.get()->copy_state());
@@ -169,6 +180,14 @@ class mrg32k3a {
169180
: pimpl_(curand::create_mrg32k3a(selector.get_queue(), seed)) {}
170181
#endif
171182

183+
#ifdef ENABLE_ROCRAND_BACKEND
184+
mrg32k3a(backend_selector<backend::rocrand> selector, std::uint32_t seed = default_seed)
185+
: pimpl_(rocrand::create_mrg32k3a(selector.get_queue(), seed)) {}
186+
187+
mrg32k3a(backend_selector<backend::rocrand> selector, std::initializer_list<std::uint32_t> seed)
188+
: pimpl_(rocrand::create_mrg32k3a(selector.get_queue(), seed)) {}
189+
#endif
190+
172191
mrg32k3a(const mrg32k3a& other) {
173192
pimpl_.reset(other.pimpl_.get()->copy_state());
174193
}

src/config.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#cmakedefine ENABLE_CUBLAS_BACKEND
2424
#cmakedefine ENABLE_CUSOLVER_BACKEND
2525
#cmakedefine ENABLE_ROCBLAS_BACKEND
26+
#cmakedefine ENABLE_ROCRAND_BACKEND
2627
#cmakedefine ENABLE_CURAND_BACKEND
2728
#cmakedefine ENABLE_MKLCPU_BACKEND
2829
#cmakedefine ENABLE_MKLGPU_BACKEND

src/rng/backends/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ endif()
2828
if(ENABLE_CURAND_BACKEND AND UNIX)
2929
add_subdirectory(curand)
3030
endif()
31+
32+
if(ENABLE_ROCRAND_BACKEND AND UNIX)
33+
add_subdirectory(rocrand)
34+
endif()
35+

0 commit comments

Comments
 (0)