Skip to content

Commit 581eddb

Browse files
Merge pull request #570 from InfiniTensor/issue/564
issue/564 - updated test info, env settings, and readme
2 parents 39ec8f0 + fe1ffc0 commit 581eddb

7 files changed

Lines changed: 527 additions & 145 deletions

File tree

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ git clone --recursive https://github.com/InfiniTensor/InfiniCore.git
5050
git submodule update --init --recursive
5151
```
5252

53+
配置`INFINI_ROOT``LD_LIBRARY_PATH` 环境变量。
54+
默认`INFINI_ROOT``$HOME/.infini`,可以使用以下命令自动配置:
55+
56+
```shell
57+
source scripts/set_env_linux.sh
58+
```
59+
5360
如果你需要在本地开发九齿算子(即需要对九齿算子库进行修改),推荐单独克隆[九齿算子库](https://github.com/InfiniTensor/ntops),并从本地安装:
5461

5562
```shell
@@ -148,10 +155,6 @@ python scripts/install.py [XMAKE_CONFIG_FLAGS]
148155
xmake build && xmake install
149156
```
150157

151-
3. 设置环境变量
152-
153-
按输出提示设置 `INFINI_ROOT``LD_LIBRARY_PATH` 环境变量。
154-
155158
#### 2. 安装 C++ 库
156159

157160
```shell

scripts/set_env_linux.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Define the content to be added
4+
content='export INFINI_ROOT="$HOME/.infini"
5+
export LD_LIBRARY_PATH="$INFINI_ROOT/lib:$LD_LIBRARY_PATH"'
6+
7+
# Check if bashrc file exists
8+
bashrc_file="$HOME/.bashrc"
9+
10+
if [ ! -f "$bashrc_file" ]; then
11+
echo "Creating $bashrc_file file"
12+
touch "$bashrc_file"
13+
fi
14+
15+
# Check if the content already exists
16+
if grep -q "export INFINI_ROOT=" "$bashrc_file"; then
17+
echo "INFINI_ROOT configuration already exists in $bashrc_file"
18+
else
19+
echo "Adding configuration to $bashrc_file"
20+
echo "$content" >> "$bashrc_file"
21+
echo "Configuration added successfully"
22+
fi
23+
24+
# Reload bashrc
25+
echo "Reloading $bashrc_file"
26+
source "$bashrc_file"
27+
28+
echo "Done! INFINI_ROOT and LD_LIBRARY_PATH have been set"

test/infinicore/framework/__init__.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,49 @@
99
profile_operation,
1010
rearrange_tensor,
1111
convert_infinicore_to_torch,
12+
get_operator_help_info,
13+
print_operator_testing_tips,
14+
)
15+
from .config import (
16+
get_args,
17+
get_hardware_args_group,
18+
get_hardware_help_text,
19+
get_supported_hardware_platforms,
20+
get_test_devices,
1221
)
13-
from .config import get_test_devices, get_args
1422
from .devices import InfiniDeviceEnum, InfiniDeviceNames, torch_device_map
1523
from .datatypes import to_torch_dtype, to_infinicore_dtype
1624
from .runner import GenericTestRunner
1725

1826
__all__ = [
19-
"TensorSpec",
27+
# Core types and classes
28+
"BaseOperatorTest",
29+
"GenericTestRunner",
30+
"InfiniDeviceEnum",
31+
"InfiniDeviceNames",
2032
"TensorInitializer",
33+
"TensorSpec",
34+
"TestCase",
2135
"TestConfig",
2236
"TestRunner",
23-
"TestCase",
24-
"BaseOperatorTest",
37+
# Core functions
2538
"compare_results",
26-
"create_test_comparator",
2739
"convert_infinicore_to_torch",
40+
"create_test_comparator",
2841
"debug",
2942
"get_args",
43+
"get_hardware_args_group",
44+
"get_hardware_help_text",
45+
"get_operator_help_info",
46+
"get_supported_hardware_platforms",
3047
"get_test_devices",
3148
"get_tolerance",
3249
"infinicore_tensor_from_torch",
50+
"print_operator_testing_tips",
3351
"profile_operation",
3452
"rearrange_tensor",
35-
"InfiniDeviceEnum",
36-
"InfiniDeviceNames",
37-
"torch_device_map",
38-
"to_torch_dtype",
53+
# Utility functions
3954
"to_infinicore_dtype",
40-
"GenericTestRunner",
55+
"to_torch_dtype",
56+
"torch_device_map",
4157
]
Lines changed: 129 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,150 @@
11
import argparse
22
from .devices import InfiniDeviceEnum
33

4+
# hardware_info.py
5+
"""
6+
Shared hardware platform information for the InfiniCore testing framework
7+
"""
8+
9+
10+
def get_supported_hardware_platforms():
11+
"""
12+
Get list of supported hardware platforms with descriptions.
13+
14+
Returns:
15+
List of tuples (flag, description)
16+
"""
17+
return [
18+
("--cpu", "Standard CPU execution"),
19+
("--nvidia", "NVIDIA GPUs with CUDA support"),
20+
("--cambricon", "Cambricon MLU accelerators (requires torch_mlu)"),
21+
("--ascend", "Huawei Ascend NPUs (requires torch_npu)"),
22+
("--iluvatar", "Iluvatar GPUs"),
23+
("--metax", "Metax GPUs"),
24+
("--moore", "Moore Threads GPUs (requires torch_musa)"),
25+
("--kunlun", "Kunlun XPUs (requires torch_xmlir)"),
26+
("--hygon", "Hygon DCUs"),
27+
]
28+
29+
30+
def get_hardware_help_text():
31+
"""
32+
Get formatted help text for hardware platforms.
33+
34+
Returns:
35+
str: Formatted help text for argument parsers
36+
"""
37+
platforms = get_supported_hardware_platforms()
38+
help_lines = ["Supported Hardware Platforms:"]
39+
40+
for flag, description in platforms:
41+
# Remove leading dashes for cleaner display
42+
name = flag.lstrip("-")
43+
help_lines.append(f" - {name.upper():<10} {description}")
44+
45+
return "\n".join(help_lines)
46+
47+
48+
def get_hardware_args_group(parser):
49+
"""
50+
Add hardware platform arguments to an argument parser.
51+
52+
Args:
53+
parser: argparse.ArgumentParser instance
54+
55+
Returns:
56+
The argument group for hardware platforms
57+
"""
58+
hardware_group = parser.add_argument_group("Hardware Platform Options")
59+
60+
for flag, description in get_supported_hardware_platforms():
61+
hardware_group.add_argument(flag, action="store_true", help=description)
62+
63+
return hardware_group
64+
465

566
def get_args():
6-
"""Parse command line arguments"""
7-
parser = argparse.ArgumentParser(description="Test Operator")
67+
"""Parse command line arguments for operator testing"""
68+
parser = argparse.ArgumentParser(
69+
description="Test InfiniCore operators across multiple hardware platforms",
70+
formatter_class=argparse.RawDescriptionHelpFormatter,
71+
epilog=f"""
72+
Examples:
73+
# Run all tests on CPU only
74+
python test_operator.py --cpu
75+
76+
# Run with benchmarking on NVIDIA GPU
77+
python test_operator.py --nvidia --bench
78+
79+
# Run with debug mode on multiple devices
80+
python test_operator.py --cpu --nvidia --debug
81+
82+
# Run performance profiling with custom iterations
83+
python test_operator.py --nvidia --bench --num_prerun 50 --num_iterations 5000
84+
85+
{get_hardware_help_text()}
86+
""",
87+
)
88+
89+
# Core testing options
890
parser.add_argument(
991
"--bench",
1092
action="store_true",
11-
help="Whether to benchmark performance",
93+
help="Enable performance benchmarking mode",
1294
)
1395
parser.add_argument(
1496
"--num_prerun",
1597
type=lambda x: max(0, int(x)),
1698
default=10,
17-
help="Set the number of pre-runs before benchmarking. Default is 10.",
99+
help="Number of warm-up runs before benchmarking (default: 10)",
18100
)
19101
parser.add_argument(
20102
"--num_iterations",
21103
type=lambda x: max(0, int(x)),
22104
default=1000,
23-
help="Set the number of iterations for benchmarking. Default is 1000.",
105+
help="Number of iterations for benchmarking (default: 1000)",
24106
)
25107
parser.add_argument(
26108
"--debug",
27109
action="store_true",
28-
help="Whether to turn on debug mode.",
110+
help="Enable debug mode for detailed tensor comparison",
29111
)
30112

