#Copyright (c) 2025 Huawei Technologies Co., Ltd.
#This program is free software, you can redistribute it and/or modify it under the terms and conditions of
#CANN Open Software License Agreement Version 2.0 (the "License").
#Please refer to the License for details. You may not use this file except in compliance with the License.
#THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
#INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
#See LICENSE in the root of the software repository for the full text of the License.
import sys
sys.stdout.reconfigure(encoding='utf-8')
with open(r'D:\AI\Vector_error_testing_angent\output\RmsNormGrad\aclnnRmsNormGrad.cpp', 'rb') as f:
data = f.read()
# Check 1: std::string(120, ...) - should have exactly 2 quotes around dash
import re
for m in re.finditer(rb'std::string\(120,', data):
snippet = data[m.start():m.start()+28]
if b"\\'" in snippet or b"\\\\" in snippet:
print('BAD DASH: %s' % repr(snippet))
else:
print('OK DASH: %s' % repr(snippet))
# Check 2: rawErrMsg[0] != '...\0'
idx = data.find(b'rawErrMsg[0] !=')
if idx >= 0:
snippet = data[idx:idx+50]
print('NULL CHECK: %s' % repr(snippet))
# In the bytes, C++ '\0' should be: ' + \ + 0 + ' = b"'\\0'"
# But actual should be: single-quote, backslash-one-byte, zero, single-quote
actual_null_char = data[idx+18:idx+25]
print(' null char part: %s' % repr(actual_null_char))
# Check 3: grep -rin
idx = data.find(b'grep -rin')
if idx >= 0:
snippet = data[idx:idx+65]
print('GREP: %s' % repr(snippet))
print()
print('=== Compile check ===')
# If any line has escaped-quote that is NOT in a string literal, it's wrong
# C++ compiler expects: std::string(120, '-') → bytes: ' - '
# rawErrMsg[0] != '\0' → bytes: ' \ 0 '
# grep -rin 'aicore error' → inside C++ string, ' is just '
for i, line in enumerate(data.split(b'\n'), 1):
if b"\\'" in line and b'std::string(120' not in line:
# Only warn about escaped quotes in non-string120 contexts
if b'rawErrMsg' in line or b'grep' in line:
print('WARN L%d: %s' % (i, line[:100]))