Class KernelManager
- java.lang.Object
-
- com.aparapi.internal.kernel.KernelManager
-
public class KernelManager extends java.lang.Object
Created by Barney on 24/08/2015.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
KernelManager.DeprecatedMethods
New home for deprecated methods ofDevice
.
-
Field Summary
Fields Modifier and Type Field Description private KernelPreferences
defaultPreferences
private static KernelManager
INSTANCE
private java.util.LinkedHashMap<java.lang.Class<? extends Kernel>,PreferencesWrapper>
preferences
private java.util.LinkedHashMap<java.lang.Class<? extends Kernel>,KernelProfile>
profiles
private java.util.LinkedHashMap<java.lang.Class<? extends Kernel>,Kernel>
sharedInstances
-
Constructor Summary
Constructors Modifier Constructor Description protected
KernelManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Device
bestDevice()
protected KernelPreferences
createDefaultPreferences()
protected java.util.LinkedHashSet<Device>
createDefaultPreferredDevices()
protected java.util.Comparator<OpenCLDevice>
getDefaultAcceleratorComparator()
NB, returns -ve for the better device.protected java.util.Comparator<OpenCLDevice>
getDefaultGPUComparator()
NB, returns -ve for the better device.KernelPreferences
getDefaultPreferences()
KernelPreferences
getPreferences(Kernel kernel)
protected java.util.List<Device.TYPE>
getPreferredDeviceTypes()
KernelProfile
getProfile(java.lang.Class<? extends Kernel> kernelClass)
private <T extends Kernel>
TgetSharedKernelInstance(java.lang.Class<T> kernelClass)
static KernelManager
instance()
void
reportDeviceUsage(java.lang.StringBuilder builder, boolean withProfilingInfo)
Append a report tobuilder
which contains information, per Kernel subclass, on which device is currently being used for the kernel class, and which (if any) devices failed to execute a given Kernel.void
reportProfilingSummary(java.lang.StringBuilder builder)
protected static boolean
selectLhs(OpenCLDevice _deviceLhs, OpenCLDevice _deviceRhs)
private static boolean
selectLhsByType(Device.TYPE lhs, Device.TYPE rhs)
protected static boolean
selectLhsIfCUDA(OpenCLDevice _deviceLhs, OpenCLDevice _deviceRhs)
NVidia/CUDA architecture reports maxComputeUnits in a completely different context, i.e.void
setDefaultPreferredDevices(java.util.LinkedHashSet<Device> _devices)
static void
setKernelManager(KernelManager manager)
void
setPreferredDevices(Kernel _kernel, java.util.LinkedHashSet<Device> _devices)
protected void
setup()
Default KernelManager initialization.
Convenience method for being overridden to an empty implementation, so that derived KernelManager classes can provide non static parameters to their constructors.static <T extends Kernel>
TsharedKernelInstance(java.lang.Class<T> kernelClass)
This method returns a shared instance of a given Kernel subclass.
-
-
-
Field Detail
-
INSTANCE
private static KernelManager INSTANCE
-
preferences
private java.util.LinkedHashMap<java.lang.Class<? extends Kernel>,PreferencesWrapper> preferences
-
profiles
private java.util.LinkedHashMap<java.lang.Class<? extends Kernel>,KernelProfile> profiles
-
sharedInstances
private java.util.LinkedHashMap<java.lang.Class<? extends Kernel>,Kernel> sharedInstances
-
defaultPreferences
private KernelPreferences defaultPreferences
-
-
Method Detail
-
setup
protected void setup()
Default KernelManager initialization.
Convenience method for being overridden to an empty implementation, so that derived KernelManager classes can provide non static parameters to their constructors.
-
instance
public static KernelManager instance()
-
setKernelManager
public static void setKernelManager(KernelManager manager)
-
sharedKernelInstance
public static <T extends Kernel> T sharedKernelInstance(java.lang.Class<T> kernelClass)
This method returns a shared instance of a given Kernel subclass. The kernelClass needs a no-args constructor, which need not be public.Each new Kernel instance requires a new JNIContext, the creation of which is expensive. There is apparently no simple solution by which a cached JNIContext can be reused for all instances of a given Kernel class, since it is intimately connected with resource aquisition and release. In the absence of a context caching solution, it is often highly desirable to only ever create one instance of any given Kernel subclass, which this method facilitates.
In order to maintain thread saftey when using a shared instance, it is necessary to synchronize on the returned kernel for the duration of the process of setting up, executing and extracting the results from that kernel.
This method instantiates a Kernel (per Kernel class) via Reflection, and thus can only be used where the Kernel class has a no-args constructor, which need not be public. In fact, if a Kernel subclass is designed to be used in conjunction with this method, it is recommended that its only constructor is a private no-args constructor.
- Throws:
java.lang.RuntimeException
- if the class cannot be instantiated
-
reportDeviceUsage
public void reportDeviceUsage(java.lang.StringBuilder builder, boolean withProfilingInfo)
Append a report tobuilder
which contains information, per Kernel subclass, on which device is currently being used for the kernel class, and which (if any) devices failed to execute a given Kernel.
-
reportProfilingSummary
public void reportProfilingSummary(java.lang.StringBuilder builder)
-
getPreferences
public KernelPreferences getPreferences(Kernel kernel)
-
setPreferredDevices
public void setPreferredDevices(Kernel _kernel, java.util.LinkedHashSet<Device> _devices)
-
getDefaultPreferences
public KernelPreferences getDefaultPreferences()
-
setDefaultPreferredDevices
public void setDefaultPreferredDevices(java.util.LinkedHashSet<Device> _devices)
-
createDefaultPreferences
protected KernelPreferences createDefaultPreferences()
-
getSharedKernelInstance
private <T extends Kernel> T getSharedKernelInstance(java.lang.Class<T> kernelClass)
-
createDefaultPreferredDevices
protected java.util.LinkedHashSet<Device> createDefaultPreferredDevices()
-
getPreferredDeviceTypes
protected java.util.List<Device.TYPE> getPreferredDeviceTypes()
-
getDefaultAcceleratorComparator
protected java.util.Comparator<OpenCLDevice> getDefaultAcceleratorComparator()
NB, returns -ve for the better device.
-
getDefaultGPUComparator
protected java.util.Comparator<OpenCLDevice> getDefaultGPUComparator()
NB, returns -ve for the better device.
-
bestDevice
public Device bestDevice()
-
selectLhs
protected static boolean selectLhs(OpenCLDevice _deviceLhs, OpenCLDevice _deviceRhs)
-
selectLhsIfCUDA
protected static boolean selectLhsIfCUDA(OpenCLDevice _deviceLhs, OpenCLDevice _deviceRhs)
NVidia/CUDA architecture reports maxComputeUnits in a completely different context, i.e. maxComputeUnits is not same as (is much less than) the number of OpenCL cores available.Therefore when comparing an NVidia device we use different criteria.
-
selectLhsByType
private static boolean selectLhsByType(Device.TYPE lhs, Device.TYPE rhs)
-
getProfile
public KernelProfile getProfile(java.lang.Class<? extends Kernel> kernelClass)
-
-