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

Add montgomery to vec_ops and example of that #566

Open
wants to merge 21 commits into
base: V2
Choose a base branch
from

Conversation

danny-shterman
Copy link
Contributor

Describe the changes

This PR...

Linked Issues

Resolves #

Copy link
Contributor

@nonam3e nonam3e left a comment

Choose a reason for hiding this comment

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

lgtm, left 1 comment

@@ -42,6 +44,7 @@ namespace vec_ops {
false, // is_b_on_device
false, // is_result_on_device
false, // is_async
false, // is_in_montgomery_form
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it would be better to separate the Montgomery form flag for inputs and the result.

Copy link
Contributor

Choose a reason for hiding this comment

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

We treat the same way for montgomery inputs in other configs as well, if changing it, best to change the apis all together

Copy link
Collaborator

@yshekel yshekel Aug 7, 2024

Choose a reason for hiding this comment

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

In MSM we let the user specify it per input. For example

bool are_scalars_montgomery_form; /**< True if scalars are in Montgomery form and false otherwise. Default value:

I am not aware of other APIs with this flag.

Copy link
Contributor

@LeonHibnik LeonHibnik left a comment

Choose a reason for hiding this comment

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

Rust need formatting, other than that lgtm

wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
wrappers/rust/icicle-core/src/vec_ops/mod.rs Outdated Show resolved Hide resolved
CHK_IF_RETURN(mont::from_montgomery(d_alloc_vec_a, n * sizeof(E), config.ctx.stream, d_alloc_vec_a));
is_d_alloc_vec_a_allocated = 1;
d_vec_a = d_alloc_vec_a;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

note that in both cases you allocated and copy. You could do it like

if (are_points_montgomery_form) {

(1) allocate
(2) copy
(3) if mont --> inplace convert

nvmlDeviceGetHandleByIndex(0, &device); // for GPU 0
std::cout << "Icicle-Examples: vector mul / add / sub operations." << std::endl;
char name[NVML_DEVICE_NAME_BUFFER_SIZE];
if (nvmlDeviceGetName(device, name, NVML_DEVICE_NAME_BUFFER_SIZE) == NVML_SUCCESS) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what all this device name and power has to do with the example?

Copy link
Collaborator

@yshekel yshekel left a comment

Choose a reason for hiding this comment

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

Two notes:
(1) there seems to be no tests for this feature (vec ops for montgomery data). I don't consider the example to be a test.
(2) In my opinion, the example is very long and it makes it hard to see that basically we can compute on montgomery data by setting a flag in the config struct.

} else {
d_result = d_vec_a;
}
} else {
if (!is_in_place) {
d_result = result;
} else {
d_result = result = d_vec_a;
// d_result = result = d_vec_a; // DEBUG - looks like a bug for in-place.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

checking - not sure it's a bug

Copy link
Contributor

Choose a reason for hiding this comment

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

seems not a bug (since there are, I believe, all the tests for all the cases) but a redundant assignment (since it's in-place so result == vec_a and on-device so d_vec_a = vec_a earlier). should be d_result= d_vec_a; for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test fails with
d_result= d_vec_a;
and passes with
d_result= result;

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh, unfortunately

      if (!is_in_place) {
        d_result = result;
      } else {
        d_result = result;
      }

I'm afraid - is logically incorrect 😏 so there must be a bug somewhere else too - still figuring it out, hope to find out asap

}

int is_d_result_allocated = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

pls use bool everywhere for all true/false unless it's multiple choice.

}

int is_d_alloc_vec_b_allocated = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

pls use bool everywhere for all true/false unless it's multiple choice.

Copy link
Contributor

@vhnatyk vhnatyk left a comment

Choose a reason for hiding this comment

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

looks great 👍🏻 and cool functionality, one note just Like @yshekel mentioned - there are few places where logic is copied and should be better not 😏 to avoid code duplication

@ChickenLover
Copy link
Contributor

@danny-shterman I agree with Yuval here.
Benches, tests and examples are three different things and they shouldn't be mixed. There is very few value in the 800 line example of doing vector multiplication. If it's urgent, feel free to merge. Otherwise - I would suggest to take some more time to split it into bench, test and a short example. If you have multiple features to showcase in an example - you can just copy paste and make several files inside one folder

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.

6 participants