#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <iostream>


const int TILE_WIDTH = 32;

int randomNumberGeneration(int upperBound, int lowerBound) {
    int num = (rand() % (upperBound - lowerBound + 1)) + lowerBound;
    return num;
}

int *createData(int *array, int num_element) {
    for (int i = 0; i < num_element; i++) {
        array[i] = randomNumberGeneration(9, 0);
    }
    return array;
}

int *createMatrix(int num_element) {
    int *array = (int *)malloc(num_element * sizeof(int *));
    // create synthetic data for matrix
    array = createData(array, num_element);
    return array;
}

int *allocateMatrix(int num_element) {
    int *array = (int *)malloc(num_element * sizeof(int *));
    return array;
}

void printArray(int *array, int width) {
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < width; j++) {
            printf("%d ", array[(i * width) + j]);
        }
        printf("\n");
    }
}

int *sequential_transpose(int *array, int width){
    // allocate space for the results array
    int *result = (int *)malloc(width*width * sizeof(int *));
    // swap i and j values (x and y) in the matrix to produce the transpose
    // result maps to result(j,i) = input(i,j)
    for (int i=0; i<width; i++){
        for (int j=0; j<width; j++){
            result[j*width +i] = array[i*width +j];
        }
    }
    return result;
}

__global__ void global_transpose_matrix(int *output_data, const int *input_data){
    // x =  get threads in x direction i.e. columns
    // y = get threads in y direction i.e. rows
    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;
    int width = gridDim.x * blockDim.x; 

    // swap x and x values in the matrix to produce the transpose
    // results map to output(y,x) = input(x,y)
    for (int i = 0; i < blockDim.x; i+= width){
        output_data[x*width + (y+i)] = input_data[(y+i)*width + x];
    }
}

__global__ void shared_transpose_matrix(int *output_data, const int *input_data){
    // creating tiles in the shared memory for faster computation
    // each tile is created of the preset size i.e. 32 in this case
    __shared__ int tile[TILE_WIDTH] [TILE_WIDTH+1];
    // x =  get threads in x direction i.e. columns
    // y = get threads in y direction i.e. rows
    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;
    int width = gridDim.x * blockDim.x;

    // swap x and x values in the tile to produce the transposed tiled
    // tile maps to (y,x) = input(x,y)
    // we save these tiles in transposed hence it is (y,x)
    // this will help us to elimanate the usage of thread synching for output 
    for (int i = 0; i < blockDim.x; i+= width){
        tile[threadIdx.y+i][threadIdx.x] = input_data[(y+i)*width + x];
    }
    // thread barrier. All threads must reach this barrier before continuing
    __syncthreads();

    // transpose the blocks for writing to output matrix
    x = blockIdx.y * blockDim.x + threadIdx.x; // swap block x to y
    y = blockIdx.x * blockDim.x + threadIdx.y; // swap block y to x

    // write to output data from tiles (shared memory) to the global memory
    for (int i=0; i< blockDim.x; i+=width){
        output_data[(y + i)*width + x] = tile[threadIdx.x][threadIdx.y+i];
    }
}

