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
pull/24527/head
Alexander Smorkalov 1 year ago committed by GitHub
parent 53f2131681
commit 960a926055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      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<v_float32>::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<v_float32>::max_nlanes];
v_store(_val, val);
for (size_t j = nlanes - redundantDim; j < nlanes; j++)
s -= _val[j];

Loading…
Cancel
Save