// Berat Postalcioglu
/*OUTPUT

	blocksPerGrid   threadsPerBlock   time to generate
	-------------   ---------------   ----------------
		 157           256              0.04400000 ms.
		  79           512              0.05434880 ms.
		  40          1024              0.09233920 ms.
	   40000             1              0.00174080 ms.
	   20000             1              0.00174080 ms.
	   10000             1              0.00179200 ms.
		5000             1              0.00189440 ms.
		1000             1              0.07427360 ms.
		   2             1             27.85148430 ms.
		   1             1             54.44231415 ms.

*/
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <ctime>
#include <cmath>
#include <iostream>
#include <cstdio>

using namespace std;

const int ArrSize = 40000;


__global__ void diffGPU(double *a, double *b, double *c, int size)
{
	int tid = threadIdx.x + blockIdx.x * blockDim.x;
	while (tid < size)
	{
		c[tid] = a[tid] - b[tid];
		tid += blockDim.x * gridDim.x;
	}
}


void generateArray(double *arr, double size)
{
	for (int i = 0; i < size; i++)
	{
		arr[i] = rand() % 100 + 1;
	}
}

double sumArray(double *data, int count)
{
	double result = 0;
	for (int i = 0; i < count; i++)
	{
		result += data[i];
	}
	return result;
}

double sumArrayDiff(double *a, double *b, int count)
{
	double *c=new double[count];
	for (int i = 0; i < count; i++)
	{
		c[i] = a[i] - b[i];
	}

	double result = sumArray(c, count);
	delete[] c;

	return result;
}

int* diffCPU(int *v1, int *v2)
{
	int res[ArrSize];
	for (int i = 0; i < ArrSize; i++)
	{
		res[i] = v1[i] - v2[i];
	}
	return res;
}

void displayArray(int *arr, int size)
{
	for (int i = 0; i < size; i++)
	{
		std::cout << arr[i] << " ";
	}
	std::cout << std::endl;
}

float duration(double *devA, double *devB, double *devC, int blocksPerGrid, int threadsPerBlock, double resultCPU)
{
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	cudaEventRecord(start, 0);
	// gpu work
	diffGPU <<<threadsPerBlock, blocksPerGrid >>> (devA, devB, devC, ArrSize);
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	
	double *resFromGpu = new double[ArrSize];
	cudaMemcpy(resFromGpu, devC, sizeof(double)*ArrSize, cudaMemcpyDeviceToHost);
	double sum = sumArray(resFromGpu, ArrSize);

	delete[] resFromGpu;

	if (sum != resultCPU)
	{
		cout << "Results from CPU and GPU are not same... Exiting..." << endl;
		exit(1);
	}

	float elapsedTime;
	cudaEventElapsedTime(&elapsedTime, start, stop);
	return elapsedTime;
}

float averageDuration(double *devA, double *devB, double *devC,
	int blocksPerGrid, int threadsPerBlock, double resultCPU, int repetition)
{
	double totalElapsedTime = 0;
	for (int i = 0; i < repetition; i++)
	{
		totalElapsedTime += duration(devA, devB, devC, blocksPerGrid, threadsPerBlock, resultCPU);
	}
	return (totalElapsedTime / repetition);
}

void prepareTable(double *devA, double *devB, double *devC, int blocksPerGrid, int threadsPerBlock, double resultCPU, int repetition) {

	double ave = averageDuration(devA, devB, devC, blocksPerGrid, threadsPerBlock, resultCPU, repetition);
	printf("%8d", blocksPerGrid);
	printf("%14d", threadsPerBlock);
	printf("%24.8f", ave);
	printf(" ms.\n");
}

