1 /* 2 * cl_argument.h - CL kernel Argument 3 * 4 * Copyright (c) 2017 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan@intel.com> 19 */ 20 21 #ifndef XCAM_CL_KERNEL_ARGUMENT_H 22 #define XCAM_CL_KERNEL_ARGUMENT_H 23 24 #include <xcam_std.h> 25 #include <ocl/cl_memory.h> 26 27 namespace XCam { 28 29 #define XCAM_DEFAULT_IMAGE_DIM 2 30 #define XCAM_CL_KERNEL_MAX_WORK_DIM 3 31 32 struct CLWorkSize 33 { 34 uint32_t dim; 35 size_t global[XCAM_CL_KERNEL_MAX_WORK_DIM]; 36 size_t local[XCAM_CL_KERNEL_MAX_WORK_DIM]; 37 CLWorkSize(); 38 }; 39 40 class CLArgument 41 { 42 public: 43 virtual ~CLArgument (); 44 void get_value (void *&adress, uint32_t &size); 45 46 protected: 47 CLArgument (uint32_t size); 48 49 private: 50 XCAM_DEAD_COPY (CLArgument); 51 52 protected: 53 void *_arg_adress; 54 uint32_t _arg_size; 55 }; 56 57 typedef std::list<SmartPtr<CLArgument> > CLArgList; 58 59 60 template<typename DataType> 61 class CLArgumentT 62 : public CLArgument 63 { 64 public: 65 CLArgumentT(const DataType & value)66 CLArgumentT (const DataType &value) 67 : CLArgument (sizeof (DataType)) 68 , _value (value) 69 { 70 _arg_adress = (void *) &_value; 71 } ~CLArgumentT()72 ~CLArgumentT () {} 73 74 private: 75 DataType _value; 76 }; 77 78 template<typename DataType, int count> 79 class CLArgumentTArray 80 : public CLArgument 81 { 82 public: 83 CLArgumentTArray(const DataType * value)84 CLArgumentTArray (const DataType *value) 85 : CLArgument (sizeof (DataType) * count) 86 { 87 memcpy (&_value[0], value, sizeof (DataType) * count); 88 _arg_adress = (void *) &_value; 89 } ~CLArgumentTArray()90 ~CLArgumentTArray () {} 91 92 private: 93 DataType _value[count]; 94 }; 95 96 class CLMemArgument 97 : public CLArgument 98 { 99 public: 100 CLMemArgument(const SmartPtr<CLMemory> & mem)101 CLMemArgument (const SmartPtr<CLMemory> &mem) 102 : CLArgument (sizeof (cl_mem)) 103 , _mem (mem) 104 { 105 XCAM_ASSERT (mem.ptr ()); 106 _arg_adress = &mem->get_mem_id (); 107 } ~CLMemArgument()108 ~CLMemArgument () {} 109 110 private: 111 SmartPtr<CLMemory> _mem; 112 }; 113 114 115 } 116 117 #endif //XCAM_CL_KERNEL_ARGUMENT_H 118