-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Keep low ply history from previous move #2688
Conversation
Since lowPlyHistory is used in MovePicker it's not obvious to me why this didn't change bench. Does anyone know why not? |
@mstembera This change only affects game playing, not analysis of single positions. This is why bench does not change |
can we use std::copy / std::fill to replace the loops (rather than memset/memcpy) ? |
The problem is, that is beyond my c++ abilities! I coded the simple loops as I thought the optimiser would make that pretty efficient and I understood it. :) My guess at copy and fill is
but it changes the bench, so presumably something is wrong :( (And the reference says the third arg to copy shouldn't point into the range defined by the first 2 args, so I'm not sure what would happen if we increase the size of the array.) Edit: the problem appears to be with the std::copy() but I haven't yet figured out how to fix it ... |
Pardon me for off-topic.. I suggest to use
|
@xoto10 The order of source and destination arguments for std::copy is reversed compared to std::memcpy. Also you are right that for std::copy the source and destination should not overlap so we should use std::move instead. Here is what I have: std::move(&lowPlyHistory[2][0], &lowPlyHistory[MAX_LPH][0], &lowPlyHistory[0][0]);
std::fill(&lowPlyHistory[MAX_LPH - 2][0], &lowPlyHistory[MAX_LPH][0], 0); @pb00068 Thanks. I have always wished bench would actually play a few moves so it would catch changes like this. @d3vv Interesting. Is this only because *buf is of type char? What if it was of type int or int16_t like our histories? Should we then use int16_t(0) to std::fill? |
@mstembera I don't know.. But with -O3 latest gcc will be good but not always.. And I have troubles with -O3 many years ago and found out this article: http://demin.ws/blog/russian/2011/05/04/who-is-faster-memset-bzero-std-fill/ But this article is in Russian.. |
I mean just the correct type for zero-symbol needed to help choose optimal template for binary code building.. |
Imo it is far clearer in its current state. leaving it this way would also make it more easily modifiable by other users in the future |
@silversolver1 We use stdlib methods like std::fill and others all over SF as it's more efficient, less code, and standardized. IMO this is easily within the minimum base level of C++ competence already required to understand existing SF code. |
@d3vv with a recent compiler all options (except the call to bzero) compile to the same memset code: |
@mstembera |
appveyor failed. is this something we need to worry about? |
I think (hope!) this is what proton is addressing in #2653 (comment) |
Yeah. . I was bored, so I went through the build stuff and added casts as needed. I don't have MSVC, so I'm just guessing, but it should be close. |
I think the appveyor failure is a random timeout. To be sure you can close and reopen the PR to trigger it again. |
hmm, it looks like it is reproducible, so we'll have to figure it out prior to merging. From looking at the log, it is hanging at the point where it runs the binary. I don't have access to MSVC |
Try
Error: attempt to subscript container with out-of-bounds index 4, but
So, it looks like obtaining the address this way is not OK. |
I guess specifying the last element and adding 1 would be more intuitive. Anyway, let's see what happens ... |
@xoto10 Yes std::copy(&lowPlyHistory[2][0], &lowPlyHistory.back().back() + 1, &lowPlyHistory[0][0]);
std::fill(&lowPlyHistory[MAX_LPH - 2][0], &lowPlyHistory.back().back() + 1, 0); would be one way to do it but I have no preference. |
I'll be merging patches tomorrow, so maybe time to look at one more version instead of back() + 1 use begin() / end() in a suitable way? |
I'm not sure if you wanted to get rid of back() completely? If so then std::copy(lowPlyHistory[2].begin(), lowPlyHistory[MAX_LPH - 1].end(), lowPlyHistory[0].begin());
std::fill(lowPlyHistory[MAX_LPH - 2].begin(), lowPlyHistory[MAX_LPH - 1].end(), 0); should also work. |
Yes, it seems there are various combinations. I was trying to use the functions as much as possible in this test, but somehow I didn't find front() when I looked for it. I think maybe your way is neatest, always use [] for the first dimension of the array and always use begin() or end() for the second. |
Oops, I forgot to wait for that earlier version to finish the checks! I think it was working ok. :) |
Ah, I expected that to work :( For the record, the code is
and it hung when running bench. Will revert to using back() and wait for the checks to finish this time ... |
It looks like end() doesn't work with MSVC, and I'm not sure there's much point in using begin() if we're not using end(). So I've retained the & operators and used |
Just need this to be merged before divP now. |
Thanks! |
Never mind. Looks like we still do. |
This patch keeps the low-ply history from the previous move, shifting the data down by 2 ply.
Tested with closedpos book:
STC:
LLR: 2.93 (-2.94,2.94) {-0.50,1.50}
Total: 71584 W: 14175 L: 13891 D: 43518
Ptnml(0-2): 1069, 8228, 16993, 8354, 1148
https://tests.stockfishchess.org/tests/view/5ec0eaafe9d85f94dc429974
LTC:
LLR: 2.94 (-2.94,2.94) {0.25,1.75}
Total: 96552 W: 13946 L: 13498 D: 69108
Ptnml(0-2): 676, 9082, 28375, 9404, 739
https://tests.stockfishchess.org/tests/view/5ec145efe9d85f94dc4299b0
Bench 4395562