#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

/*
 * See section "B. 19 Launch Bounds" from "CUDA C Programming Guide" for more
 * information about the optimal launch bounds, which differ across the major
 * architecture revisions
 */
#define THREADS_PER_BLOCK_2D 16

/* Simple utility function to check for CUDA runtime errors */
void checkCUDAError(const char* msg);

/* Host function that transposes a matrix */
void transpose_cpu(const char* mat_in, char* mat_out, unsigned int rows,
        unsigned int cols);

/* Kernel code */
__global__ void transpose_gpu(const char* mat_in, char* mat_out,
        unsigned int rows, unsigned int cols) {
    unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
    unsigned int idy = blockIdx.y * blockDim.y + threadIdx.y;

    if (idx < cols && idy < rows) {
        unsigned int pos = idy * cols + idx;
        unsigned int trans_pos = idx * rows + idy;

        mat_out[trans_pos] = mat_in[pos];
    }
}

int main(int argc, char** argv) {

    /* Process command-line arguments */
    if (argc != 3) {
        fprintf(stderr, "Usage: %s rows columns\n", argv[0]);
        fprintf(stderr, "       rows is the number of rows of the input matrix\n");
        fprintf(stderr, "       columns is the number of columns of the input matrix\n");
        return EXIT_FAILURE;
    }

    cudaEvent_t start, stop;
    float elapsed_time_ms;

    unsigned int rows = atoi(argv[1]);
    unsigned int cols = atoi(argv[2]);

    /* Pointer for host memory */
    char *h_mat_in, *h_mat_out;
    size_t mat_size = rows * cols * sizeof(char);

    /* Pointer for device memory */
    char *dev_mat_in, *dev_mat_out;

    /* Allocate host and device memory */
    h_mat_in = (char *) malloc(mat_size);
    h_mat_out = (char *) malloc(mat_size);

    cudaMalloc(&dev_mat_in, mat_size);
    cudaMalloc(&dev_mat_out, mat_size);

    /* Check for any CUDA errors */
    checkCUDAError("cudaMalloc");

    /* Fixed seed for illustration */
    srand(2047);

    /* Initialize host memory */
    for (unsigned int i = 0; i < rows; ++i) {
        for (unsigned int j = 0; j < cols; ++j) {
            h_mat_in[i * cols + j] =  rand() % (rows * cols);
            //printf("%d\t", h_mat_in[i * cols + j]);
        }
        //printf("\n");
    }

    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    /*------------------------ COMPUTATION ON CPU ----------------------------*/

    cudaEventRecord(start, 0);
    // cudaEventSynchronize(start); needed?

    transpose_cpu(h_mat_in, h_mat_out, rows, cols);

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&elapsed_time_ms, start, stop);

    /* Verify the correctness of transposed matrix computed on GPU */
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            assert(h_mat_out[i * rows + j] == h_mat_in[j * cols + i]);
        }
    }

    printf("Time to transpose a matrix of %dx%d on CPU: %f ms.\n\n", rows, cols,
                elapsed_time_ms);

    /*------------------------ COMPUTATION ON GPU ----------------------------*/

    /* Host to device memory copy */
    cudaMemcpy(dev_mat_in, h_mat_in, mat_size, cudaMemcpyHostToDevice);

    /* Check for any CUDA errors */
    checkCUDAError("cudaMemcpy");

    /* Set grid and block dimensions properly */
    unsigned int grid_rows = (rows + THREADS_PER_BLOCK_2D - 1) / THREADS_PER_BLOCK_2D;
    unsigned int grid_cols = (cols + THREADS_PER_BLOCK_2D - 1) / THREADS_PER_BLOCK_2D;
    dim3 dimGrid(grid_cols, grid_rows);
    dim3 dimBlock(THREADS_PER_BLOCK_2D, THREADS_PER_BLOCK_2D);

    cudaEventRecord(start, 0);
    // cudaEventSynchronize(start); needed?

    /* Launch kernel */
    transpose_gpu<<<dimGrid, dimBlock>>>(dev_mat_in, dev_mat_out, rows, cols);

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&elapsed_time_ms, start, stop);

    /* Check for any CUDA errors */
    checkCUDAError("kernel invocation");

    /* device to host copy */
    cudaMemcpy(h_mat_out, dev_mat_out, mat_size, cudaMemcpyDeviceToHost);

    /* Check for any CUDA errors */
    checkCUDAError("cudaMemcpy");

    /* Verify the correctness of transposed matrix computed on GPU */
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            assert(h_mat_out[i * rows + j] == h_mat_in[j * cols + i]);
        }
    }

    printf("Time to transpose a matrix of %dx%d on GPU: %f ms.\n\n", rows, cols,
            elapsed_time_ms);

    /* Output the transposed matrix
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            printf("%d\t", (int) h_mat_out[i * rows + j]);
        }
        printf("\n");
    }*/

    /* Free host and device memory */
    free(h_mat_in);
    free(h_mat_out);
    cudaFree(dev_mat_in);
    cudaFree(dev_mat_out);

    /* Check for any CUDA errors */
    checkCUDAError("cudaFree");
}