int main()
{
	srand(time(NULL));

	// cpu
	double a[ArrSize], b[ArrSize], c[ArrSize];
	generateArray(a, ArrSize);
	generateArray(b, ArrSize);
	double resultCPU = sumArrayDiff(a, b, ArrSize);

	// gpu
	unsigned int totalBytes = ArrSize * sizeof(double);
	double *devA, *devB, *devC;
	cudaMalloc(&devA, totalBytes);
	cudaMalloc(&devB, totalBytes);
	cudaMalloc(&devC, totalBytes);

	cudaMemcpy(devA, a, totalBytes, cudaMemcpyHostToDevice);
	cudaMemcpy(devB, b, totalBytes, cudaMemcpyHostToDevice);

	cout << "blocksPerGrid" << "   " << "threadsPerBlock" << "   " << "time to generate" << endl;
	cout << "-------------" << "   " << "---------------" << "   " << "----------------" << endl;
	prepareTable(devA, devB, devC, 157, 256, resultCPU, 1);
	prepareTable(devA, devB, devC, 79, 512, resultCPU, 20);
	prepareTable(devA, devB, devC, 40, 1024, resultCPU, 20);
	prepareTable(devA, devB, devC, 40000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 20000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 10000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 5000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 1000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 2, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 1, 1, resultCPU, 20);

	return 0;
}
	.file	"tmpxft_0020d5c4_00000000-6_driver.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3646:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3646:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13generateArrayPdd
	.type	_Z13generateArrayPdd, @function
_Z13generateArrayPdd:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$100, %r12d
	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
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
.L3:
	cvtsi2sdl	%ebx, %xmm1
	comisd	%xmm1, %xmm0
	jbe	.L7
	movsd	%xmm0, 8(%rsp)
	call	rand@PLT
	movsd	8(%rsp), %xmm0
	cltd
	idivl	%r12d
	incl	%edx
	cvtsi2sdl	%edx, %xmm1
	movsd	%xmm1, 0(%rbp,%rbx,8)
	incq	%rbx
	jmp	.L3
.L7:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z13generateArrayPdd, .-_Z13generateArrayPdd
	.globl	_Z8sumArrayPdi
	.type	_Z8sumArrayPdi, @function
_Z8sumArrayPdi:
.LFB3636:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L9:
	cmpl	%eax, %esi
	jle	.L11
	addsd	(%rdi,%rax,8), %xmm0
	incq	%rax
	jmp	.L9
.L11:
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z8sumArrayPdi, .-_Z8sumArrayPdi
	.globl	_Z12sumArrayDiffPdS_i
	.type	_Z12sumArrayDiffPdS_i, @function
_Z12sumArrayDiffPdS_i:
.LFB3637:
	.cfi_startproc
	endbr64
	movabsq	$1152921504606846975, %rax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	movslq	%edx, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	cmpq	%rdi, %rax
	jb	.L13
	movq	%rdi, %rbx
	salq	$3, %rdi
	movq	%rsi, %r12
	call	_Znam@PLT
	xorl	%ecx, %ecx
	movq	%rax, %rdi
	jmp	.L14
.L13:
	call	__cxa_throw_bad_array_new_length@PLT
.L14:
	cmpl	%ecx, %ebx
	jle	.L17
	movsd	0(%rbp,%rcx,8), %xmm0
	subsd	(%r12,%rcx,8), %xmm0
	movsd	%xmm0, (%rdi,%rcx,8)
	incq	%rcx
	jmp	.L14
.L17:
	movl	%ebx, %esi
	call	_Z8sumArrayPdi
	movsd	%xmm0, 8(%rsp)
	call	_ZdaPv@PLT
	movsd	8(%rsp), %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	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	_Z12sumArrayDiffPdS_i, .-_Z12sumArrayDiffPdS_i
	.globl	_Z7diffCPUPiS_
	.type	_Z7diffCPUPiS_, @function
_Z7diffCPUPiS_:
.LFB3638:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE3638:
	.size	_Z7diffCPUPiS_, .-_Z7diffCPUPiS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	" "
	.text
	.globl	_Z12displayArrayPii
	.type	_Z12displayArrayPii, @function
