#include <iostream>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "definitions.cuh"
#include <time.h>
#include "stdio.h"

//Number of elements on which to perform CFD
unsigned int Ni = 512; // Y elements
unsigned int Nj = 512; // X elements
unsigned int nIterations = 10000; // No Of Iterations
unsigned int kernelVersion =2; // Decides which GPU kernel version to call (Set it to 1 or 2)

int main(int argc, char** argv)
{

    //Variables for Timing
    float cpuTime, gpuTime;

    // CPU and GPU Pointers ( d_XX : refers to pointer pointing to GPU memory. This is just a convention)
    float *t = NULL, *t_prev = NULL;
    float *d_t = NULL,*d_t_prev= NULL;

    parseCommandLineArguments(argc, (char **)argv);
    printf("\n Ni= %d, Nj=%d nIteration=%d",Ni,Nj,nIterations);

    unsigned int size = Ni * Nj * sizeof(float);

    if(!initializeCPU(&t, &t_prev) )
    {
        printf("\n Error in allocating memory on CPU!!!");
        unInitializeCPU(&t, &t_prev);
        getchar();
        return 0;
    }

    if (!initializeGPU(&d_t, &d_t_prev))
    {
        printf("\n Error in allocating memory on GPU!!!");
        unInitializeCPU(&t, &t_prev);
        unInitializeGPU(&d_t, &d_t_prev);
        return 0;
    }

    //Perform CFD on CPU
    performCPUCFD(t,t_prev, &cpuTime);

    // To temporarily store CPU data. This is just for comparing with GPU output
    float *tempBuffer = (float*) calloc(Ni*Nj, sizeof(float));
    memcpy(tempBuffer, t_prev, size);

    //Perform CFD on GPU
    if(!performGPUCFD(d_t,d_t_prev, t, t_prev, &gpuTime))
    {
        printf("\n GPU Kernel failed !!!");
        unInitializeCPU(&t, &t_prev);
        unInitializeGPU(&d_t, &d_t_prev);
        if(tempBuffer !=NULL)
            free(tempBuffer);
        return 0;
    }

    printf("\n Is host equal to device = %d", checkHostEqualsDevice(tempBuffer,t));
    printf("\n Speedup = %fx", (float)(cpuTime/gpuTime));

    unInitializeCPU(&t, &t_prev);
    unInitializeGPU(&d_t, &d_t_prev);

    if(tempBuffer !=NULL)
        free(tempBuffer);

    printf("\n Finished Processing!!!");
    getchar();

}


void parseCommandLineArguments(int argc, char**argv)
{
    if (argc >= 1)
    {
        for (int i=1; i < argc; i++)
        {
            int bFirstArgIsParam = false;
            int string_start = 0;
            while (argv[i][string_start] == '-')
                string_start++;
            char *string_argv = &argv[i][string_start];

            if (!STRNCASECMP(string_argv, "Ni=", 3))
            {
                bFirstArgIsParam = true;
                Ni = atoi(&string_argv[3]);
                continue;
            }
            if (!STRNCASECMP(string_argv, "Nj=", 3))
            {
                bFirstArgIsParam = true;
                Nj = atoi(&string_argv[3]);
                continue;
            }
            if (!STRNCASECMP(string_argv, "iterations=", 11))
            {
                bFirstArgIsParam = true;
                nIterations = atoi(&string_argv[11]);
                continue;
            }
            if (!STRNCASECMP(string_argv, "kernel=", 7))
            {
                bFirstArgIsParam = true;
                kernelVersion = atoi(&string_argv[7]);
                continue;
            }

            if (!bFirstArgIsParam)
            {
                printf("Invalid arguments\n");
                for (int n=0; n < argc; n++)
                {
                    printf("argv[%d] = %s\n", n, argv[n]);
                }
                printf("\n");
                exit(0);
            }
        }
    }

    if(( Ni % THREADS_PER_BLOCK_Y != 0)  || (Nj % THREADS_PER_BLOCK_X != 0))
    {
        fprintf(stderr, "Please specify Ni & Nj as multiple of 16 !!!!");
        getchar();
        exit(0);
    }
}

int initializeCPU(float **t, float **t_prev)
{
    *t = (float*) calloc(Ni*Nj, sizeof(float));
    *t_prev = (float*) calloc(Ni*Nj, sizeof(float));

    if((*t)==NULL || (*t_prev) == NULL)
        return 0;
    else
        return 1;
}

void unInitializeCPU(float **t, float **t_prev)
{
    if((*t) !=NULL)
        free(*t);
    if((*t_prev) != NULL)
        free(*t_prev);
}

int initializeGPU(float **d_t, float **d_t_prev)
{

    unsigned int size = Ni * Nj * sizeof(float);



    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaError_t cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        getchar();
        return 0;
    }
    // Allocate GPU buffers.
    cudaStatus = cudaMalloc((void**)&(*d_t), size);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        getchar();
        return 0;
    }

    // Allocate GPU buffers   .
    cudaStatus = cudaMalloc((void**)&(*d_t_prev), size);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        getchar();
        return 0;
    }

    // Memset GPU buffers
    cudaStatus = cudaMemset((*d_t),0, size);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemset failed!");
        getchar();
        return 0;
    }

    // Memset GPU buffers
    cudaStatus = cudaMemset((*d_t_prev),0, size);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemset failed!");
        getchar();
        return 0;
    }

    return 1;
}


void unInitializeGPU(float **d_t, float **d_t_prev)
{
    cudaError_t cudaStatus;

    if((*d_t)!=NULL)
        cudaStatus = cudaFree((*d_t));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaFree failed!");
        return;
    }

    if((*d_t_prev)!=NULL)
        cudaStatus = cudaFree((*d_t_prev));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaFree failed!");
        return;
    }

    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        getchar();
        return;
    }
}

void performCPUCFD(float *t, float *t_prev, float *cpuTime)
{

    float h,x,y;

    h = 1.0f/(Ni-1);

    for(unsigned int i=0;i<Ni;i++)
    {
        x = i*h;
        t_prev[i*Nj+0] = x*x;
        t_prev[i*Nj+(Nj-1)] = x*x + 1.0f;
    }

    for(unsigned int j=0;j < Nj; j++)
    {
        y = j*h;
        t_prev[0*Nj+j] = y*y;
        t_prev[((Ni-1) * Nj) + j] = 1.0f + y*y;

    }

    float elapsedTimeInMs = 0.0f;

    clock_t start = clock();

    for(unsigned int k=0;k<nIterations;k++)
    {
        for(unsigned int j=1;j<(Nj-1);j++)
        {
            for(unsigned int i=1;i<(Ni-1);i++)
            {
                t[i*Nj+j] = 0.25f * (t_prev[(i-1)*Nj+j] + t_prev[(i+1)*Nj+j] + t_prev[i*Nj+(j-1)] +
                                     t_prev[i*Nj+(j+1)] - 4*h*h);
            }
        }

        float* pingPong = t_prev;
        t_prev = t;
        t = pingPong;
    }

    clock_t end = clock();
    elapsedTimeInMs = (float)((end - start) * 1000 / CLOCKS_PER_SEC);

    printf("\n CPU Time:: %f ms", elapsedTimeInMs);
    *cpuTime = elapsedTimeInMs;
}

int performGPUCFD(float *d_t, float *d_t_prev, float *t, float *t_prev, float*gpuTime)
{

    float h,x,y;
    const char *str = (char*) malloc(1024); // To store error string

    //Decide how many blocks per thread and how many blocks per grid
    dim3 dimBlock(THREADS_PER_BLOCK_X,THREADS_PER_BLOCK_Y);
    dim3 dimGrid(Nj/dimBlock.x,Ni/dimBlock.y);

    h = 1.0f/(Ni-1);
    memset(t_prev, 0, sizeof(float) * Ni * Nj);

    for(unsigned int i=0;i<Ni;i++)
    {
        x = i*h;
        t_prev[i*Nj+0] = x*x;
        t_prev[i*Nj+(Nj-1)] = x*x + 1.0f;
    }

    for(unsigned int j=0;j < Nj; j++)
    {
        y = j*h;
        t_prev[0*Nj+j] = y*y;
        t_prev[((Ni-1) * Nj) + j] = 1.0f + y*y;

    }

    //Copy data to device
    cudaMemcpy(d_t_prev, t_prev, sizeof(float) * Ni * Nj , cudaMemcpyHostToDevice);

    //Insert event to calculate time
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);


    //This calls Version 1 of kernel which uses Global memory
    if(kernelVersion ==1)
    {
        cudaEventRecord(start, 0);

        for(unsigned int k=0;k<nIterations;k++)
        {
            // Launch a kernel on the GPU with one thread for each element.
            calculateCFD_V1<<<dimGrid,dimBlock>>>(d_t_prev,d_t, Ni, Nj, h);

            float* pingPong = d_t_prev;
            d_t_prev = d_t;
            d_t = pingPong;
        }
        cudaEventRecord(stop, 0);
        cudaEventSynchronize(stop);
    }
        //This calls Version 2 of kernel which uses optimization by copying data to shared memory
    else if(kernelVersion ==2)
    {
        cudaEventRecord(start, 0);

        for(unsigned int k=0;k<nIterations;k++)
        {
            // Launch a kernel on the GPU with one thread for each element.
            calculateCFD_V2<<<dimGrid,dimBlock>>>(d_t_prev,d_t, Ni, Nj, h);

            float* pingPong = d_t_prev;
            d_t_prev = d_t;
            d_t = pingPong;
        }
        cudaEventRecord(stop, 0);
        cudaEventSynchronize(stop);

    }

    float elapsedTime;
    cudaEventElapsedTime(&elapsedTime, start, stop);
    printf("\n GPU Time:: %f ms", elapsedTime);

    *gpuTime = elapsedTime;

    cudaError_t cudaStatus = cudaMemcpy(t, d_t_prev, sizeof(float) * Ni * Nj , cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        str = cudaGetErrorString(cudaStatus);
        fprintf(stderr, "CUDA Error!:: %s\n", str);
        getchar();
        return 0;
    }

    return 1;
}

