/*
 ============================================================================
 Name        : LAB3.cu
 Author      : Kineibe
 Version     :
 Copyright   : Your copyright notice
 Description : CUDA compute reciprocals
 ============================================================================
 */

#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;

static void CheckCudaErrorAux (const char *, unsigned, const char *, cudaError_t);
#define CUDA_CHECK_RETURN(value) CheckCudaErrorAux(__FILE__,__LINE__, #value, value)
#define H_T 0.0001
#define H_X 0.5
#define TOTAL_TIME 10

#define EPSILON 0.001

#define RIGHT_COND 1
#define LEFT_COND 0
#define BLOCK_SIZE_AMOUNT 256

const double A = H_T / (H_X * H_X);
const double B = 2 * A + 1;

double countSum(int k, double* t, int size) {
	if (k == 0) {
		return t[k] * 1;
	} else if (k == size - 1) {
		return -1 * t[k - 1] / H_X + t[k] / H_X;
	} else {
		return -1 * A * t[k - 1] + t[k] / B - A * t[k + 1];
	}
}

double iterationPart(double prev, double multiplier, double f, double sum) {
	return prev + (f - sum) / multiplier;
}

void iteration(double* t_prev, int size, double* f, double* t_result) {
	for (int i = 0; i < size; ++i) {
		double a;
		if (i == 0)
			a = 1;
		else if (i == size - 1)
			a = 1 / H_X;
		else
			a = B;

		double sum = countSum(i, t_prev, size);
		double newT = iterationPart(t_prev[i], a, f[i], sum);
		t_result[i] = newT;
	}
}

bool condition(double* t_prev, double* t_result, int size) {
	double result = 0;
	for (int i = 0; i < size; ++i) {
		result += abs(t_prev[i] - t_result[i]);
	}
	return result < EPSILON;
}

void iterationManager(double* t_prev, int size, double* f, double* t_target) {
	bool check = true;
	double* t_result = new double[size];

	do {
		iteration(t_prev, size, f, t_result);
		check = condition(t_prev, t_result, size);
		double* temp = t_result;
		t_result = t_prev;
		t_prev = temp;
	} while(!check);

	for (int i = 0; i < size; ++i) {
		t_target[i] = t_prev[i];
	}
	delete[] t_result;
}

void printMas(double* arr, int size) {
	for (int i = 0; i < size; ++i) {
		cout << arr[i] << ' ';
	}
	cout << endl;
}

void model(int size) {
	double* t = new double[size];
	for (int i = 0; i < size; ++i) {
		t[i] = 0;
	}

	double* t_next = new double[size];

	double* f = new double[size];
	f[0] = LEFT_COND;
	f[size - 1] = RIGHT_COND;

//	int iterationAmount = TOTAL_TIME / H_T;
	int iterationAmount = 10;
	for (int i = 0; i < iterationAmount; ++i) {
		cout << "Iteration num " << i << endl;
		for (int i = 1; i < size - 1; ++i) {
			f[i] = t[i];
		}
		cout << "F array" << endl;
		printMas(f, size);

		iterationManager(t, size, f, t_next);
		printMas(t_next, size);

		double* temp = t_next;
		t_next = t;
		t = temp;
	}

	delete[] t_next;
	delete[] f;
	delete[] t;
}

/**
 * CUDA kernel that computes reciprocal values for a given vector
 */
__global__ void reciprocalKernel(float *data, float *newData, unsigned vectorSize) {
	unsigned idx = blockIdx.x*blockDim.x+threadIdx.x;
	if (idx < vectorSize) {
		if (idx == vectorSize - 1) {
			newData[idx] = RIGHT_COND * H_T + data[idx];
		} else if (idx == 0) {
			newData[idx] = LEFT_COND;
		} else {
			newData[idx] = data[idx] + (data[idx - 1] - 2 * data[idx] + data[idx + 1]) * H_T / (H_X * H_X);
		}
	}
}

/**
 * Host function that copies the data and launches the work on GPU
 */
void gpuReciprocal(float *data, unsigned size)
{
	cudaEvent_t GPUstart, GPUstop;
	float GPUtime = 0.0f;
	float *rc = new float[size];
	float *gpuOldData;
	float *gpuNewData;

	int iterationAmount = TOTAL_TIME / H_T;

	static const int BLOCK_SIZE = BLOCK_SIZE_AMOUNT;
	const int blockCount = 1000;

	CUDA_CHECK_RETURN(cudaMalloc((void **)&gpuOldData, sizeof(float)*size));
	CUDA_CHECK_RETURN(cudaMalloc((void **)&gpuNewData, sizeof(float)*size));
	CUDA_CHECK_RETURN(cudaMemcpy(gpuOldData, data, sizeof(float)*size, cudaMemcpyHostToDevice));

	cudaEventCreate(&GPUstart);
	cudaEventCreate(&GPUstop);


	for (int i = 0; i < iterationAmount; ++i) {
		cudaEventRecord(GPUstart, 0);

		if (i % 2 == 0) {
			reciprocalKernel<<<blockCount, BLOCK_SIZE>>> (gpuOldData, gpuNewData, size);
			cudaEventRecord(GPUstop, 0);
			CUDA_CHECK_RETURN(cudaMemcpy(rc, gpuNewData, sizeof(float)*size, cudaMemcpyDeviceToHost));
		} else {
			reciprocalKernel<<<blockCount, BLOCK_SIZE>>> (gpuNewData, gpuOldData, size);
			cudaEventRecord(GPUstop, 0);
			CUDA_CHECK_RETURN(cudaMemcpy(rc, gpuOldData, sizeof(float)*size, cudaMemcpyDeviceToHost));
		}
		cudaEventSynchronize(GPUstop);

		float temp;
		cudaEventElapsedTime(&temp, GPUstart, GPUstop);
		GPUtime += temp;
//
//		for (int i = 0; i < size; ++i) {
//			std::cout << "t[" << i << "] = " << rc[i] << std::endl;
//		}
//		std::cout << std::endl;
	}

	printf("GPU time : %.3f ms\n", GPUtime);

	CUDA_CHECK_RETURN(cudaFree(gpuOldData));
	CUDA_CHECK_RETURN(cudaFree(gpuNewData));
}

void initialize(float *data, unsigned size)
{
	for (unsigned i = 0; i < size; ++i)
		data[i] = 0;
}

void cpuIteration(float *data, float *newData, unsigned vectorSize) {
	for (int idx = 0; idx < vectorSize; ++idx) {
		if (idx == vectorSize - 1) {
			newData[idx] = RIGHT_COND * H_T + data[idx];
		} else if (idx == 0) {
			newData[idx] = LEFT_COND;
		} else {
			newData[idx] = data[idx] + (data[idx - 1] - 2 * data[idx] + data[idx + 1]) * H_T / (H_X * H_X);
		}
	}
}

void cpuReciprocal(float *data, unsigned size)
{
	float *rc = new float[size];
	float *oldData = new float[size];

	float* result;

	float CPUstart, CPUstop;
	float CPUtime = 0.0f;

	int iterationAmount = TOTAL_TIME / H_T;

	for (int i = 0; i < iterationAmount; ++i) {

		CPUstart = clock();
		if (i % 2 == 0) {
			cpuIteration(oldData, rc, size);
			result = rc;
		} else {
			cpuIteration(rc, oldData, size);
			result = oldData;
		}
		CPUstop = clock();
		CPUtime += 1000.*(CPUstop - CPUstart) / CLOCKS_PER_SEC;
//
//		for (int i = 0; i < size; ++i) {
//			std::cout << "t[" << i << "] = " << result[i] << std::endl;
//		}
//		std::cout << std::endl;
	}

	printf("CPU time : %.3f ms\n", CPUtime);
}

bool checkShodimost() {
	return true;
}

