// Simple CUDA example by Ingemar Ragnemalm 2009. Simplest possible?
// Assigns every element in an array with its index.

// nvcc simple.cu -L /usr/local/cuda/lib -lcudart -o simple

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>


static struct timeval timeStart;
static char hasStart = 0;

int GetMilliseconds()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	if (!hasStart)
	{
		hasStart = 1;
		timeStart = tv;
	}
	return (tv.tv_usec - timeStart.tv_usec) / 1000 + (tv.tv_sec - timeStart.tv_sec)*1000;
}

int GetMicroseconds()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	if (!hasStart)
	{
		hasStart = 1;
		timeStart = tv;
	}
	return (tv.tv_usec - timeStart.tv_usec) + (tv.tv_sec - timeStart.tv_sec)*1000000;
}

double GetSeconds()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	if (!hasStart)
	{
		hasStart = 1;
		timeStart = tv;
	}
	return (double)(tv.tv_usec - timeStart.tv_usec) / 1000000.0 + (double)(tv.tv_sec - timeStart.tv_sec);
}

// If you want to start from right now.
void ResetMilli()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	hasStart = 1;
	timeStart = tv;
}

// If you want to start from a specific time.
void SetMilli(int seconds, int microseconds)
{
	hasStart = 1;
	timeStart.tv_sec = seconds;
	timeStart.tv_usec = microseconds;
}

// problem size (N*N)
const int N = 2048*2; 

// max blocksize
const int blocksize = 16; 

const int grid_N = N / blocksize;

__global__ 
void simple(float *a,float *b,float *c) 
{
	//int idx = blockIdx.x * blockDim.x + threadIdx.x;
	//int index = threadIdx.y * blockDim.x + threadIdx.x;
	
	int index_x = blockIdx.x * blockDim.x + threadIdx.x;    
	int index_y = blockIdx.y * blockDim.y + threadIdx.y;
	int grid_width = gridDim.x * blockDim.x;
	int grid_height = gridDim.y * blockDim.y;

	//get the global index 
	int global_idx = index_y * grid_width + index_x;
	//int global_idx = index_x * grid_height + index_y;

	c[global_idx] = a[global_idx] + b[global_idx];
}

void add_matrix(float *a, float *b, float *c, int N)
{
	int index;
	
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
		{
			index = i + j*N;
			c[index] = a[index] + b[index];
		}
}


