GDAL
gdalwarpkernel_opencl.h
1/******************************************************************************
2 * $Id: gdalwarpkernel_opencl.h 81cf50eb5388867c88b73e923d9e9264653b5fec 2021-04-24 00:34:42 +0200 Even Rouault $
3 *
4 * Project: OpenCL Image Reprojector
5 * Purpose: Implementation of the GDALWarpKernel reprojector in OpenCL.
6 * Author: Seth Price, seth@pricepages.org
7 *
8 ******************************************************************************
9 * Copyright (c) 2010, Seth Price <seth@pricepages.org>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 ****************************************************************************/
29
30#if defined(HAVE_OPENCL)
31
32/* The following relates to the profiling calls to
33 clSetCommandQueueProperty() which are not available by default
34 with some OpenCL implementation (i.e. ATI) */
35
36#if defined(DEBUG_OPENCL) && DEBUG_OPENCL == 1
37#define CL_USE_DEPRECATED_OPENCL_1_0_APIS
38#endif
39
40#define CL_TARGET_OPENCL_VERSION 100
41
42#ifdef __APPLE__
43#include <OpenCL/OpenCL.h>
44#else
45#include <CL/opencl.h>
46#endif
47
48#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
49extern "C" {
50#endif
51
52typedef enum {
53 OCL_Bilinear=10,
54 OCL_Cubic=11,
55 OCL_CubicSpline=12,
56 OCL_Lanczos=13
57} OCLResampAlg;
58
59typedef enum
60{
61 VENDOR_OTHER,
62 VENDOR_AMD,
63 VENDOR_INTEL
64} OCLVendor;
65
66struct oclWarper {
67 cl_command_queue queue;
68 cl_context context;
69 cl_device_id dev;
70 cl_kernel kern1;
71 cl_kernel kern4;
72
73 int srcWidth;
74 int srcHeight;
75 int dstWidth;
76 int dstHeight;
77
78 int useUnifiedSrcDensity;
79 int useUnifiedSrcValid;
80 int useDstDensity;
81 int useDstValid;
82
83 int numBands;
84 int numImages;
85 OCLResampAlg resampAlg;
86
87 cl_channel_type imageFormat;
88 cl_mem *realWorkCL;
89 union {
90 void **v;
91 char **c;
92 unsigned char **uc;
93 short **s;
94 unsigned short **us;
95 float **f;
96 } realWork;
97
98 cl_mem *imagWorkCL;
99 union {
100 void **v;
101 char **c;
102 unsigned char **uc;
103 short **s;
104 unsigned short **us;
105 float **f;
106 } imagWork;
107
108 cl_mem *dstRealWorkCL;
109 union {
110 void **v;
111 char **c;
112 unsigned char **uc;
113 short **s;
114 unsigned short **us;
115 float **f;
116 } dstRealWork;
117
118 cl_mem *dstImagWorkCL;
119 union {
120 void **v;
121 char **c;
122 unsigned char **uc;
123 short **s;
124 unsigned short **us;
125 float **f;
126 } dstImagWork;
127
128 unsigned int imgChSize1;
129 cl_channel_order imgChOrder1;
130 unsigned int imgChSize4;
131 cl_channel_order imgChOrder4;
132 char useVec;
133
134 cl_mem useBandSrcValidCL;
135 char *useBandSrcValid;
136
137 cl_mem nBandSrcValidCL;
138 float *nBandSrcValid;
139
140 cl_mem xyWorkCL;
141 float *xyWork;
142
143 int xyWidth;
144 int xyHeight;
145 int coordMult;
146
147 unsigned int xyChSize;
148 cl_channel_order xyChOrder;
149
150 cl_mem fDstNoDataRealCL;
151 float *fDstNoDataReal;
152
153 OCLVendor eCLVendor;
154};
155
156struct oclWarper* GDALWarpKernelOpenCL_createEnv(int srcWidth, int srcHeight,
157 int dstWidth, int dstHeight,
158 cl_channel_type imageFormat,
159 int numBands, int coordMult,
160 int useImag, int useBandSrcValid,
161 float *fDstDensity,
162 double *dfDstNoDataReal,
163 OCLResampAlg resampAlg, cl_int *envErr);
164
165cl_int GDALWarpKernelOpenCL_setSrcValid(struct oclWarper *warper,
166 int *bandSrcValid, int bandNum);
167
168cl_int GDALWarpKernelOpenCL_setSrcImg(struct oclWarper *warper, void *imgData,
169 int bandNum);
170
171cl_int GDALWarpKernelOpenCL_setDstImg(struct oclWarper *warper, void *imgData,
172 int bandNum);
173
174cl_int GDALWarpKernelOpenCL_setCoordRow(struct oclWarper *warper,
175 double *rowSrcX, double *rowSrcY,
176 double srcXOff, double srcYOff,
177 int *success, int rowNum);
178
179cl_int GDALWarpKernelOpenCL_runResamp(struct oclWarper *warper,
180 float *unifiedSrcDensity,
181 unsigned int *unifiedSrcValid,
182 float *dstDensity,
183 unsigned int *dstValid,
184 double dfXScale, double dfYScale,
185 double dfXFilter, double dfYFilter,
186 int nXRadius, int nYRadius,
187 int nFiltInitX, int nFiltInitY);
188
189cl_int GDALWarpKernelOpenCL_getRow(struct oclWarper *warper,
190 void **rowReal, void **rowImag,
191 int rowNum, int bandNum);
192
193cl_int GDALWarpKernelOpenCL_deleteEnv(struct oclWarper *warper);
194
195#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
196}
197#endif
198
199#endif /* defined(HAVE_OPENCL) */