forked from mindspore-Ecosystem/mindspore
update code format
This commit is contained in:
parent
406728025e
commit
0922af6400
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/rank_cpu_kernel.h"
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
|
@ -84,7 +84,7 @@ template <typename T>
|
|||
void RankCpuKernel<T>::SetFunc() {
|
||||
switch (method_) {
|
||||
case Method::Max: {
|
||||
func_ = [](size_t i, int duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
func_ = [](size_t i, size_t duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
const size_t *const sort_idx, float *const output_addr) {
|
||||
for (size_t j = i - duplicate_count + 1; j < i + 1; ++j) {
|
||||
output_addr[axisIterator.GetPos(sort_idx[j])] = i + 1;
|
||||
|
@ -92,7 +92,7 @@ void RankCpuKernel<T>::SetFunc() {
|
|||
};
|
||||
} break;
|
||||
case Method::Min: {
|
||||
func_ = [](size_t i, int duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
func_ = [](size_t i, size_t duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
const size_t *const sort_idx, float *const output_addr) {
|
||||
for (size_t j = i - duplicate_count + 1; j < i + 1; ++j) {
|
||||
output_addr[axisIterator.GetPos(sort_idx[j])] = i - duplicate_count + 2;
|
||||
|
@ -106,7 +106,7 @@ void RankCpuKernel<T>::SetFunc() {
|
|||
// rank_sum = sum + duplicate_count = duplicate_count * (2 * i -
|
||||
// duplicate_count + 3) / 2 avg = rank_sum / duplicate_count = (2 * i -
|
||||
// duplicate_count + 3) / 2
|
||||
func_ = [](size_t i, int duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
func_ = [](size_t i, size_t duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
const size_t *const sort_idx, float *const output_addr) {
|
||||
float avg = (2 * i - duplicate_count + 3) / 2.0;
|
||||
for (size_t j = i - duplicate_count + 1; j < i + 1; ++j) {
|
||||
|
@ -115,7 +115,7 @@ void RankCpuKernel<T>::SetFunc() {
|
|||
};
|
||||
} break;
|
||||
case Method::First: {
|
||||
func_ = [](size_t i, int duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
func_ = [](size_t i, size_t duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
const size_t *const sort_idx, float *const output_addr) {
|
||||
for (size_t j = i - duplicate_count + 1; j < i + 1; ++j) {
|
||||
output_addr[axisIterator.GetPos(sort_idx[j])] = j + 1;
|
||||
|
@ -123,7 +123,7 @@ void RankCpuKernel<T>::SetFunc() {
|
|||
};
|
||||
} break;
|
||||
case Method::Dense: {
|
||||
func_ = [](size_t i, int duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
func_ = [](size_t i, size_t duplicate_count, int culmutive_rank, const AxisIterator &axisIterator,
|
||||
const size_t *const sort_idx, float *const output_addr) {
|
||||
for (size_t j = i - duplicate_count + 1; j < i + 1; ++j) {
|
||||
output_addr[axisIterator.GetPos(sort_idx[j])] = culmutive_rank;
|
||||
|
@ -149,7 +149,7 @@ void RankCpuKernel<T>::Launch1D(const T *input_addr, size_t *sort_idx, T *values
|
|||
SortIndex(sort_idx, values, iter);
|
||||
|
||||
int culmutive_rank = 1;
|
||||
int duplicate_count = 0;
|
||||
size_t duplicate_count = 0;
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
duplicate_count++;
|
||||
|
@ -201,7 +201,7 @@ void RankCpuKernel<T>::Launch1D(const T *input_addr, size_t *sort_idx, T *values
|
|||
SortIndex(sort_idx, values, iter);
|
||||
|
||||
int culmutive_rank = 1;
|
||||
int duplicate_count = 0;
|
||||
size_t duplicate_count = 0;
|
||||
int nans_count = 0;
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
|
|
|
@ -48,7 +48,6 @@ class RankCpuKernel : public CPUKernel {
|
|||
~RankCpuKernel() override = default;
|
||||
|
||||
void InitKernel(const CNodePtr &kernel_node) override;
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
void SetFunc();
|
||||
|
||||
|
@ -59,6 +58,9 @@ class RankCpuKernel : public CPUKernel {
|
|||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &outputs) override;
|
||||
|
||||
protected:
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
private:
|
||||
inline void SortIndex(size_t *sort_idx, const T *values, const AxisIterator &iter) const {
|
||||
std::iota(sort_idx, sort_idx + iter.AxisSize(), 0);
|
||||
|
@ -84,7 +86,7 @@ class RankCpuKernel : public CPUKernel {
|
|||
// parameters
|
||||
size_t axis_{0};
|
||||
rank::Method method_{rank::MethodNotDefined};
|
||||
std::function<void(size_t, int, int, const AxisIterator &, const size_t *const, float *const)> func_;
|
||||
std::function<void(size_t, size_t, int, const AxisIterator &, const size_t *const, float *const)> func_;
|
||||
rank::NaOption option_{rank::OptionNotDefined};
|
||||
bool ascending_{true};
|
||||
bool pct_{false};
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/rolling_cpu_kernel.h"
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include "common/thread_pool.h"
|
||||
|
||||
namespace mindspore {
|
||||
|
|
|
@ -41,11 +41,13 @@ class RollingCpuKernel : public CPUKernel {
|
|||
~RollingCpuKernel() override = default;
|
||||
|
||||
void InitKernel(const CNodePtr &kernel_node) override;
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &outputs) override;
|
||||
|
||||
protected:
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
private:
|
||||
void RollingBoundsCalculate();
|
||||
void MethodSwitch();
|
||||
|
|
|
@ -65,7 +65,7 @@ void ShiftCpuKernel<T>::InitKernel(const CNodePtr &kernel_node) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool ShiftCpuKernel<T>::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
bool ShiftCpuKernel<T>::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> & /* workspace */,
|
||||
const std::vector<AddressPtr> &outputs) {
|
||||
if (inputs.size() != 2) {
|
||||
MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the number of inputs should be 2, but got " << inputs.size()
|
||||
|
@ -103,7 +103,7 @@ bool ShiftCpuKernel<T>::Launch(const std::vector<AddressPtr> &inputs, const std:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (inputs[0]->size != outer_size * axis_size * inner_size * sizeof(T)) {
|
||||
if (inputs[0]->size != LongToSize(outer_size * axis_size * inner_size) * sizeof(T)) {
|
||||
MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the memory size of inputs error.";
|
||||
}
|
||||
|
||||
|
@ -119,16 +119,16 @@ bool ShiftCpuKernel<T>::Launch(const std::vector<AddressPtr> &inputs, const std:
|
|||
|
||||
// normal procedure
|
||||
std::vector<common::Task> tasks;
|
||||
tasks.reserve(outer_size);
|
||||
tasks.reserve(LongToSize(outer_size));
|
||||
for (int i = 0; i < outer_size; ++i) {
|
||||
(void)tasks.emplace_back([this, i, fill_value, axis_size, inner_size, input, output, outputs] {
|
||||
size_t offset = i * axis_size * inner_size;
|
||||
size_t input_offset = offset + copy_src_begin_ * inner_size;
|
||||
size_t output_offset = offset + copy_dst_begin_ * inner_size;
|
||||
size_t offset = LongToSize(i * axis_size * inner_size);
|
||||
size_t input_offset = offset + LongToSize(copy_src_begin_ * inner_size);
|
||||
size_t output_offset = offset + LongToSize(copy_dst_begin_ * inner_size);
|
||||
size_t copy_size = copy_size_ * inner_size * sizeof(T);
|
||||
size_t dst_max_size = outputs[0]->size - output_offset;
|
||||
(void)memcpy_s(output + output_offset, dst_max_size, input + input_offset, copy_size);
|
||||
size_t fill_offset = offset + fill_begin_ * inner_size;
|
||||
size_t fill_offset = offset + LongToSize(fill_begin_ * inner_size);
|
||||
(void)std::fill_n(output + fill_offset, fill_size_ * inner_size, fill_value);
|
||||
return common::SUCCESS;
|
||||
});
|
||||
|
|
|
@ -105,7 +105,7 @@ bool SortCpuKernel<T>::Launch(const std::vector<AddressPtr> &inputs, const std::
|
|||
|
||||
for (size_t k = 0; k < iter.AxisSize(); ++k) {
|
||||
const auto index = iter.GetPos(k);
|
||||
indices[index] = iter.RevertPos(idx[k]);
|
||||
indices[index] = SizeToInt(iter.RevertPos(idx[k]));
|
||||
output[index] = input[idx[k]];
|
||||
}
|
||||
return common::SUCCESS;
|
||||
|
|
|
@ -29,11 +29,13 @@ class SortCpuKernel : public CPUKernel {
|
|||
~SortCpuKernel() = default;
|
||||
|
||||
void InitKernel(const CNodePtr &kernel_node) override;
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &outputs) override;
|
||||
|
||||
protected:
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
private:
|
||||
AxisIterator axisIterator_{};
|
||||
bool descending_{false};
|
||||
|
|
|
@ -30,10 +30,13 @@ class TopKCPUKernel : public CPUKernel {
|
|||
TopKCPUKernel() = default;
|
||||
~TopKCPUKernel() override = default;
|
||||
void InitKernel(const CNodePtr &kernel_node) override;
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspaces,
|
||||
const std::vector<AddressPtr> &outputs) override;
|
||||
|
||||
protected:
|
||||
void InitInputOutputSize(const CNodePtr &kernel_node) override;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void LaunchKernel(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspaces,
|
||||
|
|
Loading…
Reference in New Issue