-
Notifications
You must be signed in to change notification settings - Fork 29
[Feature Enhancement] test_compiler support dcu and add the check of GPU utilization before test. #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[Feature Enhancement] test_compiler support dcu and add the check of GPU utilization before test. #322
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,14 @@ | |
| import sys | ||
| import json | ||
| import time | ||
| import subprocess | ||
| import shutil | ||
| import numpy as np | ||
| from dataclasses import dataclass | ||
| from contextlib import contextmanager | ||
|
|
||
| from graph_net import path_utils | ||
|
|
||
|
|
||
| @dataclass | ||
| class DurationBox: | ||
|
|
@@ -23,6 +27,103 @@ def naive_timer(duration_box, synchronizer_func): | |
| duration_box.value = (end - start) * 1000 # Store in milliseconds | ||
|
|
||
|
|
||
| def is_gpu_device(device): | ||
| return "cuda" in device or "dcu" in device | ||
|
|
||
|
|
||
| def get_device_utilization(device_id, device_count, synchronizer_func): | ||
| current_pid = os.getpid() | ||
|
|
||
| if shutil.which("nvidia-smi"): | ||
| try: | ||
| cuda_devices_str = os.getenv("CUDA_VISIBLE_DEVICES", "") | ||
| if cuda_devices_str != "": | ||
| cuda_devices = list(map(int, cuda_devices_str.split(","))) | ||
| else: | ||
| cuda_devices = list(range(device_count)) | ||
| selected_gpu_id = cuda_devices[device_id] | ||
|
|
||
| print( | ||
| f"Check the status of GPU {selected_gpu_id} for 5 times.", | ||
| file=sys.stderr, | ||
| flush=True, | ||
| ) | ||
| selected_gpu_uuid, max_gpu_util, max_mem_util = None, 0.0, 0.0 | ||
| for i in range(5): | ||
| synchronizer_func() | ||
| time.sleep(1) | ||
|
|
||
| output = ( | ||
| subprocess.check_output( | ||
| [ | ||
| "nvidia-smi", | ||
| f"--query-gpu=index,gpu_uuid,utilization.gpu,memory.used,memory.total", | ||
| "--format=csv,noheader,nounits", | ||
| ] | ||
| ) | ||
| .decode() | ||
| .strip() | ||
| ) | ||
| for line in output.split("\n"): | ||
| if line.strip(): | ||
| ( | ||
| gpu_id, | ||
| selected_gpu_uuid, | ||
| gpu_util, | ||
| used_mem, | ||
| mem_total, | ||
| ) = line.split(", ") | ||
| if int(gpu_id) == selected_gpu_id: | ||
| break | ||
|
|
||
| gpu_util = float(gpu_util) | ||
| mem_util = float(used_mem) * 100 / float(mem_total) | ||
| print( | ||
| f"- gpu_id: {selected_gpu_id}, gpu_uuid: {selected_gpu_uuid}, gpu_util: {gpu_util:.2f}%, used_mem: {used_mem}, mem_total: {mem_total}", | ||
| file=sys.stderr, | ||
| flush=True, | ||
| ) | ||
|
|
||
| max_gpu_util = gpu_util if gpu_util > max_gpu_util else max_gpu_util | ||
| max_mem_util = mem_util if mem_util > max_mem_util else max_mem_util | ||
|
|
||
| other_tasks = [] | ||
| output = ( | ||
| subprocess.check_output( | ||
| [ | ||
| "nvidia-smi", | ||
| f"--query-compute-apps=gpu_uuid,pid,used_memory", | ||
| "--format=csv,noheader,nounits", | ||
| ] | ||
| ) | ||
| .decode() | ||
| .strip() | ||
| ) | ||
| for line in output.split("\n"): | ||
| if line.strip(): | ||
| gpu_uuid, pid, used_memory = line.split(", ") | ||
| if gpu_uuid == selected_gpu_uuid and int(pid) != current_pid: | ||
| other_tasks.append(line) | ||
| # Note: in docker container, the current_pid maybe different from that captured by nvidia-smi. | ||
| print( | ||
| f"Note: There are {len(other_tasks)} tasks running on GPU {selected_gpu_id} (current_pid:{current_pid}).", | ||
| file=sys.stderr, | ||
| flush=True, | ||
| ) | ||
| for task in other_tasks: | ||
| gpu_uuid, pid, used_memory = task.split(", ") | ||
| print( | ||
| f"- gpu_uuid:{gpu_uuid}, pid:{pid}, used_memory:{used_memory}", | ||
| file=sys.stderr, | ||
| flush=True, | ||
| ) | ||
| return max_gpu_util, max_mem_util | ||
| except subprocess.CalledProcessError: | ||
| pass | ||
|
|
||
| return None, None | ||
|
|
||
|
|
||
| def get_timing_stats(elapsed_times): | ||
| stats = { | ||
| "mean": float(f"{np.mean(elapsed_times):.6g}"), | ||
|
|
@@ -75,24 +176,33 @@ def print_basic_config(args, hardware_name, compile_framework_version): | |
| ) | ||
|
|
||
|
|
||
| def print_running_status(args, eager_success, compiled_success): | ||
| def print_running_status(args, eager_success, compiled_success=None): | ||
| def convert_to_str(b): | ||
| return "success" if b else "failed" | ||
|
|
||
| print_with_log_prompt( | ||
| "[Result][status]", | ||
| f"eager:{convert_to_str(eager_success)} compiled:{convert_to_str(compiled_success)}", | ||
| args.log_prompt, | ||
| ) | ||
| if compiled_success is not None: | ||
| print_with_log_prompt( | ||
| "[Result][status]", | ||
| f"eager:{convert_to_str(eager_success)} compiled:{convert_to_str(compiled_success)}", | ||
| args.log_prompt, | ||
| ) | ||
| else: | ||
| print_with_log_prompt( | ||
| "[Result][status]", | ||
| f"eager:{convert_to_str(eager_success)}", | ||
| args.log_prompt, | ||
| ) | ||
|
|
||
|
|
||
| def print_times_and_speedup(args, eager_stats, compiled_stats): | ||
| print_with_log_prompt( | ||
| "[Performance][eager]:", json.dumps(eager_stats), args.log_prompt | ||
| ) | ||
| print_with_log_prompt( | ||
| "[Performance][compiled]:", json.dumps(compiled_stats), args.log_prompt | ||
| ) | ||
| if not eager_stats: | ||
| print_with_log_prompt( | ||
| "[Performance][eager]:", json.dumps(eager_stats), args.log_prompt | ||
| ) | ||
| if not compiled_stats: | ||
| print_with_log_prompt( | ||
| "[Performance][compiled]:", json.dumps(compiled_stats), args.log_prompt | ||
| ) | ||
|
|
||
| e2e_speedup = 0 | ||
| gpu_speedup = 0 | ||
|
|
@@ -103,7 +213,7 @@ def print_times_and_speedup(args, eager_stats, compiled_stats): | |
| if eager_e2e_time_ms > 0 and compiled_e2e_time_ms > 0: | ||
| e2e_speedup = eager_e2e_time_ms / compiled_e2e_time_ms | ||
|
|
||
| if "cuda" in args.device: | ||
| if is_gpu_device(args.device): | ||
| eager_gpu_time_ms = eager_stats.get("gpu", {}).get("mean", 0) | ||
| compiled_gpu_time_ms = compiled_stats.get("gpu", {}).get("mean", 0) | ||
|
|
||
|
|
@@ -113,7 +223,7 @@ def print_times_and_speedup(args, eager_stats, compiled_stats): | |
| if e2e_speedup > 0: | ||
| print_with_log_prompt("[Speedup][e2e]:", f"{e2e_speedup:.5f}", args.log_prompt) | ||
|
|
||
| if "cuda" in args.device and gpu_speedup > 0: | ||
| if is_gpu_device(args.device) and gpu_speedup > 0: | ||
| print_with_log_prompt("[Speedup][gpu]:", f"{gpu_speedup:.5f}", args.log_prompt) | ||
|
|
||
|
|
||
|
|
@@ -224,3 +334,18 @@ def check_allclose( | |
| compiled_out=compiled_out, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
| def get_allow_samples(allow_list): | ||
| if allow_list is None: | ||
| return None | ||
|
|
||
| assert os.path.isfile(allow_list), f"{allow_list} is not a regular file." | ||
| graphnet_root = path_utils.get_graphnet_root() | ||
| print(f"graphnet_root: {graphnet_root}", file=sys.stderr, flush=True) | ||
| test_samples = [] | ||
| with open(allow_list, "r") as f: | ||
| for line in f.readlines(): | ||
| test_samples.append(os.path.join(graphnet_root, line.strip())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个函数怎么总是返回None? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修复 |
||
|
|
||
| return test_samples | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些代码缩进层级太深,一般都意味着可维护性问题。下次可以多用列表解析(list comprehension)