# Help to find package for DSA (Discrete Stochastic Arithmetic) implementation

**URL:** https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391
**Category:** Numerics
**Tags:** question, package
**Created:** [February 19, 2024, 5:08am UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391 "2024-02-19T05:08:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hungpham3112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hungpham3112/32/34315_2.png) [@hungpham3112](https://discourse.julialang.org/u/hungpham3112)
#### Post date: [February 19, 2024, 5:08am UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391/1 "2024-02-19T05:08:46Z")

</div>

Hi, I’m working in a project where we use DSA method (based-on CESTAC) to validate results of numerical software. Currently, I’m using [Cadna](https://doi.org/10.1016/j.cpc.2008.02.003) (written in C) to solve this problem. The advantage of Cadna is it has example for CUDA implementation instead of just CPU like other tools.  
I’m looking for a package in Julia that match my requirements:

- Good CUDA support for half and bfloat16
- Implement DSA or relevant mathematical approach. (I’m still new to DSA so I guess, there is other techniques to solve numerical validation problem).

The package [StochasticArithmetic.jl](https://github.com/ffevotte/StochasticArithmetic.jl) seems not maintain anymore and only support SFloat64. Is there any expert out there have experience in this field? I really need an suggestion, thank you.

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [February 20, 2024, 9:15am UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391/2 "2024-02-20T09:15:47Z")

</div>

Hi, I’d be happy to revive `StochasticArithmetic.jl` if you have some interest in it. However, I don’t know much about GPUs, and haven’t the slightest clue how to implement DSA (or any form of Stochastic Arithmetic) in a GPU-compatible way.

I’d advise you to also look at @milankl’s work, especially [`StochasticRounding.jl`](https://github.com/milankl/StochasticRounding.jl). It’s not exactly DSA/CESTAC, but I tend to favour this kind of stochastic arithmetic these days, and this ecosystem is much more alive than my own `StochasticArithmetic.jl`. I don’t know whether `StochasticRounding.jl` supports GPUs, though.

---

<div class="post-metadata">

### Author: ![milankl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milankl/32/4198_2.png) [@milankl](https://discourse.julialang.org/u/milankl)
#### Post date: [February 20, 2024, 9:32pm UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391/3 "2024-02-20T21:32:40Z")

</div>

> I don’t know whether `StochasticRounding.jl` supports GPUs, though.

I haven’t tested whether or which issues arise on a GPU, if someone can test it, and open issues in StochasticRounding.jl then I’d be happy to address them!

---

<div class="post-metadata">

### Author: ![milankl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milankl/32/4198_2.png) [@milankl](https://discourse.julialang.org/u/milankl)
#### Post date: [February 20, 2024, 9:41pm UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391/4 "2024-02-20T21:41:49Z")

</div>

But yes, to clarify, StochasticRounding.jl only uses the a distance-proportional rounding mode where `x` between `a` and `b > a` is stochastically rounded to `b` at chance `p = (x-a) / (b-a)` and to `b` at chance `1-p`. So like if `x` is 1/4 of the way between a and b then there’s a 1/4 chance that it’s rounded to b. This rounding mode is exact in expectation, meaning that the average rounding error decreases for an increasing number of arithmetic operations.

---

<div class="post-metadata">

### Author: ![hungpham3112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hungpham3112/32/34315_2.png) [@hungpham3112](https://discourse.julialang.org/u/hungpham3112)
#### Post date: [February 21, 2024, 4:05pm UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391/5 "2024-02-21T16:05:47Z")

</div>

What is the theory or paper that you implement in your package?

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [February 21, 2024, 4:30pm UTC](https://discourse.julialang.org/t/help-to-find-package-for-dsa-discrete-stochastic-arithmetic-implementation/110391/6 "2024-02-21T16:30:44Z")

</div>

`StochasticArithmetic.jl` implements Vignes’ CESTAC arithmetic\[1\].

[https://ffevotte.github.io/StochasticArithmetic.jl/dev/](https://ffevotte.github.io/StochasticArithmetic.jl/dev/)

In comparison to DSA:

- CESTAC is asynchronous (whereas DSA is synchronous)
- you can do as many evaluations as you like (whereas DSA fixes 3 evaluations)

  

In contrast, I think `StochasticRounding.jl` implements an arithmetic more similar to Stott Parker’s Monte Carlo Arithmetic\[2\] (MCA): instead of rounding upwards or downwards with probability 1/2 (like in CESTAC), the probability is adjusted so that the expectation of the stochastic result matches the real, mathematical result.

See _e.g._ this paper for a comprehensive comparison of CESTAC/DSA vs MCA (Disclaimer: I’m one of the authors)

> Devan Sohier, Pablo De Oliveira Castro, François Févotte, Bruno Lathuilière, Eric Petit, and Olivier Jamond. Confidence intervals for stochastic arithmetic. _ACM Transactions on Mathematical Software_, 47(2), 2021.

> **[Confidence Intervals for Stochastic Arithmetic](https://hal.science/hal-01827319)**
>
> Quantifying errors and losses due to the use of Floating-Point (FP) calculations in industrial scientific computing codes is an important part of the Verification, Validation and Uncertainty Quantification (VVUQ) process. Stochastic Arithmetic is one...

* * *

1. Jean Vignes and Michel La Porte. Error Analysis in Computing, 1974 

2. Douglas Stott Parker. Monte carlo arithmetic: exploiting random-  
ness in floating-point arithmetic. Technical Report CSD-970002,  
UCLA Computer Science Dept., 1997.
