1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
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 #ifndef _action_classes_h
17 #define _action_classes_h
18 
19 #include "testBase.h"
20 
21 // This is a base class from which all actions are born
22 // Note: No actions should actually feed I/O to each other, because then
23 // it would potentially be possible for an implementation to make actions
24 // wait on one another based on their shared I/O, not because of their
25 // wait lists!
26 class Action
27 {
28     public:
Action()29         Action() {}
~Action()30         virtual ~Action() {}
31 
32         virtual cl_int        Setup( cl_device_id device, cl_context context, cl_command_queue queue ) = 0;
33         virtual cl_int        Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) = 0;
34 
35         virtual const char * GetName( void ) const = 0;
36 
37     protected:
38 
39         cl_int    IGetPreferredImageSize2D( cl_device_id device, size_t &outWidth, size_t &outHeight );
40         cl_int    IGetPreferredImageSize3D( cl_device_id device, size_t &outWidth, size_t &outHeight, size_t &outDepth );
41 };
42 
43 // Simple NDRangeKernel execution that takes a noticable amount of time
44 class NDRangeKernelAction : public Action
45 {
46     public:
NDRangeKernelAction()47         NDRangeKernelAction() {}
~NDRangeKernelAction()48         virtual ~NDRangeKernelAction() {}
49 
50         size_t                mLocalThreads[ 1 ];
51         clMemWrapper        mStreams[ 2 ];
52         clProgramWrapper    mProgram;
53         clKernelWrapper        mKernel;
54 
55         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
56         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
57 
GetName(void)58         virtual const char * GetName( void ) const { return "NDRangeKernel"; }
59 };
60 
61 // Base action for buffer actions
62 class BufferAction : public Action
63 {
64     public:
65         clMemWrapper        mBuffer;
66         size_t                mSize;
67         void                *mOutBuffer;
68 
BufferAction()69         BufferAction() { mOutBuffer = NULL; }
~BufferAction()70         virtual ~BufferAction() { free( mOutBuffer ); }
71 
72         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue, bool allocate );
73 };
74 
75 class ReadBufferAction : public BufferAction
76 {
77     public:
ReadBufferAction()78         ReadBufferAction() {}
~ReadBufferAction()79         virtual ~ReadBufferAction() {}
80 
81         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
82         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
83 
GetName(void)84         virtual const char * GetName( void ) const { return "ReadBuffer"; }
85 };
86 
87 class WriteBufferAction : public BufferAction
88 {
89     public:
WriteBufferAction()90         WriteBufferAction() {}
~WriteBufferAction()91         virtual ~WriteBufferAction() {}
92 
93         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
94         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
95 
GetName(void)96         virtual const char * GetName( void ) const { return "WriteBuffer"; }
97 };
98 
99 class MapBufferAction : public BufferAction
100 {
101     public:
MapBufferAction()102         MapBufferAction() : mQueue(0) {}
103 
104         cl_command_queue    mQueue;
105         void                *mMappedPtr;
106 
107         virtual ~MapBufferAction();
108         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
109         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
110 
GetName(void)111         virtual const char * GetName( void ) const { return "MapBuffer"; }
112 };
113 
114 class UnmapBufferAction : public BufferAction
115 {
116     public:
UnmapBufferAction()117         UnmapBufferAction() {}
~UnmapBufferAction()118         virtual ~UnmapBufferAction() {}
119 
120         void                *mMappedPtr;
121 
122         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
123         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
124 
GetName(void)125         virtual const char * GetName( void ) const { return "UnmapBuffer"; }
126 };
127 
128 class ReadImage2DAction : public Action
129 {
130     public:
ReadImage2DAction()131         ReadImage2DAction() { mOutput = NULL; }
~ReadImage2DAction()132         virtual ~ReadImage2DAction() { free( mOutput ); }
133 
134         clMemWrapper        mImage;
135         size_t                mWidth, mHeight;
136         void                *mOutput;
137 
138         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
139         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
140 
GetName(void)141         virtual const char * GetName( void ) const { return "ReadImage2D"; }
142 };
143 
144 class ReadImage3DAction : public Action
145 {
146     public:
ReadImage3DAction()147         ReadImage3DAction() { mOutput = NULL; }
~ReadImage3DAction()148         virtual ~ReadImage3DAction() { free( mOutput ); }
149 
150         clMemWrapper        mImage;
151         size_t                mWidth, mHeight, mDepth;
152         void                *mOutput;
153 
154         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
155         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
156 
GetName(void)157         virtual const char * GetName( void ) const { return "ReadImage3D"; }
158 };
159 
160 class WriteImage2DAction : public Action
161 {
162     public:
163         clMemWrapper        mImage;
164         size_t                mWidth, mHeight;
165         void                *mOutput;
166 
WriteImage2DAction()167         WriteImage2DAction() { mOutput = NULL; }
~WriteImage2DAction()168         virtual ~WriteImage2DAction() { free( mOutput ); }
169 
170         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
171         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
172 
GetName(void)173         virtual const char * GetName( void ) const { return "WriteImage2D"; }
174 };
175 
176 class WriteImage3DAction : public Action
177 {
178     public:
179         clMemWrapper        mImage;
180         size_t                mWidth, mHeight, mDepth;
181         void                *mOutput;
182 
WriteImage3DAction()183         WriteImage3DAction() { mOutput = NULL; }
~WriteImage3DAction()184         virtual ~WriteImage3DAction() { free( mOutput ); }
185 
186         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
187         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
188 
GetName(void)189         virtual const char * GetName( void ) const { return "WriteImage3D"; }
190 };
191 
192 class CopyImageAction : public Action
193 {
194     public:
CopyImageAction()195         CopyImageAction() {}
~CopyImageAction()196         virtual ~CopyImageAction() {}
197 
198         clMemWrapper        mSrcImage, mDstImage;
199         size_t                mWidth, mHeight, mDepth;
200 
201         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
202 };
203 
204 class CopyImage2Dto2DAction : public CopyImageAction
205 {
206     public:
CopyImage2Dto2DAction()207         CopyImage2Dto2DAction() {}
~CopyImage2Dto2DAction()208         virtual ~CopyImage2Dto2DAction() {}
209 
210         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
211 
GetName(void)212         virtual const char * GetName( void ) const { return "CopyImage2Dto2D"; }
213 };
214 
215 class CopyImage2Dto3DAction : public CopyImageAction
216 {
217     public:
CopyImage2Dto3DAction()218         CopyImage2Dto3DAction() {}
~CopyImage2Dto3DAction()219         virtual ~CopyImage2Dto3DAction() {}
220 
221         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
222 
GetName(void)223         virtual const char * GetName( void ) const { return "CopyImage2Dto3D"; }
224 };
225 
226 class CopyImage3Dto2DAction : public CopyImageAction
227 {
228     public:
CopyImage3Dto2DAction()229         CopyImage3Dto2DAction() {}
~CopyImage3Dto2DAction()230         virtual ~CopyImage3Dto2DAction() {}
231 
232         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
233 
GetName(void)234         virtual const char * GetName( void ) const { return "CopyImage3Dto2D"; }
235 };
236 
237 class CopyImage3Dto3DAction : public CopyImageAction
238 {
239     public:
CopyImage3Dto3DAction()240         CopyImage3Dto3DAction() {}
~CopyImage3Dto3DAction()241         virtual ~CopyImage3Dto3DAction() {}
242 
243         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
244 
GetName(void)245         virtual const char * GetName( void ) const { return "CopyImage3Dto3D"; }
246 };
247 
248 class Copy2DImageToBufferAction : public Action
249 {
250     public:
Copy2DImageToBufferAction()251         Copy2DImageToBufferAction() {}
~Copy2DImageToBufferAction()252         virtual ~Copy2DImageToBufferAction() {}
253 
254         clMemWrapper        mSrcImage, mDstBuffer;
255         size_t                mWidth, mHeight;
256 
257         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
258         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
259 
GetName(void)260         virtual const char * GetName( void ) const { return "Copy2DImageToBuffer"; }
261 };
262 
263 class Copy3DImageToBufferAction : public Action
264 {
265     public:
Copy3DImageToBufferAction()266         Copy3DImageToBufferAction() {}
~Copy3DImageToBufferAction()267         virtual ~Copy3DImageToBufferAction() {}
268 
269         clMemWrapper        mSrcImage, mDstBuffer;
270         size_t                mWidth, mHeight, mDepth;
271 
272         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
273         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
274 
GetName(void)275         virtual const char * GetName( void ) const { return "Copy3DImageToBuffer"; }
276 };
277 
278 class CopyBufferTo2DImageAction : public Action
279 {
280     public:
CopyBufferTo2DImageAction()281         CopyBufferTo2DImageAction() {}
~CopyBufferTo2DImageAction()282         virtual ~CopyBufferTo2DImageAction() {}
283 
284         clMemWrapper        mSrcBuffer, mDstImage;
285         size_t                mWidth, mHeight;
286 
287         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
288         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
289 
GetName(void)290         virtual const char * GetName( void ) const { return "CopyBufferTo2D"; }
291 };
292 
293 class CopyBufferTo3DImageAction : public Action
294 {
295     public:
CopyBufferTo3DImageAction()296         CopyBufferTo3DImageAction() {}
~CopyBufferTo3DImageAction()297         virtual ~CopyBufferTo3DImageAction() {}
298 
299         clMemWrapper        mSrcBuffer, mDstImage;
300         size_t                mWidth, mHeight, mDepth;
301 
302         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
303         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
304 
GetName(void)305         virtual const char * GetName( void ) const { return "CopyBufferTo3D"; }
306 };
307 
308 class MapImageAction : public Action
309 {
310     public:
MapImageAction()311         MapImageAction() : mQueue(0) {}
312 
313         clMemWrapper        mImage;
314         size_t                mWidth, mHeight;
315         void                *mMappedPtr;
316         cl_command_queue    mQueue;
317 
318         virtual ~MapImageAction();
319         virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue );
320         virtual cl_int    Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent );
321 
GetName(void)322         virtual const char * GetName( void ) const { return "MapImage"; }
323 };
324 
325 
326 #endif // _action_classes_h
327