Skip to content

Commit 63d7fdc

Browse files
committed
resolve linking problem
1 parent 6535661 commit 63d7fdc

File tree

3 files changed

+315
-1
lines changed

3 files changed

+315
-1
lines changed

paddle/fluid/pybind/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ include_directories(${PADDLE_SOURCE_DIR}/paddle/fluid/platform)
55
set(PYBIND_DEPS pybind python proto_desc memory executor fleet_wrapper box_wrapper prune
66
feed_fetch_method pass_builder parallel_executor profiler layer tracer engine scope_pool
77
analysis_predictor imperative_profiler imperative_flag save_load_util dlpack_tensor device_context
8-
gloo_wrapper infer_io_utils heter_wrapper generator op_version_registry ps_gpu_wrapper custom_operator ps_service graph_py_service)
8+
gloo_wrapper infer_io_utils heter_wrapper generator op_version_registry ps_gpu_wrapper custom_operator)
99

10+
if (WITH_PSCORE)
11+
set(PYBIND_DEPS ${PYBIND_DEPS} ps_service)
12+
set(PYBIND_DEPS ${PYBIND_DEPS} graph_py_service)
13+
endif()
1014
if (WITH_GPU OR WITH_ROCM)
1115
set(PYBIND_DEPS ${PYBIND_DEPS} dynload_cuda)
1216
set(PYBIND_DEPS ${PYBIND_DEPS} cuda_device_guard)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import print_function
16+
17+
import unittest
18+
import itertools
19+
import numpy as np
20+
from inference_pass_test import InferencePassTest
21+
import paddle.fluid as fluid
22+
import paddle.fluid.core as core
23+
from paddle.fluid.core import PassVersionChecker
24+
from paddle.fluid.core import AnalysisConfig
25+
26+
27+
class TRTAffineChannelTest(InferencePassTest):
28+
def setUp(self):
29+
self.bs = 2
30+
self.channel = 8
31+
self.height = 16
32+
self.width = 16
33+
self.data_layout = 'NCHW'
34+
self.precision = AnalysisConfig.Precision.Float32
35+
self.serialize = False
36+
self.enable_trt = True
37+
38+
def build(self):
39+
# set min_graph_size to 2,
40+
# because affine channel doesn't support nhwc format
41+
self.trt_parameters = InferencePassTest.TensorRTParam(
42+
1 << 30, self.bs, 2, self.precision, self.serialize, False)
43+
44+
with fluid.program_guard(self.main_program, self.startup_program):
45+
if self.data_layout == 'NCHW':
46+
shape = [-1, self.channel, self.height, self.width]
47+
else:
48+
shape = [-1, self.height, self.width, self.channel]
49+
50+
data = fluid.data(name='in', shape=shape, dtype='float32')
51+
# set scale, bias by constant
52+
scale = fluid.layers.create_parameter(
53+
shape=[self.channel],
54+
dtype='float32',
55+
default_initializer=fluid.initializer.Constant(2.))
56+
bias = fluid.layers.create_parameter(
57+
shape=[self.channel],
58+
dtype='float32',
59+
default_initializer=fluid.initializer.Constant(.5))
60+
affine_channel_out = fluid.layers.affine_channel(
61+
data, scale=scale, bias=bias, data_layout=self.data_layout)
62+
out = fluid.layers.batch_norm(affine_channel_out, is_test=True)
63+
64+
shape[0] = self.bs
65+
self.feeds = {'in': np.random.random(shape).astype('float32'), }
66+
self.fetch_list = [out]
67+
68+
def check_output(self):
69+
if core.is_compiled_with_cuda():
70+
use_gpu = True
71+
atol = 1e-5
72+
if self.trt_parameters.precision == AnalysisConfig.Precision.Half:
73+
atol = 1e-3
74+
self.check_output_with_option(use_gpu, atol, flatten=True)
75+
self.assertTrue(
76+
PassVersionChecker.IsCompatible('tensorrt_subgraph_pass'))
77+
78+
def run_test(self):
79+
self.build()
80+
self.check_output()
81+
82+
def run_test_all(self):
83+
precision_opt = [
84+
AnalysisConfig.Precision.Float32, AnalysisConfig.Precision.Half
85+
]
86+
serialize_opt = [False, True]
87+
88+
if self.data_layout == 'NCHW':
89+
min_shape = [
90+
self.bs, self.channel, self.height // 2, self.width // 2
91+
]
92+
max_shape = [self.bs, self.channel, self.height * 2, self.width * 2]
93+
opt_shape = [self.bs, self.channel, self.height, self.width]
94+
95+
if self.data_layout == 'NHWC':
96+
min_shape = [
97+
self.bs, self.height // 2, self.width // 2, self.channel
98+
]
99+
max_shape = [self.bs, self.height * 2, self.width * 2, self.channel]
100+
opt_shape = [self.bs, self.height, self.width, self.channel]
101+
102+
dynamic_shape_profile = InferencePassTest.DynamicShapeParam({
103+
'in': min_shape
104+
}, {'in': max_shape}, {'in': opt_shape}, False)
105+
dynamic_shape_opt = [None, dynamic_shape_profile]
106+
107+
for precision, serialize, dynamic_shape in itertools.product(
108+
precision_opt, serialize_opt, dynamic_shape_opt):
109+
self.precision = precision
110+
self.serialize = serialize
111+
self.dynamic_shape_params = dynamic_shape
112+
self.run_test()
113+
114+
def test_base(self):
115+
self.run_test()
116+
117+
def test_fp16(self):
118+
self.precision = AnalysisConfig.Precision.Half
119+
self.run_test()
120+
121+
def test_serialize(self):
122+
self.serialize = True
123+
self.run_test()
124+
125+
def test_dynamic(self):
126+
self.dynamic_shape_params = InferencePassTest.DynamicShapeParam({
127+
'in': [self.bs, self.channel, self.height // 2, self.width // 2]
128+
}, {'in': [self.bs, self.channel, self.height * 2, self.width * 2]
129+
}, {'in': [self.bs, self.channel, self.height, self.width]}, False)
130+
self.run_test()
131+
132+
def test_nchw_all(self):
133+
self.run_test_all()
134+
135+
def test_nhwc(self):
136+
self.data_layout = 'NHWC'
137+
self.run_test_all()
138+
139+
140+
if __name__ == "__main__":
141+
unittest.main()

scripts/paddle

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/bin/bash
2+
3+
function version(){
4+
echo "PaddlePaddle , compiled with"
5+
echo " with_avx: ON"
6+
echo " with_gpu: OFF"
7+
echo " with_mkl: ON"
8+
echo " with_mkldnn: "
9+
echo " with_python: ON"
10+
}
11+
12+
function ver2num() {
13+
set -e
14+
# convert version to number.
15+
if [ -z "$1" ]; then # empty argument
16+
printf "%03d%03d%03d%03d%03d" 0
17+
else
18+
local VERN=$(echo $1 | sed 's#v##g' | sed 's#\.# #g' \
19+
| sed 's#a# 0 #g' | sed 's#b# 1 #g' | sed 's#rc# 2 #g')
20+
if [ `echo $VERN | wc -w` -eq 3 ] ; then
21+
printf "%03d%03d%03d%03d%03d" $VERN 999 999
22+
else
23+
printf "%03d%03d%03d%03d%03d" $VERN
24+
fi
25+
fi
26+
set +e
27+
}
28+
29+
function cpu_config() {
30+
# auto set KMP_AFFINITY and OMP_DYNAMIC from Hyper Threading Status
31+
# only when MKL enabled
32+
if [ "ON" == "OFF" ]; then
33+
return 0
34+
fi
35+
platform="`uname -s`"
36+
ht=0
37+
if [ $platform == "Linux" ]; then
38+
ht=`lscpu |grep "per core"|awk -F':' '{print $2}'|xargs`
39+
elif [ $platform == "Darwin" ]; then
40+
if [ `sysctl -n hw.physicalcpu` -eq `sysctl -n hw.logicalcpu` ]; then
41+
# HT is OFF
42+
ht=1
43+
fi
44+
else
45+
return 0
46+
fi
47+
if [ $ht -eq 1 ]; then # HT is OFF
48+
if [ -z "$KMP_AFFINITY" ]; then
49+
export KMP_AFFINITY="granularity=fine,compact,0,0"
50+
fi
51+
if [ -z "$OMP_DYNAMIC" ]; then
52+
export OMP_DYNAMIC="FALSE"
53+
fi
54+
else # HT is ON
55+
if [ -z "$KMP_AFFINITY" ]; then
56+
export KMP_AFFINITY="granularity=fine,compact,1,0"
57+
fi
58+
if [ -z "$OMP_DYNAMIC" ]; then
59+
export OMP_DYNAMIC="True"
60+
fi
61+
fi
62+
}
63+
64+
function threads_config() {
65+
# auto set OMP_NUM_THREADS and MKL_NUM_THREADS
66+
# according to trainer_count and total processors
67+
# only when MKL enabled
68+
# auto set OPENBLAS_NUM_THREADS when do not use MKL
69+
platform="`uname -s`"
70+
processors=0
71+
if [ $platform == "Linux" ]; then
72+
processors=`grep "processor" /proc/cpuinfo|sort -u|wc -l`
73+
elif [ $platform == "Darwin" ]; then
74+
processors=`sysctl -n hw.logicalcpu`
75+
else
76+
return 0
77+
fi
78+
trainers=`grep -Eo 'trainer_count.[0-9]+' <<< "$@" |grep -Eo '[0-9]+'|xargs`
79+
if [ -z $trainers ]; then
80+
trainers=1
81+
fi
82+
threads=$((processors / trainers))
83+
if [ $threads -eq 0 ]; then
84+
threads=1
85+
fi
86+
if [ "ON" == "ON" ]; then
87+
if [ -z "$OMP_NUM_THREADS" ]; then
88+
export OMP_NUM_THREADS=$threads
89+
fi
90+
if [ -z "$MKL_NUM_THREADS" ]; then
91+
export MKL_NUM_THREADS=$threads
92+
fi
93+
else
94+
if [ -z "$OPENBLAS_NUM_THREADS" ]; then
95+
export OPENBLAS_NUM_THREADS=$threads
96+
fi
97+
if [ $threads -gt 1 ] && [ -z "$OPENBLAS_MAIN_FREE" ]; then
98+
export OPENBLAS_MAIN_FREE=1
99+
fi
100+
fi
101+
102+
}
103+
104+
PADDLE_CONF_HOME="$HOME/.config/paddle"
105+
mkdir -p ${PADDLE_CONF_HOME}
106+
107+
if [ -z "${PADDLE_NO_STAT+x}" ]; then
108+
SERVER_VER=`curl -m 5 -X POST --data content="{ \"version\": \"\" }"\
109+
-b ${PADDLE_CONF_HOME}/paddle.cookie \
110+
-c ${PADDLE_CONF_HOME}/paddle.cookie \
111+
http://api.paddlepaddle.org/version 2>/dev/null`
112+
if [ $? -eq 0 ] && [ "$(ver2num )" -lt $(ver2num $SERVER_VER) ]; then
113+
echo "Paddle release a new version ${SERVER_VER}, you can get the install package in http://www.paddlepaddle.org"
114+
fi
115+
fi
116+
117+
PADDLE_BIN_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
118+
119+
if [ ! -z "${DEBUGGER}" ]; then
120+
echo "Using debug command ${DEBUGGER}"
121+
fi
122+
123+
CUDNN_LIB_PATH=""
124+
125+
if [ ! -z "${CUDNN_LIB_PATH}" ]; then
126+
export LD_LIBRARY_PATH=${CUDNN_LIB_PATH}:${LD_LIBRARY_PATH}
127+
fi
128+
129+
export PYTHONPATH=${PWD}:${PYTHONPATH}
130+
131+
132+
# Check python lib installed or not.
133+
pip --help > /dev/null
134+
if [ $? -ne 0 ]; then
135+
echo "pip should be installed to run paddle."
136+
exit 1
137+
fi
138+
139+
if [ "OFF" == "ON" ]; then
140+
PADDLE_NAME="paddlepaddle-gpu"
141+
else
142+
PADDLE_NAME="paddlepaddle"
143+
fi
144+
145+
INSTALLED_VERSION=`pip freeze 2>/dev/null | grep "^${PADDLE_NAME}==" | sed 's/.*==//g'`
146+
147+
if [ -z "${INSTALLED_VERSION}" ]; then
148+
INSTALLED_VERSION="0.0.0" # not installed
149+
fi
150+
cat <<EOF | python -
151+
from distutils.version import LooseVersion
152+
import sys
153+
if LooseVersion("${INSTALLED_VERSION}") < LooseVersion(""):
154+
sys.exit(1)
155+
else:
156+
sys.exit(0)
157+
EOF
158+
159+
cpu_config
160+
# echo $KMP_AFFINITY $OMP_DYNAMIC
161+
162+
case "$1" in
163+
"version")
164+
version
165+
;;
166+
*)
167+
version
168+
;;
169+
esac

0 commit comments

Comments
 (0)