You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
supporting Arm Neoverse V2 CPUs: NVIDIA Grace, AWS Graviton 4, Google Axion #845
While looking into implementing support in archdetect for detecting the Neoverse V2-based Graviton 4, I noticed that the CPUs that implement this microarchitecture only partially overlap (based on https://gpages.juszkiewicz.com.pl/arm-socs-table/arm-socs.html):
instructions
Amazon Graviton 4
NVIDIA Grace
Google Axion
sve2
x
x
x
paca
x
x
pacg
x
x
rng
x
x
sm3
x
x
sm4
x
x
svesm4
x
x
ssbs
x
x
Google Axion not supported ssbs is particularly interesting, since that means that our aarch64/neoverse_v1 installations may not even work there...
Instructions set extensions cover a range of assembly instructions relevant to different categories (security, performance, AI/ML, Cryptography,...). We could consider keeping a catalogue of what assembly instructions are required for each software package.
We'd still need a map from the assembly instructions back to the CPU features to know whether or not a particular CPU can run the code for a particular architecture branch of EESSI. I couldn't easily find this information, so I asked ChatGPT for a helpful table for the NVIDIA Grace (which uses the Armv9-A ISA) and got something that is at the very least a good starting point:
Category
Feature Name
Description
Relevant Assembly Instructions
Security
armv9.0-a, rme
Confidential Compute Architecture (CCA): Introduces Realms for hardware-based workload isolation.
RMI (Realm Management Instructions), SEAL, UNSEAL
mte
Memory Tagging Extension (MTE): Tags memory allocations to detect overflows and use-after-free errors.
STG, LDG, STZG, LDGZ, IRG
pauth
Pointer Authentication (PAC): Improves control-flow integrity with efficient pointer signing.
Backward Compatibility: Full support for previous Armv8-A features, including FP16 and dot products.
Instructions like UDOT, SDOT, FMADD
tlbi
TLB Enhancements: Improves Translation Lookaside Buffer management for virtualized systems.
TLBIALL, TLBIVMALL, TLBIIPAS2E1IS
nv
Nested Virtualization: Enables running virtual machines within virtual machines.
HVC, ERET, SYSREG
Debugging
sysreg
System Register Enhancements: Adds support for performance monitoring and secure system debugging.
System register access instructions like MRS, MSR.
dbg
Improved Debug Architecture: Enhances system-level debugging, especially in isolated environments.
Debug instructions like BRK, DBG, and exception-generating instructions.
We only really care about a certain set of categories, so small differences in ARM instruction set extensions may not be relevant to the software stacks we ship.
I wonder if we can compile a small executable with the full list of instructions for the stack and then just run that on the CPU? If it doesn't throw an "Illegal instruction" then it is supported? Is that enough? Could things like cache sizes etc. have an impact?
EDIT: Tested the AI generated code above, doesn't seem to work out-of-the-box, but could it work in principle?
2nd EDIT: Code above now seems to work
importjson# Template for the generated C file (Fixed escaping `{}` using double `{{}}`)C_TEMPLATE="""\#include <stdio.h>#include <setjmp.h>#include <signal.h>// Global variable for signal handlingsigjmp_buf buf;// Signal handler for illegal instructionsvoid sigill_handler(int sig) {{ siglongjmp(buf, 1); // Jump back to safety}}// Function to test an instructionvoid test_instruction(const char *name, void (*instr_func)()) {{ printf("[*] Testing: %s... ", name); if (sigsetjmp(buf, 1) == 0) {{ instr_func(); // Run the instruction printf("Success\\n"); }} else {{ printf("Failed (Illegal Instruction)\\n"); }}}}// Instruction test functions{function_definitions}int main() {{ // Set up signal handler for SIGILL signal(SIGILL, sigill_handler); printf("\\n=== CPU Instruction Test ===\\n"); // Run all tests{function_calls} printf("\\n=== Test Complete ===\\n"); return 0;}}"""defgenerate_c_code(instructions):
"""Generates C code based on the provided instructions."""function_definitions= []
function_calls= []
forinstrininstructions:
func_name=f"test_{instr['name'].replace(' ', '_').lower()}"function_definitions.append(f"void {func_name}() {{ __asm__ volatile (\"{instr['assembly']}\\n\"); }}")
function_calls.append(f" test_instruction(\"{instr['name']}\", {func_name});")
returnC_TEMPLATE.format(
function_definitions="\n".join(function_definitions),
function_calls="\n".join(function_calls)
)
defmain():
# Load JSON filewithopen("instructions.json", "r") asf:
instructions=json.load(f)
# Generate C codec_code=generate_c_code(instructions)
# Write to filewithopen("test_instructions.c", "w") asf:
f.write(c_code)
print("[+] Generated 'test_instructions.c' successfully!")
if__name__=="__main__":
main()
I could see having individual instructions.json for each package, and adding all those to generate a global one for a software stack just by adding them up.
Based on this, rng can be used to discriminate Axion vs Grace (if it's there, it's not Grace), paca/pacg/ssbs are not reliable (sometimes CPU features are not exposed for security reasons). That's helpful for #1042
Activity
ocaisa commentedon Jan 10, 2025
I was wondering if we inspect what instructions our binaries actually require?
ocaisa commentedon Jan 10, 2025
Seems to be possible: https://github.com/pkgw/elfx86exts (says it works for x86 and ARM)
ocaisa commentedon Jan 10, 2025
We could inspect the instructions required by the software, and have CI complain if it goes outside the common options.
boegel commentedon Jan 10, 2025
Step 0:
ocaisa commentedon Jan 13, 2025
Sample output from
elfx86exts:ocaisa commentedon Jan 13, 2025
Instructions set extensions cover a range of assembly instructions relevant to different categories (security, performance, AI/ML, Cryptography,...). We could consider keeping a catalogue of what assembly instructions are required for each software package.
We'd still need a map from the assembly instructions back to the CPU features to know whether or not a particular CPU can run the code for a particular architecture branch of EESSI. I couldn't easily find this information, so I asked ChatGPT for a helpful table for the NVIDIA Grace (which uses the Armv9-A ISA) and got something that is at the very least a good starting point:
We only really care about a certain set of categories, so small differences in ARM instruction set extensions may not be relevant to the software stacks we ship.
ocaisa commentedon Jan 13, 2025
So a hardware check would be more like asking the question: this software stack requires
<LIST>assembly instructions, does your CPU support them?ocaisa commentedon Jan 31, 2025
It seems you can check this with a compiler:
I wonder if we can compile a small executable with the full list of instructions for the stack and then just run that on the CPU? If it doesn't throw an "Illegal instruction" then it is supported? Is that enough? Could things like cache sizes etc. have an impact?
EDIT: Tested the AI generated code above, doesn't seem to work out-of-the-box, but could it work in principle?
2nd EDIT: Code above now seems to work
ocaisa commentedon Jan 31, 2025
Indeed, in principle that approach could work:
ocaisa commentedon Jan 31, 2025
A couple more AI-generated proof-of-concepts
Based on
[ { "name": "AVX vaddps", "assembly": "vaddps %xmm0, %xmm1, %xmm2" }, { "name": "AMX tilezero", "assembly": ".byte 0xc4, 0xe2, 0x78, 0x49, 0xc0" }, { "name": "SSE movaps", "assembly": "movaps %xmm0, %xmm1" } ]you could have a python code generator like
and then
I could see having individual
instructions.jsonfor each package, and adding all those to generate a global one for a software stack just by adding them up.ocaisa commentedon Jan 31, 2025
To me, this looks promising:
boegel commentedon Apr 24, 2025
/proc/cpuinfofor Google Axion (via @trz42):ocaisa commentedon Apr 24, 2025
The table at https://gpages.juszkiewicz.com.pl/arm-socs-table/arm-socs.html is (unfortunately) wrong then
boegel commentedon Apr 24, 2025
Based on this,
rngcan be used to discriminate Axion vs Grace (if it's there, it's not Grace),paca/pacg/ssbsare not reliable (sometimes CPU features are not exposed for security reasons). That's helpful for #1042boegel commentedon Aug 5, 2025
Some interesting docs in this context that I just bumped into: https://nvidia.github.io/grace-cpu-benchmarking-guide/developer/cpudetect.html
ocaisa commentedon Aug 5, 2025
I knew this must be possible, https://nvidia.github.io/grace-cpu-benchmarking-guide/developer/cpudetect.html#cpu-hardware-capabilities ! So basically, if we can collect the instructions used by a stack, we can code up a binary that checks if they are supported. Then dropping to a supported CPU would just mean running a sequence of (tiny) executables.