]> granicus.if.org Git - imagemagick/blob - MagickCore/opencl-private.h
(no commit message)
[imagemagick] / MagickCore / opencl-private.h
1 /*
2 Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
7
8 http://www.imagemagick.org/script/license.php
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 MagickCore OpenCL private methods.
17 */
18 #ifndef _MAGICKCORE_OPENCL_PRIVATE_H
19 #define _MAGICKCORE_OPENCL_PRIVATE_H
20
21 /*
22 Include declarations.
23 */
24 #include "MagickCore/studio.h"
25 #include "MagickCore/opencl.h"
26
27 #if defined(__cplusplus) || defined(c_plusplus)
28 extern "C" {
29 #endif
30
31 #if defined(MAGICKCORE_OPENCL_SUPPORT)
32 #include <CL/cl.h>
33 #else
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 */
40 #endif
41
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
77 #endif
78
79 extern MagickExport cl_context 
80   GetOpenCLContext(MagickCLEnv);
81
82 extern MagickExport cl_kernel 
83   AcquireOpenCLKernel(MagickCLEnv, MagickOpenCLProgram, const char*);
84
85 extern MagickExport cl_command_queue 
86   AcquireOpenCLCommandQueue(MagickCLEnv);
87
88 extern MagickExport MagickBooleanType 
89   RelinquishOpenCLCommandQueue(MagickCLEnv, cl_command_queue),
90   RelinquishOpenCLKernel(MagickCLEnv, cl_kernel);
91
92 extern MagickExport unsigned long 
93   GetOpenCLDeviceLocalMemorySize(MagickCLEnv),
94   GetOpenCLDeviceMaxMemAllocSize(MagickCLEnv);
95
96 extern MagickExport const char* 
97   GetOpenCLCachedFilesDirectory();
98
99 extern MagickExport void 
100   OpenCLLog(const char*);
101
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);
112     OpenCLLog(message);
113   }
114 #else
115   magick_unreferenced(function);
116   magick_unreferenced(line);
117   magick_unreferenced(exception);
118 #endif
119 }
120
121 #if defined(__cplusplus) || defined(c_plusplus)
122 }
123 #endif
124
125 #endif