You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: Should __cpu_features__ provide target information #15558
We just added the __cpu_features__ structure. I am not quite sure what it provides, but there are up to three things that are interesting.
The CPU features:
supported by the system
NumPy is compiled with (targeted)
the union of both (i.e. the ones that are actually in use for the running instance)
I am wondering if we should add that information @seiko2plus, @mattip? That could be either by providing an additional struct, or assuming that we currently have the "supported by the system" definition, we change True to a string "enabled" and "supported" (the truthiness of which actually evaluates to the identical thing). Information "2." would not be available, but I am not sure it is super relevant.
EDIT: Sorry, if we are using definition "3.", I think that is probably all good, but I thought we may be using definition "1." in which case I wonder it is what we actually want to know in most cases.
IMHO __cpu_features__ should only contain what the running machine support and also separated from the infrastructure for the following reasons:
it may be used by other projects in different areas that don't rely on NumPy distutils
easy to dump by the end-user True or False too easy to get it, make it useful for reports.
easy to use by testing units and it's also the reason behind combining all features from all architecture together even if the CPU feature will always remain False,
for example:
fromnumpy.core._multiarray_umathimport__cpu_features__ascpu_have# in X86 VSX always exist and returns False# instead of setting a default value via get()ifcpu_have["VSX"]:
# good enoughpassifcpu_have.get("VSX", False):
# not necessarypassifcpu_have.get("VSX"):
# not necessary toopass# also it can be used to check if NumPy support a certain feature or not,# or even validate ita_feature="bla"ifa_featurenotincpu_have:
# cross-platform checkingprint("'%s' is an invalid CPU feature or maybe Numpy doesn't support yet"%a_feature)
but I think it needs to be improved like generate a python file contains the new attributes and import it into NumPy module instead of adding the new attributes to _multiarray_umath module, also add new dict contains the actual targeted features with list of the dispatch-able sources that generated for them, almost the same provided information in the build log report.
the build log report from #13516 on gcc and x86_64 :
@seberg, the user can change the default settings, and AVX2 may be part of the baseline, so it should be like this
# better to have a function insteaddeffeature_is_supported(name):
assert(isinstance(name, str))
NAME=name.upper() # lets allow lower caseifNAMEnotin__cpu_features__:
raiseValueError("Invalid CPU feature '%s'"%name)
ifNAMEin__cpu_baseline__:
# there's no need check if the CPU supports it or not# since the module will fail to load with a runtime error,# if the runnung machine doesn't support the baseline featuresreturnTrueifNAMEin__cpu_dispatch__and__cpu_features__[NAME]:
returnTruereturnFalseavx2_is_being_used=feature_is_supported("AVX2")
Activity
seiko2plus commentedon Feb 13, 2020
IMHO
__cpu_features__should only contain what the running machine support and also separated from the infrastructure for the following reasons:it may be used by other projects in different areas that don't rely on NumPy distutils
easy to dump by the end-user
TrueorFalsetoo easy to get it, make it useful for reports.easy to use by testing units and it's also the reason behind combining all features from all architecture together even if the CPU feature will always remain
False,for example:
#13516, add new two attributes to umath module
__cpu_baseline__a list of CPU baseline feature names that configured by --cpu-baseline__cpu_dispatch__a list of CPU dispatch feature names that configured by --cpu-dispatchalso #13516, combine all new attrbutes togther to provides a minmal report in pytester
but I think it needs to be improved like generate a python file contains the new attributes and import it into NumPy module instead of adding the new attributes to
_multiarray_umathmodule, also add new dict contains the actual targeted features with list of the dispatch-able sources that generated for them, almost the same provided information in the build log report.the build log report from #13516 on gcc and x86_64 :
seberg commentedon Feb 13, 2020
Sounds good, seems like if I want code to run only if AVX2 is supported I woul do:
which is fair enough, thanks for the info. I guess we may bike-shed on the naming at some point, but you got it covered for starters.
seiko2plus commentedon Feb 13, 2020
@seberg, the user can change the default settings, and AVX2 may be part of the baseline, so it should be like this