// 这个程序选中符合指定条件的设备

// CUDA 支持
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

// 传统 C++ 支持
#include <iostream>
 
using namespace std;
 
// 主函数，还没有输入参数
int main()
{
	//定义需要的设备属性
	cudaDeviceProp devicePropDefined;
    memset(&devicePropDefined, 0, sizeof(cudaDeviceProp));  //设置devicepropDefined的值
    // 版本号的要求
	devicePropDefined.major = 5;
	devicePropDefined.minor = 2;
 
	int devicedChoosed;  //选中的设备ID
	cudaError_t cudaError;
	cudaGetDevice(&devicedChoosed);  //获取当前设备ID
	cout << "当前使用设备的编号： " << devicedChoosed << endl;
 
	cudaChooseDevice(&devicedChoosed, &devicePropDefined);  //查找符合要求的设备ID
	cout << "满足指定属性要求的设备的编号： " << devicedChoosed << endl;
 
	cudaError = cudaSetDevice(devicedChoosed); //设置选中的设备为下文的运行设备
 
	if (cudaError == cudaSuccess)
		cout << "设备选取成功！" << endl;
	else
        cout << "设备选取失败！" << endl;
        
    char c;
    cin>>c;
	return 0;
}

	.file	"tmpxft_002d0f2c_00000000-6_hit_device.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\345\275\223\345\211\215\344\275\277\347\224\250\350\256\276\345\244\207\347\232\204\347\274\226\345\217\267\357\274\232 "
.LC1:
	.string	"\346\273\241\350\266\263\346\214\207\345\256\232\345\261\236\346\200\247\350\246\201\346\261\202\347\232\204\350\256\276\345\244\207\347\232\204\347\274\226\345\217\267\357\274\232 "
.LC2:
	.string	"\350\256\276\345\244\207\351\200\211\345\217\226\346\210\220\345\212\237\357\274\201"
.LC3:
	.string	"\350\256\276\345\244\207\351\200\211\345\217\226\345\244\261\350\264\245\357\274\201"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$258, %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	_ZSt4cout(%rip), %rbx
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbp
	leaq	12(%rsp), %r12
	movq	%rbp, %rdi
	rep stosl
	movq	%r12, %rdi
	movabsq	$8589934597, %rax
	movq	%rax, 376(%rsp)
	call	cudaGetDevice@PLT
	leaq	.LC0(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	12(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	%rbp, %rsi
	movq	%r12, %rdi
	call	cudaChooseDevice@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	12(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	12(%rsp), %edi
	call	cudaSetDevice@PLT
	leaq	.LC2(%rip), %rsi
	testl	%eax, %eax
	je	.L7
	leaq	.LC3(%rip), %rsi
.L7:
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	11(%rsp), %rsi
	leaq	_ZSt3cin(%rip), %rdi
	call	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_@PLT
	movq	1048(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$1056, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	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	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3661:
	.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
.LFE3661:
	.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:

// 这个程序选中符合指定条件的设备

// CUDA 支持
#include "hip/hip_runtime.h"


// 传统 C++ 支持
#include <iostream>
 
using namespace std;
 
// 主函数，还没有输入参数
int main()
{
	//定义需要的设备属性
	hipDeviceProp_t devicePropDefined;
    memset(&devicePropDefined, 0, sizeof(hipDeviceProp_t));  //设置devicepropDefined的值
    // 版本号的要求
	devicePropDefined.major = 5;
	devicePropDefined.minor = 2;
 
	int devicedChoosed;  //选中的设备ID
	hipError_t hipError_t;
	hipGetDevice(&devicedChoosed);  //获取当前设备ID
	cout << "当前使用设备的编号： " << devicedChoosed << endl;
 
	hipChooseDevice(&devicedChoosed, &devicePropDefined);  //查找符合要求的设备ID
	cout << "满足指定属性要求的设备的编号： " << devicedChoosed << endl;
 
	hipError_t = hipSetDevice(devicedChoosed); //设置选中的设备为下文的运行设备
 
	if (hipError_t == hipSuccess)
		cout << "设备选取成功！" << endl;
	else
        cout << "设备选取失败！" << endl;
        
    char c;
    cin>>c;
	return 0;
}

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

                                        # End of file scope inline assembly
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.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	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 1520
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	8(%rsp), %r14
	movl	$1472, %edx                     # imm = 0x5C0
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movabsq	$8589934597, %rax               # imm = 0x200000005
	movq	%rax, 360(%r14)
	leaq	4(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDevice
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$31, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rbx), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	hipChooseDeviceR0600
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$46, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rbx), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	(%rbx), %edi
	callq	hipSetDevice
	testl	%eax, %eax
	movl	$.L.str.2, %eax
	movl	$.L.str.3, %esi
	cmoveq	%rax, %rsi
	movl	$_ZSt4cout, %edi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	leaq	3(%rsp), %rsi
	movl	$_ZSt3cin, %edi
	callq	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_
	xorl	%eax, %eax
	addq	$1480, %rsp                     # imm = 0x5C8
	.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
.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	"\345\275\223\345\211\215\344\275\277\347\224\250\350\256\276\345\244\207\347\232\204\347\274\226\345\217\267\357\274\232 "
	.size	.L.str, 32

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\346\273\241\350\266\263\346\214\207\345\256\232\345\261\236\346\200\247\350\246\201\346\261\202\347\232\204\350\256\276\345\244\207\347\232\204\347\274\226\345\217\267\357\274\232 "
	.size	.L.str.1, 47

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\350\256\276\345\244\207\351\200\211\345\217\226\346\210\220\345\212\237\357\274\201"
	.size	.L.str.2, 22

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\350\256\276\345\244\207\351\200\211\345\217\226\345\244\261\350\264\245\357\274\201"
	.size	.L.str.3, 22

	.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 _ZSt4cout
	.addrsig_sym _ZSt3cin
	.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
