Skip to content
Open
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
90 changes: 76 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ option(WITH_NVIDIA "Enable CUDA backend" OFF)
option(WITH_ILUVATAR "Enable Iluvatar GPU backend" OFF)
option(WITH_HYGON "Enable Hygon GPU backend" OFF)
option(WITH_METAX "Enable MetaX backend" OFF)
option(WITH_MARS "Enable Mars backend" OFF)
option(WITH_CAMBRICON "Enable Cambricon backend" OFF)
option(WITH_MOORE "Enable Moore backend" OFF)
option(WITH_ASCEND "Enable Ascend backend" OFF)
Expand Down Expand Up @@ -76,9 +77,48 @@ if(AUTO_DETECT_DEVICES)
endif()
endif()

if(DEFINED ENV{MACA_PATH})
set(_infinirt_hpcc_env_root "")
if(DEFINED ENV{HPCC_PATH} AND
EXISTS "$ENV{HPCC_PATH}/include/hcr/hc_runtime.h")
set(_infinirt_hpcc_env_root "$ENV{HPCC_PATH}")
endif()

set(_infinirt_maca_env_root "")
if(DEFINED ENV{MACA_PATH} AND
EXISTS "$ENV{MACA_PATH}/include/mcr/mc_runtime.h")
set(_infinirt_maca_env_root "$ENV{MACA_PATH}")
endif()

set(_infinirt_default_hpcc_available FALSE)
if(EXISTS "/opt/hpcc/include/hcr/hc_runtime.h")
set(_infinirt_default_hpcc_available TRUE)
endif()

set(_infinirt_default_maca_available FALSE)
if(EXISTS "/opt/maca/include/mcr/mc_runtime.h")
set(_infinirt_default_maca_available TRUE)
endif()

