//
// Created by smallflyfly on 2021/5/18.
//

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

int main(int argc, char **argv) {
    int deviceCount = 0;
    cudaError_t errorId = cudaGetDeviceCount(&deviceCount);
    if (errorId != cudaSuccess) {
        printf("cudaDeviceCount returned %d\n -> %s\n", (int)errorId, cudaGetErrorString(errorId));
        printf("Result = FAIL\n");
        exit(EXIT_FAILURE);
    }

    if (deviceCount == 0) {
        printf("There are no available device that support CUDA\n");
    } else {
        printf("Detected %d CUDA Capable device\n", deviceCount);
    }

    int device = 0, driverVersion = 0, runtimeVersion = 0;
    cudaSetDevice(device);
    cudaDeviceProp deviceProp;
    cudaGetDeviceProperties(&deviceProp, device);

    printf("Device %d:\"%s\"\n", device, deviceProp.name);
    cudaDriverGetVersion(&driverVersion);
    cudaRuntimeGetVersion(&runtimeVersion);
    printf("Driver version / Runtime Version               %d.%d  /  %d.%d\n", driverVersion/1000, (driverVersion%100)/10,
           runtimeVersion/1000, (runtimeVersion%100)/10);

    printf("CUDA Capability Major/Minor version number:    %d.%d\n", deviceProp.major, deviceProp.minor);

    printf("Total amount of global memory:                 %.2f GBytes\n", (float)deviceProp.totalGlobalMem / pow(1024.0, 3));

    printf("GPU clock rate:                                %.0f MHz  (%0.2f GHz)\n", deviceProp.clockRate * 1e-3f, deviceProp.clockRate * 1e-6f);

    printf("Max number of thread per multiprocessor:       %d\n", deviceProp.maxThreadsPerMultiProcessor);

    printf("max number of thread per block:                %d\n", deviceProp.maxThreadsPerBlock);

    printf("max size of each dims of a block:              %d x %d x %d\n", deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]);

    printf("max size of each dim of a grid:                %d x %d x %d\n", deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]);

    exit(EXIT_SUCCESS);
}
	.file	"tmpxft_002385c9_00000000-6_device_information.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	"cudaDeviceCount returned %d\n -> %s\n"
.LC1:
	.string	"Result = FAIL\n"
.LC2:
	.string	"There are no available device that support CUDA\n"
.LC3:
	.string	"Detected %d CUDA Capable device\n"
.LC4:
	.string	"Device %d:\"%s\"\n"
.LC5:
	.string	"Driver version / Runtime Version               %d.%d  /  %d.%d\n"
.LC6:
	.string	"CUDA Capability Major/Minor version number:    %d.%d\n"
.LC8:
	.string	"Total amount of global memory:                 %.2f GBytes\n"
.LC11:
	.string	"GPU clock rate:                                %.0f MHz  (%0.2f GHz)\n"
.LC12:
	.string	"Max number of thread per multiprocessor:       %d\n"
.LC13:
	.string	"max number of thread per block:                %d\n"
.LC14:
	.string	"max size of each dims of a block:              %d x %d x %d\n"
.LC15:
	.string	"max size of each dim of a grid:                %d x %d x %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	xorl	%edx, %edx
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1072
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rdi
	movl	%edx, 4(%rsp)
	call	cudaGetDeviceCount@PLT
	testl	%eax, %eax
	je	.L3
	movl	%eax, %edi
	movl	%eax, %ebx
	call	cudaGetErrorString@PLT
	movl	%ebx, %edx
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$2, %edi
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	jmp	.L10
.L3:
	movl	4(%rsp), %edx
	testl	%edx, %edx
	jne	.L4
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L5
.L4:
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L5:
	xorl	%eax, %eax
	xorl	%edi, %edi
	leaq	16(%rsp), %rbx
	movl	%eax, 8(%rsp)
	movl	%eax, 12(%rsp)
	call	cudaSetDevice@PLT
	xorl	%esi, %esi
	movq	%rbx, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	%rbx, %rcx
	xorl	%edx, %edx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	8(%rsp), %rdi
	call	cudaDriverGetVersion@PLT
	leaq	12(%rsp), %rdi
	call	cudaRuntimeGetVersion@PLT
	movl	12(%rsp), %eax
	movl	$100, %r10d
	movl	$10, %edi
	movl	$1000, %esi
	cltd
	idivl	%r10d
	movl	%edx, %eax
	cltd
	idivl	%edi
	movl	%eax, %r9d
	movl	12(%rsp), %eax
	cltd
	idivl	%esi
	movl	%eax, %r8d
	movl	8(%rsp), %eax
	cltd
	idivl	%r10d
	movl	%edx, %eax
	cltd
	idivl	%edi
	movl	$2, %edi
	movl	%eax, %ecx
	movl	8(%rsp), %eax
	cltd
	idivl	%esi
	leaq	.LC5(%rip), %rsi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	380(%rsp), %ecx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	376(%rsp), %edx
	leaq	.LC6(%rip), %rsi
	call	__printf_chk@PLT
	movq	304(%rsp), %rax
	testq	%rax, %rax
	js	.L6
	cvtsi2ssq	%rax, %xmm0
	jmp	.L7
.L6:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2ssq	%rdx, %xmm0
	addss	%xmm0, %xmm0
.L7:
	cvtss2sd	%xmm0, %xmm0
	leaq	.LC8(%rip), %rsi
	mulsd	.LC7(%rip), %xmm0
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	movss	.LC9(%rip), %xmm1
	leaq	.LC11(%rip), %rsi
	movb	$2, %al
	cvtsi2ssl	364(%rsp), %xmm0
	movl	$2, %edi
	mulss	%xmm0, %xmm1
	mulss	.LC10(%rip), %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movl	640(%rsp), %edx
	leaq	.LC12(%rip), %rsi
	call	__printf_chk@PLT
	movl	336(%rsp), %edx
	leaq	.LC13(%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	.LC14(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	360(%rsp), %r8d
	movl	$2, %edi
	xorl	%eax, %eax
	movl	356(%rsp), %ecx
	movl	352(%rsp), %edx
	leaq	.LC15(%rip), %rsi
	call	__printf_chk@PLT
	xorl	%edi, %edi
.L10:
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC7:
	.long	0
	.long	1041235968
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC9:
	.long	897988541
	.align 4
.LC10:
	.long	981668463
	.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:

//
// Created by smallflyfly on 2021/5/18.
//

#include <stdio.h>
#include <hip/hip_runtime.h>

int main(int argc, char **argv) {
    int deviceCount = 0;
    hipError_t errorId = hipGetDeviceCount(&deviceCount);
    if (errorId != hipSuccess) {
        printf("cudaDeviceCount returned %d\n -> %s\n", (int)errorId, hipGetErrorString(errorId));
        printf("Result = FAIL\n");
        exit(EXIT_FAILURE);
    }

    if (deviceCount == 0) {
        printf("There are no available device that support CUDA\n");
    } else {
        printf("Detected %d CUDA Capable device\n", deviceCount);
    }

    int device = 0, driverVersion = 0, runtimeVersion = 0;
    hipSetDevice(device);
    hipDeviceProp_t deviceProp;
    hipGetDeviceProperties(&deviceProp, device);

    printf("Device %d:\"%s\"\n", device, deviceProp.name);
    hipDriverGetVersion(&driverVersion);
    hipRuntimeGetVersion(&runtimeVersion);
    printf("Driver version / Runtime Version               %d.%d  /  %d.%d\n", driverVersion/1000, (driverVersion%100)/10,
           runtimeVersion/1000, (runtimeVersion%100)/10);

    printf("CUDA Capability Major/Minor version number:    %d.%d\n", deviceProp.major, deviceProp.minor);

    printf("Total amount of global memory:                 %.2f GBytes\n", (float)deviceProp.totalGlobalMem / pow(1024.0, 3));

    printf("GPU clock rate:                                %.0f MHz  (%0.2f GHz)\n", deviceProp.clockRate * 1e-3f, deviceProp.clockRate * 1e-6f);

    printf("Max number of thread per multiprocessor:       %d\n", deviceProp.maxThreadsPerMultiProcessor);

    printf("max number of thread per block:                %d\n", deviceProp.maxThreadsPerBlock);

    printf("max size of each dims of a block:              %d x %d x %d\n", deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]);

    printf("max size of each dim of a grid:                %d x %d x %d\n", deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]);

    exit(EXIT_SUCCESS);
}
	.text
	.file	"device_information.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x3e10000000000000              # double 9.3132257461547852E-10
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI0_1:
	.long	0x3a83126f                      # float 0.00100000005
.LCPI0_2:
	.long	0x358637bd                      # float 9.99999997E-7
	.text
	.globl	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	%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 %r15, -16
	leaq	4(%rsp), %rdi
	movl	$0, (%rdi)
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.1:
	movl	4(%rsp), %esi
	testl	%esi, %esi
	jne	.LBB0_3