void checkCUDAError(const char *msg) {
    cudaError_t err = cudaGetLastError();
    if (cudaSuccess != err) {
        fprintf(stderr, "Cuda error: %s: %s.\n", msg, cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void transpose_cpu(const char* mat_in, char* mat_out, unsigned int rows,
        unsigned int cols) {
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            mat_out[i * rows + j] = mat_in[j * cols + i];
        }
    }
}

	.file	"tmpxft_00215446_00000000-6_transp_mat.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Cuda error: %s: %s.\n"
	.text
	.globl	_Z14checkCUDAErrorPKc
	.type	_Z14checkCUDAErrorPKc, @function
_Z14checkCUDAErrorPKc:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L2
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	leaq	.LC0(%rip), %rdx
	movq	%rax, %r8
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14checkCUDAErrorPKc, .-_Z14checkCUDAErrorPKc
	.globl	_Z13transpose_cpuPKcPcjj
	.type	_Z13transpose_cpuPKcPcjj, @function
_Z13transpose_cpuPKcPcjj:
.LFB2029:
	.cfi_startproc
	endbr64
	movq	%rdi, %r9
	xorl	%r8d, %r8d
	xorl	%eax, %eax
.L12:
	cmpl	%ecx, %eax
	je	.L17
	xorl	%edi, %edi
	movl	%eax, %r10d
	cmpl	%edx, %edi
	jne	.L16
	incl	%eax
	addl	%edx, %r8d
	jmp	.L12
.L17:
	ret
.L16:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
.L8:
	movl	%r10d, %r11d
	addl	%ecx, %r10d
	movb	(%r9,%r11), %bl
	leal	(%rdi,%r8), %r11d
	incl	%edi
	movb	%bl, (%rsi,%r11)
.L9:
	cmpl	%edx, %edi
	jne	.L8
	incl	%eax
	addl	%edx, %r8d
	cmpl	%ecx, %eax
	je	.L18
	movl	%eax, %r10d
	xorl	%edi, %edi
	jmp	.L9
.L18:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z13transpose_cpuPKcPcjj, .-_Z13transpose_cpuPKcPcjj
	.globl	_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj
	.type	_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj, @function
_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13transpose_gpuPKcPcjj(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L19:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj, .-_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj
	.globl	_Z13transpose_gpuPKcPcjj
	.type	_Z13transpose_gpuPKcPcjj, @function
_Z13transpose_gpuPKcPcjj:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj
	.cfi_endproc
.LFE2055:
	.size	_Z13transpose_gpuPKcPcjj, .-_Z13transpose_gpuPKcPcjj
	.section	.rodata.str1.1
.LC1:
	.string	"Usage: %s rows columns\n"
.LC2:
	.string	"       rows is the number of rows of the input matrix\n"
.LC3:
	.string	"       columns is the number of columns of the input matrix\n"
.LC4:
	.string	"cudaMalloc"
.LC5:
	.string	"Time to transpose a matrix of %dx%d on CPU: %f ms.\n\n"
.LC6:
	.string	"cudaMemcpy"
.LC7:
	.string	"kernel invocation"
.LC8:
	.string	"Time to transpose a matrix of %dx%d on GPU: %f ms.\n\n"
.LC9:
	.string	"cudaFree"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	je	.L25
	movq	(%rsi), %rcx
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L24
.L25:
	movq	8(%rsi), %rdi
	xorl	%r15d, %r15d
	xorl	%r13d, %r13d
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	movl	%ebx, %r14d
	imull	%eax, %r14d
	movl	%eax, %ebp
	movl	%r14d, %edi
	movl	%r14d, %eax
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movl	%r14d, %edi
	movq	%rax, %r12
	call	malloc@PLT
	leaq	64(%rsp), %rdi
	movl	%r14d, %esi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movl	%r14d, %esi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	.LC4(%rip), %rdi
	call	_Z14checkCUDAErrorPKc
	movl	$2047, %edi
	call	srand@PLT
.L27:
	cmpl	%ebx, %r13d
	je	.L34
	leal	0(%rbp,%r15), %esi
.L29:
	cmpl	%esi, %r15d
	je	.L35
	movl	%esi, 28(%rsp)
	call	rand@PLT
	xorl	%edx, %edx
	movl	%r15d, %edi
	movl	28(%rsp), %esi
	divl	%r14d
	incl	%r15d
	movb	%dl, (%r12,%rdi)
	jmp	.L29
.L35:
	incl	%r13d
	jmp	.L27
.L34:
	leaq	48(%rsp), %rdi
	leaq	44(%rsp), %r15
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	leaq	.LC6(%rip), %r14
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rsi
	movl	%ebp, %ecx
	movl	%ebx, %edx
	movq	%r12, %rdi
	call	_Z13transpose_cpuPKcPcjj
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	%r15, %rdi
	call	cudaEventElapsedTime@PLT
	movl	%ebp, %ecx
	movl	%ebx, %edx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	44(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdx
	movq	64(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	%r14, %rdi
	call	_Z14checkCUDAErrorPKc
	leal	15(%rbp), %eax
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	shrl	$4, %eax
	movl	$1, 88(%rsp)
	movl	%eax, 80(%rsp)
	leal	15(%rbx), %eax
	shrl	$4, %eax
	movl	$1, 100(%rsp)
	movl	%eax, 84(%rsp)
	movabsq	$68719476752, %rax
	movq	%rax, 92(%rsp)
	call	cudaEventRecord@PLT
	movl	100(%rsp), %ecx
	movl	88(%rsp), %esi
	xorl	%r9d, %r9d
	movq	92(%rsp), %rdx
	movq	80(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdi
	movl	%ebp, %ecx
	movl	%ebx, %edx
	call	_Z38__device_stub__Z13transpose_gpuPKcPcjjPKcPcjj
.L30:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	%r15, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC7(%rip), %rdi
	call	_Z14checkCUDAErrorPKc
	movq	16(%rsp), %rdx
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movq	8(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	%r14, %rdi
	call	_Z14checkCUDAErrorPKc
	movl	%ebp, %ecx
	movl	%ebx, %edx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	44(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC9(%rip), %rdi
	call	_Z14checkCUDAErrorPKc
	xorl	%eax, %eax
.L24:
	movq	104(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z13transpose_gpuPKcPcjj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z13transpose_gpuPKcPcjj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

/*
 * See section "B. 19 Launch Bounds" from "CUDA C Programming Guide" for more
 * information about the optimal launch bounds, which differ across the major
 * architecture revisions
 */
#define THREADS_PER_BLOCK_2D 16

/* Simple utility function to check for CUDA runtime errors */
void checkCUDAError(const char* msg);

/* Host function that transposes a matrix */
void transpose_cpu(const char* mat_in, char* mat_out, unsigned int rows,
        unsigned int cols);

/* Kernel code */
__global__ void transpose_gpu(const char* mat_in, char* mat_out,
        unsigned int rows, unsigned int cols) {
    unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x;
    unsigned int idy = blockIdx.y * blockDim.y + threadIdx.y;

    if (idx < cols && idy < rows) {
        unsigned int pos = idy * cols + idx;
        unsigned int trans_pos = idx * rows + idy;

        mat_out[trans_pos] = mat_in[pos];
    }
}

int main(int argc, char** argv) {

    /* Process command-line arguments */
    if (argc != 3) {
        fprintf(stderr, "Usage: %s rows columns\n", argv[0]);
        fprintf(stderr, "       rows is the number of rows of the input matrix\n");
        fprintf(stderr, "       columns is the number of columns of the input matrix\n");
        return EXIT_FAILURE;
    }

    hipEvent_t start, stop;
    float elapsed_time_ms;

    unsigned int rows = atoi(argv[1]);
    unsigned int cols = atoi(argv[2]);

    /* Pointer for host memory */
    char *h_mat_in, *h_mat_out;
    size_t mat_size = rows * cols * sizeof(char);

    /* Pointer for device memory */
    char *dev_mat_in, *dev_mat_out;

    /* Allocate host and device memory */
    h_mat_in = (char *) malloc(mat_size);
    h_mat_out = (char *) malloc(mat_size);

    hipMalloc(&dev_mat_in, mat_size);
    hipMalloc(&dev_mat_out, mat_size);

    /* Check for any CUDA errors */
    checkCUDAError("hipMalloc");

    /* Fixed seed for illustration */
    srand(2047);

    /* Initialize host memory */
    for (unsigned int i = 0; i < rows; ++i) {
        for (unsigned int j = 0; j < cols; ++j) {
            h_mat_in[i * cols + j] =  rand() % (rows * cols);
            //printf("%d\t", h_mat_in[i * cols + j]);
        }
        //printf("\n");
    }

    hipEventCreate(&start);
    hipEventCreate(&stop);

    /*------------------------ COMPUTATION ON CPU ----------------------------*/

    hipEventRecord(start, 0);
    // cudaEventSynchronize(start); needed?

    transpose_cpu(h_mat_in, h_mat_out, rows, cols);

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&elapsed_time_ms, start, stop);

    /* Verify the correctness of transposed matrix computed on GPU */
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            assert(h_mat_out[i * rows + j] == h_mat_in[j * cols + i]);
        }
    }

    printf("Time to transpose a matrix of %dx%d on CPU: %f ms.\n\n", rows, cols,
                elapsed_time_ms);

    /*------------------------ COMPUTATION ON GPU ----------------------------*/

    /* Host to device memory copy */
    hipMemcpy(dev_mat_in, h_mat_in, mat_size, hipMemcpyHostToDevice);

    /* Check for any CUDA errors */
    checkCUDAError("hipMemcpy");

    /* Set grid and block dimensions properly */
    unsigned int grid_rows = (rows + THREADS_PER_BLOCK_2D - 1) / THREADS_PER_BLOCK_2D;
    unsigned int grid_cols = (cols + THREADS_PER_BLOCK_2D - 1) / THREADS_PER_BLOCK_2D;
    dim3 dimGrid(grid_cols, grid_rows);
    dim3 dimBlock(THREADS_PER_BLOCK_2D, THREADS_PER_BLOCK_2D);

    hipEventRecord(start, 0);
    // cudaEventSynchronize(start); needed?

    /* Launch kernel */
    transpose_gpu<<<dimGrid, dimBlock>>>(dev_mat_in, dev_mat_out, rows, cols);

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&elapsed_time_ms, start, stop);

    /* Check for any CUDA errors */
    checkCUDAError("kernel invocation");

    /* device to host copy */
    hipMemcpy(h_mat_out, dev_mat_out, mat_size, hipMemcpyDeviceToHost);

    /* Check for any CUDA errors */
    checkCUDAError("hipMemcpy");

    /* Verify the correctness of transposed matrix computed on GPU */
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            assert(h_mat_out[i * rows + j] == h_mat_in[j * cols + i]);
        }
    }

    printf("Time to transpose a matrix of %dx%d on GPU: %f ms.\n\n", rows, cols,
            elapsed_time_ms);

    /* Output the transposed matrix
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            printf("%d\t", (int) h_mat_out[i * rows + j]);
        }
        printf("\n");
    }*/

    /* Free host and device memory */
    free(h_mat_in);
    free(h_mat_out);
    hipFree(dev_mat_in);
    hipFree(dev_mat_out);

    /* Check for any CUDA errors */
    checkCUDAError("hipFree");
}

void checkCUDAError(const char *msg) {
    hipError_t err = hipGetLastError();
    if (hipSuccess != err) {
        fprintf(stderr, "Cuda error: %s: %s.\n", msg, hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void transpose_cpu(const char* mat_in, char* mat_out, unsigned int rows,
        unsigned int cols) {
    for (unsigned int i = 0; i < cols; ++i) {
        for (unsigned int j = 0; j < rows; ++j) {
            mat_out[i * rows + j] = mat_in[j * cols + i];
        }
    }
}

	.text
	.file	"transp_mat.hip"
	.globl	_Z28__device_stub__transpose_gpuPKcPcjj # -- Begin function _Z28__device_stub__transpose_gpuPKcPcjj
	.type	_Z28__device_stub__transpose_gpuPKcPcjj,@function
_Z28__device_stub__transpose_gpuPKcPcjj: # @_Z28__device_stub__transpose_gpuPKcPcjj
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z13transpose_gpuPKcPcjj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z28__device_stub__transpose_gpuPKcPcjj, .Lfunc_end0-_Z28__device_stub__transpose_gpuPKcPcjj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	cmpl	$3, %edi
	jne	.LBB1_1
# %bb.3:
	movq	8(%r14), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%eax, %r15d
	imull	%ebx, %r15d
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r15, 48(%rsp)                  # 8-byte Spill
	movq	%r15, %rsi
	callq	hipMalloc
	movl	$.L.str.3, %edi
	callq	_Z14checkCUDAErrorPKc
	movl	$2047, %edi                     # imm = 0x7FF
	callq	srand
	testl	%ebx, %ebx
	je	.LBB1_7
# %bb.4:                                # %.preheader72.lr.ph
	movl	%ebp, %eax
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
	movl	%ebx, 40(%rsp)                  # 4-byte Spill
	movl	%ebp, 36(%rsp)                  # 4-byte Spill
.LBB1_5:                                # %.preheader72
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_15 Depth 2
	movq	64(%rsp), %r15                  # 8-byte Reload
	movl	%r12d, %ebx
	testl	%ebp, %ebp
	movq	48(%rsp), %rbp                  # 8-byte Reload
	je	.LBB1_6
.LBB1_15:                               #   Parent Loop BB1_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorl	%edx, %edx
	divl	%ebp
	movl	%ebx, %eax
	movb	%dl, (%r14,%rax)
	incl	%ebx
	decq	%r15
	jne	.LBB1_15
.LBB1_6:                                # %._crit_edge
                                        #   in Loop: Header=BB1_5 Depth=1
	incl	%r13d
	movl	36(%rsp), %ebp                  # 4-byte Reload
	addl	%ebp, %r12d
	movl	40(%rsp), %ebx                  # 4-byte Reload
	cmpl	%ebx, %r13d
	jne	.LBB1_5
.LBB1_7:                                # %._crit_edge75
	leaq	24(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%r13d, %r13d
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%ebp, %ebp
	movq	56(%rsp), %r15                  # 8-byte Reload
	movq	48(%rsp), %r12                  # 8-byte Reload
	je	.LBB1_11
# %bb.8:                                # %.preheader.lr.ph.i
	movl	%ebx, %eax
	xorl	%ecx, %ecx
.LBB1_9:                                # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_14 Depth 2
	movl	%ecx, %edx
	movl	%r13d, %esi
	movq	%rax, %rdi
	testl	%ebx, %ebx
	je	.LBB1_10
.LBB1_14:                               #   Parent Loop BB1_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edx, %r8d
	movb	(%r14,%r8), %r8b
	movl	%esi, %r9d
	movb	%r8b, (%r15,%r9)
	incl	%esi
	addl	%ebp, %edx
	decq	%rdi
	jne	.LBB1_14
.LBB1_10:                               # %._crit_edge.i
                                        #   in Loop: Header=BB1_9 Depth=1
	incl	%ecx
	addl	%ebx, %r13d
	cmpl	%ebp, %ecx
	jne	.LBB1_9
.LBB1_11:                               # %._crit_edge77
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	44(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r13), %xmm0
	movl	$.L.str.4, %edi
	movl	%ebx, %esi
	movl	%ebp, %edx
	movb	$1, %al
	callq	printf
	movq	16(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.5, %edi
	callq	_Z14checkCUDAErrorPKc
	movl	%ebx, %r13d
	addl	$15, %r13d
	shrl	$4, %r13d
	movl	%ebp, %eax
	addl	$15, %eax
	shrl	$4, %eax
	shlq	$32, %r13
	orq	%rax, %r13
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_13
# %bb.12:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	%ebx, %edx
	movl	%ebp, %ecx
	callq	_Z28__device_stub__transpose_gpuPKcPcjj
.LBB1_13:                               # %._crit_edge79
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	44(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	movl	$.L.str.6, %edi
	callq	_Z14checkCUDAErrorPKc
	movq	8(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.5, %edi
	callq	_Z14checkCUDAErrorPKc
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13), %xmm0
	movl	$.L.str.7, %edi
	movl	%ebx, %esi
	movl	%ebp, %edx
	movb	$1, %al
	callq	printf
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.8, %edi
	callq	_Z14checkCUDAErrorPKc
	xorl	%eax, %eax
.LBB1_2:
                                        # kill: def $eax killed $eax killed $rax
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	.cfi_def_cfa_offset 128
	movq	stderr(%rip), %rdi
	movq	(%r14), %rdx
	movl	$.L.str, %esi
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$54, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$60, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %eax
	jmp	.LBB1_2
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z14checkCUDAErrorPKc           # -- Begin function _Z14checkCUDAErrorPKc
	.type	_Z14checkCUDAErrorPKc,@function
_Z14checkCUDAErrorPKc:                  # @_Z14checkCUDAErrorPKc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB2_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.9, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z14checkCUDAErrorPKc, .Lfunc_end2-_Z14checkCUDAErrorPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z13transpose_cpuPKcPcjj        # -- Begin function _Z13transpose_cpuPKcPcjj
	.type	_Z13transpose_cpuPKcPcjj,@function
_Z13transpose_cpuPKcPcjj:               # @_Z13transpose_cpuPKcPcjj
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	je	.LBB3_5
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%edx, %eax
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_6 Depth 2
	movq	%rax, %r10
	movl	%r9d, %r11d
	movl	%r8d, %ebx
	testl	%edx, %edx
	je	.LBB3_3
.LBB3_6:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r11d, %r14d
	movb	(%rdi,%r14), %bpl
	movl	%ebx, %r14d
	movb	%bpl, (%rsi,%r14)
	incl	%ebx
	addl	%ecx, %r11d
	decq	%r10
	jne	.LBB3_6
.LBB3_3:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	incl	%r9d
	addl	%edx, %r8d
	cmpl	%ecx, %r9d
	jne	.LBB3_2
# %bb.4:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %rbp
.LBB3_5:                                # %._crit_edge18
	retq
.Lfunc_end3:
	.size	_Z13transpose_cpuPKcPcjj, .Lfunc_end3-_Z13transpose_cpuPKcPcjj
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13transpose_gpuPKcPcjj, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z13transpose_gpuPKcPcjj,@object # @_Z13transpose_gpuPKcPcjj
	.section	.rodata,"a",@progbits
	.globl	_Z13transpose_gpuPKcPcjj
	.p2align	3, 0x0
_Z13transpose_gpuPKcPcjj:
	.quad	_Z28__device_stub__transpose_gpuPKcPcjj
	.size	_Z13transpose_gpuPKcPcjj, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: %s rows columns\n"
	.size	.L.str, 24

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"       rows is the number of rows of the input matrix\n"
	.size	.L.str.1, 55

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"       columns is the number of columns of the input matrix\n"
	.size	.L.str.2, 61

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"hipMalloc"
	.size	.L.str.3, 10

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Time to transpose a matrix of %dx%d on CPU: %f ms.\n\n"
	.size	.L.str.4, 53

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipMemcpy"
	.size	.L.str.5, 10

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"kernel invocation"
	.size	.L.str.6, 18

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Time to transpose a matrix of %dx%d on GPU: %f ms.\n\n"
	.size	.L.str.7, 53

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipFree"
	.size	.L.str.8, 8

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Cuda error: %s: %s.\n"
	.size	.L.str.9, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13transpose_gpuPKcPcjj"
	.size	.L__unnamed_1, 25

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z28__device_stub__transpose_gpuPKcPcjj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13transpose_gpuPKcPcjj
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13transpose_gpuPKcPcjj ; -- Begin function _Z13transpose_gpuPKcPcjj
	.globl	_Z13transpose_gpuPKcPcjj
	.p2align	8
	.type	_Z13transpose_gpuPKcPcjj,@function
_Z13transpose_gpuPKcPcjj:               ; @_Z13transpose_gpuPKcPcjj
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b64 s[4:5], s[0:1], 0x10
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, s5, v0
	v_cmp_gt_u32_e64 s2, s4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_mad_u64_u32 v[2:3], null, v1, s5, v[0:1]
	s_waitcnt lgkmcnt(0)
	global_load_u8 v4, v2, s[0:1]
	v_mad_u64_u32 v[2:3], null, v0, s4, v[1:2]
	s_waitcnt vmcnt(0)
	global_store_b8 v2, v4, s[2:3]
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13transpose_gpuPKcPcjj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z13transpose_gpuPKcPcjj, .Lfunc_end0-_Z13transpose_gpuPKcPcjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 164
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13transpose_gpuPKcPcjj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13transpose_gpuPKcPcjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