int checkHostEqualsDevice(float* o_host, float* o_device)
{
    int flag =1;

    float tolerance = 0.0001f;
    //Compare the results
    for(unsigned int j=0;j<Nj;j++)
    {
        for(unsigned int i=0;i<Ni;i++)
        {
            if( (o_host[i*Nj+j] - o_device[i*Nj+j]) >= tolerance ||  (o_host[i*Nj+j] - o_device[i*Nj+j]) <= -tolerance)
            {
                printf("\n D=[%f]!=H=[%f] since Diff  > tol %f for [%d][%d]",o_device[i*Nj+j],  o_host[i*Nj+j],tolerance, i, j);
                flag =0;
                //getchar();
            }
        }
    }

    return flag;
}
	.file	"tmpxft_002999de_00000000-6_main.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3646:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3646:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Ni="
.LC1:
	.string	"Nj="
.LC2:
	.string	"iterations="
.LC3:
	.string	"kernel="
.LC4:
	.string	"Invalid arguments\n"
.LC5:
	.string	"argv[%d] = %s\n"
.LC6:
	.string	"\n"
.LC7:
	.string	"Please specify Ni & Nj as multiple of 16 !!!!"
	.text
	.globl	_Z25parseCommandLineArgumentsiPPc
	.type	_Z25parseCommandLineArgumentsiPPc, @function
_Z25parseCommandLineArgumentsiPPc:
.LFB3636:
	.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
	movslq	%edi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rdx
	.cfi_def_cfa_offset 64
	testl	%ebp, %ebp
	jle	.L3
	leal	-1(%rbp), %eax
	movq	%rsi, %r12
	leaq	.LC3(%rip), %r15
	movq	%rsi, %r13
	leaq	(%rsi,%rax,8), %r14
.L4:
	cmpq	%r13, %r14
	je	.L3
	movq	8(%r13), %rax
.L5:
	movq	%rax, %rbx
	incq	%rax
	cmpb	$45, -1(%rax)
	je	.L5
	movl	$3, %edx
	leaq	.LC0(%rip), %rsi
	movq	%rbx, %rdi
	call	strncasecmp@PLT
	testl	%eax, %eax
	jne	.L6
	leaq	3(%rbx), %rdi
	call	atoi@PLT
	movl	%eax, Ni(%rip)
	jmp	.L7
.L6:
	movl	$3, %edx
	leaq	.LC1(%rip), %rsi
	movq	%rbx, %rdi
	call	strncasecmp@PLT
	testl	%eax, %eax
	jne	.L8
	leaq	3(%rbx), %rdi
	call	atoi@PLT
	movl	%eax, Nj(%rip)
	jmp	.L7
.L8:
	movl	$11, %edx
	leaq	.LC2(%rip), %rsi
	movq	%rbx, %rdi
	call	strncasecmp@PLT
	testl	%eax, %eax
	jne	.L9
	leaq	11(%rbx), %rdi
	call	atoi@PLT
	movl	%eax, nIterations(%rip)
	jmp	.L7
.L9:
	movl	$7, %edx
	movq	%r15, %rsi
	movq	%rbx, %rdi
	call	strncasecmp@PLT
	testl	%eax, %eax
	jne	.L10
	leaq	7(%rbx), %rdi
	call	atoi@PLT
	movl	%eax, kernelVersion(%rip)
	jmp	.L7
.L10:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %r13
.L11:
	movq	(%r12,%rbx,8), %rcx
	movl	%ebx, %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	%rbx, %rbp
	jne	.L11
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L16
.L7:
	addq	$8, %r13
	jmp	.L4
.L3:
	movl	Ni(%rip), %eax
	movl	Nj(%rip), %edx
	andl	$15, %eax
	andl	$31, %edx
	orl	%edx, %eax
	je	.L2
	movq	stderr(%rip), %rdi
	leaq	.LC7(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	getchar@PLT
.L16:
	xorl	%edi, %edi
	call	exit@PLT
.L2:
	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
.LFE3636:
	.size	_Z25parseCommandLineArgumentsiPPc, .-_Z25parseCommandLineArgumentsiPPc
	.globl	_Z13initializeCPUPPfS0_
	.type	_Z13initializeCPUPPfS0_, @function
_Z13initializeCPUPPfS0_:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rsi, %r12
	movl	$4, %esi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	Ni(%rip), %ebp
	imull	Nj(%rip), %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movq	%rbp, %rdi
	call	calloc@PLT
	movq	%rbp, %rdi
	movl	$4, %esi
	movq	%rax, (%rbx)
	call	calloc@PLT
	movq	%rax, (%r12)
	movq	%rax, %rdx
	cmpq	$0, (%rbx)
	sete	%al
	testq	%rdx, %rdx
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	sete	%dl
	popq	%r12
	.cfi_def_cfa_offset 8
	orl	%edx, %eax
	xorl	$1, %eax
	movzbl	%al, %eax
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z13initializeCPUPPfS0_, .-_Z13initializeCPUPPfS0_
	.globl	_Z15unInitializeCPUPPfS0_
	.type	_Z15unInitializeCPUPPfS0_, @function
_Z15unInitializeCPUPPfS0_:
.LFB3638:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	(%rdi), %rdi
	movq	%rsi, %rbx
	testq	%rdi, %rdi
	je	.L21
	call	free@PLT
.L21:
	movq	(%rbx), %rdi
	testq	%rdi, %rdi
	je	.L20
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	free@PLT
.L20:
	.cfi_restore_state
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3638:
	.size	_Z15unInitializeCPUPPfS0_, .-_Z15unInitializeCPUPPfS0_
	.section	.rodata.str1.1
.LC8:
	.string	"cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?"
.LC9:
	.string	"cudaMalloc failed!"
.LC10:
	.string	"cudaMemset failed!"
	.text
	.globl	_Z13initializeGPUPPfS0_
	.type	_Z13initializeGPUPPfS0_, @function
_Z13initializeGPUPPfS0_:
.LFB3639:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	xorl	%edi, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	movl	Ni(%rip), %ebp
	movl	Nj(%rip), %r13d
	call	cudaSetDevice@PLT
	leaq	.LC8(%rip), %rdx
	testl	%eax, %eax
	jne	.L37
	imull	%r13d, %ebp
	movq	%r12, %rdi
	leal	0(,%rbp,4), %ebp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L30
.L38:
	leaq	.LC9(%rip), %rdx
.L37:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	getchar@PLT
	xorl	%eax, %eax
	jmp	.L27
.L30:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L38
	movq	(%r12), %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	call	cudaMemset@PLT
	testl	%eax, %eax
	jne	.L39
	movq	(%rbx), %rdi
	movq	%rbp, %rdx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	%eax, %edx
	movl	$1, %eax
	testl	%edx, %edx
	je	.L27
.L39:
	leaq	.LC10(%rip), %rdx
	jmp	.L37
.L27:
	popq	%rdx
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3639:
	.size	_Z13initializeGPUPPfS0_, .-_Z13initializeGPUPPfS0_
	.section	.rodata.str1.1
.LC11:
	.string	"cudaFree failed!"
.LC12:
	.string	"cudaDeviceReset failed!"
	.text
	.globl	_Z15unInitializeGPUPPfS0_
	.type	_Z15unInitializeGPUPPfS0_, @function
_Z15unInitializeGPUPPfS0_:
.LFB3640:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	(%rdi), %rdi
	movq	%rsi, %rbx
	testq	%rdi, %rdi
	je	.L41
	call	cudaFree@PLT
.L41:
	testl	%eax, %eax
	jne	.L55
	movq	(%rbx), %rdi
	testq	%rdi, %rdi
	je	.L43
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L43
.L55:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	leaq	.LC11(%rip), %rdx
	jmp	__fprintf_chk@PLT
.L43:
	.cfi_restore_state
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L40
	movq	stderr(%rip), %rdi
	leaq	.LC12(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	getchar@PLT
.L40:
	.cfi_restore_state
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3640:
	.size	_Z15unInitializeGPUPPfS0_, .-_Z15unInitializeGPUPPfS0_
	.section	.rodata.str1.1
.LC16:
	.string	"\n CPU Time:: %f ms"
	.text
	.globl	_Z13performCPUCFDPfS_S_
	.type	_Z13performCPUCFDPfS_S_, @function
_Z13performCPUCFDPfS_S_:
.LFB3641:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%ecx, %ecx
	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
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	xorl	%esi, %esi
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	Ni(%rip), %edi
	movss	.LC13(%rip), %xmm2
	leal	-1(%rdi), %edx
	movaps	%xmm2, %xmm1
	cvtsi2ssq	%rdx, %xmm0
	movq	%rdx, %rax
	movl	Nj(%rip), %edx
	leal	-1(%rdx), %r8d
	divss	%xmm0, %xmm1
.L59:
	cmpl	%ecx, %edi
	je	.L74
	movl	%ecx, %r9d
	incl	%ecx
	cvtsi2ssq	%r9, %xmm0
	movl	%esi, %r9d
	mulss	%xmm1, %xmm0
	mulss	%xmm0, %xmm0
	movss	%xmm0, (%rbx,%r9,4)
	addss	%xmm2, %xmm0
	leal	(%r8,%rsi), %r9d
	addl	%edx, %esi
	movss	%xmm0, (%rbx,%r9,4)
	jmp	.L59
.L74:
	imull	%edx, %eax
	movl	%eax, %ecx
	xorl	%eax, %eax
.L63:
	movl	%eax, %esi
	cmpl	%edx, %eax
	jnb	.L75
	movl	%eax, %edi
	addl	%ecx, %esi
	cvtsi2ssq	%rdi, %xmm0
	movl	%esi, %esi
	mulss	%xmm1, %xmm0
	mulss	%xmm0, %xmm0
	movss	%xmm0, (%rbx,%rax,4)
	addss	%xmm2, %xmm0
	incq	%rax
	movss	%xmm0, (%rbx,%rsi,4)
	jmp	.L63
.L75:
	movss	%xmm1, 12(%rsp)
	call	clock@PLT
	movl	Nj(%rip), %edi
	xorl	%ecx, %ecx
	movl	nIterations(%rip), %r9d
	movq	%rax, %r13
	movl	Ni(%rip), %eax
	movss	.LC14(%rip), %xmm3
	movss	.LC15(%rip), %xmm4
	movss	12(%rsp), %xmm1
	leal	-1(%rdi), %r10d
	leal	-1(%rax), %esi
.L67:
	cmpl	%ecx, %r9d
	je	.L76
	movl	$1, %edx
.L70:
	cmpl	%r10d, %edx
	jnb	.L77
	movl	%edx, %r14d
	movl	$1, %r8d
.L69:
	leal	(%rdi,%r14), %eax
	cmpl	%esi, %r8d
	jnb	.L78
	movaps	%xmm1, %xmm2
	leal	(%rdi,%rax), %r15d
	movl	%eax, %r11d
	incl	%r8d
	mulss	%xmm3, %xmm2
	movss	(%rbx,%r15,4), %xmm0
	addss	(%rbx,%r14,4), %xmm0
	leal	-1(%rax), %r14d
	addss	(%rbx,%r14,4), %xmm0
	leal	1(%rax), %r14d
	addss	(%rbx,%r14,4), %xmm0
	movl	%eax, %r14d
	mulss	%xmm1, %xmm2
	subss	%xmm2, %xmm0
	mulss	%xmm4, %xmm0
	movss	%xmm0, 0(%rbp,%r11,4)
	jmp	.L69
.L78:
	incl	%edx
	jmp	.L70
.L77:
	incl	%ecx
	xchgq	%rbx, %rbp
	jmp	.L67
.L76:
	call	clock@PLT
	movl	$1000, %ecx
	movl	$2, %edi
	leaq	.LC16(%rip), %rsi
	subq	%r13, %rax
	cqto
	idivq	%rcx
	cvtsi2ssq	%rax, %xmm1
	movb	$1, %al
	movss	%xmm1, 12(%rsp)
	cvtss2sd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm1
	movss	%xmm1, (%r12)
	addq	$24, %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
.LFE3641:
	.size	_Z13performCPUCFDPfS_S_, .-_Z13performCPUCFDPfS_S_
	.section	.rodata.str1.1
.LC17:
	.string	"\n GPU Time:: %f ms"
.LC18:
	.string	"cudaMemcpy failed!"
.LC19:
	.string	"CUDA Error!:: %s\n"
	.text
	.globl	_Z13performGPUCFDPfS_S_S_S_
	.type	_Z13performGPUCFDPfS_S_S_S_, @function
_Z13performGPUCFDPfS_S_S_S_:
.LFB3642:
	.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
	movq	%r8, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	movq	%rcx, %rsi
	movq	%rsi, %rdi
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movl	Ni(%rip), %ecx
	movss	.LC13(%rip), %xmm1
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	movl	Nj(%rip), %eax
	movl	$1, 56(%rsp)
	movaps	%xmm1, %xmm2
	movl	$1, 68(%rsp)
	movl	%eax, %edx
	shrl	$5, %edx
	movl	%edx, 60(%rsp)
	movl	%ecx, %edx
	shrl	$4, %edx
	movl	%edx, 64(%rsp)
	leal	-1(%rcx), %edx
	cvtsi2ssq	%rdx, %xmm0
	xorl	%edx, %edx
	imulq	%rax, %rcx
	xorl	%eax, %eax
	divss	%xmm0, %xmm2
	salq	$2, %rcx
	rep stosb
	movl	Nj(%rip), %eax
	movl	Ni(%rip), %edi
	leal	-1(%rax), %r8d
	movss	%xmm2, 12(%rsp)
.L82:
	cmpl	%edx, %edi
	je	.L104
	movl	%edx, %r9d
	incl	%edx
	cvtsi2ssq	%r9, %xmm0
	mulss	12(%rsp), %xmm0
	movl	%ecx, %r9d
	mulss	%xmm0, %xmm0
	movss	%xmm0, (%rsi,%r9,4)
	addss	%xmm1, %xmm0
	leal	(%r8,%rcx), %r9d
	addl	%eax, %ecx
	movss	%xmm0, (%rsi,%r9,4)
	jmp	.L82
.L104:
	leal	-1(%rdx), %edi
	xorl	%ecx, %ecx
	imull	%eax, %edi
.L86:
	movl	%ecx, %r8d
	cmpl	%eax, %ecx
	jnb	.L105
	movl	%ecx, %r9d
	addl	%edi, %r8d
	cvtsi2ssq	%r9, %xmm0
	mulss	12(%rsp), %xmm0
	movl	%r8d, %r8d
	mulss	%xmm0, %xmm0
	movss	%xmm0, (%rsi,%rcx,4)
	addss	%xmm1, %xmm0
	incq	%rcx
	movss	%xmm0, (%rsi,%r8,4)
	jmp	.L86
.L105:
	imulq	%rax, %rdx
	movl	$1, %ecx
	movq	%rbx, %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	kernelVersion(%rip), %eax
	movq	32(%rsp), %rdi
	cmpl	$1, %eax
	jne	.L90
	movabsq	$68719476768, %r15
	xorl	%esi, %esi
	xorl	%r14d, %r14d
	call	cudaEventRecord@PLT
.L91:
	cmpl	nIterations(%rip), %r14d
	jnb	.L103
	movl	56(%rsp), %ecx
	movq	60(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	68(%rsp), %esi
	movq	%r15, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L92
	movss	12(%rsp), %xmm0
	movl	Nj(%rip), %ecx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	movl	Ni(%rip), %edx
	call	_Z15calculateCFD_V1PfS_jjf@PLT
.L92:
	incl	%r14d
	xchgq	%rbx, %rbp
	jmp	.L91
.L90:
	cmpl	$2, %eax
	jne	.L94
	movabsq	$68719476768, %r15
	xorl	%esi, %esi
	xorl	%r14d, %r14d
	call	cudaEventRecord@PLT
.L95:
	cmpl	nIterations(%rip), %r14d
	jnb	.L103
	movl	56(%rsp), %ecx
	movq	60(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	68(%rsp), %esi
	movq	%r15, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L96
	movss	12(%rsp), %xmm0
	movl	Nj(%rip), %ecx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	movl	Ni(%rip), %edx
	call	_Z15calculateCFD_V2PfS_jjf@PLT
.L96:
	incl	%r14d
	xchgq	%rbx, %rbp
	jmp	.L95
.L103:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
.L94:
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	28(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%rbx, %rsi
	movl	Ni(%rip), %edx
	movl	Nj(%rip), %eax
	movss	28(%rsp), %xmm0
	movl	$2, %ecx
	movq	%r12, %rdi
	imulq	%rax, %rdx
	movss	%xmm0, 0(%r13)
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	movl	$1, %eax
	testl	%ebx, %ebx
	je	.L79
	movq	stderr(%rip), %rdi
	leaq	.LC18(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC19(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	getchar@PLT
	xorl	%eax, %eax
.L79:
	movq	72(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L99
	call	__stack_chk_fail@PLT
.L99:
	addq	$88, %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
.LFE3642:
	.size	_Z13performGPUCFDPfS_S_S_S_, .-_Z13performGPUCFDPfS_S_S_S_
	.section	.rodata.str1.1
.LC23:
	.string	"\n D=[%f]!=H=[%f] since Diff  > tol %f for [%d][%d]"
	.text
	.globl	_Z21checkHostEqualsDevicePfS_
	.type	_Z21checkHostEqualsDevicePfS_, @function
_Z21checkHostEqualsDevicePfS_:
.LFB3643:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rsi, %r13
	movl	$1, %edx
	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
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L107:
	cmpl	Nj(%rip), %ebx
	jnb	.L115
	xorl	%ebp, %ebp
.L112:
	cmpl	Ni(%rip), %ebp
	movl	Nj(%rip), %eax
	jnb	.L116
	imull	%ebp, %eax
	addl	%ebx, %eax
	movl	%eax, %eax
	movss	(%r12,%rax,4), %xmm1
	movss	0(%r13,%rax,4), %xmm0
	movaps	%xmm1, %xmm2
	subss	%xmm0, %xmm2
	comiss	.LC20(%rip), %xmm2
	jnb	.L108
	movss	.LC21(%rip), %xmm3
	comiss	%xmm2, %xmm3
	jb	.L109
.L108:
	movsd	.LC22(%rip), %xmm2
	movl	%ebp, %edx
	movl	%ebx, %ecx
	movb	$3, %al
	leaq	.LC23(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	call	__printf_chk@PLT
	xorl	%edx, %edx
.L109:
	incl	%ebp
	jmp	.L112
.L116:
	incl	%ebx
	jmp	.L107
.L115:
	movl	%edx, %eax
	popq	%rdx
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3643:
	.size	_Z21checkHostEqualsDevicePfS_, .-_Z21checkHostEqualsDevicePfS_
	.section	.rodata.str1.1
.LC24:
	.string	"\n Ni= %d, Nj=%d nIteration=%d"
.LC25:
	.string	"\n Error in allocating memory on CPU!!!"
.LC26:
	.string	"\n Error in allocating memory on GPU!!!"
.LC27:
	.string	"\n GPU Kernel failed !!!"
.LC28:
	.string	"\n Is host equal to device = %d"
.LC29:
	.string	"\n Speedup = %fx"
.LC30:
	.string	"\n Finished Processing!!!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	leaq	48(%rsp), %rbp
	movq	%rax, 40(%rsp)
	movq	%rax, 56(%rsp)
	movq	%rax, 64(%rsp)
	call	_Z25parseCommandLineArgumentsiPPc
	movl	nIterations(%rip), %r8d
	xorl	%eax, %eax
	movl	Nj(%rip), %ecx
	movl	Ni(%rip), %edx
	leaq	.LC24(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	40(%rsp), %rax
	movq	%rbp, %rsi
	movl	Ni(%rip), %r14d
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	movl	Nj(%rip), %r15d
	call	_Z13initializeCPUPPfS0_
	testl	%eax, %eax
	jne	.L118
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z15unInitializeCPUPPfS0_
	jmp	.L124
.L118:
	leaq	64(%rsp), %rax
	movq	%rax, 8(%rsp)
	leaq	56(%rsp), %rax
	movq	8(%rsp), %rsi
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	_Z13initializeGPUPPfS0_
	testl	%eax, %eax
	jne	.L120
	leaq	.LC26(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z15unInitializeCPUPPfS0_
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z15unInitializeGPUPPfS0_
	jmp	.L119
.L120:
	movq	48(%rsp), %r13
	movq	40(%rsp), %r12
	leaq	32(%rsp), %rdx
	imull	%r15d, %r14d
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z13performCPUCFDPfS_S_
	movl	Ni(%rip), %ebx
	movl	$4, %esi
	imull	Nj(%rip), %ebx
	movq	%rbx, %rdi
	call	calloc@PLT
	leaq	0(,%rbx,4), %rcx
	leal	0(,%r14,4), %edx
	movq	%r13, %rsi
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
	call	__memcpy_chk@PLT
	movq	64(%rsp), %rsi
	movq	%r13, %rcx
	movq	%r12, %rdx
	movq	56(%rsp), %rdi
	leaq	36(%rsp), %r8
	call	_Z13performGPUCFDPfS_S_S_S_
	testl	%eax, %eax
	jne	.L121
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z15unInitializeCPUPPfS0_
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	call	_Z15unInitializeGPUPPfS0_
	movq	24(%rsp), %rdi
	call	free@PLT
	jmp	.L119
.L121:
	movq	24(%rsp), %rdi
	movq	%r12, %rsi
	call	_Z21checkHostEqualsDevicePfS_
	leaq	.LC28(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC29(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movss	32(%rsp), %xmm0
	divss	36(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z15unInitializeCPUPPfS0_
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z15unInitializeGPUPPfS0_
	movq	24(%rsp), %rdi
	call	free@PLT
	leaq	.LC30(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L124:
	call	getchar@PLT
.L119:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L122
	call	__stack_chk_fail@PLT
.L122:
	addq	$88, %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
.LFE3635:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3669:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3669:
	.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
	.globl	kernelVersion
	.data
	.align 4
	.type	kernelVersion, @object
	.size	kernelVersion, 4
kernelVersion:
	.long	2
	.globl	nIterations
	.align 4
	.type	nIterations, @object
	.size	nIterations, 4
nIterations:
	.long	10000
	.globl	Nj
	.align 4
	.type	Nj, @object
	.size	Nj, 4
Nj:
	.long	512
	.globl	Ni
	.align 4
	.type	Ni, @object
	.size	Ni, 4
Ni:
	.long	512
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC13:
	.long	1065353216
	.align 4
.LC14:
	.long	1082130432
	.align 4
.LC15:
	.long	1048576000
	.align 4
.LC20:
	.long	953267991
	.align 4
.LC21:
	.long	-1194215657
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC22:
	.long	-536870912
	.long	1058682594
	.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 <iostream>
#include "hip/hip_runtime.h"

#include "definitions.cuh"
#include <time.h>
#include "stdio.h"

//Number of elements on which to perform CFD
unsigned int Ni = 512; // Y elements
unsigned int Nj = 512; // X elements
unsigned int nIterations = 10000; // No Of Iterations
unsigned int kernelVersion =2; // Decides which GPU kernel version to call (Set it to 1 or 2)

int main(int argc, char** argv)
{

    //Variables for Timing
    float cpuTime, gpuTime;

    // CPU and GPU Pointers ( d_XX : refers to pointer pointing to GPU memory. This is just a convention)
    float *t = NULL, *t_prev = NULL;
    float *d_t = NULL,*d_t_prev= NULL;

    parseCommandLineArguments(argc, (char **)argv);
    printf("\n Ni= %d, Nj=%d nIteration=%d",Ni,Nj,nIterations);

    unsigned int size = Ni * Nj * sizeof(float);

    if(!initializeCPU(&t, &t_prev) )
    {
        printf("\n Error in allocating memory on CPU!!!");
        unInitializeCPU(&t, &t_prev);
        getchar();
        return 0;
    }

    if (!initializeGPU(&d_t, &d_t_prev))
    {
        printf("\n Error in allocating memory on GPU!!!");
        unInitializeCPU(&t, &t_prev);
        unInitializeGPU(&d_t, &d_t_prev);
        return 0;
    }

    //Perform CFD on CPU
    performCPUCFD(t,t_prev, &cpuTime);

    // To temporarily store CPU data. This is just for comparing with GPU output
    float *tempBuffer = (float*) calloc(Ni*Nj, sizeof(float));
    memcpy(tempBuffer, t_prev, size);

    //Perform CFD on GPU
    if(!performGPUCFD(d_t,d_t_prev, t, t_prev, &gpuTime))
    {
        printf("\n GPU Kernel failed !!!");
        unInitializeCPU(&t, &t_prev);
        unInitializeGPU(&d_t, &d_t_prev);
        if(tempBuffer !=NULL)
            free(tempBuffer);
        return 0;
    }

    printf("\n Is host equal to device = %d", checkHostEqualsDevice(tempBuffer,t));
    printf("\n Speedup = %fx", (float)(cpuTime/gpuTime));

    unInitializeCPU(&t, &t_prev);
    unInitializeGPU(&d_t, &d_t_prev);

    if(tempBuffer !=NULL)
        free(tempBuffer);

    printf("\n Finished Processing!!!");
    getchar();

}


void parseCommandLineArguments(int argc, char**argv)
{
    if (argc >= 1)
    {
        for (int i=1; i < argc; i++)
        {
            int bFirstArgIsParam = false;
            int string_start = 0;
            while (argv[i][string_start] == '-')
                string_start++;
            char *string_argv = &argv[i][string_start];

            if (!STRNCASECMP(string_argv, "Ni=", 3))
            {
                bFirstArgIsParam = true;
                Ni = atoi(&string_argv[3]);
                continue;
            }
            if (!STRNCASECMP(string_argv, "Nj=", 3))
            {
                bFirstArgIsParam = true;
                Nj = atoi(&string_argv[3]);
                continue;
            }
            if (!STRNCASECMP(string_argv, "iterations=", 11))
            {
                bFirstArgIsParam = true;
                nIterations = atoi(&string_argv[11]);
                continue;
            }
            if (!STRNCASECMP(string_argv, "kernel=", 7))
            {
                bFirstArgIsParam = true;
                kernelVersion = atoi(&string_argv[7]);
                continue;
            }

            if (!bFirstArgIsParam)
            {
                printf("Invalid arguments\n");
                for (int n=0; n < argc; n++)
                {
                    printf("argv[%d] = %s\n", n, argv[n]);
                }
                printf("\n");
                exit(0);
            }
        }
    }

    if(( Ni % THREADS_PER_BLOCK_Y != 0)  || (Nj % THREADS_PER_BLOCK_X != 0))
    {
        fprintf(stderr, "Please specify Ni & Nj as multiple of 16 !!!!");
        getchar();
        exit(0);
    }
}

int initializeCPU(float **t, float **t_prev)
{
    *t = (float*) calloc(Ni*Nj, sizeof(float));
    *t_prev = (float*) calloc(Ni*Nj, sizeof(float));

    if((*t)==NULL || (*t_prev) == NULL)
        return 0;
    else
        return 1;
}

void unInitializeCPU(float **t, float **t_prev)
{
    if((*t) !=NULL)
        free(*t);
    if((*t_prev) != NULL)
        free(*t_prev);
}

int initializeGPU(float **d_t, float **d_t_prev)
{

    unsigned int size = Ni * Nj * sizeof(float);



    // Choose which GPU to run on, change this on a multi-GPU system.
    hipError_t cudaStatus = hipSetDevice(0);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        getchar();
        return 0;
    }
    // Allocate GPU buffers.
    cudaStatus = hipMalloc((void**)&(*d_t), size);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        getchar();
        return 0;
    }

    // Allocate GPU buffers   .
    cudaStatus = hipMalloc((void**)&(*d_t_prev), size);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        getchar();
        return 0;
    }

    // Memset GPU buffers
    cudaStatus = hipMemset((*d_t),0, size);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemset failed!");
        getchar();
        return 0;
    }

    // Memset GPU buffers
    cudaStatus = hipMemset((*d_t_prev),0, size);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemset failed!");
        getchar();
        return 0;
    }

    return 1;
}


void unInitializeGPU(float **d_t, float **d_t_prev)
{
    hipError_t cudaStatus;

    if((*d_t)!=NULL)
        cudaStatus = hipFree((*d_t));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipFree failed!");
        return;
    }

    if((*d_t_prev)!=NULL)
        cudaStatus = hipFree((*d_t_prev));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipFree failed!");
        return;
    }

    cudaStatus = hipDeviceReset();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceReset failed!");
        getchar();
        return;
    }
}

void performCPUCFD(float *t, float *t_prev, float *cpuTime)
{

    float h,x,y;

    h = 1.0f/(Ni-1);

    for(unsigned int i=0;i<Ni;i++)
    {
        x = i*h;
        t_prev[i*Nj+0] = x*x;
        t_prev[i*Nj+(Nj-1)] = x*x + 1.0f;
    }

    for(unsigned int j=0;j < Nj; j++)
    {
        y = j*h;
        t_prev[0*Nj+j] = y*y;
        t_prev[((Ni-1) * Nj) + j] = 1.0f + y*y;

    }

    float elapsedTimeInMs = 0.0f;

    clock_t start = clock();

    for(unsigned int k=0;k<nIterations;k++)
    {
        for(unsigned int j=1;j<(Nj-1);j++)
        {
            for(unsigned int i=1;i<(Ni-1);i++)
            {
                t[i*Nj+j] = 0.25f * (t_prev[(i-1)*Nj+j] + t_prev[(i+1)*Nj+j] + t_prev[i*Nj+(j-1)] +
                                     t_prev[i*Nj+(j+1)] - 4*h*h);
            }
        }

        float* pingPong = t_prev;
        t_prev = t;
        t = pingPong;
    }

    clock_t end = clock();
    elapsedTimeInMs = (float)((end - start) * 1000 / CLOCKS_PER_SEC);

    printf("\n CPU Time:: %f ms", elapsedTimeInMs);
    *cpuTime = elapsedTimeInMs;
}

int performGPUCFD(float *d_t, float *d_t_prev, float *t, float *t_prev, float*gpuTime)
{

    float h,x,y;
    const char *str = (char*) malloc(1024); // To store error string

    //Decide how many blocks per thread and how many blocks per grid
    dim3 dimBlock(THREADS_PER_BLOCK_X,THREADS_PER_BLOCK_Y);
    dim3 dimGrid(Nj/dimBlock.x,Ni/dimBlock.y);

    h = 1.0f/(Ni-1);
    memset(t_prev, 0, sizeof(float) * Ni * Nj);

    for(unsigned int i=0;i<Ni;i++)
    {
        x = i*h;
        t_prev[i*Nj+0] = x*x;
        t_prev[i*Nj+(Nj-1)] = x*x + 1.0f;
    }

    for(unsigned int j=0;j < Nj; j++)
    {
        y = j*h;
        t_prev[0*Nj+j] = y*y;
        t_prev[((Ni-1) * Nj) + j] = 1.0f + y*y;

    }

    //Copy data to device
    hipMemcpy(d_t_prev, t_prev, sizeof(float) * Ni * Nj , hipMemcpyHostToDevice);

    //Insert event to calculate time
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);


    //This calls Version 1 of kernel which uses Global memory
    if(kernelVersion ==1)
    {
        hipEventRecord(start, 0);

        for(unsigned int k=0;k<nIterations;k++)
        {
            // Launch a kernel on the GPU with one thread for each element.
            calculateCFD_V1<<<dimGrid,dimBlock>>>(d_t_prev,d_t, Ni, Nj, h);

            float* pingPong = d_t_prev;
            d_t_prev = d_t;
            d_t = pingPong;
        }
        hipEventRecord(stop, 0);
        hipEventSynchronize(stop);
    }
        //This calls Version 2 of kernel which uses optimization by copying data to shared memory
    else if(kernelVersion ==2)
    {
        hipEventRecord(start, 0);

        for(unsigned int k=0;k<nIterations;k++)
        {
            // Launch a kernel on the GPU with one thread for each element.
            calculateCFD_V2<<<dimGrid,dimBlock>>>(d_t_prev,d_t, Ni, Nj, h);

            float* pingPong = d_t_prev;
            d_t_prev = d_t;
            d_t = pingPong;
        }
        hipEventRecord(stop, 0);
        hipEventSynchronize(stop);

    }

    float elapsedTime;
    hipEventElapsedTime(&elapsedTime, start, stop);
    printf("\n GPU Time:: %f ms", elapsedTime);

    *gpuTime = elapsedTime;

    hipError_t cudaStatus = hipMemcpy(t, d_t_prev, sizeof(float) * Ni * Nj , hipMemcpyDeviceToHost);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        str = hipGetErrorString(cudaStatus);
        fprintf(stderr, "CUDA Error!:: %s\n", str);
        getchar();
        return 0;
    }

    return 1;
}

int checkHostEqualsDevice(float* o_host, float* o_device)
{
    int flag =1;

    float tolerance = 0.0001f;
    //Compare the results
    for(unsigned int j=0;j<Nj;j++)
    {
        for(unsigned int i=0;i<Ni;i++)
        {
            if( (o_host[i*Nj+j] - o_device[i*Nj+j]) >= tolerance ||  (o_host[i*Nj+j] - o_device[i*Nj+j]) <= -tolerance)
            {
                printf("\n D=[%f]!=H=[%f] since Diff  > tol %f for [%d][%d]",o_device[i*Nj+j],  o_host[i*Nj+j],tolerance, i, j);
                flag =0;
                //getchar();
            }
        }
    }

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

                                        # End of file scope inline assembly
	.globl	main                            # -- Begin function 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	%rbx
	.cfi_def_cfa_offset 40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%eax, %eax
	leaq	24(%rsp), %rbx
	movq	%rax, (%rbx)
	leaq	16(%rsp), %r14
	movq	%rax, (%r14)
	movq	%rax, 8(%rsp)
	movq	%rax, (%rsp)
	callq	_Z25parseCommandLineArgumentsiPPc
	movl	Ni(%rip), %esi
	movl	Nj(%rip), %edx
	movl	nIterations(%rip), %ecx
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	Ni(%rip), %ebp
	imull	Nj(%rip), %ebp
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z13initializeCPUPPfS0_
	testl	%eax, %eax
	je	.LBB0_1
# %bb.2:
	leaq	8(%rsp), %rdi
	movq	%rsp, %rsi
	callq	_Z13initializeGPUPPfS0_
	testl	%eax, %eax
	je	.LBB0_3
# %bb.4:
	shll	$2, %ebp
	movq	24(%rsp), %r14
	movq	16(%rsp), %r15
	leaq	36(%rsp), %rdx
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	_Z13performCPUCFDPfS_S_
	movl	Nj(%rip), %edi
	imull	Ni(%rip), %edi
	movl	$4, %esi
	callq	calloc
	movq	%rax, %rbx
	movl	%ebp, %edx
	movq	%rax, %rdi
	movq	%r15, %rsi
	callq	memcpy@PLT
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	leaq	32(%rsp), %r8
	movq	%r14, %rdx
	movq	%r15, %rcx
	callq	_Z13performGPUCFDPfS_S_S_S_
	testl	%eax, %eax
	je	.LBB0_5
# %bb.7:
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z21checkHostEqualsDevicePfS_
	movl	$.L.str.4, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movss	36(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	divss	32(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	leaq	24(%rsp), %rdi
	leaq	16(%rsp), %rsi
	callq	_Z15unInitializeCPUPPfS0_
	leaq	8(%rsp), %rdi
	movq	%rsp, %rsi
	callq	_Z15unInitializeGPUPPfS0_
	testq	%rbx, %rbx
	je	.LBB0_9
# %bb.8:
	movq	%rbx, %rdi
	callq	free
.LBB0_9:
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB0_10
.LBB0_1:
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	24(%rsp), %rdi
	leaq	16(%rsp), %rsi
	callq	_Z15unInitializeCPUPPfS0_
.LBB0_10:
	callq	getchar
	jmp	.LBB0_11
.LBB0_3:
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	24(%rsp), %rdi
	leaq	16(%rsp), %rsi
	callq	_Z15unInitializeCPUPPfS0_
	leaq	8(%rsp), %rdi
	movq	%rsp, %rsi
	callq	_Z15unInitializeGPUPPfS0_
	jmp	.LBB0_11
.LBB0_5:
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	24(%rsp), %rdi
	leaq	16(%rsp), %rsi
	callq	_Z15unInitializeCPUPPfS0_
	leaq	8(%rsp), %rdi
	movq	%rsp, %rsi
	callq	_Z15unInitializeGPUPPfS0_
	testq	%rbx, %rbx
	je	.LBB0_11
# %bb.6:
	movq	%rbx, %rdi
	callq	free
.LBB0_11:
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z25parseCommandLineArgumentsiPPc # -- Begin function _Z25parseCommandLineArgumentsiPPc
	.type	_Z25parseCommandLineArgumentsiPPc,@function
_Z25parseCommandLineArgumentsiPPc:      # @_Z25parseCommandLineArgumentsiPPc
	.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
	cmpl	$2, %edi
	jl	.LBB1_12
# %bb.1:                                # %.preheader.preheader
	movq	%rsi, %rbx
	movl	%edi, %r15d
	movl	$1, %r12d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
	movq	(%rbx,%r12,8), %r14
	decq	%r14
.LBB1_3:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpb	$45, 1(%r14)
	leaq	1(%r14), %r14
	je	.LBB1_3
# %bb.4:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$3, %r13d
	movl	$.L.str.7, %esi
	movl	$3, %edx
	movq	%r14, %rdi
	callq	strncasecmp
	testl	%eax, %eax
	je	.LBB1_8
# %bb.5:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$3, %r13d
	movl	$.L.str.8, %esi
	movl	$3, %edx
	movq	%r14, %rdi
	callq	strncasecmp
	testl	%eax, %eax
	je	.LBB1_9
# %bb.6:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$11, %r13d
	movl	$.L.str.9, %esi
	movl	$11, %edx
	movq	%r14, %rdi
	callq	strncasecmp
	testl	%eax, %eax
	je	.LBB1_10
# %bb.7:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$7, %r13d
	movl	$.L.str.10, %esi
	movl	$7, %edx
	movq	%r14, %rdi
	callq	strncasecmp
	movl	$kernelVersion, %ebp
	testl	%eax, %eax
	je	.LBB1_11
	jmp	.LBB1_15
.LBB1_8:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$Ni, %ebp
	jmp	.LBB1_11
.LBB1_9:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$Nj, %ebp
	jmp	.LBB1_11
.LBB1_10:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$nIterations, %ebp
.LBB1_11:                               #   in Loop: Header=BB1_2 Depth=1
	addq	%r13, %r14
	movq	%r14, %rdi
	callq	atoi
	movl	%eax, (%rbp)
	incq	%r12
	cmpq	%r15, %r12
	jne	.LBB1_2
.LBB1_12:                               # %.loopexit
	testb	$15, Ni(%rip)
	jne	.LBB1_19
# %bb.13:
	testb	$31, Nj(%rip)
	jne	.LBB1_19
# %bb.14:
	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
.LBB1_15:                               # %.lr.ph.preheader
	.cfi_def_cfa_offset 64
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%r14d, %r14d
.LBB1_16:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r14,8), %rdx
	movl	$.L.str.12, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB1_16
# %bb.17:                               # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	jmp	.LBB1_18
.LBB1_19:
	movq	stderr(%rip), %rcx
	movl	$.L.str.14, %edi
	movl	$45, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	callq	getchar
.LBB1_18:                               # %._crit_edge
	xorl	%edi, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z25parseCommandLineArgumentsiPPc, .Lfunc_end1-_Z25parseCommandLineArgumentsiPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z13initializeCPUPPfS0_         # -- Begin function _Z13initializeCPUPPfS0_
	.type	_Z13initializeCPUPPfS0_,@function
_Z13initializeCPUPPfS0_:                # @_Z13initializeCPUPPfS0_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	Nj(%rip), %r15d
	imull	Ni(%rip), %r15d
	movl	$4, %esi
	movq	%r15, %rdi
	callq	calloc
	movq	%rax, (%r14)
	movl	$4, %esi
	movq	%r15, %rdi
	callq	calloc
	movq	%rax, (%rbx)
	cmpq	$0, (%r14)
	setne	%cl
	testq	%rax, %rax
	setne	%al
	andb	%cl, %al
	movzbl	%al, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z13initializeCPUPPfS0_, .Lfunc_end2-_Z13initializeCPUPPfS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z15unInitializeCPUPPfS0_       # -- Begin function _Z15unInitializeCPUPPfS0_
	.type	_Z15unInitializeCPUPPfS0_,@function
_Z15unInitializeCPUPPfS0_:              # @_Z15unInitializeCPUPPfS0_
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rsi, %rbx
	movq	(%rdi), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	callq	free
.LBB3_2:
	movq	(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB3_3
# %bb.4:
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.LBB3_3:
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z15unInitializeCPUPPfS0_, .Lfunc_end3-_Z15unInitializeCPUPPfS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z13initializeGPUPPfS0_         # -- Begin function _Z13initializeGPUPPfS0_
	.type	_Z13initializeGPUPPfS0_,@function
_Z13initializeGPUPPfS0_:                # @_Z13initializeGPUPPfS0_
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	Ni(%rip), %ebx
	movl	Nj(%rip), %ebp
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB4_1
# %bb.2:
	imull	%ebp, %ebx
	shll	$2, %ebx
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB4_3
# %bb.4:
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB4_3
# %bb.5:
	movq	(%r15), %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB4_7
# %bb.6:
	movq	(%r14), %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	hipMemset
	movl	%eax, %ecx
	movl	$1, %eax
	testl	%ecx, %ecx
	je	.LBB4_10
.LBB4_7:
	movq	stderr(%rip), %rcx
	movl	$.L.str.17, %edi
	jmp	.LBB4_8
.LBB4_3:
	movq	stderr(%rip), %rcx
	movl	$.L.str.16, %edi
.LBB4_8:                                # %.sink.split
	movl	$17, %esi
	jmp	.LBB4_9
.LBB4_1:
	movq	stderr(%rip), %rcx
	movl	$.L.str.15, %edi
	movl	$63, %esi
.LBB4_9:                                # %.sink.split
	movl	$1, %edx
	callq	fwrite@PLT
	callq	getchar
	xorl	%eax, %eax
.LBB4_10:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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	_Z13initializeGPUPPfS0_, .Lfunc_end4-_Z13initializeGPUPPfS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z15unInitializeGPUPPfS0_       # -- Begin function _Z15unInitializeGPUPPfS0_
	.type	_Z15unInitializeGPUPPfS0_,@function
_Z15unInitializeGPUPPfS0_:              # @_Z15unInitializeGPUPPfS0_
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rsi, %rbx
	movq	(%rdi), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB5_6
.LBB5_2:                                # %.thread
	movq	(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB5_4
# %bb.3:
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB5_6
.LBB5_4:                                # %.critedge
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB5_7
# %bb.5:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB5_6:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rcx
	movl	$.L.str.18, %edi
	movl	$15, %esi
	movl	$1, %edx
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	fwrite@PLT                      # TAILCALL
.LBB5_7:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rcx
	movl	$.L.str.19, %edi
	movl	$22, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	getchar                         # TAILCALL
.Lfunc_end5:
	.size	_Z15unInitializeGPUPPfS0_, .Lfunc_end5-_Z15unInitializeGPUPPfS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13performCPUCFDPfS_S_
.LCPI6_0:
	.long	0x3f800000                      # float 1
.LCPI6_1:
	.long	0x40800000                      # float 4
.LCPI6_2:
	.long	0x3e800000                      # float 0.25
	.text
	.globl	_Z13performCPUCFDPfS_S_
	.type	_Z13performCPUCFDPfS_S_,@function
_Z13performCPUCFDPfS_S_:                # @_Z13performCPUCFDPfS_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	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	Ni(%rip), %edx
	movl	%edx, %eax
	movl	Nj(%rip), %ecx
	subl	$1, %eax
	cvtsi2ss	%rax, %xmm1
	movss	.LCPI6_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movaps	%xmm0, %xmm2
	divss	%xmm1, %xmm2
	jb	.LBB6_3
# %bb.1:                                # %.lr.ph
	leal	-1(%rcx), %esi
	xorl	%edi, %edi
	xorl	%r8d, %r8d
.LBB6_2:                                # =>This Inner Loop Header: Depth=1
	movl	%r8d, %r9d
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r9, %xmm1
	mulss	%xmm2, %xmm1
	mulss	%xmm1, %xmm1
	movl	%edi, %r9d
	movss	%xmm1, (%r14,%r9,4)
	addss	%xmm0, %xmm1
	leal	(%rsi,%rdi), %r9d
	movss	%xmm1, (%r14,%r9,4)
	incq	%r8
	addl	%ecx, %edi
	cmpq	%r8, %rdx
	jne	.LBB6_2
.LBB6_3:                                # %.preheader61
	testq	%rcx, %rcx
	je	.LBB6_6
# %bb.4:                                # %.lr.ph64
	imull	%ecx, %eax
	xorl	%edx, %edx
.LBB6_5:                                # =>This Inner Loop Header: Depth=1
	movl	%edx, %esi
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rsi, %xmm1
	mulss	%xmm2, %xmm1
	mulss	%xmm1, %xmm1
	movss	%xmm1, (%r14,%rdx,4)
	addss	%xmm0, %xmm1
	leal	(%rax,%rdx), %esi
	movss	%xmm1, (%r14,%rsi,4)
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB6_5
.LBB6_6:                                # %._crit_edge
	movss	%xmm2, 4(%rsp)                  # 4-byte Spill
	callq	clock
	movq	%rax, %r12
	movl	nIterations(%rip), %eax
	testl	%eax, %eax
	je	.LBB6_14
# %bb.7:                                # %.preheader60.lr.ph
	movl	Nj(%rip), %ecx
	leal	-1(%rcx), %edx
	movl	Ni(%rip), %esi
	decl	%esi
	movss	.LCPI6_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	mulss	%xmm1, %xmm0
	leaq	-1(%rsi), %rdi
	leal	(%rcx,%rcx), %r8d
	xorl	%r9d, %r9d
	movss	.LCPI6_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB6_8:                                # %.preheader60
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_10 Depth 2
                                        #       Child Loop BB6_16 Depth 3
	movq	%r15, %r10
	cmpl	$2, %edx
	jb	.LBB6_13
# %bb.9:                                # %.preheader.preheader
                                        #   in Loop: Header=BB6_8 Depth=1
	movl	$1, %r15d
.LBB6_10:                               # %.preheader
                                        #   Parent Loop BB6_8 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB6_16 Depth 3
	cmpl	$1, %esi
	jbe	.LBB6_11
# %bb.15:                               # %.lr.ph66
                                        #   in Loop: Header=BB6_10 Depth=2
	leal	1(%r15), %r11d
	movq	%rdi, %r13
.LBB6_16:                               #   Parent Loop BB6_8 Depth=1
                                        #     Parent Loop BB6_10 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%r15d, %ebp
	movss	(%r14,%rbp,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	leal	(%r8,%r15), %ebp
	addss	(%r14,%rbp,4), %xmm2
	leal	(%rcx,%r15), %ebp
	decl	%ebp
	addss	(%r14,%rbp,4), %xmm2
	leal	1(%rcx,%r15), %ebp
	addl	%ecx, %r15d
	addss	(%r14,%rbp,4), %xmm2
	subss	%xmm0, %xmm2
	mulss	%xmm1, %xmm2
	movss	%xmm2, (%r10,%r15,4)
                                        # kill: def $r15d killed $r15d killed $r15 def $r15
	decq	%r13
	jne	.LBB6_16
	jmp	.LBB6_12
.LBB6_11:                               # %.preheader.._crit_edge67_crit_edge
                                        #   in Loop: Header=BB6_10 Depth=2
	incl	%r15d
	movl	%r15d, %r11d
.LBB6_12:                               # %._crit_edge67
                                        #   in Loop: Header=BB6_10 Depth=2
	movl	%r11d, %r15d
	cmpl	%edx, %r11d
	jne	.LBB6_10
.LBB6_13:                               # %._crit_edge69
                                        #   in Loop: Header=BB6_8 Depth=1
	incl	%r9d
	movq	%r14, %r15
	movq	%r10, %r14
	cmpl	%eax, %r9d
	jne	.LBB6_8
.LBB6_14:                               # %._crit_edge73
	callq	clock
	subq	%r12, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rdx, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.20, %edi
	movb	$1, %al
	callq	printf
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rbx)
	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_end6:
	.size	_Z13performCPUCFDPfS_S_, .Lfunc_end6-_Z13performCPUCFDPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13performGPUCFDPfS_S_S_S_
.LCPI7_0:
	.long	0x3f800000                      # float 1
	.text
	.globl	_Z13performGPUCFDPfS_S_S_S_
	.type	_Z13performGPUCFDPfS_S_S_S_,@function
_Z13performGPUCFDPfS_S_S_S_:            # @_Z13performGPUCFDPfS_S_S_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
	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	%r8, 32(%rsp)                   # 8-byte Spill
	movq	%rcx, %rbp
	movq	%rdx, 40(%rsp)                  # 8-byte Spill
	movq	%rsi, %r15
	movq	%rdi, %r13
	movl	Nj(%rip), %edx
	movl	%edx, %ebx
	shrl	$5, %ebx
	movl	Ni(%rip), %r12d
	leal	-1(%r12), %eax
	imulq	%r12, %rdx
                                        # kill: def $r12d killed $r12d killed $r12 def $r12
	shrl	$4, %r12d
	cvtsi2ss	%rax, %xmm0
	movss	.LCPI7_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	divss	%xmm0, %xmm1
	movss	%xmm1, 12(%rsp)                 # 4-byte Spill
	shlq	$2, %rdx
	xorl	%r14d, %r14d
	movq	%rcx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movss	.LCPI7_0(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movss	12(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movl	Ni(%rip), %edx
	movl	Nj(%rip), %eax
	testq	%rdx, %rdx
	je	.LBB7_3
# %bb.1:                                # %.lr.ph
	leal	-1(%rax), %ecx
	xorl	%esi, %esi
.LBB7_2:                                # =>This Inner Loop Header: Depth=1
	movl	%esi, %edi
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rdi, %xmm0
	mulss	%xmm1, %xmm0
	mulss	%xmm0, %xmm0
	movl	%r14d, %edi
	movss	%xmm0, (%rbp,%rdi,4)
	addss	%xmm2, %xmm0
	leal	(%rcx,%r14), %edi
	movss	%xmm0, (%rbp,%rdi,4)
	incq	%rsi
	addl	%eax, %r14d
	cmpq	%rsi, %rdx
	jne	.LBB7_2
.LBB7_3:                                # %.preheader
	shlq	$32, %r12
	testq	%rax, %rax
	je	.LBB7_4
# %bb.9:                                # %.lr.ph84
	leal	-1(%rdx), %ecx
	imull	%eax, %ecx
	xorl	%esi, %esi
.LBB7_10:                               # =>This Inner Loop Header: Depth=1
	movl	%esi, %edi
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rdi, %xmm0
	mulss	%xmm1, %xmm0
	mulss	%xmm0, %xmm0
	movss	%xmm0, (%rbp,%rsi,4)
	addss	%xmm2, %xmm0
	leal	(%rcx,%rsi), %edi
	movss	%xmm0, (%rbp,%rdi,4)
	incq	%rsi
	cmpq	%rsi, %rax
	jne	.LBB7_10
	jmp	.LBB7_5
.LBB7_4:
	xorl	%eax, %eax
.LBB7_5:                                # %._crit_edge
	orq	%rbx, %r12
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r15, %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movl	kernelVersion(%rip), %eax
	cmpl	$1, %eax
	je	.LBB7_11
# %bb.6:                                # %._crit_edge
	cmpl	$2, %eax
	jne	.LBB7_21
# %bb.7:
	movq	24(%rsp), %rdi
	xorl	%r14d, %r14d
	xorl	%esi, %esi
	callq	hipEventRecord
	cmpl	$0, nIterations(%rip)
	je	.LBB7_8
# %bb.16:                               # %.lr.ph90.preheader
	movabsq	$68719476768, %rbx              # imm = 0x1000000020
.LBB7_17:                               # %.lr.ph90
                                        # =>This Inner Loop Header: Depth=1
	movq	%r13, %rbp
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_19
# %bb.18:                               #   in Loop: Header=BB7_17 Depth=1
	movl	Ni(%rip), %edx
	movl	Nj(%rip), %ecx
	movq	%r15, %rdi
	movq	%rbp, %rsi
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	_Z30__device_stub__calculateCFD_V2PfS_jjf
.LBB7_19:                               #   in Loop: Header=BB7_17 Depth=1
	incl	%r14d
	movq	%r15, %r13
	movq	%rbp, %r15
	cmpl	nIterations(%rip), %r14d
	jb	.LBB7_17
	jmp	.LBB7_20
.LBB7_11:
	movq	24(%rsp), %rdi
	xorl	%r14d, %r14d
	xorl	%esi, %esi
	callq	hipEventRecord
	cmpl	$0, nIterations(%rip)
	je	.LBB7_8
# %bb.12:                               # %.lr.ph97.preheader
	movabsq	$68719476768, %rbx              # imm = 0x1000000020
.LBB7_13:                               # %.lr.ph97
                                        # =>This Inner Loop Header: Depth=1
	movq	%r13, %rbp
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_15
# %bb.14:                               #   in Loop: Header=BB7_13 Depth=1
	movl	Ni(%rip), %edx
	movl	Nj(%rip), %ecx
	movq	%r15, %rdi
	movq	%rbp, %rsi
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	_Z30__device_stub__calculateCFD_V1PfS_jjf
.LBB7_15:                               #   in Loop: Header=BB7_13 Depth=1
	incl	%r14d
	movq	%r15, %r13
	movq	%rbp, %r15
	cmpl	nIterations(%rip), %r14d
	jb	.LBB7_13
	jmp	.LBB7_20
.LBB7_8:
	movq	%r15, %rbp
.LBB7_20:                               # %.sink.split
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	%rbp, %r15
.LBB7_21:
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	52(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.21, %edi
	movb	$1, %al
	callq	printf
	movss	(%rbx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movq	32(%rsp), %rax                  # 8-byte Reload
	movss	%xmm0, (%rax)
	movl	Ni(%rip), %eax
	movl	Nj(%rip), %edx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rsi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$1, %ebx
	testl	%eax, %eax
	jne	.LBB7_22
.LBB7_23:
	movl	%ebx, %eax
	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
.LBB7_22:
	.cfi_def_cfa_offset 112
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str.22, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	stderr(%rip), %rdi
	xorl	%ebx, %ebx
	movl	$.L.str.23, %esi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	callq	getchar
	jmp	.LBB7_23
.Lfunc_end7:
	.size	_Z13performGPUCFDPfS_S_S_S_, .Lfunc_end7-_Z13performGPUCFDPfS_S_S_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z21checkHostEqualsDevicePfS_
.LCPI8_0:
	.long	0x38d1b717                      # float 9.99999974E-5
.LCPI8_1:
	.long	0xb8d1b717                      # float -9.99999974E-5
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI8_2:
	.quad	0x3f1a36e2e0000000              # double 9.9999997473787516E-5
	.text
	.globl	_Z21checkHostEqualsDevicePfS_
	.type	_Z21checkHostEqualsDevicePfS_,@function
_Z21checkHostEqualsDevicePfS_:          # @_Z21checkHostEqualsDevicePfS_
	.cfi_startproc
# %bb.0:
	movl	Nj(%rip), %ecx
	testl	%ecx, %ecx
	je	.LBB8_1
# %bb.3:                                # %.preheader.preheader
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.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 %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	$1, %eax
	xorl	%ebp, %ebp
	movl	Ni(%rip), %edx
	movss	.LCPI8_0(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movl	%edx, %esi
.LBB8_4:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_9 Depth 2
	testl	%esi, %esi
	je	.LBB8_5
# %bb.8:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB8_4 Depth=1
	xorl	%r15d, %r15d
.LBB8_9:                                # %.lr.ph
                                        #   Parent Loop BB8_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%ecx, %esi
	imull	%r15d, %esi
	addl	%ebp, %esi
	movss	(%r14,%rsi,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movss	(%rbx,%rsi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movaps	%xmm1, %xmm2
	subss	%xmm0, %xmm2
	ucomiss	%xmm3, %xmm2
	jae	.LBB8_11
# %bb.10:                               # %.lr.ph
                                        #   in Loop: Header=BB8_9 Depth=2
	movss	.LCPI8_1(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	ucomiss	%xmm2, %xmm4
	jb	.LBB8_12
.LBB8_11:                               #   in Loop: Header=BB8_9 Depth=2
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	movl	$.L.str.24, %edi
	movsd	.LCPI8_2(%rip), %xmm2           # xmm2 = mem[0],zero
	movl	%r15d, %esi
	movl	%ebp, %edx
	movb	$3, %al
	callq	printf
	movss	.LCPI8_0(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movl	Nj(%rip), %ecx
	xorl	%eax, %eax
	movl	Ni(%rip), %edx
.LBB8_12:                               #   in Loop: Header=BB8_9 Depth=2
	incl	%r15d
	movl	%edx, %esi
	cmpl	%edx, %r15d
	jb	.LBB8_9
	jmp	.LBB8_6
.LBB8_5:                                #   in Loop: Header=BB8_4 Depth=1
	xorl	%esi, %esi
.LBB8_6:                                # %._crit_edge
                                        #   in Loop: Header=BB8_4 Depth=1
	incl	%ebp
	cmpl	%ecx, %ebp
	jb	.LBB8_4
# %bb.7:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
	retq
.LBB8_1:
	movl	$1, %eax
	retq
.Lfunc_end8:
	.size	_Z21checkHostEqualsDevicePfS_, .Lfunc_end8-_Z21checkHostEqualsDevicePfS_
	.cfi_endproc
                                        # -- End function
	.type	Ni,@object                      # @Ni
	.data
	.globl	Ni
	.p2align	2, 0x0
Ni:
	.long	512                             # 0x200
	.size	Ni, 4

	.type	Nj,@object                      # @Nj
	.globl	Nj
	.p2align	2, 0x0
Nj:
	.long	512                             # 0x200
	.size	Nj, 4

	.type	nIterations,@object             # @nIterations
	.globl	nIterations
	.p2align	2, 0x0
nIterations:
	.long	10000                           # 0x2710
	.size	nIterations, 4

	.type	kernelVersion,@object           # @kernelVersion
	.globl	kernelVersion
	.p2align	2, 0x0
kernelVersion:
	.long	2                               # 0x2
	.size	kernelVersion, 4

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"\n Ni= %d, Nj=%d nIteration=%d"
	.size	.L.str, 30

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\n Error in allocating memory on CPU!!!"
	.size	.L.str.1, 39

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\n Error in allocating memory on GPU!!!"
	.size	.L.str.2, 39

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\n GPU Kernel failed !!!"
	.size	.L.str.3, 24

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n Is host equal to device = %d"
	.size	.L.str.4, 31

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\n Speedup = %fx"
	.size	.L.str.5, 16

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\n Finished Processing!!!"
	.size	.L.str.6, 25

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Nj="
	.size	.L.str.8, 4

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"iterations="
	.size	.L.str.9, 12

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"kernel="
	.size	.L.str.10, 8

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"argv[%d] = %s\n"
	.size	.L.str.12, 15

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Please specify Ni & Nj as multiple of 16 !!!!"
	.size	.L.str.14, 46

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"hipSetDevice failed!  Do you have a CUDA-capable GPU installed?"
	.size	.L.str.15, 64

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"hipMalloc failed!"
	.size	.L.str.16, 18

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"hipMemset failed!"
	.size	.L.str.17, 18

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"hipFree failed!"
	.size	.L.str.18, 16

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"hipDeviceReset failed!"
	.size	.L.str.19, 23

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"\n CPU Time:: %f ms"
	.size	.L.str.20, 19

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"\n GPU Time:: %f ms"
	.size	.L.str.21, 19

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"hipMemcpy failed!"
	.size	.L.str.22, 18

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"CUDA Error!:: %s\n"
	.size	.L.str.23, 18

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"\n D=[%f]!=H=[%f] since Diff  > tol %f for [%d][%d]"
	.size	.L.str.24, 51

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Invalid arguments"
	.size	.Lstr, 18

	.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_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