int main(void)
{
	static const int WORK_SIZE = 256000;
	float *data = new float[WORK_SIZE];

	model(5);


	/* Free memory */
	delete[] data;

	return 0;
}

/**
 * Check the return value of the CUDA runtime API call and exit
 * the application if the call has failed.
 */
static void CheckCudaErrorAux (const char *file, unsigned line, const char *statement, cudaError_t err)
{
	if (err == cudaSuccess)
		return;
	std::cerr << statement<<" returned " << cudaGetErrorString(err) << "("<<err<< ") at "<<file<<":"<<line << std::endl;
	exit (1);
}


	.file	"tmpxft_003247d5_00000000-6_LAB2.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3878:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3878:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" returned "
.LC1:
	.string	"("
.LC2:
	.string	") at "
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/neikila/Cuda/master/LAB2.cu"
.LC4:
	.string	":"
	.text
	.type	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0, @function
_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0:
.LFB4555:
	.cfi_startproc
	testl	%edx, %edx
	je	.L4
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edi, %ebx
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %r12
	call	cudaGetErrorString@PLT
	movq	%r12, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L4:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	.cfi_restore 12
	ret
	.cfi_endproc
.LFE4555:
	.size	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0, .-_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	.globl	_Z8countSumiPdi
	.type	_Z8countSumiPdi, @function
_Z8countSumiPdi:
.LFB3862:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	jne	.L10
	movsd	(%rsi), %xmm0
	ret
.L10:
	movslq	%edi, %rcx
	decl	%edx
	leaq	0(,%rcx,8), %rax
	movsd	(%rsi,%rcx,8), %xmm1
	movsd	-8(%rsi,%rax), %xmm0
	cmpl	%edi, %edx
	jne	.L12
	xorps	.LC5(%rip), %xmm0
	addsd	%xmm1, %xmm1
	addsd	%xmm0, %xmm0
	addsd	%xmm1, %xmm0
	ret
.L12:
	mulsd	.LC6(%rip), %xmm0
	divsd	.LC7(%rip), %xmm1
	addsd	%xmm1, %xmm0
	movsd	.LC8(%rip), %xmm1
	mulsd	8(%rsi,%rax), %xmm1
	subsd	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE3862:
	.size	_Z8countSumiPdi, .-_Z8countSumiPdi
	.globl	_Z13iterationPartdddd
	.type	_Z13iterationPartdddd, @function
_Z13iterationPartdddd:
.LFB3863:
	.cfi_startproc
	endbr64
	subsd	%xmm3, %xmm2
	movaps	%xmm0, %xmm4
	movaps	%xmm2, %xmm0
	divsd	%xmm1, %xmm0
	addsd	%xmm4, %xmm0
	ret
	.cfi_endproc
.LFE3863:
	.size	_Z13iterationPartdddd, .-_Z13iterationPartdddd
	.globl	_Z9iterationPdiS_S_
	.type	_Z9iterationPdiS_S_, @function
_Z9iterationPdiS_S_:
.LFB3864:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %r10
	movl	%esi, %r9d
	movq	%rdx, %r11
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	xorl	%r8d, %r8d
	movq	%rcx, %rbx
	leal	-1(%rsi), %ebp
.L15:
	movl	%r8d, %edi
	cmpl	%r8d, %r9d
	jle	.L21
	movsd	.LC9(%rip), %xmm2
	testq	%r8, %r8
	je	.L16
	movsd	.LC7(%rip), %xmm2
	cmpl	%edi, %ebp
	jne	.L16
	movsd	.LC10(%rip), %xmm2
.L16:
	movl	%r9d, %edx
	movq	%r10, %rsi
	call	_Z8countSumiPdi
	movaps	%xmm0, %xmm1
	movsd	(%r11,%r8,8), %xmm0
	subsd	%xmm1, %xmm0
	divsd	%xmm2, %xmm0
	addsd	(%r10,%r8,8), %xmm0
	movsd	%xmm0, (%rbx,%r8,8)
	incq	%r8
	jmp	.L15
.L21:
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3864:
	.size	_Z9iterationPdiS_S_, .-_Z9iterationPdiS_S_
	.globl	_Z9conditionPdS_i
	.type	_Z9conditionPdS_i, @function
_Z9conditionPdS_i:
.LFB3865:
	.cfi_startproc
	endbr64
	movq	.LC12(%rip), %xmm2
	xorl	%eax, %eax
	xorps	%xmm1, %xmm1
.L23:
	cmpl	%eax, %edx
	jle	.L25
	movsd	(%rdi,%rax,8), %xmm0
	subsd	(%rsi,%rax,8), %xmm0
	incq	%rax
	andps	%xmm2, %xmm0
	addsd	%xmm0, %xmm1
	jmp	.L23
.L25:
	movsd	.LC13(%rip), %xmm0
	comisd	%xmm1, %xmm0
	seta	%al
	ret
	.cfi_endproc
.LFE3865:
	.size	_Z9conditionPdS_i, .-_Z9conditionPdS_i
	.globl	_Z16iterationManagerPdiS_S_
	.type	_Z16iterationManagerPdiS_S_, @function
_Z16iterationManagerPdiS_S_:
.LFB3866:
	.cfi_startproc
	endbr64
	movabsq	$1152921504606846975, %rax
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	movslq	%esi, %rdi
	cmpq	%rdi, %rax
	jb	.L27
	movq	%rdi, %r12
	salq	$3, %rdi
	movq	%rdx, %r14
	movq	%rcx, %r13
	call	_Znam@PLT
	jmp	.L34
.L27:
	call	__cxa_throw_bad_array_new_length@PLT
.L34:
	movq	%rax, %rbp
	movq	%r14, %rdx
	movl	%r12d, %esi
	movq	%rbx, %rdi
	movq	%rbp, %rcx
	call	_Z9iterationPdiS_S_
	movl	%r12d, %edx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	_Z9conditionPdS_i
	testb	%al, %al
	jne	.L32
	movq	%rbx, %rax
	movq	%rbp, %rbx
	jmp	.L34
.L32:
	xorl	%eax, %eax
.L29:
	cmpl	%eax, %r12d
	jle	.L35
	movsd	0(%rbp,%rax,8), %xmm0
	movsd	%xmm0, 0(%r13,%rax,8)
	incq	%rax
	jmp	.L29
.L35:
	testq	%rbx, %rbx
	je	.L26
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_remember_state
	.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
	jmp	_ZdaPv@PLT
.L26:
	.cfi_restore_state
	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
.LFE3866:
	.size	_Z16iterationManagerPdiS_S_, .-_Z16iterationManagerPdiS_S_
	.globl	_Z8printMasPdi
	.type	_Z8printMasPdi, @function
_Z8printMasPdi:
.LFB3867:
	.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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
.L37:
	cmpl	%ebx, %ebp
	jle	.L44
	movsd	(%r12,%rbx,8), %xmm0
	movq	%r13, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movb	$32, 7(%rsp)
	movq	%rax, %rdi
	movq	(%rax), %rax
	movq	-24(%rax), %rax
	cmpq	$0, 16(%rdi,%rax)
	je	.L38
	leaq	7(%rsp), %rsi
	movl	$1, %edx
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	jmp	.L39
.L38:
	movl	$32, %esi
	call	_ZNSo3putEc@PLT
.L39:
	incq	%rbx
	jmp	.L37
.L44:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$24, %rsp
	.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
.LFE3867:
	.size	_Z8printMasPdi, .-_Z8printMasPdi
	.section	.rodata.str1.1
.LC14:
	.string	"Iteration num "
.LC15:
	.string	"F array"
	.text
	.globl	_Z5modeli
	.type	_Z5modeli, @function
