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

https://en.wikipedia.org/wiki/Johnston_(typeface)

Agreed, it's extremely distinctive.

comment 3y ago · link · parent

This is something that fundamentally can't work, unfortunately. One showstopper (and there may be others) is subgroup size. Nvidia hardware has a subgroup (warp) size of 32, while Intel's subgroup size story is far more complicated, and depends on a compiler heuristic to tune. The short version of the story is that it's usually 16 but can be 8 if there's a lot of register pressure, or 32 for a big workgroup and not much register pressure (and for those who might reasonably question whether forcing subgroup size to 32 can solve the compatibility issue, the answer is that it will frequently cause registers to spill and performance to tank). CUDA code is not written to be agile in subgroup size, so there is no automated translation that works efficiently on Intel GPU hardware.

Longer term, I think we can write GPU code that is portable, but it will require building out the infrastructure for it. Vulkan compute shaders are one good starting point, and as of Vulkan 1.3 the "subgroup size control" feature is mandatory. WebGPU is another possible path to get there, but it's currently lacking a lot of important features, including subgroups at all. There's more discussion of subgroups as a potential WebGPU feature in [1], including how to handle subgroup size.

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

comment 3y ago · link · parent

It really depends on your workload. Prefix sum is pretty important, but you can also work around the missing barrier by doing extra dispatches. You'll want to do that if your goal is portable code. Metal also has some nice things, including real pointers (available in Vulkan 1.3 but not earlier versions, and not in HLSL).

comment 3y ago · link · parent

My personal feeling is that higher level layers should be built on top of strong lower level layers, and we don't have that yet. Scan is of course useful, and there are a ton of them in Vello, but there are other things that are somewhat scan-like but use low-level primitives in a different way, like my stack monoid work.

Out of scope for this blog post, but I also believe there is tremendous potential for hardware that broadly resembles existing GPUs (same register layout, instruction scheduling, memory hierarchy) but with fewer limitations and performance problems. For example, the queue that's currently hardcoded between vertex and fragment shaders could be exposed as a general purpose queue primitive, allowing more dynamic scheduling of multiple different kernels in parallel. I haven't done a deep enough dive into hardware to make concrete proposals, but as I explore, I get more and more indications that what we have access to is a fairly limited subset of what's possible.

comment 3y ago · link · parent

That's correct, it's the memory scope that I expect to be device-scoped. GPUs tend not to have execution barriers in the shader language beyond workgroup scope; generally the next coarser granularity for synchronization is a separate dispatch. However, single-pass prefix sum algorithms, including decoupled look-back, can function just fine with device-scoped memory barriers, and do not require execution barriers with coarser scope than workgroup.

comment 3y ago · link · parent

If you're doing advanced compute work (including lock-free data structures), then it's best effort.

https://github.com/linebender/vello/issues/42 is an issue from when Vello (then piet-gpu) had a single-pass prefix sum algorithm. Looking back, I'm fairly confident that it's a shader translation issue and that it wouldn't work with MoltenVK either, but we stopped investigating when we moved to a more robustly portable approach.

comment 3y ago · link · parent

The most complete documentation is in the applegpu repo[1] by dougallj showing a great deal of recent activity (including by alyssarosenzweig). Last I checked, the documentation of barrier instructions wasn't complete enough to tell whether these device-scoped barriers are possible. (Note: on RDNA2, they're accomplished by DLC and GLC flags on memory accesses, combined with cache flush instructions such as S_GL1_INV).

There's also a lot of great material, accessibly written, on Alyssa's blog[2], see in particular the posts titled "Dissecting the Apple M1 GPU, part ${I}".

[1]: https://github.com/dougallj/applegpu

[2]: https://rosenzweig.io/

308.

Metal shader converter and the missing device-scoped barrier(raphlinus.github.io ↗)

62 points · by raphlinus · 3y ago · 20 comments

comment 3y ago · link · parent

Vello is progressing well, it's most of what I spend my time on these days. I can't promise a date for a stable version, but I would say that for the most part we're on our roadmap.

I'm also interested in quantitative comparisons with the Rive renderer. My personal feeling is that the compute shader approach is more scalable than pixel local storage, but the latter does seem to perform nicely especially on Apple Silicon GPUs.

310.

Xilem Vector Graphics [video](youtube.com ↗)

129 points · by raphlinus · 3y ago · 14 comments

comment 3y ago · link · parent

Toastytech[1] has a great many early Mac screenshots, as well as many others from around that time.

[1]: http://toastytech.com/guis/macos1.html

comment 3y ago · link · parent

I have the Adafruit DVI board and have been hacking on it some. It's more fun than should be allowed.

There's a project to get this running using Rust[1]. Currently it outputs the blue channel with sync, but has trouble with the other two channels. I don't have a hardware lab with scope, logic analyzer, etc., so it's not easy for me to debug.

In the meantime, I've been doing some experiments in the C codebase as well[2], mostly in the direction of proportionally spaced bitmap text, using the fonts in the X11 distribution.

[1]: https://github.com/DusterTheFirst/pico-dvi-rs

[2]: https://github.com/Wren6991/PicoDVI/pull/48

comment 3y ago · link · parent

It is possible but you have to do things very differently, for example use monoids. There are a few compilers implemented on GPU, including Aaron Hsu's co-dfns and Voetter's compiler project[1]. The parentheses matching problem itself (the core of parsing) has long known efficient parallel algorithms and those have been ported to compute shaders[2] (disclosure: blatant self-promotion).

[1]: https://dl.acm.org/doi/pdf/10.1145/3528416.3530249

[2]: https://arxiv.org/pdf/2205.11659.pdf

comment 3y ago · link · parent

Shared memory, yes, with the goodies: atomics and barriers. We rely on that heavily in Vello, so we've pushed very hard on it. For example, WebGPU introduces the "workgroupUniformLoad" built-in, which lets you broadcast a value to all threads in the workgroup while not introducing potential unsafety.

Tensor cores: I can't say there are plans to add it, but it's certainly something I would like to see. You need subgroups in place first, and there's been quite a bit of discussion[1] on that as a likely extension post-1.0.

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

comment 3y ago · link · parent

> ...in the future new functionality will likely be added to take advantage of your GPU in other ways, such as training ML models and then using them via an inference engine all powered by your local GPU?

Yes.

> Is the reason you can't accomplish that today bc APIs haven't been created or opened up to allow such workloads? Are there not lower level APIs available/exposed today in WebGPU that would allow developers to begin the design of browser based ML frameworks/libraries?

That is correct, there is no way before WebGPU to access compute capability of GPU hardware through the Web. There have been some hacks based on WebGL, but those are seriously limited. The fragmentation of the existing API space is a major reason we haven't seen as much progress on this.

> Was it possible to interact with the GPU before WebGPU via Web Assembly?

Only in limited ways through WebGL - no access to workgroup shared memory, ability to do random access writes to storage buffers, etc.

> Other than ML and graphics/games (and someone is probably going to mention crypto), are there any other potentially novel uses for WebGPU?

Yes! There is research on doing parallel compilers on GPU (Aaron Hsu's co-dfns as well as Voetter's work[1]). There's quite a bit of work on implementing Fourier transforms at extremely high throughput. Obviously, physics simulations and other scientific workloads are a good fit. To me, it feels like things are wide open.

[1]: https://dl.acm.org/doi/pdf/10.1145/3528416.3530249

comment 3y ago · link · parent

I suspect this article may even be underestimating the impact of WebGPU. I'll make two observations.

First, for AI and machine learning type workloads, the infrastructure situation is a big mess right now unless you buy into the Nvidia / CUDA ecosystem. If you're a research, you pretty much have to, but increasingly people will just want to run models that have already been trained. Fairly soon, WebGPU will be an alternative that more or less Just Works, although I do expect things to be rough in the early days. There's also a performance gap, but I can see it closing.

Second, for compute shaders in general (potentially accelerating a large variety of tasks), the barrier to entry falls dramatically. That's especially true on web deployments, where running your own compute shader costs somewhere around 100 lines of code. But it becomes practical on native too, especially Rust where you can just pull in a wgpu dependency.

As for text being one of the missing pieces, I'm hoping Vello and supporting infrastructure will become one of the things people routinely reach for. That'll get you not just text but nice 2D vector graphics with fills, strokes, gradients, blend modes, and so on. It's not production-ready yet, but I'm excited about the roadmap.

[Note: very lightly adapted from a comment at cohost; one interesting response was by Tom Forsyth, suggesting I look into SYCL]

comment 3y ago · link · parent

This looks exciting, and I'm looking forward to its progress. I have questions about GPU infrastructure in particular. It seems like the GPU backend is primarily through MLIR. Does that target CUDA? Vulkan compute shaders? WebGPU? Metal shaders? I note that IREE has the first three of those listed as targets, but am not clear on exactly where that fits in to the rest of the ecosystem.

I have an idea of a dream GPU infrastructure based on compute shaders, where you compile your problem into GPU IR suitable for your operating system (SPIR-V, Metal, DXIL) and have a very lightweight runtime that just runs those. For the ahead of time compilation case, you wouldn't need to ship GPU compilers in a deployed application, though you would want that for more rapid iteration when doing research and exploratory programming.

From what I can see so far, this seems basically orthogonal to what Modular and Mojo are trying to do, but it's entirely possible I'm missing something. I'm wondering if anyone is actually building this (IREE and MediaPipe are the closest things in the space I'm aware of), and if not, why not.

comment 3y ago · link · parent

Yes, this is the idea behind the proposed error metrics in my thesis, particularly the "hybrid error metric" in 9.6.1 and then implemented in the Python code (see curves/to_cubic.py in the spiro-0.01 release). But it needs refinement, specifically calibration against perceptual data as measured by experiment.

319.

Simplifying Bézier Paths(raphlinus.github.io ↗)

8 points · by raphlinus · 3y ago · 2 comments

comment 3y ago · link · parent

Too late to edit: I was confusing RV64X and Vortex. It is indeed based on the latter, and extends it in interesting directions, in particular implementing Vulkan instead of just OpenGL.

comment 3y ago · link · parent

Typically in SIMT, all lanes in a "simd" (aka subgroup in Vulkanspeak) share the same program counter. However, there is an execution mask so not all lanes are active. Thus, to simulate "if A then B else C", you evaluate A for each lane to derive a mask, jump to C if the mask is empty, evaluate B only for the enabled lanes, invert the mask, skip over C if the mask is then empty, and evaluate C only for the enabled lanes. Loops also work, with similar logic (the real loop terminates when the predicate is false for all lanes).

comment 3y ago · link · parent

This looks like it has fairly similar goals and implementation choices as RV64X. I didn't immediately see them citing that previous work, but I've only skimmed it so far. In any case, I love seeing work like this.

comment 3y ago · link · parent

Here's my version of the example translated into safe Rust: https://play.rust-lang.org/?version=stable&mode=debug&editio...

This being safe Rust, it fixes the undefined behavior in the C++ version. You can of course implement that in unsafe Rust, but I can't quite bring myself to post that.

comment 3y ago · link · parent

I may be wrong, and overall I'm very sympathetic to changing the patent system to incentivize actually making things. That said, I think changes to policy must be interpreted in an adversarial context, assuming that people will game the system as much as possible. With this policy, patent filers will clearly be incentivized to give away as little of the store as possible. Also, determining whether the code really works, and really represents the system being protected, is just as difficult a problem (if not more so) than interpreting claims today.

comment 3y ago · link · parent

It's pretty easy to predict what would happen in practice if this policy proposal were adopted.

An entire category of bullshit jobs would be created to write "source code" that met the regulatory requirements but had little connection to the actual code deployed in production. This code would largely be derived from the claims, and, like much patent language, be crafted to be as vague and general as possible. Most of this work could be automated by ChatGPT, as no insight is required. Another class of bullshit jobs would be created to interpret and analyze the code, as it's outside the skill set of lawyers and examiners.

Any code published as part of a patent would immediately be anti-open source, as people actually creating things would be strongly discouraged from even looking at it, as doing so would support "willful infringement." The average level of code quality would be such that nobody would want to, anyway.

There's lots that could be done to make the patent system more beneficial to society (including, in my personal opinion, dropping software patents entirely), but I don't think a code requirement would be particularly helpful.

comment 3y ago · link · parent

There are no active plans to do this, but it's all open source and there are tools such as cbindgen, so if there is sufficient interest there's a good chance it will happen.

comment 3y ago · link · parent

This is 0x3f800002, which should look pretty familiar to people who work with floating point in hex; it's 2 + the representation of 1.0. To understand the lowest order bits, you've got -0.0 (0x80000000) in there, as well as everything from 0.0 (0x00000000) to 1.0 (0x3f800000) inclusive.

This is a larger number than the one cited in the post because the latter only includes "normal" numbers. This includes the "denormals" as well.

It's very easy to generalize this to 64 bits, there are 4,607,182,418,800,017,410 of them.

comment 3y ago · link · parent

You might be able to do something along those lines, but I know of no font / vector 2D renderer that does so. There is a lot of literature[1] on this, so I suspect if doing things similar to subdivision surfaces were viable for font rendering, it would have been explored by now.

[1]: https://2d.graphics/book/gpu_rendering.html

comment 3y ago · link · parent

This is true, but there is a lot more to the story. For one, WebGPU does not (yet) support mesh shaders, though it may later as an extension. For two, consider a glyph such as "o" that has two contours. Real triangulation generates a mesh that only generates triangles between the outer and inner contours, and mesh shaders aren't good at that. There are techniques compatible with mesh shaders (cover and stencil) that draw twice, incrementing and decrementing a winding number stored in the stencil buffer (see contrast renderer[1] for a clean modern implementation), but it does require nontrivial tracking on the CPU side, and can result in lots of draw calls to switch between the cover and stencil stages unless sophisticated batching is done. (The outer contour is drawn as a disc with winding number +1, and the inner contour is drawn as a smaller disc with winding number -1, so the inner part ends up as 0)

Compute shaders avoid all these problems and work on WebGPU 1.0 today.

[1]: https://github.com/Lichtso/contrast_renderer

comment 3y ago · link · parent

One of the most exciting features of WebGPU, especially over WebGL, is the ability to run compute shaders. That opens up an entire class of 2D vector graphics rendering techniques using compute shaders, including Vello. It's still in early stages, but the current code does include text rendering. There's a very rough demo at https://levien.com/vello-demo (the demo doesn't do variable fonts but the code can), and we'll be polishing that in time for Chrome M113 going stable.
1
101112
63