Pylikwid
Python interface for the LIKWID C API (https://github.com/RRZE-HPC/likwid)
Install / Use
/learn @RRZE-HPC/PylikwidREADME
pylikwid
Python interface for the C API of LIKWID (https://github.com/RRZE-HPC/likwid)
.. image:: https://travis-ci.com/RRZE-HPC/pylikwid.svg?branch=master :target: https://travis-ci.com/RRZE-HPC/pylikwid?branch=master
Installation
I added a setup.py script for the installation. It builds the C module and copies it to the proper destination.
::
$ git clone https://github.com/RRZE-HPC/pylikwid.git
$ cd pylikwid
# Build C interface
$ python setup.py build_ext -I <include path for likwid> -L <library path for likwid> -R <library path for likwid>
# Install module to the proper location
$ python setup.py install (--prefix=<where to install>)
# Testing
$ python -c "import pylikwid"
$ ./testlib.py
Functions
After import pylikwid you can call the following functions:
Marker API
pylikwid.markerinit(): Initialize the Marker API of the LIKWID library. Must be called previous to all other functions.pylikwid.markerthreadinit(): Add the current thread to the Marker API. Since Python is commonly single-threaded simply call it directly afterpylikwid.markerinit()rr = pylikwid.registerregion(regiontag): Register a region to the Marker API. This is an optional function to reduce the overhead of region registration atpylikwid.markerstartregion. If you don't callpylikwid.registerregion(regiontag), the registration is done atpylikwid.markerstartregion(regiontag). On success, 0 is return. If you havn't calledpylikwid.markerinit(), a negative number is returned.err = pylikwid.markerstartregion(regiontag): Start measurements under the nameregiontag. On success, 0 is return. If you havn't calledpylikwid.markerinit(), a negative number is returned.err = pylikwid.markerstopregion(regiontag): Stop measurements under the nameregiontagagain. On success, 0 is return. If you havn't calledpylikwid.markerinit(), a negative number is returned.num_events, events[], time, count = pylikwid.markergetregion(regiontag): Get the intermediate results of the region identified byregiontag. On success, it returns the number of events in the current group, a list with all the aggregated event results, the measurement time for the region and the number of calls.pylikwid.nextgroup(): Switch to the next event set in a round-robin fashion. If you have set only one event set on the command line, this function performs no operation.pylikwid.markerreset(regiontag): Reset the values stored using the region nameregiontag. On success, 0 is returned.pylikwid.markerclose(): Close the connection to the LIKWID Marker API and write out measurement data to file. This file will be evaluated bylikwid-perfctr.pylikwid.getprocessorid(): Returns the ID of the currently executing CPUpylikwid.pinprocess(cpuid): Pins the current process to the CPU given ascpuid.pylikwid.pinthread(cpuid): Pins the current thread to the CPU given ascpuid.
Topology
-
pylikwid.inittopology(): Initialize the topology module (reads in system topology) -
infodict = pylikwid.getcpuinfo(): Return a dict with general information about the system (CPU model, CPU family, ...)osname: Name of the CPU retrieved from the CPUID leafsname: Name of the micro architectureshort_name: Short name of the micro architecturefamily: ID of the CPU familymodel: Vendor-specific model number of the CPUstepping: Stepping (Revision) of the CPUperf_version: Version number of the hardware performance monitoring capabilitiesperf_num_ctr: Amount of general-purpose counter registers per hardware threadperf_num_fixed_ctr: Amount of fixed-purpose counter registers per hardware threadperf_width_ctr: Bit length of the counter registersclock: CPU clock (only unequal to 0 if timer module is initialized)turbo: Is turbo mode supported?isIntel: Is it an Intel CPU?supportUncore: Does the system have performance monitoring counters in the Uncore?features: String with performance relevant CPU features (AVX, SSE, ...)featureFlags: Bitmask for all available CPU features
-
topodict = pylikwid.getcputopology(): Return a dict with the topology of the system. Here is a list of fields in the dict:-
numSockets: Number of CPU sockets -
numHWThreads: Number of hardware threads (physical + hyperthreading cores) -
activeHWThreads: Number of active/usable hardware threads -
numCoresPerSocket: Amount of hardware threads per CPU socket -
numThreadsPerCore: Amount of hardware threads assembled in every physical CPU core -
numCacheLevels: Amount of levels in cacheing hierarchy -
cacheLevels: Dict with information about the cache levels, keys are the levels (1, 2, 3,...)level: Level of the cache in the hierarchylineSize: Size of a cache linesets: Amount of setsinclusive: Is the cache inclusive or exclusive?`threads: Amount of threads attached to the cacheassociativity: Associativity of the cachetype: data (= data cache), unified = (data + instruction cache)size: Size of the cache in bytes
-
threadPool: Dict with information about the hardware threads. Keys are the os-generated ID of the hardware threadcoreId: ID of the corresponding physical coreapicId: ID set by the operating systemthreadId: ID of the hardware thread in the physical corepackageId: ID of the CPU socket hosting the hardware thread
-
-
pylikwid.printsupportedcpus(): Prints all supported micro architecture names to stdout -
pylikwid.finalizetopology(): Delete all information in the topology module
NUMA
-
numadict = pylikwid.initnuma(): Initialize the NUMA module and return the gathered values-
numberOfNodes: Amount of NUMA nodes in the system -
nodes: Dict holding the information about the NUMA domains. Keys are the NUMA domain IDsid: ID of the NUMA domain (should be equal to dict key)numberOfProcessors: Number of hardware threads attached to the NUMA domainprocessors: List of all CPU IDs attached to the NUMA domainfreeMemory: Amount of free memory in the NUMA domain (in Kbytes)totalMemory: Amount of total memory in the NUMA domain (in Kbytes)numberOfDistances: How many distances to self/other NUMA domainsdistances: List with distances, NUMA domain IDs are the destination indexes in the list
-
-
pylikwid.finalizenuma(): Delete all information in the NUMA module
Affinity
-
affdict = pylikwid.initaffinity(): Initialize the affinity domain module and return the gathered values-
numberOfAffinityDomains: Amount of affinity domains -
numberOfSocketDomains: Amount of CPU socket related affinity domains -
numberOfNumaDomains: Amount of NUMA related affinity domains -
numberOfCacheDomains: Amount of last level cache related affinity domains -
numberOfProcessorsPerSocket: Amount of hardware threads per CPU socket -
numberOfCoresPerCache: Amount of physical CPU cores per last level cache -
numberOfProcessorsPerCache: Amount of hardware threads per last level cache -
domains: Dict holding the information about the affinity domainstag: Name of the affinity domain (N = node, SX = socket X, CY = cache Y, MZ = memory domain Z)numberOfProcessors: Amount of hardware threads in the domainnumberOfCores: Amount of physical CPU cores in the domainprocessorList: List holding the CPU IDs in the domain
-
-
pylikwid.finalizeaffinity(): Delete all information in the affinity domain module -
pylikwid.cpustr_to_cpulist(): Transform a valid cpu string in LIKWID syntax into a list of CPU IDs
Timer
pylikwid.getcpuclock(): Return the CPU clockt_start = pylikwid.startclock(): Start the clock and return the current timestampt_end = pylikwid.stopclock(): Stop the clock and return the current timestampt = pylikwid.getclock(t_start, t_end): Return the time in seconds betweent_startandt_endc = pylikwid.getclockcycles(t_start, t_end): Return the amount of CPU cycles betweent_startandt_end
Temperature
pylikwid.inittemp(cpu): Initialize the temperature module for CPUcpupylikwid.readtemp(cpu): Read the current temperature of CPUcpu
Energy
-
pinfo = pylikwid.getpowerinfo(): Initializes the energy module and returns gathered information. If it returnsNone, there is no energy support-
minFrequency: Minimal possible frequency of a CPU core -
baseFrequency: Base frequency of a CPU core -
hasRAPL: Are energy reading supported? -
timeUnit: Time unit -
powerUnit: Power unit -
domains: Dict holding the information about the energy domains. Keys are PKG, PP0, PP1, DRAMID: ID of the energy domainenergyUnit: Unit to derive raw register counts to uJsupportInfo: Is the information register available?tdp: TDP of the domain (only if supportInfo == True)minPower: Minimal power consumption by the domain (only if supportInfo == True
-
