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

Rework ops.random.Uniform #2531

Merged
merged 30 commits into from
Jan 13, 2021
Merged

Conversation

jantonguirao
Copy link
Contributor

@jantonguirao jantonguirao commented Dec 8, 2020

Why we need this PR?

Pick one, remove the rest

  • Refactoring to unify functionality of random number generators

What happened in this PR?

Fill relevant points, put NA otherwise. Replace anything inside []

  • What solution was applied:
    Implemented ops.random.Uniform in terms of RNGBase
    Moved ops.Uniform to ops.random.Uniform
  • Affected modules and functionalities:
    ops.random.Uniform
  • Key points relevant for the review:
    Uniform implementation
  • Validation and testing:
    Tests extended
  • Documentation (including examples):
    Existing documentation

JIRA TASK: [DALI-1196]

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
@szalpal szalpal self-assigned this Dec 14, 2020
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao jantonguirao changed the title [WIP] Rework UniformDistribution CPU Rework UniformDistribution CPU Dec 28, 2020
@jantonguirao jantonguirao changed the title Rework UniformDistribution CPU Rework ops.random.Uniform Dec 28, 2020
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1940512]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1940512]: BUILD FAILED

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1940603]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1940603]: BUILD PASSED

Copy link
Member

@szalpal szalpal left a comment

Choose a reason for hiding this comment

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

Couple of questions from my side

dali/operators/random/uniform_distribution.h Outdated Show resolved Hide resolved
dali/operators/random/uniform_distribution_cpu.cc Outdated Show resolved Hide resolved
dali/operators/random/uniform_distribution_cpu.cc Outdated Show resolved Hide resolved
dali/operators/random/uniform_distribution.h Show resolved Hide resolved
dali/operators/random/uniform_distribution.h Show resolved Hide resolved
dali/operators/util/randomizer.cuh Outdated Show resolved Hide resolved

template <typename T>
struct curand_uniform_dist {};

Copy link
Member

Choose a reason for hiding this comment

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

How about creating

template<typename T>
struct curand_uniform_dist {
static_assert( /* check if T is double or float */ );
DALI_HOST_DEV curand_uniform_dist(T start, T end)
/* etc... */
};

And specializing only curand_uniform/curand_uniform_double? This way we have this extra static verification of type with meaningful error msg (and less code duplication). Cause after

curand_uniform_dist<int> d;

We're getting something peculiar I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I changed it to a forward declaration, so it won't compile for other types.


struct curand_uniform_int_range_dist {
DALI_HOST_DEV curand_uniform_int_range_dist(int start, int end)
: range_start_(start), range_size_(end-start) {}
Copy link
Member

Choose a reason for hiding this comment

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

How about adding assert(start < end) line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

template <>
struct curand_uniform_dist<double> {
DALI_HOST_DEV curand_uniform_dist(float start, float end)
: range_start_(start), range_size_(end-start) {}
Copy link
Member

Choose a reason for hiding this comment

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

Here as well?

Signed-off-by: Joaquin Anton <janton@nvidia.com>
struct curand_uniform_dist {};

template <>
struct curand_uniform_dist<float> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As Michał suggested, you can move the common parts to the same place and specialize only the operator().

.DocStr(R"code(Generates random numbers following a uniform distribution.

The shape of the generated data can be either specified explicitly with a ``shape`` argument,
or chosen to match the shape of the input, if provided. If none are present, a single number is
Copy link
Collaborator

Choose a reason for hiding this comment

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

A single number means a batch of scalars, right? If so, maybe it could be phrased this way in the doc str.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Copy link
Member

@szalpal szalpal left a comment

Choose a reason for hiding this comment

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

My only doubt is uniform distribution CPU vs GPU, expressed offline

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1973816]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1973816]: BUILD PASSED

@jantonguirao jantonguirao merged commit 677cf5e into NVIDIA:master Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants