From bdd525bcd0486fca54a03e4dc1559d5835febecc Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Sat, 11 Nov 2023 09:09:14 +0300 Subject: [PATCH] Merge pull request #24510 from asmorkalov:as/softmax_rvv Enable softmax layer vectorization on RISC-V RVV #24510 Related: https://github.com/opencv/opencv/pull/24466 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/dnn/src/layers/cpu_kernels/softmax.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/dnn/src/layers/cpu_kernels/softmax.cpp b/modules/dnn/src/layers/cpu_kernels/softmax.cpp index 15e50f17bdfa..eb258ecfa210 100644 --- a/modules/dnn/src/layers/cpu_kernels/softmax.cpp +++ b/modules/dnn/src/layers/cpu_kernels/softmax.cpp @@ -35,7 +35,7 @@ void softmax(Mat &dst, const Mat &src, int axis, int axisBias, int axisStep){ // make the channel axis to be multiple of 8 size_t channelAxis = (axisStep + 7) & -8; -#if CV_SIMD +#if (CV_SIMD || CV_SIMD_SCALABLE) const int nlanes = VTraits::vlanes(); // the number of redundant dimension size_t redundantDim = nlanes - axisStep % nlanes; @@ -54,7 +54,7 @@ void softmax(Mat &dst, const Mat &src, int axis, int axisBias, int axisStep){ axisBuf[cnDim] = srcPtr[srcOffset + (cnDim + axisBias) * cnStep]; float s = 0.f; -#if CV_SIMD +#if (CV_SIMD || CV_SIMD_SCALABLE) // make the value of the redundant dimension to be -FLT_MAX if (redundantDim != nlanes) { for (size_t j = axisStep; j < axisStep + redundantDim; j++) @@ -121,7 +121,7 @@ void softmax(Mat &dst, const Mat &src, int axis, int axisBias, int axisStep){ s = v_reduce_sum(vs); // subtract the value of the redundant dimension if (redundantDim != nlanes) { - float* _val = new float[nlanes]; + float _val[VTraits::max_nlanes]; v_store(_val, val); for (size_t j = nlanes - redundantDim; j < nlanes; j++) s -= _val[j];