constexpr const int pool_size = 3;const float32x4_t top_data = vld1q_f32(reinterpret_cast<const float *>(input_top_ptr + input.offset())); const float32x4_t middle_data = vld1q_f32(reinterpret_cast<const float *>(input_middle_ptr + input.offset())); const float32x4_t bottom_data = vld1q_f32(reinterpret_cast<const float *>(input_bottom_ptr + input.offset())); float32x2_t res = {}; if(pooling_type == PoolingType::AVG) { // Calculate scale float scale = calculate_avg_scale(id, pool_size, upper_bound_w, upper_bound_h, pool_pad_x, pool_pad_y, pool_stride_x, pool_stride_y); const float32x2_t scale_v = vdup_n_f32(scale); // Perform pooling const float32x4_t sum_data = vaddq_f32(vaddq_f32(top_data, bottom_data), middle_data); res = vpadd_f32(vget_high_f32(vsetq_lane_f32(0.f, sum_data, 3)), vget_low_f32(sum_data)); res = vmul_f32(vpadd_f32(res, res), scale_v);//得到4個最大的float } else { const float32x4_t max_data = vmaxq_f32(vmaxq_f32(top_data, bottom_data), middle_data); res = vpmax_f32(vget_high_f32(vsetq_lane_f32(-std::numeric_limits<float>::max(), max_data, 3)), vget_low_f32(max_data)); res = vpmax_f32(res, res); } *(reinterpret_cast<float *>(output.ptr())) = vget_lane_f32(res, 0);
3x3的池化 先分別讀取三列
因為是3x3的核,所以只需要比較前三個數
vsetq_lane_f32(-std::numeric_limits<float>::max(), max_data, 3)
這個函數是將max_data的第四個數置為最小值,
vget_high_f32和vget_low_f32是將max_data分為兩部分,然後分別計算最大值,結果是float32x2_t類型
vpmax_f32比較得到最後的最大值
vget_lane_f32(res, 0);擷取res地址為0的值