Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CS] Blob-compare job preparation (#29538)

Yury Gaydaychukb494d7a0e258
diff --git a/tools/commit_slider/tests/commit_slider_test.py b/tools/commit_slider/tests/commit_slider_test.py
index c163a314b6d..ffb21544c3f 100644
--- a/tools/commit_slider/tests/commit_slider_test.py
+++ b/tools/commit_slider/tests/commit_slider_test.py
@@ -15,7 +15,7 @@ from test_data import FirstBadVersionData, FirstValidVersionData,\
BenchmarkAppUnstableDevData, BenchmarkAppWrongPathData, BenchmarkAppPathFoundData,\
BenchmarkFirstFixedAppData, AcModeData, BenchmarkMetricData, CustomizedLogData, \
MultiConfigData, ConfigMultiplicatorData, ConfigMultiplicatorWithKeyData, \
- AcModeDataBitwise
+ AcModeDataBitwise, CompareBlobsData, CompareBlobsMulOutputData, CompareBlobsAutomatchData
class CommitSliderTest(TestCase):
@skip_commit_slider_devtest
@@ -367,3 +367,47 @@ class CommitSliderTest(TestCase):
cfg["another"]["path"],
"not updated"
)
+
+ @skip_commit_slider_devtest
+ def testAccuracyBase(self):
+ breakCommit, updatedData = getExpectedCommit(
+ CompareBlobsData())
+ actualCommit, _ = getActualCommit(updatedData)
+ self.assertEqual(breakCommit, actualCommit)
+
+ @skip_commit_slider_devtest
+ def testAccuracyMultipleOutput(self):
+ breakCommit, updatedData = getExpectedCommit(
+ CompareBlobsMulOutputData())
+ actualCommit, _ = getActualCommit(updatedData)
+ self.assertEqual(breakCommit, actualCommit)
+
+ @skip_commit_slider_devtest
+ def testAccuracyMultipleOutputAutomatch(self):
+ breakCommit, updatedData = getExpectedCommit(
+ CompareBlobsAutomatchData())
+ actualCommit, _ = getActualCommit(updatedData)
+ self.assertEqual(breakCommit, actualCommit)
+
+ @skip_commit_slider_devtest
+ def testBlobMatching(self):
+ from utils.helpers import getBlobMatch
+ fileList1 = [
+ "#001_Some_node_type_1.ieb",
+ "#002_Some_node_type_2.ieb",
+ "#003_Some_node_type_3.ieb",
+ "#004_Some_node_type_4.ieb",
+ "#005_Some_node_type_5.ieb"]
+ fileList2 = [
+ "#006_Some_changed_node_type_1.ieb",
+ "#007_Some_changed_node_type_3.ieb",
+ "#008_Some_changed_node_type_2.ieb",
+ "#008_Some_changed_node_type_5.ieb",
+ "#008_Some_changed_node_type_4.ieb"
+ ]
+ expectedMatch = [
+ tuple([0, 0]), tuple([1, 2]), tuple([2, 1]), tuple([3, 4]), tuple([4, 3])]
+ curMatch = getBlobMatch(fileList1, fileList2)
+ actualMatch = [tuple([fileList1.index(v[0]), fileList2.index(v[1])]) for v in curMatch]
+ diff = set(expectedMatch).difference(set(actualMatch))
+ self.assertEqual(diff, set())
diff --git a/tools/commit_slider/tests/test_data.py b/tools/commit_slider/tests/test_data.py
index 53bd9d2c8a3..7b59d897dff 100644
--- a/tools/commit_slider/tests/test_data.py
+++ b/tools/commit_slider/tests/test_data.py
@@ -72,7 +72,10 @@ class TestData():
MultiConfig = 16,
ConfigMultiplicator = 17,
MultiConfigWithKey = 18,
- AcModeDataBitwise = 19
+ AcModeDataBitwise = 19,
+ CompareBlobsData = 20,
+ MulOutput = 21,
+ CmpBlobsAutomatch = 22
def requireTestData(self, reqLambda):
# mapping json to test data holder
@@ -217,6 +220,45 @@ class BenchmarkFirstFixedAppData(TestData):
requireBinarySearchData
)
+class CompareBlobsData(TestData):
+ def getTestCase():
+ return TestData.TestCase.CompareBlobsData
+
+ def getTestName(self):
+ return "CompareBlobsData"
+
+ def __init__(self):
+ from test_util import requireBinarySearchData
+ self.requireTestData(
+ requireBinarySearchData
+ )
+
+class CompareBlobsMulOutputData(TestData):
+ def getTestCase():
+ return TestData.TestCase.CompareBlobsData
+
+ def getTestName(self):
+ return "CompareBlobsDataMulOutput"
+
+ def __init__(self):
+ from test_util import requireBinarySearchData
+ self.requireTestData(
+ requireBinarySearchData
+ )
+
+class CompareBlobsAutomatchData(TestData):
+ def getTestCase():
+ return TestData.TestCase.CmpBlobsAutomatch
+
+ def getTestName(self):
+ return "CompareBlobsAutomatchData"
+
+ def __init__(self):
+ from test_util import requireBinarySearchData
+ self.requireTestData(
+ requireBinarySearchData
+ )
+
class BenchmarkMetricData(TestData):
def getTestCase():
return TestData.TestCase.BmLatencyMetric
diff --git a/tools/commit_slider/tests/test_util.py b/tools/commit_slider/tests/test_util.py
index fc97fd1c1a2..249d361018b 100644
--- a/tools/commit_slider/tests/test_util.py
+++ b/tools/commit_slider/tests/test_util.py
@@ -19,7 +19,6 @@ from utils.helpers import getMeaningfullCommitTail
def getVersionList(td: TestData):
with open(td.patchedFile, 'r') as file:
data = file.read()
-
# extract patch list
stats_re = re.compile(td.pattern, re.MULTILINE | re.DOTALL)
patchJSONList = stats_re.findall(data)
diff --git a/tools/commit_slider/tests/tests_res/fbv_blb_cmp_automatch_main.cpp b/tools/commit_slider/tests/tests_res/fbv_blb_cmp_automatch_main.cpp
new file mode 100644
index 00000000000..58b17233ee5
--- /dev/null
+++ b/tools/commit_slider/tests/tests_res/fbv_blb_cmp_automatch_main.cpp
@@ -0,0 +1,49 @@
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+int main() {
+ ofstream blobFile("/tmp/commit_slider_tool/tmp/some_blob.txt");
+ ofstream blobFile2("/tmp/commit_slider_tool/tmp/another_blob.txt");
+ const char *patchGenerator = R"V0G0N(
+ [
+ {
+ "str": "blobFile << \"address line\\n0.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "success_1"
+ },
+ {
+ "str": "blobFile << \"address line\\n0.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "success_2"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_1",
+ "state": "BREAK"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_2"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_3"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_4"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_5"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_6"
+ }
+ ]
+ )V0G0N";
+
+ blobFile.close();
+ blobFile2.close();
+ return 0;
+}
diff --git a/tools/commit_slider/tests/tests_res/fbv_blb_cmp_main.cpp b/tools/commit_slider/tests/tests_res/fbv_blb_cmp_main.cpp
new file mode 100644
index 00000000000..25fe1e585e0
--- /dev/null
+++ b/tools/commit_slider/tests/tests_res/fbv_blb_cmp_main.cpp
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+int main() {
+ ofstream blobFile("blob.txt");
+ const char *patchGenerator = R"V0G0N(
+ [
+ {
+ "str": "blobFile << \"address line\\n0.000\\n0.000\";",
+ "comment": "success_1"
+ },
+ {
+ "str": "blobFile << \"address line\\n0.000\\n0.000\";",
+ "comment": "success_2"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";",
+ "comment": "error_1",
+ "state": "BREAK"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";",
+ "comment": "error_2"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";",
+ "comment": "error_3"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";",
+ "comment": "error_4"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";",
+ "comment": "error_5"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";",
+ "comment": "error_6"
+ }
+ ]
+ )V0G0N";
+
+ blobFile.close();
+ return 0;
+}
diff --git a/tools/commit_slider/tests/tests_res/fbv_blb_cmp_mul_out_main.cpp b/tools/commit_slider/tests/tests_res/fbv_blb_cmp_mul_out_main.cpp
new file mode 100644
index 00000000000..33c5e9e6454
--- /dev/null
+++ b/tools/commit_slider/tests/tests_res/fbv_blb_cmp_mul_out_main.cpp
@@ -0,0 +1,49 @@
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+int main() {
+ ofstream blobFile("some_blob.txt");
+ ofstream blobFile2("another_blob.txt");
+ const char *patchGenerator = R"V0G0N(
+ [
+ {
+ "str": "blobFile << \"address line\\n0.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "success_1"
+ },
+ {
+ "str": "blobFile << \"address line\\n0.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "success_2"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_1",
+ "state": "BREAK"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_2"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_3"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_4"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_5"
+ },
+ {
+ "str": "blobFile << \"address line\\n1.000\\n0.000\";blobFile2 << \"address line\\n0.000\\n0.000\";",
+ "comment": "error_6"
+ }
+ ]
+ )V0G0N";
+
+ blobFile.close();
+ blobFile2.close();
+ return 0;
+}
diff --git a/tools/commit_slider/tests/tests_res/tests_res.json b/tools/commit_slider/tests/tests_res/tests_res.json
index 8bdd8bec6a2..3077fe239d5 100644
--- a/tools/commit_slider/tests/tests_res/tests_res.json
+++ b/tools/commit_slider/tests/tests_res/tests_res.json
@@ -402,6 +402,68 @@
}
}
},
+ "CompareBlobsData": {
+ "repoName": "CompareBlobsData",
+ "patchedFile": "tests_res/fbv_blb_cmp_main.cpp",
+ "testCfg": {
+ "appCmd" : "{appCmd}",
+ "appPath": "{appPath}",
+ "gitPath" : "{gitPath}",
+ "buildPath" : "{buildPath}",
+ "verboseOutput": false,
+ "runConfig" : {
+ "commitList" : {
+ "getCommitListCmd" : "git log {start}..{end} --boundary --pretty=\"%h\""
+ },
+ "mode" : "compareBlobs",
+ "traversal" : "firstFailedVersion",
+ "outputFileNamePattern" : "(.)*blob.txt$",
+ "outputDirectory" : "{buildPath}",
+ "limit" : 0.00
+ }
+ }
+ },
+ "CompareBlobsDataMulOutput": {
+ "repoName": "CompareBlobsDataMulOutput",
+ "patchedFile": "tests_res/fbv_blb_cmp_mul_out_main.cpp",
+ "testCfg": {
+ "appCmd" : "{appCmd}",
+ "appPath": "{appPath}",
+ "gitPath" : "{gitPath}",
+ "buildPath" : "{buildPath}",
+ "verboseOutput": false,
+ "runConfig" : {
+ "commitList" : {
+ "getCommitListCmd" : "git log {start}..{end} --boundary --pretty=\"%h\""
+ },
+ "mode" : "compareBlobs",
+ "traversal" : "firstFailedVersion",
+ "outputFileNamePattern" : "(.)*some_blob.txt$",
+ "outputDirectory" : "{buildPath}",
+ "limit" : 0.00
+ }
+ }
+ },
+ "CompareBlobsAutomatchData": {
+ "repoName": "CompareBlobsAutomatch",
+ "patchedFile": "tests_res/fbv_blb_cmp_automatch_main.cpp",
+ "testCfg": {
+ "appCmd" : "{appCmd}",
+ "appPath": "{appPath}",
+ "gitPath" : "{gitPath}",
+ "buildPath" : "{buildPath}",
+ "verboseOutput": false,
+ "runConfig" : {
+ "commitList" : {
+ "getCommitListCmd" : "git log {start}..{end} --boundary --pretty=\"%h\""
+ },
+ "mode" : "compareBlobs",
+ "traversal" : "firstFailedVersion",
+ "autoMatch" : true,
+ "limit" : 0.00
+ }
+ }
+ },
"BmLatencyMetric": {
"repoName": "BmLatencyMetric",
"patchedFile": "tests_res/fbv_bm_latency.cpp",
diff --git a/tools/commit_slider/utils/cfg.json b/tools/commit_slider/utils/cfg.json
index b0da4c5ae64..13f30fff67c 100644
--- a/tools/commit_slider/utils/cfg.json
+++ b/tools/commit_slider/utils/cfg.json
@@ -17,7 +17,8 @@
"map_builder" : "printMap",
"log_parser" : "logParser",
"break_validator": "breakValidator",
- "e2e_preparator": "getWheelMap"
+ "e2e_preparator": "getWheelMap",
+ "replace": "replacePreprocess"
},
"extendBuildCommand" : false,
"commandList" : [
@@ -71,6 +72,7 @@
"appPath" : "../../bin/intel64/Release/",
"buildPath" : "../../build/",
"cachePath" : "{workPath}/slider_cache/",
+ "defaultTmpDir" : "{workPath}/tmp/",
"userCachePath" : "",
"logPath" : "{workPath}/log/",
"userLogPath" : "",
diff --git a/tools/commit_slider/utils/cfg_samples/blob_cmp_automatch.json b/tools/commit_slider/utils/cfg_samples/blob_cmp_automatch.json
new file mode 100644
index 00000000000..25e61cb70be
--- /dev/null
+++ b/tools/commit_slider/utils/cfg_samples/blob_cmp_automatch.json
@@ -0,0 +1,56 @@
+{
+ "buildEnvVars" : [
+ {"name" : "CMAKE_CXX_COMPILER_LAUNCHER", "val" : "ccache"},
+ {"name" : "ALL_PROXY", "val" : "<path_1>"},
+ {"name" : "http_proxy", "val" : "<path_2>"},
+ {"name" : "https_proxy", "val" : "<path_3>"}
+ ],
+ "envVars" : [
+ {"name" : "ALL_PROXY", "val" : "<path_1>"},
+ {"name" : "http_proxy", "val" : "<path_2>"},
+ {"name" : "https_proxy", "val" : "<path_3>"},
+ {"name" : "OV_CPU_BLOB_DUMP_NODE_TYPE", "val" : "Output"},
+ {"name" : "OV_CPU_BLOB_DUMP_FORMAT", "val" : "TEXT"},
+ {"name" : "OV_CPU_BLOB_DUMP_DIR", "val" : "/tmp/commit_slider_tool/tmp/"}
+ ],
+ "makeCmd" : "cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=OFF -DTHREADING=TBB -DENABLE_INTEL_GPU=OFF -DENABLE_SAMPLES=ON -DENABLE_TESTS=OFF -DENABLE_HETERO=OFF -DENABLE_TEMPLATE=OFF -DENABLE_CPU_DEBUG_CAPS=ON -DENABLE_DEBUG_CAPS=ON -DENABLE_OPENVINO_DEBUG=ON -DCMAKE_CXX_FLAGS=-Wno-deprecated -DCMAKE_C_FLAGS=-Wno-deprecated -DCMAKE_CXX_FLAGS=-Wno-deprecated-declarations -DCMAKE_C_FLAGS=-Wno-deprecated-declarations -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..",
+ "appPath" : "../../bin/intel64/Release/",
+ "appCmd" : "./benchmark_app -m <path_to_model> -i <path_to_input> -t 10",
+ "verboseOutput": false,
+ "commandList" : [
+ {"cmd" : "git rm --cached -r .", "path" : "{gitPath}"},
+ {"cmd" : "git reset --hard", "path" : "{gitPath}"},
+ {"cmd" : "git rm .gitattributes", "path" : "{gitPath}"},
+ {"cmd" : "git reset .", "path" : "{gitPath}"},
+ {"cmd" : "git checkout -- .", "path" : "{gitPath}"},
+ {"cmd" : "git rm --cached -r .", "path" : "{gitPath}"},
+ {"cmd" : "git reset --hard", "path" : "{gitPath}"},
+ {"cmd" : "git rm .gitattributes", "path" : "{gitPath}"},
+ {"cmd" : "git reset .", "path" : "{gitPath}"},
+ {"cmd" : "git checkout -- .", "path" : "{gitPath}"},
+ {"cmd" : "git clean -fxd", "path" : "{gitPath}"},
+ {"cmd" : "mkdir -p build", "path" : "{gitPath}"},
+ {"cmd" : "git checkout {commit}", "catchMsg" : "(.)*error: (.)*", "path" : "{gitPath}"},
+ {"tag" : "preprocess"},
+ {"cmd" : "git submodule init", "path" : "{gitPath}"},
+ {"cmd" : "git submodule update --recursive", "path" : "{buildPath}"},
+ {"cmd" : "{makeCmd}", "catchMsg" : "CMake Error", "path" : "{buildPath}"},
+ {"cmd" : "make --jobs=4", "catchMsg" : "(.)*make(.)*Error(.)*", "path" : "{buildPath}"},
+ {"cmd" : "git checkout -- .", "path" : "{gitPath}"}
+ ],
+ "runConfig" : {
+ "preprocess" : {
+ "name" : "replace",
+ "file" : "src/plugins/intel_cpu/src/graph.cpp",
+ "pattern" : "\\!node->isDynamicNode\\(\\)\\ &&\\ \\!node->isExecutable\\(\\)\\ &&\\ \\!node->isInPlace\\(\\)",
+ "replacement" : "false"
+ },
+ "commitList" : {
+ "getCommitListCmd" : "git log <hash_1>..<hash_2> --boundary --pretty=\"%h\""
+ },
+ "mode" : "compareBlobs",
+ "traversal" : "firstFailedVersion",
+ "autoMatch" : true,
+ "limit" : 0.00
+ }
+}
diff --git a/tools/commit_slider/utils/helpers.py b/tools/commit_slider/utils/helpers.py
index c444b5bb63f..cb4fb3c3e90 100644
--- a/tools/commit_slider/utils/helpers.py
+++ b/tools/commit_slider/utils/helpers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2024 Intel Corporation
+# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import importlib
@@ -14,7 +14,8 @@ from argparse import ArgumentParser
from utils.cfg_manager import CfgManager
import copy
-
+bigOutputFilesNumber = 10
+bigFloatNumber = 1000000 # sys.float_info.max does not seem to work correctly
mulKey = 'multiplication_key'
def getMeaningfullCommitTail(commit):
@@ -137,25 +138,72 @@ 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():
+ if "nan" in sampleLine.lower() and "nan" in line.lower():
+ continue
+ return bigFloatNumber
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
+def trimFileNameByCommitHash(fileList, commit):
+ prefixLen = len(getMeaningfullCommitTail(commit))
+ return [file[(prefixLen + 1):] for file in fileList]
+
+def getBlobMatch(fileList1, fileList2, leftCommit = None, rightCommit = None):
+ if len(fileList1) >= bigOutputFilesNumber:
+ raise Exception("Too much files to compare: {f1}, {f2}. Comparision may bee too long".format(
+ f1=fileList1, f2=fileList2
+ ))
+ trimmedFileList1 = [x for x in fileList1]
+ trimmedFileList2 = [x for x in fileList2]
+
+ if not leftCommit is None or not rightCommit is None:
+ trimmedFileList1 = trimFileNameByCommitHash(fileList1, leftCommit)
+ trimmedFileList2 = trimFileNameByCommitHash(fileList2, rightCommit)
+
+ def gcs(s1: str, s2: str) -> int:
+ # great common substring
+ if s1 < s1: # gcs(A,B) == gcs(B,A)
+ return gcs(s2, s1)
+ else:
+ l1, l2 = len(s1), len(s2)
+ res = [[0] * (l2 + 1) for _ in range(l1 + 1)]
+ for i in range(1, l1 + 1):
+ for j in range(1, l2 + 1):
+ if s1[i - 1] == s2[j - 1]:
+ res[i][j] = res[i - 1][j - 1] + 1
+ else:
+ res[i][j] = max(res[i - 1][j], res[i][j - 1])
+ return res[l1][l2]
+ length = len(fileList1)
+ naturalSet = set([i for i in range(length)])
+ excMsg = "Output blobs matching error, {l1} doesn't match {l2}".format(
+ l1=fileList1, l2=fileList2)
+ if length != len(fileList2):
+ raise Exception(excMsg)
+
+ matchMtrx = [[gcs(f1, f2) for f1 in trimmedFileList1] for f2 in trimmedFileList2]
+ indOfMax = lambda a: a.index(max(a))
+ colMatch = [indOfMax([matchMtrx[i1][i2] for i1, _ in enumerate(trimmedFileList1)]) for i2, _ in enumerate(trimmedFileList2)]
+ rowMatch = [indOfMax([matchMtrx[i1][i2] for i2, _ in enumerate(trimmedFileList2)]) for i1, _ in enumerate(trimmedFileList1)]
+ if set(rowMatch) == naturalSet and set(colMatch) == naturalSet:
+ return [[f1, fileList2[colMatch[i1]]] \
+ for i1, f1 in enumerate(fileList1)]
+ else:
+ raise Exception(excMsg)
def absolutizePaths(cfg):
pl = sys.platform
@@ -588,9 +636,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)
diff --git a/tools/commit_slider/utils/modes.py b/tools/commit_slider/utils/modes.py
index 9286bf2d33b..78201869f6d 100644
--- a/tools/commit_slider/utils/modes.py
+++ b/tools/commit_slider/utils/modes.py
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
import os
-from utils.helpers import fetchAppOutput, getActualPath
+from utils.helpers import CfgManager, fetchAppOutput, getActualPath
from utils.helpers import getMeaningfullCommitTail, extractModelPath
from utils.helpers import handleCommit, getBlobDiff
from utils.helpers import getCommitLogger, CashError, CfgError,\
@@ -531,6 +531,10 @@ class CompareBlobsMode(Mode):
super().__init__(cfg)
self.createCash()
self.maxDiff = 0
+ # option of automatic matching of comparing blobs i.e.
+ # blob_for_node_1_commit_1.ieb <--> blob_for_node_1_commit_2.ieb
+ # blob_for_node_2_commit_1.ieb <--> blob_for_node_2_commit_2.ieb
+ self.autoMatch = False
def prepareRun(self, list, cfg):
# we need to exclude initial prerun-cash handling, as it may
@@ -567,35 +571,58 @@ class CompareBlobsMode(Mode):
filename = self.setCommitCash(commit, None)
return filename
- def compareCommits(self, lCommit: str, rCommit: str, cfg: map):
- leftBorderOutputName = self.getPseudoMetric(lCommit, cfg)
- rightBorderOutputName = self.getPseudoMetric(rCommit, cfg)
- fullLeftFileName = os.path.join(self.cachePath, leftBorderOutputName)
- fullRightName = os.path.join(self.cachePath, rightBorderOutputName)
- curMaxDiff = getBlobDiff(fullLeftFileName, fullRightName)
+ def compareSingleBlobPair(self, lName, rName, commit, cfg):
+ curMaxDiff = getBlobDiff(lName, rName)
isDiff = True if curMaxDiff > self.limit else False
- curCommit = rCommit
+ curCommit = commit
curCommit = curCommit.replace('"', "")
commitLogger = getCommitLogger(cfg, curCommit)
commitLogger.info(
"Commit {status} from {c}".format(
status=("differs" if isDiff else "don't differ"),
- c=rCommit)
- )
+ c=commit))
+ commitLogger.info("Absolute difference is {d}".format(d=curMaxDiff))
if isDiff:
self.maxDiff = curMaxDiff
- commitLogger.info("Absolute difference is {d}".format(d=curMaxDiff))
+ return isDiff
+
+ def compareCommits(self, lCommit: str, rCommit: str, cfg: map):
+ leftOutput = self.getPseudoMetric(lCommit, cfg)
+ rightOutput = self.getPseudoMetric(rCommit, cfg)
+
+ isDiff = False
+ matchingPairList = []
+ if self.autoMatch:
+ # auto matching of patterns
+ from utils.helpers import getBlobMatch
+ matchingPairList = getBlobMatch(leftOutput, rightOutput, lCommit, rCommit)
+ else:
+ # single specified blob pattern
+ matchingPairList = [[leftOutput, rightOutput]]
+ for matchPair in matchingPairList:
+ fullLeftFileName = os.path.join(self.cachePath, matchPair[0])
+ fullRightFileName = os.path.join(self.cachePath, matchPair[1])
+ isDiff = isDiff or self.compareSingleBlobPair(fullLeftFileName, fullRightFileName, rCommit, cfg)
return isDiff
def checkCfg(self, cfg):
super().checkCfg(cfg)
- if not ("outputFileNamePattern" in cfg["runConfig"]):
- raise CfgError("Output pattern is not configured")
- elif not ("outputDirectory" in cfg["runConfig"]):
+ isAutoMatch = "autoMatch" in cfg["runConfig"] and \
+ cfg["runConfig"]["autoMatch"] is True
+ if not ("outputFileNamePattern" in cfg["runConfig"]) and not isAutoMatch:
+ raise CfgError("Output pattern OR automatch is not configured")
+ elif not ("outputDirectory" in cfg["runConfig"]) and not isAutoMatch:
raise CfgError("Output directory pattern is not configured")
else:
- self.outFileNamePattern = cfg["runConfig"]["outputFileNamePattern"]
- self.outDir = os.path.abspath(cfg["runConfig"]["outputDirectory"])
+ if isAutoMatch:
+ self.autoMatch = True
+ cfg['defaultTmpDir'] = CfgManager.singlestepStrFormat(cfg["defaultTmpDir"], "workPath", cfg['workPath'])
+ os.makedirs(cfg['defaultTmpDir'], exist_ok=True)
+ self.outDir = os.path.abspath(cfg["defaultTmpDir"])
+ else:
+ self.autoMatch = False
+ self.outFileNamePattern = cfg["runConfig"]["outputFileNamePattern"]
+ self.outDir = os.path.abspath(cfg["runConfig"]["outputDirectory"])
if "limit" in cfg["runConfig"]:
self.limit = float(cfg["runConfig"]["limit"])
else:
@@ -603,25 +630,27 @@ class CompareBlobsMode(Mode):
def setCommitCash(self, commit, valueToCache):
isCommitCashed, _ = self.getCommitIfCashed(commit)
- newFileName = ""
+ newFileName = [] if self.autoMatch else ""
if isCommitCashed:
raise CashError("Commit already cashed")
else:
fileList = os.listdir(self.outDir)
# we look for just created output file
for filename in fileList:
- isDump = re.search(self.outFileNamePattern, filename)
+ isDump = True if self.autoMatch else re.search(self.outFileNamePattern, filename)
if isDump:
- newFileName = "{c}_{fn}".format(
+ curFileName = "{c}_{fn}".format(
c=getMeaningfullCommitTail(commit), fn=filename
)
shutil.move(
os.path.join(self.outDir, filename),
- os.path.join(self.cachePath, newFileName)
+ os.path.join(self.cachePath, curFileName)
)
- break
- if filename == "":
- raise CmdError("Output file not found")
+ if self.autoMatch:
+ newFileName.append(curFileName)
+ else:
+ newFileName = curFileName
+ break
return newFileName
def createCash(self):
@@ -629,16 +658,23 @@ class CompareBlobsMode(Mode):
# so, we just set up path to cache folder
# todo: handle usercache for multimodel case
self.cachePath = getActualPath("cachePath", self.cfg)
- pass
def getCommitIfCashed(self, commit):
fileList = os.listdir(self.cachePath)
curCommitPattern = "{c}_(.)*".format(c=getMeaningfullCommitTail(commit))
+
+ cashedFileList = []
for filename in fileList:
isDump = re.search(curCommitPattern, filename)
if isDump:
- return True, filename
- return False, None
+ if self.autoMatch:
+ cashedFileList.append(filename)
+ else:
+ return True, filename
+ if self.autoMatch:
+ return not (not cashedFileList), cashedFileList
+ else:
+ return False, None
def setOutputInfo(self, pathCommit):
pathCommit.diff = self.maxDiff
diff --git a/tools/commit_slider/utils/preprocess/replace.py b/tools/commit_slider/utils/preprocess/replace.py
index c6c39af6416..019c848f9ef 100644
--- a/tools/commit_slider/utils/preprocess/replace.py
+++ b/tools/commit_slider/utils/preprocess/replace.py
@@ -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)