#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// Input Array Variables
float* h_MatA = NULL;

// Output Array
float* h_VecV = NULL;
float* h_VecW = NULL;
float* h_NormW = NULL;

// Variables to change
int GlobalSize = 5000;         // this is the dimension of the matrix, GlobalSize*GlobalSize
const float EPS = 0.000005;    // tolerence of the error
int max_iteration = 100;       // the maximum iteration steps

// Functions
void Cleanup(void);
void InitOne(float*, int);
void UploadArray(float*, int);
float CPUReduce(float*, int);
void  Arguments(int, char**);

void CPU_AvProduct()
{
  int N = GlobalSize;
  int matIndex =0;
  for(int i=0;i<N;i++)
  {
    h_VecW[i] = 0;
    for(int j=0;j<N;j++)
    {
      matIndex = i*N + j;
      h_VecW[i] += h_MatA[matIndex] * h_VecV[j];
			
    }
  }
}

void CPU_NormalizeW()
{
  int N = GlobalSize;
  float normW=0;
  for(int i=0;i<N;i++)
    normW += h_VecW[i] * h_VecW[i];
	
  normW = sqrt(normW);
  for(int i=0;i<N;i++)
    h_VecV[i] = h_VecW[i]/normW;
}

float CPU_ComputeLamda()
{
  int N = GlobalSize;
  float lamda =0;
  for(int i=0;i<N;i++)
    lamda += h_VecV[i] * h_VecW[i];
	
  return lamda;
}

void RunCPUPowerMethod()
{
  printf("*************************************\n");
  float oldLamda =0;
  float lamda=0;
	
  //AvProduct
  CPU_AvProduct();
	
  //power loop
  for (int i=0;i<max_iteration;i++)
  {
    CPU_NormalizeW();
    CPU_AvProduct();
    lamda= CPU_ComputeLamda();
    printf("CPU lamda at %d: %f \n", i, lamda);
    //If residual is lass than epsilon break
    if(abs(oldLamda - lamda) < EPS)
      break;
    oldLamda = lamda;	
	
  }
  printf("*************************************\n");
	
}

// Host code
int main(int argc, char** argv)
{

  struct timespec t_start,t_end;
  double runtime;
  Arguments(argc, argv);
		
  int N = GlobalSize;
  printf("Matrix size %d X %d \n", N, N);
  size_t vec_size = N * sizeof(float);
  size_t mat_size = N * N * sizeof(float);
  size_t norm_size = sizeof(float);

  // Allocate normalized value in host memory
  h_NormW = (float*)malloc(norm_size);
  // Allocate input matrix in host memory
  h_MatA = (float*)malloc(mat_size);
  // Allocate initial vector V in host memory
  h_VecV = (float*)malloc(vec_size);
  // Allocate W vector for computations
  h_VecW = (float*)malloc(vec_size);


  // Initialize input matrix
  UploadArray(h_MatA, N);
  InitOne(h_VecV,N);

  printf("Power method in CPU starts\n");	   
  clock_gettime(CLOCK_REALTIME,&t_start);
  RunCPUPowerMethod();   // the lamda is already solved here
  clock_gettime(CLOCK_REALTIME,&t_end);
  runtime = (t_end.tv_sec - t_start.tv_sec) + 1e-9*(t_end.tv_nsec - t_start.tv_nsec);
  printf("CPU: run time = %f secs.\n",runtime);
  printf("Power method in CPU is finished\n");

  Cleanup();
  
}

void Cleanup(void)
{
  // Free host memory
  if (h_MatA)
    free(h_MatA);
  if (h_VecV)
    free(h_VecV);
  if (h_VecW)
    free(h_VecW);
  if (h_NormW)
    free(h_NormW);
    
  exit(0);
}


// Allocates an array with zero value.
void InitOne(float* data, int n)
{
  for (int i = 0; i < n; i++)
    data[i] = 0;
  data[0]=1;
}

void UploadArray(float* data, int n)
{
  int total = n*n;
  int value=1;
  for (int i = 0; i < total; i++)
  {
    data[i] = (int) (rand() % (int)(101));//1;//value;
    value ++; if(value>n) value =1;
    // data[i] = 1;
  }
}

