#include <stdio.h>

int main() {
	cudaDeviceProp prop;

	int count;
	cudaGetDeviceCount(&count);
	printf("Number of CUDA-enabled GPU devices: %d\n", count);
	for(int i=0; i<count; i++) {
		cudaGetDeviceProperties(&prop, i);
		printf("Device %d: \"%s\"\n", i, prop.name);
		printf("  Compute Capability:                   %d.%d\n", prop.major, prop.minor);
		printf("  Number of multi processor:            %d\n", prop.multiProcessorCount);
		printf("  Number of scalar processor:           %d\n", prop.multiProcessorCount*8);
		printf("  Clock rate:                           %d MHz\n", prop.clockRate/(1024));
		printf("  Total amount of global memory:        %1.2f GBytes\n", (float)(prop.totalGlobalMem)/(1024*1024*1024));
		printf("  Total amount of shared memory per MP: %d KBytes\n", prop.regsPerBlock/1024);
		printf("  Threads in a warp:                    %d\n", prop.warpSize);
		printf("  Max threads per block:                %d\n", prop.maxThreadsPerBlock);
		printf("  Max thread dimensions:                (%d, %d, %d)\n", prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]);
		printf("  Max grid dimensions:                  (%d, %d, %d)\n\n", prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]);
	}


	// select device satisfied given conditions
	int dev;
	memset(&prop, 0, sizeof(cudaDeviceProp));
	prop.major = 1 ;
	prop.major = 3 ;
	cudaChooseDevice(&dev, &prop);
	printf("ID of selected CUDA device: %d\n", dev);
	cudaSetDevice(dev);

	return 0;
}

	.file	"tmpxft_0020bd0c_00000000-6_querying_devices.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	"Number of CUDA-enabled GPU devices: %d\n"
.LC1:
	.string	"Device %d: \"%s\"\n"
.LC2:
	.string	"  Compute Capability:                   %d.%d\n"
.LC3:
	.string	"  Number of multi processor:            %d\n"
.LC4:
	.string	"  Number of scalar processor:           %d\n"
.LC5:
	.string	"  Clock rate:                           %d MHz\n"
.LC7:
	.string	"  Total amount of global memory:        %1.2f GBytes\n"
.LC8:
	.string	"  Total amount of shared memory per MP: %d KBytes\n"
.LC9:
	.string	"  Threads in a warp:                    %d\n"
.LC10:
	.string	"  Max threads per block:                %d\n"
.LC11:
	.string	"  Max thread dimensions:                (%d, %d, %d)\n"
.LC12:
	.string	"  Max grid dimensions:                  (%d, %d, %d)\n\n"
.LC13:
	.string	"ID of selected CUDA device: %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	8(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
.L3:
	cmpl	%ebx, 8(%rsp)
	leaq	16(%rsp), %r12
	jle	.L10
	movl	%ebx, %esi
	movq	%r12, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	%r12, %rcx
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	380(%rsp), %ecx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	376(%rsp), %edx
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movl	404(%rsp), %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	404(%rsp), %eax
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	leal	0(,%rax,8), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1024, %ecx
	movl	$2, %edi
	movl	364(%rsp), %eax
	leaq	.LC5(%rip), %rsi
	cltd
	idivl	%ecx
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	304(%rsp), %rax
	testq	%rax, %rax
	js	.L4
	cvtsi2ssq	%rax, %xmm0
	jmp	.L5
.L4:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2ssq	%rdx, %xmm0
	addss	%xmm0, %xmm0
.L5:
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	incl	%ebx
	mulss	.LC6(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	320(%rsp), %eax
	movl	$1024, %ecx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	cltd
	idivl	%ecx
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	324(%rsp), %edx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	336(%rsp), %edx
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	348(%rsp), %r8d
	xorl	%eax, %eax
	movl	344(%rsp), %ecx
	movl	340(%rsp), %edx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	360(%rsp), %r8d
	xorl	%eax, %eax
	movl	356(%rsp), %ecx
	movl	352(%rsp), %edx
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L3
.L10:
	xorl	%eax, %eax
	movl	$258, %ecx
	movq	%r12, %rdi
	movq	%r12, %rsi
	rep stosl
	leaq	12(%rsp), %rdi
	movl	$3, 376(%rsp)
	call	cudaChooseDevice@PLT
	movl	12(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC13(%rip), %rsi
	call	__printf_chk@PLT
	movl	12(%rsp), %edi
	call	cudaSetDevice@PLT
	movq	1048(%rsp), %rax
	subq	%fs:40, %rax
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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
.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
.LC6:
	.long	813694976
	.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 <stdio.h>

int main() {
	hipDeviceProp_t prop;

	int count;
	hipGetDeviceCount(&count);
	printf("Number of CUDA-enabled GPU devices: %d\n", count);
	for(int i=0; i<count; i++) {
		hipGetDeviceProperties(&prop, i);
		printf("Device %d: \"%s\"\n", i, prop.name);
		printf("  Compute Capability:                   %d.%d\n", prop.major, prop.minor);
		printf("  Number of multi processor:            %d\n", prop.multiProcessorCount);
		printf("  Number of scalar processor:           %d\n", prop.multiProcessorCount*8);
		printf("  Clock rate:                           %d MHz\n", prop.clockRate/(1024));
		printf("  Total amount of global memory:        %1.2f GBytes\n", (float)(prop.totalGlobalMem)/(1024*1024*1024));
		printf("  Total amount of shared memory per MP: %d KBytes\n", prop.regsPerBlock/1024);
		printf("  Threads in a warp:                    %d\n", prop.warpSize);
		printf("  Max threads per block:                %d\n", prop.maxThreadsPerBlock);
		printf("  Max thread dimensions:                (%d, %d, %d)\n", prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]);
		printf("  Max grid dimensions:                  (%d, %d, %d)\n\n", prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]);
	}


	// select device satisfied given conditions
	int dev;
	memset(&prop, 0, sizeof(hipDeviceProp_t));
	prop.major = 1 ;
	prop.major = 3 ;
	hipChooseDevice(&dev, &prop);
	printf("ID of selected CUDA device: %d\n", dev);
	hipSetDevice(dev);

	return 0;
}

	.text
	.file	"querying_devices.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x30800000                      # float 9.31322574E-10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 1520
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	(%rbx), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, (%rbx)
	jle	.LBB0_6
# %bb.1:                                # %.lr.ph
	leaq	16(%rsp), %rbx
	movl	$1023, %r14d                    # imm = 0x3FF
	xorl	%ebp, %ebp
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.1, %edi
	movl	%ebp, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	376(%rsp), %esi
	movl	380(%rsp), %edx
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movl	404(%rsp), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	404(%rsp), %esi
	shll	$3, %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	364(%rsp), %eax
	leal	(%rax,%r14), %esi
	testl	%eax, %eax
	cmovnsl	%eax, %esi
	sarl	$10, %esi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movq	304(%rsp), %rax
	testq	%rax, %rax
	js	.LBB0_3
# %bb.4:                                #   in Loop: Header=BB0_2 Depth=1
	cvtsi2ss	%rax, %xmm0
	jmp	.LBB0_5
.LBB0_3:                                #   in Loop: Header=BB0_2 Depth=1
	movq	%rax, %rcx
	shrq	%rcx
	andl	$1, %eax
	orq	%rcx, %rax
	cvtsi2ss	%rax, %xmm0
	addss	%xmm0, %xmm0
.LBB0_5:                                #   in Loop: Header=BB0_2 Depth=1
	mulss	.LCPI0_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movl	320(%rsp), %eax
	leal	(%rax,%r14), %esi
	testl	%eax, %eax
	cmovnsl	%eax, %esi
	sarl	$10, %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	324(%rsp), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	336(%rsp), %esi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	340(%rsp), %esi
	movl	344(%rsp), %edx
	movl	348(%rsp), %ecx
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	352(%rsp), %esi
	movl	356(%rsp), %edx
	movl	360(%rsp), %ecx
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	cmpl	8(%rsp), %ebp
	jl	.LBB0_2
.LBB0_6:                                # %._crit_edge
	leaq	16(%rsp), %rbx
	movl	$1472, %edx                     # imm = 0x5C0
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$3, 360(%rbx)
	leaq	12(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipChooseDeviceR0600
	movl	(%r14), %esi
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%r14), %edi
	callq	hipSetDevice
	xorl	%eax, %eax
	addq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.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	"Number of CUDA-enabled GPU devices: %d\n"
	.size	.L.str, 40

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Device %d: \"%s\"\n"
	.size	.L.str.1, 17

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"  Compute Capability:                   %d.%d\n"
	.size	.L.str.2, 47

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"  Number of multi processor:            %d\n"
	.size	.L.str.3, 44

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"  Number of scalar processor:           %d\n"
	.size	.L.str.4, 44

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"  Clock rate:                           %d MHz\n"
	.size	.L.str.5, 48

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"  Total amount of global memory:        %1.2f GBytes\n"
	.size	.L.str.6, 54

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"  Total amount of shared memory per MP: %d KBytes\n"
	.size	.L.str.7, 51

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"  Threads in a warp:                    %d\n"
	.size	.L.str.8, 44

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"  Max threads per block:                %d\n"
	.size	.L.str.9, 44

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"  Max thread dimensions:                (%d, %d, %d)\n"
	.size	.L.str.10, 54

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"  Max grid dimensions:                  (%d, %d, %d)\n\n"
	.size	.L.str.11, 55

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"ID of selected CUDA device: %d\n"
	.size	.L.str.12, 32

	.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
