Skip to content

Commit efedbc1

Browse files
committed
Change indexing order
1 parent 4c5f827 commit efedbc1

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

src/upsample.jl

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ upsample_trilinear(x; size, align_corners::Bool = true) = upsample_linear(x; si
355355
function upsample_linear_kernel!(
356356
y::AbstractArray{T, N}, x::AbstractArray{T, N}; align_corners::Bool = true,
357357
) where {T, N}
358-
ndrange = size(y)[1:N - 2]
358+
# ndrange = size(y)[1:N - 2]
359+
ndrange = size(y)[N - 1:end]
359360
ratios = align_corners ?
360361
ntuple(i -> real(T)((size(x, i) - 1) / (size(y, i) - 1)), N - 2) :
361362
ntuple(i -> real(T)(size(x, i) / size(y, i)), N - 2)
@@ -414,19 +415,49 @@ end
414415
T <: AbstractArray{<: Any, 4}, A,
415416
}
416417
@uniform in_width::UInt32, in_height::UInt32, channels::UInt32, batch::UInt32 = size(x)
418+
@uniform out_width::UInt32, out_height::UInt32 = size(y)[1:2]
419+
420+
c::UInt32, n::UInt32 = @index(Global, NTuple)
421+
422+
for j in UnitRange{UInt32}(1, out_height)
423+
ih0, ih1, h0lambda, h1lambda = source_index_and_lambda(rheight, j - 0x1, align, in_height)
424+
for i in UnitRange{UInt32}(1, out_width)
425+
iw0, iw1, w0lambda, w1lambda = source_index_and_lambda(rwidth, i - 0x1, align, in_width)
426+
@inbounds y[i, j, c, n] =
427+
h0lambda * (w0lambda * x[iw0, ih0, c, n] + w1lambda * x[iw1, ih0, c, n]) +
428+
h1lambda * (w0lambda * x[iw0, ih1, c, n] + w1lambda * x[iw1, ih1, c, n])
429+
end
430+
end
417431

418-
i::UInt32, j::UInt32 = @index(Global, NTuple)
432+
# i::UInt32, j::UInt32 = @index(Global, NTuple)
419433

420-
iw0, iw1, w0lambda, w1lambda = source_index_and_lambda(rwidth, i - 0x1, align, in_width)
421-
ih0, ih1, h0lambda, h1lambda = source_index_and_lambda(rheight, j - 0x1, align, in_height)
434+
# iw0, iw1, w0lambda, w1lambda = source_index_and_lambda(rwidth, i - 0x1, align, in_width)
435+
# ih0, ih1, h0lambda, h1lambda = source_index_and_lambda(rheight, j - 0x1, align, in_height)
422436

423-
@inbounds for n in 1:batch, c in 1:channels
424-
y[i, j, c, n] =
425-
h0lambda * (w0lambda * x[iw0, ih0, c, n] + w1lambda * x[iw1, ih0, c, n]) +
426-
h1lambda * (w0lambda * x[iw0, ih1, c, n] + w1lambda * x[iw1, ih1, c, n])
427-
end
437+
# @inbounds for n in 1:batch, c in 1:channels
438+
# y[i, j, c, n] =
439+
# h0lambda * (w0lambda * x[iw0, ih0, c, n] + w1lambda * x[iw1, ih0, c, n]) +
440+
# h1lambda * (w0lambda * x[iw0, ih1, c, n] + w1lambda * x[iw1, ih1, c, n])
441+
# end
428442
end
429443

444+
# @kernel function _upsample_linear_kernel!(y::T, x::T, rwidth, rheight, align::Val{A}) where {
445+
# T <: AbstractArray{<: Any, 4}, A,
446+
# }
447+
# @uniform in_width::UInt32, in_height::UInt32, channels::UInt32, batch::UInt32 = size(x)
448+
449+
# i::UInt32, j::UInt32 = @index(Global, NTuple)
450+
451+
# iw0, iw1, w0lambda, w1lambda = source_index_and_lambda(rwidth, i - 0x1, align, in_width)
452+
# ih0, ih1, h0lambda, h1lambda = source_index_and_lambda(rheight, j - 0x1, align, in_height)
453+
454+
# @inbounds for n in 1:batch, c in 1:channels
455+
# y[i, j, c, n] =
456+
# h0lambda * (w0lambda * x[iw0, ih0, c, n] + w1lambda * x[iw1, ih0, c, n]) +
457+
# h1lambda * (w0lambda * x[iw0, ih1, c, n] + w1lambda * x[iw1, ih1, c, n])
458+
# end
459+
# end
460+
430461
@kernel function _∇upsample_linear_kernel!(dx::T1, Δ::T2, rwidth, rheight, align::Val{A}) where {
431462
T1 <: AbstractArray{<: Any, 4},
432463
T2 <: AbstractArray{<: Any, 4}, A,

0 commit comments

Comments
 (0)