Skip to content

Commit

Permalink
impl std with aclnn api for ascend
Browse files Browse the repository at this point in the history
  • Loading branch information
jingguo-st committed Jun 27, 2024
1 parent 1399f5f commit f962070
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions impl/ascend/convert_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,7 @@
- diopiMaxPool2dBackward:
tensor_dtype:
indices: (int64)->int32

- diopiStd:
dtype: (float64)->float32
layout: ND
26 changes: 26 additions & 0 deletions impl/ascend/functions/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @author DeepLink
* @copyright (c) 2023, DeepLink.
*/
#include <numeric>

#include "../aclnn/acl_scalar.hpp"
#include "../aclnn/adaptor.hpp"
Expand Down Expand Up @@ -52,6 +53,31 @@ diopiError_t diopiMean(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiC
return diopiSuccess;
}

diopiError_t diopiStd(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dim, bool unbiased) {
AscendTensor inputAt(input);
AscendTensor outAt(out);

bool keepdim = false;
if (inputAt.dim() == outAt.dim()) {
keepdim = true;
}

int64_t correction = 0;
if (unbiased) {
correction = 1;
}

if (dim.data == nullptr || dim.len == 0) {
std::vector<int64_t> allDim(inputAt.dim());
std::iota(allDim.begin(), allDim.end(), 0);
diopiSize_t rDim = vectorToDiopiSize(allDim);
DIOPI_ASCEND_CALL_ACLNN(aclnnStd, ctx, input, rDim, correction, keepdim, out);
} else {
DIOPI_ASCEND_CALL_ACLNN(aclnnStd, ctx, input, dim, correction, keepdim, out);
}
return diopiSuccess;
}

diopiError_t diopiAll(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const int64_t* dim) {
diopiSize_t inputSize, outSize;
diopiGetTensorShape(input, &inputSize);
Expand Down
1 change: 1 addition & 0 deletions impl/ascend_npu/ascend_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ ascend:
- diopiSqrt
- diopiSqrtInp
- diopiStack
- diopiStd
- diopiTanh
- diopiTanhBackward
- diopiTanhInp
Expand Down

0 comments on commit f962070

Please sign in to comment.