Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS] Preprocess registered as utility #29538

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/plugins/intel_cpu/tools/commit_slider/utils/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"map_builder" : "printMap",
"log_parser" : "logParser",
"break_validator": "breakValidator",
"e2e_preparator": "getWheelMap"
"e2e_preparator": "getWheelMap",
"replace": "replacePreprocess"
},
"extendBuildCommand" : false,
"commandList" : [
Expand Down
28 changes: 17 additions & 11 deletions src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,23 @@ def getBlobDiff(file1, file2):
content = file.readlines()
with open(file2) as sampleFile:
sampleContent = sampleFile.readlines()
# ignore first line with memory address
i = -1
curMaxDiff = 0
for sampleLine in sampleContent:
i = i + 1
for i, sampleLine in enumerate(sampleContent):
if i == 0:
# ignore first line with memory address
continue
if i >= len(sampleContent):
break
line = content[i]
if "nan" in sampleLine.lower() or "nan" in line.lower():
# todo: test value
return 1000
import sys
return sys.float_info.max
sampleVal = 0
val = 0
try:
sampleVal = float(sampleLine)
val = float(line)
except ValueError:
continue
sampleVal = float(sampleLine)
val = float(line)
if val != sampleVal:
curMaxDiff = max(curMaxDiff, abs(val - sampleVal))
return curMaxDiff
Expand Down Expand Up @@ -588,9 +590,13 @@ def safeClearDir(path, cfg):

def runUtility(cfg, args):
modName = args.utility
fullModName = "utils.{un}".format(un=modName)
try:
mod = importlib.import_module(
"utils.{un}".format(un=modName))
if importlib.util.find_spec(fullModName) is not None:
mod = importlib.import_module(fullModName)
else:
mod = importlib.import_module(
"utils.preprocess.{un}".format(un=modName))
utilName = checkAndGetUtilityByName(cfg, modName)
utility = getattr(mod, utilName)
utility(args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import re
import fileinput
import os
from utils.helpers import CfgError


def replace(cfg, commit):
def replace(cfg, commit=None):
prepCfg = cfg["runConfig"]["preprocess"]
filePath = prepCfg["file"]
curDir = os.path.abspath(os.path.join(
os.path.dirname(__file__), "../../../../../../../"))
filePath = os.path.join(curDir, filePath)
pattern = prepCfg["pattern"]
replacement = ''
if "replacement" in prepCfg:
replacement = prepCfg["replacement"]
for line in fileinput.input(filePath, inplace=True):
newLine = re.sub(pattern, r'{}'.format(replacement), line, flags=0)
print(newLine, end='')

# example: python3 -m commit_slider -u replace -file src/plugins/intel_cpu/src/graph.cpp -pattern "\!node->isDynamicNode\(\)\ &&\ \!node->isExecutable\(\)\ &&\ \!node->isInPlace\(\)" -replacement "false"
def replacePreprocess(args):
argDict = vars(args)
if "-file" not in argDict:
raise CfgError("No 'file' for replace-pp provided")
if "-pattern" not in argDict:
raise CfgError("No 'pattern' for replace-pp provided")

tmpCfg = { "runConfig": { "preprocess" : {
"file" : argDict["-file"],
"pattern" : argDict["-pattern"],
"replacement" : argDict["-replacement"] if "-replacement" in argDict else ''
}}}
replace(tmpCfg)
Loading