View Javadoc
1   package net.bmahe.genetics4j.gpu.opencl;
2   
3   import org.apache.commons.lang3.Validate;
4   import org.apache.logging.log4j.LogManager;
5   import org.apache.logging.log4j.Logger;
6   import org.jocl.CL;
7   import org.jocl.cl_device_id;
8   import org.jocl.cl_kernel;
9   
10  import net.bmahe.genetics4j.gpu.opencl.model.KernelInfo;
11  
12  public class KernelInfoReader {
13  	public static final Logger logger = LogManager.getLogger(KernelInfoReader.class);
14  
15  	public KernelInfo read(final cl_device_id deviceId, final cl_kernel kernel, final String kernelName) {
16  		Validate.notNull(deviceId);
17  		Validate.notNull(kernel);
18  		Validate.notBlank(kernelName);
19  
20  		final var kernelInfoBuilder = KernelInfo.builder();
21  		kernelInfoBuilder.name(kernelName);
22  
23  		final long workGroupSize = KernelInfoUtils
24  				.getKernelWorkGroupInfoLong(deviceId, kernel, CL.CL_KERNEL_WORK_GROUP_SIZE);
25  		kernelInfoBuilder.workGroupSize(workGroupSize);
26  
27  		final long preferredWorkGroupSizeMultiple = KernelInfoUtils
28  				.getKernelWorkGroupInfoLong(deviceId, kernel, CL.CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE);
29  		kernelInfoBuilder.preferredWorkGroupSizeMultiple(preferredWorkGroupSizeMultiple);
30  
31  		final long localMemSize = KernelInfoUtils
32  				.getKernelWorkGroupInfoLong(deviceId, kernel, CL.CL_KERNEL_LOCAL_MEM_SIZE);
33  		kernelInfoBuilder.localMemSize(localMemSize);
34  
35  		final long privateMemSize = KernelInfoUtils
36  				.getKernelWorkGroupInfoLong(deviceId, kernel, CL.CL_KERNEL_PRIVATE_MEM_SIZE);
37  		kernelInfoBuilder.privateMemSize(privateMemSize);
38  
39  		return kernelInfoBuilder.build();
40  	}
41  }