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

Oh hey, I also have "in defense of undefined behavior" in the queue of blog posts I'd like to write some time, with that exact title. What a coincidence. That said, it's unlikely to get written as I have things that are more specific to my actual research ahead of it.

One of the things I'd want to say is that UB is a useful and accurate way to model what happens when, say, a program writes over memory used by the allocator. Languages like Odin might try to pretend they don't have UB, but in my opinion it's impossible to get there just by disabling certain compiler optimizations (see https://news.ycombinator.com/item?id=32800814 for an argument about this).

I see UB as essentially a proof obligation, to be discharged in some other way. A really good way is to have UB in the intermediate representation, and compile a safe language into it (with unsafe escape hatches when needed). But there are other ways, including formal methods, rigorous testing, or just being a really smart solo programmer who's learned how to avoid UB and doesn't have to work in a team.

Feel free to send me your draft.

comment 1y ago · link · parent

Well, I have some qualifications in typography, a reasonable familiarity with ML techniques, and am fairly good at math (though I can't claim to have won the Putnam), and I can imagine how to apply ML for this task.

comment 1y ago · link · parent

Agree with sibling comments. There's something very slippery and tricky going on with "perceptual area," it's not simple geometry. This is actually an area where I think machine learning has something to offer.

comment 1y ago · link · parent

Yup, nothing wrong with clear exposition about simpler algorithms, there's definitely a place for that. I just thought HN readers should have some more context on whether we were looking at a programming exercise or state of the art algorithms.

comment 1y ago · link · parent

The second one is Thomas Smith's independent reimplementation of Onesweep. For the official version, see https://github.com/NVIDIA/cccl . The Onesweep implementation is in cub/cub/agent/agent_radix_sort_onesweep.cuh .

comment 1y ago · link · parent

This is not a fast way to sort on GPU. The fastest known sorting algorithm on CUDA is Onesweep, which uses a lot of sophisticated techniques to take advantage of GPU-style parallelism and work around its limitations.

Linebender is working (slowly) on adapting these ideas to GPUs more portably. There's a wiki page here with some resources:

https://linebender.org/wiki/gpu/sorting/

comment 1y ago · link · parent

You might enjoy this talk by Erik Lindholm (now retired), who talks about Riva 128 and many of the other early Nvidia cards: https://ubc.ca.panopto.com/Panopto/Pages/Viewer.aspx?id=880a...

158.

Closing the “green gap”: energy savings from the math of the landscape function(terrytao.wordpress.com ↗)

111 points · by raphlinus · 1y ago · 71 comments

comment 1y ago · link · parent

I just want to say I'm rooting for you, and hope you enjoy the book and learn a lot from it.

I had a bad experience with complex analysis as a teen (took a grad class that was a bit over my head). Many years later, I got Tristan Needham's "Visual Complex Analysis" and the whole thing clicked for me - I'm a visual person and do a lot of geometry. I hope your experience is similar.

comment 2y ago · link · parent

I see your point, but one issue is that you can't go from HLSL or GLSL to WGSL for compute work, as the way atomics are typed is incompatible[1]. That's a primary reason we (currently) use WGSL, because going from that to legacy shader languages does work. But then you have all the limitations of WGSL.

Slang had to make a change to its type system[2] to make this work. But they did it, and as a result Slang is appealing as an "apex" language - you can translate from that to anything, and also get advanced features lacking in WebGPU.

[1]: https://github.com/gpuweb/gpuweb/issues/2377

[2]: https://github.com/shader-slang/slang/issues/5084

comment 2y ago · link · parent

In this case, GP has it very much right. Brotli was developed by people, not just faceless Googlers. Jyrki, who led the project, is as passionate an engineer as you're likely to meet. In this case, being able to pursue that passion happened to align well with Google's business interests, as it is indeed the case that improvements to compression have obvious benefits at scale when bandwidth and storage cost real money. But someone still has to push the initiative, and it's not as easy as you might think.

Disclosure: have collaborated with Jyrki and the compression team, including WOFF2 font compression, an early application of Brotli.

comment 2y ago · link · parent

Circle involute is one of my favorite curves. It has a particularly nice Cesàro equation: κ = c√s. It also has the unusual property of being its own parallel curve. Thus, if you were to draw a curve using piecewise circle involutes, you'd have an exact mathematical offset.

It'll show up in a blog post soon, once I get back to having enough time to write.

comment 2y ago · link · parent

The title immediately brings to mind the Osterhout classic, "Always Measure One Level Deeper", [1], and I imagine was probably inspired by it. Also worth revisiting.

[1]: https://cacm.acm.org/research/always-measure-one-level-deepe...

comment 2y ago · link · parent

The page mostly talks about image resampling where the goal is more or less preserving all frequencies, but it's also extremely effective at implementing Gaussian blur. Basically, you do n iterations of sampling by 1/2 using this kernel, followed by a very small FIR filter, then n iterations of upsampling 2x using the same kernel. Here, n is essentially log2 of the blur radius, and the total amount of computation is essentially invariant to that radius. All these computations are efficient on GPU - in particular, the upsampling can be done using vanilla bilinear texture sampling (which is very cheap), just being slightly clever about the fractional coordinates.

It works well because, as stated, the kernel does a good job rejecting frequencies prone to aliasing. So, in particular, you don't get any real quality loss from doing 2x scale changes as opposed to bigger steps (and thus considerably larger FIR support).

I have some Python notebooks with some of these results, haven't gotten around to publishing them yet.

comment 2y ago · link · parent

Thanks for the kind words and the clarification. I'm sure you're right; I was just multiplying things together without taking into account the different capabilities of the different execution units. Hopefully that doesn't invalidate the major points I was making.

comment 2y ago · link · parent

Here's my quick take.

A top of the line Zen core is a powerful CPU with wide SIMD (AVX-512 is 16 lanes of 32 bit quantities), significant superscalar parallelism (capable of issuing approximately 4 SIMD operations per clock), and a high clock rate (over 5GHz). There isn't a lot of confusion about what constitutes a "core," though multithreading can inflate the "thread" count. See [1] for a detailed analysis of the Zen 5 line.

A single Granite Ridge core has peak 32 bit multiply-add performance of about 730 GFLOPS.

Nvidia, by contrast, uses the marketing term "core" to refer to a single SIMD lane. Their GPUs are organized as 32 SIMD lanes grouped into each "warp," and 4 warps grouped into a Streaming Multiprocessor (SM). CPU and GPU architectures can't be directly compared, but just going by peak floating point performance, the most comparable granularity to a CPU core is the SM. A warp is in some ways more powerful than a CPU core (generally wider SIMD, larger register file, more local SRAM, better latency hiding) but in other ways less (much less superscalar parallelism, lower clock, around 2.5GHz). A 4090 has 128 SMs, which is a lot and goes a long way to explaining why a GPU has so much throughput. A 1080, by contrast, has 20 SMs - still a goodly number but not mind-meltingly bigger than a high end CPU. See the Nvidia Ada whitepaper [2] for an extremely detailed breakdown of 4090 specs (among other things).

A single Nvidia 4090 "core" has peak 32 bit multiply-add performance of about 5 GFLOPS, while an SM has 640 GFLOPS.

I don't know anybody who counts tensor cores by core count, as the capacity of a "core" varies pretty widely by generation. It's almost certainly best just to compare TFLOPS - also a bit of a slippery concept, as that depends on the precision and also whether the application can make use of the sparsity feature.

I'll also note that not all GPU vendors follow Nvidia's lead in counting individual SIMD lanes as "cores." Apple Silicon, by contrast, uses "core" to refer to a grouping of 128 SIMD lanes, similar to an Nvidia SM. A top of the line M2 Ultra contains 76 such cores, for 9728 SIMD lanes. I found Philip Turner's Metal benchmarks [3] useful for understanding the quantitative similarities and differences between Apple, AMD, and Nvidia GPUs.

[1]: http://www.numberworld.org/blogs/2024_8_7_zen5_avx512_teardo...

[2]: https://images.nvidia.com/aem-dam/Solutions/Data-Center/l4/n...

[3]: https://github.com/philipturner/metal-benchmarks

comment 2y ago · link · parent

It's Euclideon. And it is octtrees. My interpretation after reading a fascinating Reddit thread [1] is that these denials were misdirection. There's definitely new interest in splatting techniques (Gaussian in particular), though they've long been an alternative to triangles in the 3D world. I think it'd be fun to experiment with implementing some of that using modern compute shaders.

[1]: https://www.reddit.com/r/VoxelGameDev/comments/1bz5vvy/a_sma...

comment 2y ago · link · parent

To be precise, this is running in a compute shader (rasterizeSwPass.wgsl.ts for the curious). You can think of that as running the GPU in a mode where it's a type of computer with some frustrating limitations, but also the ability to efficiently run thousands of threads in parallel.

This is in contrast to hardware rasterization, where there is dedicated hardware onboard the GPU to decide which pixels are covered by a given triangle, and assigns those pixels to a fragment shader, where the color (and potentially other things) are computed, finally written to the render target as a raster op (also a bit of specialized hardware).

The seminal paper on this is cudaraster [1], which implemented basic 3D rendering in CUDA (the CUDA of 13 years ago is roughly comparable in power to compute shaders today), and basically posed the question: how much does using the specialized rasterization hardware help, compared with just using compute? The answer is roughly 2x, though it depends a lot on the details.

And those details are important. One of the assumptions that hardware rasterization relies on for efficiency is that a triangle covers dozens of pixels. In Nanite, that assumption is not valid, in fact a great many triangles are approximately a single pixel, and then software/compute approaches actually start beating the hardware.

Nanite, like this project, thus actually uses a hybrid approach: rasterization for medium to large triangles, and compute for smaller ones. Both can share the same render target.

[1]: https://research.nvidia.com/publication/2011-08_high-perform...

comment 2y ago · link · parent

Faith Ekstrand has an impressive track record of compiler work and has written a few blog posts[1], [1a]. Her Mastodon[2] is also worth a follow.

SPIR-V is important in the compute shader space, especially because DXIL and Metal's AIR are similar. I'm going to link three articles critical of SPIR-V: [3], [4], [5].

WebGPU [6] is interesting for a number of reasons, largely because they're trying to actually nail down the semantics, and also make it safe (see the uniformity analysis [7] in particular, which is a very "compiler" approach to a GPU-specific problem). Both Tint and naga projects are open source, with lots of high quality discussion in the issue trackers.

Shader languages suck, and we really need a good one. Promising approaches are Circle [8] (which is C++ based, very advanced but not open source), and Slang [9] (an evolution of HLSL). The Vcc work (also related to [4]) is worth studying.

Best of luck! This is a fascinating, if frustrating, space, and there's lots of room to improve things.

[1]: https://www.gfxstrand.net/faith/blog/

[1a]: https://www.collabora.com/news-and-blog/blog/2024/04/25/re-c...

[2]: https://mastodon.gamedev.place/@gfxstrand

[3]: https://kvark.github.io/spirv/2021/05/01/spirv-horrors.html

[4]: https://xol.io/blah/the-trouble-with-spirv/

[5]: https://themaister.net/blog/2022/08/21/my-personal-hell-of-t...

[6]: https://github.com/gpuweb/gpuweb

[7]: https://www.w3.org/TR/2022/WD-WGSL-20220505/#uniformity-over...

[8]: https://www.circle-lang.org/site/index.html

[9]: https://github.com/shader-slang/slang

comment 2y ago · link · parent

The quadratic solver implementation in kurbo is designed to be fast and reasonably precise for a wide range of inputs. But for a definitive treatment of how to solve quadratic equations, see "The Ins and Outs of Solving Quadratic Equations with Floating-Point Arithmetic" by Goualard[2]. I thought I understood the problem space pretty well, then I came across that.

[1]: https://github.com/linebender/kurbo/blob/b5bd2aa856781c6cf46...

[2]: https://cnrs.hal.science/hal-04116310/document

comment 2y ago · link · parent

Same here, except without the scare quotes. Understanding the natural world is absolutely core to being intellectually curious. And meteors are relevant to our experience on Earth, as are more generally atmospheric systems on orbital bodies. If you wanted to pick on useless research, you could find a lot better examples than this.

comment 2y ago · link · parent

My understanding is that the HSTX can do twice the bit clock as the frequency of the CPU, as opposed to 1x for RP2040. So 800x480 (60Hz) is possible with no overclocking (295MHz bit clock) and Luke said [1] he got 1280x720 50Hz with overclocking (530MHz using CVT-R according to the video timings calculator [2]).

[1]: https://mastodon.online/@wren6991@types.pl/11292855122145752...

[2]: https://tomverbeure.github.io/video_timings_calculator

comment 2y ago · link · parent

Ah, you watched my "good parallel computer" talk[﹡] :)