int main()
{
	float *a = new float[N*N];
	float *b = new float[N*N];
	float *c = new float[N*N];

	cudaEvent_t myEventStart;
	cudaEvent_t myEventStop;
	cudaEvent_t myEventStart_withoutcopy;
	cudaEvent_t myEventStop_withoutcopy;
	cudaEventCreate(&myEventStart);
	cudaEventCreate(&myEventStop);
	cudaEventCreate(&myEventStart_withoutcopy);
	cudaEventCreate(&myEventStop_withoutcopy);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)
		{
			a[i+j*N] = 10 + i;
			b[i+j*N] = (float)j / N;
		}
	}

	float *ad;
	float *bd;
	float *cd;
	const int size = N*N*sizeof(float);
	
	cudaEventRecord(myEventStart, 0);
	cudaEventSynchronize(myEventStart);

	cudaMalloc( (void**)&ad, size );
	cudaMalloc( (void**)&bd, size );
	cudaMalloc( (void**)&cd, size );
	cudaMemcpy( ad, a, size, cudaMemcpyHostToDevice ); 
	cudaMemcpy( bd, b, size, cudaMemcpyHostToDevice ); 


	dim3 dimBlock( N / grid_N, N / grid_N );
	dim3 dimGrid( grid_N, grid_N );


	cudaEventRecord(myEventStart_withoutcopy, 0);
	cudaEventSynchronize(myEventStart_withoutcopy);

	simple<<<dimGrid, dimBlock>>>(ad,bd,cd);
	cudaThreadSynchronize();


	cudaEventRecord(myEventStop_withoutcopy, 0);
	cudaEventSynchronize(myEventStop_withoutcopy);
	
	cudaMemcpy( c, cd, size, cudaMemcpyDeviceToHost ); 

	cudaFree( ad );
	cudaFree( bd );
	cudaFree( cd );

	cudaEventRecord(myEventStop, 0);
	cudaEventSynchronize(myEventStop);

	float theTime;
	cudaEventElapsedTime(&theTime, myEventStart, myEventStop);


	printf("Problem size (N): %i\n", N);
	printf("blocksize: %i\n", blocksize);
	printf("grid_N: %i\n", grid_N);

	printf("Cuda elapsed time (copy): %f\n", theTime);
	cudaEventElapsedTime(&theTime, myEventStart_withoutcopy, myEventStop_withoutcopy);
	printf("Cuda elapsed time (    ): %f\n", theTime);

	/*
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			printf("%0.2f ", c[i+j*N]);
		}
		printf("\n");
	}
	printf("\n");
	*/


	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)
		{
			a[i+j*N] = 10 + i;
			b[i+j*N] = (float)j / N;
		}
	}

	int cpu_start = GetMicroseconds();
	
	add_matrix(a, b, c, N);

	int cpu_stop = GetMicroseconds();


	printf("CPU elapsed time: %f\n", (cpu_stop - cpu_start) * 1.0e-3);

	/*
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			printf("%0.2f ", c[i+j*N]);
		}
		printf("\n");
	}
	*/
	

	printf("done\n");

	delete[] a;
	delete[] b;
	delete[] c;
	return EXIT_SUCCESS;
}

	.file	"tmpxft_002c050c_00000000-6_matrix_cuda.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15GetMillisecondsv
	.type	_Z15GetMillisecondsv, @function
_Z15GetMillisecondsv:
.LFB2027:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cmpb	$0, _ZL8hasStart(%rip)
	jne	.L3
	movups	8(%rsp), %xmm0
	movb	$1, _ZL8hasStart(%rip)
	movaps	%xmm0, _ZL9timeStart(%rip)
.L3:
	movq	16(%rsp), %rax
	subq	8+_ZL9timeStart(%rip), %rax
	movl	$1000, %ecx
	cqto
	idivq	%rcx
	movq	8(%rsp), %rdx
	subq	_ZL9timeStart(%rip), %rdx
	imull	$1000, %edx, %edx
	addl	%edx, %eax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z15GetMillisecondsv, .-_Z15GetMillisecondsv
	.globl	_Z15GetMicrosecondsv
	.type	_Z15GetMicrosecondsv, @function
_Z15GetMicrosecondsv:
.LFB2028:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cmpb	$0, _ZL8hasStart(%rip)
	jne	.L8
	movups	8(%rsp), %xmm0
	movb	$1, _ZL8hasStart(%rip)
	movaps	%xmm0, _ZL9timeStart(%rip)
.L8:
	movq	8(%rsp), %rax
	subq	_ZL9timeStart(%rip), %rax
	imull	$1000000, %eax, %eax
	subl	8+_ZL9timeStart(%rip), %eax
	addl	16(%rsp), %eax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z15GetMicrosecondsv, .-_Z15GetMicrosecondsv
	.globl	_Z10GetSecondsv
	.type	_Z10GetSecondsv, @function
_Z10GetSecondsv:
.LFB2029:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cmpb	$0, _ZL8hasStart(%rip)
	jne	.L12
	movups	8(%rsp), %xmm2
	movb	$1, _ZL8hasStart(%rip)
	movaps	%xmm2, _ZL9timeStart(%rip)
.L12:
	movq	16(%rsp), %rax
	subq	8+_ZL9timeStart(%rip), %rax
	cvtsi2sdq	%rax, %xmm0
	movq	8(%rsp), %rax
	subq	_ZL9timeStart(%rip), %rax
	divsd	.LC0(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	addsd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z10GetSecondsv, .-_Z10GetSecondsv
	.globl	_Z10ResetMilliv
	.type	_Z10ResetMilliv, @function
_Z10ResetMilliv:
.LFB2030:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	movups	8(%rsp), %xmm0
	movb	$1, _ZL8hasStart(%rip)
	movaps	%xmm0, _ZL9timeStart(%rip)
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z10ResetMilliv, .-_Z10ResetMilliv
	.globl	_Z8SetMilliii
	.type	_Z8SetMilliii, @function
_Z8SetMilliii:
.LFB2031:
	.cfi_startproc
	endbr64
	movslq	%edi, %rdi
	movslq	%esi, %rsi
	movb	$1, _ZL8hasStart(%rip)
	movq	%rdi, _ZL9timeStart(%rip)
	movq	%rsi, 8+_ZL9timeStart(%rip)
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z8SetMilliii, .-_Z8SetMilliii
	.globl	_Z10add_matrixPfS_S_i
	.type	_Z10add_matrixPfS_S_i, @function
_Z10add_matrixPfS_S_i:
.LFB2032:
	.cfi_startproc
	endbr64
	movslq	%ecx, %r8
	movq	%rdi, %r9
	xorl	%edi, %edi
	salq	$2, %r8
.L20:
	cmpl	%edi, %ecx
	jle	.L24
	leaq	0(,%rdi,4), %rax
	xorl	%r10d, %r10d
.L21:
	movss	(%r9,%rax), %xmm0
	addss	(%rsi,%rax), %xmm0
	incl	%r10d
	movss	%xmm0, (%rdx,%rax)
	addq	%r8, %rax
	cmpl	%r10d, %ecx
	jne	.L21
	incq	%rdi
	jmp	.L20
.L24:
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z10add_matrixPfS_S_i, .-_Z10add_matrixPfS_S_i
	.globl	_Z29__device_stub__Z6simplePfS_S_PfS_S_
	.type	_Z29__device_stub__Z6simplePfS_S_PfS_S_, @function
_Z29__device_stub__Z6simplePfS_S_PfS_S_:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z6simplePfS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L25:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z29__device_stub__Z6simplePfS_S_PfS_S_, .-_Z29__device_stub__Z6simplePfS_S_PfS_S_
	.globl	_Z6simplePfS_S_
	.type	_Z6simplePfS_S_, @function
_Z6simplePfS_S_:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z6simplePfS_S_PfS_S_
	.cfi_endproc
.LFE2059:
	.size	_Z6simplePfS_S_, .-_Z6simplePfS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"Problem size (N): %i\n"
.LC3:
	.string	"blocksize: %i\n"
.LC4:
	.string	"grid_N: %i\n"
.LC5:
	.string	"Cuda elapsed time (copy): %f\n"
.LC6:
	.string	"Cuda elapsed time (    ): %f\n"
.LC8:
	.string	"CPU elapsed time: %f\n"
.LC9:
	.string	"done\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$67108864, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$104, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	movl	$67108864, %edi
	movq	%rax, %rbp
	call	_Znam@PLT
	movl	$67108864, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	leaq	8(%rsp), %rdi
	movq	%rax, %r12
	call	cudaEventCreate@PLT
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	xorl	%eax, %eax
.L31:
	leal	10(%rax), %esi
	leaq	0(,%rax,4), %rcx
	xorl	%edx, %edx
	cvtsi2ssl	%esi, %xmm1
.L32:
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC1(%rip), %xmm0
	incl	%edx
	movss	%xmm1, 0(%rbp,%rcx)
	movss	%xmm0, (%rbx,%rcx)
	addq	$16384, %rcx
	cmpl	$4096, %edx
	jne	.L32
	incq	%rax
	cmpq	$4096, %rax
	jne	.L31
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	leaq	40(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	movabsq	$68719476752, %rax
	movq	%rax, 64(%rsp)
	movabsq	$1099511628032, %rax
	movl	$1, 72(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	72(%rsp), %ecx
	movl	84(%rsp), %esi
	xorl	%r9d, %r9d
	movq	64(%rsp), %rdx
	movq	76(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z29__device_stub__Z6simplePfS_S_PfS_S_
.L34:
	call	cudaThreadSynchronize@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	leaq	4(%rsp), %r13
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	16(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	call	cudaEventElapsedTime@PLT
	movl	$4096, %edx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$16, %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$256, %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	4(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r13, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	4(%rsp), %xmm0
	call	__printf_chk@PLT
	xorl	%eax, %eax
.L35:
	leal	10(%rax), %esi
	leaq	0(,%rax,4), %rcx
	xorl	%edx, %edx
	cvtsi2ssl	%esi, %xmm1
.L36:
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC1(%rip), %xmm0
	incl	%edx
	movss	%xmm1, 0(%rbp,%rcx)
	movss	%xmm0, (%rbx,%rcx)
	addq	$16384, %rcx
	cmpl	$4096, %edx
	jne	.L36
	incq	%rax
	cmpq	$4096, %rax
	jne	.L35
	call	_Z15GetMicrosecondsv
	movl	$4096, %ecx
	movq	%r12, %rdx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	movl	%eax, %r13d
	call	_Z10add_matrixPfS_S_i
	call	_Z15GetMicrosecondsv
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	subl	%r13d, %eax
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC7(%rip), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L38:
	addq	$104, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z6simplePfS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6simplePfS_S_(%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
.LFE2061:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL8hasStart
	.comm	_ZL8hasStart,1,1
	.local	_ZL9timeStart
	.comm	_ZL9timeStart,16,16
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1093567616
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	964689920
	.section	.rodata.cst8
	.align 8
.LC7:
	.long	-755914244
	.long	1062232653
	.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:

// Simple CUDA example by Ingemar Ragnemalm 2009. Simplest possible?
// Assigns every element in an array with its index.

// nvcc simple.cu -L /usr/local/cuda/lib -lcudart -o simple


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


static struct timeval timeStart;
static char hasStart = 0;

int GetMilliseconds()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	if (!hasStart)
	{
		hasStart = 1;
		timeStart = tv;
	}
	return (tv.tv_usec - timeStart.tv_usec) / 1000 + (tv.tv_sec - timeStart.tv_sec)*1000;
}

int GetMicroseconds()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	if (!hasStart)
	{
		hasStart = 1;
		timeStart = tv;
	}
	return (tv.tv_usec - timeStart.tv_usec) + (tv.tv_sec - timeStart.tv_sec)*1000000;
}

double GetSeconds()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	if (!hasStart)
	{
		hasStart = 1;
		timeStart = tv;
	}
	return (double)(tv.tv_usec - timeStart.tv_usec) / 1000000.0 + (double)(tv.tv_sec - timeStart.tv_sec);
}

// If you want to start from right now.
void ResetMilli()
{
	struct timeval tv;
	
	gettimeofday(&tv, NULL);
	hasStart = 1;
	timeStart = tv;
}

// If you want to start from a specific time.
void SetMilli(int seconds, int microseconds)
{
	hasStart = 1;
	timeStart.tv_sec = seconds;
	timeStart.tv_usec = microseconds;
}

// problem size (N*N)
const int N = 2048*2; 

// max blocksize
const int blocksize = 16; 

const int grid_N = N / blocksize;

__global__ 
void simple(float *a,float *b,float *c) 
{
	//int idx = blockIdx.x * blockDim.x + threadIdx.x;
	//int index = threadIdx.y * blockDim.x + threadIdx.x;
	
	int index_x = blockIdx.x * blockDim.x + threadIdx.x;    
	int index_y = blockIdx.y * blockDim.y + threadIdx.y;
	int grid_width = gridDim.x * blockDim.x;
	int grid_height = gridDim.y * blockDim.y;

	//get the global index 
	int global_idx = index_y * grid_width + index_x;
	//int global_idx = index_x * grid_height + index_y;

	c[global_idx] = a[global_idx] + b[global_idx];
}

void add_matrix(float *a, float *b, float *c, int N)
{
	int index;
	
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
		{
			index = i + j*N;
			c[index] = a[index] + b[index];
		}
}


int main()
{
	float *a = new float[N*N];
	float *b = new float[N*N];
	float *c = new float[N*N];

	hipEvent_t myEventStart;
	hipEvent_t myEventStop;
	hipEvent_t myEventStart_withoutcopy;
	hipEvent_t myEventStop_withoutcopy;
	hipEventCreate(&myEventStart);
	hipEventCreate(&myEventStop);
	hipEventCreate(&myEventStart_withoutcopy);
	hipEventCreate(&myEventStop_withoutcopy);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)
		{
			a[i+j*N] = 10 + i;
			b[i+j*N] = (float)j / N;
		}
	}

	float *ad;
	float *bd;
	float *cd;
	const int size = N*N*sizeof(float);
	
	hipEventRecord(myEventStart, 0);
	hipEventSynchronize(myEventStart);

	hipMalloc( (void**)&ad, size );
	hipMalloc( (void**)&bd, size );
	hipMalloc( (void**)&cd, size );
	hipMemcpy( ad, a, size, hipMemcpyHostToDevice ); 
	hipMemcpy( bd, b, size, hipMemcpyHostToDevice ); 


	dim3 dimBlock( N / grid_N, N / grid_N );
	dim3 dimGrid( grid_N, grid_N );


	hipEventRecord(myEventStart_withoutcopy, 0);
	hipEventSynchronize(myEventStart_withoutcopy);

	simple<<<dimGrid, dimBlock>>>(ad,bd,cd);
	hipDeviceSynchronize();


	hipEventRecord(myEventStop_withoutcopy, 0);
	hipEventSynchronize(myEventStop_withoutcopy);
	
	hipMemcpy( c, cd, size, hipMemcpyDeviceToHost ); 

	hipFree( ad );
	hipFree( bd );
	hipFree( cd );

	hipEventRecord(myEventStop, 0);
	hipEventSynchronize(myEventStop);

	float theTime;
	hipEventElapsedTime(&theTime, myEventStart, myEventStop);


	printf("Problem size (N): %i\n", N);
	printf("blocksize: %i\n", blocksize);
	printf("grid_N: %i\n", grid_N);

	printf("Cuda elapsed time (copy): %f\n", theTime);
	hipEventElapsedTime(&theTime, myEventStart_withoutcopy, myEventStop_withoutcopy);
	printf("Cuda elapsed time (    ): %f\n", theTime);

	/*
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			printf("%0.2f ", c[i+j*N]);
		}
		printf("\n");
	}
	printf("\n");
	*/


	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)
		{
			a[i+j*N] = 10 + i;
			b[i+j*N] = (float)j / N;
		}
	}

	int cpu_start = GetMicroseconds();
	
	add_matrix(a, b, c, N);

	int cpu_stop = GetMicroseconds();


	printf("CPU elapsed time: %f\n", (cpu_stop - cpu_start) * 1.0e-3);

	/*
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			printf("%0.2f ", c[i+j*N]);
		}
		printf("\n");
	}
	*/
	

	printf("done\n");

	delete[] a;
	delete[] b;
	delete[] c;
	return EXIT_SUCCESS;
}

	.text
	.file	"matrix_cuda.hip"
	.globl	_Z15GetMillisecondsv            # -- Begin function _Z15GetMillisecondsv
	.type	_Z15GetMillisecondsv,@function
