#include <stdio.h>

int num_devices = 0;


/******************************************************************************
*
* Auxiliary routines
*
******************************************************************************/


#define error_check(error) do                 \
{                                             \
    cuda_assert((error), __FILE__, __LINE__); \
} while (0);

void cuda_assert(cudaError_t code, const char *file, int line)
{
    if (code != cudaSuccess) {
        fprintf(stderr,
            "[ERROR] Error code: %d Message: %s %s %d\n",
            code, cudaGetErrorString(code), file, line);
        exit(code);
    }
}

void mem_ustring(char *s, long bytes)
{
    double usize = 0;
    if (bytes > 1E+9)
    {
        usize = bytes / 1E+9;
        sprintf(s, "%.2lf GB", usize);
    }
    else if (bytes > 1E+6)
    {
        usize = bytes / 1E+6;
        sprintf(s, "%.2lf MB", usize);
    }
    else if (bytes > 1E+3)
    {
        usize = bytes / 1E+3;
        sprintf(s, "%.2lf KB", usize);
    }
    else
    {
        usize = bytes;
        sprintf(s, "%lf Bytes", usize);
    }
}

void print_device_info(void)
{
    for (int n = 0; n < num_devices; n++)
    {
        char ustring[64];

        cudaDeviceProp device_prop;
        cudaGetDeviceProperties(&device_prop, n);

        size_t free_mem;;

        cudaMemGetInfo(&free_mem, NULL);

        int device_threads = device_prop.multiProcessorCount * device_prop.maxThreadsPerMultiProcessor;

        printf("Device %d: %s\n", n, device_prop.name);
        printf("    Compute capability:      %d.%d\n", device_prop.major, device_prop.minor);
        printf("    Total number of threads: %d\n", device_threads);
        mem_ustring(ustring, device_prop.totalGlobalMem);
        printf("    Global memory size:      %s\n", ustring);
        mem_ustring(ustring, device_prop.sharedMemPerBlock);
        printf("    Shared memory size:      %s\n", ustring);
        mem_ustring(ustring, device_prop.totalConstMem);
        printf("    Constant memory size:    %s\n", ustring);
        mem_ustring(ustring, free_mem);
        printf("    Total free memory:       %s\n", ustring);
        printf("    Warp size:               %d\n", device_prop.warpSize);
    }
    printf("\n");
}


/******************************************************************************
*
* CUDA kernels
*
******************************************************************************/


__global__
void char_add(char *a, char *b)
{
    a[threadIdx.x] = b[threadIdx.x];
}


/******************************************************************************
*
* Device tests
*
******************************************************************************/


void run_device_test(void)
{
    for (int n = 0; n < num_devices; n++)
    {
        cudaSetDevice(n);

        int string_size;

        char string[256] = "Hello world!";

        string_size = strlen(string) + 1;

        /* Allocate device */
        char *d_a, *d_b;
        cudaMalloc((void **)&d_a, string_size * sizeof(char));
        cudaMalloc((void **)&d_b, string_size * sizeof(char));

        /* Allocate host */
        char *a = (char *)calloc(string_size, sizeof(char));
        char *b = (char *)calloc(string_size, sizeof(char));

        strcpy(b, string);

        dim3 dim_block(string_size, 1);
        dim3 dim_grid(1);

        cudaMemcpy((void *)d_b, (const void *)b, string_size * sizeof(char), cudaMemcpyHostToDevice);

        char_add<<<dim_grid, dim_block>>>(d_a, d_b);
        error_check(cudaPeekAtLastError());
        error_check(cudaDeviceSynchronize());

        cudaMemcpy((void *)a, (void *)d_a, string_size, cudaMemcpyDeviceToHost);

        cudaDeviceProp device_prop;
        cudaGetDeviceProperties(&device_prop, n);

        if (strcmp(a, b) == 0)
            printf("[PASSED TEST] Device %d: %s\n", n, device_prop.name);
        else
            printf("[FAILED TEST] Device %d: %s\n", n, device_prop.name);

        cudaFree(d_a);
        cudaFree(d_b);
        free(a);
        free(b);
    }
    printf("\n");
}

int main(void)
{
    error_check(cudaGetDeviceCount(&num_devices));
    if (num_devices > 0)
    {
        print_device_info();
        run_device_test();
    }
    else
    {
        printf("[ERROR] No CUDA devices found!\n");
    }

    return EXIT_SUCCESS;
}

	.file	"tmpxft_00378580_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"[ERROR] Error code: %d Message: %s %s %d\n"
	.text
	.globl	_Z11cuda_assert9cudaErrorPKci
	.type	_Z11cuda_assert9cudaErrorPKci, @function
_Z11cuda_assert9cudaErrorPKci:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%rsi, 8(%rsp)
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	%ebx, %ecx
	leaq	.LC0(%rip), %rdx
	movq	%rax, %r8
	pushq	%rax
	.cfi_def_cfa_offset 56
	movl	$2, %esi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 64
	movq	24(%rsp), %r9
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z11cuda_assert9cudaErrorPKci, .-_Z11cuda_assert9cudaErrorPKci
	.section	.rodata.str1.1
.LC2:
	.string	"%.2lf GB"
.LC4:
	.string	"%.2lf MB"
.LC6:
	.string	"%.2lf KB"
.LC7:
	.string	"%lf Bytes"
	.text
	.globl	_Z11mem_ustringPcl
	.type	_Z11mem_ustringPcl, @function
_Z11mem_ustringPcl:
.LFB2028:
	.cfi_startproc
	endbr64
	cvtsi2sdq	%rsi, %xmm0
	movsd	.LC1(%rip), %xmm1
	comisd	%xmm1, %xmm0
	jbe	.L18
	divsd	%xmm1, %xmm0
	leaq	.LC2(%rip), %rcx
	jmp	.L21
.L18:
	movsd	.LC3(%rip), %xmm1
	comisd	%xmm1, %xmm0
	jbe	.L19
	divsd	%xmm1, %xmm0
	leaq	.LC4(%rip), %rcx
	jmp	.L21
.L19:
	movsd	.LC5(%rip), %xmm1
	leaq	.LC7(%rip), %rcx
	comisd	%xmm1, %xmm0
	jbe	.L21
	divsd	%xmm1, %xmm0
	leaq	.LC6(%rip), %rcx
.L21:
	orq	$-1, %rdx
	movl	$2, %esi
	movb	$1, %al
	jmp	__sprintf_chk@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z11mem_ustringPcl, .-_Z11mem_ustringPcl
	.section	.rodata.str1.1
.LC8:
	.string	"Device %d: %s\n"
.LC9:
	.string	"    Compute capability:      %d.%d\n"
.LC10:
	.string	"    Total number of threads: %d\n"
.LC11:
	.string	"    Global memory size:      %s\n"
.LC12:
	.string	"    Shared memory size:      %s\n"
.LC13:
	.string	"    Constant memory size:    %s\n"
.LC14:
	.string	"    Total free memory:       %s\n"
.LC15:
	.string	"    Warp size:               %d\n"
.LC16:
	.string	"\n"
	.text
	.globl	_Z17print_device_infov
	.type	_Z17print_device_infov, @function
