Target-cpu on aws fargate

I'm looking into enabling the target-cpu for a program that runs on fargate, I see that in cargo lambda they pass the "haswell" target-cpu and I would assume the same would work on fargate.

When I change the docker image to use the enviroment variable and run it in fargate it runs without errors.

ENV RUSTFLAGS="-C target-cpu=haswell"

I wonder if AWS decides to use a different CPU under the hood is there a chance of the program not working anymore? if the settings for the architecture wouldn't have changed (X86_64).

The general rule is that ISA support goes forwards, not backwards. As a result, if you've built for Haswell (Xeon and Core i7 from 2013), you can expect the binary to work on newer CPU designs, but not older.

In practice, it's extremely unlikely that AWS will switch to x86-64 CPUs that aren't binary-compatible with Haswell and older CPU types; all AWS x86-64 instances today (even T2) are guaranteed to support Haswell binaries.

That said, I'd be happier to see an x86-64 microarchitecture level used instead (Haswell is v3), and get a guarantee from AWS that they'll never go below that level.

I would say more idealistic than general.

Programs will crash when they hit an instruction not supported.
On linux (man ld) you can add a check that makes them fail early.
Such as RUSTFLAGS="-Clink-arg=-Wl,-zx86-64-v4"

To make code more robust but still have some extra optimization you could move bulk of code into a .so ( cdylib) and compile multiple times. Placing each into respective directories under glibc-hwcaps. (ld.so --help for what your computer supports.)

No, general rule. In general, newer CPUs of the same class support the same or broader ISAs than older CPUs (there are some exceptions, but they're unusual).

If you choose to output code that runs on Haswell server CPUs, then you can expect that it will run on all future x86-64 server CPUs that come after Haswell chronologically; Haswell is a 2013 server CPU, so you can expect that binaries built for Haswell server CPUs will run on all x86-64 server CPUs from the last 10 years, since those server CPUs are more recent than Haswell.

Well, there is the whole AVX512 (now AVX10) fiasco on Intels side. I lost track of all the twists and turns of that one.

More obscure (and more simple) is 3DNow on AMD which isn't support from Ryzen 1 and forwards.

1 Like

Thanks for the insights very helpful!