_Z15GetMillisecondsv:                   # @_Z15GetMillisecondsv
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpb	$0, _ZL8hasStart(%rip)
	jne	.LBB0_2
# %bb.1:
	movb	$1, _ZL8hasStart(%rip)
	movups	8(%rsp), %xmm0
	movups	%xmm0, _ZL9timeStart(%rip)
.LBB0_2:
	movq	16(%rsp), %rax
	subq	_ZL9timeStart+8(%rip), %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rcx
	shrq	$63, %rcx
	shrq	$7, %rdx
	movl	8(%rsp), %eax
	subl	_ZL9timeStart(%rip), %eax
	addl	%edx, %ecx
	imull	$1000, %eax, %eax               # imm = 0x3E8
	addl	%ecx, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z15GetMillisecondsv, .Lfunc_end0-_Z15GetMillisecondsv
	.cfi_endproc
                                        # -- End function
	.globl	_Z15GetMicrosecondsv            # -- Begin function _Z15GetMicrosecondsv
	.type	_Z15GetMicrosecondsv,@function
_Z15GetMicrosecondsv:                   # @_Z15GetMicrosecondsv
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpb	$0, _ZL8hasStart(%rip)
	jne	.LBB1_2
# %bb.1:
	movb	$1, _ZL8hasStart(%rip)
	movups	8(%rsp), %xmm0
	movups	%xmm0, _ZL9timeStart(%rip)
