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