-
Notifications
You must be signed in to change notification settings - Fork 176
[RNG] add RNG armpl backend #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /******************************************************************************* | ||
| * 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 _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_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,8 @@ if(ENABLE_ROCRAND_BACKEND AND UNIX) | |
| add_subdirectory(rocrand) | ||
| endif() | ||
|
|
||
| if(ENABLE_ARMPL_BACKEND AND UNIX) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
||
|
|
||
| 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 | ||
| ) |
| 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_ |
| 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 | ||
| }; |
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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