Skip to content

Commit

Permalink
move some defines from header to cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoguochun1995 committed Jan 17, 2024
1 parent 4f67034 commit 5f3acfa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 39 deletions.
39 changes: 0 additions & 39 deletions dipu/torch_dipu/csrc_dipu/vendor/ascend/basecommimpl.hpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,5 @@ struct Map {
}
};

// HCCL ReduceOp mapping
std::map<c10d::ReduceOp, HcclReduceOp> 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
18 changes: 18 additions & 0 deletions dipu/torch_dipu/csrc_dipu/vendor/ascend/communicatorimpl.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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<c10d::ReduceOp, HcclReduceOp> 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<std::pair<at::ScalarType, HcclDataType>, 9>
hcclDataTypes{{
Expand Down
12 changes: 12 additions & 0 deletions dipu/torch_dipu/csrc_dipu/vendor/ascend/deviceimpl.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#include <csrc_dipu/common.h>
#include <csrc_dipu/runtime/device/deviceapis.h>

#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;
Expand Down Expand Up @@ -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

0 comments on commit 5f3acfa

Please sign in to comment.