
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <cuda.h>

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>

// #include "cudaDefines.h"

struct ImgProp {
	uint32_t Hpixels;
	uint32_t Vpixels;

	uint8_t HeaderInfo[14];
	uint8_t* HeaderMeta;
	uint16_t HeaderMetaSize;

	uint32_t Hbytes;
	uint32_t IMAGESIZE;
};

struct ImgProp ip;
uint8_t* TheImg, * CpyImg;
uint8_t* GPUImg, * GPUCopyImg;

uint8_t* ReadBMPlin(char* fn) {
	static uint8_t* Img;
    FILE* f = fopen(fn, "rb");
	if (f == NULL) { printf("\n\n%s NOT FOUND\n\n", fn); exit(EXIT_FAILURE); }
	uint8_t HeaderInfo[14];
	fread(HeaderInfo, sizeof(uint8_t), 14, f); // read the 54-byte header
	ip.HeaderMetaSize = *(int*)&HeaderInfo[10];
	ip.HeaderMeta = (uint8_t*)malloc(ip.HeaderMetaSize * sizeof(uint8_t));
	fread(ip.HeaderMeta, sizeof(uint8_t), ip.HeaderMetaSize, f); // read the 54-byte header

	// extract image height and width from header
	int width = *(int*)&(ip.HeaderMeta[4]); ip.Hpixels = width;
	int height = *(int*)&(ip.HeaderMeta[8]); ip.Vpixels = height;
	//int RowBytes = (width * 3 + 3) & (~3); ip.Hbytes = RowBytes;
	int RowBytes = ip.Hpixels * 3; ip.Hbytes = RowBytes;

	ip.IMAGESIZE = ip.Hbytes * ip.Vpixels;
	memcpy(ip.HeaderInfo, HeaderInfo, 14); //save header for re-use
	printf("\n Input File name: %17s\n\nHeaderMetaSize: %u, Hb: %u, Hp: %u, Vp: %u, File Size=%u\n\n", fn,
		ip.HeaderMetaSize, ip.Hbytes, ip.Hpixels, ip.Vpixels, ip.IMAGESIZE);
	// allocate memory to store the main image (1 Dimensional array)
	Img = (uint8_t*)malloc(ip.IMAGESIZE);
	if (Img == NULL) return Img; // Cannot allocate memory
	// read the image from disk
	fread(Img, sizeof(uint8_t), ip.IMAGESIZE, f); fclose(f); return Img;
}

// Write the 1D linear-memory stored image into file.
void WriteBMPlin(uint8_t* Img, char* fn) {
	FILE* f = fopen(fn, "wb");
	if (f == NULL) { printf("\n\nFILE CREATION ERROR: %s\n\n", fn); exit(1); }
	fwrite(ip.HeaderInfo, sizeof(uint8_t), 14, f); //write header
	fwrite(ip.HeaderMeta, sizeof(uint8_t), ip.HeaderMetaSize, f); //write header
	fwrite(Img, sizeof(uint8_t), ip.IMAGESIZE, f); //write data
	printf("\nOutput File name: %17s (%u x %u) File Size=%u\n\n", fn, ip.Hpixels,
		ip.Vpixels, ip.IMAGESIZE);
	fclose(f);
}

__global__
void Vflip(uint8_t* ImgDst, uint8_t* ImgSrc, uint32_t Hpixels, uint32_t Vpixels) {
	uint32_t ThrPerBlk = blockDim.x;
	uint32_t MYbid = blockIdx.x;
	uint32_t MYtid = threadIdx.x;
	uint32_t MYgtid = ThrPerBlk * MYbid + MYtid;
	uint32_t BlkPerRow = (Hpixels + ThrPerBlk - 1) / ThrPerBlk; // ceil
	uint32_t RowBytes = (Hpixels * 3 + 3) & (~3);
	uint32_t MYrow = MYbid / BlkPerRow;
	uint32_t MYcol = MYgtid - MYrow * BlkPerRow * ThrPerBlk;
	if (MYcol >= Hpixels) return; // col out of range
	uint32_t MYmirrorrow = Vpixels - 1 - MYrow;
	uint32_t MYsrcOffset = MYrow * RowBytes;
	uint32_t MYdstOffset = MYmirrorrow * RowBytes;
	uint32_t MYsrcIndex = MYsrcOffset + 3 * MYcol;
	uint32_t MYdstIndex = MYdstOffset + 3 * MYcol;
	// swap pixels RGB @MYcol , @MYmirrorcol
	ImgDst[MYdstIndex] = ImgSrc[MYsrcIndex];
	ImgDst[MYdstIndex + 1] = ImgSrc[MYsrcIndex + 1];
	ImgDst[MYdstIndex + 2] = ImgSrc[MYsrcIndex + 2];
}

int main() {
	cudaError_t cudaStatus, cudaStatus2;
	cudaEvent_t time1, time2, time3, time4;
	cudaDeviceProp GPUprop;

	uint32_t SupportedKBlocks, SupportedMBlocks, MaxThrPerBlk;
	char SupportedBlocks[100];

	uint32_t BlkPerRow, ThrPerBlk = 128, NumBlocks, GPUDataTransfer;
	float totalTime, tfrCPUtoGPU, kernelExecutionTime, tfrGPUtoCPU;

	char InputFileName[] = "../img/img.bmp";
    char OutputFileName[] = "../img/flip.bmp";

	TheImg = ReadBMPlin(InputFileName);
	CpyImg = (uint8_t*)malloc(ip.IMAGESIZE);
	//WriteBMPlin(TheImg, OutputFileName);
	//return 0;

	int NumGPUs = 0; cudaGetDeviceCount(&NumGPUs);
	if (NumGPUs == 0) {
		std::cout << "\nNo CUDA Device is available\n";
		exit(EXIT_FAILURE);
	}

	cudaGetDeviceProperties(&GPUprop, 0);
	SupportedKBlocks = ((uint32_t)GPUprop.maxGridSize[0] * (uint32_t)GPUprop.maxGridSize[1] *
		(uint32_t)GPUprop.maxGridSize[2]) / 1024;

	SupportedMBlocks = SupportedKBlocks / 1024;
	sprintf(SupportedBlocks, "%u %c", (SupportedMBlocks >= 5) ? SupportedMBlocks : SupportedKBlocks,
		(SupportedMBlocks >= 5) ? 'M' : 'K');
	MaxThrPerBlk = (uint32_t)GPUprop.maxThreadsPerBlock;

	cudaEventCreate(&time1); cudaEventCreate(&time2);
	cudaEventCreate(&time3); cudaEventCreate(&time4);

	BlkPerRow = (ip.Hpixels + ThrPerBlk - 1) / ThrPerBlk;
	NumBlocks = ip.Vpixels * BlkPerRow;
	GPUDataTransfer = 2 * ip.IMAGESIZE;

	cudaEventRecord(time1, 0);
	cudaStatus = cudaMalloc((void**)&GPUImg, ip.IMAGESIZE);
	cudaStatus2 = cudaMalloc((void**)&GPUCopyImg, ip.IMAGESIZE);
	if ((cudaStatus != cudaSuccess) || (cudaStatus2 != cudaSuccess)) {
		std::cout << "cudaMalloc failed! Can't allocate GPU memory";
		exit(EXIT_FAILURE);
	}

	cudaStatus = cudaMemcpy(GPUImg, TheImg, ip.IMAGESIZE, cudaMemcpyHostToDevice);
	if (cudaStatus != cudaSuccess) {
		std::cout << "cudaMemCpy CPU to GPU failed!";
		exit(EXIT_FAILURE);
	}
	cudaEventRecord(time2, 0);

	Vflip <<<NumBlocks, ThrPerBlk>>> (GPUCopyImg, GPUImg, ip.Hpixels, ip.Vpixels);

	cudaStatus = cudaDeviceSynchronize();
	if (cudaStatus != cudaSuccess) {
		std::cout << "cudaDeviceSynchronize error code " << cudaStatus << " ...\n";
		exit(EXIT_FAILURE);
	}
	cudaEventRecord(time3, 0);

	cudaStatus = cudaMemcpy(CpyImg, GPUCopyImg, ip.IMAGESIZE, cudaMemcpyDeviceToHost);
	if (cudaStatus != cudaSuccess) {
		std::cout << "cudaMemCpy GPU to CPU failed!" << cudaStatus;
		exit(EXIT_FAILURE);
	}
	cudaEventRecord(time4, 0);

	cudaEventSynchronize(time1); cudaEventSynchronize(time2);
	cudaEventSynchronize(time3); cudaEventSynchronize(time4);
	cudaEventElapsedTime(&totalTime, time1, time4);
	cudaEventElapsedTime(&tfrCPUtoGPU, time1, time2);
	cudaEventElapsedTime(&kernelExecutionTime, time2, time3);
	cudaEventElapsedTime(&tfrGPUtoCPU, time3, time4);

	cudaStatus = cudaDeviceSynchronize();
	if (cudaStatus != cudaSuccess) {
		std::cout << "Program failed afeter cudaDeviceSyncronize()";
		free(TheImg); free(CpyImg);
		exit(EXIT_FAILURE);
	}

	WriteBMPlin(CpyImg, OutputFileName);

	printf("--...--\n"); printf("%s ComputeCapab=%d.%d [supports max %s blocks]\n",
		GPUprop.name, GPUprop.major, GPUprop.minor, SupportedBlocks); printf("...\n");
	printf("maxTrPerBlk: %d\n", MaxThrPerBlk);
	printf("%s\n %s\n\n ThrPerBlock: %u, Blocks: %u, BlkPerRow: %u\n", InputFileName,
		OutputFileName, ThrPerBlk, NumBlocks, BlkPerRow);
	printf("-------------------- ... ----------------------------\n");
	printf("CPU->GPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n",
		tfrCPUtoGPU, ip.IMAGESIZE / 1024 / 1024, (float)ip.IMAGESIZE / (tfrCPUtoGPU *
			1024.0 * 1024.0));
	printf("Kernel Execution = %5.2f ms ... %4d MB ... %6.2f GB/s\n",
		kernelExecutionTime, GPUDataTransfer / 1024 / 1024, (float)GPUDataTransfer /
		(kernelExecutionTime * 1024.0 * 1024.0));
	printf("GPU->CPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n",
		tfrGPUtoCPU, ip.IMAGESIZE / 1024 / 1024, (float)ip.IMAGESIZE / (tfrGPUtoCPU *
			1024.0 * 1024.0));
	printf("Total time elapsed = %5.2f ms\n", totalTime);
	printf("-------------------- ... ----------------------------\n");


	cudaFree(GPUImg); cudaFree(GPUCopyImg);
	cudaEventDestroy(time1); cudaEventDestroy(time2);
	cudaEventDestroy(time3); cudaEventDestroy(time4);

	cudaStatus = cudaDeviceReset();
	if (cudaStatus != cudaSuccess) {
		std::cout << "cudaDeviceReset failed!";
		free(TheImg); free(CpyImg); exit(EXIT_FAILURE);
	}
	free(TheImg); free(CpyImg);

	getchar();
	//getchar();
	return(EXIT_SUCCESS);
}
	.file	"tmpxft_0037f856_00000000-6_imgFlip.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3640:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3640:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"\n\n%s NOT FOUND\n\n"
.LC2:
	.string	"\n Input File name: %17s\n\nHeaderMetaSize: %u, Hb: %u, Hp: %u, Vp: %u, File Size=%u\n\n"
	.text
	.globl	_Z10ReadBMPlinPc
	.type	_Z10ReadBMPlinPc, @function
_Z10ReadBMPlinPc:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rsi
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L3
	movl	$2, %edi
	movq	%r12, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L3:
	leaq	10(%rsp), %rdi
	movq	%rax, %r8
	movl	$14, %ecx
	movq	%rax, %rbx
	movl	$1, %edx
	movl	$14, %esi
	call	__fread_chk@PLT
	movl	20(%rsp), %ebp
	movw	%bp, 32+ip(%rip)
	movzwl	%bp, %ebp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rcx
	movq	%rbp, %rsi
	movq	%rbx, %r8
	movq	%rax, %rdi
	movl	$1, %edx
	movq	%rax, 24+ip(%rip)
	call	__fread_chk@PLT
	movq	10(%rsp), %rcx
	movl	$2, %edi
	movq	24+ip(%rip), %rax
	leaq	.LC2(%rip), %rsi
	movl	4(%rax), %r9d
	movl	8(%rax), %eax
	movq	%rcx, 8+ip(%rip)
	movq	16(%rsp), %rcx
	leal	(%r9,%r9,2), %r8d
	movl	%eax, %edx
	movl	%eax, 4+ip(%rip)
	imull	%r8d, %edx
	movq	%rcx, 14+ip(%rip)
	movzwl	32+ip(%rip), %ecx
	movl	%r9d, ip(%rip)
	movl	%r8d, 36+ip(%rip)
	pushq	%rdx
	.cfi_def_cfa_offset 72
	pushq	%rax
	.cfi_def_cfa_offset 80
	xorl	%eax, %eax
	movl	%edx, 40+ip(%rip)
	movq	%r12, %rdx
	call	__printf_chk@PLT
	movl	40+ip(%rip), %ebp
	movq	%rbp, %rdi
	call	malloc@PLT
	popq	%rdx
	.cfi_def_cfa_offset 72
	popq	%rcx
	.cfi_def_cfa_offset 64
	movq	%rax, _ZZ10ReadBMPlinPcE3Img(%rip)
	testq	%rax, %rax
	je	.L2
	movq	%rbx, %r8
	movq	%rbp, %rcx
	movl	$1, %edx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	_ZZ10ReadBMPlinPcE3Img(%rip), %rax
