Skip to content

Commit fcd8856

Browse files
authored
feat: support MCCL on Moore Threads (#52)
1 parent 1f3e24a commit fcd8856

8 files changed

Lines changed: 62 additions & 4 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ if(AUTO_DETECT_BACKENDS)
247247
else()
248248
message(STATUS "MCCL library/headers not found in MetaX paths.")
249249
endif()
250+
elseif(WITH_MOORE)
251+
set(_MCCL_HINTS)
252+
foreach(_musa_env MUSA_ROOT MUSA_HOME MUSA_PATH)
253+
if(DEFINED ENV{${_musa_env}} AND NOT "$ENV{${_musa_env}}" STREQUAL "")
254+
list(APPEND _MCCL_HINTS "$ENV{${_musa_env}}")
255+
endif()
256+
endforeach()
257+
list(APPEND _MCCL_HINTS /usr/local/musa)
258+
259+
find_path(AUTO_MCCL_INC NAMES mccl.h HINTS ${_MCCL_HINTS} PATH_SUFFIXES include QUIET)
260+
find_library(AUTO_MCCL_LIB NAMES mccl HINTS ${_MCCL_HINTS} PATH_SUFFIXES lib lib64 QUIET)
261+
262+
if(AUTO_MCCL_INC AND AUTO_MCCL_LIB)
263+
set(WITH_MCCL ON)
264+
message(STATUS "Auto-detected MCCL backend.")
265+
else()
266+
message(STATUS "MCCL library/headers not found in Moore paths.")
267+
endif()
250268
else()
251269
message(STATUS "No suitable device environment, skipping MCCL detection.")
252270
endif()
@@ -372,8 +390,8 @@ if(WITH_NCCL)
372390
endif()
373391

374392
if(WITH_MCCL)
375-
if (NOT WITH_METAX)
376-
message(FATAL_ERROR "MCCL backend requires MetaX GPU support. Please enable `WITH_METAX`.")
393+
if (NOT WITH_METAX AND NOT WITH_MOORE)
394+
message(FATAL_ERROR "MCCL backend requires MetaX or Moore GPU support. Please enable `WITH_METAX` or `WITH_MOORE`.")
377395
endif()
378396

379397
set(_MCCL_HINTS)
@@ -385,6 +403,10 @@ if(WITH_MCCL)
385403
endif()
386404
list(APPEND _MCCL_HINTS /opt/maca)
387405

406+
if(WITH_MOORE)
407+
set(_MCCL_HINTS "${MUSA_ROOT}" /usr/local/musa)
408+
endif()
409+
388410
find_library(MCCL_LIB NAMES mccl HINTS ${_MCCL_HINTS} PATH_SUFFIXES lib lib64 REQUIRED)
389411
find_path(MCCL_INC NAMES mccl.h HINTS ${_MCCL_HINTS} PATH_SUFFIXES include REQUIRED)
390412

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export LD_LIBRARY_PATH=${INFINI_INSTALL}/lib:$LD_LIBRARY_PATH
354354
| **OpenMPI** | Full | `WITH_OMPI=ON` | The default backend. Requires the OpenMPI development package.|
355355
| **MPICH** | Full | `WITH_MPICH=ON` | Requires the MPICH development package.|
356356
| **NCCL** | Partial | `WITH_NCCL=ON` | Requires NVIDIA or Iluvatar NCCL. Currently available when `WITH_NVIDIA=ON` or `WITH_ILUVATAR=ON`.|
357-
| **MCCL** | Partial | `WITH_MCCL=ON` | Requires MetaX's MCCL. Currently only available when `WITH_METAX=ON`.|
357+
| **MCCL** | Partial | `WITH_MCCL=ON` | Requires MetaX or Moore MCCL. Currently available when `WITH_METAX=ON` or `WITH_MOORE=ON`.|
358358

359359
</details>
360360

‎examples/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ foreach(source_file ${EXAMPLE_SOURCES})
4343
if(WITH_MOORE)
4444
target_link_libraries(${target_name} PRIVATE ${MUSART_LIB})
4545
target_compile_options(${target_name} PRIVATE "-x" "musa")
46+
if(WITH_MCCL)
47+
target_compile_definitions(${target_name} PRIVATE INFINI_CCL_MCCL_BFLOAT16_UNSUPPORTED)
48+
endif()
4649
endif()
4750

4851
if(WITH_CAMBRICON)

‎src/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ if(WITH_MCCL)
243243
target_sources(infiniccl PRIVATE ${MCCL_SRCS})
244244
target_include_directories(infiniccl PRIVATE ${MCCL_INC})
245245
target_link_libraries(infiniccl PRIVATE ${MCCL_LIB})
246+
247+
if(WITH_MOORE)
248+
target_compile_definitions(infiniccl PRIVATE INFINI_CCL_MCCL_BFLOAT16_UNSUPPORTED)
249+
endif()
246250
endif()
247251

248252
# =========================================================

‎src/backend_device_map.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ template <>
2525
struct IsSupportedCombination<BackendType::kMccl, Device::Type::kMetax>
2626
: std::true_type {};
2727

28+
template <>
29+
struct IsSupportedCombination<BackendType::kMccl, Device::Type::kMoore>
30+
: std::true_type {};
31+
2832
}; // namespace infini::ccl
2933

3034
#endif // INFINI_CCL_BACKEND_DEVICE_MAP_H_

‎src/backends/ccl/mccl/moore/api.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef INFINI_CCL_BACKENDS_CCL_MCCL_MOORE_API_H_
2+
#define INFINI_CCL_BACKENDS_CCL_MCCL_MOORE_API_H_
3+
4+
#include "backends/ccl/mccl/api.h"
5+
#include "devices/moore/runtime_.h"
6+
7+
namespace infini::ccl {
8+
9+
template <>
10+
struct CclApi<BackendType::kMccl, Device::Type::kMoore>
11+
: McclApi<Device::Type::kMoore> {};
12+
13+
} // namespace infini::ccl
14+
15+
#endif // INFINI_CCL_BACKENDS_CCL_MCCL_MOORE_API_H_

‎src/backends/ccl/mccl/type_map.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
namespace infini::ccl {
1414

15+
#if defined(INFINI_CCL_MCCL_BFLOAT16_UNSUPPORTED)
16+
constexpr mcclDataType_t kMcclBFloat16Val = mcclNumTypes;
17+
#else
18+
constexpr mcclDataType_t kMcclBFloat16Val = mcclBfloat16;
19+
#endif
20+
1521
static const ConstexprMap<DataType, mcclDataType_t, 12> kMcclTypeMap{{{
1622
{DataType::kInt8, mcclInt8},
1723
{DataType::kInt16, mcclNumTypes},
@@ -24,7 +30,7 @@ static const ConstexprMap<DataType, mcclDataType_t, 12> kMcclTypeMap{{{
2430
{DataType::kFloat32, mcclFloat32},
2531
{DataType::kFloat64, mcclFloat64},
2632
{DataType::kFloat16, mcclFloat16},
27-
{DataType::kBFloat16, mcclBfloat16},
33+
{DataType::kBFloat16, kMcclBFloat16Val},
2834
}}};
2935

3036
static const ConstexprMap<ReductionOpType, mcclRedOp_t, 5> kMcclOpMap{{{

‎src/devices/moore/runtime_.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ struct Runtime<Device::Type::kMoore>
4646

4747
static constexpr auto Memset = musaMemset;
4848

49+
static constexpr auto GetDevice = [](auto &&...args) {
50+
return musaGetDevice(std::forward<decltype(args)>(args)...);
51+
};
52+
4953
static constexpr auto SetDevice = musaSetDevice;
5054

5155
static constexpr auto DeviceSynchronize = [](auto &&...args) {

0 commit comments

Comments
 (0)