#include "kernel.cuh"
#include <stdio.h>

__global__ void firstKernel(void)
{
    printf("Hello I'm thread in block: %d\n", blockIdx.x);
}

void runKernel()
{
    getDeviceProperties();
    firstKernel << <16, 1 >> > ();
}

void getDeviceProperties()
{
    int device_count = 0;
    cudaGetDeviceCount(&device_count);

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

        printDeviceName(0);
        printDriverRuntimeVersion();
        printMemoryData(0);
        printCpuData(0);
    }
}

void printDeviceName(int const deviceIndex)
{
    cudaDeviceProp device_property;
    cudaGetDeviceProperties(&device_property, deviceIndex);
    printf("\nDevice %d: \"%s\" \n", 0, device_property.name);
}

void printDriverRuntimeVersion()
{
    int driver_version, runtime_version;
    cudaDriverGetVersion(&driver_version);
    cudaRuntimeGetVersion(&runtime_version);
    printf(" CUDA Driver Version / Runtime Version: %d.%d / %d.%d\n", driver_version / 1000, (driver_version % 100) / 10, runtime_version / 1000, (runtime_version % 100) / 10);
}

void printMemoryData(int const deviceIndex)
{
    cudaDeviceProp device_property;
    cudaGetDeviceProperties(&device_property, deviceIndex);
    
    printf(" Total amount of global memeory %.0f MBytes (%llu bytes)\n", (float)device_property.totalGlobalMem / 1048576.0f, (unsigned long long) device_property.totalGlobalMem);
    printf(" Memory Clock rate: %.0f Mhz\n", device_property.memoryClockRate);
    
    if (device_property.l2CacheSize)
    {
        printf(" L2 Cache Size: %d bytes\n", device_property.l2CacheSize);
    }

    printf(" Total amount of constant memory: %lu bytes\n", device_property.totalConstMem);
    printf(" Total amount of shared memeory per block: %lu bytes\n", device_property.sharedMemPerBlock);
    printf(" Total amount of regisers available per block: %d\n", device_property.regsPerBlock);
}

void printCpuData(int const deviceIndex)
{
    cudaDeviceProp device_property;
    cudaGetDeviceProperties(&device_property, deviceIndex);
    
    printf(" (%2d) Multiprocessors", device_property.multiProcessorCount);
    printf(" GPU Max Clock rate: %.0f MHz (%0.2f GHz)\n", device_property.clockRate * 1e-3f, device_property.clockRate * 1e-6f);

    printf(" Maximum number of threads per multiprocessor: %d\n", device_property.maxThreadsPerMultiProcessor);
    printf(" Maximum number of threads per block: %d\n", device_property.maxThreadsPerBlock);
    printf(" Max dimension size of a thread block (x,y,z): (%d, %d, %d)\n", device_property.maxThreadsDim[0], device_property.maxThreadsDim[1], device_property.maxThreadsDim[2]);
    printf(" Max dimension size of a grid size (x, y, z): (%d, %d, %d)\n", device_property.maxGridSize[0], device_property.maxGridSize[1], device_property.maxGridSize[2]);
}

	.file	"tmpxft_002d148c_00000000-6_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\nDevice %d: \"%s\" \n"
	.text
	.globl	_Z15printDeviceNamei
	.type	_Z15printDeviceNamei, @function
