-
Notifications
You must be signed in to change notification settings - Fork 13.7k
rustc_scalable_vector(N)
#143924
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
base: master
Are you sure you want to change the base?
rustc_scalable_vector(N)
#143924
Conversation
rustbot has assigned @compiler-errors. Use |
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_attr_data_structures Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the platform-builtins intrinsics. Make sure the cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_gcc changes to the core type system Some changes occurred to the CTFE machinery |
I've changed this back to a draft and marked it as |
cf9474d
to
d58c634
Compare
This comment was marked as resolved.
This comment was marked as resolved.
0c22701
to
3ad0898
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5c92874
to
3edf1b6
Compare
This comment has been minimized.
This comment has been minimized.
3edf1b6
to
4f6b823
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not intend to have repr(simd)
survive this year, so I do not think this should be added.
Could you elaborate? |
I intend to replace it with an approach based on lang items for a variety of reasons, one of them being that to start with, the |
Likewise, scalable vectors do not really have a diversity in their representation. They either go in the scalable vector registers or they don't. They are one type, even if it is parameterized by the element type (and possibly the CPU's Matrix state, idk). |
I think this discussion is better for the RFC - rust-lang/rfcs#3838 - rather than the implementation. With that said, I definitely don't think this should to be blocked by your intentions to change Nothing in rust-lang/rfcs#3838 should make your plans impossible as it's just more internal infrastructure that could easily be changed to something else with a well-motivated proposal, no different than |
So you want me to race you? |
|
This comment was marked as resolved.
This comment was marked as resolved.
Extend parsing of `ReprOptions` with `rustc_scalable_vector(N)` which optionally accepts a single literal integral value - the base multiple of lanes that are in a scalable vector. Can only be applied to structs. Co-authored-by: Jamie Cunliffe <[email protected]>
Extend well-formedness checking and HIR analysis to prohibit the use of scalable vectors in structs, enums, unions, tuples and arrays. LLVM does not support scalable vectors being members of other types, so these restrictions are necessary. Co-authored-by: Jamie Cunliffe <[email protected]>
`simd_reinterpret` is a replacement for `transmute`, specifically for use with scalable SIMD types. It is used in the tests for scalable vectors and in stdarch. Co-authored-by: Jamie Cunliffe <[email protected]>
Introduces `BackendRepr::ScalableVector` corresponding to scalable vector types annotated with `repr(scalable)` which lowers to a scalable vector type in LLVM. Co-authored-by: Jamie Cunliffe <[email protected]>
LLVM doesn't handle stores on `<vscale x N x i1>` for `N != 16`, a type used internally in SVE intrinsics. Spilling to the stack to create debuginfo will cause errors during instruction selection. These types that are an internal implementation detail to the intrinsic, so users should never see them types and won't need any debuginfo. Co-authored-by: Jamie Cunliffe <[email protected]>
Scalable vectors cannot be members of ADTs and thus cannot be kept over await points in async functions.
Scalable vector types only work with the relevant target features enabled, so require this for any function with the types in its signature.
4f6b823
to
95e7b35
Compare
Updated this reflecting changes in rust-lang/rfcs#3838. It doesn't implement everything in it yet, and is definitely incomplete, but it's a starting point. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Trivial changes to rust-analyzer to keep it compiling with changes to `ReprOptions`.
6df93d3
to
26fb3ae
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I'm a student interested in the rust compiler. I'd like to ask how exactly one can write an sve intrinsic. Or how to write the following C language in rust: // #include <arm_sve.h>
// void vec_add(const float *a,const float *b,float *c,int n){
// for (int i=0; i<n; i+=svcntw()){
// svbool_t pg = svwhilelt_b32(i,n);
// svfloat32_t va = svld1(pg,&a[i]);
// svfloat32_t vb = svld1(pg,&b[i]);
// svfloat32_t vc = svadd_f32_m(pg,va,vb);
// svst1(pg,&c[i],vc);
//}
//}
#include <stdio.h>
#include <stdlib.h>
#include <arm_sve.h>
void vec_add(const float* a, const float* b, float* c, int n) {
for (int i = 0; i < n; i += svcntw()) {
svbool_t pg = svwhilelt_b32(i, n);
svfloat32_t va = svld1(pg, &a[i]);
svfloat32_t vb = svld1(pg, &b[i]);
svfloat32_t vc = svadd_f32_m(pg, va, vb);
svst1(pg, &c[i], vc);
}
}
void print_array(const char* name, const float* arr, int n) {
printf("%s: [", name);
for (int i = 0; i < n; ++i) {
printf("%.1f", arr[i]);
if (i < n - 1) printf(", ");
}
printf("]\n");
}
int main() {
#ifdef __ARM_FEATURE_SVE
printf("SVE is supported! \n");
printf("SVE vector length: %d floats (%d bits)\n",
svcntw(), svcntw() * 32);
#else
printf("SVE not supported.\n");
return 1;
#endif
const int n = 16;
float a[n], b[n], c[n];
for (int i = 0; i < n; ++i) {
a[i] = (float)i;
b[i] = (float)(2 * i);
}
printf("\nBefore vector addition:\n");
print_array("A", a, n);
print_array("B", b, n);
vec_add(a, b, c, n);
printf("\nAfter vector addition:\n");
print_array("C = A+B", c, n);
int errors = 0;
for (int i = 0; i < n; ++i) {
if (c[i] ! = a[i] + b[i]) {
printf("Error at index %d: expected %.1f, got %.1f\n",
i, a[i] + b[i], c[i]);
errors++;
}
}
if (errors == 0) {
printf("\nAll results correct! \n");
}
else {
printf("\nFound %d errors! \n", errors);
}
return 0;
}
☔ The latest upstream changes (presumably #145085) made this pull request unmergeable. Please resolve the merge conflicts. |
Supercedes #118917.
Initial experimental implementation of rust-lang/rfcs#3838. Introduces a
rustc_scalable_vector(N)
attribute that can be applied to types with a single[$ty]
field (foru{16,32,64}
,i{16,32,64}
,f{32,64}
,bool
).rustc_scalable_vector
types are lowered to scalable vectors in the codegen backend.As with any unstable feature, there will necessarily be follow-ups as we experiment and find cases that we've not considered or still need some logic to handle, but this aims to be a decent baseline to start from.
See #145052 for request for a lang experiment.