← All problems
#3 Matrix Transpose Easy

Write a program that transposes a matrix of 32-bit floating point numbers on a GPU. The transpose of a matrix switches its rows and columns. Given a matrix \(A\) of dimensions \(rows \times cols\), the transpose \(A^T\) will have dimensions \(cols \times rows\). All matrices are stored in row-major format.

A 1 2 3 4 5 6 3 × 2 rows → cols Aᵀ 1 3 5 2 4 6 2 × 3

Implementation Requirements

Example 1:

Input: 2×3 matrix

\[ \begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \end{bmatrix} \]

Output: 3×2 matrix

\[ \begin{bmatrix} 1.0 & 4.0 \\ 2.0 & 5.0 \\ 3.0 & 6.0 \end{bmatrix} \]

Example 2:

Input: 3×1 matrix

\[ \begin{bmatrix} 1.0 \\ 2.0 \\ 3.0 \end{bmatrix} \]

Output: 1×3 matrix

\[ \begin{bmatrix} 1.0 & 2.0 & 3.0 \end{bmatrix} \]

Constraints

Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.