Better HN
topnewbestaskshowjobs
Log inSign up

raphlinus

14,081 karma · joined Mar 7, 2014 (12y ago) · 1,887 submissions

I do research on fundamental UI technology and 2D graphics, with a focus on Rust and fonts. @raph@mastodon.online
Submissions

comment 6y ago · link · parent

This may have been asked rhetorically, but I will answer it seriously.

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

James Todaro is not an honest scientist. I couldn't find any A-grade sources on him, but here's an interesting Wired piece: https://www.wired.com/story/an-old-malaria-drug-may-fight-co...

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

There is threadgroup shared memory (also known as local data share), provided at 64kB per block of execution units (this block is called a "subslice" in Intel, a "streaming multiprocessor" in Nvidia, and "compute unit" in AMD). Though the exact ratios vary widely, this memory has about an order of magnitude higher bandwidth and lower latency than access to global memory, and when used skillfully really can enable systolic-like architectures.

comment 6y ago · link · parent

Indeed. I discussed this with a bunch of my GPU buddies, and we came to the conclusion that this code is not safe in the face of lack of forward progress guarantees. Also, shameless self-promotion, I have an extensive discussion of GPU forward progress in my recent blog: https://raphlinus.github.io/gpu/2020/04/30/prefix-sum.html

comment 6y ago · link · parent

Nice! I imagine with the advances in ML it would be possible to do really impressive things. I hope you or someone else takes this up.

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

https://github.com/google/music-synthesizer-for-android/tree... has an experimental port, but I'd consider it a starting point, not a polished web app.

ETA: there's also https://www.webaudiomodules.org/wamsynths/webdx7/ , but sound is pretty crackly on my setup :/

comment 6y ago · link · parent

There is a long tradition of using AI and AI-ish techniques to try to generate FM synthesis patches, for example [1] genetic algorithms (1993) to [2] neural networks (2017). See the "previous work" section in the latter paper for more references.

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

I hate the word choice here. It completely conflates the important public health activity, which is for the benefit of the people (though requiring careful attention to privacy concerns) with plain old police detective work. As this framing takes hold, it will do great damage to public health initiatives, which are already struggling with lack of resources and support.

comment 6y ago · link · parent

A large part of that is the extra frame of latency added by the compositor. One experiment that I'd very much like to do is try to get Windows to promote a window to using hardware overlays (this is sometimes called "DirectFlip" but the public documentation on it is very sparse) and see how much that helps.

comment 6y ago · link · parent

There's some work on this already, including Holophrasm and work by OpenAI on proof shortening. These efforts are linked from the Metamath wiki:

https://github.com/metamath/set.mm/wiki/Automated-proving

comment 6y ago · link · parent

Adding my voice to the "it sparks joy" crowd. I think it depends a lot on who I am and what I'm trying to do; I'm really motivated by performance, and when I'm writing in Rust I feel I can do that and also maintain higher level structure.

comment 6y ago · link · parent

I was also surprised, but found this RFC for TensorFlow on top of DirectML: https://github.com/tensorflow/community/pull/243

comment 6y ago · link · parent

Yes, (almost) everybody doing machine learning is on CUDA. There are multiple pieces of this work, and the DirectX API's are only part of it. Other pieces get CUDA running as well.

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

The associated blog post (https://devblogs.microsoft.com/directx/directx-heart-linux/) does have more details on exposing display functionality. There is no swapchain functionality yet, but it's clear they're working on it, and part of the work is "DxCore", which seems to be a cleaned up and simplified version of DXGI. So not now, but soon.

comment 6y ago · link · parent

This Atlantic piece has excellent background, including the astonishing effectiveness in cats against FIP, and questions about Gilead's motivations for prioritizing studies of one vs the other: https://www.theatlantic.com/science/archive/2020/05/remdesiv...

Edit: I see goatinaboat also posted the link (I searched for a bit of the url that was elided).

comment 6y ago · link · parent

s/trivial/possible/. But yes, this is a wishlist item for me (in piet-gpu) as well, partly because of the bloat issues and partly because I want to be able to use the most advanced features (subgroup operations) that the shader languages provide, and there's currently a pretty big gap there.

comment 6y ago · link · parent

It is, but that won't do anything about overeager lawyers.

comment 6y ago · link · parent

Super, thanks for the info. I should update the blog post with it.

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

Thanks, especially the second paragraph. I'll probably update the post based on that (I've made several updates already).

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

Followup: I've changed the language a bit, I hope you agree it's an improvement.

https://github.com/raphlinus/raphlinus.github.io/commit/6b92...

comment 6y ago · link · parent

It's a good blog, but only solves a much simpler version of the problem - it only computes prefix sum of a workgroup worth of data. It does not carry the sums forward from workgroup to workgroup, which is the entire point of the decoupled look-back approach.

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

Ok, I want to get this right. The major point I'm trying to make is that without the Vulkan memory model, the way to get atomic loads and stores is to add the "volatile" memory qualifier to the buffer interface block. This has basically the same set of problems as using "volatile" in pre-C++11 code.

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

My take is that ergonomics are pretty bad, there's a significant learning curve. But I'm also hopeful that it's possible to build tools that layer on top of Vulkan - unlike CUDA, which is a highly integrated toolchain and runtime, Vulkan really only targets the lower levels of the stack.

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

It's a gray area and currently being litigated. If Oracle prevails, then NVidia absolutely would be in a position to shut down compatible implementations of CUDA, or dictate the terms under which they might or might not be able to continue to exist.

Using open standards avoids this risk, though some companies are unwilling to work with Khronos, citing (not publicly detailed) legal concerns.

[1]: https://en.wikipedia.org/wiki/Google_v._Oracle_America

comment 6y ago · link · parent

My personal take on this is that OpenCL is not the way forward, that deployment is going to be on Vulkan and likely WebGPU. But there is an enormous gap in the ecosystem, as Vulkan is very low-level and GLSL is a primitive language for writing compute kernels (though it can be done in theory).

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.

[1]: https://github.com/jgbit/vuda

comment 6y ago · link · parent

Not a coincidence. I talk about that a bit in my thesis on curves: https://levien.com/phd/phd.html

comment 6y ago · link · parent

Sure, you'd want to do this with 32 bit floats in production, the f64 was really for prototyping.

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

There are two considerations here. One is whether you get the optimal assembly for min and max operations. Using the GLSL intrinsic is probably the best way to get confidence in that, but it's also likely that compilers are smart enough to figure it out when given other input. If it did compile to an actual branch, it would be much slower. Also note on AVX there are VMINPS and VMAXPS instructions.

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

It depends on how you use it. The Shadertoy examples demonstrate that it's possible to do a whole scene as one shader, but I agree the performance is not great for complex scenes.

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.

1
404142
63