Files
opencv-MIRROR/modules/core/perf/perf_dot.cpp
Shiven Solanki 34e51a4bf4 Merge pull request #30558 from sshivensolanki/fix-dot-new-depths
Fix
New kernels in matmul.simd.hpp, called through CV_CPU_DISPATCH like dotProd_64f:

CV_32U, CV_64U, CV_64S: thin wrappers around dotProd_ (each element converted to double, accumulated in double).
CV_16F, CV_16BF: vx_load_expand widens each value to float32, and v_muladd adds the products in float32 with two independent accumulators, in blocks of 8192 like dotProd_32f. Each block's sum is added to a double.
CV_8F_E4M3FN, CV_8F_E4M3FNUZ: decoded through decodeLUT() with v_lut, as in cvtFp8ToF32, then multiplied and added in float32 in the same 8192-element blocks.
CV_Bool gets its own kernel: any non-zero byte is true, so it counts the positions where both bytes are non-zero, using v_ne / v_and on v_uint8 with two byte counters in blocks of 255 * vlanes.
ocl_dot() returns false for the 5.x depths, so UMat::dot uses the CPU kernels instead of trying to compile an OpenCL kernel with an unsupported accumulator type.
The Mat::dot documentation now describes the CV_Bool result and the float32 accumulation of CV_16F, CV_16BF and fp8.
The 16F, 16BF and fp8 kernels only need CV_SIMD, not CV_SIMD_64F, so they also use the vector path on platforms without double-precision SIMD.

On a 1024×1024 matrix (Apple M1 Pro, NEON), Mat::dot takes 0.159 ms for CV_16F / CV_16BF and 0.363 ms for the fp8 depths, compared with 0.25 ms and 1.43 ms for the scalar dotProd_ loop.
2026-11-25 15:56:47 +05:30

55 lines
1.4 KiB
C++

#include "perf_precomp.hpp"
namespace opencv_test
{
using namespace perf;
typedef tuple<MatType, int> MatType_Length_t;
typedef TestBaseWithParam<MatType_Length_t> MatType_Length;
PERF_TEST_P( MatType_Length, dot,
testing::Combine(
testing::Values( CV_8UC1, CV_8SC1, CV_16SC1, CV_16UC1, CV_32SC1, CV_32FC1, CV_64FC1 ),
testing::Values( 32, 64, 128, 256, 512, 1024 )
))
{
int type = get<0>(GetParam());
int size = get<1>(GetParam());
Mat a(size, size, type);
Mat b(size, size, type);
declare.in(a, b, WARMUP_RNG);
declare.time(100);
double product;
TEST_CYCLE_N(1000) product = a.dot(b);
SANITY_CHECK(product, 1e-6, ERROR_RELATIVE);
}
PERF_TEST_P( MatType_Length, dot_new_types,
testing::Combine(
testing::Values( CV_16FC1, CV_16BFC1, CV_BoolC1, CV_32UC1, CV_64UC1, CV_64SC1,
CV_8F_E4M3FNC1, CV_8F_E4M3FNUZC1 ),
testing::Values( 32, 64, 128, 256, 512, 1024 )
))
{
int type = get<0>(GetParam());
int size = get<1>(GetParam());
Mat a(size, size, type);
Mat b(size, size, type);
// small integers are exact in every depth
randu(a, -8, 8);
randu(b, -8, 8);
declare.in(a, b);
declare.time(100);
TEST_CYCLE_N(1000) a.dot(b);
SANITY_CHECK_NOTHING();
}
} // namespace