|
4 | 4 | * @copyright (c) 2023, DeepLink. |
5 | 5 | */ |
6 | 6 |
|
7 | | -#include <numeric> |
8 | | - |
9 | | -#include "../common/acloprunner.hpp" |
| 7 | +#include "../aclnn/acl_scalar.hpp" |
| 8 | +#include "../aclnn/adaptor.hpp" |
10 | 9 |
|
11 | 10 | namespace impl { |
12 | 11 | namespace ascend { |
13 | 12 | diopiError_t diopiMax(diopiContextHandle_t ctx, diopiTensorHandle_t max, diopiTensorHandle_t maxIndices, diopiConstTensorHandle_t input, int64_t dim) { |
14 | | - AclOpRunner<1, 2>("ArgMaxWithValue", ctx).setAttr<int>("dimension", static_cast<int>(dim)).addInput(input).addOutput(maxIndices).addOutput(max).run(); |
| 13 | + AscendTensor inAt(input); |
| 14 | + AscendTensor maxAt(max); |
| 15 | + bool keepdim = false; |
| 16 | + if (inAt.dim() == maxAt.dim()) { |
| 17 | + keepdim = true; |
| 18 | + } |
| 19 | + DIOPI_ASCEND_CALL_ACLNN(aclnnMaxDim, ctx, input, dim, keepdim, max, maxIndices); |
15 | 20 | return diopiSuccess; |
16 | 21 | } |
17 | 22 |
|
18 | 23 | diopiError_t diopiMaxAll(diopiContextHandle_t ctx, diopiTensorHandle_t max, diopiConstTensorHandle_t input) { |
19 | | - diopiSize_t inS; |
20 | | - diopiGetTensorShape(input, &inS); |
21 | | - std::vector<int64_t> dimAllVector(inS.len); |
22 | | - std::iota(std::begin(dimAllVector), std::end(dimAllVector), 0); |
23 | | - diopiSize_t dimAll = vectorToDiopiSize(dimAllVector); |
24 | | - AclOpRunner<2, 1>("ReduceMax", ctx).addInput(input).addConstInput(dimAll).addOutput(max).run(); |
| 24 | + DIOPI_ASCEND_CALL_ACLNN(aclnnMax, ctx, input, max); |
25 | 25 | return diopiSuccess; |
26 | 26 | } |
27 | 27 |
|
28 | 28 | diopiError_t diopiMin(diopiContextHandle_t ctx, diopiTensorHandle_t min, diopiTensorHandle_t minIndices, diopiConstTensorHandle_t input, int64_t dim) { |
29 | | - AclOpRunner<1, 2>("ArgMinWithValue", ctx).setAttr<int>("dimension", static_cast<int>(dim)).addInput(input).addOutput(minIndices).addOutput(min).run(); |
| 29 | + AscendTensor inAt(input); |
| 30 | + AscendTensor minAt(min); |
| 31 | + bool keepdim = false; |
| 32 | + if (inAt.dim() == minAt.dim()) { |
| 33 | + keepdim = true; |
| 34 | + } |
| 35 | + DIOPI_ASCEND_CALL_ACLNN(aclnnMinDim, ctx, input, dim, keepdim, min, minIndices); |
30 | 36 | return diopiSuccess; |
31 | 37 | } |
32 | 38 |
|
33 | 39 | diopiError_t diopiMinAll(diopiContextHandle_t ctx, diopiTensorHandle_t min, diopiConstTensorHandle_t input) { |
34 | | - diopiSize_t inS; |
35 | | - diopiGetTensorShape(input, &inS); |
36 | | - std::vector<int64_t> dimAllVector(inS.len); |
37 | | - std::iota(std::begin(dimAllVector), std::end(dimAllVector), 0); |
38 | | - diopiSize_t dimAll = vectorToDiopiSize(dimAllVector); |
39 | | - AclOpRunner<2, 1>("ReduceMin", ctx).addInput(input).addConstInput(dimAll).addOutput(min).run(); |
| 40 | + DIOPI_ASCEND_CALL_ACLNN(aclnnMin, ctx, input, min); |
40 | 41 | return diopiSuccess; |
41 | 42 | } |
42 | 43 |
|
|
0 commit comments