2 Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
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.
16 MagickCore OpenCL private methods.
18 #ifndef _MAGICKCORE_OPENCL_PRIVATE_H
19 #define _MAGICKCORE_OPENCL_PRIVATE_H
24 #include "MagickCore/studio.h"
25 #include "MagickCore/opencl.h"
27 #if defined(__cplusplus) || defined(c_plusplus)
31 #if defined(MAGICKCORE_OPENCL_SUPPORT)
34 typedef void* cl_platform_id;
35 typedef void* cl_device_id;
36 typedef void* cl_context;
37 typedef void* cl_command_queue;
38 typedef void* cl_kernel;
39 typedef struct { unsigned char t[8]; } cl_device_type; /* 64-bit */
42 #if defined(MAGICKCORE_HDRI_SUPPORT)
43 #define CLOptions "-cl-single-precision-constant -cl-mad-enable -DMAGICKCORE_HDRI_SUPPORT=1 "\
44 "-DCLQuantum=float -DCLSignedQuantum=float -DCLPixelType=float4 -DQuantumRange=%f " \
45 "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
46 " -DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
47 #define CLPixelPacket cl_float4
48 #define CLCharQuantumScale 1.0f
49 #elif (MAGICKCORE_QUANTUM_DEPTH == 8)
50 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
51 "-DCLQuantum=uchar -DCLSignedQuantum=char -DCLPixelType=uchar4 -DQuantumRange=%f " \
52 "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
53 "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
54 #define CLPixelPacket cl_uchar4
55 #define CLCharQuantumScale 1.0f
56 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
57 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
58 "-DCLQuantum=ushort -DCLSignedQuantum=short -DCLPixelType=ushort4 -DQuantumRange=%f "\
59 "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
60 "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
61 #define CLPixelPacket cl_ushort4
62 #define CLCharQuantumScale 257.0f
63 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
64 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
65 "-DCLQuantum=uint -DCLSignedQuantum=int -DCLPixelType=uint4 -DQuantumRange=%f "\
66 "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
67 "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
68 #define CLPixelPacket cl_uint4
69 #define CLCharQuantumScale 16843009.0f
70 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
71 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
72 "-DCLQuantum=ulong -DCLSignedQuantum=long -DCLPixelType=ulong4 -DQuantumRange=%f "\
73 "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
74 "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
75 #define CLPixelPacket cl_ulong4
76 #define CLCharQuantumScale 72340172838076673.0f
79 extern MagickExport cl_context
80 GetOpenCLContext(MagickCLEnv);
82 extern MagickExport cl_kernel
83 AcquireOpenCLKernel(MagickCLEnv, MagickOpenCLProgram, const char*);
85 extern MagickExport cl_command_queue
86 AcquireOpenCLCommandQueue(MagickCLEnv);
88 extern MagickExport MagickBooleanType
89 RelinquishOpenCLCommandQueue(MagickCLEnv, cl_command_queue),
90 RelinquishOpenCLKernel(MagickCLEnv, cl_kernel);
92 extern MagickExport unsigned long
93 GetOpenCLDeviceLocalMemorySize(MagickCLEnv),
94 GetOpenCLDeviceMaxMemAllocSize(MagickCLEnv);
96 extern MagickExport const char*
97 GetOpenCLCachedFilesDirectory();
99 extern MagickExport void
100 OpenCLLog(const char*);
102 /* #define OPENCLLOG_ENABLED 1 */
103 static inline void OpenCLLogException(const char* function,
104 const unsigned int line,
105 ExceptionInfo* exception) {
106 #ifdef OPENCLLOG_ENABLED
107 if (exception->severity!=0) {
108 char message[MaxTextExtent];
109 /* dump the source into a file */
110 (void) FormatLocaleString(message,MaxTextExtent,"%s:%d Exception(%d)"
111 ,function,line,exception->severity);
115 magick_unreferenced(function);
116 magick_unreferenced(line);
117 magick_unreferenced(exception);
121 #if defined(__cplusplus) || defined(c_plusplus)