31-
# Device options
32-
device_group = parser.add_argument_group("Device options")
33-
device_group.add_argument("--cpu", action="store_true", help="Run CPU test")
34-
device_group.add_argument(
35-
"--nvidia", action="store_true", help="Run NVIDIA GPU test"
36-
)
37-
device_group.add_argument(
38-
"--cambricon", action="store_true", help="Run Cambricon MLU test"
39-
)
40-
device_group.add_argument(
41-
"--ascend", action="store_true", help="Run ASCEND NPU test"
42-
)
43-
device_group.add_argument(
44-
"--iluvatar", action="store_true", help="Run Iluvatar GPU test"
45-
)
46-
device_group.add_argument("--metax", action="store_true", help="Run METAX GPU test")
47-
device_group.add_argument(
48-
"--moore", action="store_true", help="Run MTHREADS GPU test"
49-
)
50-
device_group.add_argument(
51-
"--kunlun", action="store_true", help="Run KUNLUN XPU test"
52-
)
113+
# Device options using shared hardware info
114+
hardware_group = get_hardware_args_group(parser)
53115

54116
return parser.parse_args()
55117

56118

57119
def get_test_devices(args):
58120
"""
59121
Determine which devices to test based on command line arguments
122+
123+
Returns:
124+
List[InfiniDeviceEnum]: List of devices to test
60125
"""
61126
devices_to_test = []
62127

128+
# Check each hardware platform with proper dependency validation
63129
if args.cpu:
64130
devices_to_test.append(InfiniDeviceEnum.CPU)
131+
65132
if args.nvidia:
66-
devices_to_test.append(InfiniDeviceEnum.NVIDIA)
67-
if args.iluvatar:
68-
devices_to_test.append(InfiniDeviceEnum.ILUVATAR)
133+
try:
134+
import torch.cuda
135+
136+
devices_to_test.append(InfiniDeviceEnum.NVIDIA)
137+
except ImportError:
138+
print("Warning: CUDA not available, skipping NVIDIA tests")
139+
69140
if args.cambricon:
70141
try:
71142
import torch_mlu
72143

73144
devices_to_test.append(InfiniDeviceEnum.CAMBRICON)
74145
except ImportError:
75146
print("Warning: torch_mlu not available, skipping Cambricon tests")
147+
76148
if args.ascend:
77149
try:
78150
import torch
@@ -82,10 +154,15 @@ def get_test_devices(args):
82154
devices_to_test.append(InfiniDeviceEnum.ASCEND)
83155
except ImportError:
84156
print("Warning: torch_npu not available, skipping Ascend tests")
157+
85158
if args.metax:
86-
import torch
159+
try:
160+
import torch
161+
162+
devices_to_test.append(InfiniDeviceEnum.METAX)
163+
except ImportError:
164+
print("Warning: Metax GPU support not available")
87165

88-
devices_to_test.append(InfiniDeviceEnum.METAX)
89166
if args.moore:
90167
try:
91168
import torch
@@ -94,6 +171,16 @@ def get_test_devices(args):
94171
devices_to_test.append(InfiniDeviceEnum.MOORE)
95172
except ImportError:
96173
print("Warning: torch_musa not available, skipping Moore tests")
174+
175+
if args.iluvatar:
176+
try:
177+
# Iluvatar GPU detection
178+
import torch
179+
180+
devices_to_test.append(InfiniDeviceEnum.ILUVATAR)
181+
except ImportError:
182+
print("Warning: Iluvatar GPU support not available")
183+
97184
if args.kunlun:
98185
try:
99186
import torch_xmlir
@@ -102,8 +189,17 @@ def get_test_devices(args):
102189
except ImportError:
103190
print("Warning: torch_xmlir not available, skipping Kunlun tests")
104191

192+
if args.hygon:
193+
try:
194+
import torch
195+
196+
devices_to_test.append(InfiniDeviceEnum.HYGON)
197+
except ImportError:
198+
print("Warning: Hygon DCU support not available")
199+
105200
# Default to CPU if no devices specified
106201
if not devices_to_test:
107202
devices_to_test = [InfiniDeviceEnum.CPU]
203+
print("No devices specified, defaulting to CPU")
108204

109205
return devices_to_test

test/infinicore/framework/devices.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class InfiniDeviceEnum:
2222
InfiniDeviceEnum.HYGON: "Hygon",
2323
}
2424

25-
# Mapping that maps InfiniDeviceEnum to torch device string
2625
torch_device_map = {
2726
InfiniDeviceEnum.CPU: "cpu",
2827
InfiniDeviceEnum.NVIDIA: "cuda",

0 commit comments

Comments
 (0)