Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lite/backends/arm/math/fp16/common_preprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,26 @@ typedef __fp16 float16_t;
inline void act_acquire(lite_api::ActivationType act,
int &flag_act, // NOLINT
float &local_alpha, // NOLINT
float six,
float alpha) {
float &offset, // NOLINT
float &threshold, // NOLINT
const operators::ActivationParam act_param) {
switch (act) {
case lite_api::ActivationType::kRelu:
flag_act = 0x01;
break;
case lite_api::ActivationType::kRelu6:
flag_act = 0x02;
local_alpha = six;
local_alpha = act_param.Relu_clipped_coef;
break;
case lite_api::ActivationType::kLeakyRelu:
flag_act = 0x03;
local_alpha = alpha;
local_alpha = act_param.Leaky_relu_alpha;
break;
case lite_api::ActivationType::kHardSwish:
flag_act = 0x04;
local_alpha = 1.0 / act_param.hard_swish_scale;
offset = act_param.hard_swish_offset;
threshold = act_param.hard_swish_threshold;
break;
default:
break;
Expand Down
32 changes: 18 additions & 14 deletions lite/backends/arm/math/fp16/conv3x3_winograd_fp16.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ void conv_compute_2x2_3x3_fp16(const float16_t* input,
auto act_type = act_param.active_type;
float local_alpha = 0.f;
int flag_act = 0x00; // relu: 1, relu6: 2, leakey: 3
float offset = 0.f;
float threshold = 6.f;

if (act_param.has_active) {
act_acquire(act_type,
flag_act,
local_alpha,
act_param.Relu_clipped_coef,
act_param.Leaky_relu_alpha);
act_acquire(act_type, flag_act, local_alpha, offset, threshold, act_param);
}

// begin compute
Expand Down Expand Up @@ -265,7 +263,9 @@ void conv_compute_2x2_3x3_fp16(const float16_t* input,
flag_act,
local_alpha,
bias + ci * 8,
flag_bias);
flag_bias,
offset,
threshold);
}
} else {
for (int ci = 0; ci < oc_8; ++ci) {
Expand Down Expand Up @@ -299,7 +299,9 @@ void conv_compute_2x2_3x3_fp16(const float16_t* input,
flag_act,
local_alpha,
bias + ci * 8,
flag_bias);
flag_bias,
offset,
threshold);
}
}
}
Expand Down Expand Up @@ -373,13 +375,11 @@ void conv_compute_4x4_3x3_fp16(const float16_t* input,
float local_alpha = 0.f;
bool flag_bias = (bias != nullptr);
int flag_act = 0x00; // relu: 1, relu6: 2, leakey: 3
float offset = 0.f;
float threshold = 6.f;

if (act_param.has_active) {
act_acquire(act_type,
flag_act,
local_alpha,
act_param.Relu_clipped_coef,
act_param.Leaky_relu_alpha);
act_acquire(act_type, flag_act, local_alpha, offset, threshold, act_param);
}

// begin compute
Expand Down Expand Up @@ -543,7 +543,9 @@ void conv_compute_4x4_3x3_fp16(const float16_t* input,
flag_act,
local_alpha,
bias + ci * 8,
flag_bias);
flag_bias,
offset,
threshold);
}
} else {
for (int ci = 0; ci < oc_8; ++ci) {
Expand Down Expand Up @@ -583,7 +585,9 @@ void conv_compute_4x4_3x3_fp16(const float16_t* input,
flag_act,
local_alpha,
bias + ci * 8,
flag_bias);
flag_bias,
offset,
threshold);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions lite/backends/arm/math/fp16/conv3x3s1_direct_fp16.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,11 @@ void conv_3x3s1_direct_fp16(const float16_t* i_data,
float alpha = 0.f;
int flag_act = 0x00; // relu: 1, relu6: 2, leakey: 3

float offset = 0.f;
float threshold = 6.f;

if (act_param.has_active) {
act_acquire(act_type,
flag_act,
alpha,
act_param.Relu_clipped_coef,
act_param.Leaky_relu_alpha);
act_acquire(act_type, flag_act, alpha, offset, threshold, act_param);
}

for (int n = 0; n < bs; ++n) {
Expand Down Expand Up @@ -617,7 +616,9 @@ void conv_3x3s1_direct_fp16(const float16_t* i_data,
flag_act,
alpha,
bias_ptr,
flag_bias);
flag_bias,
offset,
threshold);
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions lite/backends/arm/math/fp16/conv3x3s2_direct_fp16.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,16 +626,13 @@ void conv_3x3s2_direct_fp16(const float16_t* i_data,
auto act_type = act_param.active_type;
bool flag_bias = param.bias != nullptr;
float alpha = 0.f;
int flag_act = 0x00; // relu: 1, relu6: 2, leakey: 3
int flag_act = 0x00; // relu: 1, relu6: 2, leakey: 3 hardswish:4
float offset = 0.f;
float threshold = 6.f;

if (act_param.has_active) {
act_acquire(act_type,
flag_act,
alpha,
act_param.Relu_clipped_coef,
act_param.Leaky_relu_alpha);
act_acquire(act_type, flag_act, alpha, offset, threshold, act_param);
}

for (int n = 0; n < bs; ++n) {
const float16_t* din_batch = i_data + n * ic * size_in_channel;
float16_t* dout_batch = o_data + n * oc * size_out_channel;
Expand Down Expand Up @@ -734,7 +731,9 @@ void conv_3x3s2_direct_fp16(const float16_t* i_data,
flag_act,
alpha,
bias_ptr,
flag_bias);
flag_bias,
offset,
threshold);
}
}
}
Expand Down Expand Up @@ -787,14 +786,12 @@ void conv_3x3s2_direct_fp16_c3(const float16_t* i_data,
auto act_type = act_param.active_type;
bool flag_bias = param.bias != nullptr;
float alpha = 0.f;
int flag_act = 0x00; // relu: 1, relu6: 2, leakey: 3
int flag_act = 0x00;
float offset = 0.f;
float threshold = 6.f;

if (act_param.has_active) {
act_acquire(act_type,
flag_act,
alpha,
act_param.Relu_clipped_coef,
act_param.Leaky_relu_alpha);
act_acquire(act_type, flag_act, alpha, offset, threshold, act_param);
}

for (int n = 0; n < bs; ++n) {
Expand Down Expand Up @@ -917,7 +914,9 @@ void conv_3x3s2_direct_fp16_c3(const float16_t* i_data,
flag_act,
alpha,
bias_ptr,
flag_bias);
flag_bias,
offset,
threshold);
}
}
}
Expand Down
Loading