int main() {
    // matrix sizes 2^9, 2^10, 2^11, 2^12 = 512, 1024, 2048, 4096
    int matrix_sizes[] = {256, 512, 1024, 2048, 4096};
        int WIDTH = matrix_sizes[4];
        int num_element = WIDTH * WIDTH;

        // create the matrix and fill it with random numbers
        int *h_input_matrix = createMatrix(num_element);
        int *h_result_matrix = allocateMatrix(num_element);
        int *d_input_matrix;
        int *d_output_matrix;

        // printArray(h_input_matrix, WIDTH);
        int memory_space_required = num_element * sizeof(int);

    //-------------- Serial Matrix Transpose on CPU --------------//
        cudaEvent_t serial_start, serial_stop;
        cudaEventCreate(&serial_start);
        cudaEventCreate(&serial_stop);

        cudaEventRecord(serial_start);
        h_result_matrix = sequential_transpose(h_input_matrix, WIDTH);
        cudaEventRecord(serial_stop);
        cudaEventSynchronize(serial_stop);

        float serial_time = 0;
        cudaEventElapsedTime(&serial_time, serial_start, serial_stop);
        // printArray(result_matrix, WIDTH);

    //-------------- CUDA --------------//

        // allocate memory on device
        cudaMalloc((void **) &d_input_matrix, memory_space_required);
        cudaMalloc((void **) &d_output_matrix, memory_space_required);

        // CUDA timing of event
        cudaEvent_t global_start, global_stop, shared_start, shared_stop;
        cudaEventCreate(&global_start);
        cudaEventCreate(&global_stop);
        cudaEventCreate(&shared_start);
        cudaEventCreate(&shared_stop);

        // copy memory from host to device
        cudaMemcpy(d_input_matrix, h_input_matrix, memory_space_required, cudaMemcpyHostToDevice);

        // dimensions for the kernel
        dim3 Grid_Dim(WIDTH/TILE_WIDTH, WIDTH/TILE_WIDTH);
        dim3 Block_Dim(TILE_WIDTH, TILE_WIDTH);

    //-------------- CUDA Matrix Transpose Global Memory --------------//
        // start the global memory kernel
        cudaEventRecord(global_start);
        global_transpose_matrix<<<Grid_Dim, Block_Dim>>>(d_output_matrix, d_input_matrix);
        cudaEventRecord(global_stop);
        cudaEventSynchronize(global_stop);

        float global_elapsedTime = 0;
        cudaEventElapsedTime(&global_elapsedTime, global_start, global_stop);
        cudaEventDestroy(global_start);
        cudaEventDestroy(global_stop);

    //-------------- CUDA Matrix Transpose Shared Memory --------------//
        // start the shared memory kernel
        cudaEventRecord(shared_start);
        shared_transpose_matrix<<<Grid_Dim, Block_Dim>>>(d_output_matrix, d_input_matrix);
        cudaEventRecord(shared_stop); 
        cudaEventSynchronize(shared_stop);
        
        float shared_elapsedTime = 0;
        cudaEventElapsedTime(&shared_elapsedTime, shared_start, shared_stop);

        cudaEventDestroy(shared_start);
        cudaEventDestroy(shared_stop);

        // copy back the results
        cudaMemcpy(h_result_matrix, d_output_matrix, memory_space_required, cudaMemcpyDeviceToHost);
        // printArray(h_result_matrix, WIDTH);

         //-------------- CUDA Performance Metrics --------------//
         float num_ops= num_element; // every element swap once
  
         float serial_throughput = num_ops / (serial_time / 1000.0f) / 1000000000.0f;
         float global_throughput = num_ops / (global_elapsedTime / 1000.0f) / 1000000000.0f;
         float shared_throughput = num_ops / (shared_elapsedTime / 1000.0f) / 1000000000.0f;
 
         std::cout << "Matrix size: " << WIDTH << "x" << WIDTH << std::endl;
         std::cout << "Tile size: " << TILE_WIDTH << "x" << TILE_WIDTH << std::endl;
 
         printf("Serial Matrix Transpose Time: %3.6f ms \n", serial_time);
         printf("Global Memory Time elpased: %3.6f ms \n", global_elapsedTime);
         printf( "Shared Memory Time elpased: %3.6f ms \n", shared_elapsedTime );
 
         std::cout << "\nSpeedup of global memory kernel (CPU/GPU): " << serial_time / global_elapsedTime << " ms" << std::endl;
         std::cout << "Speedup of shared memory kernel (CPU/GPU): " << serial_time / shared_elapsedTime << " ms" << std::endl;
       
         std::cout << "\nThroughput of serial implementation: " << serial_throughput << " GFLOPS" << std::endl;
         std::cout << "Throughput of global memory kernel: " << global_throughput << " GFLOPS" << std::endl;
         std::cout << "Throughput of shared memory kernel: " << shared_throughput << " GFLOPS" << std::endl;
         std::cout << "Performance improvement: simple over global " << serial_throughput / global_throughput << "x" << std::endl;
         std::cout << "Performance improvement: simple over shared " << serial_throughput / shared_throughput << "x" << std::endl;
         std::cout << "Performance improvement: global over shared " << global_throughput / shared_throughput << "x" << std::endl;

        //-------------- Free Memory --------------//
        free(h_input_matrix);
        free(h_result_matrix);
        cudaFree(d_input_matrix);
        cudaFree(d_output_matrix);
        printf("\n");
}
	.file	"tmpxft_00259e44_00000000-6_matrixTranspose.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3644:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3644:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4301:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4301:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z22randomNumberGenerationii
	.type	_Z22randomNumberGenerationii, @function
_Z22randomNumberGenerationii:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	pushq	%rax
	.cfi_def_cfa_offset 32
	subl	%ebp, %ebx
	call	rand@PLT
	leal	1(%rbx), %edi
	cltd
	idivl	%edi
	leal	(%rdx,%rbp), %eax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z22randomNumberGenerationii, .-_Z22randomNumberGenerationii
	.globl	_Z10createDataPii
	.type	_Z10createDataPii, @function
_Z10createDataPii:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$10, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L6:
	cmpl	%ebp, %r12d
	jle	.L10
	call	rand@PLT
	cltd
	idivl	%r13d
	movl	%edx, (%rbx,%rbp,4)
	incq	%rbp
	jmp	.L6
.L10:
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z10createDataPii, .-_Z10createDataPii
	.globl	_Z12createMatrixi
	.type	_Z12createMatrixi, @function
_Z12createMatrixi:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movslq	%edi, %rdi
	movq	%rdi, %rbx
	salq	$3, %rdi
	call	malloc@PLT
	movl	%ebx, %esi
	popq	%rbx
	.cfi_def_cfa_offset 8
	movq	%rax, %rdi
	jmp	_Z10createDataPii
	.cfi_endproc
.LFE3637:
	.size	_Z12createMatrixi, .-_Z12createMatrixi
	.globl	_Z14allocateMatrixi
	.type	_Z14allocateMatrixi, @function
_Z14allocateMatrixi:
.LFB3638:
	.cfi_startproc
	endbr64
	movslq	%edi, %rdi
	salq	$3, %rdi
	jmp	malloc@PLT
	.cfi_endproc
.LFE3638:
	.size	_Z14allocateMatrixi, .-_Z14allocateMatrixi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z10printArrayPii
	.type	_Z10printArrayPii, @function
_Z10printArrayPii:
.LFB3639:
	.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
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r13, %rbp
	salq	$2, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 64
.L15:
	cmpl	%ebp, %r12d
	jge	.L20
	leaq	(%rbx,%r13), %r15
.L16:
	movl	(%rbx), %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	addq	$4, %rbx
	call	__printf_chk@PLT
	cmpq	%r15, %rbx
	jne	.L16
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%r12d
	call	__printf_chk@PLT
	jmp	.L15
.L20:
	popq	%rax
	.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
.LFE3639:
	.size	_Z10printArrayPii, .-_Z10printArrayPii
	.globl	_Z20sequential_transposePii
	.type	_Z20sequential_transposePii, @function
