public class KernelManager extends Object
Modifier and Type | Class and Description |
---|---|
static class |
KernelManager.DeprecatedMethods
New home for deprecated methods of
Device . |
Modifier and Type | Method and Description |
---|---|
Device |
bestDevice() |
KernelPreferences |
getDefaultPreferences() |
KernelPreferences |
getPreferences(Kernel kernel) |
KernelProfile |
getProfile(Class<? extends Kernel> kernelClass) |
static KernelManager |
instance() |
void |
reportDeviceUsage(StringBuilder builder,
boolean withProfilingInfo)
Append a report to
builder 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(StringBuilder builder) |
void |
setDefaultPreferredDevices(LinkedHashSet<Device> _devices) |
static void |
setKernelManager(KernelManager manager) |
void |
setPreferredDevices(Kernel _kernel,
LinkedHashSet<Device> _devices) |
static <T extends Kernel> |
sharedKernelInstance(Class<T> kernelClass)
This method returns a shared instance of a given Kernel subclass.
|
public static KernelManager instance()
public static void setKernelManager(KernelManager manager)
public static <T extends Kernel> T sharedKernelInstance(Class<T> kernelClass)
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.
RuntimeException
- if the class cannot be instantiatedpublic void reportDeviceUsage(StringBuilder builder, boolean withProfilingInfo)
builder
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.public void reportProfilingSummary(StringBuilder builder)
public KernelPreferences getPreferences(Kernel kernel)
public void setPreferredDevices(Kernel _kernel, LinkedHashSet<Device> _devices)
public KernelPreferences getDefaultPreferences()
public void setDefaultPreferredDevices(LinkedHashSet<Device> _devices)
public Device bestDevice()
public KernelProfile getProfile(Class<? extends Kernel> kernelClass)
Copyright © 2016 Syncleus. All rights reserved.