diff --git a/debug/accuracy_tools/msprobe/ccsrc/core/AclTensor.cpp b/debug/accuracy_tools/msprobe/ccsrc/core/AclTensor.cpp index 4a5ec4c555198015603d7cc1446be66fda05765d..40ba41d079914a0e0c7a69946c17ad09efb99a1f 100644 --- a/debug/accuracy_tools/msprobe/ccsrc/core/AclTensor.cpp +++ b/debug/accuracy_tools/msprobe/ccsrc/core/AclTensor.cpp @@ -394,7 +394,7 @@ static DebuggerErrno FRAC_Z_TO_NCHW_WITH_GROUPS(AclTensorInfo& tensor) auto coutOpt = AlignCeil(eMult * coutOri, kCubeSize); auto c1Dim = cinOpt / cubeK; const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t g = 0; g < groups; ++g) { @@ -412,7 +412,8 @@ static DebuggerErrno FRAC_Z_TO_NCHW_WITH_GROUPS(AclTensorInfo& tensor) w * coutOpt * cubeK + dstCo * cubeK + temporary; int64_t hstIdx = srcCo * cDim * hDim * wDim + c * hDim * wDim + h * wDim + w; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + hstIdx * dtypeSize, src + devIdx * dtypeSize, dtypeSize); + std::copy(src + devIdx * dtypeSize, src + devIdx * dtypeSize + dtypeSize, + dst + hstIdx * dtypeSize); } } } @@ -450,7 +451,7 @@ static DebuggerErrno FRAC_Z_TO_NCHW(AclTensorInfo& tensor) } const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t nIdx = 0; nIdx < n; nIdx++) { int64_t nHeadAddr = nIdx * chw; @@ -465,7 +466,8 @@ static DebuggerErrno FRAC_Z_TO_NCHW(AclTensorInfo& tensor) auto ncIdx = nIdx; auto srcIdx = c1Idx * hwncc0 + hIdx * wncc0 + wIdx * ncc0 + ncIdx * c0 + c0Idx; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, + dst + dstIdx * dtypeSize); } } } @@ -518,7 +520,7 @@ static DebuggerErrno FRAC_NZ_TO_NCHW(AclTensorInfo& tensor) auto numW1 = w / w0; const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t timesIdx = 0; timesIdx < times; timesIdx++) { @@ -532,7 +534,8 @@ static DebuggerErrno FRAC_NZ_TO_NCHW(AclTensorInfo& tensor) int64_t srcIdx = h1h0Head + w1Idx * h1h0w0 + i; int64_t dstIdx = srcHHead + w1Idx * w0 + i; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, + dst + dstIdx * dtypeSize); } } auto w1Head = numW1 * w0; @@ -541,7 +544,7 @@ static DebuggerErrno FRAC_NZ_TO_NCHW(AclTensorInfo& tensor) int64_t srcIdx = h1h0Head + numW1 * h1h0w0 + w0Idx; int64_t dstIdx = srcHHead + srcWIdx; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, dst + dstIdx * dtypeSize); } } } @@ -568,7 +571,7 @@ static DebuggerErrno NC1HWC0_TO_NCHW(AclTensorInfo& tensor) auto c1hwc0 = c1 * hwc0; const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t nIndex = 0; nIndex < n; nIndex++) { int64_t nHeadAddr = nIndex * chw; @@ -582,7 +585,8 @@ static DebuggerErrno NC1HWC0_TO_NCHW(AclTensorInfo& tensor) int64_t c0Index = cIndex % c0; int64_t srcIdx = nIndex * c1hwc0 + c1Index * hwc0 + hIndex * wc0 + wIndex * c0 + c0Index; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, + dst + dstIdx * dtypeSize); } } } @@ -613,7 +617,7 @@ static DebuggerErrno NDC1HWC0_TO_NCDHW(AclTensorInfo& tensor) const int64_t wc0 = w * c0; const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t nIndex = 0; nIndex < n; nIndex++) { int64_t nHead = nIndex * cdhw; @@ -630,7 +634,8 @@ static DebuggerErrno NDC1HWC0_TO_NCDHW(AclTensorInfo& tensor) auto srcIdx = nIndex * dc1hwc0 + dIndex * c1hwc0 + c1Index * hwc0 + hIndex * wc0 + wIndex * c0 + c0Index; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, + dst + dstIdx * dtypeSize); } } } @@ -656,7 +661,7 @@ static DebuggerErrno C1HWNCoC0_TO_NCHW(AclTensorInfo& tensor) auto cubeK = GetCubeSizeByType(tensor.dtype); const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t nIndex = 0; nIndex < n; nIndex++) { for (int64_t cIndex = 0; cIndex < c; cIndex++) { @@ -669,7 +674,8 @@ static DebuggerErrno C1HWNCoC0_TO_NCHW(AclTensorInfo& tensor) int64_t srcIdx = c1Index * h * w * n * co * c0 + hIndex * w * n * co * c0 + wIndex * n * co * c0 + nIndex * co * c0 + coIndex * c0 + c0Index; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, + dst + dstIdx * dtypeSize); } } } @@ -708,7 +714,7 @@ static DebuggerErrno FRAC_Z3D_TO_NCDHW(AclTensorInfo& tensor) auto cdhw = c * dhw; const uint8_t* src = tensor.aclData; - uint8_t* dst = tensor.transBuf.data(); + auto dst = tensor.transBuf.begin(); auto dtypeSize = SizeOfAclDType(tensor); for (int64_t nIdx = 0; nIdx < n; nIdx++) { int64_t nHead = nIdx * cdhw; @@ -726,7 +732,8 @@ static DebuggerErrno FRAC_Z3D_TO_NCDHW(AclTensorInfo& tensor) int64_t srcIdx = dIdx * c1hwn1n0c0 + c1I * c1hwn1n0c0 + hIdx * wn1n0c0 + wI * n1n0c0 + ncIdx * c0 + c0I; /* 此处由偏移计算逻辑保障不会越界读写 */ - std::memcpy(dst + dstIdx * dtypeSize, src + srcIdx * dtypeSize, dtypeSize); + std::copy(src + srcIdx * dtypeSize, src + srcIdx * dtypeSize + dtypeSize, + dst + dstIdx * dtypeSize); } } } diff --git a/debug/accuracy_tools/msprobe/ccsrc/utils/DataUtils.cpp b/debug/accuracy_tools/msprobe/ccsrc/utils/DataUtils.cpp index c2d7df85294f7c96f0fe1a1b9458dfd2ad2e502c..ca7d9118d9c0a9fa78abde437073ff27e19ff202 100644 --- a/debug/accuracy_tools/msprobe/ccsrc/utils/DataUtils.cpp +++ b/debug/accuracy_tools/msprobe/ccsrc/utils/DataUtils.cpp @@ -56,10 +56,15 @@ BFloat16::BFloat16(float f32) BFloat16::operator float() const { - float f32 = 0; - uint32_t tmp = value_; - tmp <<= 16; - std::memcpy(&f32, &tmp, sizeof(f32)); + /* 为了兼容性,不要用c++20的bit_cast */ + union + { + float f32; + uint32_t ui32; + }; + + ui32 = static_cast(value_); + ui32 <<= 16; return f32; }