_Z5modeli:
.LFB3868:
	.cfi_startproc
	endbr64
	movabsq	$1152921504606846975, %rax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movslq	%edi, %r14
	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
	pushq	%rcx
	.cfi_def_cfa_offset 64
	cmpq	%r14, %rax
	jb	.L46
	movq	%r14, %r13
	salq	$3, %r14
	movq	%r14, %rdi
	call	_Znam@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
	jmp	.L47
.L46:
	call	__cxa_throw_bad_array_new_length@PLT
.L47:
	cmpl	%eax, %r13d
	jle	.L59
	movq	$0x000000000, (%rbx,%rax,8)
	incq	%rax
	jmp	.L47
.L59:
	movq	%r14, %rdi
	leaq	.LC14(%rip), %r15
	call	_Znam@PLT
	movq	%r14, %rdi
	movq	%rax, %rbp
	call	_Znam@PLT
	movq	$0x000000000, (%rax)
	movq	%rax, %r12
	movq	.LC9(%rip), %rax
	movq	%rax, -8(%r12,%r14)
	xorl	%r14d, %r14d
.L51:
	movq	%r15, %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r14d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	xorl	%eax, %eax
	leal	-1(%r13), %edx
.L49:
	incq	%rax
	cmpl	%eax, %edx
	jle	.L60
	movsd	(%rbx,%rax,8), %xmm0
	movsd	%xmm0, (%r12,%rax,8)
	jmp	.L49
.L60:
	leaq	.LC15(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incl	%r14d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	%r13d, %esi
	movq	%r12, %rdi
	call	_Z8printMasPdi
	movq	%rbp, %rcx
	movq	%r12, %rdx
	movl	%r13d, %esi
	movq	%rbx, %rdi
	call	_Z16iterationManagerPdiS_S_
	movl	%r13d, %esi
	movq	%rbp, %rdi
	call	_Z8printMasPdi
	cmpl	$10, %r14d
	je	.L61
	xchgq	%rbp, %rbx
	jmp	.L51
.L61:
	testq	%rbx, %rbx
	je	.L52
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
.L52:
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	testq	%rbp, %rbp
	je	.L45
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movq	%rbp, %rdi
	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
	jmp	_ZdaPv@PLT
.L45:
	.cfi_restore_state
	popq	%rax
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3868:
	.size	_Z5modeli, .-_Z5modeli
	.globl	_Z10initializePfj
	.type	_Z10initializePfj, @function
_Z10initializePfj:
.LFB3870:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L63:
	cmpl	%esi, %eax
	jnb	.L65
	movl	$0x00000000, (%rdi,%rax,4)
	incq	%rax
	jmp	.L63
.L65:
	ret
	.cfi_endproc
.LFE3870:
	.size	_Z10initializePfj, .-_Z10initializePfj
	.globl	_Z12cpuIterationPfS_j
	.type	_Z12cpuIterationPfS_j, @function
_Z12cpuIterationPfS_j:
.LFB3871:
	.cfi_startproc
	endbr64
	movsd	.LC17(%rip), %xmm3
	movsd	.LC18(%rip), %xmm4
	movq	%rdi, %rcx
	xorl	%eax, %eax
	leal	-1(%rdx), %edi
.L67:
	cmpl	%edx, %eax
	jnb	.L73
	cmpl	%eax, %edi
	jne	.L68
	cvtss2sd	(%rcx,%rax,4), %xmm0
	addsd	%xmm3, %xmm0
	jmp	.L72
.L68:
	testq	%rax, %rax
	jne	.L70
	movl	$0x00000000, (%rsi)
	jmp	.L69
.L70:
	movss	(%rcx,%rax,4), %xmm2
	movss	-4(%rcx,%rax,4), %xmm1
	movss	4(%rcx,%rax,4), %xmm0
	movaps	%xmm2, %xmm5
	addss	%xmm2, %xmm5
	cvtss2sd	%xmm2, %xmm2
	subss	%xmm5, %xmm1
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm3, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
.L72:
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rsi,%rax,4)
.L69:
	incq	%rax
	jmp	.L67
.L73:
	ret
	.cfi_endproc
.LFE3871:
	.size	_Z12cpuIterationPfS_j, .-_Z12cpuIterationPfS_j
	.section	.rodata.str1.1
.LC21:
	.string	"CPU time : %.3f ms\n"
	.text
	.globl	_Z13cpuReciprocalPfj
	.type	_Z13cpuReciprocalPfj, @function
_Z13cpuReciprocalPfj:
.LFB3872:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rbx
	salq	$2, %rbp
	movq	%rbp, %rdi
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	call	_Znam@PLT
	movq	%rbp, %rdi
	xorl	%ebp, %ebp
	movq	%rax, %r12
	call	_Znam@PLT
	movq	%rax, %r13
.L77:
	call	clock@PLT
	movl	%ebx, %edx
	cvtsi2ssq	%rax, %xmm2
	movss	%xmm2, 12(%rsp)
	testl	$1, %ebp
	jne	.L75
	movq	%r12, %rsi
	movq	%r13, %rdi
	jmp	.L80
.L75:
	movq	%r13, %rsi
	movq	%r12, %rdi
.L80:
	call	_Z12cpuIterationPfS_j
	incl	%ebp
	call	clock@PLT
	movd	%r14d, %xmm5
	cvtsi2ssq	%rax, %xmm1
	subss	12(%rsp), %xmm1
	cvtss2sd	%xmm5, %xmm0
	cvtss2sd	%xmm1, %xmm1
	mulsd	.LC19(%rip), %xmm1
	divsd	.LC20(%rip), %xmm1
	addsd	%xmm0, %xmm1
	cvtsd2ss	%xmm1, %xmm4
	movd	%xmm4, %r14d
	cmpl	$100000, %ebp
	jne	.L77
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	cvtss2sd	%xmm4, %xmm0
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE3872:
	.size	_Z13cpuReciprocalPfj, .-_Z13cpuReciprocalPfj
	.globl	_Z14checkShodimostv
	.type	_Z14checkShodimostv, @function
_Z14checkShodimostv:
.LFB3873:
	.cfi_startproc
	endbr64
	movb	$1, %al
	ret
	.cfi_endproc
.LFE3873:
	.size	_Z14checkShodimostv, .-_Z14checkShodimostv
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3874:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$5, %edi
	call	_Z5modeli
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3874:
	.size	main, .-main
	.text
	.globl	_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j
	.type	_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j, @function
