Coder Social home page Coder Social logo

Segfaults in avx2 methods about concrete HOT 6 CLOSED

zama-ai avatar zama-ai commented on August 16, 2024
Segfaults in avx2 methods

from concrete.

Comments (6)

aPere3 avatar aPere3 commented on August 16, 2024

Hi @vthib ,

Can you provide a pointer that explicitly states that fftw_malloc returns arrays aligned on 16 bits ?

I tried to find one and could not.

from concrete.

vthib avatar vthib commented on August 16, 2024

FFTW allocates using this routine: https://github.com/FFTW/fftw3/blob/master/kernel/kalloc.c#L71

It uses MIN_ALIGNMENT, defined here: https://github.com/FFTW/fftw3/blob/master/kernel/ifftw.h#L133

So it seems to use 32 bytes alignment if a certain number of conditions is met. On my distrib (arch), fftw is compiled with --enable-avx, which makes this 32 bytes alignment used afaict. But in rust-fftw, this is probably not the case.

Anyway, this seems quite hard to enforce, unless a patch is done in rust-fftw to enable avx if fftw is compiled, + an assert is added. Even with this solution it seems quite brittle.

Imho, the best solution would be to drop the use of AlignedVec from fftw, and use a custom new type, using #[repr(C, align(32)].

This also raises an interesting issue, if we want the best possible performance, fftw should be compiled with aggressive options, which does not seem to be the case

from concrete.

vthib avatar vthib commented on August 16, 2024

I can do a PR with:

  • a in-house AlignedVec where we control the alignment (forced on 32 bytes), that is a drop-in replacement for the fftw AlignedVec everywhere
  • asserts in the avx method to ensure alignment is correct.

Would that be ok for you?

from concrete.

aPere3 avatar aPere3 commented on August 16, 2024

Hey @vthib,

We are currently forking the rust_fftw wrapper, so I would prefer us to arrange for that in this new wrapper.

from concrete.

vthib avatar vthib commented on August 16, 2024

There would be a big benefit in doing it in concrete, it would decouple concrete from fftw. Right now we have functions that depends on AlignedVec for optimizations, but that isn't related to fft at all. Having AlignedVec in concrete would remove this dependency, making it much easier to use another fft library, for benchmarking or targeting wasm for example.
The Rust implem for AlignedVec is actually quite clean as well

from concrete.

aPere3 avatar aPere3 commented on August 16, 2024

The concrete-fftw crate now forces the alignment of the AlignedVec structure to 32 bytes, which solves the segfault. We may consider adding an AlignedVecto concrete when we refactor it to support rustfft.

Closing.

from concrete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.