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 2y ago · link · parent

WebGPU is not yet performance competitive with CUDA, in part because the cooperative matrix multiplication ("tensor cores" in Nvidia-speak) extension is not done yet. That in turn depends on subgroups, which are pretty far along (but not yet shipping).

That said, you can do machine learning in WebGPU, and, if your goal is to ship in a browser, it is viable.

I personally think the performance gap can be closed with some engineering effort, and that WebGPU has the potential to become a real contender, but it's too early to say for sure. Certainly CUDA has a major head-start.

comment 2y ago · link · parent

WebGL compute was not viable, and only existed as an engineering prototype with lots of rough edges. There were a bunch of hard problems that needed to get solved to ship WebGPU. Perhaps in an alternate universe, that work could have been done in the context of WebGL, but it didn't.

I'll give one example (as it's one I was personally invested in). Doing a barrier in non-uniform control flow is wildly unsafe undefined behavior (I've had it reboot my computer, and it's easy to believe it could be exploited by malicious actors). To make these barriers safe WebGPU does a "uniformity analysis." However, that in turn required adding uniform broadcast intrinsic to the shader language, otherwise a class of algorithms would be impossible to express.

As I say, it's plausible this kind of work could have been done as extensions to WebGL, but I think the end result would have been a lot less compelling than what we have now.

comment 2y ago · link · parent

Cheering on the progress. As a long time user of wgpu in Vello, I'm impressed with the progress there. The advanced compute stuff has been working quite well, and it's also got some nice extensions like subgroups (so far only usable in native configurations, but I'm hopeful the extension will be standardized so it's available in browser as well).

184.

I want a good parallel computer [video](youtube.com ↗)

15 points · by raphlinus · 2y ago · discuss

comment 2y ago · link · parent

Yes! The workhorse numerical technique is Chebyshev approximation. Remez exchange usually starts with it, for fine-tuning with respect to a "maximum error" norm, but it also works quite well by itself, and can be computed efficiently (even with a high degree) even from a function you can only evaluate numerically.

A really good place to read up on it is the documentation for Chebfun.

https://www.chebfun.org/docs/guide/guide04.html

Also: be on the lookout for a blog post on using Chebyshev polynomials to efficiently compute error metrics for curves.

comment 2y ago · link · parent

That's a really good reason, and thanks for the writeup!

My main point is that I believe there are tons of excellent numerical techniques just waiting to be discovered. Lately I've been exploring a Chebyshev polynomial basis for the Whewell equation, and I think that'll bear fruit.

comment 2y ago · link · parent

I think it's a great avenue for research. I'm probably not going to work on it myself any time soon, as I have a very full queue of ideas to pursue.

comment 2y ago · link · parent

Numerical solutions are better. Having a closed form solution is overrated. For example, the closed form solution for arc length of a quadratic Bézier becomes numerically unstable for curves that are close to a straight line. In those cases, you definitely want the numerical approach.

I also think Pythagorean Hodograph curves are overrated. Euler spirals, on the other hand, are extremely easy to work with in an arc length parametrization, it's just that you need to compute a "special function" to get back to parametrized land. Fortunately, that's easy enough to compute very accurately using standard numerical techniques.

comment 2y ago · link · parent

That's actually a very good question. To some extent, performance analysis tools may be able to give you high-accuracy timestamps of things involving context switches and other things that can cause scheduling jitter. If you can get access to things like the fill level of FIFO buffers, even better. You may also be able to do experiments like cutting buffer sizes down to the bone to see how low they can go without glitching.

Of course, it's not unusual that the many layers of abstraction in modern systems actively frustrate getting real performance data. But dealing with that is part of the requirements of doing real engineering.

comment 2y ago · link · parent

It continues to be relevant. On modern computers, mobile especially, there are are more and more things that can glitch audio from being actually real-time. Probably one of the worst offenders is power management; it is extremely likely that the power management governor has no awareness of upcoming audio deadlines.

