Skip to content

Commit c255b1b

Browse files
authored
[RNG] add RNG armpl backend (#634)
1 parent 620fe8d commit c255b1b

12 files changed

+1292
-2
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ endif()
107107
if(ENABLE_MKLCPU_BACKEND
108108
OR ENABLE_MKLGPU_BACKEND
109109
OR ENABLE_CURAND_BACKEND
110-
OR ENABLE_ROCRAND_BACKEND)
110+
OR ENABLE_ROCRAND_BACKEND
111+
OR ENABLE_ARMPL_BACKEND)
111112
list(APPEND DOMAINS_LIST "rng")
112113
endif()
113114
if(ENABLE_MKLGPU_BACKEND

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,18 @@ Supported compilers include:
282282
<td align="center">Dynamic, Static</td>
283283
</tr>
284284
<tr>
285-
<td rowspan=4 align="center">RNG</td>
285+
<td rowspan=5 align="center">RNG</td>
286286
<td align="center">x86 CPU</td>
287287
<td align="center">Intel(R) oneMKL</td>
288288
<td align="center">Intel DPC++</br>AdaptiveCpp</td>
289289
<td align="center">Dynamic, Static</td>
290290
</tr>
291+
<tr>
292+
<td align="center">aarch64 CPU</td>
293+
<td align="center">Arm Performance Libraries</td>
294+
<td align="center">Open DPC++</br>AdaptiveCpp</td>
295+
<td align="center">Dynamic, Static</td>
296+
</tr>
291297
<tr>
292298
<td align="center">Intel GPU</td>
293299
<td align="center">Intel(R) oneMKL</td>

include/oneapi/math/detail/backends_table.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ static std::map<domain, std::map<device, std::vector<const char*>>> libraries =
182182
{
183183
#ifdef ONEMATH_ENABLE_MKLCPU_BACKEND
184184
LIB_NAME("rng_mklcpu")
185+
#endif
186+
} },
187+
{ device::aarch64cpu,
188+
{
189+
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
190+
LIB_NAME("rng_armpl")
185191
#endif
186192
} },
187193
{ device::intelgpu,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*******************************************************************************
2+
* Copyright 2025 SiPearl
3+
* Copyright 2020-2021 Intel Corporation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions
15+
* and limitations under the License.
16+
*
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
*******************************************************************************/
20+
21+
#ifndef _ONEMATH_RNG_ARMPL_HPP_
22+
#define _ONEMATH_RNG_ARMPL_HPP_
23+
24+
#include <cstdint>
25+
#if __has_include(<sycl/sycl.hpp>)
26+
#include <sycl/sycl.hpp>
27+
#else
28+
#include <CL/sycl.hpp>
29+
#endif
30+
31+
#include "oneapi/math/detail/export.hpp"
32+
#include "oneapi/math/rng/detail/engine_impl.hpp"
33+
34+
namespace oneapi {
35+
namespace math {
36+
namespace rng {
37+
namespace armpl {
38+
39+
ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_philox4x32x10(sycl::queue queue,
40+
std::uint64_t seed);
41+
42+
ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_philox4x32x10(
43+
sycl::queue queue, std::initializer_list<std::uint64_t> seed);
44+
45+
ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_mrg32k3a(sycl::queue queue,
46+
std::uint32_t seed);
47+
48+
ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_mrg32k3a(
49+
sycl::queue queue, std::initializer_list<std::uint32_t> seed);
50+
51+
} // namespace armpl
52+
} // namespace rng
53+
} // namespace math
54+
} // namespace oneapi
55+
56+
#endif //_ONEMATH_RNG_ARMPL_HPP_

include/oneapi/math/rng/engines.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifdef ONEMATH_ENABLE_ROCRAND_BACKEND
4848
#include "oneapi/math/rng/detail/rocrand/onemath_rng_rocrand.hpp"
4949
#endif
50+
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
51+
#include "oneapi/math/rng/detail/armpl/onemath_rng_armpl.hpp"
52+
#endif
5053

5154
namespace oneapi {
5255
namespace math {
@@ -103,6 +106,15 @@ class philox4x32x10 {
103106
: pimpl_(rocrand::create_philox4x32x10(selector.get_queue(), seed)) {}
104107
#endif
105108

109+
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
110+
philox4x32x10(backend_selector<backend::armpl> selector, std::uint64_t seed = default_seed)
111+
: pimpl_(armpl::create_philox4x32x10(selector.get_queue(), seed)) {}
112+
113+
philox4x32x10(backend_selector<backend::armpl> selector,
114+
std::initializer_list<std::uint64_t> seed)
115+
: pimpl_(armpl::create_philox4x32x10(selector.get_queue(), seed)) {}
116+
#endif
117+
106118
philox4x32x10(const philox4x32x10& other) {
107119
pimpl_.reset(other.pimpl_.get()->copy_state());
108120
}
@@ -192,6 +204,14 @@ class mrg32k3a {
192204
: pimpl_(rocrand::create_mrg32k3a(selector.get_queue(), seed)) {}
193205
#endif
194206

207+
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
208+
mrg32k3a(backend_selector<backend::armpl> selector, std::uint32_t seed = default_seed)
209+
: pimpl_(armpl::create_mrg32k3a(selector.get_queue(), seed)) {}
210+
211+
mrg32k3a(backend_selector<backend::armpl> selector, std::initializer_list<std::uint32_t> seed)
212+
: pimpl_(armpl::create_mrg32k3a(selector.get_queue(), seed)) {}
213+
#endif
214+
195215
mrg32k3a(const mrg32k3a& other) {
196216
pimpl_.reset(other.pimpl_.get()->copy_state());
197217
}

src/rng/backends/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ if(ENABLE_ROCRAND_BACKEND AND UNIX)
3636
add_subdirectory(rocrand)
3737
endif()
3838

39+
if(ENABLE_ARMPL_BACKEND AND UNIX)
40+
add_subdirectory(armpl)
41+
endif()
42+
43+

src/rng/backends/armpl/CMakeLists.txt

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#===============================================================================
2+
# Copyright 2025 SiPearl
3+
# Copyright 2020-2021 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions
15+
# and limitations under the License.
16+
#
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#===============================================================================
20+
21+
set(LIB_NAME onemath_rng_armpl)
22+
set(LIB_OBJ ${LIB_NAME}_obj)
23+
24+
find_package(ARMPL REQUIRED)
25+
26+
set(SOURCES armpl_common.hpp
27+
philox4x32x10.cpp
28+
mrg32k3a.cpp
29+
$<$<BOOL:${BUILD_SHARED_LIBS}>: armpl_rng_cpu_wrappers.cpp>
30+
)
31+
32+
add_library(${LIB_NAME})
33+
add_library(${LIB_OBJ} OBJECT ${SOURCES})
34+
add_dependencies(onemath_backend_libs_rng ${LIB_NAME})
35+
target_include_directories(${LIB_OBJ}
36+
PRIVATE ${PROJECT_SOURCE_DIR}/include
37+
${PROJECT_SOURCE_DIR}/src
38+
${CMAKE_BINARY_DIR}/bin
39+
${ARMPL_INCLUDE}
40+
${ONEMATH_GENERATED_INCLUDE_PATH}
41+
)
42+
43+
target_compile_options(${LIB_OBJ} PRIVATE ${ONEMATH_BUILD_COPT} ${ARMPL_COPT})
44+
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
45+
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})
46+
endif()
47+
48+
target_link_libraries(${LIB_OBJ} PUBLIC ONEMATH::SYCL::SYCL ${ARMPL_LINK})
49+
50+
set_target_properties(${LIB_OBJ} PROPERTIES
51+
POSITION_INDEPENDENT_CODE ON
52+
)
53+
target_link_libraries(${LIB_NAME} PUBLIC ${LIB_OBJ})
54+
55+
# Set oneMATH libraries as not transitive for dynamic
56+
if(BUILD_SHARED_LIBS)
57+
set_target_properties(${LIB_NAME} PROPERTIES
58+
INTERFACE_LINK_LIBRARIES ONEMATH::SYCL::SYCL
59+
)
60+
endif()
61+
62+
# Add major version to the library
63+
set_target_properties(${LIB_NAME} PROPERTIES
64+
SOVERSION ${PROJECT_VERSION_MAJOR}
65+
)
66+
67+
# Add dependencies rpath to the library
68+
list(APPEND CMAKE_BUILD_RPATH $<TARGET_FILE_DIR:${LIB_NAME}>)
69+
70+
# Add the library to install package
71+
install(TARGETS ${LIB_OBJ} EXPORT oneMathTargets)
72+
install(TARGETS ${LIB_NAME} EXPORT oneMathTargets
73+
RUNTIME DESTINATION bin
74+
ARCHIVE DESTINATION lib
75+
LIBRARY DESTINATION lib
76+
)
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*******************************************************************************
2+
* Copyright 2025 SiPearl
3+
* Copyright 2020-2021 Intel Corporation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions
15+
* and limitations under the License.
16+
*
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
*******************************************************************************/
20+
21+
#ifndef _RNG_CPU_COMMON_HPP_
22+
#define _RNG_CPU_COMMON_HPP_
23+
24+
#if __has_include(<sycl/sycl.hpp>)
25+
#include <sycl/sycl.hpp>
26+
#else
27+
#include <CL/sycl.hpp>
28+
#endif
29+
30+
#define GET_MULTI_PTR template get_multi_ptr<sycl::access::decorated::yes>().get_raw()
31+
#define __fp16 _Float16
32+
#define INTEGER64 1
33+
34+
#include "armpl.h"
35+
36+
namespace oneapi {
37+
namespace math {
38+
namespace rng {
39+
namespace armpl {
40+
41+
inline int check_armpl_version(armpl_int_t major_req, armpl_int_t minor_req, armpl_int_t build_req,
42+
const char* message) {
43+
armpl_int_t major, minor, build;
44+
char* tag;
45+
armplversion(&major, &minor, &build, (const char**)&tag);
46+
if (major > major_req) {
47+
return 0;
48+
}
49+
else if (major == major_req && minor > minor_req) {
50+
return 0;
51+
}
52+
else if (major == major_req && minor == minor_req && build >= build_req) {
53+
return 0;
54+
}
55+
throw oneapi::math::unimplemented("rng", "version support", message);
56+
}
57+
58+
template <typename K, typename H, typename F>
59+
static inline auto host_task_internal(H& cgh, F f, int) -> decltype(cgh.host_task(f)) {
60+
return cgh.host_task(f);
61+
}
62+
63+
template <typename K, typename H, typename F>
64+
static inline void host_task_internal(H& cgh, F f, long) {
65+
#ifndef __SYCL_DEVICE_ONLY__
66+
cgh.template single_task<K>(f);
67+
#endif
68+
}
69+
70+
template <typename K, typename H, typename F>
71+
static inline void host_task(H& cgh, F f) {
72+
(void)host_task_internal<K>(cgh, f, 0);
73+
}
74+
75+
template <typename Engine, typename Distr>
76+
class kernel_name {};
77+
78+
template <typename Engine, typename Distr>
79+
class kernel_name_usm {};
80+
81+
} // namespace armpl
82+
} // namespace rng
83+
} // namespace math
84+
} // namespace oneapi
85+
86+
#endif //_RNG_CPU_COMMON_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************************
2+
* Copyright 2025 SiPearl
3+
* Copyright 2020-2021 Intel Corporation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions
15+
* and limitations under the License.
16+
*
17+
*
18+
* SPDX-License-Identifier: Apache-2.0
19+
*******************************************************************************/
20+
21+
#include "rng/function_table.hpp"
22+
#include "oneapi/math/rng/detail/armpl/onemath_rng_armpl.hpp"
23+
24+
#define WRAPPER_VERSION 1
25+
26+
extern "C" ONEMATH_EXPORT rng_function_table_t onemath_rng_table = {
27+
WRAPPER_VERSION, oneapi::math::rng::armpl::create_philox4x32x10,
28+
oneapi::math::rng::armpl::create_philox4x32x10, oneapi::math::rng::armpl::create_mrg32k3a,
29+
oneapi::math::rng::armpl::create_mrg32k3a
30+
};

0 commit comments

Comments
 (0)