New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pool for padics #23722
Comments
Branch: u/caruso/pool |
Commit: |
comment:2
I attach a first rough implementation that works only for CR elements. The speed up is about 50% (= 2 times faster) for New commits:
|
comment:3
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:5
Replying to @videlec:
Probably. But the pool for
Well, in my implementation, the parent plays some role (we have access to the pool through the parent and may enable/disable the pool for different parents using the same element class). It seems to be difficult to introduce these features in the
Indeed. For now, I'm just testing this for padics but it works well. |
comment:6
I justed posted a message on Cython mailing list https://groups.google.com/forum/#!topic/cython-users/Uh4JCzDdIsQ |
comment:7
Very nice! Some thoughts:
Great work Xavier! |
comment:8
Replying to @videlec:
Absolutely! This should not be specific to p-adics. |
comment:9
Also, it would be good to have a short write-up of what exactly this does (the current branch doesn't have much documentation) before continuing the discussion. |
comment:10
See also #17670 which I created a long time ago but never did anything with. |
comment:11
Replying to @roed314:
Thanks :-)
Sure.
If I actually think that this could be an option in any case. Concretely
Yes.
Reference counting should be fine (hopefully).
One possible solution: we create a new class |
comment:12
Replying to @jdemeyer:
Oh, I've always thought that overriding |
comment:13
Replying to @xcaruso:
I'm not convinced that it should. Ideally, the implementation should be as generic as possible, so the parent should not be involved. |
comment:14
Replying to @xcaruso:
I think you are right. Like I said, I wrote #17670 a long time ago and I'm not claiming that the ticket description of #17670 is correct. |
comment:16
The documentation and changes help. Here are some comments.
|
comment:17
Replying to @jdemeyer:
The benefit of having the parent involved is that you can turn on the pool for If we can make pools available upstream in Cython, I think it's worth giving up this feature. But if we're just implementing it in Sage, I like Xavier's choice to attach it to the parent, since I don't see anything in Sage other than elements using a pool, and we do get the flexibility of varying the behavior by parent. |
comment:18
Replying to @roed314:
Obvious question: why do you assume that |
comment:19
Replying to @jdemeyer:
It certainly can. But for larger I'm not strongly attached to the ability to enable and disable the pool at the level of individual parents, but I think it does provide some benefit. |
comment:20
Replying to @roed314:
So then, there is again no reason to get the parent involved... |
comment:21
Replying to @roed314:
And actually it is (in my implementation): a given pool may be shared between different parents, and it's for now the default for p-adics. |
comment:22
Replying to @jdemeyer:
Yes, there is because you may want, in some specific cases, to have separated pools. I agree that sharing the pool for Also, one can imagine other classes where the data structure corresponding to some parameters are not compatible with the data structure to other parameters (for instance, if we want to implement a p-adic number as a flint p-adic, then I guess that a 5-adic number cannot be easily recycled to a 7-adic number). For these classes, it's useful to have separated pools according to the parent. |
comment:23
Replying to @xcaruso:
Yes, I can "imagine" that. However, I feel that we should go for an implementation which is as generic as possible and which therefore would not involve something Sage-specific like a parent. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:27
In case it is not clear, let me mention that I disagree with several design choices made here (storing the pool in the parent is one of them). I think that the |
comment:28
Don't worry, I think I understood that you disagree :-). I wanted to be sure that my approach will eventually work and it's the reason why I continued working on it (and then pushed it to the ticket). But, I'm afraid that I didn't understand well your point. Could you detail more please what should be the features of a good pool (according to you)? I understand, I think, that it should be attached to a python type, it that right? Are you proposing to modify Cython and embed it in the |
comment:29
Replying to @xcaruso:
That's actually an excellent question. In decreasing order of importance, a pool should:
First of all, these are details: we should first get a good design and then think about this. To answer the question: I don't think that such features would ever be used. So, you could add them, but why? Perhaps more interesting would be to get access to some statictics, like how full is the pool, how often does it overflow/underflow... |
comment:30
Ok. At some point, I've also tried to conceal all these requirements but I then had to give up because I couldn't see how to achieve in pure Cython (i.e. without modifying the Cython compiler). Moreover, as already discussed, these brute solutions are not that fine because they do not prevent the creation/deletion of extra allocated objects (as mpz integers in the case of padics). So there would eventually require extra work. Maybe splitting I'm not part of the community of Cython developers (I mean people who are developing Cython). It's the reason why I had preferred mode "cythonic" solutions. But if you (or someone else) think that you can come up with a working code following the previous lines in a reasonable time, it's of course fine with me. Besides, I think that the implementation I proposed (where the pool is attached to the parent) has interesting features. For padics, it's really efficient (2 times faster for |
comment:31
You make some good points which I need to think about... I never said it was easy, but I like challenges :-) |
comment:32
Jeroen, are you planning on working on this soon? If not, I think it's worth trying to get an implementation based on Xavier's prototype into Sage. It has a huge performance impact, and I don't want to see it languish because we move on to other things. |
comment:33
Replying to @roed314:
You are basically proposing to have two different semi-working pool implementations (the one from |
comment:34
Replying to @jdemeyer:
I didn't say this ticket was ready for positive review yet. But what makes these implementations "semi-working?" The integer one has been in Sage for a long time and seems to be useful. As for having two implementations, I'd be curious to see how the speed of the current integer pool compares with Xavier's implementation. If nothing else, it would give us an idea of how costly performance-wise the decision to use the parent to store the pool is. |
comment:35
Replying to @roed314:
The pool for integers is faster (a simple addition takes ~70ns compared to ~110ns for |
comment:36
I have an idea for this. Instead of storing the pool in the parent, store the pool as a static C variable inside the Cython module. This is fast, general but ugly. Since one cannot dynamically create functions in C, this would mean that a single Cython module could only use a fixed number of pools. |
comment:37
I have (finally) finished my pool implementation in #17670. It is meant to be quite generally applicable. |
Changed keywords from pool to pool, padicIMA |
As discussed on zulip, we propose to implement a pool for p-adic numbers.
CC: @roed314 @saraedum @jdemeyer
Component: padics
Keywords: pool, padicIMA
Author: Xavier Caruso
Branch/Commit: u/caruso/pool @
5e3d9cd
Issue created by migration from https://trac.sagemath.org/ticket/23722
The text was updated successfully, but these errors were encountered: