Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/core/include/opencv2/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ The format of half precision floating point is defined in IEEE 754-2008.

@param src input array.
@param dst output array.

@deprecated Use Mat::convertTo with CV_16F instead.
*/
CV_EXPORTS_W void convertFp16(InputArray src, OutputArray dst);

Expand Down
5 changes: 5 additions & 0 deletions modules/core/include/opencv2/core/ocl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class CV_EXPORTS_W_SIMPLE Device
CV_WRAP int singleFPConfig() const;
CV_WRAP int halfFPConfig() const;

/// true if 'cl_khr_fp64' extension is available
CV_WRAP bool hasFP64() const;
/// true if 'cl_khr_fp16' extension is available
CV_WRAP bool hasFP16() const;

CV_WRAP bool endianLittle() const;
CV_WRAP bool errorCorrectionSupport() const;

Expand Down
8 changes: 4 additions & 4 deletions modules/core/include/opencv2/core/opencl/opencl_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ static void dumpOpenCLInformation()
DUMP_MESSAGE_STDOUT(" Max memory allocation size = " << maxMemAllocSizeStr);
DUMP_CONFIG_PROPERTY("cv_ocl_current_maxMemAllocSize", device.maxMemAllocSize());

const char* doubleSupportStr = device.doubleFPConfig() > 0 ? "Yes" : "No";
const char* doubleSupportStr = device.hasFP64() ? "Yes" : "No";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what is going to happen with doubleFPConfig and halfFPConfig. Are they deprecating as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they are still needed if we want to compute with proper inf/nans support.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked doubleFPConfig in the whole opencv project and it is basically used like this,

bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0

they are still needed if we want to compute with proper inf/nans support

Did I miss anything here? Or it is in the user code instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage is not correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the correct way? All these code is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All are subject for revising.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

DUMP_MESSAGE_STDOUT(" Double support = " << doubleSupportStr);
DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.doubleFPConfig() > 0);
DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.hasFP64());

const char* halfSupportStr = device.halfFPConfig() > 0 ? "Yes" : "No";
const char* halfSupportStr = device.hasFP16() ? "Yes" : "No";
DUMP_MESSAGE_STDOUT(" Half support = " << halfSupportStr);
DUMP_CONFIG_PROPERTY("cv_ocl_current_haveHalfSupport", device.halfFPConfig() > 0);
DUMP_CONFIG_PROPERTY("cv_ocl_current_haveHalfSupport", device.hasFP16());

const char* isUnifiedMemoryStr = device.hostUnifiedMemory() ? "Yes" : "No";
DUMP_MESSAGE_STDOUT(" Host unified memory = " << isUnifiedMemoryStr);
Expand Down
181 changes: 181 additions & 0 deletions modules/core/perf/opencl/perf_matop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading