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
2 changes: 2 additions & 0 deletions src/host/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,8 @@ function _permutedims!(::Type{IT}, dest::AbstractGPUArray,
src::AbstractGPUArray, perm::NTuple{N}) where {IT,N}
@assert length(src) <= typemax(IT)
Base.checkdims_perm(dest, src, perm)
# not every back-end supports launching an empty kernel (JuliaGPU/Metal.jl#980)
isempty(dest) && return dest
dest_strides = ntuple(k->k==1 ? 1 : prod(i->size(dest, i), 1:k-1), N)
dest_strides_perm = ntuple(i->IT(dest_strides[findfirst(==(i), perm)]), N)
size_src = IT.(size(src))
Expand Down
2 changes: 2 additions & 0 deletions test/testsuite/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@test compare(x -> permutedims(x, (2, 1)), AT, rand(Float32, 2, 3))
@test compare(x -> permutedims(x, (2, 1, 3)), AT, rand(Float32, 4, 5, 6))
@test compare(x -> permutedims(x, (3, 1, 2)), AT, rand(Float32, 4, 5, 6))
@test compare(x -> permutedims(x, (2, 1)), AT, rand(Float32, 0, 3))
@test compare(x -> permutedims(x, (3, 1, 2)), AT, rand(Float32, 4, 0, 6))
if ComplexF32 in eltypes
@test compare(x -> permutedims(x, [2,1,4,3]), AT, randn(ComplexF32,3,4,5,1))
# test UInt64 version to make sure it works properly when array length is larger than typemax of UInt32.
Expand Down
Loading