Repository navigation
Conversation
Retrigger CI after the same access violation tracked in upstream issue joblib#261. No code changes.
|
Could you please include a non-regression test? Maybe this problem can be reproduced when installing the two numpy and scipy vendored openblas copies from pypi for instance? |
|
Yeah my guess is it's already fixed ( |
|
Thanks for pointing me to #309 and suggesting a regression test. I retested I added a small regression test for two OpenBLAS controllers that share one thread count. It fails on |
|
I'll take a look tomorrow, or if I run out of time, Monday. |
|
Note that once #311 is finalized and merged, we should update this PR to add a non regression test. EDIT: actually, I had not seen that youd added 24571eb in the mean time. Not sure if we need another non-regression test or not. I tend to prefer actual integration tests rather than unit test that rely on non-trivial monkeypatch logic because maintaining such tests is non-trivial and potentially brittle in case of refactoring: they could pass silently for wrong reasons after changes in implementation details. |
|
I wonder if FlexiBLAS would give the same effect? |
|
I don't really understand the claimed diagnosis: "The two libraries share the same thread-count state. Applying the limit saves 16 for the first controller and then 1 for the second." But the code has two passes, first recording limits and then changing limits. It's not interleaved. |
|
Thanks for pointing that out. Please give me a little time to double-check my explanation and try the FlexiBLAS case. |
|
I double-checked this, and you were right about the two passes. Both entries are 16 in the initial snapshot. I missed the later refresh when OpenBLAS takes control. By the time it reads the second entry, the first setter has already changed the shared count to 1. My previous patch restored 16 on exit, but I found that I reproduced it on current I’ve updated the fix so the refresh happens before any setter runs. I verified both the reported and restored counts, including when another thread changes the count before handing over control. I also replaced the mock test with a real-library regression test for the existing Linux FlexiBLAS CI job. It fails locally on both |
|
Did a coding agent write that last comment? In any case I suspect the initial reversing approach is the correct one, given there's already a hard-coded solution that kinda-sorta does that for FlexiBLAS. And after reminding myself of the code I can see how the "by the time it gets to second one" comment came about. |
Yes, it is AI assisted. I did the checking and writing. You’re right about the FlexiBLAS ordering: the normal path puts the wrapper last and restores correctly on my machine. My test explicitly put the wrapper first. I should have made that distinction clearer. The ROCm case doesn’t need that reordering. With both libraries detected and sharing a thread count, my original patch restored 4 on exit, just as you suggest. The remaining issue was that get_original_num_threads() still returned 1 inside the context. That’s why I changed the patch. I’d be happy to keep reverse restoration if there’s a simpler way to get both values right. What way would you like to move on? Thanks again for your review. |
|
I do not want a massive rewrite of this (annoyingly subtle) logic without thinking it through very hard, so I will get back to this next week. And again, post-#312, since that fixes some of the issues (unnecessarily setting too many things). With FlexiBLAS you would have:
This was fixed by moving FlexiBLAS to end, so it's always restored last, but restoring in reverse order fixes it too and probably more generically, including the case you mention. It does mean So no need for updates to this PR, I will take a look next week. |
I ran into this with the two ROCm host OpenBLAS libraries loaded in the same process. Both exposed the same thread count: limiting BLAS to one thread worked, but leaving the context left it at one instead of restoring the original count.
The initial snapshot is correct. When a thread takes control of OpenBLAS, the limiter refreshes the saved counts in case a previous owner changed them. If the first setter has already changed a shared pool, that refresh can overwrite a later controller's original count with the temporary limit. Reversing restoration order repairs the final count in my reproducer, but leaves
get_original_num_threads()reporting the temporary limit.This change claims control and refreshes the selected counts before calling any setter. The regression test uses FlexiBLAS and its pthreads OpenBLAS backend in the existing Linux FlexiBLAS CI job. It checks both the value reported inside the context and the actual thread count after exit.