NEON 3x3 max pool範例程式碼

來源:互聯網
上載者:User

       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的值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.