llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

SME streaming status overloading

Open jroelofs opened this issue 2 years ago • 8 comments

We should have an overloading mechanism that dispatches to normal vs streaming implementations of a function at runtime based on the current streaming mode. As an optimization, we could set up dispatch to always call the matching implementation in a normal/streaming caller. In streaming-compatible callers, we'd have to inspect the streaming mode via the compiler-rt builtin.

Use case for this could be to provide a memcpy implementation that keeps the streaming mode active or inactive, and uses the corresponding instructions without a streaming mode change.

jroelofs avatar Jul 23 '24 20:07 jroelofs

cc @sdesmalen-arm, @rsandifo-arm, @aemerson for SME bits cc @labrinea, as this is kind of FMV-adjacent

jroelofs avatar Jul 23 '24 20:07 jroelofs

breadcrumb for myself: rdar://116990507

jroelofs avatar Jul 23 '24 20:07 jroelofs

Currently, you can write something like the following. This dispatches as appropriate. It currently doesn't optimize well, but that's something we could fix. Given that, what benefit does a dedicated "overloading" feature provide?

void f_streaming() __arm_streaming;
void f_nonstreaming();
inline void f() __arm_streaming_compatible {
  if (__arm_in_streaming_mode())
    f_streaming();
  else
    f_nonstreaming();
}

(Also, I'm skeptical you'd want to use this for memcpy(); small memcpys only use streaming-compatible instructions anyway, so it's cheaper to check the size before checking whether streaming mode is enabled.)

efriedma-quic avatar Jul 23 '24 23:07 efriedma-quic

I was thinking perhaps by comparing the caller/callee streaming attributes one could statically determine which version to call? Would that work? My patch https://github.com/llvm/llvm-project/pull/87939 compares target-features between caller and callee to achieve something similar. However, using FMV for SME streaming status overloading seems like a workaround to me. The streaming/non-streaming versions will have a dummy feature list in the attribute string and none of this information will actually be used for runtime dispatch.

labrinea avatar Oct 18 '24 14:10 labrinea

How is that better than just writing it out like https://github.com/llvm/llvm-project/issues/100200#issuecomment-2246454338 ?

efriedma-quic avatar Oct 18 '24 19:10 efriedma-quic

How is that better than just writing it out like #100200 (comment) ?

It's not. Exactly the point I was trying to make.

labrinea avatar Oct 18 '24 19:10 labrinea

@labrinea I think it is impossible to use current form of FMV for the overloading of functions with different streaming attributes, as my understanding is that FMV resolves only once what version should be called at runtime, while with streaming functions it depends in the state of the program, so you would need to resolve it every time before calling a function.

mgabka avatar Oct 24 '24 08:10 mgabka

@labrinea I think it is impossible to use current form of FMV for the overloading of functions with different streaming attributes, as my understanding is that FMV resolves only once what version should be called at runtime, while with streaming functions it depends in the state of the program, so you would need to resolve it every time before calling a function.

Hi Maciej. If you read my comment above I was explaining that FMV cannot do runtime dispatch based on streaming attributes, but we could create dummy FMV versions and then statically determine which version to call (never going through the ifunc resolver) based on streaming attribute comparison. As Eli highlighted this is worse than his snippet and I agree. We don't need FMV for this IMO.

labrinea avatar Oct 24 '24 09:10 labrinea