Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significant change to RISC V and scalable vector code generation. #7616

Merged
merged 15 commits into from
Jun 8, 2023

Conversation

zvookin
Copy link
Member

@zvookin zvookin commented Jun 6, 2023

It is now possible to convert between fixed and scalable vectors in LLVM. Full generality is likely not working and various architecture specific intrinsics still require scalable vectors. This PR moves to using fixed vectors to represent types that are not quantized to a vscale size and converting to a longer vscale size as necessary.

RISC V vectorization should support lengths from 2 lanes up to 8 times the number of lanes supported for the given type and vector_bits specified in the target. (All the LMUL values.) 1 lane vectors likely do not work for intrinsics quite yet due to confusion re: scalars, but this PR should remove this case showing up via just doing scalar operations when scalars are involved. (Vector/scalar is supported, and some test cases were added. More coverage for .vi vs .vx forms is needed.)

PR will likely need some changed but want to get review started now.

Z Stern added 3 commits June 5, 2023 07:01
issues iwth single element vectors being confused with scalars and
other conversions that can happen via using call_intrin.

Allows using any size vector. Only downside is splitting large vectors
no longer happens, but RISC-V allows an LMUL of 8, meaning a vector of
up to 8 times the vector register size will compile so this is much
less of an issue. Splitting larger vectors can be added.

Should also allow fractionaly LMUL in all cases, but this is not
verified.
support. Should handle many more cases and be well on the way to
handling arbitary vector widths within the LMUL range.

More tests added to simd_op_check_riscv .

Likely well setup to move SVE2 to a similar approach, perhaps without
the full genearilty on vector lengths. (I.e. they may need to be
quantized to vscale, or offer better performance in that case.)
@zvookin zvookin requested a review from steven-johnson June 6, 2023 19:24
Copy link
Contributor

@steven-johnson steven-johnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. Let me know when I should pull it into google3 for testing.

src/CodeGen_LLVM.h Outdated Show resolved Hide resolved
src/CodeGen_LLVM.cpp Show resolved Hide resolved
src/CodeGen_RISCV.cpp Show resolved Hide resolved
src/CodeGen_RISCV.cpp Show resolved Hide resolved
src/CodeGen_RISCV.cpp Outdated Show resolved Hide resolved
src/CodeGen_RISCV.cpp Outdated Show resolved Hide resolved
src/CodeGen_RISCV.cpp Outdated Show resolved Hide resolved
src/CodeGen_RISCV.cpp Outdated Show resolved Hide resolved
@steven-johnson
Copy link
Contributor

Looks like some legitimate failures, e.g. https://buildbot.halide-lang.org/master/#/builders/84/builds/40

@steven-johnson steven-johnson self-requested a review June 7, 2023 22:42
Copy link
Contributor

@steven-johnson steven-johnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending green

@steven-johnson steven-johnson merged commit bd62a35 into main Jun 8, 2023
@steven-johnson steven-johnson deleted the riscv_intrinsics_single_lane_fix branch June 8, 2023 01:27
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
…lide#7616)

* Completely rework how RISC-V vector intrinsics are called to avoid
issues iwth single element vectors being confused with scalars and
other conversions that can happen via using call_intrin.

Allows using any size vector. Only downside is splitting large vectors
no longer happens, but RISC-V allows an LMUL of 8, meaning a vector of
up to 8 times the vector register size will compile so this is much
less of an issue. Splitting larger vectors can be added.

Should also allow fractionaly LMUL in all cases, but this is not
verified.

* Significant refactor/rewrite of RISC V vector intrinsics
support. Should handle many more cases and be well on the way to
handling arbitary vector widths within the LMUL range.

More tests added to simd_op_check_riscv .

Likely well setup to move SVE2 to a similar approach, perhaps without
the full genearilty on vector lengths. (I.e. they may need to be
quantized to vscale, or offer better performance in that case.)

* Formatting fixes.

* More formatting.

* Don't try to convert void types to match expected vector type.

* Backout comment change that is no longer relevant.

* Fix failure in camera_pipe app. (Code to make sure vector types match
was being presented with a scalar only mismatch. Changed it to ignore
scalar to scalar cases.)

Address review feedback.

* One more review comment.

* Comment fix.

---------

Co-authored-by: Steven Johnson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants