Faster DP_fiber with GPU processing... Run test\gpu_cpu_comparison.m to see difference on your setup

This commit is contained in:
silas (home)
2026-02-01 13:53:20 +01:00
parent 67689bb70f
commit fba7cbdba2
15 changed files with 1281 additions and 217 deletions

View File

@@ -42,7 +42,7 @@ classdef Optical_Demultiplex < handle
function signalclasses_out = process(obj, signalclass_in)
% ---- Infer wavelength: either given or from input total signal
% ---- Infer wavelength: either given or from input total signal
if isempty(obj.wavelengthplan)
obj.wavelengthplan = signalclass_in.lambda; %meter
else
@@ -81,7 +81,7 @@ classdef Optical_Demultiplex < handle
obj
signal_in
end
w = obj.fs_out ./ obj.fs_in ;
blocklen_in = length(signal_in);
blocklen_out = w*blocklen_in;
@@ -119,30 +119,31 @@ classdef Optical_Demultiplex < handle
N = size(lo,1);
C = size(lo,2);
x_envelopes = zeros(N, C, 'like', signal_in);
y_envelopes = zeros(N, C, 'like', signal_in);
% ---- VECTORIZED: Process all channels in parallel ----
% Batched FFT operates on each column simultaneously on GPU
s1 = signal_in(:,1);
s2 = signal_in(:,2);
% Extract polarization signals
s1 = signal_in(:,1); % X polarization [N×1]
s2 = signal_in(:,2); % Y polarization [N×1]
% Reusable work buffers (avoid reallocations)
wrk_time = zeros(N,1, 'like', signal_in);
wrk_freq = zeros(N,1, 'like', signal_in);
% Broadcast signal to all channels and multiply with LO
% s1, s2 are [N×1], lo is [N×C] result is [N×C]
x_mixed = att .* s1 .* lo; % [N×C]
y_mixed = att .* s2 .* lo; % [N×C]
% Batched FFT: each column computed in parallel
x_freq = fft(x_mixed); % [N×C]
y_freq = fft(y_mixed); % [N×C]
% Apply filter (H is [N×1], broadcasts across columns)
x_filtered = x_freq .* H; % [N×C]
y_filtered = y_freq .* H; % [N×C]
% Batched IFFT
x_envelopes = ifft(x_filtered); % [N×C]
y_envelopes = ifft(y_filtered); % [N×C]
for c = 1:C
% ---- X branch ----
wrk_time(:) = att .* s1 .* lo(:,c); % N×1
wrk_freq(:) = fft(wrk_time); % N×1
wrk_freq(:) = wrk_freq .* H; % N×1
x_envelopes(:,c) = ifft(wrk_freq); % N×1
% ---- Y branch ----
wrk_time(:) = att .* s2 .* lo(:,c);
wrk_freq(:) = fft(wrk_time);
wrk_freq(:) = wrk_freq .* H;
y_envelopes(:,c) = ifft(wrk_freq);
end
end
end
end