////////////////////////////////////////////////////////////////////////////////
//                             CUDA LATTICE RELAXATION
//                           WRITTEN BY: CLAYTON RAYMENT
//
//    I wrote this program to help teach myself CUDA. While MATLAB and OCTAVE
//    are multithreaded applications, this program runs the majority of the
//    calculation directly on the GPU, which has the capability of being much
//    parallel than a standard CPU multithreaded application. Since I haven't
//    learned how to manage threads very well, the application is currently
//    running close to its memory limit. However, with a better implimentation
//    of thread handling, I would be able to utilize all 1664 CUDA cores on my 
//    GTX 970. Currently I only use blocks, which reduces that significantly.
//    The program is fully scalable, as the user can select how many divisions
//    each centimeter is split up into using the U global variable. Large values
//    of U however, exceed the maximum memory of the card due to my poor thread
//    management.
//
//////////////////////////////////////////////////////////////////////////////////
#include <time.h>
#include <iostream>
//===========
//GLOBALS:
//===========

//--------------
// VARIABLES
//--------------
const int U = 200; //Number of blocks per unit. This allows the grid spacing to be user defined.
const int H = 11*U; //Height of the outer box
const int W = 12*U; //Width of the outer box
const int h = 3*U; //Height of the inner box
const int w = 4*U; //Width of the inner box
const int N = H*W; //Number of threads required


//--------------
// FUNCTIONS
//--------------

//CUDA FUNCTIONS:

//Form the base simulation area:
__global__ void fill(double *a){
  //Form the outer rectangle:
  if(blockIdx.x < W || blockIdx.x > (N-W) || blockIdx.x % W == 0 || (blockIdx.x-(W-1))%W == 0){
    a[blockIdx.x] = 9;
  }
  else{
    a[blockIdx.x] = 1;
  }
  //Form the inner rectangle:
  if(blockIdx.x > W*((H-h)/2) && blockIdx.x < W*((H-h)/2+h) && blockIdx.x % W+1 > (W-w)/2 && blockIdx.x % W < (W-w)/2+w){
    a[blockIdx.x] = 0;
  }
}

//Perform one iteration of the matrix relaxation:
__global__ void average(double *a, double *b){
  //if we are at one of the edges, do nothing:
  if(a[blockIdx.x] == 0 || a[blockIdx.x] == 9){
    b[blockIdx.x] = a[blockIdx.x];
  }
  else{
    b[blockIdx.x] = (a[blockIdx.x]+a[blockIdx.x + 1]+a[blockIdx.x - 1]+a[blockIdx.x - W]+a[blockIdx.x + W])/5.0;
  }
}

//SERIAL FUNCTIONS:
void fillSerial(double *a){
    for(int i = 0; i < N; ++i){
        if(i < W || i > (N-W) || i%W == 0 || (i - (W-1))%W == 0){
            a[i] = 9;
        }
        else{
            a[i] = 4.5;
        }
        if( i > W*((H-h)/2) && i < W*((H-h)/2+h) && i % W+1 > (W-w)/2 && i % W < (W-w)/2+w){
            a[i] = 0;
        }
    }
}


void averageSerial(double* a, double* b){
    for(int i = 0; i < N; ++i){
        if(a[i] == 0 || a[i] == 9){
            b[i] = a[i];
        }
        else{
            b[i] = (a[i]+a[i+1]+a[i-1]+a[i+W]+a[i-W])/5.0;
        }
    }
}


//-----------------
//HELPER FUNCTIONS
//-----------------

//Quick function to print out the grid:
void print(double* a){
  for(int i = 0; i < N; ++i){
    if(i%W == 0){
      std::cout << '\n';
    }
    std::cout << a[i] << ' ';
  }
}


int main(void){
  //Serial Code:
    clock_t tS;
    clock_t tP;
    tS = clock();
    double* notPlate_s = new double[N]; //Serial copy of the non-plate locations
    double* tempVal_s = new double[N]; //Double array to hold temporary values
    fillSerial(notPlate_s);
    for(int i = 0; i < 1000; ++i){
        averageSerial(notPlate_s, tempVal_s);
        notPlate_s = tempVal_s;
    }
    tS = clock() - tS;


    tP = clock();
  //PARALLEL CODE:

  double *notPlate_h; //Host copy of the non-plate locations
  double *notPlate_d; //Device copy of the non-plate locations
  int size = N * sizeof(double);
  
  //The first thing we need to do is fill the initial experiment vector:
  cudaMalloc((void **)&notPlate_d, size); //Allocate memory on device for the not-plate vector
  notPlate_h = (double *)malloc(size); //Allocate memory on the host for the not-plate vector
  cudaMemcpy(notPlate_d, notPlate_h, size, cudaMemcpyHostToDevice);
  fill<<<N,1>>>(notPlate_d);
  cudaMemcpy(notPlate_h, notPlate_d, size, cudaMemcpyDeviceToHost);


  //Now we need to create a secondary vector to hold our rolling values while the GPU works:
  double *tempVal_h;
  double *tempVal_d;
  
  cudaMalloc((void **)&tempVal_d, size); //Allocate memory on the device for the temp vector
  tempVal_h = (double *)malloc(size); //allocate memory on the host for the temp vector
  
  
  //Since GPU time is cheap, we don't set a threshold, just run the simulation 1000 times:
  for(int i = 0; i < 1000; ++i){
    cudaMemcpy(notPlate_d, notPlate_h, size, cudaMemcpyHostToDevice);
    average<<<N,1>>>(notPlate_d, tempVal_d);
    cudaMemcpy(tempVal_h, tempVal_d, size, cudaMemcpyDeviceToHost);
    notPlate_h = tempVal_h;
  }
  //The output here will be redirected to a plaintext file which will then be opened and plot in OCTAVE
  //print(notPlate_h);

  //When uncommented, this prints to the std output what the values at the user input points are:  
 /* while(true){
    std::cout << "\nPlease enter an X coordinate: ";
    double x; 
    std::cin >> x;
    x = x*U;
    std::cout << "\nPlease enter a Y coordinate: ";
    double y;
    std::cin >> y;
    y = y*U;
    std::cout << "The point (" << x/U << "," << y/U << ") has value: " << notPlate_h[(int)(y*W+x)] << " Statvolts\n";
  }*/
  //Free the memory just to be safe:
  free(notPlate_h);
  cudaFree(notPlate_d);
  tP = clock() - tP;
  std::cout << "N: " << N << " | SERIAL: " << (float)tS/CLOCKS_PER_SEC << "s | PARALLEL: " << (float)tP/CLOCKS_PER_SEC << "s" << std::endl;
  return 0;
}

	.file	"tmpxft_002bd473_00000000-6_test.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3641:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3641:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0, @function
_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0:
.LFB4300:
	.cfi_startproc
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	(%rdi), %rax
	movb	%sil, 12(%rsp)
	movq	-24(%rax), %rax
	cmpq	$0, 16(%rdi,%rax)
	je	.L3
	leaq	12(%rsp), %rsi
	movl	$1, %edx
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	jmp	.L2
.L3:
	movsbl	12(%rsp), %esi
	call	_ZNSo3putEc@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4300:
	.size	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0, .-_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0
	.globl	_Z10fillSerialPd
	.type	_Z10fillSerialPd, @function
_Z10fillSerialPd:
.LFB3635:
	.cfi_startproc
	endbr64
	movsd	.LC0(%rip), %xmm1
	xorl	%ecx, %ecx
	movl	$2400, %r8d
.L10:
	leal	-2400(%rcx), %eax
	movsd	.LC0(%rip), %xmm0
	movl	%ecx, %esi
	movl	%ecx, %r9d
	cmpl	$5275200, %eax
	ja	.L8
	movl	%ecx, %eax
	movaps	%xmm1, %xmm0
	cltd
	idivl	%r8d
	testl	%edx, %edx
	je	.L8
	leal	-2399(%rcx), %eax
	cltd
	idivl	%r8d
	testl	%edx, %edx
	je	.L8
	movsd	.LC1(%rip), %xmm0
.L8:
	subl	$1920001, %esi
	movsd	%xmm0, (%rdi,%rcx,8)
	cmpl	$1439998, %esi
	ja	.L9
	movl	%r9d, %eax
	movl	$2400, %esi
	cltd
	idivl	%esi
	subl	$800, %edx
	cmpl	$799, %edx
	ja	.L9
	movq	$0x000000000, (%rdi,%rcx,8)
.L9:
	incq	%rcx
	cmpq	$5280000, %rcx
	jne	.L10
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z10fillSerialPd, .-_Z10fillSerialPd
	.globl	_Z13averageSerialPdS_
	.type	_Z13averageSerialPdS_, @function
_Z13averageSerialPdS_:
.LFB3636:
	.cfi_startproc
	endbr64
	movsd	.LC0(%rip), %xmm1
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	xorps	%xmm2, %xmm2
	movsd	.LC3(%rip), %xmm3
.L17:
	movsd	(%rdi,%rax), %xmm0
	ucomisd	.LC0(%rip), %xmm0
	setnp	%dl
	ucomisd	%xmm1, %xmm0
	cmovne	%r8d, %edx
	testb	%dl, %dl
	jne	.L16
	ucomisd	%xmm2, %xmm0
	setnp	%cl
	cmove	%ecx, %edx
	testb	%dl, %dl
	jne	.L16
	addsd	8(%rdi,%rax), %xmm0
	addsd	-8(%rdi,%rax), %xmm0
	addsd	19200(%rdi,%rax), %xmm0
	addsd	-19200(%rdi,%rax), %xmm0
	divsd	%xmm3, %xmm0
