Skip to content
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

Enable interleave for Loop Optimization #1054

Open
dlee992 opened this issue May 30, 2024 · 4 comments
Open

Enable interleave for Loop Optimization #1054

dlee992 opened this issue May 30, 2024 · 4 comments
Labels
feature_request Feature Request

Comments

@dlee992
Copy link
Contributor

dlee992 commented May 30, 2024

Looks like llvmlite doesn't support enabling interleave for Loop optimization for now.

In clang, it can support this style:

#pragma clang loop vectorize(enable)
#pragma clang loop interleave(enable)
for(...) {
  ...
}

more details can be found: https://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations

I saw it can get some benefits in one discussion: https://discourse.llvm.org/t/external-vectorizer-vplan/73634

nearly 2X for matrix multiplication program (on specifying the interleave count as 2

And when debugging my code with this debug setting, as numba doc suggested:

import llvmlite.binding as llvm
llvm.set_option("", "--debug-only=loop-vectorize,iv-descriptors")

I did see some logs like:

LV: Loop hints: force=? width=0 interleave=0
LV: Interleaving disabled by the pass manager

BTW, sometimes, I also saw LV: Loop hints: force=? width=0 interleave=1, I didn't find a source code location that numba or llvmlite sets it to 1, not sure where 1 comes from. I guess LLVM will choose between 0 or 1 internally?

After discussions with numba devs, if we agree it's good, I can contribute a PR to support this feature request.

tag @gmarkall

@dlee992 dlee992 changed the title Set interleavecount for Loop Vectorizer Enable interleave for Loop Optimization May 31, 2024
@dlee992
Copy link
Contributor Author

dlee992 commented Jun 1, 2024

found another llvm issue related to this: llvm/llvm-project#47011.

This makes me a bit confused. If we didn't specify disable interleave, why the debug msg tells me it's disabled by pass manager? need to figure out. Perhaps it's related to optimization level. However, I did rerun my test case with setting NUMBA_OPT to max, the log still shows disabled.

@stuartarchibald stuartarchibald added the feature_request Feature Request label Jun 4, 2024
@sklam
Copy link
Member

sklam commented Jun 4, 2024

Looks like PassManagerBuilder has a lot of new options: https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/lib/Transforms/IPO/PassManagerBuilder.cpp#L150-L177
Update: This is LLVM10

@sklam
Copy link
Member

sklam commented Jun 4, 2024

hm... LLVM14 actual have it on by default: https://github.com/llvm/llvm-project/blob/f28c006a5895fc0e329fe15fead81e37457cb1d1/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp#L194-L223

@dlee992
Copy link
Contributor Author

dlee992 commented Jun 4, 2024

Thanks for digging. After your digging, this is more interesting to me, since I did use LLVM 14.0.6 to locally build llvmlite, I strictly followed the llvm14 recipe provided by llvmlite. I suppose I have to provide a simple reproducer to prove myself.. Will try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature_request Feature Request
Projects
None yet
Development

No branches or pull requests

3 participants