-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
SIMD vector type syntax: [|N|]T #6771
Comments
Note I think syntax like |
I like the v syntax, it feels a natural extension of the usual scalar type syntax. LLVM covers your ass when working on non-canonical (where T is not |
I also think we should add a native syntax, although i prefer another option would be |
I think that f32x4 is more readable and easier to write. |
The problem with v4xf32 and f32x4 though is that the compiler still needs to generate calls to std.meta.Vector (or a long chain of builtin calls like with error set returns). |
After some discussion with @Snektron we came up with another idea, utilizing already existing features and make people remember less syntax (assimg
Just use the T ** N == @Vector(N, T) == std.meta.Vector(N, T) |
Why? Once that syntax is adopted for all the Vector types the compiler is free to use that syntax as well. |
This syntax doesn't allow for vectors of pointers, or vectors of some aliased type. |
I always forget of the vectors of pointers, thanks for reminding me. |
I very strongly disapprove of A strictly regular type modifier is a necessity in my eyes, and since we don't have a modifier application operator (and we absolutely should not ever add one), another variation on bracket syntax seems like the best option. Andrew's original proposal fits that, as well as being "augmented" enough that it's clear something else is going on. |
I dont like any of the proposals, bars, x'es, stars don't look good and also confusing, one looks like an array and others like an identifier. I'm fine with status quo, whenever i use vectors i make aliases. If we really really need syntax for vectors i guess this is the least confusing, since it similar to const array ptr: |
I know we removed it but personally I think |
I know this is a bit off topic, but "vector" is such an overloaded term in computing, and usually little to do with the original mathematical term to boot. |
|
@LemonBoy, could you clarify? I was thinking of |
Some more syntax variants on a slightly more complex example: [w][h][4]vec f32
[w][h][4v]f32
[w][h][4 simd]f32
[w][h][|4|]f32
[w][h]@Vector(4, f32) All of the bracket-based variants have the disadvantage that they only make sense on the inner-most array (you can't really have |
|
Yeah, I guess the associativity is backwards in this case 😄 |
Following this reasoning the modifier could simply be placed right of the array: |
|
Delurking for a minute. Is there any projected impact on Zig's use of SIMD vectors from things like Arm's SVE? The examples I have seen of what compilers can do to automatically vectorize normal arrays using tools like SVE and RISC-V's V extension are quite impressive. |
Interesting question. From my superficial understanding of ARM-SVE, it represents a very significant departure from the SIMD paradigm. It is designed to operate directly on large arrays with runtime-known length, rather than manually partitioned fixed-sized chunks. In particular, array length does not need to be a multiple of the native vector size, thanks to the ability to load and operate on incomplete vectors. SVE also relies heavily on a separate bank of predicate registers that don't have a direct counterpart in traditional SIMD. My cautious conclusion would be that SVE is not urgently relevant to the present bikeshedding session, since we are discussing syntax sugar for a fixed-width SIMD data type. It should also be kept in mind that the availability of SVE-supporting commodity hardware is still pretty much zero (I'm not going to count the Fujitsu A64FX), so introducing special syntax for it may be premature. All in all, it would probably be best to extract this question into a separate issue. |
Availability, yeah, that is an issue today, but probably not within a year or so. Even availability of Arm servers has gone from zero to lots with AWS being so cheap for Graviton instances. Arm is clearly pushing (we'll see what NVidia does) SVE/Helium everywhere in their next generations of cores. Everything is going to have some form of VLA (variable length array) support. It was precisely these facts that made me wonder a bit if Zig was skating to where the puck is today and not where it will be in a few years:
Where is x86 in this? No idea but with Arm now entering into the Supercomputer 500 list due to SVE... There are so many, many advantages to VLA support. But I agree that this is a different discussion point. Sorry for the diversion! I am really excited about VLA support in CPUs because of the ability to write code once that just works across a large range of hardware and it means far less support for Intel's idiotic market segmentation by ISA version (try to figure out which AVX512 instructions are supported on which processor!). I'll go back to lurking 😃 |
@andrewrk There is an ambiguity in the proposed syntax: if the length is the result of a bitwise or, the lexer will need to look ahead to know that the pipe does not pair with a close bracket. We don't have this problem with captures because they can only be alphanumeric, but integers can be arbitrary expressions. We could potentially make use of the unused Re: VLA, I think our fixed-length paradigm can be adapted, if we relax the requirement of corresponding strictly to hardware SIMD, like we already do with integers. So, we have a vector corresponding to the size of our problem, which we can make as big as we like, and then the compiler is free to split it up into appropriately-sized chunks. Lane predication could be handled by vectors of |
Adding a separate token for [| and |] would solve that. |
Both this and #1974 are talking about the same issue: numbers formats hold a lot of information. We kind of want some sort of compositional syntax that's easy to read and easy to type, if only for ease of standard communication about boilerplate. While I have no proposal for the optimal arrangements of symbols, the most obvious solution is to just literally describe the data in a way akin to the formatter syntax. This makes nobody happy, and I'm just going to use the equivalent of |
We're definitely going to have SIMD vector syntax, and get rid of |
how about [^N]T |
Is this open to more bikeshedding? If so, then I'll throw mine out there: |
I suggest |
I like |
One interesting thought: Layout-wise, vectors are what you get when you pack arrays without padding and store them in integers. In this sense, they are just like integer-backed structs (#5049). Maybe Notice for both
To my knowledge, all of this is already true about |
Note that |
A natural extension would be to allow That would give us back arrays in packed structs, which are currently unsupported under #5049 |
i noticed this got moved up recently so thought i'd give my 2 cents
any of the other suggestions either fall into one of these categories and/or have already been discussed enough sidenote, |
Something to consider about pointer vectors: |
Since SIMD only works with a handful of primitive types, why not make them individual built-in functions? i.e.
|
This syntax doesn't allow for vectors of pointers, or vectors of some aliased type. Also,
This has parsing issues like C++ templates. Thats a hard pass from me. |
To be honest, I don't really see the problem with keeping By the way, the original reason why this issue was opened has been rejected. Is this still relevant at all? |
Did some digging, do I have this timeline correctly?
But if a concise syntax is still needed, I'd like to propose the following:
|
Symbol | Set |
---|---|
u8^4 |
|
i8^3 |
|
f64^3 |
|
f32^4 |
yes but the existence of 10710 doesn't invalidate this. this issue is independently about replacing |
With the accepted issue #21635, it got me thinking. Why not simply have the idea of "vector" represent a restricted definition of an array? A vector could be defined as What are the main differences between raw arrays and vector types? It seems to be this:
The " Personally I feel this way of defining a vector makes some good sense, but I would love to hear some other opinions. EDIT: With this definition of a vector, you could directly slice a vector, but the " |
You can also refer to implement of Mojo lang |
My preferred syntax is |
Currently we have
@Vector
for this, however, see #5207 and #6209.Array syntax is
[N]T
. This is a proposal for SIMD vector syntax to be[|N|]T
instead of@Vector(N, T)
. For example, a vector of four 32-bit integers would be[|4|]i32
.The main motivation for this would be that the compiler needs to be able to talk about primitive types in type names and in compile errors. Without syntax for this primitive type, in order to do this the compiler would introduce a dependency on the std lib such as
std.meta.Vector(4, i32)
which is verbose and can make compile errors and types more difficult to read at a glance, or it would have to do something like@Type(.{.Vector = .{.len = 4, .child = i32}})
which is even more verbose, making people wonder whether simd vectors really are first-class types in zig after all.I chose
|
because it is already associated with bitwise operations, and because it looks OK when symmetrically positioned against the[
and]
.Related:
The text was updated successfully, but these errors were encountered: