Skip to content

Conversation

@topolarity
Copy link
Contributor

@topolarity topolarity commented Nov 19, 2025

More conservative version of #21 (thanks to @el-oso for the inspiration).

Adds three preferences:

  • cpu_target: if provided, use this for feature detection instead of JULIA_CPU_TARGET
  • freeze_cpu_target: if true, "freeze" the features detected based on your precompile-time CPU target
  • allow_runtime_invalidation: if false, warn instead of invalidating when CPU features don't match precompile-time
┌ Warning: Runtime invalidation was disabled, but the CPU info is out-of-date.
│ Will continue with incorrect CPU name (from build time).
└ @ HostCPUFeatures ~/repos/HostCPUFeatures.jl/src/HostCPUFeatures.jl:62

This makes the package --trim compatible and also provides a nice preference for users who do not wish for HostCPUFeatures.jl to ever cause an "invalidation storm", even if it means running with the wrong CPU info.

This makes the package (nearly) `--trim` compatible and also provides a
nice preference for users who do not wish for HostCPUFeatures.jl to ever
cause an "invalidation storm", even if it means running with the wrong
CPU info.
fast_half() = False()

@noinline function setfeaturefalse(s)
@inline function setfeaturefalse(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the inlining switch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to improve inferrability - has_feature(Val(s)) is only inferrable if the literal value of s is available in the function, which is true in all of the callers (the argument is always a literal Symbol)

@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 15.38462% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 31.45%. Comparing base (8ebc3d2) to head (bddfae2).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
src/cpu_info.jl 0.00% 9 Missing ⚠️
src/cpu_info_x86.jl 0.00% 9 Missing ⚠️
src/HostCPUFeatures.jl 42.85% 8 Missing ⚠️
src/cpu_info_aarch64.jl 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
- Coverage   36.12%   31.45%   -4.68%     
==========================================
  Files           6        6              
  Lines         191      213      +22     
==========================================
- Hits           69       67       -2     
- Misses        122      146      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

reset_extra_features!()
end
const BASELINE_CPU_NAME = get_cpu_name()
const allow_eval = @load_preference("allow_runtime_invalidation", false)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to check that --trim is enabled in JLOptions ?

everyone who will use it with trim will have to find out this culprit themself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thinking is that this preference is usable by more than just JuliaC.jl, since some users may wish to be opt-in to error / warn on invalidation storms from this package. JuliaC.jl can set this preference automatically, so the end-user experience is the same.

Also technically checking JLOptions at pre-compilation time won't detect --trim properly, but something like JuliaLang/JuliaC.jl#31 would work

@tz-lom
Copy link

tz-lom commented Nov 20, 2025

As a source of the problem I understand the approach, but it actually downgrades package HostCPUFeatures to MaybeSomeOtherHostCPUFeatures, while what we really need is to use some CompileTargetCPUFeatures in LoopVectorization etc.

Pragmatically it is "easier" upgrade standard interface of HostCPUFeatures to return features for the compile target and provide API to retrieve real Host features if that what user really wants (like printing statistics on which CPU we are running now)

@topolarity
Copy link
Contributor Author

As a source of the problem I understand the approach, but it actually downgrades package HostCPUFeatures to MaybeSomeOtherHostCPUFeatures, while what we really need is to use some CompileTargetCPUFeatures in LoopVectorization etc.

That's already true if "native" is missing from your JULIA_CPU_TARGET string though - I agree that it might be a good idea to require that we are specifically operating in the non-native case though (where we already under-approximate feature flags)

@topolarity topolarity force-pushed the ct/no-eval-pref branch 7 times, most recently from 116a624 to 09a8d77 Compare December 4, 2025 00:58
…time

We already support this dynamically, but for some reason it wasn't
possible to get this configuration at precompilation time. Also adds
a "freeze_cpu_target" preference to enable this behavior by default.
if _has_feature(feature) has
@debug "Defining $(has ? "presence" : "absense") of feature $feature."
set_feature(feature, has)
if allow_eval
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't execute if there's a preference right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on which preference you mean

Are you saying you don't think this guard is necessary?

@oscardssmith
Copy link
Member

Looks like the Julia 1.5 CI is failing. Time to bump minimum version to LTS?

@oscardssmith
Copy link
Member

Other than that, LGTM.

@oscardssmith
Copy link
Member

@tz-lom are you good with this in current state? If so, I'll merge and release.

@tz-lom
Copy link

tz-lom commented Dec 4, 2025

@tz-lom are you good with this in current state? If so, I'll merge and release.

@oscardssmith , thanks, it looks ok.
I think you need to fix test matrix to solve failing tests, and it would be nice if you put description of preferences in documentation, because now you have to dig through the code to find out this feature.

@topolarity
Copy link
Contributor Author

@tz-lom Anything else you need from me on this?

@tz-lom
Copy link

tz-lom commented Dec 6, 2025

@topolarity , no that is enough, thank you very much for your work

@oscardssmith oscardssmith merged commit ae4fdac into JuliaSIMD:main Dec 7, 2025
16 of 18 checks passed
@tz-lom
Copy link

tz-lom commented Dec 8, 2025

@topolarity hi Cody, I think we did whoopsie here
I think version was not bumped, and I see that link to documentation from the badge in README is not working (wrong link?)

also check open issue #15 , maybe it can be closed?

@oscardssmith
Copy link
Member

I'll bump and release.

@oscardssmith oscardssmith mentioned this pull request Dec 8, 2025
@oscardssmith
Copy link
Member

@topolarity you missed a compat entry on Preferences.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants