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