1 /* ************************************************************************
2  * Copyright 2013-2015 Advanced Micro Devices, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  * ************************************************************************/
16 
17 
18 /*! @file clFFT.h
19  * clFFT.h defines all the public interfaces and types that are used by clFFT clients
20  * This is the only public header file that should be consumed by clFFT clients.  It is written to adhere to native "C"
21  * interfaces to make clFFT library as portable as possible; it should be callable from C, C++, .NET and Fortran,
22  * either with the proper linking or using wrapper classes.
23  *
24  */
25 
26 #pragma once
27 #if !defined( CLFFT_H )
28 #define CLFFT_H
29 
30 #if defined(__APPLE__) || defined(__MACOSX)
31 	#include <OpenCL/cl.h>
32 #else
33 	#include <CL/cl.h>
34 #endif
35 
36 #include "clFFT.version.h"
37 
38 /*! This preprocessor definition is the standard way to export APIs
39  *  from a DLL simpler. All files within this DLL are compiled with the CLFFT_EXPORTS
40  *  symbol defined on the command line. This symbol must not be defined on any project
41  *  that uses this DLL. This ensures source files of any other project that include this file see
42  *  clfft functions as being imported from a DLL, whereas the DLL sees symbols
43  *  defined with this macro as being exported.
44  */
45 #if defined( _WIN32 )
46 	#if !defined( __cplusplus )
47 		#define inline __inline
48 	#endif
49 
50     #if defined( CLFFT_STATIC )
51         #define CLFFTAPI
52     #elif defined( CLFFT_EXPORTS )
53         #define CLFFTAPI __declspec( dllexport )
54     #else
55         #define CLFFTAPI __declspec( dllimport )
56     #endif
57 #else
58 	#define CLFFTAPI
59 #endif
60 
61 /*	In general, you cannot use namespaces for strict C compliance, so we prefix our public accessible names
62  *	with the string clfft
63  */
64 
65 /*	All functions return pre-defined error codes, and do NOT throw exceptions to the caller.
66  */
67 
68 /*!  @brief clfft error codes definition(incorporating OpenCL error definitions)
69  *
70  *   This enumeration is a superset of the OpenCL error codes.  For example, CL_OUT_OF_HOST_MEMORY,
71  *   which is defined in cl.h is aliased as CLFFT_OUT_OF_HOST_MEMORY.  The set of basic OpenCL
72  *   error codes is extended to add extra values specific to the clfft package.
73  */
74 enum clfftStatus_
75 {
76 	CLFFT_INVALID_GLOBAL_WORK_SIZE			= CL_INVALID_GLOBAL_WORK_SIZE,
77 	CLFFT_INVALID_MIP_LEVEL					= CL_INVALID_MIP_LEVEL,
78 	CLFFT_INVALID_BUFFER_SIZE				= CL_INVALID_BUFFER_SIZE,
79 	CLFFT_INVALID_GL_OBJECT					= CL_INVALID_GL_OBJECT,
80 	CLFFT_INVALID_OPERATION					= CL_INVALID_OPERATION,
81 	CLFFT_INVALID_EVENT						= CL_INVALID_EVENT,
82 	CLFFT_INVALID_EVENT_WAIT_LIST			= CL_INVALID_EVENT_WAIT_LIST,
83 	CLFFT_INVALID_GLOBAL_OFFSET				= CL_INVALID_GLOBAL_OFFSET,
84 	CLFFT_INVALID_WORK_ITEM_SIZE			= CL_INVALID_WORK_ITEM_SIZE,
85 	CLFFT_INVALID_WORK_GROUP_SIZE			= CL_INVALID_WORK_GROUP_SIZE,
86 	CLFFT_INVALID_WORK_DIMENSION			= CL_INVALID_WORK_DIMENSION,
87 	CLFFT_INVALID_KERNEL_ARGS				= CL_INVALID_KERNEL_ARGS,
88 	CLFFT_INVALID_ARG_SIZE					= CL_INVALID_ARG_SIZE,
89 	CLFFT_INVALID_ARG_VALUE					= CL_INVALID_ARG_VALUE,
90 	CLFFT_INVALID_ARG_INDEX					= CL_INVALID_ARG_INDEX,
91 	CLFFT_INVALID_KERNEL					= CL_INVALID_KERNEL,
92 	CLFFT_INVALID_KERNEL_DEFINITION			= CL_INVALID_KERNEL_DEFINITION,
93 	CLFFT_INVALID_KERNEL_NAME				= CL_INVALID_KERNEL_NAME,
94 	CLFFT_INVALID_PROGRAM_EXECUTABLE		= CL_INVALID_PROGRAM_EXECUTABLE,
95 	CLFFT_INVALID_PROGRAM					= CL_INVALID_PROGRAM,
96 	CLFFT_INVALID_BUILD_OPTIONS				= CL_INVALID_BUILD_OPTIONS,
97 	CLFFT_INVALID_BINARY					= CL_INVALID_BINARY,
98 	CLFFT_INVALID_SAMPLER					= CL_INVALID_SAMPLER,
99 	CLFFT_INVALID_IMAGE_SIZE				= CL_INVALID_IMAGE_SIZE,
100 	CLFFT_INVALID_IMAGE_FORMAT_DESCRIPTOR	= CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,
101 	CLFFT_INVALID_MEM_OBJECT				= CL_INVALID_MEM_OBJECT,
102 	CLFFT_INVALID_HOST_PTR					= CL_INVALID_HOST_PTR,
103 	CLFFT_INVALID_COMMAND_QUEUE				= CL_INVALID_COMMAND_QUEUE,
104 	CLFFT_INVALID_QUEUE_PROPERTIES			= CL_INVALID_QUEUE_PROPERTIES,
105 	CLFFT_INVALID_CONTEXT					= CL_INVALID_CONTEXT,
106 	CLFFT_INVALID_DEVICE					= CL_INVALID_DEVICE,
107 	CLFFT_INVALID_PLATFORM					= CL_INVALID_PLATFORM,
108 	CLFFT_INVALID_DEVICE_TYPE				= CL_INVALID_DEVICE_TYPE,
109 	CLFFT_INVALID_VALUE						= CL_INVALID_VALUE,
110 	CLFFT_MAP_FAILURE						= CL_MAP_FAILURE,
111 	CLFFT_BUILD_PROGRAM_FAILURE				= CL_BUILD_PROGRAM_FAILURE,
112 	CLFFT_IMAGE_FORMAT_NOT_SUPPORTED		= CL_IMAGE_FORMAT_NOT_SUPPORTED,
113 	CLFFT_IMAGE_FORMAT_MISMATCH				= CL_IMAGE_FORMAT_MISMATCH,
114 	CLFFT_MEM_COPY_OVERLAP					= CL_MEM_COPY_OVERLAP,
115 	CLFFT_PROFILING_INFO_NOT_AVAILABLE		= CL_PROFILING_INFO_NOT_AVAILABLE,
116 	CLFFT_OUT_OF_HOST_MEMORY				= CL_OUT_OF_HOST_MEMORY,
117 	CLFFT_OUT_OF_RESOURCES					= CL_OUT_OF_RESOURCES,
118 	CLFFT_MEM_OBJECT_ALLOCATION_FAILURE		= CL_MEM_OBJECT_ALLOCATION_FAILURE,
119 	CLFFT_COMPILER_NOT_AVAILABLE			= CL_COMPILER_NOT_AVAILABLE,
120 	CLFFT_DEVICE_NOT_AVAILABLE				= CL_DEVICE_NOT_AVAILABLE,
121 	CLFFT_DEVICE_NOT_FOUND					= CL_DEVICE_NOT_FOUND,
122 	CLFFT_SUCCESS							= CL_SUCCESS,
123 	//-------------------------- Extended status codes for clfft ----------------------------------------
124 	CLFFT_BUGCHECK =  4*1024,	/*!< Bugcheck. */
125 	CLFFT_NOTIMPLEMENTED,		/*!< Functionality is not implemented yet. */
126 	CLFFT_TRANSPOSED_NOTIMPLEMENTED, /*!< Transposed functionality is not implemented for this transformation. */
127 	CLFFT_FILE_NOT_FOUND,		/*!< Tried to open an existing file on the host system, but failed. */
128 	CLFFT_FILE_CREATE_FAILURE,	/*!< Tried to create a file on the host system, but failed. */
129 	CLFFT_VERSION_MISMATCH,		/*!< Version conflict between client and library. */
130 	CLFFT_INVALID_PLAN,			/*!< Requested plan could not be found. */
131 	CLFFT_DEVICE_NO_DOUBLE,		/*!< Double precision not supported on this device. */
132 	CLFFT_DEVICE_MISMATCH,		/*!< Attempt to run on a device using a plan baked for a different device. */
133 	CLFFT_ENDSTATUS				/* The last value of the enum, and marks the length of clfftStatus. */
134 };
135 typedef enum clfftStatus_ clfftStatus;
136 
137 /*!  @brief The dimension of the input and output buffers that is fed into all FFT transforms */
138 typedef enum clfftDim_
139 {
140 	CLFFT_1D		= 1,		/*!< 1 Dimensional FFT transform (default). */
141 	CLFFT_2D,					/*!< 2 Dimensional FFT transform. */
142 	CLFFT_3D,					/*!< 3 Dimensional FFT transform. */
143 	ENDDIMENSION			/*!< The last value of the enum, and marks the length of clfftDim. */
144 } clfftDim;
145 
146 /*!  @brief Specify the expected layouts of the buffers */
147 typedef enum clfftLayout_
148 {
149 	CLFFT_COMPLEX_INTERLEAVED	= 1,	/*!< An array of complex numbers, with real and imaginary components together (default). */
150 	CLFFT_COMPLEX_PLANAR,				/*!< Separate arrays of real components and imaginary components. */
151 	CLFFT_HERMITIAN_INTERLEAVED,		/*!< Compressed form of complex numbers; complex-conjugates are not stored, real and imaginary components are stored in the same array. */
152 	CLFFT_HERMITIAN_PLANAR,				/*!< Compressed form of complex numbers; complex-conjugates are not stored, real and imaginary components are stored in separate arrays. */
153 	CLFFT_REAL,							/*!< An array of real numbers, with no corresponding imaginary components. */
154 	ENDLAYOUT			/*!< The last value of the enum, and marks the length of clfftLayout. */
155 } clfftLayout;
156 
157 /*!  @brief Specify the expected precision of each FFT.
158  */
159 typedef enum clfftPrecision_
160 {
161 	CLFFT_SINGLE	= 1,	/*!< An array of complex numbers, with real and imaginary components saved as floats (default). */
162 	CLFFT_DOUBLE,			/*!< An array of complex numbers, with real and imaginary components saved as doubles. */
163 	CLFFT_SINGLE_FAST,		/*!< Faster implementation preferred. */
164 	CLFFT_DOUBLE_FAST,		/*!< Faster implementation preferred. */
165 	ENDPRECISION	/*!< The last value of the enum, and marks the length of clfftPrecision. */
166 } clfftPrecision;
167 
168 /*!  @brief Specify the expected direction of each FFT, time or the frequency domains */
169 typedef enum clfftDirection_
170 {
171 	CLFFT_FORWARD	= -1,		/*!< FFT transform from time to frequency domain. */
172 	CLFFT_BACKWARD	= 1,		/*!< FFT transform from frequency to time domain. */
173 	CLFFT_MINUS		= -1,		/*!< Alias for the forward transform. */
174 	CLFFT_PLUS		= 1,		/*!< Alias for the backward transform. */
175 	ENDDIRECTION			/*!< The last value of the enum, and marks the length of clfftDirection. */
176 } clfftDirection;
177 
178 /*!  @brief Specify wheter the input buffers are overwritten with results */
179 typedef enum clfftResultLocation_
180 {
181 	CLFFT_INPLACE		= 1,		/*!< Input and output buffers are the same (default). */
182 	CLFFT_OUTOFPLACE,				/*!< Input and output buffers are separate. */
183 	ENDPLACE				/*!< The last value of the enum, and marks the length of clfftPlaceness. */
184 } clfftResultLocation;
185 
186 /*! @brief Determines whether the result is returned in original order. It is valid only for
187 dimensions greater than 1. */
188 typedef enum clfftResultTransposed_ {
189 	CLFFT_NOTRANSPOSE = 1,		/*!< The result is returned in the original order (default) */
190 	CLFFT_TRANSPOSED,			/*!< The result is transposed where transpose kernel is supported (possibly faster) */
191 	ENDTRANSPOSED			/*!< The last value of the enum, and marks the length of clfftResultTransposed */
192 } clfftResultTransposed;
193 
194 /*! 	BitMasks to be used with clfftSetupData.debugFlags */
195 #define CLFFT_DUMP_PROGRAMS 0x1
196 
197 /*! @brief Data structure that can be passed to clfftSetup() to control the behavior of the FFT runtime
198  *  @details This structure contains values that can be initialized before instantiation of the FFT runtime
199  *  with ::clfftSetup().  To initialize this structure, pass a pointer to a user struct to ::clfftInitSetupData( ),
200  *  which clears the structure and sets the version member variables to the current values.
201  */
202 struct clfftSetupData_
203 {
204 	cl_uint major;		/*!< Major version number of the project; signifies possible major API changes. */
205 	cl_uint minor;		/*!< Minor version number of the project; minor API changes that can break backward compatibility. */
206 	cl_uint patch;		/*!< Patch version number of the project; always incrementing number, signifies change over time. */
207 
208 	/*! 	Bitwise flags that control the behavior of library debug logic. */
209 	cl_ulong debugFlags;  /*! This must be set to zero, except when debugging the clfft library.
210 	                       *  <p> debugFlags can be set to CLFFT_DUMP_PROGRAMS, in which case the dynamically generated OpenCL kernels are
211 	                       *  written to text files in the current working directory.  These files have a *.cl suffix.
212 	                       */
213 };
214 typedef struct clfftSetupData_ clfftSetupData;
215 
216 /*! @brief Type of Callback function.
217 */
218 typedef enum clfftCallbackType_
219 {
220 	PRECALLBACK,	/*!< Callback function is invoked only once for every point of input at the beginning of FFT transform. */
221 	POSTCALLBACK	/*!< Callback function is invoked only once for every point of output at the end of FFT transform. */
222 }clfftCallbackType;
223 
224 /*!  @brief An abstract handle to the object that represents the state of the FFT(s) */
225 typedef size_t clfftPlanHandle;
226 
227 #ifdef __cplusplus
228 extern "C" {
229 #endif
230 	/*! @brief Initialize a clfftSetupData struct for the client
231 	 *  @details clfftSetupData is passed to clfftSetup to control behavior of the FFT runtime.
232 	 *  @param[out] setupData Data structure is cleared and initialized with version information and default values
233 	 *  @return Enum describes the error condition; superset of OpenCL error codes
234 	 */
235 	CLFFTAPI clfftStatus clfftInitSetupData( clfftSetupData* setupData );
236 
237 
238 	/*! @brief Initialize the internal FFT resources.
239 	 *  @details The internal resources include FFT implementation caches kernels, programs, and buffers.
240 	 *  @param[in] setupData Data structure that is passed into the setup routine to control FFT generation behavior
241 	 * 	and debug functionality
242 	 *  @return Enum describing error condition; superset of OpenCL error codes
243 	 */
244 	CLFFTAPI clfftStatus	clfftSetup( const clfftSetupData* setupData );
245 
246 	/*! @brief Release all internal resources.
247 	 *  @details Called when client is done with the FFT library, allowing the library to destroy all resources it has cached
248 	 *  @return Enum describing error condition; superset of OpenCL error codes
249 	 */
250 	CLFFTAPI clfftStatus	clfftTeardown( );
251 
252 	/*! @brief Query the FFT library for version information
253 	 *  @details Returns the major, minor and patch version numbers associated with the FFT library
254 	 *  @param[out] major Major functionality change
255 	 *  @param[out] minor Minor functionality change
256 	 *  @param[out] patch Bug fixes, documentation changes, no new features introduced
257 	 *  @return Enum describing error condition; superset of OpenCL error codes
258 	 */
259 	CLFFTAPI clfftStatus	clfftGetVersion( cl_uint* major, cl_uint* minor, cl_uint* patch );
260 
261 	/*! @brief Create a plan object initialized entirely with default values.
262 	 *  @details A plan is a repository of state for calculating FFT's.  Allows the runtime to pre-calculate kernels, programs
263 	 * 	and buffers and associate them with buffers of specified dimensions.
264 	 *  @param[out] plHandle Handle to the newly created plan
265 	 *  @param[in] context Client is responsible for providing an OpenCL context for the plan
266 	 *  @param[in] dim Dimensionality of the FFT transform; describes how many elements are in the array
267 	 *  @param[in] clLengths An array of length of size 'dim';  each array value describes the length of each dimension
268 	 *  @return Enum describing error condition; superset of OpenCL error codes
269 	 */
270 	CLFFTAPI clfftStatus	clfftCreateDefaultPlan( clfftPlanHandle* plHandle, cl_context context, const clfftDim dim,
271 								const size_t* clLengths );
272 
273 	/*! @brief Create a copy of an existing plan.
274 	 *  @details This API allows a client to create a new plan based upon an existing plan.  This function can be used to
275 	 *  quickly create plans that are similar, but may differ slightly.
276 	 *  @param[out] out_plHandle Handle to the newly created plan that is based on in_plHandle
277 	 *  @param[in] new_context Client is responsible for providing a new context for the new plan
278 	 *  @param[in] in_plHandle Handle to a previously created plan that is to be copied
279 	 *  @return Enum describing error condition; superset of OpenCL error codes
280 	 */
281 	CLFFTAPI clfftStatus	clfftCopyPlan( clfftPlanHandle* out_plHandle, cl_context new_context, clfftPlanHandle in_plHandle );
282 
283 	/*! @brief Prepare the plan for execution.
284 	 *  @details After all plan parameters are set, the client has the option of 'baking' the plan, which informs the runtime that
285 	 *  no more change to the parameters of the plan is expected, and the OpenCL kernels can be compiled.  This optional function
286 	 *  allows the client application to perform the OpenCL kernel compilation when the application is initialized instead of during the first
287 	 *  execution.
288 	 *  At this point, the clfft runtime applies all implimented optimizations, including
289 	 *  running kernel experiments on the devices in the plan context.
290 	 *  <p>  This function takes a long time to execute. If a plan is not baked before being executed,
291 	 *  the first call to clfftEnqueueTransform takes a long time to execute.
292 	 *  <p>  If any significant parameter of a plan is changed after the plan is baked (by a subsequent call to any one of
293 	 *  the functions that has the prefix "clfftSetPlan"), it is not considered an error.  Instead, the plan reverts back to
294 	 *  the unbaked state, discarding the benefits of the baking operation.
295 	 *  @param[in] plHandle Handle to a previously created plan
296 	 *  @param[in] numQueues Number of command queues in commQueueFFT; 0 is a valid value, in which case the client does not want
297 	 * 	the runtime to run load experiments and only pre-calculate state information
298 	 *  @param[in] commQueueFFT An array of cl_command_queues created by the client; the command queues must be a proper subset of
299 	 * 	the devices included in the plan context
300 	 *  @param[in] pfn_notify A function pointer to a notification routine. The notification routine is a callback function that
301 	 *  an application can register and is called when the program executable is built (successfully or unsuccessfully).
302 	 *  Currently, this parameter MUST be NULL or nullptr.
303 	 *  @param[in] user_data Passed as an argument when pfn_notify is called.
304 	 *  Currently, this parameter MUST be NULL or nullptr.
305 	 *  @return Enum describing error condition; superset of OpenCL error codes
306 	 */
307 	CLFFTAPI clfftStatus	clfftBakePlan( clfftPlanHandle plHandle, cl_uint numQueues, cl_command_queue* commQueueFFT,
308 							void (CL_CALLBACK *pfn_notify)(clfftPlanHandle plHandle, void *user_data), void* user_data );
309 
310 	/*! @brief Release the resources of a plan.
311 	 *  @details A plan may include resources, such as kernels, programs, and buffers that consume memory.  When a plan
312 	 *  is no more needed, the client must release the plan.
313 	 *  @param[in,out] plHandle Handle to a previously created plan
314 	 *  @return Enum describing error condition; superset of OpenCL error codes
315 	 */
316 	CLFFTAPI clfftStatus	clfftDestroyPlan( clfftPlanHandle* plHandle );
317 
318 	/*! @brief Retrieve the OpenCL context of a previously created plan.
319 	 *  @details The user must pass a reference to a cl_context variable, which is modified to point to a
320 	 *  context set in the specified plan.
321 	 *  @param[in] plHandle Handle to a previously created plan
322 	 *  @param[out] context Reference to the user allocated cl_context, which points to context set in the plan
323 	 *  @return Enum describing error condition; superset of OpenCL error codes
324 	 */
325 	CLFFTAPI clfftStatus	clfftGetPlanContext( const clfftPlanHandle plHandle, cl_context* context );
326 
327 	/*! @brief Retrieve the floating point precision of the FFT data
328 	 *  @details The user must pass a reference to a clfftPrecision variable, which is set to the
329 	 *  precision of the FFT complex data in the plan.
330 	 *  @param[in] plHandle Handle to a previously created plan
331 	 *  @param[out] precision Reference to the user clfftPrecision enum
332 	 *  @return Enum describing error condition; superset of OpenCL error codes
333 	 */
334 	CLFFTAPI clfftStatus	clfftGetPlanPrecision( const clfftPlanHandle plHandle, clfftPrecision* precision );
335 
336 	/*! @brief Set the floating point precision of the FFT data
337 	 *  @details Sets the floating point precision of the FFT complex data in the plan.
338 	 *  @param[in] plHandle Handle to a previously created plan
339 	 *  @param[in] precision Reference to the user clfftPrecision enum
340 	 *  @return Enum describing error condition; superset of OpenCL error codes
341 	 */
342 	CLFFTAPI clfftStatus	clfftSetPlanPrecision( clfftPlanHandle plHandle, clfftPrecision precision );
343 
344 	/*! @brief Retrieve the scaling factor that is applied to the FFT data
345 	 *  @details The user must pass a reference to a cl_float variable, which is set to the
346 	 *  floating point scaling factor that is multiplied across the FFT data.
347 	 *  @param[in] plHandle Handle to a previously created plan
348 	 *  @param[in] dir Direction of the applied scaling factor
349 	 *  @param[out] scale Reference to the user cl_float variable
350 	 *  @return Enum describing error condition; superset of OpenCL error codes
351 	 */
352 	CLFFTAPI clfftStatus	clfftGetPlanScale( const clfftPlanHandle plHandle, clfftDirection dir, cl_float* scale );
353 
354 	/*! @brief Set the scaling factor that is applied to the FFT data
355 	 *  @details Sets the floating point scaling factor that is
356 	 *  multiplied across the FFT data.
357 	 *  @param[in] plHandle Handle to a previously created plan
358 	 *  @param[in] dir Direction of the applied scaling factor
359 	 *  @param[in] scale Reference to the user cl_float variable
360 	 *  @return Enum describing error condition; superset of OpenCL error codes
361 	 */
362 	CLFFTAPI clfftStatus	clfftSetPlanScale( clfftPlanHandle plHandle, clfftDirection dir, cl_float scale );
363 
364 	/*! @brief Retrieve the number of discrete arrays that the plan can concurrently handle
365 	 *  @details The user must pass a reference to a cl_uint variable, which is set to the
366 	 *  number of discrete arrays (1D or 2D) that is batched together for the plan
367 	 *  @param[in] plHandle Handle to a previously created plan
368 	 *  @param[out] batchSize Number of discrete FFTs performed
369 	 *  @return Enum describing error condition; superset of OpenCL error codes
370 	 */
371 	CLFFTAPI clfftStatus	clfftGetPlanBatchSize( const clfftPlanHandle plHandle, size_t* batchSize );
372 
373 	/*! @brief Set the number of discrete arrays that the plan can concurrently handle
374 	 *  @details Sets the plan property which sets the number of discrete arrays (1D or 2D)
375 	 *  that is batched together for the plan
376 	 *  @param[in] plHandle Handle to a previously created plan
377 	 *  @param[in] batchSize Number of discrete FFTs performed
378 	 *  @return Enum describing error condition; superset of OpenCL error codes
379 	 */
380 	CLFFTAPI clfftStatus	clfftSetPlanBatchSize( clfftPlanHandle plHandle, size_t batchSize );
381 
382 	/*! @brief Retrieve the dimensionality of the data that is transformed
383 	 *  @details Queries a plan object and retrieves the value of the dimensionality that the plan is set for.  A size is returned to
384 	 *  help the client allocate sufficient storage to hold the dimensions in a further call to clfftGetPlanLength
385 	 *  @param[in] plHandle Handle to a previously created plan
386 	 *  @param[out] dim The dimensionality of the FFT to be transformed
387 	 *  @param[out] size Value to allocate an array to hold the FFT dimensions.
388 	 *  @return Enum describing error condition; superset of OpenCL error codes
389 	 */
390 	CLFFTAPI clfftStatus	clfftGetPlanDim( const clfftPlanHandle plHandle, clfftDim* dim, cl_uint* size );
391 
392 	/*! @brief Set the dimensionality of the data that is transformed
393 	 *  @details Set the dimensionality of the data that is transformed by the plan
394 	 *  @param[in] plHandle Handle to a previously created plan
395 	 *  @param[in] dim The dimensionality of the FFT to be transformed
396 	 *  @return Enum describing error condition; superset of OpenCL error codes
397 	 */
398 	CLFFTAPI clfftStatus	clfftSetPlanDim( clfftPlanHandle plHandle, const clfftDim dim );
399 
400 	/*! @brief Retrieve the length of each dimension of the FFT
401 	 *  @details The user must pass a reference to a size_t array, which is set to the
402 	 *  length of each discrete dimension of the FFT
403 	 *  @param[in] plHandle Handle to a previously created plan
404 	 *  @param[in] dim Dimension of the FFT; describes how many elements are in the clLengths array
405 	 *  @param[out] clLengths An array of length of size 'dim';  each array value describes the length of each dimension
406 	 *  @return Enum describing error condition; superset of OpenCL error codes
407 	 */
408 	CLFFTAPI clfftStatus	clfftGetPlanLength( const clfftPlanHandle plHandle, const clfftDim dim, size_t* clLengths );
409 
410 	/*! @brief Set the length of each dimension of the FFT
411 	 *  @details Sets the plan property which is the length of each discrete dimension of the FFT
412 	 *  @param[in] plHandle Handle to a previously created plan
413 	 *  @param[in] dim The dimension of the FFT; describes how many elements are in the clLengths array
414 	 *  @param[in] clLengths An array of length of size 'dim';  each array value describes the length of each dimension
415 	 *  @return Enum describing error condition; superset of OpenCL error codes
416 	 */
417 	CLFFTAPI clfftStatus	clfftSetPlanLength( clfftPlanHandle plHandle, const clfftDim dim, const size_t* clLengths );
418 
419 	/*! @brief Retrieve the distance between consecutive elements of input buffers in each dimension.
420 	 *  @details Depending on how the dimension is set in the plan (for 2D or 3D FFT), strideY or strideZ can be safely
421 	 *  ignored
422 	 *  @param[in] plHandle Handle to a previously created plan
423 	 *  @param[in] dim The dimension of the stride parameters; provides the number of elements in the array
424 	 *  @param[out] clStrides An array of strides, of size 'dim'.
425 	 */
426 	CLFFTAPI clfftStatus	clfftGetPlanInStride( const clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides );
427 
428 	/*! @brief Set the distance between consecutive elements of input buffers in each dimension.
429 	 *  @details Set the plan properties which is the distance between elements in all dimensions of the input buffer
430 	 *  (units are in terms of clfftPrecision)
431 	 *  @param[in] plHandle Handle to a previously created plan
432 	 *  @param[in] dim The dimension of the stride parameters; provides the number of elements in the clStrides array
433 	 *  @param[in] clStrides An array of strides of size 'dim'. Usually, strideX=1 so that successive elements in the first dimension are stored contiguously.
434 	 * 	Typically, strideY=LenX and strideZ=LenX*LenY with the successive elements in the second and third dimensions stored in packed format.
435 	 *  See  @ref DistanceStridesandPitches for details.
436 	 */
437 	CLFFTAPI clfftStatus	clfftSetPlanInStride( clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides );
438 
439 	/*! @brief Retrieve the distance between consecutive elements of output buffers in each dimension.
440 	 *  @details Depending on how the dimension is set in the plan (for 2D or 3D FFT), strideY or strideZ can be safely
441 	 *  ignored
442 	 *  @param[in] plHandle Handle to a previously created plan
443 	 *  @param[in] dim The dimension of the stride parameters; provides the number of elements in the clStrides array
444 	 *  @param[out] clStrides An array of strides, of size 'dim'.
445 	 */
446 	CLFFTAPI clfftStatus	clfftGetPlanOutStride( const clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides );
447 
448 	/*! @brief Set the distance between consecutive elements of output buffers in a dimension.
449 	 *  @details Sets the plan properties which is the distance between elements in all dimensions of the output buffer
450 	 *  (units are in terms of clfftPrecision)
451 	 *  @param[in] plHandle Handle to a previously created plan
452 	 *  @param[in] dim The dimension of the stride parameters; provides the number of elements in the clStrides array
453 	 *  @param[in] clStrides An array of strides of size 'dim'.  Usually, strideX=1 so that successive elements in the first dimension are stored contiguously.
454 	 * 	Typically, strideY=LenX and strideZ=LenX*LenY cause the successive elements in the second and third dimensions be stored in packed format.
455 	 *  @sa clfftSetPlanInStride
456 	 */
457 	CLFFTAPI clfftStatus	clfftSetPlanOutStride( clfftPlanHandle plHandle, const clfftDim dim, size_t* clStrides );
458 
459 	/*! @brief Retrieve the distance between array objects
460 	 *  @details Pitch is the distance between each discrete array object in an FFT array. This is only used
461 	 *  for 'array' dimensions in clfftDim; see clfftSetPlanDimension (units are in terms of clfftPrecision)
462 	 *  @param[in] plHandle Handle to a previously created plan
463 	 *  @param[out] iDist The distance between the beginning elements of the discrete array objects in input buffer.
464 	 *  For contiguous arrays in memory, iDist=(strideX*strideY*strideZ)
465 	 *  @param[out] oDist The distance between the beginning elements of the discrete array objects in output buffer.
466 	 *  For contiguous arrays in memory, oDist=(strideX*strideY*strideZ)
467 	 */
468 	CLFFTAPI clfftStatus	clfftGetPlanDistance( const clfftPlanHandle plHandle, size_t* iDist, size_t* oDist );
469 
470 	/*! @brief Set the distance between array objects
471 	 *  @details Pitch is the distance between each discrete array object in an FFT array. This is only used
472 	 *  for 'array' dimensions in clfftDim; see clfftSetPlanDimension (units are in terms of clfftPrecision)
473 	 *  @param[in] plHandle Handle to a previously created plan
474 	 *  @param[out] iDist The distance between the beginning elements of the discrete array objects in input buffer.
475 	 *  For contiguous arrays in memory, iDist=(strideX*strideY*strideZ)
476 	 *  @param[out] oDist The distance between the beginning elements of the discrete array objects in output buffer.
477 	 *  For contiguous arrays in memory, oDist=(strideX*strideY*strideZ)
478 	 */
479 	CLFFTAPI clfftStatus	clfftSetPlanDistance( clfftPlanHandle plHandle, size_t iDist, size_t oDist );
480 
481 	/*! @brief Retrieve the expected layout of the input and output buffers
482 	 *  @details Input and output buffers can be filled with either Hermitian, complex, or real numbers.  Complex numbers are stored
483 	 *  in various layouts; this function retrieves the layouts used by input and output
484 	 *  @param[in] plHandle Handle to a previously created plan
485 	 *  @param[out] iLayout Indicates how the input buffers are laid out in memory
486 	 *  @param[out] oLayout Indicates how the output buffers are laid out in memory
487 	 */
488 	CLFFTAPI clfftStatus	clfftGetLayout( const clfftPlanHandle plHandle, clfftLayout* iLayout, clfftLayout* oLayout );
489 
490 	/*! @brief Set the expected layout of the input and output buffers
491 	 *  @details Input and output buffers can be filled with either Hermitian, complex, or real numbers.  Complex numbers can be stored
492 	 *  in various layouts; this function informs the library what layouts to use for input and output
493 	 *  @param[in] plHandle Handle to a previously created plan
494 	 *  @param[in] iLayout Indicates how the input buffers are laid out in memory
495 	 *  @param[in] oLayout Indicates how the output buffers are laid out in memory
496 	 */
497 	CLFFTAPI clfftStatus	clfftSetLayout( clfftPlanHandle plHandle, clfftLayout iLayout, clfftLayout oLayout );
498 
499 	/*! @brief Retrieve whether the input buffers are to be overwritten with results
500 	 *  @details If the setting performs an in-place transform, the input buffers are overwritten with the results of the
501 	 *  transform.  If the setting performs an out-of-place transforms, the library looks for separate output buffers
502 	 *  on the Enqueue call.
503 	 *  @param[in] plHandle Handle to a previously created plan
504 	 *  @param[out] placeness Informs the library to either overwrite the input buffers with results or to write them in separate output buffers
505 	 */
506 	CLFFTAPI clfftStatus	clfftGetResultLocation( const clfftPlanHandle plHandle, clfftResultLocation* placeness );
507 
508 	/*! @brief Set whether the input buffers are to be overwritten with results
509 	 *  @details If the setting performs an in-place transform, the input buffers are overwritten with the results of the
510 	 *  transform.  If the setting performs an out-of-place transforms, the library looks for separate output buffers
511 	 *  on the Enqueue call.
512 	 *  @param[in] plHandle Handle to a previously created plan
513 	 *  @param[in] placeness Informs the library to either overwrite the input buffers with results or to write them in separate output buffers
514 	 */
515 	CLFFTAPI clfftStatus	clfftSetResultLocation( clfftPlanHandle plHandle, clfftResultLocation placeness );
516 
517 	/*! @brief Retrieve the final transpose setting of a multi-dimensional FFT
518 	 *  @details A multi-dimensional FFT transposes the data several times during calculation. If the client
519 	 *  does not care about the final transpose, to put data back in proper dimension, the final transpose can be skipped
520 	 *  to improve speed
521 	 *  @param[in] plHandle Handle to a previously created plan
522 	 *  @param[out] transposed Specifies whether the final transpose can be skipped
523 	 */
524 	CLFFTAPI clfftStatus	clfftGetPlanTransposeResult( const clfftPlanHandle plHandle, clfftResultTransposed * transposed );
525 
526 	/*! @brief Set the final transpose setting of a multi-dimensional FFT
527 	 *  @details A multi-dimensional FFT transposes the data several times during calculation.  If the client
528 	 *  does not care about the final transpose, to put data back in proper dimension, the final transpose can be skipped
529 	 *  to improve speed
530 	 *  @param[in] plHandle Handle to a previously created plan
531 	 *  @param[in] transposed Specifies whether the final transpose can be skipped
532 	 */
533 	CLFFTAPI clfftStatus	clfftSetPlanTransposeResult( clfftPlanHandle plHandle, clfftResultTransposed transposed );
534 
535 
536 	/*! @brief Get buffer size (in bytes), which may be needed internally for an intermediate buffer
537 	 *  @details Very large FFT transforms may need multiple passes, and the operation needs a temporary buffer to hold
538 	 *  intermediate results. This function is only valid after the plan is baked, otherwise, an invalid operation error
539 	 *  is returned. If the returned buffersize is 0, the runtime needs no temporary buffer.
540 	 *  @param[in] plHandle Handle to a previously created plan
541 	 *  @param[out] buffersize Size in bytes for intermediate buffer
542 	 */
543 	CLFFTAPI clfftStatus clfftGetTmpBufSize( const clfftPlanHandle plHandle, size_t* buffersize );
544 
545 	/*! @brief Register the callback parameters
546 	 *  @details Client can provide a callback function to do custom processing while reading input data and/or
547 	 *  writing output data. The callback function is provided as a string.
548 	 *  clFFT library incorporates the callback function string into the main FFT kernel. This function is used
549 	 *  by client to set the necessary parameters for callback
550 	 *  @param[in] plHandle Handle to a previously created plan
551 	 *  @param[in] funcName Callback function name
552 	 *  @param[in] funcString Callback function in string form
553 	 *  @param[in] localMemSize Optional - Size (bytes) of the local memory used by callback function; pass 0 if no local memory is used
554 	 *  @param[in] callbackType Type of callback - Pre-Callback or Post-Callback
555 	 *  @param[in] userdata Supplementary data if any used by callback function
556 	 *  @param[in] numUserdataBuffers Number of userdata buffers
557 	 */
558 	CLFFTAPI clfftStatus clfftSetPlanCallback(clfftPlanHandle plHandle, const char* funcName, const char* funcString,
559 										int localMemSize, clfftCallbackType callbackType, cl_mem *userdata, int numUserdataBuffers);
560 
561 
562 	/*! @brief Enqueue an FFT transform operation, and return immediately (non-blocking)
563 	 *  @details This transform API function computes the FFT transform. It is non-blocking as it
564 	 *  only enqueues the OpenCL kernels for execution. The synchronization step must be managed by the user.
565 	 *  @param[in] plHandle Handle to a previously created plan
566 	 *  @param[in] dir Forward or backward transform
567 	 *  @param[in] numQueuesAndEvents Number of command queues in commQueues; number of expected events to be returned in outEvents
568 	 *  @param[in] commQueues An array of cl_command_queues created by the client; the command queues must be a proper subset of
569 	 * 	the devices included in the OpenCL context associated with the plan
570 	 *  @param[in] numWaitEvents Specify the number of elements in the eventWaitList array
571 	 *  @param[in] waitEvents Events for which the transform waits to complete before executing on the device
572 	 *  @param[out] outEvents The runtime fills this array with events corresponding one to one with the input command queues passed
573 	 *	in commQueues.  This parameter can have the value NULL or nullptr. When the value is NULL, the client is not interested in receiving notifications
574 	 *	when transforms are finished, otherwise, (if not NULL) the client is responsible for allocating this array with at least
575 	 *	as many elements as specified in numQueuesAndEvents.
576 	 *  @param[in] inputBuffers An array of cl_mem objects that contain data for processing by the FFT runtime. If the transform
577 	 *  is in-place, the FFT results overwrite the input buffers
578 	 *  @param[out] outputBuffers An array of cl_mem objects that store the results of out-of-place transforms. If the transform
579 	 *  is in-place, this parameter may be NULL or nullptr and is completely ignored
580 	 *  @param[in] tmpBuffer A cl_mem object that is reserved as a temporary buffer for FFT processing. If clTmpBuffers is NULL or nullptr,
581 	 *  and the library needs temporary storage, an internal temporary buffer is created on the fly managed by the library.
582 	 *  @return Enum describing error condition; superset of OpenCL error codes
583 	 */
584 	CLFFTAPI clfftStatus	clfftEnqueueTransform(
585 												clfftPlanHandle plHandle,
586 												clfftDirection dir,
587 												cl_uint numQueuesAndEvents,
588 												cl_command_queue* commQueues,
589 												cl_uint numWaitEvents,
590 												const cl_event* waitEvents,
591 												cl_event* outEvents,
592 												cl_mem* inputBuffers,
593 												cl_mem* outputBuffers,
594 												cl_mem tmpBuffer
595 												);
596 
597 #ifdef __cplusplus
598 }
599 #endif
600 
601 #endif
602