Skip to content
Closed
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
52 changes: 47 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ option(WITH_CPU "Enable CPU backend" OFF)
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_ALI "Enable Ali PPU backend" OFF)
option(WITH_METAX "Enable MetaX backend" OFF)
option(WITH_CAMBRICON "Enable Cambricon backend" OFF)
option(WITH_MOORE "Enable Moore backend" OFF)
Expand Down Expand Up @@ -118,7 +119,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_ALI WITH_METAX WITH_CAMBRICON WITH_MOORE WITH_ASCEND)
if(${_gpu_backend})
set(_non_nvidia_gpu_detected TRUE)
endif()
Expand All @@ -135,14 +136,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_ALI WITH_METAX 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_ALI`, `WITH_METAX`, `WITH_MOORE`, and `WITH_ASCEND` are mutually exclusive. Build one GPU backend at a time.")
endif()

if(WITH_NVIDIA)
Expand Down Expand Up @@ -217,6 +218,44 @@ if(WITH_HYGON)
find_package(CUDAToolkit REQUIRED)
endif()

if(WITH_ALI)
add_compile_definitions(WITH_ALI=1)

set(ALI_CUDA_ROOT "")
foreach(_ali_cuda_env ALI_CUDA_ROOT PPU_CUDA_ROOT)
if(NOT ALI_CUDA_ROOT AND DEFINED ENV{${_ali_cuda_env}} AND
NOT "$ENV{${_ali_cuda_env}}" STREQUAL "")
set(ALI_CUDA_ROOT "$ENV{${_ali_cuda_env}}")
endif()
endforeach()
if(NOT ALI_CUDA_ROOT AND DEFINED ENV{PPU_SDK_ROOT} AND
NOT "$ENV{PPU_SDK_ROOT}" STREQUAL "")
set(ALI_CUDA_ROOT "$ENV{PPU_SDK_ROOT}/CUDA_SDK")
endif()
if(NOT ALI_CUDA_ROOT AND EXISTS "/usr/local/PPU_SDK/CUDA_SDK")
set(ALI_CUDA_ROOT "/usr/local/PPU_SDK/CUDA_SDK")
endif()

if(NOT ALI_CUDA_ROOT OR NOT EXISTS "${ALI_CUDA_ROOT}/bin/nvcc")
message(FATAL_ERROR
"`WITH_ALI` is `ON` but the Ali PPU CUDA SDK was not found. "
"Set `ALI_CUDA_ROOT`, `PPU_CUDA_ROOT`, or `PPU_SDK_ROOT`.")
endif()

set(CMAKE_CUDA_COMPILER "${ALI_CUDA_ROOT}/bin/nvcc"
CACHE FILEPATH "Ali PPU CUDA compiler" FORCE)
set(CUDAToolkit_ROOT "${ALI_CUDA_ROOT}"
CACHE PATH "Ali PPU CUDA toolkit root" FORCE)
if(NOT CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 80 CACHE STRING
"Ali PPU CUDA architecture" FORCE)
endif()

message(STATUS "Ali PPU: CUDA toolkit ${ALI_CUDA_ROOT}")
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
endif()

if(WITH_METAX)
add_compile_definitions(WITH_METAX=1)

Expand Down Expand Up @@ -294,7 +333,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_ALI AND NOT WITH_METAX 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 @@ -312,6 +351,9 @@ endif()
if(WITH_HYGON)
list(APPEND INFINI_RT_PUBLIC_HEADER_DEVICES hygon)
endif()
if(WITH_ALI)
list(APPEND INFINI_RT_PUBLIC_HEADER_DEVICES ali)
endif()
if(WITH_METAX)
list(APPEND INFINI_RT_PUBLIC_HEADER_DEVICES metax)
endif()
Expand Down Expand Up @@ -342,7 +384,7 @@ endif()
add_subdirectory(src)

set(INFINI_RT_PACKAGE_NEEDS_CUDATOOLKIT OFF)
if(WITH_NVIDIA OR WITH_ILUVATAR OR WITH_HYGON)
if(WITH_NVIDIA OR WITH_ILUVATAR OR WITH_HYGON OR WITH_ALI)
set(INFINI_RT_PACKAGE_NEEDS_CUDATOOLKIT ON)
endif()

Expand Down
1 change: 1 addition & 0 deletions cmake/InfiniRTConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(InfiniRT_WITH_CPU @WITH_CPU@)
set(InfiniRT_WITH_NVIDIA @WITH_NVIDIA@)
set(InfiniRT_WITH_ILUVATAR @WITH_ILUVATAR@)
set(InfiniRT_WITH_HYGON @WITH_HYGON@)
set(InfiniRT_WITH_ALI @WITH_ALI@)
set(InfiniRT_WITH_METAX @WITH_METAX@)
set(InfiniRT_WITH_MOORE @WITH_MOORE@)
set(InfiniRT_WITH_CAMBRICON @WITH_CAMBRICON@)
Expand Down
7 changes: 7 additions & 0 deletions scripts/generate_public_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
("hygon", "device_.h", "native/cuda/hygon/device_.h"),
("hygon", "runtime_.h", "native/cuda/hygon/runtime_.h"),
),
"ali": (
("ali", "data_type_.h", "native/cuda/ali/data_type_.h"),
("ali", "device_.h", "native/cuda/ali/device_.h"),
("ali", "runtime_.h", "native/cuda/ali/runtime_.h"),
),
"metax": (
("metax", "data_type_.h", "native/cuda/metax/data_type_.h"),
("metax", "device_.h", "native/cuda/metax/device_.h"),
Expand Down Expand Up @@ -54,6 +59,7 @@
"nvidia": "Device::Type::kNvidia",
"iluvatar": "Device::Type::kIluvatar",
"hygon": "Device::Type::kHygon",
"ali": "Device::Type::kAli",
"metax": "Device::Type::kMetax",
"moore": "Device::Type::kMoore",
"cambricon": "Device::Type::kCambricon",
Expand All @@ -64,6 +70,7 @@
"nvidia",
"iluvatar",
"hygon",
"ali",
"metax",
"moore",
"cambricon",
Expand Down
14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ if(WITH_HYGON)
)
endif()

if(WITH_ALI)
enable_language(CUDA)

target_compile_definitions(infinirt PUBLIC WITH_ALI=1)

find_package(CUDAToolkit REQUIRED)
target_link_libraries(infinirt PUBLIC CUDA::cudart)

set_target_properties(infinirt PROPERTIES
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
)
endif()

if(WITH_METAX)
target_compile_definitions(infinirt PRIVATE WITH_METAX=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,
kAli = 8,
kCount
};

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

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},
{"ali", Type::kAli},
}}};

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::kAli>;

// Deferred computation of active devices. The `Filter` and `FilterList`
// evaluation are nested inside a class template so that `DeviceEnabled`
Expand Down
30 changes: 30 additions & 0 deletions src/native/cuda/ali/data_type_.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef INFINI_RT_ALI_DATA_TYPE__H_
#define INFINI_RT_ALI_DATA_TYPE__H_

// clang-format off
#include <cuda_bf16.h>
#include <cuda_fp16.h>
// clang-format on

#include "data_type.h"
#include "native/cuda/ali/device_.h"

namespace infini::rt {

using cuda_bfloat16 = nv_bfloat16;

using cuda_bfloat162 = nv_bfloat162;

template <>
struct TypeMap<Device::Type::kAli, DataType::kFloat16> {
using type = half;
};

template <>
struct TypeMap<Device::Type::kAli, DataType::kBFloat16> {
using type = __nv_bfloat16;
};

} // namespace infini::rt

#endif
13 changes: 13 additions & 0 deletions src/native/cuda/ali/device_.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef INFINI_RT_ALI_DEVICE__H_
#define INFINI_RT_ALI_DEVICE__H_

#include "device.h"

namespace infini::rt {

template <>
struct DeviceEnabled<Device::Type::kAli> : std::true_type {};

} // namespace infini::rt

#endif
Loading
Loading