//##########################################################//
//   Name: Kirtan Mali                                      //
//   Roll no: 18AG10016                                     //
//   Question 3: Matrix Transpose using Dynamic Shared Mem  //
//##########################################################//

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

// Cuda Libraries
#include <cuda.h>
#include <cuda_runtime.h>

// Macro for error checking and debugging
#define CHECK(call) {                                                        \
    const cudaError_t error = call;                                          \
    if (error != cudaSuccess) {                                              \
        printf("Error: %s:%d, ", __FILE__, __LINE__);                        \
        printf("code: %d, reason: %s\n", error, cudaGetErrorString(error));  \
        exit(1);                                                             \
    }                                                                        \
}

typedef long long int lli;
#define MAX_VAL 100

#define TILEDIM 32
#define BLOCK_ROWS 32
#define PAD 1

void printMat(float *matrix, lli n);
void transpose_CPU(float *matrix, float *output, int n);
float *createMat(lli n, int isempty, int seed);

__global__ void transposeCoalesced(float *matrix, float *output, lli n)
{
    int tx = threadIdx.x;
    int ty = threadIdx.y;
    int x = blockIdx.x * TILEDIM + tx;
    int y = blockIdx.y * TILEDIM + ty;

    extern __shared__ float tile[];

    for (int j=0; j<TILEDIM; j+=BLOCK_ROWS)
    {
        tile[(ty+j)*(TILEDIM+PAD) + tx] = matrix[(y+j)*n + x];
    }

    __syncthreads();

    x = blockIdx.y * TILEDIM + tx;
    y = blockIdx.x * TILEDIM + ty;

    for (int j=0; j<TILEDIM; j+=BLOCK_ROWS)
    {
        output[(y+j)*n + x] = tile[tx*(TILEDIM+PAD) + ty+j];
    }
}

int main(int argc, char **argv)
{
    // Error code to check return values for CUDA calls
    cudaError_t err = cudaSuccess;

    int isprint = 1;
    if (argc > 1)
        isprint = 0;

    lli t;
    scanf("%lld", &t);

    while (t--)
    {
        lli n;
        scanf("%lld", &n);

        size_t size = sizeof(float) * n * n;

        float *h_matrix = createMat(n, 0, t);
        float *h_output = createMat(n, 1, t);
        float *h_output_check = createMat(n, 1, t);

        float *d_matrix = NULL;
        float *d_output = NULL;

        CHECK(cudaMalloc((void **)&d_matrix, size));

        CHECK(cudaMalloc((void **)&d_output, size));

        CHECK(cudaMemcpy(d_matrix, h_matrix, size, cudaMemcpyHostToDevice));

        dim3 dimGrid(ceil((float)n/BLOCK_ROWS), ceil((float)n/BLOCK_ROWS), 1);
        dim3 dimBlock(BLOCK_ROWS, BLOCK_ROWS, 1);

        transposeCoalesced<<<dimGrid, dimBlock, TILEDIM*(TILEDIM+PAD)*sizeof(float)>>>(d_matrix, d_output, n);

        err = cudaGetLastError();

        if (err != cudaSuccess)
        {
            fprintf(stderr, "Failed to launch transposeCoalesced kernel (error code %s)!\n", cudaGetErrorString(err));
            exit(EXIT_FAILURE);
        }

        CHECK(cudaMemcpy(h_output, d_output, size, cudaMemcpyDeviceToHost));

        // transpose_CPU(h_matrix, h_output_check, n);

        if (isprint == 1)
        {
            printf("\n\n***** Original Matrix *****\n\n");
            printMat(h_matrix, n);
            printf("\n\n***** Transposed Matrix using GPU *****\n\n");
            printMat(h_output, n);
            // printf("\n\n***** Transposed Matrix using CPU *****\n\n");
            // printMat(h_output_check, n);
        }
    }

    return 0;
}

// Utility Functions
float *createMat(lli n, int isempty, int seed)
{
    srand(seed+1);
    size_t size = sizeof(float) * n * n;
    float *matrix = (float *)malloc(size);

    for (int i=0; i<n*n; i++)
    {
        if (isempty == 1)
            matrix[i] = 0.0f;
        else
            matrix[i] = (float)rand()/((float)RAND_MAX/MAX_VAL);
    }

    return matrix;
}

void printMat(float *matrix, lli n)
{
    for (lli i=0; i<n*n; i++)
    {
        printf("% 6.2f ", matrix[i]);
        if (i % n == n-1)
            printf("\n");
    }
}

void transpose_CPU(float *matrix, float *output, int n)
{
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            output[i*n+j] = matrix[j*n+i];
        }
    }
}
	.file	"tmpxft_00270512_00000000-6_transpose_TILE1D.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z9createMatxii
	.type	_Z9createMatxii, @function
_Z9createMatxii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%esi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	leal	1(%rdx), %edi
	pushq	%rcx
	.cfi_def_cfa_offset 48
	imulq	%rbx, %rbx
	call	srand@PLT
	leaq	0(,%rbx,4), %rdi
	call	malloc@PLT
	movq	%rax, %rbp
.L3:
	cmpq	%rbx, %r12
	je	.L10
	xorps	%xmm0, %xmm0
	cmpl	$1, %r13d
	je	.L4
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	divss	.LC1(%rip), %xmm0
.L4:
	movss	%xmm0, 0(%rbp,%r12,4)
	incq	%r12
	jmp	.L3
.L10:
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbp, %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
.LFE2028:
	.size	_Z9createMatxii, .-_Z9createMatxii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"% 6.2f "
.LC3:
	.string	"\n"
	.text
	.globl	_Z8printMatPfx
	.type	_Z8printMatPfx, @function
_Z8printMatPfx:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC2(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rsi, %r13
	imulq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rsi, %rbx
.L12:
	cmpq	%rbp, %r13
	je	.L16
	movq	%r14, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%r12,%rbp,4), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rax
	cqto
	idivq	%rbx
	leaq	-1(%rbx), %rax
	cmpq	%rax, %rdx
	jne	.L13
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L13:
	incq	%rbp
	jmp	.L12
.L16:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z8printMatPfx, .-_Z8printMatPfx
	.globl	_Z13transpose_CPUPfS_i
	.type	_Z13transpose_CPUPfS_i, @function
_Z13transpose_CPUPfS_i:
.LFB2030:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	xorl	%r8d, %r8d
	salq	$2, %rax
.L18:
	cmpl	%edx, %r8d
	jge	.L22
	movq	%rdi, %r9
	xorl	%ecx, %ecx
.L19:
	movss	(%r9), %xmm0
	addq	%rax, %r9
	movss	%xmm0, (%rsi,%rcx,4)
	incq	%rcx
	cmpl	%ecx, %edx
	jg	.L19
	incl	%r8d
	addq	$4, %rdi
	addq	%rax, %rsi
	jmp	.L18
.L22:
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z13transpose_CPUPfS_i, .-_Z13transpose_CPUPfS_i
	.globl	_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x
	.type	_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x, @function
