#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

void get_grid_config (dim3 &grid, dim3 &block)
{//Get the device properties

    static bool flag = 0;
    static dim3 lgrid, lthreads;

    if (!flag) {
        cudaDeviceProp devProp;
        cudaGetDeviceProperties(&devProp, 0);

        //Adjust the grid dimensions based on the device properties
        int num_blocks = 1024 * 2 * devProp.multiProcessorCount;
        lgrid = dim3(num_blocks);
        lthreads = dim3(devProp.maxThreadsPerBlock / 4);
        flag = 1;
    }

    grid = lgrid;
    block = lthreads;
}

int main() {
    dim3 grid, block;
    get_grid_config(grid, block);
    printf("Recommended grid:(%d,%d,%d)\n", grid.x, grid.y, grid.z);
    printf("Recommended size:(%d,%d,%d)\n", block.x, block.y, block.y);

    return 1;
}
	.file	"tmpxft_00254023_00000000-6_gpu_specs.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
	.globl	_Z15get_grid_configR4dim3S0_
	.type	_Z15get_grid_configR4dim3S0_, @function
_Z15get_grid_configR4dim3S0_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rsi, %rbx
	subq	$1048, %rsp
	.cfi_def_cfa_offset 1072
	movq	%fs:40, %rax
	movq	%rax, 1032(%rsp)
	xorl	%eax, %eax
	cmpb	$0, _ZZ15get_grid_configR4dim3S0_E4flag(%rip)
	jne	.L3
	xorl	%esi, %esi
	movq	%rsp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	388(%rsp), %eax
	movl	$4, %esi
	movabsq	$4294967297, %rcx
	movq	%rcx, 4+_ZZ15get_grid_configR4dim3S0_E5lgrid(%rip)
	sall	$11, %eax
	movq	%rcx, 4+_ZZ15get_grid_configR4dim3S0_E8lthreads(%rip)
	movl	%eax, _ZZ15get_grid_configR4dim3S0_E5lgrid(%rip)
	movl	320(%rsp), %eax
	movb	$1, _ZZ15get_grid_configR4dim3S0_E4flag(%rip)
	cltd
	idivl	%esi
	movl	%eax, _ZZ15get_grid_configR4dim3S0_E8lthreads(%rip)
