From cdf3933779e61b68395f6947ef458bbee3bbe22d Mon Sep 17 00:00:00 2001 From: Zimin Li Date: Wed, 24 Jun 2026 08:27:36 +0000 Subject: [PATCH 1/4] refactor: move NVIDIA's `nvidia/checks.h` to `cuda/checks.h` for code sharing among CUDA-alike platforms --- src/{nvidia => cuda}/checks.h | 6 +++--- src/nvidia/device_.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/{nvidia => cuda}/checks.h (85%) diff --git a/src/nvidia/checks.h b/src/cuda/checks.h similarity index 85% rename from src/nvidia/checks.h rename to src/cuda/checks.h index c42a4e6..4ef7e97 100644 --- a/src/nvidia/checks.h +++ b/src/cuda/checks.h @@ -1,5 +1,5 @@ -#ifndef INFINI_CCL_NVIDIA_CHECKS_H_ -#define INFINI_CCL_NVIDIA_CHECKS_H_ +#ifndef INFINI_CCL_CUDA_CHECKS_H_ +#define INFINI_CCL_CUDA_CHECKS_H_ #include @@ -29,4 +29,4 @@ inline ReturnStatus CheckCudaImpl(cudaError_t cuda_result, const char *file, } // namespace infini::ccl -#endif // INFINI_CCL_NVIDIA_CHECKS_H_ +#endif // INFINI_CCL_CUDA_CHECKS_H_ diff --git a/src/nvidia/device_.h b/src/nvidia/device_.h index f73b71c..a62b75d 100644 --- a/src/nvidia/device_.h +++ b/src/nvidia/device_.h @@ -3,7 +3,7 @@ #include -#include "checks.h" +#include "cuda/checks.h" #include "device.h" namespace infini::ccl { From c4154f38d5eac1a605e88085cedd1e8d08622f0f Mon Sep 17 00:00:00 2001 From: Zimin Li Date: Wed, 24 Jun 2026 08:28:30 +0000 Subject: [PATCH 2/4] feat: support `MemorySpace` on Iluvatar --- src/iluvatar/device_.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/iluvatar/device_.h b/src/iluvatar/device_.h index e736242..9c53f89 100644 --- a/src/iluvatar/device_.h +++ b/src/iluvatar/device_.h @@ -1,6 +1,9 @@ #ifndef INFINI_CCL_ILUVATAR_DEVICE__H_ #define INFINI_CCL_ILUVATAR_DEVICE__H_ +#include + +#include "cuda/checks.h" #include "device.h" namespace infini::ccl { @@ -8,6 +11,22 @@ namespace infini::ccl { template <> struct DeviceEnabled : std::true_type {}; +template <> +MemorySpace GetMemorySpace(const void* ptr) { + if (!ptr) { + return MemorySpace::kHost; + } + + cudaPointerAttributes attr; + INFINI_CHECK_CUDA(cudaPointerGetAttributes(&attr, ptr)); + + if (attr.type == cudaMemoryTypeDevice || attr.type == cudaMemoryTypeManaged) { + return MemorySpace::kDevice; + } + + return MemorySpace::kHost; +} + } // namespace infini::ccl #endif // INFINI_CCL_ILUVATAR_DEVICE__H_ From 12e9d952722bb6a08e93c0f17a3c9d61ac58961e Mon Sep 17 00:00:00 2001 From: Zimin Li Date: Thu, 25 Jun 2026 02:32:47 +0000 Subject: [PATCH 3/4] feat: support `MemorySpace` on Moore Threads --- src/moore/checks.h | 32 ++++++++++++++++++++++++++++++++ src/moore/device_.h | 19 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/moore/checks.h diff --git a/src/moore/checks.h b/src/moore/checks.h new file mode 100644 index 0000000..78008e3 --- /dev/null +++ b/src/moore/checks.h @@ -0,0 +1,32 @@ +#ifndef INFINI_CCL_MOORE_CHECKS_H_ +#define INFINI_CCL_MOORE_CHECKS_H_ + +#include + +#include + +#include "return_status_impl.h" + +#define INFINI_CHECK_MUSA(result) \ + ::infini::ccl::detail::CheckMusaImpl((result), __FILE__, __LINE__) + +namespace infini::ccl { + +namespace detail { + +inline ReturnStatus CheckMusaImpl(musaError_t musa_result, const char *file, + int line) { + if (musa_result != musaSuccess) { + musaGetLastError(); + std::cerr << "MUSA error code: " << musa_result << " at line " << line + << " in " << file << std::endl; + std::abort(); + } + return ReturnStatus::kSuccess; +} + +} // namespace detail + +} // namespace infini::ccl + +#endif // INFINI_CCL_MOORE_CHECKS_H_ diff --git a/src/moore/device_.h b/src/moore/device_.h index 35004f5..f700589 100644 --- a/src/moore/device_.h +++ b/src/moore/device_.h @@ -1,6 +1,9 @@ #ifndef INFINI_CCL_MOORE_DEVICE__H_ #define INFINI_CCL_MOORE_DEVICE__H_ +#include + +#include "checks.h" #include "device.h" namespace infini::ccl { @@ -8,6 +11,22 @@ namespace infini::ccl { template <> struct DeviceEnabled : std::true_type {}; +template <> +MemorySpace GetMemorySpace(const void* ptr) { + if (!ptr) { + return MemorySpace::kHost; + } + + musaPointerAttributes attr; + INFINI_CHECK_MUSA(musaPointerGetAttributes(&attr, ptr)); + + if (attr.type == musaMemoryTypeDevice || attr.type == musaMemoryTypeManaged) { + return MemorySpace::kDevice; + } + + return MemorySpace::kHost; +} + } // namespace infini::ccl #endif // INFINI_CCL_MOORE_DEVICE__H_ From 56fc65c6bb2697cab3759c35ce04db0000466036 Mon Sep 17 00:00:00 2001 From: Zimin Li Date: Thu, 25 Jun 2026 06:31:26 +0000 Subject: [PATCH 4/4] feat: support `MemorySpace` on Cambricon --- src/cambricon/checks.h | 32 ++++++++++++++++++++++++++++++++ src/cambricon/device_.h | 19 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/cambricon/checks.h diff --git a/src/cambricon/checks.h b/src/cambricon/checks.h new file mode 100644 index 0000000..218a11a --- /dev/null +++ b/src/cambricon/checks.h @@ -0,0 +1,32 @@ +#ifndef INFINI_CCL_CAMBRICON_CHECKS_H_ +#define INFINI_CCL_CAMBRICON_CHECKS_H_ + +#include + +#include + +#include "return_status_impl.h" + +#define INFINI_CHECK_CNRT(result) \ + ::infini::ccl::detail::CheckCnrtImpl((result), __FILE__, __LINE__) + +namespace infini::ccl { + +namespace detail { + +inline ReturnStatus CheckCnrtImpl(cnrtRet_t cnrt_result, const char *file, + int line) { + if (cnrt_result != cnrtSuccess) { + cnrtGetLastError(); + std::cerr << "CNRT error code: " << cnrt_result << " at line " << line + << " in " << file << std::endl; + std::abort(); + } + return ReturnStatus::kSuccess; +} + +} // namespace detail + +} // namespace infini::ccl + +#endif // INFINI_CCL_CAMBRICON_CHECKS_H_ diff --git a/src/cambricon/device_.h b/src/cambricon/device_.h index a905dcd..cb88b5c 100644 --- a/src/cambricon/device_.h +++ b/src/cambricon/device_.h @@ -1,6 +1,9 @@ #ifndef INFINI_CCL_CAMBRICON_DEVICE__H_ #define INFINI_CCL_CAMBRICON_DEVICE__H_ +#include + +#include "checks.h" #include "device.h" namespace infini::ccl { @@ -8,6 +11,22 @@ namespace infini::ccl { template <> struct DeviceEnabled : std::true_type {}; +template <> +MemorySpace GetMemorySpace(const void* ptr) { + if (!ptr) { + return MemorySpace::kHost; + } + + cnrtPointerAttributes_t attr; + INFINI_CHECK_CNRT(cnrtPointerGetAttributes(&attr, ptr)); + + if (attr.type == cnrtMemTypeDevice) { + return MemorySpace::kDevice; + } + + return MemorySpace::kHost; +} + } // namespace infini::ccl #endif // INFINI_CCL_CAMBRICON_DEVICE__H_