Re: [Haskell-cafe] ANN: hmpfr-0.3.2 (requires integer-simple, supports mpfr 3.0.0)

2011-03-04 Thread Daniel Peebles
Have you submitted a bug report to GHC of why it can't work with the current
integer-gmp binding? I know that GHC's collector is collecting MPFR's
temporary data, but maybe it'd be good to get a discussion going on what can
be done to stop it from doing this even in the context of the existing
integer-gmp + GHC's allocator (even if this needs to be a patch to MPFR to
talk to GHC a bit here and there). Might it help to go through CMM like the
GMP binding does, for example?

I'd really like to see libraries that use GMP work nicely with GHC, without
going and reimplementing GMP more slowly and so on.

Dan

2011/3/3 Michal Konečný m...@konecny.aow.cz

 Dear all,

 I am pleased to announce hmpfr-0.3.2, a new version of Aleš Bizjak's
 bindings
 to the MPFR arbitrary precision floating point arithmetic library.  The
 changes in this version are quite small but significant:

 - support for MPFR 3.0.0 as well as MPFR 2.4.*
 - dependency on integer-simple instead of integer-gmp

 The latter is most significant because unfortunately it makes it rather
 more
 difficult to install hmpfr.   Currently almost all binary distributions of
 ghc
 have integer-gmp compiled in to provide the Integer type via the standard
 GMP
 library.  Also haskell platform 2010.2.0.0 assumes that ghc has been
 compiled
 with integer-gmp although it makes no specific use of it.  Instructions on
 how
 to compile ghc and haskell platform with integer-simple instead of
 integer-gmp
 are on:

 http://code.google.com/p/hmpfr/wiki/GHCWithoutGMP

 The rationale for this change is the fact that despite much effort hmpfr is
 very unreliable on ghc that includes integer-gmp due to ghc deallocating
 GMP
 data that was allocated by MPFR at unpredictable times.

 Aleš and I hope that hmpfr can return to using integer-gmp once the
 proposal


 http://hackage.haskell.org/trac/ghc/wiki/ReplacingGMPNotes#BinaryDropinReplacementforGMP

 to replace gmp with a modified gmp in ghc is implemented and made the
 default.

 Best regards,
 Michal
 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|http://www-users.aston.ac.uk/~konecnym/
 |o|office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: hmpfr-0.3.2 (requires integer-simple, supports mpfr 3.0.0)

2011-03-04 Thread Daniel Peebles
According to Duncan Coutts (whom I asked about this issue in #ghc), the
solution here is to use the new foreign import prim machinery to talk to
MPFR. This prevents GC from occurring during the MPFR calls and will make
everything work nicely without reimplementing GMP.

Dan

On Fri, Mar 4, 2011 at 3:09 PM, Daniel Peebles pumpkin...@gmail.com wrote:

 Have you submitted a bug report to GHC of why it can't work with the
 current integer-gmp binding? I know that GHC's collector is collecting
 MPFR's temporary data, but maybe it'd be good to get a discussion going on
 what can be done to stop it from doing this even in the context of the
 existing integer-gmp + GHC's allocator (even if this needs to be a patch to
 MPFR to talk to GHC a bit here and there). Might it help to go through CMM
 like the GMP binding does, for example?

 I'd really like to see libraries that use GMP work nicely with GHC, without
 going and reimplementing GMP more slowly and so on.

 Dan

 2011/3/3 Michal Konečný m...@konecny.aow.cz

 Dear all,


 I am pleased to announce hmpfr-0.3.2, a new version of Aleš Bizjak's
 bindings
 to the MPFR arbitrary precision floating point arithmetic library.  The
 changes in this version are quite small but significant:

 - support for MPFR 3.0.0 as well as MPFR 2.4.*
 - dependency on integer-simple instead of integer-gmp

 The latter is most significant because unfortunately it makes it rather
 more
 difficult to install hmpfr.   Currently almost all binary distributions of
 ghc
 have integer-gmp compiled in to provide the Integer type via the standard
 GMP
 library.  Also haskell platform 2010.2.0.0 assumes that ghc has been
 compiled
 with integer-gmp although it makes no specific use of it.  Instructions on
 how
 to compile ghc and haskell platform with integer-simple instead of
 integer-gmp
 are on:

 http://code.google.com/p/hmpfr/wiki/GHCWithoutGMP

 The rationale for this change is the fact that despite much effort hmpfr
 is
 very unreliable on ghc that includes integer-gmp due to ghc deallocating
 GMP
 data that was allocated by MPFR at unpredictable times.

 Aleš and I hope that hmpfr can return to using integer-gmp once the
 proposal


 http://hackage.haskell.org/trac/ghc/wiki/ReplacingGMPNotes#BinaryDropinReplacementforGMP

 to replace gmp with a modified gmp in ghc is implemented and made the
 default.

 Best regards,
 Michal
 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|http://www-users.aston.ac.uk/~konecnym/
 |o|office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: hmpfr-0.3.2 (requires integer-simple, supports mpfr 3.0.0)

2011-03-04 Thread Edward Kmett
I'd be more than willing to tackle flipping things over to use foreign
prims, so that I have something I can build on top without requiring the
contortions to get a ghc build with integer-simple.

Dan has a cabal buildable library with foreign prims to use as a model.

Is the google code repository up to date?

-Edward Kmett

On Fri, Mar 4, 2011 at 3:27 PM, Daniel Peebles pumpkin...@gmail.com wrote:

 According to Duncan Coutts (whom I asked about this issue in #ghc), the
 solution here is to use the new foreign import prim machinery to talk to
 MPFR. This prevents GC from occurring during the MPFR calls and will make
 everything work nicely without reimplementing GMP.

 Dan


 On Fri, Mar 4, 2011 at 3:09 PM, Daniel Peebles pumpkin...@gmail.comwrote:

 Have you submitted a bug report to GHC of why it can't work with the
 current integer-gmp binding? I know that GHC's collector is collecting
 MPFR's temporary data, but maybe it'd be good to get a discussion going on
 what can be done to stop it from doing this even in the context of the
 existing integer-gmp + GHC's allocator (even if this needs to be a patch to
 MPFR to talk to GHC a bit here and there). Might it help to go through CMM
 like the GMP binding does, for example?

 I'd really like to see libraries that use GMP work nicely with GHC,
 without going and reimplementing GMP more slowly and so on.

 Dan

 2011/3/3 Michal Konečný m...@konecny.aow.cz

 Dear all,


 I am pleased to announce hmpfr-0.3.2, a new version of Aleš Bizjak's
 bindings
 to the MPFR arbitrary precision floating point arithmetic library.  The
 changes in this version are quite small but significant:

 - support for MPFR 3.0.0 as well as MPFR 2.4.*
 - dependency on integer-simple instead of integer-gmp

 The latter is most significant because unfortunately it makes it rather
 more
 difficult to install hmpfr.   Currently almost all binary distributions
 of ghc
 have integer-gmp compiled in to provide the Integer type via the standard
 GMP
 library.  Also haskell platform 2010.2.0.0 assumes that ghc has been
 compiled
 with integer-gmp although it makes no specific use of it.  Instructions
 on how
 to compile ghc and haskell platform with integer-simple instead of
 integer-gmp
 are on:

 http://code.google.com/p/hmpfr/wiki/GHCWithoutGMP

 The rationale for this change is the fact that despite much effort hmpfr
 is
 very unreliable on ghc that includes integer-gmp due to ghc deallocating
 GMP
 data that was allocated by MPFR at unpredictable times.

 Aleš and I hope that hmpfr can return to using integer-gmp once the
 proposal


 http://hackage.haskell.org/trac/ghc/wiki/ReplacingGMPNotes#BinaryDropinReplacementforGMP

 to replace gmp with a modified gmp in ghc is implemented and made the
 default.

 Best regards,
 Michal
 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|http://www-users.aston.ac.uk/~konecnym/
 |o|office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: hmpfr-0.3.2 (requires integer-simple, supports mpfr 3.0.0)

