Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Vector types #34

Closed
Closed

Description

@khyperia

spir-v has vector types that are dramatically useful on e.g. nvidia hardware for optimizing loads/stores. At first, let's just directly expose vector types, instead of trying to do things like auto-vectorization.

  1. Rustc already has the notion of vector types, and we directly translate them to spir-v vector types. We need to investigate under what conditions rustc emits vector types, and if we can re-use the same framework.
    Abi::Vector { ref element, count } => {
    let elem_spirv = trans_scalar(cx, ty, element, None, is_immediate);
    SpirvType::Vector {
    element: elem_spirv,
    count: count as u32,
    }
    .def(cx)
    }
  2. If we cannot re-use the same framework, create an attribute to specify a type is a builtin vector, recognize the attribute in abi.rs (example for storage classes), and emit a vector type. Perhaps do a mix of the two, e.g. if rust supports f32x2 and f32x4, but not f32x3, then we need to define our own f32x3.
  3. Investigate the spec: is emitting a spir-v "OpTypeVector" enough, or are there additional decorations/etc. we need to apply to get it to be a proper "vector type"?
    SpirvType::Vector { element, count } => cx.emit_global().type_vector(element, count),
  4. Implement the above in spirv-std, adding things like swizzling ops and other shenanigans (can come later).

This seems like a good not-quite-first-but-kinda-first task for someone other than me to do. Step 2 is a little involved and will likely need some mentorship - abi.rs is hecking wild - but getting more people who know how abi.rs works would be really really good.

Activity

  1. added
    t: designDesign of our rust-gpu language and std
    on Sep 22, 2020
  2. khyperia commented on Sep 26, 2020

    @khyperia
    ContributorAuthor

    Possibly relevant: https://github.com/hsivonen/simd/blob/045d4dae4e65f99fd43cd9042f5132812cae717e/src/lib.rs#L75-L79

    #![feature(repr_simd)]
    #[allow(non_camel_case_types)]
    #[derive(Debug, Clone, Copy)]
    #[repr(simd)]
    pub struct f32x4(f32, f32, f32, f32);
  3. khyperia commented on Oct 20, 2020

    @khyperia
    ContributorAuthor

    It looks like item 2 is not necessary - seems like #[repr(simd)] is all that needed. So yeah, definitely good first issue! Mostly just step 4 is necessary, although a more senior person digging deeper into points 1 and 3 would be nice - I don't think there's any surprises there, though (but it's good to be sure).

    f32x4 is already implemented in spirv-std by copying the above type, but it's just that, and needs all the impls and operators and whatnot (as well as all the other types). Defining all that repitition using macros seems neat.

  4. added
    a: simdIssues involving Single Instruction Multiple Data instructions.
    on Oct 22, 2020
  5. nipunG314 commented on Oct 24, 2020

    @nipunG314
    Contributor

    Hi, I would be interested with working on this.

    From what I understand in this thread, the first thing to do would be to write the operators and impls for f32x4 using macros?

  6. khyperia commented on Oct 24, 2020

    @khyperia
    ContributorAuthor

    Awesome!

    This issue is a bit out of date, though: #71 added quite a few vector items. However, it wasn't very cleanly or thoroughly implemented, and needs significant work. Some tasks remaining are:

    1. vec4 and f32x4 are duplicated right now. One of them needs to be removed. Discussing which naming scheme to go with in discord would be nice, if you're able to join there!
    2. A lot of cruft from glam was copied over, this needs to be fixed (e.g. reciprocal), and many weird comments.
    3. There's a lot of duplication: it'd be nice if we could deduplicate with macros or somesuch.
    4. The clippy use_self lint is disabled on spirv-std, primarily due to violations in the vector code, it'd be good to fix those.
    5. Tests are disabled on spirv-std right now, either remove the tests or enable them.
  7. nipunG314 commented on Oct 24, 2020

    @nipunG314
    Contributor

    Sure. I'll ping you on #rust-gpu on Discord.

  8. khyperia commented on Nov 12, 2020

    @khyperia
    ContributorAuthor

    With glam and whatnot in, this is pretty much resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: simdIssues involving Single Instruction Multiple Data instructions.t: designDesign of our rust-gpu language and stdt: good first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions