Package net.haesleinhuepf.clij.clearcl
Class ClearCLProgram
- java.lang.Object
-
- net.haesleinhuepf.clij.clearcl.ClearCLProgram
-
- All Implemented Interfaces:
AutoCloseable
public class ClearCLProgram extends Object implements AutoCloseable
ClearCLProgram is the ClearCL abstraction for OpenCl programs.- Author:
- royer
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBuildOption(String pOption)Adds an building option for this program.voidaddBuildOptionAllMathOpt()Adds all math optimizations option available.voidaddBuildOptionFastRelaxedMath()Add the -cl-fast-relaxed-math compile option.
Sets the optimization options -cl-finite-math-only and -cl-unsafe-math-optimizations.voidaddBuildOptionFiniteMathOnly()Add the -cl-finite-math-only compile option.
Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or infinites.voidaddBuildOptionMadEnable()Add the -cl-mad-enable compile option.
Allow a * b + c to be replaced by a mad.voidaddBuildOptionNoSignedZero()Add the -cl-no-signed-zero compile option.
Allow optimizations for floating-point arithmetic that ignore the signedness of zero.voidaddBuildOptionNVMaximumRegistryCount(int N)Add the -cl-nv-maxrregcount=N compilation option (NVIDIA GPUs only)
Specify the maximum number of registers that GPU functions can use.voidaddBuildOptionNVOptimizationLevel(int N)Add the -cl-nv-opt-level compilation option (NVIDIA GPUs only)
Specify optimization level (default value: 3)voidaddBuildOptionNVVerbose()Add the -cl-nv-verbose compilation option (NVIDIA GPUs only)
Enable verbose mode.voidaddBuildOptionUnsafeMathOptimizations()Add the -cl-unsafe-math-optimizations option.
Allow optimizations for floating-point arithmetic that (a) assume that arguments and results are valid, (b) may violate IEEE 754 standard and (c) may violate the OpenCL numerical compliance requirements as defined in section 7.4 for single-precision floating-point, section 9.3.9 for double-precision floating-point, and edge case behavior in section 7.5.voidaddDefine(String pSymbol)Adds a define (e.g.voidaddDefine(String pKey, Number pValue)Adds a numerical define (e.g.voidaddDefine(String pKey, String pValue)Adds a define (e.g.voidaddDefineForDataType(ImageChannelDataType pChannelDataType)Adds one of three kinds of defines: FLOAT, INT and UINT depending on the given channel datatype.voidaddIncludesReferenceClass(Class<?> pReferenceClass)Adds a reference class used to locate resources (*.cl files) for includes in cl files.voidaddIncludesSearchPackage(String pPackagePath)Adds a package to the list of Java packages to search for reference classes when loading includes in cl files.voidaddSource(Class<?> pClassForRessource, String pIncludeRessourceName)Adds source code to this program from a resource file located relative to a given class.voidaddSource(String pSourceCode)Adds source code to this program.BuildStatusbuild()Builds this program.BuildStatusbuildAndLog()Builds program and logs any errors on the stdoutvoidclearBuildOptions()Clears all options for this program.voidclearDefines()Clears all defines.voidclearSources()Clears all sources in this program.voidclose()ClearCLKernelcreateKernel(String pKernelName)Creates kernel of given name from this programStringgetBuildLog()Returns last build logs for this program.BuildStatusgetBuildStatus()Returns last build status for this program.ClearCLContextgetContext()Returns the context for this program.ClearCLDevicegetDevice()Returns the device for this program.ClearCLKernelgetKernel(String pKernelName)Returns the kernel of a given name.intgetNumberLinesOfCode()Returns the number of lines of code for this program.StringgetSourceCode()Returns the complete concatenated source code with includes and defines added.StringtoString()
-
-
-
Method Detail
-
addIncludesSearchPackage
public void addIncludesSearchPackage(String pPackagePath)
Adds a package to the list of Java packages to search for reference classes when loading includes in cl files.- Parameters:
pPackagePath- full package path and package name.
-
addIncludesReferenceClass
public void addIncludesReferenceClass(Class<?> pReferenceClass)
Adds a reference class used to locate resources (*.cl files) for includes in cl files. This method is preferred because it is more resiliant to refactoring.- Parameters:
pReferenceClass- reference class
-
addSource
public void addSource(String pSourceCode)
Adds source code to this program. You must rebuild after this call for changes to take effect.- Parameters:
pSourceCode- source code string
-
addSource
public void addSource(Class<?> pClassForRessource, String pIncludeRessourceName) throws IOException
Adds source code to this program from a resource file located relative to a given class. You must rebuild after this call for changes to take effect.- Parameters:
pClassForRessource- Reference class to locate resourcespIncludeRessourceName- Resource file names (relative to reference class)- Throws:
IOException- if problem while loading resource
-
clearSources
public void clearSources()
Clears all sources in this program. You must rebuild after this call for changes to take effect.
-
addDefine
public void addDefine(String pKey, String pValue)
Adds a define (e.g. #define 'key' 'value') to the program source code. You must rebuild after this call for changes to take effect.- Parameters:
pKey- keypValue- value
-
addDefine
public void addDefine(String pKey, Number pValue)
Adds a numerical define (e.g. #define 'key' 'value' with 'value' a number) to the program source code. You must rebuild after this call for changes to take effect.- Parameters:
pKey- keypValue- value
-
addDefine
public void addDefine(String pSymbol)
Adds a define (e.g. #define 'symbol') to the program source code. You must rebuild after this call for changes to take effect.- Parameters:
pSymbol- define symbol
-
addDefineForDataType
public void addDefineForDataType(ImageChannelDataType pChannelDataType)
Adds one of three kinds of defines: FLOAT, INT and UINT depending on the given channel datatype. This is usefull for kernels that need to switch between different variants of write_imageX and read_imageX.- Parameters:
pChannelDataType- channel data type
-
clearDefines
public void clearDefines()
Clears all defines. You must rebuild after this call for changes to take effect.
-
addBuildOption
public void addBuildOption(String pOption)
Adds an building option for this program. You must rebuild after this call for changes to take effect.- Parameters:
pOption- option string
-
clearBuildOptions
public void clearBuildOptions()
Clears all options for this program. You must rebuild after this call for changes to take effect.
-
getDevice
public ClearCLDevice getDevice()
Returns the device for this program.- Returns:
- device
-
getContext
public ClearCLContext getContext()
Returns the context for this program.- Returns:
- context
-
buildAndLog
public BuildStatus buildAndLog() throws IOException
Builds program and logs any errors on the stdout- Returns:
- build status
- Throws:
IOException- thrown if source code includes cannot be resolved
-
build
public BuildStatus build() throws IOException
Builds this program. The source code can be changed after a first build and this method will build a new program from scratch.- Returns:
- build status
- Throws:
IOException- thrown if source code includes cannot be resolved
-
getSourceCode
public String getSourceCode() throws IOException
Returns the complete concatenated source code with includes and defines added.- Returns:
- source code
- Throws:
IOException- thrown if the includes cannot be resolved
-
getBuildStatus
public BuildStatus getBuildStatus()
Returns last build status for this program.- Returns:
- last build status
-
getBuildLog
public String getBuildLog()
Returns last build logs for this program.- Returns:
- build logs
-
getKernel
public ClearCLKernel getKernel(String pKernelName)
Returns the kernel of a given name. If the kernel is not yet created, it is then created on-demand. Note: this will not recreate a kernel that already exists.- Parameters:
pKernelName- kernel name- Returns:
- kernel
-
createKernel
public ClearCLKernel createKernel(String pKernelName)
Creates kernel of given name from this program- Parameters:
pKernelName- kernel name (function name)- Returns:
- kernel
-
getNumberLinesOfCode
public int getNumberLinesOfCode()
Returns the number of lines of code for this program.- Returns:
- number of line of code.
-
addBuildOptionAllMathOpt
public void addBuildOptionAllMathOpt()
Adds all math optimizations option available. Note: this might lead to 'unsafe' floating point behavior, although in practice it is rarely a problem.F You must rebuild after this call for changes to take effect.
-
addBuildOptionFastRelaxedMath
public void addBuildOptionFastRelaxedMath()
Add the -cl-fast-relaxed-math compile option.
Sets the optimization options -cl-finite-math-only and -cl-unsafe-math-optimizations. This allows optimizations for floating-point arithmetic that may violate the IEEE 754 standard and the OpenCL numerical compliance requirements defined in the specification in section 7.4 for single-precision floating-point, section 9.3.9 for double-precision floating-point, and edge case behavior in section 7.5. This option causes the preprocessor macro __FAST_RELAXED_MATH__ to be defined in the OpenCL program.
Also see : Khronos' documentation for clBuildProgram.
-
addBuildOptionNoSignedZero
public void addBuildOptionNoSignedZero()
Add the -cl-no-signed-zero compile option.
Allow optimizations for floating-point arithmetic that ignore the signedness of zero. IEEE 754 arithmetic specifies the behavior of distinct +0.0 and -0.0 values, which then prohibits simplification of expressions such as x+0.0 or 0.0*x (even with -clfinite-math only). This option implies that the sign of a zero result isn't significant.
Also see : Khronos' documentation for clBuildProgram.
-
addBuildOptionMadEnable
public void addBuildOptionMadEnable()
Add the -cl-mad-enable compile option.
Allow a * b + c to be replaced by a mad. The mad computes a * b + c with reduced accuracy. For example, some OpenCL devices implement mad as truncate the result of a * b before adding it to c.
Also see : Khronos' documentation for clBuildProgram.
-
addBuildOptionFiniteMathOnly
public void addBuildOptionFiniteMathOnly()
Add the -cl-finite-math-only compile option.
Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or infinites. This option may violate the OpenCL numerical compliance requirements defined in in section 7.4 for single-precision floating-point, section 9.3.9 for double-precision floating-point, and edge case behavior in section 7.5.
Also see : Khronos' documentation for clBuildProgram.
-
addBuildOptionUnsafeMathOptimizations
public void addBuildOptionUnsafeMathOptimizations()
Add the -cl-unsafe-math-optimizations option.
Allow optimizations for floating-point arithmetic that (a) assume that arguments and results are valid, (b) may violate IEEE 754 standard and (c) may violate the OpenCL numerical compliance requirements as defined in section 7.4 for single-precision floating-point, section 9.3.9 for double-precision floating-point, and edge case behavior in section 7.5. This option includes the -cl-no-signed-zeros and -cl-mad-enable options.
Also see : Khronos' documentation for clBuildProgram.
-
addBuildOptionNVVerbose
public void addBuildOptionNVVerbose()
Add the -cl-nv-verbose compilation option (NVIDIA GPUs only)
Enable verbose mode. Output will be reported in JavaCL's log at the INFO level
-
addBuildOptionNVMaximumRegistryCount
public void addBuildOptionNVMaximumRegistryCount(int N)
Add the -cl-nv-maxrregcount=N compilation option (NVIDIA GPUs only)
Specify the maximum number of registers that GPU functions can use. Until a function-specific limit, a higher value will generally increase the performance of individual GPU threads that execute this function. However, because thread registers are allocated from a global register pool on each GPU, a higher value of this option will also reduce the maximum thread block size, thereby reducing the amount of thread parallelism. Hence, a good maxrregcount value is the result of a trade-off. If this option is not specified, then no maximum is assumed. Otherwise the specified value will be rounded to the next multiple of 4 registers until the GPU specific maximum of 128 registers.- Parameters:
N- positive integer
-
addBuildOptionNVOptimizationLevel
public void addBuildOptionNVOptimizationLevel(int N)
Add the -cl-nv-opt-level compilation option (NVIDIA GPUs only)
Specify optimization level (default value: 3)- Parameters:
N- positive integer, or 0 (no optimization).
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
-