2011-03-04 Thread Michal Konečný
Hi Dan,

On Friday 04 Mar 2011 21:59:12 Daniel Peebles wrote:
 I'm adding Ed to the conversation as he's very interested in this topic,
 too. 

I do apologise - I was meant to post the previous email back to haskell-cafe 
but by mistake it went only to you.  I hope you do not mind that I am taking 
the discussion back to the cafe.  I attach my email so that other readers of 
the cafe can see it.

 The experts were right about it being impossible to work with GHC's
 GMP – until recently. foreign import c calls are indeed going to call GC
 when you don't want it, but when they split integer-gmp out of GHC's own
 RTS, Duncan Coutts (one of those experts) added the foreign import prim
 construct so that he could do exactly what you want, and operate on GMP
 integers with GHC-allocated memory without worrying about temporary
 storage blowing up while you aren't looking.

 So in general, I'd lean more towards replacing all your ccall bindings to
 MPFR with cmm bindings. It does require some GHC internals knowledge but
 is fairly mechanical, and would solve all the problems, without requiring
 a rewrite of GMP (that would be slower anyway). 

 Ed is actually going to get started on a fairly simple binding to a subset
 of MPFR for one of his projects, using the CMM approach based on the
 structure of my natural-gmp package
 (https://github.com/pumpkin/natural-gmp, which is itself based heavily on
 integer-gmp, but reworked to work fine from cabal rather than depending on
 GHC's build process). Once he is done with that, you might want to refer
 to his implementation to make your more complete MPFR binding work with
 integer-gmp (and thus make no speed sacrifices).

If this is the best approach, I would welcome help with this as I will not 
have much time to work on it until the summer due to teaching commitments and 
the need to publish work done earlier.

 I would also like a gmp-compatible replacement, but it's going to
 necessarily be slower and would prefer to be able to have fast
 computations over floating-point numbers AND integers/naturals.

Eek, I made a mistake, I apologise again - the proposal I was quoting in the 
announcement is not what I had in mind.  I was meant to refer to a mention by 
igloo at the very end of

http://hackage.haskell.org/trac/ghc/ticket/311

which is a very different proposal from the one I linked to and the one you 
seem to refer to here. 

I was not at all thinking of writing a gmp compatible replacement.  I was 
thinking of taking gmp sources and mechanically modify the exported names and 
modify integer-gmp to use those modified names.  Thus there would be no 
difference in the speed of Integer as it would still use an exact clone of the 
original gmp in exactly the same way as now but not interfere with what the 
usual gmp code does via other libraries.

Please correct me if I this approach is not feasible or if there is some 
advantage in using cmm over this proposal that I am missing.

Michal
-- 
|o| Michal Konecny mikkone...@gmail.com
|o|http://www-users.aston.ac.uk/~konecnym/
|o|office: (+42) (0)121 204 3462 
|o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston
---BeginMessage---
Hello Dan,

Thank your for your suggestions.  

I implemented the dependency on integer-simple because I need hmpfr to work in 
the short term.  In the long term, I would like to adopt a better approach.  
At the moment I do not know enough about ghc internals to be able to determine 
the approach, so I welcome your pointers.  I know that Aleš, who knows more 
about the ghc internals, has tried various things but could not make hmpfr 
work with the current integer-gmp.

I did not file a bug because there was a similar ghc ticket open for quite 
some time (#601) and it has been closed when it became possible to use 
integer-simple instead of integer-gmp.  That is why I felt that the best 
solution to the problem at present is to use integer-simple.

I am not an expert but based on what I read experts say on the topic I 
concluded that it is close-to-impossible to make ghc+integer-gmp work with 
libraries such as mpfr that heavily use gmp.

Of the suggested solutions we are aware of, the one that seems to me and Aleš 
most promising is to create a clone of gmp that differs from the original only 
in the names of all exported symbols and distribute it as a part of ghc to be 
dynamically linked with all executables produced by ghc.  The clone could be 
produced using a script to allow easy updates with new versions of gmp.  I 
would be interested whether someone has been trying or has plans to try to 
implement this approach.  The reason why I like this approach than writing cmm 
wrappers around MPFR and prim importing them is that it is more maintainable 
and also opens the way for other libraries that depend on gmp to work with 
ghc.

Michal

On Friday 04 Mar 2011 20:27:10 you wrote:
 According to Duncan Coutts (whom I asked about this issue in #ghc), the
 solution here is to use 

Re: [Haskell-cafe] ANN: hmpfr-0.3.2 (requires integer-simple, supports mpfr 3.0.0)

2011-03-04 Thread Michal Konečný
On Friday 04 Mar 2011 21:06:45 Edward Kmett wrote:
 I'd be more than willing to tackle flipping things over to use foreign
 prims, so that I have something I can build on top without requiring the
 contortions to get a ghc build with integer-simple. 
 
 Dan has a cabal buildable library with foreign prims to use as a model.
 
 Is the google code repository up to date?

Hi Ed,

Yes, it is up to date.  Moreover, I am not planning to do any development on 
it in the next few weeks.  I would be very happy if you would experiment with 
the foreign prims in hmpfr.

Michal
-- 
|o| Michal Konecny mikkone...@gmail.com
|o|http://www-users.aston.ac.uk/~konecnym/
|o|office: (+42) (0)121 204 3462 
|o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston


signature.asc
Description: This is a digitally signed message part.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: hmpfr-0.3.2 (requires integer-simple, supports mpfr 3.0.0)

2011-03-03 Thread Edward Kmett
Woohoo!

I tried to fix up the hmpfr bindings myself before the
integer-simple/integer-gmp split was done, but it was impossible given the
way GHC hooks into the gmp allocator. The main issue appears to be the fact
that as mpfr has matured it has come to do more internal allocation to
handle corner cases that it was handling incorrectly, and as these are not
on slabs of memory you explicitly allocated, the GMP allocation hook causes
them to vanish willy nilly.

I'm glad I can finally pick up some of my interval arithmetic/taylor model
code again. =)

I have a half-dozen or so packages that were blocked by this.

-Edward Kmett

2011/3/3 Michal Konečný m...@konecny.aow.cz

 Dear all,

 I am pleased to announce hmpfr-0.3.2, a new version of Aleš Bizjak's
 bindings
 to the MPFR arbitrary precision floating point arithmetic library.  The
 changes in this version are quite small but significant:

 - support for MPFR 3.0.0 as well as MPFR 2.4.*
 - dependency on integer-simple instead of integer-gmp

 The latter is most significant because unfortunately it makes it rather
 more
 difficult to install hmpfr.   Currently almost all binary distributions of
 ghc
 have integer-gmp compiled in to provide the Integer type via the standard
 GMP
 library.  Also haskell platform 2010.2.0.0 assumes that ghc has been
 compiled
 with integer-gmp although it makes no specific use of it.  Instructions on
 how
 to compile ghc and haskell platform with integer-simple instead of
 integer-gmp
 are on:

 http://code.google.com/p/hmpfr/wiki/GHCWithoutGMP

 The rationale for this change is the fact that despite much effort hmpfr is
 very unreliable on ghc that includes integer-gmp due to ghc deallocating
 GMP
 data that was allocated by MPFR at unpredictable times.

 Aleš and I hope that hmpfr can return to using integer-gmp once the
 proposal


 http://hackage.haskell.org/trac/ghc/wiki/ReplacingGMPNotes#BinaryDropinReplacementforGMP

 to replace gmp with a modified gmp in ghc is implemented and made the
 default.

 Best regards,
 Michal
 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|http://www-users.aston.ac.uk/~konecnym/
 |o|office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe