#include <cstdio>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>

/**
 * @brief display gpu information
 * @param devProp device
*/
void dispGPUInfo(const cudaDeviceProp& devProp);
/**
 * @brief display gpu information
 * @param dev_id gpu id
 * @return GPU information
*/
cudaDeviceProp getGPUInfo(const unsigned int& dev_id);

cudaDeviceProp getGPUInfo(const unsigned int& dev_id)
{
	std::printf("----------------GPU----------------\r\n");
	cudaDeviceProp devProp;
	cudaGetDeviceProperties(&devProp, dev_id);
	return devProp;
}
void dispGPUInfo(const cudaDeviceProp& devProp)
{
	std::printf("ʹGPU name: %s\r\n", devProp.name);
	std::printf("number of SMs: %d\r\n", devProp.multiProcessorCount);
	std::printf("max grid size: %d x %d x %d\r\n", devProp.maxGridSize[0], devProp.maxGridSize[1], devProp.maxGridSize[2]);
	std::printf("size of shared memory per block: %f KB\r\n", devProp.sharedMemPerBlock / 1024.0);
	std::printf("max number of thread per block: %d\r\n", devProp.maxThreadsPerBlock);
	std::printf("max number of thread per SM: %d\r\n", devProp.maxThreadsPerMultiProcessor);
	std::printf("number of block per SM: %d\r\n", devProp.maxThreadsPerMultiProcessor / devProp.maxThreadsPerBlock);
	std::printf("warp size: %d\r\n", devProp.warpSize);
	std::printf("max number of thread per SM per warp size: %d\r\n", 
		devProp.maxThreadsPerMultiProcessor / devProp.warpSize);
}
	.file	"tmpxft_0028ad92_00000000-6_gpuinfo.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	"----------------GPU----------------\r\n"
	.text
	.globl	_Z10getGPUInfoRKj
	.type	_Z10getGPUInfoRKj, @function
_Z10getGPUInfoRKj:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	movl	$2, %edi
	pushq	%rax
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	0(%rbp), %esi
	movq	%rbx, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	%rbx, %rax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10getGPUInfoRKj, .-_Z10getGPUInfoRKj
	.section	.rodata.str1.1
.LC1:
	.string	"\312\271GPU name: %s\r\n"
.LC2:
	.string	"number of SMs: %d\r\n"
.LC3:
	.string	"max grid size: %d x %d x %d\r\n"
.LC5:
	.string	"size of shared memory per block: %f KB\r\n"
.LC6:
	.string	"max number of thread per block: %d\r\n"
.LC7:
	.string	"max number of thread per SM: %d\r\n"
.LC8:
	.string	"number of block per SM: %d\r\n"
.LC9:
	.string	"warp size: %d\r\n"
.LC10:
	.string	"max number of thread per SM per warp size: %d\r\n"
	.text
	.globl	_Z11dispGPUInfoRK14cudaDeviceProp
	.type	_Z11dispGPUInfoRK14cudaDeviceProp, @function
_Z11dispGPUInfoRK14cudaDeviceProp:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rdx
	movq	%rdi, %rbx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	388(%rbx), %edx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	340(%rbx), %ecx
	xorl	%eax, %eax
	movl	336(%rbx), %edx
	movl	344(%rbx), %r8d
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	296(%rbx), %rax
	testq	%rax, %rax
	js	.L5
	cvtsi2sdq	%rax, %xmm0
	jmp	.L6
.L5:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2sdq	%rdx, %xmm0
	addsd	%xmm0, %xmm0
