From 5f3acface81f9c4e15c9d85320e1bf53a793de37 Mon Sep 17 00:00:00 2001 From: zhaoguochun1995 Date: Wed, 17 Jan 2024 12:13:31 +0800 Subject: [PATCH] move some defines from header to cpp --- .../csrc_dipu/vendor/ascend/basecommimpl.hpp | 39 ------------------- .../vendor/ascend/communicatorimpl.cpp | 18 +++++++++ .../csrc_dipu/vendor/ascend/deviceimpl.cpp | 12 ++++++ 3 files changed, 30 insertions(+), 39 deletions(-) mode change 100644 => 100755 dipu/torch_dipu/csrc_dipu/vendor/ascend/basecommimpl.hpp mode change 100644 => 100755 dipu/torch_dipu/csrc_dipu/vendor/ascend/communicatorimpl.cpp mode change 100644 => 100755 dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp diff --git a/dipu/torch_dipu/csrc_dipu/vendor/ascend/basecommimpl.hpp b/dipu/torch_dipu/csrc_dipu/vendor/ascend/basecommimpl.hpp old mode 100644 new mode 100755 index d39535bbe..d789e8497 --- a/dipu/torch_dipu/csrc_dipu/vendor/ascend/basecommimpl.hpp +++ b/dipu/torch_dipu/csrc_dipu/vendor/ascend/basecommimpl.hpp @@ -27,44 +27,5 @@ struct Map { } }; -// HCCL ReduceOp mapping -std::map hcclOp = { - {ReduceOp::MIN, HCCL_REDUCE_MIN}, - {ReduceOp::MAX, HCCL_REDUCE_MAX}, - {ReduceOp::SUM, HCCL_REDUCE_SUM}, - {ReduceOp::PRODUCT, HCCL_REDUCE_PROD}, -}; - -bool isPinnedPtr(const void* p) { - TORCH_CHECK(false, "isPinnedPtr not implemented for ascend.\n"); - return false; -} - -#define TRACK_FUN_CALL(TAG, x) \ - { \ - static bool enable = std::getenv("DIPU_TRACK_" #TAG) != nullptr; \ - if (enable) { \ - printf("[%d %s: %d]:%s\n", getpid(), __FILE__, __LINE__, x); \ - } \ - } - -#define DIPU_CALLACLRT(Expr) \ - { \ - TRACK_FUN_CALL(ACL, #Expr); \ - ::aclError ret = Expr; \ - TORCH_CHECK(ret == ACL_SUCCESS, "ascend device error, expr = ", #Expr, \ - ", ret = ", ret, ", error msg = ", aclGetRecentErrMsg()); \ - } - -#define HCCL_THROW(cmd) \ - do { \ - TRACK_FUN_CALL(HCCL, #cmd) \ - TORCH_CHECK(cmd == HCCL_SUCCESS, \ - "HCCL error in: " + std::string(__FILE__) + ":" + \ - std::to_string(__LINE__) + ".\n" + \ - "And see details in Ascend logs.\n" + \ - aclGetRecentErrMsg()); \ - } while (0) - } // namespace devapis } // namespace dipu diff --git a/dipu/torch_dipu/csrc_dipu/vendor/ascend/communicatorimpl.cpp b/dipu/torch_dipu/csrc_dipu/vendor/ascend/communicatorimpl.cpp old mode 100644 new mode 100755 index 4f70f59bc..206a932f9 --- a/dipu/torch_dipu/csrc_dipu/vendor/ascend/communicatorimpl.cpp +++ b/dipu/torch_dipu/csrc_dipu/vendor/ascend/communicatorimpl.cpp @@ -1,8 +1,26 @@ #include "basecommimpl.hpp" + +#define HCCL_THROW(cmd) \ + do { \ + TORCH_CHECK(cmd == HCCL_SUCCESS, \ + "HCCL error in: " + std::string(__FILE__) + ":" + \ + std::to_string(__LINE__) + ".\n" + \ + "And see details in Ascend logs.\n" + \ + aclGetRecentErrMsg()); \ + } while (0) + namespace dipu { namespace devapis { +// HCCL ReduceOp mapping +static std::map hcclOp = { + {ReduceOp::MIN, HCCL_REDUCE_MIN}, + {ReduceOp::MAX, HCCL_REDUCE_MAX}, + {ReduceOp::SUM, HCCL_REDUCE_SUM}, + {ReduceOp::PRODUCT, HCCL_REDUCE_PROD}, +}; + // HCCL DataType mapping static constexpr std::array, 9> hcclDataTypes{{ diff --git a/dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp b/dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp old mode 100644 new mode 100755 index 996dc735f..09c3b614c --- a/dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp +++ b/dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp @@ -6,6 +6,13 @@ #include #include +#define DIPU_CALLACLRT(Expr) \ + { \ + ::aclError ret = Expr; \ + TORCH_CHECK(ret == ACL_SUCCESS, "ascend device error, expr = ", #Expr, \ + ", ret = ", ret, ", error msg = ", aclGetRecentErrMsg()); \ + } + namespace dipu { DIPU_API devapis::VendorDeviceType VENDOR_TYPE = devapis::VendorDeviceType::NPU; @@ -253,5 +260,10 @@ void destroyEvent(deviceEvent_t event) { DIPU_CALLACLRT(::aclrtDestroyEvent(event)) } +bool isPinnedPtr(const void* p) { + TORCH_CHECK(false, "isPinnedPtr not implemented for ascend.\n"); + return false; +} + } // end namespace devapis } // end namespace dipu