nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2131

**Code Changes:**
```diff
+        for (int i = 0; i < refTimings.size(); i++)
+        {
+            CV_Assert(refTimings[i] != 0.0);
+        }
+
+        net.enableFusion(true);
+        net.setPreferableBackend(backendId);
+        net.setPreferableTarget(targetId);
+        net.setInput(input);
+        Mat outputTest = net.forward().clone();
+        std::vector<double> testTimings;
```

Review comment:
How to make a deep copy of the `Net` object? I am not able to think of any straightforward way to do this. This is one option: ``` Net nets[2]; for (int i = 0; i < 2; i++) { Net& net = nets[i]; int convId = net.addLayer(convParams.name, convParams.type, convParams); int eltwiseId = net.addLayer(eltwiseParams.name, eltwiseParams.type, eltwiseParams); int activeId = net.addLayer(activationParams.name, activationParams.type, activationParams); net.connect(0, 0, convId, 0); net.connect(convId, 0, eltwiseId, 0); net.connect(0, 0, eltwiseId, 1); net.connect(eltwiseId, 0, activeId, 0); } ``` `TestLayerFusion::test` would take two `Net&` as input.
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2131

**Code Changes:**
```diff
+        for (int i = 0; i < refTimings.size(); i++)
+        {
+            CV_Assert(refTimings[i] != 0.0);
+        }
+
+        net.enableFusion(true);
+        net.setPreferableBackend(backendId);
+        net.setPreferableTarget(targetId);
+        net.setInput(input);
+        Mat outputTest = net.forward().clone();
+        std::vector<double> testTimings;
```

Review comment:
Oh, I see. So, maybe we can just add extra check that for a model without fusion all the layers have `timings >0`: https://github.com/opencv/opencv/blob/4b0132ed7a7ca2c704b4c9abee8e2f6e180bd791/modules/dnn/test/test_common.hpp#L189 also, for a model with fusion we can expect that at least one layer has zero execution time.
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions

**Code Changes:**
```diff
@@ -2046,4 +2046,436 @@ TEST_P(Layer_Test_BatchNorm, fusion)
 
 INSTANTIATE_TEST_CASE_P(/**/, Layer_Test_BatchNorm, dnnBackendsAndTargets());
 
+class TestLayerFusion : public DNNTestLayer {
+public:
+    static void makeDefaultTestConvolutionLayer(LayerParams& convParams, int in_channels, int num_filters, bool bias_term)
+    {
+        const int kernel_h = 3, kernel_w = 3;
+        const int pad_h = kernel_h / 2, pad_w = kernel_w / 2;
```

Review comment:
Copy-paste mistake is here. Should be ``` setPreferableBackend setPreferableTarget ```
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2068

**Code Changes:**
```diff
+        convParams.name = "convolution";
+
+        float conv_init_magnitude = 1.0f / in_channels / kernel_h / kernel_w;
+        int weightsShape[] = {num_filters, in_channels, kernel_h, kernel_w};
+        Mat weights(4, &weightsShape[0], CV_32F);
+        randu(weights, -conv_init_magnitude, conv_init_magnitude);
+        convParams.blobs.push_back(weights);
+        if (bias_term)
+        {
+            Mat bias(1, num_filters, CV_32F);
+            randu(bias, -1.0f, 1.0f);
```

Review comment:
I am not sure if this is a good initialization. The weights might be too small.
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2299

**Code Changes:**
```diff
+INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionEltwiseFusion, Combine(
+/* bias */              testing::Bool(),
+/* eltwise op */        TestLayerFusion::eltwiseOpList(),
+/* eltwise weighted */  testing::Bool(),
+                        TestLayerFusion::dnnBackendsAndTargetsForFusionTests()
+));
+
+typedef TestWithParam<tuple<bool, std::string, bool, std::string, tuple<Backend, Target> > > ConvolutionEltwiseActivationFusion;
+TEST_P(ConvolutionEltwiseActivationFusion, Accuracy)
+{
+    //                 input
```

Review comment:
Can this and a previous layers be merged into one?
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2299

