#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cuda.h>

#define N  1024 * 1024



#define CHECK_CUDA_ERR(x)   {			\
	err = x;				\
	if (err != cudaSuccess) { 		\
		printf("cuda error with %s in line %d\n",cudaGetErrorString(err),__LINE__);	\
		exit(1);									\
	} }

int main()
{
	
	cudaError_t err;
	cudaEvent_t start_event,stop_event;

	CHECK_CUDA_ERR ( cudaEventCreate(&start_event) );
	CHECK_CUDA_ERR ( cudaEventCreate(&stop_event)  );




	void * buf = malloc(sizeof(float) * N);

	void * dBuf;
	 CHECK_CUDA_ERR ( cudaMalloc(&dBuf,sizeof(float) * N) );

	 CHECK_CUDA_ERR ( cudaEventRecord(start_event,0) ) ;
	 CHECK_CUDA_ERR ( cudaMemcpy(dBuf,buf,sizeof(float) * N, cudaMemcpyHostToDevice));
	 CHECK_CUDA_ERR ( cudaEventRecord(stop_event,0) );
	 CHECK_CUDA_ERR ( cudaDeviceSynchronize() );
	float ms = 100.f;

	 CHECK_CUDA_ERR ( cudaEventElapsedTime(&ms,start_event,stop_event));


	printf("%f m second cost\n",ms);


	CHECK_CUDA_ERR ( cudaEventDestroy(start_event) );
	CHECK_CUDA_ERR ( cudaEventDestroy(stop_event)  );
	free(buf);
	CHECK_CUDA_ERR ( cudaFree(dBuf) );


	return 0;





}

	.file	"tmpxft_0037083b_00000000-6_elapsed.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2043:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2043:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"cuda error with %s in line %d\n"
.LC2:
	.string	"%f m second cost\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L3
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$23, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L3:
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L4
	call	cudaGetErrorString@PLT
	movl	$24, %ecx
	movq	%rax, %rdx
.L16:
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L4:
	movl	$4194304, %edi
	call	malloc@PLT
	leaq	32(%rsp), %rdi
	movl	$4194304, %esi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L5
	call	cudaGetErrorString@PLT
	movl	$32, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L5:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L6
	call	cudaGetErrorString@PLT
	movl	$34, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L6:
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movl	$4194304, %edx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L7
	call	cudaGetErrorString@PLT
	movl	$35, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L7:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L8
	call	cudaGetErrorString@PLT
	movl	$36, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L8:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L9
	call	cudaGetErrorString@PLT
	movl	$37, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L9:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	leaq	12(%rsp), %rdi
	movl	$0x42c80000, 12(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L10
	call	cudaGetErrorString@PLT
	movl	$40, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L10:
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L11
	call	cudaGetErrorString@PLT
	movl	$46, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L11:
	movq	24(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L12
	call	cudaGetErrorString@PLT
	movl	$47, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L12:
	movq	%rbx, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	movl	$49, %ecx
	movq	%rax, %rdx
	jmp	.L16
.L13:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2066:
	.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
.LFE2066:
	.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
	.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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <hip/hip_runtime.h>

#define N  1024 * 1024



#define CHECK_CUDA_ERR(x)   {			\
	err = x;				\
	if (err != hipSuccess) { 		\
		printf("cuda error with %s in line %d\n",hipGetErrorString(err),__LINE__);	\
		exit(1);									\
	} }

int main()
{
	
	hipError_t err;
	hipEvent_t start_event,stop_event;

	CHECK_CUDA_ERR ( hipEventCreate(&start_event) );
	CHECK_CUDA_ERR ( hipEventCreate(&stop_event)  );




	void * buf = malloc(sizeof(float) * N);

	void * dBuf;
	 CHECK_CUDA_ERR ( hipMalloc(&dBuf,sizeof(float) * N) );

	 CHECK_CUDA_ERR ( hipEventRecord(start_event,0) ) ;
	 CHECK_CUDA_ERR ( hipMemcpy(dBuf,buf,sizeof(float) * N, hipMemcpyHostToDevice));
	 CHECK_CUDA_ERR ( hipEventRecord(stop_event,0) );
	 CHECK_CUDA_ERR ( hipDeviceSynchronize() );
	float ms = 100.f;

	 CHECK_CUDA_ERR ( hipEventElapsedTime(&ms,start_event,stop_event));


	printf("%f m second cost\n",ms);


	CHECK_CUDA_ERR ( hipEventDestroy(start_event) );
	CHECK_CUDA_ERR ( hipEventDestroy(stop_event)  );
	free(buf);
	CHECK_CUDA_ERR ( hipFree(dBuf) );


	return 0;





}

	.text
	.file	"elapsed.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB0_1
# %bb.3:
	movq	%rsp, %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB0_4
# %bb.5:
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %rbx
	leaq	24(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_6
# %bb.7:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.9:
	movq	24(%rsp), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_10
# %bb.11:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_12
# %bb.13:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_14
# %bb.15:
	leaq	20(%rsp), %rdi
	movl	$1120403456, (%rdi)             # imm = 0x42C80000
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB0_16
# %bb.17:
	cvtss2sd	20(%rsp), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB0_18
# %bb.19:
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB0_20
# %bb.21:
	movq	%rbx, %rdi
	callq	free
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB0_22
# %bb.23:
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB0_1:
	.cfi_def_cfa_offset 48
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$23, %edx
	jmp	.LBB0_2
.LBB0_4:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$24, %edx
	jmp	.LBB0_2
.LBB0_6:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$32, %edx
	jmp	.LBB0_2
.LBB0_8:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$34, %edx
	jmp	.LBB0_2
.LBB0_10:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$35, %edx
	jmp	.LBB0_2
.LBB0_12:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$36, %edx
	jmp	.LBB0_2
.LBB0_14:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$37, %edx
	jmp	.LBB0_2
.LBB0_16:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$40, %edx
	jmp	.LBB0_2
.LBB0_18:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$46, %edx
	jmp	.LBB0_2
.LBB0_20:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$47, %edx
	jmp	.LBB0_2
.LBB0_22:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$49, %edx
.LBB0_2:
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.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	"cuda error with %s in line %d\n"
	.size	.L.str, 31

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%f m second cost\n"
	.size	.L.str.1, 18

	.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
