arm_compute v17.04
diff --git a/src/runtime/NEON/functions/NESoftmaxLayer.cpp b/src/runtime/NEON/functions/NESoftmaxLayer.cpp
index 3949529..55d4d3a 100644
--- a/src/runtime/NEON/functions/NESoftmaxLayer.cpp
+++ b/src/runtime/NEON/functions/NESoftmaxLayer.cpp
@@ -32,7 +32,7 @@
using namespace arm_compute;
NESoftmaxLayer::NESoftmaxLayer()
- : _max_kernel(), _shift_exp_sum_kernel(), _norm_kernel(), _fill_border_kernel(), _max(), _sum(), _tmp()
+ : _max_kernel(), _shift_exp_sum_kernel(), _norm_kernel(), _fill_border_kernel(), _fill_border_kernel_sum(), _max(), _sum(), _tmp()
{
}
@@ -42,31 +42,34 @@
ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::F32);
// Create intermediate tensors shapes
- TensorInfo tensor_info_tmp(input->info()->tensor_shape(), input->info()->num_channels(), input->info()->data_type());
- tensor_info_tmp.auto_padding();
- _tmp.allocator()->init(tensor_info_tmp);
- _tmp.allocator()->allocate();
+ _tmp.allocator()->init(TensorInfo(input->info()->tensor_shape(), input->info()->num_channels(), input->info()->data_type()));
TensorShape shape = input->info()->tensor_shape();
shape.set(0, 1);
TensorInfo tensor_info_max_sum(shape, input->info()->num_channels(), input->info()->data_type());
- tensor_info_max_sum.auto_padding();
_max.allocator()->init(tensor_info_max_sum);
- _max.allocator()->allocate();
_sum.allocator()->init(tensor_info_max_sum);
- _sum.allocator()->allocate();
// Configure Kernels
- _fill_border_kernel.configure(input, 3, BorderMode::CONSTANT, PixelValue(-FLT_MAX));
_max_kernel.configure(input, &_max);
_shift_exp_sum_kernel.configure(input, &_max, &_tmp, &_sum);
_norm_kernel.configure(&_tmp, &_sum, output);
+ _fill_border_kernel.configure(input, _max_kernel.border_size(), BorderMode::CONSTANT, PixelValue(-FLT_MAX));
+ // Fill the border around tmp buffer with sensible negative value.
+ // This avoids exp(-FLT_MAX) which will lead to -inf and destroy the calculation of sum when input is not a multiple of processed elements
+ _fill_border_kernel_sum.configure(input, _shift_exp_sum_kernel.border_size(), BorderMode::CONSTANT, PixelValue(-50.f));
+
+ // Allocate intermediate tensors
+ _tmp.allocator()->allocate();
+ _max.allocator()->allocate();
+ _sum.allocator()->allocate();
}
void NESoftmaxLayer::run()
{
NEScheduler::get().multithread(&_fill_border_kernel);
NEScheduler::get().multithread(&_max_kernel);
+ NEScheduler::get().multithread(&_fill_border_kernel_sum);
NEScheduler::get().multithread(&_shift_exp_sum_kernel);
NEScheduler::get().multithread(&_norm_kernel);
}