if(WITH_MARS OR WITH_METAX)
message(STATUS "Skipping MetaX-family auto-detection because a backend was explicitly enabled")
elseif(_infinirt_hpcc_env_root AND _infinirt_maca_env_root)
message(FATAL_ERROR
"Both HPCC_PATH and MACA_PATH identify valid SDKs. Select Mars with -DWITH_MARS=ON or MetaX with -DWITH_METAX=ON.")
elseif(_infinirt_hpcc_env_root)
set(WITH_MARS ON)
message(STATUS "Auto-detected Mars HPCC environment from HPCC_PATH")
elseif(_infinirt_maca_env_root)
set(WITH_METAX ON)
message(STATUS "Auto-detected MetaX environment from MACA_PATH")
message(STATUS "Auto-detected MetaX MACA environment from MACA_PATH")
elseif(_infinirt_default_hpcc_available AND _infinirt_default_maca_available)
message(FATAL_ERROR
"Both /opt/hpcc and /opt/maca contain valid SDKs. Select Mars with -DWITH_MARS=ON or MetaX with -DWITH_METAX=ON.")
elseif(_infinirt_default_hpcc_available)
set(WITH_MARS ON)
message(STATUS "Auto-detected Mars HPCC environment from /opt/hpcc")
elseif(_infinirt_default_maca_available)
set(WITH_METAX ON)
message(STATUS "Auto-detected MetaX MACA environment from /opt/maca")
else()
execute_process(
COMMAND sh -c "grep -h 9999 /sys/bus/pci/devices/*/vendor 2>/dev/null"
Expand All @@ -89,8 +129,7 @@ if(AUTO_DETECT_DEVICES)
string(FIND "${_pci_vendor_output}" "9999" _found_pos)

if(_found_pos GREATER -1)
set(WITH_METAX ON)
message(STATUS "Detected MetaX GPU from PCI vendor ID 0x9999")
message(STATUS "Detected a MetaX-family GPU from PCI vendor ID 0x9999, but no MACA or HPCC SDK was found")
else()
set(WITH_METAX OFF)
message(STATUS "No MetaX GPU detected")
Expand Down Expand Up @@ -118,7 +157,7 @@ if(AUTO_DETECT_DEVICES)

if(WITH_NVIDIA)
set(_non_nvidia_gpu_detected FALSE)
foreach(_gpu_backend WITH_ILUVATAR WITH_HYGON WITH_METAX WITH_CAMBRICON WITH_MOORE WITH_ASCEND)
foreach(_gpu_backend WITH_ILUVATAR WITH_HYGON WITH_METAX WITH_MARS WITH_CAMBRICON WITH_MOORE WITH_ASCEND)
if(${_gpu_backend})
set(_non_nvidia_gpu_detected TRUE)
endif()
Expand All @@ -135,14 +174,14 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

# Only one CUDA-like GPU backend can be enabled at a time.
set(_gpu_backend_count 0)
foreach(_gpu_backend WITH_NVIDIA WITH_ILUVATAR WITH_HYGON WITH_METAX WITH_MOORE WITH_ASCEND)
foreach(_gpu_backend WITH_NVIDIA WITH_ILUVATAR WITH_HYGON WITH_METAX WITH_MARS WITH_MOORE WITH_ASCEND)
if(${_gpu_backend})
math(EXPR _gpu_backend_count "${_gpu_backend_count} + 1")
endif()
endforeach()

if(_gpu_backend_count GREATER 1)
message(FATAL_ERROR "`WITH_NVIDIA`, `WITH_ILUVATAR`, `WITH_HYGON`, `WITH_METAX`, `WITH_MOORE`, and `WITH_ASCEND` are mutually exclusive. Build one GPU backend at a time.")
message(FATAL_ERROR "`WITH_NVIDIA`, `WITH_ILUVATAR`, `WITH_HYGON`, `WITH_METAX`, `WITH_MARS`, `WITH_MOORE`, and `WITH_ASCEND` are mutually exclusive. Build one GPU backend at a time.")
endif()

if(WITH_NVIDIA)
Expand Down Expand Up @@ -220,18 +259,38 @@ endif()
if(WITH_METAX)
add_compile_definitions(WITH_METAX=1)

# Normally can be found at: `/opt/maca/`.
set(MACA_PATH $ENV{MACA_PATH})
set(CMAKE_C_COMPILER ${CMAKE_CURRENT_SOURCE_DIR}/scripts/mxcc_wrapper.sh)
set(MACA_PATH "$ENV{MACA_PATH}" CACHE PATH "Path to the MetaX MACA SDK")
if(NOT MACA_PATH)
set(MACA_PATH "/opt/maca")
endif()
if(NOT EXISTS "${MACA_PATH}/include/mcr/mc_runtime.h")
message(FATAL_ERROR "`WITH_METAX` requires a MACA SDK. Set MACA_PATH to a root containing include/mcr/mc_runtime.h.")
endif()
set(CMAKE_CXX_COMPILER ${CMAKE_CURRENT_SOURCE_DIR}/scripts/mxcc_wrapper.sh)
message(STATUS "MetaX: using MACA SDK at ${MACA_PATH}")

include_directories("${MACA_PATH}/include")
link_directories("${MACA_PATH}/lib")

# Libraries: mcruntime / mcdnn / mcblas.
find_library(MACA_RUNTIME_LIB NAMES mcruntime HINTS "${MACA_PATH}/lib" REQUIRED)
endif()

if(WITH_MARS)
add_compile_definitions(WITH_MARS=1)

set(HPCC_PATH "$ENV{HPCC_PATH}" CACHE PATH "Path to the Mars HPCC SDK")
if(NOT HPCC_PATH)
set(HPCC_PATH "/opt/hpcc")
endif()
if(NOT EXISTS "${HPCC_PATH}/include/hcr/hc_runtime.h")
message(FATAL_ERROR "`WITH_MARS` requires an HPCC SDK. Set HPCC_PATH to a root containing include/hcr/hc_runtime.h.")
endif()
message(STATUS "Mars: using HPCC SDK at ${HPCC_PATH}")

include_directories("${HPCC_PATH}/include")
link_directories("${HPCC_PATH}/lib")
find_library(HPCC_RUNTIME_LIB NAMES hcruntime HINTS "${HPCC_PATH}/lib" REQUIRED)
endif()

if(WITH_MOORE)
add_compile_definitions(WITH_MOORE=1)

Expand Down Expand Up @@ -294,7 +353,7 @@ if(WITH_ASCEND)
endif()

# If all other platforms are not enabled, CPU is enabled by default.
if(NOT WITH_NVIDIA AND NOT WITH_ILUVATAR AND NOT WITH_HYGON AND NOT WITH_METAX AND NOT WITH_MOORE AND NOT WITH_CAMBRICON AND NOT WITH_ASCEND)
if(NOT WITH_NVIDIA AND NOT WITH_ILUVATAR AND NOT WITH_HYGON AND NOT WITH_METAX AND NOT WITH_MARS AND NOT WITH_MOORE AND NOT WITH_CAMBRICON AND NOT WITH_ASCEND)
set(WITH_CPU ON)
add_compile_definitions(WITH_CPU=1)
endif()
Expand All @@ -315,6 +374,9 @@ endif()
if(WITH_METAX)
list(APPEND INFINI_RT_PUBLIC_HEADER_DEVICES metax)
endif()
if(WITH_MARS)
list(APPEND INFINI_RT_PUBLIC_HEADER_DEVICES mars)
endif()
if(WITH_MOORE)
list(APPEND INFINI_RT_PUBLIC_HEADER_DEVICES moore)
endif()
Expand Down Expand Up @@ -347,7 +409,7 @@ if(WITH_NVIDIA OR WITH_ILUVATAR OR WITH_HYGON)
endif()

set(INFINI_RT_PACKAGE_VENDOR_BACKEND "")
foreach(_backend METAX MOORE CAMBRICON ASCEND)
foreach(_backend METAX MARS MOORE CAMBRICON ASCEND)
if(WITH_${_backend})
set(INFINI_RT_PACKAGE_VENDOR_BACKEND "${_backend}")
endif()
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Common backend options are:
-DWITH_ILUVATAR=ON
-DWITH_HYGON=ON
-DWITH_METAX=ON
-DWITH_MARS=ON
-DWITH_MOORE=ON
-DWITH_CAMBRICON=ON
-DWITH_ASCEND=ON
Expand Down Expand Up @@ -200,7 +201,8 @@ ruff check .

1. **CMake cannot find a backend SDK**: Check the backend-specific environment
variables documented in `docs/backends.md`, such as `DTK_ROOT`,
`MACA_PATH`, `MUSA_ROOT`, `NEUWARE_HOME`, or `ASCEND_HOME_PATH`.
`MACA_PATH`, `HPCC_PATH`, `MUSA_ROOT`, `NEUWARE_HOME`, or
`ASCEND_HOME_PATH`.
2. **Switching between backends gives stale build errors**: Use a separate
build directory per platform or delete the stale build directory.
3. **Generated headers are stale**: Re-run CMake configure. Public headers are
Expand Down
26 changes: 26 additions & 0 deletions cmake/InfiniRTConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(InfiniRT_WITH_NVIDIA @WITH_NVIDIA@)
set(InfiniRT_WITH_ILUVATAR @WITH_ILUVATAR@)
set(InfiniRT_WITH_HYGON @WITH_HYGON@)
set(InfiniRT_WITH_METAX @WITH_METAX@)
set(InfiniRT_WITH_MARS @WITH_MARS@)
set(InfiniRT_WITH_MOORE @WITH_MOORE@)
set(InfiniRT_WITH_CAMBRICON @WITH_CAMBRICON@)
set(InfiniRT_WITH_ASCEND @WITH_ASCEND@)
Expand All @@ -34,6 +35,7 @@ if(_InfiniRT_VENDOR_BACKEND STREQUAL "METAX")
if(DEFINED ENV{MACA_PATH})
list(APPEND _InfiniRT_ROOT_HINTS "$ENV{MACA_PATH}")
endif()
list(APPEND _InfiniRT_ROOT_HINTS /opt/maca)
find_path(_InfiniRT_BACKEND_INCLUDE_DIR
NAMES mcr/mc_runtime.h
HINTS ${_InfiniRT_ROOT_HINTS}
Expand All @@ -52,6 +54,30 @@ if(_InfiniRT_VENDOR_BACKEND STREQUAL "METAX")
_infinirt_define_backend_runtime(
"${_InfiniRT_BACKEND_INCLUDE_DIR}"
"${_InfiniRT_BACKEND_RUNTIME_LIBRARY}")
elseif(_InfiniRT_VENDOR_BACKEND STREQUAL "MARS")
set(_InfiniRT_ROOT_HINTS "${InfiniRT_MARS_ROOT}")
if(DEFINED ENV{HPCC_PATH})
list(APPEND _InfiniRT_ROOT_HINTS "$ENV{HPCC_PATH}")
endif()
list(APPEND _InfiniRT_ROOT_HINTS /opt/hpcc)
find_path(_InfiniRT_BACKEND_INCLUDE_DIR
NAMES hcr/hc_runtime.h
HINTS ${_InfiniRT_ROOT_HINTS}
PATH_SUFFIXES include)
find_library(_InfiniRT_BACKEND_RUNTIME_LIBRARY
NAMES hcruntime
HINTS ${_InfiniRT_ROOT_HINTS}
PATH_SUFFIXES lib lib64)
if(NOT _InfiniRT_BACKEND_INCLUDE_DIR OR
NOT _InfiniRT_BACKEND_RUNTIME_LIBRARY)
set(InfiniRT_FOUND FALSE)
set(InfiniRT_NOT_FOUND_MESSAGE
"Mars HPCC SDK not found. Set InfiniRT_MARS_ROOT or HPCC_PATH.")
return()
endif()
_infinirt_define_backend_runtime(
"${_InfiniRT_BACKEND_INCLUDE_DIR}"
"${_InfiniRT_BACKEND_RUNTIME_LIBRARY}")
elseif(_InfiniRT_VENDOR_BACKEND STREQUAL "MOORE")
set(_InfiniRT_ROOT_HINTS "${InfiniRT_MOORE_ROOT}")
foreach(_InfiniRT_ENV MUSA_ROOT MUSA_HOME MUSA_PATH)
Expand Down
1 change: 1 addition & 0 deletions docs/api/core-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Known device types include:
- `Device::Type::kNvidia`
- `Device::Type::kIluvatar`
- `Device::Type::kMetax`
- `Device::Type::kMars`
- `Device::Type::kMoore`
- `Device::Type::kHygon`
- `Device::Type::kCambricon`
Expand Down
7 changes: 6 additions & 1 deletion docs/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ backend.
| NVIDIA | `WITH_NVIDIA` | Requires CUDA toolkit. |
| Iluvatar | `WITH_ILUVATAR` | CUDA-compatible backend using clang with ivcore flags. |
| MetaX | `WITH_METAX` | Requires `MACA_PATH`. |
| Mars | `WITH_MARS` | Requires the HPCC SDK from `HPCC_PATH` or `/opt/hpcc`. |
| Moore | `WITH_MOORE` | Requires `MUSA_ROOT`, `MUSA_HOME`, or `MUSA_PATH`. |
| Hygon | `WITH_HYGON` | Requires DTK and a DTK CUDA toolkit. |
| Cambricon | `WITH_CAMBRICON` | Requires `NEUWARE_HOME`. |
Expand All @@ -20,6 +21,9 @@ backend.
Only one accelerator backend can be enabled at a time. CPU can be enabled
together with the selected accelerator backend.

When both HPCC and MACA SDKs are installed, select `WITH_MARS` or `WITH_METAX`
explicitly. Automatic detection rejects an ambiguous MetaX-family environment.

## Runtime API Support

All enabled runtime backends provide the core device and memory entry points
Expand All @@ -33,7 +37,8 @@ Current test expectations are:
| CPU | No | Yes | No | Yes | No | Yes | No |
| NVIDIA | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Iluvatar | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| MetaX | Yes | Yes | Yes | Yes | Yes | Yes | No |
| MetaX | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Mars | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Moore | Yes | Yes | No | Yes | Yes | Yes | No |
| Hygon | Yes | Yes | Yes | Yes | Yes | Yes | No |
| Cambricon | Yes | No | No | No | No | No | No |
Expand Down
1 change: 1 addition & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ InfiniRT uses CMake and C++17.
-DWITH_NVIDIA=ON
-DWITH_ILUVATAR=ON
-DWITH_METAX=ON
-DWITH_MARS=ON
-DWITH_MOORE=ON
-DWITH_HYGON=ON
-DWITH_CAMBRICON=ON
Expand Down
17 changes: 14 additions & 3 deletions scripts/generate_public_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataclasses
import pathlib
import re
import shutil


_DETAIL_PREFIX = "infini/rt/detail"
Expand All @@ -28,9 +29,14 @@
("hygon", "runtime_.h", "native/cuda/hygon/runtime_.h"),
),
"metax": (
("metax", "data_type_.h", "native/cuda/metax/data_type_.h"),
("metax", "device_.h", "native/cuda/metax/device_.h"),
("metax", "runtime_.h", "native/cuda/metax/runtime_.h"),
("metax", "data_type_.h", "native/maca/metax/data_type_.h"),
("metax", "device_.h", "native/maca/metax/device_.h"),
("metax", "runtime_.h", "native/maca/metax/runtime_.h"),
),
"mars": (
("mars", "data_type_.h", "native/hpcc/mars/data_type_.h"),
("mars", "device_.h", "native/hpcc/mars/device_.h"),
("mars", "runtime_.h", "native/hpcc/mars/runtime_.h"),
),
"moore": (
("moore", "data_type_.h", "native/cuda/moore/data_type_.h"),
Expand All @@ -55,6 +61,7 @@
"iluvatar": "Device::Type::kIluvatar",
"hygon": "Device::Type::kHygon",
"metax": "Device::Type::kMetax",
"mars": "Device::Type::kMars",
"moore": "Device::Type::kMoore",
"cambricon": "Device::Type::kCambricon",
"ascend": "Device::Type::kAscend",
Expand All @@ -65,6 +72,7 @@
"iluvatar",
"hygon",
"metax",
"mars",
"moore",
"cambricon",
"ascend",
Expand Down Expand Up @@ -663,6 +671,9 @@ def main():
include_root = pathlib.Path(args.output_dir)
source_root = pathlib.Path(args.runtime_header).parent

if include_root.exists():
shutil.rmtree(include_root)

_write_detail_headers(include_root, source_root, devices)
for device in devices:
for wrapper_device, header_name, target in _DEVICE_HEADERS[device]:
Expand Down
1 change: 1 addition & 0 deletions scripts/run_performance_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
("WITH_ILUVATAR", "iluvatar"),
("WITH_HYGON", "hygon"),
("WITH_METAX", "metax"),
("WITH_MARS", "mars"),
("WITH_MOORE", "moore"),
("WITH_CAMBRICON", "cambricon"),
("WITH_ASCEND", "ascend"),
Expand Down
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ if(WITH_HYGON)
endif()

if(WITH_METAX)
target_compile_definitions(infinirt PRIVATE WITH_METAX=1)
target_compile_definitions(infinirt PUBLIC WITH_METAX=1)
_infinirt_use_backend_runtime(
"${MACA_PATH}/include"
"${MACA_RUNTIME_LIB}")
endif()

if(WITH_MARS)
target_compile_definitions(infinirt PUBLIC WITH_MARS=1)
_infinirt_use_backend_runtime(
"${HPCC_PATH}/include"
"${HPCC_RUNTIME_LIB}")
endif()

if(WITH_MOORE)
target_compile_definitions(infinirt PRIVATE WITH_MOORE=1)
_infinirt_use_backend_runtime(
Expand Down
5 changes: 4 additions & 1 deletion src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Device {
kMoore = 5,
kIluvatar = 6,
kHygon = 7,
kMars = 8,
kCount
};

Expand Down Expand Up @@ -64,6 +65,7 @@ class Device {
{Type::kMoore, "moore"},
{Type::kIluvatar, "iluvatar"},
{Type::kHygon, "hygon"},
{Type::kMars, "mars"},
}}};

static constexpr ConstexprMap<std::string_view, Device::Type,
Expand All @@ -77,6 +79,7 @@ class Device {
{"moore", Type::kMoore},
{"iluvatar", Type::kIluvatar},
{"hygon", Type::kHygon},
{"mars", Type::kMars},
}}};

int index_{0};
Expand All @@ -91,7 +94,7 @@ struct DeviceEnabled : std::false_type {};
using AllDeviceTypes =
List<Device::Type::kCpu, Device::Type::kNvidia, Device::Type::kCambricon,
Device::Type::kAscend, Device::Type::kMetax, Device::Type::kMoore,
Device::Type::kIluvatar, Device::Type::kHygon>;
Device::Type::kIluvatar, Device::Type::kHygon, Device::Type::kMars>;

// Deferred computation of active devices. The `Filter` and `FilterList`
// evaluation are nested inside a class template so that `DeviceEnabled`
Expand Down
Loading
Loading