diff --git a/mindspore-lite/test/config_level0/ascend/prof.json b/mindspore-lite/test/config_level0/ascend/prof.json new file mode 100644 index 0000000000000000000000000000000000000000..148b66c7680706b336024573c612dc50cbaef644 --- /dev/null +++ b/mindspore-lite/test/config_level0/ascend/prof.json @@ -0,0 +1,7 @@ +{ + "profiler": { + "switch": "on", + "output": "./profiling", + "aicpu": "on" + } +} \ No newline at end of file diff --git a/mindspore-lite/test/st/python/python_api/test_acl_profiling.py b/mindspore-lite/test/st/python/python_api/test_acl_profiling.py new file mode 100644 index 0000000000000000000000000000000000000000..3b9a92157961126dfaafb1e1bda56f80464b2f07 --- /dev/null +++ b/mindspore-lite/test/st/python/python_api/test_acl_profiling.py @@ -0,0 +1,73 @@ +# Copyright 2025 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +Test for MindSpore Lite Profiling of Ascend ALC +""" + +import os +import pytest +import mindspore_lite as mslite +import numpy as np + +# ----------- config file ----------- +# [acl_build_options] +# input_format="ND" +# input_shape="sample:2,4,-1,-1;timestep:1;encoder_hidden_states:2,77,768" +# ge.dynamicDims="64,64;96,96" + +MODEL_FILE = "./sd1.5_unet.onnx_graph.mindir" +DEVICE_ID = 0 + + +def test_acl_profiling_with_config_file(): + """ + test profiling with config file + """ + context = mslite.Context() + context.target = ["ascend"] + context.ascend.device_id = DEVICE_ID + model = mslite.Model() + profiling_config = {"ascend_context": {"profiling_config_file": "./prof.json"}} + model.build_from_file(model_path=MODEL_FILE, model_type=mslite.ModelType.MINDIR, context=context, + config_dict=profiling_config) + + input_data_1 = np.random.rand(2, 4, 96, 96).astype(np.float32) + input_data_2 = np.random.rand(1).astype(np.float32) + input_data_3 = np.random.rand(2, 77, 768).astype(np.float32) + + model.resize(model.get_inputs(), [[2, 4, 96, 96], [1], [2, 77, 768]]) + model.predict([input_data_1, input_data_2, input_data_3]) + path_list = os.listdir("./profiling") + assert len(path_list) == 1 + prof_path = os.path.join("./profiling", path_list[0]) + prof_file_list = os.listdir(prof_path) + assert len(prof_file_list) == 2 + assert "device_" + str(DEVICE_ID) in prof_file_list + assert "host" in prof_file_list + + +def test_acl_profiling_without_config_file(): + """ + test profiling without config file + """ + context = mslite.Context() + context.target = ["ascend"] + context.ascend.device_id = DEVICE_ID + model = mslite.Model() + profiling_config = {"ascend_context": {"profiling_config_file": "./xx.json"}} + with pytest.raises(RuntimeError) as raise_info: + model.build_from_file(model_path=MODEL_FILE, model_type=mslite.ModelType.MINDIR, context=context, + config_dict=profiling_config) + assert "build_from_file failed! Error is Common error code." in str(raise_info.value) diff --git a/mindspore-lite/test/st/scripts/ascend/run_cloud_arm_a2.sh b/mindspore-lite/test/st/scripts/ascend/run_cloud_arm_a2.sh index 81975e679395cb2027d8641c0a84a331c2c822f0..2a21c3d153dee571a67ee07caaf99a7dfe71475e 100644 --- a/mindspore-lite/test/st/scripts/ascend/run_cloud_arm_a2.sh +++ b/mindspore-lite/test/st/scripts/ascend/run_cloud_arm_a2.sh @@ -388,6 +388,7 @@ echo "---------- Run MindSpore Lite API ----------" cd ${basepath}/python/python_api/ || exit 1 cp -r ${ms_models_path}/sd1.5_unet.onnx* . || exit 1 # for Model Predict ST cp -r ${ms_models_path}/single_matmul_model.onnx.mindir . || exit 1 # for Update weights ST +cp -r ${basepath}/../${config_folder}/ascend/prof.json . || exit 1 # for test profiling #for code coverage in A2 if [[ "${MSLITE_ENABLE_COVERAGE}" == "on" || "${MSLITE_ENABLE_COVERAGE}" == "ON" ]]; then echo "MSLITE_ENABLE_COVERAGE: ${MSLITE_ENABLE_COVERAGE}, MSLITE_COVERAGE_FILE: ${MSLITE_COVERAGE_FILE}" @@ -396,12 +397,14 @@ if [[ "${MSLITE_ENABLE_COVERAGE}" == "on" || "${MSLITE_ENABLE_COVERAGE}" == "ON" python3 -m coverage run --rcfile=${MSLITE_COVERAGE_FILE} -m pytest test_model_parallel_runner.py || exit 1 python3 -m coverage run --rcfile=${MSLITE_COVERAGE_FILE} -m pytest test_model_info.py || exit 1 python3 -m coverage run --rcfile=${MSLITE_COVERAGE_FILE} -m pytest test_update_weight.py || exit 1 + python3 -m coverage run --rcfile=${MSLITE_COVERAGE_FILE} -m pytest test_acl_profiling.py || exit 1 else pytest test_tensor.py || exit 1 pytest test_model.py || exit 1 pytest test_model_parallel_runner.py || exit 1 pytest test_model_info.py || exit 1 pytest test_update_weight.py || exit 1 + pytest test_acl_profiling.py || exit 1 fi echo "---------- Run MindSpore Lite API SUCCESS ----------" #---------------------------------------------------------