diff --git a/.ci/env/openrng.sh b/.ci/env/openrng.sh new file mode 100755 index 00000000000..a4f4dfd2ed4 --- /dev/null +++ b/.ci/env/openrng.sh @@ -0,0 +1,69 @@ +#!/bin/bash +#=============================================================================== +# Copyright contributors to the oneDAL project +# +# 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. +#=============================================================================== + +SCRIPT_PATH=$(readlink -f "${BASH_SOURCE[0]}") +SCRIPT_DIR=$(dirname "${SCRIPT_PATH}") +ONEDAL_DIR=$(readlink -f "${SCRIPT_DIR}/../..") +OPENRNG_DEFAULT_SOURCE_DIR="${ONEDAL_DIR}/__work/openrng" + +show_help() { + echo "Usage: $0 [--help]" + column -t -s":" <<< '--help:Display this information +--rng-src:The path to an existing OpenRNG source dircetory. The source is cloned if this parameter is omitted +--prefix:The path where OpenRNG will be installed +' +} + +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + --rng-src) + rng_src_dir="$2" + shift;; + --prefix) + PREFIX="$2" + shift;; + --help) + show_help + exit 0 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac + shift +done + +OPENRNG_DEFAULT_PREFIX="${ONEDAL_DIR}"/__deps/openrng +rng_prefix="${PREFIX:-${OPENRNG_DEFAULT_PREFIX}}" + +rng_src_dir=${rng_src_dir:-$OPENRNG_DEFAULT_SOURCE_DIR} +if [[ ! -d "${rng_src_dir}" ]] ; then + git clone https://git.gitlab.arm.com/libraries/openrng.git "${rng_src_dir}" +fi + +echo $rng_src_dir +echo $rng_prefix +pushd "${rng_src_dir}" + rm -rf build + mkdir build + pushd build + cmake -DCMAKE_INSTALL_PREFIX="${rng_prefix}" ./../ + make install + popd +popd diff --git a/.ci/scripts/build.sh b/.ci/scripts/build.sh index 47bd0b81e57..f9c25245483 100755 --- a/.ci/scripts/build.sh +++ b/.ci/scripts/build.sh @@ -34,6 +34,7 @@ show_help() { --plat:The platform to build for. This is passed to the oneDAL top level Makefile --blas-dir:The BLAS installation directory to use to build oneDAL with in the case that the backend is given as `ref`. If the installation directory does not exist, attempts to build this from source --tbb-dir:The TBB installation directory to use to build oneDAL with in the case that the backend is given as `ref`. If the installation directory does not exist, attempts to build this from source +--use-openrng:Set this to yes if openrng is to be used as RNG backend. Use this only with the `ref` backend. --sysroot:The sysroot to use, in the case that clang is used as the cross-compiler ' } @@ -72,6 +73,9 @@ while [[ $# -gt 0 ]]; do --sysroot) sysroot="$2" shift;; + --use-openrng) + use_openrng="$2" + shift;; --help) show_help exit 0 @@ -186,6 +190,14 @@ elif [ "${backend_config}" == "ref" ]; then "${ONEDAL_DIR}"/.ci/env/openblas.sh "${openblas_options[@]}" fi export OPENBLASROOT="${ONEDAL_DIR}/__deps/openblas_${ARCH}" + if [ "${use_openrng}" == "yes" ]; then + echo "Sourcing ref(openrng) env" + if [ ! -d "${ONEDAL_DIR}"/__deps/openrng ]; then + echo "${ONEDAL_DIR}"/.ci/env/openrng.sh + "${ONEDAL_DIR}"/.ci/env/openrng.sh + fi + export OPENRNGROOT="${ONEDAL_DIR}"/__deps/openrng + fi else echo "Not supported backend env" fi @@ -231,6 +243,10 @@ if [ "${cross_compile}" == "yes" ] && [ "${compiler}" == "clang" ] ; then make_options+=(SYSROOT="${sysroot}") fi +if [ "${use_openrng}" == "yes" ]; then + make_options+=(RNG_BACKEND=openrng) +fi + echo "Calling make" echo "CXX=$CXX" echo "CC=$CC" diff --git a/cpp/daal/src/externals/service_rng_openrng.h b/cpp/daal/src/externals/service_rng_openrng.h new file mode 100644 index 00000000000..dd70c644606 --- /dev/null +++ b/cpp/daal/src/externals/service_rng_openrng.h @@ -0,0 +1,392 @@ +/* file: service_rng_openrng.h */ +/******************************************************************************* +* Copyright contributors to the oneDAL project +* +* 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. +*******************************************************************************/ + +#ifndef __SERVICE_RNG_OPENRNG_H__ +#define __SERVICE_RNG_OPENRNG_H__ + +#include "openrng.h" +#include "src/externals/service_rng_common.h" + +// RNGs +#define __DAAL_BRNG_MT2203 VSL_BRNG_MT2203 +#define __DAAL_BRNG_MT19937 VSL_BRNG_MT19937 +#define __DAAL_BRNG_MCG59 VSL_BRNG_MCG59 +#define __DAAL_RNG_METHOD_UNIFORM_STD VSL_RNG_METHOD_UNIFORM_STD +#define __DAAL_RNG_METHOD_UNIFORMBITS32_STD 0 +#define __DAAL_RNG_METHOD_BERNOULLI_ICDF VSL_RNG_METHOD_BERNOULLI_ICDF +#define __DAAL_RNG_METHOD_GAUSSIAN_BOXMULLER VSL_RNG_METHOD_GAUSSIAN_BOXMULLER +#define __DAAL_RNG_METHOD_GAUSSIAN_BOXMULLER2 VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2 +#define __DAAL_RNG_METHOD_GAUSSIAN_ICDF VSL_RNG_METHOD_GAUSSIAN_ICDF + +namespace daal +{ +namespace internal +{ +namespace ref +{ +/* Uniform distribution generator functions */ +template +int uniformRNG(const size_t n, T * r, void * stream, const T a, const T b, const int method); + +template +int uniformRNG(const size_t cn, size_t * r, void * stream, const size_t a, const size_t b, const int method) +{ + size_t n = cn; + int errcode = 0; + + if (a >= b) + { + return -3; + } + + if (sizeof(size_t) == sizeof(unsigned int)) + { + size_t len = b - a; + int na = -(len / 2 + len % 2); + int nb = len / 2; + openrng_int_t nn = (openrng_int_t)n; + int * rr = (int *)r; + errcode = viRngUniform((openrng_int_t)method, stream, nn, rr, na, nb); + + if (errcode != 0) + { + return errcode; + } + + size_t shift = a - na; + for (size_t i = 0; i < n; i++) + { + r[i] = r[i] + shift; + } + } + else + { + // works only for case when sizeof(size_t) > sizeof(unsigned int) + if (b - a < ((size_t)1 << sizeof(size_t) * 8 / 2)) + { + size_t len = b - a; + int na = -(len / 2 + len % 2); + int nb = len / 2; + openrng_int_t nn = (openrng_int_t)n; + int * rr = (int *)r + n; + errcode = viRngUniform((openrng_int_t)method, stream, nn, rr, na, nb); + + if (errcode != 0) + { + return errcode; + } + + rr = (int *)r + n; + size_t shift = a - na; + for (size_t i = 0; i < n; i++) + { + r[i] = rr[i] + shift; + } + } + else + { + unsigned __int64 * cr = (unsigned __int64 *)r; + + size_t len = b - a; + size_t rem = (size_t)(-1) % len; + rem = (rem + 1) % len; + size_t MAX = -rem; + long double dv = 0.0; + + if (MAX == 0) + { + dv = len; + for (int i = 0; i < 64; i++) dv /= 2.0; + openrng_int_t nn = (openrng_int_t)n; + unsigned __int64 * rr = cr; + errcode = viRngUniformBits64((openrng_int_t)method, stream, nn, rr); + + if (errcode != 0) + { + return errcode; + } + } + else + { + dv = (long double)len / MAX; + size_t pos = 0; + while (pos < cn) + { + n = cn - pos; + openrng_int_t nn = (openrng_int_t)n; + unsigned __int64 * rr = cr + pos; + errcode = viRngUniformBits64((openrng_int_t)method, stream, nn, rr); + + if (errcode != 0) + { + return errcode; + } + + for (size_t i = pos; i < cn; i++) + { + if (cr[i] < MAX) + { + cr[pos++] = cr[i]; + } + } + } + } + + for (size_t i = 0; i < cn; i++) + { + cr[i] = a + cr[i] * dv; + } + } + } + + return errcode; +} + +template +int uniformRNG(const size_t n, int * r, void * stream, const int a, const int b, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + int * rr = r; + errcode = viRngUniform((openrng_int_t)method, stream, nn, rr, a, b); + return errcode; +} + +template +int uniformRNG(const size_t n, float * r, void * stream, const float a, const float b, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + float * rr = r; + errcode = vsRngUniform((openrng_int_t)method, stream, nn, rr, a, b); + return errcode; +} + +template +int uniformRNG(const size_t n, double * r, void * stream, const double a, const double b, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + double * rr = r; + errcode = vdRngUniform((openrng_int_t)method, stream, nn, rr, a, b); + return errcode; +} + +template +int uniformBits32RNG(const size_t n, unsigned int * r, void * stream, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + unsigned int * rr = r; + errcode = viRngUniformBits32((openrng_int_t)method, stream, nn, rr); + return errcode; +} + +/* Gaussian distribution generator functions */ +template +int gaussianRNG(const size_t n, T * r, void * stream, const T a, const T sigma, const int method); + +template +int gaussianRNG(const size_t n, float * r, void * stream, const float a, const float sigma, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + float * rr = r; + errcode = vsRngGaussian((openrng_int_t)method, stream, nn, rr, a, sigma); + return errcode; +} + +template +int gaussianRNG(const size_t n, double * r, void * stream, const double a, const double sigma, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + double * rr = r; + errcode = vdRngGaussian((openrng_int_t)method, stream, nn, rr, a, sigma); + return errcode; +} + +/* Bernoulli distribution generator functions */ +template +int bernoulliRNG(const size_t n, T * r, void * stream, const double p, const int method); + +template +int bernoulliRNG(const size_t n, int * r, void * stream, const double p, const int method) +{ + int errcode = 0; + openrng_int_t nn = (openrng_int_t)n; + int * rr = r; + errcode = viRngBernoulli((openrng_int_t)method, stream, nn, rr, p); + return errcode; +} + +template +class BaseRNG : public BaseRNGIface +{ +public: + BaseRNG(const unsigned int seed, const int brngId) : _stream(0), _seed(nullptr), _seedSize(0), _brngId(brngId) + { + services::Status s = allocSeeds(1); + if (s) + { + _seed[0] = seed; + int errcode = 0; + errcode = vslNewStreamEx(&_stream, (openrng_int_t)brngId, 1, &seed); + } + } + + BaseRNG(const size_t n, const unsigned int * seed, const int brngId = __DAAL_BRNG_MT19937) + : _stream(0), _seed(nullptr), _seedSize(0), _brngId(brngId) + { + services::Status s = allocSeeds(n); + if (s) + { + if (seed) + { + for (size_t i = 0; i < n; i++) + { + _seed[i] = seed[i]; + } + } + int errcode = 0; + errcode = vslNewStreamEx(&_stream, (openrng_int_t)brngId, (openrng_int_t)n, seed); + } + } + + BaseRNG(const BaseRNG & other) : _stream(0), _seed(nullptr), _seedSize(other._seedSize), _brngId(other._brngId) + { + services::Status s = allocSeeds(_seedSize); + if (s) + { + for (size_t i = 0; i < _seedSize; i++) + { + _seed[i] = other._seed[i]; + } + int errcode = 0; + errcode = vslNewStreamEx(&_stream, _brngId, _seedSize, _seed); + if (!errcode) errcode = vslCopyStreamState(_stream, other._stream); + } + } + + ~BaseRNG() + { + daal::services::daal_free((void *)_seed); + int errcode = 0; + errcode = vslDeleteStream(&_stream); + } + + int getStateSize() const + { + int res = 0; + res = vslGetStreamSize(_stream); + return res; + } + + int saveState(void * dest) const + { + int errcode = 0; + errcode = vslSaveStreamM(_stream, (char *)dest); + return errcode; + } + + int loadState(const void * src) + { + int errcode = 0; + errcode = vslDeleteStream(&_stream); + if (!errcode) errcode = vslLoadStreamM(&_stream, (const char *)src); + return errcode; + } + + int leapfrog(size_t threadNum, size_t nThreads) + { + int errcode = 0; + errcode = vslLeapfrogStream(_stream, (openrng_int_t)threadNum, (openrng_int_t)nThreads); + return errcode; + } + + int skipAhead(size_t nSkip) + { + int errcode = 0; + errcode = vslSkipAheadStream(_stream, (long long int)nSkip); + return errcode; + } + + void * getState() { return _stream; } + +protected: + services::Status allocSeeds(const size_t n) + { + _seedSize = n; + _seed = (unsigned int *)daal::services::daal_malloc(sizeof(unsigned int) * n); + DAAL_CHECK_MALLOC(_seed); + return services::Status(); + } + +private: + void * _stream; + unsigned int * _seed; + size_t _seedSize; + const int _brngId; +}; + +/* +// Generator functions definition +*/ +template +class RNGs +{ +public: + typedef DAAL_INT SizeType; + typedef BaseRNG BaseType; + + RNGs() {} + + int uniform(const SizeType n, Type * r, BaseType & brng, const Type a, const Type b, const int method) + { + return uniformRNG(n, r, brng.getState(), a, b, method); + } + + int uniform(const SizeType n, Type * r, void * state, const Type a, const Type b, const int method) + { + return uniformRNG(n, r, state, a, b, method); + } + + int uniformBits32(const SizeType n, Type * r, void * state, const int method) { return uniformBits32RNG(n, r, state, method); } + + int bernoulli(const SizeType n, Type * r, BaseType & brng, const double p, const int method) + { + return bernoulliRNG(n, r, brng.getState(), p, method); + } + + int bernoulli(const SizeType n, Type * r, void * state, const double p, const int method) { return bernoulliRNG(n, r, state, p, method); } + + int gaussian(const SizeType n, Type * r, BaseType & brng, const Type a, const Type sigma, const int method) + { + return gaussianRNG(n, r, brng.getState(), a, sigma, method); + } + + int gaussian(const SizeType n, Type * r, void * state, const Type a, const Type sigma, const int method) + { + return gaussianRNG(n, r, state, a, sigma, method); + } +}; + +} // namespace ref +} // namespace internal +} // namespace daal + +#endif diff --git a/cpp/daal/src/externals/service_rng_ref.h b/cpp/daal/src/externals/service_rng_ref.h index 40e1dfd2c28..fc56fcf6205 100644 --- a/cpp/daal/src/externals/service_rng_ref.h +++ b/cpp/daal/src/externals/service_rng_ref.h @@ -1,6 +1,7 @@ /* file: service_rng_ref.h */ /******************************************************************************* * Copyright 2023 Intel Corporation +* Copyright contributors to the oneDAL project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,21 +25,27 @@ #ifndef __SERVICE_RNG_REF_H__ #define __SERVICE_RNG_REF_H__ -#include "src/externals/service_rng_common.h" -#include "services/error_indexes.h" -#include +#ifdef OPENRNG_BACKEND -// RNGs -#define __DAAL_BRNG_MT2203 (1 << 20) * 9 //VSL_BRNG_MT2203 -#define __DAAL_BRNG_MT19937 (1 << 20) * 8 //VSL_BRNG_MT19937 -#define __DAAL_BRNG_MCG59 (1 << 20) * 4 //VSL_BRNG_MCG59 + #include "service_rng_openrng.h" -#define __DAAL_RNG_METHOD_UNIFORM_STD 0 //VSL_RNG_METHOD_UNIFORM_STD -#define __DAAL_RNG_METHOD_UNIFORMBITS32_STD 4 -#define __DAAL_RNG_METHOD_BERNOULLI_ICDF 0 //VSL_RNG_METHOD_BERNOULLI_ICDF -#define __DAAL_RNG_METHOD_GAUSSIAN_BOXMULLER 0 //VSL_RNG_METHOD_GAUSSIAN_BOXMULLER -#define __DAAL_RNG_METHOD_GAUSSIAN_BOXMULLER2 1 //VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2 -#define __DAAL_RNG_METHOD_GAUSSIAN_ICDF 2 //VSL_RNG_METHOD_GAUSSIAN_ICDF +#else + + #include "src/externals/service_rng_common.h" + #include "services/error_indexes.h" + #include + + // RNGs + #define __DAAL_BRNG_MT2203 (1 << 20) * 9 //VSL_BRNG_MT2203 + #define __DAAL_BRNG_MT19937 (1 << 20) * 8 //VSL_BRNG_MT19937 + #define __DAAL_BRNG_MCG59 (1 << 20) * 4 //VSL_BRNG_MCG59 + + #define __DAAL_RNG_METHOD_UNIFORM_STD 0 //VSL_RNG_METHOD_UNIFORM_STD + #define __DAAL_RNG_METHOD_UNIFORMBITS32_STD 4 + #define __DAAL_RNG_METHOD_BERNOULLI_ICDF 0 //VSL_RNG_METHOD_BERNOULLI_ICDF + #define __DAAL_RNG_METHOD_GAUSSIAN_BOXMULLER 0 //VSL_RNG_METHOD_GAUSSIAN_BOXMULLER + #define __DAAL_RNG_METHOD_GAUSSIAN_BOXMULLER2 1 //VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2 + #define __DAAL_RNG_METHOD_GAUSSIAN_ICDF 2 //VSL_RNG_METHOD_GAUSSIAN_ICDF namespace daal { @@ -55,24 +62,24 @@ class StateIface { public: virtual ~StateIface() {} - virtual int uniformRNG(const size_t n, size_t * r, const size_t a, const size_t b, const int method) = 0; - virtual int uniformRNG(const size_t n, int * r, const int a, const int b, const int method) = 0; - virtual int uniformRNG(const size_t n, float * r, const float a, const float b, const int method) = 0; - virtual int uniformRNG(const size_t n, double * r, const double a, const double b, const int method) = 0; - virtual int gaussianRNG(const size_t n, float * r, const float a, const float sigma, const int method) = 0; + virtual int uniformRNG(const size_t n, size_t * r, const size_t a, const size_t b, const int method) = 0; + virtual int uniformRNG(const size_t n, int * r, const int a, const int b, const int method) = 0; + virtual int uniformRNG(const size_t n, float * r, const float a, const float b, const int method) = 0; + virtual int uniformRNG(const size_t n, double * r, const double a, const double b, const int method) = 0; + virtual int gaussianRNG(const size_t n, float * r, const float a, const float sigma, const int method) = 0; virtual int gaussianRNG(const size_t n, double * r, const double a, const double sigma, const int method) = 0; - virtual int bernoulliRNG(const size_t n, int * r, const double p, const int method) = 0; - virtual int getSize() = 0; - virtual void clone(void * dest) const = 0; - virtual StateIface * clone() const = 0; - virtual void assign(const void * src) = 0; - virtual void discard(size_t nSkip) = 0; + virtual int bernoulliRNG(const size_t n, int * r, const double p, const int method) = 0; + virtual int getSize() = 0; + virtual void clone(void * dest) const = 0; + virtual StateIface * clone() const = 0; + virtual void assign(const void * src) = 0; + virtual void discard(size_t nSkip) = 0; }; template class State : public StateIface { - using ThisType = State; + using ThisType = State; static constexpr unsigned int elSize = sizeof(unsigned int); public: @@ -124,20 +131,20 @@ class State : public StateIface int getSize() final { return sizeof(ThisType); } void clone(void * dest) const final { - State * destState = static_cast(dest); + State * destState = static_cast(dest); destState->_seedSize = _seedSize; - destState->_brngId = _brngId; - destState->_nSkip = _nSkip; - destState->_seed = (unsigned int *)daal::services::daal_malloc(sizeof(unsigned int) * destState->_seedSize); + destState->_brngId = _brngId; + destState->_nSkip = _nSkip; + destState->_seed = (unsigned int *)daal::services::daal_malloc(sizeof(unsigned int) * destState->_seedSize); daal::services::daal_memcpy_s(destState->_seed, destState->_seedSize * elSize, _seed, _seedSize * elSize); } StateIface * clone() const final { return new ThisType(*this); } void assign(const void * src) final { const State * srcState = static_cast(src); - _seedSize = srcState->_seedSize; - _brngId = srcState->_brngId; - _nSkip = srcState->_nSkip; + _seedSize = srcState->_seedSize; + _brngId = srcState->_brngId; + _nSkip = srcState->_nSkip; if (_seed) { daal::services::daal_free((void *)_seed); @@ -344,4 +351,5 @@ class RNGs } // namespace internal } // namespace daal +#endif // openrng #endif diff --git a/dev/make/compiler_definitions/gnu.ref.arm.mk b/dev/make/compiler_definitions/gnu.ref.arm.mk index bf7379cc8bc..a78f213183a 100644 --- a/dev/make/compiler_definitions/gnu.ref.arm.mk +++ b/dev/make/compiler_definitions/gnu.ref.arm.mk @@ -23,7 +23,7 @@ include dev/make/compiler_definitions/gnu.mk PLATs.gnu = lnxarm COMPILER.all.gnu = ${CXX} -march=armv8-a+sve -fwrapv -fno-strict-overflow -fno-delete-null-pointer-checks \ - -DDAAL_REF -DONEDAL_REF -DDAAL_CPU=sve -Werror -Wreturn-type + -DDAAL_REF -DONEDAL_REF -DDAAL_CPU=sve -Werror -Wreturn-type $(if $(RNG_OPENRNG), -DOPENRNG_BACKEND) link.dynamic.all.gnu = ${CXX} -march=native diff --git a/dev/make/deps.ref.mk b/dev/make/deps.ref.mk index 7d240eb8f8d..9cfdcf719af 100644 --- a/dev/make/deps.ref.mk +++ b/dev/make/deps.ref.mk @@ -1,5 +1,6 @@ #=============================================================================== # Copyright 2023 Intel Corporation +# Copyright contributors to the oneDAL project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,6 +31,19 @@ daaldep.math_backend.seq := $(OPENBLASDIR.libia)/libopenblas.$a daaldep.math_backend.incdir := $(OPENBLASDIR.include) daaldep.math_backend_oneapi.incdir := $(OPENBLASDIR.include) +ifeq ($(RNG_OPENRNG), yes) + OPENRNGDIR:= $(if $(wildcard $(DIR)/__deps/openrng/*),$(DIR)/__deps/openrng, \ + $(if $(wildcard $(OPENRNGROOT)/include/*),$(subst \,/,$(OPENRNGROOT)), \ + $(error Can`t find OPENRNG libs in $(DIR)/__deps/openrng or OPENRNGROOT))) + OPENRNGDIR.include := $(OPENRNGDIR)/include + OPENRNGDIR.libia := $(OPENRNGDIR)/lib + + daaldep.rng_backend.incdir := $(OPENRNGDIR.include) + daaldep.rng_backend.lib := $(OPENRNGDIR.libia)/libopenrng.$a + + daaldep.math_backend.incdir += $(daaldep.rng_backend.incdir) +endif + daaldep.math_backend.ext := $(daaldep.math_backend.thr) daaldep.math_backend.sycl := $(daaldep.math_backend.thr) daaldep.math_backend.oneapi := $(daaldep.math_backend.thr) diff --git a/dev/make/function_definitions/lnx32e.mk b/dev/make/function_definitions/lnx32e.mk index ea5e759520a..9df4c046531 100644 --- a/dev/make/function_definitions/lnx32e.mk +++ b/dev/make/function_definitions/lnx32e.mk @@ -28,6 +28,7 @@ define set_daal_rt_deps -lpthread $$(daaldep.lnx32e.rt.$$(COMPILER)) \ $$(if $$(COV.libia),$$(COV.libia)/libcov.a)) $$(eval daaldep.lnx32e.rt.seq := -lpthread $$(daaldep.lnx32e.rt.$$(COMPILER)) \ + $$(if $$(RNG_OPENRNG), $$(daaldep.rng_backend.lib)) \ $$(if $$(COV.libia),$$(COV.libia)/libcov.a)) $$(eval daaldep.lnx32e.rt.dpc := -lpthread -lOpenCL \ $$(if $$(COV.libia),$$(COV.libia)/libcov.a)) diff --git a/dev/make/function_definitions/lnxarm.mk b/dev/make/function_definitions/lnxarm.mk index c44df217e03..c282df31398 100644 --- a/dev/make/function_definitions/lnxarm.mk +++ b/dev/make/function_definitions/lnxarm.mk @@ -28,6 +28,7 @@ define set_daal_rt_deps -lpthread $$(daaldep.lnxarm.rt.$$(COMPILER)) \ $$(if $$(COV.libia),$$(COV.libia)/libcov.a)) $$(eval daaldep.lnxarm.rt.seq := -lpthread $$(daaldep.lnxarm.rt.$$(COMPILER)) \ + $$(if $$(RNG_OPENRNG), $$(daaldep.rng_backend.lib)) \ $$(if $$(COV.libia),$$(COV.libia)/libcov.a)) $$(eval daaldep.lnxarm.rt.dpc := -lpthread -lOpenCL \ $$(if $$(COV.libia),$$(COV.libia)/libcov.a)) diff --git a/makefile b/makefile index 9a9c8be5e6a..2984ec4eba9 100644 --- a/makefile +++ b/makefile @@ -274,6 +274,23 @@ releasetbb.LIBS_Y := $(TBBDIR.soia)/$(plib)tbb$(if $(OS_is_win),12$(dtbb),).$(y) #============================= Math backend folders ===================================== +ifeq ($(BACKEND_CONFIG), ref) + ifeq ($(RNG_BACKEND), openrng) + RNG_OPENRNG := yes + endif + ifndef RNG_BACKEND + RNG_BACKEND := ref + endif + $(if $(filter $(RNG_BACKEND),ref openrng),,$(error unknown rng backend $(RNG_BACKEND))) +endif + +ifeq ($(BACKEND_CONFIG), mkl) + ifndef RNG_BACKEND + RNG_BACKEND := mkl + endif + $(if $(filter $(RNG_BACKEND),mkl),,$(error mkl backend does not support the rng backend $(RNG_BACKEND))) +endif + include dev/make/deps.$(BACKEND_CONFIG).mk #===============================================================================