by spacedcowboy 2 days ago

So I've been working for the past half-year or so on a language called xc - it's a heterogeneous compiler, so it takes source code and can target both the CPUs and GPUs (or in fact GPUs across a network or thunderbolt link).

Theres no need for any data-hazard checks in your code, the compiler will do it for you. If you want an analogy, where "ARC" freed programmers from having to manually manage memory, this is "ARC for algorithms", freeing you from having to care where the code runs.

It measures the computing environment at runtime not compile-time, and its opportunistic, so it will schedule work on the most-efficient worker at any given time - be that single-CPU, multiple-threads on the CPU, SIMD or similar hardware, GPU, multiple GPUs, or across a network via an installed daemon.

Here's some results for single-threaded CPU:

     xc cf              arm64 (M3 Max)   x86-64 (AMD Ryzen 9 9955HX)
     ------------       --------------   ---------------------------
     Objective-C        1.45× faster     1.24× faster
     C++ (clang)        1.12× faster     1.04× slower
     C++ (GCC)          1.12× faster     1.13× faster
     Swift              1.44× faster     1.43× faster

Or, on a Mac M3 Max, looking at GPU vs fastest CPU:

     benchmark   1 thread  N threads    GPU     all     auto    GPU vs N threads
     ----------  --------  ---------    ---     ---     ----    ----------------
     mandelbrot  164       13.5         1.3     1.2     1.0     10.1× faster
     md5         1349      108          4.9     5.5     4.8     22× faster 
     md5_mask    1064      85.2         4.1     4.3     4.1     21× faster 
     nbody       17.7      1.8          609 µs  1.3     1.3     3.0× faster 
     perlin      89.9      7.7          1.2     1.2     1.2     6.4× faster 
     saxpy       1.4       1.1          3.9     5.2     1.1     3.6× slower
 

The data-parallel sections are automatically detected, I've recently added a C front-end using clang to generate LLVM IR, which is then converted to our IR, which is then parallelised as usual.

The language itself is fairly modern (classes, protocols for interfaces, blocks for closures, callbacks, exceptions) and each platform is a cross-compiler for each other platform, so I have a binary on my iPhone which was created, compiled, and signed with my dev-certificate all on a linux box. Works great :)