Added support and fixed parallel scan in CSR kernels for Blackwell (SM_120) architecture. Added extra CUDA matrix tests. - #2012
Conversation
…M_120) architecture. Added extra CUDA matrix tests.
|
I did a quick check and indeed, this fixes all the tests that were failing in #1981 on the NVIDIA GB10. |
|
Hi @spiralbit thanks for your contribution and welcome to Ginkgo. For AI-assistant, at least in my opinion, the contributor needs to understand the code (how and why), and verify the reference. |
|
For background, here is the last part of Claude's reasoning for this fix. Prior to this section there were a lot of trials on various other code paths. In this section there were a number of test runs to check if the proposed parallel fix would work, which Claude found they would not on Blackwell:
|
Good catch! I've pushed a fix for that.
For me Claude is great help in understanding the code and finding the source of test fails. I know a little CUDA and linear math, but I'm still learning. I would like a clean run of tests so I can get properly started on running Ginkgo and analysing it. I have another PR open here, could you please take a look: #2009
I've pasted in Claude's background cogitations. Hopefully that is helpful. I think we haven't really uncovered the real underlying bug. Why should this parallel code fail under Blackwell? That's quite a deep question, but it would be good to debug it fully. It would be good to understand because there might be other parts of the code where it is also failing, but in a way which is not immediately obvious. I've raised this PR to highlight the issue and provoke discussion. We can accept this fix, or use it to look deeper. |
|
Actually good news, in a way, I've done some more testing and it seems that the bug is triggered by the |
|
I've raised an official bug report to NVIDIA here: https://developer.nvidia.com/bugs/6155374. If they acknowledge and fix this then the workaround in this PR may become superfluous. |
NVIDIA have acknowledged this bug, and might have a fix for it soon... I'm just waiting for an update. If that is the case then I could: a) Withdraw this entire PR and we say to people don't use CUDA 13.2 or do so with this patch. I think previous versions of CUDA had this issue as well - I will get some precision from NVIDIA about that. Once we have the precision about which versions are affected and which version it is fixed in, we could just update the README and that will be the extent of this. b) Adjust the code using a macro depending on the version of CUDA. c) A flavour of a) or b) but we keep the matrix tests - are those useful? Thank you |
|
@yhmtsai Hi, there are no reviewers on this PR, would you like to add yourself and someone else for the project? |
|
@spiralbit do you hear anything from the bug report? |
I've just chased NVidia for the second time. The person handling it is called Yuki Ni. I thought it might be in the last CUDA release but it appears that it isn't, but I'm not 100% sure about that. Yuki has at least acknowledged the bug and has reproduced it using the program I submitted in the bug report. Here is the report: https://developer.nvidia.com/bugs/6155374 I think you might need an NVIDIA developer account to see it. Anyway, the status is still Open which I take to mean they have not fixed it. Maybe it's a difficult bug for them to fix... I haven't had so much time to look at Gingko recently. I just started a new job which involves travelling and I'm finishing a part-time course too so I'm rather maxed out. I hope to get back to Gingko work soon. There are still three failing tests on Windows. Two of them fail because the tolerance is too tight - that might an arch issue rather than OS: the numerical difference is 10e-14 which is close enough I think. I've worked a lot with comparing numerical results on diverse platforms and anything smaller than 10e-12 or 10e-13 is good IMHO. The tests have a tolerance of 10e-15 which is too hopeful, again in MHO. Anyway, that's for another PR. I forget what the third fail was. |
|
@spiralbit did your email address change recently? You should have received a response already, but maybe it was sent to a defunct address. Can you see the last message from May 25th in the portal? This is not a bug, I'm checking internally whether I can share the full response in this PR. |
Hi @upsj, I did not see a message on 25th May but I get a lot of email and I might have missed it. I have not changed my email address. Yes, it is not a bug in Gingko, however with the failing Gingko test it has exposed a bug in NVIDIA's CUDA complier. You might want to take the workaround in this PR and apply it in the case where the CUDA version is within a specific range... once NVIDIA fix it which they haven't yet. I think @yhmtsai might have an idea in which version the bug in CUDA appeared? |
|
@spiralbit the core misunderstanding is that this is not an nvcc compiler bug, but a slight misinterpretation of the semantics of |
|
@spiralbit The ticket response was sent on 05/25/2026 10:43 AM, checking your registered account oxon.org should have received our emails. Below is the conclusion. [Public] Hi David, After review, this is being classified as a restrict contract violation, not a compiler defect. The C/C++ definition of restrict (which NVCC inherits) is single-threaded: each invocation of the device function has its own val parameter, but in this kernel all 128 threads' val pointers designate the same shared array, with each thread writing through it while neighbours read it. Under the standard's "based-on" rule this is cross-thread aliasing, which violates the restrict contract, so the compiler is permitted to assume no aliasing and eliminate the shared store across the barrier. The C spec, which we defer to for the definition of restrict, states: void B(T * restrict P) { The following clause in the spec reads: Recommended fixes, in order of preference: Drop restrict from the val parameter (your variant E). Minimal change, no measurable perf regression for this kernel — the qualifier was never safe in this pattern. We will close this ticket as Not a Bug. We will try to enhance the CUDA Programming Guide documentation gap on our side so future readers see an explicit warning and example. Thanks again for the high-quality report. Best, |
These changes fix the issues reported here; #1981, although the architecture in that report is different to mine (Blackwell), the failure mode is the same. It would be good to know if the fixes here fix the DGX Spark issues.
This is my first real contribution to the code base. I'm still learning my way around so likely some more experienced people here might like some different changes, but it was fun to investigate and fix the matrix issues thrown up by NVIDIA's Blackwell SM_120 architecture.
Claude Code was used extensively for the CSR kernel code analysis and did a lot of the heavy lifting in terms of iterating over the various possibilities of the source of the error. Claude's suggested fix of avoiding a parallel scan in the block_segment_scan_reverse function is I hope acceptable. Claude said:
block_segment_scan_reverse parallel scan broken on sm_120 (line ~105): The Hillis-Steele parallel prefix scan with shared memory read-modify-write inside a __forceinline__ function produces wrong values on Blackwell/NVCC 13.2. Replaced with a serial scan by thread 0 — correct on all architectures, with negligible performance impact (SpMV is memory-bound; the scan is a tiny fraction).I don't share Claude's conviction that it is "correct on all architectures" because I don't have all architectures here on my desktop!
Anyway, this is a good starting point for a discussion about potential fixes, if they don't take this exact form - at least Claude has found the source of the issue. Both matrix_cuda and csr_kernels2_cuda tests are now fixed on Blackwell with these fixes.
I also prompted Claude to create a suite of tests to expose the problem and they are included in this PR. They could be made hardware agnostic I suppose - I would appreciate some guidance on how to do that. They would perhaps be more meaningful like that, or perhaps it's better to have CUDA specific ones. Anyway, I will be happy to move, remove or rewrite them.