This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Size of vectors in SVE2

Hello,

I want to use the SVE2 instruction set. To this end, I have created a VM in a known cloud provider based on armv9 architecture which supports SVE2 instruction set.

I want to ask the following:

1) How can I determine the size of the vectors? The only way that I am aware of is by executing the following asm code:

rdvl            x9, #1
cmp             x9, #16
bgt             .label1

And branch based on the VL number. Is there any other command in the operating system level?

2) How can I change the size of the vectors? Currently, I can see that the size in my VM is 128 bits (using the aforementioned asm code). Is there a way to increase this value (provided that the underlying processor supports it)? For example, a command in the operating system level?

3) I want to have vectors whose size is bigger than 128 bits. Is a processor that supports this enough or do I need anything else (for example a specific version of a specific operating system, specific gcc, and so on)?

4) Do you know a cloud provider which supports armv9 VMs with vector size bigger than 128 bits?

Thank you in advance,

Akis

Parents
  • Hi Akis,

    Inspecting the SVE vector length directly with assembly as in your code snippet
    is likely to be the fastest way, but you can also determine this from the
    operating system by using a prctl:

    #include <sys/prctl.h>
    #include <stdio.h>
    
    int main() {
      int vl_in_bytes = prctl(PR_SVE_GET_VL) & PR_SVE_VL_LEN_MASK;
      printf("%d bits\n", vl_in_bytes * 8);
    
      int new_vl_in_bytes = 16; // set to 128 bits
      prctl(PR_SVE_SET_VL, new_vl_in_bytes); // should check success/failure
    
      vl_in_bytes = prctl(PR_SVE_GET_VL) & PR_SVE_VL_LEN_MASK;
      printf("%d bits\n", vl_in_bytes * 8);
    }

    The above program will query the vector length, then set it to 128-bits and
    fetch the vector length again. On a system with a default vector-length of
    256-bits for instance you should see:

    $ gcc test.c
    $ ./a.out
    256 bits
    128 bits

    I would suggest reading the Linux documentation around PR_SVE_GET_VL and
    PR_SVE_SET_VL for additional options (in particular PR_SVE_SET_VL_ONEXEC and
    PR_SVE_VL_INHERIT).

    If your processor supports a vector length larger than 128-bits then that alone
    should be enough, for instance the Amazon Graviton 3 instances have a default
    vector length of 256-bits. If your processor does not support a larger vector
    length (and I would imagine that it does not support it, given the VM
    defaulting to 128-bits?) then the above prctl to set the vector length will
    correctly fail to set the vector length.

    I am not aware of any cloud providers with Arm v9 offerings with an SVE2 vector
    length of 128-bits, unfortunately. The Amazon Graviton 3 supports a vector
    length of 256-bits however this is only SVE1 and not SVE2, but this might be
    sufficient for your use case?

    Thanks,
    George

Reply
  • Hi Akis,

    Inspecting the SVE vector length directly with assembly as in your code snippet
    is likely to be the fastest way, but you can also determine this from the
    operating system by using a prctl:

    #include <sys/prctl.h>
    #include <stdio.h>
    
    int main() {
      int vl_in_bytes = prctl(PR_SVE_GET_VL) & PR_SVE_VL_LEN_MASK;
      printf("%d bits\n", vl_in_bytes * 8);
    
      int new_vl_in_bytes = 16; // set to 128 bits
      prctl(PR_SVE_SET_VL, new_vl_in_bytes); // should check success/failure
    
      vl_in_bytes = prctl(PR_SVE_GET_VL) & PR_SVE_VL_LEN_MASK;
      printf("%d bits\n", vl_in_bytes * 8);
    }

    The above program will query the vector length, then set it to 128-bits and
    fetch the vector length again. On a system with a default vector-length of
    256-bits for instance you should see:

    $ gcc test.c
    $ ./a.out
    256 bits
    128 bits

    I would suggest reading the Linux documentation around PR_SVE_GET_VL and
    PR_SVE_SET_VL for additional options (in particular PR_SVE_SET_VL_ONEXEC and
    PR_SVE_VL_INHERIT).

    If your processor supports a vector length larger than 128-bits then that alone
    should be enough, for instance the Amazon Graviton 3 instances have a default
    vector length of 256-bits. If your processor does not support a larger vector
    length (and I would imagine that it does not support it, given the VM
    defaulting to 128-bits?) then the above prctl to set the vector length will
    correctly fail to set the vector length.

    I am not aware of any cloud providers with Arm v9 offerings with an SVE2 vector
    length of 128-bits, unfortunately. The Amazon Graviton 3 supports a vector
    length of 256-bits however this is only SVE1 and not SVE2, but this might be
    sufficient for your use case?

    Thanks,
    George

Children