#include <iostream>

namespace ckt {
  void check_cuda_error_always(const char *kernelname, const char *file, int line_no, cudaStream_t stream);

  void check_cuda_error(const char *kernelname, const char *file, int line_no, cudaStream_t stream )
  {
#ifdef DEBUG
    check_cuda_error_always(kernelname, file, line_no, stream);
#endif
  }

  void check_cuda_error_always(const char *kernelname, const char *file, int line_no, cudaStream_t stream)
  {
    cudaError_t err;
    if (stream)
      err = cudaStreamSynchronize(stream);
    else
      err = cudaDeviceSynchronize();
    
    err = cudaGetLastError();
    if (err != cudaSuccess) {
      std::cerr << "CUDA error at kernel " << kernelname << " @ file " << file << " line " << line_no << " for reason: "  << 
	        cudaGetErrorString(err) << std::endl;
    }
  }
}

	.file	"tmpxft_0025e4ef_00000000-6_utility.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3639:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3639:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_ZN3ckt16check_cuda_errorEPKcS1_iP11CUstream_st
	.type	_ZN3ckt16check_cuda_errorEPKcS1_iP11CUstream_st, @function
_ZN3ckt16check_cuda_errorEPKcS1_iP11CUstream_st:
.LFB3635:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE3635:
	.size	_ZN3ckt16check_cuda_errorEPKcS1_iP11CUstream_st, .-_ZN3ckt16check_cuda_errorEPKcS1_iP11CUstream_st
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error at kernel "
.LC1:
	.string	" @ file "
.LC2:
	.string	" line "
.LC3:
	.string	" for reason: "
	.text
	.globl	_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP11CUstream_st
	.type	_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP11CUstream_st, @function
_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP11CUstream_st:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%r8
	.cfi_def_cfa_offset 48
	testq	%rcx, %rcx
	je	.L4
	movq	%rcx, %rdi
	call	cudaStreamSynchronize@PLT
	jmp	.L5
.L4:
	call	cudaDeviceSynchronize@PLT
.L5:
	call	cudaGetLastError@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L3
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r13, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %edi
	movq	%rax, %rbp
	call	cudaGetErrorString@PLT
	movq	%rbp, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%rax, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L3:
	.cfi_restore_state
	popq	%rax
	.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
.LFE3636:
	.size	_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP11CUstream_st, .-_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP11CUstream_st
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3662:
	.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
.LFE3662:
	.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 <hip/hip_runtime.h>
#include <iostream>

namespace ckt {
  void check_cuda_error_always(const char *kernelname, const char *file, int line_no, hipStream_t stream);

  void check_cuda_error(const char *kernelname, const char *file, int line_no, hipStream_t stream )
  {
#ifdef DEBUG
    check_cuda_error_always(kernelname, file, line_no, stream);
#endif
  }

  void check_cuda_error_always(const char *kernelname, const char *file, int line_no, hipStream_t stream)
  {
    hipError_t err;
    if (stream)
      err = hipStreamSynchronize(stream);
    else
      err = hipDeviceSynchronize();
    
    err = hipGetLastError();
    if (err != hipSuccess) {
      std::cerr << "CUDA error at kernel " << kernelname << " @ file " << file << " line " << line_no << " for reason: "  << 
	        hipGetErrorString(err) << std::endl;
    }
  }
}

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

                                        # End of file scope inline assembly
	.globl	_ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t # -- Begin function _ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t
	.type	_ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t,@function
_ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t: # @_ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t
	.cfi_startproc
# %bb.0:
	retq
.Lfunc_end0:
	.size	_ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t, .Lfunc_end0-_ZN3ckt16check_cuda_errorEPKcS1_iP12ihipStream_t
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t # -- Begin function _ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t
	.type	_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t,@function
_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t: # @_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t
	.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
	movl	%edx, %ebx
	movq	%rsi, %r14
	movq	%rdi, %r15
	testq	%rcx, %rcx
	je	.LBB1_2
# %bb.1:
	movq	%rcx, %rdi
	callq	hipStreamSynchronize
	jmp	.LBB1_3
.LBB1_2:
	callq	hipDeviceSynchronize
.LBB1_3:
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB1_14
# %bb.4:
	movl	%eax, %ebp
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	testq	%r15, %r15
	je	.LBB1_5
# %bb.6:
	movq	%r15, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB1_7
.LBB1_14:
	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
.LBB1_5:
	.cfi_def_cfa_offset 48
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB1_7:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.1, %esi
	movl	$8, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	testq	%r14, %r14
	je	.LBB1_8
# %bb.9:
	movq	%r14, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB1_10
.LBB1_8:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB1_10:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit9
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.2, %esi
	movl	$6, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	%ebx, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movl	$13, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%ebp, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB1_11
# %bb.12:
	movq	%rax, %r14
	movq	%rax, %rdi
	callq	strlen
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB1_13
.LBB1_11:
	movq	(%rbx), %rax
	movq	-24(%rax), %rax
	movq	%rbx, %rdi
	addq	%rax, %rdi
	movl	32(%rbx,%rax), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB1_13:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit11
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	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
	jmp	_ZNSo5flushEv                   # TAILCALL
.Lfunc_end1:
	.size	_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t, .Lfunc_end1-_ZN3ckt23check_cuda_error_alwaysEPKcS1_iP12ihipStream_t
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA error at kernel "
	.size	.L.str, 22

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	" @ file "
	.size	.L.str.1, 9

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	" for reason: "
	.size	.L.str.3, 14

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