From ba6f88d783014f921ebd7ca34ac2927531856682 Mon Sep 17 00:00:00 2001 From: Erich Focht Date: Wed, 19 Dec 2018 23:52:40 +0100 Subject: [PATCH] Created package directory for veosinfo. Added pure python calc_metrics() function. --- .gitignore | 5 +++ Makefile | 10 ++--- setup.py | 9 ++-- veosinfo/__init__.py | 2 + veosinfo.pyx => veosinfo/_veosinfo.pyx | 57 ------------------------- veosinfo/metrics.py | 59 ++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 66 deletions(-) create mode 100644 .gitignore create mode 100644 veosinfo/__init__.py rename veosinfo.pyx => veosinfo/_veosinfo.pyx (90%) create mode 100644 veosinfo/metrics.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2adbd40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*~ +*.o +*.so +_veosinfo.c +*.pyc diff --git a/Makefile b/Makefile index 64f97eb..8bbffcb 100644 --- a/Makefile +++ b/Makefile @@ -4,25 +4,25 @@ # ... # -veosinfo.so: veosinfo.pyx +veosinfo/_veosinfo.so: veosinfo/_veosinfo.pyx python setup.py build_ext -i --use-cython test: PATHONPATH=. python test_cython.py clean: - rm -f *.so veosinfo.c + rm -f veosinfo/*.so veosinfo/_veosinfo.c veosinfo/*.pyc -install: veosinfo.so +install: veosinfo/_veosinfo.so python setup.py install sdist: python setup.py sdist --use-cython -rpm: veosinfo.so +rpm: veosinfo/_veosinfo.so python setup.py bdist_rpm -srpm: veosinfo.so +srpm: veosinfo/_veosinfo.so python setup.py bdist_rpm --source-only .PHONY: test clean install sdist rpm diff --git a/setup.py b/setup.py index 80625ad..d6940a2 100644 --- a/setup.py +++ b/setup.py @@ -11,11 +11,11 @@ ext = ".pyx" _ext_mods=[ - Extension("veosinfo", - sources=["veosinfo" + ext], + Extension("veosinfo._veosinfo", + sources=["veosinfo/_veosinfo" + ext], libraries=["veosinfo"], # Unix-like specific - library_dirs=["/opt/nec/ve/veos/lib64"], - include_dirs=["/opt/nec/ve/veos/include"] + library_dirs=["veosinfo", "/opt/nec/ve/veos/lib64"], + include_dirs=["veosinfo", "/opt/nec/ve/veos/include"] ) ] @@ -54,6 +54,7 @@ license = "GPLv2", description = "Python bindings for the veosinfo library for the SX-Aurora Vector Engine", long_description = _long_descr, + packages = [ "veosinfo" ], data_files = [("share/py-veosinfo", ["README.md"])], url = "https://github.com/sx-aurora/py-veosinfo", classifiers=[ diff --git a/veosinfo/__init__.py b/veosinfo/__init__.py new file mode 100644 index 0000000..20a02b1 --- /dev/null +++ b/veosinfo/__init__.py @@ -0,0 +1,2 @@ +from veosinfo._veosinfo import * +from metrics import * diff --git a/veosinfo.pyx b/veosinfo/_veosinfo.pyx similarity index 90% rename from veosinfo.pyx rename to veosinfo/_veosinfo.pyx index c98f306..40d5a4f 100644 --- a/veosinfo.pyx +++ b/veosinfo/_veosinfo.pyx @@ -535,60 +535,3 @@ def ve_pid_perf(int nodeid, int pid): res[regname] = regval[2 + i] return res - -ve_cpu_info_cache = dict() - -def calc_metrics(nodeid, old, new): - """ - Calculate metrics from two perf counter values dicts. - nodeid needs to be passed in order to have the correct value of the clock. - The result is stored in a dict with keys being the metric names. - - MOPS = (EX-VX+VE+FMAEC) / USRCC*clck - MFLOPS = FPEC/USRCC*clck - V.OP RATIO = VE/(EX-VX+VE)*100 - AVER. V.LEN [-] = VE/VX - VECTOR TIME = VECC/1.4GHz - L1CACHE MISS = L1MCC/1.4GHz - CPU PORT CONF = PCCC/1.4GHz - VLD LLC HIT E [%] = (1-VLCME/VLEC)*100 - - """ - global ve_cpu_info - r = dict() - if nodeid not in ve_cpu_info_cache: - ve_cpu_info_cache[nodeid] = cpu_info(nodeid) - clck = float(ve_cpu_info_cache[nodeid]['mhz']) - clck_hz = clck * 1000000 - for _r in ["EX", "VX", "VE", "FMAEC", "FPEC", "USRCC", "VECC", - "L1MCC", "PCCC", "VLCME", "VLEC", "T"]: - exec("d%s = float(new.get(\"%s\", 0) - old.get(\"%s\", 0))" % (_r, _r, _r)) - #exec("print \"d%s=%%r new %s=%%r old %s=%%r\" %% (d%s, new.get(\"%s\", 0), old.get(\"%s\", 0))" % - # (_r, _r, _r, _r, _r, _r)) - - - r["USRSEC"] = new.get("USRCC", 0) / clck_hz - r["USRTIME"] = dUSRCC / clck_hz - r["ELAPSED"] = dT - - if r["ELAPSED"] > 0: - r["EFFTIME"] = r["USRTIME"] / r["ELAPSED"] - - if dUSRCC > 0: - r["MOPS"] = (dEX - dVX + dVE + dFMAEC) * clck / dUSRCC - r["MFLOPS"] = dFPEC * clck / dUSRCC - r["VTIMERATIO"] = dVECC * 100 / dUSRCC - r["L1CACHEMISS"] = dL1MCC * 100 / dUSRCC - r["CPUPORTCONF"] = dPCCC * 100 / dUSRCC - - if dEX > 0: - r["VOPRAT"] = dVE * 100 / (dEX - dVX + dVE) - - if dVX > 0: - r["AVGVL"] = dVE / dVX - - if dVLEC > 0: - r["VLDLLCHIT"] = (1 - dVLCME / dVLEC) * 100 - - return r - diff --git a/veosinfo/metrics.py b/veosinfo/metrics.py new file mode 100644 index 0000000..4d8a95d --- /dev/null +++ b/veosinfo/metrics.py @@ -0,0 +1,59 @@ +from _veosinfo import cpu_info + + +ve_cpu_info_cache = dict() + + +def calc_metrics(nodeid, old, new): + """ + Calculate metrics from two perf counter values dicts. + nodeid needs to be passed in order to have the correct value of the clock. + The result is stored in a dict with keys being the metric names. + + MOPS = (EX-VX+VE+FMAEC) / USRCC*clck + MFLOPS = FPEC/USRCC*clck + V.OP RATIO = VE/(EX-VX+VE)*100 + AVER. V.LEN [-] = VE/VX + VECTOR TIME = VECC/1.4GHz + L1CACHE MISS = L1MCC/1.4GHz + CPU PORT CONF = PCCC/1.4GHz + VLD LLC HIT E [%] = (1-VLCME/VLEC)*100 + + """ + global ve_cpu_info_cache + r = dict() + if nodeid not in ve_cpu_info_cache: + ve_cpu_info_cache[nodeid] = cpu_info(nodeid) + clck = float(ve_cpu_info_cache[nodeid]['mhz']) + clck_hz = clck * 1000000 + for _r in ["EX", "VX", "VE", "FMAEC", "FPEC", "USRCC", "VECC", + "L1MCC", "PCCC", "VLCME", "VLEC", "T"]: + exec("d%s = float(new.get(\"%s\", 0) - old.get(\"%s\", 0))" % (_r, _r, _r)) + #exec("print \"d%s=%%r new %s=%%r old %s=%%r\" %% (d%s, new.get(\"%s\", 0), old.get(\"%s\", 0))" % + # (_r, _r, _r, _r, _r, _r)) + + + r["USRSEC"] = new.get("USRCC", 0) / clck_hz + r["USRTIME"] = dUSRCC / clck_hz + r["ELAPSED"] = dT + + if r["ELAPSED"] > 0: + r["EFFTIME"] = r["USRTIME"] / r["ELAPSED"] + + if dUSRCC > 0: + r["MOPS"] = (dEX - dVX + dVE + dFMAEC) * clck / dUSRCC + r["MFLOPS"] = dFPEC * clck / dUSRCC + r["VTIMERATIO"] = dVECC * 100 / dUSRCC + r["L1CACHEMISS"] = dL1MCC * 100 / dUSRCC + r["CPUPORTCONF"] = dPCCC * 100 / dUSRCC + + if dEX > 0: + r["VOPRAT"] = dVE * 100 / (dEX - dVX + dVE) + + if dVX > 0: + r["AVGVL"] = dVE / dVX + + if dVLEC > 0: + r["VLDLLCHIT"] = (1 - dVLCME / dVLEC) * 100 + + return r