Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ endif()
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CURAND_BACKEND
OR ENABLE_ROCRAND_BACKEND)
OR ENABLE_ROCRAND_BACKEND
OR ENABLE_ARMPL_BACKEND)
list(APPEND DOMAINS_LIST "rng")
endif()
if(ENABLE_MKLGPU_BACKEND
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,18 @@ Supported compilers include:
<td align="center">Dynamic, Static</td>
</tr>
<tr>
<td rowspan=4 align="center">RNG</td>
<td rowspan=5 align="center">RNG</td>
<td align="center">x86 CPU</td>
<td align="center">Intel(R) oneMKL</td>
<td align="center">Intel DPC++</br>AdaptiveCpp</td>
<td align="center">Dynamic, Static</td>
</tr>
<tr>
<td align="center">aarch64 CPU</td>
<td align="center">Arm Performance Libraries</td>
<td align="center">Open DPC++</br>AdaptiveCpp</td>
<td align="center">Dynamic, Static</td>
</tr>
<tr>
<td align="center">Intel GPU</td>
<td align="center">Intel(R) oneMKL</td>
Expand Down
6 changes: 6 additions & 0 deletions include/oneapi/math/detail/backends_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ static std::map<domain, std::map<device, std::vector<const char*>>> libraries =
{
#ifdef ONEMATH_ENABLE_MKLCPU_BACKEND
LIB_NAME("rng_mklcpu")
#endif
} },
{ device::aarch64cpu,
{
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
LIB_NAME("rng_armpl")
#endif
} },
{ device::intelgpu,
Expand Down
56 changes: 56 additions & 0 deletions include/oneapi/math/rng/detail/armpl/onemath_rng_armpl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright 2025 SiPearl
* Copyright 2020-2021 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why the Intel's copyright is added?

Copy link
Contributor Author

@adegomme adegomme Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello, most of these files have been duplicated from oneMKL backend, as implementation is roughly the same (OpenRNG from ArmPl is a drop-in replacement for Intel VSL, using same API. Some calls are not supported, others are added, so minor modifications were still necessary). So initial copyright was retained in these files. I can remove it if necessary, but I see this as derivative, so apache license says to retain them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. Let us take a closer look to determine whether this copyright is necessary or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We see no issues with that. Let's keep 2 copyrights in this and similar files

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/

#ifndef _ONEMATH_RNG_ARMPL_HPP_
#define _ONEMATH_RNG_ARMPL_HPP_

#include <cstdint>
#if __has_include(<sycl/sycl.hpp>)
#include <sycl/sycl.hpp>
#else
#include <CL/sycl.hpp>
#endif

#include "oneapi/math/detail/export.hpp"
#include "oneapi/math/rng/detail/engine_impl.hpp"

namespace oneapi {
namespace math {
namespace rng {
namespace armpl {

ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_philox4x32x10(sycl::queue queue,
std::uint64_t seed);

ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_philox4x32x10(
sycl::queue queue, std::initializer_list<std::uint64_t> seed);

ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_mrg32k3a(sycl::queue queue,
std::uint32_t seed);

ONEMATH_EXPORT oneapi::math::rng::detail::engine_impl* create_mrg32k3a(
sycl::queue queue, std::initializer_list<std::uint32_t> seed);

} // namespace armpl
} // namespace rng
} // namespace math
} // namespace oneapi

#endif //_ONEMATH_RNG_ARMPL_HPP_
20 changes: 20 additions & 0 deletions include/oneapi/math/rng/engines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#ifdef ONEMATH_ENABLE_ROCRAND_BACKEND
#include "oneapi/math/rng/detail/rocrand/onemath_rng_rocrand.hpp"
#endif
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
#include "oneapi/math/rng/detail/armpl/onemath_rng_armpl.hpp"
#endif

namespace oneapi {
namespace math {
Expand Down Expand Up @@ -103,6 +106,15 @@ class philox4x32x10 {
: pimpl_(rocrand::create_philox4x32x10(selector.get_queue(), seed)) {}
#endif

#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
philox4x32x10(backend_selector<backend::armpl> selector, std::uint64_t seed = default_seed)
: pimpl_(armpl::create_philox4x32x10(selector.get_queue(), seed)) {}

philox4x32x10(backend_selector<backend::armpl> selector,
std::initializer_list<std::uint64_t> seed)
: pimpl_(armpl::create_philox4x32x10(selector.get_queue(), seed)) {}
#endif

philox4x32x10(const philox4x32x10& other) {
pimpl_.reset(other.pimpl_.get()->copy_state());
}
Expand Down Expand Up @@ -192,6 +204,14 @@ class mrg32k3a {
: pimpl_(rocrand::create_mrg32k3a(selector.get_queue(), seed)) {}
#endif

#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
mrg32k3a(backend_selector<backend::armpl> selector, std::uint32_t seed = default_seed)
: pimpl_(armpl::create_mrg32k3a(selector.get_queue(), seed)) {}

mrg32k3a(backend_selector<backend::armpl> selector, std::initializer_list<std::uint32_t> seed)
: pimpl_(armpl::create_mrg32k3a(selector.get_queue(), seed)) {}
#endif

mrg32k3a(const mrg32k3a& other) {
pimpl_.reset(other.pimpl_.get()->copy_state());
}
Expand Down
5 changes: 5 additions & 0 deletions src/rng/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ if(ENABLE_ROCRAND_BACKEND AND UNIX)
add_subdirectory(rocrand)
endif()

if(ENABLE_ARMPL_BACKEND AND UNIX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is only supported for Linux, should https://github.com/uxlfoundation/oneMath/blob/develop/cmake/FindARMPL.cmake (or other cmake files) handle the case when ENABLE_ARMPL_BACKEND is specified on Windows to have a clear error message on the configuration stage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually discovered recently that there is an ArmPl version available for Windows/Arm platform, so it may actually work. I don't think I'll be able to try the setup with oneMath anytime soon though, so I'm fine adding a message here.

add_subdirectory(armpl)
endif()


76 changes: 76 additions & 0 deletions src/rng/backends/armpl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#===============================================================================
# Copyright 2025 SiPearl
# Copyright 2020-2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
#
#
# SPDX-License-Identifier: Apache-2.0
#===============================================================================

set(LIB_NAME onemath_rng_armpl)
set(LIB_OBJ ${LIB_NAME}_obj)

find_package(ARMPL REQUIRED)

set(SOURCES armpl_common.hpp
philox4x32x10.cpp
mrg32k3a.cpp
$<$<BOOL:${BUILD_SHARED_LIBS}>: armpl_rng_cpu_wrappers.cpp>
)

add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT ${SOURCES})
add_dependencies(onemath_backend_libs_rng ${LIB_NAME})
target_include_directories(${LIB_OBJ}
PRIVATE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/bin
${ARMPL_INCLUDE}
${ONEMATH_GENERATED_INCLUDE_PATH}
)

target_compile_options(${LIB_OBJ} PRIVATE ${ONEMATH_BUILD_COPT} ${ARMPL_COPT})
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})
endif()

target_link_libraries(${LIB_OBJ} PUBLIC ONEMATH::SYCL::SYCL ${ARMPL_LINK})

set_target_properties(${LIB_OBJ} PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
target_link_libraries(${LIB_NAME} PUBLIC ${LIB_OBJ})

# Set oneMATH libraries as not transitive for dynamic
if(BUILD_SHARED_LIBS)
set_target_properties(${LIB_NAME} PROPERTIES
INTERFACE_LINK_LIBRARIES ONEMATH::SYCL::SYCL
)
endif()

# Add major version to the library
set_target_properties(${LIB_NAME} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
)

# Add dependencies rpath to the library
list(APPEND CMAKE_BUILD_RPATH $<TARGET_FILE_DIR:${LIB_NAME}>)

# Add the library to install package
install(TARGETS ${LIB_OBJ} EXPORT oneMathTargets)
install(TARGETS ${LIB_NAME} EXPORT oneMathTargets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
86 changes: 86 additions & 0 deletions src/rng/backends/armpl/armpl_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright 2025 SiPearl
* Copyright 2020-2021 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/

#ifndef _RNG_CPU_COMMON_HPP_
#define _RNG_CPU_COMMON_HPP_

#if __has_include(<sycl/sycl.hpp>)
#include <sycl/sycl.hpp>
#else
#include <CL/sycl.hpp>
#endif

#define GET_MULTI_PTR template get_multi_ptr<sycl::access::decorated::yes>().get_raw()
#define __fp16 _Float16
#define INTEGER64 1

#include "armpl.h"

namespace oneapi {
namespace math {
namespace rng {
namespace armpl {

inline int check_armpl_version(armpl_int_t major_req, armpl_int_t minor_req, armpl_int_t build_req,
const char* message) {
armpl_int_t major, minor, build;
char* tag;
armplversion(&major, &minor, &build, (const char**)&tag);
if (major > major_req) {
return 0;
}
else if (major == major_req && minor > minor_req) {
return 0;
}
else if (major == major_req && minor == minor_req && build >= build_req) {
return 0;
}
throw oneapi::math::unimplemented("rng", "version support", message);
}

template <typename K, typename H, typename F>
static inline auto host_task_internal(H& cgh, F f, int) -> decltype(cgh.host_task(f)) {
return cgh.host_task(f);
}

template <typename K, typename H, typename F>
static inline void host_task_internal(H& cgh, F f, long) {
#ifndef __SYCL_DEVICE_ONLY__
cgh.template single_task<K>(f);
#endif
}

template <typename K, typename H, typename F>
static inline void host_task(H& cgh, F f) {
(void)host_task_internal<K>(cgh, f, 0);
}

template <typename Engine, typename Distr>
class kernel_name {};

template <typename Engine, typename Distr>
class kernel_name_usm {};

} // namespace armpl
} // namespace rng
} // namespace math
} // namespace oneapi

#endif //_RNG_CPU_COMMON_HPP_
30 changes: 30 additions & 0 deletions src/rng/backends/armpl/armpl_rng_cpu_wrappers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright 2025 SiPearl
* Copyright 2020-2021 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/

#include "rng/function_table.hpp"
#include "oneapi/math/rng/detail/armpl/onemath_rng_armpl.hpp"

#define WRAPPER_VERSION 1

extern "C" ONEMATH_EXPORT rng_function_table_t onemath_rng_table = {
WRAPPER_VERSION, oneapi::math::rng::armpl::create_philox4x32x10,
oneapi::math::rng::armpl::create_philox4x32x10, oneapi::math::rng::armpl::create_mrg32k3a,
oneapi::math::rng::armpl::create_mrg32k3a
};
Loading
Loading