Rust SIMD on the GPU

(vectorware.com)

44 points | by sagacity 2 hours ago

7 comments

  • 6r17 29 minutes ago
    My heard hurts - i was stupid enough to think that SIMD was a CPU only thing - I don't understand why it would be ported to GPU - huge kudos to managing to surprise me
    • chlorion 7 minutes ago
      GPUs work on vectors and matrices very often, that's what they are good at, so it makes a lot of sense that they can operate with SIMD I think!
    • hingler36 21 minutes ago
      Welcome to the lucky 10,000! SIMD is actually a pretty integral part of how GPUs are able to work efficiently, it's part of why there's such a strong focus on branchless programming in the field.
  • LegNeato 49 minutes ago
    Author here, AMA.
    • Eridrus 0 minutes ago
      Given the massive demand for GPUs for LLMs, what sorts of work do you expect to economically benefit from utilizing GPUs more?
    • lbhdc 22 minutes ago
      What is vectorware's business model? Are you planning to sell support/consulting to companies using your stack? Or are you looking to sell licenses to your tool? Or something else?
      • LegNeato 1 minute ago
        The tentative plan is to open source all the compiler and `std` bits with our products built on top (compilers are not good businesses). More about our products coming in the next couple of months!
    • jcranmer 42 minutes ago
      The post is kind of vague on the IR you're targeting. Can you give some examples of what the SIMD-ized IR looks like, and how it maps to the target PTX?
      • the__alchemist 38 minutes ago
        I'm confused too. How does this fit between these approaches for paraellization:

          - CUDA kernels and Tiles (e.g. Cudarc, cuda-oxide, rust-gpu etc) - SIMD on the GPU. (E.g. as in the title...)
          - CPU SIMD using avx or SSE instructions (And probably thin wrappers for vectors so you can have sane syntax). Or the maybe-upcoming core simd which should abstract over architecture-specific instructions. Magic floats etc which do 4-16 computations at once, but are a bit clumsy to work with
          - Rayon thread pools - arbitrary parallel computations, including SIMD, one per CPU core.
        
        It looks like from the code samples like maybe a cleaner syntax for writing code on the GPU than CUDA kernels? E.g. without mucking with serialization, host and device by abstracting over it? And inspired by core::simd. (Good choice if so, in the interest of standardizing on syntax; I did this for my x86 SIMD vector/quaternion lib as well)
      • LegNeato 3 minutes ago
        Didn't want to go into crazy detail in the post.

        Each family of operations is a trait parameterized by the operation itself:

        ` pub trait EvaluateReduction<Operation, T>: LaneEvaluator { /// Reduce one distributed definition to an ordinary uniform scalar. fn evaluate_reduction(&self, value: LaneValue<Self, role::Distributed, T>) -> T; } `

        Call sites name the operation:

        ``` let one = evaluator.splat::<Splat, _>(1_u32); let two = evaluator.splat::<Splat, _>(2_u32); let three = evaluator.binary::<Add, _>(one, two);

          let total   = evaluator.reduce::<Sum, u32>(three);   // a uniform u32
          let running = <Executor as EvaluateScan<Scan<Sum, Exclusive>, u32>>::scan(&evaluator, three);
        ```

        Operations like Sum, Max, ReduceXor, Inclusive, and Exclusive are all distinct types.

        As mentioned in the post, execution shape is typed too. A static shuffle takes its control as a type-level constant, and the shuffle mode constrains which controls are expressible:

        ``` // Shift down one lane, keeping our own value where the source is inactive. let down = <Executor as EvaluateShuffle<Shuffle<Down>, DownOrSelf<1>, u32>>::shuffle(&ev, v); // Broadcast from lane zero. let bcast = <Executor as EvaluateShuffle<Shuffle<Broadcast>, WarpLane<0>, u32>>::shuffle(&ev, down); // Butterfly exchange with the neighbor one bit away. let bfly = <Executor as EvaluateShuffle<Shuffle<Xor>, Butterfly<1>, u32>>::shuffle(&ev, bcast); ```

        For an example of errors caught, a warp-scoped executor for a device-scoped barrier is a compile error:

        ``` <ScopedWarpExecutor<'_, WarpUniform> as EvaluateBarrier<Barrier<Device>>>::barrier(evaluator) // error[E0277]: the trait bound `Device: NvptxBarrierScope` is not satisfied // help: the trait `NvptxBarrierScope` is implemented for `Warp` ```

        Strip mining is typed on the amount of work and the lane capacity, and it hands back one chunk at a time along with the predicate saying which lanes live in that chunk:

        ``` // Six work items across four active lanes: two chunks, based at 0 and 4. <Executor as EvaluateStripMine<StripMine, (WorkItems, ActiveLanes<StripMined<4>>), i32>>:: for_each_strip_mined( &evaluator, (WorkItems::new(6)?, ActiveLanes::new(4)?), |index, active| { // ... }, ); ```

        Hopefully that gives the flavor of it.

    • lbhdc 26 minutes ago
      This is really cool! It sounds like y'all have a compiler fork that you are using to make this work. I wanna tinker with this, is your compiler available?
    • guess__who 47 minutes ago
      [flagged]
  • efnx 1 hour ago
    Congrats to the Rust-GPU folks! Nice to see the good work flowing.
  • rust-lang 19 minutes ago
    Good job!
  • the__alchemist 28 minutes ago
    Hey - this is probably off-topic/meta, but what is going on with the comments here? Is it bots?
    • dev_l1x_be 22 minutes ago
      No idea, but it seems HN needs POW challenges.
  • lx-user 23 minutes ago
    [flagged]
  • guess__who 47 minutes ago
    [flagged]
    • LegNeato 43 minutes ago
      We never mention anything about superiority nor compare with other languages or programming models. This post is about making existing Rust CPU code work on the GPU.
      • guess__who 40 minutes ago
        I can read between the lines and the sentiment is just to 'show them the right way'.

        HN people are too nice to acknowledge this. But deep down you know this is true.

    • extrem-RAM-shor 27 minutes ago
      Rust is the best. No other language is fun enough to program.
    • kooi 33 minutes ago
      Useless blabbering.

      If you have real feedback, great, but it's useless to rip on the hard work of others without it.

      • fire_wheel 30 minutes ago
        I am rewriting some components in rust - I dont like such sentiment. It negatively impacts the community.

        Rust is better in so many ways.

    • throwaway894345 30 minutes ago
      I'm not a Rust user apart from an occasional toy program here and there, but you seem really triggered about a language that other people use. What's the issue?
    • the__alchemist 35 minutes ago
      I care because it means I can use this in a Rust program without a FFI barrier. Regrettably, we have built computing infrastructure as a society with many barriers; programming language is one.