Repository navigation
Add reusable band-power contexts with bounded native workers - #873
Open
Andrey1994 wants to merge 1 commit into
Open
Andrey1994 wants to merge 1 commit into
Andrey1994 wants to merge 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| var batch = new double[8, 2048]; | ||
| for (int row = 0; row < 8; row++) | ||
| for (int col = 0; col < 2048; col++) | ||
| batch[row, col] = Math.Sin((row + 1) * col * 0.1); |
| [DllImport ("DataHandler", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int read_file (double[] data, int[] num_rows, int[] num_cols, string file_name, int max_elements); | ||
| [DllImport ("DataHandler", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int create_band_power_context (int max_channels, int max_samples, double[] starts, double[] stops, int bands, int fs, int apply, int nfft, double low, double high, int mains, int detrend, int workers, int[] handle); |
| [DllImport ("DataHandler", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int create_band_power_context (int max_channels, int max_samples, double[] starts, double[] stops, int bands, int fs, int apply, int nfft, double low, double high, int mains, int detrend, int workers, int[] handle); | ||
| [DllImport ("DataHandler", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int process_band_power_context (int handle, double[,] data, int capacity, int rows, int samples, int stride, int[] channels, int count, double[] averages, double[] deviations, int output_capacity); |
| [DllImport ("DataHandler", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int process_band_power_context (int handle, double[,] data, int capacity, int rows, int samples, int stride, int[] channels, int count, double[] averages, double[] deviations, int output_capacity); | ||
| [DllImport ("DataHandler", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int release_band_power_context (int handle); |
| [DllImport ("DataHandler32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int read_file (double[] data, int[] num_rows, int[] num_cols, string file_name, int max_elements); | ||
| [DllImport ("DataHandler32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int create_band_power_context (int max_channels, int max_samples, double[] starts, double[] stops, int bands, int fs, int apply, int nfft, double low, double high, int mains, int detrend, int workers, int[] handle); |
| [DllImport ("DataHandler32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int create_band_power_context (int max_channels, int max_samples, double[] starts, double[] stops, int bands, int fs, int apply, int nfft, double low, double high, int mains, int detrend, int workers, int[] handle); | ||
| [DllImport ("DataHandler32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int process_band_power_context (int handle, double[,] data, int capacity, int rows, int samples, int stride, int[] channels, int count, double[] averages, double[] deviations, int output_capacity); |
| [DllImport ("DataHandler32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int process_band_power_context (int handle, double[,] data, int capacity, int rows, int samples, int stride, int[] channels, int count, double[] averages, double[] deviations, int output_capacity); | ||
| [DllImport ("DataHandler32", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] | ||
| public static extern int release_band_power_context (int handle); |
| switch (PlatformHelper.get_library_environment ()) | ||
| { | ||
| case LibraryEnvironment.x64: | ||
| return DataHandlerLibrary64.create_band_power_context (max_channels, max_samples, starts, stops, bands, fs, apply, nfft, low, high, mains, detrend, workers, handle); |
| case LibraryEnvironment.x64: | ||
| return DataHandlerLibrary64.create_band_power_context (max_channels, max_samples, starts, stops, bands, fs, apply, nfft, low, high, mains, detrend, workers, handle); | ||
| case LibraryEnvironment.x86: | ||
| return DataHandlerLibrary32.create_band_power_context (max_channels, max_samples, starts, stops, bands, fs, apply, nfft, low, high, mains, detrend, workers, handle); |
| switch (PlatformHelper.get_library_environment ()) | ||
| { | ||
| case LibraryEnvironment.x64: | ||
| return DataHandlerLibrary64.process_band_power_context (handle, data, capacity, rows, samples, stride, channels, count, averages, deviations, output_capacity); |
| def __del__(self): | ||
| try: | ||
| self.close() | ||
| except Exception: |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repeated windowed band-power calls rebuild filter/FFT setup and allocate channel workspaces. Add an optional bounded context API that retains coefficients, normalized windows, FFT plans, per-worker scratch buffers, and native worker threads. Python and C# can select source rows directly and reuse caller-owned output arrays. Existing APIs remain available; the shared spectral kernel preserves their numerical definition.
The C API validates input/output capacities and row strides. Context calls serialize per handle; independent contexts run concurrently. Release is safe with in-flight operations through shared ownership. Batches below eight channels run serially; workers=0 chooses up to four workers, and workers=1 is serial. This uses std::thread and adds no OpenMP runtime dependency. It does not change windowed zero-phase processing into causal streaming.
Validation: MSVC Release /MT build; 18 signal-processing and 22 band-power Python regressions passed, including legacy equivalence, custom settings, repeated/reordered channels, failure recovery, capacities, and concurrent calls; C# context/regression executable passed against the new DLL. Tests extend the existing Windows/Unix CI suites. A local 64-channel x 2,000-sample filtered band-power probe improved from 28.7 ms to 9.25 ms with four workers (~3.1x); performance depends on workload and hardware.
Part of #601. Based directly on master, independent of #871 and #872.