mirror of
https://github.com/opencv/opencv.git
synced 2026-12-03 05:33:03 -06:00
02dcf5605877a554d097175d571c5d127b0b3678
51 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
02dcf56058 |
Merge pull request #30276 from SavyaSanchi-Sharma:opti/consts
dnn: share equal constants and merge duplicate nodes in the ONNX importer - #30276 # Summary The ONNX importer now gives initializers with the same type, shape and bytes a single constant, and `parseNode()` skips a node that has the same op, attributes and inputs as an earlier one, reusing that node's outputs instead. Many exported models repeat identical work: RAFT pads the same correlation pyramid again in each of its 10 refinement iterations, and each iteration's `pads` constant has a different name, so the Pads only look identical when constants are compared by value. With this change RAFT runs 5 Pads instead of 41, as ONNX Runtime does. Custom-domain ops, random ops, nodes with subgraphs and nodes producing graph outputs are never merged. Neither are `QuantizeLinear`/`DequantizeLinear`: `fuseQDQ()` only folds a DQ into MatMul/Gemm/Conv while it has a single consumer, so merging them would switch off int8 fusion. Outputs match ONNX Runtime as closely as before. | Model | This PR | OpenCV 5.0.0 | ORT 1.30 | vs 5.0.0 | vs ORT 1.30 | |---|---:|---:|---:|---:|---:| | RAFT | 392.4 ms | 544.5 ms | 291.3 ms | 1.39× faster | 0.74× | | NAFNet | 1815.8 ms | 2157.6 ms | 1532.6 ms | 1.19× faster | 0.84× | | YOLOX | 28.3 ms | 29.8 ms | 15.1 ms | 1.05× faster | 0.53× | > Benchmarked on AMD Ryzen 9 9950X ### 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 - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] 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 |
||
|
|
4c20250a62 |
Merge pull request #29474 from SavyaSanchi-Sharma:extra_parsers
Remove Tensorflow Importer - #29474 [PR OpenCV Extra](https://github.com/opencv/opencv_extra/pull/1390) [PR OpenCV Contrib](https://github.com/opencv/opencv_contrib/pull/4171) Removed tensorflow importers ### 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 |
||
|
|
5750b9d74c |
dnn(cuda): ResNet layer coverage and cuDNN JIT conv/pooling on the new
engine |
||
|
|
38a2f1556a |
Merge pull request #29807 from SavyaSanchi-Sharma:cudnnjit_p2
dnn(cuda): move the CUDA backend to UMat device buffers - #29807 This PR is in continuation with #29658 and #30259 ### 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 - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] 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 |
||
|
|
2c6130dc03 | Merge 5.x: keep unconditional bias push, keep QKV grouping | ||
|
|
6dc5ff5c1f |
Merge pull request #30181 from abhishek-gola:onnx-conformance-fixes-5x
dnn: fix ONNX conformance failures in layers and the graph engine - #30181 Fixes wrong results found by running the ONNX backend-scoreboard conformance suite (onnx 1.23.2) against the new DNN engine. No new ops are added; these are all ops OpenCV already claims to support but computed incorrectly. Updated ONNX coverage is: `[scoreboard] passed=1740 failed=21 skipped=272 total=2033 (85.6% passed)` **Graph engine / importer** - Reshape+Reshape fusion now only fires when the outer shape is known and has no `0` entries, since a `0` copies a dim from the inner Reshape's output. - Scan slices rank-1 inputs to scalars, so scalar loop-carried state keeps rank 0. - Rank-0 tensors read from ONNX keep rank 0 instead of becoming 1x1. - When a model is refused, `setInput()` now reports the actual import failure (including unknown ops that throw early) instead of a misleading "missing blob" error. **Attention** - Softcap is applied before the bias/mask, as the spec does, so masked keys no longer leak probability. - `qk_matmul_output_mode` 1 and 2 now return the right tensors (checked against onnxruntime; the old denylist entries blaming the reference data were wrong). - Attention-25 `left_window_size` / `right_window_size` are supported, including together with `attn_mask`. - A fully masked row now gives all zeros instead of a uniform distribution. **Layers** - GRU: `direction="reverse"` is honoured. - LSTM reverse: `Y_h` / `Y_c` are taken from the correct time step. - SpaceToDepth: opset-28 `mode` (CRD / DCR) is supported. - MaxPool: `storage_order` is respected for the indices output. - OneHot: out-of-range indices produce an all-`off_value` row instead of wrapping. - Mod with `fmod=0`: no longer truncates through int (wrong for float, lossy for int64). - ReduceMax / ReduceMin on an empty bool set return the correct identity. - Swish: `alpha` is respected (CPU and OpenCL). - Quantize/DequantizeLinear: scale and zero_point may differ in shape when they're broadcast-compatible (e.g. rank-0 scale with `[1]` zero_point). - BitShift: signed integer types are supported. **Tests** - 12 conformance tests removed from the denylists, a few OpenVINO filter entries added, and new 1D layer tests for the fixes. - Full C++ conformance passes (5376/5376); `opencv_test_dnn` has no new failures compared with 5.x. ### 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 |
||
|
|
d5c8ad61fe |
dnn: faster transformer inference on CPU; accept rank > 3 Attention input
- Attention Q/K/V projection: pack each (Q/K/V, head) weight slice with MLAS and run all per-head GEMMs in one multithreaded mlasSgemmPackedBatch() call; the fastGemm loop stays as the fallback. - MLAS: split each operation into 4 tiles per thread on hybrid CPUs. - forward(): hand the private output Mats to the caller instead of copying them again. - Attention: accept [..., S, C] input (SAM3 decoder). |
||
|
|
2d8ac70091 |
dnn: return the declared half dtype from Net::forward()
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com> |
||
|
|
3303de8ae0 |
Merge pull request #30044 from sanjayk9:transform-layout-add-fusion
dnn: speed up deconvolution-heavy decoders via spatial threading and TransformLayout+Add fusion - #30044 ## Summary Two related changes to the new DNN graph engine, both exercised by the SAM2 decoder model (deep ConvTranspose2 stack with skip connections): 1. **Parallelize the deconvolution spatial loop for narrow-output layers**, which were leaving most threads idle. 2. **Fuse a following NaryEltwise Add into TransformLayout's deinterleave pass** when the Add's other operand is a same-shape, no-broadcast CONST or model input — removes one full read-modify-write pass over the tensor per fused site. **Decoder wall-clock median: 20.97ms → 13.9ms after the deconvolution threading fix (33.7% faster) → 13.37ms after the TransformLayout+Add fusion (~0.6ms faster still).** Companion data PR: opencv/opencv_extra#1415 (adds the ONNX models/data these tests load — needs to merge alongside or before this one). ## Details ### 1. Deconvolution spatial threading `deconvBlock32f` parallelised only over `N*K1` (`K1` = blocked output-channel count). A narrow-channel output — a 32-channel output is just 4 tasks — left most threads idle while each task walked the whole spatial plane serially. The kernel gathers rather than scatters (every output position writes only its own slot), so the spatial loop was already safe to split, it just wasn't. Adds `computeSpatChunks()` (shared between the forward-conv and deconv kernels) to split the spatial range into chunks whenever `N*K1` alone is too few tasks to occupy every thread, targeting `getNumThreads()*8` for load balancing; returns 1 (no-op) whenever `N*K1` already saturates the pool. ### 2. TransformLayout + Add fusion Goes through the `LayerMath`/`AdjacencyGraph`/`ChainFuser` machinery from #29656 rather than a separate one-off pass. `LayerMath` had no way to represent a second value computed live by another layer — `INPUT` is pinned to node 0, and `CONST`/`PER_CHANNEL_CONST` are both baked into a `Mat` once at fuse time, wrong for a residual whose real value only exists at `forward()` time. Adds a new `FusionEltwiseOp::TENSOR` node kind carrying an `Arg` instead of a value, opt-in per sink (`FusionOps::acceptsTensorOperands`) so an unprepared sink is never offered an expression it can't execute. `TransformLayoutLayerImpl` accepts exactly `ADD(INPUT, TENSOR)`; the fused kernel correctly handles a channel count that isn't a multiple of `C0` (partial last block) rather than assuming it can't happen. ### 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 - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] 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 |
||
|
|
f16daf1793 |
Merge pull request #29569 from Prasadayus:fix/engine_new_on_tflite
Extend TFLite importer to support more models on the new engine - #29569 Requires: https://github.com/opencv/opencv_extra/pull/1399 ### 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 |
||
|
|
c093fe7d31 |
Merge pull request #30088 from Prasadayus:unify_graph_fusion
Unified DNN graph fusion behind fuseChains - #30088 Requires: https://github.com/opencv/opencv_extra/pull/1417 ### What This PR Does Follow-up to #29656, which added the backend-agnostic chain mechanism. That PR introduced it and made pointwise fusion its first consumer; this one moves the rest of the fusion onto it. - `Net::Impl::fuseBasic()` is gone. Its conv+BatchNorm, conv+activation and conv+residual branches now go through the chain mechanism. - `fuseBN` and the six other passes now run from inside `fuseChains()`, in their existing order. - `graph_fusion_basic.cpp` keeps `fuseBN()` and `fuseInstanceNormAffine()`. - New `FusionOps::foldInputScale` folds a scale sitting before a conv directly into its weights, across the dense, depthwise, grouped and MLAS-prepacked layouts. ### Results Measured on Intel Core i9-11900K | Model | 5.x | this PR | speedup | |-----------------------------|-----------|-----------|---------| | inception_v2 | 15.04 ms | 11.80 ms | 1.27 | | efficientnet-lite4 | 14.83 ms | 12.28 ms | 1.21 | | pose_estimation_mediapipe | 5.66 ms | 5.25 ms | 1.08 | | siglip_base_patch16_224 | 143.04 ms | 135.27 ms | 1.06 | | densenet121 | 25.99 ms | 24.76 ms | 1.05 | ### 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 |
||
|
|
e6f8c94063 |
Merge pull request #30065 from SavyaSanchi-Sharma:fusion/shape
dnn: fold Shape of static-shape inputs in constFold() - #30065 When a graph input has a fully known shape, `constFold()` now replaces `Shape` ops on it with constants. The usual const-folding cascade then also removes the Gather/Concat/Cast/Slice ops that follow. **What it adds** - `graph_const_fold.cpp`: tracks known shapes and types through the graph during folding and folds `Shape` layers whose input shape is known. - `net_impl2.cpp`: once a `Shape` has been folded, `setGraphInput()` rejects an input of a different shape instead of running with stale constants. It also fixes `tryInferGraphShapes()` to report untyped const or empty inputs as `Mat().type()`. The extra folding exposed a Resize type-check failure without this fix. - `test_fusion.cpp`: two tests, one checking that no `Shape` layer remains after folding, one checking that a different input shape is rejected. **Effect on graphs** (outputs identical to 5.x) CRNN 84 → 34 layers, ViT/DeiT 361 → 274, BEiT 373 → 286, MobileViT_XS 352 → 289. **Performance** (OCV/CPU, 32 threads; median of 5 interleaved runs per side) | Model | 5.x, ms | PR, ms | Speedup | |---|---|---|---| | MobileViT_XS | 6.50 | 6.23 | 1.04x | | BEiT_Base_Patch16_224 | 30.03 | 29.23 | 1.03x | | VIT_Base_Patch16_224 | 27.17 | 26.53 | 1.02x | | DeiT_Tiny_Patch16_224 | 4.90 | 4.81 | 1.02x | | CRNN | 2.52 | 2.51 | 1.01x | | FacePaint | 328.1 | 329.5 | 1.00x | **Dependency** This depends on the upcoming CUDA integration in DNN and should be merged after it. ### 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 - [ ] 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 |
||
|
|
61127d3812 |
Merge pull request #29656 from SavyaSanchi-Sharma:backendAgnostic
Added Backend Agnostic fusion in DNN - #29656 # What This Adds A way for any layer, on any backend, to absorb trailing per-element math — with the pass knowing nothing about either layer and holding no list of op types. - **Description**: `LayerMath` (one layer's math) → `AdjacencyGraph` (hash-consed chain) - **Contract**: two `bool` virtuals on `Layer` - **CPU implementations**: three, behind that contract Pointwise fusion is the first consumer, not the point. ## The Problem ```cpp ActivationLayer* activ = dynamic_cast<ActivationLayer*>(layer_ptr); Conv2Layer* conv = getLayer<Conv2Layer>(newprog, conv_layer_idx); if (conv) conv->fuseActivation(layer); ``` Guest type, host type, method name all hardcoded in the pass. `Clip` never fused (fails the cast), `Gemm` never fused (no virtual), no 2-op chain fused at all, and no backend could fuse anything without a CPU-specific method. ## Results | Model | 5.x | this PR | speedup | |-----------------------|----------|----------|---------| | MPHand | 2.34 ms | 1.03 ms | 2.27 | | EfficientNet | 9.82 ms | 5.00 ms | 1.96 | | MPPose | 5.14 ms | 2.81 ms | 1.83 | | MobileNet_SSD_v1_ONNX | 12.58 ms | 8.38 ms | 1.50 | | BlazeFace | 0.95 ms | 0.77 ms | 1.23 | | DenseNet_121 | 20.56 ms | 19.08 ms | 1.08 | | MobileNetv2_ONNX | 2.07 ms | 1.99 ms | 1.04 | | MobileViT_XS | 6.33 ms | 6.11 ms | 1.04 | | YuNet_320 | 1.33 ms | 1.27 ms | 1.04 | | PPOCRv3 | 43.05 ms | 42.15 ms | 1.02 | | BERT | 9.78 ms | 9.68 ms | 1.01 | | BEiT_Base_Patch16_224 | 27.48 ms | 27.08 ms | 1.01 | | DeiT_Tiny_Patch16_224 | 4.74 ms | 4.72 ms | 1.01 | | MPPalm | 1.88 ms | 1.85 ms | 1.01 | | SSD | 50.19 ms | 49.82 ms | 1.01 | | YOLOv4_tiny | 7.10 ms | 7.03 ms | 1.01 | ### 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 - [ ] 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 |
||
|
|
0627765f01 |
Merge pull request #29360 from abhishek-gola:exotic_cast_operations
Support ONNX Cast/CastLike for FP8/FP4/INT4/UINT4/E8M0 dtypes - #29360 ### 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 |
||
|
|
cfe81c9388 | separated weight and shape re-initialization | ||
|
|
34c478016d |
Adapt merged 5.x Scan helpers to the LayerInfo split
# Ptr<LayerInfo> over body->prog(). # (matches sibling parseLoop/parseIf). # sliceScanAxis/stackScanAxis helpers (definition order only). |
||
|
|
58c28e1e82 | wrapper-free GpuMatND forward path | ||
|
|
12fb9a6c24 | using gpuMat instead of backend wrappers | ||
|
|
e7dc3a9a9b | added support check | ||
|
|
0843a0bb17 | fusion fix | ||
|
|
c48e3f7f3e | changed OpData to LayerInfo | ||
|
|
72ffdfc170 | cuda support and Layer Split + per-op executors | ||
|
|
0bc2636564 | fixed single output | ||
|
|
ad8056f9b0 | Support named output subset | ||
|
|
18b39f1f34 |
RVV: switch scalable universal intrinsics from LMUL=2 to LMUL=1 (#29493)
* dnn:rvv: restore the fixed block size C0 == 8
#29304 made the net-wide block size follow the RVV vector width
(defaultC0 = max(8, vlanes())), so the blocked memory layout of every tensor
depended on the host's VLEN and on the LMUL of the universal intrinsics in core.
The same model gets a different layout on a 128-, 256- or 1024-bit machine.
Restore the fixed default of 8, which is the mainstream, well-tested setting on
every platform. C0/K0 become compile-time constants again on RVV as they already
were elsewhere, so the runtime block-size plumbing and the vlanes()-based scratch
sizing are dropped, and getConvFunc_ no longer advertises block sizes the kernels
cannot handle.
The blocked kernels currently require C0 == vlanes(), which this alone does not
satisfy; the next commit removes that requirement.
* dnn:rvv: pin the vector length to the channel block
The blocked kernels assumed one channel block is exactly one vector
(C0 == vlanes()). That is not a property of the layout, it is a property of the
hardware, so the kernels only worked where the two happened to coincide: with
C0 fixed at 8 they break wherever vlanes() != 8 -- under-filling the block when
the vector is narrower (silently leaving output channels unwritten) and
overrunning it when the vector is wider (CV_Assert).
The universal intrinsics cannot express this: v_float32 is always vlanes() wide
and there is no way to make it span exactly C0 elements. So the RVV paths drop to
native intrinsics and set the vector length explicitly:
const size_t _vl = __riscv_vsetvl_e32m2(C0); // == 8 on every VLEN >= 128
LMUL=2 is required, not incidental: vlmax(e32,m2) = VLEN/32*2 >= 8 even at
VLEN=128, the narrowest RVV configuration, so _vl == C0 on every RVV 1.0 core.
One vector then spans precisely one channel block regardless of VLEN, and the
C0-vs-vlanes asserts and VLEN-dependent branches are removed rather than extended.
The existing int8 kernels already choose LMUL=2 for the same reason
(conv2_int8_kernels.simd.hpp).
This is a native per-kernel choice and is independent of the LMUL the universal
intrinsics are built with; dnn no longer reads the vector width of
intrin_rvv_scalable.hpp at all.
conv, deconv, maxpool, avgpool and depthwise use native intrinsics. batch_norm
stays portable and instead replicates the C0-wide coefficient pattern across the
vector, which keeps full lane utilisation where a fixed vl would idle most of it.
The x86/ARM paths are restored to their pre-#29304 form and are unchanged.
Tested on SpaceMIT K3 (X100 VLEN=256, A100 VLEN=1024), opencv_test_dnn: no
regressions against upstream on either core.
* core:rvv: switch scalable universal intrinsics from LMUL=2 to LMUL=1
Move the RVV universal-intrinsic types (v_uint8..v_float64) from m2 (paired
registers, 16 usable) to m1 (individual registers, 32 usable) per #29454, to
relieve register pressure in the complex kernels that rely on universal
intrinsics. Simple kernels that regress can take native RVV branches; the complex
ones cannot, so the default should suit them.
Only intrin_rvv_scalable.hpp changes. The widening/narrowing cascades and
max_nlanes are adjusted, and helpers that spell an LMUL into the intrinsic name
shift down one step (m2->m1, m1->mf2): v_popcount, v_lut (vector and f64 paths),
the f64 dot-product reduction (#27003), v_matmul, and the byte-indexed v_lut
added by #29250, whose __riscv_vluxei8_v_u8m2 no longer matches the m1 base type.
VLEN=1024 needs no change: under m1, max_nlanes = CV_RVV_MAX_VLEN/SZ equals
vlanes() at 1024, and CV_RVV_MAX_VLEN already defaults to 1024. Verified on a
1024-bit core.
Tested on SpaceMIT K3, which exposes both a 256-bit (X100) and a 1024-bit (A100)
core. opencv_test_core: 5605/5612, the 7 failures (filestorage_base64, globbing)
non-SIMD and failing identically on the m2 baseline. Perf (x-factor = m2/m1,
>1 = m1 faster), median >= 300us: core 0.966 -> 0.996 and imgproc 0.950 -> 1.038
as VLEN goes 256 -> 1024, i.e. m2's width advantage disappears once both are wide
while m1's register headroom persists. m1 wins resize (1.50/1.41), Exp (1.28),
gaussianBlur (1.23), norm (1.22), scharr (1.20); m2 still wins the light
memory-streaming kernels addWeighted (0.76), compare (0.82) and dot (0.87), which
are the natural candidates for native RVV branches.
* Revert "dnn:rvv: pin the vector length to the channel block"
This reverts commit
|
||
|
|
fe482bd575 |
Merge pull request #29577 from abhishek-gola:scan_layer
Add Scan layer to the new engine #29577 ### 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 |
||
|
|
f968fb969f |
Broadcasting element-wise engine for cv::Mat (+ cv::texpr) (#29426)
* experimental new arithmetics; work-in-progress * continue working on new-gen arithmetic expressions * * improved performance of the new add on small arrays * added sub * extended tests * fixed potential bug when adding multi-channel array and a single-channel scalar * improved const handling * * added copyMask * added mul/dev (without scale so far) * * accelerated mul * addedd scale to mul and div * * done substantial refactoring; however a few more rounds of refactoring are ahead. * added min, max, absdiff, addweighted. * improved performance of the new arithmetic functions, but some of them are still slow, e.g. operations with mask have some bugs (that affect speed, not accuracy). * * further (significantly) accelerated several functions, especially on small arrays: mul, binary ops with mask * further polished the new arithmetic engine * started integration of the new element-wise arithmetic engine into core * big step forward. We now use the new engine inside cv::add, subtract, multiply, divide, absdiff, min and max. * big progress: * added bitwise operations * fixed and accelerated compare * ported regression tests to test new broadcasting behaviour of arithmetic functions * lot's of improvements in compare, divide, addWeighted! * lot's of small and big performance improvements in the new arithmetics * * some more optimizations; parsing texpr-expressions is now faster as well * port new_arithm to Linux/x86: dispatch guards, scalar-Mat compat fallback, dnn shape-contract fixes Core: - arithm.simd.hpp: CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY guards (the file is included once per dispatched mode on x86), vx_load_expand instead of the 128-bit v_load_expand, VTraits::vlanes() instead of ::nlanes - arithm.cpp/precomp.hpp: compat fallback for scalar-like Mat operands (1x1, 1xcn/cnx1, 4x1 CV_64F - java/python tuples, operator-(Mat, Matx)): treated as a per-channel scalar ONLY when the shapes are not broadcast-compatible, so every valid numpy-style broadcast keeps its meaning and calls that would otherwise throw get the 4.x semantics DNN (fallout of the stricter shape semantics, found by the new engine): - dict.hpp: DictValue relied on fresh AutoBuffer having size()==fixed_size; allocate explicitly - batch_norm: weights_/bias_ are 1-D [n] now; 0/1-D forward runs on exact-shape 1-D views - net_impl2: extend the post-forward sanity check to non-temp outputs - a layer that reallocates its preallocated output tensor now fails loudly instead of silently detaching the result from the graph - LSTM/LSTM2 batchwise (layout=1): getMemoryShapes now matches what forward() writes (ONNX: Y=(batch,seq,dirs,hid), Yh/Yc=(batch,dirs,hid)); forward assembles seq-major results in a local buffer and transposes INTO the preallocated outputs in place Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * u8/s8 multiply: exact integer SIMD path on non-FP16 builds (3-10x vs 5.x) The unit-scale branch of vecBinaryKernel already supported a separate work-vector type Wvec1 (used by the ARM f16 build and by u16/s16 everywhere), but on x86 the u8/s8 same-type multiply still went through the f32 hub. Route it through v_uint16/v_int16: products of 8-bit values fit exactly (255^2 < 2^16), the saturating pack on store gives bit-exact results at half the vector traffic. Also fix a latent kernel bug this exposed: the unit-scale branch stepped by Wvec's lane count while loading/storing Wvec1 vectors. All previous Wvec1 instantiations had equal lane counts, but u8's v_uint16 has 2x the lanes of v_float32 - the pairs overlapped (50% redundant work) and the tail backoff could write VECSZ bytes past the row end. The branch now derives its step, offsets and tail condition from Wvec1 itself. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * vecBinaryKernel: constexpr Op::useScalar instead of a runtime-only scale check Every binary op functor now declares whether it consumes the scale scalar (params[0]): true only for mul and the two div variants. Ops that ignore it (add/sub/min/max/absdiff) take the fast 2-arg branch unconditionally - the 'scalar == 1' check used to fail for them (their params[0] is 0), sending them through the preproc branch, and the condition now folds at compile time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * restore cv::hal::mul8u as a wrapper over the element-wise engine The symbol is still declared in core/hal/hal.hpp and called directly by external code (the G-API fluid backend in opencv_contrib), but its implementation went away with the old arithm kernels. Forward it to getMulFunc(CV_8U, CV_8U) - with scale==1 it lands on the new exact integer SIMD path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * silence every new-arithm warning reported by CI (ARM64/Mac) and gcc 15 - arithm.cpp: bitwise_op_ocl and the actualScalarDepth/coerceTypes helpers are consumed only by the OpenCL paths - guard them with HAVE_OPENCL; haveScalar in cv::compare is read only inside CV_OCL_RUN - CV_UNUSED for OpenCL-less builds - arithm_expr.hpp: declare getBitwiseFunc/getNotFunc/getAddWeightedFunc next to the other per-op entry points (-Wmissing-prototypes in arithm.dispatch.cpp) - arithm.simd.hpp: define CV_SIMD_16F to 0 when FP16 SIMD is absent (-Wundef); {}-init the expandScalar staging buffers (-Wmaybe-uninitialized: they are fully written before use, but the compiler cannot prove it with runtime vector widths); rename the compare kernel's lambda parameter (-Wshadow) - arithm_expr.cpp: rename the exec tile-lambda's hot-field locals that shadowed TExpr members and outer locals (-Wshadow) - test_new_arithm_extensive.cpp: rename the name-generator lambdas' parameter shadowing the INSTANTIATE macro's own (-Wshadow), drop an unused variable Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * restore 4.x scalar semantics for the bindings' 4x1 CV_64F Scalar columns The python/java bindings materialize numbers and tuples as a 2-D 4x1 CV_64F Mat - or UMat, when the call carries UMat arguments. Three CI-reported python failures came from those pseudo-scalars reaching the engine as arrays: - absdiff(int_arr, 0): the (4,1) column is broadcast-COMPATIBLE with a 1-D array, so numpy semantics silently won - an outer-product f64 result instead of the int per-channel-scalar one; - subtract(u8 4x8x4, (40,)): same, by the rows==4 coincidence; - multiply(UMat, 2., dst=UMat): the scalar arrives as a UMAT, which the scalar detection did not recognize at all. isScalarArg now treats the exact bindings shape - 2-D 4x1 CV_64F single-channel Mat/UMat against a <=4-channel array - as a scalar UNCONDITIONALLY (a 1-D [4] array has dims==1 and still broadcasts). One exception, decided in arithm_op: when the partner is itself a tiny scalar-shaped array, both are honest data and ride the broadcast (compare(Mat 4x1, Mat 1x1) - issue #8999 - stays elementwise). Small-array discipline, this all runs per engine call: the probes read Mat/UMat fields directly (rows == 4 alone rejects almost everything, no _InputArray getter dispatch), and a UMAT scalar's 32 bytes are copied into a caller-stack buffer - no heap, no getMat mapping. Measured: no latency change on 4x4/16x16 element-wise calls. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * cv::texpr: std::string_view -> const std::string& in the public API string_view in an exported signature breaks some CUDA toolchain builds, and for short expression strings the difference is immaterial (SSO, parsed once). The parser internals keep string_view - the argument converts implicitly. Also drop the now-unused <string_view> include from cvstd.hpp, so the header does not reach every nvcc TU. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * compare boundary-rewrite: fixed 4-slot kind/bound arrays instead of AutoBuffers A CONST operand is capped at 4 channels (addConst), so the per-channel kind/bound staging needs no dynamic buffers - plain int[4]/double[4], with a CV_Assert on the contract. This is also what gcc's -Wmaybe-uninitialized was flagging (it could not see the AutoBuffer's inline storage get filled). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * element-wise engine: unary math kernels (sqrt/exp/log/sin/cos/tanh/erf/relu) + select New dispatched pair math.simd.hpp / math.dispatch.cpp - the unary/ternary sibling of arithm.simd.hpp: - vecUnaryKernel: T -> T over f16/bf16/f32/f64 on top of the intrin_math primitives (v_exp/v_log/v_sin/v_cos/v_sqrt/v_erf/v_max). f32/f64 compute natively, f16/bf16 ride the f32 hub inside the kernel (vx_load_pair_as / v_store_pair_as) - no materialized casts. Continuity collapse + the halide right-edge backoff, suppressed in-place (it would re-apply Op to already-written values). tanh = (e^2x-1)/(e^2x+1) with the input clamped to +/-10 (f32) / +/-20 (f64) - unclamped saturation hits inf/inf = NaN. erf has no f64 SIMD primitive: std::erf per lane. - selectKernel(mask, x, y): 1-byte mask expanded to lane width and tested against zero in the INTEGER domain (immune to DAZ/FTZ), branches of any depth by element size, broadcast branches supported. - emitUnary: math over a float input is T -> T now (f16 in -> f16 out, native kernel when input and result depths match); integer inputs still compute in the float domain and land in f32. - emitTernary/select: literal branches are typed via typedConstFrom (an OP_CAST of a depth-less flex const crashed); a non-1-byte mask is normalized by an explicit "mask != 0" compare, never a value cast. texpr already parsed the function names - they now execute. Tests: per-depth accuracy of all 8 ops against the double std:: reference, integer input, in-place, select over 4 depths / const branch / float mask. Perf vs the classic kernels (1920x1080 f32, 16 threads, AVX2): exp 3.7x, log 2.6x, sqrt 5.7x faster; polarToCart expressed as (r*cos(a), r*sin(a)) 4.0x. Accuracy improves too (max rel err vs f64 reference): exp 8.1e-8 vs 2.1e-7, log 8.0e-8 vs 1.5e-7. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * engine: OP_COPY_MASK folded into OP_SELECT; selectKernel moved to arithm.simd.hpp copyMask(dst, mask, src) is select(mask, src, dst) - one masking primitive instead of two. The compiler emits the masked-op tail as addInsn(OP_SELECT, mask, r, out, out): the output slot rides as both arg2 and the result, so unmasked elements are preserved by reading them back through the b-branch. OP_COPY_MASK, copyMaskKernel and getCopyMaskFunc are gone. selectKernel (moved from math.simd.hpp to arithm.simd.hpp) inherits every copyMaskKernel optimization: - the interleaved multichannel fast path (2..4 channels under a per-pixel mask: expand the mask once per VECSZ rows, v_store_interleave across lanes); - the per-row scalar path with the row-skip when the selected source row IS dst (the "leave the output untouched" half of copyMask); - plus the select-specific ones: branch broadcasts (stepx == 0) and the right-edge tail backoff under dst-aliases-a-branch - safe because re-running select over already-blended elements is idempotent; only dst == mask keeps the backoff off (the store would rewrite mask bytes before the re-read). Masked-add perf is on par with the old copyMask (1280x720, 1 thread: 8UC3 204 -> 198 us, 32FC3 1395 -> 1344, 8UC1/32FC1 within noise). Full core suite 24117 green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * engine: dedicated vectorized pow kernel (moved from arithm to math.simd.hpp) pow was the last scalar-only binary op (scalarBinaryKernel + std::pow, f32/f64 only). The new powKernel keeps exact std::pow semantics and is T x T -> T over all four float depths (f16/bf16 via the f32 hub): - scalar exponent (the dominant call shape - texpr literals ride as 0-dim broadcast consts) is dispatched PER ROW to the special cases: y==2 -> x*x, y==3 -> x*x*x, y==0.5 -> v_sqrt, y==1 -> copy, y==0 -> fill 1; - everything else - including a per-element exponent array - runs the general vectorized exp(y * log(x)) path, valid for x > 0; a vector pair containing any x <= 0 lane falls back to scalar std::pow for that pair (v_check_any), which preserves every std::pow subtlety: signed results for integer y on negative bases, NaN for fractional y, the x == 0 family; - no right-edge tail backoff: pow is not idempotent, in-place calls finish rows in the scalar tail. Perf vs the classic cv::pow (1920x1080 f32, 16 threads, AVX2): p=2 1.4x (classic special-cases it too), p=3 6.1x, p=0.5 6.3x, fractional p 4.5x with slightly better accuracy (6.1e-7 vs 7.4e-7 max rel err). Tests: exponent sweep 2/3/0.5/1/0/2.5/-1.5 vs the double std::pow reference on f32/f64, negative bases (exact signed cubes, NaN for fractional), array exponent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * powKernel: halide right-edge tail backoff in every SIMD loop Same shape as vecBinaryKernel: the final partial vector re-processes [width - VECSZ*2, width) instead of finishing scalar, suppressed when dst aliases an input (pow is not idempotent - the overlap region must be recomputed from an untouched source, which the no-alias case guarantees). Modest measured win (~2% on ROI rows for the special-cased exponents; the general path tail was already cheap - modern libm powf is fast), no regressions; mainly aligns the kernel with the house style, where every SIMD loop ends vector-wide. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix MSVC 2019 C2975: function-local constexpr as a template argument inside a lambda MSVC 2019 loses the constexpr-ness of function-local constants (LOCAL_OPS, MAX_DIMS, ...) when they are used as template arguments inside a lambda body (AutoBuffer<Slice, LOCAL_OPS> / std::array<int, MAX_DIMS> in the parallel bodies of BroadcastOp::run and TExpr::exec). Hoist them to namespace scope - no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ocl_arithm_op: route 16U multiply to the CPU engine on Apple OpenCL The Apple OpenCL driver miscompiles the 16U multiply kernel: products near the top of the u16 range come back wrapped instead of saturated (CPU vs GPU NORM_INF up to 65535 in OCL_Arithm/Mul.Mat CV_16U cases). The same arithm.cl kernel is correct on Intel NEO and NVIDIA drivers - verified not to reproduce on Linux/Intel iGPU - so gate the decline to __APPLE__ only; the CPU engine computes 16u multiply exactly (integer SIMD path). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * engine: neg/abs as compositions, clamp kernel, ** and ?: operators, abs(a-b) peephole - OP_NEG and OP_ABS need no kernels: neg = sub(0, a), abs = absdiff(a, 0) - including the engine absdiff auto-type rule (signed |a| lands in the UNSIGNED type of the same width: |SHRT_MIN| fits u16 exactly instead of saturating; NB the public cv::absdiff auto depth keeps the source type for 4.x compatibility - values agree, the depth rule is the engine own). - peephole: abs(x - y) rewrites to absdiff(x, y) ALWAYS. On integers the literal semantics differ (the subtract saturates first: u8 gives max(x-y, 0)), but whoever writes abs(a - b) means absdiff - we deliberately hand out the useful semantics instead of the saturation artifact. The just- emitted OP_SUB is retired via the moveToOutput manoeuvre, so the program shrinks to the single absdiff instruction. abs(x), abs(x - 0) and absdiff(x, 0) all give one result. - OP_CLAMP kernel (arithm.simd.hpp): v_min(v_max(x, lo), hi) over u8/s8/u16/s16/u32/s32/f32 (+f64 with 64-bit SIMD), scalar f16/bf16/64-bit ints; lo/hi may broadcast (the common clamp(img, a, b) shape) or be full arrays; the tail backoff stays on under dst-aliases-x (clamp is idempotent). emitTernary types literal bounds via typedConstFrom (same flex-const crash select had) and keeps the auto result type pinned to x. - parser: "a ** b" == pow(a, b), precedence above * /, RIGHT-associative (a ** 2 ** 3 == a ** 8); "cond ? a : b" == select(cond, a, b), precedence below everything, right-associative chains (f1 ? a : f2 ? b : c) work without parentheses. parseTernary() is the expression entry point now. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * cv::exp/log/sqrt on the engine via math_op; hal functions wrapped as engine kernels math_op is the master function of the unary math family (the arithm_op analogue): same-shape same-type output over f16/bf16/f32/f64 (classic exp/log accepted f32/f64 only - the half floats are new), two tiers: - small (<= 100000 elements) and continuous: call the kernel DIRECTLY over the flattened data - no TExpr, no broadcastOp, no parallel_for setup; - everything else: the usual single-instruction program via compile()/exec() (parallelism for large arrays, real steps for ROIs). getMathFunc routes OP_EXP/OP_LOG at f32/f64 through the full cv::hal stack - an external vendor HAL (CALL_HAL), IPP, or the built-in table kernels, whichever is installed - by wrapping hal::exp32f/exp64f/log32f/log64f as engine kernels with the function pointer in TKernel::userdata, the same mechanism castKernel uses for core BinaryFuncs. The engine adds tiling and parallelism on top, so every tier gets the best available scalar-span implementation. v_exp/v_log remain for f16/bf16 (the f32 hub) and the ops hal has no entry points for. v_log_default_32f: the degree-8 polynomial is evaluated by Estrin pairing (4 dependent levels) instead of an 8-FMA Horner chain (~5% on the f16 hub path). An exp64 Taylor-without-division rewrite was tried and benched SLOWER than the Cephes Pade scheme (the evaluation is FMA-throughput-bound, and vdivpd pipelines well enough) - reverted; a table-based reduction is the only way further there. cv::exp f32 (16 threads, AVX2+IPP build), old -> new: 640 elements 0.16 -> 0.15 us, 16k 2.79 -> 2.49, 640x480 47 -> 20, 1920x1080 452 -> 60 us (the old CPU loops were single-threaded); f64 exp 1080p 1295 -> 161 us. No size regresses; small arrays now run at installed-HAL speed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * getMathFunc: IPP tier + raw-HAL probing; the exp/log table kernels are deleted The raw cv_hal_* entry points return int for a reason: without an installed HAL they are stubs returning CV_HAL_ERROR_NOT_IMPLEMENTED. getMathFunc now selects the exp/log implementation in three tiers: 1. HAVE_IPP && ipp::useIPP(): ippsExp/ippsLn through thin int adapters (IPP is not routed through the cv_hal_ hooks, so it needs its own tier); 2. the raw cv_hal_exp32f/... hook, PROBED once with a 1-element call on the safe input 1.0 (cached in magic statics): implemented -> wrapped as an engine kernel with the function pointer in TKernel::userdata; 3. the engine own v_exp/v_log kernels. Whichever wins, the engine adds tiling and parallelism on top. The EXPTAB/LOGTAB table kernels and their tables (~790 lines in mathfuncs_core.simd.hpp + mathfuncs.cpp) are DELETED: they benched within ~15% of v_exp/v_log, not worth a second implementation. The public cv::hal::exp32f/exp64f/log32f/log64f keep their contract - CALL_HAL, then IPP, then the built-in implementation - but the built-in is now the engine vector kernel via ew::mathSpanEngine (one contiguous span, exported from math.dispatch.cpp). All unary math kernels (vec/scalar/hal wrappers, pow) also handle the vertical-broadcast tile (s0y == 0, a row expanded into a matrix): the first row is computed, the rest are memcpy of it - transcendentals cost far more than a row copy. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * texpr: hypot(x, y) binary op (alias: mag) hypot = sqrt(x^2 + y^2), NAIVE like cv::magnitude (not the overflow-safe std::hypot), computed in the float work type; kernels for the four float depths only (T x T -> T; integer inputs ride the usual f32-compute + cast). A 10-line EwHypot functor on top of vecBinaryKernel in arithm.simd.hpp - broadcast branches, continuity collapse and the tail backoff come for free. Registered in the parser as both "hypot" (the C/numpy name) and "mag" (the cv::magnitude-flavored alias). A building block for the future cartToPolar. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * texpr: atan2(y, x) binary op - radians, standard C range v_atan2 (arithm.simd.hpp, generic over the universal-intrinsic float vector): the fastAtan2 minimax polynomial from mathfuncs_core v_atan_f32 reworked to plain radians - the 180/pi factor dropped from the coefficients and the C quadrant logic instead of the [0, 360) wrap, so the result matches std::atan2 over (-pi, pi]. Measured absolute accuracy ~1.6e-4 rad. (v_atan_f32 itself is untouched - cv::phase/fastAtan2 keep their degree semantics.) EwAtan2 rides vecBinaryKernel: f16/bf16/f32 through v_atan2 (the f32 hub), f64 through exact scalar std::atan2. arg0 = y, arg1 = x, like std::atan2; float depths only, same emitBinary policy as pow/hypot. Parser name "atan2". Together with hypot this completes the cartToPolar building blocks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix the RISC-V RVV build and two ARM64 warnings The new f64 kernel registrations (hypot, pow, the unary math family) gate on CV_SIMD_64F || CV_SIMD_SCALABLE_64F, but the vx_setall_as(const double*, v_float64&) helper family in arithm.simd.hpp was still CV_SIMD_64F-only - scalable platforms (RVV) have v_float64 with CV_SIMD_64F == 0, so vecBinaryKernel<double, ...> failed to instantiate there. Widen the helper gate to match (verified with a riscv64 rv64gcv cross-build of opencv_core - the engine f64 paths now vectorize on RVV instead of not compiling). cv::exp/cv::log: the depth local is consumed by CV_OCL_RUN only - CV_UNUSED for OpenCL-less builds (ARM64 -Wunused-variable). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * silence the remaining ARM64 gcc warnings - compare boundary-rewrite: {}-init the fixed kind/bound arrays (filled for every channel used below, but gcc cannot prove it across the cn <= 4 loop); - cv::exp/log: [[maybe_unused]] on the depth local (consumed by CV_OCL_RUN only), instead of the CV_UNUSED idiom; - AutoBuffer::reserve: a targeted -Wmaybe-uninitialized suppression around the live-element copy loop - only [0, sz) is read, all written before, but gcc inlining a grow-from-inline-storage chain cannot see that. An annotation for the analyzer, no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * saturating 32-bit add/sub kernels; cv::texpr python binding; two CI warnings - v_add_sat/v_sub_sat for v_int32/v_uint32, local to arithm.simd.hpp for now (the plan is to grow them into proper universal intrinsics later): NEON single-instruction vqadd/vqsub, elsewhere the Hacker Delight bit tricks over universal intrinsics (u32 add is 2 ops: or with the wrapped-compare mask). EwAdd/EwSub overload vec() for the 32-bit lanes and getAddSubFunc routes 32S/32U T->T through vecBinaryKernel instead of the former pure scalar kernel. Semantics unchanged - the scalar int64 tail already saturated; directed boundary tests added (both rails, 0 - INT_MIN, u32 cases, a full-range random block vs an exact int64 reference). 640x480 32S add: 0.48x of 5.x -> parity (memory-bound); 1080p: 6-8x. - cv::texpr becomes CV_EXPORTS_W: python gets cv.texpr(expr, [inputs]) -> tuple of ndarrays, so `res, = cv.texpr(...)` and `mag, ang = cv.texpr(...)` unpacking both work. modules/python/test/test_expr.py covers arithmetic, the fused abs(a-b), casts, broadcasting, ?: and ** operators, math functions vs numpy, clamp, named temporaries, tuple outputs, the one-line cartToPolar and the int32 saturation cases. - warnings: {}-init the parser args array (gcc -Wmaybe-uninitialized on Ubuntu 20/22); the compare short-row block gates sizeof(T) <= 4 as constexpr so the f64 instantiation does not leave set-but-unused locals (gcc 9 -Wunused-but-set-variable). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * arithm_op: direct-kernel fast path for small continuous arrays Building and compiling the 1-instruction program plus the BroadcastOp setup costs ~40-250ns per call - negligible on big images, dominant at 127x61-class sizes where the classic 5.x functions were 1.3-2x faster. Mirror math_op two tiers in arithm_op: two same-type same-shape continuous arrays, no mask, no scalar, result depth == input depth, <= 100k elements -> call the T x T -> T kernel directly over the flattened elements (checks ordered cheapest-first). Applies to add/subtract/min/max/absdiff/multiply/addWeighted/and/or/xor; compare and divide lower to more than a single kernel (boundary rewrites, int guards) and keep the ordinary path. addWeighted falls through automatically for the 32/64-bit int types whose lowering is wide-compute + cast (getElemwiseFunc returns no direct kernel there). 127x61 vs 5.x, was -> now: add/subtract 8UC1 0.76x -> 1.3x, min/max u8 0.6x -> ~1x, addWeighted 1.0x -> 1.1-1.4x (32SC1 stays 4.5x); the one remaining laggard is add/sub 32SC1 (0.74-0.82x) - the price of the new SATURATING semantics (7-instruction AVX2 emulation vs the wrapping single add of 5.x; single-instruction on NEON). The 127x61 size is ADDED PERMANENTLY to the arithmetic/addWeighted/compare perf grids: per-call overhead regressions in these base functions must be caught by CI, not discovered by users. dst creation goes through createSameSize (whole-shape transfer including layout and future metadata, not piecemeal dims+sizes) here and in math_op. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * cv::pow rebuilt on the engine; integer-exponent and 1/sqrt(x) kernel branches Routing: p = 0/1/2 keep their early special cases (fill/copy/multiply); an INTEGER array with an INTEGER power keeps the classic iPow multiply chain - bit-exact compatibility, including its wrap-around quirks (iPow squares in int, so e.g. pow(255,4) on u8 wraps negative and saturates to 0 - somebody may rely on that). Everything else goes through the engine with the math_op two-tier scheme: small continuous arrays call powKernel directly (the exponent rides as a broadcast T scalar), the rest run the tiled parallel program. Integer arrays with fractional powers compute in the float domain and saturate back; the 32U/64-bit depths (classic iPow asserted on them) and f16/bf16 (the classic float path misread them) now just work. powKernel gets two new per-row exponent branches: - p == -0.5: 1/v_sqrt(x) (the classic path used IPP ippsInvSqrt_A21, a 21-bit approximation; ours is exact - slightly slower on small arrays, 4.5x faster at 1080p via parallelism); - any other INTEGER p (|p| <= 65536): LSB-first binary exponentiation, the same multiply chain and order as iPow, fully vectorized - a few ulp accurate vs ~2e-7 of exp(p*log x), and exact on non-positive bases (the sign falls out of the multiplies, 0^negative divides to inf) - no scalar patching. cv::pow f32 vs 5.x: p=0.5 365 -> 61 us at 1080p (6x), p=3 7.7x, p=5 7x AND faster at every size (the old scalar chain: 0.81 -> 0.47 us at 127x61), p=2.5 5.3x. The s16^5 iPow path is untouched (118.7 == 118.5 us). pow_exponents accuracy tests extended to 11 exponents x f32/f64 against the double std::pow reference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * perf: SANITY_CHECK_NOTHING for the tests whose grids got the 127x61 size The 127x61 entry added to guard per-call overhead has no regression data in opencv_extra, so the legacy SANITY_CHECK in addWeighted/compare failed on CI (locally it passes silently without the test-data path). Accuracy of both functions is covered by the accuracy suite; the perf tests should measure time. PatchNaNs/finiteMask keep their SANITY_CHECK - their grids are untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix a temp-buffer double release in the liveness pass ("d*d" crash) When the same temp is passed as SEVERAL arguments of its last-use instruction (e.g. the named-intermediate expression "d = {0} - {1}; d*d", where the MUL consumes slot d twice), the buffer-reuse scan pushed the temp's physical buffer onto the free list once per argument. That overflows the ntemps-sized freeBufs array (caught by the AutoBuffer range check in Debug: python test_expr.py::test_named_temporary) and, in larger programs, would hand the same physical buffer to two live temps. Release the buffer once by retiring lastUse[t] after the first hit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * executor: recalibrate opCost to vectorized cycles + clamp the stripe count The per-element op costs fed into the parallel_for_ stripe hint were scalar-era estimates (~20x above the vectorized reality: the atan2/exp polynomials run at ~1.5 cycles/element, not 30). The hint therefore split transcendental/divide work into hundreds of ~1 us jobs, which the macOS/GCD backend dispatches poorly under sustained load, on top of the P/E-core equal-share straggler effect. Measured on M4 Max (12P+4E), sustained medians @1920x1080 f32: texpr atan2 320 -> 133 us, cv::exp 280 -> 141 us, cv::log 301 -> ~200 us, cv::pow(x,2.5) 388 -> 376 us; the PR tables' math rows improved ~1.5-2x across the board. - opCost is now in units of ~1/4 cycle/element of the SIMD kernels: cheap ops 1 (unchanged), div/sqrt/hypot/convert_scale 10 -> 3, transcendentals 30 -> 6. - the stripe hint is clamped by min(4*nthreads, max(32, 3*nthreads)): ~4 stripes/thread is plenty of granularity for element-wise work, and the ceiling is 32 pieces except on machines with many (heterogeneous) cores, where anything coarser than ~3 pieces/worker turns the slow cores into equal-share bottlenecks (measured: 32 stripes on 16 threads is the worst point of the curve - 193 us vs 137 us at 48 for atan2). getNumThreads() is clamped from below (WINRT/plugin backends may report 0). Not addressed here (needs cross-machine data, M2/M3 Ultra): streaming memory-bound ops saturate the M4 Max fabric at ~8 fat stripes and E-core participation only adds contention - a cost model cannot express that; candidate follow-up is a bytes-aware clamp or a GCD-backend-level fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * multiply: v_mul_sat integer kernels (full product clamped to the type) v_mul_sat(V, V) -> V for u8/s8/u16/s16/u32/s32 - the full-precision product clamped to the lane type, which is exactly cv::multiply's integer semantics at scale == 1. Local to arithm.simd.hpp for now, next to v_add_sat/v_sub_sat, to be promoted into proper universal intrinsics later. NEON: widening vmull + saturating narrow (vqmovn); other backends: the portable v_mul_expand + saturating v_pack composition for 8/16-bit lanes. 32-bit lanes have no universal widening multiply (no v_mul_expand for s32), so the 32-bit integer fast path is NEON-only for now and the other backends keep the previous f64 work-vector kernels (which measure well on x86 with IPP-free AVX2). EwMul::vec() now routes the integer lane types through v_mul_sat, and getMulFunc_ passes the NATIVE lane vector as the scale==1 fast-path type: whole-register loads/stores, the widening happens inside the multiply. Replaces both the half-register widening loads (u8/s8/u16/s16) and the scalar-equivalent f64 path for 32S/32U on NEON. M4 Max, 640x480 (the sizes where the old kernels lost to carotene): 8U 22.0 -> 13.6 us, 8S 15.0 -> 11.1, 16S 21.2 -> 17.4, 32S 84.8 -> 30.5 (parity with the classic path everywhere, 32S was 0.38x). 1920x1080: 8S 1.30x -> 1.78x, 16S 2.57x -> 2.98x, 32S 2.20x -> 4.02x vs 5.x. Correctness: exhaustive 8-bit (all 65536 pairs per sign), directed saturation corners for 16/32-bit (46341^2, INT_MIN*-1, 65536*65536, all sign combinations) against an exact int64 reference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * NEON: make v_cvt_f64(v_int32) exact (was via f32, losing bits > 2^24) The NEON implementations of v_cvt_f64/v_cvt_f64_high for v_int32 did s32 -> f32 -> f64 (vcvt_f32_s32 + vcvt_f64_f32), silently rounding any |x| > 2^24. Every vectorized f64 work path with int32 inputs on AArch64 was affected: the engine's addWeighted/divide 32S kernels, convertTo 32S -> 64F, etc. Found via addWeighted 32SC1 on values ~1e9: max error was 32 vs the exact double reference (the classic carotene path is worse still - it computes in f32 end-to-end with f32-truncated weights, max error 96 on the same data). The exact sequence sxtl + scvtf (vmovl_s32 + vcvtq_f64_s64) is the same 2 instructions, so there is no cost. addWeighted 32SC1 on the engine now matches the exact-double reference bit-for-bit and stays at parity/1.4x vs the classic path (640x480/1920x1080). Pre-existing upstream bug (same code in 4.x) - worth a standalone backport with directed large-value tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * math_op: drop the temporary direct-IPP tier for exp/log Upstream moved the IPP math wrappers into the hal/ipp HAL module (cv_hal_exp32f/ log32f & co now resolve to ipp_hal_* which honor cv::ipp::useIPP via CV_HAL_CHECK_USE_IPP). The engine's single probeHalUnary(cv_hal_*) probe already picks that up uniformly, so the stopgap #ifdef HAVE_IPP ippExp/ippLog tier and its ipp::useIPP() branch in getMathFunc are now redundant - removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * arithm: restore cv::hal::and8u/or8u/xor8u/not8u as engine wrappers These public CV_EXPORTS entry points (core/hal/hal.hpp) lost their definitions when the bitwise ops moved to the element-wise engine, but they are still declared and called by other modules (opencv_objdetect's aruco) and external code - the link broke with undefined references to cv::hal::and8u/xor8u. Restore them as thin forwarders over the engine's byte-wise bitwise kernels (getBitwiseFunc / getNotFunc), mirroring the existing mul8u wrapper. CV_Assert guards the kernel lookup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * blobdetector: guard empty contour when computing blob radius The new AutoBuffer leaves its tail uninitialized for trivial types, which surfaced a -Wmaybe-uninitialized in findBlobs where the median of per-point distances is read. Use a std::vector, default the radius to 0, and compute the median only for a non-empty contour - no unproven size invariant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> |
||
|
|
3f45dab070 |
Merge pull request #29304 from velonica0:dnn-rvv-block
dnn: fix new-engine block layout for RVV when VLEN > 128 #29304 ### 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 <!-- Note!!! If you are an automated agent, we have a special process for you: add 🤖🤖🤖 to the end of the PR title. --> #### Problem Fixes #28852. The new DNN engine packs activations in a blocked NCHWc layout with a fixed channel-block size `C0 = 8`. The blocked-layout kernels (MaxPool, AveragePool, BatchNorm, depthwise Conv, ConvTranspose, generic Conv) load one block into a SIMD vector and assert: `C0 == nlanes || C0 == nlanes*2 || C0 % (nlanes*4) == 0` On RISC-V the universal intrinsics are **scalable with LMUL=2**, so `nlanes = (VLEN/32)*2` — **16 at VLEN=256, 64 at VLEN=1024** — which exceeds the fixed `C0=8`. The assertion fails with `-215` and the ONNX pooling/conv conformance tests abort. #29180 worked around it by disabling the RVV SIMD path in those kernels. #### Fix Make the block size track the hardware vector width on RVV instead of assuming 8: - `net_impl.cpp`: `defaultC0 = max(8, VTraits<v_float32>::vlanes())` (16/64 on RVV). - The fp32 blocked kernels read `C0` at runtime and size scratch buffers by `max_nlanes` (bounded by the compile-time `CV_RVV_MAX_VLEN`, default 1024). - All changes are guarded by `CV_SIMD_SCALABLE`, so **x86/NEON are unchanged**. - The int8 quantized kernels are hardwired to `C0=8` (VNNI/NEON packing + per-channel quant) and are scalar on RVV, so quantized graphs are pinned to `C0=8` in `prepareForInference()` (detected via a `CV_8S` arg); only fp32 graphs use the wider block. #### Validation (native RISC-V) I have already conducted tests on the Spacemit K3, covering both the X100 (VLEN=256) and the A100 (VLEN=1024). `opencv_test_dnn`, ENGINE_AUTO (new engine), no assertions: | VLEN | Test_ONNX_conformance | Test_ONNX_layers (conv/pool/depthwise/quantized/MobileNet_v4) | |------|-----------------------|--------------------------------------------------------------| | 256 | 1641 / 1641 | all pass (incl. `Quantized_Convolution`) | | 1024 | 1641 / 1641 | all pass (incl. `Quantized_Convolution`) | |
||
|
|
04aee009aa |
Merge pull request #29220 from omrope79:doc_optimizations_v4
[FOLLOW UP] : Documentation optimizations for the new Sphinx structure #29220 ### Pull Request Readiness Checklist This PR serves as a follow-up to the new documentation system introduced in [#29206](https://github.com/opencv/opencv/pull/29206) Co-authored by: @abhishek-gola @kirtijindal14 @Akansha-977 @Prasadayus @varun-jaiswal17 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 |
||
|
|
be2c53c2b7 |
Merge pull request #29127 from Prasadayus:KV-cache
Add KV cache with paged attention and prefetch #29127 Closes: https://github.com/opencv/opencv/issues/27159 ### 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 |
||
|
|
104d987ca2 |
Merge pull request #29093 from varun-jaiswal17:dnn-overflow-large-image
fix int32 overflow in shape_utils::total() for large tensors #29093 Fixes https://github.com/opencv/opencv/issues/24914 ### Problem When running inference with a ConvTranspose (deconvolution) layer on large inputs (e.g. 4864×4864 with 30 channels), the DNN module crashes with: OpenCV net_impl.cpp: error: (expected: 'total(ints[i]) > 0'), where 'total(ints[i])' is -1455947776 must be greater than '0' is 0 The root cause is `shape_utils::total()` which returns `int` (32-bit signed). `ENGINE_CLASSIC` catches this via `CV_CheckGT` and throws. `ENGINE_NEW` was silently bypassing the check — the overflow in `total()` itself was never addressed. ### Changes **`modules/dnn/include/opencv2/dnn/shape_utils.hpp`** — root fix - Changed return type of both `total()` overloads from `int` to `size_t` - Changed accumulator from `int elems = 1` to `size_t elems = 1` **`modules/dnn/src/net_impl.cpp`** - Updated `CV_CheckGT(total(...), 0)` to `CV_CheckGT(total(...), (size_t)0)` to match the new return type **`modules/dnn/src/net_impl2.cpp`** - Added the same `CV_CheckGT` shape validation that `ENGINE_CLASSIC` has in `net_impl.cpp:1333-1337` — `ENGINE_NEW` was missing this check entirely **`modules/dnn/src/legacy_backend.hpp`** - Removed the now-incorrect `(int)` cast in `CV_CheckEQ` — both sides are now `size_t` ### Test Added `Net.ShapeUtils_total_no_int32_overflow` in `modules/dnn/test/test_misc.cpp`: - The shape [1920 × 1,478,656] is the exact im2col buffer from the bug report. EXPECT_EQ verifies total() returns the correct size_t value 2,839,019,520. EXPECT_LT documents that casting it to int wraps to -1,455,947,776 — the value that caused the original crash. ### 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 <!-- Note!!! If you are an automated agent, we have a special process for you: add 🤖🤖🤖 to the end of the PR title. --> |
||
|
|
0a8603b3ac |
Merge pull request #28889 from abhishek-gola:simd_kernel_speedup
SIMD Kernel speedup for DNN layers #28889 This PR add following speedups for Grounding Dino tiny model. For Device: Intel(R) Core(TM) i9-14900KS, x86, 32 Cores, ubuntu 24.04, | Model | `ENGINE_NEW (Before)` | `ENGINE_NEW (After)` | `ENGINE_ORT` | | :--- | :--- | :--- | :--- | | **Grounding Dino Tiny** | 3130 ms | 1872.06 ms| 1800.18 ms| ### 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 |
||
|
|
873a4635c6 |
Merge pull request #28752 from abhishek-gola:net_profiling
Added net profiling support #28752 ### 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 |
||
|
|
72e0bc2bf3 |
Merge pull request #28957 from abhishek-gola:fusion_block_layout_extension
Extend attention fusion for runtime QK scale and add MatMul to Gemm rewriter #28957 ### 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 |
||
|
|
7b6dc220b1 |
Merge pull request #28722 from omrope79:fix-dnn-fusion
fixes a bug in ENGINE_NEW of incorrect fusion of conv+relu+batchnorm #28722 ### Pull Request Readiness Checklist OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1325 Closes Issue https://github.com/opencv/opencv/issues/28689 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 |
||
|
|
2760c0c08a |
Merge pull request #28931 from abhishek-gola:extended_fusions
Extended graph fusion for transformer models #28931 ### Pull Request Readiness Checklist Performance numbers on Intel(R) Core(TM) i9-14900KS: ``` AlexNet::DNNTestNetwork::OCV/CPU 7.143 6.871 1.04 AlexNet::DNNTestNetwork::OCV/OCL 7.471 7.047 1.06 AlexNet::DNNTestNetwork::OCV/OCL_FP16 7.157 6.907 1.04 BERT::DNNTestNetwork::OCV/CPU 9.454 9.154 1.03 BERT::DNNTestNetwork::OCV/OCL 9.657 9.138 1.06 BERT::DNNTestNetwork::OCV/OCL_FP16 9.590 9.271 1.03 CRNN::DNNTestNetwork::OCV/CPU 18.194 17.020 1.07 CRNN::DNNTestNetwork::OCV/OCL 17.855 17.433 1.02 CRNN::DNNTestNetwork::OCV/OCL_FP16 17.629 17.277 1.02 DenseNet_121::DNNTestNetwork::OCV/CPU 24.735 23.863 1.04 DenseNet_121::DNNTestNetwork::OCV/OCL 24.991 25.140 0.99 DenseNet_121::DNNTestNetwork::OCV/OCL_FP16 24.598 24.019 1.02 EAST_text_detection::DNNTestNetwork::OCV/CPU 26.929 27.084 0.99 EAST_text_detection::DNNTestNetwork::OCV/OCL 26.863 27.531 0.98 EAST_text_detection::DNNTestNetwork::OCV/OCL_FP16 26.884 27.082 0.99 EfficientDet::DNNTestNetwork::OCV/CPU 62.667 62.716 1.00 EfficientDet_int8::DNNTestNetwork::OCV/CPU 34.446 34.796 0.99 EfficientNet::DNNTestNetwork::OCV/CPU 11.875 11.786 1.01 EfficientNet::DNNTestNetwork::OCV/OCL 12.434 11.806 1.05 EfficientNet::DNNTestNetwork::OCV/OCL_FP16 11.886 11.899 1.00 FastNeuralStyle_eccv16::DNNTestNetwork::OCV/CPU 15.104 14.327 1.05 FastNeuralStyle_eccv16::DNNTestNetwork::OCV/OCL 15.071 14.670 1.03 FastNeuralStyle_eccv16::DNNTestNetwork::OCV/OCL_FP16 15.262 14.072 1.08 GoogLeNet::DNNTestNetwork::OCV/CPU 5.030 5.031 1.00 GoogLeNet::DNNTestNetwork::OCV/OCL 5.075 5.017 1.01 GoogLeNet::DNNTestNetwork::OCV/OCL_FP16 5.053 5.055 1.00 Inception_5h::DNNTestNetwork::OCV/CPU 6.777 6.430 1.05 Inception_5h::DNNTestNetwork::OCV/OCL 7.309 6.683 1.09 Inception_5h::DNNTestNetwork::OCV/OCL_FP16 6.624 6.549 1.01 Inception_v2_Faster_RCNN::DNNTestNetwork::OCV/CPU 86.676 82.918 1.05 Inception_v2_Faster_RCNN::DNNTestNetwork::OCV/OCL 85.460 84.873 1.01 Inception_v2_SSD_TensorFlow::DNNTestNetwork::OCV/CPU 16.007 15.723 1.02 Inception_v2_SSD_TensorFlow::DNNTestNetwork::OCV/OCL 15.974 16.015 1.00 Inception_v2_SSD_TensorFlow::DNNTestNetwork::OCV/OCL_FP16 16.219 15.593 1.04 MPHand::DNNTestNetwork::OCV/CPU 3.273 3.313 0.99 MPHand::DNNTestNetwork::OCV/OCL 3.466 3.318 1.04 MPHand::DNNTestNetwork::OCV/OCL_FP16 3.314 3.258 1.02 MPPalm::DNNTestNetwork::OCV/CPU 2.839 1.973 1.44 MPPalm::DNNTestNetwork::OCV/OCL 2.773 2.132 1.30 MPPalm::DNNTestNetwork::OCV/OCL_FP16 2.783 2.133 1.30 MPPose::DNNTestNetwork::OCV/CPU 7.644 8.711 0.88 MPPose::DNNTestNetwork::OCV/OCL 7.555 7.210 1.05 MPPose::DNNTestNetwork::OCV/OCL_FP16 7.564 7.559 1.00 MobileNet_SSD_Caffe::DNNTestNetwork::OCV/CPU 9.040 8.813 1.03 MobileNet_SSD_Caffe::DNNTestNetwork::OCV/OCL 8.692 9.481 0.92 MobileNet_SSD_Caffe::DNNTestNetwork::OCV/OCL_FP16 8.792 8.884 0.99 MobileNet_SSD_v1_TensorFlow::DNNTestNetwork::OCV/CPU 7.893 7.735 1.02 MobileNet_SSD_v1_TensorFlow::DNNTestNetwork::OCV/OCL 8.233 7.816 1.05 MobileNet_SSD_v1_TensorFlow::DNNTestNetwork::OCV/OCL_FP16 7.949 7.817 1.02 MobileNet_SSD_v2_TensorFlow::DNNTestNetwork::OCV/CPU 14.373 15.282 0.94 MobileNet_SSD_v2_TensorFlow::DNNTestNetwork::OCV/OCL 14.218 15.788 0.90 MobileNet_SSD_v2_TensorFlow::DNNTestNetwork::OCV/OCL_FP16 14.473 14.853 0.97 MobileNetv2_ONNX::DNNTestNetwork::OCV/CPU 1.507 1.440 1.05 MobileNetv2_ONNX::DNNTestNetwork::OCV/OCL 1.529 1.394 1.10 MobileNetv2_ONNX::DNNTestNetwork::OCV/OCL_FP16 1.448 1.433 1.01 PPHumanSeg::DNNTestNetwork::OCV/CPU 2.302 1.919 1.20 PPHumanSeg::DNNTestNetwork::OCV/OCL 2.097 1.865 1.12 PPHumanSeg::DNNTestNetwork::OCV/OCL_FP16 2.129 1.908 1.12 PPOCRv3::DNNTestNetwork::OCV/CPU 20.612 20.858 0.99 PPOCRv3::DNNTestNetwork::OCV/OCL 21.672 21.444 1.01 PPOCRv3::DNNTestNetwork::OCV/OCL_FP16 22.660 20.857 1.09 ResNet50_QDQ_ONNX::DNNTestNetwork::OCV/CPU 6.443 6.718 0.96 ResNet50_QDQ_ONNX::DNNTestNetwork::OCV/OCL 6.842 6.823 1.00 ResNet50_QDQ_ONNX::DNNTestNetwork::OCV/OCL_FP16 6.895 6.579 1.05 ResNet_50_v1_ONNX::DNNTestNetwork::OCV/CPU 7.669 7.629 1.01 ResNet_50_v1_ONNX::DNNTestNetwork::OCV/OCL 7.514 7.473 1.01 ResNet_50_v1_ONNX::DNNTestNetwork::OCV/OCL_FP16 7.598 7.513 1.01 SFace::DNNTestNetwork::OCV/CPU 3.427 3.334 1.03 SFace::DNNTestNetwork::OCV/OCL 3.420 3.337 1.02 SFace::DNNTestNetwork::OCV/OCL_FP16 3.497 3.375 1.04 SSD::DNNTestNetwork::OCV/CPU 83.165 83.476 1.00 SSD::DNNTestNetwork::OCV/OCL 83.531 84.121 0.99 SSD::DNNTestNetwork::OCV/OCL_FP16 82.447 83.234 0.99 SqueezeNet_v1_1::DNNTestNetwork::OCV/CPU 1.334 1.308 1.02 SqueezeNet_v1_1::DNNTestNetwork::OCV/OCL 1.279 1.313 0.97 SqueezeNet_v1_1::DNNTestNetwork::OCV/OCL_FP16 1.429 1.290 1.11 VIT_Base_Patch16_224::DNNTestNetwork::OCV/CPU 71.211 75.013 0.95 VIT_Base_Patch16_224::DNNTestNetwork::OCV/OCL 71.988 71.218 1.01 VIT_Base_Patch16_224::DNNTestNetwork::OCV/OCL_FP16 73.700 82.285 0.90 VitTrack::DNNTestNetwork::OCV/CPU 4.096 2.091 1.96 VitTrack::DNNTestNetwork::OCV/OCL 3.830 2.056 1.86 VitTrack::DNNTestNetwork::OCV/OCL_FP16 3.796 2.110 1.80 YOLOX::DNNTestNetwork::OCV/CPU 24.346 23.079 1.05 YOLOX::DNNTestNetwork::OCV/OCL 24.442 23.459 1.04 YOLOX::DNNTestNetwork::OCV/OCL_FP16 23.947 23.327 1.03 YOLOv3::DNNTestNetwork::OCV/CPU 59.140 59.140 1.00 YOLOv3::DNNTestNetwork::OCV/OCL 46.725 45.292 1.03 YOLOv3::DNNTestNetwork::OCV/OCL_FP16 46.939 45.382 1.03 YOLOv4::DNNTestNetwork::OCV/CPU 70.062 68.145 1.03 YOLOv4::DNNTestNetwork::OCV/OCL 219.570 214.823 1.02 YOLOv4::DNNTestNetwork::OCV/OCL_FP16 219.276 213.472 1.03 YOLOv4_tiny::DNNTestNetwork::OCV/CPU 8.362 8.221 1.02 YOLOv4_tiny::DNNTestNetwork::OCV/OCL 8.373 8.095 1.03 YOLOv4_tiny::DNNTestNetwork::OCV/OCL_FP16 8.830 8.088 1.09 YOLOv5::DNNTestNetwork::OCV/CPU 9.237 8.484 1.09 YOLOv5::DNNTestNetwork::OCV/OCL 8.776 8.537 1.03 YOLOv5::DNNTestNetwork::OCV/OCL_FP16 8.747 8.536 1.02 YOLOv8::DNNTestNetwork::OCV/CPU 11.019 11.463 0.96 YOLOv8::DNNTestNetwork::OCV/OCL 11.204 10.766 1.04 YOLOv8::DNNTestNetwork::OCV/OCL_FP16 11.355 10.764 1.05 YuNet::DNNTestNetwork::OCV/CPU 3.371 3.466 0.97 YuNet::DNNTestNetwork::OCV/OCL 3.396 3.105 1.09 YuNet::DNNTestNetwork::OCV/OCL_FP16 3.150 3.130 1.01 ``` 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 |
||
|
|
ae1f3a991c |
Merge pull request #28859 from abhishek-gola:fuse_attention
Added Attention fusion and thin gemm support #28859 Merge with: https://github.com/opencv/opencv_extra/pull/1350 Performance numbers after these optimizations: For Device: Intel(R) Core(TM) i9-14900KS, x86, 32 Cores, ubuntu 24.04, | Model | `ENGINE_NEW (Before)` | `ENGINE_NEW (After)` | `ENGINE_ORT` | | :--- | :--- | :--- | :--- | | **BERT** |26.3 ms| 9.15 ms| 9.13 ms| | **ViT** | 79.65 ms| 63.23 ms| 32.3 ms| ### 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 |
||
|
|
b883454620 | fixed forced ORT engine | ||
|
|
de851d24a5 |
Merge pull request #28121 from abhishek-gola:loop_layer_add
Add Loop layer to new DNN engine #28121 Addition of loop layer in 5.x for issue: https://github.com/opencv/opencv/issues/26179 and https://github.com/opencv/opencv/issues/26141 and https://github.com/opencv/opencv/issues/25200 OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1335 ### 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 |
||
|
|
2ec6a6bb65 |
Merge pull request #28588 from abhishek-gola:ORT_GPU_wrapper
Added OnnxRuntime GPU wrapper #28588 ### 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 |
||
|
|
47ac80995f |
Merge pull request #28749 from Prasadayus:NMS-empty-detection-fix
Nms empty detection fix #28749 Requires opencv_extra: https://github.com/opencv/opencv_extra/pull/1330 ### 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 |
||
|
|
e59506bbf5 |
Merge pull request #28595 from abhishek-gola:qdq_support
* added qdq fusion * Added VNNI optimizations |
||
|
|
40ce5b4132 |
Merge pull request #28637 from abhishek-gola:old_dnn_tickets_cleanup
Added Output Tensor Names support in new DNN engine #28637 closes: https://github.com/opencv/opencv/issues/26201 ### 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 |
||
|
|
1b483ffea6 |
Merge pull request #28585 from vpisarev:dnn_block_layout_v5
Block layout-based convolution in DNN #28585 merge together with https://github.com/opencv/opencv_extra/pull/1321 Some core parts of the new engine in DNN module have been revised substantially: 1. all tests seem to pass, except for `Test_Graph_Simplifier.ResizeSubgraph`, which has been disabled because it does not take the newly added `TransformLayoutLayer` into account. The test should be reworked perhaps. 1. convolution and related operations (maxpool/avgpool) now use so-called block layout (`DATA_LAYOUT_BLOCK`), where `NxCxHxW` tensors are represented as `NxC1xHxWxC0`, where `C1=(C + C0-1)/C0` and `C0` is a power-of-two (usually 4, 8, 16 or 32). 1. graph is now pre-processed and `TransformLayoutLayer` is inserted to convert data from NCHW or NHWC layout to the block layout or vice versa. The transformations are done in a lazy way only when they are really needed. For example, in the whole Resnet only 2 transformations are performed. 1. transformer-based models and other models that do not use convolutions will run as usual, without going to block layout. 1. there is yet another graph preprocessing stage added that embeds constant weights/scale and bias into convolution and batch norm layers. 1. 'batchnorm', 'activation' and 'adding a residual' are now fused with convolution, just like in the old engine. That brings some noticeable acceleration. 1. optimized convolution kernels have been added. * depthwise convolution, as well as maxpool and avgpool support C0=4, 8, 16 etc. _as long as_ C0 is divisible by the number of fp32 lanes in a SIMD register of the target platform (e.g. on ARM with NEON there must be `C0 % 4 == 0`, on x64 with AVX2 `C0 % 8 == 0`). * non-depthwise convolution only supports C0=8 for now. C0=8 seems to be a sweetspot for ARM with NEON, x64 with AVX2 or RISC-V with RVV (with 128- or 256-bit registers). For some platforms with dedicated matrix accelerators C0=16 or even C0=32 might be more efficient, but we could add the respective kernels later. * only fp32 kernels have been added. fp16/bf16 kernels might be added a little later. ### 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 - [ ] 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 - [x] Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake |
||
|
|
95c66292b5 |
Merge pull request #28444 from abhishek-gola:added_ORT_wrapper
Added ONNX Runtime as an optional wrapper #28444 This PR adds ONNXRuntime (ORT) as an _optional_ wrapper, which can be enabled by adding **WITH_ONNXRUNTIME** flag in CMake command. Using ORT wrapper the inference time for _resnet50.onnx model_ has come to _**~7ms**_ from _**~14ms**_. Also, we are able to run models like `ssd_mobilenet_v1.onnx`. ### 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 |
||
|
|
b258926e54 |
Merge pull request #28058 from nklskyoy:onnx-importer2-dispatch-map
Onnx importer2 dispatch map #28058 I have noticed that PR[28032]( https://github.com/opencv/opencv/pull/28032) was incomplete - it fixed only the new ONNX importer. Also, building the dispatch map based on the parsed opset version hypotetically can cause trouble if the graph simplifier inserts a node with a different opset version which is not included in the dispatch map. So I removed this parameter in `buildDispatchMap_COM_MICROSOFT` and `buildDispatchMap_ONNX_AI` for now. It was marked as `CV_UNUSED` anyway. ### 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 - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] 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 |
||
|
|
93385c6cdf |
Merge pull request #27816 from abhishek-gola:reduce_layer
Extended Reduce layer support in new DNN engine #27816 ### 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 |
||
|
|
2470c07f1b |
Merge pull request #27698 from abhishek-gola:add_cast_layer
Added cast and castlike layers support in new DNN engine #27698 ### 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 |
||
|
|
709eabda16 |
Merge pull request #27508 from abhishek-gola:if_layer_add
IfLayer add to new DNN engine #27508 ### 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 |
||
|
|
3672a14b42 |
Merge pull request #26394 from alexlyulkov:al/new-engine-tf-parser
Modified tensorflow parser for the new dnn engine #26394 ### 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 - [ ] 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 |