**Code Changes:**
```diff
+INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionEltwiseFusion, Combine(
+/* bias */              testing::Bool(),
+/* eltwise op */        TestLayerFusion::eltwiseOpList(),
+/* eltwise weighted */  testing::Bool(),
+                        TestLayerFusion::dnnBackendsAndTargetsForFusionTests()
+));
+
+typedef TestWithParam<tuple<bool, std::string, bool, std::string, tuple<Backend, Target> > > ConvolutionEltwiseActivationFusion;
+TEST_P(ConvolutionEltwiseActivationFusion, Accuracy)
+{
+    //                 input
```

Review comment:
I am thinking of adding a new bool parameter that indicates if the eltwise has coefficients. But it might create redundant tests for eltwise operations that do not use coefficients if `Combine()` is used. I don't know how to instantiate test cases where the weighted bool is true for "sum" only without making another test case.
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2299

**Code Changes:**
```diff
+INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionEltwiseFusion, Combine(
+/* bias */              testing::Bool(),
+/* eltwise op */        TestLayerFusion::eltwiseOpList(),
+/* eltwise weighted */  testing::Bool(),
+                        TestLayerFusion::dnnBackendsAndTargetsForFusionTests()
+));
+
+typedef TestWithParam<tuple<bool, std::string, bool, std::string, tuple<Backend, Target> > > ConvolutionEltwiseActivationFusion;
+TEST_P(ConvolutionEltwiseActivationFusion, Accuracy)
+{
+    //                 input
```

Review comment:
Maybe just skip them?
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2068

**Code Changes:**
```diff
+        convParams.name = "convolution";
+
+        float conv_init_magnitude = 1.0f / in_channels / kernel_h / kernel_w;
+        int weightsShape[] = {num_filters, in_channels, kernel_h, kernel_w};
+        Mat weights(4, &weightsShape[0], CV_32F);
+        randu(weights, -conv_init_magnitude, conv_init_magnitude);
+        convParams.blobs.push_back(weights);
+        if (bias_term)
+        {
+            Mat bias(1, num_filters, CV_32F);
+            randu(bias, -1.0f, 1.0f);
```

Review comment:
Why do you think if that's a problem? I think it also good chance to track if we have no regressions with such kind of optimizations: https://github.com/opencv/opencv/pull/17295
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2068

**Code Changes:**
```diff
+        convParams.name = "convolution";
+
+        float conv_init_magnitude = 1.0f / in_channels / kernel_h / kernel_w;
+        int weightsShape[] = {num_filters, in_channels, kernel_h, kernel_w};
+        Mat weights(4, &weightsShape[0], CV_32F);
+        randu(weights, -conv_init_magnitude, conv_init_magnitude);
+        convParams.blobs.push_back(weights);
+        if (bias_term)
+        {
+            Mat bias(1, num_filters, CV_32F);
+            randu(bias, -1.0f, 1.0f);
```

Review comment:
It will squeeze all weights to a very small range `[-0.007, 0.007]`. I don't think there is any serious problem but not sure.
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2383

**Code Changes:**
```diff
+            {
+                expectedFusedLayers.push_back(eltwiseId);
+                expectedFusedLayers.push_back(activId);
+            }
+        }
+    }
+
+    TestLayerFusion::test(input, net, backendId, targetId, expectedFusedLayers);
+}
+INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionEltwiseActivationFusion, Combine(
+/* bias */              testing::Bool(),
```

Review comment:
I still don't like code duplication. Is that possible to move common parts into `TestLayerFusion` but keep the tests only for different instantiations?
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2383

**Code Changes:**
```diff
+            {
+                expectedFusedLayers.push_back(eltwiseId);
+                expectedFusedLayers.push_back(activId);
+            }
+        }
+    }
+
+    TestLayerFusion::test(input, net, backendId, targetId, expectedFusedLayers);
+}
+INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionEltwiseActivationFusion, Combine(
+/* bias */              testing::Bool(),
```

Review comment:
Like in `testDarknetModel` from https://github.com/opencv/opencv/blob/master/modules/dnn/test/test_darknet_importer.cpp
**File:** modules/dnn/test/test_layers.cpp
**Change Type:** modified
**Context:** PR #17976: dnn: add exhaustive fusion tests, enable more eltwise fusions
**Review Line:** 2383

