__init__.py 2.1 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
T
typhoonzero 已提交
21
from distribute_transpiler_simple import SimpleDistributeTranspiler
Y
Update  
Yang Yu 已提交
22
import clip
23
from memory_optimization_transpiler import memory_optimize
24 25 26

Tensor = LoDTensor
__all__ = framework.__all__ + executor.__all__ + [
27 28 29 30 31 32 33 34 35 36 37 38 39 40
    'io',
    'initializer',
    'layers',
    'nets',
    'optimizer',
    'backward',
    'regularizer',
    'LoDTensor',
    'CPUPlace',
    'CUDAPlace',
    'Tensor',
    'ParamAttr'
    'DataFeeder',
    'clip',
T
typhoonzero 已提交
41
    'SimpleDistributeTranspiler',
42 43
    'DistributeTranspiler',
    'memory_optimize',
44 45 46
]


Y
Yang Yu 已提交
47
def __bootstrap__():
48 49
    """
    Enable reading gflags from environment variables.
Y
Yu Yang 已提交
50

51 52 53 54 55
    Returns:
        None
    """
    import sys
    import core
Y
Yang Yu 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    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 已提交
74
    read_env_flags = ['use_pinned_memory', 'check_nan_inf']
75
    if core.is_compile_gpu():
D
dzhwinter 已提交
76
        read_env_flags += ['fraction_of_gpu_memory_to_use', 'op_sync']
Q
QI JUN 已提交
77 78
    core.init_gflags([sys.argv[0]] +
                     ["--tryfromenv=" + ",".join(read_env_flags)])
Y
Yang Yu 已提交
79
    core.init_glog(sys.argv[0])
80
    core.init_devices()
D
dzhwinter 已提交
81

82

Y
Yang Yu 已提交
83
__bootstrap__()