/*  This code implements the serial solution and CUDA version for finding the maximal burst in a time series;

    How to compile:
        nvcc compare.cu 
    How to run:
        ./a.out n k //n is the length of the time series and k is the minimum lenght of a subsequence

    Results to see:
	       The burst found by two methods are printed out: "burst start from .. end at ..; max-me is .."			
    Notes:
        The serial takes long time for a large n (e.g n=3000) 
*/

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

// kernel function
__global__ void max_each_block(float *dmaxarr, int *dmaxstart, int *dmaxend, float * darr,  int n, int k);

// max_burst calls the kernel, return three arrays, one for the maxval, one for startpoint, one for the endpoint in each block;
void max_burst(float *x, int n, int k, int *startend, float *bigmax);

//find the maximum from the returned arrays from the kernel. This function is called by max_burst
void find_max_from_blocks(float *maxarr, int *maxstart, int *maxend, int numBlock,int *startend, float *bigmax);

//serial solution
void s_max_burst(float *arr, int n, int k);
float mean(float *y, int s, int e);

int main(int argc, char **argv) {
				int n = atoi(argv[1]);
				int k = atoi(argv[2]); 
				
		 //generate a 1d array
				float *arr = (float*) malloc(n*sizeof(float));
				int i;
				for (i = n; i > 0; i--) {
							arr[n-i] = (float)(rand() % 80);			
				}

			// Cuda solution
			int startend[2];
			float bigmax;
   max_burst(arr, n,k, startend, &bigmax); 
		 // serial solution	
   s_max_burst(arr, n,k);

			return 0;
}

__global__ void max_each_block(float *dmaxarr, int *dmaxstart, int *dmaxend, float * darr, int n,int k) {
  // declare three array for the maximum found by each thread 
	 // learning material for shared memory: https://devblogs.nvidia.com/parallelforall/using-shared-memory-cuda-cc/
  extern __shared__ float sh[];
  float *mymaxvals = sh;
  int *mystartmaxes = (int *)&mymaxvals[blockDim.x];
  int *myendmaxes = (int *)&mystartmaxes[blockDim.x];

  int perstart = threadIdx.x + blockDim.x * blockIdx.x;
  int perlen, perend;
  double xbar; // a temporay variable used when computing mean of subsequence

  int i, tid = threadIdx.x;

  if (perstart <= n-k) {
    for (perlen = k ; perlen <= n - perstart ; perlen++) {
      perend = perstart + perlen - 1;
      //compute the mean of subsequence incrementally
      if (perlen ==k) {
         xbar = 0;
         for ( i = perstart; i <= perend; i++) {
           xbar += darr[i];
         }
         xbar /= (perend - perstart + 1);
         mymaxvals[tid] = xbar;
         mystartmaxes[tid] = perstart;
         myendmaxes[tid] = perend;
      } else {
        xbar = ( (perlen-1) * xbar + darr[perend] ) / perlen;
      }
      //update the mymaxvals[tid] if the next subsequence in a thread has a higher mean
      if (xbar >  mymaxvals[tid]) {
         mymaxvals[tid] = xbar;
         mystartmaxes[tid] = perstart;
         myendmaxes[tid] = perend;
      }
    }
  } else {
    mymaxvals[tid] = 0;//initialize it with the smallest number
  }
  __syncthreads(); //sync to make sure each thread in this block has done with the for loop
   // get the highest among the mymaxvals using reduce
			for (int s = blockDim.x/2; s > 0; s>>=1) {
			if (tid < s ) {
				if(mymaxvals[tid+s] > mymaxvals[tid]) {
							mymaxvals[tid] =  mymaxvals[tid+s];
							mystartmaxes[tid] = mystartmaxes[tid + s];
							myendmaxes[tid] = myendmaxes[tid + s];
				}
			}
			__syncthreads();
  }
 //put the maximum among the mymaxvals in this block to dmaxarr
 if(tid == 0) {
  dmaxarr[blockIdx.x] = mymaxvals[0];
  dmaxstart[blockIdx.x] =  mystartmaxes[0];
  dmaxend[blockIdx.x] =  myendmaxes[0];
  }
}

void max_burst(float *x, int n, int k, int *startend, float *bigmax) {
		const int numthreadsBlock = 1024;
		int numBlock = ( n + numthreadsBlock - 1)/numthreadsBlock;
		//declare arrays on cpu to store the results from the kernel
		float *maxarr = (float *)malloc(numBlock * sizeof(float));
  int *maxstart = (int *)malloc(numBlock * sizeof(int));
  int *maxend = (int *)malloc(numBlock * sizeof(int));

		// declare GPU memory pointers
		float *darr, * dmaxarr;
		int *dmaxstart, *dmaxend;
		cudaMalloc((void **)&darr, n*sizeof(float));
		cudaMalloc((void **)&dmaxarr, numBlock*sizeof(float));
		cudaMalloc((void **)&dmaxstart, numBlock*sizeof(int));
		cudaMalloc((void **)&dmaxend, numBlock*sizeof(int));

		//copy the input x to device
		cudaMemcpy(darr, x, n*sizeof(float), cudaMemcpyHostToDevice);
  // execution configuration
		dim3 dimGrid(numBlock,1);
		dim3 dimBlock(numthreadsBlock,1,1);
  //call the kernel
		max_each_block<<<dimGrid,dimBlock,(3*numthreadsBlock)*sizeof(float)>>>(dmaxarr,dmaxstart,dmaxend, darr, n, k);
		cudaThreadSynchronize();
		//copy the results from device to cpu
		cudaMemcpy(maxarr, dmaxarr, numBlock*sizeof(float), cudaMemcpyDeviceToHost);
		cudaMemcpy(maxstart, dmaxstart, numBlock*sizeof(int), cudaMemcpyDeviceToHost);
		cudaMemcpy(maxend, dmaxend, numBlock*sizeof(int), cudaMemcpyDeviceToHost);
  //free memory on device
		cudaFree(darr);
		cudaFree(dmaxarr);
		cudaFree(dmaxstart);
		cudaFree(dmaxend);

  find_max_from_blocks( maxarr, maxstart, maxend,  numBlock,startend, bigmax);
  printf("burst start from %d end at %d; max-mean is %f\n", startend[0], startend[1], *bigmax);

}

void find_max_from_blocks(float *maxarr, int *maxstart, int *maxend, int numBlock,int *startend, float *bigmax) {
	*bigmax = 0;
	for (int i = 0; i < numBlock; i++) {
   if (*bigmax < maxarr[i]) {
      *bigmax = maxarr[i];
      startend[0] = maxstart[i];
     	startend[1] = maxend[i];
			}	
 }
}

void s_max_burst(float *arr, int n, int k) {
   float mymaxval = -1; 
   int perstart, perlen,perend, mystart, myend;
   float xbar;
   for (perstart = 0; perstart <= n-k; perstart++) {
     for (perlen = k; perlen <= n - perstart; perlen++) {
        perend = perstart + perlen -1; 
        xbar = mean(arr, perstart, perend);
     if (xbar > mymaxval) {
        mymaxval = xbar;
        mystart = perstart;
        myend = perend;
     }   
     }   
   }   
   printf("\nburst start from %d end %d, max-mean is %f\n", mystart, myend,mymaxval);
}

float mean(float *y, int s, int e){ 
  int i;  
  float tot =0; 
  for (i=s; i<=e; i++) tot += y[i];
  return tot / (e -s + 1); 
}

	.file	"tmpxft_00337c41_00000000-6_compare.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z20find_max_from_blocksPfPiS0_iS0_S_
	.type	_Z20find_max_from_blocksPfPiS0_iS0_S_, @function
_Z20find_max_from_blocksPfPiS0_iS0_S_:
.LFB2029:
	.cfi_startproc
	endbr64
	movl	$0x00000000, (%r9)
	xorl	%eax, %eax
.L3:
	cmpl	%eax, %ecx
	jle	.L9
	movss	(%rdi,%rax,4), %xmm0
	comiss	(%r9), %xmm0
	jbe	.L4
	movl	(%rsi,%rax,4), %r10d
	movss	%xmm0, (%r9)
	movl	%r10d, (%r8)
	movl	(%rdx,%rax,4), %r10d
	movl	%r10d, 4(%r8)
.L4:
	incq	%rax
	jmp	.L3
.L9:
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z20find_max_from_blocksPfPiS0_iS0_S_, .-_Z20find_max_from_blocksPfPiS0_iS0_S_
	.globl	_Z4meanPfii
	.type	_Z4meanPfii, @function
_Z4meanPfii:
.LFB2031:
	.cfi_startproc
	endbr64
	movslq	%esi, %rax
	xorps	%xmm0, %xmm0
.L11:
	cmpl	%eax, %edx
	jl	.L13
	addss	(%rdi,%rax,4), %xmm0
	incq	%rax
	jmp	.L11
.L13:
	subl	%esi, %edx
	incl	%edx
	cvtsi2ssl	%edx, %xmm1
	divss	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z4meanPfii, .-_Z4meanPfii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"\nburst start from %d end %d, max-mean is %f\n"
	.text
	.globl	_Z11s_max_burstPfii
	.type	_Z11s_max_burstPfii, @function
_Z11s_max_burstPfii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%esi, %r8d
	movl	%edx, %r10d
	xorl	%ecx, %ecx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	subl	%edx, %r12d
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%r9
	.cfi_def_cfa_offset 48
	movss	.LC1(%rip), %xmm2
.L15:
	cmpl	%ecx, %r12d
	jl	.L18
	movl	%r8d, %ebp
	leal	(%r10,%rcx), %r9d
	subl	%ecx, %ebp
.L19:
	movl	%r9d, %eax
	subl	%ecx, %eax
	cmpl	%ebp, %eax
	jg	.L22
	leal	-1(%r9), %r13d
	movl	%ecx, %esi
	movl	%r13d, %edx
	call	_Z4meanPfii
	comiss	%xmm2, %xmm0
	ja	.L20
	movl	%r11d, %r13d
	movaps	%xmm2, %xmm0
	jmp	.L16
.L20:
	movl	%ecx, %ebx
.L16:
	incl	%r9d
	movl	%r13d, %r11d
	movaps	%xmm0, %xmm2
	jmp	.L19
.L22:
	incl	%ecx
	jmp	.L15
