logoalt Hacker News

Zig – SPIR-V Backend Progress

87 pointsby Retro_Devlast Thursday at 10:03 PM45 commentsview on HN

Comments

mccoybtoday at 9:18 AM

This is inspiring! At the same time, it’s not exactly clear to me how this is going to work in the long term without changes to the Zig language itself, questions below.

Assuming the goal is to be able to write compute kernels and shaders in Zig - the concerns of writing (and especially optimizing) these programs are significantly different from high-performance CPU execution.

Mojo, for instance, has seemed to solve this problem (presumably: I haven’t studied the compiler myself, but this is a claim of theirs) but the community has implied that solving this problem required semantic and compiler design decisions different from the Zig compiler, especially around memory spaces, pointers, and origins.

Further: if you open up a modern tensor / GPU compiler (Triton, XLA, logical / scheduled kernel systems like Halide or Exo, or low-level kernel compilers like Mojo) — the optimizations and analyses which are performed on GPU kernel code are significantly different than CPU code

Is the end goal to write such a pipeline into the Zig compiler?

It seems possible to do this - but I’m not sure … it seems a bit hacky, or like one has to coerce existing Zig semantics to be repurposed for a job it was not designed for in the first place?

One alternative might be to use comptime to expose a kernel builder DSL, followed by a GPU compiler pipeline implemented in Zig (a completely separate compiler). This seems straightforward and allows you to implement and gain access to the specialized semantics / optimizations that you’d need for high-performance kernels?

I could absolutely be wrong, interested in thoughts.

show 1 reply
Gerharddclast Friday at 6:39 AM

Really cool to see work progressing on this! It would be awesome to one day be able to use Zig for serious shader work

weitzjtoday at 5:10 AM

Side question as I am following zig only losely and do Go Programming:

Zig has the feature that you can drop in your allocator from the caller. Now with 0.16 you also "bring your own IO" implementation with you.

And for my understanding this looks like the pattern Go uses with its Context package, where you pass in transitive data, cancellation signals and timers to for example stop an SQL query in server B, since a user canceled a web request in their browser before hitting server A, whilst all elements delegate the Context.

Then yesterday was total unrelated article about NUMA architecture, and I remember somewhere that the creator of Erlang mentioned (Joe Armstrong) that you cannot get around physics and it takes time to call a function between servers, therefore so not try to hide the latency between the calls.

And now to my question:

Would that in any way make sense for zig to go even more in this direction, where you pass in your allocator, IO, but now with something similar to Google Go context, but have it even more fine grained?

So that your functions could actually in their interface expose somehow the time in between CPU cores (NUMA) up to the request cancellation as Google go context is used for timeout signals, cancellation signals.

Also probably making time an external dependency as well.

So in essence , every function would be treated as a remote procedure calls, whereas remote would mean: "other cpu", other server/service

show 1 reply
LegNeatotoday at 6:05 AM

See also the rust spir-v backend: https://github.com/Rust-GPU/rust-gpu/

laszlojamflast Friday at 7:06 AM

I really love everything about zig except the language itself. The governance, the culture, all of it seem really cool, but reading https://ziglang.org/learn/why_zig_rust_d_cpp/ I still don't get _why_ I would use it. To an untrained eye, it seems like go, but with manual allocation. Or an imperative-only rust. Like it has some features of all the languages it competes with, but not the ones that would make me reach for them. What do people use zig for, and why zig and not one of the others?

show 7 replies
z0ltantoday at 12:36 PM

[dead]

joshsyntoday at 5:21 AM

[dead]

sylwaretoday at 11:41 AM

LLVM? Ok it is over. Bye.

show 2 replies