blob: 7264366ae42e4aaeaa47356156db4e089f35e201 [file] [log] [blame]
cristydbba8212013-07-19 14:53:50 +00001/*
cristy6398ec72013-11-28 02:00:27 +00002 Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
cristydbba8212013-07-19 14:53:50 +00004
cristy6398ec72013-11-28 02:00:27 +00005 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
cristyf034abb2013-11-24 14:16:14 +00007
cristy6398ec72013-11-28 02:00:27 +00008 http://www.imagemagick.org/script/license.php
cristyf034abb2013-11-24 14:16:14 +00009
cristy6398ec72013-11-28 02:00:27 +000010 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.
cristyf034abb2013-11-24 14:16:14 +000015
cristy6398ec72013-11-28 02:00:27 +000016 MagickCore OpenCL private methods.
cristydbba8212013-07-19 14:53:50 +000017*/
18#ifndef _MAGICKCORE_OPENCL_PRIVATE_H
19#define _MAGICKCORE_OPENCL_PRIVATE_H
20
cristyf034abb2013-11-24 14:16:14 +000021#include "MagickCore/studio.h"
cristye85d0f72013-11-27 02:25:43 +000022#include "MagickCore/opencl.h"
cristyf034abb2013-11-24 14:16:14 +000023
cristydbba8212013-07-19 14:53:50 +000024#if defined(__cplusplus) || defined(c_plusplus)
25extern "C" {
26#endif
27
cristyf034abb2013-11-24 14:16:14 +000028#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
76extern MagickExport cl_context
77 GetOpenCLContext(MagickCLEnv);
78
79extern MagickExport cl_kernel
80 AcquireOpenCLKernel(MagickCLEnv, MagickOpenCLProgram, const char*);
81
82extern MagickExport cl_command_queue
83 AcquireOpenCLCommandQueue(MagickCLEnv);
84
85extern MagickExport MagickBooleanType
86 RelinquishOpenCLCommandQueue(MagickCLEnv, cl_command_queue),
87 RelinquishOpenCLKernel(MagickCLEnv, cl_kernel);
88
89extern MagickExport unsigned long
90 GetOpenCLDeviceLocalMemorySize(MagickCLEnv),
91 GetOpenCLDeviceMaxMemAllocSize(MagickCLEnv);
92
93extern MagickExport const char*
94 GetOpenCLCachedFilesDirectory();
95
96extern MagickExport void
97 OpenCLLog(const char*);
98
cristye85d0f72013-11-27 02:25:43 +000099/* #define OPENCLLOG_ENABLED 1 */
cristyf034abb2013-11-24 14:16:14 +0000100static inline void OpenCLLogException(const char* function,
101 const unsigned int line,
102 ExceptionInfo* exception) {
cristye85d0f72013-11-27 02:25:43 +0000103#ifdef OPENCLLOG_ENABLED
cristyf034abb2013-11-24 14:16:14 +0000104 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);
cristy711ed182013-11-24 15:15:16 +0000110 }
cristye85d0f72013-11-27 02:25:43 +0000111#else
112 magick_unreferenced(function);
113 magick_unreferenced(line);
114 magick_unreferenced(exception);
115#endif
cristyf034abb2013-11-24 14:16:14 +0000116}
117
cristydbba8212013-07-19 14:53:50 +0000118#if defined(__cplusplus) || defined(c_plusplus)
119}
120#endif
121
122#endif