/*******************************************************************************
* PROGRAM: canny_edge_detector
* FILE: ui.cu / a small user interface, use WIN32 graphic lib
* PURPOSE: This program is a case study on porting algorithm implemented in C to CUDA
* The original C code is referenced from canny_edge program implemented by Profs. Mike Heath
* This program also uses some of the funtions from canny_edge program
* PURPOSE: Apply Gaussian Smooth to input pgm image
* NAME: Vuong Pham-Duy
*       Faculty of Computer Science and Technology
*       Ho Chi Minh University of Technology, Viet Nam
*       vuongpd95@gmail.com
* DATE: 11/10/2016
*******************************************************************************/
#include<stdio.h>
#include<stdlib.h>

#define INFILENAME "D:\\Vuong_only\\Images\\pgm_in\\img2.pgm"
#define DEBUGFILE "D:\\Vuong_only\\Images\\edge_out\\debug.txt"
#define SIGMA 1.5
#define TLOW 0.35
#define THIGH 0.75
double cuda_canny(char *infilename, float sigma, float tlow, float thigh, double &init_time);
double one_canny(char *infilename, float sigma, float tlow, float thigh);

int main()
{
	double one, cuda, init;
	// TODO UI codes go here
	cuda = cuda_canny(INFILENAME, SIGMA, TLOW, THIGH, init);
	one = one_canny(INFILENAME, SIGMA, TLOW, THIGH);
	printf("\n\nRESULT:\nCUDA: %f INIT_TIME: %f\nCPU: %f \n", cuda, init, one);
	return 0;
}

	.file	"tmpxft_0022f640_00000000-6_ui.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"D:\\Vuong_only\\Images\\pgm_in\\img2.pgm"
.LC4:
	.string	"\n\nRESULT:\nCUDA: %f INIT_TIME: %f\nCPU: %f \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	.LC0(%rip), %rbx
	movq	%rbx, %rdi
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movss	.LC1(%rip), %xmm2
	movss	.LC2(%rip), %xmm1
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movss	.LC3(%rip), %xmm0
	movq	%rsp, %rsi
	call	_Z10cuda_cannyPcfffRd@PLT
	movss	.LC1(%rip), %xmm2
	movss	.LC2(%rip), %xmm1
	movq	%rbx, %rdi
	movq	%xmm0, %r14
	movss	.LC3(%rip), %xmm0
	call	_Z9one_cannyPcfff@PLT
	movsd	(%rsp), %xmm1
	leaq	.LC4(%rip), %rsi
	movb	$3, %al
	movaps	%xmm0, %xmm2
	movl	$2, %edi
	movq	%r14, %xmm0
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2053:
	.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
.LFE2053:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1061158912
	.align 4
.LC2:
	.long	1051931443
	.align 4
.LC3:
	.long	1069547520
	.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:

/*******************************************************************************
* PROGRAM: canny_edge_detector
* FILE: ui.cu / a small user interface, use WIN32 graphic lib
* PURPOSE: This program is a case study on porting algorithm implemented in C to CUDA
* The original C code is referenced from canny_edge program implemented by Profs. Mike Heath
* This program also uses some of the funtions from canny_edge program
* PURPOSE: Apply Gaussian Smooth to input pgm image
* NAME: Vuong Pham-Duy
*       Faculty of Computer Science and Technology
*       Ho Chi Minh University of Technology, Viet Nam
*       vuongpd95@gmail.com
* DATE: 11/10/2016
*******************************************************************************/

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

#define INFILENAME "D:\\Vuong_only\\Images\\pgm_in\\img2.pgm"
#define DEBUGFILE "D:\\Vuong_only\\Images\\edge_out\\debug.txt"
#define SIGMA 1.5
#define TLOW 0.35
#define THIGH 0.75
double cuda_canny(char *infilename, float sigma, float tlow, float thigh, double &init_time);
double one_canny(char *infilename, float sigma, float tlow, float thigh);

int main()
{
	double one, cuda, init;
	// TODO UI codes go here
	cuda = cuda_canny(INFILENAME, SIGMA, TLOW, THIGH, init);
	one = one_canny(INFILENAME, SIGMA, TLOW, THIGH);
	printf("\n\nRESULT:\nCUDA: %f INIT_TIME: %f\nCPU: %f \n", cuda, init, one);
	return 0;
}

	.text
	.file	"ui.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x3fc00000                      # float 1.5
.LCPI0_1:
	.long	0x3eb33333                      # float 0.349999994
.LCPI0_2:
	.long	0x3f400000                      # float 0.75
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movss	.LCPI0_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI0_2(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	leaq	8(%rsp), %rbx
	movl	$.L.str, %edi
	movq	%rbx, %rsi
	callq	_Z10cuda_cannyPcfffRd
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movl	$.L.str, %edi
	movss	.LCPI0_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI0_2(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	callq	_Z9one_cannyPcfff
	movaps	%xmm0, %xmm2
	movsd	(%rbx), %xmm1                   # xmm1 = mem[0],zero
	movl	$.L.str.1, %edi
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$3, %al
	callq	printf
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"D:\\Vuong_only\\Images\\pgm_in\\img2.pgm"
	.size	.L.str, 37

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\n\nRESULT:\nCUDA: %f INIT_TIME: %f\nCPU: %f \n"
	.size	.L.str.1, 43

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __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