// Obtain program arguments
void Arguments(int argc, char** argv)
{
  for (int i = 0; i < argc; ++i) 
  {
    if (strcmp(argv[i], "--size") == 0 || strcmp(argv[i], "-size") == 0)
    {
      GlobalSize = atoi(argv[i+1]);
      i = i + 1;
    }
    if (strcmp(argv[i], "--max_iteration") == 0 || strcmp(argv[i], "-max_iteration") == 0)
    {
      max_iteration = atoi(argv[i+1]);
      i = i + 1;
    }
  }
}

	.file	"tmpxft_0033260c_00000000-6_power_cpu.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2038:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2038:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13CPU_AvProductv
	.type	_Z13CPU_AvProductv, @function
_Z13CPU_AvProductv:
.LFB2027:
	.cfi_startproc
	endbr64
	movslq	GlobalSize(%rip), %r8
	movq	h_VecW(%rip), %rsi
	xorl	%eax, %eax
	movq	h_VecV(%rip), %r9
	movq	h_MatA(%rip), %rdi
	movq	%r8, %rcx
	salq	$2, %r8
.L3:
	cmpl	%eax, %ecx
	jle	.L8
	movl	$0x00000000, (%rsi,%rax,4)
	xorl	%edx, %edx
.L4:
	movss	(%rdi,%rdx,4), %xmm0
	mulss	(%r9,%rdx,4), %xmm0
	incq	%rdx
	addss	(%rsi,%rax,4), %xmm0
	movss	%xmm0, (%rsi,%rax,4)
	cmpl	%edx, %ecx
	jg	.L4
	incq	%rax
	addq	%r8, %rdi
	jmp	.L3
.L8:
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13CPU_AvProductv, .-_Z13CPU_AvProductv
	.globl	_Z14CPU_NormalizeWv
	.type	_Z14CPU_NormalizeWv, @function
_Z14CPU_NormalizeWv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%eax, %eax
	xorps	%xmm1, %xmm1
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rdx
	.cfi_def_cfa_offset 32
	movl	GlobalSize(%rip), %ebx
	movq	h_VecW(%rip), %rbp
.L10:
	cmpl	%eax, %ebx
	jle	.L15
	movss	0(%rbp,%rax,4), %xmm0
	incq	%rax
	mulss	%xmm0, %xmm0
	addss	%xmm0, %xmm1
	jmp	.L10
.L15:
	movaps	%xmm1, %xmm0
	call	sqrtf@PLT
	movq	h_VecV(%rip), %rdx
	xorl	%eax, %eax
.L12:
	cmpl	%eax, %ebx
	jle	.L16
	movss	0(%rbp,%rax,4), %xmm1
	divss	%xmm0, %xmm1
	movss	%xmm1, (%rdx,%rax,4)
	incq	%rax
	jmp	.L12
.L16:
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14CPU_NormalizeWv, .-_Z14CPU_NormalizeWv
	.globl	_Z16CPU_ComputeLamdav
	.type	_Z16CPU_ComputeLamdav, @function
_Z16CPU_ComputeLamdav:
.LFB2029:
	.cfi_startproc
	endbr64
	movl	GlobalSize(%rip), %edx
	movq	h_VecV(%rip), %rcx
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
	movq	h_VecW(%rip), %rsi
.L18:
	cmpl	%eax, %edx
	jle	.L20
	movss	(%rcx,%rax,4), %xmm1
	mulss	(%rsi,%rax,4), %xmm1
	incq	%rax
	addss	%xmm1, %xmm0
	jmp	.L18
.L20:
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z16CPU_ComputeLamdav, .-_Z16CPU_ComputeLamdav
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"*************************************\n"
.LC2:
	.string	"CPU lamda at %d: %f \n"
	.text
	.globl	_Z17RunCPUPowerMethodv
	.type	_Z17RunCPUPowerMethodv, @function
_Z17RunCPUPowerMethodv:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC1(%rip), %rbp
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rbp, %rsi
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
	xorps	%xmm1, %xmm1
	call	_Z13CPU_AvProductv
.L22:
	cmpl	%ebx, max_iteration(%rip)
	jle	.L26
	movss	%xmm1, 12(%rsp)
	call	_Z14CPU_NormalizeWv
	call	_Z13CPU_AvProductv
	movl	$2, %edi
	call	_Z16CPU_ComputeLamdav
	movl	%ebx, %edx
	leaq	.LC2(%rip), %rsi
	movb	$1, %al
	movaps	%xmm0, %xmm2
	cvtss2sd	%xmm0, %xmm0
	movss	%xmm2, 8(%rsp)
	call	__printf_chk@PLT
	movss	8(%rsp), %xmm2
	movss	12(%rsp), %xmm1
	movss	.LC4(%rip), %xmm0
	subss	%xmm2, %xmm1
	andps	.LC3(%rip), %xmm1
	comiss	%xmm1, %xmm0
	jbe	.L27
.L26:
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
.L27:
	.cfi_restore_state
	incl	%ebx
	movaps	%xmm2, %xmm1
	jmp	.L22
	.cfi_endproc
.LFE2030:
	.size	_Z17RunCPUPowerMethodv, .-_Z17RunCPUPowerMethodv
	.globl	_Z7Cleanupv
	.type	_Z7Cleanupv, @function
_Z7Cleanupv:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	h_MatA(%rip), %rdi
	testq	%rdi, %rdi
	je	.L30
	call	free@PLT
.L30:
	movq	h_VecV(%rip), %rdi
	testq	%rdi, %rdi
	je	.L31
	call	free@PLT
.L31:
	movq	h_VecW(%rip), %rdi
	testq	%rdi, %rdi
	je	.L32
	call	free@PLT
.L32:
	movq	h_NormW(%rip), %rdi
	testq	%rdi, %rdi
	je	.L33
	call	free@PLT
.L33:
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2032:
	.size	_Z7Cleanupv, .-_Z7Cleanupv
	.globl	_Z7InitOnePfi
	.type	_Z7InitOnePfi, @function
_Z7InitOnePfi:
.LFB2033:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L48:
	cmpl	%eax, %esi
	jle	.L50
	movl	$0x00000000, (%rdi,%rax,4)
	incq	%rax
	jmp	.L48
.L50:
	movl	$0x3f800000, (%rdi)
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z7InitOnePfi, .-_Z7InitOnePfi
	.globl	_Z11UploadArrayPfi
	.type	_Z11UploadArrayPfi, @function
_Z11UploadArrayPfi:
.LFB2034:
	.cfi_startproc
	endbr64
	imull	%esi, %esi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	$101, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movslq	%esi, %rsi
	leaq	(%rdi,%rsi,4), %r12
.L52:
	cmpq	%r12, %rbx
	je	.L55
	call	rand@PLT
	addq	$4, %rbx
	cltd
	idivl	%ebp
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -4(%rbx)
	jmp	.L52
.L55:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z11UploadArrayPfi, .-_Z11UploadArrayPfi
	.section	.rodata.str1.1
.LC6:
	.string	"--size"
.LC7:
	.string	"-size"
.LC8:
	.string	"--max_iteration"
.LC9:
	.string	"-max_iteration"
	.text
	.globl	_Z9ArgumentsiPPc
	.type	_Z9ArgumentsiPPc, @function
