harmonize-python 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,148 @@
1
+
2
+ #ifndef HARMONIZE_UTIL
3
+ #define HARMONIZE_UTIL
4
+
5
+
6
+
7
+
8
+ namespace util {
9
+
10
+
11
+ /*
12
+ // Gives a count of how many threads in the current warp with a lower warp-local id are currently
13
+ // active. This is useful for finding an index for a set of operations performed once by an
14
+ // unpredictable number of threads within a warp.
15
+ */
16
+ static __device__ unsigned int warp_inc_scan(){
17
+
18
+ unsigned int active = __activemask();
19
+ unsigned int keep = (1 << threadIdx.x) - 1;
20
+ unsigned int scan = __popc(active & keep);
21
+ return scan;
22
+
23
+ }
24
+
25
+
26
+ /*
27
+ // This function returns the number of currently active threads in a warp
28
+ */
29
+ static __device__ unsigned int active_count(){
30
+ return __popc(__activemask());
31
+ }
32
+
33
+
34
+ /*
35
+ // This returns true only if the current thread is the active thread with the lowest warp-local id.
36
+ // This is valuable for electing a "leader" to perform single-threaded work for a warp.
37
+ // (__ffs (find first set) indexes bits from one, hence the -1 )
38
+ */
39
+ static __device__ bool current_leader(){
40
+ return ((__ffs(__activemask())-1) == threadIdx.x);
41
+ }
42
+
43
+
44
+ static __device__ unsigned int pop_count(unsigned int value) {
45
+ return __popc(value);
46
+ }
47
+ static __device__ unsigned long long int pop_count(unsigned long long int value) {
48
+ return __popcll(value);
49
+ }
50
+
51
+
52
+ static __device__ unsigned int leading_zeros(unsigned int value) {
53
+ return __clz(value);
54
+ }
55
+ static __device__ unsigned long long int leading_zeros(unsigned long long int value) {
56
+ return __clzll(value);
57
+ }
58
+
59
+
60
+ /*
61
+ // A simple pseudo-random number generator. This algorithm should never be used for cryptography,
62
+ // it is simply used to generate numbers random enough to reduce collisions for atomic
63
+ // instructions performed to manage the runtime state.
64
+ */
65
+ #if 1
66
+ static __host__ __device__ unsigned int random_uint(unsigned int &state){
67
+
68
+ state = (0x10DCDu * state + 1u);
69
+ return state;
70
+
71
+ }
72
+ static __host__ __device__ unsigned long long int random_uint(unsigned long long int &state){
73
+
74
+ state = ( 2971215073 * state + 12345u);
75
+ return state;
76
+
77
+ }
78
+ #else
79
+ static __device__ unsigned int random_uint(unsigned int& rand_state){
80
+
81
+ rand_state = (1103515245u * rand_state + 12345u);// % 0x80000000;
82
+ return rand_state;
83
+
84
+ }
85
+ #endif
86
+
87
+
88
+ struct Stopwatch {
89
+
90
+ adapt::GPUrtEvent_t beg;
91
+ adapt::GPUrtEvent_t end;
92
+ float duration;
93
+
94
+ Stopwatch() {
95
+
96
+ adapt::GPUrtError_t beg_stat = adapt::GPUrtEventCreate( &beg );
97
+ adapt::GPUrtError_t end_stat = adapt::GPUrtEventCreate( &end );
98
+
99
+ if(beg_stat != adapt::GPUrtSuccess){
100
+ const char* err_str = adapt::GPUrtGetErrorString(beg_stat);
101
+ printf("Failed to create Stopwatch start event. ERROR: \"%s\"\n",err_str);
102
+ }
103
+
104
+ if(end_stat != adapt::GPUrtSuccess){
105
+ const char* err_str = adapt::GPUrtGetErrorString(end_stat);
106
+ printf("Failed to create Stopwatch end event. ERROR: \"%s\"\n" ,err_str);
107
+ }
108
+
109
+ if( (beg_stat != adapt::GPUrtSuccess) || (end_stat != adapt::GPUrtSuccess) ) {
110
+ printf("Failed to create one or more Stopwatch events\n");
111
+ std::exit(1);
112
+ }
113
+ }
114
+
115
+
116
+ bool start() {
117
+ return ( adapt::GPUrtEventRecord( beg, nullptr ) == adapt::GPUrtSuccess);
118
+ }
119
+
120
+ bool stop() {
121
+ if ( adapt::GPUrtEventRecord( end, nullptr ) != adapt::GPUrtSuccess ){
122
+ return false;
123
+ }
124
+ auto _x = adapt::GPUrtEventSynchronize( end );
125
+ auto _y = adapt::GPUrtEventElapsedTime( &duration, beg, end );
126
+ return true;
127
+ }
128
+
129
+ float ms_duration(){
130
+ return duration;
131
+ }
132
+
133
+ };
134
+
135
+
136
+ }
137
+
138
+
139
+ #include "host.h"
140
+
141
+ #include "mem.h"
142
+
143
+ #include "iter.h"
144
+
145
+ #include "cli.h"
146
+
147
+
148
+ #endif
@@ -0,0 +1,487 @@
1
+ """Environment report (`python -m harmonize info`) and readiness checks
2
+ (`python -m harmonize check`) for Harmonize's GPU platforms.
3
+
4
+ Both commands share `collect_info`, which never raises: anything that cannot
5
+ be determined is recorded as None or as an error string.
6
+ """
7
+
8
+ import os
9
+ import platform as host_platform
10
+ import re
11
+ import shutil
12
+ import subprocess
13
+ import sys
14
+ import tempfile
15
+ from importlib import metadata
16
+
17
+ from harmonize import config
18
+
19
+
20
+ NUMBA_HIP_REPOSITORY = "https://github.com/ROCm/numba-hip.git"
21
+
22
+ # CUDA major versions with a `harmonize[cudaNN]` install extra (pyproject.toml)
23
+ CUDA_EXTRAS = (12, 13)
24
+
25
+
26
+ # ======================================================================================
27
+ # Information gathering
28
+ # ======================================================================================
29
+
30
+
31
+ def package_version(name):
32
+ try:
33
+ return metadata.version(name)
34
+ except metadata.PackageNotFoundError:
35
+ return None
36
+
37
+
38
+ def run_text(command):
39
+ """Return a command's stdout, or None if it cannot be run."""
40
+ try:
41
+ result = subprocess.run(
42
+ command, capture_output=True, text=True, timeout=60, check=False
43
+ )
44
+ except (OSError, subprocess.SubprocessError):
45
+ return None
46
+ if result.returncode != 0:
47
+ return None
48
+ return result.stdout
49
+
50
+
51
+ def parse_version(text, pattern):
52
+ """Extract a (major, minor) tuple using a regex with two groups."""
53
+ if text is None:
54
+ return None
55
+ match = re.search(pattern, text)
56
+ if match is None:
57
+ return None
58
+ return int(match.group(1)), int(match.group(2))
59
+
60
+
61
+ def format_version(version):
62
+ if version is None:
63
+ return "unknown"
64
+ else:
65
+ return ".".join(str(part) for part in version)
66
+
67
+
68
+ def selected_platform():
69
+ if config.CUDA_AVAILABLE:
70
+ return "cuda"
71
+ if config.ROCM_AVAILABLE:
72
+ return "rocm"
73
+ return None
74
+
75
+
76
+ def detect_rocm_version(rocm_path):
77
+ """Best-effort ROCm version from hipconfig or the install's version file."""
78
+ version = parse_version(
79
+ run_text([shutil.which("hipconfig") or "hipconfig", "--version"]),
80
+ r"(\d+)\.(\d+)",
81
+ )
82
+ if version is not None:
83
+ return version
84
+ if rocm_path is not None:
85
+ try:
86
+ with open(os.path.join(rocm_path, ".info", "version")) as file:
87
+ return parse_version(file.read(), r"(\d+)\.(\d+)")
88
+ except OSError:
89
+ pass
90
+ return None
91
+
92
+
93
+ def detect_cuda_version(nvcc):
94
+ """Best-effort CUDA version"""
95
+ return parse_version(
96
+ run_text([nvcc, "--version"]), r"release (\d+)\.(\d+)"
97
+ )
98
+
99
+
100
+ def collect_cuda_info():
101
+ info = {
102
+ "cuda_path": config.CUDA_PATH,
103
+ "nvcc": None,
104
+ "nvcc_version": None,
105
+ "nvcc_archs": [],
106
+ "driver_version": None,
107
+ "runtime_version": None,
108
+ "devices": [],
109
+ "device_error": None,
110
+ }
111
+
112
+ # Toolkit compiler used to build Harmonize's runtime
113
+ nvcc = config.nvcc_path()
114
+ info["nvcc"] = shutil.which(nvcc)
115
+ if info["nvcc"] is not None:
116
+ info["nvcc_version"] = detect_cuda_version(info["nvcc"])
117
+ archs = run_text([info["nvcc"], "--list-gpu-code"]) or ""
118
+ info["nvcc_archs"] = re.findall(r"sm_(\d+)", archs)
119
+
120
+ # Driver and devices, through the selected Numba CUDA backend
121
+ if config.CUDA_AVAILABLE:
122
+ cuda = config.cuda
123
+ try:
124
+ from numba.cuda.cudadrv import driver
125
+
126
+ info["driver_version"] = tuple(driver.driver.get_version())
127
+ except Exception as error:
128
+ info["device_error"] = str(error)
129
+ try:
130
+ info["runtime_version"] = tuple(cuda.runtime.get_version())
131
+ except Exception:
132
+ pass
133
+ try:
134
+ if cuda.is_available():
135
+ for device in cuda.list_devices():
136
+ name = device.name
137
+ if isinstance(name, bytes):
138
+ name = name.decode()
139
+ major, minor = device.compute_capability
140
+ info["devices"].append(
141
+ {"id": device.id, "name": name, "arch": f"{major}{minor}"}
142
+ )
143
+ elif info["device_error"] is None:
144
+ info["device_error"] = "numba.cuda.is_available() returned False"
145
+ except Exception as error:
146
+ info["device_error"] = str(error)
147
+
148
+ if info["nvcc"] is not None and info["devices"]:
149
+ info["ptx_probe"] = probe_ptx_assembly(info["nvcc"], info["devices"][0]["arch"])
150
+ else:
151
+ info["ptx_probe"] = None
152
+ return info
153
+
154
+
155
+ def probe_ptx_assembly(nvcc, arch):
156
+ """Compile a trivial device function to PTX with Numba's NVVM, then assemble it
157
+ with nvcc as Harmonize does. NVVM comes from Numba's CUDA packages, not from
158
+ nvcc's toolkit, and libNVVM's own version number does not identify the PTX ISA
159
+ it emits, so trying the round trip is the only reliable check."""
160
+ probe = {"ptx_version": None, "ok": None, "error": None}
161
+ try:
162
+ from numba import cuda, float64
163
+
164
+ ptx, _ = cuda.compile_ptx(
165
+ lambda a: None,
166
+ (float64[:],),
167
+ device=True,
168
+ cc=(int(arch[:-1]), int(arch[-1])),
169
+ )
170
+ except Exception as error:
171
+ probe["error"] = f"Numba could not generate PTX: {error}"
172
+ return probe
173
+ match = re.search(r"^\.version\s+(\S+)", ptx, re.MULTILINE)
174
+ probe["ptx_version"] = match.group(1) if match else None
175
+ with tempfile.TemporaryDirectory() as tmp:
176
+ source = os.path.join(tmp, "probe.ptx")
177
+ with open(source, "w") as file:
178
+ file.write(ptx)
179
+ try:
180
+ result = subprocess.run(
181
+ [nvcc, "-dc", f"-arch=sm_{arch}", source, "-o", os.path.join(tmp, "probe.o")],
182
+ capture_output=True,
183
+ text=True,
184
+ timeout=120,
185
+ )
186
+ except (OSError, subprocess.SubprocessError) as error:
187
+ probe["error"] = str(error)
188
+ return probe
189
+ probe["ok"] = result.returncode == 0
190
+ if not probe["ok"]:
191
+ lines = (result.stderr or result.stdout).strip().splitlines()
192
+ probe["error"] = lines[0] if lines else f"nvcc exited with {result.returncode}"
193
+ return probe
194
+
195
+
196
+
197
+
198
+ def collect_rocm_info():
199
+ hipcc = shutil.which(config.hipcc_path())
200
+ rocm_path = config.ROCM_PATH
201
+ if rocm_path is None and hipcc is not None:
202
+ rocm_path = os.path.dirname(os.path.dirname(os.path.realpath(hipcc)))
203
+ return {
204
+ "rocm_path": config.ROCM_PATH,
205
+ "hipcc": hipcc,
206
+ "rocm_version": detect_rocm_version(rocm_path),
207
+ "tools_complete": config.ROCM_PATH is not None
208
+ and config.check_rocm_path(quiet=True),
209
+ }
210
+
211
+
212
+ def collect_info():
213
+ return {
214
+ "harmonize": {
215
+ "version": package_version("harmonize-python"),
216
+ "location": config.HARMONIZE_ROOT_DIR,
217
+ },
218
+ "host": {
219
+ "python": sys.version.split()[0],
220
+ "system": f"{host_platform.system()} {host_platform.machine()}",
221
+ },
222
+ "packages": {
223
+ name: package_version(name)
224
+ for name in (
225
+ "numba",
226
+ "numba-cuda",
227
+ "numba-hip",
228
+ "cuda-bindings",
229
+ "nvidia-nvvm",
230
+ "numpy",
231
+ )
232
+ },
233
+ "platform": {
234
+ "requested": config.PLATFORM_REQUEST,
235
+ "selected": selected_platform(),
236
+ "import_errors": dict(config.PLATFORM_IMPORT_ERRORS),
237
+ },
238
+ "cuda": collect_cuda_info(),
239
+ "rocm": collect_rocm_info(),
240
+ }
241
+
242
+
243
+ # ======================================================================================
244
+ # Readiness checks
245
+ # ======================================================================================
246
+
247
+
248
+ class Finding:
249
+ def __init__(self, level, message, hint=None):
250
+ self.level = level # "error" or "warning"
251
+ self.message = message
252
+ self.hint = hint
253
+
254
+
255
+ def numba_hip_install_hint(rocm_version):
256
+ if rocm_version is None:
257
+ key = "rocm-<major>-<minor>-<patch>"
258
+ else:
259
+ key = f"rocm-{rocm_version[0]}-{rocm_version[1]}-<patch>"
260
+ return (
261
+ "Install AMD's Numba HIP backend for your ROCm release, e.g.\n"
262
+ f' pip install --extra-index-url https://test.pypi.org/simple "numba-hip[{key}] @ git+{NUMBA_HIP_REPOSITORY}"'
263
+ )
264
+
265
+
266
+ def check_cuda(info, findings):
267
+ cuda = info["cuda"]
268
+
269
+ if cuda["device_error"] is not None or not cuda["devices"]:
270
+ findings.append(
271
+ Finding(
272
+ "error",
273
+ f"No usable CUDA device ({cuda['device_error'] or 'no devices found'}).",
274
+ "Check the NVIDIA driver with `nvidia-smi`, and that this process can see a GPU "
275
+ "(e.g. CUDA_VISIBLE_DEVICES, or a GPU allocation on a cluster).",
276
+ )
277
+ )
278
+
279
+ if cuda["nvcc"] is None:
280
+ findings.append(
281
+ Finding(
282
+ "error",
283
+ f"nvcc was not found (looked for '{config.nvcc_path()}').",
284
+ "Put a CUDA toolkit's bin directory on PATH (e.g. `module load cuda`, or "
285
+ "`conda install -c nvidia cuda-nvcc`), or call harmonize.config.set_cuda_path().",
286
+ )
287
+ )
288
+ return
289
+
290
+ toolkit, driver = cuda["nvcc_version"], cuda["driver_version"]
291
+ if toolkit is not None and driver is not None:
292
+ if toolkit[0] > driver[0]:
293
+ findings.append(
294
+ Finding(
295
+ "error",
296
+ f"nvcc is CUDA {format_version(toolkit)}, but the driver only supports "
297
+ f"CUDA {format_version(driver)}.",
298
+ "Use a toolkit no newer than the driver, or update the driver.",
299
+ )
300
+ )
301
+ elif toolkit > driver:
302
+ findings.append(
303
+ Finding(
304
+ "warning",
305
+ f"nvcc (CUDA {format_version(toolkit)}) is newer than the driver "
306
+ f"(CUDA {format_version(driver)}); this relies on minor-version compatibility.",
307
+ )
308
+ )
309
+
310
+ bindings = info["packages"]["cuda-bindings"]
311
+ if toolkit is not None and bindings is not None:
312
+ if int(bindings.split(".")[0]) != toolkit[0]:
313
+ if toolkit[0] in CUDA_EXTRAS:
314
+ hint = f"Install the matching extra: `pip install harmonize[cuda{toolkit[0]}]`."
315
+ else:
316
+ hint = (
317
+ "Use a CUDA toolkit whose major version matches cuda-bindings "
318
+ f"(supported extras: {', '.join(f'cuda{v}' for v in CUDA_EXTRAS)})."
319
+ )
320
+ findings.append(
321
+ Finding(
322
+ "warning",
323
+ f"cuda-bindings {bindings} (used by numba-cuda) and nvcc "
324
+ f"(CUDA {format_version(toolkit)}) are from different major CUDA versions.",
325
+ hint,
326
+ )
327
+ )
328
+
329
+ probe = cuda.get("ptx_probe")
330
+ if probe is not None and not probe["ok"]:
331
+ if probe["ptx_version"] is not None:
332
+ nvvm = info["packages"].get("nvidia-nvvm")
333
+ source = f" (pip package nvidia-nvvm {nvvm})" if nvvm else ""
334
+ message = (
335
+ f"Numba's NVVM{source} emits PTX ISA {probe['ptx_version']}, which nvcc "
336
+ f"(CUDA {format_version(toolkit)}) cannot assemble: {probe['error']}"
337
+ )
338
+ hint = (
339
+ "Match Numba's NVVM to nvcc, e.g. "
340
+ f"`pip install \"cuda-toolkit[nvvm,nvjitlink]=={format_version(toolkit)}.*\"`, "
341
+ "or use an nvcc at least as new as NVVM (and no newer than the driver)."
342
+ )
343
+ else:
344
+ message = f"Could not test PTX assembly with nvcc: {probe['error']}"
345
+ hint = None
346
+ findings.append(Finding("error", message, hint))
347
+
348
+ supported = set(cuda["nvcc_archs"])
349
+ for device in cuda["devices"]:
350
+ if supported and device["arch"] not in supported:
351
+ findings.append(
352
+ Finding(
353
+ "error",
354
+ f"nvcc (CUDA {format_version(toolkit)}) cannot compile for device "
355
+ f"{device['id']} ({device['name']}, sm_{device['arch']}).",
356
+ "Use a newer CUDA toolkit that supports this GPU architecture.",
357
+ )
358
+ )
359
+
360
+
361
+ def check_rocm(info, findings):
362
+ rocm = info["rocm"]
363
+ if rocm["hipcc"] is None and config.ROCM_PATH is None:
364
+ findings.append(
365
+ Finding(
366
+ "error",
367
+ "hipcc was not found.",
368
+ "Put ROCm's bin directory on PATH (e.g. `module load rocm`), or call "
369
+ "harmonize.config.set_rocm_path().",
370
+ )
371
+ )
372
+ elif not rocm["tools_complete"]:
373
+ findings.append(
374
+ Finding(
375
+ "error",
376
+ "The ROCm install is missing tools Harmonize needs "
377
+ "(hipcc, clang-offload-bundler, llvm-link, llvm-as).",
378
+ "Point harmonize.config.set_rocm_path() at a complete ROCm install.",
379
+ )
380
+ )
381
+
382
+
383
+ def run_checks(info):
384
+ findings = []
385
+ selected = info["platform"]["selected"]
386
+ requested = info["platform"]["requested"]
387
+
388
+ if selected is None:
389
+ if requested == "rocm":
390
+ hint = numba_hip_install_hint(info["rocm"]["rocm_version"])
391
+ elif requested == "cuda":
392
+ hint = "Install the CUDA backend: `pip install harmonize[cuda12]` or `harmonize[cuda13]`."
393
+ else:
394
+ hint = (
395
+ "For NVIDIA GPUs: `pip install harmonize[cuda12]` or `harmonize[cuda13]`.\n"
396
+ + numba_hip_install_hint(info["rocm"]["rocm_version"])
397
+ )
398
+ reasons = "; ".join(
399
+ f"{name}: {reason}" for name, reason in info["platform"]["import_errors"].items()
400
+ )
401
+ findings.append(
402
+ Finding(
403
+ "error",
404
+ f"No GPU platform is available (HARMONIZE_PLATFORM={requested}). {reasons}",
405
+ hint,
406
+ )
407
+ )
408
+ return findings
409
+
410
+ if selected == "cuda":
411
+ check_cuda(info, findings)
412
+ else:
413
+ check_rocm(info, findings)
414
+ return findings
415
+
416
+
417
+ # ======================================================================================
418
+ # Report formatting
419
+ # ======================================================================================
420
+
421
+
422
+ def format_info(info):
423
+ lines = []
424
+
425
+ def section(title):
426
+ lines.append("")
427
+ lines.append(title)
428
+
429
+ def item(label, value):
430
+ lines.append(f" {label:<22}{'not found' if value is None else value}")
431
+
432
+ section("Harmonize")
433
+ item("version", info["harmonize"]["version"])
434
+ item("location", os.path.realpath(info["harmonize"]["location"]))
435
+ item("python", info["host"]["python"])
436
+ item("system", info["host"]["system"])
437
+
438
+ section("Packages")
439
+ for name, version in info["packages"].items():
440
+ item(name, version)
441
+
442
+ section("Platform")
443
+ item("requested", f"{info['platform']['requested']} ({config.PLATFORM_ENV_VAR})")
444
+ item("selected", info["platform"]["selected"] or "none")
445
+ for name, reason in info["platform"]["import_errors"].items():
446
+ item(f"{name} unavailable", reason)
447
+
448
+ cuda = info["cuda"]
449
+ section("CUDA")
450
+ item("nvcc", cuda["nvcc"])
451
+ if cuda["nvcc"] is not None:
452
+ item("nvcc version", format_version(cuda["nvcc_version"]))
453
+ if info["platform"]["selected"] == "cuda":
454
+ item("driver supports", format_version(cuda["driver_version"]))
455
+ item("runtime version", format_version(cuda["runtime_version"]))
456
+ for device in cuda["devices"]:
457
+ item(f"device {device['id']}", f"{device['name']} (sm_{device['arch']})")
458
+ probe = cuda.get("ptx_probe")
459
+ if probe is not None:
460
+ status = "ok" if probe["ok"] else f"FAILED ({probe['error']})"
461
+ item("numba PTX -> nvcc", f"PTX ISA {probe['ptx_version']}: {status}")
462
+ if cuda["device_error"] is not None:
463
+ item("device error", cuda["device_error"])
464
+
465
+ rocm = info["rocm"]
466
+ section("ROCm")
467
+ item("hipcc", rocm["hipcc"])
468
+ item("ROCm version", format_version(rocm["rocm_version"]) if rocm["hipcc"] else None)
469
+ if config.ROCM_PATH is not None:
470
+ item("ROCm path", config.ROCM_PATH)
471
+
472
+ return "\n".join(lines[1:])
473
+
474
+
475
+ def format_findings(findings):
476
+ if not findings:
477
+ return "OK: Harmonize is ready to build GPU programs."
478
+ lines = []
479
+ for finding in findings:
480
+ lines.append(f"{finding.level.upper()}: {finding.message}")
481
+ if finding.hint:
482
+ for hint_line in finding.hint.splitlines():
483
+ lines.append(f" {hint_line}")
484
+ errors = sum(finding.level == "error" for finding in findings)
485
+ warnings = len(findings) - errors
486
+ lines.append(f"\n{errors} error(s), {warnings} warning(s).")
487
+ return "\n".join(lines)
harmonize/errors.py ADDED
@@ -0,0 +1,12 @@
1
+ import numba
2
+
3
+ def no_platforms(request="auto", import_errors=None):
4
+ message = "No GPU platforms (CUDA/ROCM) "
5
+ if request != "auto":
6
+ message += f"\nHARMONIZE_PLATFORM={request} was requested, but it is unavailable."
7
+ for platform, reason in (import_errors or {}).items():
8
+ message += f"\n {platform}: {reason}"
9
+ message += "\nRun `python -m harmonize check` for details."
10
+ raise numba.errors.UnsupportedError(message)
11
+
12
+
harmonize/logging.py ADDED
@@ -0,0 +1,51 @@
1
+
2
+ from harmonize import config
3
+
4
+ PINK = '\033[95m'
5
+ BLUE = '\033[94m'
6
+ CYAN = '\033[96m'
7
+ GREEN = '\033[92m'
8
+ YELLOW = '\033[93m'
9
+ RED = '\033[91m'
10
+ NORMAL = '\033[0m'
11
+ BOLD = '\033[1m'
12
+ UNDERLINE = '\033[4m'
13
+
14
+
15
+ def verbose_print(*args):
16
+ if config.VERBOSE:
17
+ if config.COLOR_LOG:
18
+ print(CYAN,"[ VERBOSE ]",NORMAL,*args,flush=True)
19
+ else:
20
+ print("[ VERBOSE ]",*args,flush=True)
21
+
22
+ def debug_print(*args):
23
+ if config.INTERNAL_DEBUG:
24
+ if config.COLOR_LOG:
25
+ print(YELLOW,"[ DEBUG ]",NORMAL,*args,flush=True)
26
+ else:
27
+ print("[ DEBUG ]",*args,flush=True)
28
+
29
+ def error_print(*args):
30
+ if config.ERROR_PRINT:
31
+ if config.COLOR_LOG:
32
+ print(RED,"[ ERROR ]",NORMAL,*args,flush=True)
33
+ else:
34
+ print("[ ERROR ]",*args,flush=True)
35
+
36
+
37
+ biggest_progress_print = 0
38
+
39
+ def progress_print(message):
40
+ if config.VERBOSE or config.INTERNAL_DEBUG:
41
+ verbose_print(message)
42
+ else:
43
+ global biggest_progress_print
44
+ length = len(message)
45
+ if length < biggest_progress_print:
46
+ message.ljust(biggest_progress_print)
47
+ elif length > biggest_progress_print:
48
+ biggest_progress_print = length
49
+
50
+ print(f"{message:<{biggest_progress_print}}\r",end="",flush=True)
51
+