.LBB1_2:
	movl	8(%rsp), %eax
	movl	16(%rsp), %ecx
	subl	_ZL9timeStart+8(%rip), %ecx
	subl	_ZL9timeStart(%rip), %eax
	imull	$1000000, %eax, %eax            # imm = 0xF4240
	addl	%ecx, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z15GetMicrosecondsv, .Lfunc_end1-_Z15GetMicrosecondsv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10GetSecondsv
.LCPI2_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z10GetSecondsv
	.type	_Z10GetSecondsv,@function
_Z10GetSecondsv:                        # @_Z10GetSecondsv
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpb	$0, _ZL8hasStart(%rip)
	jne	.LBB2_2
# %bb.1:
	movb	$1, _ZL8hasStart(%rip)
	movups	8(%rsp), %xmm0
	movups	%xmm0, _ZL9timeStart(%rip)
.LBB2_2:
	movq	8(%rsp), %rax
	movq	16(%rsp), %rcx
	subq	_ZL9timeStart+8(%rip), %rcx
	cvtsi2sd	%rcx, %xmm1
	divsd	.LCPI2_0(%rip), %xmm1
	subq	_ZL9timeStart(%rip), %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm1, %xmm0
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z10GetSecondsv, .Lfunc_end2-_Z10GetSecondsv
	.cfi_endproc
                                        # -- End function
	.globl	_Z10ResetMilliv                 # -- Begin function _Z10ResetMilliv
	.type	_Z10ResetMilliv,@function
_Z10ResetMilliv:                        # @_Z10ResetMilliv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movb	$1, _ZL8hasStart(%rip)
	movups	(%rbx), %xmm0
	movups	%xmm0, _ZL9timeStart(%rip)
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z10ResetMilliv, .Lfunc_end3-_Z10ResetMilliv
	.cfi_endproc
                                        # -- End function
	.globl	_Z8SetMilliii                   # -- Begin function _Z8SetMilliii
	.type	_Z8SetMilliii,@function
_Z8SetMilliii:                          # @_Z8SetMilliii
	.cfi_startproc
# %bb.0:
	movb	$1, _ZL8hasStart(%rip)
	movslq	%edi, %rax
	movq	%rax, _ZL9timeStart(%rip)
	movslq	%esi, %rax
	movq	%rax, _ZL9timeStart+8(%rip)
	retq
.Lfunc_end4:
	.size	_Z8SetMilliii, .Lfunc_end4-_Z8SetMilliii
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__simplePfS_S_ # -- Begin function _Z21__device_stub__simplePfS_S_
	.type	_Z21__device_stub__simplePfS_S_,@function
_Z21__device_stub__simplePfS_S_:        # @_Z21__device_stub__simplePfS_S_
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z6simplePfS_S_, %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_end5:
	.size	_Z21__device_stub__simplePfS_S_, .Lfunc_end5-_Z21__device_stub__simplePfS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z10add_matrixPfS_S_i           # -- Begin function _Z10add_matrixPfS_S_i
	.type	_Z10add_matrixPfS_S_i,@function
_Z10add_matrixPfS_S_i:                  # @_Z10add_matrixPfS_S_i
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB6_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%ecx, %eax
	leaq	(,%rax,4), %rcx
	xorl	%r8d, %r8d
.LBB6_2:                                # %.lr.ph.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_3 Depth 2
	movq	%rax, %r9
	xorl	%r10d, %r10d
.LBB6_3:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rdi,%r10), %xmm0              # xmm0 = mem[0],zero,zero,zero
	addss	(%rsi,%r10), %xmm0
	movss	%xmm0, (%rdx,%r10)
	addq	%rcx, %r10
	decq	%r9
	jne	.LBB6_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	incq	%r8
	addq	$4, %rdx
	addq	$4, %rsi
	addq	$4, %rdi
	cmpq	%rax, %r8
	jne	.LBB6_2
.LBB6_5:                                # %._crit_edge18
	retq
.Lfunc_end6:
	.size	_Z10add_matrixPfS_S_i, .Lfunc_end6-_Z10add_matrixPfS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI7_0:
	.long	0x39800000                      # float 2.44140625E-4
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI7_1:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	_Znam
	movq	%rax, %rbx
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	_Znam
	movq	%rax, %r14
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	_Znam
	movq	%rax, %r15
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB7_1:                                # %.preheader46
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_2 Depth 2
	leal	10(%rcx), %edx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edx, %xmm0
	movq	%rax, %rdx
	xorl	%esi, %esi
.LBB7_2:                                #   Parent Loop BB7_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	%xmm0, (%rbx,%rdx)
	xorps	%xmm1, %xmm1
	cvtsi2ss	%esi, %xmm1
	mulss	.LCPI7_0(%rip), %xmm1
	movss	%xmm1, (%r14,%rdx)
	incq	%rsi
	addq	$16384, %rdx                    # imm = 0x4000
	cmpq	$4096, %rsi                     # imm = 0x1000
	jne	.LBB7_2
# %bb.3:                                #   in Loop: Header=BB7_1 Depth=1
	incq	%rcx
	addq	$4, %rax
	cmpq	$4096, %rcx                     # imm = 0x1000
	jne	.LBB7_1