_Z15printDeviceNamei:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %esi
	subq	$1040, %rsp
	.cfi_def_cfa_offset 1056
	movq	%fs:40, %rax
	movq	%rax, 1032(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	xorl	%edx, %edx
	xorl	%eax, %eax
	movq	%rbx, %rcx
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	1032(%rsp), %rax
	subq	%fs:40, %rax
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$1040, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z15printDeviceNamei, .-_Z15printDeviceNamei
	.section	.rodata.str1.1
.LC1:
	.string	" CUDA Driver Version / Runtime Version: %d.%d / %d.%d\n"
	.text
	.globl	_Z25printDriverRuntimeVersionv
	.type	_Z25printDriverRuntimeVersionv, @function
_Z25printDriverRuntimeVersionv:
.LFB2030:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaDriverGetVersion@PLT
	leaq	4(%rsp), %rdi
	call	cudaRuntimeGetVersion@PLT
	movl	4(%rsp), %eax
	movl	$100, %r10d
	movl	$10, %edi
	movl	$1000, %esi
	cltd
	idivl	%r10d
	movl	%edx, %eax
	cltd
	idivl	%edi
	movl	%eax, %r9d
	movl	4(%rsp), %eax
	cltd
	idivl	%esi
	movl	%eax, %r8d
	movl	(%rsp), %eax
	cltd
	idivl	%r10d
	movl	%edx, %eax
	cltd
	idivl	%edi
	movl	$2, %edi
	movl	%eax, %ecx
	movl	(%rsp), %eax
	cltd
	idivl	%esi
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z25printDriverRuntimeVersionv, .-_Z25printDriverRuntimeVersionv
	.section	.rodata.str1.1
.LC3:
	.string	" Total amount of global memeory %.0f MBytes (%llu bytes)\n"
.LC4:
	.string	" Memory Clock rate: %.0f Mhz\n"
.LC5:
	.string	" L2 Cache Size: %d bytes\n"
.LC6:
	.string	" Total amount of constant memory: %lu bytes\n"
.LC7:
	.string	" Total amount of shared memeory per block: %lu bytes\n"
.LC8:
	.string	" Total amount of regisers available per block: %d\n"
	.text
	.globl	_Z15printMemoryDatai
	.type	_Z15printMemoryDatai, @function
_Z15printMemoryDatai:
.LFB2031:
	.cfi_startproc
	endbr64
	subq	$1048, %rsp
	.cfi_def_cfa_offset 1056
	movl	%edi, %esi
	movq	%fs:40, %rax
	movq	%rax, 1032(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	288(%rsp), %rdx
	testq	%rdx, %rdx
	js	.L10
	cvtsi2ssq	%rdx, %xmm0
	jmp	.L11
.L10:
	movq	%rdx, %rax
	movq	%rdx, %rcx
	shrq	%rax
	andl	$1, %ecx
	orq	%rcx, %rax
	cvtsi2ssq	%rax, %xmm0
	addss	%xmm0, %xmm0
.L11:
	mulss	.LC2(%rip), %xmm0
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movl	608(%rsp), %edx
	leaq	.LC4(%rip), %rsi
	call	__printf_chk@PLT
	movl	616(%rsp), %edx
	testl	%edx, %edx
	je	.L12
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	movq	352(%rsp), %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	296(%rsp), %rdx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	304(%rsp), %edx
	xorl	%eax, %eax
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	1032(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$1048, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z15printMemoryDatai, .-_Z15printMemoryDatai
	.section	.rodata.str1.1
.LC9:
	.string	" (%2d) Multiprocessors"
.LC12:
	.string	" GPU Max Clock rate: %.0f MHz (%0.2f GHz)\n"
.LC13:
	.string	" Maximum number of threads per multiprocessor: %d\n"
.LC14:
	.string	" Maximum number of threads per block: %d\n"
.LC15:
	.string	" Max dimension size of a thread block (x,y,z): (%d, %d, %d)\n"
.LC16:
	.string	" Max dimension size of a grid size (x, y, z): (%d, %d, %d)\n"
	.text
	.globl	_Z12printCpuDatai
	.type	_Z12printCpuDatai, @function
_Z12printCpuDatai:
.LFB2032:
	.cfi_startproc
	endbr64
	subq	$1048, %rsp
	.cfi_def_cfa_offset 1056
	movl	%edi, %esi
	movq	%fs:40, %rax
	movq	%rax, 1032(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	388(%rsp), %edx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movss	.LC10(%rip), %xmm1
	leaq	.LC12(%rip), %rsi
	movb	$2, %al
	cvtsi2ssl	348(%rsp), %xmm0
	movl	$2, %edi
	mulss	%xmm0, %xmm1
	mulss	.LC11(%rip), %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movl	624(%rsp), %edx
	leaq	.LC13(%rip), %rsi
	call	__printf_chk@PLT
	movl	320(%rsp), %edx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	332(%rsp), %r8d
	xorl	%eax, %eax
	movl	328(%rsp), %ecx
	movl	324(%rsp), %edx
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	344(%rsp), %r8d
	movl	340(%rsp), %ecx
	xorl	%eax, %eax
	movl	336(%rsp), %edx
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	1032(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$1048, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z12printCpuDatai, .-_Z12printCpuDatai
	.section	.rodata.str1.1
.LC17:
	.string	"There are no available devices that support CUDA"
.LC18:
	.string	"Detected %d CUDA capable device(s)\n"
	.text
	.globl	_Z19getDevicePropertiesv
	.type	_Z19getDevicePropertiesv, @function
_Z19getDevicePropertiesv:
.LFB2028:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rdi
	xorl	%eax, %eax
	movl	%eax, 4(%rsp)
	call	cudaGetDeviceCount@PLT
	movl	4(%rsp), %edx
	testl	%edx, %edx
	jne	.L22
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L21
.L22:
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	_Z15printDeviceNamei
	call	_Z25printDriverRuntimeVersionv
	xorl	%edi, %edi
	call	_Z15printMemoryDatai
	xorl	%edi, %edi
	call	_Z12printCpuDatai
.L21:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z19getDevicePropertiesv, .-_Z19getDevicePropertiesv
	.globl	_Z30__device_stub__Z11firstKernelvv
	.type	_Z30__device_stub__Z11firstKernelvv, @function
_Z30__device_stub__Z11firstKernelvv:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$88, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	movabsq	$4294967297, %rax
	leaq	8(%rsp), %rcx
	movq	%rsp, %rdx
	leaq	28(%rsp), %rsi
	leaq	16(%rsp), %rdi
	movl	$1, 24(%rsp)
	movl	$1, 36(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 28(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	pushq	8(%rsp)
	.cfi_def_cfa_offset 104
	leaq	_Z11firstKernelv(%rip), %rdi
	pushq	8(%rsp)
	.cfi_def_cfa_offset 112
	movq	44(%rsp), %rcx
	movl	52(%rsp), %r8d
	movq	32(%rsp), %rsi
	movl	40(%rsp), %edx
	leaq	80(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 104
	popq	%rdx
	.cfi_def_cfa_offset 96
.L26:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$88, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z30__device_stub__Z11firstKernelvv, .-_Z30__device_stub__Z11firstKernelvv
	.globl	_Z11firstKernelv
	.type	_Z11firstKernelv, @function
_Z11firstKernelv:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z11firstKernelvv
	.cfi_endproc
.LFE2058:
	.size	_Z11firstKernelv, .-_Z11firstKernelv
	.globl	_Z9runKernelv
	.type	_Z9runKernelv, @function
_Z9runKernelv:
.LFB2027:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	call	_Z19getDevicePropertiesv
	movl	$268435457, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$4, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967297, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	_Z30__device_stub__Z11firstKernelvv
.L31:
	.cfi_restore_state
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9runKernelv, .-_Z9runKernelv
	.section	.rodata.str1.1
.LC19:
	.string	"_Z11firstKernelv"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC19(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11firstKernelv(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.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
.LC2:
	.long	897581056
	.align 4
.LC10:
	.long	897988541
	.align 4
.LC11:
	.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:

#include <hip/hip_runtime.h>


__global__ void firstKernel(void);

void runKernel();
void getDeviceProperties();
void printDeviceName(int const deviceIndex);
void printDriverRuntimeVersion();
void printMemoryData(int const deviceIndex);
void printCpuData(int const deviceIndex);

	.text
	.file	"kernel.hip"
	.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