.L16:
	movsd	%xmm0, (%rsi,%rax)
	addq	$8, %rax
	cmpq	$42240000, %rax
	jne	.L17
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z13averageSerialPdS_, .-_Z13averageSerialPdS_
	.globl	_Z5printPd
	.type	_Z5printPd, @function
_Z5printPd:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	_ZSt4cout(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L21:
	movl	%ebx, %eax
	movl	$2400, %ecx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L20
	movl	$10, %esi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0
.L20:
	movsd	0(%rbp,%rbx,8), %xmm0
	movq	%r12, %rdi
	incq	%rbx
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movl	$32, %esi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0
	cmpq	$5280000, %rbx
	jne	.L21
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z5printPd, .-_Z5printPd
	.globl	_Z23__device_stub__Z4fillPdPd
	.type	_Z23__device_stub__Z4fillPdPd, @function
_Z23__device_stub__Z4fillPdPd:
.LFB3663:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z4fillPd(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L24:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z23__device_stub__Z4fillPdPd, .-_Z23__device_stub__Z4fillPdPd
	.globl	_Z4fillPd
	.type	_Z4fillPd, @function
_Z4fillPd:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z23__device_stub__Z4fillPdPd
	.cfi_endproc
.LFE3664:
	.size	_Z4fillPd, .-_Z4fillPd
	.globl	_Z28__device_stub__Z7averagePdS_PdS_
	.type	_Z28__device_stub__Z7averagePdS_PdS_, @function
_Z28__device_stub__Z7averagePdS_PdS_:
.LFB3665:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7averagePdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L29:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3665:
	.size	_Z28__device_stub__Z7averagePdS_PdS_, .-_Z28__device_stub__Z7averagePdS_PdS_
	.globl	_Z7averagePdS_
	.type	_Z7averagePdS_, @function
_Z7averagePdS_:
.LFB3666:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z7averagePdS_PdS_
	.cfi_endproc
.LFE3666:
	.size	_Z7averagePdS_, .-_Z7averagePdS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"N: "
.LC5:
	.string	" | SERIAL: "
.LC7:
	.string	"s | PARALLEL: "
.LC8:
	.string	"s"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3638:
	.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	clock@PLT
	movl	$42240000, %edi
	movq	%rax, %rbp
	call	_Znam@PLT
	movl	$42240000, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	movq	%rbx, %rdi
	movq	%rax, %r10
	call	_Z10fillSerialPd
	movl	$1000, %r9d
.L35:
	movq	%r10, %rsi
	movq	%rbx, %rdi
	call	_Z13averageSerialPdS_
	decl	%r9d
	je	.L43
	movq	%r10, %rbx
	jmp	.L35
.L43:
	call	clock@PLT
	subq	%rbp, %rax
	movq	%rax, %r12
	call	clock@PLT
	movl	$42240000, %esi
	movq	%rsp, %rdi
	movq	%rax, %r13
	call	cudaMalloc@PLT
	movl	$42240000, %edi
	call	malloc@PLT
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movl	$42240000, %edx
	movq	%rax, %rsi
	movq	%rax, %rbx
	call	cudaMemcpy@PLT
	movl	$16797841, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$8, %rdi
	movl	$1, %ecx
	movabsq	$4294967297, %rdx
	movl	$1, %esi
	movq	%rdx, 28(%rsp)
	movl	$1, 36(%rsp)
	movq	%rdi, 16(%rsp)
	movl	$1, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	movq	(%rsp), %rdi
	call	_Z23__device_stub__Z4fillPdPd
.L36:
	movq	(%rsp), %rsi
	movl	$2, %ecx
	movl	$42240000, %edx
	movq	%rbx, %rdi
	movabsq	$4294967297, %r15
	movl	$1000, %r14d
	call	cudaMemcpy@PLT
	leaq	8(%rsp), %rdi
	movl	$42240000, %esi
	call	cudaMalloc@PLT
	movl	$42240000, %edi
	call	malloc@PLT
	movq	%rax, %rbp
.L38:
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movl	$42240000, %edx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	movl	$16797841, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$8, %rdi
	movq	%r15, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movq	%r15, 28(%rsp)
	movl	$1, 36(%rsp)
	movq	%rdi, 16(%rsp)
	movl	$1, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	call	_Z28__device_stub__Z7averagePdS_PdS_
.L37:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movl	$42240000, %edx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	decl	%r14d
	je	.L44
	movq	%rbp, %rbx
	jmp	.L38
.L44:
	movq	%rbp, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	call	clock@PLT
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	subq	%r13, %rax
	movq	%rax, %rbx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$5280000, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtsi2ssq	%r12, %xmm0
	divss	.LC6(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtsi2ssq	%rbx, %xmm0
	divss	.LC6(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$56, %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
.LFE3638:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z7averagePdS_"
.LC10:
	.string	"_Z4fillPd"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3668:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7averagePdS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC10(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z4fillPd(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3668:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1075970048
	.align 8
.LC1:
	.long	0
	.long	1074921472
	.align 8
.LC3:
	.long	0
	.long	1075052544
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC6:
	.long	1232348160
	.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 LATTICE RELAXATION
//                           WRITTEN BY: CLAYTON RAYMENT
//
//    I wrote this program to help teach myself CUDA. While MATLAB and OCTAVE
//    are multithreaded applications, this program runs the majority of the
//    calculation directly on the GPU, which has the capability of being much
//    parallel than a standard CPU multithreaded application. Since I haven't
//    learned how to manage threads very well, the application is currently
//    running close to its memory limit. However, with a better implimentation
//    of thread handling, I would be able to utilize all 1664 CUDA cores on my 
//    GTX 970. Currently I only use blocks, which reduces that significantly.
//    The program is fully scalable, as the user can select how many divisions
//    each centimeter is split up into using the U global variable. Large values
//    of U however, exceed the maximum memory of the card due to my poor thread
//    management.
//
//////////////////////////////////////////////////////////////////////////////////

#include <hip/hip_runtime.h>
#include <time.h>
#include <iostream>
//===========
//GLOBALS:
//===========

//--------------
// VARIABLES
//--------------
const int U = 200; //Number of blocks per unit. This allows the grid spacing to be user defined.
const int H = 11*U; //Height of the outer box
const int W = 12*U; //Width of the outer box
const int h = 3*U; //Height of the inner box
const int w = 4*U; //Width of the inner box
const int N = H*W; //Number of threads required


//--------------
// FUNCTIONS
//--------------

//CUDA FUNCTIONS:

//Form the base simulation area:
__global__ void fill(double *a){
  //Form the outer rectangle:
  if(blockIdx.x < W || blockIdx.x > (N-W) || blockIdx.x % W == 0 || (blockIdx.x-(W-1))%W == 0){
    a[blockIdx.x] = 9;
  }
  else{
    a[blockIdx.x] = 1;
  }
  //Form the inner rectangle:
  if(blockIdx.x > W*((H-h)/2) && blockIdx.x < W*((H-h)/2+h) && blockIdx.x % W+1 > (W-w)/2 && blockIdx.x % W < (W-w)/2+w){
    a[blockIdx.x] = 0;
  }
}

//Perform one iteration of the matrix relaxation:
__global__ void average(double *a, double *b){
  //if we are at one of the edges, do nothing:
  if(a[blockIdx.x] == 0 || a[blockIdx.x] == 9){
    b[blockIdx.x] = a[blockIdx.x];
  }
  else{
    b[blockIdx.x] = (a[blockIdx.x]+a[blockIdx.x + 1]+a[blockIdx.x - 1]+a[blockIdx.x - W]+a[blockIdx.x + W])/5.0;
  }
}

//SERIAL FUNCTIONS:
void fillSerial(double *a){
    for(int i = 0; i < N; ++i){
        if(i < W || i > (N-W) || i%W == 0 || (i - (W-1))%W == 0){
            a[i] = 9;
        }
        else{
            a[i] = 4.5;
        }
        if( i > W*((H-h)/2) && i < W*((H-h)/2+h) && i % W+1 > (W-w)/2 && i % W < (W-w)/2+w){
            a[i] = 0;
        }
    }
}


void averageSerial(double* a, double* b){
    for(int i = 0; i < N; ++i){
        if(a[i] == 0 || a[i] == 9){
            b[i] = a[i];
        }
        else{
            b[i] = (a[i]+a[i+1]+a[i-1]+a[i+W]+a[i-W])/5.0;
        }
    }
}


//-----------------
//HELPER FUNCTIONS
//-----------------

//Quick function to print out the grid:
void print(double* a){
  for(int i = 0; i < N; ++i){
    if(i%W == 0){
      std::cout << '\n';
    }
    std::cout << a[i] << ' ';
  }
}


int main(void){
  //Serial Code:
    clock_t tS;
    clock_t tP;
    tS = clock();
    double* notPlate_s = new double[N]; //Serial copy of the non-plate locations
    double* tempVal_s = new double[N]; //Double array to hold temporary values
    fillSerial(notPlate_s);
    for(int i = 0; i < 1000; ++i){
        averageSerial(notPlate_s, tempVal_s);
        notPlate_s = tempVal_s;
    }
    tS = clock() - tS;


    tP = clock();
  //PARALLEL CODE:

  double *notPlate_h; //Host copy of the non-plate locations
  double *notPlate_d; //Device copy of the non-plate locations
  int size = N * sizeof(double);
  
  //The first thing we need to do is fill the initial experiment vector:
  hipMalloc((void **)&notPlate_d, size); //Allocate memory on device for the not-plate vector
  notPlate_h = (double *)malloc(size); //Allocate memory on the host for the not-plate vector
  hipMemcpy(notPlate_d, notPlate_h, size, hipMemcpyHostToDevice);
  fill<<<N,1>>>(notPlate_d);
  hipMemcpy(notPlate_h, notPlate_d, size, hipMemcpyDeviceToHost);


  //Now we need to create a secondary vector to hold our rolling values while the GPU works:
  double *tempVal_h;
  double *tempVal_d;
  
  hipMalloc((void **)&tempVal_d, size); //Allocate memory on the device for the temp vector
  tempVal_h = (double *)malloc(size); //allocate memory on the host for the temp vector
  
  
  //Since GPU time is cheap, we don't set a threshold, just run the simulation 1000 times:
  for(int i = 0; i < 1000; ++i){
    hipMemcpy(notPlate_d, notPlate_h, size, hipMemcpyHostToDevice);
    average<<<N,1>>>(notPlate_d, tempVal_d);
    hipMemcpy(tempVal_h, tempVal_d, size, hipMemcpyDeviceToHost);
    notPlate_h = tempVal_h;
  }
  //The output here will be redirected to a plaintext file which will then be opened and plot in OCTAVE
  //print(notPlate_h);

  //When uncommented, this prints to the std output what the values at the user input points are:  
 /* while(true){
    std::cout << "\nPlease enter an X coordinate: ";
    double x; 
    std::cin >> x;
    x = x*U;
    std::cout << "\nPlease enter a Y coordinate: ";
    double y;
    std::cin >> y;
    y = y*U;
    std::cout << "The point (" << x/U << "," << y/U << ") has value: " << notPlate_h[(int)(y*W+x)] << " Statvolts\n";
  }*/
  //Free the memory just to be safe:
  free(notPlate_h);
  hipFree(notPlate_d);
  tP = clock() - tP;
  std::cout << "N: " << N << " | SERIAL: " << (float)tS/CLOCKS_PER_SEC << "s | PARALLEL: " << (float)tP/CLOCKS_PER_SEC << "s" << std::endl;
  return 0;
}

	.text
	.file	"test.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z19__device_stub__fillPd       # -- Begin function _Z19__device_stub__fillPd
	.type	_Z19__device_stub__fillPd,@function
_Z19__device_stub__fillPd:              # @_Z19__device_stub__fillPd
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z4fillPd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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	_Z19__device_stub__fillPd, .Lfunc_end0-_Z19__device_stub__fillPd
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__averagePdS_  # -- Begin function _Z22__device_stub__averagePdS_
	.type	_Z22__device_stub__averagePdS_,@function
_Z22__device_stub__averagePdS_:         # @_Z22__device_stub__averagePdS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7averagePdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z22__device_stub__averagePdS_, .Lfunc_end1-_Z22__device_stub__averagePdS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10fillSerialPd
.LCPI2_0:
	.quad	0x4022000000000000              # double 9
.LCPI2_1:
	.quad	0x4012000000000000              # double 4.5
	.text
	.globl	_Z10fillSerialPd
	.type	_Z10fillSerialPd,@function
_Z10fillSerialPd:                       # @_Z10fillSerialPd
	.cfi_startproc
# %bb.0:
	movl	$-2399, %eax                    # imm = 0xF6A1
	xorl	%ecx, %ecx
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movl	%ecx, %edx
	imulq	$458129845, %rdx, %rdx          # imm = 0x1B4E81B5
	shrq	$40, %rdx
	imull	$-2400, %edx, %edx              # imm = 0xF6A0
	leal	-5277601(%rcx), %esi
	movaps	%xmm0, %xmm2
	cmpl	$-5275201, %esi                 # imm = 0xFFAF81BF
	jb	.LBB2_5
# %bb.2:                                #   in Loop: Header=BB2_1 Depth=1
	movl	%ecx, %esi
	movaps	%xmm0, %xmm2
	addl	%edx, %esi
	je	.LBB2_5
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	movl	%eax, %esi
	imulq	$458129845, %rsi, %rsi          # imm = 0x1B4E81B5
	shrq	$40, %rsi
	imull	$2400, %esi, %esi               # imm = 0x960
	addl	$2368, %esi                     # imm = 0x940
	orq	$31, %rsi
	movaps	%xmm0, %xmm2
	cmpl	%ecx, %esi
	je	.LBB2_5
# %bb.4:                                #   in Loop: Header=BB2_1 Depth=1
	movaps	%xmm1, %xmm2
.LBB2_5:                                #   in Loop: Header=BB2_1 Depth=1
	movsd	%xmm2, (%rdi,%rcx,8)
	leal	-1920001(%rcx), %esi
	cmpl	$1439998, %esi                  # imm = 0x15F8FE
	ja	.LBB2_8
# %bb.6:                                #   in Loop: Header=BB2_1 Depth=1
	movslq	%edx, %rdx
	addq	$-800, %rdx                     # imm = 0xFCE0
	addl	%ecx, %edx
	cmpl	$799, %edx                      # imm = 0x31F
	ja	.LBB2_8
# %bb.7:                                #   in Loop: Header=BB2_1 Depth=1
	movq	$0, (%rdi,%rcx,8)
.LBB2_8:                                #   in Loop: Header=BB2_1 Depth=1
	incq	%rcx
	incl	%eax
	cmpq	$5280000, %rcx                  # imm = 0x509100
	jne	.LBB2_1
# %bb.9:
	retq
.Lfunc_end2:
	.size	_Z10fillSerialPd, .Lfunc_end2-_Z10fillSerialPd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13averageSerialPdS_
.LCPI3_0:
	.quad	0x4022000000000000              # double 9
.LCPI3_1:
	.quad	0x4014000000000000              # double 5
	.text
	.globl	_Z13averageSerialPdS_
	.type	_Z13averageSerialPdS_,@function
_Z13averageSerialPdS_:                  # @_Z13averageSerialPdS_
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
	xorpd	%xmm0, %xmm0
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI3_1(%rip), %xmm2           # xmm2 = mem[0],zero
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	movsd	(%rdi,%rax,8), %xmm3            # xmm3 = mem[0],zero
	ucomisd	%xmm0, %xmm3
	jne	.LBB3_2
	jnp	.LBB3_4
.LBB3_2:                                #   in Loop: Header=BB3_1 Depth=1
	ucomisd	%xmm1, %xmm3
	jne	.LBB3_3
	jnp	.LBB3_4
.LBB3_3:                                #   in Loop: Header=BB3_1 Depth=1
	addsd	8(%rdi,%rax,8), %xmm3
	addsd	-8(%rdi,%rax,8), %xmm3
	addsd	19200(%rdi,%rax,8), %xmm3
	addsd	-19200(%rdi,%rax,8), %xmm3
	divsd	%xmm2, %xmm3
.LBB3_4:                                #   in Loop: Header=BB3_1 Depth=1
	movsd	%xmm3, (%rsi,%rax,8)
	incq	%rax
	cmpq	$5280000, %rax                  # imm = 0x509100
	jne	.LBB3_1
# %bb.5:
	retq
.Lfunc_end3:
	.size	_Z13averageSerialPdS_, .Lfunc_end3-_Z13averageSerialPdS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z5printPd                      # -- Begin function _Z5printPd
	.type	_Z5printPd,@function
_Z5printPd:                             # @_Z5printPd
	.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	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	xorl	%r12d, %r12d
	leaq	14(%rsp), %r14
	leaq	15(%rsp), %r15
	xorl	%r13d, %r13d
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movl	%r13d, %eax
	imulq	$458129845, %rax, %rax          # imm = 0x1B4E81B5
	shrq	$40, %rax
	imull	$2400, %eax, %eax               # imm = 0x960
	addl	%r12d, %eax
	jne	.LBB4_5
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	movb	$10, 14(%rsp)
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	cmpq	$0, _ZSt4cout+16(%rax)
	je	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$1, %edx
	movq	%r14, %rsi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB4_5
.LBB4_4:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$10, %esi
	callq	_ZNSo3putEc
.LBB4_5:                                #   in Loop: Header=BB4_1 Depth=1
	movsd	(%rbx,%r13,8), %xmm0            # xmm0 = mem[0],zero
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movb	$32, 15(%rsp)
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	cmpq	$0, 16(%rax,%rcx)
	je	.LBB4_7
# %bb.6:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$1, %edx
	movq	%rax, %rdi
	movq	%r15, %rsi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB4_8
.LBB4_7:                                #   in Loop: Header=BB4_1 Depth=1
	movq	%rax, %rdi
	movl	$32, %esi
	callq	_ZNSo3putEc
.LBB4_8:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.exit6
                                        #   in Loop: Header=BB4_1 Depth=1
	incq	%r13
	decl	%r12d
	cmpq	$5280000, %r13                  # imm = 0x509100
	jne	.LBB4_1
# %bb.9:
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	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_end4:
	.size	_Z5printPd, .Lfunc_end4-_Z5printPd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI5_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	callq	clock
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	$42240000, %edi                 # imm = 0x2848800
	callq	_Znam
	movq	%rax, %r14
	movl	$42240000, %edi                 # imm = 0x2848800
	callq	_Znam
	movq	%rax, %rbx
	movq	%r14, %rdi
	callq	_Z10fillSerialPd
	movl	$1000, %ebp                     # imm = 0x3E8
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	_Z13averageSerialPdS_
	movq	%rbx, %r14
	decl	%ebp
	jne	.LBB5_1
# %bb.2:
	movabsq	$4294967297, %r12               # imm = 0x100000001
	callq	clock
	movq	%rax, %r14
	callq	clock
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	leaq	8(%rsp), %rbx
	movl	$42240000, %esi                 # imm = 0x2848800
	movq	%rbx, %rdi
	callq	hipMalloc
	movl	$42240000, %edi                 # imm = 0x2848800
	callq	malloc
	movq	%rax, %rbp
	movq	(%rbx), %rdi
	movl	$42240000, %edx                 # imm = 0x2848800
	movq	%rax, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	5279999(%r12), %r13
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_4
# %bb.3:
	movq	8(%rsp), %rdi
	callq	_Z19__device_stub__fillPd
.LBB5_4:
	movq	8(%rsp), %rsi
	movl	$42240000, %edx                 # imm = 0x2848800
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rdi
	movl	$42240000, %esi                 # imm = 0x2848800
	callq	hipMalloc
	movl	$42240000, %edi                 # imm = 0x2848800
	callq	malloc
	movq	%rax, %rbx
	movl	$1000, %r15d                    # imm = 0x3E8
.LBB5_5:                                # =>This Inner Loop Header: Depth=1
	movq	8(%rsp), %rdi
	movl	$42240000, %edx                 # imm = 0x2848800
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_7
# %bb.6:                                #   in Loop: Header=BB5_5 Depth=1
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z22__device_stub__averagePdS_
.LBB5_7:                                #   in Loop: Header=BB5_5 Depth=1
	movq	16(%rsp), %rsi
	movl	$42240000, %edx                 # imm = 0x2848800
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%rbx, %rbp
	decl	%r15d
	jne	.LBB5_5
# %bb.8:
	subq	32(%rsp), %r14                  # 8-byte Folded Reload
	movq	%rbx, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	callq	clock
	movq	%rax, %rbx
	subq	24(%rsp), %rbx                  # 8-byte Folded Reload
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$5280000, %esi                  # imm = 0x509100
	callq	_ZNSolsEi
	movq	%rax, %r15
	movl	$.L.str.1, %esi
	movl	$11, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtsi2ss	%r14, %xmm0
	divss	.LCPI5_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.2, %esi
	movl	$14, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rbx, %xmm0
	divss	.LCPI5_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	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
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4fillPd, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7averagePdS_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_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	_Z4fillPd,@object               # @_Z4fillPd
	.section	.rodata,"a",@progbits
	.globl	_Z4fillPd
	.p2align	3, 0x0
_Z4fillPd:
	.quad	_Z19__device_stub__fillPd
	.size	_Z4fillPd, 8

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"N: "
	.size	.L.str, 4

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	" | SERIAL: "
	.size	.L.str.1, 12

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"s | PARALLEL: "
	.size	.L.str.2, 15

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4fillPd"
	.size	.L__unnamed_1, 10

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7averagePdS_"
	.size	.L__unnamed_2, 15

	.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 _Z19__device_stub__fillPd
	.addrsig_sym _Z22__device_stub__averagePdS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4fillPd
	.addrsig_sym _Z7averagePdS_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4fillPd               ; -- Begin function _Z4fillPd
	.globl	_Z4fillPd
	.p2align	8
	.type	_Z4fillPd,@function
_Z4fillPd:                              ; @_Z4fillPd
; %bb.0:
	s_add_i32 s3, s15, 0xffaf785f
	v_mov_b32_e32 v0, 0
	s_cmp_lt_u32 s3, 0xffaf81bf
	s_mul_hi_u32 s3, s15, 0x1b4e81b5
	s_cselect_b32 s5, -1, 0
	s_lshr_b32 s3, s3, 8
	v_mov_b32_e32 v1, 0x40220000
	s_mulk_i32 s3, 0x960
	s_mov_b32 s2, s15
	s_sub_i32 s4, s15, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_cmp_eq_u32 s4, 0
	s_cselect_b32 s3, -1, 0
	s_or_b32 s3, s5, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 vcc_lo, exec_lo, s3
	s_mov_b32 s3, 0
	s_cbranch_vccnz .LBB0_2
; %bb.1:
	s_mul_i32 s5, s2, 0x962fc963
	v_mov_b32_e32 v1, 0x40220000
	s_add_i32 s5, s5, 0x962fc943
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_alignbit_b32 v0, s5, s5, 5
	v_cmp_gt_u32_e32 vcc_lo, 0x1b4e82, v0
	s_delay_alu instid0(VALU_DEP_3)
	v_dual_mov_b32 v0, 0 :: v_dual_cndmask_b32 v1, 0x3ff00000, v1
.LBB0_2:
	s_load_b64 s[0:1], s[0:1], 0x0
	s_lshl_b64 s[6:7], s[2:3], 3
	v_mov_b32_e32 v2, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s0, s6
	s_addc_u32 s1, s1, s7
	s_add_i32 s2, s2, 0xffe2b3ff
	global_store_b64 v2, v[0:1], s[0:1]
	s_cmp_lt_u32 s2, 0x15f8ff
	s_cselect_b32 s2, -1, 0
	s_addk_i32 s4, 0xfce0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_cmpk_lt_u32 s4, 0x320
	s_cselect_b32 s3, -1, 0
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_4
; %bb.3:
	v_mov_b32_e32 v3, v2
	global_store_b64 v2, v[2:3], s[0:1]
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4fillPd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 8
		.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 4
		.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	_Z4fillPd, .Lfunc_end0-_Z4fillPd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 260
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; 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
	.protected	_Z7averagePdS_          ; -- Begin function _Z7averagePdS_
	.globl	_Z7averagePdS_
	.p2align	8
	.type	_Z7averagePdS_,@function
_Z7averagePdS_:                         ; @_Z7averagePdS_
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mov_b32 s6, s15
	s_mov_b32 s7, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[4:5], s[6:7], 3
	s_waitcnt lgkmcnt(0)
	s_add_u32 s8, s0, s4
	s_addc_u32 s9, s1, s5
	s_load_b64 s[8:9], s[8:9], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmp_eq_f64_e64 s10, s[8:9], 0
	v_cmp_eq_f64_e64 s11, 0x40220000, s[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s10, s10, s11
	s_and_b32 vcc_lo, exec_lo, s10
	s_cbranch_vccnz .LBB1_2
; %bb.1:
	s_add_i32 s10, s6, 1
	s_mov_b32 s11, s7
	s_mov_b32 s13, s7
	s_lshl_b64 s[10:11], s[10:11], 3
	s_mov_b32 s15, s7
	s_add_u32 s10, s0, s10
	s_addc_u32 s11, s1, s11
	s_add_i32 s12, s6, -1
	s_load_b64 s[10:11], s[10:11], 0x0
	s_lshl_b64 s[12:13], s[12:13], 3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_add_u32 s12, s0, s12
	s_addc_u32 s13, s1, s13
	s_add_i32 s14, s6, 0xfffff6a0
	s_lshl_b64 s[14:15], s[14:15], 3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_add_u32 s14, s0, s14
	s_addc_u32 s15, s1, s15
	s_addk_i32 s6, 0x960
	s_lshl_b64 s[6:7], s[6:7], 3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s0, s6
	s_addc_u32 s1, s1, s7
	s_clause 0x2
	s_load_b64 s[6:7], s[12:13], 0x0
	s_load_b64 s[12:13], s[14:15], 0x0
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_add_f64 v[0:1], s[8:9], s[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[0:1], v[0:1], s[6:7]
	v_add_f64 v[0:1], v[0:1], s[12:13]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[0:1], v[0:1], s[0:1]
	v_div_scale_f64 v[2:3], null, 0x40140000, 0x40140000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[4:5], v[2:3]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[6:7], -v[2:3], v[4:5], 1.0
	v_fma_f64 v[4:5], v[4:5], v[6:7], v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[6:7], -v[2:3], v[4:5], 1.0
	v_fma_f64 v[4:5], v[4:5], v[6:7], v[4:5]
	v_div_scale_f64 v[6:7], vcc_lo, v[0:1], 0x40140000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[8:9], v[6:7], v[4:5]
	v_fma_f64 v[2:3], -v[2:3], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[2:3], v[2:3], v[4:5], v[8:9]
	v_div_fixup_f64 v[0:1], v[2:3], 0x40140000, v[0:1]
	s_branch .LBB1_3
.LBB1_2:
	v_dual_mov_b32 v0, s8 :: v_dual_mov_b32 v1, s9
.LBB1_3:
	v_mov_b32_e32 v2, 0
	s_add_u32 s0, s2, s4
	s_addc_u32 s1, s3, s5
	global_store_b64 v2, v[0:1], s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7averagePdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.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 10
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z7averagePdS_, .Lfunc_end1-_Z7averagePdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 416
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; 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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 8
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4fillPd
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4fillPd.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7averagePdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7averagePdS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
