Merge pull request #28750 from abhishek-gola:activation_fusion

Extended fusion for activation functions in new DNN engine #28750

After this fusion, we see following improvements in YOLO models:

| Model | Before (`ENGINE_NEW`) | After (`ENGINE_NEW`) | `ENGINE_ORT` | % Improvement (Before v/s After) |
| :--- | :--- | :--- | :--- | :--- |
| **YOLOv8n** | 18.89  ms| 12.06 ms| 12.15 ms| 36.16% |
| **YOLOv5n** | 17.12  ms| 9.29 ms| 9.23 ms| 45.73% |
| **YOLOX-S** | 38.78  ms| 25.56 ms| 25.16 ms| 34.09% |

Device details: 
      - Model name: Intel(R) Core(TM) i9-14900KS, x86, 32 Cores, ubuntu 24.04,
### 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.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Abhishek Gola
2026-04-14 11:38:14 +05:30
committed by GitHub
parent 53d9a67cf3
commit 3d77645a3a
13 changed files with 561 additions and 23 deletions

View File

@@ -918,6 +918,36 @@ CV__DNN_INLINE_NS_BEGIN
static Ptr<Pad2Layer> create(const LayerParams& params);
};
/* Activation function pointer type.
Used for fast, platform-optimized activation implementations.
@param input pointer to input data
@param output pointer to output data (can be same as input for in-place)
@param len number of elements
@param params activation-specific parameters (e.g., alpha, beta)
*/
typedef void (*ActivationFunc)(const void* input, void* output,
size_t len, const float* params);
/** Activation type enumeration for dispatched activation function retrieval. */
enum ActivationType {
ACTIV_NONE = 0,
ACTIV_MISH,
ACTIV_SWISH,
ACTIV_SIGMOID,
ACTIV_TANH,
ACTIV_ELU,
ACTIV_HARDSWISH,
ACTIV_HARDSIGMOID,
ACTIV_GELU,
ACTIV_GELU_APPROX,
ACTIV_RELU,
ACTIV_CLIP
};
/** Returns a platform-optimized activation function pointer for the given type.
The returned function is selected via CPU dispatch for the best available ISA. */
CV_EXPORTS ActivationFunc getActivationFunc(int activationType);
/* Activations */
class CV_EXPORTS ActivationLayer : public Layer
{
@@ -932,6 +962,13 @@ CV__DNN_INLINE_NS_BEGIN
size_t /*outPlaneSize*/, int /*cn0*/, int /*cn1*/) const {}
virtual void forwardSlice(const int8_t* /*src*/, const int8_t* /*lut*/, int8_t* /*dst*/, int /*len*/,
size_t /*outPlaneSize*/, int /*cn0*/, int /*cn1*/) const {}
/** Returns a platform-optimized activation function pointer for this layer.
@return function pointer, or nullptr if not available for the given depth
*/
virtual ActivationFunc getActivationFunc(int /*depth*/,
std::vector<float>& /*activParams*/) const
{ return nullptr; }
};
class CV_EXPORTS ReLULayer : public ActivationLayer