Skip to content

Add SME vector length detect #287

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ jobs:
env:
ANDROID_NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
cmake-linux-qemu:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
timeout-minutes: 40
strategy:
matrix:
build_props:
- [
"cmake-linux-riscv64",
"riscv64/ubuntu:22.04"
"riscv64/ubuntu:24.04"
]

name: ${{ matrix.build_props[0] }}
Expand Down
10 changes: 10 additions & 0 deletions include/cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@ struct cpuinfo_arm_isa {
bool sme_b16b16;
bool sme_f16f16;
uint32_t svelen;
uint32_t smelen;
#endif
bool rdm;
bool fp16arith;
Expand Down Expand Up @@ -2081,6 +2082,15 @@ static inline uint32_t cpuinfo_get_max_arm_sve_length(void) {
#endif
}

// Function to get the max SME vector length on ARM CPU's which support SME.
static inline uint32_t cpuinfo_get_max_arm_sme_length(void) {
#if CPUINFO_ARCH_ARM64
return cpuinfo_isa.smelen * 8; // bytes * 8 = bit length(vector length)
#else
return 0;
#endif
}

static inline bool cpuinfo_has_arm_sme(void) {
#if CPUINFO_ARCH_ARM64
return cpuinfo_isa.sme;
Expand Down
18 changes: 18 additions & 0 deletions src/arm/linux/aarch64-isa.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,22 @@ void cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(
// Mask out the SVE vector length bits
isa->svelen = ret & PR_SVE_VL_LEN_MASK;
}

#ifndef PR_SME_GET_VL
#define PR_SME_GET_VL 64
#endif

#ifndef PR_SME_VL_LEN_MASK
#define PR_SME_VL_LEN_MASK 0xffff
#endif

ret = prctl(PR_SME_GET_VL);
if (ret < 0) {
cpuinfo_log_warning("No SME support on this machine");
isa->smelen = 0; // Assume no SME support if the call fails
} else {
// Mask out the SME vector length bits
isa->smelen = ret & PR_SME_VL_LEN_MASK;
}
}

1 change: 1 addition & 0 deletions tools/isa-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ int main(int argc, char** argv) {

printf("ARM SVE Capabilities:\n");
printf("\tSVE max length: %d\n", cpuinfo_get_max_arm_sve_length());
printf("\tSME max length: %d\n", cpuinfo_get_max_arm_sme_length());

printf("Cryptography extensions:\n");
printf("\tAES: %s\n", cpuinfo_has_arm_aes() ? "yes" : "no");
Expand Down
Loading