-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
make arraymancer work with devel #505
Comments
Currently getting the same error with nim 1.4.8, 1.60, 1.6.2... Is there a known workaround? Running archlinux, error happens whether I use import arraymancer
let d = [[1, 2, 3], [4, 5, 6]].toTensor()
let x = d * d
Which isn't particularly recent. Running an i5-4310U cpu, which doesn't have avx512. Something going wrong with cpu detection maybe? |
Tracked it down a bit. This will compile AND print "BRANCH 2" on my PC. This shows that cpuinfo seems to be working correctly. HOWEVER, if we change the 1st branch to I'm not sure what's going on. Maybe a Nim compiler bug leading to the 1st branch being codegen'd even though it shouldn't? |
Thanks for digging into this. I've seen the error myself, but never encountered it in practice. Never attempted it to fix it, because I was hoping it'd be a trivial fix for mratsim. At the same time I simply lack the experience dealing with stuff like AVX and the error message is rather opaque. Your git bisect and further digging is really appreciated though! Maybe that's enough for me to figure out a solution. |
I've been able to reproduce this issue using an i7-8665U CPU which also does not support AVX-512 and have also been able to reproduce the behaviour from @auxym's patch. I've done some further digging but have come up empty so far 😓 I may well be wrong here, but the error messages seem to suggest that gcc is rejecting compilation of the AVX-512 specific C code that Nim generates (even if it wouldn't actually be called at runtime):
That function in particular:
|
Thanks for looking into it @SteadBytes as well! Just dug myself a bit: If I pass |
Great news! Can confirm that Out of curiosity, why? Wouldn't that enable avx512 extensions? How does that work on a cpu without avx512? Next step, what do we do about it? Document it? Can it be added automatically to build flags when arraymancer is imported? Does that limit arraymancer to usage on x86 and/or gcc compiler only? |
Fantastic - nice find @Vindaar! @auxym I think what's happening is that passing diff --git a/arraymancer.nimble b/arraymancer.nimble
index 3a021e9..93448cf 100644
--- a/arraymancer.nimble
+++ b/arraymancer.nimble
@@ -188,7 +188,7 @@ task all_tests, "Run all tests - Intel MKL + Cuda + OpenCL + OpenMP":
# test "tests_cpu_remainder", switch, split = true
task test, "Run all tests - Default BLAS & Lapack":
- test "tests_cpu", "", split = false
+ test "tests_cpu", " --passC:-mavx512dq", split = false
task test_arc, "Run all tests under ARC - Default BLAS & Lapack":
test "tests_cpu", "--gc:arc", split = false
The failing test calls
Inspecting a coredump using GCC shows that the illegal instruction was
|
I don't fully see a good solution. As it seems to me right now:
So this leads me to believe that the best solution for now is to simply disable AVX512 by default and add a Nim |
What seems very odd here is that I can reproduce the original compilation error on a CPU with AVX-512:
Using the same reproducer saved as
Compiling with the |
This seems like a good solution to me, and something that can be implemented via The main downside of it is that Another option would be using |
Take a look at my earlier comment #505 (comment) I agree that disabling AVX-512 by default is probably a good idea. However I feel like something is missing here - this was working, right? 🤔
FWIW, clang also has
For GCC/clang this is handled with the It seems like disabling AVX-512 by default and then opting in at compile time rather than runtime CPU feature detection will more reliably produce working code - at the expense of having to compile with specific options and generating less "universal" code. I'm personally fine with that trade off but I, of course, cannot speak for everyone 😅 |
This commit fixes issue mratsim#505, which is a codegen issue arising from generated C code that is only valid if the `-mavx512dq` compilation flag is handed to the C compiler. The issue is that: - we cannot generate the code without the compilation flag (and compile it successfully) - handing the compilation flag makes the code compile, but forces every CPU to attempt to run the AVX512 code, which is an illegal operation for CPUs that do not support it. For this reason AVX512 support is hidden behind a `-d:avx512` compilation flag that needs to be handed. The resulting binary then *will* use AVX512 for gemm.
* do not compile with AVX512 support by default This commit fixes issue #505, which is a codegen issue arising from generated C code that is only valid if the `-mavx512dq` compilation flag is handed to the C compiler. The issue is that: - we cannot generate the code without the compilation flag (and compile it successfully) - handing the compilation flag makes the code compile, but forces every CPU to attempt to run the AVX512 code, which is an illegal operation for CPUs that do not support it. For this reason AVX512 support is hidden behind a `-d:avx512` compilation flag that needs to be handed. The resulting binary then *will* use AVX512 for gemm. * update README with a note about `-d:avx512` * fix whitespace in README
Now we disable AVX512 by default. If anyone comes up with a solution that makes it work automagically if available, but still compiles on all targets, I'm all ears. |
I think there is a change in how Nim passes file-specific compilation flags in 1.6. |
The cause of arraymancer failure has been tracked here: mratsim/Arraymancer#505 And it was fixed by mratsim/Arraymancer#542
The cause of arraymancer failure has been tracked here: mratsim/Arraymancer#505 And it was fixed by mratsim/Arraymancer#542
@mratsim I did reproduce with 1.4.8 (and some older versions too if I recall correctly) |
I'm not sure if this is related. |
We do Lines 77 to 83 in 20e0dc3
|
For reference also here (posted initially here status-im/nim-blscurve#133 (comment)): I just did a git bisect on one of the test cases that are broken with the AVX512 error with arraymancer before #542 was merged. The Nim PR that introduced the regression is: which nicely enough already has a still open "fix arraymancer regression" TODO! |
Nice find @Vindaar!
Haha, the infamous TODO that doesn't get done strikes again 😆 On the plus side, hopefully that means there's a fix to be had sooner rather than later 🤞 |
The cause of arraymancer failure has been tracked here: mratsim/Arraymancer#505 And it was fixed by mratsim/Arraymancer#542
https://pipelines.actions.githubusercontent.com/ZRinn1OrR0LWxU3iWy1StaQcZRN2kXW9lHWwDJ3esfasrmfdRn/_apis/pipelines/1/runs/18644/signedlogcontent/8?urlExpires=2021-04-18T15%3A29%3A02.1515769Z&urlSigningMethod=HMACV1&urlSignature=ES5o3LHv4%2Bky4FEHjiSAzReQNwqIZDrkd2X%2B6tFYxcU%3D
and https://github.com/nim-lang/Nim/runs/2374356299
The text was updated successfully, but these errors were encountered: