Live data from Hacker News

Everyone should know SIMD

mitchellh.com

91–100 of 263 posts

Re: Everyone should know SIMD

#91
post #84

Isn't the better abstraction here to use a higher level library in the style of pandas/polars that will operate as vectors, compose and feel readable and inuitive, while (almost?) maxing out SIMD?

Most code cannot be expressed this way unfortunately

Re: Everyone should know SIMD

#92

This is an interesting article. I don't really work with low level enough languages for this to matter (unless - does this ever show up in Javascript somehow?). I guess I don't understand the "reduce" step. It seems like you have to be careful not to "undo" all the benefit from SIMD. Sure, it can compare 8 values in parallel, but then if you have to look at each of the 8 answers in turn you're back to where you began…

It can show up in JavaScript if you write your code in a way that lets the browser engine lower it to SIMD under the hood

Re: Everyone should know SIMD

#93

I always must ask, why isn’t your compiler doing this for you? I know they often aren’t because I’ve seen speed ups from writing SIMD or using the vector functions in MKL, but this is something I really think the compilers should do for us in the simple case.

It’s really hard to make this work in general

Re: Everyone should know SIMD

#94
post #46

Everyone doesn't need to know SIMD. Mechanical sympathy is an important passive perk for software architects to cut down the number of reworks down the line, but I would rate benchmarking and being able to identify bottlenecks as more important everyday skills. I'm working on a voxel space renderer homebrew for the PlayStation. I only have so many cycles to spend on rendering before it becomes a slideshow, so I count…

It’s worth knowing SIMD for the purpose of knowing when it’s not worth using

Re: Everyone should know SIMD

#95
post #85

It distresses me that we don’t have a language that can do a best effort parallelization of arbitrary loop like code across SIMD, multiple threads, multiple cores and GPU with a small directive. I don’t need it to be optimal, just … handy as an option! The last time I brought this up here, folks offered a bunch of options that don’t quite do this, and the best candidate was this 15 year old compiler project that is I…

ISPC isn’t Intel-only: https://github.com/ispc/ispc

Re: Everyone should know SIMD

#98
post #2

I just do gcc -O3 and get SIMD without having to learn it

I have no idea why you're being downvoted. HN has a fetish for SIMD, but if you are hand-rolling SIMD and you aren't writing an explicit acceleration library, you're doing it wrong. Like, 100% of the time. Every modern language has a vectorization optimizing compiler, and through some fairly straightforward techniques this is automagic. And contrary to the various replies, unless you screwed something up compilers ar…

Compilers are really good but really good is not actually that useful in cases where you need SIMD

Re: Everyone should know SIMD

#99

I'd slightly rephrase the title to "everyone should know when SIMD didn't happen." Modern compliers are extremely good at vectorization until they suddenly aren't, an they'll often fall back to scalar code because if assumptions or a single-data dependent branch. Learning to check the compliers optimization reports is arguably more valuable.

That’s exactly what happened:

https://xcancel.com/mitchellh/status/2079672171321081908#m

Re: Everyone should know SIMD

#100

I like SIMD, but before super-optimizing your code with SIMD and the like, really consider your data structures and access patterns. I've been singing Data-Oriented Design's praises, so I'll just collect all my comments here [1], but I think it's a good approach to optimization. I played around with SIMD in my old code (in Zig), but my approach to modelling datastructures was so antithetical to optimization, it was l…

Very much agreed. Even more basic than that - memory access patterns are important. The amusing thing is that you end up writing GPU-style code even for CPU. For example - instead of an array of objects, using parquet-style object of arrays is one such trick.

There's been some good implicit/explicit discussion about SoA on this post [1]. For anyone curious, there are a few different terms that refer to basically the same thing:

- Struct of Arrays (SoA) vs Array of Structs (AoS);

- Row-major order vs column-major order; and

- Row-based vs column based / columnar (in databases)

Most code has arrays of structs (or "lists of objects", the effect is the same), and most databases are row based (same thing). But many game engines use SoA and keep heterogeneous elements together. Some databases like DuckDB do this too, this is an article about the pros and cons of columnar storage in DBs [2].

1. https://news.ycombinator.com/item?id=49012056

2. https://motherduck.com/learn/columnar-storage-guide/

Post reply on HN