**Code Changes:**
```diff
+            {
+                expectedFusedLayers.push_back(eltwiseId);
+                expectedFusedLayers.push_back(activId);
+            }
+        }
+    }
+
+    TestLayerFusion::test(input, net, backendId, targetId, expectedFusedLayers);
+}
+INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionEltwiseActivationFusion, Combine(
+/* bias */              testing::Bool(),
```

Review comment:
Not sure that code here can be reduced significantly. Sometimes it is better to keep tests simple and straightforward if over-complicated helpers can't reduce amount of code.
**File:** modules/core/include/opencv2/core.hpp
**Change Type:** modified
**Context:** PR #18008: Document PatchNANs input type (issue #18000)

**Code Changes:**
```diff
@@ -1615,7 +1615,9 @@ elements.
 CV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0,
                             double minVal = -DBL_MAX, double maxVal = DBL_MAX);
 
-/** @brief converts NaN's to the given number
+/** @brief converts NaNs to the given number
+@param a input/output matrix (CV_32F type).
+@param val value to convert the NaNs
 */
 CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0);
```

Review comment:
I propose to replace `CV_32FC1` with `CV_32F`, amount of channels does not matter.
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #17742: Adding comment from source code to DetectionOutputLayer class documentation - Adds a comment written in the source code for bool getMemoryS...

**Code Changes:**
```diff
@@ -598,6 +598,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
         static Ptr<RegionLayer> create(const LayerParams& params);
     };
 
+    /**
+     * @brief Detection output layer.
+     *
+     * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
+     *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
+     *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
```

Review comment:
What is Lp?
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #17742: Adding comment from source code to DetectionOutputLayer class documentation - Adds a comment written in the source code for bool getMemoryS...

**Code Changes:**
```diff
@@ -598,6 +598,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
         static Ptr<RegionLayer> create(const LayerParams& params);
     };
 
+    /**
+     * @brief Detection output layer.
+     *
+     * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
+     *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
+     *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
```

Review comment:
What is num and channels? Just specify how output shape is computed
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #17742: Adding comment from source code to DetectionOutputLayer class documentation - Adds a comment written in the source code for bool getMemoryS...

**Code Changes:**
```diff
@@ -598,6 +598,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
         static Ptr<RegionLayer> create(const LayerParams& params);
     };
 
+    /**
+     * @brief Detection output layer.
+     *
+     * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
+     *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
+     *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
```

Review comment:
Oh. I copied the comment from below and left that part. Removing it now.
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #17742: Adding comment from source code to DetectionOutputLayer class documentation - Adds a comment written in the source code for bool getMemoryS...

**Code Changes:**
```diff
@@ -598,6 +598,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
         static Ptr<RegionLayer> create(const LayerParams& params);
     };
 
+    /**
+     * @brief Detection output layer.
+     *
+     * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
+     *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
+     *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
```

Review comment:
number of detections multiplied by batch size?
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #17742: Adding comment from source code to DetectionOutputLayer class documentation - Adds a comment written in the source code for bool getMemoryS...

**Code Changes:**
```diff
@@ -598,6 +598,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
         static Ptr<RegionLayer> create(const LayerParams& params);
     };
 
+    /**
+     * @brief Detection output layer.
+     *
+     * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
+     *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
+     *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
```

Review comment:
Yes. At least that's what I see in code.
**File:** modules/dnn/include/opencv2/dnn/all_layers.hpp
**Change Type:** modified
**Context:** PR #17742: Adding comment from source code to DetectionOutputLayer class documentation - Adds a comment written in the source code for bool getMemoryS...
**Review Line:** 606

**Code Changes:**
```diff
+    /**
+     * @brief Detection output layer.
+     *
+     * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
+     *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
+     *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
+     *    where image_id is the index of image input in the batch.
+     */
     class CV_EXPORTS DetectionOutputLayer : public Layer
     {
     public:
```

