#include<stdio.h>
#include<cuda_runtime.h>

bool init_cuda(){
	int count;
	cudaGetDeviceCount(&count);
	if(0 == count) {
		fprintf(stderr, "There is no device \n");
		return false;
	}

	int i;
	for(i = 0; i < count; i++) {
		cudaDeviceProp prop;
		if(cudaSuccess == cudaGetDeviceProperties(&prop, i)) {
			if(prop.major >= 1){
				break;
			}
		}
	}

	if(i == count){
		fprintf(stderr, "There is no device supporting CUDA 1.x.\n");
		return false;
	}

	cudaSetDevice(i);

	return true;
}

int main() {
	if(!init_cuda()) {
		return 0;
	}

	printf("CUDA initialize.\n");

	return 0;
}



	.file	"tmpxft_00308a69_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"There is no device \n"
.LC1:
	.string	"There is no device supporting CUDA 1.x.\n"
	.text
	.globl	_Z9init_cudav
	.type	_Z9init_cudav, @function
_Z9init_cudav:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$1064, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	cmpl	$0, 12(%rsp)
	leaq	.LC0(%rip), %rdx
	je	.L16
	xorl	%ebx, %ebx
	leaq	16(%rsp), %rbp
.L3:
	cmpl	%ebx, 12(%rsp)
	jle	.L7
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	testl	%eax, %eax
	jne	.L5
	cmpl	$0, 376(%rsp)
	jg	.L7
.L5:
	incl	%ebx
	jmp	.L3
.L7:
	cmpl	%ebx, 12(%rsp)
	jne	.L9
	leaq	.LC1(%rip), %rdx
.L16:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	xorl	%eax, %eax
	jmp	.L2
.L9:
	movl	%ebx, %edi
	call	cudaSetDevice@PLT
	movb	$1, %al
.L2:
	movq	1048(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$1064, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9init_cudav, .-_Z9init_cudav
	.section	.rodata.str1.1
.LC2:
	.string	"CUDA initialize.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rcx
	.cfi_def_cfa_offset 16
	call	_Z9init_cudav
	testb	%al, %al
	je	.L19
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L19:
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.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
.LFE2054:
	.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<hip/hip_runtime.h>

bool init_cuda(){
	int count;
	hipGetDeviceCount(&count);
	if(0 == count) {
		fprintf(stderr, "There is no device \n");
		return false;
	}

	int i;
	for(i = 0; i < count; i++) {
		hipDeviceProp_t prop;
		if(hipSuccess == hipGetDeviceProperties(&prop, i)) {
			if(prop.major >= 1){
				break;
			}
		}
	}

	if(i == count){
		fprintf(stderr, "There is no device supporting CUDA 1.x.\n");
		return false;
	}

	hipSetDevice(i);

	return true;
}

int main() {
	if(!init_cuda()) {
		return 0;
	}

	printf("CUDA initialize.\n");

	return 0;
}



	.text
	.file	"main.hip"
	.globl	_Z9init_cudav                   # -- Begin function _Z9init_cudav
	.type	_Z9init_cudav,@function
_Z9init_cudav:                          # @_Z9init_cudav
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	leaq	4(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	(%rbx), %ecx
	testl	%ecx, %ecx
	je	.LBB0_3
# %bb.1:                                # %.preheader
	jle	.LBB0_2
# %bb.5:                                # %.lr.ph
	xorl	%ebx, %ebx
	leaq	8(%rsp), %r14
.LBB0_6:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	hipGetDevicePropertiesR0600
	movl	4(%rsp), %ecx
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.7:                                #   in Loop: Header=BB0_6 Depth=1
	cmpl	$0, 368(%rsp)
	jg	.LBB0_9
.LBB0_8:                                #   in Loop: Header=BB0_6 Depth=1
	incl	%ebx
	cmpl	%ecx, %ebx
	jl	.LBB0_6
	jmp	.LBB0_9
.LBB0_2:
	xorl	%ebx, %ebx
.LBB0_9:                                # %._crit_edge
	cmpl	%ecx, %ebx
	je	.LBB0_10
# %bb.11:
	movl	%ebx, %edi
	callq	hipSetDevice
	movb	$1, %al
.LBB0_12:
                                        # kill: def $al killed $al killed $eax
	addq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB0_3:
	.cfi_def_cfa_offset 1504
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$20, %esi
	jmp	.LBB0_4
.LBB0_10:
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$40, %esi
.LBB0_4:
	movl	$1, %edx
	callq	fwrite@PLT
	xorl	%eax, %eax
	jmp	.LBB0_12
.Lfunc_end0:
	.size	_Z9init_cudav, .Lfunc_end0-_Z9init_cudav
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	_Z9init_cudav
	testb	%al, %al
	je	.LBB1_2
# %bb.1:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB1_2:
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"There is no device \n"
	.size	.L.str, 21

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"There is no device supporting CUDA 1.x.\n"
	.size	.L.str.1, 41

	.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	"CUDA initialize."
	.size	.Lstr, 17

	.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