_Z17print_device_infov:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC8(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$1128, %rsp
	.cfi_def_cfa_offset 1168
	movq	%fs:40, %rax
	movq	%rax, 1112(%rsp)
	xorl	%eax, %eax
.L23:
	cmpl	%ebp, num_devices(%rip)
	jle	.L28
	leaq	16(%rsp), %r12
	movl	%ebp, %esi
	movq	%r12, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemGetInfo@PLT
	movl	%ebp, %edx
	movl	404(%rsp), %ebx
	xorl	%eax, %eax
	imull	640(%rsp), %ebx
	movq	%r12, %rcx
	movq	%r13, %rsi
	incl	%ebp
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	380(%rsp), %ecx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	376(%rsp), %edx
	leaq	.LC9(%rip), %rsi
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	1048(%rsp), %rbx
	call	__printf_chk@PLT
	movq	304(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z11mem_ustringPcl
	movq	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC11(%rip), %rsi
	call	__printf_chk@PLT
	movq	312(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z11mem_ustringPcl
	movq	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC12(%rip), %rsi
	call	__printf_chk@PLT
	movq	368(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z11mem_ustringPcl
	movq	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC13(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z11mem_ustringPcl
	movq	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC14(%rip), %rsi
	call	__printf_chk@PLT
	movl	324(%rsp), %edx
	leaq	.LC15(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L23
.L28:
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$1128, %rsp
	.cfi_def_cfa_offset 40
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z17print_device_infov, .-_Z17print_device_infov
	.globl	_Z29__device_stub__Z8char_addPcS_PcS_
	.type	_Z29__device_stub__Z8char_addPcS_PcS_, @function
_Z29__device_stub__Z8char_addPcS_PcS_:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z8char_addPcS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L29:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z29__device_stub__Z8char_addPcS_PcS_, .-_Z29__device_stub__Z8char_addPcS_PcS_
	.globl	_Z8char_addPcS_
	.type	_Z8char_addPcS_, @function
_Z8char_addPcS_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z8char_addPcS_PcS_
	.cfi_endproc
.LFE2057:
	.size	_Z8char_addPcS_, .-_Z8char_addPcS_
	.section	.rodata.str1.1
.LC17:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/fredaas/synthbench/master/cuda-test/main.cu"
.LC18:
	.string	"[PASSED TEST] Device %d: %s\n"
.LC19:
	.string	"[FAILED TEST] Device %d: %s\n"
	.text
	.globl	_Z15run_device_testv
	.type	_Z15run_device_testv, @function
_Z15run_device_testv:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$1368, %rsp
	.cfi_def_cfa_offset 1424
	movq	%fs:40, %rax
	movq	%rax, 1352(%rsp)
	xorl	%eax, %eax
.L35:
	cmpl	%ebx, num_devices(%rip)
	jle	.L44
	movl	%ebx, %edi
	leaq	1096(%rsp), %r15
	call	cudaSetDevice@PLT
	movaps	.LC20(%rip), %xmm0
	xorl	%eax, %eax
	leaq	1112(%rsp), %rdi
	movl	$60, %ecx
	rep stosl
	movq	%r15, %rdi
	movups	%xmm0, 1096(%rsp)
	call	strlen@PLT
	leaq	24(%rsp), %rdi
	leal	1(%rax), %ebp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	$1, %esi
	movq	%rbp, %rdi
	call	calloc@PLT
	movl	$1, %esi
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	calloc@PLT
	movq	%rbp, %rdx
	movq	%r15, %rsi
	movq	%rax, %rdi
	movq	%rax, %r12
	call	__strcpy_chk@PLT
	movq	32(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movabsq	$4294967297, %rax
	movl	$1, %ecx
	movl	%ebp, 40(%rsp)
	movq	%rax, 44(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	cudaMemcpy@PLT
	movl	48(%rsp), %ecx
	movl	60(%rsp), %esi
	xorl	%r9d, %r9d
	movq	40(%rsp), %rdx
	movq	52(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z29__device_stub__Z8char_addPcS_PcS_
.L36:
	call	cudaPeekAtLastError@PLT
	leaq	.LC17(%rip), %r14
	movl	$135, %edx
	movl	%eax, %edi
	movq	%r14, %rsi
	call	_Z11cuda_assert9cudaErrorPKci
	call	cudaDeviceSynchronize@PLT
	movl	$136, %edx
	movq	%r14, %rsi
	movl	%eax, %edi
	call	_Z11cuda_assert9cudaErrorPKci
	movq	24(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r13, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	leaq	64(%rsp), %rcx
	movl	%ebx, %esi
	movq	%rcx, %rdi
	movq	%rcx, 8(%rsp)
	call	cudaGetDeviceProperties_v2@PLT
	movq	%r12, %rsi
	movq	%r13, %rdi
	call	strcmp@PLT
	movq	8(%rsp), %rcx
	movl	%ebx, %edx
	leaq	.LC18(%rip), %rsi
	testl	%eax, %eax
	movl	$2, %edi
	je	.L43
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
.L43:
	call	__printf_chk@PLT
	movq	24(%rsp), %rdi
	incl	%ebx
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	jmp	.L35
.L44:
	movq	1352(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$1368, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z15run_device_testv, .-_Z15run_device_testv
	.section	.rodata.str1.1
.LC21:
	.string	"[ERROR] No CUDA devices found!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rcx
	.cfi_def_cfa_offset 16
	leaq	num_devices(%rip), %rdi
	call	cudaGetDeviceCount@PLT
	movl	$158, %edx
	leaq	.LC17(%rip), %rsi
	movl	%eax, %edi
	call	_Z11cuda_assert9cudaErrorPKci
	cmpl	$0, num_devices(%rip)
	jle	.L46
	call	_Z17print_device_infov
	call	_Z15run_device_testv
	jmp	.L47
.L46:
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L47:
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC22:
	.string	"_Z8char_addPcS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC22(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8char_addPcS_(%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
.LFE2059:
	.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
	.globl	num_devices
	.bss
	.align 4
	.type	num_devices, @object
	.size	num_devices, 4
num_devices:
	.zero	4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1104006501
	.align 8
.LC3:
	.long	0
	.long	1093567616
	.align 8
.LC5:
	.long	0
	.long	1083129856
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC20:
	.quad	8031924123371070792
	.quad	560229490
	.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 num_devices = 0;


/******************************************************************************
*
* Auxiliary routines
*
******************************************************************************/


#define error_check(error) do                 \
{                                             \
    cuda_assert((error), __FILE__, __LINE__); \
} while (0);

void cuda_assert(hipError_t code, const char *file, int line)
{
    if (code != hipSuccess) {
        fprintf(stderr,
            "[ERROR] Error code: %d Message: %s %s %d\n",
            code, hipGetErrorString(code), file, line);
        exit(code);
    }
}

void mem_ustring(char *s, long bytes)
{
    double usize = 0;
    if (bytes > 1E+9)
    {
        usize = bytes / 1E+9;
        sprintf(s, "%.2lf GB", usize);
    }
    else if (bytes > 1E+6)
    {
        usize = bytes / 1E+6;
        sprintf(s, "%.2lf MB", usize);
    }
    else if (bytes > 1E+3)
    {
        usize = bytes / 1E+3;
        sprintf(s, "%.2lf KB", usize);
    }
    else
    {
        usize = bytes;
        sprintf(s, "%lf Bytes", usize);
    }
}

void print_device_info(void)
{
    for (int n = 0; n < num_devices; n++)
    {
        char ustring[64];

        hipDeviceProp_t device_prop;
        hipGetDeviceProperties(&device_prop, n);

        size_t free_mem;;

        hipMemGetInfo(&free_mem, NULL);

        int device_threads = device_prop.multiProcessorCount * device_prop.maxThreadsPerMultiProcessor;

        printf("Device %d: %s\n", n, device_prop.name);
        printf("    Compute capability:      %d.%d\n", device_prop.major, device_prop.minor);
        printf("    Total number of threads: %d\n", device_threads);
        mem_ustring(ustring, device_prop.totalGlobalMem);
        printf("    Global memory size:      %s\n", ustring);
        mem_ustring(ustring, device_prop.sharedMemPerBlock);
        printf("    Shared memory size:      %s\n", ustring);
        mem_ustring(ustring, device_prop.totalConstMem);
        printf("    Constant memory size:    %s\n", ustring);
        mem_ustring(ustring, free_mem);
        printf("    Total free memory:       %s\n", ustring);
        printf("    Warp size:               %d\n", device_prop.warpSize);
    }
    printf("\n");
}


/******************************************************************************
*
* CUDA kernels
*
******************************************************************************/


__global__
void char_add(char *a, char *b)
{
    a[threadIdx.x] = b[threadIdx.x];
}


/******************************************************************************
*
* Device tests
*
******************************************************************************/


void run_device_test(void)
{
    for (int n = 0; n < num_devices; n++)
    {
        hipSetDevice(n);

        int string_size;

        char string[256] = "Hello world!";

        string_size = strlen(string) + 1;

        /* Allocate device */
        char *d_a, *d_b;
        hipMalloc((void **)&d_a, string_size * sizeof(char));
        hipMalloc((void **)&d_b, string_size * sizeof(char));

        /* Allocate host */
        char *a = (char *)calloc(string_size, sizeof(char));
        char *b = (char *)calloc(string_size, sizeof(char));

        strcpy(b, string);

        dim3 dim_block(string_size, 1);
        dim3 dim_grid(1);

        hipMemcpy((void *)d_b, (const void *)b, string_size * sizeof(char), hipMemcpyHostToDevice);

        char_add<<<dim_grid, dim_block>>>(d_a, d_b);
        error_check(hipPeekAtLastError());
        error_check(hipDeviceSynchronize());

        hipMemcpy((void *)a, (void *)d_a, string_size, hipMemcpyDeviceToHost);

        hipDeviceProp_t device_prop;
        hipGetDeviceProperties(&device_prop, n);

        if (strcmp(a, b) == 0)
            printf("[PASSED TEST] Device %d: %s\n", n, device_prop.name);
        else
            printf("[FAILED TEST] Device %d: %s\n", n, device_prop.name);

        hipFree(d_a);
        hipFree(d_b);
        free(a);
        free(b);
    }
    printf("\n");
}

int main(void)
{
    error_check(hipGetDeviceCount(&num_devices));
    if (num_devices > 0)
    {
        print_device_info();
        run_device_test();
    }
    else
    {
        printf("[ERROR] No CUDA devices found!\n");
    }

    return EXIT_SUCCESS;
}

	.text
	.file	"main.hip"
	.globl	_Z11cuda_assert10hipError_tPKci # -- Begin function _Z11cuda_assert10hipError_tPKci
	.type	_Z11cuda_assert10hipError_tPKci,@function
_Z11cuda_assert10hipError_tPKci:        # @_Z11cuda_assert10hipError_tPKci
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rsi, %r14
	movl	%edi, %ebx
	movq	stderr(%rip), %r15
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%r15, %rdi
	movl	%ebx, %edx
	movq	%rax, %rcx
	movq	%r14, %r8
	movl	%ebp, %r9d
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z11cuda_assert10hipError_tPKci, .Lfunc_end0-_Z11cuda_assert10hipError_tPKci
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z11mem_ustringPcl
.LCPI1_0:
	.quad	0x408f400000000000              # double 1000
.LCPI1_1:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI1_2:
	.quad	0x41cdcd6500000000              # double 1.0E+9
	.text
	.globl	_Z11mem_ustringPcl
	.type	_Z11mem_ustringPcl,@function
_Z11mem_ustringPcl:                     # @_Z11mem_ustringPcl
	.cfi_startproc
# %bb.0:
	cvtsi2sd	%rsi, %xmm0
	cmpq	$1000000001, %rsi               # imm = 0x3B9ACA01
	jl	.LBB1_2
# %bb.1:
	divsd	.LCPI1_2(%rip), %xmm0
	movl	$.L.str.1, %esi
	jmp	.LBB1_7
.LBB1_2:
	cmpq	$1000001, %rsi                  # imm = 0xF4241
	jl	.LBB1_4
# %bb.3:
	divsd	.LCPI1_1(%rip), %xmm0
	movl	$.L.str.2, %esi
	jmp	.LBB1_7
.LBB1_4:
	cmpq	$1001, %rsi                     # imm = 0x3E9
	jl	.LBB1_6
# %bb.5:
	divsd	.LCPI1_0(%rip), %xmm0
	movl	$.L.str.3, %esi
	jmp	.LBB1_7
.LBB1_6:
	movl	$.L.str.4, %esi
.LBB1_7:
	movb	$1, %al
	jmp	sprintf                         # TAILCALL
.Lfunc_end1:
	.size	_Z11mem_ustringPcl, .Lfunc_end1-_Z11mem_ustringPcl
	.cfi_endproc
                                        # -- End function
	.globl	_Z17print_device_infov          # -- Begin function _Z17print_device_infov
	.type	_Z17print_device_infov,@function
_Z17print_device_infov:                 # @_Z17print_device_infov
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$1552, %rsp                     # imm = 0x610
	.cfi_def_cfa_offset 1600
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$0, num_devices(%rip)
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph
	leaq	80(%rsp), %rbx
	leaq	8(%rsp), %r14
	leaq	16(%rsp), %r15
	xorl	%ebp, %ebp
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	hipMemGetInfo
	movl	704(%rsp), %r12d
	imull	468(%rsp), %r12d
	movl	$.L.str.5, %edi
	movl	%ebp, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	440(%rsp), %esi
	movl	444(%rsp), %edx
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.7, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	368(%rsp), %rsi
	movq	%r15, %rdi
	callq	_Z11mem_ustringPcl
	movl	$.L.str.8, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	376(%rsp), %rsi
	movq	%r15, %rdi
	callq	_Z11mem_ustringPcl
	movl	$.L.str.9, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	432(%rsp), %rsi
	movq	%r15, %rdi
	callq	_Z11mem_ustringPcl
	movl	$.L.str.10, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	8(%rsp), %rsi
	movq	%r15, %rdi
	callq	_Z11mem_ustringPcl
	movl	$.L.str.11, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	388(%rsp), %esi
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	cmpl	num_devices(%rip), %ebp
	jl	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	addq	$1552, %rsp                     # imm = 0x610
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z17print_device_infov, .Lfunc_end2-_Z17print_device_infov
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__char_addPcS_ # -- Begin function _Z23__device_stub__char_addPcS_
	.type	_Z23__device_stub__char_addPcS_,@function
_Z23__device_stub__char_addPcS_:        # @_Z23__device_stub__char_addPcS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z8char_addPcS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z23__device_stub__char_addPcS_, .Lfunc_end3-_Z23__device_stub__char_addPcS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z15run_device_testv            # -- Begin function _Z15run_device_testv
	.type	_Z15run_device_testv,@function
_Z15run_device_testv:                   # @_Z15run_device_testv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$1496, %rsp                     # imm = 0x5D8
	.cfi_def_cfa_offset 1552
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$0, num_devices(%rip)
	jle	.LBB4_5
# %bb.1:                                # %.lr.ph.preheader
	movabsq	$4294967297, %rax               # imm = 0x100000001
	leaq	12(%rax), %r12
	leaq	24(%rsp), %r13
	movl	$.L.str.15, %ebx
	xorl	%ebp, %ebp
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebp, %edi
	callq	hipSetDevice
	movl	$13, %esi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	$13, %esi
	leaq	8(%rsp), %rdi
	callq	hipMalloc
	movl	$13, %edi
	movl	$1, %esi
	callq	calloc
	movq	%rax, %r14
	movl	$13, %edi
	movl	$1, %esi
	callq	calloc
	movq	%rax, %r15
	movabsq	$8031924123371070792, %rax      # imm = 0x6F77206F6C6C6548
	movq	%rax, (%r15)
	movabsq	$9399091170604832, %rax         # imm = 0x21646C726F7720
	movq	%rax, 5(%r15)
	movq	8(%rsp), %rdi
	movl	$13, %edx
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	callq	_Z23__device_stub__char_addPcS_
.LBB4_4:                                #   in Loop: Header=BB4_2 Depth=1
	callq	hipPeekAtLastError
	movl	$.L.str.14, %esi
	movl	%eax, %edi
	movl	$137, %edx
	callq	_Z11cuda_assert10hipError_tPKci
	callq	hipDeviceSynchronize
	movl	$.L.str.14, %esi
	movl	%eax, %edi
	movl	$138, %edx
	callq	_Z11cuda_assert10hipError_tPKci
	movq	16(%rsp), %rsi
	movl	$13, %edx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	strcmp
	testl	%eax, %eax
	movl	$.L.str.16, %edi
	cmoveq	%rbx, %rdi
	movl	%ebp, %esi
	movq	%r13, %rdx
	xorl	%eax, %eax
	callq	printf
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	incl	%ebp
	cmpl	num_devices(%rip), %ebp
	jl	.LBB4_2
.LBB4_5:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	addq	$1496, %rsp                     # imm = 0x5D8
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z15run_device_testv, .Lfunc_end4-_Z15run_device_testv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$num_devices, %edi
	callq	hipGetDeviceCount
	movl	$.L.str.14, %esi
	movl	%eax, %edi
	movl	$160, %edx
	callq	_Z11cuda_assert10hipError_tPKci
	cmpl	$0, num_devices(%rip)
	jle	.LBB5_2
# %bb.1:
	callq	_Z17print_device_infov
	callq	_Z15run_device_testv
	jmp	.LBB5_3
.LBB5_2:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB5_3:
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8char_addPcS_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	num_devices,@object             # @num_devices
	.bss
	.globl	num_devices
	.p2align	2, 0x0
num_devices:
	.long	0                               # 0x0
	.size	num_devices, 4

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"[ERROR] Error code: %d Message: %s %s %d\n"
	.size	.L.str, 42

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%.2lf GB"
	.size	.L.str.1, 9

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%.2lf MB"
	.size	.L.str.2, 9

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%.2lf KB"
	.size	.L.str.3, 9

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%lf Bytes"
	.size	.L.str.4, 10

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"    Compute capability:      %d.%d\n"
	.size	.L.str.6, 36

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"    Total number of threads: %d\n"
	.size	.L.str.7, 33

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"    Global memory size:      %s\n"
	.size	.L.str.8, 33

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"    Shared memory size:      %s\n"
	.size	.L.str.9, 33

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"    Constant memory size:    %s\n"
	.size	.L.str.10, 33

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"    Total free memory:       %s\n"
	.size	.L.str.11, 33

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"    Warp size:               %d\n"
	.size	.L.str.12, 33

	.type	_Z8char_addPcS_,@object         # @_Z8char_addPcS_
	.section	.rodata,"a",@progbits
	.globl	_Z8char_addPcS_
	.p2align	3, 0x0
_Z8char_addPcS_:
	.quad	_Z23__device_stub__char_addPcS_
	.size	_Z8char_addPcS_, 8

	.type	.L__const._Z15run_device_testv.string,@object # @__const._Z15run_device_testv.string
	.p2align	4, 0x0
.L__const._Z15run_device_testv.string:
	.asciz	"Hello world!\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.size	.L__const._Z15run_device_testv.string, 256

	.type	.L.str.14,@object               # @.str.14
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.14:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/fredaas/synthbench/master/cuda-test/main.hip"
	.size	.L.str.14, 107

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"[PASSED TEST] Device %d: %s\n"
	.size	.L.str.15, 29

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"[FAILED TEST] Device %d: %s\n"
	.size	.L.str.16, 29

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8char_addPcS_"
	.size	.L__unnamed_1, 16

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.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	"[ERROR] No CUDA devices found!"
	.size	.Lstr, 31

	.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 _Z23__device_stub__char_addPcS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym num_devices
	.addrsig_sym _Z8char_addPcS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8char_addPcS_         ; -- Begin function _Z8char_addPcS_
	.globl	_Z8char_addPcS_
	.p2align	8
	.type	_Z8char_addPcS_,@function
_Z8char_addPcS_:                        ; @_Z8char_addPcS_
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	global_load_u8 v1, v0, s[2:3]
	s_waitcnt vmcnt(0)
	global_store_b8 v0, v1, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8char_addPcS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 2
		.amdhsa_next_free_sgpr 4
		.amdhsa_reserve_vcc 0
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z8char_addPcS_, .Lfunc_end0-_Z8char_addPcS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 44
; NumSgprs: 4
; NumVgprs: 2
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 4
; NumVGPRsForWavesPerEU: 2
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8char_addPcS_
    .private_segment_fixed_size: 0
    .sgpr_count:     4
    .sgpr_spill_count: 0
    .symbol:         _Z8char_addPcS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     2
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
