Why do we put GMP allocations on GHC heaps?

Edward Kmett ekmett at gmail.com
Wed Oct 23 14:07:27 UTC 2013

What we're doing right now is a little less invasive.

It embeds a patched copy of MPFR, but tweaks the way they store their
constant cache, so that it doesn't use the allocator and not tell us about
it, but instead stores the cache using a secondary allocation path.

It works. However, we at last check had some limitations loading it with
ghci. I'm hopeful that with 7.8 and the less magic dynamic linker that this
will "just work".

Before that Dan Peebles took a stab at rehooking the GMP allocator hook for
me to introspect on the stack and switch to malloc when called from the
constant cache, so we could just link to the host MPFR implementation. That
_worked_, but the code was awful, and it wouldn't work from ghci. We
couldn't get the allocator rehook to load from ghci because ghci doesn't
currently run c++ initialization blocks. This also appears to be fixed in
7.8 so that may be another path forward.

This has been a very slow burn project for me. I need it eventually so I
can finish a library for working with Taylor models, where I need the
result interval to have proper rounding, so I can say definitively that the
answer lies within some small region and can use extra leading terms in the
Taylor model to make the intervals involved arbitrarily small, so I don't
get swamped in the error.

When that finally works Haskell should be able to compete with COSY
Infinity<http://www.bt.pa.msu.edu/index_cosy.htm> in
computing models for things like accelerator lattices, electron
microscopes, spectrographs, etc.


On Wed, Oct 23, 2013 at 9:45 AM, Gergely Risko <gergely at risko.hu> wrote:

> On Tue, 22 Oct 2013 20:26:53 -0400, Edward Kmett <ekmett at gmail.com>
> writes:
> > Not suggesting we actually switch, but there is one strong 'why': You
> > can't link Haskell code with any library that uses GMP internally
> > internally without switching to using integer-simple. I've been trying
> > with very limited success to get good MPFR bindings for Haskell for ~3
> > years now as a result.
> Have you tried going the other-way around?  Modifying GMP+MPFR just a
> little bit to ignore the mem_set_functions that are called by GHC and
> force them to use malloc.  Then writing a wrapper for this patched
> Gergely
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20131023/73d57ab1/attachment.html>

More information about the ghc-devs mailing list