add custom aicpu proto and cfg
This commit is contained in:
parent
7be674362d
commit
1e3039cf16
|
@ -137,3 +137,9 @@
|
|||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/ms_kernel/left_shift.cc" "clarifyCalculation"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/cpu/kernel/reversev2_cpu_kernel.cc" "unsignedLessThanZero"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.cc" "unreadVariable"
|
||||
|
||||
# custom AICPU op_protos
|
||||
"mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "syntaxError"
|
||||
"mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "constParameter"
|
||||
"mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "unreadVariable"
|
||||
"mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "useStlAlgorithm"
|
||||
|
|
|
@ -170,4 +170,23 @@
|
|||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.cc" "readability/casting"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.cc" "build/include_order"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.h" "runtime/explicit"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.h" "whitespace/indent"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.h" "whitespace/indent"
|
||||
|
||||
# custom AICPU op_protos
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "whitespace/ending_newline"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "build/include_subdir"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "runtime/references"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "readability/casting"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "readability/namespace"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/" "readability/braces"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/inc/" "whitespace/ending_newline"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/inc/" "build/include_subdir"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/inc/" "runtime/references"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/inc/" "readability/casting"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/inc/" "readability/namespace"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/" "whitespace/ending_newline"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/" "build/include_subdir"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/" "build/namespaces"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/" "runtime/references"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/" "readability/casting"
|
||||
"mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/" "readability/namespace"
|
|
@ -382,4 +382,25 @@ mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel
|
|||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/ms_kernel/batchmatmul.cc:aicpu::BatchMatMulCpuKernel::DoCompute
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/ms_kernel/sparse_to_dense.cc:aicpu::SparseToDenseCpuKernel::ValidParam
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/ms_kernel/upsample_trilinear3d_grad.cc:aicpu::UpsampleTrilinear3dGradCpuKernel::UpsampleTrilinear3dGradCompute
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.cc:aicpu::CastKernel::DoCompute
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cast_kernels.cc:aicpu::CastKernel::DoCompute
|
||||
|
||||
# custom AICPU op_protos
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/common_shape_fns.cc:ge::SubShape
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/util.cc:ge::TwoBroadcastShape
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/util.cc:ge::TwoShapeAndRangeBroadcast
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/util.cc:ge::InferShapeAndTypeTwoInOneOutBroadcast
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/fractional_max_pool_3d_with_fixed_ksize_proto.cc:ge::IMPLEMT_COMMON_INFERFUNC
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/max_pool_3d_grad_with_argmax_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/max_unpool_3d_grad_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/sspaddmm.cc:ge::CUST_IMPLEMT_INFERFUNC
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/sparse_matrix_transpose_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/batch_norm_grad_grad_proto.cc:ge::CUST_IMPLEMT_INFERFUNC
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/sparse_matrix_mat_mul_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/sparse_matrix_nnz_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/max_unpool_2d_grad_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/max_unpool_3d_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/max_unpool_2d_proto.cc:ge::CUST_IMPLEMT_VERIFIER
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/utils/util.cc:ge::InferShapeAndTypeTwoInOneOutBroadcast
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/fractional_max_pool_3d_with_fixed_ksize_proto.cc:ge::IMPLEMT_COMMON_INFERFUNC
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/sspaddmm.cc:ge::CUST_IMPLEMT_INFERFUNC
|
||||
mindspore/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/op_proto/fractional_max_pool_3d_grad_with_fixed_ksize_proto.cc:ge::IMPLEMT_COMMON_INFERFUNC
|
|
@ -19,7 +19,6 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
|
||||
#include "common/kernel_util.h"
|
||||
#include "aicpu/common/aicpu_task_struct.h"
|
||||
|
@ -80,37 +79,5 @@ class KernelBase {
|
|||
std::vector<FWKAdapter::ShapeAndType *> input_shape_and_type_;
|
||||
std::vector<FWKAdapter::ShapeAndType *> output_shape_and_type_;
|
||||
};
|
||||
|
||||
inline size_t IntToSize(int u) {
|
||||
if (u < 0) {
|
||||
AICPU_LOGE("The int value [%d] is less than 0.", u);
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return static_cast<size_t>(u);
|
||||
}
|
||||
|
||||
inline int SizeToInt(size_t u) {
|
||||
if (u > static_cast<size_t>((std::numeric_limits<int>::max)())) {
|
||||
AICPU_LOGE("The size_t value [%lu] exceeds the maximum value of int.", u);
|
||||
return INT_MAX;
|
||||
}
|
||||
return static_cast<int>(u);
|
||||
}
|
||||
|
||||
inline size_t LongToSize(int64_t u) {
|
||||
if (u < 0) {
|
||||
AICPU_LOGE("The int64_t value [%ld] is less than 0.", u);
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return static_cast<size_t>(u);
|
||||
}
|
||||
|
||||
inline int32_t LongToInt(int64_t u) {
|
||||
if (u > static_cast<int64_t>((std::numeric_limits<int32_t>::max)())) {
|
||||
AICPU_LOGE("The size_t value [%ld] exceeds the maximum value of int.", u);
|
||||
return INT_MAX;
|
||||
}
|
||||
return static_cast<int32_t>(u);
|
||||
}
|
||||
} // namespace aicpu
|
||||
#endif // AICPU_OPS_AICPU_COMMON_KERNEL_BASE_H_
|
||||
|
|
|
@ -15,8 +15,41 @@
|
|||
*/
|
||||
#ifndef AICPU_OPS_AICPU_COMMON_KERNEL_UTIL_H_
|
||||
#define AICPU_OPS_AICPU_COMMON_KERNEL_UTIL_H_
|
||||
|
||||
#include <climits>
|
||||
#include <limits>
|
||||
#include "common/kernel_log.h"
|
||||
#ifndef AICPU_VISIBILITY_API
|
||||
#define AICPU_VISIBILITY_API __attribute__((visibility("default")))
|
||||
inline size_t IntToSize(int u) {
|
||||
if (u < 0) {
|
||||
AICPU_LOGE("The int value [%d] is less than 0.", u);
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return static_cast<size_t>(u);
|
||||
}
|
||||
|
||||
inline int SizeToInt(size_t u) {
|
||||
if (u > static_cast<size_t>((std::numeric_limits<int>::max)())) {
|
||||
AICPU_LOGE("The size_t value [%lu] exceeds the maximum value of int.", u);
|
||||
return INT_MAX;
|
||||
}
|
||||
return static_cast<int>(u);
|
||||
}
|
||||
|
||||
inline size_t LongToSize(int64_t u) {
|
||||
if (u < 0) {
|
||||
AICPU_LOGE("The int64_t value [%ld] is less than 0.", u);
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return static_cast<size_t>(u);
|
||||
}
|
||||
|
||||
inline int32_t LongToInt(int64_t u) {
|
||||
if (u > static_cast<int64_t>((std::numeric_limits<int32_t>::max)())) {
|
||||
AICPU_LOGE("The size_t value [%ld] exceeds the maximum value of int.", u);
|
||||
return INT_MAX;
|
||||
}
|
||||
return static_cast<int32_t>(u);
|
||||
}
|
||||
#endif
|
||||
#endif // AICPU_OPS_AICPU_COMMON_KERNEL_UTIL_H_
|
||||
|
|
|
@ -31,12 +31,23 @@ static inline std::shared_ptr<T> MakeShared(Args &&... args) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
#define REGISTER_CPU_KERNEL(type, clazz) \
|
||||
#define REGISTER_KERNEL(type, clazz) \
|
||||
std::shared_ptr<CpuKernel> Creator_##type##_Kernel() { \
|
||||
std::shared_ptr<clazz> ptr = nullptr; \
|
||||
ptr = MakeShared<clazz>(); \
|
||||
return ptr; \
|
||||
} \
|
||||
bool g_##type##_Kernel_Creator __attribute__((unused)) = RegistCpuKernel(type, Creator_##type##_Kernel)
|
||||
#define REGISTER_CUST_KERNEL(type, clazz) \
|
||||
std::shared_ptr<CpuKernel> Creator_Cust##type##_Kernel() { \
|
||||
std::shared_ptr<clazz> ptr = nullptr; \
|
||||
ptr = MakeShared<clazz>(); \
|
||||
return ptr; \
|
||||
} \
|
||||
bool g_Cust##type##_Kernel_Creator __attribute__((unused)) = \
|
||||
RegistCpuKernel("Cust" + static_cast<std::string>(type), Creator_Cust##type##_Kernel)
|
||||
#define REGISTER_CPU_KERNEL(type, clazz) \
|
||||
REGISTER_KERNEL(type, clazz); \
|
||||
REGISTER_CUST_KERNEL(type, clazz);
|
||||
} // namespace aicpu
|
||||
#endif // CPU_KERNEL_H
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gather_d_grad_v2.h"
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
#include "securec.h"
|
||||
#include "tile.h"
|
||||
#include "utils/eigen_tensor.h"
|
||||
#include "utils/kernel_util.h"
|
||||
#include "cpu_kernel_utils.h"
|
||||
#include "Eigen/Core"
|
||||
#include "mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/common/atomic_op.h"
|
||||
|
||||
namespace aicpu {
|
||||
namespace {
|
||||
const uint32_t kOutputNum = 1;
|
||||
const uint32_t kInputNum = 3;
|
||||
const char *kGatherDGradV2 = "GatherDGradV2";
|
||||
constexpr auto kDim = "dim";
|
||||
constexpr auto kAddressSize = 4;
|
||||
constexpr auto kDim0 = 0;
|
||||
constexpr auto kDim1 = 1;
|
||||
constexpr auto kDim2 = 2;
|
||||
constexpr auto kDim3 = 3;
|
||||
|
||||
template <typename T, typename S>
|
||||
static uint32_t GatherGrad(const T *index, const S *grad, S *output, int64_t dim_before_axis, int64_t dim_at_axis_index,
|
||||
int64_t dim_at_axis_output, int64_t dim_after_axis, CpuKernelContext &ctx) {
|
||||
if (dim_after_axis == 0) {
|
||||
AICPU_LOGE("dim_after_axis cannot be 0.");
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
int64_t number = dim_before_axis * dim_at_axis_index * dim_after_axis;
|
||||
bool status = false;
|
||||
auto shard_gather_grad = [&](size_t start, size_t end) {
|
||||
int64_t dim_input = dim_at_axis_index * dim_after_axis;
|
||||
int64_t dim_output = dim_at_axis_output * dim_after_axis;
|
||||
for (size_t id = start; id < end; ++id) {
|
||||
T j_read = index[id];
|
||||
auto max_index = static_cast<T>(dim_at_axis_output);
|
||||
if (j_read >= max_index || j_read < -max_index) {
|
||||
AICPU_LOGE("The value of 'dim' should be in [%d %d), but got %d", -max_index, max_index, j_read);
|
||||
AtomicAdd<bool>(&status, true);
|
||||
return;
|
||||
}
|
||||
if (j_read < 0) {
|
||||
j_read += max_index;
|
||||
}
|
||||
|
||||
int64_t signed_id = SizeToInt(id);
|
||||
int64_t signed_j_read = static_cast<int64_t>(j_read);
|
||||
int64_t read_id =
|
||||
signed_id / dim_input * dim_output + signed_j_read * dim_after_axis + signed_id % dim_after_axis;
|
||||
AtomicAdd<S>(output + read_id, grad[id]);
|
||||
}
|
||||
};
|
||||
|
||||
const int64_t per_unit_size = number / std::thread::hardware_concurrency();
|
||||
KERNEL_HANDLE_ERROR(CpuKernelUtils::ParallelFor(ctx, number, per_unit_size, shard_gather_grad),
|
||||
"GatherDGradV2 compute failed.");
|
||||
if (status) {
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
return KERNEL_STATUS_OK;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
template <typename T, typename S>
|
||||
uint32_t GatherDGradV2Kernel::GatherDGradV2Task(CpuKernelContext &ctx) {
|
||||
T *index = reinterpret_cast<T *>(ctx.Input(kDim1)->GetData());
|
||||
S *grad = reinterpret_cast<S *>(ctx.Input(kDim2)->GetData());
|
||||
S *output = reinterpret_cast<S *>(ctx.Output(kDim0)->GetData());
|
||||
|
||||
int64_t output_rank = static_cast<int64_t>(output_shape_.size());
|
||||
if (dim_ >= output_rank || dim_ < -output_rank) {
|
||||
AICPU_LOGE("The value of 'dim' should be in [%d %d), but got %d", -output_rank, output_rank, dim_);
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
if (dim_ < 0) {
|
||||
dim_ = dim_ + output_rank;
|
||||
}
|
||||
int64_t grad_rank = static_cast<int64_t>(grad_shape_.size());
|
||||
if (dim_ >= grad_rank) {
|
||||
AICPU_LOGE("The value of 'dim' should be in [%d %d), but got %d", -grad_rank, grad_rank, dim_);
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
|
||||
int64_t dim_before_axis =
|
||||
std::accumulate(output_shape_.begin(), output_shape_.begin() + dim_, 1, std::multiplies<int64_t>());
|
||||
int64_t dim_at_axis_grad = grad_shape_[LongToSize(dim_)];
|
||||
int64_t dim_at_axis_output = output_shape_[LongToSize(dim_)];
|
||||
int64_t dim_after_axis =
|
||||
std::accumulate(output_shape_.begin() + dim_ + 1, output_shape_.end(), 1, std::multiplies<int64_t>());
|
||||
int64_t output_size = dim_before_axis * dim_at_axis_output * dim_after_axis * sizeof(S);
|
||||
if (memset_s(output, output_size, 0x0, output_size) != EOK) {
|
||||
AICPU_LOGE("memset_s failed!");
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
return GatherGrad(index, grad, output, dim_before_axis, dim_at_axis_grad, dim_at_axis_output, dim_after_axis, ctx);
|
||||
}
|
||||
|
||||
uint32_t GatherDGradV2Kernel::ParseKernelParam(CpuKernelContext &ctx) {
|
||||
KERNEL_HANDLE_ERROR(NormalCheck(ctx, kInputNum, kOutputNum), "GatherDGradV2 check input and output number failed.");
|
||||
// ori input
|
||||
input_shape_ = ctx.Input(kDim0)->GetTensorShape()->GetDimSizes();
|
||||
|
||||
// index input
|
||||
auto input_tensor = ctx.Input(kDim1);
|
||||
index_type_ = input_tensor->GetDataType();
|
||||
index_shape_ = input_tensor->GetTensorShape()->GetDimSizes();
|
||||
|
||||
// grad input
|
||||
auto grad_tensor = ctx.Input(kDim2);
|
||||
grad_type_ = grad_tensor->GetDataType();
|
||||
grad_shape_ = grad_tensor->GetTensorShape()->GetDimSizes();
|
||||
if (index_shape_ != grad_shape_) {
|
||||
AICPU_LOGE("the shape of index and grad should be same!");
|
||||
return KERNEL_STATUS_PARAM_INVALID;
|
||||
}
|
||||
|
||||
// output
|
||||
auto output_tensor = ctx.Output(kDim0);
|
||||
output_shape_ = output_tensor->GetTensorShape()->GetDimSizes();
|
||||
if (output_shape_ != input_shape_) {
|
||||
AICPU_LOGE("the shape of input and output should be same!");
|
||||
return KERNEL_STATUS_PARAM_INVALID;
|
||||
}
|
||||
|
||||
dim_ = ctx.GetAttr(kDim)->GetInt();
|
||||
return KERNEL_STATUS_OK;
|
||||
}
|
||||
|
||||
using namespace std::placeholders;
|
||||
uint32_t GatherDGradV2Kernel::Compute(CpuKernelContext &ctx) {
|
||||
ParseKernelParam(ctx);
|
||||
std::map<DataType, std::map<DataType, std::function<uint32_t(CpuKernelContext &)>>> calls;
|
||||
// index int32
|
||||
calls[DT_INT32][DT_INT8] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, int8_t>, this, _1);
|
||||
calls[DT_INT32][DT_INT16] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, int16_t>, this, _1);
|
||||
calls[DT_INT32][DT_INT32] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, int32_t>, this, _1);
|
||||
calls[DT_INT32][DT_INT64] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, int64_t>, this, _1);
|
||||
calls[DT_INT32][DT_FLOAT16] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, Eigen::half>, this, _1);
|
||||
calls[DT_INT32][DT_FLOAT] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, float>, this, _1);
|
||||
calls[DT_INT32][DT_DOUBLE] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, double>, this, _1);
|
||||
calls[DT_INT32][DT_UINT8] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, uint8_t>, this, _1);
|
||||
calls[DT_INT32][DT_UINT16] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, uint16_t>, this, _1);
|
||||
calls[DT_INT32][DT_UINT32] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, uint32_t>, this, _1);
|
||||
calls[DT_INT32][DT_UINT64] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, uint64_t>, this, _1);
|
||||
calls[DT_INT32][DT_BOOL] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int32_t, bool>, this, _1);
|
||||
// index int64
|
||||
calls[DT_INT64][DT_INT8] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, int8_t>, this, _1);
|
||||
calls[DT_INT64][DT_INT16] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, int16_t>, this, _1);
|
||||
calls[DT_INT64][DT_INT32] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, int32_t>, this, _1);
|
||||
calls[DT_INT64][DT_INT64] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, int64_t>, this, _1);
|
||||
calls[DT_INT64][DT_FLOAT16] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, Eigen::half>, this, _1);
|
||||
calls[DT_INT64][DT_FLOAT] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, float>, this, _1);
|
||||
calls[DT_INT64][DT_DOUBLE] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, double>, this, _1);
|
||||
calls[DT_INT64][DT_UINT8] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, uint8_t>, this, _1);
|
||||
calls[DT_INT64][DT_UINT16] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, uint16_t>, this, _1);
|
||||
calls[DT_INT64][DT_UINT32] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, uint32_t>, this, _1);
|
||||
calls[DT_INT64][DT_UINT64] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, uint64_t>, this, _1);
|
||||
calls[DT_INT64][DT_BOOL] = std::bind(&GatherDGradV2Kernel::GatherDGradV2Task<int64_t, bool>, this, _1);
|
||||
|
||||
if (calls.find(index_type_) == calls.end()) {
|
||||
AICPU_LOGE("GatherDGradV2 op don't support index tensor types: %s", typeid(index_type_).name());
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
return calls[index_type_][grad_type_](ctx);
|
||||
}
|
||||
|
||||
REGISTER_CPU_KERNEL(kGatherDGradV2, GatherDGradV2Kernel);
|
||||
} // namespace aicpu
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef AICPU_KERNELS_NORMALIZED_GATHER_D_GRAD_V2_H_
|
||||
#define AICPU_KERNELS_NORMALIZED_GATHER_D_GRAD_V2_H_
|
||||
|
||||
#include "cpu_ops_kernel.h"
|
||||
|
||||
namespace aicpu {
|
||||
class GatherDGradV2Kernel : public CpuKernel {
|
||||
public:
|
||||
GatherDGradV2Kernel() = default;
|
||||
~GatherDGradV2Kernel() override = default;
|
||||
|
||||
protected:
|
||||
uint32_t Compute(CpuKernelContext &ctx) override;
|
||||
|
||||
private:
|
||||
uint32_t ParseKernelParam(CpuKernelContext &ctx);
|
||||
|
||||
template <typename T, typename S>
|
||||
uint32_t GatherDGradV2Task(CpuKernelContext &ctx);
|
||||
|
||||
int64_t dim_{0};
|
||||
std::vector<int64_t> input_shape_;
|
||||
std::vector<int64_t> index_shape_;
|
||||
std::vector<int64_t> grad_shape_;
|
||||
std::vector<int64_t> output_shape_;
|
||||
|
||||
DataType index_type_{DT_UNDEFINED};
|
||||
DataType grad_type_{DT_UNDEFINED};
|
||||
};
|
||||
} // namespace aicpu
|
||||
#endif
|
|
@ -0,0 +1,253 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "slice_grad.h"
|
||||
#include <functional>
|
||||
#include "securec.h"
|
||||
#include "cpu_kernel_utils.h"
|
||||
#include "unsupported/Eigen/CXX11/Tensor"
|
||||
#include "status.h"
|
||||
#include "utils/kernel_util.h"
|
||||
|
||||
namespace aicpu {
|
||||
namespace {
|
||||
const char *kSliceGrad = "SliceGrad";
|
||||
constexpr size_t kInputNum = 4;
|
||||
constexpr size_t kOutputNum = 1;
|
||||
constexpr size_t kDim2 = 2;
|
||||
constexpr size_t kDim3 = 3;
|
||||
} // namespace
|
||||
|
||||
bool SliceGradKernel::CheckParams() const {
|
||||
// check dy shape, N-D
|
||||
auto n = dy_shape_.size();
|
||||
if (n == 0) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'dy' shape can not be empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// check begin shape, 1-D with shape [N]
|
||||
if (begin_shape_.size() != 1) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'begin' shape rank must be 1, but got %lu", begin_shape_.size());
|
||||
return false;
|
||||
}
|
||||
if (LongToSize(begin_shape_[0]) != n) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'begin' shape must be [%lu], but got [%ld]", n, begin_shape_[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check size shape, 1-D with shape [N]
|
||||
if (size_shape_.size() != 1) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'size' shape rank must be 1, but got %lu", size_shape_.size());
|
||||
return false;
|
||||
}
|
||||
if (LongToSize(size_shape_[0]) != n) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'size' shape must be [%lu], but got [%ld]", n, size_shape_[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check output shape, N-D
|
||||
if (output_shape_.size() != n) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'dy' shape and output tensor shape must have same rank, but got %lu vs %lu", n,
|
||||
output_shape_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (dy_shape_[i] <= 0 || dy_shape_[i] > output_shape_[i]) {
|
||||
AICPU_LOGE(
|
||||
"For 'SliceGrad', it is required that 0 < 'dy' shape[%lu] <= output tensor shape[%lu], but got %ld vs %ld", i,
|
||||
i, dy_shape_[i], output_shape_[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SliceGradKernel::CheckBeginSizeValue() {
|
||||
for (size_t i = 0; i < begin_value_.size(); ++i) {
|
||||
if (begin_value_[i] < 0 || begin_value_[i] >= output_shape_[i]) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'begin' [%lu] must be in range [0, %ld), but got %ld", i, output_shape_[i],
|
||||
begin_value_[i]);
|
||||
return false;
|
||||
}
|
||||
if (size_value_[i] < 0) {
|
||||
size_value_[i] = output_shape_[i] - begin_value_[i];
|
||||
}
|
||||
if (size_value_[i] != dy_shape_[i]) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'size' [%lu] must be equal to 'dy' shape[%lu], but got %ld vs %ld", i, i,
|
||||
size_value_[i], dy_shape_[i]);
|
||||
return false;
|
||||
}
|
||||
if (begin_value_[i] + size_value_[i] > output_shape_[i]) {
|
||||
AICPU_LOGE(
|
||||
"For 'SliceGrad', 'begin' [%lu] + 'size' [%lu] must be <= output tensor shape[%lu], but got %ld, %ld, %ld", i,
|
||||
i, i, begin_value_[i], size_value_[i], output_shape_[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename S>
|
||||
uint32_t SliceGradKernel::SliceGradTask(CpuKernelContext &ctx) {
|
||||
if (!CheckParams()) {
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
|
||||
S *dy_addr = reinterpret_cast<S *>(ctx.Input(0)->GetData());
|
||||
T *begin_addr = reinterpret_cast<T *>(ctx.Input(kDim2)->GetData());
|
||||
T *size_addr = reinterpret_cast<T *>(ctx.Input(kDim3)->GetData());
|
||||
S *out_addr = reinterpret_cast<S *>(ctx.Output(0)->GetData());
|
||||
|
||||
for (size_t i = 0; i < dy_shape_.size(); ++i) {
|
||||
begin_value_.push_back(static_cast<int64_t>(begin_addr[i]));
|
||||
size_value_.push_back(static_cast<int64_t>(size_addr[i]));
|
||||
}
|
||||
if (!CheckBeginSizeValue()) {
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
|
||||
// Calc process
|
||||
// 1. fill output address with 0
|
||||
int64_t output_num = std::accumulate(output_shape_.begin(), output_shape_.end(), 1, std::multiplies<int64_t>());
|
||||
size_t output_byte = LongToSize(output_num) * sizeof(S);
|
||||
if (memset_s(out_addr, output_byte, 0, output_byte) != EOK) {
|
||||
AICPU_LOGE("For 'SliceGrad', memset_s on output tensor address failed!");
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
|
||||
// 2. copy dy_addr to out_addr
|
||||
// case: 1D
|
||||
if (dy_shape_.size() == 1) {
|
||||
size_t block_byte = LongToSize(dy_shape_[0]) * sizeof(S);
|
||||
S *out_start_addr = out_addr + begin_value_[0];
|
||||
if (memcpy_s(out_start_addr, block_byte, dy_addr, block_byte) != EOK) {
|
||||
AICPU_LOGE("For 'SliceGrad', memcpy_s failed!");
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
return KERNEL_STATUS_OK;
|
||||
}
|
||||
// case: > 1D (0D already checked inside CheckParams), the last dim will be scheduled as a block
|
||||
std::vector<size_t> dy_block_shape;
|
||||
(void)std::transform(dy_shape_.begin(), dy_shape_.end() - 1, std::back_inserter(dy_block_shape), LongToSize);
|
||||
|
||||
std::vector<size_t> out_block_shape_acc{1};
|
||||
size_t acc = 1;
|
||||
for (size_t i = output_shape_.size() - kDim2; i > 0; --i) {
|
||||
acc *= LongToSize(output_shape_[i]);
|
||||
(void)out_block_shape_acc.insert(out_block_shape_acc.begin(), acc);
|
||||
}
|
||||
|
||||
auto block_task = [this, &dy_addr, &out_addr, &dy_block_shape, &out_block_shape_acc](size_t start, size_t end) {
|
||||
for (size_t i = start; i < end; ++i) {
|
||||
size_t k = 0;
|
||||
auto a = i;
|
||||
for (size_t j = 0; j < dy_block_shape.size(); ++j) {
|
||||
size_t m = dy_block_shape.size() - 1 - j;
|
||||
auto idx = a % dy_block_shape[m] + LongToSize(begin_value_[m]);
|
||||
a /= dy_block_shape[m];
|
||||
k += idx * out_block_shape_acc[m];
|
||||
}
|
||||
auto block_sz = LongToSize(dy_shape_.back());
|
||||
size_t block_byte = block_sz * sizeof(S);
|
||||
S *dy_start_addr = dy_addr + i * block_sz;
|
||||
S *out_start_addr = out_addr + k * LongToSize(output_shape_.back()) + begin_value_.back();
|
||||
if (memcpy_s(out_start_addr, block_byte, dy_start_addr, block_byte) != EOK) {
|
||||
AICPU_LOGE("For 'SliceGrad', memcpy_s failed! Current block index is %lu", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int64_t block_num = 1;
|
||||
for (size_t i = 0; i < dy_shape_.size() - 1; ++i) {
|
||||
block_num *= dy_shape_[i];
|
||||
}
|
||||
const int64_t per_unit_size = block_num / static_cast<int64_t>(std::thread::hardware_concurrency());
|
||||
KERNEL_HANDLE_ERROR(CpuKernelUtils::ParallelFor(ctx, block_num, per_unit_size, block_task),
|
||||
"SliceGrad Compute failed.");
|
||||
|
||||
return KERNEL_STATUS_OK;
|
||||
}
|
||||
|
||||
uint32_t SliceGradKernel::ParseKernelParam(CpuKernelContext &ctx) {
|
||||
KERNEL_HANDLE_ERROR(NormalCheck(ctx, kInputNum, kOutputNum), "SliceGrad check input and output number failed.");
|
||||
// dy
|
||||
auto dy_tensor = ctx.Input(0);
|
||||
dy_shape_ = dy_tensor->GetTensorShape()->GetDimSizes();
|
||||
dy_type_ = dy_tensor->GetDataType();
|
||||
|
||||
// begin
|
||||
auto begin_tensor = ctx.Input(SizeToInt(kDim2));
|
||||
begin_shape_ = begin_tensor->GetTensorShape()->GetDimSizes();
|
||||
begin_type_ = begin_tensor->GetDataType();
|
||||
|
||||
// size
|
||||
auto size_tensor = ctx.Input(SizeToInt(kDim3));
|
||||
size_shape_ = size_tensor->GetTensorShape()->GetDimSizes();
|
||||
auto size_type = size_tensor->GetDataType();
|
||||
if (size_type != begin_type_) {
|
||||
AICPU_LOGE("For 'SliceGrad', 'begin' and 'size' must have same data type.");
|
||||
return KERNEL_STATUS_PARAM_INVALID;
|
||||
}
|
||||
|
||||
auto output_tensor = ctx.Output(0);
|
||||
output_shape_ = output_tensor->GetTensorShape()->GetDimSizes();
|
||||
return KERNEL_STATUS_OK;
|
||||
}
|
||||
|
||||
using namespace std::placeholders;
|
||||
uint32_t SliceGradKernel::Compute(CpuKernelContext &ctx) {
|
||||
ParseKernelParam(ctx);
|
||||
std::unordered_map<aicpu::DataType, std::unordered_map<aicpu::DataType, std::function<uint32_t(CpuKernelContext &)>>>
|
||||
func_list;
|
||||
// begin type int32
|
||||
func_list[DT_INT32][DT_FLOAT16] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, Eigen::half>, this, _1);
|
||||
func_list[DT_INT32][DT_FLOAT] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, float>, this, _1);
|
||||
func_list[DT_INT32][DT_DOUBLE] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, double>, this, _1);
|
||||
func_list[DT_INT32][DT_UINT8] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, uint8_t>, this, _1);
|
||||
func_list[DT_INT32][DT_UINT16] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, uint16_t>, this, _1);
|
||||
func_list[DT_INT32][DT_UINT32] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, uint32_t>, this, _1);
|
||||
func_list[DT_INT32][DT_UINT64] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, uint64_t>, this, _1);
|
||||
func_list[DT_INT32][DT_INT8] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, int8_t>, this, _1);
|
||||
func_list[DT_INT32][DT_INT16] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, int16_t>, this, _1);
|
||||
func_list[DT_INT32][DT_INT32] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, int32_t>, this, _1);
|
||||
func_list[DT_INT32][DT_INT64] = std::bind(&SliceGradKernel::SliceGradTask<int32_t, int64_t>, this, _1);
|
||||
// begin type int64
|
||||
func_list[DT_INT64][DT_FLOAT16] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, Eigen::half>, this, _1);
|
||||
func_list[DT_INT64][DT_FLOAT] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, float>, this, _1);
|
||||
func_list[DT_INT64][DT_DOUBLE] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, double>, this, _1);
|
||||
func_list[DT_INT64][DT_UINT8] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, uint8_t>, this, _1);
|
||||
func_list[DT_INT64][DT_UINT16] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, uint16_t>, this, _1);
|
||||
func_list[DT_INT64][DT_UINT32] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, uint32_t>, this, _1);
|
||||
func_list[DT_INT64][DT_UINT64] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, uint64_t>, this, _1);
|
||||
func_list[DT_INT64][DT_INT8] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, int8_t>, this, _1);
|
||||
func_list[DT_INT64][DT_INT16] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, int16_t>, this, _1);
|
||||
func_list[DT_INT64][DT_INT32] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, int32_t>, this, _1);
|
||||
func_list[DT_INT64][DT_INT64] = std::bind(&SliceGradKernel::SliceGradTask<int64_t, int64_t>, this, _1);
|
||||
|
||||
if (func_list.find(begin_type_) == func_list.end()) {
|
||||
AICPU_LOGE("'SliceGrad' does not support current 'begin' type.");
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
if (func_list[begin_type_].find(dy_type_) == func_list[begin_type_].end()) {
|
||||
AICPU_LOGE("'SliceGrad' does not support current 'dy' type.");
|
||||
return KERNEL_STATUS_INNER_ERROR;
|
||||
}
|
||||
return func_list[begin_type_][dy_type_](ctx);
|
||||
}
|
||||
REGISTER_CPU_KERNEL(kSliceGrad, SliceGradKernel);
|
||||
} // namespace aicpu
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef AICPU_KERNELS_NORMALIZED_SLICEGRAD_H_
|
||||
#define AICPU_KERNELS_NORMALIZED_SLICEGRAD_H_
|
||||
|
||||
#include "cpu_ops_kernel.h"
|
||||
#include <vector>
|
||||
|
||||
namespace aicpu {
|
||||
class SliceGradKernel : public CpuKernel {
|
||||
public:
|
||||
SliceGradKernel() = default;
|
||||
~SliceGradKernel() override = default;
|
||||
|
||||
protected:
|
||||
uint32_t Compute(CpuKernelContext &ctx) override;
|
||||
|
||||
private:
|
||||
template <typename T, typename S>
|
||||
uint32_t SliceGradTask(CpuKernelContext &ctx);
|
||||
bool CheckParams() const;
|
||||
uint32_t ParseKernelParam(CpuKernelContext &ctx);
|
||||
bool CheckBeginSizeValue();
|
||||
|
||||
std::vector<int64_t> dy_shape_;
|
||||
std::vector<int64_t> begin_shape_;
|
||||
std::vector<int64_t> size_shape_;
|
||||
std::vector<int64_t> output_shape_;
|
||||
std::vector<int64_t> begin_value_;
|
||||
std::vector<int64_t> size_value_;
|
||||
DataType dy_type_{DT_UNDEFINED};
|
||||
DataType begin_type_{DT_UNDEFINED};
|
||||
};
|
||||
} // namespace aicpu
|
||||
#endif
|
|
@ -299,5 +299,36 @@ uint32_t CheckTensorTypeSame(const std::map<std::string, DataType> &types, const
|
|||
uint32_t CheckTensorShapeSame(const std::map<std::string, TensorShapePtr> &shapes,
|
||||
const std::vector<int64_t> &check_shape, const std::string &prim_name);
|
||||
|
||||
inline size_t IntToSize(int u) {
|
||||
if (u < 0) {
|
||||
AICPU_LOGE("The int value [%d] is less than 0.", u);
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return static_cast<size_t>(u);
|
||||
}
|
||||
|
||||
inline int SizeToInt(size_t u) {
|
||||
if (u > static_cast<size_t>((std::numeric_limits<int>::max)())) {
|
||||
AICPU_LOGE("The size_t value [%lu] exceeds the maximum value of int.", u);
|
||||
return INT_MAX;
|
||||
}
|
||||
return static_cast<int>(u);
|
||||
}
|
||||
|
||||
inline size_t LongToSize(int64_t u) {
|
||||
if (u < 0) {
|
||||
AICPU_LOGE("The int64_t value [%ld] is less than 0.", u);
|
||||
return SIZE_MAX;
|
||||
}
|
||||
return static_cast<size_t>(u);
|
||||
}
|
||||
|
||||
inline int32_t LongToInt(int64_t u) {
|
||||
if (u > static_cast<int64_t>((std::numeric_limits<int32_t>::max)())) {
|
||||
AICPU_LOGE("The size_t value [%ld] exceeds the maximum value of int.", u);
|
||||
return INT_MAX;
|
||||
}
|
||||
return static_cast<int32_t>(u);
|
||||
}
|
||||
} // namespace aicpu
|
||||
#endif
|
||||
|
|
|
@ -39,6 +39,9 @@ add_subdirectory(op_proto)
|
|||
set(INSTALL_LIBRARY_DIR ${BUILD_PATH}/package/mindspore/lib/plugin/ascend)
|
||||
install(DIRECTORY ${OUTPUT_DIR} DESTINATION ${INSTALL_LIBRARY_DIR})
|
||||
# copy libmindspore_cpu_kernels.so to ${OP_IMPL_PATH} and rename to libcust_aicpu_kernels.so
|
||||
set(IMPL_FILE ${CMAKE_CURRENT_BINARY_DIR}/../cpu_kernel/libmindspore_cpu_kernels.so)
|
||||
set(CPU_KERNELS ${CMAKE_CURRENT_BINARY_DIR}/../cpu_kernel/libmindspore_cpu_kernels.so)
|
||||
set(AICPU_KERNELS ${CMAKE_CURRENT_BINARY_DIR}/../libmindspore_aicpu_kernels.so)
|
||||
set(INPL_FILE_DIR ${INSTALL_LIBRARY_DIR}/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl)
|
||||
install(FILES ${IMPL_FILE} RENAME "libcust_aicpu_kernels.so" DESTINATION ${INPL_FILE_DIR})
|
||||
set(ENV{CMAKE_INSTALL_MODE} REL_SYMLINK)
|
||||
install(FILES ${CPU_KERNELS} RENAME "libcust_cpu_kernels.so" DESTINATION ${INPL_FILE_DIR})
|
||||
install(FILES ${AICPU_KERNELS} RENAME "libcust_aicpu_kernels.so" DESTINATION ${INPL_FILE_DIR})
|
File diff suppressed because it is too large
Load Diff
|
@ -14,13 +14,13 @@ endif()
|
|||
|
||||
# add source files
|
||||
aux_source_directory(. SRCS)
|
||||
set(SRCS ${SRCS}
|
||||
../utils/util.cc
|
||||
../utils/transfer_shape_according_to_format.cc
|
||||
../utils/axis_util.cc
|
||||
../src/error_util.cc
|
||||
../src/op_util.cc)
|
||||
aux_source_directory(utils UTILS_SRCS)
|
||||
|
||||
add_library(${OP_PROTO_TARGET} SHARED ${SRCS})
|
||||
include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc/transform/graph_ir/)
|
||||
|
||||
target_link_libraries(${OP_PROTO_TARGET} ${ASCEND_TENSOR_COMPILER}/lib64/libgraph.so)
|
||||
add_library(${OP_PROTO_TARGET} SHARED ${SRCS} ${UTILS_SRCS})
|
||||
|
||||
find_library(register libregister.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
find_library(graph libgraph.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
target_link_libraries(${OP_PROTO_TARGET} ${register})
|
||||
target_link_libraries(${OP_PROTO_TARGET} ${graph})
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/adaptive_avg_pool_3d_grad_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "external/graph/operator_reg.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// --------- AdaptiveAvgPool3dGrad ---------------
|
||||
CUST_IMPLEMT_VERIFIER(AdaptiveAvgPool3dGrad, AdaptiveAvgPool3dGradVerify) {
|
||||
auto input_grad_desc = op.GetInputDescByName("input_grad");
|
||||
auto orig_input_shape_desc = op.GetInputDescByName("orig_input_shape");
|
||||
ge::AscendString op_name;
|
||||
(void)op.GetName(op_name);
|
||||
|
||||
auto orig_input_shape_dim = orig_input_shape_desc.GetShape().GetDimNum();
|
||||
if (orig_input_shape_dim != 1) {
|
||||
OP_LOGE("AdaptiveAvgPool3dGrad", "Num Dim of orig_input_shape is invalid");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
|
||||
auto orig_input_dim_num = orig_input_shape_desc.GetShape().GetShapeSize();
|
||||
auto input_grad_dim_num = input_grad_desc.GetShape().GetDimNum();
|
||||
|
||||
if (orig_input_dim_num != static_cast<int64_t>(input_grad_dim_num)) {
|
||||
OP_LOGE("AdaptiveAvgPool3dGrad", "Num Dim of orig_input and input_grad should be the same");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
IMPLEMT_COMMON_INFERFUNC(AdaptiveAvgPool3dGradInferShape) {
|
||||
map<int, std::string> format2str = {
|
||||
{ge::FORMAT_NCHW, "NCHW"}, {ge::FORMAT_NHWC, "NHWC"}, {ge::FORMAT_HWCN, "HWCN"}, {ge::FORMAT_DHWNC, "DHWNC"},
|
||||
{ge::FORMAT_DHWCN, "DHWCN"}, {ge::FORMAT_NDHWC, "NDHWC"}, {ge::FORMAT_NCDHW, "NCDHW"}};
|
||||
|
||||
auto input_desc = op.GetInputDescByName("input_grad");
|
||||
auto orig_input_shape_desc = op.GetInputDescByName("orig_input_shape");
|
||||
TensorDesc out_desc = op.GetOutputDescByName("output_grad");
|
||||
ge::AscendString op_name;
|
||||
(void)op.GetName(op_name);
|
||||
|
||||
// update format
|
||||
Format input_format = input_desc.GetFormat();
|
||||
std::string format_str = format2str[input_format];
|
||||
if (input_format != FORMAT_NCHW) {
|
||||
OP_LOGE("AdaptiveAvgPool3dGrad",
|
||||
"Input format only support NCHW"
|
||||
", input format is [%s]",
|
||||
format_str.c_str());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
out_desc.SetFormat(input_format);
|
||||
|
||||
// update data type
|
||||
DataType input_type = input_desc.GetDataType();
|
||||
out_desc.SetDataType(input_type);
|
||||
|
||||
// infer shape
|
||||
Tensor orig_input_size_tensor;
|
||||
if (op.GetInputConstData("orig_input_shape", orig_input_size_tensor) != GRAPH_SUCCESS) {
|
||||
OP_LOGE("AdaptiveAvgPool3dGrad", "failed to get tensor from output_size");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
int32_t *orig_input_size_data = reinterpret_cast<int32_t *>(orig_input_size_tensor.GetData());
|
||||
if (orig_input_size_data == nullptr) {
|
||||
OP_LOGE("AdaptiveAvgPool3dGrad", "output_size data is invalid");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
|
||||
auto input_size_dim_num = input_desc.GetShape().GetDimNum();
|
||||
std::vector<int64_t> output_shape(input_size_dim_num);
|
||||
|
||||
for (uint64_t i = 0; i < input_size_dim_num; ++i) {
|
||||
output_shape[i] = orig_input_size_data[i];
|
||||
}
|
||||
|
||||
out_desc.SetShape(Shape(output_shape));
|
||||
if (op.UpdateOutputDesc("output_grad", out_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE("AdaptiveAvgPool3dGrad", "failed to update output desc");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(AdaptiveAvgPool3dGrad, AdaptiveAvgPool3dGradInferShape);
|
||||
CUST_VERIFY_FUNC_REG(AdaptiveAvgPool3dGrad, AdaptiveAvgPool3dGradVerify);
|
||||
// --------- AdaptiveAvgPool3dGrad end---------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/adaptive_avg_pool_3d_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// --------- AdaptiveAvgPool3d ---------------
|
||||
IMPLEMT_COMMON_INFERFUNC(AdaptiveAvgPool3dInferShape) {
|
||||
map<int, std::string> format2str = {
|
||||
{ge::FORMAT_NCHW, "NCHW"}, {ge::FORMAT_NHWC, "NHWC"}, {ge::FORMAT_HWCN, "HWCN"}, {ge::FORMAT_DHWNC, "DHWNC"},
|
||||
{ge::FORMAT_DHWCN, "DHWCN"}, {ge::FORMAT_NDHWC, "NDHWC"}, {ge::FORMAT_NCDHW, "NCDHW"}};
|
||||
|
||||
// verify the dim of output_size
|
||||
auto output_size_desc = op.GetInputDescByName("output_size");
|
||||
auto output_size_dim = output_size_desc.GetShape().GetDimNum();
|
||||
ge::AscendString op_name;
|
||||
(void)op.GetName(op_name);
|
||||
if (output_size_dim != 1) {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "Num Dim of output_szie is invalid");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
|
||||
auto input_desc = op.GetInputDescByName("x");
|
||||
TensorDesc out_desc = op.GetOutputDescByName("y");
|
||||
|
||||
// update data type
|
||||
DataType input_type = input_desc.GetDataType();
|
||||
out_desc.SetDataType(input_type);
|
||||
|
||||
// update format
|
||||
Format input_format = input_desc.GetFormat();
|
||||
std::string format_str = format2str[input_format];
|
||||
if (input_format != FORMAT_NCHW) {
|
||||
OP_LOGE("AdaptiveAvgPool3d",
|
||||
"Input format only support NCHW"
|
||||
", input format is [%s]",
|
||||
format_str.c_str());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
out_desc.SetFormat(input_format);
|
||||
|
||||
std::vector<int64_t> input_size_shape = input_desc.GetShape().GetDims();
|
||||
auto input_size_dim_num = input_size_shape.size();
|
||||
std::vector<int64_t> output_shape(input_size_dim_num);
|
||||
for (uint64_t i = 0; i < input_size_dim_num - 3; ++i) {
|
||||
output_shape[i] = input_size_shape[i];
|
||||
}
|
||||
|
||||
Tensor output_size_tensor;
|
||||
if (op.GetInputConstData("output_size", output_size_tensor) != GRAPH_SUCCESS) {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "failed to get tensor from output_size");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
int32_t *output_size_data = reinterpret_cast<int32_t *>(output_size_tensor.GetData());
|
||||
if (output_size_data == nullptr) {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "output_size data is invalid");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
|
||||
auto output_size_num = output_size_desc.GetShape().GetShapeSize();
|
||||
if (output_size_num == 1) {
|
||||
for (uint64_t i = input_size_dim_num - 3; i < input_size_dim_num; ++i) {
|
||||
if (output_size_data[0] < 0) {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "Value of output_size can\'t be negative");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
output_shape[i] = output_size_data[0];
|
||||
}
|
||||
} else if (output_size_num == 3) {
|
||||
for (uint64_t i = input_size_dim_num - 3; i < input_size_dim_num; ++i) {
|
||||
auto data = output_size_data[i - input_size_dim_num + 3];
|
||||
if (data < 0) {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "Value of output_size can\'t be negative");
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
output_shape[i] = data;
|
||||
}
|
||||
} else {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "Shape of output_size is invalid");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
out_desc.SetShape(Shape(output_shape));
|
||||
if (op.UpdateOutputDesc("y", out_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE("AdaptiveAvgPool3d", "failed to update output desc");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(AdaptiveAvgPool3d, AdaptiveAvgPool3dInferShape);
|
||||
// --------- AdaptiveAvgPool3d end---------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/adaptive_max_pool3_d_grad_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_INFERFUNC(AdaptiveMaxPool3dGrad, AdaptiveMaxPool3dGradInferShape) {
|
||||
TensorDesc output_grad = op.GetOutputDescByName("output_grad");
|
||||
TensorDesc input = op.GetInputDescByName("x");
|
||||
DataType input_dtype = input.GetDataType();
|
||||
Shape input_shape = input.GetShape();
|
||||
output_grad.SetShape(input_shape);
|
||||
output_grad.SetDataType(input_dtype);
|
||||
if (op.UpdateOutputDesc("output_grad", output_grad) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(AdaptiveMaxPool3dGrad, AdaptiveMaxPool3dGradVerify) { return GRAPH_SUCCESS; }
|
||||
|
||||
CUST_INFER_FUNC_REG(AdaptiveMaxPool3dGrad, AdaptiveMaxPool3dGradInferShape);
|
||||
CUST_VERIFY_FUNC_REG(AdaptiveMaxPool3dGrad, AdaptiveMaxPool3dGradVerify);
|
||||
} // namespace ge
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/adaptive_max_pool3d_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_INFERFUNC(AdaptiveMaxPool3d, AdaptiveMaxPool3dInferShape) {
|
||||
TensorDesc input = op.GetInputDesc(0);
|
||||
TensorDesc output_size = op.GetInputDesc(1);
|
||||
TensorDesc output = op.GetOutputDesc(0);
|
||||
TensorDesc argmax = op.GetOutputDesc(1);
|
||||
|
||||
const size_t input_num_dims = input.GetShape().GetDimNum();
|
||||
const std::vector<int64_t> output_size_shape = output_size.GetShape().GetDims();
|
||||
if ((input_num_dims == 4 || input_num_dims == 5) == false) {
|
||||
OP_LOGE(TbeGetName(op), "Input dimensions must be equal to 4 or 5.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (output_size_shape.size() != 1) {
|
||||
OP_LOGE(TbeGetName(op), "output_size dim should be equal to 1.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (output_size_shape[0] != 3) {
|
||||
OP_LOGE(TbeGetName(op), "output_size shape[0] should be equal to 3.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
DataType input_dtype = input.GetDataType();
|
||||
Shape output_shape(UNKNOWN_SHAPE);
|
||||
output.SetDataType(input_dtype);
|
||||
output.SetShape(output_shape);
|
||||
argmax.SetDataType(DT_INT32);
|
||||
argmax.SetShape(output_shape);
|
||||
(void)op.UpdateOutputDesc("y", output);
|
||||
(void)op.UpdateOutputDesc("argmax", argmax);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(AdaptiveMaxPool3d, AdaptiveMaxPool3dVerify) { return GRAPH_SUCCESS; }
|
||||
|
||||
CUST_INFER_FUNC_REG(AdaptiveMaxPool3d, AdaptiveMaxPool3dInferShape);
|
||||
CUST_VERIFY_FUNC_REG(AdaptiveMaxPool3d, AdaptiveMaxPool3dVerify);
|
||||
} // namespace ge
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/adaptive_max_pool_2d_grad_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_INFERFUNC(AdaptiveMaxPool2dGrad, AdaptiveMaxPool2dGradInferShape) {
|
||||
TensorDesc input_grad = op.GetOutputDescByName("x_grad");
|
||||
TensorDesc input = op.GetInputDescByName("x");
|
||||
DataType input_dtype = input.GetDataType();
|
||||
Shape input_shape = input.GetShape();
|
||||
input_grad.SetShape(input_shape);
|
||||
input_grad.SetDataType(input_dtype);
|
||||
if (op.UpdateOutputDesc("x_grad", input_grad) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(AdaptiveMaxPool2dGrad, AdaptiveMaxPool2dGradVerify) { return GRAPH_SUCCESS; }
|
||||
|
||||
CUST_INFER_FUNC_REG(AdaptiveMaxPool2dGrad, AdaptiveMaxPool2dGradInferShape);
|
||||
CUST_VERIFY_FUNC_REG(AdaptiveMaxPool2dGrad, AdaptiveMaxPool2dGradVerify);
|
||||
} // namespace ge
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/adjust_contrastv2_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/common_shape_fns.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_INFERFUNC(AdjustContrast, AdjustContrastInfer) {
|
||||
auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
|
||||
|
||||
GeShape shape;
|
||||
std::string err_msg;
|
||||
auto contrast_factor_desc = op_desc->MutableInputDesc(1);
|
||||
if (WithRank(contrast_factor_desc, 0, shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
err_msg = GetShapeErrMsg(1, DebugString(contrast_factor_desc->GetShape().GetDims()), "scalar");
|
||||
err_msg = string("failed to call WithRank function, ") + err_msg;
|
||||
AICPU_INFER_SHAPE_CALL_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
auto images_desc = op_desc->MutableInputDesc(0);
|
||||
if (WithRankAtLeast(images_desc, 3, shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
err_msg = GetShapeErrMsg(0, DebugString(images_desc->GetShape().GetDims()), "at least 3D");
|
||||
err_msg = string("failed to call WithRankAtLeast function, ") + err_msg;
|
||||
AICPU_INFER_SHAPE_CALL_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_PARAM_INVALID;
|
||||
}
|
||||
|
||||
auto y_desc = op_desc->MutableOutputDesc(0);
|
||||
y_desc->SetShape(shape);
|
||||
y_desc->SetDataType(images_desc->GetDataType());
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_INFER_FUNC_REG(AdjustContrast, AdjustContrastInfer);
|
||||
} // namespace ge
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/arg_max_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/op_const.h"
|
||||
|
||||
namespace ge {
|
||||
IMPLEMT_COMMON_INFERFUNC(ArgMaxInferShape) {
|
||||
// get all input desc
|
||||
const vector<string> depend_names = {"dimension"};
|
||||
PREPARE_DYNAMIC_SHAPE(depend_names);
|
||||
auto op_info_arg = OpDescUtils::GetOpDescFromOperator(op);
|
||||
static const int64_t x_input_idx = 0;
|
||||
static const int64_t y_output_idx = 0;
|
||||
auto input_desc = op_info_arg->MutableInputDesc(x_input_idx);
|
||||
auto y_desc = op_info_arg->MutableOutputDesc(y_output_idx);
|
||||
// get x shape
|
||||
const ge::GeShape &x_shape = input_desc->MutableShape();
|
||||
|
||||
// get and set output dtype
|
||||
ge::DataType dtype;
|
||||
if (op.GetAttr("dtype", dtype) == GRAPH_SUCCESS) {
|
||||
y_desc->SetDataType(dtype);
|
||||
} else {
|
||||
OP_LOGW(TbeGetName(op).c_str(), "get attr dtype failed.");
|
||||
y_desc->SetDataType(DT_INT32);
|
||||
}
|
||||
|
||||
// if x_shape == -2, set output -2
|
||||
if (IsUnknownRankShape(x_shape)) {
|
||||
y_desc->SetShape(x_shape);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
// if x_shape.size() < 2, set output scalar
|
||||
if (x_shape.GetDimNum() <= 1) {
|
||||
vector<int64_t> output_dims;
|
||||
y_desc->SetShape(GeShape(output_dims));
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
// read dimension const value
|
||||
int64_t dimension = 0;
|
||||
static const int64_t dimension_input_idx = 1;
|
||||
if (ops::GetConstInt(op, dimension_input_idx, dimension)) {
|
||||
dimension = dimension < 0 ? dimension + x_shape.GetDimNum() : dimension;
|
||||
if ((dimension < 0) || (dimension >= static_cast<int64_t>(x_shape.GetDimNum()))) {
|
||||
OP_LOGE(TbeGetName(op), "The dimension value %ld must in range of input shape size %ld.", dimension,
|
||||
x_shape.GetDimNum());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
ge::GeShape &output_shape = y_desc->MutableShape();
|
||||
output_shape.SetDimNum(x_shape.GetDimNum() - 1);
|
||||
for (int64_t i = 0; i < dimension; i++) {
|
||||
output_shape.SetDim(i, x_shape.GetDim(i));
|
||||
}
|
||||
for (int64_t i = dimension + 1; i < static_cast<int64_t>(x_shape.GetDimNum()); i++) {
|
||||
output_shape.SetDim(i - 1, x_shape.GetDim(i));
|
||||
}
|
||||
|
||||
// when output is dynamic will update range
|
||||
if (output_shape.IsUnknownShape()) {
|
||||
std::vector<std::pair<int64_t, int64_t>> input_range;
|
||||
input_desc->GetShapeRange(input_range);
|
||||
MakeUpShapeRange(x_shape, input_range);
|
||||
input_range.erase(input_range.begin() + dimension);
|
||||
y_desc->SetShapeRange(input_range);
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
// dimension is not const, set all output is -1, range is [0, -1]
|
||||
vector<int64_t> output_dims;
|
||||
std::vector<std::pair<int64_t, int64_t>> output_range;
|
||||
for (size_t item = 0; item < (x_shape.GetDimNum() - 1); ++item) {
|
||||
output_dims.push_back(-1);
|
||||
}
|
||||
MakeUpShapeRange(output_dims, output_range);
|
||||
y_desc->SetShape(GeShape(output_dims));
|
||||
y_desc->SetShapeRange(output_range);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(ArgMaxV2, ArgMaxInferShape);
|
||||
} // namespace ge
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/bartlett_window_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/common_shape_fns.h"
|
||||
|
||||
namespace ge {
|
||||
// ---------BartlettWindow-------------------
|
||||
IMPLEMT_COMMON_INFERFUNC(BartlettWindowInferShape) {
|
||||
int dtype;
|
||||
Format input_format = op.GetInputDescByName("window_length").GetFormat();
|
||||
TensorDesc out_desc = op.GetOutputDescByName("y");
|
||||
Shape unused;
|
||||
std::string err_msg;
|
||||
|
||||
// Set output shape
|
||||
if (WithRankAtMost(op.GetInputDescByName("window_length"), 1, unused, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
err_msg = GetShapeErrMsg(1, DebugString(op.GetInputDescByName("window_length").GetShape().GetDims()), "at most 1D");
|
||||
err_msg = std::string("failed to call WithRankAtMost, ") + err_msg;
|
||||
AICPU_INFER_SHAPE_CALL_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
std::vector<std::string> input_infer_depends = {"window_length"};
|
||||
auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
|
||||
op_desc->SetOpInferDepends(input_infer_depends);
|
||||
Tensor tensor;
|
||||
if (op.GetInputConstData("window_length", tensor) == GRAPH_SUCCESS) {
|
||||
auto tensor_data = reinterpret_cast<int64_t *>(tensor.GetData());
|
||||
if (*tensor_data == 0) {
|
||||
std::vector<int64_t> dim_vector = {};
|
||||
Shape output_shape(dim_vector);
|
||||
out_desc.SetShape(output_shape);
|
||||
} else {
|
||||
std::vector<int64_t> dim_vector = {};
|
||||
dim_vector.push_back(*tensor_data);
|
||||
Shape output_shape(dim_vector);
|
||||
out_desc.SetShape(output_shape);
|
||||
}
|
||||
}
|
||||
|
||||
// Set output dtype
|
||||
if (op.GetAttr("dtype", dtype) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Get attr dtype failed.");
|
||||
return GRAPH_FAILED;
|
||||
} else {
|
||||
switch (dtype) {
|
||||
case 0:
|
||||
out_desc.SetDataType(DT_FLOAT);
|
||||
break;
|
||||
case 1:
|
||||
out_desc.SetDataType(DT_FLOAT16);
|
||||
break;
|
||||
case 11:
|
||||
out_desc.SetDataType(DT_DOUBLE);
|
||||
break;
|
||||
default:
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Set output format
|
||||
out_desc.SetFormat(input_format);
|
||||
|
||||
if (op.UpdateOutputDesc("y", out_desc) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(BartlettWindow, BartlettWindowInferShape);
|
||||
// ---------BartlettWindow End-------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,138 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/batch_norm_grad_grad_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_INFERFUNC(BatchNormGradGrad, BatchNormGradGradInferShape) {
|
||||
// check attr
|
||||
float epsilon;
|
||||
if (op.GetAttr("epsilon", epsilon) == GRAPH_SUCCESS) {
|
||||
if (epsilon <= 0) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "'epsilon' must be greater than 0");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
std::string data_format;
|
||||
if (op.GetAttr("data_format", data_format) == GRAPH_SUCCESS) {
|
||||
if (data_format != "NHWC" && data_format != "NCHW") {
|
||||
string expected_format_list = ConcatString("NHWC, NCHW");
|
||||
std::string err_msg = GetInputFormatNotSupportErrMsg("data_format", expected_format_list, data_format);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
}
|
||||
ge::Format format;
|
||||
if (data_format == "NCHW") {
|
||||
format = FORMAT_NCHW;
|
||||
} else {
|
||||
format = FORMAT_NHWC;
|
||||
}
|
||||
|
||||
// check dtype
|
||||
DataType x_dtype = op.GetInputDescByName("x").GetDataType();
|
||||
DataType dy_dtype = op.GetInputDescByName("dy").GetDataType();
|
||||
DataType ddx_dtype = op.GetInputDescByName("ddx").GetDataType();
|
||||
|
||||
DataType scale_dtype = op.GetInputDescByName("scale").GetDataType();
|
||||
DataType reserve_space_1_dtype = op.GetInputDescByName("reserve_space_1").GetDataType();
|
||||
DataType reserve_space_2_dtype = op.GetInputDescByName("reserve_space_2").GetDataType();
|
||||
DataType ddscale_dtype = op.GetInputDescByName("ddscale").GetDataType();
|
||||
DataType ddoffset_dtype = op.GetInputDescByName("ddoffset").GetDataType();
|
||||
|
||||
if (x_dtype != DT_FLOAT16 && x_dtype != DT_FLOAT) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "'x' should have datatype fp16 or fp32");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (x_dtype != dy_dtype || x_dtype != ddx_dtype) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "'x' 'dy' 'ddx' should have the same datatype");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (scale_dtype != DT_FLOAT || reserve_space_1_dtype != DT_FLOAT || reserve_space_2_dtype != DT_FLOAT ||
|
||||
ddscale_dtype != DT_FLOAT || ddoffset_dtype != DT_FLOAT) {
|
||||
OP_LOGE(TbeGetName(op).c_str(),
|
||||
"'scale' 'reserve_space_1' 'reserve_space_2' 'ddscale' 'ddoffset' must have datatype fp32");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// check shape
|
||||
ge::Shape x_shape = op.GetInputDescByName("x").GetShape();
|
||||
ge::Shape dy_shape = op.GetInputDescByName("dy").GetShape();
|
||||
ge::Shape ddx_shape = op.GetInputDescByName("ddx").GetShape();
|
||||
|
||||
ge::Shape scale_shape = op.GetInputDescByName("scale").GetShape();
|
||||
ge::Shape reserve_space_1_shape = op.GetInputDescByName("reserve_space_1").GetShape();
|
||||
ge::Shape reserve_space_2_shape = op.GetInputDescByName("reserve_space_2").GetShape();
|
||||
ge::Shape ddscale_shape = op.GetInputDescByName("ddscale").GetShape();
|
||||
ge::Shape ddoffset_shape = op.GetInputDescByName("ddoffset").GetShape();
|
||||
|
||||
if (x_shape.GetDimNum() != 4) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "'x' must be a 4D tensor");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (x_shape.GetDims() != dy_shape.GetDims() || x_shape.GetDims() != ddx_shape.GetDims()) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "'x' 'dy' 'ddx' must have the same shape");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (scale_shape.GetDimNum() != 1) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "'scale' must be a 1D tensor");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (scale_shape.GetDims() != reserve_space_1_shape.GetDims() ||
|
||||
scale_shape.GetDims() != reserve_space_2_shape.GetDims() || scale_shape.GetDims() != ddscale_shape.GetDims() ||
|
||||
scale_shape.GetDims() != ddoffset_shape.GetDims()) {
|
||||
OP_LOGE(TbeGetName(op).c_str(),
|
||||
"'scale' 'reserve_space_1' 'reserve_space_2' 'ddscale' 'ddoffset' must have the same shape");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if ((format == FORMAT_NHWC && x_shape.GetDim(3) != scale_shape.GetShapeSize()) ||
|
||||
(format == FORMAT_NCHW && x_shape.GetDim(1) != scale_shape.GetShapeSize())) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "the size of 1D tensor should be equal to the size of C dim of 'x'");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// infer dtype and format and shape
|
||||
TensorDesc dx_desc = op.GetOutputDescByName("dx");
|
||||
dx_desc.SetDataType(x_dtype);
|
||||
dx_desc.SetFormat(format);
|
||||
dx_desc.SetShape(x_shape);
|
||||
(void)op.UpdateOutputDesc("dx", dx_desc);
|
||||
|
||||
TensorDesc ddy_desc = op.GetOutputDescByName("ddy");
|
||||
ddy_desc.SetDataType(dy_dtype);
|
||||
ddy_desc.SetFormat(format);
|
||||
ddy_desc.SetShape(dy_shape);
|
||||
(void)op.UpdateOutputDesc("ddy", ddy_desc);
|
||||
|
||||
TensorDesc dscale_desc = op.GetOutputDescByName("dscale");
|
||||
dscale_desc.SetDataType(scale_dtype);
|
||||
dscale_desc.SetShape(scale_shape);
|
||||
(void)op.UpdateOutputDesc("dscale", dscale_desc);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_INFER_FUNC_REG(BatchNormGradGrad, BatchNormGradGradInferShape);
|
||||
} // namespace ge
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/bessel_i0_op.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
namespace ge {
|
||||
|
||||
IMPLEMT_COMMON_INFERFUNC(BesselI0InferShape) {
|
||||
TensorDesc tensordesc_output = op.GetOutputDescByName("y");
|
||||
tensordesc_output.SetShape(op.GetInputDescByName("x").GetShape());
|
||||
tensordesc_output.SetDataType(op.GetInputDescByName("x").GetDataType());
|
||||
tensordesc_output.SetFormat(op.GetInputDescByName("x").GetFormat());
|
||||
(void)op.UpdateOutputDesc("y", tensordesc_output);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(BesselI0, BesselI0Verify) { return GRAPH_SUCCESS; }
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(BesselI0, BesselI0InferShape);
|
||||
|
||||
CUST_VERIFY_FUNC_REG(BesselI0, BesselI0Verify);
|
||||
|
||||
} // namespace ge
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/blackman_window_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/common_shape_fns.h"
|
||||
|
||||
namespace ge {
|
||||
// ----------------BlackmanWindow------------------
|
||||
CUST_IMPLEMT_VERIFIER(BlackmanWindow, BlackmanWindowVerify) { return GRAPH_SUCCESS; }
|
||||
|
||||
IMPLEMT_COMMON_INFERFUNC(BlackmanWindowInferShape) {
|
||||
Shape shape;
|
||||
Shape unused;
|
||||
|
||||
if (WithRank(op.GetInputDesc(0), 0, unused, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
Tensor window_length_tensor;
|
||||
if (op.GetInputConstData("window_length", window_length_tensor) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
int64_t length;
|
||||
if (MakeDimForScalarInput(window_length_tensor, length, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (Vector(length, shape) != GRAPH_SUCCESS) {
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), string("fail to gen vector shape according dim bins."));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
Operator::OpType type;
|
||||
if (op.GetAttr("dtype", type) != GRAPH_SUCCESS) {
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), std::string("get attr[dtype] failed"));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
TensorDesc output_desc = op.GetOutputDescByName("y");
|
||||
output_desc.SetDataType(type);
|
||||
output_desc.SetShape(shape);
|
||||
return op.UpdateOutputDesc("y", output_desc);
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(BlackmanWindow, BlackmanWindowInferShape);
|
||||
CUST_VERIFY_FUNC_REG(BlackmanWindow, BlackmanWindowVerify);
|
||||
// ----------------BlackmanWindow End----------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/cauchy_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// ---------Cauchy-------------------
|
||||
CUST_IMPLEMT_VERIFIER(Cauchy, CauchyVerify) {
|
||||
OP_LOGI(TbeGetName(op).c_str(), "Enter CauchyVerify.");
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
CUST_VERIFY_FUNC_REG(Cauchy, CauchyVerify);
|
||||
|
||||
IMPLEMT_COMMON_INFERFUNC(CauchyInferShape) {
|
||||
TensorDesc output_desc = op.GetOutputDescByName("y");
|
||||
std::vector<int64_t> shape_size{};
|
||||
if (op.GetAttr("size", shape_size) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Get attr size failed");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
output_desc.SetShape(ge::Shape(shape_size));
|
||||
(void)op.UpdateOutputDesc("y", output_desc);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(Cauchy, CauchyInferShape);
|
||||
// ---------Cauchy End-------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/cholesky_inverse_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// -----------------------CholeskyInverse---------------------
|
||||
IMPLEMT_COMMON_INFERFUNC(CholeskyInverseInferShape) {
|
||||
TensorDesc out_desc = op.GetOutputDescByName("x");
|
||||
out_desc.SetDataType(op.GetInputDescByName("x").GetDataType());
|
||||
if (op.UpdateOutputDesc("x", out_desc) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(CholeskyInverse, CholeskyInverseInferShape);
|
||||
|
||||
// -----------------------CholeskyInverse END---------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/cholesky_solve_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
namespace ge {
|
||||
// ----------------------CholeskySlove Starts----------------------
|
||||
CUST_IMPLEMT_VERIFIER(CholeskySolve, CholeskySolveVerify) {
|
||||
if (!CheckTwoInputDtypeSame(op, "x1", "x2")) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_INFERFUNC(CholeskySolve, CholeskySolveInfer) {
|
||||
DataType x1_type = op.GetInputDescByName("x1").GetDataType();
|
||||
Shape x1_shape = op.GetInputDescByName("x1").GetShape();
|
||||
Shape x2_shape = op.GetInputDescByName("x2").GetShape();
|
||||
if (x1_shape.GetDimNum() != 2 && x1_shape.GetDimNum() != 3) {
|
||||
// OP_LOGE(TbeGetName(op), "Op CholeskySolve's inputs must be rank 2 or 3.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x1_shape.GetDimNum() != x2_shape.GetDimNum()) {
|
||||
// OP_LOGE(TbeGetName(op), "Op CholeskySolve's two inputs cannot match.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
size_t rank = x1_shape.GetDimNum();
|
||||
if (rank == 2) {
|
||||
if (x1_shape.GetDim(0) != x2_shape.GetDim(0)) {
|
||||
// OP_LOGE(TbeGetName(op), "Op CholeskySolve's two inputs cannot match.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x2_shape.GetDim(0) != x2_shape.GetDim(1)) {
|
||||
// OP_LOGE(TbeGetName(op), "Op CholeskySolve's second input should be batch square.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
} else {
|
||||
if (x1_shape.GetDim(0) != x2_shape.GetDim(0) || x1_shape.GetDim(1) != x2_shape.GetDim(1)) {
|
||||
// OP_LOGE(TbeGetName(op), "Op CholeskySolve's two inputs cannot match.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x2_shape.GetDim(1) != x2_shape.GetDim(2)) {
|
||||
// OP_LOGE(TbeGetName(op), "Op CholeskySolve's second input should be batch square.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
}
|
||||
TensorDesc y_desc = op.GetOutputDescByName("y");
|
||||
y_desc.SetShape(x1_shape);
|
||||
y_desc.SetDataType(x1_type);
|
||||
op.UpdateOutputDesc("y", y_desc);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
// Registered inferfunction
|
||||
CUST_INFER_FUNC_REG(CholeskySolve, CholeskySolveInfer);
|
||||
// Registered verify function
|
||||
CUST_VERIFY_FUNC_REG(CholeskySolve, CholeskySolveVerify);
|
||||
// ----------------------CholeskySolve End----------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/coalesce_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// ----------------Coalesce Begin------------------------
|
||||
CUST_IMPLEMT_VERIFIER(Coalesce, CoalesceVerify) {
|
||||
TensorDesc x_indices_desc = op.GetInputDescByName("x_indices");
|
||||
TensorDesc x_values_desc = op.GetInputDescByName("x_values");
|
||||
TensorDesc x_shape_desc = op.GetInputDescByName("x_shape");
|
||||
DataType x_indices_type = x_indices_desc.GetDataType();
|
||||
DataType x_values_type = x_values_desc.GetDataType();
|
||||
DataType x_shape_type = x_shape_desc.GetDataType();
|
||||
Shape x_indices_shape = x_indices_desc.GetShape();
|
||||
Shape x_values_shape = x_values_desc.GetShape();
|
||||
Shape x_shape_shape = x_shape_desc.GetShape();
|
||||
if (x_indices_shape.GetDimNum() != 2) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "x_indices should be a 2-D tensor, but got x_indices is a %lu-D tensor.",
|
||||
x_indices_shape.GetDimNum());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_values_shape.GetDimNum() != 1) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "x_values should be a 1-D tensor, but got x_values is a %lu-D tensor.",
|
||||
x_values_shape.GetDimNum());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_shape_shape.GetDimNum() != 1) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "x_shape should be a 1-D tensor, but got x_shape is a %lu-D tensor.",
|
||||
x_shape_shape.GetDimNum());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_indices_shape.GetDim(1) != x_values_shape.GetDim(0)) {
|
||||
OP_LOGE(TbeGetName(op).c_str(),
|
||||
"sizes of dim1 of x_indices and dim0 of x_values should be equal, but got %lu and %lu.",
|
||||
x_indices_shape.GetDim(1), x_values_shape.GetDim(0));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_indices_shape.GetDim(0) != x_shape_shape.GetDim(0)) {
|
||||
OP_LOGE(TbeGetName(op).c_str(),
|
||||
"sizes of dim0 of x_indices and dim0 of x_shape should be equal, but got %lu and %lu.",
|
||||
x_indices_shape.GetDim(0), x_shape_shape.GetDim(0));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_values_type != DT_FLOAT && x_values_type != DT_FLOAT16) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "the data type of x_values should be DT_FLOAT or DT_FLOAT16.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_indices_type != DT_INT64 || x_shape_type != DT_INT64) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "the data types of x_indices and x_shape should be DT_INT64.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
IMPLEMT_COMMON_INFERFUNC(CoalesceInferShape) {
|
||||
TensorDesc x_indices_desc = op.GetInputDescByName("x_indices");
|
||||
TensorDesc x_values_desc = op.GetInputDescByName("x_values");
|
||||
TensorDesc x_shape_desc = op.GetInputDescByName("x_shape");
|
||||
DataType x_indices_type = x_indices_desc.GetDataType();
|
||||
DataType x_values_type = x_values_desc.GetDataType();
|
||||
DataType x_shape_type = x_shape_desc.GetDataType();
|
||||
Shape x_indices_shape = x_indices_desc.GetShape();
|
||||
Shape x_values_shape = x_values_desc.GetShape();
|
||||
Shape x_shape_shape = x_shape_desc.GetShape();
|
||||
TensorDesc y_indices_desc = op.GetOutputDescByName("y_indices");
|
||||
TensorDesc y_values_desc = op.GetOutputDescByName("y_values");
|
||||
TensorDesc y_shape_desc = op.GetOutputDescByName("y_shape");
|
||||
|
||||
std::vector<int64_t> new_dims;
|
||||
new_dims.push_back(x_indices_shape.GetDim(0));
|
||||
new_dims.push_back(ge::UNKNOWN_DIM);
|
||||
y_indices_desc.SetShape(Shape(new_dims));
|
||||
y_indices_desc.SetDataType(x_indices_type);
|
||||
(void)op.UpdateOutputDesc("y_indices", y_indices_desc);
|
||||
new_dims.clear();
|
||||
new_dims.push_back(ge::UNKNOWN_DIM);
|
||||
y_values_desc.SetShape(Shape(new_dims));
|
||||
y_values_desc.SetDataType(x_values_type);
|
||||
(void)op.UpdateOutputDesc("y_values", y_values_desc);
|
||||
y_shape_desc.SetShape(x_shape_shape);
|
||||
y_shape_desc.SetDataType(x_shape_type);
|
||||
(void)op.UpdateOutputDesc("y_shape", y_shape_desc);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(Coalesce, CoalesceInferShape);
|
||||
CUST_VERIFY_FUNC_REG(Coalesce, CoalesceVerify);
|
||||
// ----------------Coalesce END---------------------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/csr_sparse_matrix_to_dense_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_VERIFIER(CSRSparseMatrixToDense, CSRSparseMatrixToDenseVerify) {
|
||||
string err_msg;
|
||||
DataType value_type_x = op.GetInputDescByName("x_values").GetDataType();
|
||||
DataType shape_type_x = op.GetInputDescByName("x_dense_shape").GetDataType();
|
||||
DataType batch_type_x = op.GetInputDescByName("x_batch_pointers").GetDataType();
|
||||
DataType row_type_x = op.GetInputDescByName("x_row_pointers").GetDataType();
|
||||
DataType col_type_x = op.GetInputDescByName("x_col_indices").GetDataType();
|
||||
if (shape_type_x != batch_type_x || batch_type_x != row_type_x || row_type_x != col_type_x) {
|
||||
err_msg = "Data type of batch | shape | row | col is not the same!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
bool validValueType = (value_type_x != DT_FLOAT) && (value_type_x != DT_DOUBLE) && (value_type_x != DT_COMPLEX64) &&
|
||||
(value_type_x != DT_COMPLEX128);
|
||||
bool validShapeType = (shape_type_x != DT_INT32) && (shape_type_x != DT_INT64);
|
||||
bool validRowType = (row_type_x != DT_INT32) && (row_type_x != DT_INT64);
|
||||
bool validColType = (col_type_x != DT_INT32) && (col_type_x != DT_INT64);
|
||||
if (validValueType || validShapeType || validShapeType || validRowType || validColType) {
|
||||
err_msg = "Data type of some input is wrong!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
CUST_VERIFY_FUNC_REG(CSRSparseMatrixToDense, CSRSparseMatrixToDenseVerify);
|
||||
|
||||
CUST_IMPLEMT_INFERFUNC(CSRSparseMatrixToDense, CSRSparseMatrixToDenseInfer) {
|
||||
std::string err_msg;
|
||||
Shape x_dense_shape_shape = op.GetInputDescByName("x_dense_shape").GetShape();
|
||||
DataType value_type_x = op.GetInputDescByName("x_values").GetDataType();
|
||||
const int rank_x = x_dense_shape_shape.GetDim(0);
|
||||
if ((rank_x != 2 && rank_x != 3)) {
|
||||
err_msg = "Dense rank of input should be 2 or 3, please check!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
TensorDesc y_desc = op.GetOutputDescByName("y");
|
||||
y_desc.SetDataType(value_type_x);
|
||||
std::vector<int64_t> newDims;
|
||||
if (rank_x == 2) {
|
||||
newDims.push_back(ge::UNKNOWN_DIM);
|
||||
newDims.push_back(ge::UNKNOWN_DIM);
|
||||
y_desc.SetShape(Shape(newDims));
|
||||
} else {
|
||||
newDims.push_back(ge::UNKNOWN_DIM);
|
||||
newDims.push_back(ge::UNKNOWN_DIM);
|
||||
newDims.push_back(ge::UNKNOWN_DIM);
|
||||
y_desc.SetShape(Shape(newDims));
|
||||
}
|
||||
if (op.UpdateOutputDesc("y", y_desc) != GRAPH_SUCCESS) {
|
||||
err_msg = "CSRSparseMatrixToDense failed to update output y.";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
CUST_INFER_FUNC_REG(CSRSparseMatrixToDense, CSRSparseMatrixToDenseInfer);
|
||||
} // namespace ge
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/csr_sparse_matrix_to_sparse_tensor_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/common_shape_fns.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_INFERFUNC(CSRSparseMatrixToSparseTensor, CSRSparseMatrixToSparseTensorInfer) {
|
||||
auto op_desc = OpDescUtils::GetOpDescFromOperator(op);
|
||||
|
||||
GeShape x_dense_shape_shape;
|
||||
auto x_dense_shape_desc = op_desc->MutableInputDesc(0);
|
||||
if (WithRank(x_dense_shape_desc, 1, x_dense_shape_shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Input x_dense_shape must be 1-D.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
GeShape x_batch_pointers_shape;
|
||||
auto x_batch_pointers_desc = op_desc->MutableInputDesc(1);
|
||||
if (WithRank(x_batch_pointers_desc, 1, x_batch_pointers_shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Input x_batch_pointers must be 1-D.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
GeShape x_row_pointers_shape;
|
||||
auto x_row_pointers_desc = op_desc->MutableInputDesc(2);
|
||||
if (WithRank(x_row_pointers_desc, 1, x_row_pointers_shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Input x_row_pointers must be 1-D.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
GeShape x_col_indices_shape;
|
||||
auto x_col_indices_desc = op_desc->MutableInputDesc(3);
|
||||
if (WithRank(x_col_indices_desc, 1, x_col_indices_shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Input x_col_indices must be 1-D.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
GeShape x_values_shape;
|
||||
auto x_values_desc = op_desc->MutableInputDesc(4);
|
||||
if (WithRank(x_values_desc, 1, x_values_shape, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Input x_values must be 1-D.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
GeShape unused;
|
||||
if (Merge(x_col_indices_shape, x_values_shape, unused, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
GeShape indices_shape;
|
||||
if (Concatenate(x_col_indices_shape, x_dense_shape_shape, indices_shape) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
auto indices_desc = op_desc->MutableOutputDesc(0);
|
||||
indices_desc->SetDataType(x_col_indices_desc->GetDataType());
|
||||
indices_desc->SetShape(indices_shape);
|
||||
|
||||
auto values_desc = op_desc->MutableOutputDesc(1);
|
||||
values_desc->SetDataType(x_values_desc->GetDataType());
|
||||
values_desc->SetShape(x_values_shape);
|
||||
|
||||
auto dense_shape_desc = op_desc->MutableOutputDesc(2);
|
||||
dense_shape_desc->SetDataType(x_dense_shape_desc->GetDataType());
|
||||
dense_shape_desc->SetShape(x_dense_shape_shape);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_INFER_FUNC_REG(CSRSparseMatrixToSparseTensor, CSRSparseMatrixToSparseTensorInfer);
|
||||
} // namespace ge
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/dense_to_csr_sparse_matrix_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
CUST_IMPLEMT_VERIFIER(DenseToCSRSparseMatrix, DenseToCSRSparseMatrixVerify) {
|
||||
string err_msg;
|
||||
DataType dense_type = op.GetInputDescByName("dense_input").GetDataType();
|
||||
DataType indices_type = op.GetInputDescByName("indices").GetDataType();
|
||||
bool validValueType = (dense_type != DT_FLOAT) && (dense_type != DT_DOUBLE) && (dense_type != DT_COMPLEX64) &&
|
||||
(dense_type != DT_COMPLEX128);
|
||||
bool validIdxType = (indices_type != DT_INT32) && (indices_type != DT_INT64);
|
||||
if (validValueType || validIdxType) {
|
||||
err_msg = "Data type of some input is wrong!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
CUST_VERIFY_FUNC_REG(DenseToCSRSparseMatrix, DenseToCSRSparseMatrixVerify);
|
||||
|
||||
CUST_IMPLEMT_INFERFUNC(DenseToCSRSparseMatrix, DenseToCSRSparseMatrixInfer) {
|
||||
std::string err_msg;
|
||||
Shape dense_input_shape = op.GetInputDescByName("dense_input").GetShape();
|
||||
DataType dense_input_type = op.GetInputDescByName("dense_input").GetDataType();
|
||||
Shape indices_shape = op.GetInputDescByName("indices").GetShape();
|
||||
DataType indices_type = op.GetInputDescByName("indices").GetDataType();
|
||||
const int64_t dense_input_rank = dense_input_shape.GetDimNum();
|
||||
const int64_t indices_rank = indices_shape.GetDimNum();
|
||||
if ((dense_input_rank != 2 && dense_input_rank != 3)) {
|
||||
err_msg = "Rank of dense input should be 2 or 3, please check!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if ((indices_rank != 2)) {
|
||||
err_msg = "Indices must be a matrix, please check!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if ((dense_input_rank != indices_shape.GetDim(1))) {
|
||||
err_msg = "Indices.shape[1] must be equal to the rank of dense input, please check!";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
TensorDesc y_dense_shape_desc = op.GetOutputDescByName("y_dense_shape");
|
||||
TensorDesc y_batch_pointers_desc = op.GetOutputDescByName("y_batch_pointers");
|
||||
TensorDesc y_row_pointers_desc = op.GetOutputDescByName("y_row_pointers");
|
||||
TensorDesc y_col_indices_desc = op.GetOutputDescByName("y_col_indices");
|
||||
TensorDesc y_values_desc = op.GetOutputDescByName("y_values");
|
||||
y_dense_shape_desc.SetDataType(indices_type);
|
||||
y_batch_pointers_desc.SetDataType(indices_type);
|
||||
y_row_pointers_desc.SetDataType(indices_type);
|
||||
y_col_indices_desc.SetDataType(indices_type);
|
||||
y_values_desc.SetDataType(dense_input_type);
|
||||
const int64_t total_nnz = indices_shape.GetDim(0);
|
||||
const int64_t batch_size = (dense_input_rank == 2) ? 1 : dense_input_shape.GetDim(0);
|
||||
const int64_t num_rows = (dense_input_rank == 2) ? dense_input_shape.GetDim(0) : dense_input_shape.GetDim(1);
|
||||
std::vector<int64_t> newDims;
|
||||
newDims.push_back(dense_input_rank);
|
||||
y_dense_shape_desc.SetShape(Shape(newDims));
|
||||
newDims.clear();
|
||||
newDims.push_back((batch_size + 1));
|
||||
y_batch_pointers_desc.SetShape(Shape(newDims));
|
||||
newDims.clear();
|
||||
newDims.push_back((batch_size * (num_rows + 1)));
|
||||
y_row_pointers_desc.SetShape(Shape(newDims));
|
||||
newDims.clear();
|
||||
newDims.push_back(total_nnz);
|
||||
y_col_indices_desc.SetShape(Shape(newDims));
|
||||
newDims.clear();
|
||||
newDims.push_back(total_nnz);
|
||||
y_values_desc.SetShape(Shape(newDims));
|
||||
if (op.UpdateOutputDesc("y_dense_shape", y_dense_shape_desc) != GRAPH_SUCCESS) {
|
||||
err_msg = "DenseToCSRSparseMatrix failed to update output y_dense_shape.";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (op.UpdateOutputDesc("y_batch_pointers", y_batch_pointers_desc) != GRAPH_SUCCESS) {
|
||||
err_msg = "DenseToCSRSparseMatrix failed to update output y_dense_shape.";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (op.UpdateOutputDesc("y_row_pointers", y_row_pointers_desc) != GRAPH_SUCCESS) {
|
||||
err_msg = "DenseToCSRSparseMatrix failed to update output y_dense_shape.";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (op.UpdateOutputDesc("y_col_indices", y_col_indices_desc) != GRAPH_SUCCESS) {
|
||||
err_msg = "DenseToCSRSparseMatrix failed to update output y_dense_shape.";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (op.UpdateOutputDesc("y_values", y_values_desc) != GRAPH_SUCCESS) {
|
||||
err_msg = "DenseToCSRSparseMatrix failed to update output y_dense_shape.";
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
CUST_INFER_FUNC_REG(DenseToCSRSparseMatrix, DenseToCSRSparseMatrixInfer);
|
||||
} // namespace ge
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/eig_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// -----------------------Eig Starts----------------------
|
||||
IMPLEMT_COMMON_INFERFUNC(EigInferShape) {
|
||||
Shape x_shape = op.GetInputDescByName("x").GetShape();
|
||||
DataType x_dtype = op.GetInputDescByName("x").GetDataType();
|
||||
DataType y_dtype;
|
||||
if (x_dtype != DT_FLOAT && x_dtype != DT_DOUBLE && x_dtype != DT_COMPLEX64 && x_dtype != DT_COMPLEX128) {
|
||||
OP_LOGE(TbeGetName(op).c_str(),
|
||||
"For Eig, input x's data type should be either of float, double, complex64, complex128.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_dtype == DT_FLOAT || x_dtype == DT_COMPLEX64) {
|
||||
y_dtype = DT_COMPLEX64;
|
||||
} else {
|
||||
y_dtype = DT_COMPLEX128;
|
||||
}
|
||||
bool compute_v;
|
||||
if (op.GetAttr("compute_v", compute_v) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "For Eig, get attr compute_v failed!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
int64_t rank = x_shape.GetDimNum();
|
||||
vector<int64_t> x_shape_list = x_shape.GetDims();
|
||||
if (rank < 2) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "For Eig, rank of input x must be equal to or greater than 2.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (x_shape_list[rank - 1] != x_shape_list[rank - 2]) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "For Eig, input x must be square or batch squares.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
TensorDesc val_desc = op.GetOutputDescByName("eigen_values");
|
||||
TensorDesc vec_desc = op.GetOutputDescByName("eigen_vectors");
|
||||
val_desc.SetDataType(y_dtype);
|
||||
vec_desc.SetDataType(y_dtype);
|
||||
std::vector<int64_t> vec_shape_list = {};
|
||||
std::vector<int64_t> val_shape_list = {};
|
||||
val_shape_list.assign(x_shape_list.begin(), x_shape_list.end());
|
||||
val_shape_list.pop_back();
|
||||
if (compute_v) {
|
||||
vec_shape_list.assign(x_shape_list.begin(), x_shape_list.end());
|
||||
}
|
||||
Shape vec_shape(vec_shape_list);
|
||||
Shape val_shape(val_shape_list);
|
||||
vec_desc.SetShape(vec_shape);
|
||||
val_desc.SetShape(val_shape);
|
||||
if (op.UpdateOutputDesc("eigen_values", val_desc) != GRAPH_SUCCESS ||
|
||||
op.UpdateOutputDesc("eigen_vectors", vec_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Failed to update output desc.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(Eig, EigInferShape);
|
||||
} // namespace ge
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/exp.h"
|
||||
#include "register/infer_axis_slice_registry.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/common_shape_fns.h"
|
||||
namespace ge {
|
||||
IMPLEMT_COMMON_INFERFUNC(OneInOneOutCommonInferShape) {
|
||||
static const int64_t input_x_idx = 0;
|
||||
static const int64_t output_y_idx = 0;
|
||||
if (OneInOneOutDynamicInfer(op, input_x_idx, {output_y_idx})) {
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// ----------------Exp-------------------
|
||||
CUST_COMMON_INFER_FUNC_REG(Exp, OneInOneOutCommonInferShape);
|
||||
INFER_AXIS_TYPE_INFO_REG(Exp, InferAxisType4ElementwiseOp);
|
||||
// ----------------Exp END-------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/fft_with_size_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
IMPLEMT_COMMON_INFERFUNC(FFTWithSizeInferShape) {
|
||||
TensorDesc out_desc = op.GetOutputDescByName("x");
|
||||
out_desc.SetDataType(op.GetInputDescByName("x").GetDataType());
|
||||
if (op.UpdateOutputDesc("x", out_desc) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(FFTWithSize, FFTWithSizeInferShape);
|
||||
} // namespace ge
|
|
@ -0,0 +1,151 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/fractional_max_pool_3d_grad_with_fixed_ksize_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// -----------------FractionalMaxPool3DGradWithFixedKsize start----------------
|
||||
IMPLEMT_COMMON_INFERFUNC(FractionalMaxPool3DGradWithFixedKsizeInferShape) {
|
||||
const size_t DIM_SIZE4 = 4;
|
||||
const size_t DIM_SIZE5 = 5;
|
||||
TensorDesc origin_input_desc = op.GetInputDescByName("origin_input");
|
||||
TensorDesc out_backprop_desc = op.GetInputDescByName("out_backprop");
|
||||
TensorDesc argmax_desc = op.GetInputDescByName("argmax");
|
||||
TensorDesc out_desc = op.GetOutputDescByName("y");
|
||||
Format input_format = origin_input_desc.GetFormat();
|
||||
DataType out_backprop_type = out_backprop_desc.GetDataType();
|
||||
|
||||
std::vector<int64_t> origin_input_shape = origin_input_desc.GetShape().GetDims();
|
||||
std::vector<int64_t> out_backprop_shape = out_backprop_desc.GetShape().GetDims();
|
||||
std::vector<int64_t> argmax_shape = argmax_desc.GetShape().GetDims();
|
||||
auto origin_input_dims = origin_input_shape.size();
|
||||
auto out_backprop_dims = out_backprop_shape.size();
|
||||
auto argmax_dims = argmax_shape.size();
|
||||
|
||||
if ((origin_input_dims != DIM_SIZE4) && (origin_input_dims != DIM_SIZE5)) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "length of origin_input should be 4 or 5!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if ((out_backprop_dims != DIM_SIZE4) && (out_backprop_dims != DIM_SIZE5)) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "length of out_backprop should be 4 or 5!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if ((argmax_dims != DIM_SIZE4) && (argmax_dims != DIM_SIZE5)) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "length of argmax should be 4 or 5!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
std::string data_format;
|
||||
if (GRAPH_SUCCESS != op.GetAttr("data_format", data_format)) {
|
||||
std::string err_msg = GetInputInvalidErrMsg("data_format");
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (data_format != "NDHWC" && data_format != "NCDHW") {
|
||||
string expected_format_list = ConcatString("NDHWC, NCDHW");
|
||||
std::string err_msg = GetInputFormatNotSupportErrMsg("data_format", expected_format_list, data_format);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// set data type
|
||||
out_desc.SetDataType(out_backprop_type);
|
||||
if (op.UpdateOutputDesc("y", out_desc) != GRAPH_SUCCESS) {
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), std::string("update output[y] desc failed."));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// set shape
|
||||
if ((input_format == FORMAT_NCDHW && data_format != "NCDHW") ||
|
||||
(input_format == FORMAT_NDHWC && data_format != "NDHWC")) {
|
||||
string expected_format = ConcatString("Format of input must be same with data_format! input_format:", input_format,
|
||||
", data_format:", data_format);
|
||||
std::string err_msg = OtherErrMsg(expected_format);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
std::vector<int64_t> output_size;
|
||||
int64_t n_dim = 0;
|
||||
int64_t c_dim = 0;
|
||||
int64_t d_dim = 0;
|
||||
int64_t h_dim = 0;
|
||||
int64_t w_dim = 0;
|
||||
|
||||
if (origin_input_dims == 4) {
|
||||
if (data_format == "NCDHW") {
|
||||
c_dim = origin_input_desc.GetShape().GetDim(0);
|
||||
d_dim = origin_input_desc.GetShape().GetDim(1);
|
||||
h_dim = origin_input_desc.GetShape().GetDim(2);
|
||||
w_dim = origin_input_desc.GetShape().GetDim(3);
|
||||
output_size.push_back(c_dim);
|
||||
output_size.push_back(d_dim);
|
||||
output_size.push_back(h_dim);
|
||||
output_size.push_back(w_dim);
|
||||
} else {
|
||||
d_dim = origin_input_desc.GetShape().GetDim(0);
|
||||
h_dim = origin_input_desc.GetShape().GetDim(1);
|
||||
w_dim = origin_input_desc.GetShape().GetDim(2);
|
||||
c_dim = origin_input_desc.GetShape().GetDim(3);
|
||||
output_size.push_back(d_dim);
|
||||
output_size.push_back(h_dim);
|
||||
output_size.push_back(w_dim);
|
||||
output_size.push_back(c_dim);
|
||||
}
|
||||
} else {
|
||||
if (data_format == "NCDHW") {
|
||||
n_dim = origin_input_desc.GetShape().GetDim(0);
|
||||
c_dim = origin_input_desc.GetShape().GetDim(1);
|
||||
d_dim = origin_input_desc.GetShape().GetDim(2);
|
||||
h_dim = origin_input_desc.GetShape().GetDim(3);
|
||||
w_dim = origin_input_desc.GetShape().GetDim(4);
|
||||
output_size.push_back(n_dim);
|
||||
output_size.push_back(c_dim);
|
||||
output_size.push_back(d_dim);
|
||||
output_size.push_back(h_dim);
|
||||
output_size.push_back(w_dim);
|
||||
} else {
|
||||
n_dim = origin_input_desc.GetShape().GetDim(0);
|
||||
d_dim = origin_input_desc.GetShape().GetDim(1);
|
||||
h_dim = origin_input_desc.GetShape().GetDim(2);
|
||||
w_dim = origin_input_desc.GetShape().GetDim(3);
|
||||
c_dim = origin_input_desc.GetShape().GetDim(4);
|
||||
output_size.push_back(n_dim);
|
||||
output_size.push_back(d_dim);
|
||||
output_size.push_back(h_dim);
|
||||
output_size.push_back(w_dim);
|
||||
output_size.push_back(c_dim);
|
||||
}
|
||||
}
|
||||
out_desc.SetShape(ge::Shape(output_size));
|
||||
out_desc.SetFormat(input_format);
|
||||
|
||||
if (op.UpdateOutputDesc("y", out_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Fail to update output y!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(FractionalMaxPool3DGradWithFixedKsize, FractionalMaxPool3DGradWithFixedKsizeVerify) {
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(FractionalMaxPool3DGradWithFixedKsize, FractionalMaxPool3DGradWithFixedKsizeInferShape);
|
||||
CUST_VERIFY_FUNC_REG(FractionalMaxPool3DGradWithFixedKsize, FractionalMaxPool3DGradWithFixedKsizeVerify);
|
||||
// -----------------FractionalMaxPool3DGradWithFixedKsize end----------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,183 @@
|
|||
/**
|
||||
* Copyright (c) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/fractional_max_pool_3d_with_fixed_ksize_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// -----------------FractionalMaxPool3DWithFixedKsize start----------------
|
||||
IMPLEMT_COMMON_INFERFUNC(FractionalMaxPool3DWithFixedKsizeInferShape) {
|
||||
const size_t DIM_SIZE1 = 1;
|
||||
const size_t DIM_SIZE3 = 3;
|
||||
const size_t DIM_SIZE4 = 4;
|
||||
const size_t DIM_SIZE5 = 5;
|
||||
TensorDesc input_desc = op.GetInputDescByName("x");
|
||||
TensorDesc random_samples_desc = op.GetInputDescByName("random_samples");
|
||||
TensorDesc out_desc = op.GetOutputDescByName("y");
|
||||
TensorDesc argmax_desc = op.GetOutputDescByName("argmax");
|
||||
Format input_format = input_desc.GetFormat();
|
||||
DataType input_type = input_desc.GetDataType();
|
||||
DataType argmax_dtype = argmax_desc.GetDataType();
|
||||
|
||||
std::vector<int64_t> input_shape = input_desc.GetShape().GetDims();
|
||||
auto input_dims = input_shape.size();
|
||||
if ((input_dims != DIM_SIZE4) && (input_dims != DIM_SIZE5)) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "length of x should be 4 or 5!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
std::vector<int64_t> outputshapeList;
|
||||
if (GRAPH_SUCCESS != op.GetAttr("output_shape", outputshapeList)) {
|
||||
std::string err_msg = GetInputInvalidErrMsg("output_shape");
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if ((outputshapeList.size() != DIM_SIZE1) && (outputshapeList.size() != DIM_SIZE3)) {
|
||||
string excepted_size = ConcatString(DIM_SIZE1, " or ", DIM_SIZE3);
|
||||
std::string err_msg = GetAttrSizeErrMsg("outputshapeList", ConcatString(outputshapeList.size()), excepted_size);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (outputshapeList.size() == DIM_SIZE1) {
|
||||
for (int64_t i = 0; i < 3; i++) {
|
||||
outputshapeList[i] = outputshapeList[0];
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float> ksizeList;
|
||||
if (GRAPH_SUCCESS != op.GetAttr("ksize", ksizeList)) {
|
||||
std::string err_msg = GetInputInvalidErrMsg("ksize");
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if ((ksizeList.size() != DIM_SIZE1) && (ksizeList.size() != DIM_SIZE3)) {
|
||||
string excepted_size = ConcatString(DIM_SIZE1, " or ", DIM_SIZE3);
|
||||
std::string err_msg = GetAttrSizeErrMsg("ksizeList", ConcatString(ksizeList.size()), excepted_size);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (ksizeList.size() == DIM_SIZE1) {
|
||||
for (int64_t i = 0; i < 3; i++) {
|
||||
ksizeList[i] = ksizeList[0];
|
||||
}
|
||||
}
|
||||
|
||||
std::string data_format;
|
||||
if (GRAPH_SUCCESS != op.GetAttr("data_format", data_format)) {
|
||||
std::string err_msg = GetInputInvalidErrMsg("data_format");
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (data_format != "NDHWC" && data_format != "NCDHW") {
|
||||
string expected_format_list = ConcatString("NDHWC, NCDHW");
|
||||
std::string err_msg = GetInputFormatNotSupportErrMsg("data_format", expected_format_list, data_format);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// set data type
|
||||
out_desc.SetDataType(input_type);
|
||||
if (op.UpdateOutputDesc("y", out_desc) != GRAPH_SUCCESS) {
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), std::string("update output[y] desc failed."));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
if (argmax_dtype == DT_UNDEFINED) {
|
||||
argmax_desc.SetDataType(DT_INT64);
|
||||
}
|
||||
argmax_desc.SetDataType(argmax_dtype);
|
||||
if (op.UpdateOutputDesc("argmax", argmax_desc) != GRAPH_SUCCESS) {
|
||||
AICPU_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), std::string("update output[argmax] desc failed."));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
// set shape
|
||||
if ((input_format == FORMAT_NCDHW && data_format != "NCDHW") ||
|
||||
(input_format == FORMAT_NDHWC && data_format != "NDHWC")) {
|
||||
string expected_format = ConcatString("Format of input must be same with data_format! input_format:", input_format,
|
||||
", data_format:", data_format);
|
||||
std::string err_msg = OtherErrMsg(expected_format);
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
std::vector<int64_t> output_size;
|
||||
int64_t n_dim = 0;
|
||||
int64_t c_dim = 0;
|
||||
int64_t outputT = outputshapeList[0];
|
||||
int64_t outputH = outputshapeList[1];
|
||||
int64_t outputW = outputshapeList[2];
|
||||
|
||||
if (input_dims == 4) {
|
||||
if (data_format == "NCDHW") {
|
||||
c_dim = input_desc.GetShape().GetDim(0);
|
||||
output_size.push_back(c_dim);
|
||||
output_size.push_back(outputT);
|
||||
output_size.push_back(outputH);
|
||||
output_size.push_back(outputW);
|
||||
} else {
|
||||
c_dim = input_desc.GetShape().GetDim(3);
|
||||
output_size.push_back(outputT);
|
||||
output_size.push_back(outputH);
|
||||
output_size.push_back(outputW);
|
||||
output_size.push_back(c_dim);
|
||||
}
|
||||
} else {
|
||||
if (data_format == "NCDHW") {
|
||||
n_dim = input_desc.GetShape().GetDim(0);
|
||||
c_dim = input_desc.GetShape().GetDim(1);
|
||||
output_size.push_back(n_dim);
|
||||
output_size.push_back(c_dim);
|
||||
output_size.push_back(outputT);
|
||||
output_size.push_back(outputH);
|
||||
output_size.push_back(outputW);
|
||||
} else {
|
||||
n_dim = input_desc.GetShape().GetDim(0);
|
||||
c_dim = input_desc.GetShape().GetDim(4);
|
||||
output_size.push_back(n_dim);
|
||||
output_size.push_back(outputT);
|
||||
output_size.push_back(outputH);
|
||||
output_size.push_back(outputW);
|
||||
output_size.push_back(c_dim);
|
||||
}
|
||||
}
|
||||
out_desc.SetFormat(input_format);
|
||||
argmax_desc.SetFormat(ge::FORMAT_ND);
|
||||
|
||||
out_desc.SetShape(ge::Shape(output_size));
|
||||
if (op.UpdateOutputDesc("y", out_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Fail to update output y!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
argmax_desc.SetShape(ge::Shape(output_size));
|
||||
if (op.UpdateOutputDesc("argmax", argmax_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Fail to update output argmax!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(FractionalMaxPool3DWithFixedKsize, FractionalMaxPool3DWithFixedKsizeVerify) {
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(FractionalMaxPool3DWithFixedKsize, FractionalMaxPool3DWithFixedKsizeInferShape);
|
||||
CUST_VERIFY_FUNC_REG(FractionalMaxPool3DWithFixedKsize, FractionalMaxPool3DWithFixedKsizeVerify);
|
||||
// -----------------FractionalMaxPool3DWithFixedKsize end----------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/fractional_max_pool_grad_with_fixed_ksize_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// -----------------------FractionalMaxPoolGradWithFixedKsize start-------------------------------------
|
||||
CUST_IMPLEMT_INFERFUNC(FractionalMaxPoolGradWithFixedKsize, FractionalMaxPoolGradWithFixedKsizeInfer) {
|
||||
std::string data_format;
|
||||
if (ge::GRAPH_SUCCESS == op.GetAttr("data_format", data_format)) {
|
||||
if (data_format.compare("NCHW") != 0) {
|
||||
std::string expected_format_list = ConcatString("NCHW");
|
||||
std::string err_msg =
|
||||
GetInputFormatNotSupportErrMsg("data_format", expected_format_list, ConcatString(data_format));
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
} else {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "GetOpAttr data_format failed!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
TensorDesc orig_input_desc = op.GetInputDescByName("origin_input");
|
||||
std::vector<int64_t> orig_input_dims = orig_input_desc.GetShape().GetDims();
|
||||
if (orig_input_dims.size() != 4) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Dim of input[origin_input] must be 4.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
Format orig_input_format = orig_input_desc.GetFormat();
|
||||
if (orig_input_format != FORMAT_NCHW) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "The data_format of input[origin_input] must be NCHW.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
Shape y_dims(orig_input_dims);
|
||||
|
||||
TensorDesc out_backprop_desc = op.GetInputDescByName("out_backprop");
|
||||
Format out_backprop_format = out_backprop_desc.GetFormat();
|
||||
if (out_backprop_format != FORMAT_NCHW) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "The data_format of input[out_backprop] must be NCHW.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
DataType out_backprop_dtype = out_backprop_desc.GetDataType();
|
||||
|
||||
TensorDesc y_desc = op.GetOutputDescByName("y");
|
||||
y_desc.SetDataType(out_backprop_dtype);
|
||||
y_desc.SetFormat(FORMAT_NCHW);
|
||||
y_desc.SetShape(y_dims);
|
||||
(void)op.UpdateOutputDesc("y", y_desc);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_INFER_FUNC_REG(FractionalMaxPoolGradWithFixedKsize, FractionalMaxPoolGradWithFixedKsizeInfer);
|
||||
// -----------------------FractionalMaxPoolGradWithFixedKsize end---------------------------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/fractional_max_pool_with_fixed_ksize_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// ---------------------------------FractionalMaxPoolWithFixedKsize start-------------------------------------------
|
||||
CUST_IMPLEMT_INFERFUNC(FractionalMaxPoolWithFixedKsize, FractionalMaxPoolWithFixedKsizeInfer) {
|
||||
TensorDesc input_x = op.GetInputDescByName("x");
|
||||
DataType input_x_dtype = input_x.GetDataType();
|
||||
std::vector<int64_t> input_x_dims = input_x.GetShape().GetDims();
|
||||
if (input_x_dims.size() != 4) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Dim of input x must be 4.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
int64_t output_dim_H;
|
||||
int64_t output_dim_W;
|
||||
std::vector<int64_t> output_shape_list;
|
||||
if (ge::GRAPH_SUCCESS == op.GetAttr("output_shape", output_shape_list)) {
|
||||
if (output_shape_list.size() == 1) {
|
||||
output_dim_H = output_shape_list[0];
|
||||
output_dim_W = output_shape_list[0];
|
||||
} else if (output_shape_list.size() == 2) {
|
||||
output_dim_H = output_shape_list[0];
|
||||
output_dim_W = output_shape_list[1];
|
||||
} else {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "The length of output_shape must be 1 or 2.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
} else {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "GetOpAttr output_shape failed!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
std::vector<int64_t> output_y_dims;
|
||||
std::string data_format;
|
||||
if (ge::GRAPH_SUCCESS == op.GetAttr("data_format", data_format)) {
|
||||
if (data_format == "NCHW") {
|
||||
output_y_dims.push_back(input_x_dims[0]);
|
||||
output_y_dims.push_back(input_x_dims[1]);
|
||||
output_y_dims.push_back(output_dim_H);
|
||||
output_y_dims.push_back(output_dim_W);
|
||||
} else {
|
||||
std::string expected_format_list = ConcatString("NCHW");
|
||||
std::string err_msg =
|
||||
GetInputFormatNotSupportErrMsg("data_format", expected_format_list, ConcatString(data_format));
|
||||
VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op).c_str(), err_msg);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
} else {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "GetOpAttr data_format failed!");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
Shape output_dims(output_y_dims);
|
||||
|
||||
TensorDesc output_y = op.GetOutputDescByName("y");
|
||||
output_y.SetDataType(input_x_dtype);
|
||||
output_y.SetFormat(ge::FORMAT_NCHW);
|
||||
output_y.SetShape(output_dims);
|
||||
(void)op.UpdateOutputDesc("y", output_y);
|
||||
|
||||
TensorDesc output_argmax = op.GetOutputDescByName("argmax");
|
||||
output_argmax.SetDataType(DT_INT64);
|
||||
output_argmax.SetFormat(ge::FORMAT_ND);
|
||||
output_argmax.SetShape(output_dims);
|
||||
(void)op.UpdateOutputDesc("argmax", output_argmax);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_INFER_FUNC_REG(FractionalMaxPoolWithFixedKsize, FractionalMaxPoolWithFixedKsizeInfer);
|
||||
// ---------------------------------FractionalMaxPoolWithFixedKsize end-------------------------------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/geqrf_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
#include "utils/common_shape_fns.h"
|
||||
|
||||
namespace ge {
|
||||
// ---------------Geqrf-------------------
|
||||
CUST_IMPLEMT_INFERFUNC(Geqrf, GeqrfInfer) {
|
||||
auto tensor = op.get_input_desc_x();
|
||||
Shape input;
|
||||
if (WithRank(tensor, 2, input, TbeGetName(op).c_str()) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
int dim_num = input.GetDimNum();
|
||||
int m = input.GetDim(dim_num - 2);
|
||||
int n = input.GetDim(dim_num - 1);
|
||||
Shape r_shape;
|
||||
Shape tau_shape;
|
||||
int p = m > n ? n : m;
|
||||
Matrix(m, n, r_shape);
|
||||
Vector(p, tau_shape);
|
||||
|
||||
DataType type = op.GetInputDescByName("x").GetDataType();
|
||||
TensorDesc r_desc = op.GetOutputDescByName("r");
|
||||
r_desc.SetShape(Shape(r_shape));
|
||||
r_desc.SetDataType(type);
|
||||
if (op.UpdateOutputDesc("r", r_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Update r desc failed.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
TensorDesc tau_desc = op.GetOutputDescByName("tau");
|
||||
tau_desc.SetShape(Shape(tau_shape));
|
||||
tau_desc.SetDataType(type);
|
||||
if (op.UpdateOutputDesc("tau", tau_desc) != GRAPH_SUCCESS) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Update tau desc failed.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_INFER_FUNC_REG(Geqrf, GeqrfInfer);
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(Geqrf, GeqrfVerify) {
|
||||
DataType type = op.GetInputDescByName("x").GetDataType();
|
||||
if (type != DT_FLOAT16 && type != DT_FLOAT && type != DT_DOUBLE && type != DT_COMPLEX64 && type != DT_COMPLEX128) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Expect a floating point or complex tensor as input.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_VERIFY_FUNC_REG(Geqrf, GeqrfVerify);
|
||||
// ---------------Geqrf End---------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/glu_grad_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// ------------------GluGrad Begin--------------------
|
||||
IMPLEMT_COMMON_INFERFUNC(GluGradInferShape) {
|
||||
TensorDesc x = op.GetInputDescByName("x");
|
||||
Shape x_shape = x.GetShape();
|
||||
std::vector<int64_t> dim_vector = x_shape.GetDims();
|
||||
Shape output_shape(dim_vector);
|
||||
TensorDesc out = op.GetOutputDescByName("y");
|
||||
out.SetShape(output_shape);
|
||||
op.UpdateOutputDesc("y", out);
|
||||
out.SetDataType(op.GetInputDescByName("x").GetDataType());
|
||||
if (op.UpdateOutputDesc("y", out) != GRAPH_SUCCESS) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_IMPLEMT_VERIFIER(GluGrad, GluGradVerify) {
|
||||
DataType input_type_grad = op.GetInputDescByName("grads").GetDataType();
|
||||
DataType input_type_x = op.GetInputDescByName("x").GetDataType();
|
||||
if (input_type_grad != input_type_x) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(GluGrad, GluGradInferShape);
|
||||
CUST_VERIFY_FUNC_REG(GluGrad, GluGradVerify);
|
||||
// ------------------GluGrad END--------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/glu_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// ----------------Glu Begin------------------------
|
||||
IMPLEMT_COMMON_INFERFUNC(GluInferShape) {
|
||||
auto opname = TbeGetName(op).c_str();
|
||||
Shape x_shape = op.GetInputDescByName("x").GetShape();
|
||||
DataType x_dtype = op.GetInputDescByName("x").GetDataType();
|
||||
Format x_format = op.GetInputDescByName("x").GetFormat();
|
||||
|
||||
int64_t split_dim;
|
||||
if (op.GetAttr("axis", split_dim) == GRAPH_FAILED) {
|
||||
split_dim = -1;
|
||||
}
|
||||
|
||||
int64_t dim_num = x_shape.GetDimNum();
|
||||
if ((split_dim < -dim_num) || (split_dim >= dim_num)) {
|
||||
OP_LOGE(opname, "The value of the attribute axis is out of range.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (split_dim < 0) {
|
||||
split_dim += dim_num;
|
||||
}
|
||||
int64_t split_dim_value = x_shape.GetDim(split_dim);
|
||||
if (split_dim_value % 2 != 0) {
|
||||
OP_LOGE(opname, "The value of thea attribute axis is not even\n");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
std::vector<int64_t> dim_vector = x_shape.GetDims();
|
||||
dim_vector[split_dim] = split_dim_value / 2;
|
||||
|
||||
Shape output_shape(dim_vector);
|
||||
TensorDesc td = op.GetOutputDescByName("y");
|
||||
td.SetShape(output_shape);
|
||||
td.SetDataType(x_dtype);
|
||||
td.SetFormat(x_format);
|
||||
op.UpdateOutputDesc("y", td);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
CUST_COMMON_INFER_FUNC_REG(Glu, GluInferShape);
|
||||
// ----------------Glu END---------------------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "inc/hamming_window_op.h"
|
||||
#include "register/op_impl_registry.h"
|
||||
#include "utils/util.h"
|
||||
|
||||
namespace ge {
|
||||
// ----------------HammingWindow Begin---------------------
|
||||
IMPLEMT_COMMON_INFERFUNC(HammingWindowInferShape) {
|
||||
std::vector<int64_t> input_dim = op.GetInputDesc(0).GetShape().GetDims();
|
||||
if (input_dim.size() != 1) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Tensor length input must be 1D.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
Tensor length_tensor;
|
||||
int64_t length_data;
|
||||
if (op.GetInputConstData("length", length_tensor) == GRAPH_SUCCESS) {
|
||||
uint8_t *length = length_tensor.GetData();
|
||||
length_data = static_cast<int64_t>(*length);
|
||||
} else {
|
||||
length_data = UNKNOWN_DIM;
|
||||
}
|
||||
std::vector<int64_t> output_dim;
|
||||
if (length_data != UNKNOWN_DIM && length_data < 0) {
|
||||
OP_LOGE(TbeGetName(op).c_str(), "Non-negative window length required, got [%ld].", length_data);
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (length_data != 0) {
|
||||
output_dim.push_back(length_data);
|
||||
}
|
||||
ge::Shape output_shape = ge::Shape(output_dim);
|
||||
|
||||
Operator::OpInt dtype;
|
||||
if (op.GetAttr("dtype", dtype) != GRAPH_SUCCESS) {
|
||||
dtype = 0;
|
||||
}
|
||||
DataType output_dtype = static_cast<DataType>(dtype);
|
||||
|
||||
TensorDesc output_desc = op.GetOutputDescByName("y");
|
||||
output_desc.SetShape(output_shape);
|
||||
output_desc.SetDataType(output_dtype);
|
||||
op.UpdateOutputDesc("y", output_desc);
|
||||
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
CUST_COMMON_INFER_FUNC_REG(HammingWindow, HammingWindowInferShape);
|
||||
// ----------------HammingWindow End---------------------
|
||||
} // namespace ge
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_AVG_POOL_3D_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_AVG_POOL_3D_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief backward function of AdaptiveAvgPool3d . \n
|
||||
|
||||
* @par Inputs:
|
||||
* input_grad: A tensor of type float16, float32, double, int8, uint8, int16, int32, int64 . \n
|
||||
* orig_input_shape: The shape of output. A tensor of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* output_grad: The average pooled output tensor. Has the same type and format as input "input_grad" . \n
|
||||
*/
|
||||
|
||||
REG_CUST_OP(AdaptiveAvgPool3dGrad)
|
||||
.INPUT(input_grad, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
|
||||
.INPUT(orig_input_shape, TensorType({DT_INT32}))
|
||||
.OUTPUT(output_grad, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
|
||||
.CUST_OP_END_FACTORY_REG(AdaptiveAvgPool3dGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_AVG_POOL_3D_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_AVG_POOL_3D_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs average pooling on the last 3 dimension . \n
|
||||
|
||||
* @par Inputs:
|
||||
* x: A tensor of type float16, float32, double, int8, uint8, int16, int32, int64 . \n
|
||||
* output_size: The shape of the last 3 dim of output. A tensor of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: The average pooled output tensor. Has the same type and format as input "x" . \n
|
||||
*/
|
||||
|
||||
REG_CUST_OP(AdaptiveAvgPool3d)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
|
||||
.INPUT(output_size, TensorType({DT_INT32}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
|
||||
.CUST_OP_END_FACTORY_REG(AdaptiveAvgPool3d)
|
||||
|
||||
REG_CUST_OP(Constant)
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_UINT32,
|
||||
DT_UINT64, DT_BOOL, DT_DOUBLE}))
|
||||
.ATTR(value, Tensor, Tensor())
|
||||
.CUST_OP_END_FACTORY_REG(Constant)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_MAX_POOL3_D_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_MAX_POOL3_D_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs the backpropagation of AdaptiveMaxPool3dGrad. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li input_grad: A 4D or 5D Tensor of input's gradient. Must be one of RealNumberType. \n
|
||||
* @li x: A 4D or 5D Tensor. Must be one of RealNumberType. \n
|
||||
* @li argmax: A 4D or 5D Tensor of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li output_grad: A Tensor. Has the same data type and shape as "x" \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator AdaptiveMaxPool3dGrad.
|
||||
*/
|
||||
REG_CUST_OP(AdaptiveMaxPool3dGrad)
|
||||
.INPUT(input_grad, TensorType::RealNumberType())
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(argmax, TensorType({DT_INT32}))
|
||||
.OUTPUT(output_grad, TensorType::RealNumberType())
|
||||
.CUST_OP_END_FACTORY_REG(AdaptiveMaxPool3dGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_MAX_POOL3D_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_MAX_POOL3D_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Applies a 3D adaptive max pooling over an input signal composed of several input planes. \n
|
||||
* The output is of size D x H x W, for 4D/5D input Tensor. \n
|
||||
* The number of output features is equal to the number of input planes.
|
||||
|
||||
* @par Inputs:
|
||||
* Two inputs, including:
|
||||
* @li x: A 4D/5D Tensor. Must be one of RealNumberType.
|
||||
* @li output_size: A 3D Tensor with data type int32.
|
||||
|
||||
* @par Outputs:
|
||||
* Two outputs, including:
|
||||
* @li y: A Tensor. Has the same data type as "x" \n
|
||||
* @li argmax: A Tensor with data type int32. Has the same shape as "y"
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator AdaptiveMaxPool3d.
|
||||
*/
|
||||
REG_CUST_OP(AdaptiveMaxPool3d)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(output_size, TensorType({DT_INT32}))
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.OUTPUT(argmax, TensorType({DT_INT32}))
|
||||
.CUST_OP_END_FACTORY_REG(AdaptiveMaxPool3d)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_MAX_POOL_2D_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ADAPTIVE_MAX_POOL_2D_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs the backpropagation of AdaptiveMaxPool2dGrad. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li input_grad: A 3D or 4D Tensor of input's gradient. Must be one of RealNumberType. \n
|
||||
* @li x: A 3D or 4D Tensor. Must be one of RealNumberType. \n
|
||||
* @li argmax: A 3D or 4D Tensor of type IndexNumberType. \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li output_grad: A Tensor. Has the same data type and shape as "x" \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator AdaptiveMaxPool2dGrad.
|
||||
*/
|
||||
REG_CUST_OP(AdaptiveMaxPool2dGrad)
|
||||
.INPUT(y_grad, TensorType::FloatingDataType())
|
||||
.INPUT(x, TensorType::FloatingDataType())
|
||||
.INPUT(argmax, TensorType::IndexNumberType())
|
||||
.OUTPUT(x_grad, TensorType::FloatingDataType())
|
||||
.CUST_OP_END_FACTORY_REG(AdaptiveMaxPool2dGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ADJUST_CONTRASTV2_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ADJUST_CONTRASTV2_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Adjust the contrast of one or more images . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Input images is a tensor of at least 3 dimensions. The last 3 dimensions are
|
||||
interpreted as '[height, width, channels]'. Inputs include:
|
||||
* @li images:A Tensor of type float. Images to adjust. At least 3-D. The format
|
||||
must be NHWC.
|
||||
* @li scale:A Tensor of type float. A float multiplier for adjusting contrast . \n
|
||||
|
||||
* @par Outputs:
|
||||
* y:A Tensor of type float. The format must be NHWC. \n
|
||||
|
||||
* @attention Constraints:
|
||||
* Input images is a tensor of at least 3 dimensions. The last dimension is
|
||||
interpreted as channels, and must be three . \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with tensorflow AdjustContrast operator.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(AdjustContrast)
|
||||
.INPUT(images, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(contrast_factor, TensorType({DT_FLOAT}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.CUST_OP_END_FACTORY_REG(AdjustContrast)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_ARG_MAX_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_ARG_MAX_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
*@brief Returns the index with the largest value across axes of a tensor. \n
|
||||
|
||||
*@par Inputs:
|
||||
* Two inputs, including:
|
||||
*@li x: A multi-dimensional Tensor of type float16, float32, or int16.
|
||||
*@li dimension: A Scalar of type int32, specifying the index with the largest value. \n
|
||||
|
||||
*@par Attributes:
|
||||
*dtype: The output type, either "int32" or "int64". Defaults to "int64". \n
|
||||
|
||||
*@par Outputs:
|
||||
*y: A multi-dimensional Tensor of type int32 or int64, specifying the index with the largest value. The dimension is one
|
||||
less than that of "x". \n
|
||||
|
||||
*@attention Constraints:
|
||||
*@li x: If there are multiple maximum values, the index of the first maximum value is used.
|
||||
*@li The value range of "dimension" is [-dims, dims - 1]. "dims" is the dimension length of "x". \n
|
||||
|
||||
*@par Third-party framework compatibility
|
||||
* Compatible with TensorFlow operator ArgMax.
|
||||
*/
|
||||
REG_CUST_OP(ArgMaxV2)
|
||||
.INPUT(x, TensorType::NumberType())
|
||||
.INPUT(dimension, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType({DT_INT32, DT_INT64}))
|
||||
.ATTR(dtype, Type, DT_INT64)
|
||||
.CUST_OP_END_FACTORY_REG(ArgMaxV2)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_BARTLETT_WINDOW_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_BARTLETT_WINDOW_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes Bartlett window function. \n
|
||||
|
||||
*
|
||||
* @par Inputs:
|
||||
* @li window_length: A tensor of IntegerDataType.
|
||||
*
|
||||
* @par Attributes:
|
||||
* @li periodic: An optional attribute. Defaults to true .
|
||||
* @li dtype: An optional attribute. Defaults to "0" .
|
||||
*
|
||||
*
|
||||
* @par Outputs:
|
||||
* y: A 1-D tensor of size (window_length,) containing the window
|
||||
*
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator LogicalXor.
|
||||
*
|
||||
*/
|
||||
REG_CUST_OP(BartlettWindow)
|
||||
.INPUT(window_length, TensorType({DT_INT32, DT_INT64}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.ATTR(periodic, Bool, true)
|
||||
.ATTR(dtype, Int, 0)
|
||||
.CUST_OP_END_FACTORY_REG(BartlettWindow)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_BATCH_NORM_GRAD_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_BATCH_NORM_GRAD_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs the backpropagation of BatchNormGrad. \n
|
||||
|
||||
* @par Notes:
|
||||
* @li Note that the size of 4D Tensors are defined by either "NHWC" or "NCHW".
|
||||
* The size of 1D Tensors matches the dimension C of the 4D Tensors. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x: the input "x" from BatchNormGrad. Must be a 4D tensor.
|
||||
* @li dy: the input "y_backprop" from BatchNormGrad. Must be a 4D tensor.
|
||||
* @li scale: the input "scale" from BatchNormGrad. Must be a 1D tensor.
|
||||
* @li reserve_space_1: If "is_training" is true, input the batch-mean of "x".
|
||||
* If "is_training" is false, input the running-mean of "x". Must be a 1D tensor.
|
||||
* @li reserve_space_2: If "is_training" is true, input the batch-var of "x".
|
||||
* If "is_training" is false, input the running-var of "x". Must be a 1D tensor.
|
||||
* @li ddx: the output "x_backprop" from BatchNormGrad. Must be a 4D tensor.
|
||||
* @li ddscale: the output "scale_backprop" from BatchNormGrad. Must be a 1D tensor.
|
||||
* @li ddoffset: the output "offset_backprop" from BatchNormGrad. Must be a 1D tensor. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li epsilon: An optional float32. Defaults to "0.0001". A small float number added to the variance of "x".
|
||||
* @li data_format: An optional string, ranging from "NHWC" "NCHW". Defaults to "NHWC".
|
||||
* @li is_training: An optional bool. Defaults to "true". Specifies the operation is for training or inference . \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li dx: the gradient of x. It has the same tensor desc as "x".
|
||||
* @li ddy: the gradient of dy. It has the same tensor desc as "dy".
|
||||
* @li dscale: the gradient of scale. It has the same tensor desc as "scale". \n
|
||||
*/
|
||||
REG_CUST_OP(BatchNormGradGrad)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(scale, TensorType({DT_FLOAT}))
|
||||
.INPUT(reserve_space_1, TensorType({DT_FLOAT}))
|
||||
.INPUT(reserve_space_2, TensorType({DT_FLOAT}))
|
||||
.INPUT(ddx, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(ddscale, TensorType({DT_FLOAT}))
|
||||
.INPUT(ddoffset, TensorType({DT_FLOAT}))
|
||||
.OUTPUT(dx, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(ddy, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(dscale, TensorType({DT_FLOAT}))
|
||||
.ATTR(epsilon, Float, 0.0001)
|
||||
.ATTR(data_format, String, "NHWC")
|
||||
.ATTR(is_training, Bool, true)
|
||||
.CUST_OP_END_FACTORY_REG(BatchNormGradGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GE_OP_BESSEL_I0_H
|
||||
#define GE_OP_BESSEL_I0_H
|
||||
#include "op_proto_macro.h"
|
||||
namespace ge {
|
||||
REG_CUST_OP(BesselI0)
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.CUST_OP_END_FACTORY_REG(BesselI0)
|
||||
}
|
||||
#endif // GE_OP_BESSEL_I0_H
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_BLACKMAN_WINDOW_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_BLACKMAN_WINDOW_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
REG_CUST_OP(BlackmanWindow)
|
||||
.INPUT(window_length, TensorType({DT_INT32, DT_INT64}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16}))
|
||||
.ATTR(periodic, Bool, true)
|
||||
.CUST_OP_END_FACTORY_REG(BlackmanWindow)
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CAUCHY_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CAUCHY_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the output as cauchy distribution . \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li sigma: Optional. Must be one of the following types: float32. Defaults to 1.0.
|
||||
* @li median: Optional. Must be one of the following types: float32. Defaults to 0.0.
|
||||
* @li size: Required. Must be one of the following types: listint . \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A Tensor. types:float16, float32.
|
||||
*/
|
||||
REG_CUST_OP(Cauchy)
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.ATTR(sigma, Float, 1.0)
|
||||
.ATTR(median, Float, 0.0)
|
||||
.REQUIRED_ATTR(size, ListInt)
|
||||
.CUST_OP_END_FACTORY_REG(Cauchy);
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_INVERSE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_INVERSE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
REG_CUST_OP(CholeskyInverse)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.ATTR(upper, Bool, false)
|
||||
.CUST_OP_END_FACTORY_REG(CholeskyInverse)
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Solves a linear system of equations with a positive semidefinite matrix
|
||||
to be inverted given its Cholesky factor matrix u . \n
|
||||
|
||||
* @par Inputs:
|
||||
* x1:A Tensor. input matrix b of size [..., M, K], where ... is zero or more batch dimensions.
|
||||
* x2:A Tensor. input matrix u of size [..., M, M], where ... is zero of more batch dimensions
|
||||
composed of upper or lower triangular Cholesky factor . \n
|
||||
|
||||
* @par Attributes:
|
||||
* upper:An optional bool. Defaults to False.Boolean indicating whether to
|
||||
consider the Cholesky factor as a lower or upper triangular matrix . \n
|
||||
|
||||
* @par Outputs:
|
||||
* y:A Tensor. Has the same type as x1 . \n
|
||||
|
||||
* @attention Constraints:
|
||||
* The input x2 is a tensor of shape [..., M, M] whose inner-most 2 dimensions
|
||||
form square matrices.
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with pytorch cholesky_solve operator.
|
||||
*/
|
||||
REG_CUST_OP(CholeskySolve)
|
||||
.INPUT(x1, TensorType::RealNumberType())
|
||||
.INPUT(x2, TensorType::RealNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.ATTR(upper, Bool, false)
|
||||
.CUST_OP_END_FACTORY_REG(CholeskySolve)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_COALESCE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_COALESCE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Returns the coalesced sparse tensor of the input. \n
|
||||
|
||||
* @par Inputs:
|
||||
* Three inputs, contains:
|
||||
* @li x_indices: A 2-D `Tensor` of type `int64`. It's elements should be non-negative.
|
||||
* The `indices` of nonzero elements of the `SparseTensor`, size `[ndims, nnz]`. \n
|
||||
* @li x_values: A 1-D `Tensor`. Must be one of the following types: float32, float16.
|
||||
* The `values` of the `SparseTensor`, size `[nnz]`. \n
|
||||
* @li x_shape: A 1-D `Tensor` of type `int64`.
|
||||
* The `shape` of the `SparseTensor`, size `[ndims]`. \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y_indices: A 2-D `Tensor` of type `int64`. It's elements are non-negative.
|
||||
* The `indices` of nonzero elements of the coalesced `SparseTensor`, size `[ndims, nnz_coalesced]`.
|
||||
* The `nnz_coalesced` represents the number of different indices in `x_indices` \n
|
||||
* @li y_values: A 1-D `Tensor`. Has the same type as `x_values`.
|
||||
* The `values` of the coalesced `SparseTensor`, size `[nnz_coalesced]`. \n
|
||||
* @li y_shape: A 1-D `Tensor` of type `int64`.
|
||||
* The `shape` of the coalesced `SparseTensor`, size `[ndims]`. \n
|
||||
|
||||
* @par Third-party framework compatibility.
|
||||
* Compatible with the Pytorch operator Coalesce. \n
|
||||
*/
|
||||
REG_CUST_OP(Coalesce)
|
||||
.INPUT(x_indices, TensorType({DT_INT64}))
|
||||
.INPUT(x_values, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(x_shape, TensorType({DT_INT64}))
|
||||
.OUTPUT(y_indices, TensorType({DT_INT64}))
|
||||
.OUTPUT(y_values, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(y_shape, TensorType({DT_INT64}))
|
||||
.CUST_OP_END_FACTORY_REG(Coalesce)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CSR_SPARSE_MATRIX_TO_DENSE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CSR_SPARSE_MATRIX_TO_DENSE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Converts a (possibly batched) CSRSparseMatrix to dense matrices. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x_dense_shape: A vector Tensor of type int32 or int64. 1D.
|
||||
* @li x_batch_pointers: A vector Tensor of type int32 or int64. 1D.
|
||||
* @li x_row_pointers: A vector Tensor of type int32 or int64. 1D.
|
||||
* @li x_values: A matrix Tensor of type float, double, complex64 or complex128. 2D. \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A matrix Tensor. Has the same type as "x_values", with shape "x_dense_shape". \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator CSRSparseMatrixToDense.
|
||||
*/
|
||||
REG_CUST_OP(CSRSparseMatrixToDense)
|
||||
.INPUT(x_dense_shape, TensorType({DT_INT64, DT_INT32}))
|
||||
.INPUT(x_batch_pointers, TensorType({DT_INT64, DT_INT32}))
|
||||
.INPUT(x_row_pointers, TensorType({DT_INT64, DT_INT32}))
|
||||
.INPUT(x_col_indices, TensorType({DT_INT64, DT_INT32}))
|
||||
.INPUT(x_values, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.CUST_OP_END_FACTORY_REG(CSRSparseMatrixToDense)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CSR_SPARSE_MATRIX_TO_SPARSE_TENSOR_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CSR_SPARSE_MATRIX_TO_SPARSE_TENSOR_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Converts a (possibly batched) CSRSparseMatrix to a SparseTensor . \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x_dense_shape: A 1D Tensor of type int32 or int64. The shape of the dense output tensor.
|
||||
* @li x_batch_pointers: A 1D Tensor of the same type as "x_dense_shape".
|
||||
* @li x_row_pointers: A 1D Tensor of the same type as "x_dense_shape".
|
||||
* @li x_col_indices: A 1D Tensor of the same type as "x_dense_shape".
|
||||
* @li x_values: A 1D Tensor of type float, double, complex64 or complex128 . \n
|
||||
|
||||
* @par Outputs:
|
||||
* indices: A 2D Tensor of the same type as "x_col_indices".
|
||||
* values: A 1D Tensor of the same type as "x_values".
|
||||
* dense_shape: A 1D Tensor of the same type as "x_dense_shape" . \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator CSRSparseMatrixToSparseTensor.
|
||||
*/
|
||||
REG_CUST_OP(CSRSparseMatrixToSparseTensor)
|
||||
.INPUT(x_dense_shape, TensorType({DT_INT32, DT_INT64}))
|
||||
.INPUT(x_batch_pointers, TensorType({DT_INT32, DT_INT64}))
|
||||
.INPUT(x_row_pointers, TensorType({DT_INT32, DT_INT64}))
|
||||
.INPUT(x_col_indices, TensorType({DT_INT32, DT_INT64}))
|
||||
.INPUT(x_values, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(indices, TensorType({DT_INT32, DT_INT64}))
|
||||
.OUTPUT(values, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(dense_shape, TensorType({DT_INT32, DT_INT64}))
|
||||
.CUST_OP_END_FACTORY_REG(CSRSparseMatrixToSparseTensor)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_DENSE_TO_CSR_SPARSE_MATRIX_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_DENSE_TO_CSR_SPARSE_MATRIX_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Converts a (possibly batched)dense matrix to CSRSparseMatrix. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li dense_input: A dense matrix Tensor of 2D or 3D. Dtype fp32, fp64, cfp64, cfp128. \n
|
||||
* @li indices: A matrix Tensor indicating positions of nonzero elements. Dtype int32, int64 \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y_dense_shape: A vector Tensor of type int32 or int64. 1D.
|
||||
* @li y_batch_pointers: A vector Tensor of type int32 or int64. 1D.
|
||||
* @li y_row_pointers: A vector Tensor of type int32 or int64. 1D.
|
||||
* @li y_values: A matrix Tensor of type float, double, complex64 or complex128. 2D. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator DenseToCSRSparseMatrix.
|
||||
*/
|
||||
REG_CUST_OP(DenseToCSRSparseMatrix)
|
||||
.INPUT(dense_input, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.INPUT(indices, TensorType({DT_INT64, DT_INT32}))
|
||||
.OUTPUT(y_dense_shape, TensorType({DT_INT64, DT_INT32}))
|
||||
.OUTPUT(y_batch_pointers, TensorType({DT_INT64, DT_INT32}))
|
||||
.OUTPUT(y_row_pointers, TensorType({DT_INT64, DT_INT32}))
|
||||
.OUTPUT(y_col_indices, TensorType({DT_INT64, DT_INT32}))
|
||||
.OUTPUT(y_values, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.CUST_OP_END_FACTORY_REG(DenseToCSRSparseMatrix)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_EIG_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_EIG_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the eigenvalue decomposition of a square matrix. \n
|
||||
|
||||
* @par Inputs:
|
||||
* One input, including:
|
||||
* @li x:A Tensor. Must be one of the following types: float32, float64, complex64, complex128.
|
||||
Shape is [N, N]. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li compute_v: A bool. Indicating whether to compute eigenvectors. \n
|
||||
|
||||
* @par Outputs:
|
||||
* eigen_values: A Tensor. Has the corresponding complex type with "x". Shape is [N, 1].
|
||||
* eigen_vectors: A Tensor. Has the corresponding complex type with "x". Shape is [N, N] with compute_v true,
|
||||
Shape is empty with compute_v false. \n
|
||||
*/
|
||||
|
||||
REG_CUST_OP(Eig)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(eigen_values, TensorType({DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(eigen_vectors, TensorType({DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.ATTR(compute_v, Bool, false)
|
||||
.CUST_OP_END_FACTORY_REG(Eig)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the exponential of "x" element-wise. \n
|
||||
|
||||
* @par Inputs:
|
||||
* One input:\n
|
||||
* x: A Tensor. Must be one of the following types: float16, float32, double, complex64, complex128. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li base: An optional attribute of type float32, specifying the base gamma. Defaults to "-1.0".
|
||||
* @li scale: An optional attribute of type float32, specifying the scale alpha. Defaults to "1.0".
|
||||
* @li shift: An optional attribute of type float32, specifying the shift beta. Defaults to "0.0". \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor of the same type as "x". \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with TensorFlow operator Exp.
|
||||
*/
|
||||
REG_CUST_OP(Exp)
|
||||
.INPUT(x, TensorType::UnaryDataType())
|
||||
.OUTPUT(y, TensorType::UnaryDataType())
|
||||
.ATTR(base, Float, -1.0)
|
||||
.ATTR(scale, Float, 1.0)
|
||||
.ATTR(shift, Float, 0.0)
|
||||
.CUST_OP_END_FACTORY_REG(Exp)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_FFT_WITH_SIZE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_FFT_WITH_SIZE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
REG_CUST_OP(FFTWithSize)
|
||||
.INPUT(x, TensorType({DT_DOUBLE, DT_FLOAT, DT_COMPLEX128, DT_COMPLEX64}))
|
||||
.OUTPUT(y, TensorType({DT_DOUBLE, DT_FLOAT, DT_COMPLEX128, DT_COMPLEX64}))
|
||||
.REQUIRED_ATTR(signal_nadim, Int)
|
||||
.REQUIRED_ATTR(inverse, Bool)
|
||||
.ATTR(signal_sizes, ListInt, {})
|
||||
.ATTR(norm, String, "backward")
|
||||
.ATTR(onesided, Bool, true)
|
||||
.CUST_OP_END_FACTORY_REG(FFTWithSize)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL_3D_GRAD_WITH_FIXED_KSIZE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL_3D_GRAD_WITH_FIXED_KSIZE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Compute gradients of FractionalMaxPool3d function. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li origin_input: A Tensor. Must be one of the following types: int32, int64, supported format list ["NCDHW, NDHWC"].
|
||||
* @li out_backprop: A Tensor. Must be one of the following types: float16,
|
||||
* float32, double, int32, int64, supported format list ["NCDHW, NDHWC"].
|
||||
* @li argmax: A Tensor. Must be one of the following types: int32, int64. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li data_format: An optional string. Defaults to "NCDHW". \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A Tensor. Has the same type as x.
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* @li compatible with Pytorch FractionalMaxPool3dBackward operator.
|
||||
*/
|
||||
REG_CUST_OP(FractionalMaxPool3DGradWithFixedKsize)
|
||||
.INPUT(origin_input, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16, DT_INT32, DT_INT64}))
|
||||
.INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16, DT_INT32, DT_INT64}))
|
||||
.INPUT(argmax, TensorType({DT_INT32, DT_INT64}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16, DT_INT32, DT_INT64}))
|
||||
.ATTR(data_format, String, "NCDHW")
|
||||
.CUST_OP_END_FACTORY_REG(FractionalMaxPool3DGradWithFixedKsize);
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL__3D_WITH_FIXED_KSIZE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL__3D_WITH_FIXED_KSIZE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs fractional max pooling on the input. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x: A Tensor. Must be one of the following types: float16, float32, double, int32,
|
||||
* int64, supported format list ["NCDHW, NDHWC"].
|
||||
* @li random_samples: A Tensor. Must be one of the following types: float16, float32, double. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li ksize: A required list of 3 floats. specifying the window size (D,H,W) of the input tensor.
|
||||
* @li output_shape: A required list of 3 ints. specifying the size (D,H,W) of the output tensor.
|
||||
* @li data_format: An optional string. Defaults to "NCDHW". \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A Tensor. Has the same type as x.
|
||||
* @li argmax: A Tensor of type int64 or int32. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* @li compatible with Pytorch FractionalMaxPool3d operator.
|
||||
*/
|
||||
REG_CUST_OP(FractionalMaxPool3DWithFixedKsize)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16, DT_INT32, DT_INT64}))
|
||||
.INPUT(random_samples, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16, DT_INT32, DT_INT64}))
|
||||
.OUTPUT(argmax, TensorType({DT_INT32, DT_INT64}))
|
||||
.REQUIRED_ATTR(ksize, ListFloat)
|
||||
.REQUIRED_ATTR(output_shape, ListInt)
|
||||
.ATTR(data_format, String, "NCDHW")
|
||||
.CUST_OP_END_FACTORY_REG(FractionalMaxPool3DWithFixedKsize);
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL_GRAD_WITH_FIXED_KSIZE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL_GRAD_WITH_FIXED_KSIZE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes gradient of the FractionalMaxPoolWithFixedKsize function . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Inputs include:
|
||||
* @li origin_input: A Tensor. Only use its shape. Must be one of the following types: int32, int64.
|
||||
* @li out_backprop: A Tensor. Gradient returned by back propagation. Must be one of the following
|
||||
types: float16, float32, double, int32, int64.
|
||||
* @li argmax: A Tensor. Must be one of the following types: int32, int64.\n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor. Has the same type as out_backprop. \n
|
||||
|
||||
* @par Attributes:
|
||||
* data_format: The default is "NCHW". \n
|
||||
|
||||
* @attention Constraints:
|
||||
* The implementation for FractionalMaxPoolGradWithFixedKsize on Ascend uses AICPU, with bad performance.
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* @li compatible with pytorch fractional_max_pool2d_backward operator.
|
||||
*/
|
||||
REG_CUST_OP(FractionalMaxPoolGradWithFixedKsize)
|
||||
.INPUT(origin_input, TensorType({DT_INT32, DT_INT64}))
|
||||
.INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
|
||||
.INPUT(argmax, TensorType({DT_INT32, DT_INT64}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
|
||||
.ATTR(data_format, String, "NCHW")
|
||||
.CUST_OP_END_FACTORY_REG(FractionalMaxPoolGradWithFixedKsize)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL_WITH_FIXED_KSIZE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_FRACTIONAL_MAX_POOL_WITH_FIXED_KSIZE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs fractional max pooling with fixed ksize on the input . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Inputs include:
|
||||
* @li x: A Tensor. Must be one of the following types: float16, float32, double, int32, int64.
|
||||
* 4-D with shape [batch, channels, height, width] . \n
|
||||
* @li random_samples: A Tensor. The value must > 0 and < 1. 3-D with shape [batch, channels, 2]
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A Tensor. Has the same type as x.
|
||||
* @li argmax: A Tensor. Has the same shape as y. Specifying the index of maximum value in input x
|
||||
* Each element in y is a maximum value.
|
||||
|
||||
* @par Attributes:
|
||||
* @li ksize: A required tuple or list, specifying the size of the window for each dimension of the input tensor.
|
||||
* @li output_shape: A required tuple or list, specifying the size of the output y.
|
||||
* @li data_format: The default is "NCHW". Specifying the format for input x.
|
||||
*/
|
||||
REG_CUST_OP(FractionalMaxPoolWithFixedKsize)
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
|
||||
.INPUT(random_samples, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
|
||||
.OUTPUT(argmax, TensorType({DT_INT32, DT_INT64}))
|
||||
.REQUIRED_ATTR(ksize, ListInt)
|
||||
.REQUIRED_ATTR(output_shape, ListInt)
|
||||
.ATTR(data_format, String, "NCHW")
|
||||
.CUST_OP_END_FACTORY_REG(FractionalMaxPoolWithFixedKsize)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_GEQRF_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_GEQRF_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the Geqrf decompositions of one matrix.
|
||||
|
||||
* @par Inputs:
|
||||
* @li x: A Tensor whose shape is [M, N].The inpute shape of x must be 2D.
|
||||
|
||||
* @par Outputs:
|
||||
* @li r: A Tensor. Has the same type as x.
|
||||
* @li tau: A Vector. Has min(M, N) elements.
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with pytorch Geqrf operator.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(Geqrf)
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(r, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(tau, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.CUST_OP_END_FACTORY_REG(Geqrf)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_GLU_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_GLU_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Counts the number of occurrences of each value in an integer array. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li grads: A Tensor of grad_output. Its data tpye must be float16, float, double.
|
||||
* @li x: A Tensor of input. Its data tpye must be float16, float, double.
|
||||
|
||||
* @par Outputs:
|
||||
* @li output: A Tensor of grad_input with the same shape of x. Its data tpye must be float16, float, double.
|
||||
|
||||
* @par Attributes:
|
||||
* binary_output: An required value for computing.
|
||||
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* the pytorch framework does not have the same operation.
|
||||
*/
|
||||
REG_CUST_OP(GluGrad)
|
||||
.INPUT(grads, TensorType({DT_DOUBLE, DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(x, TensorType({DT_DOUBLE, DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(y, TensorType({DT_DOUBLE, DT_FLOAT, DT_FLOAT16}))
|
||||
.REQUIRED_ATTR(axis, Int)
|
||||
.CUST_OP_END_FACTORY_REG(GluGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_GLU_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_GLU_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief The Glu operator represents a gated linear unit. Where the input is divided into two halves to
|
||||
* form A and B, All elements in B are evaluated by the sigmoid function, A and B do elements-wise product . \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x: A tensor of type float16, float32, float64 . \n
|
||||
|
||||
* @par Attributes:
|
||||
* axis: An optional attribute int32. Specifies the dimension along which to split. Defaults to -1 . \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: output with the same dtype of input x. \n
|
||||
|
||||
* @attention Constraints:
|
||||
* @li "axis" is in the range [-len(x.shape), (x.shape)-1] . \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the PyTorch operator GLU.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(Glu)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_FLOAT16}))
|
||||
.ATTR(axis, Int, -1)
|
||||
.CUST_OP_END_FACTORY_REG(Glu)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_HAMMING_WINDOW_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_HAMMING_WINDOW_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the hamming_window function. \n
|
||||
|
||||
* @par Inputs:
|
||||
* length: A Tensor of IntegerDataType, the size of returned window. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li periodic: An optional flag, if True, returns a window to be used as periodic
|
||||
* function. If False, return a symmetric window. Defaults to True. \n
|
||||
* @li alpha: An optional float coefficient. Defaults to 0.54. \n
|
||||
* @li beta: An optional float coefficient. Defaults to 0.46. \n
|
||||
* @li dtype: The desired data type of returned tensor. Only floating point
|
||||
* types are supported. Defaults to "float". \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor with type as attribute dtype. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator hamming_window. \n
|
||||
*/
|
||||
REG_CUST_OP(HammingWindow)
|
||||
.INPUT(length, TensorType::IntegerDataType())
|
||||
.OUTPUT(y, TensorType::FloatingDataType())
|
||||
.ATTR(periodic, Bool, true)
|
||||
.ATTR(alpha, Float, 0.54)
|
||||
.ATTR(beta, Float, 0.46)
|
||||
.ATTR(dtype, Int, 0)
|
||||
.CUST_OP_END_FACTORY_REG(HammingWindow)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Fills the elements of the input tensor with value val by selecting the indices in the order given in index. \n
|
||||
|
||||
* @par Inputs:
|
||||
* Four inputs, including:
|
||||
* @li x: A Tensor. Must be one of the following types: float16, float32, float64, uint8, uint16, uint32,
|
||||
* uint64, int8, int16, int32, int64. \n
|
||||
* @li dim: A Tensor of type int32, dimension along which to index. \n
|
||||
* @li indices: A Tensor of the indices, type should be int32. \n
|
||||
* @li value: A tensor. Must be one of the following types: float16, float32, float64, uint8, uint16, uint32,
|
||||
* uint64, int8, int16, int32, int64. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor with the same type and shape of input_x's. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator IndexFill. \n
|
||||
*/
|
||||
REG_CUST_OP(IndexFill)
|
||||
.INPUT(x, TensorType::BasicType())
|
||||
.INPUT(dim, TensorType({DT_INT32}))
|
||||
.INPUT(indices, TensorType({DT_INT32}))
|
||||
.INPUT(value, TensorType::BasicType())
|
||||
.OUTPUT(y, TensorType::BasicType())
|
||||
.CUST_OP_END_FACTORY_REG(IndexFill)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief InstanceNormV2Grad operator interface implementation.
|
||||
|
||||
* @par Inputs:
|
||||
* Seven inputs, including:
|
||||
* @li dy: A Tensor. Must be one of the following types: float16, float32.
|
||||
* @li x: A Tensor. Must be one of the following types: float16, float32.
|
||||
* @li gamma: A Tensor. Must be one of the following types: float32.
|
||||
* @li mean: A Tensor. Must be one of the following types: float32.
|
||||
* @li gamma: A Tensor. Must be one of the following types: float32.
|
||||
* @li save_mean: A Tensor. Must be one of the following types: float32.
|
||||
* @li save_variance: A Tensor. Must be one of the following types: float32.
|
||||
|
||||
* @par Attributes:
|
||||
* @li is_training: An optional bool, specifying if the operation is used for
|
||||
* training or inference. Defaults to "True".
|
||||
* @li epsilon: An optional float32, specifying the small value added to
|
||||
* variance to avoid dividing by zero. Defaults to "0.00001".
|
||||
|
||||
* @par Outputs:
|
||||
* Three outputs, including:
|
||||
* @li pd_x: A Tensor. Must be one of the following types: float16, float32.
|
||||
* @li pd_gamma: A Tensor. Must be one of the following types: float32.
|
||||
* @li pd_beta: A Tensor. Must be one of the following types: float32.
|
||||
|
||||
* @par Restrictions:
|
||||
* Warning: THIS FUNCTION NOW IS SUPPORT 5D INPUT WITH FORMAT NC1HWC0 AND 4D INPUT WITH FORMAT NCHW & NHWC
|
||||
*/
|
||||
REG_CUST_OP(InstanceNormV2Grad)
|
||||
.INPUT(dy, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(gamma, TensorType({DT_FLOAT}))
|
||||
.INPUT(mean, TensorType({DT_FLOAT}))
|
||||
.INPUT(variance, TensorType({DT_FLOAT}))
|
||||
.INPUT(save_mean, TensorType({DT_FLOAT}))
|
||||
.INPUT(save_variance, TensorType({DT_FLOAT}))
|
||||
|
||||
.OUTPUT(pd_x, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.OUTPUT(pd_gamma, TensorType({DT_FLOAT}))
|
||||
.OUTPUT(pd_beta, TensorType({DT_FLOAT}))
|
||||
|
||||
.ATTR(is_training, Bool, true)
|
||||
.ATTR(epsilon, Float, 0.00001)
|
||||
.CUST_OP_END_FACTORY_REG(InstanceNormV2Grad)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_LAYER_NORM_GRAD_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_LAYER_NORM_GRAD_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Compute the backward of LayerNormGrad. \n
|
||||
* @par Inputs:
|
||||
* x: the input x from LayerNorm. Must be one of the following types: float16, float32. \n
|
||||
* dy: the gradient of y. Must be one of the following types: float16,float32. \n
|
||||
* variance: the variance of x. Must be one of the following types: float16, float32. \n
|
||||
* mean: the mean value of x. Must be one of the following types: float16, float32. \n
|
||||
* gamma: the input gamma from LayerNorm. Must be one of the following types: float16, float32. \n
|
||||
* d_dx: the gradient of dx. Must be one of the following types: float16, float32. \n
|
||||
* d_dg: the gradient of dg. Must be one of the following types: float16, float32. \n
|
||||
* d_db: the gradient of db. Must be one of the following types: float16, float32. \n
|
||||
*
|
||||
* @par Outputs:
|
||||
* sopd_x: the gradient of x. Must be one of the following types: float16, float32. \n
|
||||
* sopd_dy: the gradient of dy. Must be one of the following types: float16, float32. \n
|
||||
* sopd_gamma: the gradient of gamma. Must be one of the following types: float16, float32. \n
|
||||
*/
|
||||
REG_CUST_OP(LayerNormGradGrad)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(dy, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(variance, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(mean, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(d_dx, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(d_dg, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(d_db, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(sopd_x, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(sopd_dy, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(sopd_gamma, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.CUST_OP_END_FACTORY_REG(LayerNormGradGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Draws samples from a multinomial distribution. \n
|
||||
* @brief Fills the elements of the input tensor with log normal values initialized by given mean and std \n
|
||||
|
||||
* @par Inputs:
|
||||
* Four inputs, including:
|
||||
* @li x: A Tensor. Must be one of the following types: float32, float64 \n
|
||||
* @li dim: A Tensor of type float, which is the mean of normal distribution. \n
|
||||
* @li std: A Tensor of type float, which is the mean of normal distribution. \n
|
||||
* @par Outputs:
|
||||
* y: A Tensor with the same type and shape of input_x's. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator LogNormal. \n
|
||||
*/
|
||||
REG_CUST_OP(LogNormalReverse)
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.ATTR(mean, Float, 2.0)
|
||||
.ATTR(std, Float, 1.0)
|
||||
.CUST_OP_END_FACTORY_REG(LogNormalReverse)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_LOGICAL_XOR_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_LOGICAL_XOR_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the element-wise LogicalXOR of the given input tensors.
|
||||
Zeros are treated as False and nonzeros are treated as True. \n
|
||||
|
||||
*
|
||||
* @par Inputs:
|
||||
* @li x1: A tensor of type bool.
|
||||
* @li x2: A tensor of the same type as "x1".
|
||||
*
|
||||
* @attention Constraints:
|
||||
* LogicalXor supports broadcasting.
|
||||
*
|
||||
* @par Outputs:
|
||||
* y: A tensor of the same type as "x1".
|
||||
*
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator LogicalXor.
|
||||
*
|
||||
*/
|
||||
REG_CUST_OP(LogicalXor)
|
||||
.INPUT(x1, TensorType({DT_BOOL}))
|
||||
.INPUT(x2, TensorType({DT_BOOL}))
|
||||
.OUTPUT(y, TensorType({DT_BOOL}))
|
||||
.CUST_OP_END_FACTORY_REG(LogicalXor)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Creates a one-dimensional tensor of size steps whose values are
|
||||
evenly spaced from start to end, inclusive, on a logarithmic scale
|
||||
with base base.
|
||||
|
||||
* @par Inputs:
|
||||
* Two inputs, including:
|
||||
* start: A tensor. Must be one of the following types:
|
||||
* float16, float32. \n
|
||||
* end: A tensor. Must be one of the following types:
|
||||
* float16, float32. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li steps: An optional int.Defaults to 100. \n
|
||||
* @li base: An optional float.Defaults to 10.0. \n
|
||||
* @li dtype: An optional int.Defaults to 1. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor with the same type and shape of input_x's. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator logspace. \n
|
||||
*/
|
||||
REG_CUST_OP(LogSpace)
|
||||
.INPUT(start, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(end, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.ATTR(steps, Int, 100)
|
||||
.ATTR(base, Int, 10)
|
||||
.ATTR(dtype, Int, 1)
|
||||
.CUST_OP_END_FACTORY_REG(LogSpace)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_LSTSQ_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_LSTSQ_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @Calculates the solutions of the least squares and minimum norm problems. \n
|
||||
|
||||
* @par Inputs:
|
||||
* matrix: An 2D tensor of type float16, float32, double.
|
||||
* rhs: An 2D tensor of type float16, float32, double.
|
||||
|
||||
* @par Attributes:
|
||||
* @li Ie_regularizer: An optional float. This value defaults to 0.0.
|
||||
* @li fast: An optional bool. This value defaults to True.
|
||||
|
||||
* @par Outputs:
|
||||
* y: An 2D tensor of type float16, float32, double.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(Lstsq)
|
||||
.INPUT(matrix, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(rhs, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.ATTR(l2_regularizer, Float, 0.0)
|
||||
.ATTR(fast, Bool, true)
|
||||
.CUST_OP_END_FACTORY_REG(Lstsq)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_LU_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_LU_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
REG_CUST_OP(LuSolve)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(lu_data, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.INPUT(lu_pivots, TensorType({DT_INT32}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.CUST_OP_END_FACTORY_REG(LuSolve)
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief: Returns the matrix logarithm of one or more square matrices. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x: A Tensor. Must be one of the following types:
|
||||
* complex64, complex128. \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A Tensor. Has the same type as "x". \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MaxLogarithm.
|
||||
*/
|
||||
REG_CUST_OP(MatrixLogarithm)
|
||||
.INPUT(x, TensorType({DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.OUTPUT(y, TensorType({DT_COMPLEX64, DT_COMPLEX128}))
|
||||
.CUST_OP_END_FACTORY_REG(MatrixLogarithm)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MATRIX_POWER_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MATRIX_POWER_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief: Computes the n-th power of a batch of square matrices. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li x: A tensor of shape (n, m, m). Must be one of the following types: float32, float16. \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li y: A tensor of the same shape and type with x. \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li n: A required int. The exponent. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator MatrixPower.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(MatrixPower)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
|
||||
.REQUIRED_ATTR(n, Int)
|
||||
.CUST_OP_END_FACTORY_REG(MatrixPower)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MAX_POOL3_D_GRAD_WITH_ARGMAX_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MAX_POOL3_D_GRAD_WITH_ARGMAX_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes gradients of the MaxPool3DWithArgmax function
|
||||
*
|
||||
* @par Inputs:
|
||||
* Three input:
|
||||
* x: An 5D tensor. Supported type: RealNumberType. Format as NCDHW.
|
||||
* grads: Gradient tensor(NDC1HWC0) of RealNumberType
|
||||
* argmax: An 5D tensor. Supported type: int32/int64.
|
||||
* @par Attributes:
|
||||
* @li ksize: A required list of int32 values,
|
||||
* specifying the size of the window for each dimension of the input tensor.
|
||||
* No default value.
|
||||
* @li strides: A required list of int32 values,
|
||||
* specifying the stride of the sliding window for each dimension of
|
||||
* the input tensor. No default value.
|
||||
* @li pads: A required 3*2-dimension-list of int32 values.
|
||||
* specifying the pad of three dimension of input, implement with 0.
|
||||
* @li dilation: dilation of kernel. default value is {1,1,1,1,1}.
|
||||
* @li ceil_mode: default value is false.
|
||||
* @li data_format: the format of torch input, default value is "NCDHW".
|
||||
* @li dtype: the function of this field is to determine the type of
|
||||
* output tensor, "0" is the default value, represents float32. Only "0" and
|
||||
* "1" for float16 is supported.
|
||||
* @par Outputs:
|
||||
* y: Result tensor of RealNumberType.
|
||||
*/
|
||||
REG_CUST_OP(MaxPool3DGradWithArgmax)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(grads, TensorType::RealNumberType())
|
||||
.INPUT(argmax, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.REQUIRED_ATTR(ksize, ListInt)
|
||||
.REQUIRED_ATTR(strides, ListInt)
|
||||
.REQUIRED_ATTR(pads, ListInt)
|
||||
.REQUIRED_ATTR(dilation, ListInt)
|
||||
.ATTR(ceil_mode, Bool, false)
|
||||
.ATTR(data_format, String, "NCDHW")
|
||||
.ATTR(dtype, Int, 0)
|
||||
.CUST_OP_END_FACTORY_REG(MaxPool3DGradWithArgmax)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL_2D_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL_2D_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs the backpropagation of MaxUnpool2DGrad . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Three inputs, including:
|
||||
* @li x: An 4d tensor. Supported type: float, double, int32,
|
||||
* uint8, int16, int8, int64, uint16, half, uint32, uint64.
|
||||
* Must set the format, supported format list ["NCHW, NHWC"]
|
||||
* @li grads: An 4d tensor. Supported type: float, double, int32,
|
||||
* uint8, int16, int8, int64, uint16, half, uint32, uint64.
|
||||
* Must set the format, supported format list ["NCHW, NHWC"]
|
||||
* @li An 4d tensor of type uint16 or int64. Must set the format, supported format list ["NCHW, NHWC"] \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li ksize: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the size of the window for each dimension of the input tensor.
|
||||
* No default value.
|
||||
* @li strides: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the stride of the sliding window for each dimension of
|
||||
* the input tensor. No default value.
|
||||
* @li pads:A required list of int8, int16, int32, or int64 values,
|
||||
* a data to calculate when padding_mode is "CALCULATED".
|
||||
* @li data_format: An optional string. Defaults to "NCHW" .
|
||||
* @li output_shape: A required tuple or list of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor. Has the same type and format as input "x" . \n
|
||||
|
||||
* @attention Constraints:
|
||||
* @li "ksize" is a list that has length 4: ksize[0] = ksize[1] = 1 or ksize[0] = ksize[3] = 1,
|
||||
* @li "strides" is a list that has length 4: strides[0] = strides[1] = 1 or strides[0] = strides[3] = 1
|
||||
* @li "pads" is a list that has specify the number of implicit zero pad in
|
||||
* each dimension and the corresponding function dimension is the same as stride. \n
|
||||
|
||||
* @see MaxUnpool2D
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MaxUnpool2DGrad.
|
||||
*/
|
||||
REG_CUST_OP(MaxUnpool2DGrad)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(grads, TensorType::RealNumberType())
|
||||
.INPUT(argmax, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.REQUIRED_ATTR(ksize, ListInt)
|
||||
.REQUIRED_ATTR(strides, ListInt)
|
||||
.REQUIRED_ATTR(pads, ListInt)
|
||||
.ATTR(data_format, String, "NCHW")
|
||||
.ATTR(output_shape, ListInt, {})
|
||||
.CUST_OP_END_FACTORY_REG(MaxUnpool2DGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL2_D_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL2_D_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief 'MaxUnpool2D` takes in as input the output of :class:`MaxPool2D`
|
||||
including the indices of the maximal values and computes a partial inverse
|
||||
in which all non-maximal values are set to zero. . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Two inputs, including:
|
||||
* @li x: An 4d tensor. Supported type: float, double, int32,
|
||||
* uint8, int16, int8, int64, uint16, half, uint32, uint64.
|
||||
* Must set the format, supported format list ["NCHW, NHWC"]
|
||||
* @li argmx: An 4d tensor of type uint16 or int64. Must set the format, supported format list ["NCHW, NHWC"] \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li ksize: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the size of the window for each dimension of the input tensor.
|
||||
* No default value.
|
||||
* @li strides: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the stride of the sliding window for each dimension of
|
||||
* the input tensor. No default value.
|
||||
* @li pads:A required list of int8, int16, int32, or int64 values,
|
||||
* a data to calculate when padding_mode is "CALCULATED".
|
||||
* @li data_format: An optional string. Defaults to "NCHW" .
|
||||
* @li output_shape: A required tuple or list of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor. Has the same type and format as input "x". \n
|
||||
|
||||
* @attention Constraints:
|
||||
* @li "ksize" is a list that has length 4: ksize[0] = ksize[1] = 1 or ksize[0] = ksize[3] = 1,
|
||||
* @li "strides" is a list that has length 4: strides[0] = strides[1] = 1 or strides[0] = strides[3] = 1
|
||||
* @li "pads" pads should be smaller than half of ksize".
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MaxUnpool2D.
|
||||
*/
|
||||
REG_CUST_OP(MaxUnpool2D)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(argmax, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.REQUIRED_ATTR(ksize, ListInt)
|
||||
.REQUIRED_ATTR(strides, ListInt)
|
||||
.REQUIRED_ATTR(pads, ListInt)
|
||||
.ATTR(data_format, String, "NCHW")
|
||||
.ATTR(output_shape, ListInt, {})
|
||||
.CUST_OP_END_FACTORY_REG(MaxUnpool2D)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL_3D_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL_3D_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Performs the backpropagation of MaxUnpool3DGrad . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Three inputs, including:
|
||||
* @li x: An 5d tensor. Supported type: float, double, int32,
|
||||
* uint8, int16, int8, int64, uint16, half, uint32, uint64.
|
||||
* Must set the format, supported format list ["NCDHW, NDHWC"]
|
||||
* @li grads: An 4d tensor. Supported type: float, double, int32,
|
||||
* uint8, int16, int8, int64, uint16, half, uint32, uint64.
|
||||
* Must set the format, supported format list ["NCDHW, NDHWC"]
|
||||
* @li An 5d tensor of type uint16 or int64. Must set the format, supported format list ["NCDHW, NDHWC"] \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li ksize: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the size of the window for each dimension of the input tensor.
|
||||
* No default value.
|
||||
* @li strides: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the stride of the sliding window for each dimension of
|
||||
* the input tensor. No default value.
|
||||
* @li pads:A required list of int8, int16, int32, or int64 values,
|
||||
* a data to calculate when padding_mode is "CALCULATED".
|
||||
* @li data_format: An optional string. Defaults to "NCHW" .
|
||||
* @li output_shape: A required tuple or list of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor. Has the same type and format as input "x" . \n
|
||||
|
||||
* @attention Constraints:
|
||||
* @li "ksize" is a list that has length 5: ksize[0] = ksize[1] = 1 or ksize[0] = ksize[4] = 1
|
||||
* @li "strides" is a list that has length 5: strides[0] = strides[1] = 1 or strides[0] = strides[4] = 1
|
||||
* @li "pads" is a list that has specify the number of implicit zero pad in
|
||||
* each dimension and the corresponding function dimension is the same as stride. \n
|
||||
|
||||
* @see MaxUnpool3D
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MaxUnpool3DGrad.
|
||||
*/
|
||||
REG_CUST_OP(MaxUnpool3DGrad)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(grads, TensorType::RealNumberType())
|
||||
.INPUT(argmax, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.REQUIRED_ATTR(ksize, ListInt)
|
||||
.REQUIRED_ATTR(strides, ListInt)
|
||||
.REQUIRED_ATTR(pads, ListInt)
|
||||
.ATTR(data_format, String, "NCDHW")
|
||||
.ATTR(output_shape, ListInt, {})
|
||||
.CUST_OP_END_FACTORY_REG(MaxUnpool3DGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL_3D_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MAX_UNPOOL_3D_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief 'MaxUnpool3D` takes in as input the output of :class:`MaxPool3D`
|
||||
including the indices of the maximal values and computes a partial inverse
|
||||
in which all non-maximal values are set to zero. . \n
|
||||
|
||||
* @par Inputs:
|
||||
* Two inputs, including:
|
||||
* @li x: An 5d tensor. Supported type: float, double, int32,
|
||||
* uint8, int16, int8, int64, uint16, half, uint32, uint64.
|
||||
* Must set the format, supported format list ["NCDHW, NDHWC"]
|
||||
* @li argmx: An 5d tensor of type uint16 or int64. Must set the format, supported format list ["NCDHW, NDHWC"] \n
|
||||
|
||||
* @par Attributes:
|
||||
* @li ksize: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the size of the window for each dimension of the input tensor.
|
||||
* No default value.
|
||||
* @li strides: A required list of int8, int16, int32, or int64 values,
|
||||
* specifying the stride of the sliding window for each dimension of
|
||||
* the input tensor. No default value.
|
||||
* @li pads:A required list of int8, int16, int32, or int64 values,
|
||||
* a data to calculate when padding_mode is "CALCULATED".
|
||||
* @li data_format: An optional string. Defaults to "NCDHW" .
|
||||
* @li output_shape: A required tuple or list of type int32. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor. Has the same type and format as input "x". \n
|
||||
|
||||
* @attention Constraints:
|
||||
* @li "ksize" is a list that has length 5: ksize[0] = ksize[1] = 1 or ksize[0] = ksize[4] = 1
|
||||
* @li "strides" is a list that has length 5: strides[0] = strides[1] = 1 or strides[0] = strides[4] = 1
|
||||
* @li "pads" pads should be smaller than half of ksize".
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MaxUnpool3D.
|
||||
*/
|
||||
REG_CUST_OP(MaxUnpool3D)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(argmax, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.REQUIRED_ATTR(ksize, ListInt)
|
||||
.REQUIRED_ATTR(strides, ListInt)
|
||||
.REQUIRED_ATTR(pads, ListInt)
|
||||
.ATTR(data_format, String, "NCDHW")
|
||||
.ATTR(output_shape, ListInt, {})
|
||||
.CUST_OP_END_FACTORY_REG(MaxUnpool3D)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Calculates the reversed outputs of the function "MaximumGradGrad". \n
|
||||
|
||||
* @par Inputs:
|
||||
* Four inputs, including:
|
||||
* @li grad_y1: A mutable Tensor. Must be one of the following types:
|
||||
* float16, float32, int32.
|
||||
* @li grad_y2: A mutable Tensor. Has the same type as "grad_y1".
|
||||
* @li x1: A mutable Tensor of the same type as "grad_y1".
|
||||
* @li x2: A mutable Tensor of the same type as "grad_y1". \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li spod_x1: A mutable Tensor. Has the same type as "grad_y1".
|
||||
* @li spod_x2: A mutable Tensor. Has the same type as "grad_y1".
|
||||
* @li sopd_grads: A mutable Tensor. Has the same type as "grad_y1". \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MaximumGradGrad.
|
||||
*/
|
||||
REG_CUST_OP(MaximumGradGrad)
|
||||
.INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.INPUT(grad_y1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.INPUT(grad_y2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.OUTPUT(spod_x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.OUTPUT(spod_x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.OUTPUT(spod_grads, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.CUST_OP_END_FACTORY_REG(MaximumGradGrad)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MEDIAN_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MEDIAN_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief MedianGrad. \n
|
||||
|
||||
* @par Inputs:
|
||||
* four inputs, including:
|
||||
* @li y_grad: A Tensor. Support int16/int32/int64/float/double.\n
|
||||
* @li x: A Tensor. Support int16/int32/int64/float/double.\n
|
||||
* @li y: A Tensor. Support int16/int32/int64/float/double.\n
|
||||
* @li indices: A Tensor. Support int32/int64.\n
|
||||
|
||||
* @par Outputs:
|
||||
* one output, including:
|
||||
* @li x_grad: A Tensor. Support int16/int32/int64/float/double.\n
|
||||
|
||||
* @par Attributes:
|
||||
* @li global_median: whether the output is the global median of all elements or just in the dim.\n
|
||||
* @li axis:the dimension to reduce.\n
|
||||
* @li keepdim: whether the output tensor has dim retained or not.\n
|
||||
*/
|
||||
REG_CUST_OP(MedianGrad)
|
||||
.INPUT(y_grad, TensorType({DT_INT16, DT_INT32, DT_INT64, DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(x, TensorType({DT_INT16, DT_INT32, DT_INT64, DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(y, TensorType({DT_INT16, DT_INT32, DT_INT64, DT_FLOAT, DT_DOUBLE}))
|
||||
.OPTIONAL_INPUT(indices, TensorType({DT_INT32, DT_INT64}))
|
||||
.OUTPUT(x_grad, TensorType({DT_INT16, DT_INT32, DT_INT64, DT_FLOAT, DT_DOUBLE}))
|
||||
.REQUIRED_ATTR(global_median, Bool)
|
||||
.ATTR(axis, Int, 0)
|
||||
.ATTR(keepdim, Bool, false)
|
||||
.CUST_OP_END_FACTORY_REG(MedianGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MEDIAN_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MEDIAN_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Returns the median of the values in input.
|
||||
*
|
||||
* @par Inputs
|
||||
* one input including:
|
||||
* @li x: input A Tensor.Must be one of the RealNumberType types.
|
||||
*
|
||||
* @par Attributes:
|
||||
* @li global_median: whether the output is the global median of all elements or just in the dim.
|
||||
* @li axis: the dimension to reduce.
|
||||
* @li keepdim: whether the output tensor has dim retained or not.
|
||||
*
|
||||
* @par Output:
|
||||
* one output including:
|
||||
* @li y: The output format is (Tensor, Tensor),The first tensor will be populated with the median values and the
|
||||
* second tensor, which must have dtype long, with their indices in the dimension dim of input.
|
||||
*/
|
||||
REG_CUST_OP(Median)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT16, DT_INT32, DT_INT64}))
|
||||
.OUTPUT(values, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT16, DT_INT32, DT_INT64}))
|
||||
.OUTPUT(indices, TensorType({DT_INT32, DT_INT64}))
|
||||
.REQUIRED_ATTR(global_median, Bool)
|
||||
.ATTR(axis, Int, 0)
|
||||
.ATTR(keepdim, Bool, false)
|
||||
.CUST_OP_END_FACTORY_REG(Median)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Calculates the reversed outputs of the function "MinimumGradGrad"
|
||||
|
||||
* @par Inputs:
|
||||
* Three inputs, including:
|
||||
* @li grad_y1: A mutable Tensor. Must be one of the following types:
|
||||
* float16, float32, int32.
|
||||
* @li grad_y2: A mutable Tensor. Has the same type as "grad_y1".
|
||||
* @li x1: A mutable Tensor of the same type as "grad_y1".
|
||||
* @li x2: A mutable Tensor of the same type as "grad_y1". \n
|
||||
|
||||
* @par Outputs:
|
||||
* @li spod_x1: A mutable Tensor. Has the same type as "grad_y1".
|
||||
* @li spod_x2: A mutable Tensor. Has the same type as "grad_y1".
|
||||
* @li sopd_grads: A mutable Tensor. Has the same type as "grad_y1". \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator MinimumGradGrad.
|
||||
*/
|
||||
REG_CUST_OP(MinimumGradGrad)
|
||||
.INPUT(x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.INPUT(x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.INPUT(grad_y1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.INPUT(grad_y2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.OUTPUT(spod_x1, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.OUTPUT(spod_x2, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.OUTPUT(spod_grads, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT32}))
|
||||
.CUST_OP_END_FACTORY_REG(MinimumGradGrad)
|
||||
} // namespace ge
|
||||
|
||||
#endif // CUSTOMIZE_OP_PROTO_INC_CHOLESKY_SOLVE_OP_H
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MULTI_MARGIN_LOSS_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MULTI_MARGIN_LOSS_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the MultiMarginLossGrad. \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li y_grad: A scalar of type float16, float32, double.
|
||||
* @li x: A 2D Tensor of dtype float16, float32, double.
|
||||
* @li target: A 1D Tensor of dtype int64.
|
||||
* @li weight:Optional 1D Tensor of dtype float16, float32, double.
|
||||
a manual rescaling weight given to each class.
|
||||
* If given, it has to be a Tensor of size C. Otherwise,
|
||||
* it is treated as if having all ones. \n
|
||||
|
||||
* @par Attributes:
|
||||
* margin :An optional float , Defaults to 1.
|
||||
* p :An optional int .The norm degree for pairwise distance.Should be 1 or 2.
|
||||
Defaults to 1.
|
||||
* reduction:A character string from "none", "mean", and "sum", specifying the
|
||||
* reduction type to be applied to the output. Defaults to "mean". \n
|
||||
|
||||
|
||||
* @par Outputs:
|
||||
* x_grad: A Tensor. the same type and shape as "x".
|
||||
*/
|
||||
|
||||
REG_CUST_OP(MultiMarginLossGrad)
|
||||
.INPUT(y_grad, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(target, TensorType({DT_INT64}))
|
||||
.OPTIONAL_INPUT(weight, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.ATTR(p, Int, 1)
|
||||
.ATTR(margin, Float, 1.0)
|
||||
.ATTR(reduction, String, "mean")
|
||||
.OUTPUT(x_grad, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.CUST_OP_END_FACTORY_REG(MultiMarginLossGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MULTI_MARGIN_LOSS_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MULTI_MARGIN_LOSS_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes Multi Margin loss.
|
||||
* @par Inputs:
|
||||
* two inputs,one optional input including:
|
||||
* @li x: with shape :math:`(N, C)`. Data type only support float32 and float16,float64
|
||||
* @li target: Ground truth labels, with shape :math:`(N,)`. Data type only support int64.
|
||||
* @li weight:The rescaling weight to each class, with shape :math:`(C,)` and data type only
|
||||
support float32 and float16,float64. \n
|
||||
|
||||
* @par Attributes:
|
||||
* margin :An optional float , Defaults to 1.
|
||||
* p :An optional int .The norm degree for pairwise distance. Should be 1 or 2. Defaults to 1.
|
||||
* reduction:A character string from "none", "mean", and "sum", specifying the
|
||||
* reduction type to be applied to the output. Defaults to "mean". \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: when reduction="sum" or "mean", y is a scalar. when reduction="none", y has the
|
||||
* same shape as "target". \n
|
||||
*/
|
||||
REG_CUST_OP(MultiMarginLoss)
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(target, TensorType({DT_INT64}))
|
||||
.OPTIONAL_INPUT(weight, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.ATTR(p, Int, 1)
|
||||
.ATTR(margin, Float, 1.0)
|
||||
.ATTR(reduction, String, "mean")
|
||||
.OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
|
||||
.CUST_OP_END_FACTORY_REG(MultiMarginLoss)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MULTILABEL_MARGIN_LOSS_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MULTILABEL_MARGIN_LOSS_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the MultilabelMarginLossGrad . \n
|
||||
|
||||
* @par Inputs:
|
||||
* @li y_grad: A scalar of type float16, float32. \n
|
||||
* @li x: A 1D or 2D Tensor of dtype float16, float32. \n
|
||||
* @li target: A 1D or 2D Tensor of dtype int32. \n
|
||||
* @li is_target: A 1D or 2D Tensor of dtype int32. \n
|
||||
|
||||
* @par Attributes:
|
||||
* reduction:A character string from "none", "mean", and "sum", specifying the
|
||||
* reduction type to be applied to the output. Defaults to "mean". \n
|
||||
|
||||
* @par Outputs:
|
||||
* x_grad: A Tensor. The same type and shape as "x". \n
|
||||
*/
|
||||
REG_CUST_OP(MultilabelMarginLossGrad)
|
||||
.INPUT(y_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(target, TensorType({DT_INT32}))
|
||||
.INPUT(is_target, TensorType({DT_INT32}))
|
||||
.ATTR(reduction, String, "mean")
|
||||
.OUTPUT(x_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.CUST_OP_END_FACTORY_REG(MultilabelMarginLossGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MVLGAMMA_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MVLGAMMA_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes gradients for Mvlgamma (multivariate log-gamma function). \n
|
||||
|
||||
* @par Inputs:
|
||||
* y_grad:A Tensor. Must be one of the following types: float32, double.
|
||||
* x:A Tensor. Must be one of the following types: float32, double.
|
||||
|
||||
* @par Attributes:
|
||||
* p:A required attribute of the following types: int32, int64. \n
|
||||
|
||||
* @par Outputs:
|
||||
* x_grad:A Tensor. Has the same type as y_grad and x. \n
|
||||
|
||||
* @par Third-party framework compatibility.
|
||||
* Compatible with pytorch mvlgamma_backward operator.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(MvlgammaGrad)
|
||||
.INPUT(y_grad, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.OUTPUT(x_grad, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.REQUIRED_ATTR(p, Int)
|
||||
.CUST_OP_END_FACTORY_REG(MvlgammaGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_MVLGAMMA_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_MVLGAMMA_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the multivariate log-gamma function. \n
|
||||
|
||||
* @par Inputs:
|
||||
* x:A Tensor. Must be one of the following types: float32, double.
|
||||
|
||||
* @par Attributes:
|
||||
* p:A required attribute of the following types: int32, int64. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y:A Tensor. Has the same type as x. \n
|
||||
|
||||
* @par Third-party framework compatibility.
|
||||
* Compatible with pytorch Mvlgamma operator.
|
||||
*/
|
||||
REG_CUST_OP(Mvlgamma)
|
||||
.INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
|
||||
.REQUIRED_ATTR(p, Int)
|
||||
.CUST_OP_END_FACTORY_REG(Mvlgamma)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -21,5 +21,10 @@
|
|||
|
||||
#define REG_CUST_OP(x) REG_OP(Cust##x)
|
||||
#define CUST_OP_END_FACTORY_REG(x) OP_END_FACTORY_REG(Cust##x)
|
||||
#define CUST_IMPLEMT_VERIFIER(op_name, x) IMPLEMT_VERIFIER(Cust##op_name, x)
|
||||
#define CUST_VERIFY_FUNC_REG(op_name, x) VERIFY_FUNC_REG(Cust##op_name, x)
|
||||
#define CUST_IMPLEMT_INFERFUNC(op_name, x) IMPLEMT_INFERFUNC(Cust##op_name, x)
|
||||
#define CUST_INFER_FUNC_REG(op_name, x) INFER_FUNC_REG(Cust##op_name, x)
|
||||
#define CUST_COMMON_INFER_FUNC_REG(op_name, x) COMMON_INFER_FUNC_REG(Cust##op_name, x)
|
||||
|
||||
#endif // MINDSPORE_CCSRC_PLUGIN_DEVICE_ASCEND_KERNEL_AICPU_AICPU_OPS_CUSTOMIZE_OP_PTOTO_H_
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_PDIST_GRAD_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_PDIST_GRAD_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief Computes the grad of x in pdist. \n
|
||||
|
||||
* @par Inputs:
|
||||
* Thress inputs, including:
|
||||
* @li grad: A tensor. Must be one of the following types:
|
||||
* float16, float32. \n
|
||||
* @li x: A tensor. Must be one of the following types:
|
||||
* float16, float32. \n
|
||||
* @li pdist: Output tensor of cdist forward.
|
||||
* Must be one of the following types: float16, float32. \n
|
||||
|
||||
* @par Attributes:
|
||||
* p: An optional float.Defaults to 2. \n
|
||||
|
||||
* @par Outputs:
|
||||
* y: A Tensor with the same type and shape of x's. \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the Pytorch operator Pdist Backward. \n
|
||||
*/
|
||||
REG_CUST_OP(PdistGrad)
|
||||
.INPUT(y_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.INPUT(pdist, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.OUTPUT(x_grad, TensorType({DT_FLOAT16, DT_FLOAT}))
|
||||
.ATTR(p, Float, 2.0)
|
||||
.CUST_OP_END_FACTORY_REG(PdistGrad)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_SEGMENT_MEAN_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_SEGMENT_MEAN_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief: Computes the maximum along segments of a tensor.
|
||||
* Computes a tensor such that output[i]=(data[i]) where max is over j such that segment_ids[j] == i.
|
||||
* If the max is empty for a given segment ID i, output[i] = 0
|
||||
|
||||
* @par Inputs:
|
||||
* Two inputs, include:
|
||||
* @li x:A Tensor of type float16, float32, int32,int8,uint8.
|
||||
* @li segment_ids:should be the size of the first dimension
|
||||
must sorted and need not cover all values in the full range of valid values
|
||||
must be positive intege
|
||||
|
||||
* @par Outputs:
|
||||
* y:A Tensor with same type as "x" . \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator SegmentMean.
|
||||
*/
|
||||
REG_CUST_OP(SegmentMean)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(segment_ids, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.CUST_OP_END_FACTORY_REG(SegmentMean)
|
||||
} // namespace ge
|
||||
#endif
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMIZE_OP_PROTO_INC_SEGMENT_MIN_OP_H
|
||||
#define CUSTOMIZE_OP_PROTO_INC_SEGMENT_MIN_OP_H
|
||||
|
||||
#include "op_proto_macro.h"
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @brief: Computes the minimum along segments of a tensor.
|
||||
* Computes a tensor such that output[i]=(data[i]) where max is over j such that segment_ids[j] == i.
|
||||
* If the min is empty for a given segment ID i, output[i] = 0
|
||||
|
||||
* @par Inputs:
|
||||
* Two inputs, include:
|
||||
* @li x:A Tensor of type float16, float32, int32,int8,uint8.
|
||||
* @li segment_ids:should be the size of the first dimension
|
||||
must sorted and need not cover all values in the full range of valid values
|
||||
must be positive intege
|
||||
|
||||
* @par Outputs:
|
||||
* y:A Tensor with same type as "x" . \n
|
||||
|
||||
* @par Third-party framework compatibility
|
||||
* Compatible with the TensorFlow operator SegmentMin.
|
||||
*/
|
||||
|
||||
REG_CUST_OP(SegmentMin)
|
||||
.INPUT(x, TensorType::RealNumberType())
|
||||
.INPUT(segment_ids, TensorType::IndexNumberType())
|
||||
.OUTPUT(y, TensorType::RealNumberType())
|
||||
.CUST_OP_END_FACTORY_REG(SegmentMin)
|
||||
} // namespace ge
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue