1 /* 2 * Copyright (c) 2002-2010 LWJGL Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'LWJGL' nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.lwjgl.opencl; 33 34 /** 35 * This class is a wrapper around a cl_kernel pointer. 36 * 37 * @author Spasi 38 */ 39 public final class CLKernel extends CLObjectChild<CLProgram> { 40 41 private static final CLKernelUtil util = (CLKernelUtil)CLPlatform.getInfoUtilInstance(CLKernel.class, "CL_KERNEL_UTIL"); 42 CLKernel(final long pointer, final CLProgram program)43 CLKernel(final long pointer, final CLProgram program) { 44 super(pointer, program); 45 if ( isValid() ) 46 program.getCLKernelRegistry().registerObject(this); 47 } 48 49 // ---------------[ UTILITY METHODS ]--------------- 50 51 // clSetKernelArg methods 52 53 /** 54 * Sets a kernel argument at the specified index to the specified 55 * byte value. 56 * 57 * @param index the argument index 58 * @param value the argument value 59 * 60 * @return this CLKernel object 61 */ setArg(final int index, final byte value)62 public CLKernel setArg(final int index, final byte value) { 63 util.setArg(this, index, value); 64 return this; 65 } 66 67 /** 68 * Sets a kernel argument at the specified index to the specified 69 * byte value. 70 * 71 * @param index the argument index 72 * @param value the argument value 73 * 74 * @return this CLKernel object 75 */ setArg(final int index, final short value)76 public CLKernel setArg(final int index, final short value) { 77 util.setArg(this, index, value); 78 return this; 79 } 80 81 /** 82 * Sets a kernel argument at the specified index to the specified 83 * int value. 84 * 85 * @param index the argument index 86 * @param value the argument value 87 * 88 * @return this CLKernel object 89 */ setArg(final int index, final int value)90 public CLKernel setArg(final int index, final int value) { 91 util.setArg(this, index, value); 92 return this; 93 } 94 95 /** 96 * Sets a kernel argument at the specified index to the specified 97 * long value. 98 * 99 * @param index the argument index 100 * @param value the argument value 101 * 102 * @return this CLKernel object 103 */ setArg(final int index, final long value)104 public CLKernel setArg(final int index, final long value) { 105 util.setArg(this, index, value); 106 return this; 107 } 108 109 /** 110 * Sets a kernel argument at the specified index to the specified 111 * float value. 112 * 113 * @param index the argument index 114 * @param value the argument value 115 * 116 * @return this CLKernel object 117 */ setArg(final int index, final float value)118 public CLKernel setArg(final int index, final float value) { 119 util.setArg(this, index, value); 120 return this; 121 } 122 123 /** 124 * Sets a kernel argument at the specified index to the specified 125 * double value. 126 * 127 * @param index the argument index 128 * @param value the argument value 129 * 130 * @return this CLKernel object 131 */ setArg(final int index, final double value)132 public CLKernel setArg(final int index, final double value) { 133 util.setArg(this, index, value); 134 return this; 135 } 136 137 /** 138 * Sets a kernel argument at the specified index to the specified 139 * pointer value. 140 * 141 * @param index the argument index 142 * @param value the argument value 143 * 144 * @return this CLKernel object 145 */ setArg(final int index, final CLObject value)146 public CLKernel setArg(final int index, final CLObject value) { 147 util.setArg(this, index, value); 148 return this; 149 } 150 151 /** 152 * Sets the size of a __local kernel argument at the specified index. 153 * 154 * @param index the argument index 155 * @param size the argument size 156 * 157 * @return this CLKernel object 158 */ setArgSize(final int index, final long size)159 public CLKernel setArgSize(final int index, final long size) { 160 util.setArgSize(this, index, size); 161 return this; 162 } 163 164 // clGetKernelInfo methods 165 166 /** 167 * Returns the String value of the specified parameter. 168 * 169 * @param param_name the parameter 170 * 171 * @return the parameter value 172 */ getInfoString(final int param_name)173 public String getInfoString(final int param_name) { 174 return util.getInfoString(this, param_name); 175 } 176 177 /** 178 * Returns the integer value of the specified parameter. 179 * 180 * @param param_name the parameter 181 * 182 * @return the parameter value 183 */ getInfoInt(final int param_name)184 public int getInfoInt(final int param_name) { 185 return util.getInfoInt(this, param_name); 186 } 187 188 // clGetKernelWorkGroupInfo methods 189 190 /** 191 * Returns the size_t value of the specified parameter. 192 * 193 * @param param_name the parameter 194 * 195 * @return the parameter value 196 */ getWorkGroupInfoSize(final CLDevice device, int param_name)197 public long getWorkGroupInfoSize(final CLDevice device, int param_name) { 198 return util.getWorkGroupInfoSize(this, device, param_name); 199 } 200 201 /** 202 * Returns an array of size_t values of the specified parameter. 203 * 204 * @param param_name the parameter 205 * 206 * @return the parameter values 207 */ getWorkGroupInfoSizeArray(final CLDevice device, int param_name)208 public long[] getWorkGroupInfoSizeArray(final CLDevice device, int param_name) { 209 return util.getWorkGroupInfoSizeArray(this, device, param_name); 210 } 211 212 /** 213 * Returns the long value of the specified parameter. Can be used 214 * for both cl_ulong and cl_bitfield parameters. 215 * 216 * @param param_name the parameter 217 * 218 * @return the parameter value 219 */ getWorkGroupInfoLong(final CLDevice device, int param_name)220 public long getWorkGroupInfoLong(final CLDevice device, int param_name) { 221 return util.getWorkGroupInfoLong(this, device, param_name); 222 } 223 224 /** CLKernel utility methods interface. */ 225 interface CLKernelUtil extends InfoUtil<CLKernel> { 226 setArg(CLKernel kernel, int index, byte value)227 void setArg(CLKernel kernel, int index, byte value); 228 setArg(CLKernel kernel, int index, short value)229 void setArg(CLKernel kernel, int index, short value); 230 setArg(CLKernel kernel, int index, int value)231 void setArg(CLKernel kernel, int index, int value); 232 setArg(CLKernel kernel, int index, long value)233 void setArg(CLKernel kernel, int index, long value); 234 setArg(CLKernel kernel, int index, float value)235 void setArg(CLKernel kernel, int index, float value); 236 setArg(CLKernel kernel, int index, double value)237 void setArg(CLKernel kernel, int index, double value); 238 setArg(CLKernel kernel, int index, CLObject pointer)239 void setArg(CLKernel kernel, int index, CLObject pointer); 240 setArgSize(CLKernel kernel, int index, long size)241 void setArgSize(CLKernel kernel, int index, long size); 242 getWorkGroupInfoSize(CLKernel kernel, CLDevice device, int param_name)243 long getWorkGroupInfoSize(CLKernel kernel, CLDevice device, int param_name); 244 getWorkGroupInfoSizeArray(CLKernel kernel, CLDevice device, int param_name)245 long[] getWorkGroupInfoSizeArray(CLKernel kernel, CLDevice device, int param_name); 246 getWorkGroupInfoLong(CLKernel kernel, CLDevice device, int param_name)247 long getWorkGroupInfoLong(CLKernel kernel, CLDevice device, int param_name); 248 249 } 250 251 // -------[ IMPLEMENTATION STUFF BELOW ]------- 252 release()253 int release() { 254 try { 255 return super.release(); 256 } finally { 257 if ( !isValid() ) 258 getParent().getCLKernelRegistry().unregisterObject(this); 259 } 260 } 261 262 }