.L6:
	mulsd	.LC4(%rip), %xmm0
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	movl	320(%rbx), %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	624(%rbx), %edx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	624(%rbx), %eax
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	cltd
	idivl	320(%rbx)
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	308(%rbx), %edx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	624(%rbx), %eax
	movl	$2, %edi
	leaq	.LC10(%rip), %rsi
	cltd
	idivl	308(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	movl	%eax, %edx
	xorl	%eax, %eax
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z11dispGPUInfoRK14cudaDeviceProp, .-_Z11dispGPUInfoRK14cudaDeviceProp
	.section	.text.startup,"ax",@progbits
	.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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	0
	.long	1062207488
	.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 <cstdio>
#include <hip/hip_runtime.h>


/**
 * @brief display gpu information
 * @param devProp device
*/
void dispGPUInfo(const hipDeviceProp_t& devProp);
/**
 * @brief display gpu information
 * @param dev_id gpu id
 * @return GPU information
*/
hipDeviceProp_t getGPUInfo(const unsigned int& dev_id);

hipDeviceProp_t getGPUInfo(const unsigned int& dev_id)
{
	std::printf("----------------GPU----------------\r\n");
	hipDeviceProp_t devProp;
	hipGetDeviceProperties(&devProp, dev_id);
	return devProp;
}
void dispGPUInfo(const hipDeviceProp_t& devProp)
{
	std::printf("ʹGPU name: %s\r\n", devProp.name);
	std::printf("number of SMs: %d\r\n", devProp.multiProcessorCount);
	std::printf("max grid size: %d x %d x %d\r\n", devProp.maxGridSize[0], devProp.maxGridSize[1], devProp.maxGridSize[2]);
	std::printf("size of shared memory per block: %f KB\r\n", devProp.sharedMemPerBlock / 1024.0);
	std::printf("max number of thread per block: %d\r\n", devProp.maxThreadsPerBlock);
	std::printf("max number of thread per SM: %d\r\n", devProp.maxThreadsPerMultiProcessor);
	std::printf("number of block per SM: %d\r\n", devProp.maxThreadsPerMultiProcessor / devProp.maxThreadsPerBlock);
	std::printf("warp size: %d\r\n", devProp.warpSize);
	std::printf("max number of thread per SM per warp size: %d\r\n", 
		devProp.maxThreadsPerMultiProcessor / devProp.warpSize);
}
	.text
	.file	"gpuinfo.hip"
	.globl	_Z10getGPUInfoRKj               # -- Begin function _Z10getGPUInfoRKj
	.type	_Z10getGPUInfoRKj,@function
_Z10getGPUInfoRKj:                      # @_Z10getGPUInfoRKj
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	(%rbx), %esi
	movq	%r14, %rdi
	callq	hipGetDevicePropertiesR0600
	movq	%r14, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z10getGPUInfoRKj, .Lfunc_end0-_Z10getGPUInfoRKj
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z11dispGPUInfoRK20hipDeviceProp_tR0600
.LCPI1_0:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI1_1:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_2:
	.quad	0x3f50000000000000              # double 9.765625E-4
	.text
	.globl	_Z11dispGPUInfoRK20hipDeviceProp_tR0600
	.type	_Z11dispGPUInfoRK20hipDeviceProp_tR0600,@function
_Z11dispGPUInfoRK20hipDeviceProp_tR0600: # @_Z11dispGPUInfoRK20hipDeviceProp_tR0600
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$.L.str.1, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	388(%rbx), %esi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movl	336(%rbx), %esi
	movl	340(%rbx), %edx
	movl	344(%rbx), %ecx
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movsd	296(%rbx), %xmm1                # xmm1 = mem[0],zero
	unpcklps	.LCPI1_0(%rip), %xmm1           # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
	subpd	.LCPI1_1(%rip), %xmm1
	movapd	%xmm1, %xmm0
	unpckhpd	%xmm1, %xmm0                    # xmm0 = xmm0[1],xmm1[1]
	addsd	%xmm1, %xmm0
	mulsd	.LCPI1_2(%rip), %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	movl	320(%rbx), %esi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	624(%rbx), %esi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	624(%rbx), %eax
	cltd
	idivl	320(%rbx)
	movl	$.L.str.7, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movl	308(%rbx), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	624(%rbx), %eax
	cltd
	idivl	308(%rbx)
	movl	$.L.str.9, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end1:
	.size	_Z11dispGPUInfoRK20hipDeviceProp_tR0600, .Lfunc_end1-_Z11dispGPUInfoRK20hipDeviceProp_tR0600
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"\312\271GPU name: %s\r\n"
	.size	.L.str.1, 17

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"number of SMs: %d\r\n"
	.size	.L.str.2, 20

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"max grid size: %d x %d x %d\r\n"
	.size	.L.str.3, 30

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"size of shared memory per block: %f KB\r\n"
	.size	.L.str.4, 41

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"max number of thread per block: %d\r\n"
	.size	.L.str.5, 37

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"max number of thread per SM: %d\r\n"
	.size	.L.str.6, 34

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"number of block per SM: %d\r\n"
	.size	.L.str.7, 29

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"warp size: %d\r\n"
	.size	.L.str.8, 16

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"max number of thread per SM per warp size: %d\r\n"
	.size	.L.str.9, 48

	.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	"----------------GPU----------------\r"
	.size	.Lstr, 37

	.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
