parent
3bfcf8947c
commit
ae389ae1f9
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2020 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 MINDSPORE_LITE_NNACL_FP32_GRAD_CONVOLUTION_GRAD_FILTER_H_
|
||||
#define MINDSPORE_LITE_NNACL_FP32_GRAD_CONVOLUTION_GRAD_FILTER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "nnacl/conv_parameter.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ConvDwFilterGrad(const float *x, const float *dy, float *dw, int start, int count, const ConvParameter *conv_param);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MINDSPORE_LITE_NNACL_FP32_GRAD_CONVOLUTION_GRAD_FILTER_H_
|
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright 2019 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 "nnacl/fp32_grad/strided_slice_grad.h"
|
||||
#include "nnacl/errorcode.h"
|
||||
|
||||
static size_t CalcIndex(const int *shape, size_t size, int i, size_t pos) {
|
||||
size_t res = 1;
|
||||
for (size_t j = 0; j < size; j++) {
|
||||
res *= shape[(i + 1) + j];
|
||||
}
|
||||
return (pos / res % shape[i]);
|
||||
}
|
||||
|
||||
int DoStridedSliceGrad(const float *inputs, float *output, const int *dx_shape, StridedSliceParameter *param) {
|
||||
if (inputs == NULL || output == NULL || param == NULL) {
|
||||
return NNACL_NULL_PTR;
|
||||
}
|
||||
if (param->num_axes_ > DIMENSION_7D) {
|
||||
return NNACL_PARAM_INVALID;
|
||||
}
|
||||
|
||||
size_t size = 1;
|
||||
int *s = param->strides_;
|
||||
int *b = param->begins_;
|
||||
for (int i = 0; i < DIMENSION_7D; i++) {
|
||||
size *= param->in_shape_[i];
|
||||
}
|
||||
|
||||
for (size_t pos = 0; pos < size; pos++) {
|
||||
size_t i = CalcIndex(param->in_shape_, 6, 0, pos);
|
||||
size_t j = CalcIndex(param->in_shape_, 5, 1, pos);
|
||||
size_t k = CalcIndex(param->in_shape_, 4, 2, pos);
|
||||
size_t l = CalcIndex(param->in_shape_, 3, 3, pos);
|
||||
size_t m = CalcIndex(param->in_shape_, 2, 4, pos);
|
||||
size_t n = CalcIndex(param->in_shape_, 1, 5, pos);
|
||||
size_t o = CalcIndex(param->in_shape_, 0, 6, pos);
|
||||
|
||||
size_t input_idx =
|
||||
(i * s[0] + b[0]) * dx_shape[1] * dx_shape[2] * dx_shape[3] * dx_shape[4] * dx_shape[5] * dx_shape[6] +
|
||||
(j * s[1] + b[1]) * dx_shape[2] * dx_shape[3] * dx_shape[4] * dx_shape[5] * dx_shape[6] +
|
||||
(k * s[2] + b[2]) * dx_shape[3] * dx_shape[4] * dx_shape[5] * dx_shape[6] +
|
||||
(l * s[3] + b[3]) * dx_shape[4] * dx_shape[5] * dx_shape[6] + (m * s[4] + b[4]) * dx_shape[5] * dx_shape[6] +
|
||||
(n * s[5] + b[5]) * dx_shape[6] + (o * s[6] + b[6]);
|
||||
output[input_idx] = inputs[pos];
|
||||
}
|
||||
return NNACL_OK;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright 2020 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 MINDSPORE_LITE_NNACL_FP32_GRAD_STRIDED_SLICE_GRAD_H_
|
||||
#define MINDSPORE_LITE_NNACL_FP32_GRAD_STRIDED_SLICE_GRAD_H_
|
||||
|
||||
#include "nnacl/op_base.h"
|
||||
#include "nnacl/strided_slice_parameter.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int DoStridedSliceGrad(const float *inputs, float *output, const int *dx_shape, StridedSliceParameter *param);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MINDSPORE_LITE_NNACL_FP32_GRAD_STRIDED_SLICE_GRAD_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright 2019-2020 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 MINDSPORE_LITE_SRC_OPS_STRIDED_SLICE_GRAD_H_
|
||||
#define MINDSPORE_LITE_SRC_OPS_STRIDED_SLICE_GRAD_H_
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
#include "src/ops/strided_slice.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class StridedSliceGrad : public StridedSlice {
|
||||
public:
|
||||
StridedSliceGrad() = default;
|
||||
~StridedSliceGrad() = default;
|
||||
#ifdef PRIMITIVE_WRITEABLE
|
||||
MS_DECLARE_PARENT(StridedSliceGrad, StridedSlice);
|
||||
explicit StridedSliceGrad(schema::PrimitiveT *primitive) : StridedSlice(primitive) {}
|
||||
void SetBeginMask(int begin_mask);
|
||||
void SetEndMask(int end_mask);
|
||||
void SetEllipsisMask(int ellipsis_mask);
|
||||
void SetNewAxisMask(int new_axis_mask);
|
||||
void SetShrinkAxisMask(int shrink_axis_mask);
|
||||
void SetBegin(const std::vector<int> &begin);
|
||||
void SetEnd(const std::vector<int> &end);
|
||||
void SetStride(const std::vector<int> &stride);
|
||||
void SetIsScale(const std::vector<int> &is_scale);
|
||||
int UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inputs);
|
||||
#else
|
||||
int UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) override;
|
||||
#endif
|
||||
int InferShape(std::vector<lite::Tensor *> inputs_, std::vector<lite::Tensor *> outputs_) override;
|
||||
// bool CheckInputs(std::vector<lite::Tensor *> inputs_);
|
||||
int GetBeginMask() const;
|
||||
int GetEndMask() const;
|
||||
int GetEllipsisMask() const;
|
||||
int GetNewAxisMask() const;
|
||||
int GetShrinkAxisMask() const;
|
||||
std::vector<int> GetBegin() const;
|
||||
std::vector<int> GetEnd() const;
|
||||
std::vector<int> GetStride() const;
|
||||
std::vector<int> GetIsScale() const;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_OPS_STRIDED_SLICE_GRAD_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue