mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #24918 from opencv-pushbot:gitee/alalek/core_convertfp16_replacement
core(OpenCL): optimize convertTo() with CV_16F (convertFp16() replacement) #24918 relates #24909 relates #24917 relates #24892 Performance changes: - [x] 12700K (1 thread) + Intel iGPU |Name of Test|noOCL|convertFp16|convertTo BASE|convertTo PATCH| |---|:-:|:-:|:-:|:-:| |ConvertFP16FP32MatMat::OCL_Core|3.130|3.152|3.127|3.136| |ConvertFP16FP32MatUMat::OCL_Core|3.030|3.996|3.007|2.671| |ConvertFP16FP32UMatMat::OCL_Core|3.010|3.101|3.056|2.854| |ConvertFP16FP32UMatUMat::OCL_Core|3.016|3.298|2.072|2.061| |ConvertFP32FP16MatMat::OCL_Core|2.697|2.652|2.723|2.721| |ConvertFP32FP16MatUMat::OCL_Core|2.752|4.268|2.662|2.947| |ConvertFP32FP16UMatMat::OCL_Core|2.706|2.601|2.603|2.528| |ConvertFP32FP16UMatUMat::OCL_Core|2.704|3.215|1.999|1.988| Patched version is not worse than convertFp16 and convertTo baseline (except MatUMat 32->16, baseline uses CPU code+dst buffer map). There are still gaps against noOpenCL(CPU only) mode due to T-API implementation issues (unnecessary synchronization). - [x] 12700K + AMD dGPU |Name of Test|noOCL|convertFp16 dGPU|convertTo BASE dGPU|convertTo PATCH dGPU| |---|:-:|:-:|:-:|:-:| |ConvertFP16FP32MatMat::OCL_Core|3.130|3.133|3.172|3.087| |ConvertFP16FP32MatUMat::OCL_Core|3.030|1.713|9.559|1.729| |ConvertFP16FP32UMatMat::OCL_Core|3.010|6.515|6.309|4.452| |ConvertFP16FP32UMatUMat::OCL_Core|3.016|0.242|23.597|0.170| |ConvertFP32FP16MatMat::OCL_Core|2.697|2.641|2.713|2.689| |ConvertFP32FP16MatUMat::OCL_Core|2.752|4.076|6.483|4.191| |ConvertFP32FP16UMatMat::OCL_Core|2.706|9.042|16.481|1.834| |ConvertFP32FP16UMatUMat::OCL_Core|2.704|0.229|15.730|0.176| convertTo-baseline can't compile OpenCL kernel for FP16 properly - FIXED. dGPU has much more power, so results are x16-17 better than single cpu core. Patched version is not worse than convertFp16 and convertTo baseline. There are still gaps against noOpenCL(CPU only) mode due to T-API implementation issues (unnecessary synchronization) and required memory transfers. Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
This commit is contained in:
committed by
GitHub
parent
ae21368eb9
commit
40533dbf69
@@ -80,6 +80,187 @@ OCL_PERF_TEST_P(ConvertToFixture, ConvertTo,
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
|
||||
//#define RUN_CONVERTFP16
|
||||
static Size convertFP16_srcSize(4000, 4000);
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP32FP16MatMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_32F;
|
||||
const int dtype = CV_16F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
Mat src(srcSize, type);
|
||||
Mat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP32FP16MatUMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_32F;
|
||||
const int dtype = CV_16F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
Mat src(srcSize, type);
|
||||
UMat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP32FP16UMatMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_32F;
|
||||
const int dtype = CV_16F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
UMat src(srcSize, type);
|
||||
Mat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP32FP16UMatUMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_32F;
|
||||
const int dtype = CV_16F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
UMat src(srcSize, type);
|
||||
UMat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP16FP32MatMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_16F;
|
||||
const int dtype = CV_32F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
Mat src(srcSize, type);
|
||||
Mat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP16FP32MatUMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_16F;
|
||||
const int dtype = CV_32F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
Mat src(srcSize, type);
|
||||
UMat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP16FP32UMatMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_16F;
|
||||
const int dtype = CV_32F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
UMat src(srcSize, type);
|
||||
Mat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
OCL_PERF_TEST(Core, ConvertFP16FP32UMatUMat)
|
||||
{
|
||||
const Size srcSize = convertFP16_srcSize;
|
||||
const int type = CV_16F;
|
||||
const int dtype = CV_32F;
|
||||
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, type);
|
||||
checkDeviceMaxMemoryAllocSize(srcSize, dtype);
|
||||
|
||||
UMat src(srcSize, type);
|
||||
UMat dst(srcSize, dtype);
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
#ifdef RUN_CONVERTFP16
|
||||
OCL_TEST_CYCLE() convertFp16(src, dst);
|
||||
#else
|
||||
OCL_TEST_CYCLE() src.convertTo(dst, dtype);
|
||||
#endif
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
|
||||
///////////// CopyTo ////////////////////////
|
||||
|
||||
typedef Size_MatType CopyToFixture;
|
||||
|
||||
Reference in New Issue
Block a user