-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Running time improvement of the bitset_len method #13352
Comments
comment:2
I'd rather "implement" the functions in C (where you can use the C preprocessor and GCC e.g. chooses efficient machine implementations (probably a single instruction), depending on the (configured or specified) target and perhaps also further compiler flags. Note that GMP has functions like Not sure what the |
trials not working |
This comment has been minimized.
This comment has been minimized.
comment:3
Attachment: trac_13352-bitcount-in-c.patch.gz Replying to @nexttime:
As reported in https://groups.google.com/forum/#!topic/sage-devel/GnudTUwbGG4, I tried to implement the function in C with
It could be another solution, but I have not been able yet to find how to access the functions used for int behind?
In fact, the 4 lines |
This comment has been minimized.
This comment has been minimized.
comment:5
Replying to @dcoudert:
Well, obviously not, since you have the data dependence on Btw., you should use The types of the shift parameters (of |
comment:6
I'm able to import UINT32_MAX, but not UINT32_C.
Any special trick? |
comment:7
Attachment: trac_13352_bitset_len.patch.gz |
Attachment: trac_13352_bitset_len_v2.patch.gz |
comment:8
Hello, Since I have now understood how to use before:
after:
I'm wondering if I should add a wrapper in case the Thanks. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:9
I have now implemented the function in C in file
I have used the |
comment:10
Hello, after browsing the web, I came up with this new version. The current version tests is the cpu has builtin support. If yes, we use builtin version. Else, we use hakmem methods.
We don't need all the methods for Let me know if it is OK. |
comment:11
HMmmmmmmmm.... I'm trying to understand the code and it's much more complicated than what I actually read. Funny, looks like you can have as much fun with GCC than with Python, and decide how stuff is to be run at run time instead of compile time This being said, if I understand well what "ifunc" does I do not see how the popcount instruction will be used when available. To me it looks like you should make sure that the file is compiled with the This being said, it is a very nice trick Nathann |
comment:12
I would also say that those 2 blocks
are mistakes. Whatever happens, regardless of the architecture, Also, perhaps you should credit Cristian Rodríguez somewhere Nathann |
comment:13
Attachment: trac_13352_bitset_len_v3.patch.gz Right. I have simplified the code and add credits to Cristian Rodriguez. |
comment:14
Here's a slightly cleaner version which does not use ifunc but only G++'s multiversionning. C's looking very much like Python these days Nice links :
Nathann |
Attachment: a.c.gz |
comment:15
Unfortunately, I'm unable to use this for the patch because the "default" keyword is not recognized. |
comment:16
Hmmmmmm... Well, it seems that this feature is only available in gcc 4.8+. I asked Volker for his advice on this ticket (or rather on the .c file I uploaded), and he told me that we should check for both gcc 4.8+ and x86 (ifdef Besides, he saw on that link (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36041, though I can't find out where on the page) that GCC was about to patch that, and improve the generic version of I'll try to send a version with both codes today. And we'll remove the old one in a couple of years Nathann |
comment:17
Hey I don't get it... In your patch you also use a attribute/target with popcount. You can't compile my code yet you can compile yours ? And that means that they added this attribute/target feature before adding the "default" keyword ? Nathann |
comment:18
Apparently yes. Have you tried to modify the patch and compile on your own computer? |
comment:31
That would be great if you have the good trick to use that method. I tried some time ago to use |
comment:32
I'm also merging |
comment:33
Hmmmmmmmmmm You are on a dangerous road, Jeroen. The road to many broken dependencies in the graph/ folder Nathann |
comment:34
Replying to @nathanncohen:
You mean because of
if you prefer. |
Changed author from David Coudert to David Coudert, Jeroen Demeyer |
This comment has been minimized.
This comment has been minimized.
comment:36
Replying to @dcoudert:
The trick is to use |
comment:37
Speed is much better too. With attachment: trac_13352_bitset_len_v3.patch:
With attachment: trac_13352_bitset_len_v4.patch:
|
comment:38
Similar improvements could be made to other bitset functions (in particular to |
comment:39
Strangely, many places were importing Even stranger were two files
which was in both cases unused. |
Attachment: trac_13352_bitset_len_v4.patch.gz |
comment:40
Excellent! The patch is working perfectly (install, doctests on sage/ , etc.). The simplification of the hamming weight method is also very good. Thank you very much. Should we let Nathann conclude on the status of this ticket? |
comment:41
See also #10093 for another bitset-related ticket ready for review. |
comment:42
No sorry, please deal with this without me, I'm already juggling with 1000 patches right now Nathann |
comment:43
For me the patch proposed by Jeroen is OK (and I can install #10093 on top of it), so I set its status to positive. |
Reviewer: David Coudert |
comment:45
This is ridiculous and shows how fast
|
comment:46
Hmmmmmm... Would you happen to have the popcount instruction on the computer on which you try this ? Nathann |
comment:47
Replying to @nathanncohen:
I think so, yes. |
Merged: sage-5.13.rc0 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:50
I changed the description since we use |
comment:51
Follow-up: #16937 |
This patch improves the running time of the
bitset_len
method by usingmpn_popcount()
.Before:
After:
This patch also reorganizes the bitset files, including deleting the
sage/misc/bitset_pxd.pxi
file.APPLY:
CC: @nathanncohen @nexttime
Component: misc
Author: David Coudert, Jeroen Demeyer
Reviewer: David Coudert
Merged: sage-5.13.rc0
Issue created by migration from https://trac.sagemath.org/ticket/13352
The text was updated successfully, but these errors were encountered: