cell init performance opt

This commit is contained in:
kingxian 2020-09-02 17:13:05 +08:00 committed by jinxiaoxian
parent e06dc0a946
commit 92bebe65a9
4 changed files with 9 additions and 3 deletions

View File

@ -16,6 +16,7 @@
import inspect
import time
import gc
import os
from collections import OrderedDict
import numpy
from mindspore import log as logger
@ -73,8 +74,11 @@ class Cell:
self._parameter_layout_dict = {}
self._create_time = int(time.time() * 1e9)
init_backend()
# call gc to release GE session resources used by non-used cell objects
if os.getenv('GC_COLLECT_IN_CELL') == '1':
gc.collect()
self._construct_inputs_num = 0
self._construct_inputs_names = []
self._auto_parallel_mode = False

View File

@ -35,10 +35,10 @@ class Net_Pool(nn.Cell):
class Net_Pool2(nn.Cell):
def __init__(self):
super(Net_Pool2, self).__init__()
self.maxpool_fun = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="SAME")
self.maxpool_fun2 = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="SAME")
def construct(self, x):
return self.maxpool_fun(x)
return self.maxpool_fun2(x)
@pytest.mark.level0

View File

@ -29,6 +29,7 @@ cd ${BUILD_PATH}/mindspore/tests/ut/cpp
export LD_LIBRARY_PATH=${BUILD_PATH}/mindspore/googletest/googlemock/gtest:${PROJECT_PATH}/mindspore:${PROJECT_PATH}/mindspore/lib:$LD_LIBRARY_PATH
export PYTHONPATH=${PROJECT_PATH}/tests/ut/cpp/python_input:$PYTHONPATH:${PROJECT_PATH}
export GLOG_v=2
export GC_COLLECT_IN_CELL=1
## prepare data for dataset & mindrecord
cp -fr $PROJECT_PATH/tests/ut/data ${PROJECT_PATH}/build/mindspore/tests/ut/cpp/

View File

@ -27,6 +27,7 @@ fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${BUILD_PATH}/third_party/gtest/lib
export PYTHONPATH=$PYTHONPATH:${PROJECT_PATH}:${PROJECT_PATH}/tests/ut/cpp/python_input:${PROJECT_PATH}/tests/ut/python
echo "export PYTHONPATH=$PYTHONPATH"
export GC_COLLECT_IN_CELL=1
if [ $# -eq 1 ] && ([ "$1" == "stage1" ] || [ "$1" == "stage2" ] || [ "$1" == "stage3" ]); then
if [ $1 == "stage1" ]; then