# %bb.4:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	56(%rsp), %r12
	movl	$67108864, %esi                 # imm = 0x4000000
	movq	%r12, %rdi
	callq	hipMalloc
	leaq	48(%rsp), %r13
	movl	$67108864, %esi                 # imm = 0x4000000
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	movabsq	$1099511628032, %rdi            # imm = 0x10000000100
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_6
# %bb.5:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	_Z21__device_stub__simplePfS_S_
.LBB7_6:
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rdi
	xorl	%r13d, %r13d
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdx
	leaq	68(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	movl	$.L.str, %edi
	movl	$4096, %esi                     # imm = 0x1000
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.1, %edi
	movl	$16, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.2, %edi
	movl	$256, %esi                      # imm = 0x100
	xorl	%eax, %eax
	callq	printf
	cvtss2sd	(%r12), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12), %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	movss	.LCPI7_0(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
.LBB7_7:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_8 Depth 2
	leal	10(%rax), %ecx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	movq	%r13, %rcx
	xorl	%edx, %edx
.LBB7_8:                                #   Parent Loop BB7_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	%xmm0, (%rbx,%rcx)
	xorps	%xmm1, %xmm1
	cvtsi2ss	%edx, %xmm1
	mulss	%xmm2, %xmm1
	movss	%xmm1, (%r14,%rcx)
	incq	%rdx
	addq	$16384, %rcx                    # imm = 0x4000
	cmpq	$4096, %rdx                     # imm = 0x1000
	jne	.LBB7_8
# %bb.9:                                #   in Loop: Header=BB7_7 Depth=1
	incq	%rax
	addq	$4, %r13
	cmpq	$4096, %rax                     # imm = 0x1000
	jne	.LBB7_7
# %bb.10:
	xorl	%r12d, %r12d
	callq	_Z15GetMicrosecondsv
	movl	%eax, %ebp
	movq	%rbx, %rax
	movq	%r14, %rcx
	movq	%r15, %rdx
.LBB7_11:                               # %.lr.ph.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_12 Depth 2
	xorl	%esi, %esi
.LBB7_12:                               # %.lr.ph.i
                                        #   Parent Loop BB7_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rax,%rsi), %xmm0              # xmm0 = mem[0],zero,zero,zero
	addss	(%rcx,%rsi), %xmm0
	movss	%xmm0, (%rdx,%rsi)
	addq	$16384, %rsi                    # imm = 0x4000
	cmpq	$67108864, %rsi                 # imm = 0x4000000
	jne	.LBB7_12
# %bb.13:                               # %._crit_edge.i
                                        #   in Loop: Header=BB7_11 Depth=1
	incq	%r12
	addq	$4, %rdx
	addq	$4, %rcx
	addq	$4, %rax
	cmpq	$4096, %r12                     # imm = 0x1000
	jne	.LBB7_11
# %bb.14:                               # %_Z10add_matrixPfS_S_i.exit
	callq	_Z15GetMicrosecondsv
	subl	%ebp, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	mulsd	.LCPI7_1(%rip), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_ZdaPv
	movq	%r15, %rdi
	callq	_ZdaPv
	xorl	%eax, %eax
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	main, .Lfunc_end7-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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6simplePfS_S_, %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_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_ZL8hasStart,@object            # @_ZL8hasStart
	.local	_ZL8hasStart
	.comm	_ZL8hasStart,1,1
	.type	_ZL9timeStart,@object           # @_ZL9timeStart
	.local	_ZL9timeStart
	.comm	_ZL9timeStart,16,8
	.type	_Z6simplePfS_S_,@object         # @_Z6simplePfS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z6simplePfS_S_
	.p2align	3, 0x0
_Z6simplePfS_S_:
	.quad	_Z21__device_stub__simplePfS_S_
	.size	_Z6simplePfS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Problem size (N): %i\n"
	.size	.L.str, 22

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"blocksize: %i\n"
	.size	.L.str.1, 15

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"grid_N: %i\n"
	.size	.L.str.2, 12

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Cuda elapsed time (copy): %f\n"
	.size	.L.str.3, 30

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Cuda elapsed time (    ): %f\n"
	.size	.L.str.4, 30

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"CPU elapsed time: %f\n"
	.size	.L.str.5, 22

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6simplePfS_S_"
	.size	.L__unnamed_1, 16

	.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	"done"
	.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 _Z21__device_stub__simplePfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6simplePfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6simplePfS_S_         ; -- Begin function _Z6simplePfS_S_
	.globl	_Z6simplePfS_S_
	.p2align	8
	.type	_Z6simplePfS_S_,@function
_Z6simplePfS_S_:                        ; @_Z6simplePfS_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s3, s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s4, v[1:2]
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[3:4], null, v2, s3, s[14:15]
	v_mad_u64_u32 v[1:2], null, v3, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v1, vcc_lo
	v_add_co_u32 v4, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[4:5], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v2, v2, v3
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6simplePfS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 6
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z6simplePfS_S_, .Lfunc_end0-_Z6simplePfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 204
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .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:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6simplePfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6simplePfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