_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z18transposeCoalescedPfS_x(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L23:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x, .-_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x
	.globl	_Z18transposeCoalescedPfS_x
	.type	_Z18transposeCoalescedPfS_x, @function
_Z18transposeCoalescedPfS_x:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x
	.cfi_endproc
.LFE2056:
	.size	_Z18transposeCoalescedPfS_x, .-_Z18transposeCoalescedPfS_x
	.section	.rodata.str1.1
.LC4:
	.string	"%lld"
.LC5:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/KaLiMaLi555/hp3/master/term_assignments/transpose_TILE1D.cu"
.LC6:
	.string	"Error: %s:%d, "
.LC7:
	.string	"code: %d, reason: %s\n"
.LC9:
	.string	"Failed to launch transposeCoalesced kernel (error code %s)!\n"
.LC10:
	.string	"\n\n***** Original Matrix *****\n\n"
.LC11:
	.string	"\n\n***** Transposed Matrix using GPU *****\n\n"
	.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
	leaq	.LC4(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edi, %r13d
	movq	%r14, %rdi
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc23_scanf@PLT
.L29:
	movq	(%rsp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, (%rsp)
	testq	%rax, %rax
	je	.L43
	leaq	8(%rsp), %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movq	8(%rsp), %rdi
	movl	(%rsp), %edx
	xorl	%esi, %esi
	movq	%rdi, %rbx
	imulq	%rdi, %rbx
	call	_Z9createMatxii
	movl	(%rsp), %edx
	movq	8(%rsp), %rdi
	movl	$1, %esi
	movq	%rax, %r12
	call	_Z9createMatxii
	movl	(%rsp), %edx
	movq	8(%rsp), %rdi
	movl	$1, %esi
	salq	$2, %rbx
	movq	%rax, %rbp
	call	_Z9createMatxii
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, 16(%rsp)
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L30
	movl	$86, %ecx
	jmp	.L40
.L30:
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L31
	movl	$88, %ecx
.L40:
	leaq	.LC5(%rip), %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%r15d, %edi
	call	cudaGetErrorString@PLT
	movl	%r15d, %edx
	movq	%rax, %rcx
.L41:
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L42:
	movl	$1, %edi
	call	exit@PLT
.L31:
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L32
	movl	$90, %ecx
	jmp	.L40
.L32:
	cvtsi2ssq	8(%rsp), %xmm0
	mulss	.LC8(%rip), %xmm0
	call	ceilf@PLT
	xorl	%r9d, %r9d
	movl	$4224, %r8d
	movabsq	$137438953504, %rdx
	cvttss2siq	%xmm0, %rax
	movl	$1, %ecx
	movl	$1, %esi
	movl	%eax, 32(%rsp)
	movl	%eax, 36(%rsp)
	movq	32(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movq	8(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z41__device_stub__Z18transposeCoalescedPfS_xPfS_x
.L33:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L34
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L42
.L34:
	movq	24(%rsp), %rsi
	movq	%rbx, %rdx
	movl	$2, %ecx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L35
	movl	$105, %ecx
	leaq	.LC5(%rip), %rdx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	movl	%ebx, %edx
	movq	%rax, %rcx
	jmp	.L41
.L35:
	cmpl	$1, %r13d
	jg	.L29
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rsi
	movq	%r12, %rdi
	call	_Z8printMatPfx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rsi
	movq	%rbp, %rdi
	call	_Z8printMatPfx
	jmp	.L29
.L43:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L38:
	addq	$72, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z18transposeCoalescedPfS_x"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z18transposeCoalescedPfS_x(%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
.LFE2058:
	.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
.LC1:
	.long	1269028618
	.align 4
.LC8:
	.long	1023410176
	.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:

//##########################################################//
//   Name: Kirtan Mali                                      //
//   Roll no: 18AG10016                                     //
//   Question 3: Matrix Transpose using Dynamic Shared Mem  //
//##########################################################//

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

// Cuda Libraries
#include <hip/hip_runtime.h>


// Macro for error checking and debugging
#define CHECK(call) {                                                        \
    const hipError_t error = call;                                          \
    if (error != hipSuccess) {                                              \
        printf("Error: %s:%d, ", __FILE__, __LINE__);                        \
        printf("code: %d, reason: %s\n", error, hipGetErrorString(error));  \
        exit(1);                                                             \
    }                                                                        \
}

typedef long long int lli;
#define MAX_VAL 100

#define TILEDIM 32
#define BLOCK_ROWS 32
#define PAD 1

void printMat(float *matrix, lli n);
void transpose_CPU(float *matrix, float *output, int n);
float *createMat(lli n, int isempty, int seed);

__global__ void transposeCoalesced(float *matrix, float *output, lli n)
{
    int tx = threadIdx.x;
    int ty = threadIdx.y;
    int x = blockIdx.x * TILEDIM + tx;
    int y = blockIdx.y * TILEDIM + ty;

    extern __shared__ float tile[];

    for (int j=0; j<TILEDIM; j+=BLOCK_ROWS)
    {
        tile[(ty+j)*(TILEDIM+PAD) + tx] = matrix[(y+j)*n + x];
    }

    __syncthreads();

    x = blockIdx.y * TILEDIM + tx;
    y = blockIdx.x * TILEDIM + ty;

    for (int j=0; j<TILEDIM; j+=BLOCK_ROWS)
    {
        output[(y+j)*n + x] = tile[tx*(TILEDIM+PAD) + ty+j];
    }
}

int main(int argc, char **argv)
{
    // Error code to check return values for CUDA calls
    hipError_t err = hipSuccess;

    int isprint = 1;
    if (argc > 1)
        isprint = 0;

    lli t;
    scanf("%lld", &t);

    while (t--)
    {
        lli n;
        scanf("%lld", &n);

        size_t size = sizeof(float) * n * n;

        float *h_matrix = createMat(n, 0, t);
        float *h_output = createMat(n, 1, t);
        float *h_output_check = createMat(n, 1, t);

        float *d_matrix = NULL;
        float *d_output = NULL;

        CHECK(hipMalloc((void **)&d_matrix, size));

        CHECK(hipMalloc((void **)&d_output, size));

        CHECK(hipMemcpy(d_matrix, h_matrix, size, hipMemcpyHostToDevice));

        dim3 dimGrid(ceil((float)n/BLOCK_ROWS), ceil((float)n/BLOCK_ROWS), 1);
        dim3 dimBlock(BLOCK_ROWS, BLOCK_ROWS, 1);

        transposeCoalesced<<<dimGrid, dimBlock, TILEDIM*(TILEDIM+PAD)*sizeof(float)>>>(d_matrix, d_output, n);

        err = hipGetLastError();

        if (err != hipSuccess)
        {
            fprintf(stderr, "Failed to launch transposeCoalesced kernel (error code %s)!\n", hipGetErrorString(err));
            exit(EXIT_FAILURE);
        }

        CHECK(hipMemcpy(h_output, d_output, size, hipMemcpyDeviceToHost));

        // transpose_CPU(h_matrix, h_output_check, n);

        if (isprint == 1)
        {
            printf("\n\n***** Original Matrix *****\n\n");
            printMat(h_matrix, n);
            printf("\n\n***** Transposed Matrix using GPU *****\n\n");
            printMat(h_output, n);
            // printf("\n\n***** Transposed Matrix using CPU *****\n\n");
            // printMat(h_output_check, n);
        }
    }

    return 0;
}

// Utility Functions
float *createMat(lli n, int isempty, int seed)
{
    srand(seed+1);
    size_t size = sizeof(float) * n * n;
    float *matrix = (float *)malloc(size);

    for (int i=0; i<n*n; i++)
    {
        if (isempty == 1)
            matrix[i] = 0.0f;
        else
            matrix[i] = (float)rand()/((float)RAND_MAX/MAX_VAL);
    }

    return matrix;
}

void printMat(float *matrix, lli n)
{
    for (lli i=0; i<n*n; i++)
    {
        printf("% 6.2f ", matrix[i]);
        if (i % n == n-1)
            printf("\n");
    }
}

void transpose_CPU(float *matrix, float *output, int n)
{
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            output[i*n+j] = matrix[j*n+i];
        }
    }
}
	.text
	.file	"transpose_TILE1D.hip"
	.globl	_Z33__device_stub__transposeCoalescedPfS_x # -- Begin function _Z33__device_stub__transposeCoalescedPfS_x
	.type	_Z33__device_stub__transposeCoalescedPfS_x,@function
_Z33__device_stub__transposeCoalescedPfS_x: # @_Z33__device_stub__transposeCoalescedPfS_x
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z18transposeCoalescedPfS_x, %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	_Z33__device_stub__transposeCoalescedPfS_x, .Lfunc_end0-_Z33__device_stub__transposeCoalescedPfS_x
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x3d000000                      # float 0.03125
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.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	%edi, %ebx
	leaq	16(%rsp), %r14
	movl	$.L.str, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	subq	$1, (%r14)
	jb	.LBB1_12
# %bb.1:                                # %.lr.ph.preheader
	xorl	%r13d, %r13d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str, %edi
	leaq	8(%rsp), %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movq	8(%rsp), %rdi
	movq	%rdi, %r15
	imulq	%rdi, %r15
	shlq	$2, %r15
	movl	16(%rsp), %edx
	xorl	%esi, %esi
	callq	_Z9createMatxii
	movq	%rax, %r14
	movq	8(%rsp), %rdi
	movl	16(%rsp), %edx
	movl	$1, %esi
	callq	_Z9createMatxii
	movq	%rax, %rbp
	movq	8(%rsp), %rdi
	movl	16(%rsp), %edx
	movl	$1, %esi
	callq	_Z9createMatxii
	movq	%r13, 32(%rsp)
	movq	%r13, 24(%rsp)
	leaq	32(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_17
# %bb.3:                                #   in Loop: Header=BB1_2 Depth=1
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.4:                                #   in Loop: Header=BB1_2 Depth=1
	movq	32(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.5:                                #   in Loop: Header=BB1_2 Depth=1
	cvtsi2ssq	8(%rsp), %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %rdi
	movl	%edi, %eax
	shlq	$32, %rdi
	orq	%rax, %rdi
	movl	$4224, %r8d                     # imm = 0x1080
	movl	$1, %esi
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_7
# %bb.6:                                #   in Loop: Header=BB1_2 Depth=1
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	_Z33__device_stub__transposeCoalescedPfS_x
.LBB1_7:                                #   in Loop: Header=BB1_2 Depth=1
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.8:                                #   in Loop: Header=BB1_2 Depth=1
	movq	24(%rsp), %rsi
	movq	%rbp, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_13
# %bb.9:                                #   in Loop: Header=BB1_2 Depth=1
	cmpl	$1, %ebx
	jg	.LBB1_11
# %bb.10:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	8(%rsp), %rsi
	movq	%r14, %rdi
	callq	_Z8printMatPfx
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	8(%rsp), %rsi
	movq	%rbp, %rdi
	callq	_Z8printMatPfx
.LBB1_11:                               #   in Loop: Header=BB1_2 Depth=1
	subq	$1, 16(%rsp)
	jae	.LBB1_2
.LBB1_12:                               # %._crit_edge
	xorl	%eax, %eax
	addq	$40, %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_13:
	.cfi_def_cfa_offset 96
	movl	%eax, %r15d
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	movl	$105, %edx
	xorl	%eax, %eax
	callq	printf
	movl	%r15d, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %edi
	movl	%r15d, %esi
	jmp	.LBB1_19
.LBB1_14:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_20
.LBB1_15:
	movl	%eax, %r12d
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	movl	$90, %edx
	jmp	.LBB1_18
.LBB1_16:
	movl	%eax, %r12d
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	movl	$88, %edx
	jmp	.LBB1_18
.LBB1_17:
	movl	%eax, %r12d
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	movl	$86, %edx
.LBB1_18:
	xorl	%eax, %eax
	callq	printf
	movl	%r12d, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %edi
	movl	%r12d, %esi
.LBB1_19:
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
.LBB1_20:
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z9createMatxii
.LCPI2_0:
	.long	0x4ba3d70a                      # float 21474836
	.text
	.globl	_Z9createMatxii
	.type	_Z9createMatxii,@function
_Z9createMatxii:                        # @_Z9createMatxii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.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 %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
                                        # kill: def $edx killed $edx def $rdx
	movl	%esi, %ebx
	movq	%rdi, %r15
	leal	1(%rdx), %edi
	callq	srand
	movq	%r15, %r12
	imulq	%r15, %r12
	leaq	(,%r12,4), %rdi
	callq	malloc
	movq	%rax, %r14
	testq	%r15, %r15
	je	.LBB2_5
# %bb.1:                                # %.lr.ph
	cmpq	$1, %r12
	adcq	$0, %r12
	xorl	%r15d, %r15d
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cmpl	$1, %ebx
	je	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI2_0(%rip), %xmm0
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB2_2
.LBB2_5:                                # %._crit_edge
	movq	%r14, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z9createMatxii, .Lfunc_end2-_Z9createMatxii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8printMatPfx                  # -- Begin function _Z8printMatPfx
	.type	_Z8printMatPfx,@function
_Z8printMatPfx:                         # @_Z8printMatPfx
	.cfi_startproc
# %bb.0:
	testq	%rsi, %rsi
	je	.LBB3_6
# %bb.1:                                # %.lr.ph
	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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %r12
	imulq	%rbx, %r12
	leaq	-1(%rsi), %r13
	cmpq	$1, %r12
	adcq	$0, %r12
	xorl	%r15d, %r15d
.LBB3_2:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movq	%r15, %rax
	cqto
	idivq	%rbx
	cmpq	%r13, %rdx
	jne	.LBB3_4
# %bb.3:                                #   in Loop: Header=BB3_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
.LBB3_4:                                #   in Loop: Header=BB3_2 Depth=1
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB3_2
# %bb.5:
	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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_6:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z8printMatPfx, .Lfunc_end3-_Z8printMatPfx
	.cfi_endproc
                                        # -- End function
	.globl	_Z13transpose_CPUPfS_i          # -- Begin function _Z13transpose_CPUPfS_i
	.type	_Z13transpose_CPUPfS_i,@function
_Z13transpose_CPUPfS_i:                 # @_Z13transpose_CPUPfS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB4_6
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edx, %eax
	leaq	(,%rax,4), %rcx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB4_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_3 Depth 2
	movl	%r8d, %r10d
	leaq	(%rsi,%r10,4), %r10
	movq	%rdi, %r11
	xorl	%ebx, %ebx
.LBB4_3:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r11), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r10,%rbx,4)
	incq	%rbx
	addq	%rcx, %r11
	cmpq	%rbx, %rax
	jne	.LBB4_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%r9
	addl	%edx, %r8d
	addq	$4, %rdi
	cmpq	%rax, %r9
	jne	.LBB4_2
# %bb.5:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB4_6:                                # %._crit_edge17
	retq
.Lfunc_end4:
	.size	_Z13transpose_CPUPfS_i, .Lfunc_end4-_Z13transpose_CPUPfS_i
	.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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18transposeCoalescedPfS_x, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z18transposeCoalescedPfS_x,@object # @_Z18transposeCoalescedPfS_x
	.section	.rodata,"a",@progbits
	.globl	_Z18transposeCoalescedPfS_x
	.p2align	3, 0x0
_Z18transposeCoalescedPfS_x:
	.quad	_Z33__device_stub__transposeCoalescedPfS_x
	.size	_Z18transposeCoalescedPfS_x, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%lld"
	.size	.L.str, 5

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Error: %s:%d, "
	.size	.L.str.1, 15

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/KaLiMaLi555/hp3/master/term_assignments/transpose_TILE1D.hip"
	.size	.L.str.2, 123

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"code: %d, reason: %s\n"
	.size	.L.str.3, 22

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Failed to launch transposeCoalesced kernel (error code %s)!\n"
	.size	.L.str.4, 61

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"% 6.2f "
	.size	.L.str.7, 8

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18transposeCoalescedPfS_x"
	.size	.L__unnamed_1, 28

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"\n\n***** Original Matrix *****\n"
	.size	.Lstr, 31

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\n\n***** Transposed Matrix using GPU *****\n"
	.size	.Lstr.1, 43

	.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 _Z33__device_stub__transposeCoalescedPfS_x
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z18transposeCoalescedPfS_x
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18transposeCoalescedPfS_x ; -- Begin function _Z18transposeCoalescedPfS_x
	.globl	_Z18transposeCoalescedPfS_x
	.p2align	8
	.type	_Z18transposeCoalescedPfS_x,@function
_Z18transposeCoalescedPfS_x:            ; @_Z18transposeCoalescedPfS_x
; %bb.0:                                ; %.critedge
	s_load_b64 s[4:5], s[0:1], 0x10
	v_bfe_u32 v5, v0, 10, 10
	s_lshl_b32 s6, s15, 5
	s_load_b128 s[0:3], s[0:1], 0x0
	v_and_b32_e32 v7, 0x3ff, v0
	s_lshl_b32 s7, s14, 5
	v_add_nc_u32_e32 v3, s6, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v3
	s_waitcnt lgkmcnt(0)
	v_mul_lo_u32 v4, v1, s4
	v_mul_lo_u32 v6, v3, s5
	v_mad_u64_u32 v[1:2], null, v3, s4, 0
	v_add_nc_u32_e32 v3, s7, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add3_u32 v2, v2, v6, v4
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_lshlrev_b64 v[2:3], 2, v[3:4]
	v_mad_u32_u24 v4, v5, 33, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshl_add_u32 v4, v4, 2, 0
	v_add_co_u32 v0, vcc_lo, v0, v2
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo
	v_add_nc_u32_e32 v2, s7, v5
	v_mad_u32_u24 v5, v7, 33, v5
	global_load_b32 v3, v[0:1], off
	v_ashrrev_i32_e32 v0, 31, v2
	v_mul_lo_u32 v8, v2, s5
	v_lshl_add_u32 v5, v5, 2, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v6, v0, s4
	v_mad_u64_u32 v[0:1], null, v2, s4, 0
	v_add_nc_u32_e32 v2, s6, v7
	v_add3_u32 v1, v1, v8, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v4, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v4, v5
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_add_co_u32 v0, vcc_lo, v0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v4, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18transposeCoalescedPfS_x
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 9
		.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	_Z18transposeCoalescedPfS_x, .Lfunc_end0-_Z18transposeCoalescedPfS_x
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 364
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18transposeCoalescedPfS_x
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18transposeCoalescedPfS_x.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