.L3:
	movq	_ZZ15get_grid_configR4dim3S0_E5lgrid(%rip), %rax
	movq	%rax, 0(%rbp)
	movl	8+_ZZ15get_grid_configR4dim3S0_E5lgrid(%rip), %eax
	movl	%eax, 8(%rbp)
	movq	_ZZ15get_grid_configR4dim3S0_E8lthreads(%rip), %rax
	movq	%rax, (%rbx)
	movl	8+_ZZ15get_grid_configR4dim3S0_E8lthreads(%rip), %eax
	movl	%eax, 8(%rbx)
	movq	1032(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$1048, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z15get_grid_configR4dim3S0_, .-_Z15get_grid_configR4dim3S0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Recommended grid:(%d,%d,%d)\n"
.LC1:
	.string	"Recommended size:(%d,%d,%d)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	movabsq	$4294967297, %rax
	leaq	12(%rsp), %rsi
	movq	%rsp, %rdi
	movl	$1, 8(%rsp)
	movq	%rax, (%rsp)
	movq	%rax, 12(%rsp)
	call	_Z15get_grid_configR4dim3S0_
	movl	8(%rsp), %r8d
	movl	4(%rsp), %ecx
	xorl	%eax, %eax
	movl	(%rsp), %edx
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	16(%rsp), %ecx
	movl	12(%rsp), %edx
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movl	%ecx, %r8d
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	movl	$1, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.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
	.data
	.align 8
	.type	_ZZ15get_grid_configR4dim3S0_E8lthreads, @object
	.size	_ZZ15get_grid_configR4dim3S0_E8lthreads, 12
_ZZ15get_grid_configR4dim3S0_E8lthreads:
	.long	1
	.long	1
	.long	1
	.align 8
	.type	_ZZ15get_grid_configR4dim3S0_E5lgrid, @object
	.size	_ZZ15get_grid_configR4dim3S0_E5lgrid, 12
_ZZ15get_grid_configR4dim3S0_E5lgrid:
	.long	1
	.long	1
	.long	1
	.local	_ZZ15get_grid_configR4dim3S0_E4flag
	.comm	_ZZ15get_grid_configR4dim3S0_E4flag,1,1
	.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>
#include <stdlib.h>
#include <stdbool.h>

void get_grid_config (dim3 &grid, dim3 &block)
{//Get the device properties

    static bool flag = 0;
    static dim3 lgrid, lthreads;

    if (!flag) {
        hipDeviceProp_t devProp;
        hipGetDeviceProperties(&devProp, 0);

        //Adjust the grid dimensions based on the device properties
        int num_blocks = 1024 * 2 * devProp.multiProcessorCount;
        lgrid = dim3(num_blocks);
        lthreads = dim3(devProp.maxThreadsPerBlock / 4);
        flag = 1;
    }

    grid = lgrid;
    block = lthreads;
}

int main() {
    dim3 grid, block;
    get_grid_config(grid, block);
    printf("Recommended grid:(%d,%d,%d)\n", grid.x, grid.y, grid.z);
    printf("Recommended size:(%d,%d,%d)\n", block.x, block.y, block.y);

    return 1;
}
	.text
	.file	"gpu_specs.hip"
	.globl	_Z15get_grid_configR4dim3S0_    # -- Begin function _Z15get_grid_configR4dim3S0_
	.type	_Z15get_grid_configR4dim3S0_,@function
_Z15get_grid_configR4dim3S0_:           # @_Z15get_grid_configR4dim3S0_
	.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	$1472, %rsp                     # imm = 0x5C0
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	cmpb	$0, _ZZ15get_grid_configR4dim3S0_E4flag(%rip)
	jne	.LBB0_2
# %bb.1:
	movq	%rsp, %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	320(%r15), %eax
	movl	388(%r15), %ecx
	shll	$11, %ecx
	movl	%ecx, _ZZ15get_grid_configR4dim3S0_E5lgrid(%rip)
	movabsq	$4294967297, %rcx               # imm = 0x100000001
	movq	%rcx, _ZZ15get_grid_configR4dim3S0_E5lgrid+4(%rip)
	leal	3(%rax), %edx
	testl	%eax, %eax
	cmovnsl	%eax, %edx
	sarl	$2, %edx
	movl	%edx, _ZZ15get_grid_configR4dim3S0_E8lthreads(%rip)
	movq	%rcx, _ZZ15get_grid_configR4dim3S0_E8lthreads+4(%rip)
	movb	$1, _ZZ15get_grid_configR4dim3S0_E4flag(%rip)
.LBB0_2:
	movl	_ZZ15get_grid_configR4dim3S0_E5lgrid+8(%rip), %eax
	movl	%eax, 8(%r14)
	movq	_ZZ15get_grid_configR4dim3S0_E5lgrid(%rip), %rax
	movq	%rax, (%r14)
	movl	_ZZ15get_grid_configR4dim3S0_E8lthreads+8(%rip), %eax
	movl	%eax, 8(%rbx)
	movq	_ZZ15get_grid_configR4dim3S0_E8lthreads(%rip), %rax
	movq	%rax, (%rbx)
	addq	$1472, %rsp                     # imm = 0x5C0
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z15get_grid_configR4dim3S0_, .Lfunc_end0-_Z15get_grid_configR4dim3S0_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movabsq	$4294967297, %rax               # imm = 0x100000001
	leaq	12(%rsp), %rbx
	movq	%rax, (%rbx)
	movl	$1, 8(%rbx)
	movq	%rsp, %r14
	movq	%rax, (%r14)
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z15get_grid_configR4dim3S0_
	movl	(%rbx), %esi
	movl	4(%rbx), %edx
	movl	8(%rbx), %ecx
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%r14), %esi
	movl	4(%r14), %ecx
	movl	$.L.str.1, %edi
	movl	%ecx, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	_ZZ15get_grid_configR4dim3S0_E4flag,@object # @_ZZ15get_grid_configR4dim3S0_E4flag
	.local	_ZZ15get_grid_configR4dim3S0_E4flag
	.comm	_ZZ15get_grid_configR4dim3S0_E4flag,1,1
	.type	_ZZ15get_grid_configR4dim3S0_E5lgrid,@object # @_ZZ15get_grid_configR4dim3S0_E5lgrid
	.data
	.p2align	2, 0x0
_ZZ15get_grid_configR4dim3S0_E5lgrid:
	.long	1                               # 0x1
	.long	1                               # 0x1
	.long	1                               # 0x1
	.size	_ZZ15get_grid_configR4dim3S0_E5lgrid, 12

	.type	_ZZ15get_grid_configR4dim3S0_E8lthreads,@object # @_ZZ15get_grid_configR4dim3S0_E8lthreads
	.p2align	2, 0x0
_ZZ15get_grid_configR4dim3S0_E8lthreads:
	.long	1                               # 0x1
	.long	1                               # 0x1
	.long	1                               # 0x1
	.size	_ZZ15get_grid_configR4dim3S0_E8lthreads, 12

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Recommended grid:(%d,%d,%d)\n"
	.size	.L.str, 29

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Recommended size:(%d,%d,%d)\n"
	.size	.L.str.1, 29

	.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