Obviously the happy case is when all the audio processing is done in a DSP where scheduling is deterministic, but it's rare to be able to count on that. Part of the problem is that modern computers are so fast that people expect them to handle audio tasks without breathing hard. But that speed is usually measured as throughput rather than worst-case latency.

The advice I'd give to anybody building audio today is to relentlessly measure all potential sources of scheduling jitter end-to-end. Once you know that, it becomes clearer how to address it.

comment 2y ago · link · parent

+1 to always measuring. That said, we have done some experiments regarding power, including on Android, and it looks favorable.

The general rule of thumb is that a GPU has about 10x the raw throughput per joule as a CPU (which, today, is basically the same metric as throughput per dollar). So if your GPU is only barely faster than the CPU because of overheads of the parallel algorithm, you might not win, but if it sails way past the CPU because it's work efficient and lean (as I believe this work is), you do win both on power and throughput (frames per second).

comment 2y ago · link · parent

So this is a little bit more complicated as a tradeoff. The main reason Skia is faster is that it's generating fewer primitives (quadratic Béziers instead of lines or arcs). Depending on the details of the renderer, you may also want to lower to a simpler primitive, and our method does both. If the goal is lines, then the additional cost of applying, say, Wang's method would make them take roughly the same runtime, though our method would produce fewer lines. If the goal is arcs, then I think our method comes out way ahead, as I'm not aware of anything else that generates arcs efficiently.

But it does mean that for outline-to-outline applications running on the CPU, methods like Skia's are likely better (though ours is still faster than the Nehab implementation).

I'm working on a cubic-to-cubic version also, but it's requiring some pretty deep math. See the Zulip thread to follow that work in progress[1].

[1]: https://xi.zulipchat.com/#narrow/stream/260979-kurbo/topic/C...

comment 2y ago · link · parent

Good catch! We took the mmark CPU numbers out (in response to review feedback) because they made the graphs hard to read, but it scales very much the same way as the Nehab timings dataset. The raw CPU numbers for mmark are in the repo[1] in the "timings" file.

[1]: https://github.com/linebender/gpu-stroke-expansion-paper

comment 2y ago · link · parent

The technique works for both fills and strokes, and is used by Vello for both, including for the text rendering. One of the nice things we found is that lowering Euler spirals to arcs works particularly well, and you need many fewer arc segments than line segments to accurately approximate a smooth curve. We haven't plumbed arcs all the way through the rendering pipeline yet, but it's planned; the math for rendering arcs is not that much more complicated than lines.

195.

GPU-Friendly Stroke Expansion(arxiv.org ↗)

180 points · by raphlinus · 2y ago · 39 comments

comment 2y ago · link · parent

The description of "project manager mathematicians" reminded me of "A letter to my old friend Jonathan" [1] and the followup [2] by Edsger Dijkstra from 1975. It was written as satire, basically criticizing the way that software was produced by showing how ridiculous it would be to produce mathematics the same way. But in some ways it was prescient. Of course, the main point of these documents is to critique intellectual property (particularly the absurdity of applying it to mathematical truth) but fortunately that aspect is not a significant concern of this push toward mechanization.

[1]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/E...

[2]: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD05xx/E...

comment 2y ago · link · parent

There's a bit more information at [1], but I think the details are not public. The hardware is tracking a separate program counter (and call stack) for each thread. So in the CAS example, one thread wins and continues making progress, while the other threads loop.

There seems to some more detail in a Bachelors thesis by Phillip Grote[2], with lots of measurements of different synchronization primitives, but it doesn't go too deep into the hardware.

[1]: https://arxiv.org/abs/2205.11659

[2]: https://www.clemenslutz.com/pdfs/bsc_thesis_phillip_grote.pd...

comment 2y ago · link · parent

