llnl.util.cpu package

Submodules

llnl.util.cpu.alias module

class llnl.util.cpu.alias.FeatureAliasTest(rules)

Bases: object

A test that must be passed for a feature alias to succeed.

Parameters

rules (dict) – dictionary of rules to be met. Each key must be a valid alias predicate

llnl.util.cpu.alias.alias_predicate(predicate_schema)

Decorator to register a predicate that can be used to define feature aliases.

Parameters

predicate_schema (dict) – schema to be enforced in microarchitectures.json for the predicate

llnl.util.cpu.alias.any_of(list_of_features)

Returns a predicate that is True if any of the feature in the list is in the microarchitecture being tested, False otherwise.

llnl.util.cpu.alias.families(list_of_families)

Returns a predicate that is True if the architecture family of the microarchitecture being tested is in the list, False otherwise.

llnl.util.cpu.alias.reason(motivation_for_the_alias)

This predicate returns always True and it’s there to allow writing a documentation string in the JSON file to explain why an alias is needed.

llnl.util.cpu.detect module

llnl.util.cpu.detect.check_output(args, env)
llnl.util.cpu.detect.compatibility_check(architecture_family)

Decorator to register a function as a proper compatibility check.

A compatibility check function takes the raw info dictionary as a first argument and an arbitrary target as the second argument. It returns True if the target is compatible with the info dictionary, False otherwise.

Parameters

architecture_family (str or tuple) – architecture family for which this test can be used, e.g. x86_64 or ppc64le etc.

llnl.util.cpu.detect.compatibility_check_for_power(info, target)
llnl.util.cpu.detect.compatibility_check_for_x86_64(info, target)
llnl.util.cpu.detect.compatibility_checks = {'ppc64': <function compatibility_check_for_power>, 'ppc64le': <function compatibility_check_for_power>, 'x86_64': <function compatibility_check_for_x86_64>}

Mapping from micro-architecture families (x86_64, ppc64le, etc.) to functions checking the compatibility of the host with a given target

llnl.util.cpu.detect.compatible_microarchitectures(info)

Returns an unordered list of known micro-architectures that are compatible with the info dictionary passed as argument.

Parameters

info (dict) – dictionary containing information on the host cpu

llnl.util.cpu.detect.host()

Detects the host micro-architecture and returns it.

llnl.util.cpu.detect.info_dict(operating_system)

Decorator to mark functions that are meant to return raw info on the current cpu.

Parameters

operating_system (str or tuple) – operating system for which the marked function is a viable factory of raw info dictionaries.

llnl.util.cpu.detect.info_factory = {'Darwin': [<function sysctl_info_dict>], 'Linux': [<function proc_cpuinfo>]}

Mapping from operating systems to chain of commands to obtain a dictionary of raw info on the current cpu

llnl.util.cpu.detect.proc_cpuinfo()

Returns a raw info dictionary by parsing the first entry of /proc/cpuinfo

llnl.util.cpu.detect.raw_info_dictionary()

Returns a dictionary with information on the cpu of the current host.

This function calls all the viable factories one after the other until there’s one that is able to produce the requested information.

llnl.util.cpu.detect.sysctl_info_dict()

Returns a raw info dictionary parsing the output of sysctl.

llnl.util.cpu.microarchitecture module

class llnl.util.cpu.microarchitecture.Microarchitecture(name, parents, vendor, features, compilers, generation=0)

Bases: object

ancestors
family

Returns the architecture family a given target belongs to

feature_aliases = <llnl.util.cpu.schema.LazyDictionary object>

Aliases for micro-architecture’s features

optimization_flags(compiler, version)

Returns a string containing the optimization flags that needs to be used to produce code optimized for this micro-architecture.

If there is no information on the compiler passed as argument the function returns an empty string. If it is known that the compiler version we want to use does not support this architecture the function raises an exception.

Parameters
  • compiler (str) – name of the compiler to be used

  • version (str) – version of the compiler to be used

to_dict(return_list_of_items=False)

Returns a dictionary representation of this object.

Parameters

return_list_of_items (bool) – if True returns an ordered list of items instead of the dictionary

exception llnl.util.cpu.microarchitecture.UnsupportedMicroarchitecture

Bases: ValueError

Raised if a compiler version does not support optimization for a given micro-architecture.

llnl.util.cpu.microarchitecture.coerce_target_names(func)

Decorator that automatically converts a known target name to a proper Microarchitecture object.

llnl.util.cpu.microarchitecture.generic_microarchitecture(name)

Returns a generic micro-architecture with no vendor and no features.

Parameters

name (str) – name of the micro-architecture

llnl.util.cpu.microarchitecture.targets = <llnl.util.cpu.schema.LazyDictionary object>

Dictionary of known micro-architectures

llnl.util.cpu.microarchitecture.version_components(version)

Decomposes the version passed as input in version number and suffix and returns them.

If the version number of the suffix are not present, an empty string is returned.

Parameters

version (str) – version to be decomposed into its components

llnl.util.cpu.schema module

class llnl.util.cpu.schema.LazyDictionary(factory, *args, **kwargs)

Bases: collections.abc.MutableMapping

Lazy dictionary that gets constructed on first access to any object key

Parameters

factory (callable) – factory function to construct the dictionary

data
llnl.util.cpu.schema.targets_json = <llnl.util.cpu.schema.LazyDictionary object>

In memory representation of the data in microarchitectures.json, loaded on first access

Module contents

class llnl.util.cpu.Microarchitecture(name, parents, vendor, features, compilers, generation=0)

Bases: object

ancestors
family

Returns the architecture family a given target belongs to

feature_aliases = <llnl.util.cpu.schema.LazyDictionary object>

Aliases for micro-architecture’s features

optimization_flags(compiler, version)

Returns a string containing the optimization flags that needs to be used to produce code optimized for this micro-architecture.

If there is no information on the compiler passed as argument the function returns an empty string. If it is known that the compiler version we want to use does not support this architecture the function raises an exception.

Parameters
  • compiler (str) – name of the compiler to be used

  • version (str) – version of the compiler to be used

to_dict(return_list_of_items=False)

Returns a dictionary representation of this object.

Parameters

return_list_of_items (bool) – if True returns an ordered list of items instead of the dictionary

exception llnl.util.cpu.UnsupportedMicroarchitecture

Bases: ValueError

Raised if a compiler version does not support optimization for a given micro-architecture.

llnl.util.cpu.generic_microarchitecture(name)

Returns a generic micro-architecture with no vendor and no features.

Parameters

name (str) – name of the micro-architecture

llnl.util.cpu.host()

Detects the host micro-architecture and returns it.

llnl.util.cpu.version_components(version)

Decomposes the version passed as input in version number and suffix and returns them.

If the version number of the suffix are not present, an empty string is returned.

Parameters

version (str) – version to be decomposed into its components