-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CUDA support * Add Socket.flagChanged() No more socket.setValue(socket.getValue()) hacks * Allow CUDA versions to be optionally specified with -Pcuda Or -PWITH_CUDA * Add special CUDA socket Socket is disabled when CUDA is unavailable * Exit when CUDA runtime is required but not available * Make normalize operation CUDA-accelerated Slight speedup versus CPU * Add CUDA acceleration to basic CV operations * Clean up flagChanged in OutputSocketImpl * Append 'cuda' to versions of GRIP with CUDA acceleration * Add CUDA classes to dedicated cuda module This lets us create CudaDetectors etc. before loading OpenCV in the core module Move logger setup to its own class, since the core module may not load before app exits * Make SafeShutdown take an ExitCode enum instead of raw int * Use JNI loading to locate CUDA install * Use WriteProperties task to save CUDA runtime properties
- Loading branch information
1 parent
142b1de
commit 34afc3d
Showing
103 changed files
with
2,413 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package edu.wpi.grip.core; | ||
|
||
import edu.wpi.grip.core.cuda.AccelerationMode; | ||
import edu.wpi.grip.core.cuda.CudaAccelerationMode; | ||
import edu.wpi.grip.core.cuda.CudaDetector; | ||
import edu.wpi.grip.core.cuda.CudaVerifier; | ||
import edu.wpi.grip.core.cuda.LoadingCudaDetector; | ||
import edu.wpi.grip.core.cuda.NullAccelerationMode; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Scopes; | ||
import com.google.inject.name.Names; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class GripCudaModule extends AbstractModule { | ||
|
||
private static final Logger logger = Logger.getLogger(GripCudaModule.class.getName()); | ||
private static final String CUDA_ENABLED_KEY = "edu.wpi.grip.cuda.enabled"; | ||
|
||
@Override | ||
protected void configure() { | ||
bind(CudaDetector.class).to(LoadingCudaDetector.class); | ||
|
||
Properties cudaProperties = getCudaProperties(); | ||
bind(Properties.class) | ||
.annotatedWith(Names.named("cudaProperties")) | ||
.toInstance(cudaProperties); | ||
|
||
if (Boolean.valueOf(cudaProperties.getProperty(CUDA_ENABLED_KEY, "false"))) { | ||
bind(AccelerationMode.class).to(CudaAccelerationMode.class); | ||
} else { | ||
bind(AccelerationMode.class).to(NullAccelerationMode.class); | ||
} | ||
|
||
bind(CudaVerifier.class).in(Scopes.SINGLETON); | ||
} | ||
|
||
private Properties getCudaProperties() { | ||
try (InputStream resourceAsStream = getClass().getResourceAsStream("CUDA.properties")) { | ||
Properties cudaProps = new Properties(); | ||
cudaProps.load(resourceAsStream); | ||
return cudaProps; | ||
} catch (IOException e) { | ||
logger.log(Level.WARNING, "Could not read CUDA properties", e); | ||
return new Properties(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package edu.wpi.grip.core; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.FileHandler; | ||
import java.util.logging.Handler; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.LogRecord; | ||
import java.util.logging.Logger; | ||
import java.util.logging.SimpleFormatter; | ||
import java.util.logging.StreamHandler; | ||
|
||
public final class Loggers { | ||
|
||
private Loggers() { | ||
throw new UnsupportedOperationException("This is a utility class!"); | ||
} | ||
|
||
/** | ||
* Sets up loggers to print to stdout and to ~/GRIP/GRIP.log. This should only be called once | ||
* in the application lifecycle, at startup. | ||
*/ | ||
public static void setupLoggers() { | ||
// Set up the global level logger. This handles IO for all loggers. | ||
final Logger globalLogger = LogManager.getLogManager().getLogger(""); | ||
|
||
try { | ||
// Remove the default handlers that stream to System.err | ||
for (Handler handler : globalLogger.getHandlers()) { | ||
globalLogger.removeHandler(handler); | ||
} | ||
|
||
GripFileManager.GRIP_DIRECTORY.mkdirs(); | ||
final Handler fileHandler | ||
= new FileHandler(GripFileManager.GRIP_DIRECTORY.getPath() + "/GRIP.log"); | ||
|
||
//Set level to handler and logger | ||
fileHandler.setLevel(Level.INFO); | ||
globalLogger.setLevel(Level.INFO); | ||
|
||
// We need to stream to System.out instead of System.err | ||
final StreamHandler sh = new StreamHandler(System.out, new SimpleFormatter()) { | ||
|
||
@Override | ||
public synchronized void publish(final LogRecord record) { | ||
super.publish(record); | ||
// For some reason this doesn't happen automatically. | ||
// This will ensure we get all of the logs printed to the console immediately | ||
// when running on a remote device. | ||
flush(); | ||
} | ||
}; | ||
sh.setLevel(Level.CONFIG); | ||
|
||
globalLogger.addHandler(sh); // Add stream handler | ||
|
||
globalLogger.addHandler(fileHandler); //Add the handler to the global logger | ||
|
||
fileHandler.setFormatter(new SimpleFormatter()); //log in text, not xml | ||
|
||
globalLogger.config("Configuration done."); //Log that we are done setting up the logger | ||
globalLogger.config("GRIP Version: " + edu.wpi.grip.core.Main.class.getPackage() | ||
.getImplementationVersion()); | ||
|
||
} catch (IOException exception) { //Something happened setting up file IO | ||
throw new IllegalStateException("Failed to configure the Logger", exception); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.