.L2:
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z10ReadBMPlinPc, .-_Z10ReadBMPlinPc
	.section	.rodata.str1.1
.LC3:
	.string	"wb"
.LC4:
	.string	"\n\nFILE CREATION ERROR: %s\n\n"
.LC5:
	.string	"\nOutput File name: %17s (%u x %u) File Size=%u\n\n"
	.text
	.globl	_Z11WriteBMPlinPhPc
	.type	_Z11WriteBMPlinPhPc, @function
_Z11WriteBMPlinPhPc:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rsi, %rbp
	leaq	.LC3(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rbp, %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L12
	movl	$2, %edi
	movq	%rbp, %rdx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L12:
	movq	%rax, %rcx
	movl	$14, %edx
	movl	$1, %esi
	movq	%rax, %rbx
	leaq	8+ip(%rip), %rdi
	call	fwrite@PLT
	movzwl	32+ip(%rip), %edx
	movq	%rbx, %rcx
	movq	24+ip(%rip), %rdi
	movl	$1, %esi
	call	fwrite@PLT
	movq	%rbx, %rcx
	movq	%r12, %rdi
	movl	$1, %esi
	movl	40+ip(%rip), %edx
	call	fwrite@PLT
	movl	ip(%rip), %ecx
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	40+ip(%rip), %r9d
	movl	4+ip(%rip), %r8d
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE3636:
	.size	_Z11WriteBMPlinPhPc, .-_Z11WriteBMPlinPhPc
	.globl	_Z28__device_stub__Z5VflipPhS_jjPhS_jj
	.type	_Z28__device_stub__Z5VflipPhS_jjPhS_jj, @function
_Z28__device_stub__Z5VflipPhS_jjPhS_jj:
.LFB3662:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z5VflipPhS_jj(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L14:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3662:
	.size	_Z28__device_stub__Z5VflipPhS_jjPhS_jj, .-_Z28__device_stub__Z5VflipPhS_jjPhS_jj
	.globl	_Z5VflipPhS_jj
	.type	_Z5VflipPhS_jj, @function
_Z5VflipPhS_jj:
.LFB3663:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z5VflipPhS_jjPhS_jj
	.cfi_endproc
.LFE3663:
	.size	_Z5VflipPhS_jj, .-_Z5VflipPhS_jj
	.section	.rodata.str1.1
.LC6:
	.string	"\nNo CUDA Device is available\n"
.LC7:
	.string	"%u %c"
.LC8:
	.string	"cudaMalloc failed! Can't allocate GPU memory"
.LC9:
	.string	"cudaMemCpy CPU to GPU failed!"
.LC10:
	.string	"cudaDeviceSynchronize error code "
.LC11:
	.string	" ...\n"
.LC12:
	.string	"cudaMemCpy GPU to CPU failed!"
.LC13:
	.string	"Program failed afeter cudaDeviceSyncronize()"
.LC14:
	.string	"--...--\n"
.LC15:
	.string	"%s ComputeCapab=%d.%d [supports max %s blocks]\n"
.LC16:
	.string	"...\n"
.LC17:
	.string	"maxTrPerBlk: %d\n"
.LC18:
	.string	"%s\n %s\n\n ThrPerBlock: %u, Blocks: %u, BlkPerRow: %u\n"
.LC19:
	.string	"-------------------- ... ----------------------------\n"
.LC21:
	.string	"CPU->GPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n"
.LC22:
	.string	"Kernel Execution = %5.2f ms ... %4d MB ... %6.2f GB/s\n"
.LC23:
	.string	"GPU->CPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n"
.LC24:
	.string	"Total time elapsed = %5.2f ms\n"
.LC25:
	.string	"cudaDeviceReset failed!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3637:
	.cfi_startproc
	endbr64
	movabsq	$31645465844935020, %rdx
	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	$1272, %rsp
	.cfi_def_cfa_offset 1328
	movq	%fs:40, %rax
	movq	%rax, 1256(%rsp)
	movabsq	$7579390417501629998, %rax
	movq	%rdx, 1148(%rsp)
	movq	%rax, 1125(%rsp)
	movabsq	$31645465844346217, %rax
	movq	%rax, 1132(%rsp)
	movabsq	$7363217635387846190, %rax
	movq	%rax, 1140(%rsp)
	leaq	1125(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	_Z10ReadBMPlinPc
	movl	40+ip(%rip), %edi
	movq	%rax, TheImg(%rip)
	call	malloc@PLT
	xorl	%esi, %esi
	leaq	28(%rsp), %rdi
	movl	%esi, 28(%rsp)
	movq	%rax, CpyImg(%rip)
	call	cudaGetDeviceCount@PLT
	cmpl	$0, 28(%rsp)
	leaq	.LC6(%rip), %rsi
	je	.L38
	leaq	88(%rsp), %r14
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	424(%rsp), %r8d
	imull	428(%rsp), %r8d
	imull	432(%rsp), %r8d
	cmpl	$5242879, %r8d
	jbe	.L21
	shrl	$20, %r8d
	movl	$77, %r9d
	jmp	.L22
.L21:
	shrl	$10, %r8d
	movl	$75, %r9d
.L22:
	leaq	1156(%rsp), %r15
	leaq	.LC7(%rip), %rcx
	movl	$100, %edx
	xorl	%eax, %eax
	movl	$2, %esi
	movq	%r15, %rdi
	call	__sprintf_chk@PLT
	movl	408(%rsp), %eax
	leaq	32(%rsp), %rdi
	movl	%eax, 12(%rsp)
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	ip(%rip), %eax
	xorl	%esi, %esi
	movq	32(%rsp), %rdi
	movl	4+ip(%rip), %r13d
	leal	127(%rax), %ebp
	movl	40+ip(%rip), %eax
	shrl	$7, %ebp
	imull	%ebp, %r13d
	leal	(%rax,%rax), %ebx
	call	cudaEventRecord@PLT
	movl	40+ip(%rip), %esi
	leaq	GPUImg(%rip), %rdi
	call	cudaMalloc@PLT
	movl	40+ip(%rip), %esi
	leaq	GPUCopyImg(%rip), %rdi
	movl	%eax, %r12d
	call	cudaMalloc@PLT
	orl	%r12d, %eax
	je	.L23
	leaq	.LC8(%rip), %rsi
.L38:
	leaq	_ZSt4cout(%rip), %rdi
.L40:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L39:
	movl	$1, %edi
	call	exit@PLT
.L23:
	movq	TheImg(%rip), %rsi
	movl	40+ip(%rip), %edx
	movl	$1, %ecx
	movq	GPUImg(%rip), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC9(%rip), %rsi
	testl	%eax, %eax
	jne	.L38
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%r13d, 64(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	$33554433, %edx
	movl	$1, %ecx
	movl	$1, 84(%rsp)
	movq	%rax, 68(%rsp)
	movq	64(%rsp), %rdi
	salq	$7, %rdx
	movl	72(%rsp), %esi
	movq	%rdx, 76(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movl	4+ip(%rip), %ecx
	movl	ip(%rip), %edx
	movq	GPUImg(%rip), %rsi
	movq	GPUCopyImg(%rip), %rdi
	call	_Z28__device_stub__Z5VflipPhS_jjPhS_jj
.L25:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L26
	leaq	.LC10(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	jmp	.L40
.L26:
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	40+ip(%rip), %edx
	movl	$2, %ecx
	movq	GPUCopyImg(%rip), %rsi
	movq	CpyImg(%rip), %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L27
	leaq	.LC12(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	jmp	.L39
.L27:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdx
	leaq	76(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	call	cudaDeviceSynchronize@PLT
	leaq	.LC13(%rip), %rsi
	testl	%eax, %eax
	jne	.L41
	leaq	1140(%rsp), %r12
	movq	CpyImg(%rip), %rdi
	movq	%r12, %rsi
	call	_Z11WriteBMPlinPhPc
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r15, %r9
	movq	%r14, %rdx
	movl	$2, %edi
	movl	448(%rsp), %ecx
	movl	452(%rsp), %r8d
	leaq	.LC15(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	12(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC17(%rip), %rsi
	call	__printf_chk@PLT
	movl	%r13d, %r9d
	movq	%r12, %rcx
	movl	$2, %edi
	pushq	%rax
	.cfi_def_cfa_offset 1336
	movl	$128, %r8d
	leaq	.LC18(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 1344
	movq	16(%rsp), %rdx
	leaq	.LC19(%rip), %rbp
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 1336
	movq	%rbp, %rsi
	popq	%rcx
	.cfi_def_cfa_offset 1328
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	40+ip(%rip), %eax
	movsd	.LC20(%rip), %xmm0
	cvtss2sd	24(%rsp), %xmm2
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	mulsd	%xmm2, %xmm0
	cvtsi2ssq	%rax, %xmm1
	movq	%rax, %rdx
	movb	$2, %al
	mulsd	.LC20(%rip), %xmm0
	shrl	$20, %edx
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm0, %xmm1
	movaps	%xmm2, %xmm0
	call	__printf_chk@PLT
	movsd	.LC20(%rip), %xmm0
	movl	%ebx, %eax
	cvtss2sd	64(%rsp), %xmm2
	cvtsi2ssq	%rax, %xmm1
	shrl	$20, %ebx
	movl	$2, %edi
	movb	$2, %al
	mulsd	%xmm2, %xmm0
	movl	%ebx, %edx
	leaq	.LC22(%rip), %rsi
	mulsd	.LC20(%rip), %xmm0
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm0, %xmm1
	movaps	%xmm2, %xmm0
	call	__printf_chk@PLT
	cvtss2sd	76(%rsp), %xmm2
	movsd	.LC20(%rip), %xmm0
	movl	40+ip(%rip), %eax
	leaq	.LC23(%rip), %rsi
	movl	$2, %edi
	mulsd	%xmm2, %xmm0
	cvtsi2ssq	%rax, %xmm1
	movq	%rax, %rdx
	movb	$2, %al
	mulsd	.LC20(%rip), %xmm0
	shrl	$20, %edx
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm0, %xmm1
	movaps	%xmm2, %xmm0
	call	__printf_chk@PLT
	leaq	.LC24(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	GPUImg(%rip), %rdi
	call	cudaFree@PLT
	movq	GPUCopyImg(%rip), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L35
	leaq	.LC25(%rip), %rsi
.L41:
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	TheImg(%rip), %rdi
	call	free@PLT
	movq	CpyImg(%rip), %rdi
	call	free@PLT
	jmp	.L39
.L35:
	movq	TheImg(%rip), %rdi
	call	free@PLT
	movq	CpyImg(%rip), %rdi
	call	free@PLT
	call	getchar@PLT
	movq	1256(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$1272, %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
.LFE3637:
	.size	main, .-main
	.section	.rodata.str1.1
.LC26:
	.string	"_Z5VflipPhS_jj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3665:
	.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	.LC26(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z5VflipPhS_jj(%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
.LFE3665:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZZ10ReadBMPlinPcE3Img
	.comm	_ZZ10ReadBMPlinPcE3Img,8,8
	.globl	GPUCopyImg
	.bss
	.align 8
	.type	GPUCopyImg, @object
	.size	GPUCopyImg, 8
GPUCopyImg:
	.zero	8
	.globl	GPUImg
	.align 8
	.type	GPUImg, @object
	.size	GPUImg, 8
GPUImg:
	.zero	8
	.globl	CpyImg
	.align 8
	.type	CpyImg, @object
	.size	CpyImg, 8
CpyImg:
	.zero	8
	.globl	TheImg
	.align 8
	.type	TheImg, @object
	.size	TheImg, 8
TheImg:
	.zero	8
	.globl	ip
	.align 32
	.type	ip, @object
	.size	ip, 48
ip:
	.zero	48
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC20:
	.long	0
	.long	1083179008
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>



#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>

// #include "cudaDefines.h"

struct ImgProp {
	uint32_t Hpixels;
	uint32_t Vpixels;

	uint8_t HeaderInfo[14];
	uint8_t* HeaderMeta;
	uint16_t HeaderMetaSize;

	uint32_t Hbytes;
	uint32_t IMAGESIZE;
};

struct ImgProp ip;
uint8_t* TheImg, * CpyImg;
uint8_t* GPUImg, * GPUCopyImg;

uint8_t* ReadBMPlin(char* fn) {
	static uint8_t* Img;
    FILE* f = fopen(fn, "rb");
	if (f == NULL) { printf("\n\n%s NOT FOUND\n\n", fn); exit(EXIT_FAILURE); }
	uint8_t HeaderInfo[14];
	fread(HeaderInfo, sizeof(uint8_t), 14, f); // read the 54-byte header
	ip.HeaderMetaSize = *(int*)&HeaderInfo[10];
	ip.HeaderMeta = (uint8_t*)malloc(ip.HeaderMetaSize * sizeof(uint8_t));
	fread(ip.HeaderMeta, sizeof(uint8_t), ip.HeaderMetaSize, f); // read the 54-byte header

	// extract image height and width from header
	int width = *(int*)&(ip.HeaderMeta[4]); ip.Hpixels = width;
	int height = *(int*)&(ip.HeaderMeta[8]); ip.Vpixels = height;
	//int RowBytes = (width * 3 + 3) & (~3); ip.Hbytes = RowBytes;
	int RowBytes = ip.Hpixels * 3; ip.Hbytes = RowBytes;

	ip.IMAGESIZE = ip.Hbytes * ip.Vpixels;
	memcpy(ip.HeaderInfo, HeaderInfo, 14); //save header for re-use
	printf("\n Input File name: %17s\n\nHeaderMetaSize: %u, Hb: %u, Hp: %u, Vp: %u, File Size=%u\n\n", fn,
		ip.HeaderMetaSize, ip.Hbytes, ip.Hpixels, ip.Vpixels, ip.IMAGESIZE);
	// allocate memory to store the main image (1 Dimensional array)
	Img = (uint8_t*)malloc(ip.IMAGESIZE);
	if (Img == NULL) return Img; // Cannot allocate memory
	// read the image from disk
	fread(Img, sizeof(uint8_t), ip.IMAGESIZE, f); fclose(f); return Img;
}

// Write the 1D linear-memory stored image into file.
void WriteBMPlin(uint8_t* Img, char* fn) {
	FILE* f = fopen(fn, "wb");
	if (f == NULL) { printf("\n\nFILE CREATION ERROR: %s\n\n", fn); exit(1); }
	fwrite(ip.HeaderInfo, sizeof(uint8_t), 14, f); //write header
	fwrite(ip.HeaderMeta, sizeof(uint8_t), ip.HeaderMetaSize, f); //write header
	fwrite(Img, sizeof(uint8_t), ip.IMAGESIZE, f); //write data
	printf("\nOutput File name: %17s (%u x %u) File Size=%u\n\n", fn, ip.Hpixels,
		ip.Vpixels, ip.IMAGESIZE);
	fclose(f);
}

__global__
void Vflip(uint8_t* ImgDst, uint8_t* ImgSrc, uint32_t Hpixels, uint32_t Vpixels) {
	uint32_t ThrPerBlk = blockDim.x;
	uint32_t MYbid = blockIdx.x;
	uint32_t MYtid = threadIdx.x;
	uint32_t MYgtid = ThrPerBlk * MYbid + MYtid;
	uint32_t BlkPerRow = (Hpixels + ThrPerBlk - 1) / ThrPerBlk; // ceil
	uint32_t RowBytes = (Hpixels * 3 + 3) & (~3);
	uint32_t MYrow = MYbid / BlkPerRow;
	uint32_t MYcol = MYgtid - MYrow * BlkPerRow * ThrPerBlk;
	if (MYcol >= Hpixels) return; // col out of range
	uint32_t MYmirrorrow = Vpixels - 1 - MYrow;
	uint32_t MYsrcOffset = MYrow * RowBytes;
	uint32_t MYdstOffset = MYmirrorrow * RowBytes;
	uint32_t MYsrcIndex = MYsrcOffset + 3 * MYcol;
	uint32_t MYdstIndex = MYdstOffset + 3 * MYcol;
	// swap pixels RGB @MYcol , @MYmirrorcol
	ImgDst[MYdstIndex] = ImgSrc[MYsrcIndex];
	ImgDst[MYdstIndex + 1] = ImgSrc[MYsrcIndex + 1];
	ImgDst[MYdstIndex + 2] = ImgSrc[MYsrcIndex + 2];
}

int main() {
	hipError_t cudaStatus, cudaStatus2;
	hipEvent_t time1, time2, time3, time4;
	hipDeviceProp_t GPUprop;

	uint32_t SupportedKBlocks, SupportedMBlocks, MaxThrPerBlk;
	char SupportedBlocks[100];

	uint32_t BlkPerRow, ThrPerBlk = 128, NumBlocks, GPUDataTransfer;
	float totalTime, tfrCPUtoGPU, kernelExecutionTime, tfrGPUtoCPU;

	char InputFileName[] = "../img/img.bmp";
    char OutputFileName[] = "../img/flip.bmp";

	TheImg = ReadBMPlin(InputFileName);
	CpyImg = (uint8_t*)malloc(ip.IMAGESIZE);
	//WriteBMPlin(TheImg, OutputFileName);
	//return 0;

	int NumGPUs = 0; hipGetDeviceCount(&NumGPUs);
	if (NumGPUs == 0) {
		std::cout << "\nNo CUDA Device is available\n";
		exit(EXIT_FAILURE);
	}

	hipGetDeviceProperties(&GPUprop, 0);
	SupportedKBlocks = ((uint32_t)GPUprop.maxGridSize[0] * (uint32_t)GPUprop.maxGridSize[1] *
		(uint32_t)GPUprop.maxGridSize[2]) / 1024;

	SupportedMBlocks = SupportedKBlocks / 1024;
	sprintf(SupportedBlocks, "%u %c", (SupportedMBlocks >= 5) ? SupportedMBlocks : SupportedKBlocks,
		(SupportedMBlocks >= 5) ? 'M' : 'K');
	MaxThrPerBlk = (uint32_t)GPUprop.maxThreadsPerBlock;

	hipEventCreate(&time1); hipEventCreate(&time2);
	hipEventCreate(&time3); hipEventCreate(&time4);

	BlkPerRow = (ip.Hpixels + ThrPerBlk - 1) / ThrPerBlk;
	NumBlocks = ip.Vpixels * BlkPerRow;
	GPUDataTransfer = 2 * ip.IMAGESIZE;

	hipEventRecord(time1, 0);
	cudaStatus = hipMalloc((void**)&GPUImg, ip.IMAGESIZE);
	cudaStatus2 = hipMalloc((void**)&GPUCopyImg, ip.IMAGESIZE);
	if ((cudaStatus != hipSuccess) || (cudaStatus2 != hipSuccess)) {
		std::cout << "hipMalloc failed! Can't allocate GPU memory";
		exit(EXIT_FAILURE);
	}

	cudaStatus = hipMemcpy(GPUImg, TheImg, ip.IMAGESIZE, hipMemcpyHostToDevice);
	if (cudaStatus != hipSuccess) {
		std::cout << "cudaMemCpy CPU to GPU failed!";
		exit(EXIT_FAILURE);
	}
	hipEventRecord(time2, 0);

	Vflip <<<NumBlocks, ThrPerBlk>>> (GPUCopyImg, GPUImg, ip.Hpixels, ip.Vpixels);

	cudaStatus = hipDeviceSynchronize();
	if (cudaStatus != hipSuccess) {
		std::cout << "hipDeviceSynchronize error code " << cudaStatus << " ...\n";
		exit(EXIT_FAILURE);
	}
	hipEventRecord(time3, 0);

	cudaStatus = hipMemcpy(CpyImg, GPUCopyImg, ip.IMAGESIZE, hipMemcpyDeviceToHost);
	if (cudaStatus != hipSuccess) {
		std::cout << "cudaMemCpy GPU to CPU failed!" << cudaStatus;
		exit(EXIT_FAILURE);
	}
	hipEventRecord(time4, 0);

	hipEventSynchronize(time1); hipEventSynchronize(time2);
	hipEventSynchronize(time3); hipEventSynchronize(time4);
	hipEventElapsedTime(&totalTime, time1, time4);
	hipEventElapsedTime(&tfrCPUtoGPU, time1, time2);
	hipEventElapsedTime(&kernelExecutionTime, time2, time3);
	hipEventElapsedTime(&tfrGPUtoCPU, time3, time4);

	cudaStatus = hipDeviceSynchronize();
	if (cudaStatus != hipSuccess) {
		std::cout << "Program failed afeter cudaDeviceSyncronize()";
		free(TheImg); free(CpyImg);
		exit(EXIT_FAILURE);
	}

	WriteBMPlin(CpyImg, OutputFileName);

	printf("--...--\n"); printf("%s ComputeCapab=%d.%d [supports max %s blocks]\n",
		GPUprop.name, GPUprop.major, GPUprop.minor, SupportedBlocks); printf("...\n");
	printf("maxTrPerBlk: %d\n", MaxThrPerBlk);
	printf("%s\n %s\n\n ThrPerBlock: %u, Blocks: %u, BlkPerRow: %u\n", InputFileName,
		OutputFileName, ThrPerBlk, NumBlocks, BlkPerRow);
	printf("-------------------- ... ----------------------------\n");
	printf("CPU->GPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n",
		tfrCPUtoGPU, ip.IMAGESIZE / 1024 / 1024, (float)ip.IMAGESIZE / (tfrCPUtoGPU *
			1024.0 * 1024.0));
	printf("Kernel Execution = %5.2f ms ... %4d MB ... %6.2f GB/s\n",
		kernelExecutionTime, GPUDataTransfer / 1024 / 1024, (float)GPUDataTransfer /
		(kernelExecutionTime * 1024.0 * 1024.0));
	printf("GPU->CPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n",
		tfrGPUtoCPU, ip.IMAGESIZE / 1024 / 1024, (float)ip.IMAGESIZE / (tfrGPUtoCPU *
			1024.0 * 1024.0));
	printf("Total time elapsed = %5.2f ms\n", totalTime);
	printf("-------------------- ... ----------------------------\n");


	hipFree(GPUImg); hipFree(GPUCopyImg);
	hipEventDestroy(time1); hipEventDestroy(time2);
	hipEventDestroy(time3); hipEventDestroy(time4);

	cudaStatus = hipDeviceReset();
	if (cudaStatus != hipSuccess) {
		std::cout << "hipDeviceReset failed!";
		free(TheImg); free(CpyImg); exit(EXIT_FAILURE);
	}
	free(TheImg); free(CpyImg);

	getchar();
	//getchar();
	return(EXIT_SUCCESS);
}
	.text
	.file	"imgFlip.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z10ReadBMPlinPc                # -- Begin function _Z10ReadBMPlinPc
	.type	_Z10ReadBMPlinPc,@function
_Z10ReadBMPlinPc:                       # @_Z10ReadBMPlinPc
	.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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %r14
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_4
# %bb.1:
	movq	%rax, %rbx
	leaq	10(%rsp), %r15
	movl	$1, %esi
	movl	$14, %edx
	movq	%r15, %rdi
	movq	%rax, %rcx
	callq	fread
	movl	10(%r15), %eax
	movzwl	%ax, %r12d
	movw	%r12w, ip+32(%rip)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, ip+24(%rip)
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r12, %rdx
	movq	%rbx, %rcx
	callq	fread
	movq	ip+24(%rip), %rax
	movl	4(%rax), %r8d
	movl	%r8d, ip(%rip)
	movl	8(%rax), %r9d
	movl	%r9d, ip+4(%rip)
	leal	(%r8,%r8,2), %ecx
	movl	%ecx, ip+36(%rip)
	movl	%r9d, %eax
	imull	%ecx, %eax
	movl	%eax, ip+40(%rip)
	movq	(%r15), %rdx
	movq	6(%r15), %rsi
	movq	%rdx, ip+8(%rip)
	movq	%rsi, ip+14(%rip)
	movzwl	ip+32(%rip), %edx
	movl	%eax, (%rsp)
	xorl	%r15d, %r15d
	movl	$.L.str.2, %edi
	movq	%r14, %rsi
                                        # kill: def $r8d killed $r8d killed $r8
	xorl	%eax, %eax
	callq	printf
	movl	ip+40(%rip), %r14d
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, _ZZ10ReadBMPlinPcE3Img(%rip)
	testq	%rax, %rax
	je	.LBB0_3
# %bb.2:
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r14, %rdx
	movq	%rbx, %rcx
	callq	fread
	movq	%rbx, %rdi
	callq	fclose
	movq	_ZZ10ReadBMPlinPcE3Img(%rip), %r15
.LBB0_3:
	movq	%r15, %rax
	addq	$24, %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
.LBB0_4:
	.cfi_def_cfa_offset 64
	movl	$.L.str.1, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z10ReadBMPlinPc, .Lfunc_end0-_Z10ReadBMPlinPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z11WriteBMPlinPhPc             # -- Begin function _Z11WriteBMPlinPhPc
	.type	_Z11WriteBMPlinPhPc,@function
_Z11WriteBMPlinPhPc:                    # @_Z11WriteBMPlinPhPc
	.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, %r15
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_1
# %bb.2:
	movq	%rax, %r14
	movl	$ip+8, %edi
	movl	$1, %esi
	movl	$14, %edx
	movq	%rax, %rcx
	callq	fwrite
	movq	ip+24(%rip), %rdi
	movzwl	ip+32(%rip), %edx
	movl	$1, %esi
	movq	%r14, %rcx
	callq	fwrite
	movl	ip+40(%rip), %edx
	movl	$1, %esi
	movq	%r15, %rdi
	movq	%r14, %rcx
	callq	fwrite
	movl	ip(%rip), %edx
	movl	ip+4(%rip), %ecx
	movl	ip+40(%rip), %r8d
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	%r14, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.LBB1_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.4, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z11WriteBMPlinPhPc, .Lfunc_end1-_Z11WriteBMPlinPhPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z20__device_stub__VflipPhS_jj  # -- Begin function _Z20__device_stub__VflipPhS_jj
	.type	_Z20__device_stub__VflipPhS_jj,@function
_Z20__device_stub__VflipPhS_jj:         # @_Z20__device_stub__VflipPhS_jj
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z5VflipPhS_jj, %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_end2:
	.size	_Z20__device_stub__VflipPhS_jj, .Lfunc_end2-_Z20__device_stub__VflipPhS_jj
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI3_0:
	.byte	46                              # 0x2e
	.byte	46                              # 0x2e
	.byte	47                              # 0x2f
	.byte	105                             # 0x69
	.byte	109                             # 0x6d
	.byte	103                             # 0x67
	.byte	47                              # 0x2f
	.byte	102                             # 0x66
	.byte	108                             # 0x6c
	.byte	105                             # 0x69
	.byte	112                             # 0x70
	.byte	46                              # 0x2e
	.byte	98                              # 0x62
	.byte	109                             # 0x6d
	.byte	112                             # 0x70
	.byte	0                               # 0x0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI3_1:
	.quad	0x4090000000000000              # double 1024
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$1680, %rsp                     # imm = 0x690
	.cfi_def_cfa_offset 1728
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$7579390417501629998, %rax      # imm = 0x692F676D692F2E2E
	leaq	65(%rsp), %rdi
	movq	%rax, (%rdi)
	movl	$1647208301, 8(%rdi)            # imm = 0x622E676D
	movw	$28781, 12(%rdi)                # imm = 0x706D
	movb	$0, 14(%rdi)
	movaps	.LCPI3_0(%rip), %xmm0           # xmm0 = [46,46,47,105,109,103,47,102,108,105,112,46,98,109,112,0]
	movaps	%xmm0, 80(%rsp)
	callq	_Z10ReadBMPlinPc
	movq	%rax, TheImg(%rip)
	movl	ip+40(%rip), %edi
	callq	malloc
	movq	%rax, CpyImg(%rip)
	leaq	60(%rsp), %rbx
	movl	$0, (%rbx)
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	je	.LBB3_10
# %bb.1:
	leaq	208(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	340(%rbx), %edx
	imull	336(%rbx), %edx
	imull	344(%rbx), %edx
	xorl	%eax, %eax
	cmpl	$5242880, %edx                  # imm = 0x500000
	setae	%al
	movl	$20, %esi
	movl	$10, %ecx
	cmovael	%esi, %ecx
                                        # kill: def $cl killed $cl killed $ecx
	shrl	%cl, %edx
	leal	75(,%rax,2), %ecx
	leaq	96(%rsp), %rdi
	movl	$.L.str.7, %esi
	xorl	%eax, %eax
	callq	sprintf
	movl	320(%rbx), %ebp
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movl	ip(%rip), %r14d
	addl	$127, %r14d
	shrl	$7, %r14d
	movl	ip+4(%rip), %r15d
	imull	%r14d, %r15d
	movl	ip+40(%rip), %ebx
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	ip+40(%rip), %esi
	movl	$GPUImg, %edi
	callq	hipMalloc
	movl	%eax, %r12d
	movl	ip+40(%rip), %esi
	movl	$GPUCopyImg, %edi
	callq	hipMalloc
	orl	%r12d, %eax
	jne	.LBB3_11
# %bb.2:
	movq	GPUImg(%rip), %rdi
	movq	TheImg(%rip), %rsi
	movl	ip+40(%rip), %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_12
# %bb.3:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	%r15d, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$128, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_5
# %bb.4:
	movq	GPUCopyImg(%rip), %rdi
	movq	GPUImg(%rip), %rsi
	movl	ip(%rip), %edx
	movl	ip+4(%rip), %ecx
	callq	_Z20__device_stub__VflipPhS_jj
.LBB3_5:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_13
# %bb.6:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	CpyImg(%rip), %rdi
	movq	GPUCopyImg(%rip), %rsi
	movl	ip+40(%rip), %edx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_16
# %bb.7:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	56(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdx
	leaq	52(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	48(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	44(%rsp), %rdi
	callq	hipEventElapsedTime
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_17
# %bb.8:
	addl	%ebx, %ebx
	movq	CpyImg(%rip), %rdi
	leaq	80(%rsp), %r12
	movq	%r12, %rsi
	callq	_Z11WriteBMPlinPhPc
	movl	$.Lstr, %edi
	callq	puts@PLT
	leaq	208(%rsp), %rsi
	movl	360(%rsi), %edx
	movl	364(%rsi), %ecx
	leaq	96(%rsp), %r8
	movl	$.L.str.15, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.L.str.17, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	leaq	65(%rsp), %rsi
	movl	$.L.str.18, %edi
	movq	%r12, %rdx
	movl	$128, %ecx
	movl	%r15d, %r8d
	movl	%r14d, %r9d
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	cvtss2sd	52(%rsp), %xmm0
	movl	ip+40(%rip), %eax
	cvtsi2ss	%rax, %xmm1
	movl	%eax, %esi
	shrl	$20, %esi
	cvtss2sd	%xmm1, %xmm1
	movsd	.LCPI3_1(%rip), %xmm3           # xmm3 = mem[0],zero
	movaps	%xmm0, %xmm2
	mulsd	%xmm3, %xmm2
	mulsd	%xmm3, %xmm2
	divsd	%xmm2, %xmm1
	movl	$.L.str.20, %edi
	movb	$2, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	48(%rsp), %xmm0
	movl	%ebx, %eax
	shrl	$20, %ebx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	cvtss2sd	%xmm1, %xmm1
	movaps	%xmm0, %xmm2
	movsd	.LCPI3_1(%rip), %xmm3           # xmm3 = mem[0],zero
	mulsd	%xmm3, %xmm2
	mulsd	%xmm3, %xmm2
	divsd	%xmm2, %xmm1
	movl	$.L.str.21, %edi
	movl	%ebx, %esi
	movb	$2, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	44(%rsp), %xmm0
	movl	ip+40(%rip), %eax
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	movl	%eax, %esi
	shrl	$20, %esi
	cvtss2sd	%xmm1, %xmm1
	movaps	%xmm0, %xmm2
	movsd	.LCPI3_1(%rip), %xmm3           # xmm3 = mem[0],zero
	mulsd	%xmm3, %xmm2
	mulsd	%xmm3, %xmm2
	divsd	%xmm2, %xmm1
	movl	$.L.str.22, %edi
	movb	$2, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	56(%rsp), %xmm0
	movl	$.L.str.23, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movq	GPUImg(%rip), %rdi
	callq	hipFree
	movq	GPUCopyImg(%rip), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB3_18
# %bb.9:
	movq	TheImg(%rip), %rdi
	callq	free
	movq	CpyImg(%rip), %rdi
	callq	free
	callq	getchar
	xorl	%eax, %eax
	addq	$1680, %rsp                     # imm = 0x690
	.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
	retq
.LBB3_10:
	.cfi_def_cfa_offset 1728
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	jmp	.LBB3_14
.LBB3_11:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	jmp	.LBB3_14
.LBB3_12:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	jmp	.LBB3_14
.LBB3_13:
	movl	%eax, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%r12d, %esi
	callq	_ZNSolsEi
	movl	$.L.str.11, %esi
	movq	%rax, %rdi
.LBB3_14:
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	jmp	.LBB3_15
.LBB3_16:
	movl	%eax, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.12, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%r12d, %esi
	callq	_ZNSolsEi
	jmp	.LBB3_15
.LBB3_17:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.13, %esi
	jmp	.LBB3_19
.LBB3_18:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.24, %esi
.LBB3_19:
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	TheImg(%rip), %rdi
	callq	free
	movq	CpyImg(%rip), %rdi
	callq	free
.LBB3_15:
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z5VflipPhS_jj, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	ip,@object                      # @ip
	.bss
	.globl	ip
	.p2align	3, 0x0
ip:
	.zero	48
	.size	ip, 48

	.type	TheImg,@object                  # @TheImg
	.globl	TheImg
	.p2align	3, 0x0
TheImg:
	.quad	0
	.size	TheImg, 8

	.type	CpyImg,@object                  # @CpyImg
	.globl	CpyImg
	.p2align	3, 0x0
CpyImg:
	.quad	0
	.size	CpyImg, 8

	.type	GPUImg,@object                  # @GPUImg
	.globl	GPUImg
	.p2align	3, 0x0
GPUImg:
	.quad	0
	.size	GPUImg, 8

	.type	GPUCopyImg,@object              # @GPUCopyImg
	.globl	GPUCopyImg
	.p2align	3, 0x0
GPUCopyImg:
	.quad	0
	.size	GPUCopyImg, 8

	.type	_ZZ10ReadBMPlinPcE3Img,@object  # @_ZZ10ReadBMPlinPcE3Img
	.local	_ZZ10ReadBMPlinPcE3Img
	.comm	_ZZ10ReadBMPlinPcE3Img,8,8
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"rb"
	.size	.L.str, 3

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\n\n%s NOT FOUND\n\n"
	.size	.L.str.1, 17

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\n Input File name: %17s\n\nHeaderMetaSize: %u, Hb: %u, Hp: %u, Vp: %u, File Size=%u\n\n"
	.size	.L.str.2, 84

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"wb"
	.size	.L.str.3, 3

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n\nFILE CREATION ERROR: %s\n\n"
	.size	.L.str.4, 28

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\nOutput File name: %17s (%u x %u) File Size=%u\n\n"
	.size	.L.str.5, 49

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

	.type	.L.str.6,@object                # @.str.6
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.6:
	.asciz	"\nNo CUDA Device is available\n"
	.size	.L.str.6, 30

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipMalloc failed! Can't allocate GPU memory"
	.size	.L.str.8, 44

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"cudaMemCpy CPU to GPU failed!"
	.size	.L.str.9, 30

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"hipDeviceSynchronize error code "
	.size	.L.str.10, 33

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	" ...\n"
	.size	.L.str.11, 6

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"cudaMemCpy GPU to CPU failed!"
	.size	.L.str.12, 30

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Program failed afeter cudaDeviceSyncronize()"
	.size	.L.str.13, 45

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"%s ComputeCapab=%d.%d [supports max %s blocks]\n"
	.size	.L.str.15, 48

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"maxTrPerBlk: %d\n"
	.size	.L.str.17, 17

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"%s\n %s\n\n ThrPerBlock: %u, Blocks: %u, BlkPerRow: %u\n"
	.size	.L.str.18, 53

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"CPU->GPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n"
	.size	.L.str.20, 56

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"Kernel Execution = %5.2f ms ... %4d MB ... %6.2f GB/s\n"
	.size	.L.str.21, 55

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"GPU->CPU Transfer = %5.2f ms ... %4d MB ... %6.2f GB/s\n"
	.size	.L.str.22, 56

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"Total time elapsed = %5.2f ms\n"
	.size	.L.str.23, 31

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z5VflipPhS_jj"
	.size	.L__unnamed_1, 15

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

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

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

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"..."
	.size	.Lstr.1, 4

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"-------------------- ... ----------------------------"
	.size	.Lstr.3, 54

	.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 _Z20__device_stub__VflipPhS_jj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym ip
	.addrsig_sym GPUImg
	.addrsig_sym GPUCopyImg
	.addrsig_sym _Z5VflipPhS_jj
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z5VflipPhS_jj          ; -- Begin function _Z5VflipPhS_jj
	.globl	_Z5VflipPhS_jj
	.p2align	8
	.type	_Z5VflipPhS_jj,@function
_Z5VflipPhS_jj:                         ; @_Z5VflipPhS_jj
; %bb.0:
	s_load_b32 s2, s[0:1], 0x24
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s2, 0xffff
	s_load_b64 s[2:3], s[0:1], 0x10
	v_cvt_f32_u32_e32 v1, s5
	s_sub_i32 s6, 0, s5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	s_waitcnt lgkmcnt(0)
	s_add_i32 s7, s2, s5
	v_cvt_u32_f32_e32 v1, v1
	s_add_i32 s7, s7, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s4, v1
	s_mul_i32 s6, s6, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s6, s4, s6
	s_add_i32 s4, s4, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s4, s7, s4
	s_mul_i32 s6, s4, s5
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s6, s7, s6
	s_add_i32 s7, s4, 1
	s_sub_i32 s8, s6, s5
	s_cmp_ge_u32 s6, s5
	s_cselect_b32 s4, s7, s4
	s_cselect_b32 s6, s8, s6
	s_add_i32 s7, s4, 1
	s_cmp_ge_u32 s6, s5
	s_cselect_b32 s6, s7, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v1, s6
	s_sub_i32 s7, 0, s6
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v1, v1
	v_readfirstlane_b32 s4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s7, s7, s4
	s_mul_hi_u32 s7, s4, s7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s4, s4, s7
	s_mul_hi_u32 s4, s15, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_mul_i32 s7, s4, s6
	s_add_i32 s8, s4, 1
	s_sub_i32 s7, s15, s7
	s_sub_i32 s9, s7, s6
	s_cmp_ge_u32 s7, s6
	s_cselect_b32 s4, s8, s4
	s_cselect_b32 s7, s9, s7
	s_add_i32 s8, s4, 1
	s_cmp_ge_u32 s7, s6
	s_cselect_b32 s4, s8, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s6, s4, s6
	s_sub_i32 s6, s15, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s6, s5, v[0:1]
	s_mov_b32 s5, exec_lo
	v_cmpx_gt_u32_e64 s2, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[8:11], s[0:1], 0x0
	s_mul_i32 s0, s2, 3
	v_lshl_add_u32 v0, v1, 1, v1
	s_add_i32 s0, s0, 3
	s_not_b32 s1, s4
	s_and_b32 s0, s0, -4
	s_add_i32 s1, s1, s3
	v_mad_u64_u32 v[1:2], null, s4, s0, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s1, s0, v[0:1]
	v_add_nc_u32_e32 v0, 1, v1
	s_waitcnt lgkmcnt(0)
	global_load_u8 v4, v1, s[10:11]
	v_add_nc_u32_e32 v1, 2, v1
	v_add_nc_u32_e32 v3, 1, v2
	s_waitcnt vmcnt(0)
	global_store_b8 v2, v4, s[8:9]
	global_load_u8 v0, v0, s[10:11]
	s_waitcnt vmcnt(0)
	global_store_b8 v3, v0, s[8:9]
	global_load_u8 v0, v1, s[10:11]
	v_add_nc_u32_e32 v1, 2, v2
	s_waitcnt vmcnt(0)
	global_store_b8 v1, v0, s[8:9]
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z5VflipPhS_jj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_reserve_vcc 0
		.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	_Z5VflipPhS_jj, .Lfunc_end0-_Z5VflipPhS_jj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 444
; NumSgprs: 16
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 16
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