If I were going to take it on, I'd start with BVH construction - the H-PLOC paper at the latest HPG [1] looks promising - then traverse down the hierarchy until you get very small number of path segments so you can pairwise compare them. Obviously any time there is an intersection you need at least the two segments.

This seems hard to me, humbling even. I mean, overlap removal is hard enough on the CPU, especially because it's so sensitive to numerical robustness, and doubly so for curves. But I think you'll learn something for trying!

[﹡] https://news.ycombinator.com/item?id=41105102 but it didn't make the front page; I'm holding back promoting it further pending writing a companion blog post.

[1]: https://gpuopen.com/download/publications/HPLOC.pdf

comment 2y ago · link · parent

If you want to go hardcore into the frequency domain, may I suggest "A Fresh Look at Generalized Sampling" by Nehab and Hoppe[1]. That said, while a frequency-centric approach works super well for audio, for images you need to keep good track of what happens in the spatial domain, and in particular the support of sampling filters needs to be small.

[1]: https://hhoppe.com/filtering.pdf

comment 2y ago · link · parent

I don't see how you can support the claim of perfect thin line rendering, it's visibly just not very good. So box filtering logically can't possibly be the best possible quality.

Can we make a magical adaptive filter which resembles box filter for half-planes, a tent filter for thin lines, Mitchell-Netravali or oblique projection for natural images, and Gaussian when filtering images for which high frequency detail is not important? Perhaps, but that feels like advanced research, and also computationally expensive. I don't think you can claim "perfect" without backing it up with human factors data really demonstrating that the filtered images are optimum with respect to perceived quality.

comment 2y ago · link · parent

These are sampling artifacts, but I believe yorbwa is correct in distinguishing these from conflation artifacts, as defined in Kilgard & Bolz. I think of the latter as compositing not commuting exactly with antialiasing (sampling). You only get conflation artifacts when compositing multiple shapes (or rendering a single shape using analytical area when the winding number is not everywhere 0 or 1), while you definitely see aliasing when rendering a single shape, say a Siemens star.

comment 2y ago · link · parent

I think the story is a lot more complicated. Talking about "the best possible output quality" is a big claim, and I have no reason to believe it can be achieved by mathematically simple techniques (ie linear convolution with a kernel). Quality is ultimately a function of human perception, which is complex and poorly understood, and optimizing for that is similarly not going to be easy.

The Mitchell-Netravali paper[1] correctly describes sampling as a tradeoff space. If you optimize for frequency response (brick wall rejection of aliasing) the impulse response is sinc and you get a lot of ringing. If you optimize for total rejection of aliasing while maintaining positive support, you get something that looks like a Gaussian impulse response, which is very smooth but blurry. And if you optimize for small spatial support and lack of ringing, you get a box filter, which lets some aliasing through.

Which is best, I think, depends on what you're filtering. For natural scenes, you can make an argument that the oblique projection approach of Rocha et al[2] is the optimal point in the tradeoff space. I tried it on text, though, and there were noticeable ringing artifacts; box filtering is definitely better quality to my eyes.

I like to think about antialiasing specific test images. The Siemens star is very sensitive in showing aliasing, but it also makes sense to look at a half-plane and a thin line, as they're more accurate models of real 2D scenes that people care about. It's hard to imagine doing better than a box filter for a half-plane; either you get ringing (which has the additional negative impact of clipping when the half-planes are at the gamut boundary of the display; not something you have to worry about with natural images) or blurriness. In particular, a tent filter is going to be softer but your eye won't pick up the reduction in aliasing, though it is certainly present in the frequency domain.

A thin line is a different story. With a box filter, you get basically a non antialiased line of single pixel thickness, just less alpha, and it's clearly possible to do better; a tent filter is going to look better.

But a thin line is just a linear combination of two half-planes. So if you accept that a box filter is better visual quality than a tent filter for a half-plane, and the other way around for a thin line, then the conclusion is that linear filtering is not the correct path to truly highest quality.

With the exception of thin lines, for most 2D scenes a box filter with antialiasing done in the correct color space is very close to the best quality - maybe the midwit meme applies, and it does make sense to model a pixel as a little square in that case. But I am interested in the question of how to truly achieve the best quality, and I don't think we really know the answer yet.

[1] https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/l...

[2] https://www.inf.ufrgs.br/~eslgastal/SBS3/Rocha_Oliveira_Gast...

comment 2y ago · link · parent

No, Vello does not analytically find intersections. Compositing is (currently) done by alpha blending, which is consistent with the W3C spec but has its own tradeoffs.

comment 2y ago · link · parent

I love to see more work in this space. It's clear that GPU compute is the future of 2D rendering, and we need to explore a bunch of different approaches to find the best one. I especially appreciate the focus on rendering quality; the author is absolutely correct that the current state of Vello has conflation artifacts and does not do antialiasing in the correct (linear) colorspace.

We do have a plan for conflation free compositing[1] which should closely approximate the quality of the samples here. That in turn depends on sparse strips[2], though a degraded performance experiment could be done to validate the quality outcomes. Sparse strips in turn depend on high performance segmented sort[3].

The analytic approach to path overlaps is intriguing, but I think it will be very challenging to implement efficiently on GPU. I'm looking forward to seeing what results.

[1]: https://xi.zulipchat.com/#narrow/stream/197075-gpu/topic/Con...

[2]: https://docs.google.com/document/d/16dlcHvvLMumRa5MAyk2Du_Ms...

[3]: https://xi.zulipchat.com/#narrow/stream/197075-gpu/topic/A.2...

comment 2y ago · link · parent

The official deprecation [1] cites "some technical barriers, including ... [macOS support]". I'm not able to speak for Chrome, but my understanding is that these technical barriers included serious challenges in making it safe. That's where a significant amount of engineering went into WebGPU from the beginning.

[1]: https://issues.chromium.org/issues/40150444

1
567
63