Browse Source

cell init performance opt

tags/v1.0.0
kingxian jinxiaoxian 5 years ago
parent
commit
92bebe65a9
4 changed files with 9 additions and 3 deletions
  1. +5
    -1
      mindspore/nn/cell.py
  2. +2
    -2
      tests/st/ops/cpu/test_maxpool_op.py
  3. +1
    -0
      tests/ut/cpp/runtest.sh
  4. +1
    -0
      tests/ut/python/runtest.sh

+ 5
- 1
mindspore/nn/cell.py View File

@@ -16,6 +16,7 @@
import inspect import inspect
import time import time
import gc import gc
import os
from collections import OrderedDict from collections import OrderedDict
import numpy import numpy
from mindspore import log as logger from mindspore import log as logger
@@ -73,8 +74,11 @@ class Cell:
self._parameter_layout_dict = {} self._parameter_layout_dict = {}
self._create_time = int(time.time() * 1e9) self._create_time = int(time.time() * 1e9)
init_backend() init_backend()

# call gc to release GE session resources used by non-used cell objects # call gc to release GE session resources used by non-used cell objects
gc.collect()
if os.getenv('GC_COLLECT_IN_CELL') == '1':
gc.collect()

self._construct_inputs_num = 0 self._construct_inputs_num = 0
self._construct_inputs_names = [] self._construct_inputs_names = []
self._auto_parallel_mode = False self._auto_parallel_mode = False


+ 2
- 2
tests/st/ops/cpu/test_maxpool_op.py View File

@@ -35,10 +35,10 @@ class Net_Pool(nn.Cell):
class Net_Pool2(nn.Cell): class Net_Pool2(nn.Cell):
def __init__(self): def __init__(self):
super(Net_Pool2, self).__init__() 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): def construct(self, x):
return self.maxpool_fun(x)
return self.maxpool_fun2(x)




@pytest.mark.level0 @pytest.mark.level0


+ 1
- 0
tests/ut/cpp/runtest.sh 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 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 PYTHONPATH=${PROJECT_PATH}/tests/ut/cpp/python_input:$PYTHONPATH:${PROJECT_PATH}
export GLOG_v=2 export GLOG_v=2
export GC_COLLECT_IN_CELL=1


## prepare data for dataset & mindrecord ## prepare data for dataset & mindrecord
cp -fr $PROJECT_PATH/tests/ut/data ${PROJECT_PATH}/build/mindspore/tests/ut/cpp/ cp -fr $PROJECT_PATH/tests/ut/data ${PROJECT_PATH}/build/mindspore/tests/ut/cpp/


+ 1
- 0
tests/ut/python/runtest.sh View File

@@ -27,6 +27,7 @@ fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${BUILD_PATH}/third_party/gtest/lib 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 export PYTHONPATH=$PYTHONPATH:${PROJECT_PATH}:${PROJECT_PATH}/tests/ut/cpp/python_input:${PROJECT_PATH}/tests/ut/python
echo "export PYTHONPATH=$PYTHONPATH" echo "export PYTHONPATH=$PYTHONPATH"
export GC_COLLECT_IN_CELL=1


if [ $# -eq 1 ] && ([ "$1" == "stage1" ] || [ "$1" == "stage2" ] || [ "$1" == "stage3" ]); then if [ $# -eq 1 ] && ([ "$1" == "stage1" ] || [ "$1" == "stage2" ] || [ "$1" == "stage3" ]); then
if [ $1 == "stage1" ]; then if [ $1 == "stage1" ]; then


Loading…
Cancel
Save