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

__device__ float edo_original(float t)
{
	return 9 * (powf(t, 2)) - 4 * t + 5;
}

__global__ void euler_method_gpu(float t, float *y, float delta_t, float m)
{
	int tId = threadIdx.x + blockIdx.x*blockDim.x;
	if(tId < (int) m){
  	y[tId] = y[tId] + delta_t*(4*t - y[tId] + 3 + tId);
	}
}
void euler_method(float t, float *y, int m, float delta_t);
float edo_resuelta(float t, int j);

int main(){
  FILE *fp_time;
  float *y, *y_dev;
  clock_t start_t, end_t, total_t;
  cudaEvent_t ct1, ct2;
  int j, k, counter = 0;
  int block_size, grid_size;
  float m[5] = {powf(10, 4), powf(10, 5), powf(10, 6), powf(10, 7), powf(10, 8)};
	int block_iterate[4] = {64, 128, 256, 512};
  int N = (int) powf(10,3);
  float delta_t = powf(10,-3);
  float time[14];
	float t = 0;
  float dt;

  cudaEventCreate(&ct1); cudaEventCreate(&ct2);
  fp_time = fopen("2_time", "w");

  for(k = 0 ; k < 5 ; k++)
  {
    // Calcular valores iniciales
    y = (float*) malloc(sizeof(float)*m[k]);
    cudaMalloc(&y_dev, sizeof(float)*m[k]);
    for(j = 0; j < m[k]; j++){
      y[j] = j;
    }
    // Copiarlos a GPU
    cudaMemcpy(y_dev, y, m[k]*sizeof(float), cudaMemcpyHostToDevice);

    // CPU CODE
    start_t = clock();
		for(int i = 0; i < N ; i++){
			t = i*delta_t;
			euler_method(t, y, m[k], delta_t);
		}
    end_t = clock();
    total_t = end_t - start_t;
		counter++;
    // GPU CODE
    block_size = 256;
		grid_size = (int)ceil((float) m[k] / block_size);
    cudaEventRecord(ct1);
		for(int i = 0; i < N ; i++){
			t = i*delta_t;
			euler_method_gpu<<<grid_size,block_size>>>(t, y_dev, delta_t, m[k]);
		}
		cudaEventRecord(ct2);
		cudaMemcpy(y, y_dev, m[k]*sizeof(float), cudaMemcpyDeviceToHost);
		cudaEventSynchronize(ct2);
		cudaEventElapsedTime(&dt, ct1, ct2);
    /*
    for(j = 0; j < m[k]; j++){
      fprintf(fp, "Valor obtenido = %f , Valor real = %f j = %d\n", y[j], edo_resuelta(1,j), j+1);
    }
    */
    time[k] = (float) 1000*total_t/CLOCKS_PER_SEC;
    time[5 + k] = dt;
    printf("Tiempo que demora en CPU = %f [ms] para m numero %d\n", ((float) 1000*total_t/CLOCKS_PER_SEC), counter);
    printf("Tiempo que demora en GPU = %f [ms] para m numero %d\n", dt, counter);
	  free(y);
    cudaFree(y_dev);
  }
	//Iteraciones para block_size
	y = (float*) malloc(sizeof(float)*m[4]);
	cudaMalloc(&y_dev, sizeof(float)*m[4]);
	for(j = 0; j < 4; j++){
		block_size = block_iterate[j];
		grid_size = (int)ceil((float) m[4] / block_size);
    cudaEventRecord(ct1);
		for(int i = 0; i < N ; i++){
			t = i*delta_t;
			euler_method_gpu<<<grid_size,block_size>>>(t, y_dev, delta_t, m[4]);
		}
		cudaEventRecord(ct2);
		cudaMemcpy(y, y_dev, m[4]*sizeof(float), cudaMemcpyDeviceToHost);
		cudaEventSynchronize(ct2);
		cudaEventElapsedTime(&dt, ct1, ct2);
		time[10 + j] = dt;
		printf("Tiempo que demora en GPU = %f [ms] para block_size = %d\n", dt, block_size);
	}
	free(y);
	cudaFree(y_dev);
  for(int i = 0; i < 14; i++){
		if((i%5 == 0) && (i != 0)){
			fprintf(fp_time, "\n");
		}
		if(i < 10){
	    fprintf(fp_time, "%f %f ",m[i%5], time[i]);
		}
		else if(i >= 10){
			fprintf(fp_time, "%d %f ",block_iterate[i%5], time[i]);
		}
  }
  fclose(fp_time);
  return 0;
}


void euler_method(float t, float *y, int m, float delta_t){
  for(int j = 0; j < m ; j++){
      y[j] = y[j] + delta_t*(4*t - y[j] + 3 + j);
  }
}

float edo_resuelta(float t, int j)
{
	return expf(-t) + 4*t - 1 + j;
}

	.file	"tmpxft_00371539_00000000-6_Lab2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12edo_originalf
	.type	_Z12edo_originalf, @function
_Z12edo_originalf:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z12edo_originalf, .-_Z12edo_originalf
	.globl	_Z12euler_methodfPfif
	.type	_Z12euler_methodfPfif, @function
_Z12euler_methodfPfif:
.LFB2029:
	.cfi_startproc
	endbr64
	movss	.LC0(%rip), %xmm4
	movss	.LC1(%rip), %xmm5
	xorl	%eax, %eax
.L5:
	cmpl	%eax, %esi
	jle	.L8
	movaps	%xmm0, %xmm2
	movss	(%rdi,%rax,4), %xmm3
	cvtsi2ssl	%eax, %xmm6
	mulss	%xmm4, %xmm2
	subss	%xmm3, %xmm2
	addss	%xmm5, %xmm2
	addss	%xmm6, %xmm2
	mulss	%xmm1, %xmm2
	addss	%xmm3, %xmm2
	movss	%xmm2, (%rdi,%rax,4)
	incq	%rax
	jmp	.L5
.L8:
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z12euler_methodfPfif, .-_Z12euler_methodfPfif
	.globl	_Z12edo_resueltafi
	.type	_Z12edo_resueltafi, @function
_Z12edo_resueltafi:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	movss	%xmm0, 12(%rsp)
	xorps	.LC2(%rip), %xmm0
	call	expf@PLT
	movss	12(%rsp), %xmm1
	mulss	.LC0(%rip), %xmm1
	addss	%xmm0, %xmm1
	subss	.LC3(%rip), %xmm1
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	cvtsi2ssl	%ebx, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 8
	addss	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z12edo_resueltafi, .-_Z12edo_resueltafi
	.globl	_Z39__device_stub__Z16euler_method_gpufPffffPfff
	.type	_Z39__device_stub__Z16euler_method_gpufPffffPfff, @function