_Z20sequential_transposePii:
.LFB3640:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	movl	%esi, %edi
	imull	%esi, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%esi, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	malloc@PLT
	movslq	%ebx, %rcx
	movq	%rbp, %rdx
	xorl	%edi, %edi
	movq	%rax, %r8
	salq	$2, %rcx
.L22:
	cmpl	%ebx, %edi
	jge	.L27
	movq	%r8, %r9
	xorl	%esi, %esi
.L23:
	movl	(%rdx,%rsi,4), %r10d
	incq	%rsi
	movl	%r10d, (%r9)
	addq	%rcx, %r9
	cmpl	%esi, %ebx
	jg	.L23
	incl	%edi
	addq	$4, %r8
	addq	%rcx, %rdx
	jmp	.L22
.L27:
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3640:
	.size	_Z20sequential_transposePii, .-_Z20sequential_transposePii
	.globl	_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi
	.type	_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi, @function
_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi:
.LFB3666:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z23global_transpose_matrixPiPKi(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L28:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3666:
	.size	_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi, .-_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi
	.globl	_Z23global_transpose_matrixPiPKi
	.type	_Z23global_transpose_matrixPiPKi, @function
_Z23global_transpose_matrixPiPKi:
.LFB3667:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi
	.cfi_endproc
.LFE3667:
	.size	_Z23global_transpose_matrixPiPKi, .-_Z23global_transpose_matrixPiPKi
	.globl	_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi
	.type	_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi, @function
_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi:
.LFB3668:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z23shared_transpose_matrixPiPKi(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L33:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3668:
	.size	_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi, .-_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi
	.globl	_Z23shared_transpose_matrixPiPKi
	.type	_Z23shared_transpose_matrixPiPKi, @function
_Z23shared_transpose_matrixPiPKi:
.LFB3669:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi
	.cfi_endproc
.LFE3669:
	.size	_Z23shared_transpose_matrixPiPKi, .-_Z23shared_transpose_matrixPiPKi
	.section	.rodata.str1.1
.LC6:
	.string	"Matrix size: "
.LC7:
	.string	"x"
.LC8:
	.string	"Tile size: "
.LC9:
	.string	"Serial Matrix Transpose Time: %3.6f ms \n"
.LC10:
	.string	"Global Memory Time elpased: %3.6f ms \n"
.LC11:
	.string	"Shared Memory Time elpased: %3.6f ms \n"
.LC12:
	.string	"\nSpeedup of global memory kernel (CPU/GPU): "
.LC13:
	.string	" ms"
.LC14:
	.string	"Speedup of shared memory kernel (CPU/GPU): "
.LC15:
	.string	"\nThroughput of serial implementation: "
.LC16:
	.string	" GFLOPS"
.LC17:
	.string	"Throughput of global memory kernel: "
.LC18:
	.string	"Throughput of shared memory kernel: "
.LC19:
	.string	"Performance improvement: simple over global "
.LC20:
	.string	"Performance improvement: simple over shared "
.LC21:
	.string	"Performance improvement: global over shared "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3641:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$16777216, %edi
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	call	_Z12createMatrixi
	movl	$16777216, %edi
	movq	%rax, %rbp
	call	_Z14allocateMatrixi
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$4096, %esi
	movq	%rbp, %rdi
	call	_Z20sequential_transposePii
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %r13
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	20(%rsp), %rdi
	movl	$0x00000000, 20(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	32(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	movl	$67108864, %esi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	88(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	movabsq	$549755814016, %rax
	movq	%rax, 96(%rsp)
	movabsq	$137438953504, %rax
	movl	$1, 104(%rsp)
	movq	%rax, 108(%rsp)
	movl	$1, 116(%rsp)
	call	cudaEventRecord@PLT
	movl	116(%rsp), %ecx
	movl	104(%rsp), %esi
	xorl	%r9d, %r9d
	movq	108(%rsp), %rdx
	movq	96(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	movq	32(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z46__device_stub__Z23global_transpose_matrixPiPKiPiPKi
.L39:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	24(%rsp), %rdi
	movl	$0x00000000, 24(%rsp)
	call	cudaEventElapsedTime@PLT
	movq	64(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	116(%rsp), %ecx
	movl	104(%rsp), %esi
	xorl	%r9d, %r9d
	movq	108(%rsp), %rdx
	movq	96(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	32(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z46__device_stub__Z23shared_transpose_matrixPiPKiPiPKi
.L40:
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	leaq	_ZSt4cout(%rip), %rbx
	leaq	.LC7(%rip), %r12
	leaq	.LC13(%rip), %r14
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	28(%rsp), %rdi
	movl	$0x00000000, 28(%rsp)
	call	cudaEventElapsedTime@PLT
	movq	80(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	88(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	movss	.LC3(%rip), %xmm3
	movq	%rbx, %rdi
	movss	20(%rsp), %xmm2
	movss	.LC4(%rip), %xmm1
	leaq	.LC6(%rip), %rsi
	divss	%xmm3, %xmm2
	movaps	%xmm1, %xmm0
	movaps	%xmm1, %xmm4
	divss	%xmm2, %xmm0
	movss	.LC5(%rip), %xmm2
	divss	%xmm2, %xmm0
	movd	%xmm0, %r15d
	movss	24(%rsp), %xmm0
	divss	%xmm3, %xmm0
	divss	%xmm0, %xmm4
	movss	28(%rsp), %xmm0
	divss	%xmm3, %xmm0
	divss	%xmm2, %xmm4
	divss	%xmm0, %xmm1
	movss	%xmm4, 8(%rsp)
	divss	%xmm2, %xmm1
	movss	%xmm1, 12(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$4096, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$4096, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC8(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$32, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$32, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC10(%rip), %rsi
	cvtss2sd	24(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	leaq	.LC12(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	20(%rsp), %xmm0
	divss	24(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC14(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	20(%rsp), %xmm0
	divss	28(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	leaq	.LC16(%rip), %r14
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC15(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%r15d, %xmm5
	movq	%rax, %rdi
	cvtss2sd	%xmm5, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC17(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC18(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	12(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC19(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%r15d, %xmm0
	divss	8(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC20(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%r15d, %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC21(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	8(%rsp), %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE3641:
	.size	main, .-main
	.section	.rodata.str1.1
.LC22:
	.string	"_Z23shared_transpose_matrixPiPKi"
.LC23:
	.string	"_Z23global_transpose_matrixPiPKi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3671:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC22(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z23shared_transpose_matrixPiPKi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC23(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z23global_transpose_matrixPiPKi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3671:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1148846080
	.align 4
.LC4:
	.long	1266679808
	.align 4
.LC5:
	.long	1315859240
	.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 <time.h> 
#include <iostream>


const int TILE_WIDTH = 32;

int randomNumberGeneration(int upperBound, int lowerBound) {
    int num = (rand() % (upperBound - lowerBound + 1)) + lowerBound;
    return num;
}

int *createData(int *array, int num_element) {
    for (int i = 0; i < num_element; i++) {
        array[i] = randomNumberGeneration(9, 0);
    }
    return array;
}

int *createMatrix(int num_element) {
    int *array = (int *)malloc(num_element * sizeof(int *));
    // create synthetic data for matrix
    array = createData(array, num_element);
    return array;
}

int *allocateMatrix(int num_element) {
    int *array = (int *)malloc(num_element * sizeof(int *));
    return array;
}

void printArray(int *array, int width) {
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < width; j++) {
            printf("%d ", array[(i * width) + j]);
        }
        printf("\n");
    }
}

int *sequential_transpose(int *array, int width){
    // allocate space for the results array
    int *result = (int *)malloc(width*width * sizeof(int *));
    // swap i and j values (x and y) in the matrix to produce the transpose
    // result maps to result(j,i) = input(i,j)
    for (int i=0; i<width; i++){
        for (int j=0; j<width; j++){
            result[j*width +i] = array[i*width +j];
        }
    }
    return result;
}

__global__ void global_transpose_matrix(int *output_data, const int *input_data){
    // x =  get threads in x direction i.e. columns
    // y = get threads in y direction i.e. rows
    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;
    int width = gridDim.x * blockDim.x; 

    // swap x and x values in the matrix to produce the transpose
    // results map to output(y,x) = input(x,y)
    for (int i = 0; i < blockDim.x; i+= width){
        output_data[x*width + (y+i)] = input_data[(y+i)*width + x];
    }
}

__global__ void shared_transpose_matrix(int *output_data, const int *input_data){
    // creating tiles in the shared memory for faster computation
    // each tile is created of the preset size i.e. 32 in this case
    __shared__ int tile[TILE_WIDTH] [TILE_WIDTH+1];
    // x =  get threads in x direction i.e. columns
    // y = get threads in y direction i.e. rows
    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;
    int width = gridDim.x * blockDim.x;

    // swap x and x values in the tile to produce the transposed tiled
    // tile maps to (y,x) = input(x,y)
    // we save these tiles in transposed hence it is (y,x)
    // this will help us to elimanate the usage of thread synching for output 
    for (int i = 0; i < blockDim.x; i+= width){
        tile[threadIdx.y+i][threadIdx.x] = input_data[(y+i)*width + x];
    }
    // thread barrier. All threads must reach this barrier before continuing
    __syncthreads();

    // transpose the blocks for writing to output matrix
    x = blockIdx.y * blockDim.x + threadIdx.x; // swap block x to y
    y = blockIdx.x * blockDim.x + threadIdx.y; // swap block y to x

    // write to output data from tiles (shared memory) to the global memory
    for (int i=0; i< blockDim.x; i+=width){
        output_data[(y + i)*width + x] = tile[threadIdx.x][threadIdx.y+i];
    }
}

int main() {
    // matrix sizes 2^9, 2^10, 2^11, 2^12 = 512, 1024, 2048, 4096
    int matrix_sizes[] = {256, 512, 1024, 2048, 4096};
        int WIDTH = matrix_sizes[4];
        int num_element = WIDTH * WIDTH;

        // create the matrix and fill it with random numbers
        int *h_input_matrix = createMatrix(num_element);
        int *h_result_matrix = allocateMatrix(num_element);
        int *d_input_matrix;
        int *d_output_matrix;

        // printArray(h_input_matrix, WIDTH);
        int memory_space_required = num_element * sizeof(int);

    //-------------- Serial Matrix Transpose on CPU --------------//
        hipEvent_t serial_start, serial_stop;
        hipEventCreate(&serial_start);
        hipEventCreate(&serial_stop);

        hipEventRecord(serial_start);
        h_result_matrix = sequential_transpose(h_input_matrix, WIDTH);
        hipEventRecord(serial_stop);
        hipEventSynchronize(serial_stop);

        float serial_time = 0;
        hipEventElapsedTime(&serial_time, serial_start, serial_stop);
        // printArray(result_matrix, WIDTH);

    //-------------- CUDA --------------//

        // allocate memory on device
        hipMalloc((void **) &d_input_matrix, memory_space_required);
        hipMalloc((void **) &d_output_matrix, memory_space_required);

        // CUDA timing of event
        hipEvent_t global_start, global_stop, shared_start, shared_stop;
        hipEventCreate(&global_start);
        hipEventCreate(&global_stop);
        hipEventCreate(&shared_start);
        hipEventCreate(&shared_stop);

        // copy memory from host to device
        hipMemcpy(d_input_matrix, h_input_matrix, memory_space_required, hipMemcpyHostToDevice);

        // dimensions for the kernel
        dim3 Grid_Dim(WIDTH/TILE_WIDTH, WIDTH/TILE_WIDTH);
        dim3 Block_Dim(TILE_WIDTH, TILE_WIDTH);

    //-------------- CUDA Matrix Transpose Global Memory --------------//
        // start the global memory kernel
        hipEventRecord(global_start);
        global_transpose_matrix<<<Grid_Dim, Block_Dim>>>(d_output_matrix, d_input_matrix);
        hipEventRecord(global_stop);
        hipEventSynchronize(global_stop);

        float global_elapsedTime = 0;
        hipEventElapsedTime(&global_elapsedTime, global_start, global_stop);
        hipEventDestroy(global_start);
        hipEventDestroy(global_stop);

    //-------------- CUDA Matrix Transpose Shared Memory --------------//
        // start the shared memory kernel
        hipEventRecord(shared_start);
        shared_transpose_matrix<<<Grid_Dim, Block_Dim>>>(d_output_matrix, d_input_matrix);
        hipEventRecord(shared_stop); 
        hipEventSynchronize(shared_stop);
        
        float shared_elapsedTime = 0;
        hipEventElapsedTime(&shared_elapsedTime, shared_start, shared_stop);

        hipEventDestroy(shared_start);
        hipEventDestroy(shared_stop);

        // copy back the results
        hipMemcpy(h_result_matrix, d_output_matrix, memory_space_required, hipMemcpyDeviceToHost);
        // printArray(h_result_matrix, WIDTH);

         //-------------- CUDA Performance Metrics --------------//
         float num_ops= num_element; // every element swap once
  
         float serial_throughput = num_ops / (serial_time / 1000.0f) / 1000000000.0f;
         float global_throughput = num_ops / (global_elapsedTime / 1000.0f) / 1000000000.0f;
         float shared_throughput = num_ops / (shared_elapsedTime / 1000.0f) / 1000000000.0f;
 
         std::cout << "Matrix size: " << WIDTH << "x" << WIDTH << std::endl;
         std::cout << "Tile size: " << TILE_WIDTH << "x" << TILE_WIDTH << std::endl;
 
         printf("Serial Matrix Transpose Time: %3.6f ms \n", serial_time);
         printf("Global Memory Time elpased: %3.6f ms \n", global_elapsedTime);
         printf( "Shared Memory Time elpased: %3.6f ms \n", shared_elapsedTime );
 
         std::cout << "\nSpeedup of global memory kernel (CPU/GPU): " << serial_time / global_elapsedTime << " ms" << std::endl;
         std::cout << "Speedup of shared memory kernel (CPU/GPU): " << serial_time / shared_elapsedTime << " ms" << std::endl;
       
         std::cout << "\nThroughput of serial implementation: " << serial_throughput << " GFLOPS" << std::endl;
         std::cout << "Throughput of global memory kernel: " << global_throughput << " GFLOPS" << std::endl;
         std::cout << "Throughput of shared memory kernel: " << shared_throughput << " GFLOPS" << std::endl;
         std::cout << "Performance improvement: simple over global " << serial_throughput / global_throughput << "x" << std::endl;
         std::cout << "Performance improvement: simple over shared " << serial_throughput / shared_throughput << "x" << std::endl;
         std::cout << "Performance improvement: global over shared " << global_throughput / shared_throughput << "x" << std::endl;

        //-------------- Free Memory --------------//
        free(h_input_matrix);
        free(h_result_matrix);
        hipFree(d_input_matrix);
        hipFree(d_output_matrix);
        printf("\n");
}
	.text
	.file	"matrixTranspose.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z22randomNumberGenerationii    # -- Begin function _Z22randomNumberGenerationii
	.type	_Z22randomNumberGenerationii,@function
_Z22randomNumberGenerationii:           # @_Z22randomNumberGenerationii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movl	%esi, %ebx
	movl	%edi, %ebp
	callq	rand
	subl	%ebx, %ebp
	incl	%ebp
	cltd
	idivl	%ebp
	addl	%edx, %ebx
	movl	%ebx, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22randomNumberGenerationii, .Lfunc_end0-_Z22randomNumberGenerationii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10createDataPii               # -- Begin function _Z10createDataPii
	.type	_Z10createDataPii,@function
_Z10createDataPii:                      # @_Z10createDataPii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.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 %r15, -16
	movq	%rdi, %rbx
	testl	%esi, %esi
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movl	%eax, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z10createDataPii, .Lfunc_end1-_Z10createDataPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z12createMatrixi               # -- Begin function _Z12createMatrixi
	.type	_Z12createMatrixi,@function
_Z12createMatrixi:                      # @_Z12createMatrixi
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edi, %ebp
	movslq	%edi, %r14
	leaq	(,%r14,8), %rdi
	callq	malloc
	movq	%rax, %rbx
	testl	%r14d, %r14d
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader.i
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movl	%eax, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
.LBB2_3:                                # %_Z10createDataPii.exit
	movq	%rbx, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.Lfunc_end2:
	.size	_Z12createMatrixi, .Lfunc_end2-_Z12createMatrixi
	.cfi_endproc
                                        # -- End function
	.globl	_Z14allocateMatrixi             # -- Begin function _Z14allocateMatrixi
	.type	_Z14allocateMatrixi,@function
_Z14allocateMatrixi:                    # @_Z14allocateMatrixi
	.cfi_startproc
# %bb.0:
	movslq	%edi, %rdi
	shlq	$3, %rdi
	jmp	malloc                          # TAILCALL
.Lfunc_end3:
	.size	_Z14allocateMatrixi, .Lfunc_end3-_Z14allocateMatrixi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printArrayPii               # -- Begin function _Z10printArrayPii
	.type	_Z10printArrayPii,@function
_Z10printArrayPii:                      # @_Z10printArrayPii
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%rdi, (%rsp)                    # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB4_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %ebx
	movl	%esi, %r15d
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
.LBB4_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_3 Depth 2
	movl	%ebp, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,4), %r13
	xorl	%r14d, %r14d
.LBB4_3:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r13,%r14,4), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB4_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r12
	addl	%ebx, %ebp
	cmpq	%r15, %r12
	jne	.LBB4_2
.LBB4_5:                                # %._crit_edge13
	addq	$8, %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
.Lfunc_end4:
	.size	_Z10printArrayPii, .Lfunc_end4-_Z10printArrayPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z20sequential_transposePii     # -- Begin function _Z20sequential_transposePii
	.type	_Z20sequential_transposePii,@function
_Z20sequential_transposePii:            # @_Z20sequential_transposePii
	.cfi_startproc
# %bb.0:
	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	%esi, %ebx
	movq	%rdi, %r14
	movl	%esi, %edi
	imull	%edi, %edi
	shlq	$3, %rdi
	callq	malloc
	testl	%ebx, %ebx
	jle	.LBB5_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %ecx
	leaq	(,%rcx,4), %rdx
	xorl	%esi, %esi
	movq	%rax, %rdi
	xorl	%r8d, %r8d
.LBB5_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_3 Depth 2
	movl	%esi, %r9d
	leaq	(%r14,%r9,4), %r9
	movq	%rdi, %r10
	xorl	%r11d, %r11d
.LBB5_3:                                #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r9,%r11,4), %ebp
	movl	%ebp, (%r10)
	incq	%r11
	addq	%rdx, %r10
	cmpq	%r11, %rcx
	jne	.LBB5_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	incq	%r8
	addl	%ebx, %esi
	addq	$4, %rdi
	cmpq	%rcx, %r8
	jne	.LBB5_2
.LBB5_5:                                # %._crit_edge20
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z20sequential_transposePii, .Lfunc_end5-_Z20sequential_transposePii
	.cfi_endproc
                                        # -- End function
	.globl	_Z38__device_stub__global_transpose_matrixPiPKi # -- Begin function _Z38__device_stub__global_transpose_matrixPiPKi
	.type	_Z38__device_stub__global_transpose_matrixPiPKi,@function
_Z38__device_stub__global_transpose_matrixPiPKi: # @_Z38__device_stub__global_transpose_matrixPiPKi
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z23global_transpose_matrixPiPKi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end6:
	.size	_Z38__device_stub__global_transpose_matrixPiPKi, .Lfunc_end6-_Z38__device_stub__global_transpose_matrixPiPKi
	.cfi_endproc
                                        # -- End function
	.globl	_Z38__device_stub__shared_transpose_matrixPiPKi # -- Begin function _Z38__device_stub__shared_transpose_matrixPiPKi
	.type	_Z38__device_stub__shared_transpose_matrixPiPKi,@function
_Z38__device_stub__shared_transpose_matrixPiPKi: # @_Z38__device_stub__shared_transpose_matrixPiPKi
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z23shared_transpose_matrixPiPKi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end7:
	.size	_Z38__device_stub__shared_transpose_matrixPiPKi, .Lfunc_end7-_Z38__device_stub__shared_transpose_matrixPiPKi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI8_0:
	.long	0x447a0000                      # float 1000
.LCPI8_1:
	.long	0x4b800000                      # float 16777216
.LCPI8_2:
	.long	0x4e6e6b28                      # float 1.0E+9
	.text
	.globl	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	$104, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	_Z12createMatrixi
	movq	%rax, %rbx
	leaq	88(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventCreate
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r14), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$134217728, %edi                # imm = 0x8000000
	callq	malloc
	movq	%rax, %r14
	movq	%rbx, %rax
	movq	%r14, %rcx
.LBB8_1:                                # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_2 Depth 2
	movq	%rcx, %rdx
	xorl	%esi, %esi
.LBB8_2:                                #   Parent Loop BB8_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rax,%rsi,4), %edi
	movl	%edi, (%rdx)
	incq	%rsi
	addq	$16384, %rdx                    # imm = 0x4000
	cmpq	$4096, %rsi                     # imm = 0x1000
	jne	.LBB8_2
# %bb.3:                                # %._crit_edge.i
                                        #   in Loop: Header=BB8_1 Depth=1
	incq	%r15
	addq	$4, %rcx
	addq	$16384, %rax                    # imm = 0x4000
	cmpq	$4096, %r15                     # imm = 0x1000
	jne	.LBB8_1
# %bb.4:                                # %_Z20sequential_transposePii.exit
	movabsq	$549755814016, %r12             # imm = 0x8000000080
	movabsq	$137438953504, %r15             # imm = 0x2000000020
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	64(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	12(%rsp), %rdi
	movl	$0, (%rdi)
	movq	88(%rsp), %rsi
	movq	64(%rsp), %rdx
	callq	hipEventElapsedTime
	leaq	72(%rsp), %r13
	movl	$67108864, %esi                 # imm = 0x4000000
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	leaq	80(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	leaq	56(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_6
# %bb.5:
	movq	48(%rsp), %rdi
	movq	72(%rsp), %rsi
	callq	_Z38__device_stub__global_transpose_matrixPiPKi
.LBB8_6:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	28(%rsp), %rdi
	movl	$0, (%rdi)
	movq	80(%rsp), %rsi
	movq	40(%rsp), %rdx
	callq	hipEventElapsedTime
	movq	80(%rsp), %rdi
	callq	hipEventDestroy
	movq	40(%rsp), %rdi
	callq	hipEventDestroy
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_8
# %bb.7:
	movq	48(%rsp), %rdi
	movq	72(%rsp), %rsi
	callq	_Z38__device_stub__shared_transpose_matrixPiPKi
.LBB8_8:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	100(%rsp), %r15
	movl	$0, (%r15)
	movq	56(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	56(%rsp), %rdi
	callq	hipEventDestroy
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	movq	48(%rsp), %rsi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI8_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	movss	.LCPI8_1(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm3, %xmm2
	divss	%xmm0, %xmm2
	movss	.LCPI8_2(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	%xmm0, %xmm2
	movss	%xmm2, 16(%rsp)                 # 4-byte Spill
	movss	28(%rsp), %xmm2                 # xmm2 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm2
	movaps	%xmm3, %xmm4
	divss	%xmm2, %xmm4
	divss	%xmm0, %xmm4
	movss	%xmm4, 24(%rsp)                 # 4-byte Spill
	movss	(%r15), %xmm2                   # xmm2 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm2
	divss	%xmm2, %xmm3
	divss	%xmm0, %xmm3
	movss	%xmm3, 20(%rsp)                 # 4-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$4096, %esi                     # imm = 0x1000
	callq	_ZNSolsEi
	movq	%rax, %r12
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r12, %rdi
	movl	$4096, %esi                     # imm = 0x1000
	callq	_ZNSolsEi
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$11, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$32, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r12, %rdi
	movl	$32, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	cvtss2sd	12(%rsp), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	28(%rsp), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	28(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movl	$.L.str.9, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r12), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$43, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	(%r15), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.9, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$38, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	16(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.12, %esi
	movl	$7, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.13, %esi
	movl	$36, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	24(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.12, %esi
	movl	$7, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.14, %esi
	movl	$36, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	20(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.12, %esi
	movl	$7, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.15, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	16(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	divss	24(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.16, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	16(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	divss	20(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.17, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movss	24(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	divss	20(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%eax, %eax
	addq	$104, %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
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23global_transpose_matrixPiPKi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23shared_transpose_matrixPiPKi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

	.type	_Z23global_transpose_matrixPiPKi,@object # @_Z23global_transpose_matrixPiPKi
	.section	.rodata,"a",@progbits
	.globl	_Z23global_transpose_matrixPiPKi
	.p2align	3, 0x0
_Z23global_transpose_matrixPiPKi:
	.quad	_Z38__device_stub__global_transpose_matrixPiPKi
	.size	_Z23global_transpose_matrixPiPKi, 8

	.type	_Z23shared_transpose_matrixPiPKi,@object # @_Z23shared_transpose_matrixPiPKi
	.globl	_Z23shared_transpose_matrixPiPKi
	.p2align	3, 0x0
_Z23shared_transpose_matrixPiPKi:
	.quad	_Z38__device_stub__shared_transpose_matrixPiPKi
	.size	_Z23shared_transpose_matrixPiPKi, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"Matrix size: "
	.size	.L.str.2, 14

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"x"
	.size	.L.str.3, 2

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Tile size: "
	.size	.L.str.4, 12

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Serial Matrix Transpose Time: %3.6f ms \n"
	.size	.L.str.5, 41

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Global Memory Time elpased: %3.6f ms \n"
	.size	.L.str.6, 39

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Shared Memory Time elpased: %3.6f ms \n"
	.size	.L.str.7, 39

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\nSpeedup of global memory kernel (CPU/GPU): "
	.size	.L.str.8, 45

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	" ms"
	.size	.L.str.9, 4

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Speedup of shared memory kernel (CPU/GPU): "
	.size	.L.str.10, 44

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"\nThroughput of serial implementation: "
	.size	.L.str.11, 39

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

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Throughput of global memory kernel: "
	.size	.L.str.13, 37

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Throughput of shared memory kernel: "
	.size	.L.str.14, 37

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Performance improvement: simple over global "
	.size	.L.str.15, 45

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Performance improvement: simple over shared "
	.size	.L.str.16, 45

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Performance improvement: global over shared "
	.size	.L.str.17, 45

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z23global_transpose_matrixPiPKi"
	.size	.L__unnamed_1, 33

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z23shared_transpose_matrixPiPKi"
	.size	.L__unnamed_2, 33

	.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 _Z38__device_stub__global_transpose_matrixPiPKi
	.addrsig_sym _Z38__device_stub__shared_transpose_matrixPiPKi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z23global_transpose_matrixPiPKi
	.addrsig_sym _Z23shared_transpose_matrixPiPKi
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z23global_transpose_matrixPiPKi ; -- Begin function _Z23global_transpose_matrixPiPKi
	.globl	_Z23global_transpose_matrixPiPKi
	.p2align	8
	.type	_Z23global_transpose_matrixPiPKi,@function
_Z23global_transpose_matrixPiPKi:       ; @_Z23global_transpose_matrixPiPKi
; %bb.0:
	s_load_b32 s5, s[0:1], 0x1c
	s_add_u32 s2, s0, 16
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	v_cmp_eq_u16_e64 s4, s5, 0
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s4
	s_mov_b32 s4, 0
	s_cbranch_vccnz .LBB0_3
; %bb.1:                                ; %.lr.ph
	s_load_b32 s7, s[2:3], 0x0
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v5, v0, 10, 10
	s_lshr_b32 s2, s5, 16
	s_and_b32 s5, s5, 0xffff
	s_mul_i32 s15, s15, s2
	v_mad_u64_u32 v[0:1], null, s14, s5, v[2:3]
	v_add_nc_u32_e32 v1, s15, v5
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mul_i32 s8, s5, s5
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[3:4], null, s7, v1, s[14:15]
	s_mul_i32 s6, s7, s5
	s_mul_i32 s7, s7, s7
	v_mul_lo_u32 v4, v0, s6
	s_mul_i32 s7, s7, s8
	v_mad_u64_u32 v[0:1], null, v3, s5, v[2:3]
	s_delay_alu instid0(VALU_DEP_2)
	v_add3_u32 v2, v5, v4, s15
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[3:4], 2, v[0:1]
	v_add_nc_u32_e32 v0, s7, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s2, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v4, vcc_lo
	global_load_b32 v1, v[3:4], off
	v_add_nc_u32_e32 v3, s4, v2
	s_add_i32 s4, s4, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_ge_u32 s4, s5
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b32 v[3:4], v1, off
	s_cbranch_scc0 .LBB0_2
.LBB0_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23global_transpose_matrixPiPKi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 6
		.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	_Z23global_transpose_matrixPiPKi, .Lfunc_end0-_Z23global_transpose_matrixPiPKi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 284
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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
	.protected	_Z23shared_transpose_matrixPiPKi ; -- Begin function _Z23shared_transpose_matrixPiPKi
	.globl	_Z23shared_transpose_matrixPiPKi
	.p2align	8
	.type	_Z23shared_transpose_matrixPiPKi,@function
_Z23shared_transpose_matrixPiPKi:       ; @_Z23shared_transpose_matrixPiPKi
; %bb.0:
	s_clause 0x2
	s_load_b32 s11, s[0:1], 0x1c
	s_load_b32 s8, s[0:1], 0x10
	s_load_b128 s[0:3], s[0:1], 0x0
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_mov_b32 s4, s15
	s_mov_b32 s10, 0
	s_waitcnt lgkmcnt(0)
	v_cmp_eq_u16_e64 s7, s11, 0
	s_and_b32 s5, s11, 0xffff
	v_cmp_ne_u16_e64 s9, s11, 0
	s_mul_i32 s12, s8, s8
	s_mul_i32 s13, s5, s5
	s_mul_i32 s6, s8, s5
	s_and_b32 vcc_lo, exec_lo, s7
	s_mul_i32 s7, s12, s13
	s_cbranch_vccnz .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	s_lshr_b32 s11, s11, 16
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s4, s11, v[0:1]
	s_mul_i32 s11, s6, 0x84
	v_mad_u64_u32 v[4:5], null, s8, v2, s[14:15]
	v_lshlrev_b32_e32 v5, 2, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[2:3], null, v4, s5, v[1:2]
	v_mad_u32_u24 v4, 0x84, v0, v5
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_ashrrev_i32_e32 v3, 31, v2
	s_add_i32 s10, s10, s6
	s_cmp_ge_u32 s10, s5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[5:6], 2, v[2:3]
	v_add_nc_u32_e32 v2, s7, v2
	v_add_co_u32 v5, vcc_lo, s2, v5
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v6, vcc_lo
	global_load_b32 v3, v[5:6], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v4, v3
	v_add_nc_u32_e32 v4, s11, v4
	s_cbranch_scc0 .LBB1_2
.LBB1_3:                                ; %._crit_edge
	s_and_not1_b32 vcc_lo, exec_lo, s9
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccnz .LBB1_6
; %bb.4:                                ; %.lr.ph29.preheader
	v_mad_u64_u32 v[2:3], null, s14, s5, v[0:1]
	v_lshlrev_b32_e32 v0, 2, v0
	s_lshl_b32 s2, s6, 2
	s_mov_b32 s3, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mad_u32_u24 v0, 0x84, v1, v0
	v_mad_u64_u32 v[4:5], null, s8, v2, s[4:5]
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, v4, s5, v[1:2]
.LBB1_5:                                ; %.lr.ph29
                                        ; =>This Inner Loop Header: Depth=1
	ds_load_b32 v1, v0
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_nc_u32_e32 v0, s2, v0
	s_add_i32 s3, s3, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	s_cmp_ge_u32 s3, s5
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_add_nc_u32_e32 v2, s7, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[3:4], v1, off
	s_cbranch_scc0 .LBB1_5
.LBB1_6:                                ; %._crit_edge30
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23shared_transpose_matrixPiPKi
		.amdhsa_group_segment_fixed_size 4224
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 7
		.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_end1:
	.size	_Z23shared_transpose_matrixPiPKi, .Lfunc_end1-_Z23shared_transpose_matrixPiPKi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 404
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4224 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23global_transpose_matrixPiPKi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z23global_transpose_matrixPiPKi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 4224
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23shared_transpose_matrixPiPKi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z23shared_transpose_matrixPiPKi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
