Caffe2 - Python API
A deep learning, cross platform ML framework
env.py
1 import os
2 import platform
3 import struct
4 import sys
5 from itertools import chain
6 
7 
8 IS_WINDOWS = (platform.system() == 'Windows')
9 IS_DARWIN = (platform.system() == 'Darwin')
10 IS_LINUX = (platform.system() == 'Linux')
11 IS_PPC = (platform.machine() == 'ppc64le')
12 IS_ARM = (platform.machine() == 'aarch64')
13 
14 IS_CONDA = 'conda' in sys.version or 'Continuum' in sys.version or any([x.startswith('CONDA') for x in os.environ])
15 CONDA_DIR = os.path.join(os.path.dirname(sys.executable), '..')
16 
17 IS_64BIT = (struct.calcsize("P") == 8)
18 
19 
20 def check_env_flag(name, default=''):
21  return os.getenv(name, default).upper() in ['ON', '1', 'YES', 'TRUE', 'Y']
22 
23 
24 def check_negative_env_flag(name, default=''):
25  return os.getenv(name, default).upper() in ['OFF', '0', 'NO', 'FALSE', 'N']
26 
27 
28 def gather_paths(env_vars):
29  return list(chain(*(os.getenv(v, '').split(os.pathsep) for v in env_vars)))
30 
31 
32 def lib_paths_from_base(base_path):
33  return [os.path.join(base_path, s) for s in ['lib/x64', 'lib', 'lib64']]
34 
35 
36 def hotpatch_var(var, prefix='USE_'):
37  if check_env_flag('NO_' + var):
38  os.environ[prefix + var] = '0'
39  elif check_negative_env_flag('NO_' + var):
40  os.environ[prefix + var] = '1'
41  elif check_env_flag('WITH_' + var):
42  os.environ[prefix + var] = '1'
43  elif check_negative_env_flag('WITH_' + var):
44  os.environ[prefix + var] = '0'
45 
46 
47 def hotpatch_build_env_vars():
48  # Before we run the setup_helpers, let's look for NO_* and WITH_*
49  # variables and hotpatch environment with the USE_* equivalent
50  use_env_vars = ['CUDA', 'CUDNN', 'FBGEMM', 'MIOPEN', 'MKLDNN', 'NNPACK', 'DISTRIBUTED',
51  'OPENCV', 'TENSORRT', 'QNNPACK', 'FFMPEG', 'SYSTEM_NCCL',
52  'GLOO_IBVERBS']
53  list(map(hotpatch_var, use_env_vars))
54 
55  # Also hotpatch a few with BUILD_* equivalent
56  build_env_vars = ['BINARY', 'TEST', 'CAFFE2_OPS']
57  [hotpatch_var(v, 'BUILD_') for v in build_env_vars]
58 
59 hotpatch_build_env_vars()
60 
61 DEBUG = check_env_flag('DEBUG')
62 REL_WITH_DEB_INFO = check_env_flag('REL_WITH_DEB_INFO')
63 USE_MKLDNN = check_env_flag('USE_MKLDNN', 'OFF' if IS_PPC or IS_ARM else 'ON')
Module caffe2.python.layers.split.