# %bb.2:
	movl	$.Lstr, %edi
	callq	puts@PLT
	jmp	.LBB0_4
.LBB0_8:
	movl	%eax, %ebx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	%ebx, %esi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.LBB0_3:
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
.LBB0_4:
	xorl	%eax, %eax
	leaq	12(%rsp), %r15
	movl	%eax, (%r15)
	leaq	8(%rsp), %r14
	movl	%eax, (%r14)
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.4, %edi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	movq	%r15, %rdi
	callq	hipDriverGetVersion
	movq	%r14, %rdi
	callq	hipRuntimeGetVersion
	movslq	(%r15), %rax
	imulq	$274877907, %rax, %rsi          # imm = 0x10624DD3
	movq	%rsi, %rcx
	shrq	$63, %rcx
	sarq	$38, %rsi
	addl	%ecx, %esi
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	shrq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	movsbl	%al, %eax
	imull	$103, %eax, %ecx
	movl	$65535, %eax                    # imm = 0xFFFF
	movswl	%cx, %edx
	andl	%eax, %ecx
	shrl	$15, %ecx
	shrl	$10, %edx
	addb	%cl, %dl
	movsbl	%dl, %edx
	movslq	(%r14), %rdi
	imulq	$274877907, %rdi, %rcx          # imm = 0x10624DD3
	movq	%rcx, %r8
	shrq	$63, %r8
	sarq	$38, %rcx
	addl	%r8d, %ecx
	imulq	$1374389535, %rdi, %r8          # imm = 0x51EB851F
	movq	%r8, %r9
	shrq	$63, %r9
	shrq	$37, %r8
	addl	%r9d, %r8d
	imull	$100, %r8d, %r8d
	subl	%r8d, %edi
	movsbl	%dil, %edi
	imull	$103, %edi, %edi
	andl	%edi, %eax
	shrl	$15, %eax
	movswl	%di, %edi
	shrl	$10, %edi
	addb	%al, %dil
	movsbl	%dil, %r8d
	movl	$.L.str.5, %edi
                                        # kill: def $esi killed $esi killed $rsi
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	printf
	movl	360(%rbx), %esi
	movl	364(%rbx), %edx
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movq	288(%rbx), %rax
	testq	%rax, %rax
	js	.LBB0_5
# %bb.6:
	cvtsi2ss	%rax, %xmm0
	jmp	.LBB0_7
.LBB0_5:
	movq	%rax, %rcx
	shrq	%rcx
	andl	$1, %eax
	orq	%rcx, %rax
	cvtsi2ss	%rax, %xmm0
	addss	%xmm0, %xmm0
.LBB0_7:
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI0_0(%rip), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	cvtsi2ssl	364(%rsp), %xmm1
	movss	.LCPI0_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulss	.LCPI0_2(%rip), %xmm1
	cvtss2sd	%xmm1, %xmm1
	movl	$.L.str.8, %edi
	movb	$2, %al
	callq	printf
	movl	640(%rsp), %esi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	336(%rsp), %esi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	340(%rsp), %esi
	movl	344(%rsp), %edx
	movl	348(%rsp), %ecx
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	352(%rsp), %esi
	movl	356(%rsp), %edx
	movl	360(%rsp), %ecx
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%edi, %edi
	callq	exit
.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	"cudaDeviceCount returned %d\n -> %s\n"
	.size	.L.str, 36

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Detected %d CUDA Capable device\n"
	.size	.L.str.3, 33

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Driver version / Runtime Version               %d.%d  /  %d.%d\n"
	.size	.L.str.5, 64

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"CUDA Capability Major/Minor version number:    %d.%d\n"
	.size	.L.str.6, 54

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Total amount of global memory:                 %.2f GBytes\n"
	.size	.L.str.7, 60

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"GPU clock rate:                                %.0f MHz  (%0.2f GHz)\n"
	.size	.L.str.8, 70

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Max number of thread per multiprocessor:       %d\n"
	.size	.L.str.9, 51

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

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"max size of each dims of a block:              %d x %d x %d\n"
	.size	.L.str.11, 61

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"max size of each dim of a grid:                %d x %d x %d\n"
	.size	.L.str.12, 61

	.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	"There are no available device that support CUDA"
	.size	.Lstr, 48

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Result = FAIL"
	.size	.Lstr.1, 14

	.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
