Skip to content
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

Adding OpenRNG Backend #2871

Merged
merged 6 commits into from
Oct 1, 2024
Merged

Conversation

DhanusML
Copy link
Contributor

OpenRNG is an open-source Random Number Generator library developed at Arm. OpenRNG includes the interface to the random number generation part of the Vector Statistics Library (VSL) developed by Intel(R) and shipped for x86 processors as part of oneMKL. This PR adds an option to use OpenRNG as the RNG backend for oneDAL.

To build using OpenRNG backend follow these steps

.ci/scripts/build.sh --compiler gnu --optimizations sve --target onedal_c --backend-config ref  --plat lnxarm --use-openrng yes
.ci/scripts/build.sh --compiler gnu --optimizations sve --target daal --backend-config ref  --plat lnxarm --use-openrng yes

With this PR, OpenRNG backend becomes available for builds on arm machine with ref backend using gnu compiler. (For the other kinds of ref builds, support can be added in the future)

The script .ci/env/openrng.sh builds openrng at __deps/openrng. For more control over the build process, this script can be run before running the make command. While building using make, the variable RNG_BACKEND should be set to openrng for the build to use OpenRNG backend.

If openRNG is installed in a directory other than ./__deps/openrng, the environment variable OPENRNGROOT can be set before using the make command to specify the openRNG build directory.

@Alexandr-Solovev
Copy link
Contributor

/intelci: run

@DhanusML
Copy link
Contributor Author

DhanusML commented Sep 3, 2024

@Alexandr-Solovev, any feedbacks on this?

@Alexandr-Solovev
Copy link
Contributor

/intelci: run

To build using openrng backend follow these steps

.ci/scripts/build.sh --compiler gnu --optimizations sve \
    --target onedal_c --backend-config ref  --plat lnxarm --use-openrng yes
.ci/scripts/build.sh --compiler gnu --optimizations sve \
    --target daal --backend-config ref  --plat lnxarm --use-openrng yes

With this PR, openRNG backend becomes available for builds on
arm machine with ref backend using gnu compiler.
(For the other kinds of ref builds, support can be added in the future)

The script `.ci/env/openrng.sh` builds openrng at `__deps/openrng`.

For more control over the build process, this script can be run before
running the make command. While building using make, the variable
`RNG_BACKEND` should be set to `openrng` for the build to use openRNG backend.

If openRNG is installed in a directory other than `./__deps/openrng`,
the environment variable `OPENRNGROOT` can be set before using the make
command to specify the openRNG build directory.

Signed-off-by: Dhanus M Lal <[email protected]>
Signed-off-by: Dhanus M Lal <[email protected]>
{
services::Status s = allocSeeds(n);
if (s)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

What about just directly reporting an error here?

Copy link
Contributor Author

@DhanusML DhanusML Sep 12, 2024

Choose a reason for hiding this comment

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

I am not sure how to report an error in the constructor. I could throw an exception, but the calling functions may not have mechanisms to handle them. Also, this is exactly how the MKL backend handles it (in service_rng_mkl.h). In fact service_rng_openrng.h is a copy of service_rng_mkl.h, except for some minor changes.

services::Status s = allocSeeds(_seedSize);
if (s)
{
for (size_t i = 0; i < _seedSize; i++)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's just a matter of preferences but I would suggest to use correctly typed constants i.e. 0ul instead of an implicit conversion from 0 wherever it is posssible

@ethanglaser
Copy link
Contributor

/intelci: run

2 similar comments
@ethanglaser
Copy link
Contributor

/intelci: run

@ethanglaser
Copy link
Contributor

/intelci: run

@ethanglaser
Copy link
Contributor

Hi @DhanusML thanks for putting this together, in order to run our internal validation the fork name must be oneDAL or daal. Would you mind changing yours from oneDAL-dhanus to just oneDAL?

@DhanusML
Copy link
Contributor Author

Hi @DhanusML thanks for putting this together, in order to run our internal validation the fork name must be oneDAL or daal. Would you mind changing yours from oneDAL-dhanus to just oneDAL?

Done

@ethanglaser
Copy link
Contributor

/intelci: run

@ethanglaser
Copy link
Contributor

Please rebase your branch as well

@ethanglaser
Copy link
Contributor

/intelci: run

@ethanglaser
Copy link
Contributor

Changes look reasonable to me - but there is no validation from what I can tell. Perhaps it would make sense to add this flag to one of the ARM CI checks?

@@ -0,0 +1,393 @@
/* file: service_rng_openrng.h.h */
Copy link
Contributor

Choose a reason for hiding this comment

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

service_rng_openrng.h

int nb = len / 2;
int nn = (int)n;
int * rr = (int *)r;
__DAAL_VSLFN_CALL_NR_WHILE(, viRngUniform, (method, stream, nn, rr, na, nb), errcode);
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you use DAAL macros in this file? Are you sure that it will be opened and work as expected? Can it be replaced with the direct call of openrng functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be replaced with direct calls to openrng functions. It works as expected using daal macros (from service_stat_rng_ref.h) but, I will change them to direct function calls for the sake of readability.

int nb = len / 2;
int nn = (int)n;
int * rr = (int *)r;
__DAAL_VSLFN_CALL_NR_WHILE(, viRngUniform, (method, stream, nn, rr, na, nb), errcode);
Copy link
Contributor

Choose a reason for hiding this comment

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

should the method and n be casted to openrng_int_t?

@@ -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 with the `ref` backend.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
--use-openrng:Set this to yes if openrng is to be used as RNG backend. Use this with the `ref` backend.
--use-openrng:Set this to yes if openrng is to be used as RNG backend. Use this only with the `ref` backend.

makefile Outdated
Comment on lines 58 to 60
ifeq ($(RNG_BACKEND), openrng)
RNG_OPENRNG := yes
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

RNG_BACKEND variable should be one of mkl, ref and openrng with default value dependent on platform type.

DhanusML and others added 3 commits September 27, 2024 15:32
setting RNG_BACKEND variable based on the backend config in makefile.

Signed-off-by: Dhanus M Lal <[email protected]>
@napetrov
Copy link
Contributor

/intelci: run

Copy link
Contributor

@Alexandr-Solovev Alexandr-Solovev left a comment

Choose a reason for hiding this comment

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

LGTM

@Alexsandruss Alexsandruss merged commit 7f05e43 into oneapi-src:main Oct 1, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants