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

Sure. It's a tradeoff space. Gain portability and ergonomics, lose throughput. For applications that are throttled by TOPS at low precisions (ie most ML inferencing) then the performance drop from not being able to use tensor cores is going to be unacceptable. Glad you found something that works for you, but it certainly doesn't spell the end of CUDA.

comment 2y ago · link · parent

That's a really good question. I don't know enough about SYCL to be able to tell you the answer, but I've heard rumblings that it may be the thing to watch. I think there may be some other limitations, for example SYCL 2020 depends on unified shared memory, and that is definitely not something you can depend on in compute shader land (in some cases you can get some of it, for example with resizable BAR, but it depends).

In researching this answer, I came across a really interesting thread[1] on diagnosing performance problems with USM in SYCL (running on AMD HIP in this case). It's a good tour of why this is hard, and why for the vast majority of users it's far better to just use CUDA and not have to deal with any of this bullshit - things pretty much just work.

When targeting compute shaders, you pretty much have to manage buffers manually, and also do copying between host and device memory explicitly (when needed - on hardware such as Apple Silicon, you prefer to not copy). I personally don't have a problem with this, as I like things being explicit, but it is definitely one of the ergonomic advantages of modern CUDA, and one of the reasons why fully automated conversion to other runtimes is not going to work well.

[1]: https://stackoverflow.com/questions/76700305/4000-performanc...

comment 2y ago · link · parent

The two I know of are IREE and Kompute[1]. I'm not sure how much momentum the latter has, I don't see it referenced much. There's also a growing body of work that uses Vulkan indirectly through WebGPU. This is currently lagging in performance due to lack of subgroups and cooperative matrix mult, but I see that gap closing. There I think wonnx[2] has the most momentum, but I am aware of other efforts.

[1]: https://kompute.cc/

[2]: https://github.com/webonnx/wonnx

comment 2y ago · link · parent

I understand why you've picked D3D11, but people have to understand that comes with serious limitations. There are no subgroups, which also means no cooperative matrix multiplication ("tensor cores"). For throughput in machine learning inference in particular, there's no way D3D11 can compete with either CUDA or a more modern compute shader stack, such as one based on Vulkan 1.3.

comment 2y ago · link · parent

Vulkan 1.3 has pointers, thanks to buffer device address[1]. It took a while to get there, and earlier pointer support was flawed. I also don't know of any major applications that use this.

Modern Vulkan is looking pretty good now. Cooperative matrix multiplication has also landed (as a widely supported extension), and I think it's fair to say it's gone past OpenCL.

Whether we get significant adoption of all this I think is too early to say, but I think it's a plausible foundation for real stuff. It's no longer just a toy.

[1] https://community.arm.com/arm-community-blogs/b/graphics-gam...

comment 2y ago · link · parent

That's the right question, and what my work a quarter century ago on "attack resistant trust metrics" attempted to answer. That's written up in a bunch of places, but I think probably the best starting point is my "lessons from Advogato"[1] talk in 2007.

[1]: https://www.youtube.com/watch?v=d9gjy1OsTGQ

comment 2y ago · link · parent

Which largely explains the fontations project. This is new Rust implementation of the lower levels of the font stack, and also on track to shipping, it's now in Chrome Canary.

https://github.com/googlefonts/fontations

comment 3y ago · link · parent

I haven't carefully read the relevant part of the spec, but I imagine that pointers have to be modeled as not subject to tearing, otherwise safety guarantees would completely fall apart.

The flip side of this is that adding "fat pointers" safely to Java would be very difficult. Fat pointers are widely used in languages such as Go, Rust, and Swift to represent both slices (pointer + length) and various forms of dynamic dispatch (pointer + vtable). In Rust, this is safe because data races are forbidden, enforced by the type system. I consider Go and Rust to be "safe-ish" in that data races can happen, and can violate safety. Apparently this hasn't led to huge problems in Go. Thus, the roadmap for Carbon[1] targets a comparable level of safety, not trying to prevent data races, but aiming for memory safety in single threaded contexts.

[1]: https://www.youtube.com/watch?v=1ZTJ9omXOQ0

comment 3y ago · link · parent

It's essentially the same as a relaxed atomic at the machine level, but it's weaker - it corresponds to "unordered" in the LLVM sense. In particular, it allows for a lot more optimization - operations can be reordered with respect to each other as long as the compiler is aware that they refer to disjoint memory locations.

comment 3y ago · link · parent

For the generation of simplified Bézier paths, I hope they consider the new methods in kurbo[1]. These have some fairly fancy math behind them and result in pretty close to a global optimum in terms of the minimal number of segments needed to hit an error target. They don't do implicit low-pass filtering, rather treat the input as a source of truth, but perhaps options could be added for that.

[1]: https://docs.rs/kurbo/latest/kurbo/simplify/index.html

comment 3y ago · link · parent

A particular point in the space I find very appealing is emulators running on RP2040 class microcontrollers such as Raspberry Pi Pico. These have most of the advantages of FPGA, including latency measured in microseconds, near instant boot, and "racing the beam," but at considerably lower cost.

comment 3y ago · link · parent

If you want to understand rinse aids better, I recommend this Technology Connections video (I've set the time stamp to the rinse aid section): https://www.youtube.com/watch?v=Ll6-eGDpimU&t=1935s

comment 3y ago · link · parent

And before that Gill[1].

[1]: https://levien.com/svg/

comment 3y ago · link · parent

They're related. Requiring sb ∪ rf to be acyclic is indeed one solution to the OOTA problem, but is arguably too heavy a hammer.

The other thing to say about OOTA is that it's usually referred to as a purely theoretical problem, but it is possible to imagine compiler optimization that would implicate it, for example using the storage location of the atomic to store a temporary value, knowing that it will be written later in program order anyway. That would be a perfectly reasonable thing to do in sequential code, but obviously a bad idea for atomics. Even so, experience shows that when it comes to letting compiler writers do optimizations that are obviously a bad idea, we have to explicitly and unambiguously forbid it in the spec.

comment 3y ago · link · parent

Thanks for this, quite useful.

There's also more discussion in [1], linked from there, which contains perspective from real memory model experts. I think it's fair to say they're skeptical of the proposal. In particular, they've debunked the SC-DRF claim, which seemed fishy to me, but I didn't want to say anything before gathering more evidence.

[1]: https://discourse.llvm.org/t/rfc-strengthen-relaxed-atomics-...

comment 3y ago · link · parent

I'm not sure how I feel about this. Are there nontrivial programs that depend on the (1, 1) outcome of the LB litmus test being forbidden? (See section 2.3 of the Lahav paper[1] for definitions and context)

If so, then these programs are at significant risk of miscompilation on compilers today. Strengthening the standard would mean that this risk continues until compilers are updated.

If not, then the proposal is asking for an (admittedly modest) performance regression to address what might not be a real problem.

Rust doesn't have a formal memory model yet, but the loom tool reports the (1, 1) outcome as not allowed[2]. I also ran it as normal threaded Rust code (not using a model checker) on M1 Max (which in theory is subject to the same miscompilation), and was not able to reproduce the failures as reported in the linked paper[3], but that doesn't mean much, as it's notoriously tricky to observe memory model violations.

In GPU-land, the (1, 1) outcome is allowed, as can be verified in the Vulkan memory model by the Alloy test in the second file of [2]. Neither HLSL nor Metal Shading Language have proper memory models, so it's hard to say, but in general it's fair to expect that anything allowed by the Vulkan memory model can be observed in other GPU implementations.

Perhaps what is called for is a finer gradation of strength, where the author explicitly asks for the guarantees needed, and the compiler inserts the BAL when it's needed, and skips it if not. Already I can see a lot of value in an explicit "unordered" value for ordering, which would be even weaker than relaxed (allowing more compiler optimization).

[1]: https://plv.mpi-sws.org/scfix/paper.pdf

[2]: https://gist.github.com/raphlinus/41d78d04d117ab0ba3b77065b9...

[3]: https://arxiv.org/pdf/2310.12337.pdf

comment 3y ago · link · parent

This is known as the Hadamard product and is covered in the video. The tl;dr is that, while it certainly has uses, it doesn't represent multiplication of vector spaces in any reasonable way (in particular, it gives different results when there's a change of basis, while other notions of "product", including dot product, are invariant).

There's a deeper explanation here: https://math.stackexchange.com/questions/185888/why-dont-we-...

comment 3y ago · link · parent

The numerical robustness thing gave me a chuckle (rotate 1 radian and pray to the geometry gods), especially as I've been spending a good fraction of my time dealing with that in fancy path rendering and stroking.

One of the things I really want to work on in the next few months is a path intersection implementation that's robust by construction, backed up both by a convincing (if not formal) argument and tests crafted to shake out robustness issues. I have a bunch of ideas, largely motivated by the need to generalize well to curves - Shewchuk's work, cited elsethread, is impressive but I'm not smart enough to figure out how to make it work for arbitrary Béziers.

There's an issue[277] to track the work, and that has pointers to some of the ideas. If anyone is interested in working with me on this, please get in touch. If successful, I think it'll result in a nice code base and also likely a publishable paper.

[277]: https://github.com/linebender/kurbo/issues/277

comment 3y ago · link · parent

I knew her son Peter[1] fairly well through the Berkeley Quaker meeting, though did not learn about her illustrious science contributions until after he died.

[1]: https://www.berkeleyside.org/2014/10/29/in-remembrance-peter...

comment 3y ago · link · parent

Yes, I've got my eye on those and am hopeful. Do you know of any meaty technical description of the programming model? All I've been able to find so far is fairly high level marketing material. At least for Tenstorrent Jim Keller has promised that the software stack will be open sourced, something I'm looking forward to.

comment 3y ago · link · parent

Subgroup operations[1]. In SIMT, they are fairly easily modeled[2] as communication between the different threads running on the same SIMD, and in most cases explicitly expose the predication mask. In fact, subgroupBallot(true) is a common idiom to extract that mask, and also to determine the subgroup size if run in subgroup uniform control flow. Generally they have good performance characteristics.

In SPMD, subgroups aren't easy to model, and would generally be emulated by inter-thread communication if it's important to match the semantics of a source program that includes them. Performance in that case would be terrible.

[1] In Vulkan, OpenGL, OpenCL, and WebGPU they are called "subgroups". In Nvidia including CUDA they are called "warps". In D3D and AMD they are called "waves". In Metal (often running on the same hardware) they are called "simdgroups". This fragmentation of terminology is part of the flavor of working with GPUs.

[2] "Fairly easily" by the standards of GPU infrastructure. In fact, the exact semantics have never been nailed down, and in particular "reconvergence" is poorly defined. Working through this is one of the things blocking subgroups in WebGPU (https://github.com/gpuweb/gpuweb/issues/4306). Even so, they're used commonly in practice, especially for things like fast matrix multiplication where you need to shuffle lots of data into place.

comment 3y ago · link · parent

In addition to ISPC, some of this is also done in software fallback implementations of GPU APIs. In the open source world we have SwiftShader and Lavapipe, and on Windows we have WARP[1].

It's sad to me that Larrabee didn't catch on, as that might have been a path to a good parallel computer, one that has efficient parallel throughput like a GPU, but also agility more like a CPU, so you don't need to batch things into huge dispatches and wait RPC-like latencies for them to complete. Apparently the main thing that sunk it was power consumption.

[1]: https://learn.microsoft.com/en-us/windows/win32/direct3darti...

comment 3y ago · link · parent

For earlier archaeology see [19]. It seems to me people had started coding extensions in VS Code without giving any real thought to the question, so the default choice inherited from the language was UTF-16.

[19]: https://github.com/microsoft/language-server-protocol/issues...

comment 3y ago · link · parent

I don't agree. A 256 bit profile of the new AVX stuff gives you lots of goodies over AVX2, including mask predication, the fancy ternary op, and so on.

Additionally, because it consumes half as many register bits as the 512 bit profile, it could be a lot more economical (and power efficient) to implement on cores that are not the high end server parts. Keep in mind ARM (even the top of their line) is still stuck on 128.

So I think the case for this is a good one.

comment 3y ago · link · parent

Search is 100% a valid justification to use contiguous storage. It wasn't high in my list of considerations when I was starting out.

comment 3y ago · link · parent

Interesting article, and I love to see performance numbers to back up engineering decisions. I'm also glad xi-rope wasn't included, as I'm sure it's performance lags :)

That said, it's not measuring what I would measure. The jumprope benchmarks are reported as the total time to complete a number of tasks. To me, the massive strength of the rope data structure is its O(log n) worst case performance when performing a simple operation such as inserting or deleting a character. That translates into user-perceivable latency. If you have a sequence of a thousand edits, and your rope accomplishes each in 200µs, while your gap buffer has a mean of 100µs but variance extending to 10ms, then I'd much prefer the former, even though this benchmark would indicate the latter is 2x faster.

comment 3y ago · link · parent

This is touched on in Olivier Giroux' talk on forward progress in C++[1]. I've time-stamped the section on the roach motel problem, which ends with the observation that the execution model should capture "as-if isolated for a finite time." But even if C++ were to be improved in this way, you'd still only get the guarantee if you expressed the write as an atomic. There are no guarantees for non-atomic writes and shouldn't be.

But this gets to the deeper problem of the blog. There are three ways you can reason about these kinds of problems:

1. What happens with the execution of assembly language on the chip? Behavior is pretty well specified by the ISA, and you absolutely can reason operationally. The x86 memory model includes TSO, so you get fairly strong guarantees; it's basically acquire/release "for free," so you know you won't get tearing or other such things.

2. The formal memory model provided by the language. In the case of C and C++, it's also pretty well specified, and there's lots of work that's gone into it over many years. Again, it's possible to reason productively in this world, though it's quite different than case 1 - ultimately you've got causality graphs and other things expressed on an abstract machine. Ideally you'd do this work with formal proofs, but model checkers like CDSChecker can help a lot.

3. Informal reasoning based on an intuitive model of what the computer "should" do. This is serious YOLO territory, and basically a guarantee that whatever you write will be broken, possibly leading to serious security vulnerabilities. It's popular among a subset of confidently wrong HN commenters though, who I expect will come out in force in this thread.

[1]: https://youtu.be/g9Rgu6YEuqY?si=ZvKlDnqKOqzfFVSZ&t=4267

comment 3y ago · link · parent

What tools were used to create the audio? For example, the exact patterns of dither-based noise shaping[1] may reveal insight, but are by definition inaudible. Or perhaps there's an ultrasound source - something recorded near old-school CRT monitors may have a 15.75kHz tone, ordinarily outside the threshold of hearing but shows up as a clear peak on a spectrogram.

[1]: https://www.sweetwater.com/insync/hear-effects-dithering/

comment 3y ago · link · parent

Agreed. And one more consideration is that (extended) grapheme cluster boundaries vary from one version of Unicode to another, and also allow for "tailoring." For example, should "อำ" be one grapheme cluster or two? It's two on Android but one by Unicode recommendation and is the behavior on mac. So in applications where a query such as length needs to have one definitive answer which cannot change by context, counting (extended) grapheme clusters is the wrong way to go.

comment 3y ago · link · parent

As a followup, here it is:

https://github.com/raphlinus/r6502

1
8910
63