
/****************************************
 * CUDA kernel for transposing matrices *
 ****************************************/

#include <stdio.h>

#define CUDA_SAFE_CALL( call ) {                                         \
 cudaError_t err = call;                                                 \
 if( cudaSuccess != err ) {                                              \
   fprintf(stderr,"CUDA: error occurred in cuda routine. Exiting...\n"); \
   exit(err);                                                            \
 } }

#define	A(i,j)		A[ (j) + ((i)*(n)) ]
#define	B(i,j)		B[ (j) + ((i)*(m)) ]
#define	B_cpu(i,j) 	B_cpu[ (j) + ((i)*(m)) ]
#define	B_gpu(i,j) 	B_gpu[ (j) + ((i)*(m)) ]
#define	d_A(i,j) 	d_A[ (j) + ((i)*(n)) ]
#define	d_B(i,j) 	d_B[ (j) + ((i)*(m)) ]

__global__ void compute_kernel( unsigned int m, unsigned int n, float *d_A, float *d_B ) {
    /* Index of thread in x dimension */
    int x = threadIdx.x;
    /* Index of thread in y dimension */
    int y = threadIdx.y;
    /* Global index to a matrix row (i) */
    int i = blockIdx.x * blockDim.x + x;
    /* Global index to a matrix col (j) */
    int j = blockIdx.y * blockDim.y + y;

    /* Copy element A(i,j) into B(j,i) to form the transposed matrix */
    if (i < m && j < n){
      d_B(j, i) = d_A(i, j); 
    }

}

int cu_transpose( unsigned int m, unsigned int n, unsigned int block_size, float *h_A, float *h_B  ) {

  // Allocate device memory
  unsigned int mem_size = m * n * sizeof(float);
  float *d_A, *d_B;
  CUDA_SAFE_CALL( cudaMalloc((void **) &d_A, mem_size ) );
  CUDA_SAFE_CALL( cudaMalloc((void **) &d_B, mem_size ) );

  // Copy host memory to device 
  CUDA_SAFE_CALL( cudaMemcpy( d_A, h_A, mem_size, cudaMemcpyHostToDevice ) );

  // Calculate blocks grid size
  int blocks_col = (int) ceil( (float) n / (float) block_size );
  int blocks_row = (int) ceil( (float) m / (float) block_size );

  // Execute the kernel
  dim3 dimGrid( blocks_col, blocks_row );
  dim3 dimBlock( block_size, block_size );
  compute_kernel<<< dimGrid, dimBlock >>>( m, n, d_A, d_B );

  // Copy device memory to host 
  CUDA_SAFE_CALL( cudaMemcpy( h_B, d_B, mem_size, cudaMemcpyDeviceToHost ) );

  // Deallocate device memory
  CUDA_SAFE_CALL( cudaFree(d_A) );
  CUDA_SAFE_CALL( cudaFree(d_B) );

  return EXIT_SUCCESS;
}
 
int transpose( unsigned int m, unsigned int n, float *A, float *B ) {

  unsigned int i, j;
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      B( j, i ) = A( i, j );
    }
  }
  return EXIT_SUCCESS;

}

void printMatrix( unsigned int m, unsigned int n, float *A ) {
  int i, j;
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      printf("%8.1f",A(i,j));
    }
    printf("\n");
  }
}

int main( int argc, char *argv[] ) {
  unsigned int m, n;
  unsigned int block_size;
  unsigned int i, j;

  /* Generating input data */
  if( argc<4 ) {
    printf("Usage: %s n_rows n_cols block_size \n",argv[0]);
    exit(-1);
  }
  sscanf(argv[1],"%d",&m);
  sscanf(argv[2],"%d",&n);
  sscanf(argv[3],"%d",&block_size);
  float *A = (float *) malloc( m*n*sizeof(float) );
  printf("%s: Generating a random matrix of size %dx%d...\n",argv[0],m,n);
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      A( i, j ) = 2.0f * ( (float) rand() / RAND_MAX ) - 1.0f;
    }
  }
  float *B_cpu = (float *) malloc( m*n*sizeof(float) );
  float *B_gpu = (float *) malloc( m*n*sizeof(float) );

  printf("%s: Transposing matrix A into B in CPU...\n",argv[0]);
  transpose( m, n, A, B_cpu );

  printf("%s: Transposing matrix A into B in GPU...\n",argv[0]);
  cu_transpose( m, n, block_size, A, B_gpu );

  /* Check for correctness */
  float error = 0.0f;
  for( i=0; i<n; i++ ) {
    for( j=0; j<m; j++ ) {
      error += fabs( B_gpu( i, j ) - B_cpu( i, j ) );
    }
  }
  printf("Error CPU/GPU = %.3e\n",error);
  
  free(A);
  free(B_cpu);
  free(B_gpu);
  
}


	.file	"tmpxft_002cd769_00000000-6_MatrixTransposition_v1.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	_Z9transposejjPfS_
	.type	_Z9transposejjPfS_, @function
