“1e116208e168d07d5bd1dc1c28a0ff3fe604a120”上不存在“doc/mobile/cross_compiling_for_raspberry_en.html”
提交 25f8d24c 编写于 作者: J jingqinghe

add support for three-dimentional input in reduce max test=develop

上级 d132b8f3
......@@ -47,62 +47,62 @@ void reduce_n<float>(const float* src,
}
template <>
void reduce_first_of_three<float>(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
for (int i = 0; i < second_in; i++){
for (int j = 0; j < third_in; j++){
dst[i*third_in+j] = src[i*third_in+j];
for (int k = 1; k < first_in; k++){
dst[i*third_in+j] = src[k*second_in*third_in+i*third_in+j] > dst[i*third_in+j] ? src[k*second_in*third_in+i*third_in+j] : dst[i*third_in+j];
void reduce_first_of_three<float>(
const float* src, float* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < second_in; i++) {
for (int j = 0; j < third_in; j++) {
dst[i * third_in + j] = src[i * third_in + j];
for (int k = 1; k < first_in; k++) {
dst[i * third_in + j] =
src[k * second_in * third_in + i * third_in + j] >
dst[i * third_in + j]
? src[k * second_in * third_in + i * third_in + j]
: dst[i * third_in + j];
}
}
}
}
template <>
void reduce_second_of_three<float>(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
for (int i = 0; i < first_in; i++){
for (int j = 0; j < third_in; j++){
dst[i*third_in+j] = src[i*second_in*third_in+j];
for (int k = 1; k < second_in; k++){
dst[i*third_in+j] = src[i*second_in*third_in+third_in*k+j] > dst[i*third_in+j] ? src[i*second_in*third_in+third_in*k+j] : dst[i*third_in+j];
void reduce_second_of_three<float>(
const float* src, float* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < first_in; i++) {
for (int j = 0; j < third_in; j++) {
dst[i * third_in + j] = src[i * second_in * third_in + j];
for (int k = 1; k < second_in; k++) {
dst[i * third_in + j] =
src[i * second_in * third_in + third_in * k + j] >
dst[i * third_in + j]
? src[i * second_in * third_in + third_in * k + j]
: dst[i * third_in + j];
}
}
}
}
template <>
void reduce_third_of_three<float>(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
for (int i = 0; i < first_in; i++){
for (int j = 0; j < second_in; j++){
dst[i*second_in+j] = src[i*second_in*third_in+j*second_in];
for (int k = 0; k< third_in; k++){
dst[i*second_in+j] = src[i*second_in*third_in+j*second_in+k] > dst[i*second_in+j] ? src[i*second_in*third_in+j*second_in+k] : dst[i*second_in+j];
void reduce_third_of_three<float>(
const float* src, float* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < first_in; i++) {
for (int j = 0; j < second_in; j++) {
dst[i * second_in + j] = src[i * second_in * third_in + j * second_in];
for (int k = 0; k < third_in; k++) {
dst[i * second_in + j] =
src[i * second_in * third_in + j * second_in + k] >
dst[i * second_in + j]
? src[i * second_in * third_in + j * second_in + k]
: dst[i * second_in + j];
}
}
}
}
template <>
void reduce_all_of_three<float>(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
void reduce_all_of_three<float>(
const float* src, float* dst, int first_in, int second_in, int third_in) {
float max = src[0];
int total_element = first_in * second_in * third_in;
for (int i = 0; i <total_element; i++){
for (int i = 0; i < total_element; i++) {
max = src[i] > max ? src[i] : max;
}
dst[0] = max;
......
......@@ -36,32 +36,20 @@ void reduce_c(const T* src,
int width_in);
template <typename T>
void reduce_all_of_three(const T* src,
T* dst,
int first_in,
int second_in,
int third_in);
void reduce_all_of_three(
const T* src, T* dst, int first_in, int second_in, int third_in);
template <typename T>
void reduce_first_of_three(const T* src,
T* dst,
int first_in,
int second_in,
int third_in);
void reduce_first_of_three(
const T* src, T* dst, int first_in, int second_in, int third_in);
template <typename T>
void reduce_second_of_three(const T* src,
T* dst,
int first_in,
int second_in,
int third_in);
void reduce_second_of_three(
const T* src, T* dst, int first_in, int second_in, int third_in);
template <typename T>
void reduce_third_of_three(const T* src,
T* dst,
int first_in,
int second_in,
int third_in);
void reduce_third_of_three(
const T* src, T* dst, int first_in, int second_in, int third_in);
template <typename T>
void reduce_h(const T* src,
......
......@@ -39,37 +39,33 @@ void ReduceMaxCompute::Run() {
}
}
if (x_dims.size()==3){
if (dim.size() == 0 || dim.size() == 3){
lite::arm::math::reduce_all_of_three(input, output, x_dims[0], x_dims[1], x_dims[2]);
}
else if (dim.size() == 1){
switch (dim[0])
{
if (x_dims.size() == 3) {
if (dim.size() == 0 || dim.size() == 3) {
lite::arm::math::reduce_all_of_three(
input, output, x_dims[0], x_dims[1], x_dims[2]);
} else if (dim.size() == 1) {
switch (dim[0]) {
case 0:
lite::arm::math::reduce_first_of_three(input, output, x_dims[0], x_dims[1], x_dims[2]);
lite::arm::math::reduce_first_of_three(
input, output, x_dims[0], x_dims[1], x_dims[2]);
break;
case 1:
lite::arm::math::reduce_second_of_three(input, output, x_dims[0], x_dims[1], x_dims[2]);
lite::arm::math::reduce_second_of_three(
input, output, x_dims[0], x_dims[1], x_dims[2]);
break;
case 2:
lite::arm::math::reduce_third_of_three(input, output, x_dims[0], x_dims[1], x_dims[2]);
lite::arm::math::reduce_third_of_three(
input, output, x_dims[0], x_dims[1], x_dims[2]);
break;
default:
LOG(FATAL) << "error!!!";
}
}
else if (dim.size() == 2){
}
else {
} else if (dim.size() == 2) {
} else {
LOG(FATAL) << "dim size should not larger than 3!!!";
}
}
else if (x_dims.size()==4){
} else if (x_dims.size() == 4) {
int n_in = x_dims[0];
int c_in = x_dims[1];
int h_in = x_dims[2];
......@@ -107,8 +103,9 @@ void ReduceMaxCompute::Run() {
} else {
LOG(FATAL) << "dim's size over than 2, which is not supported now!!";
}
} else {
LOG(FATAL) << "only support input with 3&4 dimensions now!!";
}
}
} // namespace arm
......
......@@ -190,71 +190,64 @@ void reduce_hw(const float* src,
reduce_w(tmp_out, dst, num_in, channel_in, 1, width_in);
}
void reduce_first_of_three(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
for (int i = 0; i < second_in; i++){
for (int j = 0; j < third_in; j++){
dst[i*third_in+j] = src[i*third_in+j];
for (int k = 1; k < first_in; k++){
dst[i*third_in+j] = src[k*second_in*third_in+i*third_in+j] > dst[i*third_in+j] ? src[k*second_in*third_in+i*third_in+j] : dst[i*third_in+j];
void reduce_first_of_three(
const float* src, float* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < second_in; i++) {
for (int j = 0; j < third_in; j++) {
dst[i * third_in + j] = src[i * third_in + j];
for (int k = 1; k < first_in; k++) {
dst[i * third_in + j] =
src[k * second_in * third_in + i * third_in + j] >
dst[i * third_in + j]
? src[k * second_in * third_in + i * third_in + j]
: dst[i * third_in + j];
}
}
}
}
void reduce_second_of_three(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
for (int i = 0; i < first_in; i++){
for (int j = 0; j < third_in; j++){
dst[i*third_in+j] = src[i*second_in*third_in+j];
for (int k = 1; k < second_in; k++){
dst[i*third_in+j] = src[i*second_in*third_in+third_in*k+j] > dst[i*third_in+j] ? src[i*second_in*third_in+third_in*k+j] : dst[i*third_in+j];
void reduce_second_of_three(
const float* src, float* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < first_in; i++) {
for (int j = 0; j < third_in; j++) {
dst[i * third_in + j] = src[i * second_in * third_in + j];
for (int k = 1; k < second_in; k++) {
dst[i * third_in + j] =
src[i * second_in * third_in + third_in * k + j] >
dst[i * third_in + j]
? src[i * second_in * third_in + third_in * k + j]
: dst[i * third_in + j];
}
}
}
}
void reduce_third_of_three(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
for (int i = 0; i < first_in; i++){
for (int j = 0; j < second_in; j++){
dst[i*second_in+j] = src[i*second_in*third_in+j*second_in];
for (int k = 0; k< third_in; k++){
dst[i*second_in+j] = src[i*second_in*third_in+j*second_in+k] > dst[i*second_in+j] ? src[i*second_in*third_in+j*second_in+k] : dst[i*second_in+j];
void reduce_third_of_three(
const float* src, float* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < first_in; i++) {
for (int j = 0; j < second_in; j++) {
dst[i * second_in + j] = src[i * second_in * third_in + j * second_in];
for (int k = 0; k < third_in; k++) {
dst[i * second_in + j] =
src[i * second_in * third_in + j * second_in + k] >
dst[i * second_in + j]
? src[i * second_in * third_in + j * second_in + k]
: dst[i * second_in + j];
}
}
}
}
void reduce_all_of_three(const float* src,
float* dst,
int first_in,
int second_in,
int third_in){
void reduce_all_of_three(
const float* src, float* dst, int first_in, int second_in, int third_in) {
float max = src[0];
int total_element = first_in * second_in * third_in;
for (int i = 0; i <total_element; i++){
for (int i = 0; i < total_element; i++) {
max = src[i] > max ? src[i] : max;
}
dst[0] = max;
}
class ReduceMaxComputeTester : public arena::TestCase {
protected:
// common attributes for this op.
......@@ -322,36 +315,35 @@ class ReduceMaxComputeTester : public arena::TestCase {
auto* out_data = out->mutable_data<float>();
if (x_dims_.size()==3){
if (dim_.size() == 0 || dim_.size() == 3){
reduce_all_of_three(x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
}
else if (dim_.size() == 1){
switch (dim_[0])
{
if (x_dims_.size() == 3) {
if (dim_.size() == 0 || dim_.size() == 3) {
reduce_all_of_three(
x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
} else if (dim_.size() == 1) {
switch (dim_[0]) {
case 0:
reduce_first_of_three(x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
reduce_first_of_three(
x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
break;
case 1:
reduce_second_of_three(x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
reduce_second_of_three(
x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
break;
case 2:
reduce_third_of_three(x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
reduce_third_of_three(
x_data, out_data, x_dims_[0], x_dims_[1], x_dims_[2]);
break;
default:
LOG(FATAL) << "error!!!";
}
}
else if (dim_.size() == 2){
} else if (dim_.size() == 2) {
LOG(FATAL) << "invalid dims_!!";
}
else {
} else {
LOG(FATAL) << "dim size should not larger than 3!!!";
}
}
else if (x_dims_.size()==4){
} else if (x_dims_.size() == 4) {
int in_n = x_dims_[0];
int in_c = x_dims_[1];
int in_h = x_dims_[2];
......@@ -386,11 +378,7 @@ class ReduceMaxComputeTester : public arena::TestCase {
LOG(FATAL) << "invalid dims_!!";
}
}
}
}
void PrepareOpDesc(cpp::OpDesc* op_desc) {
......@@ -434,16 +422,14 @@ void test_reduce_max(Place place) {
}
void test_reduce_max_for_three(Place place) {
std::vector<std::vector<int>> reduce_dim{
{0}, {1}, {2}};
std::vector<std::vector<int>> reduce_dim{{0}, {1}, {2}};
for (auto f : {1, 3}) {
for (auto s : {1, 2}) {
for (auto t : {1, 3}) {
for (bool keep_dim : {false, true}) {
for (auto dim : reduce_dim) {
auto x_dims = DDim(std::vector<int64_t>({f, s, t}));
std::unique_ptr<arena::TestCase> tester(
new ReduceMaxComputeTester(
std::unique_ptr<arena::TestCase> tester(new ReduceMaxComputeTester(
place, "def", dim, keep_dim, x_dims));
arena::Arena arena(std::move(tester), place, 2e-5);
arena.TestPrecision();
......@@ -452,8 +438,7 @@ void test_reduce_max_for_three(Place place) {
}
}
}
}
}
TEST(ReduceMax, precision) {
// #ifdef LITE_WITH_X86
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册