-
Notifications
You must be signed in to change notification settings - Fork 219
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
feature: rng primitive refactoring #3040
base: main
Are you sure you want to change the base?
feature: rng primitive refactoring #3040
Conversation
/intelci: run |
/intelci: run |
/intelci: run |
/intelci: run |
/intelci: run |
/intelci: run |
/intelci: run |
/intelci: run |
cpp/daal/src/algorithms/engines/mrg32k3a/mrg32k3a_batch_container.h
Outdated
Show resolved
Hide resolved
cpp/oneapi/dal/backend/primitives/rng/dpc_engine_collection.hpp
Outdated
Show resolved
Hide resolved
/intelci: run |
/// @param[in] queue The SYCL queue used to manage device operations. | ||
/// @param[in] seed The initial seed for the random number generator. Defaults to `777`. |
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.
Please move those to the constructor's description.
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.
It would be also good to provide the descriptions to every public method, not only to the class.
seed_(seed) { | ||
engines_.reserve(count_); | ||
for (Size i = 0; i < count_; ++i) { | ||
engines_.push_back(dpc_engine<EngineType>(queue, seed_)); |
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.
This initialization looks meaningless for mt2203. Because different engine_idx
should also be provided to have independent sequences of random numbers:
https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2023-0/oneapi-mkl-rng-mt2203.html
/intelci: run |
/// | ||
/// @tparam EngineType The RNG engine type to be used. Defaults to `engine_method::mt2203`. | ||
/// | ||
/// @param[in] seed The initial seed for the random number generator. Defaults to `777`. |
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.
The came comment as for dpc_engine
apply here: need to add descriptions to the methods and functions; need to fix rule of five.
/intelci: run |
/intelci: run |
1 similar comment
/intelci: run |
/intelci: run |
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.
This is a review just for the DAAL side of things, will do a second review for the DAL side. DAAL looks rather straightforward, and looks as though oneDAL requires the most attention.
@@ -0,0 +1,183 @@ | |||
/* file: mrg32k3a.h */ | |||
/******************************************************************************* | |||
* Copyright contributors to the oneDAL project |
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.
The files in cpp/daal/include/*
seems to follow exactly the layout of the other RNG engines, so I have glanced through to make sure that they are the same, but didn't look super close. @Alexandr-Solovev let me know if there is anything specific to mrg32k3a
or philox4x32x10
in these folders that are different. This implies that there isn't any architectural change to the RNG engines on the DAAL side of things outside of the inclusion of the two new ones. Is that so? (on second glance, it looks that we are doing a better standardization of the error codes, but thats it?)
@@ -0,0 +1,60 @@ | |||
/* file: mrg32k3a.cpp */ |
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.
Overall structure in the daal/src/*
also looks to match. I will focus on reviewing the batch_impl.h
files.
{ | ||
switch (technique) | ||
{ | ||
case engines::internal::family: return false; |
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.
Not anything you need to change in your PR, but I find it a bit odd that all of the RNGs in DAAL define or try unused skipping methods entirely even if the technique isn't known to be implemented (i.e. false) rather than just setting the errorcode directly. Am I misunderstanding things?
@@ -19,8 +19,8 @@ | |||
// Declaration of template function that calculate mt2203s. | |||
//-- | |||
|
|||
#ifndef __MCG59_KERNEL_H__ |
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.
This is crazy, especially for something that is so widely used in the codebase. Good catch.
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
|
||
template <engine_type EngineType = engine_type::mt2203> |
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.
Will the change of default engine be left for a different PR?
/// Constructor that initializes the mt2203 generator for use on the GPU. | ||
/// @param[in] queue The SYCL queue to manage device operations. | ||
/// @param[in] seed The initial seed for the generator. | ||
gen_mt2203(sycl::queue queue, std::int64_t seed) : _gen(queue, seed, 0) {} |
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.
One more parameter should be added to the constructor.
Because mt2203 is a set of 6024 Mersenne Twister RNGs.
gen_mt2203(sycl::queue queue, std::int64_t seed) : _gen(queue, seed, 0) {} | |
gen_mt2203(sycl::queue queue, std::int64_t seed, std::int64_t engine_idx = 0) : _gen(queue, seed, engine_idx) {} |
for (std::int64_t i = 0; i < count_; ++i) { | ||
engines_.push_back(device_engine<EngineType>(queue, base_seed_ + i)); | ||
} |
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.
More correctly will be to initialize the collection with the different RNGs for mt2203:
for (std::int64_t i = 0; i < count_; ++i) { | |
engines_.push_back(device_engine<EngineType>(queue, base_seed_ + i)); | |
} | |
if (EngineType == engine_type::mt2203) | |
{ | |
for (std::int64_t i = 0; i < count_; ++i) { | |
engines_.push_back(device_engine<EngineType>(queue, base_seed_, i)); | |
} | |
} | |
else | |
{ | |
for (std::int64_t i = 0; i < count_; ++i) { | |
engines_.push_back(device_engine<EngineType>(queue, base_seed_ + i)); | |
} | |
} |
throw domain_error(dal::detail::error_messages::unsupported_data_type()); | ||
} | ||
oneapi::mkl::rng::uniform<Type> distr(a, b); | ||
auto event = generate_rng(distr, engine_, count, dst, deps); |
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.
Why not returning the event?
Skip ahead for CPU can be just moved upper in the code.
} | ||
} | ||
|
||
explicit host_engine(const daal::algorithms::engines::EnginePtr& eng) : host_engine_(eng) { |
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.
I do not think that this is a proper fix to rule of three. Because a copy constructor should accept the object of the same type host_engine
.
engine_.skip_ahead_cpu(count); | ||
} | ||
|
||
//Currently only CPU impl |
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.
Please add more meaningful comments.
What is the buffer
is not obvious, for example.
//Currently only CPU impl | |
/// Generates a sequence of uniformly distributed random numbers from the interval [a, b). | |
/// The numbers in the sequence do not repeat. | |
/// In current version the data generation is only available on CPU. | |
/// | |
/// @tparam Type ... | |
/// | |
/// @param queue ... |
/intelci: run |
Description
Add a comprehensive description of proposed changes
List associated issue number(s) if exist(s): #6 (for example)
Documentation PR (if needed): #1340 (for example)
Benchmarks PR (if needed): IntelPython/scikit-learn_bench#155 (for example)
PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.
You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).
Checklist to comply with before moving PR from draft:
PR completeness and readability
Testing
Performance