Review comment:
Please clarify that `image id in batch`
**File:** cmake/OpenCVCompilerOptimizations.cmake
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -49,6 +49,7 @@ list(APPEND CPU_ALL_OPTIMIZATIONS "AVX512_COMMON;AVX512_KNL;AVX512_KNM;AVX512_SK
 list(APPEND CPU_ALL_OPTIMIZATIONS NEON VFPV3 FP16)
 list(APPEND CPU_ALL_OPTIMIZATIONS MSA)
 list(APPEND CPU_ALL_OPTIMIZATIONS VSX VSX3)
+list(APPEND CPU_ALL_OPTIMIZATIONS RVV)
 list(REMOVE_DUPLICATES CPU_ALL_OPTIMIZATIONS)
 
 ocv_update(CPU_VFPV3_FEATURE_ALIAS "")
@@ -102,6 +103,8 @@ ocv_optimization_process_obsolete_option(ENABLE_NEON NEON OFF)
 
```

Review comment:
`ENABLE_RISCV` is bad choise as it's general architecture name. I propose to use something `ENABLE_RVV` or enable `ENABLE_RISCV_VEXT`.
**File:** modules/core/src/system.cpp
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics
**Review Line:** 603

**Code Changes:**
```diff
@@ -597,6 +599,10 @@ struct HWFeatures
         have[CV_CPU_VSX3] = (CV_VSX3);
     #endif
 
+    #if defined __riscv && defined __riscv_vector
+        have[CV_CPU_RVV] = true;
+    #endif
+
         bool skip_baseline_check = false;
 #ifndef NO_GETENV
         if (getenv("OPENCV_SKIP_CPU_BASELINE_CHECK"))
```

Review comment:
`__riscv` is very general and defined for general RISC-V architecture. There should be some specific check here.
**File:** modules/core/include/opencv2/core/hal/intrin.hpp
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -199,6 +199,7 @@ using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE;
 #   undef CV_VSX
 #   undef CV_FP16
 #   undef CV_MSA
+#   undef CV_RVV
 #endif
 
 #if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD) && !defined(CV_FORCE_SIMD128_CPP)
@@ -226,6 +227,9 @@ using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE;
 #elif CV_WASM_SIMD && !defined(CV_FORCE_SIMD128_CPP)
```

Review comment:
Please revert the change here till we do not have specific optimizations.
**File:** modules/core/include/opencv2/core/hal/intrin_rvv.hpp
**Change Type:** added
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -0,0 +1,1678 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#ifndef OPENCV_HAL_INTRIN_RVV_HPP
+#define OPENCV_HAL_INTRIN_RVV_HPP
+
+#include <limits>
+#include <cstring>
```

Review comment:
Please remove all doxygen comments (with below format) from this file, we use only intrin_cpp for intrinsic documentation: ``` //! /** ```
**File:** modules/core/include/opencv2/core/hal/intrin_rvv.hpp
**Change Type:** added
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -0,0 +1,1678 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#ifndef OPENCV_HAL_INTRIN_RVV_HPP
+#define OPENCV_HAL_INTRIN_RVV_HPP
+
+#include <limits>
+#include <cstring>
```

Review comment:
Please rename this preprocessor directive.
**File:** modules/core/include/opencv2/core/hal/intrin_rvv.hpp
**Change Type:** added
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -0,0 +1,1678 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#ifndef OPENCV_HAL_INTRIN_RVV_HPP
+#define OPENCV_HAL_INTRIN_RVV_HPP
+
+#include <limits>
+#include <cstring>
```

Review comment:
Please use short (3-line) license header for new files.
**File:** modules/core/include/opencv2/core/cv_cpu_dispatch.h
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -168,6 +168,10 @@
 #  include <wasm_simd128.h>
 #endif
 
+#if defined CV_CPU_COMPILE_RVV
+#  define CV_RVV 1
+#endif
+
 #endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__
 
```

Review comment:
Please add an empty line at the end of file.
**File:** modules/core/include/opencv2/core/cv_cpu_dispatch.h
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -168,6 +168,10 @@
 #  include <wasm_simd128.h>
 #endif
 
+#if defined CV_CPU_COMPILE_RVV
+#  define CV_RVV 1
+#endif
+
 #endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__
 
```

Review comment:
I believe it should be something like `CV_CPU_COMPILE_RVV`.
**File:** modules/core/include/opencv2/core/cv_cpu_dispatch.h
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -168,6 +168,10 @@
 #  include <wasm_simd128.h>
 #endif
 
+#if defined CV_CPU_COMPILE_RVV
+#  define CV_RVV 1
+#endif
+
 #endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__
 
```

Review comment:
Why is this commented? Is it needed?
**File:** modules/core/include/opencv2/core/hal/intrin_rvv.hpp
**Change Type:** added
**Context:** PR #17922: Build riscv with c++ intrinsics
**Review Line:** 10

**Code Changes:**
```diff
+#ifndef OPENCV_HAL_INTRIN_RVV_HPP
+#define OPENCV_HAL_INTRIN_RVV_HPP
+
+#include <limits>
+#include <cstring>
+#include <algorithm>
+#include "opencv2/core/saturate.hpp"
+
+#define CV_SIMD128_CPP 1
+#if defined(CV_FORCE_SIMD128_CPP) || defined(CV_DOXYGEN)
+#define CV_SIMD128 1
```

Review comment:
Are these headers actually required?
**File:** platforms/linux/riscv64-clang.toolchain.cmake
**Change Type:** added
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -0,0 +1,27 @@
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_SYSTEM_PROCESSOR riscv64)
+
+set(RISCV_CLANG_BUILD_ROOT /opt/rvv-llvm CACHE PATH "Path to CLANG for RISC-V cross compiler build directory")
+set(RISCV_GCC_INSTALL_ROOT /opt/RISCV CACHE PATH "Path to GCC for RISC-V cross compiler installation directory")
+set(CMAKE_SYSROOT ${RISCV_GCC_INSTALL_ROOT}/sysroot CACHE PATH "RISC-V sysroot")
+
+set(CLANG_TARGET_TRIPLE riscv64-unknown-linux-gnu)
+
```

Review comment:
Maybe it would be better to use paths based in `/opt` as default locations?
**File:** modules/core/src/system.cpp
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics
**Review Line:** 603

**Code Changes:**
```diff
@@ -597,6 +599,10 @@ struct HWFeatures
         have[CV_CPU_VSX3] = (CV_VSX3);
     #endif
 
+    #if defined __riscv && defined __riscv_vector
+        have[CV_CPU_RVV] = true;
+    #endif
+
         bool skip_baseline_check = false;
 #ifndef NO_GETENV
         if (getenv("OPENCV_SKIP_CPU_BASELINE_CHECK"))
```

Review comment:
This check should be dynamic, otherwise dispatching does not make sense. Is it possible to detect vector extensions in runtime?
**File:** modules/core/include/opencv2/core/cv_cpu_dispatch.h
**Change Type:** modified
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -168,6 +168,10 @@
 #  include <wasm_simd128.h>
 #endif
 
+#if defined CV_CPU_COMPILE_RVV
+#  define CV_RVV 1
+#endif
+
 #endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__
 
```

Review comment:
This header is not needed now for C++ version universal intrinsics and will be needed later for rvv version universal intrinsics. Should I remove it now and add it later when it is needed?
**File:** platforms/linux/riscv64-clang.toolchain.cmake
**Change Type:** added
**Context:** PR #17922: Build riscv with c++ intrinsics

**Code Changes:**
```diff
@@ -0,0 +1,27 @@
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_SYSTEM_PROCESSOR riscv64)
+
+set(RISCV_CLANG_BUILD_ROOT /opt/rvv-llvm CACHE PATH "Path to CLANG for RISC-V cross compiler build directory")
+set(RISCV_GCC_INSTALL_ROOT /opt/RISCV CACHE PATH "Path to GCC for RISC-V cross compiler installation directory")
+set(CMAKE_SYSROOT ${RISCV_GCC_INSTALL_ROOT}/sysroot CACHE PATH "RISC-V sysroot")
+
+set(CLANG_TARGET_TRIPLE riscv64-unknown-linux-gnu)
+
```

Review comment:
Now the release version of RISC-V toolchain does not support latest RISC-V vector extension. We use the latest version of toochain installed by code in GitHub. And Clang does not support also. We use a Github version that under development. Should I still edit the path here?