Skip to content

Misc. bug: Incorrect usage of __riscv_v_intrinsic macro - should use __riscv_v for RVV separation #22159

@arniechangsifive

Description

@arniechangsifive

Name and Version

version: 8683 (d0a6dfe)
built with Clang 20.9.0 for Linux riscv64

Operating systems

Linux

Which llama.cpp modules do you know to be affected?

llama-cli

Command line

Problem description & steps to reproduce

Summary
The llama.cpp codebase incorrectly uses __riscv_v_intrinsic for conditional compilation to separate RISC-V Vector (RVV) implementation from scalar code. According to the official RISC-V "V" Vector Extension Intrinsic specification, __riscv_v should be used instead.

The Issue
According to the RISC-V "V" Vector Extension Intrinsic Document, section on predefined macros:
__riscv_v_intrinsic: Version number macro for the intrinsic API
This macro should be defined even if the vector extension is not enabled.
__riscv_v: RVV extension detection macro
Only defined when the vector extension is actually enabled. This is the correct macro for RVV/scalar code separation

Current State in llama.cpp
The codebase has inconsistent usage:

  1. Correct usage (older code):
    #if defined(__riscv_v)
  2. Incorrect usage (newer code)
    #if defined __riscv_v_intrinsic

Impact
Using __riscv_v_intrinsic instead of __riscv_v for RVV separation can lead to runtime crashes, vector instructions executed on hardware without vector support.

First Bad Commit

No response

Relevant log output

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions