Skip to content

Commit 2d73e5b

Browse files
committed
feat: Add metax build for cuda script
1 parent 9facb01 commit 2d73e5b

3 files changed

Lines changed: 133 additions & 50 deletions

File tree

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
cmake_minimum_required(VERSION 3.18)
2-
project(CudaPerfSuite VERSION 1.0.0 LANGUAGES CXX CUDA)
2+
3+
# Platform detection
4+
if(NOT DEFINED PLATFORM)
5+
message(FATAL_ERROR "PLATFORM is not set. Use -DPLATFORM=cuda or -DPLATFORM=metax")
6+
endif()
7+
8+
if(PLATFORM STREQUAL "cuda")
9+
project(CudaPerfSuite LANGUAGES CXX CUDA VERSION 1.0.0)
10+
elseif(PLATFORM STREQUAL "metax")
11+
project(CudaPerfSuite LANGUAGES CXX VERSION 1.0.0)
12+
else()
13+
message(FATAL_ERROR "Unsupported PLATFORM: ${PLATFORM}. Use 'cuda' or 'metax'")
14+
endif()
315

416
# Set C++ standard
517
set(CMAKE_CXX_STANDARD 17)
618
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7-
set(CMAKE_CUDA_STANDARD 17)
8-
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
9-
10-
# Set CUDA architecture (adjust based on your GPU)
11-
set(CMAKE_CUDA_ARCHITECTURES "80;86;89;90" CACHE STRING "CUDA architectures")
1219

1320
# Build type
1421
if(NOT CMAKE_BUILD_TYPE)
1522
set(CMAKE_BUILD_TYPE Release)
1623
endif()
1724

18-
# Compiler flags
19-
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wall")
20-
set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -O3 -lineinfo")
21-
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
22-
23-
# Find CUDA
24-
find_package(CUDAToolkit REQUIRED)
25-
2625
# Include directories
27-
include_directories(${CUDA_INCLUDE_DIRS}
28-
${CMAKE_CURRENT_SOURCE_DIR}/include)
26+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
2927

3028
# Source files
3129
set(CUDA_SOURCES
@@ -36,29 +34,43 @@ set(CXX_SOURCES
3634
# Add any .cpp files here if needed
3735
)
3836

39-
# Create executable
40-
add_executable(cuda_perf_suite
41-
${CUDA_SOURCES}
42-
${CXX_SOURCES}
43-
)
37+
# ---- Platform-specific settings ----
38+
39+
if(PLATFORM STREQUAL "cuda")
40+
set(CMAKE_CUDA_STANDARD 17)
41+
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
42+
set(CMAKE_CUDA_ARCHITECTURES "80;86;89;90" CACHE STRING "CUDA architectures")
43+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wall")
44+
set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -O3 -lineinfo")
45+
46+
add_executable(cuda_perf_suite ${CUDA_SOURCES} ${CXX_SOURCES})
47+
48+
elseif(PLATFORM STREQUAL "metax")
49+
# Use cu-bridge compiler
50+
set(CMAKE_CXX_COMPILER "$ENV{CUDA_PATH}/bin/nvcc")
51+
set(CMAKE_C_COMPILER "$ENV{CUDA_PATH}/bin/nvcc")
52+
53+
# Treat .cu as CXX for cu-bridge
54+
set_source_files_properties(src/main.cu PROPERTIES LANGUAGE CXX)
55+
56+
add_executable(cuda_perf_suite ${CUDA_SOURCES} ${CXX_SOURCES})
57+
endif()
4458

4559
# Link libraries
46-
target_link_libraries(cuda_perf_suite
47-
${CUDA_LIBRARIES}
48-
${CMAKE_THREADS_LIB_INIT}
49-
)
60+
target_link_libraries(cuda_perf_suite ${CMAKE_THREADS_LIB_INIT})
5061

5162
# Installation
52-
install(TARGETS cuda_perf_suite
53-
RUNTIME DESTINATION bin
54-
)
63+
install(TARGETS cuda_perf_suite RUNTIME DESTINATION bin)
5564

5665
# Print configuration
5766
message(STATUS "")
5867
message(STATUS "Configuration Summary:")
5968
message(STATUS " Project: ${PROJECT_NAME}")
6069
message(STATUS " Version: ${PROJECT_VERSION}")
70+
message(STATUS " Platform: ${PLATFORM}")
6171
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
6272
message(STATUS " C++ standard: ${CMAKE_CXX_STANDARD}")
63-
message(STATUS " CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
73+
if(PLATFORM STREQUAL "cuda")
74+
message(STATUS " CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
75+
endif()
6476
message(STATUS "")

infinimetrics/hardware/cuda-memory-benchmark/build.sh

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22

33
# Build script for CUDA Performance Suite
4+
# Usage:
5+
# bash build.sh --platform cuda # Build with native CUDA (NVIDIA GPU)
6+
# bash build.sh --platform metax # Build with cu-bridge (MetaX GPU)
47

58
set -e # Exit on error
69

@@ -10,34 +13,92 @@ GREEN='\033[0;32m'
1013
YELLOW='\033[1;33m'
1114
NC='\033[0m' # No Color
1215

16+
# Parse arguments
17+
PLATFORM=""
18+
while [[ $# -gt 0 ]]; do
19+
case $1 in
20+
--platform)
21+
PLATFORM="$2"
22+
shift 2
23+
;;
24+
*)
25+
echo -e "${RED}Unknown option: $1${NC}"
26+
echo "Usage: bash build.sh --platform <cuda|metax>"
27+
exit 1
28+
;;
29+
esac
30+
done
31+
32+
if [[ -z "$PLATFORM" ]]; then
33+
echo -e "${RED}ERROR: --platform is required.${NC}"
34+
echo "Usage: bash build.sh --platform <cuda|metax>"
35+
exit 1
36+
fi
37+
1338
echo "=========================================="
1439
echo " CUDA Performance Suite - Build Script"
40+
echo " Platform: ${PLATFORM}"
1541
echo "=========================================="
1642
echo ""
1743

18-
# Check if CUDA is available
19-
if ! command -v nvcc &> /dev/null; then
20-
echo -e "${RED}ERROR: nvcc not found. Please install CUDA toolkit.${NC}"
21-
exit 1
22-
fi
44+
if [[ "$PLATFORM" == "metax" ]]; then
45+
# ---- MetaX platform: using cu-bridge ----
46+
47+
export MACA_PATH=${MACA_PATH:-/opt/maca}
48+
export CUCC_PATH=${CUCC_PATH:-${MACA_PATH}/tools/cu-bridge}
49+
export PATH=$PATH:${CUCC_PATH}/tools:${CUCC_PATH}/bin
50+
export CUCC_CMAKE_ENTRY=2
51+
export CUDA_PATH=${CUCC_PATH}
52+
53+
# Create nvcc symlink (if it doesn't exist)
54+
if [ ! -e ${CUCC_PATH}/bin/nvcc ]; then
55+
ln -s ${CUCC_PATH}/bin/cucc ${CUCC_PATH}/bin/nvcc
56+
fi
57+
58+
if ! command -v cucc &> /dev/null; then
59+
echo -e "${RED}ERROR: cucc not found. Please check cu-bridge installation at ${CUCC_PATH}${NC}"
60+
exit 1
61+
fi
62+
63+
echo -e "${YELLOW}[MetaX] Using cu-bridge: ${CUCC_PATH}${NC}"
64+
65+
mkdir -p build
66+
cd build
2367

24-
# Create build directory
25-
echo -e "${YELLOW}Creating build directory...${NC}"
26-
mkdir -p build
27-
cd build
68+
echo -e "${YELLOW}Configuring with cmake_maca...${NC}"
69+
cmake_maca .. -DCMAKE_BUILD_TYPE=Release -DPLATFORM=metax
2870

29-
# Configure with CMake
30-
echo -e "${YELLOW}Configuring with CMake...${NC}"
31-
cmake .. -DCMAKE_BUILD_TYPE=Release
71+
echo -e "${YELLOW}Building with make_maca...${NC}"
72+
make_maca -j$(nproc)
3273

33-
# Build
34-
echo -e "${YELLOW}Building...${NC}"
35-
make -j$(nproc)
74+
elif [[ "$PLATFORM" == "cuda" ]]; then
75+
# ---- NVIDIA CUDA platform ----
76+
77+
if ! command -v nvcc &> /dev/null; then
78+
echo -e "${RED}ERROR: nvcc not found. Please install CUDA toolkit.${NC}"
79+
exit 1
80+
fi
81+
82+
echo -e "${YELLOW}[CUDA] Using native nvcc: $(which nvcc)${NC}"
83+
84+
mkdir -p build
85+
cd build
86+
87+
echo -e "${YELLOW}Configuring with CMake...${NC}"
88+
cmake .. -DCMAKE_BUILD_TYPE=Release -DPLATFORM=cuda
89+
90+
echo -e "${YELLOW}Building...${NC}"
91+
make -j$(nproc)
92+
93+
else
94+
echo -e "${RED}ERROR: Unsupported platform '${PLATFORM}'. Use 'cuda' or 'metax'.${NC}"
95+
exit 1
96+
fi
3697

3798
# Check if build was successful
3899
if [ $? -eq 0 ]; then
39100
echo ""
40-
echo -e "${GREEN}Build completed successfully!${NC}"
101+
echo -e "${GREEN}Build completed successfully!${NC}"
41102
echo ""
42103
echo "Executable: build/cuda_perf_suite"
43104
echo ""
@@ -50,8 +111,7 @@ if [ $? -eq 0 ]; then
50111
echo ""
51112
else
52113
echo ""
53-
echo -e "${RED}Build failed!${NC}"
114+
echo -e "${RED}Build failed!${NC}"
54115
echo "Please check the error messages above."
55116
exit 1
56117
fi
57-

infinimetrics/hardware/hardware_adapter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import subprocess
66
import re
7+
import shutil
78
from pathlib import Path
89
from typing import Any, Dict, Optional, List
910

@@ -29,6 +30,15 @@
2930
logger = logging.getLogger(__name__)
3031

3132

33+
def detect_platform() -> str:
34+
"""Detect GPU platform: 'metax' if MACA/cu-bridge is available, else 'cuda'."""
35+
maca_path = Path("/opt/maca")
36+
cucc_path = maca_path / "tools" / "cu-bridge" / "bin" / "cucc"
37+
if cucc_path.exists() or shutil.which("cucc") or shutil.which("mxcc"):
38+
return "metax"
39+
return "cuda"
40+
41+
3242
class HardwareTestAdapter(BaseAdapter):
3343
"""Adapter for CUDA Unified hardware performance tests."""
3444

@@ -126,18 +136,19 @@ def _build_cuda_project(self) -> None:
126136
)
127137
if not self.build_script.exists():
128138
raise FileNotFoundError(f"Build script not found: {self.build_script}")
129-
logger.info("Building CUDA project in: %s", self.build_dir)
139+
platform = detect_platform()
140+
logger.info("Building CUDA project in: %s (platform: %s)", self.build_dir, platform)
130141
try:
131142
result = subprocess.run(
132-
["bash", str(self.build_script)],
143+
["bash", str(self.build_script), "--platform", platform],
133144
cwd=str(self.build_dir),
134145
capture_output=True,
135146
text=True,
136147
timeout=300,
137148
)
138149
if result.returncode != 0:
139150
raise RuntimeError(f"Failed to build CUDA project:\n{result.stderr}")
140-
logger.info("CUDA project build completed successfully")
151+
logger.info("CUDA project build completed successfully (platform: %s)", platform)
141152
except subprocess.TimeoutExpired:
142153
raise RuntimeError("CUDA project build timed out after 5 minutes")
143154

0 commit comments

Comments
 (0)