_Z9ArgumentsiPPc:
.LFB2035:
	.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	.LC9(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC8(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L57:
	cmpl	%r12d, %ebx
	jge	.L70
	movslq	%ebx, %rax
	leaq	.LC6(%rip), %rsi
	movq	0(%rbp,%rax,8), %rdi
	leaq	0(,%rax,8), %r15
	movq	%rdi, 8(%rsp)
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L58
	movq	8(%rsp), %rdi
	leaq	.LC7(%rip), %rsi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L59
.L58:
	movq	8(%rbp,%r15), %rdi
	incl	%ebx
	call	atoi@PLT
	movl	%eax, GlobalSize(%rip)
.L59:
	movslq	%ebx, %rax
	movq	%r13, %rsi
	movq	0(%rbp,%rax,8), %rdi
	leaq	0(,%rax,8), %r15
	movq	%rdi, 8(%rsp)
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L60
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L61
.L60:
	movq	8(%rbp,%r15), %rdi
	incl	%ebx
	call	atoi@PLT
	movl	%eax, max_iteration(%rip)
.L61:
	incl	%ebx
	jmp	.L57
.L70:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z9ArgumentsiPPc, .-_Z9ArgumentsiPPc
	.section	.rodata.str1.1
.LC10:
	.string	"Matrix size %d X %d \n"
.LC11:
	.string	"Power method in CPU starts\n"
.LC13:
	.string	"CPU: run time = %f secs.\n"
.LC14:
	.string	"Power method in CPU is finished\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z9ArgumentsiPPc
	movslq	GlobalSize(%rip), %r12
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	movl	%r12d, %ecx
	movl	%r12d, %edx
	movq	%r12, %rbx
	salq	$2, %r12
	call	__printf_chk@PLT
	movl	$4, %edi
	call	malloc@PLT
	movl	%ebx, %edi
	imull	%ebx, %edi
	movq	%rax, h_NormW(%rip)
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, %rbp
	movq	%rax, h_MatA(%rip)
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, h_VecV(%rip)
	call	malloc@PLT
	movl	%ebx, %esi
	movq	%rbp, %rdi
	movq	%rax, h_VecW(%rip)
	call	_Z11UploadArrayPfi
	movq	h_VecV(%rip), %rdi
	movl	%ebx, %esi
	call	_Z7InitOnePfi
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	8(%rsp), %rsi
	xorl	%edi, %edi
	call	clock_gettime@PLT
	call	_Z17RunCPUPowerMethodv
	leaq	24(%rsp), %rsi
	xorl	%edi, %edi
	call	clock_gettime@PLT
	movq	32(%rsp), %rax
	subq	16(%rsp), %rax
	leaq	.LC13(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	movq	24(%rsp), %rax
	subq	8(%rsp), %rax
	movl	$2, %edi
	mulsd	.LC12(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	movb	$1, %al
	addsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	_Z7Cleanupv
	.cfi_endproc
.LFE2031:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2061:
	.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
	.globl	max_iteration
	.data
	.align 4
	.type	max_iteration, @object
	.size	max_iteration, 4
max_iteration:
	.long	100
	.globl	GlobalSize
	.align 4
	.type	GlobalSize, @object
	.size	GlobalSize, 4
GlobalSize:
	.long	5000
	.globl	h_NormW
	.bss
	.align 8
	.type	h_NormW, @object
	.size	h_NormW, 8
h_NormW:
	.zero	8
	.globl	h_VecW
	.align 8
	.type	h_VecW, @object
	.size	h_VecW, 8
h_VecW:
	.zero	8
	.globl	h_VecV
	.align 8
	.type	h_VecV, @object
	.size	h_VecV, 8
h_VecV:
	.zero	8
	.globl	h_MatA
	.align 8
	.type	h_MatA, @object
	.size	h_MatA, 8
h_MatA:
	.zero	8
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC3:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC4:
	.long	916964780
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC12:
	.long	-400107883
	.long	1041313291
	.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 <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// Input Array Variables
float* h_MatA = NULL;

// Output Array
float* h_VecV = NULL;
float* h_VecW = NULL;
float* h_NormW = NULL;

// Variables to change
int GlobalSize = 5000;         // this is the dimension of the matrix, GlobalSize*GlobalSize
const float EPS = 0.000005;    // tolerence of the error
int max_iteration = 100;       // the maximum iteration steps

// Functions
void Cleanup(void);
void InitOne(float*, int);
void UploadArray(float*, int);
float CPUReduce(float*, int);
void  Arguments(int, char**);

void CPU_AvProduct()
{
  int N = GlobalSize;
  int matIndex =0;
  for(int i=0;i<N;i++)
  {
    h_VecW[i] = 0;
    for(int j=0;j<N;j++)
    {
      matIndex = i*N + j;
      h_VecW[i] += h_MatA[matIndex] * h_VecV[j];
			
    }
  }
}

void CPU_NormalizeW()
{
  int N = GlobalSize;
  float normW=0;
  for(int i=0;i<N;i++)
    normW += h_VecW[i] * h_VecW[i];
	
  normW = sqrt(normW);
  for(int i=0;i<N;i++)
    h_VecV[i] = h_VecW[i]/normW;
}

float CPU_ComputeLamda()
{
  int N = GlobalSize;
  float lamda =0;
  for(int i=0;i<N;i++)
    lamda += h_VecV[i] * h_VecW[i];
	
  return lamda;
}

void RunCPUPowerMethod()
{
  printf("*************************************\n");
  float oldLamda =0;
  float lamda=0;
	
  //AvProduct
  CPU_AvProduct();
	
  //power loop
  for (int i=0;i<max_iteration;i++)
  {
    CPU_NormalizeW();
    CPU_AvProduct();
    lamda= CPU_ComputeLamda();
    printf("CPU lamda at %d: %f \n", i, lamda);
    //If residual is lass than epsilon break
    if(abs(oldLamda - lamda) < EPS)
      break;
    oldLamda = lamda;	
	
  }
  printf("*************************************\n");
	
}

// Host code
int main(int argc, char** argv)
{

  struct timespec t_start,t_end;
  double runtime;
  Arguments(argc, argv);
		
  int N = GlobalSize;
  printf("Matrix size %d X %d \n", N, N);
  size_t vec_size = N * sizeof(float);
  size_t mat_size = N * N * sizeof(float);
  size_t norm_size = sizeof(float);

  // Allocate normalized value in host memory
  h_NormW = (float*)malloc(norm_size);
  // Allocate input matrix in host memory
  h_MatA = (float*)malloc(mat_size);
  // Allocate initial vector V in host memory
  h_VecV = (float*)malloc(vec_size);
  // Allocate W vector for computations
  h_VecW = (float*)malloc(vec_size);


  // Initialize input matrix
  UploadArray(h_MatA, N);
  InitOne(h_VecV,N);

  printf("Power method in CPU starts\n");	   
  clock_gettime(CLOCK_REALTIME,&t_start);
  RunCPUPowerMethod();   // the lamda is already solved here
  clock_gettime(CLOCK_REALTIME,&t_end);
  runtime = (t_end.tv_sec - t_start.tv_sec) + 1e-9*(t_end.tv_nsec - t_start.tv_nsec);
  printf("CPU: run time = %f secs.\n",runtime);
  printf("Power method in CPU is finished\n");

  Cleanup();
  
}

void Cleanup(void)
{
  // Free host memory
  if (h_MatA)
    free(h_MatA);
  if (h_VecV)
    free(h_VecV);
  if (h_VecW)
    free(h_VecW);
  if (h_NormW)
    free(h_NormW);
    
  exit(0);
}


// Allocates an array with zero value.
void InitOne(float* data, int n)
{
  for (int i = 0; i < n; i++)
    data[i] = 0;
  data[0]=1;
}

void UploadArray(float* data, int n)
{
  int total = n*n;
  int value=1;
  for (int i = 0; i < total; i++)
  {
    data[i] = (int) (rand() % (int)(101));//1;//value;
    value ++; if(value>n) value =1;
    // data[i] = 1;
  }
}

// Obtain program arguments
void Arguments(int argc, char** argv)
{
  for (int i = 0; i < argc; ++i) 
  {
    if (strcmp(argv[i], "--size") == 0 || strcmp(argv[i], "-size") == 0)
    {
      GlobalSize = atoi(argv[i+1]);
      i = i + 1;
    }
    if (strcmp(argv[i], "--max_iteration") == 0 || strcmp(argv[i], "-max_iteration") == 0)
    {
      max_iteration = atoi(argv[i+1]);
      i = i + 1;
    }
  }
}

	.text
	.file	"power_cpu.hip"
	.globl	_Z13CPU_AvProductv              # -- Begin function _Z13CPU_AvProductv
	.type	_Z13CPU_AvProductv,@function
_Z13CPU_AvProductv:                     # @_Z13CPU_AvProductv
	.cfi_startproc
# %bb.0:
	movl	GlobalSize(%rip), %eax
	testl	%eax, %eax
	jle	.LBB0_5
# %bb.1:                                # %.lr.ph18
	movq	h_VecW(%rip), %rcx
	movq	h_MatA(%rip), %rdx
	xorl	%esi, %esi
	movq	h_VecV(%rip), %rdi
	xorl	%r8d, %r8d
.LBB0_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_3 Depth 2
	movl	%esi, %r9d
	leaq	(%rdx,%r9,4), %r9
	movl	$0, (%rcx,%r8,4)
	xorps	%xmm0, %xmm0
	xorl	%r10d, %r10d
.LBB0_3:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r9,%r10,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdi,%r10,4), %xmm1
	addss	%xmm1, %xmm0
	movss	%xmm0, (%rcx,%r8,4)
	incq	%r10
	cmpq	%r10, %rax
	jne	.LBB0_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	incq	%r8
	addl	%eax, %esi
	cmpq	%rax, %r8
	jne	.LBB0_2
.LBB0_5:                                # %._crit_edge19
	retq
.Lfunc_end0:
	.size	_Z13CPU_AvProductv, .Lfunc_end0-_Z13CPU_AvProductv
	.cfi_endproc
                                        # -- End function
	.globl	_Z14CPU_NormalizeWv             # -- Begin function _Z14CPU_NormalizeWv
	.type	_Z14CPU_NormalizeWv,@function
_Z14CPU_NormalizeWv:                    # @_Z14CPU_NormalizeWv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	GlobalSize(%rip), %ebx
	testl	%ebx, %ebx
	jle	.LBB1_9
# %bb.1:                                # %.lr.ph
	xorps	%xmm0, %xmm0
	movq	h_VecW(%rip), %rax
	xorl	%ecx, %ecx
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	movss	(%rax,%rcx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm1
	addss	%xmm1, %xmm0
	incq	%rcx
	cmpq	%rcx, %rbx
	jne	.LBB1_2
# %bb.3:                                # %._crit_edge
	xorps	%xmm1, %xmm1
	ucomiss	%xmm1, %xmm0
	jb	.LBB1_5
# %bb.4:
	sqrtss	%xmm0, %xmm0
	jmp	.LBB1_6
.LBB1_5:                                # %call.sqrt
	callq	sqrtf
.LBB1_6:                                # %._crit_edge.split
	testl	%ebx, %ebx
	jle	.LBB1_9
# %bb.7:                                # %.lr.ph19
	movq	h_VecW(%rip), %rax
	movq	h_VecV(%rip), %rcx
	xorl	%edx, %edx
.LBB1_8:                                # =>This Inner Loop Header: Depth=1
	movss	(%rax,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	divss	%xmm0, %xmm1
	movss	%xmm1, (%rcx,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rbx
	jne	.LBB1_8
.LBB1_9:                                # %._crit_edge20
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z14CPU_NormalizeWv, .Lfunc_end1-_Z14CPU_NormalizeWv
	.cfi_endproc
                                        # -- End function
	.globl	_Z16CPU_ComputeLamdav           # -- Begin function _Z16CPU_ComputeLamdav
	.type	_Z16CPU_ComputeLamdav,@function
_Z16CPU_ComputeLamdav:                  # @_Z16CPU_ComputeLamdav
	.cfi_startproc
# %bb.0:
	movl	GlobalSize(%rip), %eax
	testl	%eax, %eax
	jle	.LBB2_1
# %bb.3:                                # %.lr.ph
	movq	h_VecV(%rip), %rcx
	xorps	%xmm0, %xmm0
	movq	h_VecW(%rip), %rdx
	xorl	%esi, %esi
.LBB2_4:                                # =>This Inner Loop Header: Depth=1
	movss	(%rcx,%rsi,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdx,%rsi,4), %xmm1
	addss	%xmm1, %xmm0
	incq	%rsi
	cmpq	%rsi, %rax
	jne	.LBB2_4
# %bb.2:                                # %._crit_edge
	retq
.LBB2_1:
	xorps	%xmm0, %xmm0
	retq
.Lfunc_end2:
	.size	_Z16CPU_ComputeLamdav, .Lfunc_end2-_Z16CPU_ComputeLamdav
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z17RunCPUPowerMethodv
.LCPI3_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI3_1:
	.long	0x36a7c5ac                      # float 4.99999987E-6
	.text
	.globl	_Z17RunCPUPowerMethodv
	.type	_Z17RunCPUPowerMethodv,@function
_Z17RunCPUPowerMethodv:                 # @_Z17RunCPUPowerMethodv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	callq	_Z13CPU_AvProductv
	cmpl	$0, max_iteration(%rip)
	jle	.LBB3_7
# %bb.1:                                # %.lr.ph.preheader
	xorps	%xmm0, %xmm0
	xorl	%ebx, %ebx
.LBB3_3:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_5 Depth 2
	movaps	%xmm0, 16(%rsp)                 # 16-byte Spill
	callq	_Z14CPU_NormalizeWv
	callq	_Z13CPU_AvProductv
	movl	GlobalSize(%rip), %eax
	xorps	%xmm1, %xmm1
	testl	%eax, %eax
	jle	.LBB3_6
# %bb.4:                                # %.lr.ph.i
                                        #   in Loop: Header=BB3_3 Depth=1
	movq	h_VecV(%rip), %rcx
	movq	h_VecW(%rip), %rdx
	xorl	%esi, %esi
.LBB3_5:                                #   Parent Loop BB3_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rcx,%rsi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	mulss	(%rdx,%rsi,4), %xmm0
	addss	%xmm0, %xmm1
	incq	%rsi
	cmpq	%rsi, %rax
	jne	.LBB3_5
.LBB3_6:                                # %_Z16CPU_ComputeLamdav.exit
                                        #   in Loop: Header=BB3_3 Depth=1
	movss	%xmm1, 12(%rsp)                 # 4-byte Spill
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.1, %edi
	movl	%ebx, %esi
	movb	$1, %al
	callq	printf
	movss	12(%rsp), %xmm2                 # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	movaps	16(%rsp), %xmm1                 # 16-byte Reload
	subss	%xmm2, %xmm1
	andps	.LCPI3_0(%rip), %xmm1
	movss	.LCPI3_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm0
	ja	.LBB3_7
# %bb.2:                                #   in Loop: Header=BB3_3 Depth=1
	incl	%ebx
	movaps	%xmm2, %xmm0
	cmpl	max_iteration(%rip), %ebx
	jl	.LBB3_3
.LBB3_7:                                # %_Z16CPU_ComputeLamdav.exit._crit_edge
	movl	$.Lstr.1, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end3:
	.size	_Z17RunCPUPowerMethodv, .Lfunc_end3-_Z17RunCPUPowerMethodv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	callq	_Z9ArgumentsiPPc
	movslq	GlobalSize(%rip), %r14
	movl	$.L.str.2, %edi
	movl	%r14d, %esi
	movl	%r14d, %edx
	xorl	%eax, %eax
	callq	printf
	leaq	(,%r14,4), %r12
	movl	%r14d, %r13d
	imull	%r13d, %r13d
	leaq	(,%r13,4), %rbx
	movl	$4, %edi
	callq	malloc
	movq	%rax, h_NormW(%rip)
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%rax, h_MatA(%rip)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rax, h_VecV(%rip)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, h_VecW(%rip)
	testq	%r14, %r14
	je	.LBB4_5
# %bb.1:                                # %.lr.ph.preheader.i
	movl	%r14d, %r14d
	cmpl	$1, %r13d
	adcl	$0, %r13d
	xorl	%r15d, %r15d
.LBB4_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$680390859, %rax, %rcx          # imm = 0x288DF0CB
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$36, %rcx
	addl	%edx, %ecx
	imull	$101, %ecx, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r13
	jne	.LBB4_2
# %bb.3:                                # %_Z11UploadArrayPfi.exit
	movq	h_VecV(%rip), %r15
	testl	%r14d, %r14d
	jle	.LBB4_5
# %bb.4:                                # %.lr.ph.preheader.i14
	shlq	$2, %r14
	movq	%r15, %rdi
	xorl	%esi, %esi
	movq	%r14, %rdx
	callq	memset@PLT
.LBB4_5:                                # %_Z7InitOnePfi.exit
	movl	$1065353216, (%r15)             # imm = 0x3F800000
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	leaq	16(%rsp), %rbx
	xorl	%edi, %edi
	movq	%rbx, %rsi
	callq	clock_gettime
	callq	_Z17RunCPUPowerMethodv
	movq	%rsp, %r14
	xorl	%edi, %edi
	movq	%r14, %rsi
	callq	clock_gettime
	movq	(%r14), %rax
	movq	8(%r14), %rcx
	subq	(%rbx), %rax
	cvtsi2sd	%rax, %xmm1
	subq	8(%rbx), %rcx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rcx, %xmm0
	mulsd	.LCPI4_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	callq	_Z7Cleanupv
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z9ArgumentsiPPc                # -- Begin function _Z9ArgumentsiPPc
	.type	_Z9ArgumentsiPPc,@function
_Z9ArgumentsiPPc:                       # @_Z9ArgumentsiPPc
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jle	.LBB5_10
# %bb.1:                                # %.lr.ph.preheader
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.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 %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	xorl	%r15d, %r15d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movslq	%r15d, %r12
	movq	(%rbx,%r12,8), %r14
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB5_4
# %bb.3:                                #   in Loop: Header=BB5_2 Depth=1
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB5_5
.LBB5_4:                                #   in Loop: Header=BB5_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %r14
	movq	%r14, %rdi
	callq	atoi
	movl	%eax, GlobalSize(%rip)
.LBB5_5:                                #   in Loop: Header=BB5_2 Depth=1
	movl	$.L.str.8, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB5_7
# %bb.6:                                #   in Loop: Header=BB5_2 Depth=1
	movl	$.L.str.9, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB5_8
.LBB5_7:                                #   in Loop: Header=BB5_2 Depth=1
	movslq	%r15d, %rax
	incl	%r15d
	movq	8(%rbx,%rax,8), %rdi
	callq	atoi
	movl	%eax, max_iteration(%rip)
.LBB5_8:                                #   in Loop: Header=BB5_2 Depth=1
	incl	%r15d
	cmpl	%ebp, %r15d
	jl	.LBB5_2
# %bb.9:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
.LBB5_10:                               # %._crit_edge
	retq
.Lfunc_end5:
	.size	_Z9ArgumentsiPPc, .Lfunc_end5-_Z9ArgumentsiPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z11UploadArrayPfi              # -- Begin function _Z11UploadArrayPfi
	.type	_Z11UploadArrayPfi,@function
_Z11UploadArrayPfi:                     # @_Z11UploadArrayPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB6_4
# %bb.1:                                # %.lr.ph.preheader
	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
	movl	%esi, %ebx
	movq	%rdi, %r14
	imull	%ebx, %ebx
	cmpl	$1, %ebx
	adcl	$0, %ebx
	xorl	%r15d, %r15d
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$680390859, %rax, %rcx          # imm = 0x288DF0CB
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$36, %rcx
	addl	%edx, %ecx
	imull	$101, %ecx, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB6_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB6_4:                                # %._crit_edge
	retq
.Lfunc_end6:
	.size	_Z11UploadArrayPfi, .Lfunc_end6-_Z11UploadArrayPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z7InitOnePfi                   # -- Begin function _Z7InitOnePfi
	.type	_Z7InitOnePfi,@function
_Z7InitOnePfi:                          # @_Z7InitOnePfi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	testl	%esi, %esi
	jle	.LBB7_2
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %edx
	shlq	$2, %rdx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB7_2:                                # %._crit_edge
	movl	$1065353216, (%rbx)             # imm = 0x3F800000
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_Z7InitOnePfi, .Lfunc_end7-_Z7InitOnePfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z7Cleanupv                     # -- Begin function _Z7Cleanupv
	.type	_Z7Cleanupv,@function
_Z7Cleanupv:                            # @_Z7Cleanupv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	h_MatA(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	callq	free
.LBB8_2:
	movq	h_VecV(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_4
# %bb.3:
	callq	free
.LBB8_4:
	movq	h_VecW(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_6
# %bb.5:
	callq	free
.LBB8_6:
	movq	h_NormW(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_8
# %bb.7:
	callq	free
.LBB8_8:
	xorl	%edi, %edi
	callq	exit
.Lfunc_end8:
	.size	_Z7Cleanupv, .Lfunc_end8-_Z7Cleanupv
	.cfi_endproc
                                        # -- End function
	.type	h_MatA,@object                  # @h_MatA
	.bss
	.globl	h_MatA
	.p2align	3, 0x0
h_MatA:
	.quad	0
	.size	h_MatA, 8

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

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

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

	.type	GlobalSize,@object              # @GlobalSize
	.data
	.globl	GlobalSize
	.p2align	2, 0x0
GlobalSize:
	.long	5000                            # 0x1388
	.size	GlobalSize, 4

	.type	max_iteration,@object           # @max_iteration
	.globl	max_iteration
	.p2align	2, 0x0
max_iteration:
	.long	100                             # 0x64
	.size	max_iteration, 4

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"CPU lamda at %d: %f \n"
	.size	.L.str.1, 22

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Matrix size %d X %d \n"
	.size	.L.str.2, 22

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"CPU: run time = %f secs.\n"
	.size	.L.str.4, 26

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"--size"
	.size	.L.str.6, 7

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"-size"
	.size	.L.str.7, 6

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"--max_iteration"
	.size	.L.str.8, 16

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"-max_iteration"
	.size	.L.str.9, 15

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr.1,@object                 # @str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr.1:
	.asciz	"*************************************"
	.size	.Lstr.1, 38

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Power method in CPU starts"
	.size	.Lstr.2, 27

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Power method in CPU is finished"
	.size	.Lstr.3, 32

	.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_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
