14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions
comment 6y ago · link · parent
First, there are some really good science reporters out there, doing excellent work. I recommend Ed Yong at the Atlantic, Helen Branswell of STAT News, Jon Cohen at Science, Amy Maxmen at Nature. There are others (it's a team effort and those are all great publications), but if you just read all of the articles under their bylines, you will get a good overview of what's going on. They will not let you down.
If you have a little bit more time and energy for this stuff (as I do), then there are many experts on Twitter who freely share their analysis, and among them are some excellent communicators. When controversial stuff comes out, you can get a good sense very quickly what the flaws are and what seems to be the consensus. If you want to dip your toes into these waters, I recommend Angela Rasmussen, Trevor Bedford, and Marc Lipsitch. For critical analysis of bullshit published by seemingly reputable academics, I highly recommend Carl Bergstrom (his takedowns are highly entertaining as well as informative).
It's frustrating for me to see such pearls of knowledge and expertise so freely available, yet the vast majority of people snarfing down huge quantities of information swill.
comment 6y ago · link · parent
If people don't know this story, Todaro and Rigano published what looked like an academic paper as a Google doc, with academic qualifications that verge on fraudulent, if not crossing the line. The original Google doc has been taken down for TOS violation, but it is still accessible on archive.org [1].
To be clear, I decry the fact that HCQ has become a political soccer match (with apparently bad behavior on both sides), where what we really need is something that at least approximates an impartial, objective search for truth.
The fact that people are getting their information from this guy (even though he's actually right about the Lancet study being flawed) is strong evidence that we're living in a dystopian information nightmare.
[1]: https://web.archive.org/web/20200315004631/https://docs.goog...
comment 6y ago · link · parent
comment 6y ago · link · parent
comment 6y ago · link · parent
Also, this is really a reason to love Hacker News. Sometimes I question why I spend so much time here, this is not one of those times :)
comment 6y ago · link · parent
ETA: there's also https://www.webaudiomodules.org/wamsynths/webdx7/ , but sound is pretty crackly on my setup :/
comment 6y ago · link · parent
Disclosure: I wrote the original sound engine in Dexed. I love seeing stuff like this!
[1]: https://www.jstor.org/stable/3680541?seq=1 [2]: http://research.gold.ac.uk/22516/1/myk_lf_vsti_programming.p...
comment 6y ago · link · parent
comment 6y ago · link · parent
comment 6y ago · link · parent
comment 6y ago · link · parent
And yet another piece is a layer to get OpenGL and OpenCL workloads running on DX12 as well, rather similar in scope to how MoltenVK and the gfx-hal Vulkan Portability work are a layer to get Vulkan workloads running on Metal. This is a big effort, and it seems to me their goal is to get things to the point where stuff Just Works and you don't have to think too hard about the various bits of (technically difficult!) infrastructure to get you there.
comment 6y ago · link · parent
comment 6y ago · link · parent
Edit: I see goatinaboat also posted the link (I searched for a bit of the url that was elided).
comment 6y ago · link · parent
comment 6y ago · link · parent
That paper calls for standardizing forward progress guarantees. Because you mention that there are GPUs that don't meet the occupancy bound as defined in the paper, that work might not go smoothly.
It occurs to me that for this particular algorithm there might be a chance to rescue it. Instead of simply spinning, a waiting workgroup might make a small amount of progress recomputing the aggregate for the partition it's waiting on. After a finite number of spins (the partition size divided by this grain of progress), it would have the aggregate for the partition so would be able to move on to the next partition. Thus the correctness concern becomes a performance concern, where a very high probability of the spin yielding early is likely "good enough."
I'll not make any promises about another blog - I worry that subgroup size tuning is too much in the weeds other than for a very specialized audience. But I certainly do hope to blog more about piet-gpu and will see if I can touch on the topic then.
comment 6y ago · link · parent
On 1, I'm wondering if there's some confusion, especially as I don't see what difference Volta makes here. I accept that the Vulkan spec makes no guarantees about thread scheduling fairness, and that one could write an adversarial but spec-compliant implementation which schedules the atomic bump of the first workgroup to claim the first partition, then context switches to the second workgroup and attempts to run it to completion, which will deadlock.
But I think it is reasonable to make the assumption, for an extremely wide range of hardware, that when the atomic bump is scheduled, the code to compute the partition aggregate will make forward progress at least to the point where it writes that aggregate, which is all that is required for completion. Note that this all of this is about a workgroup depending on the progress of another workgroup. Obviously if invocations within a workgroup were depending on the progress of other invocations within the same workgroup, that would be a problem, but of course there are control barriers for that.
I don't see how it is any more technically safe to run this on Volta than any other hardware. If there is a document that guarantees stronger forward progress than mandated by the spec, I'm unaware of it.
From my reading of the spec, there is no way to write a one-pass prefix sum that is technically guaranteed deadlock-free. I'd argue that this is a defect of the spec, as there's a gap between useful guarantees that can safely be made by all real hardware and what the spec provides. I'll allow that fixing this defect is not easy. Until then, I think a good strategy is to ignore the defect.
On 3, while I hope to avoid code duplication, so far our track record has been pretty rough. For piet-metal, I tried writing the kernel in subgroup size adaptive way, but had problems with size 64 subgroups, as that requires dealing with 64 bit ballot values, and I never got that to work (I don't have 64 bit hardware in front of me, so had to iterate by asking other people to test). Also, for Brian's work on 32x32 boolean matrix transpose, we tried a hybrid approach using both subgroups and thread local storage, and performance was really disappointing. But, armed with this experience, perhaps we can do better going forward.
comment 6y ago · link · parent
https://github.com/raphlinus/raphlinus.github.io/commit/6b92...
comment 6y ago · link · parent
The per-workgroup implementation in that blog is basically similar to mine, though I've put more effort into maxing out the partition size (using as many registers as available).
comment 6y ago · link · parent
There is definitely precedent for using "volatile" in multithreaded code (though, researching this, I think there may be stronger precedents in C than in C++, see [1], particularly the "In C++11, normally never use volatile for threading, only for MMIO" answer). I agree a good argument can be made that it's incorrect. To be clear, the argument that volatile is incorrect for multithreading is extremely strong from the perspective of standard C and C++, but I think in practice it was considered quite usable.
I have a feeling we agree on the substance (a memory model is a dramatic improvement over using volatile), but I can probably improve the wording.
[1]: https://stackoverflow.com/questions/4557979/when-to-use-vola...
ETA: Here's what I consider a great reference for the widespread use of volatile for multithreaded programming. It's from 2001, but by Andrei Alexandrescu, who I think can be considered an authority: https://www.drdobbs.com/cpp/volatile-the-multithreaded-progr...
comment 6y ago · link · parent
I can't speak to your memory allocation question, as I'm personally quite happy with the default behavior.
1224.
Prefix Sum on Vulkan(raphlinus.github.io ↗)
58 points · by raphlinus · 6y ago · 19 comments
comment 6y ago · link · parent
Using open standards avoids this risk, though some companies are unwilling to work with Khronos, citing (not publicly detailed) legal concerns.
comment 6y ago · link · parent
I think the OpenCL people get that, and have listed clvk and clspv on their roadmap. That gives considerably better options for actually running compute workloads than crossing one's fingers and hoping that the GPU vendors will implement the spec out of a sense of pity for the spec writers. Another similar project I learned about recently is vuda[1].
Another project to watch closely is JAX/MLIR, which promises to run Tensorflow workloads directly on Vulkan. In that ecosystem, it's not clear at all what value an OpenCL layer would add.
I have a blog post in draft about very fast prefix sum running on Vulkan, thanks to a comment from fluffything in response to my GPU talk (could you let me know how you would like to be attributed)? I finally got it to within 10% of memcpy bandwidth over the weekend, so I'm going to declare victory and write it up.
comment 6y ago · link · parent
comment 6y ago · link · parent
I didn't compare smoothstep. It's worth doing an analysis of the tradeoff between performance and quality. In any case, I think in practice this erf approximation will be plenty fast, and probably a bit better quality, especially in the tail region.
comment 6y ago · link · parent
The other consideration is the style of writing the code. If you were writing for a sequential processor with fast branching, it would be very tempting to write "if in the corner, compute this. If exterior on the edge, compute that. etc." This might save quite a bit in the number of "actual work" operations, but is much more likely to compile into branches, which on a GPU (or SIMD or, likely, any modern CPU) the will cost more than the work saved.
So it's very idiomatic when writing shader code to use min and max to combine a bunch of cases into a unified code path that can be executed as a straight line.
comment 6y ago · link · parent
This one is intended to be used as part of a 2D renderer. It would be easy to write this up as a fragment shader (and the parameter calculation can be done in either the vertex shader on the CPU). I believe, without having tested it yet, that it would be lightning fast, especially because the heart of the erf approximation can be done with inversesqrt.
I'm also working on a compute-centric renderer, and for that I expect it to be even faster. There, I'll break the scene into tiles, and for each tile there can be an analysis of what's inside. So tiles on the interior of a large blurred rounded rectangle can be solid colors, the edges can just compute a 1d function, etc, and only the corners with the full version.
Keep in mind, what's done in many, if not most, rendering pipelines is to render the rounded rect into a buffer, run a Gaussian blur shader over that buffer into another one (often two or more stages for the separable version of the kernel or something like a dual Kawase blur). Even the simple fragment shader version should massively outperform that.