Rust-GPU / Rust-GPU/rust-cuda

Incorrect arithmetics in large function

Open
#38 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-llvm bug C-rustc_codegen_nvvm
Dominant language
Rust
Stars
5.4k
Forks
249
PR merge metrics
No merged PRs in 30d

Description

Hi

I am trying more examples with using crypto, and this time problem that I encounter is with integer arithmetic mismatch between GPU and CPU.

There is an example of the code: CPU and GPU

They both have same code of fiat_25519_to_bytes function, however result is slightly different for CPU and GPU

CPU OUT: [192, 72, 16, 54, 192, 98, 172, 116, 44, 128, 112, 112, 150, 42, 195, 95, 129, 14, 47, 50, 18, 198, 117, 255, 32, 79, 57, 78, 137, 92, 244, 98]
GPU OUT: [192, 72, 16, 54, 192, 98, 172, 124, 44, 128, 112, 112, 86, 106, 195, 95, 129, 14, 47, 48, 20, 198, 117, 255, 32, 63, 57, 78, 137, 92, 244, 98]

(note element 7 for example)

Understandably function is fairly large, however I was not able to reduce example. For instance, when trying to narrow down what happen I can see that basically result on this line is incorrect:

fiat_25519_addcarryx_u51(&mut x14, &mut x15, x13, x3, (x11 & 0x7ffffffffffff));

However, when taking this line out of context of large function it works perfectly fine on GPU, so the problem is likely with some kind of optimization that breaks integer arithmetics logic.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CPU example at examples/cuda/cpu/add/src/main.rs and GPU example at examples/cuda/gpu/add_gpu/src/lib.rs, focusing on fiat_25519_to_bytes and the reported fiat_25519_addcarryx_u51 call. Run both examples and compare their outputs, then trace the large function to identify why GPU arithmetic diverges from CPU arithmetic. Done means the corresponding CPU and GPU results match for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.