Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ If you plan to use the hardware testing modules, you need to build the CUDA memo

```bash
cd infinimetrics/hardware/cuda-memory-benchmark
bash build.sh
bash build.sh --platform cuda
```

For MetaX, Iluvatar, Hygon, and Moore Threads build and runtime instructions,
see [Hardware Benchmarks](../infinimetrics/hardware/README.md).

**Note**: This requires:
- CUDA toolkit (compatible with your GPU driver)
- C++ compiler with CUDA support
Expand Down
1 change: 1 addition & 0 deletions infinimetrics/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AcceleratorType(str, Enum):
AMD = "amd" # ROCm
ASCEND = "ascend" # Huawei NPU
CAMBRICON = "cambricon" # Cambricon MLU
MTHREADS = "moore" # Moore Threads MUSA
GENERIC = "generic"


Expand Down
63 changes: 62 additions & 1 deletion infinimetrics/common/hardware_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"default_name": "NVIDIA GPU",
"parse_output": True,
},
"moore": {
"command": ["mthreads-gmi", "-q"],
"pattern": r"\bGPU\b|\bProduct\b",
"default_name": "Moore Threads GPU",
},
"amd": {
"candidates": ["amd-smi", "rocm-smi"],
"pattern": r"\bGPU\b",
Expand Down Expand Up @@ -99,13 +104,17 @@ def collect(self, accel_type: str = "", device_ids: Any = None) -> Dict[str, Any
hw["cuda_version"] = (
self._collect_cuda_version() or hw["cuda_version"]
)
elif probe_type == "moore":
musa_ver = self._collect_musa_version()
if musa_ver:
hw["cuda_version"] = f"MUSA {musa_ver}"
return hw

return hw

def _get_probe_order(self, hint: str) -> List[str]:
"""Get probe order based on accelerator type hint."""
order = ["nvidia", "amd", "ascend", "cambricon"]
order = ["nvidia", "moore", "amd", "ascend", "cambricon"]
if hint in order:
return [hint] + [p for p in order if p != hint]
return order
Expand Down Expand Up @@ -137,6 +146,7 @@ def _probe(self, probe_type: str, hw: Dict[str, Any]) -> ProbeResult:
"""Generic probe dispatcher."""
probe_methods = {
"nvidia": self._probe_nvidia,
"moore": self._probe_mthreads,
"amd": self._probe_amd,
"ascend": self._probe_generic_command,
"cambricon": self._probe_generic_command,
Expand Down Expand Up @@ -182,6 +192,42 @@ def _probe_amd(self, probe_type: str, hw: Dict[str, Any]) -> ProbeResult:
cmd, config["pattern"], config["default_name"], hw
)

def _probe_mthreads(self, probe_type: str, hw: Dict[str, Any]) -> ProbeResult:
"""Probe Moore Threads GPU using mthreads-gmi."""
config = PROBE_CONFIGS["moore"]
if not _which(config["command"][0]):
return ProbeResult(success=False)

try:
r = subprocess.run(
config["command"], capture_output=True, text=True, timeout=5
)
if r.returncode != 0 or not r.stdout.strip():
return ProbeResult(success=False)

gpu_count = 0
gpu_name = None
for line in r.stdout.splitlines():
stripped = line.strip()
if re.match(r"^GPU\d+\s", stripped):
gpu_count += 1
if stripped.startswith("Product Name") and ":" in stripped:
gpu_name = stripped.split(":", 1)[1].strip()

if gpu_count > 0:
hw["gpu_count"] = max(hw["gpu_count"], gpu_count)
if hw["gpu_model"] == "Unknown":
hw["gpu_model"] = gpu_name or config["default_name"]

# Try to get MUSA version
musa_ver = self._collect_musa_version()
if musa_ver:
hw["cuda_version"] = f"MUSA {musa_ver}"

return ProbeResult(success=True, count=hw["gpu_count"])
except Exception:
return ProbeResult(success=False)

def _probe_generic_command(
self, probe_type: str, hw: Dict[str, Any]
) -> ProbeResult:
Expand Down Expand Up @@ -228,6 +274,21 @@ def _collect_cuda_version(self) -> Optional[str]:
logger.debug(f"Failed to collect CUDA version: {e}")
return None

def _collect_musa_version(self) -> Optional[str]:
"""Collect MUSA version using mcc."""
try:
r = subprocess.run(
["mcc", "--version"], capture_output=True, text=True, timeout=2
)
if r.returncode == 0:
for line in r.stdout.splitlines():
match = re.search(r"(\d+\.\d+\.\d+)", line)
if match:
return match.group(1)
except Exception:
pass
return None


# Singleton instance for convenience
_collector = HardwareCollector()
Expand Down
81 changes: 81 additions & 0 deletions infinimetrics/hardware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Hardware Benchmarks

InfiniBench provides one hardware adapter for NVIDIA CUDA and four additional
CUDA-compatible accelerator platforms. Existing CUDA command shapes and metric
names are kept unchanged.

## Platforms

| Platform | `config.device` values | Build command | Binary |
| --- | --- | --- | --- |
| NVIDIA CUDA | `cuda`, `cudaUnified`, `nvidia` | `bash build.sh --platform cuda` | `cuda-memory-benchmark/build/cuda_perf_suite` |
| MetaX | `metax` | `bash build.sh --platform metax` | `cuda-memory-benchmark/build/cuda_perf_suite` |
| Iluvatar CoreX | `corex`, `iluvatar` | `bash build.sh --platform corex` | `cuda-memory-benchmark/build/cuda_perf_suite` |
| Hygon DCU | `hygon` | `bash build.sh --platform hygon` | `cuda-memory-benchmark/build/cuda_perf_suite` |
| Moore Threads | `moore` | `bash build.sh --platform moore` | `cuda-memory-benchmark/build/cuda_perf_suite` |

Run each build command from its benchmark directory. All binaries use the same
test selectors and common arguments:

```bash
./build/<binary> --all
./build/<binary> --memory
./build/<binary> --stream --iterations 3 --array-size 1048576
./build/<binary> --cache --device 0
```

## Platform Selection

`HardwareTestAdapter` resolves a platform in this order:

1. `config.device`, when supplied.
2. The locally installed accelerator toolchain.
3. CUDA as the compatibility fallback.

The testcase framework remains `cudaUnified` for every hardware platform. For
example, Moore Threads STREAM uses:

```json
{
"testcase": "hardware.cudaUnified.Stream",
"config": {
"device": "moore"
}
}
```

The aliases `nvidia`, `musa`, and `mthreads` are also accepted as explicit
device values. A selected non-CUDA platform is recorded in the result
configuration as `platform`; metric names remain compatible with CUDA results.

## Device Visibility

Restrict the process to an idle physical device before starting a benchmark.
The selected physical device is renumbered to device 0 inside the process.

| Platform | Visibility variable |
| --- | --- |
| NVIDIA, MetaX, Iluvatar | `CUDA_VISIBLE_DEVICES` |
| Hygon | `HIP_VISIBLE_DEVICES` and `ROCR_VISIBLE_DEVICES` |
| Moore Threads | `MUSA_VISIBLE_DEVICES` |

For example:

```bash
CUDA_VISIBLE_DEVICES=2 ./build/cuda_perf_suite --stream --device 0
MUSA_VISIBLE_DEVICES=0 ./build/cuda_perf_suite --stream --device 0
```

## Container Notes

Hygon DTK containers may require the host driver libraries to be mounted at
the path expected by DTK:

```bash
docker run --rm --privileged \
--mount type=bind,source=/opt/hyhal,target=/opt/hyhal,readonly \
<dtk-image> bash
```

Without this mount, management tools can list DCUs while HIP applications fail
to load `libhsa-runtime64.so` or `libhydmi.so`.
47 changes: 47 additions & 0 deletions infinimetrics/hardware/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Hardware platform aliases and benchmark configuration."""

PLATFORM_ALIASES = {
"cuda": "cuda",
"cudaunified": "cuda",
"nvidia": "cuda",
"metax": "metax",
"corex": "corex",
"iluvatar": "corex",
"hygon": "hygon",
"moore": "moore",
"mthreads": "moore",
"musa": "moore",
}

PLATFORM_CONFIGS = {
"cuda": {
"binary_name": "cuda_perf_suite",
"benchmark_subdir": "cuda-memory-benchmark",
"build_platform": "cuda",
"cache_parser": "cuda",
},
"metax": {
"binary_name": "cuda_perf_suite",
"benchmark_subdir": "cuda-memory-benchmark",
"build_platform": "metax",
"cache_parser": "cuda",
},
"corex": {
"binary_name": "cuda_perf_suite",
"benchmark_subdir": "cuda-memory-benchmark",
"build_platform": "corex",
"cache_parser": "cuda",
},
"hygon": {
"binary_name": "cuda_perf_suite",
"benchmark_subdir": "cuda-memory-benchmark",
"build_platform": "hygon",
"cache_parser": "cuda",
},
"moore": {
"binary_name": "cuda_perf_suite",
"benchmark_subdir": "cuda-memory-benchmark",
"build_platform": "moore",
"cache_parser": "cuda",
},
}
34 changes: 32 additions & 2 deletions infinimetrics/hardware/cuda-memory-benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ cmake_minimum_required(VERSION 3.18)

# Platform detection
if(NOT DEFINED PLATFORM)
message(FATAL_ERROR "PLATFORM is not set. Use -DPLATFORM=cuda or -DPLATFORM=metax")
message(FATAL_ERROR "PLATFORM is not set. Use -DPLATFORM=cuda, -DPLATFORM=metax, -DPLATFORM=corex, or -DPLATFORM=hygon")
endif()

if(PLATFORM STREQUAL "cuda")
project(CudaPerfSuite LANGUAGES CXX CUDA VERSION 1.0.0)
elseif(PLATFORM STREQUAL "metax")
project(CudaPerfSuite LANGUAGES CXX VERSION 1.0.0)
elseif(PLATFORM STREQUAL "corex")
project(CudaPerfSuite LANGUAGES CXX CUDA VERSION 1.0.0)
elseif(PLATFORM STREQUAL "hygon")
project(CudaPerfSuite LANGUAGES CXX VERSION 1.0.0)
else()
message(FATAL_ERROR "Unsupported PLATFORM: ${PLATFORM}. Use 'cuda' or 'metax'")
message(FATAL_ERROR "Unsupported PLATFORM: ${PLATFORM}. Use 'cuda', 'metax', 'corex', or 'hygon'")
endif()

# Set C++ standard
Expand Down Expand Up @@ -53,6 +57,30 @@ elseif(PLATFORM STREQUAL "metax")
# Treat .cu as CXX for cu-bridge
set_source_files_properties(src/main.cu PROPERTIES LANGUAGE CXX)

add_executable(cuda_perf_suite ${CUDA_SOURCES} ${CXX_SOURCES})

elseif(PLATFORM STREQUAL "corex")
# CoreX adapted CMake handles CUDA compiler automatically (clang++)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_ARCHITECTURES "ivcore20" CACHE STRING "CoreX GPU architectures")

include_directories($ENV{COREX_PATH}/include)
link_directories($ENV{COREX_PATH}/lib64)

add_executable(cuda_perf_suite ${CUDA_SOURCES} ${CXX_SOURCES})

elseif(PLATFORM STREQUAL "hygon")
# Hygon DCU: use hipcc from DTK
find_program(HIPCC hipcc REQUIRED)
set(CMAKE_CXX_COMPILER "${HIPCC}")
set(CMAKE_C_COMPILER "${HIPCC}")

# Treat .cu as CXX so hipcc handles kernel launch syntax
set_source_files_properties(src/main.cu PROPERTIES LANGUAGE CXX)

add_compile_definitions(GPU_PLATFORM_HIP)

add_executable(cuda_perf_suite ${CUDA_SOURCES} ${CXX_SOURCES})
endif()

Expand All @@ -72,5 +100,7 @@ message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS " C++ standard: ${CMAKE_CXX_STANDARD}")
if(PLATFORM STREQUAL "cuda")
message(STATUS " CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
elseif(PLATFORM STREQUAL "corex")
message(STATUS " CoreX arch: ${CMAKE_CUDA_ARCHITECTURES}")
endif()
message(STATUS "")
Loading
Loading