From 5fd1071da88b5457213620e7685445b8989391e0 Mon Sep 17 00:00:00 2001 From: Zhangzefeng Date: Wed, 11 Oct 2023 15:54:29 +0800 Subject: [PATCH] zzf/add adaptor (#440) * add adaptor --- .../python/conformance/conformance_test.py | 5 +- impl/ascend/CMakeLists.txt | 32 ++++++---- impl/ascend/common/acloprunner.hpp | 8 +-- impl/ascend/common/debug.hpp | 3 +- impl/ascend/common/generator_helper.cpp | 3 +- impl/ascend/convert_config.yaml | 0 impl/ascend/functions/activation.cpp | 60 +++++++++---------- impl/ascend/functions/addcdiv.cpp | 14 ++--- impl/ascend/functions/addcmul.cpp | 14 ++--- impl/ascend/functions/arange.cpp | 5 +- impl/ascend/functions/argmax.cpp | 4 +- impl/ascend/functions/batch_norm.cpp | 18 +++--- impl/ascend/functions/binary.cpp | 59 ++++++++---------- impl/ascend/functions/bitwise.cpp | 10 +--- impl/ascend/functions/bmm.cpp | 4 +- impl/ascend/functions/cast.cpp | 39 +++++++++--- impl/ascend/functions/cat.cpp | 6 +- impl/ascend/functions/clamp.cpp | 17 +++--- impl/ascend/functions/contiguous.cpp | 20 +++++++ impl/ascend/functions/conv2d.cpp | 13 ++-- impl/ascend/functions/copy.cpp | 7 +-- impl/ascend/functions/cos.cpp | 6 -- impl/ascend/functions/cumsum.cpp | 2 - impl/ascend/functions/dropout.cpp | 9 +-- impl/ascend/functions/embedding.cpp | 13 ++-- impl/ascend/functions/error.cpp | 3 +- impl/ascend/functions/fill.cpp | 6 -- impl/ascend/functions/flip.cpp | 6 +- impl/ascend/functions/floor.cpp | 8 +-- impl/ascend/functions/gather.cpp | 7 +-- impl/ascend/functions/index.cpp | 7 +-- impl/ascend/functions/interpolate.cpp | 14 ++--- impl/ascend/functions/layer_norm.cpp | 17 ++---- impl/ascend/functions/linear.cpp | 11 ++-- impl/ascend/functions/logic.cpp | 6 -- impl/ascend/functions/loss.cpp | 32 ++++------ impl/ascend/functions/masked_fill.cpp | 5 -- impl/ascend/functions/minmax.cpp | 14 ++--- impl/ascend/functions/mm.cpp | 4 +- impl/ascend/functions/multinomial.cpp | 8 +-- impl/ascend/functions/nonzero.cpp | 6 +- impl/ascend/functions/norm.cpp | 7 +-- impl/ascend/functions/one_hot.cpp | 6 +- impl/ascend/functions/pool.cpp | 10 +--- impl/ascend/functions/pow.cpp | 6 -- impl/ascend/functions/reduce.cpp | 6 +- impl/ascend/functions/repeat.cpp | 6 -- impl/ascend/functions/sgn.cpp | 6 -- impl/ascend/functions/sin.cpp | 5 -- impl/ascend/functions/sort.cpp | 8 +-- impl/ascend/functions/stack.cpp | 6 +- impl/ascend/functions/threshold.cpp | 16 ++--- impl/ascend/functions/topk.cpp | 8 +-- impl/ascend/functions/transpose.cpp | 8 +-- impl/ascend/functions/tril.cpp | 8 +-- impl/ascend/functions/triu.cpp | 9 +-- impl/ascend/functions/unary.cpp | 37 +++++------- impl/ascend/functions/upsample.cpp | 10 +--- impl/ascend/functions/where.cpp | 8 +-- impl/ascend/test/conform_test.cpp | 5 +- 60 files changed, 265 insertions(+), 435 deletions(-) create mode 100644 impl/ascend/convert_config.yaml create mode 100644 impl/ascend/functions/contiguous.cpp diff --git a/diopi_test/python/conformance/conformance_test.py b/diopi_test/python/conformance/conformance_test.py index 10304780d..a8b97e15d 100644 --- a/diopi_test/python/conformance/conformance_test.py +++ b/diopi_test/python/conformance/conformance_test.py @@ -23,7 +23,10 @@ def convert_input_tensors(function_paras: dict, test_tag: list, nhwc_list=[], dt if glob_vars.four_bytes and (para in dtype_list) \ and tensor is not None and tensor.dtype == np.int64: tensor = tensor.astype(np.int32) - if isinstance(function_paras['kwargs'][para], np.ndarray): + + if isinstance(tensor, Tensor): + tensor = tensor.numpy() + if isinstance(tensor, np.ndarray): ndim = tensor.ndim if glob_vars.nhwc and (para in nhwc_list): if ndim < glob_vars.nhwc_min_dim or ndim > 5: diff --git a/impl/ascend/CMakeLists.txt b/impl/ascend/CMakeLists.txt index 789a195ac..efc6b05d2 100755 --- a/impl/ascend/CMakeLists.txt +++ b/impl/ascend/CMakeLists.txt @@ -23,21 +23,33 @@ endif() file(GLOB_RECURSE IMPL_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functions/*.cpp common/*.cpp) list(APPEND IMPL_SRC ascend_tensor.cpp) +# adaptor +set(USE_ADAPTOR OFF) +if(EXISTS "${PROJECT_SOURCE_DIR}/convert_config.yaml") + set(USE_ADAPTOR ON) +endif() + +if(USE_ADAPTOR) + + file(GLOB ADAPTOR_TEMPLATE_CODE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${ADAPTOR_DIR}/codegen/*.py) + add_custom_target(adaptor_gen_dependency DEPENDS ${ADAPTOR_TEMPLATE_CODE}) + + set(ADAPTOR_CSRC_PATH "${ADAPTOR_DIR}/csrc") + set(GEN_FILES ${ADAPTOR_CSRC_PATH}/diopi_adaptor.cpp ${ADAPTOR_CSRC_PATH}/impl_functions.hpp) + add_custom_target(adaptor_code_gen + COMMAND python3 ${ADAPTOR_DIR}/codegen/gen.py --diopi_dir=${CMAKE_SOURCE_DIR}/../ --output_dir=${ADAPTOR_CSRC_PATH} --config_device=ascend + BYPRODUCTS ${GEN_FILES} + DEPENDS adaptor_gen_dependency) + list(APPEND IMPL_SRC ${GEN_FILES} ${ADAPTOR_CSRC_PATH}/convert.cpp ${ADAPTOR_CSRC_PATH}/diopi_adaptor.cpp) + add_definitions(-DTEST_USE_ADAPTOR) +endif() + add_library(${DEVICEIMPL} SHARED ${IMPL_SRC}) set_target_properties(${DEVICEIMPL} PROPERTIES SUFFIX ".so") - target_link_libraries(${DEVICEIMPL} ascendcl acl_op_compiler) -if(EXISTS "${PROJECT_SOURCE_DIR}/convert_config.yaml") - set(ADAPTOR_GEN_PATH "${CMAKE_SOURCE_DIR}/../adaptor/codegen") - add_custom_target(adaptor_code_gen COMMAND python3 ${ADAPTOR_GEN_PATH}/gen.py - --diopi_dir=${CMAKE_SOURCE_DIR}/../ --output_dir=${ADAPTOR_GEN_PATH}/../csrc/ - --config_device=ascend) - set(USE_ADAPTOR "true") +if(USE_ADAPTOR) add_dependencies(${DEVICEIMPL} adaptor_code_gen) - add_definitions(-DTEST_USE_ADAPTOR) -else() - set(USE_ADAPTOR "false") endif() if (TEST) diff --git a/impl/ascend/common/acloprunner.hpp b/impl/ascend/common/acloprunner.hpp index b70efff0a..f8e02acc4 100755 --- a/impl/ascend/common/acloprunner.hpp +++ b/impl/ascend/common/acloprunner.hpp @@ -1,10 +1,6 @@ #ifndef IMPL_ASCEND_COMMON_ACLOPRUNNER_HPP_ #define IMPL_ASCEND_COMMON_ACLOPRUNNER_HPP_ -#include -#include -#include -#include #include #include @@ -21,7 +17,11 @@ #include #include "../ascend_tensor.hpp" +#include "acl/acl.h" +#include "acl/acl_op.h" +#include "acl/acl_op_compiler.h" #include "debug.hpp" +#include "impl_functions.hpp" #include "utils.hpp" namespace impl { diff --git a/impl/ascend/common/debug.hpp b/impl/ascend/common/debug.hpp index 1a574d042..2eab540b7 100644 --- a/impl/ascend/common/debug.hpp +++ b/impl/ascend/common/debug.hpp @@ -7,13 +7,12 @@ #ifndef IMPL_ASCEND_COMMON_DEBUG_HPP_ #define IMPL_ASCEND_COMMON_DEBUG_HPP_ -#include - #include #include #include #include "../ascend_tensor.hpp" +#include "impl_functions.hpp" namespace impl { namespace ascend { diff --git a/impl/ascend/common/generator_helper.cpp b/impl/ascend/common/generator_helper.cpp index 65ca2e48f..f882ce9d6 100644 --- a/impl/ascend/common/generator_helper.cpp +++ b/impl/ascend/common/generator_helper.cpp @@ -4,11 +4,10 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "acloprunner.hpp" +#include "impl_functions.hpp" namespace impl { namespace ascend { diff --git a/impl/ascend/convert_config.yaml b/impl/ascend/convert_config.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/impl/ascend/functions/activation.cpp b/impl/ascend/functions/activation.cpp index 43fd3bf24..52cd5dcd8 100644 --- a/impl/ascend/functions/activation.cpp +++ b/impl/ascend/functions/activation.cpp @@ -4,46 +4,44 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiRelu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { + +diopiError_t diopiRelu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Relu", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiReluInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { +diopiError_t diopiReluInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { AclOpRunner<1, 1>("Relu", ctx).addInput(input).addOutput(input).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiSoftmax(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim) { +diopiError_t diopiSoftmax(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim) { std::vector dimList = {dim}; AclOpRunner<1, 1>("SoftmaxV2", ctx).addInput(input).setAttr("axes", dimList).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiSoftmaxBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t output, int64_t dim) { +diopiError_t diopiSoftmaxBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t output, + int64_t dim) { std::vector dimList = {dim}; AclOpRunner<2, 1>("SoftmaxGrad", ctx).addInput(output).addInput(gradOutput).setAttr("axes", dimList).addOutput(gradInput).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiLogSoftmax(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim) { +diopiError_t diopiLogSoftmax(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim) { std::vector dimList = {dim}; AclOpRunner<1, 1>("LogSoftmaxV2", ctx).addInput(input).setAttr("axes", dimList).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiLogSoftmaxBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t output, int64_t dim) { +diopiError_t diopiLogSoftmaxBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, + diopiConstTensorHandle_t output, int64_t dim) { diopiSize_t sumSize; diopiGetTensorShape(gradOutput, &sumSize); std::vector sumSizeVec(sumSize.data, sumSize.data + sumSize.len); @@ -67,15 +65,14 @@ DIOPI_API diopiError_t diopiLogSoftmaxBackward(diopiContextHandle_t ctx, diopiTe return diopiSuccess; } -DIOPI_API diopiError_t diopiSilu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiSilu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Swish", ctx).addInput(input).setAttr("scale", 1.0).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiSiluInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiSilu(ctx, input, input); } +diopiError_t diopiSiluInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiSilu(ctx, input, input); } -DIOPI_API diopiError_t diopiSiluBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input) { +diopiError_t diopiSiluBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input) { diopiTensorHandle_t out; makeTensorLike(ctx, &out, input); diopiSilu(ctx, out, input); @@ -83,7 +80,7 @@ DIOPI_API diopiError_t diopiSiluBackward(diopiContextHandle_t ctx, diopiTensorHa return diopiSuccess; } -DIOPI_API diopiError_t diopiSigmoid(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiSigmoid(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Sigmoid", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } @@ -96,28 +93,28 @@ DIOPI_API diopiError_t diopiSigmoidBackward(diopiContextHandle_t ctx, diopiTenso return diopiSuccess; } -DIOPI_API diopiError_t diopiGelu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const char* approximate) { +diopiError_t diopiGelu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const char* approximate) { AclOpRunner<1, 1>("Gelu", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiGeluBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, const char* approximate) { +diopiError_t diopiGeluBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, + const char* approximate) { AclOpRunner<3, 1>("GeluGrad", ctx).addInput(gradOutput).addInput(input).addInput(gradOutput).addOutput(gradInput).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiLeakyRelu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* negativeSlope) { +diopiError_t diopiLeakyRelu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* negativeSlope) { AclOpRunner<1, 1>("LeakyRelu", ctx).addInput(input).setAttr("negative_slope", getValue(negativeSlope)).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiLeakyReluInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* negativeSlope) { +diopiError_t diopiLeakyReluInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* negativeSlope) { return diopiLeakyRelu(ctx, input, input, negativeSlope); } -DIOPI_API diopiError_t diopiLeakyReluBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, const diopiScalar_t* negativeSlope, bool inputIsResult) { +diopiError_t diopiLeakyReluBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, + diopiConstTensorHandle_t input, const diopiScalar_t* negativeSlope, bool inputIsResult) { AclOpRunner<2, 1>("LeakyReluGrad", ctx) .addInput(gradOutput) .addInput(input) @@ -127,19 +124,18 @@ DIOPI_API diopiError_t diopiLeakyReluBackward(diopiContextHandle_t ctx, diopiTen return diopiSuccess; } -DIOPI_API diopiError_t diopiTanh(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiTanh(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Tanh", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiTanhBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t output) { +diopiError_t diopiTanhBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t output) { AclOpRunner<2, 1>("TanhGrad", ctx).addInput(output).addInput(gradOutput).addOutput(gradInput).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiHardtanh(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* minVal, - const diopiScalar_t* maxVal) { +diopiError_t diopiHardtanh(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* minVal, + const diopiScalar_t* maxVal) { diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); diopiScalar_t min = *minVal; @@ -156,12 +152,12 @@ DIOPI_API diopiError_t diopiHardtanh(diopiContextHandle_t ctx, diopiTensorHandle return diopiSuccess; } -DIOPI_API diopiError_t diopiHardtanhInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* minVal, const diopiScalar_t* maxVal) { +diopiError_t diopiHardtanhInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* minVal, const diopiScalar_t* maxVal) { return diopiHardtanh(ctx, input, input, minVal, maxVal); } -DIOPI_API diopiError_t diopiHardtanhBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, const diopiScalar_t* minVal, const diopiScalar_t* maxVal) { +diopiError_t diopiHardtanhBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, + const diopiScalar_t* minVal, const diopiScalar_t* maxVal) { diopiDtype_t inDtype; diopiGetTensorDtype(input, &inDtype); std::set supportDtypes{diopi_dtype_float16, diopi_dtype_float32}; @@ -192,6 +188,6 @@ DIOPI_API diopiError_t diopiHardtanhBackward(diopiContextHandle_t ctx, diopiTens } return diopiSuccess; } -} + } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/addcdiv.cpp b/impl/ascend/functions/addcdiv.cpp index f61bf6588..86b15c4d8 100644 --- a/impl/ascend/functions/addcdiv.cpp +++ b/impl/ascend/functions/addcdiv.cpp @@ -4,17 +4,13 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiAddcdiv(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t tensor1, - diopiConstTensorHandle_t tensor2, const diopiScalar_t* value) { +diopiError_t diopiAddcdiv(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t tensor1, + diopiConstTensorHandle_t tensor2, const diopiScalar_t* value) { diopiTensorHandle_t trOther = nullptr; diopiDtype_t dtype; diopiGetTensorDtype(out, &dtype); @@ -23,12 +19,10 @@ DIOPI_API diopiError_t diopiAddcdiv(diopiContextHandle_t ctx, diopiTensorHandle_ return diopiSuccess; } -DIOPI_API diopiError_t diopiAddcdivInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t tensor1, diopiConstTensorHandle_t tensor2, - const diopiScalar_t* value) { +diopiError_t diopiAddcdivInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t tensor1, diopiConstTensorHandle_t tensor2, + const diopiScalar_t* value) { return diopiAddcdiv(ctx, input, input, tensor1, tensor2, value); } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/addcmul.cpp b/impl/ascend/functions/addcmul.cpp index c05bd4b16..d697fbd07 100644 --- a/impl/ascend/functions/addcmul.cpp +++ b/impl/ascend/functions/addcmul.cpp @@ -4,17 +4,13 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiAddcmul(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t tensor1, - diopiConstTensorHandle_t tensor2, const diopiScalar_t* value) { +diopiError_t diopiAddcmul(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t tensor1, + diopiConstTensorHandle_t tensor2, const diopiScalar_t* value) { diopiTensorHandle_t trOther = nullptr; diopiDtype_t dtype; diopiGetTensorDtype(out, &dtype); @@ -23,12 +19,10 @@ DIOPI_API diopiError_t diopiAddcmul(diopiContextHandle_t ctx, diopiTensorHandle_ return diopiSuccess; } -DIOPI_API diopiError_t diopiAddcmulInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t tensor1, diopiConstTensorHandle_t tensor2, - const diopiScalar_t* value) { +diopiError_t diopiAddcmulInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t tensor1, diopiConstTensorHandle_t tensor2, + const diopiScalar_t* value) { return diopiAddcmul(ctx, input, input, tensor1, tensor2, value); } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/arange.cpp b/impl/ascend/functions/arange.cpp index 106bc881e..0cde09e42 100644 --- a/impl/ascend/functions/arange.cpp +++ b/impl/ascend/functions/arange.cpp @@ -4,15 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" DIOPI_API diopiError_t diopiArange(diopiContextHandle_t ctx, diopiTensorHandle_t out, const diopiScalar_t* start, const diopiScalar_t* end, - const diopiScalar_t* step) { +diopiError_t diopiArange(diopiContextHandle_t ctx, diopiTensorHandle_t out, const diopiScalar_t* start, const diopiScalar_t* end, const diopiScalar_t* step) { AclOpRunner<3, 1>("Range", ctx).addConstInput(*start).addConstInput(*end).addConstInput(*step).addOutput(out).run(); return diopiSuccess; } diff --git a/impl/ascend/functions/argmax.cpp b/impl/ascend/functions/argmax.cpp index 3ae92e7b5..f0cd5cbc8 100644 --- a/impl/ascend/functions/argmax.cpp +++ b/impl/ascend/functions/argmax.cpp @@ -4,14 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" diopiError_t diopiArgmax(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const int64_t* dim, bool keepdim) { +diopiError_t diopiArgmax(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const int64_t* dim, bool keepdim) { AclOpRunner<2, 1>("ArgMaxV2", ctx).addInput(input).addConstInput(*dim, diopi_dtype_int64).setAttr("keep_dims", keepdim).addOutput(out).run(); return diopiSuccess; } diff --git a/impl/ascend/functions/batch_norm.cpp b/impl/ascend/functions/batch_norm.cpp index b1f5e3f9f..e056fc9bc 100644 --- a/impl/ascend/functions/batch_norm.cpp +++ b/impl/ascend/functions/batch_norm.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { @@ -50,10 +48,9 @@ void batchNormBackwardTrainingReduceNocheck(diopiContextHandle_t ctx, diopiTenso .run(); } -extern "C" DIOPI_API diopiError_t diopiBatchNorm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiTensorHandle_t saveMean, - diopiTensorHandle_t saveInvstd, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, - diopiConstTensorHandle_t bias, diopiTensorHandle_t runningMean, diopiTensorHandle_t runningVar, bool training, - double momentum, double eps) { +diopiError_t diopiBatchNorm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiTensorHandle_t saveMean, diopiTensorHandle_t saveInvstd, + diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, diopiConstTensorHandle_t bias, diopiTensorHandle_t runningMean, + diopiTensorHandle_t runningVar, bool training, double momentum, double eps) { if (!training) { AclOpRunner<5, 1>("BNInfer", ctx) .addInput(input) @@ -92,11 +89,10 @@ extern "C" DIOPI_API diopiError_t diopiBatchNorm(diopiContextHandle_t ctx, diopi return diopiSuccess; } -extern "C" DIOPI_API diopiError_t diopiBatchNormBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, - diopiTensorHandle_t gradBias, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, - diopiConstTensorHandle_t weight, diopiConstTensorHandle_t runninMean, - diopiConstTensorHandle_t runningVar, diopiConstTensorHandle_t saveMean, - diopiConstTensorHandle_t saveInvstd, bool training, double eps) { +diopiError_t diopiBatchNormBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, diopiTensorHandle_t gradBias, + diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, + diopiConstTensorHandle_t runninMean, diopiConstTensorHandle_t runningVar, diopiConstTensorHandle_t saveMean, + diopiConstTensorHandle_t saveInvstd, bool training, double eps) { if (!training) { batchNormBackwardTrainingUpdate(ctx, gradWeight, gradBias, gradOutput, input, runninMean, runningVar, eps); AclOpRunner<3, 1>("BNInferGrad", ctx) diff --git a/impl/ascend/functions/binary.cpp b/impl/ascend/functions/binary.cpp index 6524f2fcb..fc95d91d6 100755 --- a/impl/ascend/functions/binary.cpp +++ b/impl/ascend/functions/binary.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -32,9 +30,8 @@ bool isScalarOne(const diopiScalar_t* alpha) { } } -extern "C" { -DIOPI_API diopiError_t diopiAdd(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, - const diopiScalar_t* alpha) { +diopiError_t diopiAdd(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, + const diopiScalar_t* alpha) { diopiDtype_t outDtype, inputDtype, otherDtype; diopiGetTensorDtype(out, &outDtype); diopiGetTensorDtype(input, &inputDtype); @@ -70,12 +67,12 @@ DIOPI_API diopiError_t diopiAdd(diopiContextHandle_t ctx, diopiTensorHandle_t ou return diopiSuccess; } -extern "C" DIOPI_API diopiError_t diopiAddInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other, const diopiScalar_t* alpha) { +diopiError_t diopiAddInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other, const diopiScalar_t* alpha) { return diopiAdd(ctx, input, input, other, alpha); } -extern "C" DIOPI_API diopiError_t diopiAddScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other, - const diopiScalar_t* alpha) { +diopiError_t diopiAddScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other, + const diopiScalar_t* alpha) { diopiTensorHandle_t trOther = nullptr; diopiDtype_t dtype; diopiGetTensorDtype(out, &dtype); @@ -83,13 +80,12 @@ extern "C" DIOPI_API diopiError_t diopiAddScalar(diopiContextHandle_t ctx, diopi return diopiAdd(ctx, out, input, trOther, alpha); } -extern "C" DIOPI_API diopiError_t diopiAddInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other, - const diopiScalar_t* alpha) { +diopiError_t diopiAddInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other, const diopiScalar_t* alpha) { return diopiAddScalar(ctx, input, input, other, alpha); } -extern "C" DIOPI_API diopiError_t diopiSub(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, - const diopiScalar_t* alpha) { +diopiError_t diopiSub(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, + const diopiScalar_t* alpha) { diopiDtype_t outDtype, inputDtype, otherDtype; diopiGetTensorDtype(out, &outDtype); diopiGetTensorDtype(input, &inputDtype); @@ -116,12 +112,12 @@ extern "C" DIOPI_API diopiError_t diopiSub(diopiContextHandle_t ctx, diopiTensor return diopiSuccess; } -extern "C" DIOPI_API diopiError_t diopiSubInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other, const diopiScalar_t* alpha) { +diopiError_t diopiSubInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other, const diopiScalar_t* alpha) { return diopiSub(ctx, input, input, other, alpha); } -extern "C" DIOPI_API diopiError_t diopiSubScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other, - const diopiScalar_t* alpha) { +diopiError_t diopiSubScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other, + const diopiScalar_t* alpha) { diopiTensorHandle_t trOther = nullptr; diopiDtype_t dtype; diopiGetTensorDtype(out, &dtype); @@ -129,12 +125,11 @@ extern "C" DIOPI_API diopiError_t diopiSubScalar(diopiContextHandle_t ctx, diopi return diopiSub(ctx, out, input, trOther, alpha); } -extern "C" DIOPI_API diopiError_t diopiSubInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other, - const diopiScalar_t* alpha) { +diopiError_t diopiSubInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other, const diopiScalar_t* alpha) { return diopiSubScalar(ctx, input, input, other, alpha); } -extern "C" DIOPI_API diopiError_t diopiMul(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { +diopiError_t diopiMul(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { diopiDtype_t outDtype, inputDtype, otherDtype; diopiGetTensorDtype(out, &outDtype); diopiGetTensorDtype(input, &inputDtype); @@ -151,23 +146,20 @@ extern "C" DIOPI_API diopiError_t diopiMul(diopiContextHandle_t ctx, diopiTensor return diopiSuccess; } -extern "C" DIOPI_API diopiError_t diopiMulInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other) { - return diopiMul(ctx, input, input, other); -} +diopiError_t diopiMulInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other) { return diopiMul(ctx, input, input, other); } -extern "C" DIOPI_API diopiError_t diopiMulScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, - const diopiScalar_t* other) { +diopiError_t diopiMulScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other) { diopiTensorHandle_t trOther = nullptr; makeTensorFromScalar(ctx, other, &trOther, diopi_dtype_float32, diopiDevice_t::diopi_device); return diopiMul(ctx, out, input, trOther); } -extern "C" DIOPI_API diopiError_t diopiMulInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other) { +diopiError_t diopiMulInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other) { return diopiMulScalar(ctx, input, input, other); } -extern "C" DIOPI_API diopiError_t diopiDiv(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, - diopiRoundMode_t roundingMode) { +diopiError_t diopiDiv(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, + diopiRoundMode_t roundingMode) { diopiDtype_t outDtype, inputDtype, otherDtype; diopiGetTensorDtype(out, &outDtype); diopiGetTensorDtype(input, &inputDtype); @@ -184,13 +176,12 @@ extern "C" DIOPI_API diopiError_t diopiDiv(diopiContextHandle_t ctx, diopiTensor return diopiSuccess; } -extern "C" DIOPI_API diopiError_t diopiDivInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other, - diopiRoundMode_t roundingMode) { +diopiError_t diopiDivInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t other, diopiRoundMode_t roundingMode) { return diopiDiv(ctx, input, input, other, roundingMode); } -extern "C" DIOPI_API diopiError_t diopiDivScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other, - diopiRoundMode_t roundingMode) { +diopiError_t diopiDivScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* other, + diopiRoundMode_t roundingMode) { diopiTensorHandle_t trOther = nullptr; diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); @@ -198,12 +189,11 @@ extern "C" DIOPI_API diopiError_t diopiDivScalar(diopiContextHandle_t ctx, diopi return diopiDiv(ctx, out, input, trOther, roundingMode); } -extern "C" DIOPI_API diopiError_t diopiDivInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other, - diopiRoundMode_t roundingMode) { +diopiError_t diopiDivInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* other, diopiRoundMode_t roundingMode) { return diopiDivScalar(ctx, input, input, other, roundingMode); } -DIOPI_API diopiError_t diopiMaximum(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { +diopiError_t diopiMaximum(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); // as this op do not support BOOL, UIT8, and Int16, these three data types are converted to Int32 @@ -220,13 +210,12 @@ DIOPI_API diopiError_t diopiMaximum(diopiContextHandle_t ctx, diopiTensorHandle_ return diopiSuccess; } -DIOPI_API diopiError_t diopiMinimum(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { +diopiError_t diopiMinimum(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { diopiDtype_t dtype; diopiGetTensorDtype(out, &dtype); AclOpRunner<2, 1>("Minimum", ctx).addInput(input, dtype).addInput(other, dtype).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/bitwise.cpp b/impl/ascend/functions/bitwise.cpp index 47103d5b8..2e98a0721 100644 --- a/impl/ascend/functions/bitwise.cpp +++ b/impl/ascend/functions/bitwise.cpp @@ -4,16 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiBitwiseNot(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiBitwiseNot(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); if (diopi_dtype_bool == dtype) { @@ -24,7 +20,7 @@ DIOPI_API diopiError_t diopiBitwiseNot(diopiContextHandle_t ctx, diopiTensorHand return diopiSuccess; } -DIOPI_API diopiError_t diopiBitwiseAnd(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { +diopiError_t diopiBitwiseAnd(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other) { diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); if (diopi_dtype_bool == dtype) { @@ -35,7 +31,5 @@ DIOPI_API diopiError_t diopiBitwiseAnd(diopiContextHandle_t ctx, diopiTensorHand return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/bmm.cpp b/impl/ascend/functions/bmm.cpp index 42ee4f64f..c6300e011 100644 --- a/impl/ascend/functions/bmm.cpp +++ b/impl/ascend/functions/bmm.cpp @@ -4,14 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" diopiError_t diopiBmm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t mat2) { +diopiError_t diopiBmm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t mat2) { AclOpRunner<2, 1>("BatchMatMul", ctx).addInput(input).addInput(mat2).setAttr("adj_x1", false).setAttr("adj_x1", false).addOutput(out).run(); return diopiSuccess; } diff --git a/impl/ascend/functions/cast.cpp b/impl/ascend/functions/cast.cpp index fb2148f47..93e2058b1 100644 --- a/impl/ascend/functions/cast.cpp +++ b/impl/ascend/functions/cast.cpp @@ -4,20 +4,43 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" diopiError_t diopiCastDtype(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiCastDtype(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { + int64_t numel = 0; + diopiGetTensorNumel(input, &numel); + if (0 == numel) { + return diopiSuccess; + } + AscendTensor inputAt(input), outAt(out); - AclOpRunner<1, 1>("Cast", ctx) - .addInput(inputAt.data(), inputAt.getAclMemBufferSize(), inputAt.getAclMemShape(), inputAt.getAclDataFormat(), inputAt.dtype()) - .addOutput(const_cast(outAt.data()), outAt.getAclMemBufferSize(), outAt.getAclMemShape(), outAt.getAclDataFormat(), outAt.dtype()) - .setAttr("dst_type", outAt.getAclDataType()) - .run(); + if (inputAt.stride() == outAt.stride()) { + AclOpRunner<1, 1>("Cast", ctx) + .addInput(inputAt.data(), inputAt.getAclMemBufferSize(), inputAt.getAclMemShape(), inputAt.getAclDataFormat(), inputAt.dtype()) + .addOutput(const_cast(outAt.data()), outAt.getAclMemBufferSize(), outAt.getAclMemShape(), outAt.getAclDataFormat(), outAt.dtype()) + .setAttr("dst_type", outAt.getAclDataType()) + .run(); + } else { + diopiTensorHandle_t inputCopy; + makeTensorLike(ctx, &inputCopy, input, outAt.dtype()); + diopiCastDtype(ctx, inputCopy, input); + AscendTensor inputCopyAt(inputCopy); + + AclOpRunner<8, 1>("ViewCopy", ctx) + .addInputWithoutContiguous(out) + .addConstInput(outAt.shape()) + .addConstInput(outAt.stride()) + .addConstInput(0, diopi_dtype_int64) + .addInputWithoutContiguous(inputCopy) + .addConstInput(inputCopyAt.shape()) + .addConstInput(inputCopyAt.stride()) + .addConstInput(0, diopi_dtype_int64) + .addOutputWithoutContiguous(out) + .run(); + } return diopiSuccess; } diff --git a/impl/ascend/functions/cat.cpp b/impl/ascend/functions/cat.cpp index 5b5b81bfd..abdf95e44 100644 --- a/impl/ascend/functions/cat.cpp +++ b/impl/ascend/functions/cat.cpp @@ -4,20 +4,16 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiCat(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t* tensors, int64_t numInputs, int64_t dim) { +diopiError_t diopiCat(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t* tensors, int64_t numInputs, int64_t dim) { std::vector dynamicInput(tensors, tensors + numInputs); AclOpRunner<1, 1>("ConcatD", ctx).addDynamicInput(dynamicInput).setAttr("N", numInputs).setAttr("concat_dim", dim).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/clamp.cpp b/impl/ascend/functions/clamp.cpp index 26849da5f..55723e7b7 100644 --- a/impl/ascend/functions/clamp.cpp +++ b/impl/ascend/functions/clamp.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include @@ -13,9 +11,9 @@ namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiClamp(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t min, - diopiConstTensorHandle_t max) { + +diopiError_t diopiClamp(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t min, + diopiConstTensorHandle_t max) { diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); AclOpRunner<3, 1> runner("ClipByValue", ctx); @@ -48,12 +46,12 @@ DIOPI_API diopiError_t diopiClamp(diopiContextHandle_t ctx, diopiTensorHandle_t return diopiSuccess; } -DIOPI_API diopiError_t diopiClampInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t min, diopiConstTensorHandle_t max) { +diopiError_t diopiClampInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t min, diopiConstTensorHandle_t max) { return diopiClamp(ctx, input, input, min, max); } -DIOPI_API diopiError_t diopiClampScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* min, - const diopiScalar_t* max) { +diopiError_t diopiClampScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* min, + const diopiScalar_t* max) { diopiDtype_t dtype; diopiGetTensorDtype(input, &dtype); AclOpRunner<3, 1> runner("ClipByValue", ctx); @@ -80,10 +78,9 @@ DIOPI_API diopiError_t diopiClampScalar(diopiContextHandle_t ctx, diopiTensorHan return diopiSuccess; } -DIOPI_API diopiError_t diopiClampInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* min, const diopiScalar_t* max) { +diopiError_t diopiClampInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* min, const diopiScalar_t* max) { return diopiClampScalar(ctx, input, input, min, max); } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/contiguous.cpp b/impl/ascend/functions/contiguous.cpp new file mode 100644 index 000000000..7bbae420e --- /dev/null +++ b/impl/ascend/functions/contiguous.cpp @@ -0,0 +1,20 @@ +/** + * @file + * @author DeepLink + * @copyright (c) 2023, DeepLink. + */ + +#include +#include + +#include "../common/acloprunner.hpp" + +namespace impl { +namespace ascend { +diopiError_t diopiContiguous(diopiContextHandle_t ctx, diopiTensorHandle_t* out, diopiConstTensorHandle_t input, diopiMemoryFormat_t memoryFormat) { + *out = contiguous(ctx, input, memoryFormat); + return diopiSuccess; +} + +} // namespace ascend +} // namespace impl diff --git a/impl/ascend/functions/conv2d.cpp b/impl/ascend/functions/conv2d.cpp index 2050c0688..5f5cf8c57 100755 --- a/impl/ascend/functions/conv2d.cpp +++ b/impl/ascend/functions/conv2d.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include @@ -13,8 +11,8 @@ namespace impl { namespace ascend { -extern "C" diopiError_t diopiConvolution2d(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, - diopiConstTensorHandle_t bias, diopiSize_t stride, diopiSize_t padding, diopiSize_t dilation, int64_t groups) { +diopiError_t diopiConvolution2d(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, + diopiConstTensorHandle_t bias, diopiSize_t stride, diopiSize_t padding, diopiSize_t dilation, int64_t groups) { auto format = getAclDataFormat(input); const std::string dataFormat = (format == ACL_FORMAT_NHWC) ? "NHWC" : "NCHW"; std::vector strideTemp(4, 1); @@ -47,10 +45,9 @@ extern "C" diopiError_t diopiConvolution2d(diopiContextHandle_t ctx, diopiTensor return diopiSuccess; } -extern "C" diopiError_t diopiConvolution2dBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, - diopiTensorHandle_t gradBias, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, - diopiConstTensorHandle_t weight, diopiSize_t *biasSizes, diopiSize_t stride, diopiSize_t padding, - diopiSize_t dilation, int64_t groups) { +diopiError_t diopiConvolution2dBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, diopiTensorHandle_t gradBias, + diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, + diopiSize_t *biasSizes, diopiSize_t stride, diopiSize_t padding, diopiSize_t dilation, int64_t groups) { auto format = getAclDataFormat(input); const std::string dataFormat = (format == ACL_FORMAT_NHWC) ? "NHWC" : "NCHW"; diff --git a/impl/ascend/functions/copy.cpp b/impl/ascend/functions/copy.cpp index 222235588..ba6137940 100644 --- a/impl/ascend/functions/copy.cpp +++ b/impl/ascend/functions/copy.cpp @@ -4,15 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiCopyInp(diopiContextHandle_t ctx, diopiConstTensorHandle_t src, diopiTensorHandle_t dest) { +diopiError_t diopiCopyInp(diopiContextHandle_t ctx, diopiConstTensorHandle_t src, diopiTensorHandle_t dest) { int64_t numel = 0; diopiGetTensorNumel(src, &numel); if (0 == numel) { @@ -45,6 +42,6 @@ DIOPI_API diopiError_t diopiCopyInp(diopiContextHandle_t ctx, diopiConstTensorHa } return diopiSuccess; } -} + } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/cos.cpp b/impl/ascend/functions/cos.cpp index adbe0a823..2a46530e4 100644 --- a/impl/ascend/functions/cos.cpp +++ b/impl/ascend/functions/cos.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -13,8 +11,6 @@ namespace impl { namespace ascend { -extern "C" { - diopiError_t diopiCosInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { diopiCos(ctx, input, input); return diopiSuccess; @@ -43,7 +39,5 @@ diopiError_t diopiCos(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiCo return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/cumsum.cpp b/impl/ascend/functions/cumsum.cpp index ee1169e0a..5f4e0d790 100644 --- a/impl/ascend/functions/cumsum.cpp +++ b/impl/ascend/functions/cumsum.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { diff --git a/impl/ascend/functions/dropout.cpp b/impl/ascend/functions/dropout.cpp index c4fe9ecfb..ecdc25fde 100644 --- a/impl/ascend/functions/dropout.cpp +++ b/impl/ascend/functions/dropout.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { @@ -22,9 +20,8 @@ aclDataType dtypeConvertor(diopiDtype_t type) { } // namespace -extern "C" { -DIOPI_API diopiError_t diopiDropout(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiTensorHandle_t mask, diopiConstTensorHandle_t input, double p, - bool train, diopiGeneratorHandle_t generator) { +diopiError_t diopiDropout(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiTensorHandle_t mask, diopiConstTensorHandle_t input, double p, bool train, + diopiGeneratorHandle_t generator) { if (train) { diopiTensorHandle_t maskTempTensor; @@ -61,6 +58,6 @@ DIOPI_API diopiError_t diopiDropout(diopiContextHandle_t ctx, diopiTensorHandle_ } return diopiSuccess; } -} + } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/embedding.cpp b/impl/ascend/functions/embedding.cpp index 016633586..3cd4a7dbd 100644 --- a/impl/ascend/functions/embedding.cpp +++ b/impl/ascend/functions/embedding.cpp @@ -4,23 +4,21 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiEmbedding(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t weight, diopiConstTensorHandle_t indices, - int64_t paddingIdx, bool scaleGradByfreq, bool sparse) { + +diopiError_t diopiEmbedding(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t weight, diopiConstTensorHandle_t indices, + int64_t paddingIdx, bool scaleGradByfreq, bool sparse) { std::vector dimVec({0}); diopiSize_t dim = vectorToDiopiSize(dimVec); AclOpRunner<3, 1>("GatherV2", ctx).addInput(weight).addInput(indices).addConstInput(dim).setAttr("batch_dims", 0).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiEmbeddingBackward(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t grad, - diopiConstTensorHandle_t indices, int64_t numWeights, int64_t paddingIdx, bool scaleGradByfreq, bool sparse) { +diopiError_t diopiEmbeddingBackward(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t grad, diopiConstTensorHandle_t indices, + int64_t numWeights, int64_t paddingIdx, bool scaleGradByfreq, bool sparse) { AclOpRunner<2, 1>("EmbeddingDenseGrad", ctx) .addInput(grad) .addInput(indices, diopi_dtype_int32) @@ -31,7 +29,6 @@ DIOPI_API diopiError_t diopiEmbeddingBackward(diopiContextHandle_t ctx, diopiTen .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/error.cpp b/impl/ascend/functions/error.cpp index a31d2fc00..0e367b087 100644 --- a/impl/ascend/functions/error.cpp +++ b/impl/ascend/functions/error.cpp @@ -7,7 +7,6 @@ #include "../error.hpp" #include -#include #include @@ -24,7 +23,7 @@ const char* ascendGetLastErrorString() { return strLastError; } -extern "C" DIOPI_RT_API const char* diopiGetLastErrorString() { return ascendGetLastErrorString(); } +const char* diopiGetLastErrorString() { return ascendGetLastErrorString(); } } // namespace ascend diff --git a/impl/ascend/functions/fill.cpp b/impl/ascend/functions/fill.cpp index bab3ca1d1..bd4698fce 100644 --- a/impl/ascend/functions/fill.cpp +++ b/impl/ascend/functions/fill.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include #include @@ -15,8 +13,6 @@ namespace impl { namespace ascend { -extern "C" { - diopiError_t diopiFill(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t *value) { int64_t numel = 0; diopiGetTensorNumel(input, &numel); @@ -58,7 +54,5 @@ diopiError_t diopiFill(diopiContextHandle_t ctx, diopiTensorHandle_t input, cons return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/flip.cpp b/impl/ascend/functions/flip.cpp index 677801153..a4987b564 100644 --- a/impl/ascend/functions/flip.cpp +++ b/impl/ascend/functions/flip.cpp @@ -4,19 +4,15 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiFlip(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dims) { +diopiError_t diopiFlip(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dims) { AclOpRunner<2, 1>("ReverseV2", ctx).addInput(input).addConstInput(dims).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/floor.cpp b/impl/ascend/functions/floor.cpp index 722353662..b8c3ae653 100644 --- a/impl/ascend/functions/floor.cpp +++ b/impl/ascend/functions/floor.cpp @@ -4,20 +4,16 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiFloor(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiFloor(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Floor", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiFloorInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiFloor(ctx, input, input); } -} +diopiError_t diopiFloorInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiFloor(ctx, input, input); } } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/gather.cpp b/impl/ascend/functions/gather.cpp index 03309043a..c0830039c 100644 --- a/impl/ascend/functions/gather.cpp +++ b/impl/ascend/functions/gather.cpp @@ -4,19 +4,14 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiGather(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim, - diopiConstTensorHandle_t index) { +diopiError_t diopiGather(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim, diopiConstTensorHandle_t index) { AclOpRunner<2, 1>("GatherElements", ctx).addInput(input).addInput(index).setAttr("dim", dim).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/index.cpp b/impl/ascend/functions/index.cpp index b8118dd19..fb191db60 100644 --- a/impl/ascend/functions/index.cpp +++ b/impl/ascend/functions/index.cpp @@ -4,21 +4,16 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiIndexSelect(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim, - diopiConstTensorHandle_t index) { +diopiError_t diopiIndexSelect(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim, diopiConstTensorHandle_t index) { std::vector dimVec({dim}); diopiSize_t dimInput = vectorToDiopiSize(dimVec); AclOpRunner<3, 1>("GatherV2", ctx).addInput(input).addInput(index).addConstInput(dimInput).setAttr("batch_dims", 0).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/interpolate.cpp b/impl/ascend/functions/interpolate.cpp index 83abea096..bc74bf92c 100644 --- a/impl/ascend/functions/interpolate.cpp +++ b/impl/ascend/functions/interpolate.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include #include @@ -16,10 +14,8 @@ namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiUpsampleLinear(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t size, - bool alignCorners, const char* mode) { +diopiError_t diopiUpsampleLinear(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t size, bool alignCorners, + const char* mode) { std::string modeStr(mode); if ("bilinear" == modeStr) { AclOpRunner<2, 1>("ResizeBilinearV2", ctx) @@ -35,8 +31,8 @@ DIOPI_API diopiError_t diopiUpsampleLinear(diopiContextHandle_t ctx, diopiTensor return diopiSuccess; } -DIOPI_API diopiError_t diopiUpsampleLinearBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiSize_t outSize, diopiSize_t inSize, bool alignCorners, const char* mode) { +diopiError_t diopiUpsampleLinearBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiSize_t outSize, + diopiSize_t inSize, bool alignCorners, const char* mode) { diopiDtype_t dtype; diopiGetTensorDtype(gradOutput, &dtype); diopiSize_t stride; @@ -58,7 +54,5 @@ DIOPI_API diopiError_t diopiUpsampleLinearBackward(diopiContextHandle_t ctx, dio return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/layer_norm.cpp b/impl/ascend/functions/layer_norm.cpp index f805d6775..6ef6d7d0a 100644 --- a/impl/ascend/functions/layer_norm.cpp +++ b/impl/ascend/functions/layer_norm.cpp @@ -4,17 +4,14 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiLayerNorm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiTensorHandle_t saveMean, diopiTensorHandle_t saveInvstd, - diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, diopiConstTensorHandle_t bias, - diopiSize_t normalizedShape, double eps) { +diopiError_t diopiLayerNorm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiTensorHandle_t saveMean, diopiTensorHandle_t saveInvstd, + diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, diopiConstTensorHandle_t bias, diopiSize_t normalizedShape, + double eps) { // gen begin normalized dim diopiSize_t inShape; diopiGetTensorShape(input, &inShape); @@ -36,10 +33,9 @@ DIOPI_API diopiError_t diopiLayerNorm(diopiContextHandle_t ctx, diopiTensorHandl return diopiSuccess; } -DIOPI_API diopiError_t diopiLayerNormBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, - diopiTensorHandle_t gradBias, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, - diopiConstTensorHandle_t weight, diopiConstTensorHandle_t bias, diopiConstTensorHandle_t mean, - diopiConstTensorHandle_t rstd, diopiSize_t normalizedShape) { +diopiError_t diopiLayerNormBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, diopiTensorHandle_t gradBias, + diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, + diopiConstTensorHandle_t bias, diopiConstTensorHandle_t mean, diopiConstTensorHandle_t rstd, diopiSize_t normalizedShape) { AclOpRunner<5, 3>("LayerNormGrad", ctx) .addInput(gradOutput) .addInput(input) @@ -52,6 +48,5 @@ DIOPI_API diopiError_t diopiLayerNormBackward(diopiContextHandle_t ctx, diopiTen .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/linear.cpp b/impl/ascend/functions/linear.cpp index 7858ebbf4..4f1d91678 100644 --- a/impl/ascend/functions/linear.cpp +++ b/impl/ascend/functions/linear.cpp @@ -4,16 +4,14 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" diopiError_t diopiLinear(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, - diopiConstTensorHandle_t bias) { +diopiError_t diopiLinear(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight, + diopiConstTensorHandle_t bias) { diopiSize_t inputSize, outputSize; diopiGetTensorShape(input, &inputSize); diopiGetTensorShape(out, &outputSize); @@ -55,9 +53,8 @@ extern "C" diopiError_t diopiLinear(diopiContextHandle_t ctx, diopiTensorHandle_ return diopiSuccess; } -extern "C" diopiError_t diopiLinearBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, - diopiTensorHandle_t gradBias, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, - diopiConstTensorHandle_t weight) { +diopiError_t diopiLinearBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiTensorHandle_t gradWeight, diopiTensorHandle_t gradBias, + diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, diopiConstTensorHandle_t weight) { diopiSize_t inputSize, gradOutSize; diopiGetTensorShape(input, &inputSize); diopiGetTensorShape(gradOutput, &gradOutSize); diff --git a/impl/ascend/functions/logic.cpp b/impl/ascend/functions/logic.cpp index 8e36ecdbd..99c33df4c 100644 --- a/impl/ascend/functions/logic.cpp +++ b/impl/ascend/functions/logic.cpp @@ -4,15 +4,11 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - diopiError_t logic(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t other, const char* logicOp) { diopiDtype_t inputDtype, otherDtype; diopiGetTensorDtype(input, &inputDtype); @@ -167,7 +163,5 @@ diopiError_t diopiLogicalNot(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiError_t diopiLogicalNotInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiLogicalNot(ctx, input, input); } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/loss.cpp b/impl/ascend/functions/loss.cpp index 93ba076bf..8f2e34ecb 100644 --- a/impl/ascend/functions/loss.cpp +++ b/impl/ascend/functions/loss.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { @@ -94,10 +92,8 @@ std::string getReductionStr(const diopiReduction_t reduction) { return reductionStr; } -extern "C" { - -DIOPI_API diopiError_t diopiNLLLoss(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, - diopiConstTensorHandle_t weight, diopiReduction_t reduction, int64_t ignoreIndex) { +diopiError_t diopiNLLLoss(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, + diopiConstTensorHandle_t weight, diopiReduction_t reduction, int64_t ignoreIndex) { auto totalWeightSizeVec = std::vector({1}); auto totalWeightSize = vectorToDiopiSize(totalWeightSizeVec); diopiTensorHandle_t totalWeight, weightCopy; @@ -119,9 +115,8 @@ DIOPI_API diopiError_t diopiNLLLoss(diopiContextHandle_t ctx, diopiTensorHandle_ return diopiSuccess; } -DIOPI_API diopiError_t diopiNLLLossBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, diopiConstTensorHandle_t weight, - diopiReduction_t reduction, int64_t ignoreIndex) { +diopiError_t diopiNLLLossBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, + diopiConstTensorHandle_t target, diopiConstTensorHandle_t weight, diopiReduction_t reduction, int64_t ignoreIndex) { auto totalWeightSizeVec = std::vector({1}); auto totalWeightSize = vectorToDiopiSize(totalWeightSizeVec); diopiTensorHandle_t weightCopy, totalWeight, out, inputCopy, targetCopy, gradInputCopy; @@ -226,8 +221,8 @@ DIOPI_API diopiError_t diopiNLLLossBackward(diopiContextHandle_t ctx, diopiTenso return diopiSuccess; } -DIOPI_API diopiError_t diopiCrossEntropyLoss(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, - diopiConstTensorHandle_t weight, diopiReduction_t reduction, int64_t ignoreIndex, double labelSmoothing) { +diopiError_t diopiCrossEntropyLoss(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, + diopiConstTensorHandle_t weight, diopiReduction_t reduction, int64_t ignoreIndex, double labelSmoothing) { diopiTensorHandle_t logTensor; makeTensorLike(ctx, &logTensor, input); diopiLogSoftmax(ctx, logTensor, input, 1); @@ -236,9 +231,9 @@ DIOPI_API diopiError_t diopiCrossEntropyLoss(diopiContextHandle_t ctx, diopiTens return diopiSuccess; } -DIOPI_API diopiError_t diopiCrossEntropyLossBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, diopiConstTensorHandle_t weight, - diopiReduction_t reduction, int64_t ignoreIndex, double labelSmoothing) { +diopiError_t diopiCrossEntropyLossBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, + diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, diopiConstTensorHandle_t weight, + diopiReduction_t reduction, int64_t ignoreIndex, double labelSmoothing) { diopiTensorHandle_t logTensor, gradLog; makeTensorLike(ctx, &logTensor, input); diopiLogSoftmax(ctx, logTensor, input, 1); @@ -249,14 +244,14 @@ DIOPI_API diopiError_t diopiCrossEntropyLossBackward(diopiContextHandle_t ctx, d return diopiSuccess; } -DIOPI_API diopiError_t diopiMSELoss(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, - diopiReduction_t reduction) { +diopiError_t diopiMSELoss(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, + diopiReduction_t reduction) { AclOpRunner<2, 1>("MseLoss", ctx).addInput(input).addInput(target).addOutput(out).setAttr("reduction", getReductionStr(reduction)).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiMSELossBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, diopiConstTensorHandle_t target, diopiReduction_t reduction) { +diopiError_t diopiMSELossBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiConstTensorHandle_t input, + diopiConstTensorHandle_t target, diopiReduction_t reduction) { AclOpRunner<3, 1>("MseLossGrad", ctx) .addInput(input) .addInput(target) @@ -267,6 +262,5 @@ DIOPI_API diopiError_t diopiMSELossBackward(diopiContextHandle_t ctx, diopiTenso return diopiSuccess; } -} // extern "C" } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/masked_fill.cpp b/impl/ascend/functions/masked_fill.cpp index 9db9f5374..575aa6c28 100644 --- a/impl/ascend/functions/masked_fill.cpp +++ b/impl/ascend/functions/masked_fill.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -13,8 +11,6 @@ namespace impl { namespace ascend { -extern "C" { - diopiError_t diopiMaskedFill(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t mask, diopiConstTensorHandle_t value) { int64_t numel = 0; @@ -91,7 +87,6 @@ diopiError_t diopiMaskedFillScalar(diopiContextHandle_t ctx, diopiTensorHandle_t diopiError_t diopiMaskedFillInpScalar(diopiContextHandle_t ctx, diopiTensorHandle_t input, diopiConstTensorHandle_t mask, const diopiScalar_t* value) { return diopiMaskedFillScalar(ctx, input, input, mask, value); } -} // extern "C" } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/minmax.cpp b/impl/ascend/functions/minmax.cpp index fb0bbc116..411653341 100644 --- a/impl/ascend/functions/minmax.cpp +++ b/impl/ascend/functions/minmax.cpp @@ -4,22 +4,18 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiMax(diopiContextHandle_t ctx, diopiTensorHandle_t max, diopiTensorHandle_t maxIndices, diopiConstTensorHandle_t input, - int64_t dim) { +diopiError_t diopiMax(diopiContextHandle_t ctx, diopiTensorHandle_t max, diopiTensorHandle_t maxIndices, diopiConstTensorHandle_t input, int64_t dim) { AclOpRunner<1, 2>("ArgMaxWithValue", ctx).setAttr("dimension", static_cast(dim)).addInput(input).addOutput(maxIndices).addOutput(max).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiMaxAll(diopiContextHandle_t ctx, diopiTensorHandle_t max, diopiConstTensorHandle_t input) { +diopiError_t diopiMaxAll(diopiContextHandle_t ctx, diopiTensorHandle_t max, diopiConstTensorHandle_t input) { diopiSize_t inS; diopiGetTensorShape(input, &inS); std::vector dimAllVector(inS.len); @@ -29,13 +25,12 @@ DIOPI_API diopiError_t diopiMaxAll(diopiContextHandle_t ctx, diopiTensorHandle_t return diopiSuccess; } -DIOPI_API diopiError_t diopiMin(diopiContextHandle_t ctx, diopiTensorHandle_t min, diopiTensorHandle_t minIndices, diopiConstTensorHandle_t input, - int64_t dim) { +diopiError_t diopiMin(diopiContextHandle_t ctx, diopiTensorHandle_t min, diopiTensorHandle_t minIndices, diopiConstTensorHandle_t input, int64_t dim) { AclOpRunner<1, 2>("ArgMinWithValue", ctx).setAttr("dimension", static_cast(dim)).addInput(input).addOutput(minIndices).addOutput(min).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiMinAll(diopiContextHandle_t ctx, diopiTensorHandle_t min, diopiConstTensorHandle_t input) { +diopiError_t diopiMinAll(diopiContextHandle_t ctx, diopiTensorHandle_t min, diopiConstTensorHandle_t input) { diopiSize_t inS; diopiGetTensorShape(input, &inS); std::vector dimAllVector(inS.len); @@ -44,7 +39,6 @@ DIOPI_API diopiError_t diopiMinAll(diopiContextHandle_t ctx, diopiTensorHandle_t AclOpRunner<2, 1>("ReduceMin", ctx).addInput(input).addConstInput(dimAll).addOutput(min).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/mm.cpp b/impl/ascend/functions/mm.cpp index 99e26eed5..a88804aec 100644 --- a/impl/ascend/functions/mm.cpp +++ b/impl/ascend/functions/mm.cpp @@ -4,14 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" diopiError_t diopiMm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t mat2) { +diopiError_t diopiMm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t mat2) { AclOpRunner<2, 1>("BatchMatMul", ctx).addInput(input).addInput(mat2).setAttr("adj_x1", true).setAttr("adj_x1", true).addOutput(out).run(); return diopiSuccess; } diff --git a/impl/ascend/functions/multinomial.cpp b/impl/ascend/functions/multinomial.cpp index bc3b7401c..8b770fd78 100644 --- a/impl/ascend/functions/multinomial.cpp +++ b/impl/ascend/functions/multinomial.cpp @@ -4,15 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiMultinomial(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t numSamples, bool replacement, - diopiGeneratorHandle_t generator) { +diopiError_t diopiMultinomial(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t numSamples, bool replacement, + diopiGeneratorHandle_t generator) { auto pair = getSeedAndOffset(ctx, generator, 10); AclOpRunner<3, 1>("MultinomialWithReplacement", ctx) .addInput(input) @@ -24,7 +21,6 @@ DIOPI_API diopiError_t diopiMultinomial(diopiContextHandle_t ctx, diopiTensorHan .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/nonzero.cpp b/impl/ascend/functions/nonzero.cpp index 41d29f5b3..883f40e8f 100644 --- a/impl/ascend/functions/nonzero.cpp +++ b/impl/ascend/functions/nonzero.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { @@ -21,8 +19,7 @@ std::vector nonzeroNpuMaxOutputSize(diopiConstTensorHandle_t input) { return maxOutputSize; } -extern "C" { -DIOPI_API diopiError_t diopiNonzero(diopiContextHandle_t ctx, diopiTensorHandle_t* out, diopiConstTensorHandle_t input) { +diopiError_t diopiNonzero(diopiContextHandle_t ctx, diopiTensorHandle_t* out, diopiConstTensorHandle_t input) { auto outputSizeVec = nonzeroNpuMaxOutputSize(input); diopiSize_t outputSize = vectorToDiopiSize(outputSizeVec); @@ -33,6 +30,5 @@ DIOPI_API diopiError_t diopiNonzero(diopiContextHandle_t ctx, diopiTensorHandle_ *out = output; return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/norm.cpp b/impl/ascend/functions/norm.cpp index d9641bdde..c52518c98 100644 --- a/impl/ascend/functions/norm.cpp +++ b/impl/ascend/functions/norm.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -13,9 +11,7 @@ namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiNorm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* p, diopiSize_t dim) { +diopiError_t diopiNorm(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* p, diopiSize_t dim) { diopiSize_t size; diopiGetTensorShape(out, &size); diopiDtype_t dtype; @@ -43,7 +39,6 @@ DIOPI_API diopiError_t diopiNorm(diopiContextHandle_t ctx, diopiTensorHandle_t o return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/one_hot.cpp b/impl/ascend/functions/one_hot.cpp index f07abcca6..a26477e76 100644 --- a/impl/ascend/functions/one_hot.cpp +++ b/impl/ascend/functions/one_hot.cpp @@ -4,15 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiOneHot(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t numClasses) { +diopiError_t diopiOneHot(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t numClasses) { diopiDtype_t dtype; diopiGetTensorDtype(out, &dtype); @@ -26,6 +23,5 @@ DIOPI_API diopiError_t diopiOneHot(diopiContextHandle_t ctx, diopiTensorHandle_t .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/pool.cpp b/impl/ascend/functions/pool.cpp index a01f13d88..a4563319a 100644 --- a/impl/ascend/functions/pool.cpp +++ b/impl/ascend/functions/pool.cpp @@ -4,15 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiAdaptiveAvgPool2d(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t outputSize) { +diopiError_t diopiAdaptiveAvgPool2d(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t outputSize) { AclOpRunner<1, 1>("AdaptiveAvgPool2d", ctx) .addInput(input) .setAttr("output_size", std::vector{static_cast(outputSize.data[0]), static_cast(outputSize.data[1])}) @@ -21,8 +18,8 @@ DIOPI_API diopiError_t diopiAdaptiveAvgPool2d(diopiContextHandle_t ctx, diopiTen return diopiSuccess; } -DIOPI_API diopiError_t diopiAdaptiveAvgPool2dBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input) { +diopiError_t diopiAdaptiveAvgPool2dBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, + diopiConstTensorHandle_t input) { diopiSize_t shape; diopiGetTensorShape(input, &shape); AclOpRunner<1, 1>("AdaptiveAvgPool2dGrad", ctx) @@ -34,7 +31,6 @@ DIOPI_API diopiError_t diopiAdaptiveAvgPool2dBackward(diopiContextHandle_t ctx, .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/pow.cpp b/impl/ascend/functions/pow.cpp index 3d0534399..a85666a87 100644 --- a/impl/ascend/functions/pow.cpp +++ b/impl/ascend/functions/pow.cpp @@ -4,15 +4,11 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - diopiError_t diopiPowTensor(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiConstTensorHandle_t exponent) { AclOpRunner<2, 1>("Pow", ctx).addInput(input).addInput(exponent).addOutput(out).run(); return diopiSuccess; @@ -38,7 +34,5 @@ diopiError_t diopiPowScalar(diopiContextHandle_t ctx, diopiTensorHandle_t out, c return diopiPowTensor(ctx, out, inputTensor, exponent); } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/reduce.cpp b/impl/ascend/functions/reduce.cpp index b52f980ef..6c345e3f4 100644 --- a/impl/ascend/functions/reduce.cpp +++ b/impl/ascend/functions/reduce.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include #include @@ -17,7 +15,7 @@ namespace ascend { extern diopiError_t negativeInputRtnFillNan(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input); -extern "C" diopiError_t diopiSum(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dim) { +diopiError_t diopiSum(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dim) { int64_t numel = 0; diopiGetTensorNumel(input, &numel); if (0 == numel) { @@ -64,7 +62,7 @@ extern "C" diopiError_t diopiSum(diopiContextHandle_t ctx, diopiTensorHandle_t o return diopiSuccess; } -extern "C" diopiError_t diopiMean(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dim) { +diopiError_t diopiMean(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dim) { int64_t numel = 0; diopiGetTensorNumel(input, &numel); if (0 == numel) { diff --git a/impl/ascend/functions/repeat.cpp b/impl/ascend/functions/repeat.cpp index 79d595499..1cfa658bf 100644 --- a/impl/ascend/functions/repeat.cpp +++ b/impl/ascend/functions/repeat.cpp @@ -4,21 +4,15 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - diopiError_t diopiRepeat(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t repeatsSize) { AclOpRunner<2, 1>("Tile", ctx).addInput(input).addConstInput(repeatsSize).addOutput(out).run(); return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/sgn.cpp b/impl/ascend/functions/sgn.cpp index dc70c85f4..15e458148 100644 --- a/impl/ascend/functions/sgn.cpp +++ b/impl/ascend/functions/sgn.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -13,8 +11,6 @@ namespace impl { namespace ascend { -extern "C" { - diopiError_t diopiSgn(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { int64_t numel = 0; diopiGetTensorNumel(input, &numel); @@ -46,7 +42,5 @@ diopiError_t diopiSgn(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiCo diopiError_t diopiSgnInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiSgn(ctx, input, input); } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/sin.cpp b/impl/ascend/functions/sin.cpp index a5b814345..fa4fe625c 100644 --- a/impl/ascend/functions/sin.cpp +++ b/impl/ascend/functions/sin.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -13,7 +11,6 @@ namespace impl { namespace ascend { -extern "C" { diopiError_t diopiSinInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { diopiSin(ctx, input, input); return diopiSuccess; @@ -42,7 +39,5 @@ diopiError_t diopiSin(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiCo return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/sort.cpp b/impl/ascend/functions/sort.cpp index f422772f8..97f511848 100644 --- a/impl/ascend/functions/sort.cpp +++ b/impl/ascend/functions/sort.cpp @@ -4,19 +4,15 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiSort(diopiContextHandle_t ctx, diopiTensorHandle_t values, diopiTensorHandle_t indices, diopiConstTensorHandle_t input, int64_t dim, - bool descending, const bool* stable) { +diopiError_t diopiSort(diopiContextHandle_t ctx, diopiTensorHandle_t values, diopiTensorHandle_t indices, diopiConstTensorHandle_t input, int64_t dim, + bool descending, const bool* stable) { AclOpRunner<1, 2>("Sort", ctx).addInput(input).setAttr("axis", dim).setAttr("descending", descending).addOutput(values).addOutput(indices).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/stack.cpp b/impl/ascend/functions/stack.cpp index 17ac9e7ae..b6c1841f3 100644 --- a/impl/ascend/functions/stack.cpp +++ b/impl/ascend/functions/stack.cpp @@ -4,20 +4,16 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiStack(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t* tensors, int64_t numInputs, int64_t dim) { +diopiError_t diopiStack(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t* tensors, int64_t numInputs, int64_t dim) { std::vector dynamicInput(tensors, tensors + numInputs); AclOpRunner<1, 1>("Pack", ctx).addDynamicInput(dynamicInput).setAttr("N", numInputs).setAttr("axis", dim).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/threshold.cpp b/impl/ascend/functions/threshold.cpp index 04cbfa710..f6b622b71 100644 --- a/impl/ascend/functions/threshold.cpp +++ b/impl/ascend/functions/threshold.cpp @@ -4,17 +4,13 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiThreshold(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* threshold, - const diopiScalar_t* value) { +diopiError_t diopiThreshold(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, const diopiScalar_t* threshold, + const diopiScalar_t* value) { diopiTensorHandle_t thresholdTensor; diopiTensorHandle_t valueTensor; makeTensorFromScalar(ctx, threshold, &thresholdTensor); @@ -23,17 +19,15 @@ DIOPI_API diopiError_t diopiThreshold(diopiContextHandle_t ctx, diopiTensorHandl return diopiSuccess; } -DIOPI_API diopiError_t diopiThresholdInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* threshold, const diopiScalar_t* value) { +diopiError_t diopiThresholdInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, const diopiScalar_t* threshold, const diopiScalar_t* value) { return diopiThreshold(ctx, input, input, threshold, value); } -DIOPI_API diopiError_t diopiThresholdBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiConstTensorHandle_t input, const diopiScalar_t* threshold) { +diopiError_t diopiThresholdBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, + diopiConstTensorHandle_t input, const diopiScalar_t* threshold) { AclOpRunner<2, 1>("ThresholdGradV2D", ctx).addInput(gradOutput).addInput(input).setAttr("threshold", getValue(threshold)).addOutput(gradInput).run(); return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/topk.cpp b/impl/ascend/functions/topk.cpp index edc500186..f0571b82d 100644 --- a/impl/ascend/functions/topk.cpp +++ b/impl/ascend/functions/topk.cpp @@ -4,15 +4,12 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiTopk(diopiContextHandle_t ctx, diopiTensorHandle_t values, diopiTensorHandle_t indices, diopiConstTensorHandle_t input, int64_t k, - int64_t dim, bool largest, bool sorted) { +diopiError_t diopiTopk(diopiContextHandle_t ctx, diopiTensorHandle_t values, diopiTensorHandle_t indices, diopiConstTensorHandle_t input, int64_t k, + int64_t dim, bool largest, bool sorted) { std::vector kVec({k}); diopiSize_t kSize = vectorToDiopiSize(kVec); AclOpRunner<2, 2>("TopKV2", ctx) @@ -26,7 +23,6 @@ DIOPI_API diopiError_t diopiTopk(diopiContextHandle_t ctx, diopiTensorHandle_t v .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/transpose.cpp b/impl/ascend/functions/transpose.cpp index 687f970f3..224c3d044 100644 --- a/impl/ascend/functions/transpose.cpp +++ b/impl/ascend/functions/transpose.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include #include "../common/acloprunner.hpp" @@ -13,8 +11,7 @@ namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiTranspose(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim0, int64_t dim1) { +diopiError_t diopiTranspose(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t dim0, int64_t dim1) { diopiSize_t inputShape; diopiGetTensorShape(input, &inputShape); int64_t inputSize = inputShape.len; @@ -29,11 +26,10 @@ DIOPI_API diopiError_t diopiTranspose(diopiContextHandle_t ctx, diopiTensorHandl return diopiSuccess; } -DIOPI_API diopiError_t diopiPermute(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dims) { +diopiError_t diopiPermute(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t dims) { AclOpRunner<2, 1>("Transpose", ctx).addInput(input).addConstInput(dims).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/tril.cpp b/impl/ascend/functions/tril.cpp index e8c6886d2..79462e096 100644 --- a/impl/ascend/functions/tril.cpp +++ b/impl/ascend/functions/tril.cpp @@ -4,21 +4,15 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { - -DIOPI_API diopiError_t diopiTril(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t diagonal) { +diopiError_t diopiTril(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t diagonal) { AclOpRunner<1, 1>("Tril", ctx).addInput(input).setAttr("diagonal", diagonal).addOutput(out).run(); return diopiSuccess; } -} // extern "C" - } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/triu.cpp b/impl/ascend/functions/triu.cpp index 9b5ac7417..717232706 100644 --- a/impl/ascend/functions/triu.cpp +++ b/impl/ascend/functions/triu.cpp @@ -4,20 +4,17 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiTriu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t diagonal) { +diopiError_t diopiTriu(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, int64_t diagonal) { AclOpRunner<1, 1>("Triu", ctx).addInput(input).setAttr("diagonal", diagonal).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiTriuInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, int64_t diagonal) { return diopiTriu(ctx, input, input, diagonal); } -} +diopiError_t diopiTriuInp(diopiContextHandle_t ctx, diopiTensorHandle_t input, int64_t diagonal) { return diopiTriu(ctx, input, input, diagonal); } + } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/unary.cpp b/impl/ascend/functions/unary.cpp index f9a8790f1..b4505d5e9 100644 --- a/impl/ascend/functions/unary.cpp +++ b/impl/ascend/functions/unary.cpp @@ -4,8 +4,6 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { @@ -32,33 +30,32 @@ diopiError_t negativeInputRtnFillNan(diopiContextHandle_t ctx, diopiTensorHandle return diopiMaskedFillInp(ctx, out, mask, nanValue); } -extern "C" { -DIOPI_API diopiError_t diopiNeg(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiNeg(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Neg", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiNegInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiNeg(ctx, input, input); } +diopiError_t diopiNegInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiNeg(ctx, input, input); } -DIOPI_API diopiError_t diopiRsqrt(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiRsqrt(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Rsqrt", ctx).addInput(input, ACL_FORMAT_ND).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiRsqrtInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiRsqrt(ctx, input, input); } +diopiError_t diopiRsqrtInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiRsqrt(ctx, input, input); } -DIOPI_API diopiError_t diopiSqrt(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiSqrt(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Sqrt", ctx).addInput(input).addOutput(out).run(); negativeInputRtnFillNan(ctx, out, input); return diopiSuccess; } -DIOPI_API diopiError_t diopiErf(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiErf(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Erfinv", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiErfInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiErf(ctx, input, input); } +diopiError_t diopiErfInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiErf(ctx, input, input); } DIOPI_API diopiError_t diopiAbs(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { diopiDtype_t inputDtype; @@ -73,38 +70,32 @@ DIOPI_API diopiError_t diopiAbs(diopiContextHandle_t ctx, diopiTensorHandle_t ou return diopiSuccess; } -DIOPI_API diopiError_t diopiAbsInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiAbs(ctx, input, input); } +diopiError_t diopiAbsInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiAbs(ctx, input, input); } -DIOPI_API diopiError_t diopiLog(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiLog(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Log", ctx).addInput(input).setAttr("base", -1.0).setAttr("scale", 1.0).setAttr("shift", 0.0).addOutput(out).run(); negativeInputRtnFillNan(ctx, out, input); return diopiSuccess; } -DIOPI_API diopiError_t diopiLogInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { +diopiError_t diopiLogInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { AclOpRunner<1, 1>("Log", ctx).addInput(input).setAttr("base", -1.0).setAttr("scale", 1.0).setAttr("shift", 0.0).addOutput(input).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiFloor(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { - AclOpRunner<1, 1>("Floor", ctx).addInput(input).addOutput(out).run(); - return diopiSuccess; -} - -DIOPI_API diopiError_t diopiExp(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiExp(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Exp", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiExpInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiExp(ctx, input, input); } +diopiError_t diopiExpInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiExp(ctx, input, input); } -DIOPI_API diopiError_t diopiReciprocal(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { +diopiError_t diopiReciprocal(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input) { AclOpRunner<1, 1>("Reciprocal", ctx).addInput(input).addOutput(out).run(); return diopiSuccess; } -DIOPI_API diopiError_t diopiReciprocalInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiReciprocal(ctx, input, input); } -} +diopiError_t diopiReciprocalInp(diopiContextHandle_t ctx, diopiTensorHandle_t input) { return diopiReciprocal(ctx, input, input); } } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/upsample.cpp b/impl/ascend/functions/upsample.cpp index ede9761d0..af25d4efd 100644 --- a/impl/ascend/functions/upsample.cpp +++ b/impl/ascend/functions/upsample.cpp @@ -4,14 +4,11 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiUpsampleNearest(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t size) { +diopiError_t diopiUpsampleNearest(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t input, diopiSize_t size) { AclOpRunner<2, 1>("ResizeNearestNeighborV2", ctx) .addInput(input) .addConstInput(size, diopi_dtype_int32) @@ -22,8 +19,8 @@ DIOPI_API diopiError_t diopiUpsampleNearest(diopiContextHandle_t ctx, diopiTenso return diopiSuccess; } -DIOPI_API diopiError_t diopiUpsampleNearestBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, - diopiSize_t outSize, diopiSize_t inSize) { +diopiError_t diopiUpsampleNearestBackward(diopiContextHandle_t ctx, diopiTensorHandle_t gradInput, diopiConstTensorHandle_t gradOutput, diopiSize_t outSize, + diopiSize_t inSize) { auto gradOutputCopy = contiguous(ctx, gradOutput); std::vector outputSizeVec({inSize.data[2], inSize.data[3]}); diopiSize_t outputSize = vectorToDiopiSize(outputSizeVec); @@ -36,7 +33,6 @@ DIOPI_API diopiError_t diopiUpsampleNearestBackward(diopiContextHandle_t ctx, di .run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/functions/where.cpp b/impl/ascend/functions/where.cpp index e8bc6c7dd..68ac72d3f 100644 --- a/impl/ascend/functions/where.cpp +++ b/impl/ascend/functions/where.cpp @@ -4,20 +4,16 @@ * @copyright (c) 2023, DeepLink. */ -#include - #include "../common/acloprunner.hpp" namespace impl { namespace ascend { -extern "C" { -DIOPI_API diopiError_t diopiWhere(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t condition, diopiConstTensorHandle_t input, - diopiConstTensorHandle_t other) { +diopiError_t diopiWhere(diopiContextHandle_t ctx, diopiTensorHandle_t out, diopiConstTensorHandle_t condition, diopiConstTensorHandle_t input, + diopiConstTensorHandle_t other) { std::vector dimVec({0}); AclOpRunner<3, 1>("Select", ctx).addInput(condition).addInput(input).addInput(other).addOutput(out).run(); return diopiSuccess; } -} } // namespace ascend } // namespace impl diff --git a/impl/ascend/test/conform_test.cpp b/impl/ascend/test/conform_test.cpp index cf0139141..e05ad2295 100755 --- a/impl/ascend/test/conform_test.cpp +++ b/impl/ascend/test/conform_test.cpp @@ -5,12 +5,15 @@ * *************************************************************************************************/ +#include +#include +#include #include #include #include -#include "../common/acloprunner.hpp" +#include "../ascend_tensor.hpp" #include "../error.hpp" namespace impl {