I'm not aware of any similarly mature GPU-based JSON parser, but I believe such a thing is possible. My stack monoid work [1] contains a bunch of ideas that may be helpful for building one. I've thought about pursuing that, but have kept focus on 2D graphics as it's clearer how that will actually be useful.

[1]: https://arxiv.org/abs/2205.11659

comment 2y ago · link · parent

One of the other major things that's changed is that Nvidia now has independent thread scheduling (as of Volta, see [1]). That allows things like individual threads to take locks, which is a pretty big leap. Essentially, it allows you to program each individual thread as if it's running a C++ program, but of course you do have to think about the warp and block structure if you want to optimize performance.

I disagree that SIMT is only for embarrassingly parallel problems. Both CUDA and compute shaders are now used for fairly sophisticated data structures (including trees) and algorithms (including sorting).

[1]: https://developer.nvidia.com/blog/inside-volta/#independent_...

comment 2y ago · link · parent

There's also a recent Mastodon thread[1] that has the highlights of this blog post and links to it.

[1]: https://mastodon.online/@johncarlosbaez@mathstodon.xyz/11258...

comment 2y ago · link · parent

Until that video comes out, you can read the proposal[1]. This appears to be quite recent (the timestamp says 4 days ago).

I personally found the writing style of the proposal to be clearer than the tutorial-flavor of the original blog post (I haven't watched the video). But that's probably because I have a programming language background and am intimately familiar with Rust.

[1]: https://github.com/modularml/mojo/blob/main/proposals/lifeti...

comment 2y ago · link · parent

Personally, I would say writing compute shaders to do nontrivial tasks like parsing, sorting, and handling data structures. There's a lot of this in Vello. There's a small community of people doing this, which I think will be growing as WebGPU catches on.

comment 2y ago · link · parent

I think that to some extent represents the dream, with caveats. A few pieces need to fall into place.

1. You need to formalize the semantics of unsafe Rust. Ralf Jung's pioneering RustBelt[1] work was a huge step in that direction, but it is not yet complete. One element that's emerging as tricky is "pointer provenance."

2. Part of that is making a formal model of the borrow checker. Stacked borrows[2] was a good attempt, but has some flaws. Tree borrows[3] may correct those flaws, but it's possible something even more refined may emerge.

3. Another part of that is a formal memory model, which is mostly about the behavior of atomics and synchronization (thus, is critically important for standard library components such as Arc). It is widely understood that Rust's memory model should be similar to the C++ one (and that they should interoperate), but there are some remaining flaws in that, such as the "out of thin air" problem and also some missing functionality like seqlocks (part of why the Linux kernel still has its own).

4. You need a proof that the safety guarantees compose well; in particular if you have sound code written in unsafe Rust, composed with other code written in safe Rust, the safety guarantees still hold. There are good results so far but it needs to be proved over the entire system.

5. You do need to close all the remaining soundness bugs in Rust[1], for such a proof to hold for all code. Progress on this is slow, as many of these problems are theoretical, or are only really relevant for adversarial code[5].

When all this is done, you still only have a partial guarantee. Huge amounts of the surface area to interface with the system are based on unsafe code. If you're doing only pure computation, that's one thing, but if you're building, say, a graphical UI, there's a massive amount of stuff that can still go wrong.

Even so, there is a practical path forward, and that leads to a much better situation than the usual state of things today, which is of course systems riddled with vulnerabilities.

[1]: https://people.mpi-sws.org/~dreyer/papers/rustbelt/paper.pdf

[2]: https://plv.mpi-sws.org/rustbelt/stacked-borrows/

[3]: https://www.ralfj.de/blog/2023/06/02/tree-borrows.html

[4]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Ao...

[5]: https://github.com/Speykious/cve-rs

comment 2y ago · link · parent

It's a good question. I touch on it a little in my thesis (mostly chapter 2). First, there is psychology literature from the 50's [1] that indicates that curvature minima and maxima are salient, so having superfluous curvature extrema makes a curve less aesthetically pleasing. Hobby splines suffer from this, if you arrange the control points in a zigzag to make a serpentine, it places curvature extrema just on either side of the control point.

Second, there's all the log-aesthetic stuff from Japan, [2] has links to a lot of papers. Honestly, I find their claims of aesthetic beauty to be fluffy, not backed up by hard empirical evidence. I did do a small amount of human evaluation research in [3], which suggests that the log-aesthetic curves are visually pleasing, but the math for their use in an interpolating spline (which is the subject of TFA) is less stable than Hobby splines, Euler spiral splines, or Minimum Energy Curves (all of which are fairly similar).

I think there's more that could be done here. Thanks for your question.

[1]: Fred Attneave. Some informational aspects of visual perception. Psychological Review, 61(3):183–193, 1954.

[2]: https://www.yoshida-lab.net/english/research-e/log-aesthetic...

[3]: https://levien.com/phd/LevienSequinCAD09_014.pdf

comment 2y ago · link · parent

That's a joke answer, as you meant it to be trivially true for any curve family, but there is an important sense in which it is not true - Hobby splines are not closed under subdivision. So if you put an additional point down that lies exactly on the spline, then you won't in fact minimize the supremal difference (I assume you mean Hausdorff or Fréchet distance) to the original Hobby spline.

comment 2y ago · link · parent

No. Among other things, they'd have a higher degree of continuity if they were.

I personally find this a fascinating topic, so much so that I did a PhD on it. The most natural loss function to optimize for is minimizing bending energy, and there are solutions to that going back about 300 years. However, in practice that's unlikely to be what you want - the problem with it is that its scaling properties give an advantage to curves with a longer arclength even if they have more curvature variation. Intuitively, the smoothest curve through a set of co-circular points should be a circular arc, but that's not what you get from the minimum energy curve, at least unless you impose an additional arc length constraint.

The long story is of course much more complicated, but the short version is that the Euler spiral fixes these scaling issues and has some other really nice properties. If your problem is "what is the smoothest curve that goes through this sequence of points" then arguably the piecewise Euler spiral G2 continuous spline is the distinguished answer.

comment 2y ago · link · parent

Most of the applications of Hobby's spline would be better served by using Euler spirals instead. These are G2 continuous and have less curvature varation (in fact, Euler spirals are solutions of the Minimum Variation Curvature problem). I think it's fair to characterize Hobby's spline as an approximation to Euler spiral splines, just less expensive to compute.

I think there's even more to be done on this topic. In particular, I think the tension should increase as angles go up, which can solve the "flipping" behavior you see with both Hobby and Euler spiral splines. This is true for the Adobe κ-curves paper (which considerably overstates the extent to which it's the basis for the "curvature" tool in Adobe Illustrator; the latter has not to my knowledge been adequately documented).

comment 2y ago · link · parent

As a counterpoint, I appreciated this recent post by Martin Kleppmann[1]:

I've worked out why I don't get much value out of LLMs. The hardest and most time-consuming parts of my job involve distinguishing between ideas that are correct, and ideas that are plausible-sounding but wrong. Current AI is great at the latter type of ideas, and I don't need more of those.

[1]: https://bsky.app/profile/martin.kleppmann.com/post/3kquvol6s...

comment 2y ago · link · parent

It's... ok.

What kurbo does is lower to quadratic Béziers[1], then the analytic solution to nearest for a quadratic Bézier is the solution to a cubic equation[2].

I'm not sure this is the best possible answer, but it's at least pretty good, and certainly better than flattening to lines.

And I'd like for people to get in the habit of checking kurbo; the intent is for it to always have the best in class algorithm.

[1]: https://docs.rs/kurbo/latest/src/kurbo/cubicbez.rs.html#647-...

[2]: https://docs.rs/kurbo/latest/src/kurbo/quadbez.rs.html#297-3...

1
678
63