.L18:
	popq	%r8
	.cfi_def_cfa_offset 40
	movl	%ebx, %edx
	movl	%r11d, %ecx
	popq	%rbx
	.cfi_def_cfa_offset 32
	leaq	.LC2(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 24
	movl	$2, %edi
	popq	%r12
	.cfi_def_cfa_offset 16
	movb	$1, %al
	popq	%r13
	.cfi_def_cfa_offset 8
	cvtss2sd	%xmm2, %xmm0
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z11s_max_burstPfii, .-_Z11s_max_burstPfii
	.globl	_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii
	.type	_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii, @function
_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movl	%r9d, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z14max_each_blockPfPiS0_S_ii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L23:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii, .-_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii
	.globl	_Z14max_each_blockPfPiS0_S_ii
	.type	_Z14max_each_blockPfPiS0_S_ii, @function
_Z14max_each_blockPfPiS0_S_ii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii
	.cfi_endproc
.LFE2057:
	.size	_Z14max_each_blockPfPiS0_S_ii, .-_Z14max_each_blockPfPiS0_S_ii
	.section	.rodata.str1.1
.LC3:
	.string	"burst start from %d end at %d; max-mean is %f\n"
	.text
	.globl	_Z9max_burstPfiiPiS_
	.type	_Z9max_burstPfiiPiS_, @function
_Z9max_burstPfiiPiS_:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r8, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rcx, %rbp
	movl	$1024, %ecx
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leal	1023(%rsi), %eax
	cltd
	idivl	%ecx
	cltq
	movq	%rax, %rbx
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movslq	%r12d, %rdx
	leaq	48(%rsp), %rdi
	salq	$2, %rdx
	movq	%rax, 32(%rsp)
	movq	%rdx, %rsi
	movq	%rdx, 40(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdx
	movq	48(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, 80(%rsp)
	movl	$4194305, %edx
	movabsq	$4294967297, %rax
	movq	%rax, 84(%rsp)
	movq	80(%rsp), %rdi
	xorl	%r9d, %r9d
	salq	$10, %rdx
	movl	88(%rsp), %esi
	movl	$12288, %r8d
	movl	$1, %ecx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	movq	48(%rsp), %rcx
	movq	72(%rsp), %rdx
	movl	%r14d, %r9d
	movl	%r12d, %r8d
	movq	64(%rsp), %rsi
	movq	56(%rsp), %rdi
	call	_Z43__device_stub__Z14max_each_blockPfPiS0_S_iiPfPiS0_S_ii
.L29:
	call	cudaThreadSynchronize@PLT
	movq	8(%rsp), %rdx
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	16(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movq	24(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movq	32(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdx
	movl	%ebx, %ecx
	movq	%r13, %r9
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movq	%rbp, %r8
	call	_Z20find_max_from_blocksPfPiS0_iS0_S_
	movl	4(%rbp), %ecx
	movl	0(%rbp), %edx
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	movb	$1, %al
	cvtss2sd	0(%r13), %xmm0
	call	__printf_chk@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9max_burstPfiiPiS_, .-_Z9max_burstPfiiPiS_
	.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
	movl	$80, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movslq	%eax, %r13
	call	atoi@PLT
	leaq	0(,%r13,4), %rdi
	movq	%r13, %rbp
	movl	%eax, %r12d
	call	malloc@PLT
	movq	%rax, %rbx
	movq	%rax, %r14
.L33:
	testl	%r13d, %r13d
	jle	.L37
	call	rand@PLT
	decq	%r13
	addq	$4, %r14
	cltd
	idivl	%r15d
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -4(%r14)
	jmp	.L33
.L37:
	movl	%r12d, %edx
	movl	%ebp, %esi
	leaq	16(%rsp), %rcx
	movq	%rbx, %rdi
	leaq	12(%rsp), %r8
	call	_Z9max_burstPfiiPiS_
	movl	%r12d, %edx
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_Z11s_max_burstPfii
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$40, %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
.LC4:
	.string	"_Z14max_each_blockPfPiS0_S_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC4(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14max_each_blockPfPiS0_S_ii(%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
.LFE2059:
	.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	-1082130432
	.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:

/*  This code implements the serial solution and CUDA version for finding the maximal burst in a time series;

    How to compile:
        nvcc compare.cu 
    How to run:
        ./a.out n k //n is the length of the time series and k is the minimum lenght of a subsequence

    Results to see:
	       The burst found by two methods are printed out: "burst start from .. end at ..; max-me is .."			
    Notes:
        The serial takes long time for a large n (e.g n=3000) 
*/

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

// kernel function
__global__ void max_each_block(float *dmaxarr, int *dmaxstart, int *dmaxend, float * darr,  int n, int k);

// max_burst calls the kernel, return three arrays, one for the maxval, one for startpoint, one for the endpoint in each block;
void max_burst(float *x, int n, int k, int *startend, float *bigmax);

//find the maximum from the returned arrays from the kernel. This function is called by max_burst
void find_max_from_blocks(float *maxarr, int *maxstart, int *maxend, int numBlock,int *startend, float *bigmax);

//serial solution
void s_max_burst(float *arr, int n, int k);
float mean(float *y, int s, int e);

int main(int argc, char **argv) {
				int n = atoi(argv[1]);
				int k = atoi(argv[2]); 
				
		 //generate a 1d array
				float *arr = (float*) malloc(n*sizeof(float));
				int i;
				for (i = n; i > 0; i--) {
							arr[n-i] = (float)(rand() % 80);			
				}

			// Cuda solution
			int startend[2];
			float bigmax;
   max_burst(arr, n,k, startend, &bigmax); 
		 // serial solution	
   s_max_burst(arr, n,k);

			return 0;
}

__global__ void max_each_block(float *dmaxarr, int *dmaxstart, int *dmaxend, float * darr, int n,int k) {
  // declare three array for the maximum found by each thread 
	 // learning material for shared memory: https://devblogs.nvidia.com/parallelforall/using-shared-memory-cuda-cc/
  extern __shared__ float sh[];
  float *mymaxvals = sh;
  int *mystartmaxes = (int *)&mymaxvals[blockDim.x];
  int *myendmaxes = (int *)&mystartmaxes[blockDim.x];

  int perstart = threadIdx.x + blockDim.x * blockIdx.x;
  int perlen, perend;
  double xbar; // a temporay variable used when computing mean of subsequence

  int i, tid = threadIdx.x;

  if (perstart <= n-k) {
    for (perlen = k ; perlen <= n - perstart ; perlen++) {
      perend = perstart + perlen - 1;
      //compute the mean of subsequence incrementally
      if (perlen ==k) {
         xbar = 0;
         for ( i = perstart; i <= perend; i++) {
           xbar += darr[i];
         }
         xbar /= (perend - perstart + 1);
         mymaxvals[tid] = xbar;
         mystartmaxes[tid] = perstart;
         myendmaxes[tid] = perend;
      } else {
        xbar = ( (perlen-1) * xbar + darr[perend] ) / perlen;
      }
      //update the mymaxvals[tid] if the next subsequence in a thread has a higher mean
      if (xbar >  mymaxvals[tid]) {
         mymaxvals[tid] = xbar;
         mystartmaxes[tid] = perstart;
         myendmaxes[tid] = perend;
      }
    }
  } else {
    mymaxvals[tid] = 0;//initialize it with the smallest number
  }
  __syncthreads(); //sync to make sure each thread in this block has done with the for loop
   // get the highest among the mymaxvals using reduce
			for (int s = blockDim.x/2; s > 0; s>>=1) {
			if (tid < s ) {
				if(mymaxvals[tid+s] > mymaxvals[tid]) {
							mymaxvals[tid] =  mymaxvals[tid+s];
							mystartmaxes[tid] = mystartmaxes[tid + s];
							myendmaxes[tid] = myendmaxes[tid + s];
				}
			}
			__syncthreads();
  }
 //put the maximum among the mymaxvals in this block to dmaxarr
 if(tid == 0) {
  dmaxarr[blockIdx.x] = mymaxvals[0];
  dmaxstart[blockIdx.x] =  mystartmaxes[0];
  dmaxend[blockIdx.x] =  myendmaxes[0];
  }
}

void max_burst(float *x, int n, int k, int *startend, float *bigmax) {
		const int numthreadsBlock = 1024;
		int numBlock = ( n + numthreadsBlock - 1)/numthreadsBlock;
		//declare arrays on cpu to store the results from the kernel
		float *maxarr = (float *)malloc(numBlock * sizeof(float));
  int *maxstart = (int *)malloc(numBlock * sizeof(int));
  int *maxend = (int *)malloc(numBlock * sizeof(int));

		// declare GPU memory pointers
		float *darr, * dmaxarr;
		int *dmaxstart, *dmaxend;
		hipMalloc((void **)&darr, n*sizeof(float));
		hipMalloc((void **)&dmaxarr, numBlock*sizeof(float));
		hipMalloc((void **)&dmaxstart, numBlock*sizeof(int));
		hipMalloc((void **)&dmaxend, numBlock*sizeof(int));

		//copy the input x to device
		hipMemcpy(darr, x, n*sizeof(float), hipMemcpyHostToDevice);
  // execution configuration
		dim3 dimGrid(numBlock,1);
		dim3 dimBlock(numthreadsBlock,1,1);
  //call the kernel
		max_each_block<<<dimGrid,dimBlock,(3*numthreadsBlock)*sizeof(float)>>>(dmaxarr,dmaxstart,dmaxend, darr, n, k);
		hipDeviceSynchronize();
		//copy the results from device to cpu
		hipMemcpy(maxarr, dmaxarr, numBlock*sizeof(float), hipMemcpyDeviceToHost);
		hipMemcpy(maxstart, dmaxstart, numBlock*sizeof(int), hipMemcpyDeviceToHost);
		hipMemcpy(maxend, dmaxend, numBlock*sizeof(int), hipMemcpyDeviceToHost);
  //free memory on device
		hipFree(darr);
		hipFree(dmaxarr);
		hipFree(dmaxstart);
		hipFree(dmaxend);

  find_max_from_blocks( maxarr, maxstart, maxend,  numBlock,startend, bigmax);
  printf("burst start from %d end at %d; max-mean is %f\n", startend[0], startend[1], *bigmax);

}

void find_max_from_blocks(float *maxarr, int *maxstart, int *maxend, int numBlock,int *startend, float *bigmax) {
	*bigmax = 0;
	for (int i = 0; i < numBlock; i++) {
   if (*bigmax < maxarr[i]) {
      *bigmax = maxarr[i];
      startend[0] = maxstart[i];
     	startend[1] = maxend[i];
			}	
 }
}

void s_max_burst(float *arr, int n, int k) {
   float mymaxval = -1; 
   int perstart, perlen,perend, mystart, myend;
   float xbar;
   for (perstart = 0; perstart <= n-k; perstart++) {
     for (perlen = k; perlen <= n - perstart; perlen++) {
        perend = perstart + perlen -1; 
        xbar = mean(arr, perstart, perend);
     if (xbar > mymaxval) {
        mymaxval = xbar;
        mystart = perstart;
        myend = perend;
     }   
     }   
   }   
   printf("\nburst start from %d end %d, max-mean is %f\n", mystart, myend,mymaxval);
}

float mean(float *y, int s, int e){ 
  int i;  
  float tot =0; 
  for (i=s; i<=e; i++) tot += y[i];
  return tot / (e -s + 1); 
}

	.text
	.file	"compare.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movslq	%ebx, %r15
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%r15d, %r15d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	incq	%r15
	movq	%r14, %r12
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	shll	$4, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r12)
	decq	%r15
	addq	$4, %r12
	cmpq	$1, %r15
	jg	.LBB0_2
.LBB0_3:                                # %._crit_edge
	leaq	8(%rsp), %rcx
	leaq	4(%rsp), %r8
	movq	%r14, %rdi
	movl	%ebx, %esi
	movl	%ebp, %edx
	callq	_Z9max_burstPfiiPiS_
	movq	%r14, %rdi
	movl	%ebx, %esi
	movl	%ebp, %edx
	callq	_Z11s_max_burstPfii
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	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
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z9max_burstPfiiPiS_            # -- Begin function _Z9max_burstPfiiPiS_
	.type	_Z9max_burstPfiiPiS_,@function
_Z9max_burstPfiiPiS_:                   # @_Z9max_burstPfiiPiS_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%r8, 64(%rsp)                   # 8-byte Spill
	movq	%rcx, %rbx
	movl	%edx, 36(%rsp)                  # 4-byte Spill
	movl	%esi, %r14d
	movq	%r14, 40(%rsp)                  # 8-byte Spill
	leal	1023(%r14), %eax
	leal	2046(%r14), %r12d
	testl	%eax, %eax
	cmovnsl	%eax, %r12d
	movq	%rdi, 48(%rsp)                  # 8-byte Spill
	sarl	$10, %r12d
	movslq	%r12d, %rbp
	shlq	$2, %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r13
	movslq	%r14d, %r14
	shlq	$2, %r14
	leaq	24(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$12288, %r8d                    # imm = 0x3000
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movq	24(%rsp), %rcx
	movq	40(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	movl	36(%rsp), %r9d                  # 4-byte Reload
	callq	_Z29__device_stub__max_each_blockPfPiS0_S_ii
.LBB1_2:
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rsi
	movq	%r15, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rsi
	movq	56(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rsi
	movq	%r13, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdx                  # 8-byte Reload
	movl	$0, (%rdx)
	cmpl	$0, 40(%rsp)                    # 4-byte Folded Reload
	jle	.LBB1_3
# %bb.4:                                # %.lr.ph.i
	xorps	%xmm0, %xmm0
	xorl	%eax, %eax
.LBB1_5:                                # =>This Inner Loop Header: Depth=1
	movss	(%r15,%rax,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jbe	.LBB1_7
# %bb.6:                                #   in Loop: Header=BB1_5 Depth=1
	movss	%xmm1, (%rdx)
	movl	(%r14,%rax,4), %ecx
	movl	%ecx, (%rbx)
	movl	(%r13,%rax,4), %ecx
	movl	%ecx, 4(%rbx)
	movaps	%xmm1, %xmm0
.LBB1_7:                                #   in Loop: Header=BB1_5 Depth=1
	incq	%rax
	cmpq	%rax, %r12
	jne	.LBB1_5
# %bb.8:                                # %_Z20find_max_from_blocksPfPiS0_iS0_S_.exit.loopexit
	cvtss2sd	%xmm0, %xmm0
	jmp	.LBB1_9
.LBB1_3:
	xorps	%xmm0, %xmm0
.LBB1_9:                                # %_Z20find_max_from_blocksPfPiS0_iS0_S_.exit
	movl	(%rbx), %esi
	movl	4(%rbx), %edx
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z9max_burstPfiiPiS_, .Lfunc_end1-_Z9max_burstPfiiPiS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z11s_max_burstPfii
.LCPI2_0:
	.long	0xbf800000                      # float -1
	.text
	.globl	_Z11s_max_burstPfii
	.type	_Z11s_max_burstPfii,@function
_Z11s_max_burstPfii:                    # @_Z11s_max_burstPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movslq	%esi, %rcx
	incl	%esi
	movslq	%edx, %rax
	movl	%esi, %r8d
	subl	%eax, %r8d
	subq	%rax, %rcx
	movl	%eax, %r9d
	movss	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	xorl	%r10d, %r10d
                                        # implicit-def: $edx
                                        # implicit-def: $eax
.LBB2_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
                                        #       Child Loop BB2_5 Depth 3
	cmpq	%rcx, %r10
	jg	.LBB2_7
# %bb.2:                                # %.lr.ph
                                        #   in Loop: Header=BB2_1 Depth=1
	movq	%r9, %r11
	movaps	%xmm0, %xmm1
.LBB2_3:                                #   Parent Loop BB2_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_5 Depth 3
	xorps	%xmm0, %xmm0
	testl	%r11d, %r11d
	jle	.LBB2_6
# %bb.4:                                # %.lr.ph.i.preheader
                                        #   in Loop: Header=BB2_3 Depth=2
	xorl	%ebx, %ebx
.LBB2_5:                                # %.lr.ph.i
                                        #   Parent Loop BB2_1 Depth=1
                                        #     Parent Loop BB2_3 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	addss	(%rdi,%rbx,4), %xmm0
	incq	%rbx
	cmpl	%ebx, %r11d
	jne	.LBB2_5
.LBB2_6:                                # %_Z4meanPfii.exit
                                        #   in Loop: Header=BB2_3 Depth=2
	xorps	%xmm2, %xmm2
	cvtsi2ss	%r11d, %xmm2
	divss	%xmm2, %xmm0
	ucomiss	%xmm1, %xmm0
	cmoval	%r10d, %eax
	leal	-1(%r11,%r10), %ebx
	cmoval	%ebx, %edx
	maxss	%xmm1, %xmm0
	incq	%r11
	movaps	%xmm0, %xmm1
	cmpl	%esi, %r11d
	jne	.LBB2_3
.LBB2_7:                                # %._crit_edge
                                        #   in Loop: Header=BB2_1 Depth=1
	incq	%r10
	decl	%esi
	addq	$4, %rdi
	cmpq	%r8, %r10
	jne	.LBB2_1
# %bb.8:                                # %._crit_edge43
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.1, %edi
	movl	%eax, %esi
	movb	$1, %al
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end2:
	.size	_Z11s_max_burstPfii, .Lfunc_end2-_Z11s_max_burstPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__max_each_blockPfPiS0_S_ii # -- Begin function _Z29__device_stub__max_each_blockPfPiS0_S_ii
	.type	_Z29__device_stub__max_each_blockPfPiS0_S_ii,@function
_Z29__device_stub__max_each_blockPfPiS0_S_ii: # @_Z29__device_stub__max_each_blockPfPiS0_S_ii
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	8(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z14max_each_blockPfPiS0_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end3:
	.size	_Z29__device_stub__max_each_blockPfPiS0_S_ii, .Lfunc_end3-_Z29__device_stub__max_each_blockPfPiS0_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z20find_max_from_blocksPfPiS0_iS0_S_ # -- Begin function _Z20find_max_from_blocksPfPiS0_iS0_S_
	.type	_Z20find_max_from_blocksPfPiS0_iS0_S_,@function
_Z20find_max_from_blocksPfPiS0_iS0_S_:  # @_Z20find_max_from_blocksPfPiS0_iS0_S_
	.cfi_startproc
# %bb.0:
	movl	$0, (%r9)
	testl	%ecx, %ecx
	jle	.LBB4_5
# %bb.1:                                # %.lr.ph
	movl	%ecx, %eax
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rcx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jbe	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	movss	%xmm1, (%r9)
	movl	(%rsi,%rcx,4), %r10d
	movl	%r10d, (%r8)
	movl	(%rdx,%rcx,4), %r10d
	movl	%r10d, 4(%r8)
	movaps	%xmm1, %xmm0
.LBB4_4:                                #   in Loop: Header=BB4_2 Depth=1
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB4_2
.LBB4_5:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z20find_max_from_blocksPfPiS0_iS0_S_, .Lfunc_end4-_Z20find_max_from_blocksPfPiS0_iS0_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z4meanPfii                     # -- Begin function _Z4meanPfii
	.type	_Z4meanPfii,@function
_Z4meanPfii:                            # @_Z4meanPfii
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	xorps	%xmm0, %xmm0
	subl	%esi, %edx
	jl	.LBB5_3
# %bb.1:                                # %.lr.ph.preheader
	movslq	%esi, %rax
	leaq	(%rdi,%rax,4), %rax
	leal	1(%rdx), %ecx
	xorl	%esi, %esi
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rax,%rsi,4), %xmm0
	incq	%rsi
	cmpl	%esi, %ecx
	jne	.LBB5_2
.LBB5_3:                                # %._crit_edge
	incl	%edx
	cvtsi2ss	%edx, %xmm1
	divss	%xmm1, %xmm0
	retq
.Lfunc_end5:
	.size	_Z4meanPfii, .Lfunc_end5-_Z4meanPfii
	.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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14max_each_blockPfPiS0_S_ii, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14max_each_blockPfPiS0_S_ii,@object # @_Z14max_each_blockPfPiS0_S_ii
	.section	.rodata,"a",@progbits
	.globl	_Z14max_each_blockPfPiS0_S_ii
	.p2align	3, 0x0
_Z14max_each_blockPfPiS0_S_ii:
	.quad	_Z29__device_stub__max_each_blockPfPiS0_S_ii
	.size	_Z14max_each_blockPfPiS0_S_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"burst start from %d end at %d; max-mean is %f\n"
	.size	.L.str, 47

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\nburst start from %d end %d, max-mean is %f\n"
	.size	.L.str.1, 45

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14max_each_blockPfPiS0_S_ii"
	.size	.L__unnamed_1, 30

	.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__max_each_blockPfPiS0_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14max_each_blockPfPiS0_S_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14max_each_blockPfPiS0_S_ii ; -- Begin function _Z14max_each_blockPfPiS0_S_ii
	.globl	_Z14max_each_blockPfPiS0_S_ii
	.p2align	8
	.type	_Z14max_each_blockPfPiS0_S_ii,@function
_Z14max_each_blockPfPiS0_S_ii:          ; @_Z14max_each_blockPfPiS0_S_ii
; %bb.0:
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x34
	s_load_b64 s[12:13], s[0:1], 0x20
	s_load_b256 s[4:11], s[0:1], 0x0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s14, s3, 0xffff
	s_sub_i32 s0, s12, s13
	v_mad_u64_u32 v[1:2], null, s2, s14, v[0:1]
	s_lshl_b32 s1, s14, 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s3, s1, 0
	s_add_i32 s1, s3, s1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ge_i32_e32 vcc_lo, s0, v1
	s_and_saveexec_b32 s0, vcc_lo
	s_xor_b32 s15, exec_lo, s0
	s_cbranch_execz .LBB0_16
; %bb.1:                                ; %.preheader96
	v_sub_nc_u32_e32 v12, s12, v1
	s_mov_b32 s12, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_le_i32_e64 s13, v12
	s_cbranch_execz .LBB0_15
; %bb.2:                                ; %.lr.ph103
	v_cvt_f64_i32_e32 v[3:4], s13
	v_lshlrev_b32_e32 v7, 2, v0
	v_ashrrev_i32_e32 v2, 31, v1
	s_cmp_gt_i32 s13, 0
	s_mov_b32 s16, 0
	s_cselect_b32 s17, -1, 0
	v_add_nc_u32_e32 v13, 0, v7
	v_lshlrev_b64 v[5:6], 2, v[1:2]
	v_add_nc_u32_e32 v2, s3, v7
	v_add_nc_u32_e32 v14, s1, v7
	s_mov_b32 s18, s13
	ds_load_b32 v11, v13
                                        ; implicit-def: $vgpr9_vgpr10
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	s_add_u32 s10, s10, -4
	s_addc_u32 s11, s11, -1
.LBB0_3:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_9 Depth 2
	v_add_nc_u32_e32 v7, s18, v1
	s_cmp_lg_u32 s18, s13
	s_cbranch_scc0 .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v8, 31, v7
	s_add_i32 s0, s18, -1
	v_cvt_f64_i32_e32 v[19:20], s18
	v_lshlrev_b64 v[15:16], 2, v[7:8]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v15, vcc_lo, s10, v15
	v_add_co_ci_u32_e32 v16, vcc_lo, s11, v16, vcc_lo
	global_load_b32 v8, v[15:16], off
	v_cvt_f64_i32_e32 v[15:16], s0
	s_mov_b32 s0, 0
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[17:18], v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], v[9:10], v[15:16], v[17:18]
	v_div_scale_f64 v[15:16], null, v[19:20], v[19:20], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[17:18], v[15:16]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[21:22], -v[15:16], v[17:18], 1.0
	v_fma_f64 v[17:18], v[17:18], v[21:22], v[17:18]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[21:22], -v[15:16], v[17:18], 1.0
	v_fma_f64 v[17:18], v[17:18], v[21:22], v[17:18]
	v_div_scale_f64 v[21:22], vcc_lo, v[8:9], v[19:20], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[23:24], v[21:22], v[17:18]
	v_fma_f64 v[15:16], -v[15:16], v[23:24], v[21:22]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[15:16], v[15:16], v[17:18], v[23:24]
	v_div_fixup_f64 v[9:10], v[15:16], v[19:20], v[8:9]
	s_branch .LBB0_6
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=1
	s_mov_b32 s0, -1
                                        ; implicit-def: $vgpr9_vgpr10
                                        ; implicit-def: $vgpr11
.LBB0_6:                                ; %Flow132
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v15, -1, v7
	s_and_not1_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccnz .LBB0_12
; %bb.7:                                ; %.preheader
                                        ;   in Loop: Header=BB0_3 Depth=1
	v_mov_b32_e32 v8, 0
	v_mov_b32_e32 v9, 0
	s_and_not1_b32 vcc_lo, exec_lo, s17
	s_cbranch_vccnz .LBB0_11
; %bb.8:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v11, v6 :: v_dual_mov_b32 v10, v5
	v_mov_b32_e32 v16, v1
	s_mov_b32 s19, 0
.LBB0_9:                                ; %.lr.ph
                                        ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b32 v17, v[10:11], off
	v_add_nc_u32_e32 v16, 1, v16
	v_add_co_u32 v10, s0, v10, 4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v11, s0, 0, v11, s0
	v_cmp_ge_i32_e32 vcc_lo, v16, v7
	s_or_b32 s19, vcc_lo, s19
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[17:18], v17
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[8:9], v[8:9], v[17:18]
	s_and_not1_b32 exec_lo, exec_lo, s19
	s_cbranch_execnz .LBB0_9
; %bb.10:                               ; %Flow130
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
.LBB0_11:                               ; %._crit_edge
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f64 v[10:11], null, v[3:4], v[3:4], v[8:9]
	v_div_scale_f64 v[20:21], vcc_lo, v[8:9], v[3:4], v[8:9]
	v_rcp_f64_e32 v[16:17], v[10:11]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[18:19], -v[10:11], v[16:17], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[16:17], v[16:17], v[18:19], v[16:17]
	v_fma_f64 v[18:19], -v[10:11], v[16:17], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[16:17], v[16:17], v[18:19], v[16:17]
	v_mul_f64 v[18:19], v[20:21], v[16:17]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[10:11], -v[10:11], v[18:19], v[20:21]
	v_div_fmas_f64 v[10:11], v[10:11], v[16:17], v[18:19]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[9:10], v[10:11], v[3:4], v[8:9]
	v_cvt_f32_f64_e32 v11, v[9:10]
	ds_store_b32 v13, v11
	ds_store_b32 v2, v1
	ds_store_b32 v14, v15
.LBB0_12:                               ;   in Loop: Header=BB0_3 Depth=1
	s_waitcnt lgkmcnt(0)
	v_cvt_f64_f32_e32 v[7:8], v11
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_f64_e32 v[9:10], v[7:8]
	s_cbranch_execz .LBB0_14
; %bb.13:                               ;   in Loop: Header=BB0_3 Depth=1
	v_cvt_f32_f64_e32 v11, v[9:10]
	ds_store_b32 v13, v11
	ds_store_b32 v2, v1
	ds_store_b32 v14, v15
.LBB0_14:                               ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_cmp_ge_i32_e32 vcc_lo, s18, v12
	s_add_i32 s18, s18, 1
	s_or_b32 s16, vcc_lo, s16
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s16
	s_cbranch_execnz .LBB0_3
.LBB0_15:                               ; %Flow135
	s_or_b32 exec_lo, exec_lo, s12
.LBB0_16:                               ; %Flow136
	s_and_not1_saveexec_b32 s0, s15
	s_cbranch_execz .LBB0_18
; %bb.17:
	v_lshl_add_u32 v1, v0, 2, 0
	v_mov_b32_e32 v2, 0
	ds_store_b32 v1, v2
.LBB0_18:                               ; %.loopexit
	s_or_b32 exec_lo, exec_lo, s0
	s_cmp_lt_u32 s14, 2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_24
; %bb.19:                               ; %.lr.ph108
	v_lshlrev_b32_e32 v3, 2, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v1, 0, v3
	v_add_nc_u32_e32 v2, s3, v3
	v_add_nc_u32_e32 v3, s1, v3
.LBB0_20:                               ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s0, s14
	s_lshr_b32 s14, s14, 1
	s_mov_b32 s10, exec_lo
	v_cmpx_gt_u32_e64 s14, v0
	s_cbranch_execz .LBB0_23
; %bb.21:                               ;   in Loop: Header=BB0_20 Depth=1
	v_lshl_add_u32 v4, s14, 2, v1
	ds_load_b32 v4, v4
	ds_load_b32 v5, v1
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_f32_e32 vcc_lo, v4, v5
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_23
; %bb.22:                               ;   in Loop: Header=BB0_20 Depth=1
	s_lshl_b32 s11, s14, 2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v5, s11, v2
	v_add_nc_u32_e32 v6, s11, v3
	ds_load_b32 v5, v5
	s_waitcnt lgkmcnt(0)
	ds_store_b32 v2, v5
	ds_load_b32 v5, v6
	ds_store_b32 v1, v4
	s_waitcnt lgkmcnt(1)
	ds_store_b32 v3, v5
.LBB0_23:                               ;   in Loop: Header=BB0_20 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_cmp_lt_u32 s0, 4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_20
.LBB0_24:                               ; %._crit_edge109
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_26
; %bb.25:
	v_dual_mov_b32 v0, 0 :: v_dual_mov_b32 v1, s3
	v_mov_b32_e32 v2, s1
	s_mov_b32 s3, 0
	ds_load_b32 v3, v0
	ds_load_b32 v1, v1
	ds_load_b32 v2, v2
	s_lshl_b64 s[0:1], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s2, s4, s0
	s_addc_u32 s3, s5, s1
	s_add_u32 s4, s6, s0
	s_addc_u32 s5, s7, s1
	s_add_u32 s0, s8, s0
	s_addc_u32 s1, s9, s1
	s_waitcnt lgkmcnt(2)
	global_store_b32 v0, v3, s[2:3]
	s_waitcnt lgkmcnt(1)
	global_store_b32 v0, v1, s[4:5]
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v2, s[0:1]
.LBB0_26:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14max_each_blockPfPiS0_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 25
		.amdhsa_next_free_sgpr 20
		.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	_Z14max_each_blockPfPiS0_S_ii, .Lfunc_end0-_Z14max_each_blockPfPiS0_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1104
; NumSgprs: 22
; NumVgprs: 25
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 25
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         160
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14max_each_blockPfPiS0_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z14max_each_blockPfPiS0_S_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     25
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
