__init__.py 2.0 KB
Newer Older
Y
Yang Yu 已提交
1
from __future__ import print_function
2
# import all class inside framework into fluid module
Y
Update  
Yang Yu 已提交
3 4
import framework
from framework import *
Y
Yang Yu 已提交
5 6
# import all class inside executor into fluid module
import executor
Y
Update  
Yang Yu 已提交
7 8
from executor import *

Y
Yang Yu 已提交
9
import io
Y
Update  
Yang Yu 已提交
10 11
import evaluator
import initializer
12 13 14
import layers
import nets
import optimizer
Y
Update  
Yang Yu 已提交
15
import backward
16
import regularizer
Y
Update  
Yang Yu 已提交
17
from param_attr import ParamAttr
Y
Yu Yang 已提交
18
from data_feeder import DataFeeder
Y
Update  
Yang Yu 已提交
19
from core import LoDTensor, CPUPlace, CUDAPlace
T
done  
typhoonzero 已提交
20
from distribute_transpiler import DistributeTranspiler
Y
Update  
Yang Yu 已提交
21
import clip
22
from memory_optimization_transpiler import memory_optimize
23 24 25 26

Tensor = LoDTensor
__all__ = framework.__all__ + executor.__all__ + [
    'io', 'initializer', 'layers', 'nets', 'optimizer', 'backward',
D
dzhwinter 已提交
27
    'regularizer', 'LoDTensor', 'CPUPlace', 'CUDAPlace', 'Tensor', 'ParamAttr'
28
    'DataFeeder', 'clip', 'DistributeTranspiler', 'memory_optimize'
29 30 31
]


Y
Yang Yu 已提交
32
def __bootstrap__():
33 34
    """
    Enable reading gflags from environment variables.
Y
Yu Yang 已提交
35

36 37 38 39 40
    Returns:
        None
    """
    import sys
    import core
Y
Yang Yu 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    import os

    try:
        num_threads = int(os.getenv('OMP_NUM_THREADS', '1'))
    except ValueError:
        num_threads = 1

    if num_threads > 1:
        print(
            'WARNING: OMP_NUM_THREADS set to {0}, not 1. The computation '
            'speed will not be optimized if you use data parallel. It will '
            'fail if this PaddlePaddle binary is compiled with OpenBlas since'
            ' OpenBlas does not support multi-threads.'.format(num_threads),
            file=sys.stderr)
        print('PLEASE USE OMP_NUM_THREADS WISELY.', file=sys.stderr)

    os.environ['OMP_NUM_THREADS'] = str(num_threads)

Y
Yang Yu 已提交
59
    read_env_flags = ['use_pinned_memory', 'check_nan_inf']
60
    if core.is_compile_gpu():
D
dzhwinter 已提交
61
        read_env_flags += ['fraction_of_gpu_memory_to_use', 'op_sync']
Q
QI JUN 已提交
62 63
    core.init_gflags([sys.argv[0]] +
                     ["--tryfromenv=" + ",".join(read_env_flags)])
Y
Yang Yu 已提交
64
    core.init_glog(sys.argv[0])
65
    core.init_devices()
D
dzhwinter 已提交
66

67

Y
Yang Yu 已提交
68
__bootstrap__()