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

@@ -24,6 +24,8 @@ classdef DP_Fiber
SS_dzmax % [m] max dz (adaptive SSFM)
SS_dzmin % [m] min dz (adaptive SSFM)
n_waveplates % number of PMD waveplates
useGPU % GPU acceleration: true, false, or 'auto' (default)
useSingle % Use single precision on GPU (default: false)
% ---- Internal state (persistent between calls) ----
state % struct mirroring legacy 'state'
@@ -56,6 +58,8 @@ classdef DP_Fiber
options.SS_dzmax = 2e4 % m
options.SS_dzmin = 100 % m
options.n_waveplates = 100
options.useGPU = 'auto' % 'auto', true, or false
options.useSingle = false % single precision GPU
end
% Copy provided options into properties
@@ -208,7 +212,7 @@ classdef DP_Fiber
% Frequency-dependent PMD phase term (legacy form)
st.brf.db0 = (R.rand(st.wave_plates,1)*2*pi - pi) * brf_multiplier;
st.brf.db1 = sqrt(3*pi/8)*(st.dgd/obj.fa)/st.wave_plates .* st.omega;
st.brf.simdgd = 0;
st.brf.simdgd = 0;
% cumsum used in legacy only for debug; keep compatibility variable:
~cumsum(st.brf.db0); % no-op to mirror legacy path
@@ -228,7 +232,18 @@ classdef DP_Fiber
x_in = signal_in(:,1).';
y_in = signal_in(:,2).';
[x_out, y_out, obj.state] = CNLSE_plain(x_in, y_in, obj.state);
% Determine GPU usage
if ischar(obj.useGPU) || isstring(obj.useGPU)
if strcmpi(obj.useGPU, 'auto')
gpuFlag = []; % Let CNLSE_plain auto-detect
else
error('DP_Fiber:InvalidGPU', 'useGPU must be true, false, or ''auto''');
end
else
gpuFlag = logical(obj.useGPU);
end
[x_out, y_out, obj.state] = CNLSE_plain(x_in, y_in, obj.state, gpuFlag, obj.useSingle);
obj.state.propagated_length = obj.state.propagated_length + obj.state.L;