Learning a language as it is is boring and one cannot appreciate it's offerings unless they're applied. I would like to present ziglang and it's powerful features like comptime, build.zig and many more that I applied in building a GPU library.
It's the specific code regions in the source code that should be resolved during comptime. For example, below Fibonacci number at 50th position get's resolved to 12586269025 during compilation and the value is available during runtime.
const std = @import("std");
fn fibo(position: usize) usize {
var a: usize = 0;
var b: usize = 1;
for (0..position) |_| {
b = a + b;
a = b - a;
}
return a;
}
pub fn main() void {
const comptime_fib = comptime fibo(50); // calculates during compilation
std.debug.print("comptime_val:{d}", .{comptime_fib});
}
Assembly output is just 5 lines: https://godbolt.org/z/8553K9Ps7
get_fibo:
push rbp
mov rbp, rsp
movabs rax, 12586269025
pop rbp
ret
I have used this powerful feature in creating Error types for my gpu library during compile time by parsing flat strings.
Here's where https://github.com/akhildevelops/cudaz/blob/cb8b1d11fa87b399ebf59a00b3031d34b64eb4c1/src/error.zig#L10-L12 error types are generated through comptime.
The library should be portable i.e, should work on windows / linux. The major problem is to search and link gpu dynamic library provided by the vendor. In this regard we need a stronger build system like cmake and build.zig is the answer for zig ecosystem. build.zig helps in book keeping activities, pre-comptime checks, generate tree like process flows to generate executables, libraries. Interestingly compilation flow can be written in zig code. The build file for gpu library can be found at https://github.com/akhildevelops/cudaz/blob/main/build.zig
It's easy to integrate C libraries into zig code using compiler builtin functions. They have been extensively used to import C headerfiles https://github.com/akhildevelops/cudaz/blob/main/src/c.zig
There are many other features with simpler syntax that will be shared in the talk in the context of gpu library.
I'll also show an end to end example in running a GPU application through ziglang and the library.
Ziglang ergonomics
GPU basics
compile time codegen
Great proposal. I think the author has a good story to share with the world .
I would appreciate if the author could put in a lot of diagrams to make the audience comfortable with binding shared libraries.
The code for device execution also needs to be explained before diving deep into writing kernel code.
The author needs to ensure the key takeaways that they will focus on.
The focus of this talk is not GPU programming as the title implies. The proposer seems to have done interesting work with their project cudaz that adds CUDA support for Zig. Unfortunately, the proposal and the title don't jam well together.
The talk is better understood as "how to build a native code/CUDA wrapper for Zig", which seems to be the real focus of the talk; comptypes and such have nothing to do with GPU programming per-se, but are useful language tools that have been used to build the wrapper.
There is potential in this talk in terms of promise of technical depth. Wrappers for GPU libraries can need careful handling and techniques. Knowledge of these is not commonplace, but can well be applied in other contexts.
If we go ahead with the talk, the title would certainly have to change.