_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j:
.LFB3900:
	.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
	movl	%edx, 12(%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	12(%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	.L84
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z16reciprocalKernelPfS_j(%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
.L84:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L86
	call	__stack_chk_fail@PLT
.L86:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3900:
	.size	_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j, .-_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j
	.globl	_Z16reciprocalKernelPfS_j
	.type	_Z16reciprocalKernelPfS_j, @function
_Z16reciprocalKernelPfS_j:
.LFB3901:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j
	.cfi_endproc
.LFE3901:
	.size	_Z16reciprocalKernelPfS_j, .-_Z16reciprocalKernelPfS_j
	.section	.rodata.str1.1
.LC22:
	.string	"cudaMalloc((void **)&gpuOldData, sizeof(float)*size)"
.LC23:
	.string	"cudaMalloc((void **)&gpuNewData, sizeof(float)*size)"
.LC24:
	.string	"cudaMemcpy(gpuOldData, data, sizeof(float)*size, cudaMemcpyHostToDevice)"
.LC25:
	.string	"cudaMemcpy(rc, gpuNewData, sizeof(float)*size, cudaMemcpyDeviceToHost)"
.LC26:
	.string	"cudaMemcpy(rc, gpuOldData, sizeof(float)*size, cudaMemcpyDeviceToHost)"
.LC27:
	.string	"GPU time : %.3f ms\n"
.LC28:
	.string	"cudaFree(gpuOldData)"
.LC29:
	.string	"cudaFree(gpuNewData)"
	.text
	.globl	_Z13gpuReciprocalPfj
	.type	_Z13gpuReciprocalPfj, @function
_Z13gpuReciprocalPfj:
.LFB3869:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movabsq	$4294967552, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	movq	%rbx, %rbp
	salq	$2, %rbx
	movq	%rbx, %rdi
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, %r13
	call	cudaMalloc@PLT
	leaq	.LC22(%rip), %rsi
	movl	$164, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	.LC23(%rip), %rsi
	movl	$165, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	16(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r12d, %r12d
	call	cudaMemcpy@PLT
	leaq	.LC24(%rip), %rsi
	movl	$166, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	%rsp, %rdi
	call	cudaEventCreate@PLT
	leaq	8(%rsp), %rdi
	call	cudaEventCreate@PLT
.L94:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$536871037, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$3, %rdi
	movq	%r14, 44(%rsp)
	movq	%r14, %rdx
	movl	$1, %ecx
	movl	$1, 52(%rsp)
	movl	$1, %esi
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	testl	$1, %r12d
	jne	.L90
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L91
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebp, %edx
	call	_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j
.L91:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%r13, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	leaq	.LC25(%rip), %rsi
	movl	$178, %edi
	movl	%eax, %edx
	jmp	.L98
.L90:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L93
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdi
	movl	%ebp, %edx
	call	_Z39__device_stub__Z16reciprocalKernelPfS_jPfS_j
.L93:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	16(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%r13, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	leaq	.LC26(%rip), %rsi
	movl	$182, %edi
	movl	%eax, %edx
.L98:
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	8(%rsp), %rdi
	incl	%r12d
	call	cudaEventSynchronize@PLT
	movq	8(%rsp), %rdx
	movq	(%rsp), %rsi
	leaq	44(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movd	%r15d, %xmm1
	addss	44(%rsp), %xmm1
	movd	%xmm1, %r15d
	cmpl	$100000, %r12d
	jne	.L94
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC28(%rip), %rsi
	movl	$198, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC29(%rip), %rsi
	movl	$199, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L95
	call	__stack_chk_fail@PLT
.L95:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3869:
	.size	_Z13gpuReciprocalPfj, .-_Z13gpuReciprocalPfj
	.section	.rodata.str1.1
.LC30:
	.string	"_Z16reciprocalKernelPfS_j"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3903:
	.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	.LC30(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z16reciprocalKernelPfS_j(%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
.LFE3903:
	.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.cst16,"aM",@progbits,16
	.align 16
.LC5:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC6:
	.long	-350469331
	.long	-1086703902
	.align 8
.LC7:
	.long	-597859448
	.long	1072694086
	.align 8
.LC8:
	.long	-350469331
	.long	1060779746
	.align 8
.LC9:
	.long	0
	.long	1072693248
	.align 8
.LC10:
	.long	0
	.long	1073741824
	.section	.rodata.cst16
	.align 16
.LC12:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC13:
	.long	-755914244
	.long	1062232653
	.align 8
.LC17:
	.long	-350469331
	.long	1058682594
	.align 8
.LC18:
	.long	0
	.long	1074790400
	.align 8
.LC19:
	.long	0
	.long	1083129856
	.align 8
.LC20:
	.long	0
	.long	1093567616
	.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:

/*
 ============================================================================
 Name        : LAB3.cu
 Author      : Kineibe
 Version     :
 Copyright   : Your copyright notice
 Description : CUDA compute reciprocals
 ============================================================================
 */


#include <hip/hip_runtime.h>
#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;

static void CheckCudaErrorAux (const char *, unsigned, const char *, hipError_t);
#define CUDA_CHECK_RETURN(value) CheckCudaErrorAux(__FILE__,__LINE__, #value, value)
#define H_T 0.0001
#define H_X 0.5
#define TOTAL_TIME 10

#define EPSILON 0.001

#define RIGHT_COND 1
#define LEFT_COND 0
#define BLOCK_SIZE_AMOUNT 256

const double A = H_T / (H_X * H_X);
const double B = 2 * A + 1;

double countSum(int k, double* t, int size) {
	if (k == 0) {
		return t[k] * 1;
	} else if (k == size - 1) {
		return -1 * t[k - 1] / H_X + t[k] / H_X;
	} else {
		return -1 * A * t[k - 1] + t[k] / B - A * t[k + 1];
	}
}

double iterationPart(double prev, double multiplier, double f, double sum) {
	return prev + (f - sum) / multiplier;
}

void iteration(double* t_prev, int size, double* f, double* t_result) {
	for (int i = 0; i < size; ++i) {
		double a;
		if (i == 0)
			a = 1;
		else if (i == size - 1)
			a = 1 / H_X;
		else
			a = B;

		double sum = countSum(i, t_prev, size);
		double newT = iterationPart(t_prev[i], a, f[i], sum);
		t_result[i] = newT;
	}
}

bool condition(double* t_prev, double* t_result, int size) {
	double result = 0;
	for (int i = 0; i < size; ++i) {
		result += abs(t_prev[i] - t_result[i]);
	}
	return result < EPSILON;
}

void iterationManager(double* t_prev, int size, double* f, double* t_target) {
	bool check = true;
	double* t_result = new double[size];

	do {
		iteration(t_prev, size, f, t_result);
		check = condition(t_prev, t_result, size);
		double* temp = t_result;
		t_result = t_prev;
		t_prev = temp;
	} while(!check);

	for (int i = 0; i < size; ++i) {
		t_target[i] = t_prev[i];
	}
	delete[] t_result;
}

void printMas(double* arr, int size) {
	for (int i = 0; i < size; ++i) {
		cout << arr[i] << ' ';
	}
	cout << endl;
}

void model(int size) {
	double* t = new double[size];
	for (int i = 0; i < size; ++i) {
		t[i] = 0;
	}

	double* t_next = new double[size];

	double* f = new double[size];
	f[0] = LEFT_COND;
	f[size - 1] = RIGHT_COND;

//	int iterationAmount = TOTAL_TIME / H_T;
	int iterationAmount = 10;
	for (int i = 0; i < iterationAmount; ++i) {
		cout << "Iteration num " << i << endl;
		for (int i = 1; i < size - 1; ++i) {
			f[i] = t[i];
		}
		cout << "F array" << endl;
		printMas(f, size);

		iterationManager(t, size, f, t_next);
		printMas(t_next, size);

		double* temp = t_next;
		t_next = t;
		t = temp;
	}

	delete[] t_next;
	delete[] f;
	delete[] t;
}

/**
 * CUDA kernel that computes reciprocal values for a given vector
 */
__global__ void reciprocalKernel(float *data, float *newData, unsigned vectorSize) {
	unsigned idx = blockIdx.x*blockDim.x+threadIdx.x;
	if (idx < vectorSize) {
		if (idx == vectorSize - 1) {
			newData[idx] = RIGHT_COND * H_T + data[idx];
		} else if (idx == 0) {
			newData[idx] = LEFT_COND;
		} else {
			newData[idx] = data[idx] + (data[idx - 1] - 2 * data[idx] + data[idx + 1]) * H_T / (H_X * H_X);
		}
	}
}

/**
 * Host function that copies the data and launches the work on GPU
 */
void gpuReciprocal(float *data, unsigned size)
{
	hipEvent_t GPUstart, GPUstop;
	float GPUtime = 0.0f;
	float *rc = new float[size];
	float *gpuOldData;
	float *gpuNewData;

	int iterationAmount = TOTAL_TIME / H_T;

	static const int BLOCK_SIZE = BLOCK_SIZE_AMOUNT;
	const int blockCount = 1000;

	CUDA_CHECK_RETURN(hipMalloc((void **)&gpuOldData, sizeof(float)*size));
	CUDA_CHECK_RETURN(hipMalloc((void **)&gpuNewData, sizeof(float)*size));
	CUDA_CHECK_RETURN(hipMemcpy(gpuOldData, data, sizeof(float)*size, hipMemcpyHostToDevice));

	hipEventCreate(&GPUstart);
	hipEventCreate(&GPUstop);


	for (int i = 0; i < iterationAmount; ++i) {
		hipEventRecord(GPUstart, 0);

		if (i % 2 == 0) {
			reciprocalKernel<<<blockCount, BLOCK_SIZE>>> (gpuOldData, gpuNewData, size);
			hipEventRecord(GPUstop, 0);
			CUDA_CHECK_RETURN(hipMemcpy(rc, gpuNewData, sizeof(float)*size, hipMemcpyDeviceToHost));
		} else {
			reciprocalKernel<<<blockCount, BLOCK_SIZE>>> (gpuNewData, gpuOldData, size);
			hipEventRecord(GPUstop, 0);
			CUDA_CHECK_RETURN(hipMemcpy(rc, gpuOldData, sizeof(float)*size, hipMemcpyDeviceToHost));
		}
		hipEventSynchronize(GPUstop);

		float temp;
		hipEventElapsedTime(&temp, GPUstart, GPUstop);
		GPUtime += temp;
//
//		for (int i = 0; i < size; ++i) {
//			std::cout << "t[" << i << "] = " << rc[i] << std::endl;
//		}
//		std::cout << std::endl;
	}

	printf("GPU time : %.3f ms\n", GPUtime);

	CUDA_CHECK_RETURN(hipFree(gpuOldData));
	CUDA_CHECK_RETURN(hipFree(gpuNewData));
}

void initialize(float *data, unsigned size)
{
	for (unsigned i = 0; i < size; ++i)
		data[i] = 0;
}

void cpuIteration(float *data, float *newData, unsigned vectorSize) {
	for (int idx = 0; idx < vectorSize; ++idx) {
		if (idx == vectorSize - 1) {
			newData[idx] = RIGHT_COND * H_T + data[idx];
		} else if (idx == 0) {
			newData[idx] = LEFT_COND;
		} else {
			newData[idx] = data[idx] + (data[idx - 1] - 2 * data[idx] + data[idx + 1]) * H_T / (H_X * H_X);
		}
	}
}

void cpuReciprocal(float *data, unsigned size)
{
	float *rc = new float[size];
	float *oldData = new float[size];

	float* result;

	float CPUstart, CPUstop;
	float CPUtime = 0.0f;

	int iterationAmount = TOTAL_TIME / H_T;

	for (int i = 0; i < iterationAmount; ++i) {

		CPUstart = clock();
		if (i % 2 == 0) {
			cpuIteration(oldData, rc, size);
			result = rc;
		} else {
			cpuIteration(rc, oldData, size);
			result = oldData;
		}
		CPUstop = clock();
		CPUtime += 1000.*(CPUstop - CPUstart) / CLOCKS_PER_SEC;
//
//		for (int i = 0; i < size; ++i) {
//			std::cout << "t[" << i << "] = " << result[i] << std::endl;
//		}
//		std::cout << std::endl;
	}

	printf("CPU time : %.3f ms\n", CPUtime);
}

bool checkShodimost() {
	return true;
}

int main(void)
{
	static const int WORK_SIZE = 256000;
	float *data = new float[WORK_SIZE];

	model(5);


	/* Free memory */
	delete[] data;

	return 0;
}

/**
 * Check the return value of the CUDA runtime API call and exit
 * the application if the call has failed.
 */
static void CheckCudaErrorAux (const char *file, unsigned line, const char *statement, hipError_t err)
{
	if (err == hipSuccess)
		return;
	std::cerr << statement<<" returned " << hipGetErrorString(err) << "("<<err<< ") at "<<file<<":"<<line << std::endl;
	exit (1);
}


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

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8countSumiPdi
.LCPI0_0:
	.quad	0x3f3a36e2eb1c432d              # double 4.0000000000000002E-4
.LCPI0_1:
	.quad	0x3ff00346dc5d6388              # double 1.0007999999999999
	.text
	.globl	_Z8countSumiPdi
	.type	_Z8countSumiPdi,@function
_Z8countSumiPdi:                        # @_Z8countSumiPdi
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	je	.LBB0_1
# %bb.2:
	decl	%edx
	movslq	%edi, %rax
	movsd	-8(%rsi,%rax,8), %xmm1          # xmm1 = mem[0],zero
	movsd	(%rsi,%rax,8), %xmm0            # xmm0 = mem[0],zero
	cmpl	%edi, %edx
	jne	.LBB0_5
# %bb.3:
	addsd	%xmm1, %xmm1
	addsd	%xmm0, %xmm0
	subsd	%xmm1, %xmm0
	retq
.LBB0_1:
	movsd	(%rsi), %xmm0                   # xmm0 = mem[0],zero
	retq
.LBB0_5:
	movsd	.LCPI0_0(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm1
	divsd	.LCPI0_1(%rip), %xmm0
	subsd	%xmm1, %xmm0
	mulsd	8(%rsi,%rax,8), %xmm2
	subsd	%xmm2, %xmm0
	retq
.Lfunc_end0:
	.size	_Z8countSumiPdi, .Lfunc_end0-_Z8countSumiPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z13iterationPartdddd           # -- Begin function _Z13iterationPartdddd
	.type	_Z13iterationPartdddd,@function
_Z13iterationPartdddd:                  # @_Z13iterationPartdddd
	.cfi_startproc
# %bb.0:
	subsd	%xmm3, %xmm2
	divsd	%xmm1, %xmm2
	addsd	%xmm2, %xmm0
	retq
.Lfunc_end1:
	.size	_Z13iterationPartdddd, .Lfunc_end1-_Z13iterationPartdddd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z9iterationPdiS_S_
.LCPI2_0:
	.quad	0x3f3a36e2eb1c432d              # double 4.0000000000000002E-4
.LCPI2_1:
	.quad	0x3ff00346dc5d6388              # double 1.0007999999999999
.LCPI2_2:
	.quad	0x4000000000000000              # double 2
.LCPI2_3:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z9iterationPdiS_S_
	.type	_Z9iterationPdiS_S_,@function
_Z9iterationPdiS_S_:                    # @_Z9iterationPdiS_S_
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	testl	%esi, %esi
	jle	.LBB2_8
# %bb.1:                                # %.lr.ph
	leal	-1(%rsi), %eax
	movl	%esi, %esi
	shlq	$3, %rax
	shlq	$3, %rsi
	xorl	%r8d, %r8d
	movsd	.LCPI2_3(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	.LCPI2_2(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI2_0(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm3           # xmm3 = mem[0],zero
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	testq	%r8, %r8
	je	.LBB2_3
# %bb.4:                                #   in Loop: Header=BB2_2 Depth=1
	movsd	-8(%rdi,%r8), %xmm6             # xmm6 = mem[0],zero
	movsd	(%rdi,%r8), %xmm4               # xmm4 = mem[0],zero
	cmpq	%r8, %rax
	jne	.LBB2_6
# %bb.5:                                #   in Loop: Header=BB2_2 Depth=1
	addsd	%xmm6, %xmm6
	movapd	%xmm4, %xmm5
	addsd	%xmm4, %xmm5
	subsd	%xmm6, %xmm5
	movapd	%xmm1, %xmm6
	jmp	.LBB2_7
.LBB2_3:                                #   in Loop: Header=BB2_2 Depth=1
	movsd	(%rdi), %xmm4                   # xmm4 = mem[0],zero
	movapd	%xmm0, %xmm6
	movapd	%xmm4, %xmm5
	jmp	.LBB2_7
.LBB2_6:                                #   in Loop: Header=BB2_2 Depth=1
	mulsd	%xmm2, %xmm6
	movapd	%xmm4, %xmm5
	divsd	%xmm3, %xmm5
	subsd	%xmm6, %xmm5
	movsd	8(%rdi,%r8), %xmm6              # xmm6 = mem[0],zero
	mulsd	%xmm2, %xmm6
	subsd	%xmm6, %xmm5
	movapd	%xmm3, %xmm6
.LBB2_7:                                # %_Z8countSumiPdi.exit
                                        #   in Loop: Header=BB2_2 Depth=1
	movsd	(%rdx,%r8), %xmm7               # xmm7 = mem[0],zero
	subsd	%xmm5, %xmm7
	divsd	%xmm6, %xmm7
	addsd	%xmm4, %xmm7
	movsd	%xmm7, (%rcx,%r8)
	addq	$8, %r8
	cmpq	%r8, %rsi
	jne	.LBB2_2
.LBB2_8:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z9iterationPdiS_S_, .Lfunc_end2-_Z9iterationPdiS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z9conditionPdS_i
.LCPI3_0:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI3_1:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.text
	.globl	_Z9conditionPdS_i
	.type	_Z9conditionPdS_i,@function
_Z9conditionPdS_i:                      # @_Z9conditionPdS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB3_1
# %bb.4:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorpd	%xmm0, %xmm0
	xorl	%ecx, %ecx
	movapd	.LCPI3_0(%rip), %xmm1           # xmm1 = [NaN,NaN]
.LBB3_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rdi,%rcx,8), %xmm2            # xmm2 = mem[0],zero
	subsd	(%rsi,%rcx,8), %xmm2
	andpd	%xmm1, %xmm2
	addsd	%xmm2, %xmm0
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB3_5
# %bb.2:                                # %._crit_edge.loopexit
	movsd	.LCPI3_1(%rip), %xmm1           # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	seta	%al
	retq
.LBB3_1:
	movb	$1, %al
	retq
.Lfunc_end3:
	.size	_Z9conditionPdS_i, .Lfunc_end3-_Z9conditionPdS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z16iterationManagerPdiS_S_
.LCPI4_0:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_1:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.text
	.globl	_Z16iterationManagerPdiS_S_
	.type	_Z16iterationManagerPdiS_S_,@function
_Z16iterationManagerPdiS_S_:            # @_Z16iterationManagerPdiS_S_
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movq	%rdx, %r12
	movl	%esi, %ebp
	movq	%rdi, %r13
	movl	%esi, %r15d
	leaq	(,%r15,8), %rax
	testl	%esi, %esi
	movq	$-1, %rdi
	cmovnsq	%rax, %rdi
	callq	_Znam
	movq	%r13, (%rsp)                    # 8-byte Spill
.LBB4_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_10 Depth 2
	movq	%r13, %r14
	movq	%rax, %r13
	movq	%r14, %rdi
	movl	%ebp, %esi
	movq	%r12, %rdx
	movq	%rax, %rcx
	callq	_Z9iterationPdiS_S_
	testl	%ebp, %ebp
	jle	.LBB4_2
# %bb.9:                                # %.lr.ph.i.preheader
                                        #   in Loop: Header=BB4_1 Depth=1
	xorpd	%xmm0, %xmm0
	xorl	%eax, %eax
	movapd	.LCPI4_0(%rip), %xmm2           # xmm2 = [NaN,NaN]
.LBB4_10:                               # %.lr.ph.i
                                        #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%rax,8), %xmm1            # xmm1 = mem[0],zero
	subsd	(%r13,%rax,8), %xmm1
	andpd	%xmm2, %xmm1
	addsd	%xmm1, %xmm0
	incq	%rax
	cmpq	%rax, %r15
	jne	.LBB4_10
# %bb.11:                               # %._crit_edge.loopexit.i
                                        #   in Loop: Header=BB4_1 Depth=1
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	movq	%r14, %rax
	jbe	.LBB4_1
# %bb.5:                                # %_Z9conditionPdS_i.exit.preheader
	testl	%ebp, %ebp
	jle	.LBB4_4
# %bb.6:                                # %_Z9conditionPdS_i.exit.preheader42
	xorl	%eax, %eax
.LBB4_7:                                # %_Z9conditionPdS_i.exit
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r13,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%rbx,%rax,8)
	incq	%rax
	cmpq	%rax, %r15
	jne	.LBB4_7
# %bb.8:
	movq	%r14, %rax
	jmp	.LBB4_3
.LBB4_2:
	movq	(%rsp), %rax                    # 8-byte Reload
	movq	%rax, %r14
.LBB4_3:                                # %_Z9conditionPdS_i.exit._crit_edge
	testq	%rax, %rax
	je	.LBB4_12
.LBB4_4:                                # %_Z9conditionPdS_i.exit._crit_edge.thread
	movq	%r14, %rdi
	addq	$8, %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	_ZdaPv                          # TAILCALL
.LBB4_12:
	.cfi_def_cfa_offset 64
	addq	$8, %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_end4:
	.size	_Z16iterationManagerPdiS_S_, .Lfunc_end4-_Z16iterationManagerPdiS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z8printMasPdi                  # -- Begin function _Z8printMasPdi
	.type	_Z8printMasPdi,@function
_Z8printMasPdi:                         # @_Z8printMasPdi
	.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
	testl	%esi, %esi
	jle	.LBB5_6
# %bb.1:                                # %.lr.ph.preheader
	movq	%rdi, %rbx
	movl	%esi, %r15d
	xorl	%r12d, %r12d
	leaq	7(%rsp), %r14
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rbx,%r12,8), %xmm0            # xmm0 = mem[0],zero
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movb	$32, 7(%rsp)
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	cmpq	$0, 16(%rax,%rcx)
	je	.LBB5_4
# %bb.3:                                #   in Loop: Header=BB5_2 Depth=1
	movl	$1, %edx
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB5_5
.LBB5_4:                                #   in Loop: Header=BB5_2 Depth=1
	movq	%rax, %rdi
	movl	$32, %esi
	callq	_ZNSo3putEc
.LBB5_5:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.exit
                                        #   in Loop: Header=BB5_2 Depth=1
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB5_2
.LBB5_6:                                # %._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
	callq	_ZNSo5flushEv
	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_end5:
	.size	_Z8printMasPdi, .Lfunc_end5-_Z8printMasPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z5modeli                       # -- Begin function _Z5modeli
	.type	_Z5modeli,@function
_Z5modeli:                              # @_Z5modeli
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%edi, %ebx
	movl	%edi, %r15d
	shlq	$3, %r15
	testl	%edi, %edi
	movq	$-1, %r14
	cmovnsq	%r15, %r14
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r13
	movq	%rbx, %r12
	testl	%ebx, %ebx
	jle	.LBB6_2
# %bb.1:                                # %.lr.ph.preheader
	movq	%r13, %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
.LBB6_2:                                # %._crit_edge
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	$0, (%rax)
	leal	-1(%r12), %ebx
	movslq	%r12d, %rax
	movabsq	$4607182418800017408, %rcx      # imm = 0x3FF0000000000000
	movq	%rcx, -8(%r14,%rax,8)
	xorl	%ebp, %ebp
.LBB6_3:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_5 Depth 2
	movq	%r15, (%rsp)                    # 8-byte Spill
	movq	%r13, %r15
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$14, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %r13
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r13, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	cmpl	$3, %r12d
	jl	.LBB6_6
# %bb.4:                                # %.lr.ph43.preheader
                                        #   in Loop: Header=BB6_3 Depth=1
	movl	$1, %eax
.LBB6_5:                                # %.lr.ph43
                                        #   Parent Loop BB6_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r15,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%r14,%rax,8)
	incq	%rax
	cmpq	%rax, %rbx
	jne	.LBB6_5
.LBB6_6:                                # %._crit_edge44
                                        #   in Loop: Header=BB6_3 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$7, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	movl	$_ZSt4cout, %eax
	addq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r14, %rdi
	movl	%r12d, %esi
	callq	_Z8printMasPdi
	movq	%r15, %rdi
	movl	%r12d, %esi
	movq	%r14, %rdx
	movq	(%rsp), %r13                    # 8-byte Reload
	movq	%r13, %rcx
	callq	_Z16iterationManagerPdiS_S_
	movq	%r13, %rdi
	movl	%r12d, %esi
	callq	_Z8printMasPdi
	incl	%ebp
	cmpl	$10, %ebp
	jne	.LBB6_3
# %bb.7:
	testq	%r15, %r15
	je	.LBB6_9
# %bb.8:
	movq	%r15, %rdi
	callq	_ZdaPv
.LBB6_9:
	movq	%r14, %rdi
	callq	_ZdaPv
	movq	(%rsp), %rdi                    # 8-byte Reload
	addq	$8, %rsp
	testq	%rdi, %rdi
	je	.LBB6_10
# %bb.11:
	.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	_ZdaPv                          # TAILCALL
.LBB6_10:
	.cfi_def_cfa_offset 64
	.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_end6:
	.size	_Z5modeli, .Lfunc_end6-_Z5modeli
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__reciprocalKernelPfS_j # -- Begin function _Z31__device_stub__reciprocalKernelPfS_j
	.type	_Z31__device_stub__reciprocalKernelPfS_j,@function
_Z31__device_stub__reciprocalKernelPfS_j: # @_Z31__device_stub__reciprocalKernelPfS_j
	.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	12(%rsp), %rsi
	movl	%edx, (%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	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16reciprocalKernelPfS_j, %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_end7:
	.size	_Z31__device_stub__reciprocalKernelPfS_j, .Lfunc_end7-_Z31__device_stub__reciprocalKernelPfS_j
	.cfi_endproc
                                        # -- End function
	.globl	_Z13gpuReciprocalPfj            # -- Begin function _Z13gpuReciprocalPfj
	.type	_Z13gpuReciprocalPfj,@function
_Z13gpuReciprocalPfj:                   # @_Z13gpuReciprocalPfj
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %r13
	movabsq	$4294967552, %r14               # imm = 0x100000100
	movl	%esi, 12(%rsp)                  # 4-byte Spill
	movl	%esi, %r15d
	shlq	$2, %r15
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r12
	leaq	24(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movl	$.L.str.3, %esi
	movl	$166, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movl	$.L.str.4, %esi
	movl	$167, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movq	(%rbp), %rdi
	movq	%r13, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.5, %esi
	movl	$168, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	xorl	%ebx, %ebx
	xorps	%xmm0, %xmm0
	leaq	744(%r14), %r13
	leaq	44(%rsp), %rbp
.LBB8_1:                                # =>This Inner Loop Header: Depth=1
	movss	%xmm0, 40(%rsp)                 # 4-byte Spill
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testb	$1, %bl
	jne	.LBB8_5
# %bb.2:                                #   in Loop: Header=BB8_1 Depth=1
	testl	%eax, %eax
	jne	.LBB8_4
# %bb.3:                                #   in Loop: Header=BB8_1 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	12(%rsp), %edx                  # 4-byte Reload
	callq	_Z31__device_stub__reciprocalKernelPfS_j
.LBB8_4:                                #   in Loop: Header=BB8_1 Depth=1
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.6, %esi
	movl	$180, %edi
	jmp	.LBB8_8
.LBB8_5:                                #   in Loop: Header=BB8_1 Depth=1
	testl	%eax, %eax
	jne	.LBB8_7
# %bb.6:                                #   in Loop: Header=BB8_1 Depth=1
	movq	16(%rsp), %rdi
	movq	24(%rsp), %rsi
	movl	12(%rsp), %edx                  # 4-byte Reload
	callq	_Z31__device_stub__reciprocalKernelPfS_j
.LBB8_7:                                #   in Loop: Header=BB8_1 Depth=1
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.7, %esi
	movl	$184, %edi
.LBB8_8:                                #   in Loop: Header=BB8_1 Depth=1
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	movq	48(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	%rbp, %rdi
	callq	hipEventElapsedTime
	movss	40(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	44(%rsp), %xmm0
	incl	%ebx
	cmpl	$100000, %ebx                   # imm = 0x186A0
	jne	.LBB8_1
# %bb.9:
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movq	24(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.9, %esi
	movl	$200, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.10, %esi
	movl	$201, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	addq	$56, %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_end8:
	.size	_Z13gpuReciprocalPfj, .Lfunc_end8-_Z13gpuReciprocalPfj
	.cfi_endproc
                                        # -- End function
	.type	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t,@function # -- Begin function _ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t: # @_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jne	.LBB9_2
# %bb.1:
	retq
.LBB9_2:
	pushq	%rbp
	.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 %rbp, -16
	movl	%edx, %ebp
	movl	%edi, %ebx
	movl	$_ZSt4cerr, %edi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.12, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.13, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movl	$.L.str.14, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.15, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%ebx, %esi
	callq	_ZNSolsEj
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end9:
	.size	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t, .Lfunc_end9-_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	.cfi_endproc
                                        # -- End function
	.globl	_Z10initializePfj               # -- Begin function _Z10initializePfj
	.type	_Z10initializePfj,@function
_Z10initializePfj:                      # @_Z10initializePfj
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB10_1
# %bb.2:                                # %.lr.ph.preheader
	movl	%esi, %edx
	shlq	$2, %rdx
	xorl	%esi, %esi
	jmp	memset@PLT                      # TAILCALL
.LBB10_1:                               # %._crit_edge
	retq
.Lfunc_end10:
	.size	_Z10initializePfj, .Lfunc_end10-_Z10initializePfj
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12cpuIterationPfS_j
.LCPI11_0:
	.quad	0x3f1a36e2eb1c432d              # double 1.0E-4
.LCPI11_1:
	.quad	0x4010000000000000              # double 4
	.text
	.globl	_Z12cpuIterationPfS_j
	.type	_Z12cpuIterationPfS_j,@function
_Z12cpuIterationPfS_j:                  # @_Z12cpuIterationPfS_j
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	testl	%edx, %edx
	je	.LBB11_8
# %bb.1:                                # %.lr.ph
	leal	-1(%rdx), %eax
	movl	%edx, %ecx
	xorl	%edx, %edx
	movsd	.LCPI11_0(%rip), %xmm0          # xmm0 = mem[0],zero
	movsd	.LCPI11_1(%rip), %xmm1          # xmm1 = mem[0],zero
.LBB11_2:                               # =>This Inner Loop Header: Depth=1
	cmpq	%rdx, %rax
	jne	.LBB11_4
# %bb.3:                                #   in Loop: Header=BB11_2 Depth=1
	xorps	%xmm2, %xmm2
	cvtss2sd	(%rdi,%rax,4), %xmm2
	addsd	%xmm0, %xmm2
	cvtsd2ss	%xmm2, %xmm2
	movss	%xmm2, (%rsi,%rax,4)
	jmp	.LBB11_7
.LBB11_4:                               #   in Loop: Header=BB11_2 Depth=1
	testq	%rdx, %rdx
	je	.LBB11_5
# %bb.6:                                #   in Loop: Header=BB11_2 Depth=1
	movss	-4(%rdi,%rdx,4), %xmm2          # xmm2 = mem[0],zero,zero,zero
	movss	(%rdi,%rdx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	xorps	%xmm4, %xmm4
	cvtss2sd	%xmm3, %xmm4
	addss	%xmm3, %xmm3
	subss	%xmm3, %xmm2
	addss	4(%rdi,%rdx,4), %xmm2
	cvtss2sd	%xmm2, %xmm2
	mulsd	%xmm0, %xmm2
	mulsd	%xmm1, %xmm2
	addsd	%xmm4, %xmm2
	cvtsd2ss	%xmm2, %xmm2
	movss	%xmm2, (%rsi,%rdx,4)
	jmp	.LBB11_7
.LBB11_5:                               #   in Loop: Header=BB11_2 Depth=1
	movl	$0, (%rsi)
.LBB11_7:                               #   in Loop: Header=BB11_2 Depth=1
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB11_2
.LBB11_8:                               # %._crit_edge
	retq
.Lfunc_end11:
	.size	_Z12cpuIterationPfS_j, .Lfunc_end11-_Z12cpuIterationPfS_j
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13cpuReciprocalPfj
.LCPI12_0:
	.quad	0x408f400000000000              # double 1000
.LCPI12_1:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z13cpuReciprocalPfj
	.type	_Z13cpuReciprocalPfj,@function
_Z13cpuReciprocalPfj:                   # @_Z13cpuReciprocalPfj
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movl	%esi, %r15d
	shlq	$2, %r15
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r15
	xorps	%xmm0, %xmm0
	xorl	%ebp, %ebp
.LBB12_1:                               # =>This Inner Loop Header: Depth=1
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	callq	clock
	movq	%rax, %r12
	testb	$1, %bpl
	jne	.LBB12_3
# %bb.2:                                #   in Loop: Header=BB12_1 Depth=1
	movq	%r15, %rdi
	movq	%r14, %rsi
	jmp	.LBB12_4
.LBB12_3:                               #   in Loop: Header=BB12_1 Depth=1
	movq	%r14, %rdi
	movq	%r15, %rsi
.LBB12_4:                               #   in Loop: Header=BB12_1 Depth=1
	movl	%ebx, %edx
	callq	_Z12cpuIterationPfS_j
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12, %xmm0
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	callq	clock
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	subss	8(%rsp), %xmm0                  # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI12_0(%rip), %xmm0
	divsd	.LCPI12_1(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	12(%rsp), %xmm1                 # 4-byte Folded Reload
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	incl	%ebp
	cmpl	$100000, %ebp                   # imm = 0x186A0
	jne	.LBB12_1
# %bb.5:
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end12:
	.size	_Z13cpuReciprocalPfj, .Lfunc_end12-_Z13cpuReciprocalPfj
	.cfi_endproc
                                        # -- End function
	.globl	_Z14checkShodimostv             # -- Begin function _Z14checkShodimostv
	.type	_Z14checkShodimostv,@function
_Z14checkShodimostv:                    # @_Z14checkShodimostv
	.cfi_startproc
# %bb.0:
	movb	$1, %al
	retq
.Lfunc_end13:
	.size	_Z14checkShodimostv, .Lfunc_end13-_Z14checkShodimostv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$5, %edi
	callq	_Z5modeli
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end14:
	.size	main, .Lfunc_end14-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	.LBB15_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB15_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16reciprocalKernelPfS_j, %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_end15:
	.size	__hip_module_ctor, .Lfunc_end15-__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	.LBB16_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
.LBB16_2:
	retq
.Lfunc_end16:
	.size	__hip_module_dtor, .Lfunc_end16-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Iteration num "
	.size	.L.str, 15

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"F array"
	.size	.L.str.1, 8

	.type	_Z16reciprocalKernelPfS_j,@object # @_Z16reciprocalKernelPfS_j
	.section	.rodata,"a",@progbits
	.globl	_Z16reciprocalKernelPfS_j
	.p2align	3, 0x0
_Z16reciprocalKernelPfS_j:
	.quad	_Z31__device_stub__reciprocalKernelPfS_j
	.size	_Z16reciprocalKernelPfS_j, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/neikila/Cuda/master/LAB2.hip"
	.size	.L.str.2, 91

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"hipMalloc((void **)&gpuOldData, sizeof(float)*size)"
	.size	.L.str.3, 52

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipMalloc((void **)&gpuNewData, sizeof(float)*size)"
	.size	.L.str.4, 52

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipMemcpy(gpuOldData, data, sizeof(float)*size, hipMemcpyHostToDevice)"
	.size	.L.str.5, 71

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipMemcpy(rc, gpuNewData, sizeof(float)*size, hipMemcpyDeviceToHost)"
	.size	.L.str.6, 69

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"hipMemcpy(rc, gpuOldData, sizeof(float)*size, hipMemcpyDeviceToHost)"
	.size	.L.str.7, 69

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"GPU time : %.3f ms\n"
	.size	.L.str.8, 20

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"hipFree(gpuOldData)"
	.size	.L.str.9, 20

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"hipFree(gpuNewData)"
	.size	.L.str.10, 20

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"CPU time : %.3f ms\n"
	.size	.L.str.11, 20

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	" returned "
	.size	.L.str.12, 11

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"("
	.size	.L.str.13, 2

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16reciprocalKernelPfS_j"
	.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__reciprocalKernelPfS_j
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _ZSt4cout
	.addrsig_sym _Z16reciprocalKernelPfS_j
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16reciprocalKernelPfS_j ; -- Begin function _Z16reciprocalKernelPfS_j
	.globl	_Z16reciprocalKernelPfS_j
	.p2align	8
	.type	_Z16reciprocalKernelPfS_j,@function
_Z16reciprocalKernelPfS_j:              ; @_Z16reciprocalKernelPfS_j
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s4, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_u32_e64 s4, v1
	s_cbranch_execz .LBB0_9
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_add_i32 s4, s4, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ne_u32_e32 vcc_lo, s4, v1
	s_and_saveexec_b32 s4, vcc_lo
	s_xor_b32 s4, exec_lo, s4
	s_cbranch_execz .LBB0_7
; %bb.2:
	s_mov_b32 s5, exec_lo
	v_cmpx_ne_u32_e32 0, v1
	s_xor_b32 s5, exec_lo, s5
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_mov_b32_e32 v2, 0
	s_mov_b32 s6, 0xeb1c432d
	s_mov_b32 s7, 0x3f1a36e2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v1, -1, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v5, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_clause 0x1
	global_load_b64 v[5:6], v[5:6], off
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v0, -2.0, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_f32_e32 v0, v0, v6
	v_cvt_f64_f32_e32 v[5:6], v5
	v_cvt_f64_f32_e32 v[0:1], v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[0:1], v[0:1], s[6:7]
	v_fma_f64 v[0:1], v[0:1], 4.0, v[5:6]
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_f64_e32 v2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s2, v3
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v4, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_4:                                ; %Flow
	s_and_not1_saveexec_b32 s5, s5
	s_cbranch_execz .LBB0_6
; %bb.5:
	v_mov_b32_e32 v0, 0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v0, s[2:3]
.LBB0_6:                                ; %Flow30
	s_or_b32 exec_lo, exec_lo, s5
                                        ; implicit-def: $vgpr1_vgpr2
.LBB0_7:                                ; %Flow31
	s_and_not1_saveexec_b32 s4, s4
	s_cbranch_execz .LBB0_9
; %bb.8:
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v1, vcc_lo
	s_mov_b32 s0, 0xeb1c432d
	s_mov_b32 s1, 0x3f1a36e2
	v_add_co_u32 v0, vcc_lo, s2, v0
	global_load_b32 v2, v[2:3], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[2:3], v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[2:3], s[0:1]
	v_cvt_f32_f64_e32 v2, v[2:3]
	global_store_b32 v[0:1], v2, off
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16reciprocalKernelPfS_j
		.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 7
		.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	_Z16reciprocalKernelPfS_j, .Lfunc_end0-_Z16reciprocalKernelPfS_j
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 432
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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
      - .offset:         16
        .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:           _Z16reciprocalKernelPfS_j
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16reciprocalKernelPfS_j.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