_Z9transposejjPfS_:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	xorl	%r9d, %r9d
	xorl	%edi, %edi
.L3:
	cmpl	%eax, %edi
	je	.L8
	movl	%edi, %r10d
	xorl	%r8d, %r8d
.L5:
	cmpl	%esi, %r8d
	je	.L9
	leal	(%r8,%r9), %r11d
	incl	%r8d
	movss	(%rdx,%r11,4), %xmm0
	movl	%r10d, %r11d
	addl	%eax, %r10d
	movss	%xmm0, (%rcx,%r11,4)
	jmp	.L5
.L9:
	incl	%edi
	addl	%esi, %r9d
	jmp	.L3
.L8:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9transposejjPfS_, .-_Z9transposejjPfS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%8.1f"
.LC1:
	.string	"\n"
	.text
	.globl	_Z11printMatrixjjPf
	.type	_Z11printMatrixjjPf, @function
_Z11printMatrixjjPf:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%esi, %r13d
	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
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rcx
	.cfi_def_cfa_offset 64
.L11:
	cmpq	%rbp, %r12
	je	.L16
	movl	%r15d, %ebx
.L13:
	leal	0(%r13,%r15), %eax
	cmpl	%eax, %ebx
	je	.L17
	movl	%ebx, %eax
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	incl	%ebx
	cvtss2sd	(%r14,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	jmp	.L13
.L17:
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	incq	%r12
	movl	%ebx, %r15d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L11
.L16:
	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
.LFE2029:
	.size	_Z11printMatrixjjPf, .-_Z11printMatrixjjPf
	.globl	_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_
	.type	_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_, @function
_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	56(%rsp), %rdi
	movl	%esi, 24(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 16(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14compute_kerneljjPfS_(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L18:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_, .-_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_
	.globl	_Z14compute_kerneljjPfS_
	.type	_Z14compute_kerneljjPfS_, @function
_Z14compute_kerneljjPfS_:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_
	.cfi_endproc
.LFE2056:
	.size	_Z14compute_kerneljjPfS_, .-_Z14compute_kerneljjPfS_
	.section	.rodata.str1.1
.LC2:
	.string	"CUDA: error occurred in cuda routine. Exiting...\n"
	.text
	.globl	_Z12cu_transposejjjPfS_
	.type	_Z12cu_transposejjjPfS_, @function
_Z12cu_transposejjjPfS_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%r8, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rcx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	movl	%edi, %eax
	leaq	16(%rsp), %rdi
	imull	%esi, %eax
	leal	0(,%rax,4), %eax
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	jne	.L39
	movq	(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L25
.L39:
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%r13d, %edi
	jmp	.L40
.L25:
	movq	(%rsp), %rdx
	movq	16(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L26
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%r14d, %edi
.L40:
	call	exit@PLT
.L26:
	movl	%r12d, %eax
	cvtsi2ssq	%rax, %xmm1
	movl	%ebp, %eax
	cvtsi2ssq	%rax, %xmm0
	movss	%xmm1, 12(%rsp)
	divss	%xmm1, %xmm0
	call	ceilf@PLT
	movl	%ebx, %eax
	movss	12(%rsp), %xmm1
	movd	%xmm0, %r14d
	cvtsi2ssq	%rax, %xmm0
	divss	%xmm1, %xmm0
	call	ceilf@PLT
	movd	%r14d, %xmm2
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttss2sil	%xmm2, %eax
	movl	%r12d, 44(%rsp)
	movl	$1, %ecx
	movl	$1, %esi
	movl	%r12d, 48(%rsp)
	movq	44(%rsp), %rdx
	movl	%eax, 32(%rsp)
	cvttss2sil	%xmm0, %eax
	movl	%eax, 36(%rsp)
	movq	32(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movq	24(%rsp), %rcx
	movq	16(%rsp), %rdx
	movl	%ebp, %esi
	movl	%ebx, %edi
	call	_Z38__device_stub__Z14compute_kerneljjPfS_jjPfS_
.L33:
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L41
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L41
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L36
.L41:
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	jmp	.L40
.L36:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	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	_Z12cu_transposejjjPfS_, .-_Z12cu_transposejjjPfS_
	.section	.rodata.str1.1
.LC4:
	.string	"Usage: %s n_rows n_cols block_size \n"
.LC5:
	.string	"%d"
.LC6:
	.string	"%s: Generating a random matrix of size %dx%d...\n"
.LC9:
	.string	"%s: Transposing matrix A into B in CPU...\n"
.LC10:
	.string	"%s: Transposing matrix A into B in GPU...\n"
.LC12:
	.string	"Error CPU/GPU = %.3e\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	jg	.L43
	movq	(%rsi), %rdx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L43:
	leaq	.LC5(%rip), %rbp
	movq	8(%rsi), %rdi
	xorl	%eax, %eax
	xorl	%r13d, %r13d
	movq	%rbp, %rsi
	leaq	28(%rsp), %rdx
	call	__isoc23_sscanf@PLT
	movq	16(%rbx), %rdi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	leaq	32(%rsp), %rdx
	call	__isoc23_sscanf@PLT
	movq	24(%rbx), %rdi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	leaq	36(%rsp), %rdx
	call	__isoc23_sscanf@PLT
	movl	28(%rsp), %ebp
	movl	32(%rsp), %r8d
	movl	%ebp, %edi
	movl	%r8d, 12(%rsp)
	imull	%r8d, %edi
	salq	$2, %rdi
	call	malloc@PLT
	movl	12(%rsp), %r8d
	movq	(%rbx), %rdx
	movl	%ebp, %ecx
	movq	%rax, %r12
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L44:
	movl	28(%rsp), %ebp
	cmpl	%ebp, %r13d
	jnb	.L54
	xorl	%ebp, %ebp
.L46:
	cmpl	32(%rsp), %ebp
	jnb	.L55
	call	rand@PLT
	movl	%eax, %edx
	movl	32(%rsp), %eax
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC7(%rip), %xmm0
	imull	%r13d, %eax
	addl	%ebp, %eax
	incl	%ebp
	addss	%xmm0, %xmm0
	subss	.LC8(%rip), %xmm0
	movl	%eax, %eax
	movss	%xmm0, (%r12,%rax,4)
	jmp	.L46
.L55:
	incl	%r13d
	jmp	.L44
.L54:
	imull	32(%rsp), %ebp
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	(%rbx), %rdx
	movl	$2, %edi
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rbp
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	32(%rsp), %esi
	movl	28(%rsp), %edi
	movq	%r13, %rcx
	movq	%r12, %rdx
	call	_Z9transposejjPfS_
	movq	(%rbx), %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rsi
	call	__printf_chk@PLT
	movl	36(%rsp), %edx
	movl	32(%rsp), %esi
	movq	%rbp, %r8
	movl	28(%rsp), %edi
	movq	%r12, %rcx
	call	_Z12cu_transposejjjPfS_
	movl	32(%rsp), %r8d
	movl	28(%rsp), %esi
	xorl	%ecx, %ecx
	xorps	%xmm0, %xmm0
	xorl	%edx, %edx
	movss	.LC11(%rip), %xmm2
.L47:
	cmpl	%edx, %r8d
	je	.L56
	xorl	%eax, %eax
.L49:
	cmpl	%eax, %esi
	je	.L57
	leal	(%rax,%rcx), %edi
	incl	%eax
	movss	0(%rbp,%rdi,4), %xmm1
	subss	0(%r13,%rdi,4), %xmm1
	andps	%xmm2, %xmm1
	addss	%xmm1, %xmm0
	jmp	.L49
.L57:
	incl	%edx
	addl	%esi, %ecx
	jmp	.L47
.L56:
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L50
	call	__stack_chk_fail@PLT
.L50:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z14compute_kerneljjPfS_"
	.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	.LC13(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14compute_kerneljjPfS_(%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
.LC7:
	.long	805306368
	.align 4
.LC8:
	.long	1065353216
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC11:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.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:


/****************************************
 * CUDA kernel for transposing matrices *
 ****************************************/


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

#define CUDA_SAFE_CALL( call ) {                                         \
 hipError_t err = call;                                                 \
 if( hipSuccess != err ) {                                              \
   fprintf(stderr,"CUDA: error occurred in cuda routine. Exiting...\n"); \
   exit(err);                                                            \
 } }

#define	A(i,j)		A[ (j) + ((i)*(n)) ]
#define	B(i,j)		B[ (j) + ((i)*(m)) ]
#define	B_cpu(i,j) 	B_cpu[ (j) + ((i)*(m)) ]
#define	B_gpu(i,j) 	B_gpu[ (j) + ((i)*(m)) ]
#define	d_A(i,j) 	d_A[ (j) + ((i)*(n)) ]
#define	d_B(i,j) 	d_B[ (j) + ((i)*(m)) ]

__global__ void compute_kernel( unsigned int m, unsigned int n, float *d_A, float *d_B ) {
    /* Index of thread in x dimension */
    int x = threadIdx.x;
    /* Index of thread in y dimension */
    int y = threadIdx.y;
    /* Global index to a matrix row (i) */
    int i = blockIdx.x * blockDim.x + x;
    /* Global index to a matrix col (j) */
    int j = blockIdx.y * blockDim.y + y;

    /* Copy element A(i,j) into B(j,i) to form the transposed matrix */
    if (i < m && j < n){
      d_B(j, i) = d_A(i, j); 
    }

}

int cu_transpose( unsigned int m, unsigned int n, unsigned int block_size, float *h_A, float *h_B  ) {

  // Allocate device memory
  unsigned int mem_size = m * n * sizeof(float);
  float *d_A, *d_B;
  CUDA_SAFE_CALL( hipMalloc((void **) &d_A, mem_size ) );
  CUDA_SAFE_CALL( hipMalloc((void **) &d_B, mem_size ) );

  // Copy host memory to device 
  CUDA_SAFE_CALL( hipMemcpy( d_A, h_A, mem_size, hipMemcpyHostToDevice ) );

  // Calculate blocks grid size
  int blocks_col = (int) ceil( (float) n / (float) block_size );
  int blocks_row = (int) ceil( (float) m / (float) block_size );

  // Execute the kernel
  dim3 dimGrid( blocks_col, blocks_row );
  dim3 dimBlock( block_size, block_size );
  compute_kernel<<< dimGrid, dimBlock >>>( m, n, d_A, d_B );

  // Copy device memory to host 
  CUDA_SAFE_CALL( hipMemcpy( h_B, d_B, mem_size, hipMemcpyDeviceToHost ) );

  // Deallocate device memory
  CUDA_SAFE_CALL( hipFree(d_A) );
  CUDA_SAFE_CALL( hipFree(d_B) );

  return EXIT_SUCCESS;
}
 
int transpose( unsigned int m, unsigned int n, float *A, float *B ) {

  unsigned int i, j;
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      B( j, i ) = A( i, j );
    }
  }
  return EXIT_SUCCESS;

}

void printMatrix( unsigned int m, unsigned int n, float *A ) {
  int i, j;
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      printf("%8.1f",A(i,j));
    }
    printf("\n");
  }
}

int main( int argc, char *argv[] ) {
  unsigned int m, n;
  unsigned int block_size;
  unsigned int i, j;

  /* Generating input data */
  if( argc<4 ) {
    printf("Usage: %s n_rows n_cols block_size \n",argv[0]);
    exit(-1);
  }
  sscanf(argv[1],"%d",&m);
  sscanf(argv[2],"%d",&n);
  sscanf(argv[3],"%d",&block_size);
  float *A = (float *) malloc( m*n*sizeof(float) );
  printf("%s: Generating a random matrix of size %dx%d...\n",argv[0],m,n);
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      A( i, j ) = 2.0f * ( (float) rand() / RAND_MAX ) - 1.0f;
    }
  }
  float *B_cpu = (float *) malloc( m*n*sizeof(float) );
  float *B_gpu = (float *) malloc( m*n*sizeof(float) );

  printf("%s: Transposing matrix A into B in CPU...\n",argv[0]);
  transpose( m, n, A, B_cpu );

  printf("%s: Transposing matrix A into B in GPU...\n",argv[0]);
  cu_transpose( m, n, block_size, A, B_gpu );

  /* Check for correctness */
  float error = 0.0f;
  for( i=0; i<n; i++ ) {
    for( j=0; j<m; j++ ) {
      error += fabs( B_gpu( i, j ) - B_cpu( i, j ) );
    }
  }
  printf("Error CPU/GPU = %.3e\n",error);
  
  free(A);
  free(B_cpu);
  free(B_gpu);
  
}


	.text
	.file	"MatrixTransposition_v1.hip"
	.globl	_Z29__device_stub__compute_kerneljjPfS_ # -- Begin function _Z29__device_stub__compute_kerneljjPfS_
	.type	_Z29__device_stub__compute_kerneljjPfS_,@function
_Z29__device_stub__compute_kerneljjPfS_: # @_Z29__device_stub__compute_kerneljjPfS_
	.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	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	8(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14compute_kerneljjPfS_, %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	_Z29__device_stub__compute_kerneljjPfS_, .Lfunc_end0-_Z29__device_stub__compute_kerneljjPfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12cu_transposejjjPfS_         # -- Begin function _Z12cu_transposejjjPfS_
	.type	_Z12cu_transposejjjPfS_,@function
_Z12cu_transposejjjPfS_:                # @_Z12cu_transposejjjPfS_
	.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
	movq	%r8, 32(%rsp)                   # 8-byte Spill
	movq	%rcx, %r13
	movl	%edx, %r12d
	movl	%esi, %ebp
	movl	%edi, %r15d
	movl	%edi, %r14d
	imull	%esi, %r14d
	shll	$2, %r14d
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.1:
	leaq	8(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.2:
	movq	16(%rsp), %rdi
	movq	%r13, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.3:
	movl	%ebp, %eax
	cvtsi2ss	%rax, %xmm0
	movl	%r12d, %ebx
	cvtsi2ss	%rbx, %xmm1
	movss	%xmm1, 28(%rsp)                 # 4-byte Spill
	divss	%xmm1, %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r12d
	movl	%r15d, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	divss	28(%rsp), %xmm0                 # 4-byte Folded Reload
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	shlq	$32, %rdi
	orq	%r12, %rdi
	movq	%rbx, %rdx
	shlq	$32, %rdx
	orq	%rbx, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_5
# %bb.4:
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rcx
	movl	%r15d, %edi
	movl	%ebp, %esi
	callq	_Z29__device_stub__compute_kerneljjPfS_
.LBB1_5:
	movq	8(%rsp), %rsi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.6:
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.7:
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.8:
	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_9:
	.cfi_def_cfa_offset 96
	movl	%eax, %ebx
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$49, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	%ebx, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z12cu_transposejjjPfS_, .Lfunc_end1-_Z12cu_transposejjjPfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9transposejjPfS_              # -- Begin function _Z9transposejjPfS_
	.type	_Z9transposejjPfS_,@function
_Z9transposejjPfS_:                     # @_Z9transposejjPfS_
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	je	.LBB2_7
# %bb.1:                                # %.preheader.lr.ph
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%esi, %eax
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%esi, %esi
	je	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movq	%rax, %r10
	movl	%r8d, %r11d
	movl	%r9d, %ebx
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r11d, %r14d
	movss	(%rdx,%r14,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movl	%ebx, %r14d
	movss	%xmm0, (%rcx,%r14,4)
	addl	%edi, %ebx
	incl	%r11d
	decq	%r10
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incl	%r9d
	addl	%esi, %r8d
	cmpl	%edi, %r9d
	jne	.LBB2_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
.LBB2_7:                                # %._crit_edge18
	xorl	%eax, %eax
	retq
.Lfunc_end2:
	.size	_Z9transposejjPfS_, .Lfunc_end2-_Z9transposejjPfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printMatrixjjPf             # -- Begin function _Z11printMatrixjjPf
	.type	_Z11printMatrixjjPf,@function
_Z11printMatrixjjPf:                    # @_Z11printMatrixjjPf
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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, 12(%rsp)                  # 4-byte Spill
	testl	%edi, %edi
	je	.LBB3_6
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdx, %rbx
	movl	%esi, %ebp
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	testl	%ebp, %ebp
	je	.LBB3_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	16(%rsp), %r15                  # 8-byte Reload
	movl	%r14d, %r12d
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r12d, %eax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%rax,4), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	incl	%r12d
	decq	%r15
	jne	.LBB3_4
.LBB3_5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incl	%r13d
	addl	%ebp, %r14d
	cmpl	12(%rsp), %r13d                 # 4-byte Folded Reload
	jne	.LBB3_2
.LBB3_6:                                # %._crit_edge13
	addq	$24, %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_end3:
	.size	_Z11printMatrixjjPf, .Lfunc_end3-_Z11printMatrixjjPf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI4_1:
	.long	0xbf800000                      # float -1
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI4_2:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	cmpl	$3, %edi
	jle	.LBB4_24
# %bb.1:
	movq	8(%r14), %rdi
	leaq	16(%rsp), %r15
	movl	$.L.str.4, %esi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	16(%r14), %rdi
	leaq	12(%rsp), %r12
	movl	$.L.str.4, %esi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	24(%r14), %rdi
	leaq	20(%rsp), %rdx
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movl	(%r15), %ebp
	movl	(%r12), %r13d
	movl	%r13d, %edi
	imull	%ebp, %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	(%r14), %rsi
	movl	$.L.str.5, %edi
	movl	%ebp, %edx
	movl	%r13d, %ecx
	xorl	%eax, %eax
	callq	printf
	movl	(%r15), %eax
	movl	(%r12), %r12d
	testl	%eax, %eax
	je	.LBB4_2
# %bb.3:                                # %.preheader40.preheader
	xorl	%ebp, %ebp
	movl	%r12d, %ecx
.LBB4_4:                                # %.preheader40
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_6 Depth 2
	testl	%ecx, %ecx
	movl	$0, %ecx
	je	.LBB4_8
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB4_4 Depth=1
	xorl	%r15d, %r15d
.LBB4_6:                                # %.lr.ph
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movss	.LCPI4_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm0
	addss	%xmm1, %xmm0
	movl	12(%rsp), %r12d
	movl	%ebp, %eax
	imull	%r12d, %eax
	addl	%r15d, %eax
	movss	%xmm0, (%rbx,%rax,4)
	incl	%r15d
	cmpl	%r12d, %r15d
	jb	.LBB4_6
# %bb.7:                                # %._crit_edge.loopexit
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	16(%rsp), %eax
	movl	%r12d, %ecx
.LBB4_8:                                # %._crit_edge
                                        #   in Loop: Header=BB4_4 Depth=1
	incl	%ebp
	cmpl	%eax, %ebp
	jb	.LBB4_4
	jmp	.LBB4_9
.LBB4_2:
	xorl	%eax, %eax
.LBB4_9:                                # %._crit_edge43
	imull	%eax, %r12d
	shlq	$2, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	(%r14), %rsi
	xorl	%ebp, %ebp
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	16(%rsp), %eax
	testl	%eax, %eax
	je	.LBB4_15
# %bb.10:                               # %.preheader.lr.ph.i
	movl	12(%rsp), %ecx
	xorl	%edx, %edx
.LBB4_11:                               # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_13 Depth 2
	testq	%rcx, %rcx
	je	.LBB4_14
# %bb.12:                               # %.lr.ph.i
                                        #   in Loop: Header=BB4_11 Depth=1
	movl	%ebp, %esi
	movl	%edx, %edi
	movq	%rcx, %r8
.LBB4_13:                               #   Parent Loop BB4_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%esi, %r9d
	movss	(%rbx,%r9,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movl	%edi, %r9d
	movss	%xmm0, (%r15,%r9,4)
	addl	%eax, %edi
	incl	%esi
	decq	%r8
	jne	.LBB4_13
.LBB4_14:                               # %._crit_edge.i
                                        #   in Loop: Header=BB4_11 Depth=1
	incl	%edx
	addl	%ecx, %ebp
	cmpl	%eax, %edx
	jne	.LBB4_11
.LBB4_15:                               # %_Z9transposejjPfS_.exit
	movq	(%r14), %rsi
	xorl	%ebp, %ebp
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	16(%rsp), %edi
	movl	12(%rsp), %esi
	movl	20(%rsp), %edx
	movq	%rbx, %rcx
	movq	%r12, %r8
	callq	_Z12cu_transposejjjPfS_
	movl	12(%rsp), %eax
	testl	%eax, %eax
	je	.LBB4_16
# %bb.17:                               # %.preheader.lr.ph
	movl	16(%rsp), %ecx
	xorps	%xmm0, %xmm0
	movaps	.LCPI4_2(%rip), %xmm1           # xmm1 = [NaN,NaN,NaN,NaN]
	xorl	%edx, %edx
.LBB4_18:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_20 Depth 2
	testq	%rcx, %rcx
	je	.LBB4_21
# %bb.19:                               # %.lr.ph46
                                        #   in Loop: Header=BB4_18 Depth=1
	movq	%rcx, %rsi
	movl	%ebp, %edi
.LBB4_20:                               #   Parent Loop BB4_18 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edi, %r8d
	movss	(%r12,%r8,4), %xmm2             # xmm2 = mem[0],zero,zero,zero
	subss	(%r15,%r8,4), %xmm2
	andps	%xmm1, %xmm2
	addss	%xmm2, %xmm0
	incl	%edi
	decq	%rsi
	jne	.LBB4_20
.LBB4_21:                               # %._crit_edge47
                                        #   in Loop: Header=BB4_18 Depth=1
	incl	%edx
	addl	%ecx, %ebp
	cmpl	%eax, %edx
	jne	.LBB4_18
# %bb.22:                               # %._crit_edge51.loopexit
	cvtss2sd	%xmm0, %xmm0
	jmp	.LBB4_23
.LBB4_16:
	xorps	%xmm0, %xmm0
.LBB4_23:                               # %._crit_edge51
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$24, %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
.LBB4_24:
	.cfi_def_cfa_offset 80
	movq	(%r14), %rsi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	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	$_Z14compute_kerneljjPfS_, %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	_Z14compute_kerneljjPfS_,@object # @_Z14compute_kerneljjPfS_
	.section	.rodata,"a",@progbits
	.globl	_Z14compute_kerneljjPfS_
	.p2align	3, 0x0
_Z14compute_kerneljjPfS_:
	.quad	_Z29__device_stub__compute_kerneljjPfS_
	.size	_Z14compute_kerneljjPfS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA: error occurred in cuda routine. Exiting...\n"
	.size	.L.str, 50

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%8.1f"
	.size	.L.str.1, 6

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Usage: %s n_rows n_cols block_size \n"
	.size	.L.str.3, 37

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d"
	.size	.L.str.4, 3

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%s: Generating a random matrix of size %dx%d...\n"
	.size	.L.str.5, 49

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%s: Transposing matrix A into B in CPU...\n"
	.size	.L.str.6, 43

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%s: Transposing matrix A into B in GPU...\n"
	.size	.L.str.7, 43

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Error CPU/GPU = %.3e\n"
	.size	.L.str.8, 22

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

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

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

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

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14compute_kerneljjPfS_ ; -- Begin function _Z14compute_kerneljjPfS_
	.globl	_Z14compute_kerneljjPfS_
	.p2align	8
	.type	_Z14compute_kerneljjPfS_,@function
_Z14compute_kerneljjPfS_:               ; @_Z14compute_kerneljjPfS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b64 s[4:5], s[0:1], 0x0
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, s4, v0
	v_cmp_gt_u32_e64 s2, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x8
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, v0, s5, v[1:2]
	v_mov_b32_e32 v3, 0
	v_lshlrev_b64 v[4:5], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	global_load_b32 v2, v[4:5], off
	v_mad_u64_u32 v[4:5], null, v1, s4, v[0:1]
	v_mov_b32_e32 v5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[4:5]
	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)
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14compute_kerneljjPfS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 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	_Z14compute_kerneljjPfS_, .Lfunc_end0-_Z14compute_kerneljjPfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 228
; 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
	.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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14compute_kerneljjPfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14compute_kerneljjPfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