_Z12displayArrayPii:
.LFB3639:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	_ZSt4cout(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 48
.L20:
	cmpl	%ebx, %ebp
	jle	.L23
	movl	(%r12,%rbx,4), %esi
	movq	%r13, %rdi
	incq	%rbx
	call	_ZNSolsEi@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L20
.L23:
	popq	%rax
	.cfi_def_cfa_offset 40
	movq	%r13, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	.cfi_endproc
.LFE3639:
	.size	_Z12displayArrayPii, .-_Z12displayArrayPii
	.globl	_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i
	.type	_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i, @function
_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i:
.LFB3668:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z7diffGPUPdS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L24:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3668:
	.size	_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i, .-_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i
	.globl	_Z7diffGPUPdS_S_i
	.type	_Z7diffGPUPdS_S_i, @function
_Z7diffGPUPdS_S_i:
.LFB3669:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i
	.cfi_endproc
.LFE3669:
	.size	_Z7diffGPUPdS_S_i, .-_Z7diffGPUPdS_S_i
	.section	.rodata.str1.1
.LC2:
	.string	"Results from CPU and GPU are not same... Exiting..."
	.text
	.globl	_Z8durationPdS_S_iid
	.type	_Z8durationPdS_S_iid, @function
_Z8durationPdS_S_iid:
.LFB3640:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	%ecx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%r8d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movsd	%xmm0, (%rsp)
	leaq	16(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	cudaEventCreate@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%r14d, 44(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r13d, 32(%rsp)
	movq	%rax, 48(%rsp)
	movl	52(%rsp), %ecx
	movq	%rax, 36(%rsp)
	movq	44(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	movl	$40000, %ecx
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movq	%rbx, %rdi
	call	_Z31__device_stub__Z7diffGPUPdS_S_iPdS_S_i
.L30:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	$320000, %edi
	call	_Znam@PLT
	movl	$2, %ecx
	movl	$320000, %edx
	movq	%rbp, %rsi
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	cudaMemcpy@PLT
	movl	$40000, %esi
	movq	%rbx, %rdi
	call	_Z8sumArrayPdi
	movsd	%xmm0, 8(%rsp)
	call	_ZdaPv@PLT
	movsd	8(%rsp), %xmm0
	ucomisd	(%rsp), %xmm0
	jp	.L34
	je	.L31
.L34:
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L31:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	leaq	44(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	44(%rsp), %xmm0
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3640:
	.size	_Z8durationPdS_S_iid, .-_Z8durationPdS_S_iid
	.globl	_Z15averageDurationPdS_S_iidi
	.type	_Z15averageDurationPdS_S_iidi, @function
_Z15averageDurationPdS_S_iidi:
.LFB3641:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorps	%xmm1, %xmm1
	movl	%r8d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%ecx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%r9d, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%rdi, 8(%rsp)
	movsd	%xmm0, 16(%rsp)
.L37:
	cmpl	%ebx, %ebp
	jge	.L40
	movsd	16(%rsp), %xmm0
	movq	8(%rsp), %rdi
	movl	%r15d, %r8d
	incl	%ebp
	movl	%r14d, %ecx
	movq	%r13, %rdx
	movq	%r12, %rsi
	movsd	%xmm1, 24(%rsp)
	call	_Z8durationPdS_S_iid
	movsd	24(%rsp), %xmm1
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm1
	jmp	.L37
.L40:
	cvtsi2sdl	%ebx, %xmm0
	addq	$40, %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
	divsd	%xmm0, %xmm1
	cvtsd2ss	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE3641:
	.size	_Z15averageDurationPdS_S_iidi, .-_Z15averageDurationPdS_S_iidi
	.section	.rodata.str1.1
.LC3:
	.string	"%8d"
.LC4:
	.string	"%14d"
.LC5:
	.string	"%24.8f"
.LC6:
	.string	" ms.\n"
	.text
	.globl	_Z12prepareTablePdS_S_iidi
	.type	_Z12prepareTablePdS_S_iidi, @function
_Z12prepareTablePdS_S_iidi:
.LFB3642:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%r8d, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	call	_Z15averageDurationPdS_S_iidi
	movl	%ebp, %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, 8(%rsp)
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movsd	8(%rsp), %xmm0
	leaq	.LC5(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	leaq	.LC6(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE3642:
	.size	_Z12prepareTablePdS_S_iidi, .-_Z12prepareTablePdS_S_iidi
	.section	.rodata.str1.1
.LC8:
	.string	"blocksPerGrid"
.LC9:
	.string	"   "
.LC10:
	.string	"threadsPerBlock"
.LC11:
	.string	"time to generate"
.LC12:
	.string	"-------------"
.LC13:
	.string	"---------------"
.LC14:
	.string	"----------------"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3643:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-638976(%rsp), %r11
	.cfi_def_cfa 11, 639008
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1056, %rsp
	.cfi_def_cfa_offset 640064
	xorl	%edi, %edi
	movq	%fs:40, %rax
	movq	%rax, 640024(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rbp
	leaq	320024(%rsp), %rbx
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movsd	.LC7(%rip), %xmm0
	movq	%rbp, %rdi
	call	_Z13generateArrayPdd
	movsd	.LC7(%rip), %xmm0
	movq	%rbx, %rdi
	call	_Z13generateArrayPdd
	movl	$40000, %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	_Z12sumArrayDiffPdS_i
	movq	%rsp, %rdi
	movl	$320000, %esi
	movq	%xmm0, %r14
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$320000, %esi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$320000, %esi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$320000, %edx
	leaq	_ZSt4cout(%rip), %rbp
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$320000, %edx
	leaq	.LC9(%rip), %rbx
	call	cudaMemcpy@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rbp, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rbp, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC14(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$1, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$256, %r8d
	movl	$157, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$512, %r8d
	movl	$79, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1024, %r8d
	movl	$40, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$40000, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$20000, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$10000, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$5000, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$1000, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$2, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$20, %r9d
	movq	(%rsp), %rdi
	movq	%r14, %xmm0
	movl	$1, %r8d
	movl	$1, %ecx
	call	_Z12prepareTablePdS_S_iidi
	movq	640024(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$640032, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3643:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z7diffGPUPdS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3671:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z7diffGPUPdS_S_i(%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
.LFE3671:
	.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
.LC7:
	.long	0
	.long	1088653312
	.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:

// Berat Postalcioglu
/*OUTPUT

	blocksPerGrid   threadsPerBlock   time to generate
	-------------   ---------------   ----------------
		 157           256              0.04400000 ms.
		  79           512              0.05434880 ms.
		  40          1024              0.09233920 ms.
	   40000             1              0.00174080 ms.
	   20000             1              0.00174080 ms.
	   10000             1              0.00179200 ms.
		5000             1              0.00189440 ms.
		1000             1              0.07427360 ms.
		   2             1             27.85148430 ms.
		   1             1             54.44231415 ms.

*/
#include "hip/hip_runtime.h"

#include <ctime>
#include <cmath>
#include <iostream>
#include <cstdio>

using namespace std;

const int ArrSize = 40000;


__global__ void diffGPU(double *a, double *b, double *c, int size)
{
	int tid = threadIdx.x + blockIdx.x * blockDim.x;
	while (tid < size)
	{
		c[tid] = a[tid] - b[tid];
		tid += blockDim.x * gridDim.x;
	}
}


void generateArray(double *arr, double size)
{
	for (int i = 0; i < size; i++)
	{
		arr[i] = rand() % 100 + 1;
	}
}

double sumArray(double *data, int count)
{
	double result = 0;
	for (int i = 0; i < count; i++)
	{
		result += data[i];
	}
	return result;
}

double sumArrayDiff(double *a, double *b, int count)
{
	double *c=new double[count];
	for (int i = 0; i < count; i++)
	{
		c[i] = a[i] - b[i];
	}

	double result = sumArray(c, count);
	delete[] c;

	return result;
}

int* diffCPU(int *v1, int *v2)
{
	int res[ArrSize];
	for (int i = 0; i < ArrSize; i++)
	{
		res[i] = v1[i] - v2[i];
	}
	return res;
}

void displayArray(int *arr, int size)
{
	for (int i = 0; i < size; i++)
	{
		std::cout << arr[i] << " ";
	}
	std::cout << std::endl;
}

float duration(double *devA, double *devB, double *devC, int blocksPerGrid, int threadsPerBlock, double resultCPU)
{
	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);
	hipEventRecord(start, 0);
	// gpu work
	diffGPU <<<threadsPerBlock, blocksPerGrid >>> (devA, devB, devC, ArrSize);
	hipEventRecord(stop, 0);
	hipEventSynchronize(stop);
	
	double *resFromGpu = new double[ArrSize];
	hipMemcpy(resFromGpu, devC, sizeof(double)*ArrSize, hipMemcpyDeviceToHost);
	double sum = sumArray(resFromGpu, ArrSize);

	delete[] resFromGpu;

	if (sum != resultCPU)
	{
		cout << "Results from CPU and GPU are not same... Exiting..." << endl;
		exit(1);
	}

	float elapsedTime;
	hipEventElapsedTime(&elapsedTime, start, stop);
	return elapsedTime;
}

float averageDuration(double *devA, double *devB, double *devC,
	int blocksPerGrid, int threadsPerBlock, double resultCPU, int repetition)
{
	double totalElapsedTime = 0;
	for (int i = 0; i < repetition; i++)
	{
		totalElapsedTime += duration(devA, devB, devC, blocksPerGrid, threadsPerBlock, resultCPU);
	}
	return (totalElapsedTime / repetition);
}

void prepareTable(double *devA, double *devB, double *devC, int blocksPerGrid, int threadsPerBlock, double resultCPU, int repetition) {

	double ave = averageDuration(devA, devB, devC, blocksPerGrid, threadsPerBlock, resultCPU, repetition);
	printf("%8d", blocksPerGrid);
	printf("%14d", threadsPerBlock);
	printf("%24.8f", ave);
	printf(" ms.\n");
}

int main()
{
	srand(time(NULL));

	// cpu
	double a[ArrSize], b[ArrSize], c[ArrSize];
	generateArray(a, ArrSize);
	generateArray(b, ArrSize);
	double resultCPU = sumArrayDiff(a, b, ArrSize);

	// gpu
	unsigned int totalBytes = ArrSize * sizeof(double);
	double *devA, *devB, *devC;
	hipMalloc(&devA, totalBytes);
	hipMalloc(&devB, totalBytes);
	hipMalloc(&devC, totalBytes);

	hipMemcpy(devA, a, totalBytes, hipMemcpyHostToDevice);
	hipMemcpy(devB, b, totalBytes, hipMemcpyHostToDevice);

	cout << "blocksPerGrid" << "   " << "threadsPerBlock" << "   " << "time to generate" << endl;
	cout << "-------------" << "   " << "---------------" << "   " << "----------------" << endl;
	prepareTable(devA, devB, devC, 157, 256, resultCPU, 1);
	prepareTable(devA, devB, devC, 79, 512, resultCPU, 20);
	prepareTable(devA, devB, devC, 40, 1024, resultCPU, 20);
	prepareTable(devA, devB, devC, 40000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 20000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 10000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 5000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 1000, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 2, 1, resultCPU, 20);
	prepareTable(devA, devB, devC, 1, 1, resultCPU, 20);

	return 0;
}
	.text
	.file	"driver.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z22__device_stub__diffGPUPdS_S_i # -- Begin function _Z22__device_stub__diffGPUPdS_S_i
	.type	_Z22__device_stub__diffGPUPdS_S_i,@function
_Z22__device_stub__diffGPUPdS_S_i:      # @_Z22__device_stub__diffGPUPdS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z7diffGPUPdS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22__device_stub__diffGPUPdS_S_i, .Lfunc_end0-_Z22__device_stub__diffGPUPdS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z13generateArrayPdd            # -- Begin function _Z13generateArrayPdd
	.type	_Z13generateArrayPdd,@function
_Z13generateArrayPdd:                   # @_Z13generateArrayPdd
	.cfi_startproc
# %bb.0:
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jbe	.LBB1_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	movsd	%xmm1, (%rbx,%r14,8)
	incq	%r14
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r14d, %xmm1
	ucomisd	%xmm1, %xmm0
	ja	.LBB1_2
# %bb.3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
.LBB1_4:                                # %._crit_edge
	retq
.Lfunc_end1:
	.size	_Z13generateArrayPdd, .Lfunc_end1-_Z13generateArrayPdd
	.cfi_endproc
                                        # -- End function
	.globl	_Z8sumArrayPdi                  # -- Begin function _Z8sumArrayPdi
	.type	_Z8sumArrayPdi,@function
_Z8sumArrayPdi:                         # @_Z8sumArrayPdi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%esi, %eax
	xorpd	%xmm0, %xmm0
	xorl	%ecx, %ecx
.LBB2_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addsd	(%rdi,%rcx,8), %xmm0
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB2_4
# %bb.2:                                # %._crit_edge
	retq
.LBB2_1:
	xorps	%xmm0, %xmm0
	retq
.Lfunc_end2:
	.size	_Z8sumArrayPdi, .Lfunc_end2-_Z8sumArrayPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z12sumArrayDiffPdS_i           # -- Begin function _Z12sumArrayDiffPdS_i
	.type	_Z12sumArrayDiffPdS_i,@function
_Z12sumArrayDiffPdS_i:                  # @_Z12sumArrayDiffPdS_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edx, %ebx
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	%edx, %r12d
	leaq	(,%r12,8), %rax
	testl	%edx, %edx
	movq	$-1, %rdi
	cmovnsq	%rax, %rdi
	callq	_Znam
	xorpd	%xmm1, %xmm1
	testl	%ebx, %ebx
	jle	.LBB3_6
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ecx, %ecx
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r15,%rcx,8), %xmm0            # xmm0 = mem[0],zero
	subsd	(%r14,%rcx,8), %xmm0
	movsd	%xmm0, (%rax,%rcx,8)
	incq	%rcx
	cmpq	%rcx, %r12
	jne	.LBB3_2
# %bb.3:                                # %._crit_edge
	testl	%ebx, %ebx
	jle	.LBB3_6
# %bb.4:                                # %.lr.ph.i.preheader
	xorpd	%xmm1, %xmm1
	xorl	%ecx, %ecx
.LBB3_5:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	addsd	(%rax,%rcx,8), %xmm1
	incq	%rcx
	cmpq	%rcx, %r12
	jne	.LBB3_5
.LBB3_6:                                # %_Z8sumArrayPdi.exit
	movsd	%xmm1, (%rsp)                   # 8-byte Spill
	movq	%rax, %rdi
	callq	_ZdaPv
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z12sumArrayDiffPdS_i, .Lfunc_end3-_Z12sumArrayDiffPdS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z7diffCPUPiS_                  # -- Begin function _Z7diffCPUPiS_
	.type	_Z7diffCPUPiS_,@function
_Z7diffCPUPiS_:                         # @_Z7diffCPUPiS_
	.cfi_startproc
# %bb.0:
	subq	$159880, %rsp                   # imm = 0x27088
	.cfi_def_cfa_offset 159888
	xorl	%eax, %eax
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movl	(%rdi,%rax,4), %ecx
	subl	(%rsi,%rax,4), %ecx
	movl	%ecx, -128(%rsp,%rax,4)
	incq	%rax
	cmpq	$40000, %rax                    # imm = 0x9C40
	jne	.LBB4_1
# %bb.2:
	leaq	-128(%rsp), %rax
	addq	$159880, %rsp                   # imm = 0x27088
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z7diffCPUPiS_, .Lfunc_end4-_Z7diffCPUPiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12displayArrayPii             # -- Begin function _Z12displayArrayPii
	.type	_Z12displayArrayPii,@function
_Z12displayArrayPii:                    # @_Z12displayArrayPii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	testl	%esi, %esi
	jle	.LBB5_3
# %bb.1:                                # %.lr.ph.preheader
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r15,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movl	$.L.str, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB5_2
.LBB5_3:                                # %._crit_edge
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	_ZNSo5flushEv                   # TAILCALL
.Lfunc_end5:
	.size	_Z12displayArrayPii, .Lfunc_end5-_Z12displayArrayPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8durationPdS_S_iid            # -- Begin function _Z8durationPdS_S_iid
	.type	_Z8durationPdS_S_iid,@function
_Z8durationPdS_S_iid:                   # @_Z8durationPdS_S_iid
	.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
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movl	%r8d, %ebp
	movl	%ecx, %r12d
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r15
	leaq	24(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	%ebp, %edi
	btsq	$32, %rdi
	movl	%r12d, %edx
	btsq	$32, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_2
# %bb.1:
	movq	%r15, %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	movl	$40000, %ecx                    # imm = 0x9C40
	callq	_Z22__device_stub__diffGPUPdS_S_i
.LBB6_2:
	movq	(%rsp), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movl	$320000, %edi                   # imm = 0x4E200
	callq	_Znam
	movq	%rax, %r14
	movl	$320000, %edx                   # imm = 0x4E200
	movq	%rax, %rdi
	movq	%rbx, %rsi
	movl	$2, %ecx
	callq	hipMemcpy
	xorpd	%xmm0, %xmm0
.LBB6_3:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	addsd	(%r14,%r15,8), %xmm0
	incq	%r15
	cmpq	$40000, %r15                    # imm = 0x9C40
	jne	.LBB6_3
# %bb.4:                                # %_Z8sumArrayPdi.exit
	movq	%r14, %rdi
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	callq	_ZdaPv
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	ucomisd	16(%rsp), %xmm0                 # 8-byte Folded Reload
	jne	.LBB6_6
	jp	.LBB6_6
# %bb.5:
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	36(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	movss	(%rbx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	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
.LBB6_6:
	.cfi_def_cfa_offset 96
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	_Z8durationPdS_S_iid, .Lfunc_end6-_Z8durationPdS_S_iid
	.cfi_endproc
                                        # -- End function
	.globl	_Z15averageDurationPdS_S_iidi   # -- Begin function _Z15averageDurationPdS_S_iidi
	.type	_Z15averageDurationPdS_S_iidi,@function
_Z15averageDurationPdS_S_iidi:          # @_Z15averageDurationPdS_S_iidi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	testl	%r9d, %r9d
	movl	%r9d, 4(%rsp)                   # 4-byte Spill
	jle	.LBB7_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%r8d, %ebp
	movl	%ecx, %r14d
	movq	%rdx, %r15
	movq	%rsi, %r12
	movq	%rdi, %r13
	xorpd	%xmm1, %xmm1
	movl	%r9d, %ebx
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
.LBB7_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	movq	%r13, %rdi
	movq	%r12, %rsi
	movq	%r15, %rdx
	movl	%r14d, %ecx
	movl	%ebp, %r8d
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_Z8durationPdS_S_iid
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm1
	decl	%ebx
	jne	.LBB7_4
	jmp	.LBB7_2
.LBB7_1:
	xorpd	%xmm1, %xmm1
.LBB7_2:                                # %._crit_edge
	xorps	%xmm0, %xmm0
	cvtsi2sdl	4(%rsp), %xmm0          # 4-byte Folded Reload
	divsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_Z15averageDurationPdS_S_iidi, .Lfunc_end7-_Z15averageDurationPdS_S_iidi
	.cfi_endproc
                                        # -- End function
	.globl	_Z12prepareTablePdS_S_iidi      # -- Begin function _Z12prepareTablePdS_S_iidi
	.type	_Z12prepareTablePdS_S_iidi,@function
_Z12prepareTablePdS_S_iidi:             # @_Z12prepareTablePdS_S_iidi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, %ebx
	movl	%ecx, %ebp
	testl	%r9d, %r9d
	movl	%r9d, 12(%rsp)                  # 4-byte Spill
	jle	.LBB8_1
# %bb.2:                                # %.lr.ph.i.preheader
	movq	%rdx, %r15
	movq	%rsi, %r12
	movq	%rdi, %r13
	xorpd	%xmm1, %xmm1
	movl	%r9d, %r14d
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
.LBB8_3:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movsd	%xmm1, (%rsp)                   # 8-byte Spill
	movq	%r13, %rdi
	movq	%r12, %rsi
	movq	%r15, %rdx
	movl	%ebp, %ecx
	movl	%ebx, %r8d
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_Z8durationPdS_S_iid
	movsd	(%rsp), %xmm1                   # 8-byte Reload
                                        # xmm1 = mem[0],zero
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm1
	decl	%r14d
	jne	.LBB8_3
	jmp	.LBB8_4
.LBB8_1:
	xorpd	%xmm1, %xmm1
.LBB8_4:                                # %_Z15averageDurationPdS_S_iidi.exit
	xorps	%xmm0, %xmm0
	cvtsi2sdl	12(%rsp), %xmm0         # 4-byte Folded Reload
	divsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movl	$.L.str.2, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.4, %edi
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.Lstr, %edi
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end8:
	.size	_Z12prepareTablePdS_S_iidi, .Lfunc_end8-_Z12prepareTablePdS_S_iidi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$640032, %rsp                   # imm = 0x9C420
	.cfi_def_cfa_offset 640080
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	xorl	%ebx, %ebx
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
.LBB9_1:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, 320032(%rsp,%rbx,8)
	incq	%rbx
	cmpq	$40000, %rbx                    # imm = 0x9C40
	jne	.LBB9_1
# %bb.2:                                # %.lr.ph.i14.preheader
	xorl	%ebx, %ebx
.LBB9_3:                                # %.lr.ph.i14
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, 32(%rsp,%rbx,8)
	incq	%rbx
	cmpq	$40000, %rbx                    # imm = 0x9C40
	jne	.LBB9_3
# %bb.4:                                # %_Z13generateArrayPdd.exit17
	leaq	320032(%rsp), %r13
	leaq	32(%rsp), %r12
	movq	%r13, %rdi
	movq	%r12, %rsi
	movl	$40000, %edx                    # imm = 0x9C40
	callq	_Z12sumArrayDiffPdS_i
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	leaq	24(%rsp), %rbx
	movl	$320000, %esi                   # imm = 0x4E200
	movq	%rbx, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %r14
	movl	$320000, %esi                   # imm = 0x4E200
	movq	%r14, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %r15
	movl	$320000, %esi                   # imm = 0x4E200
	movq	%r15, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movl	$320000, %edx                   # imm = 0x4E200
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r14), %rdi
	movl	$320000, %edx                   # imm = 0x4E200
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$15, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$16, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$15, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.12, %esi
	movl	$16, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$157, %ecx
	movl	$256, %r8d                      # imm = 0x100
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$1, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$79, %ecx
	movl	$512, %r8d                      # imm = 0x200
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$40, %ecx
	movl	$1024, %r8d                     # imm = 0x400
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$40000, %ecx                    # imm = 0x9C40
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$20000, %ecx                    # imm = 0x4E20
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$10000, %ecx                    # imm = 0x2710
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$5000, %ecx                     # imm = 0x1388
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$1000, %ecx                     # imm = 0x3E8
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$2, %ecx
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	movq	(%rbx), %rdi
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	movl	$1, %ecx
	movl	$1, %r8d
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movl	$20, %r9d
	callq	_Z12prepareTablePdS_S_iidi
	xorl	%eax, %eax
	addq	$640032, %rsp                   # imm = 0x9C420
	.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_end9:
	.size	main, .Lfunc_end9-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB10_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB10_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7diffGPUPdS_S_i, %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_end10:
	.size	__hip_module_ctor, .Lfunc_end10-__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	.LBB11_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
.LBB11_2:
	retq
.Lfunc_end11:
	.size	__hip_module_dtor, .Lfunc_end11-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z7diffGPUPdS_S_i,@object       # @_Z7diffGPUPdS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z7diffGPUPdS_S_i
	.p2align	3, 0x0
_Z7diffGPUPdS_S_i:
	.quad	_Z22__device_stub__diffGPUPdS_S_i
	.size	_Z7diffGPUPdS_S_i, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Results from CPU and GPU are not same... Exiting..."
	.size	.L.str.1, 52

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

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%24.8f"
	.size	.L.str.4, 7

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"blocksPerGrid"
	.size	.L.str.6, 14

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

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"time to generate"
	.size	.L.str.9, 17

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"-------------"
	.size	.L.str.10, 14

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

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"----------------"
	.size	.L.str.12, 17

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7diffGPUPdS_S_i"
	.size	.L__unnamed_1, 18

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

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

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

	.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 _Z22__device_stub__diffGPUPdS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7diffGPUPdS_S_i
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7diffGPUPdS_S_i       ; -- Begin function _Z7diffGPUPdS_S_i
	.globl	_Z7diffGPUPdS_S_i
	.p2align	8
	.type	_Z7diffGPUPdS_S_i,@function
_Z7diffGPUPdS_S_i:                      ; @_Z7diffGPUPdS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b32 s8, s[0:1], 0x18
	s_add_u32 s2, s0, 32
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s9, s4, 0xffff
	s_mov_b32 s4, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s9, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph
	s_load_b32 s10, s[2:3], 0x0
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s1, s10, s9
	s_mov_b32 s9, 0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	v_add_nc_u32_e32 v1, s1, v1
	v_add_co_u32 v4, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	v_add_co_u32 v6, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v3, vcc_lo
	v_cmp_le_i32_e32 vcc_lo, s8, v1
	global_load_b64 v[4:5], v[4:5], off
	global_load_b64 v[6:7], v[6:7], off
	v_add_co_u32 v2, s0, s2, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s0, s3, v3, s0
	s_or_b32 s9, vcc_lo, s9
	s_waitcnt vmcnt(0)
	v_add_f64 v[4:5], v[4:5], -v[6:7]
	global_store_b64 v[2:3], v[4:5], off
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_2
.LBB0_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7diffGPUPdS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 8
		.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	_Z7diffGPUPdS_S_i, .Lfunc_end0-_Z7diffGPUPdS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 240
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; 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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7diffGPUPdS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7diffGPUPdS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