_Z39__device_stub__Z16euler_method_gpufPffffPfff:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 16(%rsp)
	leaq	48(%rsp), %rcx
	leaq	40(%rsp), %rdx
	movss	%xmm0, 28(%rsp)
	leaq	68(%rsp), %rsi
	leaq	56(%rsp), %rdi
	movss	%xmm1, 24(%rsp)
	movss	%xmm2, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	12(%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	.L11
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16euler_method_gpufPfff(%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
.L11:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z39__device_stub__Z16euler_method_gpufPffffPfff, .-_Z39__device_stub__Z16euler_method_gpufPffffPfff
	.globl	_Z16euler_method_gpufPfff
	.type	_Z16euler_method_gpufPfff, @function
_Z16euler_method_gpufPfff:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z16euler_method_gpufPffffPfff
	.cfi_endproc
.LFE2056:
	.size	_Z16euler_method_gpufPfff, .-_Z16euler_method_gpufPfff
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"w"
.LC6:
	.string	"2_time"
.LC12:
	.string	"Tiempo que demora en CPU = %f [ms] para m numero %d\n"
.LC13:
	.string	"Tiempo que demora en GPU = %f [ms] para m numero %d\n"
.LC14:
	.string	"Tiempo que demora en GPU = %f [ms] para block_size = %d\n"
.LC15:
	.string	"%f %f "
.LC16:
	.string	"\n"
.LC17:
	.string	"%d %f "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$1, %ebx
	subq	$216, %rsp
	.cfi_def_cfa_offset 272
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	movabsq	$5171064759257939968, %rax
	leaq	64(%rsp), %rdi
	movl	$0x4cbebc20, 140(%rsp)
	movq	%rax, 124(%rsp)
	movabsq	$5411240430017979392, %rax
	movq	%rax, 132(%rsp)
	movabsq	$549755813952, %rax
	movq	%rax, 108(%rsp)
	movabsq	$2199023255808, %rax
	movq	%rax, 116(%rsp)
	call	cudaEventCreate@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC5(%rip), %rsi
	leaq	.LC6(%rip), %rdi
	call	fopen@PLT
	movq	%rax, 16(%rsp)
.L24:
	movss	120(%rsp,%rbx,4), %xmm3
	movss	.LC0(%rip), %xmm0
	mulss	%xmm3, %xmm0
	movss	%xmm3, 8(%rsp)
	comiss	.LC7(%rip), %xmm0
	jnb	.L17
	cvttss2siq	%xmm0, %r12
	jmp	.L18
.L17:
	subss	.LC7(%rip), %xmm0
	cvttss2siq	%xmm0, %r12
	btcq	$63, %r12
.L18:
	movq	%r12, %rdi
	call	malloc@PLT
	leaq	56(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	xorl	%eax, %eax
.L19:
	cvtsi2ssl	%eax, %xmm0
	movss	8(%rsp), %xmm5
	comiss	%xmm0, %xmm5
	jbe	.L41
	movss	%xmm0, 0(%rbp,%rax,4)
	incq	%rax
	jmp	.L19
.L41:
	movq	56(%rsp), %rdi
	movq	%r12, %rdx
	movl	$1, %ecx
	movq	%rbp, %rsi
	call	cudaMemcpy@PLT
	call	clock@PLT
	xorl	%edx, %edx
	movq	%rax, %r13
.L21:
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC8(%rip), %xmm0
	movq	%rbp, %rdi
	incl	%edx
	cvttss2sil	8(%rsp), %esi
	movss	.LC8(%rip), %xmm1
	call	_Z12euler_methodfPfif
	cmpl	$1000, %edx
	jne	.L21
	call	clock@PLT
	movss	8(%rsp), %xmm0
	mulss	.LC9(%rip), %xmm0
	movl	%ebx, 28(%rsp)
	movabsq	$4294967552, %r14
	subq	%r13, %rax
	xorl	%r13d, %r13d
	movq	%rax, 40(%rsp)
	call	ceilf@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	cvttss2sil	%xmm0, %r15d
	call	cudaEventRecord@PLT
.L23:
	movl	%r15d, 84(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r14, %rdx
	movabsq	$4294967297, %rax
	movl	$1, %ecx
	movq	%r14, 96(%rsp)
	movq	%rax, 88(%rsp)
	movq	84(%rsp), %rdi
	movl	92(%rsp), %esi
	movl	$1, 104(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	cvtsi2ssl	%r13d, %xmm0
	movss	8(%rsp), %xmm2
	movq	56(%rsp), %rdi
	mulss	.LC8(%rip), %xmm0
	movss	.LC8(%rip), %xmm1
	call	_Z39__device_stub__Z16euler_method_gpufPffffPfff
.L22:
	incl	%r13d
	cmpl	$1000, %r13d
	jne	.L23
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rsi
	movq	%r12, %rdx
	movq	%rbp, %rdi
	movl	$2, %ecx
	leaq	144(%rsp), %r12
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	leaq	52(%rsp), %rax
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	28(%rsp), %edx
	movl	$2, %edi
	movb	$1, %al
	movss	52(%rsp), %xmm1
	cvtsi2ssq	40(%rsp), %xmm0
	leaq	.LC12(%rip), %rsi
	mulss	.LC10(%rip), %xmm0
	movss	%xmm1, 160(%rsp,%rbx,4)
	divss	.LC11(%rip), %xmm0
	movss	%xmm0, 140(%rsp,%rbx,4)
	cvtss2sd	%xmm0, %xmm0
	incq	%rbx
	call	__printf_chk@PLT
	movl	28(%rsp), %edx
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC13(%rip), %rsi
	cvtss2sd	52(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	cmpq	$6, %rbx
	jne	.L24
	movl	$400000000, %edi
	xorl	%ebx, %ebx
	movabsq	$4294967297, %r14
	call	malloc@PLT
	leaq	56(%rsp), %rdi
	movl	$400000000, %esi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
.L27:
	movl	108(%rsp,%rbx), %r13d
	movss	.LC4(%rip), %xmm0
	xorl	%ebp, %ebp
	cvtsi2ssl	%r13d, %xmm1
	divss	%xmm1, %xmm0
	call	ceilf@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	cvttss2sil	%xmm0, %r15d
	call	cudaEventRecord@PLT
.L26:
	movq	%r14, 100(%rsp)
	movl	104(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r14, 88(%rsp)
	movl	92(%rsp), %esi
	movl	%r13d, 96(%rsp)
	movq	96(%rsp), %rdx
	movl	%r15d, 84(%rsp)
	movq	84(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	cvtsi2ssl	%ebp, %xmm0
	mulss	.LC8(%rip), %xmm0
	movq	56(%rsp), %rdi
	movss	.LC4(%rip), %xmm2
	movss	.LC8(%rip), %xmm1
	call	_Z39__device_stub__Z16euler_method_gpufPffffPfff
.L25:
	incl	%ebp
	cmpl	$1000, %ebp
	jne	.L26
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$2, %ecx
	movl	$400000000, %edx
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	52(%rsp), %xmm0
	movl	%r13d, %edx
	movb	$1, %al
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	movss	%xmm0, 184(%rsp,%rbx)
	addq	$4, %rbx
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	cmpq	$16, %rbx
	jne	.L27
	movq	8(%rsp), %rdi
	xorl	%ebx, %ebx
	leaq	.LC17(%rip), %r13
	call	free@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
.L33:
	movl	%ebx, %eax
	movl	$5, %ecx
	leaq	1(%rbx), %r14
	cltd
	idivl	%ecx
	testl	%edx, %edx
	movslq	%edx, %rbp
	jne	.L28
	testq	%rbx, %rbx
	jne	.L29
.L31:
	movq	16(%rsp), %rdi
	leaq	.LC15(%rip), %rdx
	movl	$2, %esi
	movb	$2, %al
	cvtss2sd	(%r12,%rbx,4), %xmm1
	cvtss2sd	124(%rsp,%rbp,4), %xmm0
	movq	%r14, %rbx
	call	__fprintf_chk@PLT
	jmp	.L33
.L29:
	movq	16(%rsp), %rdi
	leaq	.LC16(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L28:
	movss	(%r12,%rbx,4), %xmm0
	cmpq	$9, %rbx
	jbe	.L31
	movl	108(%rsp,%rbp,4), %ecx
	movq	16(%rsp), %rdi
	movq	%r13, %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	%xmm0, %xmm0
	movq	%r14, %rbx
	call	__fprintf_chk@PLT
	cmpq	$14, %r14
	jne	.L33
	movq	16(%rsp), %rdi
	call	fclose@PLT
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$216, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z16euler_method_gpufPfff"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z16euler_method_gpufPfff(%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
.LFE2058:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1082130432
	.align 4
.LC1:
	.long	1077936128
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4
	.align 4
.LC3:
	.long	1065353216
	.align 4
.LC4:
	.long	1287568416
	.align 4
.LC7:
	.long	1593835520
	.align 4
.LC8:
	.long	981668463
	.align 4
.LC9:
	.long	998244352
	.align 4
.LC10:
	.long	1148846080
	.align 4
.LC11:
	.long	1232348160
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


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

__device__ float edo_original(float t)
{
	return 9 * (powf(t, 2)) - 4 * t + 5;
}

__global__ void euler_method_gpu(float t, float *y, float delta_t, float m)
{
	int tId = threadIdx.x + blockIdx.x*blockDim.x;
	if(tId < (int) m){
  	y[tId] = y[tId] + delta_t*(4*t - y[tId] + 3 + tId);
	}
}
void euler_method(float t, float *y, int m, float delta_t);
float edo_resuelta(float t, int j);

int main(){
  FILE *fp_time;
  float *y, *y_dev;
  clock_t start_t, end_t, total_t;
  hipEvent_t ct1, ct2;
  int j, k, counter = 0;
  int block_size, grid_size;
  float m[5] = {powf(10, 4), powf(10, 5), powf(10, 6), powf(10, 7), powf(10, 8)};
	int block_iterate[4] = {64, 128, 256, 512};
  int N = (int) powf(10,3);
  float delta_t = powf(10,-3);
  float time[14];
	float t = 0;
  float dt;

  hipEventCreate(&ct1); hipEventCreate(&ct2);
  fp_time = fopen("2_time", "w");

  for(k = 0 ; k < 5 ; k++)
  {
    // Calcular valores iniciales
    y = (float*) malloc(sizeof(float)*m[k]);
    hipMalloc(&y_dev, sizeof(float)*m[k]);
    for(j = 0; j < m[k]; j++){
      y[j] = j;
    }
    // Copiarlos a GPU
    hipMemcpy(y_dev, y, m[k]*sizeof(float), hipMemcpyHostToDevice);

    // CPU CODE
    start_t = clock();
		for(int i = 0; i < N ; i++){
			t = i*delta_t;
			euler_method(t, y, m[k], delta_t);
		}
    end_t = clock();
    total_t = end_t - start_t;
		counter++;
    // GPU CODE
    block_size = 256;
		grid_size = (int)ceil((float) m[k] / block_size);
    hipEventRecord(ct1);
		for(int i = 0; i < N ; i++){
			t = i*delta_t;
			euler_method_gpu<<<grid_size,block_size>>>(t, y_dev, delta_t, m[k]);
		}
		hipEventRecord(ct2);
		hipMemcpy(y, y_dev, m[k]*sizeof(float), hipMemcpyDeviceToHost);
		hipEventSynchronize(ct2);
		hipEventElapsedTime(&dt, ct1, ct2);
    /*
    for(j = 0; j < m[k]; j++){
      fprintf(fp, "Valor obtenido = %f , Valor real = %f j = %d\n", y[j], edo_resuelta(1,j), j+1);
    }
    */
    time[k] = (float) 1000*total_t/CLOCKS_PER_SEC;
    time[5 + k] = dt;
    printf("Tiempo que demora en CPU = %f [ms] para m numero %d\n", ((float) 1000*total_t/CLOCKS_PER_SEC), counter);
    printf("Tiempo que demora en GPU = %f [ms] para m numero %d\n", dt, counter);
	  free(y);
    hipFree(y_dev);
  }
	//Iteraciones para block_size
	y = (float*) malloc(sizeof(float)*m[4]);
	hipMalloc(&y_dev, sizeof(float)*m[4]);
	for(j = 0; j < 4; j++){
		block_size = block_iterate[j];
		grid_size = (int)ceil((float) m[4] / block_size);
    hipEventRecord(ct1);
		for(int i = 0; i < N ; i++){
			t = i*delta_t;
			euler_method_gpu<<<grid_size,block_size>>>(t, y_dev, delta_t, m[4]);
		}
		hipEventRecord(ct2);
		hipMemcpy(y, y_dev, m[4]*sizeof(float), hipMemcpyDeviceToHost);
		hipEventSynchronize(ct2);
		hipEventElapsedTime(&dt, ct1, ct2);
		time[10 + j] = dt;
		printf("Tiempo que demora en GPU = %f [ms] para block_size = %d\n", dt, block_size);
	}
	free(y);
	hipFree(y_dev);
  for(int i = 0; i < 14; i++){
		if((i%5 == 0) && (i != 0)){
			fprintf(fp_time, "\n");
		}
		if(i < 10){
	    fprintf(fp_time, "%f %f ",m[i%5], time[i]);
		}
		else if(i >= 10){
			fprintf(fp_time, "%d %f ",block_iterate[i%5], time[i]);
		}
  }
  fclose(fp_time);
  return 0;
}


void euler_method(float t, float *y, int m, float delta_t){
  for(int j = 0; j < m ; j++){
      y[j] = y[j] + delta_t*(4*t - y[j] + 3 + j);
  }
}

float edo_resuelta(float t, int j)
{
	return expf(-t) + 4*t - 1 + j;
}

	.text
	.file	"Lab2.hip"
	.globl	_Z31__device_stub__euler_method_gpufPfff # -- Begin function _Z31__device_stub__euler_method_gpufPfff
	.type	_Z31__device_stub__euler_method_gpufPfff,@function
_Z31__device_stub__euler_method_gpufPfff: # @_Z31__device_stub__euler_method_gpufPfff
	.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	20(%rsp), %rax
	movss	%xmm0, (%rax)
	leaq	40(%rsp), %rcx
	movq	%rdi, (%rcx)
	leaq	16(%rsp), %rdx
	movss	%xmm1, (%rdx)
	leaq	12(%rsp), %rsi
	movss	%xmm2, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdx, 16(%rbx)
	movq	%rsi, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z16euler_method_gpufPfff, %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	_Z31__device_stub__euler_method_gpufPfff, .Lfunc_end0-_Z31__device_stub__euler_method_gpufPfff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x461c4000                      # float 1.0E+4
	.long	0x47c35000                      # float 1.0E+5
	.long	0x49742400                      # float 1.0E+6
	.long	0x4b189680                      # float 1.0E+7
.LCPI1_1:
	.long	64                              # 0x40
	.long	128                             # 0x80
	.long	256                             # 0x100
	.long	512                             # 0x200
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI1_2:
	.long	0x40800000                      # float 4
.LCPI1_3:
	.long	0x5f000000                      # float 9.22337203E+18
.LCPI1_4:
	.long	0x3a83126f                      # float 0.00100000005
.LCPI1_5:
	.long	0x40400000                      # float 3
.LCPI1_6:
	.long	0x3b800000                      # float 0.00390625
.LCPI1_7:
	.long	0x447a0000                      # float 1000
.LCPI1_8:
	.long	0x49742400                      # float 1.0E+6
.LCPI1_9:
	.long	0x4cbebc20                      # float 1.0E+8
.LCPI1_10:
	.long	0x00000000                      # float 0
	.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	$152, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$4294967296, %rbx               # imm = 0x100000000
	movaps	.LCPI1_0(%rip), %xmm0           # xmm0 = [1.0E+4,1.0E+5,1.0E+6,1.0E+7]
	movaps	%xmm0, 48(%rsp)
	movl	$1287568416, 64(%rsp)           # imm = 0x4CBEBC20
	movaps	.LCPI1_1(%rip), %xmm0           # xmm0 = [64,128,256,512]
	movaps	%xmm0, 80(%rsp)
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	xorl	%r14d, %r14d
	movss	.LCPI1_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	leaq	256(%rbx), %r15
.LBB1_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
                                        #     Child Loop BB1_5 Depth 2
                                        #       Child Loop BB1_7 Depth 3
                                        #     Child Loop BB1_10 Depth 2
	movss	48(%rsp,%r14,4), %xmm0          # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rsp)                   # 4-byte Spill
	mulss	%xmm1, %xmm0
	cvttss2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subss	.LCPI1_3(%rip), %xmm0
	cvttss2si	%xmm0, %rbp
	andq	%rcx, %rbp
	orq	%rax, %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r13
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	movss	(%rsp), %xmm1                   # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	ucomiss	.LCPI1_10(%rip), %xmm1
	jbe	.LBB1_4
# %bb.2:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_1 Depth=1
	xorps	%xmm0, %xmm0
	xorl	%eax, %eax
.LBB1_3:                                # %.lr.ph
                                        #   Parent Loop BB1_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	%xmm0, (%r13,%rax,4)
	incq	%rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	ucomiss	%xmm0, %xmm1
	ja	.LBB1_3
.LBB1_4:                                # %._crit_edge
                                        #   in Loop: Header=BB1_1 Depth=1
	movq	8(%rsp), %rdi
	movq	%r13, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, %r12
	cvttss2si	(%rsp), %eax            # 4-byte Folded Reload
	xorl	%ecx, %ecx
	movss	.LCPI1_4(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	movss	.LCPI1_2(%rip), %xmm5           # xmm5 = mem[0],zero,zero,zero
	movss	.LCPI1_5(%rip), %xmm6           # xmm6 = mem[0],zero,zero,zero
.LBB1_5:                                #   Parent Loop BB1_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_7 Depth 3
	testl	%eax, %eax
	jle	.LBB1_8
# %bb.6:                                # %.lr.ph.i
                                        #   in Loop: Header=BB1_5 Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	mulss	%xmm4, %xmm0
	mulss	%xmm5, %xmm0
	xorl	%edx, %edx
.LBB1_7:                                #   Parent Loop BB1_1 Depth=1
                                        #     Parent Loop BB1_5 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r13,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movaps	%xmm0, %xmm2
	xorps	%xmm3, %xmm3
	cvtsi2ss	%edx, %xmm3
	subss	%xmm1, %xmm2
	addss	%xmm6, %xmm2
	addss	%xmm2, %xmm3
	mulss	%xmm4, %xmm3
	addss	%xmm1, %xmm3
	movss	%xmm3, (%r13,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rax
	jne	.LBB1_7
.LBB1_8:                                # %_Z12euler_methodfPfif.exit
                                        #   in Loop: Header=BB1_5 Depth=2
	incl	%ecx
	cmpl	$1000, %ecx                     # imm = 0x3E8
	jne	.LBB1_5
# %bb.9:                                #   in Loop: Header=BB1_1 Depth=1
	movq	%r14, 40(%rsp)                  # 8-byte Spill
	callq	clock
	movq	%rax, %r14
	subq	%r12, %r14
	movss	(%rsp), %xmm0                   # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	mulss	.LCPI1_6(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r12d
	movq	24(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %r12
.LBB1_10:                               #   Parent Loop BB1_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.11:                               #   in Loop: Header=BB1_10 Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	movss	.LCPI1_4(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movq	8(%rsp), %rdi
	movss	(%rsp), %xmm2                   # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	callq	_Z31__device_stub__euler_method_gpufPfff
.LBB1_12:                               #   in Loop: Header=BB1_10 Depth=2
	incl	%ebx
	cmpl	$1000, %ebx                     # imm = 0x3E8
	jne	.LBB1_10
# %bb.13:                               #   in Loop: Header=BB1_1 Depth=1
	movq	40(%rsp), %rbx                  # 8-byte Reload
	leaq	1(%rbx), %r12
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	4(%rsp), %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14, %xmm0
	mulss	.LCPI1_7(%rip), %xmm0
	divss	.LCPI1_8(%rip), %xmm0
	movss	%xmm0, 96(%rsp,%rbx,4)
	movss	4(%rsp), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, 116(%rsp,%rbx,4)
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.2, %edi
	movl	%r12d, %esi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%rsp), %xmm0
	movl	$.L.str.3, %edi
	movl	%r12d, %esi
	movb	$1, %al
	callq	printf
	movq	%r13, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r12, %r14
	cmpq	$5, %r12
	movss	.LCPI1_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	jne	.LBB1_1
# %bb.14:
	movl	$400000000, %edi                # imm = 0x17D78400
	callq	malloc
	movq	%rax, %r14
	leaq	8(%rsp), %rdi
	movl	$400000000, %esi                # imm = 0x17D78400
	callq	hipMalloc
	xorl	%ebx, %ebx
.LBB1_15:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_16 Depth 2
	movl	80(%rsp,%rbx,4), %r12d
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r12d, %xmm1
	movss	.LCPI1_9(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r13d
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %r13
	movq	%r12, %rbp
	orq	%rax, %rbp
	xorl	%r15d, %r15d
.LBB1_16:                               #   Parent Loop BB1_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_18
# %bb.17:                               #   in Loop: Header=BB1_16 Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	movss	.LCPI1_4(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movq	8(%rsp), %rdi
	movss	.LCPI1_9(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	callq	_Z31__device_stub__euler_method_gpufPfff
.LBB1_18:                               #   in Loop: Header=BB1_16 Depth=2
	incl	%r15d
	cmpl	$1000, %r15d                    # imm = 0x3E8
	jne	.LBB1_16
# %bb.19:                               #   in Loop: Header=BB1_15 Depth=1
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rsi
	movl	$400000000, %edx                # imm = 0x17D78400
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	4(%rsp), %rdi
	callq	hipEventElapsedTime
	movss	4(%rsp), %xmm0                  # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 136(%rsp,%rbx,4)
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.4, %edi
	movl	%r12d, %esi
	movb	$1, %al
	callq	printf
	incq	%rbx
	cmpq	$4, %rbx
	jne	.LBB1_15
# %bb.20:
	movq	%r14, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	xorl	%r14d, %r14d
	movabsq	$-3689348814741910323, %rbx     # imm = 0xCCCCCCCCCCCCCCCD
	leaq	80(%rsp), %r12
	leaq	48(%rsp), %r13
	movq	32(%rsp), %rbp                  # 8-byte Reload
.LBB1_21:                               # =>This Inner Loop Header: Depth=1
	movq	%r14, %rax
	mulq	%rbx
	movq	%rdx, %r15
	testq	%r14, %r14
	je	.LBB1_24
# %bb.22:                               #   in Loop: Header=BB1_21 Depth=1
	movzbl	%r14b, %eax
	imull	$205, %eax, %eax
	shrl	$10, %eax
	leal	(%rax,%rax,4), %eax
	movl	%r14d, %ecx
	subl	%eax, %ecx
	testb	%cl, %cl
	jne	.LBB1_24
# %bb.23:                               #   in Loop: Header=BB1_21 Depth=1
	movl	$10, %edi
	movq	%rbp, %rsi
	callq	fputc@PLT
.LBB1_24:                               #   in Loop: Header=BB1_21 Depth=1
	andq	$-4, %r15
	leaq	(%r15,%r15,4), %rax
	cmpq	$9, %r14
	ja	.LBB1_26
# %bb.25:                               #   in Loop: Header=BB1_21 Depth=1
	movq	%r13, %rcx
	subq	%rax, %rcx
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rcx,%r14,4), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	96(%rsp,%r14,4), %xmm1
	movl	$.L.str.6, %esi
	movq	%rbp, %rdi
	movb	$2, %al
	callq	fprintf
	jmp	.LBB1_27
.LBB1_26:                               #   in Loop: Header=BB1_21 Depth=1
	movq	%r12, %rcx
	subq	%rax, %rcx
	movl	(%rcx,%r14,4), %edx
	xorps	%xmm0, %xmm0
	cvtss2sd	96(%rsp,%r14,4), %xmm0
	movl	$.L.str.7, %esi
	movq	%rbp, %rdi
	movb	$1, %al
	callq	fprintf
.LBB1_27:                               #   in Loop: Header=BB1_21 Depth=1
	incq	%r14
	cmpq	$14, %r14
	jne	.LBB1_21
# %bb.28:
	movq	%rbp, %rdi
	callq	fclose
	xorl	%eax, %eax
	addq	$152, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z12euler_methodfPfif
.LCPI2_0:
	.long	0x40800000                      # float 4
.LCPI2_1:
	.long	0x40400000                      # float 3
	.text
	.globl	_Z12euler_methodfPfif
	.type	_Z12euler_methodfPfif,@function
_Z12euler_methodfPfif:                  # @_Z12euler_methodfPfif
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph
	mulss	.LCPI2_0(%rip), %xmm0
	movl	%esi, %eax
	xorl	%ecx, %ecx
	movss	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rcx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm0, %xmm4
	xorps	%xmm5, %xmm5
	cvtsi2ss	%ecx, %xmm5
	subss	%xmm3, %xmm4
	addss	%xmm2, %xmm4
	addss	%xmm4, %xmm5
	mulss	%xmm1, %xmm5
	addss	%xmm3, %xmm5
	movss	%xmm5, (%rdi,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z12euler_methodfPfif, .Lfunc_end2-_Z12euler_methodfPfif
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z12edo_resueltafi
.LCPI3_0:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI3_1:
	.long	0x40800000                      # float 4
.LCPI3_2:
	.long	0xbf800000                      # float -1
	.text
	.globl	_Z12edo_resueltafi
	.type	_Z12edo_resueltafi,@function
_Z12edo_resueltafi:                     # @_Z12edo_resueltafi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	movaps	%xmm0, %xmm1
	movaps	%xmm0, (%rsp)                   # 16-byte Spill
	movaps	.LCPI3_0(%rip), %xmm0           # xmm0 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	xorps	%xmm1, %xmm0
	callq	expf
	movaps	(%rsp), %xmm1                   # 16-byte Reload
	mulss	.LCPI3_1(%rip), %xmm1
	addss	%xmm1, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ebx, %xmm1
	addss	.LCPI3_2(%rip), %xmm0
	addss	%xmm1, %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z12edo_resueltafi, .Lfunc_end3-_Z12edo_resueltafi
	.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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16euler_method_gpufPfff, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z16euler_method_gpufPfff,@object # @_Z16euler_method_gpufPfff
	.section	.rodata,"a",@progbits
	.globl	_Z16euler_method_gpufPfff
	.p2align	3, 0x0
_Z16euler_method_gpufPfff:
	.quad	_Z31__device_stub__euler_method_gpufPfff
	.size	_Z16euler_method_gpufPfff, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"w"
	.size	.L.str.1, 2

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Tiempo que demora en CPU = %f [ms] para m numero %d\n"
	.size	.L.str.2, 53

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Tiempo que demora en GPU = %f [ms] para m numero %d\n"
	.size	.L.str.3, 53

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Tiempo que demora en GPU = %f [ms] para block_size = %d\n"
	.size	.L.str.4, 57

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16euler_method_gpufPfff"
	.size	.L__unnamed_1, 26

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z31__device_stub__euler_method_gpufPfff
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z16euler_method_gpufPfff
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16euler_method_gpufPfff ; -- Begin function _Z16euler_method_gpufPfff
	.globl	_Z16euler_method_gpufPfff
	.p2align	8
	.type	_Z16euler_method_gpufPfff,@function
_Z16euler_method_gpufPfff:              ; @_Z16euler_method_gpufPfff
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cvt_i32_f32_e32 v0, s3
	s_mov_b32 s3, exec_lo
	v_cmpx_lt_i32_e64 v1, v0
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b64 s[4:5], s[0:1], 0x8
	v_ashrrev_i32_e32 v2, 31, v1
	s_load_b32 s0, s[0:1], 0x0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_cvt_f32_i32_e32 v1, v1
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v0, v[2:3], off
	s_waitcnt vmcnt(0)
	v_fma_f32 v4, s0, 4.0, -v0
	v_add_f32_e32 v4, 0x40400000, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v1, v4, v1
	v_fmac_f32_e32 v0, s2, v1
	global_store_b32 v[2:3], v0, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16euler_method_gpufPfff
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 5
		.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	_Z16euler_method_gpufPfff, .Lfunc_end0-_Z16euler_method_gpufPfff
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 180
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .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:           _Z16euler_method_gpufPfff
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16euler_method_gpufPfff.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
