Skip to content

Commit 1694bef

Browse files
authored
[RNG][ARMPL] Support using OpenRNG in place of ArmPL (#660)
1 parent 4ad4dfb commit 1694bef

File tree

11 files changed

+155
-55
lines changed

11 files changed

+155
-55
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ oneMath is part of the [UXL Foundation](http://www.uxlfoundation.org).
2121
</thead>
2222
<tbody>
2323
<tr>
24-
<td rowspan=15 align="center">oneMath</td>
25-
<td rowspan=15 align="center">oneMath selector</td>
24+
<td rowspan=16 align="center">oneMath</td>
25+
<td rowspan=16 align="center">oneMath selector</td>
2626
<td align="center"><a href="https://software.intel.com/en-us/oneapi/onemkl">Intel(R) oneAPI Math Kernel Library (oneMKL)</a></td>
2727
<td align="center">x86 CPU, Intel GPU</td>
2828
</tr>
@@ -55,6 +55,10 @@ oneMath is part of the [UXL Foundation](http://www.uxlfoundation.org).
5555
<td align="center"><a href="https://www.arm.com/products/development-tools/server-and-hpc/allinea-studio/performance-libraries">Arm Performance Libraries</a></td>
5656
<td align="center">aarch64 CPU</td>
5757
</tr>
58+
<tr>
59+
<td align="center"><a href="https://gitlab.arm.com/libraries/openrng">Arm OpenRNG</a></td>
60+
<td align="center">x86 and aarch64 CPU</td>
61+
</tr>
5862
<tr>
5963
<td align="center"><a href="https://rocblas.readthedocs.io/en/rocm-4.5.2/"> AMD rocBLAS</a></td>
6064
<td align="center">AMD GPU</td>
@@ -285,18 +289,28 @@ Supported compilers include:
285289
<td align="center">Dynamic, Static</td>
286290
</tr>
287291
<tr>
288-
<td rowspan=5 align="center">RNG</td>
289-
<td align="center">x86 CPU</td>
292+
<td rowspan=7 align="center">RNG</td>
293+
<td rowspan=2 align="center">x86 CPU</td>
290294
<td align="center">Intel(R) oneMKL</td>
291295
<td align="center">Intel DPC++</br>AdaptiveCpp</td>
292296
<td align="center">Dynamic, Static</td>
293297
</tr>
294298
<tr>
295-
<td align="center">aarch64 CPU</td>
299+
<td align="center">Arm OpenRNG</td>
300+
<td align="center">Open DPC++</br>AdaptiveCpp</td>
301+
<td align="center">Dynamic, Static</td>
302+
</tr>
303+
<tr>
304+
<td rowspan=2 align="center">aarch64 CPU</td>
296305
<td align="center">Arm Performance Libraries</td>
297306
<td align="center">Open DPC++</br>AdaptiveCpp</td>
298307
<td align="center">Dynamic, Static</td>
299308
</tr>
309+
<tr>
310+
<td align="center">Arm OpenRNG</td>
311+
<td align="center">Open DPC++</br>AdaptiveCpp</td>
312+
<td align="center">Dynamic, Static</td>
313+
</tr>
300314
<tr>
301315
<td align="center">Intel GPU</td>
302316
<td align="center">Intel(R) oneMKL</td>

cmake/FindARMPL.cmake

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,52 @@ else()
3232
endif()
3333
find_package_handle_standard_args(ARMPL REQUIRED_VARS ARMPL_LIBRARY)
3434

35-
get_filename_component(ARMPL_LIB_DIR ${ARMPL_LIBRARY} DIRECTORY)
36-
find_path(ARMPL_INCLUDE armpl.h HINTS ${ARMPL_ROOT} $ENV{ARMPLROOT} PATH_SUFFIXES include)
37-
#cmake replaces fullpath to libarmpl by -larmpl (because SONAME is absent) and -Wl,-rpath is not enough for some compilers as hint
38-
#so we need to add -L to compiler, otherwise we need to set LIBRARY_PATH manually when building
39-
if(UNIX)
40-
list(APPEND ARMPL_LINK "-Wl,-rpath,${ARMPL_LIB_DIR} -L${ARMPL_LIB_DIR}")
41-
endif()
42-
list(APPEND ARMPL_LINK ${ARMPL_LIBRARY})
43-
list(APPEND ARMPL_LINK ${ARMPL_LIBRARY})
44-
message(${ARMPL_LINK})
45-
find_package_handle_standard_args(ARMPL REQUIRED_VARS ARMPL_INCLUDE ARMPL_LINK)
35+
if (ARMPL_FOUND AND NOT TARGET ONEMKL::ARMPL::ARMPL)
36+
get_filename_component(ARMPL_LIB_DIR ${ARMPL_LIBRARY} DIRECTORY)
37+
find_path(ARMPL_INCLUDE armpl.h HINTS ${ARMPL_ROOT} $ENV{ARMPLROOT} PATH_SUFFIXES include)
38+
#cmake replaces fullpath to libarmpl by -larmpl (because SONAME is absent) and -Wl,-rpath is not enough for some compilers as hint
39+
#so we need to add -L to compiler, otherwise we need to set LIBRARY_PATH manually when building
40+
if(UNIX)
41+
list(APPEND ARMPL_LINK "-Wl$<COMMA>-rpath$<COMMA>${ARMPL_LIB_DIR} -L${ARMPL_LIB_DIR}")
42+
endif()
43+
list(APPEND ARMPL_LINK ${ARMPL_LIBRARY})
44+
list(APPEND ARMPL_LINK ${ARMPL_LIBRARY})
45+
message(${ARMPL_LINK})
46+
find_package_handle_standard_args(ARMPL REQUIRED_VARS ARMPL_INCLUDE ARMPL_LINK)
4647

47-
# Check ARMPL version (only versions higher or equal to 22.0.1 are supported)
48-
set(ARMPL_MAJOR 22)
49-
set(ARMPL_MINOR 0)
50-
set(ARMPL_BUILD 1)
51-
file(WRITE ${CMAKE_BINARY_DIR}/armplversion.cpp
52-
"#include <stdio.h>\n"
53-
"\n"
54-
"#include \"armpl.h\"\n"
55-
"\n"
56-
"int main(void) {\n"
57-
" int major, minor, build;\n"
58-
" char *tag;\n"
59-
" armplversion(&major, &minor, &build, (const char **)&tag);\n"
60-
" if (major > MAJOR) {\n"
61-
" return 0;\n"
62-
" }\n"
63-
" else if (major == MAJOR && minor > MINOR) {\n"
64-
" return 0;\n"
65-
" }\n"
66-
" else if (major == MAJOR && minor == MINOR && build >= BUILD) {\n"
67-
" return 0;\n"
68-
" }\n"
69-
" printf(\"You are using version %d.%d.%d\\n\", major, minor, build);\n"
70-
" return 1;\n"
71-
"}\n")
72-
execute_process(COMMAND ${CMAKE_CXX_COMPILER} armplversion.cpp -O0 -I${ARMPL_INCLUDE} -Wl,-rpath,${ARMPL_LIB_DIR} -larmpl -DMAJOR=${ARMPL_MAJOR} -DMINOR=${ARMPL_MINOR} -DBUILD=${ARMPL_BUILD} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
73-
execute_process(COMMAND ./a.out WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE ARMPL_CHECK_VERSION)
74-
execute_process(COMMAND rm ./a.out WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
75-
execute_process(COMMAND rm armplversion.cpp WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
76-
if(ARMPL_CHECK_VERSION)
77-
message(FATAL_ERROR "ARMPL backend does not support ARMPL version prior to version ${ARMPL_MAJOR}.${ARMPL_MINOR}.${ARMPL_BUILD}")
78-
endif()
48+
# Check ARMPL version (only versions higher or equal to 22.0.1 are supported)
49+
set(ARMPL_MAJOR 22)
50+
set(ARMPL_MINOR 0)
51+
set(ARMPL_BUILD 1)
52+
file(WRITE ${CMAKE_BINARY_DIR}/armplversion.cpp
53+
"#include <stdio.h>\n"
54+
"\n"
55+
"#include \"armpl.h\"\n"
56+
"\n"
57+
"int main(void) {\n"
58+
" int major, minor, build;\n"
59+
" char *tag;\n"
60+
" armplversion(&major, &minor, &build, (const char **)&tag);\n"
61+
" if (major > MAJOR) {\n"
62+
" return 0;\n"
63+
" }\n"
64+
" else if (major == MAJOR && minor > MINOR) {\n"
65+
" return 0;\n"
66+
" }\n"
67+
" else if (major == MAJOR && minor == MINOR && build >= BUILD) {\n"
68+
" return 0;\n"
69+
" }\n"
70+
" printf(\"You are using version %d.%d.%d\\n\", major, minor, build);\n"
71+
" return 1;\n"
72+
"}\n")
73+
execute_process(COMMAND ${CMAKE_CXX_COMPILER} armplversion.cpp -O0 -I${ARMPL_INCLUDE} -Wl,-rpath,${ARMPL_LIB_DIR} -larmpl -DMAJOR=${ARMPL_MAJOR} -DMINOR=${ARMPL_MINOR} -DBUILD=${ARMPL_BUILD} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
74+
execute_process(COMMAND ./a.out WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE ARMPL_CHECK_VERSION)
75+
execute_process(COMMAND rm ./a.out WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
76+
execute_process(COMMAND rm armplversion.cpp WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
77+
if(ARMPL_CHECK_VERSION)
78+
message(FATAL_ERROR "ARMPL backend does not support ARMPL version prior to version ${ARMPL_MAJOR}.${ARMPL_MINOR}.${ARMPL_BUILD}")
79+
endif()
7980

80-
add_library(ONEMKL::ARMPL::ARMPL UNKNOWN IMPORTED)
81-
set_target_properties(ONEMKL::ARMPL::ARMPL PROPERTIES IMPORTED_LOCATION ${ARMPL_LIBRARY})
81+
add_library(ONEMKL::ARMPL::ARMPL UNKNOWN IMPORTED)
82+
set_target_properties(ONEMKL::ARMPL::ARMPL PROPERTIES IMPORTED_LOCATION ${ARMPL_LIBRARY})
83+
endif()

cmake/FindOpenRNG.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#==========================================================================
2+
# Copyright (C) Codeplay Software Limited
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# For your convenience, a copy of the License has been included in this
10+
# repository.
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
#=========================================================================
19+
20+
include_guard()
21+
22+
include(FindPackageHandleStandardArgs)
23+
find_library(OpenRNG_LIBRARY
24+
NAMES openrng
25+
HINTS ${OpenRNG_ROOT}
26+
PATH_SUFFIXES lib lib64)
27+
find_path(OpenRNG_INCLUDE_DIR
28+
NAMES openrng.h
29+
HINTS ${OpenRNG_ROOT}
30+
PATH_SUFFIXES include)
31+
find_package_handle_standard_args(OpenRNG
32+
REQUIRED_VARS
33+
OpenRNG_LIBRARY
34+
OpenRNG_INCLUDE_DIR
35+
VERSION_VAR OpenRNG_VERSION)
36+
37+
if (OpenRNG_FOUND AND NOT TARGET ONEMATH::OpenRNG::OpenRNG)
38+
add_library(ONEMATH::OpenRNG::OpenRNG UNKNOWN IMPORTED)
39+
set_target_properties(ONEMATH::OpenRNG::OpenRNG PROPERTIES
40+
IMPORTED_LOCATION ${OpenRNG_LIBRARY}
41+
INTERFACE_INCLUDE_DIRECTORIES ${OpenRNG_INCLUDE_DIR})
42+
endif()

docs/building_the_project_with_dpcpp.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ The most important supported build options are:
115115
* - ENABLE_ARMPL_OMP
116116
- True, False
117117
- True
118+
* - ENABLE_ARMPL_OPENRNG
119+
- True, False
120+
- False
118121
* - ENABLE_ROCBLAS_BACKEND
119122
- True, False
120123
- False
@@ -334,6 +337,14 @@ ArmPL is to be used, ``-DARMPL_ROOT=<armpl_install_prefix>`` can be used.
334337
Default behavior is to used the OpenMP flavor of ArmPL libraries, this can be
335338
changed using the ``-DENABLE_ARMPL_OMP=True/False`` flag.
336339

340+
ArmPL bundles the OpenRNG project as its implementation of the random number
341+
generator interface. The oneMath ArmPL backend for the RNG domain can be built
342+
with the open-source version of OpenRNG in place of ArmPL. This build supports
343+
both aarch64 and x86_64 CPU architectures. When building oneMath with
344+
`-DTARGET_DOMAINS=rng -DENABLE_ARMPL_BACKEND=True` while ArmPL binaries are not
345+
available, the build will switch to using OpenRNG by default. The use of OpenRNG
346+
can also be forced with the option `-DENABLE_ARMPL_OPENRNG=True`.
347+
337348
.. _build_additional_options_dpcpp:
338349

339350
Additional Build Options

examples/rng/device/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# If users build more than one backend (i.e. mklcpu and mklgpu, or mklcpu and CUDA), they may need to
2424
# overwrite ONEAPI_DEVICE_SELECTOR in their environment to run on the desired backend
2525
set(DEVICE_FILTERS "")
26-
if(ENABLE_MKLCPU_BACKEND)
26+
if(ENABLE_MKLCPU_BACKEND OR ENABLE_ARMPL_BACKEND)
2727
list(APPEND DEVICE_FILTERS "opencl:cpu")
2828
endif()
2929
# RNG only supports mklcpu backend on Windows

examples/rng/run_time_dispatching/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# If users build more than one backend (i.e. mklcpu and mklgpu, or mklcpu and CUDA), they may need to
2424
# overwrite ONEAPI_DEVICE_SELECTOR in their environment to run on the desired backend
2525
set(DEVICE_FILTERS "")
26-
if(ENABLE_MKLCPU_BACKEND)
26+
if(ENABLE_MKLCPU_BACKEND OR ENABLE_ARMPL_BACKEND)
2727
list(APPEND DEVICE_FILTERS "opencl:cpu")
2828
endif()
2929
# RNG only supports mklcpu backend on Windows

include/oneapi/math/detail/backends_table.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ static std::map<domain, std::map<device, std::vector<const char*>>> libraries =
181181
{ { device::x86cpu,
182182
{
183183
#ifdef ONEMATH_ENABLE_MKLCPU_BACKEND
184-
LIB_NAME("rng_mklcpu")
184+
LIB_NAME("rng_mklcpu"),
185+
#endif
186+
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
187+
LIB_NAME("rng_armpl")
185188
#endif
186189
} },
187190
{ device::aarch64cpu,

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function(generate_header_file)
8989
set(ONEMATH_ENABLE_ROCBLAS_BACKEND ${ENABLE_ROCBLAS_BACKEND})
9090
set(ONEMATH_ENABLE_NETLIB_BACKEND ${ENABLE_NETLIB_BACKEND})
9191
set(ONEMATH_ENABLE_ARMPL_BACKEND ${ENABLE_ARMPL_BACKEND})
92+
set(ONEMATH_ENABLE_ARMPL_OPENRNG ${ENABLE_ARMPL_OPENRNG})
9293
set(ONEMATH_ENABLE_GENERIC_BLAS_BACKEND ${ENABLE_GENERIC_BLAS_BACKEND})
9394
set(ONEMATH_ENABLE_CURAND_BACKEND ${ENABLE_CURAND_BACKEND})
9495
set(ONEMATH_ENABLE_ROCRAND_BACKEND ${ENABLE_ROCRAND_BACKEND})

src/config.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define ONEMATH_CONFIG_H
2222

2323
#cmakedefine ONEMATH_ENABLE_ARMPL_BACKEND
24+
#cmakedefine ONEMATH_ENABLE_ARMPL_OPENRNG
2425
#cmakedefine ONEMATH_ENABLE_CUBLAS_BACKEND
2526
#cmakedefine ONEMATH_ENABLE_CUFFT_BACKEND
2627
#cmakedefine ONEMATH_ENABLE_CURAND_BACKEND

src/rng/backends/armpl/CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@
2121
set(LIB_NAME onemath_rng_armpl)
2222
set(LIB_OBJ ${LIB_NAME}_obj)
2323

24-
find_package(ARMPL REQUIRED)
24+
option(ENABLE_ARMPL_OPENRNG "Use the open-source OpenRNG library for ARMPL RNG backend" OFF)
25+
26+
if (ENABLE_ARMPL_OPENRNG)
27+
find_package(OpenRNG REQUIRED)
28+
else()
29+
find_package(ARMPL)
30+
if (NOT ARMPL_FOUND)
31+
message(STATUS "ARMPL not found, trying OpenRNG instead")
32+
set(ENABLE_ARMPL_OPENRNG ON CACHE BOOL "Use the open-source OpenRNG library for ARMPL RNG backend" FORCE)
33+
find_package(OpenRNG)
34+
endif()
35+
endif()
36+
37+
if (NOT ARMPL_FOUND AND NOT OpenRNG_FOUND)
38+
message(FATAL_ERROR "Could NOT find ARMPL or OpenRNG")
39+
endif()
2540

2641
set(SOURCES armpl_common.hpp
2742
philox4x32x10.cpp
@@ -45,7 +60,7 @@ if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
4560
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})
4661
endif()
4762

48-
target_link_libraries(${LIB_OBJ} PUBLIC ONEMATH::SYCL::SYCL ${ARMPL_LINK})
63+
target_link_libraries(${LIB_OBJ} PUBLIC ONEMATH::SYCL::SYCL $<IF:$<BOOL:${ENABLE_ARMPL_OPENRNG}>,ONEMATH::OpenRNG::OpenRNG,${ARMPL_LINK}>)
4964

5065
set_target_properties(${LIB_OBJ} PROPERTIES
5166
POSITION_INDEPENDENT_CODE ON

0 commit comments

Comments
 (0)