From 46c5dc035e1ac23b0dc41f19d2c892ff6af26824 Mon Sep 17 00:00:00 2001 From: Maximillian Bensch Date: Wed, 29 Apr 2020 12:53:13 +0200 Subject: [PATCH] Add clFFT_GetSize() for getting the estimated size of a plan - similar to cufftGetSize() --- include/clFFT.h | 2 ++ src/fft_setup.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/clFFT.h b/include/clFFT.h index e1f46aa..5eb803d 100644 --- a/include/clFFT.h +++ b/include/clFFT.h @@ -194,6 +194,8 @@ cl_int clFFT_1DTwistPlannar(clFFT_Plan Plan, cl_command_queue queue, cl_mem arra void clFFT_DumpPlan( clFFT_Plan plan, FILE *file); +cl_int clFFT_GetSize(clFFT_Plan Plan, size_t* workSize, cl_uint batchSize); + #ifdef __cplusplus } #endif diff --git a/src/fft_setup.cpp b/src/fft_setup.cpp index 942e852..b014ea7 100644 --- a/src/fft_setup.cpp +++ b/src/fft_setup.cpp @@ -526,3 +526,25 @@ void clFFT_DumpPlan( clFFT_Plan Plan, FILE *file) } fprintf(out, "%s\n", plan->kernel_string->c_str()); } + +cl_int +clFFT_GetSize(clFFT_Plan Plan, size_t* workSize, cl_uint batchSize) +{ + if ( workSize == NULL ) { + return CL_INVALID_VALUE; + } + cl_fft_plan *plan = (cl_fft_plan *) Plan; + *workSize = 0; + // from precomputeSinCosLUTs() called in clFFT_CreatePlanAdv() + if (plan->twiddleMethod == clFFT_TaylorLUT || plan->twiddleMethod == clFFT_BigLUT) { + *workSize += ( plan->N1 + plan->N2 ) * 2 * sizeof(float); + } + // Additional alloc's from allocateTemporaryBufferInterleaved(), called in clFFT_ExecuteInterleaved() + // or allocateTemporaryBufferPlannar() called in clFFT_ExecutePlannar() + if(plan->temp_buffer_needed) { + size_t tmpLength = plan->n.x * plan->n.y * plan->n.z * batchSize * 2 * sizeof(cl_float); + *workSize += tmpLength; + } + + return CL_SUCCESS; +} -- GitLab