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 public: Action()28 Action() {} ~Action()29 virtual ~Action() {} 30 31 virtual cl_int Setup(cl_device_id device, cl_context context, 32 cl_command_queue queue) = 0; 33 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 34 cl_event *waits, cl_event *outEvent) = 0; 35 36 virtual const char *GetName(void) const = 0; 37 38 protected: 39 cl_int IGetPreferredImageSize2D(cl_device_id device, size_t &outWidth, 40 size_t &outHeight); 41 cl_int IGetPreferredImageSize3D(cl_device_id device, size_t &outWidth, 42 size_t &outHeight, size_t &outDepth); 43 }; 44 45 // Simple NDRangeKernel execution that takes a noticable amount of time 46 class NDRangeKernelAction : public Action { 47 public: NDRangeKernelAction()48 NDRangeKernelAction() {} ~NDRangeKernelAction()49 virtual ~NDRangeKernelAction() {} 50 51 size_t mLocalThreads[1]; 52 clMemWrapper mStreams[2]; 53 clProgramWrapper mProgram; 54 clKernelWrapper mKernel; 55 56 virtual cl_int Setup(cl_device_id device, cl_context context, 57 cl_command_queue queue); 58 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 59 cl_event *waits, cl_event *outEvent); 60 GetName(void)61 virtual const char *GetName(void) const { return "NDRangeKernel"; } 62 }; 63 64 // Base action for buffer actions 65 class BufferAction : public Action { 66 public: 67 clMemWrapper mBuffer; 68 size_t mSize; 69 void *mOutBuffer; 70 BufferAction()71 BufferAction() { mOutBuffer = NULL; } ~BufferAction()72 virtual ~BufferAction() { free(mOutBuffer); } 73 74 virtual cl_int Setup(cl_device_id device, cl_context context, 75 cl_command_queue queue); 76 }; 77 78 class ReadBufferAction : public BufferAction { 79 public: ReadBufferAction()80 ReadBufferAction() {} ~ReadBufferAction()81 virtual ~ReadBufferAction() {} 82 83 virtual cl_int Setup(cl_device_id device, cl_context context, 84 cl_command_queue queue); 85 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 86 cl_event *waits, cl_event *outEvent); 87 GetName(void)88 virtual const char *GetName(void) const { return "ReadBuffer"; } 89 }; 90 91 class WriteBufferAction : public BufferAction { 92 public: WriteBufferAction()93 WriteBufferAction() {} ~WriteBufferAction()94 virtual ~WriteBufferAction() {} 95 96 virtual cl_int Setup(cl_device_id device, cl_context context, 97 cl_command_queue queue); 98 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 99 cl_event *waits, cl_event *outEvent); 100 GetName(void)101 virtual const char *GetName(void) const { return "WriteBuffer"; } 102 }; 103 104 class MapBufferAction : public BufferAction { 105 public: MapBufferAction()106 MapBufferAction(): mQueue(0) {} 107 108 cl_command_queue mQueue; 109 void *mMappedPtr; 110 111 virtual ~MapBufferAction(); 112 virtual cl_int Setup(cl_device_id device, cl_context context, 113 cl_command_queue queue); 114 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 115 cl_event *waits, cl_event *outEvent); 116 GetName(void)117 virtual const char *GetName(void) const { return "MapBuffer"; } 118 }; 119 120 class UnmapBufferAction : public BufferAction { 121 public: UnmapBufferAction()122 UnmapBufferAction() {} ~UnmapBufferAction()123 virtual ~UnmapBufferAction() {} 124 125 void *mMappedPtr; 126 127 virtual cl_int Setup(cl_device_id device, cl_context context, 128 cl_command_queue queue); 129 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 130 cl_event *waits, cl_event *outEvent); 131 GetName(void)132 virtual const char *GetName(void) const { return "UnmapBuffer"; } 133 }; 134 135 class ReadImage2DAction : public Action { 136 public: ReadImage2DAction()137 ReadImage2DAction() { mOutput = NULL; } ~ReadImage2DAction()138 virtual ~ReadImage2DAction() { free(mOutput); } 139 140 clMemWrapper mImage; 141 size_t mWidth, mHeight; 142 void *mOutput; 143 144 virtual cl_int Setup(cl_device_id device, cl_context context, 145 cl_command_queue queue); 146 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 147 cl_event *waits, cl_event *outEvent); 148 GetName(void)149 virtual const char *GetName(void) const { return "ReadImage2D"; } 150 }; 151 152 class ReadImage3DAction : public Action { 153 public: ReadImage3DAction()154 ReadImage3DAction() { mOutput = NULL; } ~ReadImage3DAction()155 virtual ~ReadImage3DAction() { free(mOutput); } 156 157 clMemWrapper mImage; 158 size_t mWidth, mHeight, mDepth; 159 void *mOutput; 160 161 virtual cl_int Setup(cl_device_id device, cl_context context, 162 cl_command_queue queue); 163 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 164 cl_event *waits, cl_event *outEvent); 165 GetName(void)166 virtual const char *GetName(void) const { return "ReadImage3D"; } 167 }; 168 169 class WriteImage2DAction : public Action { 170 public: 171 clMemWrapper mImage; 172 size_t mWidth, mHeight; 173 void *mOutput; 174 WriteImage2DAction()175 WriteImage2DAction() { mOutput = NULL; } ~WriteImage2DAction()176 virtual ~WriteImage2DAction() { free(mOutput); } 177 178 virtual cl_int Setup(cl_device_id device, cl_context context, 179 cl_command_queue queue); 180 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 181 cl_event *waits, cl_event *outEvent); 182 GetName(void)183 virtual const char *GetName(void) const { return "WriteImage2D"; } 184 }; 185 186 class WriteImage3DAction : public Action { 187 public: 188 clMemWrapper mImage; 189 size_t mWidth, mHeight, mDepth; 190 void *mOutput; 191 WriteImage3DAction()192 WriteImage3DAction() { mOutput = NULL; } ~WriteImage3DAction()193 virtual ~WriteImage3DAction() { free(mOutput); } 194 195 virtual cl_int Setup(cl_device_id device, cl_context context, 196 cl_command_queue queue); 197 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 198 cl_event *waits, cl_event *outEvent); 199 GetName(void)200 virtual const char *GetName(void) const { return "WriteImage3D"; } 201 }; 202 203 class CopyImageAction : public Action { 204 public: CopyImageAction()205 CopyImageAction() {} ~CopyImageAction()206 virtual ~CopyImageAction() {} 207 208 clMemWrapper mSrcImage, mDstImage; 209 size_t mWidth, mHeight, mDepth; 210 211 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 212 cl_event *waits, cl_event *outEvent); 213 }; 214 215 class CopyImage2Dto2DAction : public CopyImageAction { 216 public: CopyImage2Dto2DAction()217 CopyImage2Dto2DAction() {} ~CopyImage2Dto2DAction()218 virtual ~CopyImage2Dto2DAction() {} 219 220 virtual cl_int Setup(cl_device_id device, cl_context context, 221 cl_command_queue queue); 222 GetName(void)223 virtual const char *GetName(void) const { return "CopyImage2Dto2D"; } 224 }; 225 226 class CopyImage2Dto3DAction : public CopyImageAction { 227 public: CopyImage2Dto3DAction()228 CopyImage2Dto3DAction() {} ~CopyImage2Dto3DAction()229 virtual ~CopyImage2Dto3DAction() {} 230 231 virtual cl_int Setup(cl_device_id device, cl_context context, 232 cl_command_queue queue); 233 GetName(void)234 virtual const char *GetName(void) const { return "CopyImage2Dto3D"; } 235 }; 236 237 class CopyImage3Dto2DAction : public CopyImageAction { 238 public: CopyImage3Dto2DAction()239 CopyImage3Dto2DAction() {} ~CopyImage3Dto2DAction()240 virtual ~CopyImage3Dto2DAction() {} 241 242 virtual cl_int Setup(cl_device_id device, cl_context context, 243 cl_command_queue queue); 244 GetName(void)245 virtual const char *GetName(void) const { return "CopyImage3Dto2D"; } 246 }; 247 248 class CopyImage3Dto3DAction : public CopyImageAction { 249 public: CopyImage3Dto3DAction()250 CopyImage3Dto3DAction() {} ~CopyImage3Dto3DAction()251 virtual ~CopyImage3Dto3DAction() {} 252 253 virtual cl_int Setup(cl_device_id device, cl_context context, 254 cl_command_queue queue); 255 GetName(void)256 virtual const char *GetName(void) const { return "CopyImage3Dto3D"; } 257 }; 258 259 class Copy2DImageToBufferAction : public Action { 260 public: Copy2DImageToBufferAction()261 Copy2DImageToBufferAction() {} ~Copy2DImageToBufferAction()262 virtual ~Copy2DImageToBufferAction() {} 263 264 clMemWrapper mSrcImage, mDstBuffer; 265 size_t mWidth, mHeight; 266 267 virtual cl_int Setup(cl_device_id device, cl_context context, 268 cl_command_queue queue); 269 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 270 cl_event *waits, cl_event *outEvent); 271 GetName(void)272 virtual const char *GetName(void) const { return "Copy2DImageToBuffer"; } 273 }; 274 275 class Copy3DImageToBufferAction : public Action { 276 public: Copy3DImageToBufferAction()277 Copy3DImageToBufferAction() {} ~Copy3DImageToBufferAction()278 virtual ~Copy3DImageToBufferAction() {} 279 280 clMemWrapper mSrcImage, mDstBuffer; 281 size_t mWidth, mHeight, mDepth; 282 283 virtual cl_int Setup(cl_device_id device, cl_context context, 284 cl_command_queue queue); 285 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 286 cl_event *waits, cl_event *outEvent); 287 GetName(void)288 virtual const char *GetName(void) const { return "Copy3DImageToBuffer"; } 289 }; 290 291 class CopyBufferTo2DImageAction : public Action { 292 public: CopyBufferTo2DImageAction()293 CopyBufferTo2DImageAction() {} ~CopyBufferTo2DImageAction()294 virtual ~CopyBufferTo2DImageAction() {} 295 296 clMemWrapper mSrcBuffer, mDstImage; 297 size_t mWidth, mHeight; 298 299 virtual cl_int Setup(cl_device_id device, cl_context context, 300 cl_command_queue queue); 301 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 302 cl_event *waits, cl_event *outEvent); 303 GetName(void)304 virtual const char *GetName(void) const { return "CopyBufferTo2D"; } 305 }; 306 307 class CopyBufferTo3DImageAction : public Action { 308 public: CopyBufferTo3DImageAction()309 CopyBufferTo3DImageAction() {} ~CopyBufferTo3DImageAction()310 virtual ~CopyBufferTo3DImageAction() {} 311 312 clMemWrapper mSrcBuffer, mDstImage; 313 size_t mWidth, mHeight, mDepth; 314 315 virtual cl_int Setup(cl_device_id device, cl_context context, 316 cl_command_queue queue); 317 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 318 cl_event *waits, cl_event *outEvent); 319 GetName(void)320 virtual const char *GetName(void) const { return "CopyBufferTo3D"; } 321 }; 322 323 class MapImageAction : public Action { 324 public: MapImageAction()325 MapImageAction(): mQueue(0) {} 326 327 clMemWrapper mImage; 328 size_t mWidth, mHeight; 329 void *mMappedPtr; 330 cl_command_queue mQueue; 331 332 virtual ~MapImageAction(); 333 virtual cl_int Setup(cl_device_id device, cl_context context, 334 cl_command_queue queue); 335 virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, 336 cl_event *waits, cl_event *outEvent); 337 GetName(void)338 virtual const char *GetName(void) const { return "MapImage"; } 339 }; 340 341 342 #endif // _action_classes_h 343