Repository navigation
Expand file tree
/
Copy pathConfig.py
More file actions
71 lines (47 loc) · 1.36 KB
/
Copy pathConfig.py
File metadata and controls
71 lines (47 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys, multiprocessing, logging
from enum import Enum
from os import environ
class ConfigError(Exception):
pass
class Backend(Enum):
cuda = 0
hip = 1
cpu = 2
intel = 3
backend_from_env = (environ.get('PUZZLELIB_BACKEND') or '').lower()
if backend_from_env == '': # if not set, attempt CUDA
backend = Backend.cuda
elif backend_from_env == 'cuda':
backend = Backend.cuda
elif backend_from_env == 'hip':
backend = Backend.hip
elif backend_from_env == 'cpu':
backend = Backend.cpu
elif backend_from_env == 'intel':
backend = Backend.intel
else:
raise ConfigError('Unknown PuzzleLib backend "%s".' % environ.get('PUZZLELIB_BACKEND'))
deviceIdx = 0
allowMultiContext = False
systemLog = False
logger = None
libname = "PuzzleLib"
globalEvalMode = False
disableDtypeShapeChecks = False
disableModuleCompatChecks = False
verifyData = False
showWarnings = True
def isCPUBased(bnd):
return bnd in {Backend.cpu, Backend.intel}
def shouldInit():
return multiprocessing.current_process().name == "MainProcess" or allowMultiContext
def getLogger():
global logger
if logger is not None:
return logger
logger = logging.getLogger(libname)
logger.setLevel(logging.DEBUG if systemLog else logging.INFO)
handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))
logger.addHandler(handler)
return logger