Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #30

Merged
merged 5 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tracking"
uuid = "10b2438b-ffd4-5096-aa58-44041d5c8f3b"
authors = ["Soeren Zorn <soeren.zorn@nav.rwth-aachen.de>"]
version = "0.14.7"
version = "0.14.8"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand Down
2 changes: 1 addition & 1 deletion src/code_replica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function gen_code_replica!(
start_code_phase::AbstractFloat,
start_sample::Integer,
num_samples::Integer,
correlator_sample_shifts::SVector,
correlator_sample_shifts::AbstractVector,
prn::Integer
)
most_early_sample_shift = correlator_sample_shifts[end]
Expand Down
30 changes: 17 additions & 13 deletions src/correlator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,12 @@ function correlate(
start_sample,
num_samples
) where {T <: AbstractCorrelator}
accumulators = zero_accumulators(get_accumulators(correlator), downconverted_signal)
a_re = zero_accumulators(get_accumulators(correlator), downconverted_signal)
a_im = zero_accumulators(get_accumulators(correlator), downconverted_signal)
d_re = downconverted_signal.re
d_im = downconverted_signal.im
a_re = real.(accumulators)
a_im = imag.(accumulators)
@avx for i = start_sample:num_samples + start_sample - 1
for j = 1:length(accumulators)
for j = 1:length(a_re)
sample_shift = correlator_sample_shifts[j] - correlator_sample_shifts[1]
a_re[j] += d_re[i] * code[i + sample_shift]
a_im[j] += d_im[i] * code[i + sample_shift]
Expand All @@ -278,10 +277,10 @@ function correlate(
end

function zero_accumulators(accumulators::SVector, signal)
zeros(MVector{length(accumulators), eltype(signal)})
zeros(MVector{length(accumulators), real(eltype(signal))})
end
function zero_accumulators(accumulators::Vector, signal)
zeros(eltype(signal), length(accumulators))
zeros(real(eltype(signal)), length(accumulators))
end

"""
Expand All @@ -297,21 +296,26 @@ function correlate(
start_sample,
num_samples,
) where {N}
accumulators = zero(MMatrix{N, length(correlator_sample_shifts), eltype(downconverted_signal)})
a_re = real.(accumulators)
a_im = imag.(accumulators)
a_re = zero_accumulators(get_accumulators(correlator), downconverted_signal)
a_im = zero_accumulators(get_accumulators(correlator), downconverted_signal)
d_re = downconverted_signal.re
d_im = downconverted_signal.im
@avx for i = start_sample:num_samples + start_sample - 1
for k = 1:size(accumulators, 2)
for j = 1:size(accumulators, 1)
for k = 1:size(a_re, 2)
for j = 1:size(a_re, 1)
shift = correlator_sample_shifts[k] - correlator_sample_shifts[1]
a_re[j,k] += d_re[i,j] * code[shift + i]
a_im[j,k] += d_im[i,j] * code[shift + i]
end
end
end

accumulators_new = SVector(eachcol(complex.(SMatrix(a_re), SMatrix(a_im)))...)
typeof(correlator)(map(+, get_accumulators(correlator), accumulators_new))
typeof(correlator)(map(+, get_accumulators(correlator), eachcol(complex.(a_re, a_im))))
end

function zero_accumulators(accumulators::SVector{NC, <:SVector{NA}}, signal) where {NC, NA}
zeros(MMatrix{NA, NC, real(eltype(signal))})
end
function zero_accumulators(accumulators::Vector{<:SVector{NA}}, signal) where NA
zeros(real(eltype(signal)), NA, length(accumulators))
end
73 changes: 44 additions & 29 deletions test/correlator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@
@test @inferred(get_prompt(correlator, correlator_sample_shifts)) == 0.0
@test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0

correlator = @inferred EarlyPromptLateCorrelator(NumAnts(1), 3)
@test isa(get_accumulators(correlator), Vector)

correlator = @inferred EarlyPromptLateCorrelator(NumAnts(1))

@test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0
@test @inferred(get_prompt(correlator, correlator_sample_shifts)) == 0.0
@test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0

correlator = @inferred EarlyPromptLateCorrelator(NumAnts(1), 3)

@test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0
@test @inferred(get_prompt(correlator, correlator_sample_shifts)) == 0.0
@test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0

correlator = @inferred EarlyPromptLateCorrelator(NumAnts(2))

@test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im)
@test @inferred(get_prompt(correlator, correlator_sample_shifts)) == SVector(0.0 + 0.0im, 0.0 + 0.0im)
@test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im)

correlator = @inferred EarlyPromptLateCorrelator(NumAnts(2), 3)

@test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im)
@test @inferred(get_prompt(correlator, correlator_sample_shifts)) == SVector(0.0 + 0.0im, 0.0 + 0.0im)
@test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im)

end
@testset "Zeroing correlator" begin
correlator = @inferred EarlyPromptLateCorrelator(
Expand Down Expand Up @@ -154,6 +170,8 @@
)
)
end


@testset "Correlate" begin
gpsl1 = GPSL1()
signal = StructArray{Complex{Float32}}(
Expand All @@ -166,36 +184,33 @@
(1 + correlator_sample_shifts[1]:2500 + correlator_sample_shifts[end]) * 1023e3 / 2.5e6,
1
)
correlator = EarlyPromptLateCorrelator(SVector(0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im))

correlator_result = Tracking.correlate(
correlator,
signal,
code,
correlator_sample_shifts,
1,
2500
)
@test get_early(correlator_result, correlator_sample_shifts, 1) ==
get_late(correlator_result, correlator_sample_shifts, 1)
@test get_prompt(correlator_result, correlator_sample_shifts) == 2500


signal_mat = repeat(signal, outer = (1,3))
correlator_sample_shifts = SVector(-1,0,1)
correlator = EarlyPromptLateCorrelator(NumAnts(3))

correlator_result = Tracking.correlate(
correlator,
signal_mat,
code,
correlator_sample_shifts,
1,
2500,
)
@test get_early(correlator_result, correlator_sample_shifts, 1) == get_late(correlator_result, correlator_sample_shifts, 1)
@test all(get_early(correlator_result, correlator_sample_shifts, 1) .== 1476)
@test all(get_prompt(correlator_result, correlator_sample_shifts) .== 2500)
@testset "↳ $na antennas" for na ∈ [1, 4, 15]
signal_mat = na == 1 ? signal : repeat(signal, outer=(1,na))

@testset "↳ $(string(type)) accumulator" for type ∈ [:SVector, :Vector]
if type == :SVector
correlator = EarlyPromptLateCorrelator(NumAnts(na))
else
correlator = EarlyPromptLateCorrelator(NumAnts(na), 3)
end

correlator_result = Tracking.correlate(
correlator,
signal_mat,
code,
correlator_sample_shifts,
1,
2500,
)
early = get_early(correlator_result, correlator_sample_shifts, 1)
prompt = get_prompt(correlator_result, correlator_sample_shifts)
late = get_late(correlator_result, correlator_sample_shifts, 1)
@test early == late
@test all(early .== 1476)
@test all(prompt .== 2500)
end
end
end

end