Skip to content

Commit fea7e20

Browse files
authored
Remove ct.transpose, making transpose 1D/2D only (#124)
1 parent 46de3a6 commit fea7e20

2 files changed

Lines changed: 22 additions & 41 deletions

File tree

src/compiler/intrinsics/core.jl

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -435,41 +435,6 @@ function emit_intrinsic!(ctx::CGCtx, ::typeof(Intrinsics.permute), args)
435435
CGVal(result, output_tile_type, Tile{elem_type, Tuple{output_shape...}}, output_shape)
436436
end
437437

438-
# cuda_tile.transpose
439-
@intrinsic transpose(tile)
440-
function tfunc(𝕃, ::typeof(Intrinsics.transpose), @nospecialize(tile_lat))
441-
tile_type = CC.widenconst(tile_lat)
442-
tile_type <: Tile || return nothing
443-
s = size(tile_type)
444-
isempty(s) && return nothing
445-
T = eltype(tile_type)
446-
return Tile{T, Tuple{reverse(s)...}}
447-
end
448-
function emit_intrinsic!(ctx::CGCtx, ::typeof(Intrinsics.transpose), args)
449-
cb = ctx.cb
450-
tt = ctx.tt
451-
452-
source = emit_value!(ctx, args[1])
453-
source === nothing && throw(IRError("Cannot resolve operand for transpose()"))
454-
455-
input_shape = source.shape
456-
isempty(input_shape) && throw(IRError("Cannot determine tile shape for transpose()"))
457-
458-
output_shape = reverse(input_shape)
459-
460-
elem_type = eltype(CC.widenconst(source.jltype))
461-
462-
dtype = julia_to_tile_dtype!(tt, elem_type)
463-
output_tile_type = tile_type!(tt, dtype, output_shape)
464-
465-
ndim = length(output_shape)
466-
permutation = collect(ndim-1:-1:0)
467-
468-
result = encode_PermuteOp!(cb, output_tile_type, source.v, permutation)
469-
470-
CGVal(result, output_tile_type, Tile{elem_type, Tuple{output_shape...}}, output_shape)
471-
end
472-
473438

474439
# cuda_tile.reduce
475440
@intrinsic reduce(tiles, axis, f, identities)

src/language/operations.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,16 +545,15 @@ permuted = permutedims(tile, (3, 1, 2)) # Shape (4, 2, 3)
545545
546546
Permute a 2D tile, swapping its dimensions. Defaults to permutation `(2, 1)`.
547547
548-
Differs from `transpose` in that the operation is not recursive. For tiles
549-
of numeric element types, the two operations are equivalent.
548+
Equivalent to `transpose`.
550549
551550
---
552551
553552
permutedims(tile::Tile{T, (N,)}) -> Tile{T, (1, N)}
554553
555554
Reshape a 1D tile into a `1 × N` row tile.
556555
557-
Differs from `transpose` in that the operation is not recursive.
556+
Equivalent to `transpose`.
558557
"""
559558
@generated function Base.permutedims(tile::T) where {T <: Tile}
560559
n = ndims(T)
@@ -573,10 +572,27 @@ end
573572
transpose(tile::Tile{T, (M, N)}) -> Tile{T, (N, M)}
574573
575574
Transpose a 2D tile, swapping its dimensions.
576-
Equivalent to `permute(tile, (2, 1))`.
575+
576+
---
577+
578+
transpose(tile::Tile{T, (N,)}) -> Tile{T, (1, N)}
579+
580+
Reshape a 1D tile into a `1 × N` row tile.
581+
582+
Equivalent to single-arg `permutedims`.
577583
"""
578-
@inline Base.transpose(tile::Tile{T}) where {T} =
579-
Intrinsics.transpose(tile)
584+
@generated function Base.transpose(tile::T) where {T <: Tile}
585+
n = ndims(T)
586+
first_dim = n >= 1 ? size(T, 1) : nothing
587+
588+
if n == 2
589+
return :(Intrinsics.permute(tile, (1, 0)))
590+
elseif n == 1
591+
return :(Intrinsics.reshape(tile, (1, $first_dim)))
592+
else
593+
return :(throw(ArgumentError("transpose(tile) only works for 1D or 2D tiles")))
594+
end
595+
end
580596

581597
@inline Base.convert(::Type{Tile{T2}}, tile::Tile{T1, Shape}) where {T1, T2, Shape} =
582598
map(T2, tile)

0 commit comments

Comments
 (0)