1#!/bin/bash 2# Copyright 2021-2022 Huawei Technologies Co., Ltd 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================ 16 17set -e 18 19SCRIPT_DIR=$(dirname "$0") 20MS_DIR=$(realpath ${SCRIPT_DIR}/..) 21BUILD_DIR=${MS_DIR}/build 22HASH_EXE=${BUILD_DIR}/gentid 23HASH_SRC=${BUILD_DIR}/gentid.cc 24 25mkdir -p ${BUILD_DIR} 26echo "#include <iostream>" > ${HASH_SRC} 27echo "#include \"${MS_DIR}/mindspore/core/utils/hashing.h\"" >> ${HASH_SRC} 28echo "int main(int argc, char *argv[0]) { std::cout << mindspore::ConstStringHash(argv[1]) << std::endl; }" >> ${HASH_SRC} 29g++ -std=c++17 -o ${HASH_EXE} ${HASH_SRC} 30 31BASE_TID=$(${HASH_EXE} Base) 32declare -A TIDMAP=( [${BASE_TID}]=Base ) 33 34grep -r MS_DECLARE_PARENT --include=*.h --include=*.cc ${MS_DIR} | while read line 35do 36#echo $line 37if [[ "$line" =~ .*\((.*)\,(.*)\).* ]] 38then 39CLASS_NAME=${BASH_REMATCH[2]}_${BASH_REMATCH[1]} 40TID=$(${HASH_EXE} ${CLASS_NAME}) 41if [ ${TIDMAP["${TID}"]+_} ]; then 42 echo $line 43 echo Same tid $TID is used by $CLASS_NAME and ${TIDMAP[${TID}]}. 44 exit 1 45fi 46TIDMAP[${TID}]=${CLASS_NAME} 47echo ${TID} ${CLASS_NAME} 48fi 49done 50if [ $? != 0 ];then 51 echo 'Check tid failed!' 52 exit 1 53fi 54echo 'All tids are unique, check tid ok.' 55