Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.jl.mem
deps/deps.jl
Manifest.toml
Manifest-v*.toml
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RegisterWorkerAperturesMismatch"
uuid = "30e56b64-2659-11e9-2fbf-0524297743d8"
authors = ["Tim Holy <tim.holy@gmail.com>"]
version = "0.2.4"
version = "1.0.0"

[deps]
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
Expand Down
24 changes: 13 additions & 11 deletions src/RegisterWorkerAperturesMismatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module RegisterWorkerAperturesMismatch
using ImageCore, CoordinateTransformations, Interpolations, StaticArrays, SharedArrays
using RegisterCore, RegisterDeformation, RegisterFit, RegisterPenalty, RegisterOptimize
using RegisterMismatch, RegisterMismatchCommon
# Note: RegisterMismatchCuda is loaded dynamically below when dev >= 0
# Note: RegisterMismatchCuda is loaded dynamically below when dev !== nothing
using RegisterWorkerShell # , RegisterDriver

import RegisterWorkerShell: worker, init!, close!, load_mm_package
import RegisterWorkerShell: worker, init!, close!, load_mm_package, workertid

export AperturesMismatch, monitor, monitor!, worker

Expand All @@ -22,20 +22,22 @@ mutable struct AperturesMismatch{A<:AbstractArray,T,K,N} <: AbstractWorker
cs
Qs
mmis
workertid::Int
dev::Int
tid::Int
dev::Union{Nothing,Int}
cuda_objects::Dict{Symbol,Any}
end

workertid(w::AperturesMismatch) = w.tid

function load_mm_package(dev)
if dev >= 0
if dev !== nothing
eval(:(using CUDA, RegisterMismatchCuda))
end
nothing
end

function init!(algorithm::AperturesMismatch)
if algorithm.dev >= 0
if algorithm.dev !== nothing
cuda_init!(algorithm)
end
nothing
Expand Down Expand Up @@ -64,8 +66,8 @@ function cuda_init!(algorithm)
end

function close!(algorithm::AperturesMismatch)
if algorithm.dev >= 0
if old_active_context != nothing
if algorithm.dev !== nothing
if !isnothing(old_active_context)
activate(old_active_context)
end
end
Expand Down Expand Up @@ -111,10 +113,10 @@ pre-processing function, but see also `PreprocessSNF`.
```

"""
function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=-1) where {K,N}
function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift::NTuple{N,<:Integer}, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=nothing) where {K,N}
gridsize = map(length, nodes)
nimages(fixed) == 1 || error("Register to a single image")
if thresh == nothing
if isnothing(thresh)
thresh = (thresh_fac/prod(gridsize)) * (normalization==:pixels ? length(fixed) : sumabs2(fixed))
end
T = eltype(fixed) <: AbstractFloat ? eltype(fixed) : Float32
Expand All @@ -131,7 +133,7 @@ function worker(algorithm::AperturesMismatch, img, tindex, mon)
moving0 = getindex_t(img, tindex)
moving = algorithm.preprocess(moving0)
gridsize = map(length, algorithm.nodes)
use_cuda = algorithm.dev >= 0
use_cuda = algorithm.dev !== nothing
if use_cuda
device!(CuDevice(algorithm.dev))
d_fixed = algorithm.cuda_objects[:d_fixed]
Expand Down
7 changes: 7 additions & 0 deletions test/internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
@test RegisterWorkerAperturesMismatch.cudatype(Int32) == Float32
@test RegisterWorkerAperturesMismatch.cudatype(UInt8) == Float32
end

@testset "AperturesMismatch constructor argument validation" begin
fixed = rand(Float32, 20, 20)
nodes = (range(1, stop=20, length=4), range(1, stop=20, length=4))
# Vector maxshift should not match the NTuple{N,<:Integer} signature
@test_throws MethodError AperturesMismatch(fixed, nodes, [3, 3])
end
Loading