Updates complex decimation filters to use either scalar or vector optimal implementation. (#1148)

Updates HackRF native byte buffers with automatic DC removal.
Creates new half-band channel source to replace the cic-based channel source in the heterodyne channelizer.  Resolves issue in RTL native buffer processing.  Creates a CACHED thread pool and reduces the number of threads for the SCHEDULED thread pool to 2.  Changes each of the channel source implementations to use a dedicated thread (Dispatcher class) instead of the scheduled thread pool, to reduce the amount of buffered/retained samples objects in memory. Lots of other small changes and tweaks.
Removes last of Reusable buffer code.  Updates DFTProcessor to use a single thread scheduled executor.  Updates Polyphase channelizer to use threads instead of an executor.  Removes a number of unused classes.
Commenting out window calibration.  Scalar is faster in both implementations.
Adds vector and scalar implementations for windows.  Repackages window and window type classes.
WIP adds vector implementations for Airspy non-interleaved buffer iterator and calibration plugins for both interleaved and non-interleaved buffer iterators.
WIP adds vector implementations for Airspy interleaved buffer iterator.
Work on developing scalar and vector implementations of airspy sample conversion and airspy native buffer processing.
Introduces new INativeBuffer framework where tuner raw samples are retained in their native (compressed) format until when they're needed and they are converted on-demand into smaller complex sample buffers to aid garbage collection.
Removes all usage of ReusableComplexBuffers and ReusableChannelREsultsBuffers.  Updates polyphase channelizer to be more efficient in output channel processing.
Updates ViterbiDecoder to change Map usage to array for memory efficiency.
Updates channel processors to used scalar implementation for gain and mixer, until the polyphase channel results can be fixed to be a multiple of the SIMD lane width.
Resolves final changes for the conversion from interleaved sample arrays to complexsamples buffers for distributing baseband samples to channels and processing chains.
Updates tuner channel sources and all decoders to receive new complex samples buffers, removing the previous reusable complex buffers as the default baseband samples buffer object.
Still to resolve is the ComplexMixer implementations.  Needs validation and a calibration implementation with an update to the complex mixer factory.
Updates the DMR decoder to use optimal (scalar vs vector) implementations of filter and AGC controls.
Updates the AM demodulator for separated I&Q float sample processing.
Code review and testing changes.
updates build script for runtime configuration.
Integrates calibration manager with main sdrtrunk application.  Updates NBFMDecoder to use new optimized FIR and Decimation filter options.
Updates real half-band decimation filters to select the optimal (scalar vs vector) implementation.
Adds calibration manager plugins.
Adds calibration manager and plugins to determine the optimal (scalar vs vector) implementation type to use for various classes of dsp components.
Adds vector squelching FM demodulator and cleans up the IIR filter and power squelch to use all floats.
Adds vector implementation of FM demodulator.  This introduces a new interface that accepts i/q samples as two separate float arrays, versus an interleaved array, which enables more efficient processing.  This new complex sample interface will be used across the codebase eventually.
Adds ComplexOscillator and a SIMD version VectorComplexOscillator.  Deprecates the LowPhaseNoiseOscillator because the ComplexOscillator is about 35% faster.  The vectorized version is about 43% faster when SIMD lane width is 8x.
Adds new vector complex filters and new real oscillators.  Note: the RealOscillator using straight Java math sin() function is 3x slower than the existing legacy implementation.  Will replace this with a complex oscillator that only uses the real part.
Updates ComplexFIRFilter to be 50% more efficient.
Adds 23 tap filter implementations.  Will not add 63-tap implementations because they are slower than the default vector implementation.
Adds 15-tap customized vector half band filters.
Adds initial custom complex vector half-band decimation filters for 11-tap and 15-tap decimation filters..
Adds vector complex half band filter implementations.  Note: performance of the generic 64-bit 2-lane filter is horrible and is not included.
Optimizes complex half-band filter to be 27% more efficient.
Implements vectorized real half-band filter implementations.
Implements a new FIR filter class that processes sample buffers instead of single sample at a time.
Refactored all of the calibratons to be time-duration based.  Testing on windows i7 gen 3 CPU showed that it took 1000x longer for one of the calibrations to run, versus my AMD 5800x.
Changed gradle jvm args so that the windows plaf export is always applied.
Updates gradle build script to ensure incubator module is included and to cleanup javafx library management for building runtime images.
Testing tweaks and changes.
Adds logging limiter to dispatcher for buffer overflows
Adds User Preferences editor for performing Vector/SIMD calibrations and new startup dialog prompting the user to perform calibrations.
Updates calibration manager and all calibration implementations to add warm-up and test phases and to reduce the overall time it takes to calibrate a system.

Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
Denny Sheirer
2022-03-04 08:45:05 -05:00
committed by GitHub
parent 5e9c239ea3
commit 0eec2e7ab8
403 changed files with 22916 additions and 15088 deletions

View File

@@ -0,0 +1,73 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.gui.preference.calibration;
import io.github.dsheirer.preference.UserPreferences;
import javafx.geometry.Insets;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
/**
* Dialog to prompt the user to run the calibrations.
*/
public class CalibrationDialog extends Dialog
{
private UserPreferences mUserPreferences;
public CalibrationDialog(UserPreferences userPreferences)
{
mUserPreferences = userPreferences;
setTitle("Calibrate CPU");
setHeaderText("Perform CPU Calibration?");
Label instructionsLabel = new Label("The sdrtrunk application can run more efficiently by using Vector or Single " +
"Instruction Multiple Data (SIMD) CPU operations. sdrtrunk must calibrate your CPU in order " +
"to determine the best implementation.\n\n" +
"Calibration takes a few minutes to complete.\n\n" +
"If you click 'Cancel', you will be prompted next time you run sdrtrunk, or you can open the " +
"User Preferences dialog from the View menu and manually start the calibration process.");
instructionsLabel.setPrefWidth(300);
instructionsLabel.setWrapText(true);
CheckBox doNotShowAgainCheckBox = new CheckBox("Do not show again");
doNotShowAgainCheckBox.setOnAction(event ->
{
mUserPreferences.getVectorCalibrationPreference().setHideCalibrationDialog(doNotShowAgainCheckBox.isSelected());
});
VBox.setVgrow(instructionsLabel, Priority.ALWAYS);
VBox contentBox = new VBox();
contentBox.setPadding(new Insets(10));
contentBox.setSpacing(20);
contentBox.getChildren().addAll(instructionsLabel, doNotShowAgainCheckBox);
getDialogPane().setContent(contentBox);
ButtonType calibrateButtonType = new ButtonType("Calibrate", ButtonBar.ButtonData.OK_DONE);
ButtonType cancelButtonType = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
getDialogPane().getButtonTypes().addAll(calibrateButtonType, cancelButtonType);
}
}

View File

@@ -0,0 +1,347 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.gui.preference.calibration;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import com.google.common.eventbus.Subscribe;
import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.preference.CalibrateRequest;
import io.github.dsheirer.log.TextAreaLogAppender;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.preference.calibration.VectorCalibrationPreference;
import io.github.dsheirer.util.ThreadPool;
import io.github.dsheirer.vector.calibrate.Calibration;
import io.github.dsheirer.vector.calibrate.CalibrationException;
import io.github.dsheirer.vector.calibrate.CalibrationManager;
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import org.controlsfx.control.ToggleSwitch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
* Preference settings for duplicate call audio handling
*/
public class VectorCalibrationPreferenceEditor extends HBox
{
private final static Logger mLog = LoggerFactory.getLogger(VectorCalibrationPreferenceEditor.class);
private VectorCalibrationPreference mPreference;
private GridPane mEditorPane;
private ToggleSwitch mHideDialogSwitch;
private ToggleSwitch mVectorEnabled;
private Label mCalibrationsPendingValue;
private Button mResetAllButton;
private Button mCalibrateButton;
private ProgressBar mProgressBar;
private Label mCalibratingLabel;
private TextArea mConsoleTextArea;
private TextAreaLogAppender mTextAreaLogAppender;
/**
* Constructs an instance
*/
public VectorCalibrationPreferenceEditor(UserPreferences userPreferences)
{
MyEventBus.getGlobalEventBus().register(this);
mPreference = userPreferences.getVectorCalibrationPreference();
setMaxHeight(Double.MAX_VALUE);
setMaxWidth(Double.MAX_VALUE);
VBox vbox = new VBox();
vbox.setMaxHeight(Double.MAX_VALUE);
vbox.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(vbox, Priority.ALWAYS);
VBox.setVgrow(getEditorPane(), Priority.NEVER);
vbox.getChildren().add(getEditorPane());
ScrollPane scrollPane = new ScrollPane(getConsoleTextArea());
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
vbox.getChildren().add(scrollPane);
getChildren().add(vbox);
}
@Subscribe
public void process(CalibrateRequest request)
{
getCalibrateButton().fire();
}
private GridPane getEditorPane()
{
if(mEditorPane == null)
{
int row = 0;
mEditorPane = new GridPane();
mEditorPane.setPadding(new Insets(10));
mEditorPane.setHgap(10);
mEditorPane.setVgap(10);
Label titleLabel = new Label("CPU Vector SIMD Preferences");
GridPane.setConstraints(titleLabel, 0, row++, 2, 1);
mEditorPane.getChildren().add(titleLabel);
GridPane.setConstraints(getVectorEnabledToggleSwitch(), 0, row);
GridPane.setHalignment(getVectorEnabledToggleSwitch(), HPos.RIGHT);
mEditorPane.getChildren().add(getVectorEnabledToggleSwitch());
Label enableSimdLabel = new Label("Enable SIMD Vector Operations");
GridPane.setConstraints(enableSimdLabel, 1, row++);
mEditorPane.getChildren().add((enableSimdLabel));
GridPane.setConstraints(getHideDialogSwitch(), 0, row);
GridPane.setHalignment(getHideDialogSwitch(), HPos.RIGHT);
mEditorPane.getChildren().add(getHideDialogSwitch());
Label hideDialogLabel = new Label("Don't Show Calibration Dialog When New Calibrations Are Available");
GridPane.setConstraints(hideDialogLabel, 1, row++);
mEditorPane.getChildren().add((hideDialogLabel));
GridPane.setConstraints(getCalibrationsPendingValue(), 0, row);
mEditorPane.getChildren().add(getCalibrationsPendingValue());
Label calibrationsPendingLabel = new Label("Calibrations To Perform");
GridPane.setHalignment(getCalibrationsPendingValue(), HPos.RIGHT);
GridPane.setConstraints(calibrationsPendingLabel, 1, row++);
mEditorPane.getChildren().add(calibrationsPendingLabel);
updateControls();
GridPane.setConstraints(getCalibratingLabel(), 0, row);
mEditorPane.getChildren().add(getCalibratingLabel());
GridPane.setConstraints(getProgressBar(), 1, row++);
mEditorPane.getChildren().add(getProgressBar());
HBox buttonsBox = new HBox();
buttonsBox.setSpacing(10);
buttonsBox.getChildren().addAll(getCalibrateButton(), getResetAllButton());
GridPane.setHalignment(buttonsBox, HPos.CENTER);
GridPane.setConstraints(buttonsBox, 0, row, 2, 1);
mEditorPane.getChildren().add(buttonsBox);
}
return mEditorPane;
}
private void enableConsoleLogging()
{
LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory();
Logger logger = loggerContext.getLogger(Calibration.class);
((ch.qos.logback.classic.Logger)logger).setLevel(Level.INFO);
((ch.qos.logback.classic.Logger)logger).addAppender(getTextAreaLogAppender());
getTextAreaLogAppender().start();
}
private void disableConsoleLogging()
{
LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory();
Logger logger = loggerContext.getLogger(Calibration.class);
((ch.qos.logback.classic.Logger)logger).detachAppender(getTextAreaLogAppender());
getTextAreaLogAppender().stop();
}
private TextAreaLogAppender getTextAreaLogAppender()
{
if(mTextAreaLogAppender == null)
{
mTextAreaLogAppender = new TextAreaLogAppender(getConsoleTextArea(), "My Console Logger");
}
return mTextAreaLogAppender;
}
private TextArea getConsoleTextArea()
{
if(mConsoleTextArea == null)
{
mConsoleTextArea = new TextArea();
mConsoleTextArea.setDisable(true);
mConsoleTextArea.setMaxHeight(Double.MAX_VALUE);
mConsoleTextArea.setMaxWidth(Double.MAX_VALUE);
}
return mConsoleTextArea;
}
private ProgressBar getProgressBar()
{
if(mProgressBar == null)
{
mProgressBar = new ProgressBar();
mProgressBar.setVisible(false);
}
return mProgressBar;
}
private Button getResetAllButton()
{
if(mResetAllButton == null)
{
mResetAllButton = new Button("Reset All Calibrations");
mResetAllButton.setTooltip(new Tooltip("Reset all calibrations to an Uncalibrated state"));
mResetAllButton.setOnAction(event ->
{
CalibrationManager.getInstance().reset();
updateControls();
});
}
return mResetAllButton;
}
private Button getCalibrateButton()
{
if(mCalibrateButton == null)
{
mCalibrateButton = new Button("Calibrate");
mCalibrateButton.setTooltip(new Tooltip("Calibrate the items that need calibrated"));
mCalibrateButton.setOnAction(event ->
{
getCalibrateButton().setDisable(true);
getResetAllButton().setDisable(true);
getConsoleTextArea().clear();
getConsoleTextArea().appendText("Calibrating. Each calibration lasts 20 - 40 seconds.");
enableConsoleLogging();
getCalibratingLabel().setVisible(true);
getProgressBar().setVisible(true);
getProgressBar().setProgress(0.0);
ThreadPool.CACHED.submit(() ->
{
try
{
CalibrationManager manager = CalibrationManager.getInstance();
List<Calibration> calibrations = manager.getUncalibrated();
int counter = 0;
for(Calibration calibration: calibrations)
{
counter++;
final String message = "\n\nCalibration [" + counter + "/" + calibrations.size() + "] - " + calibration.getType();
Platform.runLater(() -> getConsoleTextArea().appendText(message));
try
{
calibration.calibrate();
final double progress = (double)counter / (double)calibrations.size();
Platform.runLater(() -> getProgressBar().setProgress(progress));
}
catch(CalibrationException ce)
{
mLog.error("Calibration error for " + calibration.getType(), ce);
}
}
}
catch(Throwable t)
{
mLog.error("Error while performing calibrations", t);
}
Platform.runLater(() ->
{
getConsoleTextArea().appendText("\nCalibration Complete!\nNote: restart the application to use these new settings.");
getCalibratingLabel().setVisible(false);
getProgressBar().setVisible(false);
updateControls();
disableConsoleLogging();
});
});
});
}
return mCalibrateButton;
}
private Label getCalibratingLabel()
{
if(mCalibratingLabel == null)
{
mCalibratingLabel = new Label("Calibrating:");
mCalibratingLabel.setVisible(false);
}
return mCalibratingLabel;
}
private void updateControls()
{
int pending = CalibrationManager.getInstance().getUncalibrated().size();
int total = CalibrationManager.getInstance().getCalibrationTypes().size();
getCalibrationsPendingValue().setText(String.valueOf(pending));
getCalibrateButton().setDisable(pending == 0);
getResetAllButton().setDisable(pending == total);
}
private Label getCalibrationsPendingValue()
{
if(mCalibrationsPendingValue == null)
{
mCalibrationsPendingValue = new Label(" ");
}
return mCalibrationsPendingValue;
}
private ToggleSwitch getVectorEnabledToggleSwitch()
{
if(mVectorEnabled == null)
{
mVectorEnabled = new ToggleSwitch();
mVectorEnabled.setTooltip(new Tooltip("Allow sdrtrunk to use optimized vector operations when supported by your CPU"));
mVectorEnabled.setSelected(mPreference.isVectorEnabled());
mVectorEnabled.selectedProperty()
.addListener((observable, oldValue, enabled) -> mPreference.setVectorEnabled(enabled));
}
return mVectorEnabled;
}
private ToggleSwitch getHideDialogSwitch()
{
if(mHideDialogSwitch == null)
{
mHideDialogSwitch = new ToggleSwitch();
mHideDialogSwitch.setTooltip(new Tooltip("Don't show dialog when new calibrations are available"));
mHideDialogSwitch.setSelected(mPreference.isHideCalibrationDialog());
mHideDialogSwitch.selectedProperty().addListener((observable, oldValue, hide) -> mPreference.setHideCalibrationDialog(hide));
}
return mHideDialogSwitch;
}
}