1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #20203 from JoeHowse:clMath-patches

Fix dynamic loading of clBLAS and clFFT (formerly, clAmdBlas and clAmdFft)

* Fix dynamic loading of clBLAS and clFFT

* Update filenames and function names for clBLAS (formerly, clAmdBlas)

* Update filenames and function names for clFFT (formerly, clAmdFft)

* Uncomment teardown of clFFT; tear down clFFT in same way as clBLAS

* Fix generators for clBLAS and clFFT headers

* Update generators to parse recent clBLAS and clFFT library headers

* Update generators to be compatible with Python 3

* Re-generate OpenCV's clBLAS and clFFT headers

* Update function calls to match names in newly generated headers

* Disable (and comment on) teardown code for clBLAS and clFFT

* Renaming *clamd* files

* Renaming *clamdblas* files to *clblas*

* Renaming *clamdfft* files to *clfft*

* Update generator for CL headers

* Update generator to be compatible with Python 3
This commit is contained in:
JoeHowse
2021-06-07 17:24:27 -03:00
committed by GitHub
parent 286ec92967
commit 34183237ce
28 changed files with 2562 additions and 2880 deletions
+25 -23
View File
@@ -40,7 +40,7 @@
//M*/
#include "precomp.hpp"
#include "opencv2/core/opencl/runtime/opencl_clamdfft.hpp"
#include "opencv2/core/opencl/runtime/opencl_clfft.hpp"
#include "opencv2/core/opencl/runtime/opencl_core.hpp"
#include "opencl_kernels_core.hpp"
#include <map>
@@ -2420,7 +2420,7 @@ namespace cv {
#define CLAMDDFT_Assert(func) \
{ \
clAmdFftStatus s = (func); \
clfftStatus s = (func); \
CV_Assert(s == CLFFT_SUCCESS); \
}
@@ -2437,8 +2437,8 @@ class PlanCache
bool dft_scale = (flags & DFT_SCALE) != 0;
bool dft_rows = (flags & DFT_ROWS) != 0;
clAmdFftLayout inLayout = CLFFT_REAL, outLayout = CLFFT_REAL;
clAmdFftDim dim = dft_size.height == 1 || dft_rows ? CLFFT_1D : CLFFT_2D;
clfftLayout inLayout = CLFFT_REAL, outLayout = CLFFT_REAL;
clfftDim dim = dft_size.height == 1 || dft_rows ? CLFFT_1D : CLFFT_2D;
size_t batchSize = dft_rows ? dft_size.height : 1;
size_t clLengthsIn[3] = { (size_t)dft_size.width, dft_rows ? 1 : (size_t)dft_size.height, 1 };
@@ -2475,28 +2475,30 @@ class PlanCache
clStridesIn[2] = dft_rows ? clStridesIn[1] : dft_size.width * clStridesIn[1];
clStridesOut[2] = dft_rows ? clStridesOut[1] : dft_size.width * clStridesOut[1];
CLAMDDFT_Assert(clAmdFftCreateDefaultPlan(&plHandle, (cl_context)ocl::Context::getDefault().ptr(), dim, clLengthsIn))
CLAMDDFT_Assert(clfftCreateDefaultPlan(&plHandle, (cl_context)ocl::Context::getDefault().ptr(), dim, clLengthsIn))
// setting plan properties
CLAMDDFT_Assert(clAmdFftSetPlanPrecision(plHandle, doubleFP ? CLFFT_DOUBLE : CLFFT_SINGLE));
CLAMDDFT_Assert(clAmdFftSetResultLocation(plHandle, inplace ? CLFFT_INPLACE : CLFFT_OUTOFPLACE))
CLAMDDFT_Assert(clAmdFftSetLayout(plHandle, inLayout, outLayout))
CLAMDDFT_Assert(clAmdFftSetPlanBatchSize(plHandle, batchSize))
CLAMDDFT_Assert(clAmdFftSetPlanInStride(plHandle, dim, clStridesIn))
CLAMDDFT_Assert(clAmdFftSetPlanOutStride(plHandle, dim, clStridesOut))
CLAMDDFT_Assert(clAmdFftSetPlanDistance(plHandle, clStridesIn[dim], clStridesOut[dim]))
CLAMDDFT_Assert(clfftSetPlanPrecision(plHandle, doubleFP ? CLFFT_DOUBLE : CLFFT_SINGLE));
CLAMDDFT_Assert(clfftSetResultLocation(plHandle, inplace ? CLFFT_INPLACE : CLFFT_OUTOFPLACE))
CLAMDDFT_Assert(clfftSetLayout(plHandle, inLayout, outLayout))
CLAMDDFT_Assert(clfftSetPlanBatchSize(plHandle, batchSize))
CLAMDDFT_Assert(clfftSetPlanInStride(plHandle, dim, clStridesIn))
CLAMDDFT_Assert(clfftSetPlanOutStride(plHandle, dim, clStridesOut))
CLAMDDFT_Assert(clfftSetPlanDistance(plHandle, clStridesIn[dim], clStridesOut[dim]))
float scale = dft_scale ? 1.0f / (dft_rows ? dft_size.width : dft_size.area()) : 1.0f;
CLAMDDFT_Assert(clAmdFftSetPlanScale(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD, scale))
CLAMDDFT_Assert(clfftSetPlanScale(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD, scale))
// ready to bake
cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &queue, NULL, NULL))
CLAMDDFT_Assert(clfftBakePlan(plHandle, 1, &queue, NULL, NULL))
}
~FftPlan()
{
// clAmdFftDestroyPlan(&plHandle);
// Do not tear down clFFT.
// The user application may still use clFFT even after OpenCV is unloaded.
/*clfftDestroyPlan(&plHandle);*/
}
friend class PlanCache;
@@ -2510,7 +2512,7 @@ class PlanCache
FftType fftType;
cl_context context;
clAmdFftPlanHandle plHandle;
clfftPlanHandle plHandle;
};
public:
@@ -2519,8 +2521,8 @@ public:
CV_SINGLETON_LAZY_INIT_REF(PlanCache, new PlanCache())
}
clAmdFftPlanHandle getPlanHandle(const Size & dft_size, int src_step, int dst_step, bool doubleFP,
bool inplace, int flags, FftType fftType)
clfftPlanHandle getPlanHandle(const Size & dft_size, int src_step, int dst_step, bool doubleFP,
bool inplace, int flags, FftType fftType)
{
cl_context currentContext = (cl_context)ocl::Context::getDefault().ptr();
@@ -2620,13 +2622,13 @@ static bool ocl_dft_amdfft(InputArray _src, OutputArray _dst, int flags)
UMat src = _src.getUMat(), dst = _dst.getUMat();
bool inplace = src.u == dst.u;
clAmdFftPlanHandle plHandle = PlanCache::getInstance().
clfftPlanHandle plHandle = PlanCache::getInstance().
getPlanHandle(ssize, (int)src.step, (int)dst.step,
depth == CV_64F, inplace, flags, fftType);
// get the bufferSize
size_t bufferSize = 0;
CLAMDDFT_Assert(clAmdFftGetTmpBufSize(plHandle, &bufferSize))
CLAMDDFT_Assert(clfftGetTmpBufSize(plHandle, &bufferSize))
UMat tmpBuffer(1, (int)bufferSize, CV_8UC1);
cl_mem srcarg = (cl_mem)src.handle(ACCESS_READ);
@@ -2635,9 +2637,9 @@ static bool ocl_dft_amdfft(InputArray _src, OutputArray _dst, int flags)
cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
cl_event e = 0;
CLAMDDFT_Assert(clAmdFftEnqueueTransform(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD,
1, &queue, 0, NULL, &e,
&srcarg, &dstarg, (cl_mem)tmpBuffer.handle(ACCESS_RW)))
CLAMDDFT_Assert(clfftEnqueueTransform(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD,
1, &queue, 0, NULL, &e,
&srcarg, &dstarg, (cl_mem)tmpBuffer.handle(ACCESS_RW)))
tmpBuffer.addref();
clSetEventCallback(e, CL_COMPLETE, oclCleanupCallback, tmpBuffer.u);