tpp-mlir icon indicating copy to clipboard operation
tpp-mlir copied to clipboard

Option to select extension support (replace target/cpu/fpu)

Open rengolin opened this issue 9 months ago • 3 comments

As discussed with @shahidact, we could add an option to both tpp-run and tpp-opt that will select the best tuple of { triple, cpu, target-features } for each arch and extension, to make sure we build the LLVM TargetMachine correctly and can restrict code generation on newer machines.

The idea is to keep the current default (via ifdef) for each arch, but replace the triple/cpu/fpu flags with a single one extension that allows you to pick the appropriate options. Something like:

struct { StringRef, StringRef, StringRef } getTargetMachineOptions (StringRef option) {
  return StringSwitch<StringRef>(option)
              .Case("avx", { "x86_64-linux-gnu", "sandybridge", "+avx" })
              .Case("avx2", { "x86_64-linux-gnu", "haswell", "+avx2" })
              .Case("avx512", { "x86_64-linux-gnu", "skylake", "+avx512" })
              .Case("avx512vnni", { "x86_64-linux-gnu", "znver4", "+avx512vnni" })
              .Case("neon", { "armv8a-linux-gnu", "cortex-a53", "+neon" })
              .Case("sve", { "armv8a-linux-gnu", "a64fx", "+sve" })
              .Default({ "", "", "" });
}

and then use those three parameters when building the TargetMachine.

rengolin avatar May 08 '25 14:05 rengolin

This should serve to create the TargetMachine, however, we need to also introduce something like gpuBackend say cpuBackendFeature which will be available to client passes. The above proposed StringRef option argument is effectively cpuBackendFeature

shahidact avatar May 08 '25 15:05 shahidact

What is this supposed to control? How passes behave at compile time? How llvm compilation behaves?

I am just trying to understand if this has meaningful connection with DLTI and/or an MLIR attribute like #llvm.target<triple, cpu, target-features> that is under discussion for controlling the conversion to llvm dialect.

rolfmorel avatar May 08 '25 15:05 rolfmorel

I am just trying to understand if this has meaningful connection with DLTI and/or an MLIR attribute like #llvm.target<triple, cpu, target-features> that is under discussion for controlling the conversion to llvm dialect.

In theory, DLTI target would replace this flag. Meanwhile, we mimic what the DLTI target will give us in an option, so that it becomes trivial to replace them (or even just add DLTI via the flag).

rengolin avatar May 08 '25 16:05 rengolin