]> 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 #include "MagickCore/studio.h"
22 #include "MagickCore/opencl.h"
23
24 #if defined(__cplusplus) || defined(c_plusplus)
25 extern "C" {
26 #endif
27
28 #if !defined(MAGICKCORE_OPENCL_SUPPORT)
29   typedef void* cl_platform_id;
30   typedef void* cl_device_id;
31   typedef void* cl_context;
32   typedef void* cl_command_queue;
33   typedef void* cl_kernel;
34   typedef struct { unsigned char t[8]; } cl_device_type; /* 64-bit */
35 #endif
36
37 #if defined(MAGICKCORE_HDRI_SUPPORT)
38 #define CLOptions "-cl-single-precision-constant -cl-mad-enable -DMAGICKCORE_HDRI_SUPPORT=1 "\
39   "-DCLQuantum=float -DCLSignedQuantum=float -DCLPixelType=float4 -DQuantumRange=%f " \
40   "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
41   " -DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
42 #define CLPixelPacket  cl_float4
43 #define CLCharQuantumScale 1.0f
44 #elif (MAGICKCORE_QUANTUM_DEPTH == 8)
45 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
46   "-DCLQuantum=uchar -DCLSignedQuantum=char -DCLPixelType=uchar4 -DQuantumRange=%f " \
47   "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
48   "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
49 #define CLPixelPacket  cl_uchar4
50 #define CLCharQuantumScale 1.0f
51 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
52 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
53   "-DCLQuantum=ushort -DCLSignedQuantum=short -DCLPixelType=ushort4 -DQuantumRange=%f "\
54   "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
55   "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
56 #define CLPixelPacket  cl_ushort4
57 #define CLCharQuantumScale 257.0f
58 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
59 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
60   "-DCLQuantum=uint -DCLSignedQuantum=int -DCLPixelType=uint4 -DQuantumRange=%f "\
61   "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
62   "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
63 #define CLPixelPacket  cl_uint4
64 #define CLCharQuantumScale 16843009.0f
65 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
66 #define CLOptions "-cl-single-precision-constant -cl-mad-enable " \
67   "-DCLQuantum=ulong -DCLSignedQuantum=long -DCLPixelType=ulong4 -DQuantumRange=%f "\
68   "-DQuantumScale=%f -DCharQuantumScale=%f -DMagickEpsilon=%f -DMagickPI=%f "\
69   "-DMaxMap=%u -DMAGICKCORE_QUANTUM_DEPTH=%u"
70 #define CLPixelPacket  cl_ulong4
71 #define CLCharQuantumScale 72340172838076673.0f
72 #endif
73
74 extern MagickPrivate cl_context 
75   GetOpenCLContext(MagickCLEnv);
76
77 extern MagickPrivate cl_kernel 
78   AcquireOpenCLKernel(MagickCLEnv, MagickOpenCLProgram, const char*);
79
80 extern MagickPrivate cl_command_queue 
81   AcquireOpenCLCommandQueue(MagickCLEnv);
82
83 extern MagickPrivate MagickBooleanType 
84   RelinquishOpenCLCommandQueue(MagickCLEnv, cl_command_queue),
85   RelinquishOpenCLKernel(MagickCLEnv, cl_kernel);
86
87 extern MagickPrivate unsigned long 
88   GetOpenCLDeviceLocalMemorySize(MagickCLEnv),
89   GetOpenCLDeviceMaxMemAllocSize(MagickCLEnv);
90
91 extern MagickPrivate const char* 
92   GetOpenCLCachedFilesDirectory();
93
94 extern MagickPrivate void 
95   OpenCLLog(const char*);
96
97 /* #define OPENCLLOG_ENABLED 1 */
98 static inline void OpenCLLogException(const char* function, 
99                         const unsigned int line, 
100                         ExceptionInfo* exception) {
101 #ifdef OPENCLLOG_ENABLED
102   if (exception->severity!=0) {
103     char message[MaxTextExtent];
104     /*  dump the source into a file */
105     (void) FormatLocaleString(message,MaxTextExtent,"%s:%d Exception(%d)"
106       ,function,line,exception->severity);
107     OpenCLLog(message);
108   }
109 #else
110   magick_unreferenced(function);
111   magick_unreferenced(line);
112   magick_unreferenced(exception);
113 #endif
114 }
115
116 #if defined(__cplusplus) || defined(c_plusplus)
117 }
118 #endif
119
120 #endif