/**
 *  @file   cuda.cu
 *  @author Damian Smela <damian.a.smela@gmail.com>
 *  @date   10.02.2019
 *  @brief  CUDA example - finds all the primes in the large list of positive 
 *          integers.
 */

/********************************* INCLUDES ***********************************/

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

/********************************* DEFINES ************************************/

#define FILE_LINE_BUFF_SIZE (128U)
#define TMP_STR_BUFF_SIZE   (FILE_LINE_BUFF_SIZE)
#define LIST_FILENAME       "prime_list.txt"
#define NUM_OF_THREADS      (4U)

#define NUM_OF_CUDA_BLOCKS  (64U)
#define NUM_OF_CUDA_THREADS (128U)

/***************************** STATIC FUNCTIONS *******************************/

/* Converts ASCII char to corresponding number */
static int ascii_to_num(char ascii_char)
{
    return ((int) ascii_char) - 48;
}


/* Checks if given string is a integer number */
static bool is_number(char num_str[])
{
    char *str_ptr = &num_str[0];

    while(*str_ptr != '\0')
    {
     	if (ascii_to_num(*str_ptr) < 0 || ascii_to_num(*str_ptr) > 9)
        {
            return false;
        }
	    str_ptr++;
    }
    return true;
}


/* Returns the next positive integer from list file */
static int get_next_num_from_file(FILE      *file_ptr, 
                                  char      *line_buff, 
                                  size_t    *line_buff_size)
{
    int num_of_line_chars_tmp;

    memset(line_buff, 0, *line_buff_size);
    num_of_line_chars_tmp = (int) getline(&line_buff, line_buff_size, file_ptr);
    line_buff[num_of_line_chars_tmp - 1] = '\0';                                /* Erase '\n' char from string*/

    if (!is_number(line_buff))
    {
     	return -1;
    }
    else
    {
     	return atoi(line_buff);
    }
}


/* Resolve number of CUDA blocks and threads to cover all the remaining ints
 * to process */
static void resolve_cuda_threads(const int  ints_remaining,
                                 int        *num_of_cuda_blocks,
                                 int        *num_of_cuda_threads)
{
    /* Change the defaults only if there is lower number of data to process
     * than threads in a block */
    if (ints_remaining < NUM_OF_CUDA_BLOCKS * NUM_OF_CUDA_THREADS)
    {
        /* Load the defaults */
        *num_of_cuda_blocks = NUM_OF_CUDA_BLOCKS;
        *num_of_cuda_threads = NUM_OF_CUDA_THREADS;

        /* Check if the next iteration can be run in one-shot */
        for (int i = *num_of_cuda_threads; i > 0; i--)
        {
            if (ints_remaining % i == 0)
            {
                /* If there is enough blocks */
                if (ints_remaining / i < NUM_OF_CUDA_BLOCKS)
                {
                    /* The last iteration can be run in a one shot */
                    *num_of_cuda_blocks = ints_remaining / i;
                    *num_of_cuda_threads = i;
                    return;
                }
            }
        }

        /* The code reaches here if there is no way to run the code in
         * a one-shot */
        
        /* Calculate how many full blocks can run the next iteration 
         * and modify the defaults for the next iteration */
        *num_of_cuda_blocks = ints_remaining / NUM_OF_CUDA_THREADS;
    }
}                                                    

/******************************* CUDA KERNELS *********************************/

__global__ void is_prime_kernel(int *int_list)
{
    /* Get the unique thread index */
    int index = threadIdx.x + blockIdx.x * blockDim.x;

    /* Check if the integer of this index is prime */
    for (int i = 2; i < *(int_list + index); i++)
    {
        if (*(int_list + index) % i == 0)
        {
            /* If it's not a prime then change its value to -1 
             * so it wont be written to the file */
            *(int_list + index) = -1;
            break;
        }
    }
}

/*********************************** MAIN *************************************/

int main(int argc, char **argv)
{
    FILE *file_load_ptr = NULL;                                                 /* File pointer for loaded file */
    FILE *file_gen_ptr = NULL;                                                  /* File pointer for generated file */
    char *filename;                                                             /* Pointer to the string containing file name */
    char *line_buff;                                                            /* Buffer storing temp line of a file */
    size_t buff_size = FILE_LINE_BUFF_SIZE;                                     /* Size of a line buffer (can be realloc()-ed by the getline() func) */
    int num_of_line_chars_tmp;                                                  /* Var storing temp num of chars in the line */
    char str_buff_tmp[TMP_STR_BUFF_SIZE];                                       /* String buffer for temp actions */
    int num_of_ints;                                                            /* Number of integers to analyze */

    int num_of_cuda_blocks = NUM_OF_CUDA_BLOCKS;                                /* Number of cuda blocks */
    int num_of_cuda_threads = NUM_OF_CUDA_THREADS;                              /* Number of cuda threads */                     

    int prime_cnt = 0;                                                          /* Number of primes found */

    float time;                                                                 /* Variables used for measuring time */
    cudaEvent_t start, stop;                                                    /* - || - */

    printf("-------------------------CUDA Example-------------------------\n");
    printf("Finds all the primes in the large list of positive integers\n\n");

    /* Check if there is exactly one argument given */
    if (argc != 2)
    {
     	printf("Program needs exactly one argument - filename of the list " 
               "containing positive integer numbers!\n");
        return 1;
    }

    filename = argv[1];

    /* Open the ./"filename" file with read permission */
    file_load_ptr = fopen(filename, "r");
    if (file_load_ptr == NULL)
    {
     	printf("Couldn't open \"%s\" file\n", filename);
        return 2;
    }

    /* Allocate buffers for string parsing operations */
    line_buff = (char *) malloc(buff_size);
    memset(line_buff, 0, buff_size);
    memset(str_buff_tmp, 0, TMP_STR_BUFF_SIZE);

    /* Read the first line from file */
    num_of_line_chars_tmp = (int) getline(&line_buff, 
                                          &buff_size, 
                                          file_load_ptr);

    /* Check if the first line fits the "list_len=X" pattern */
    if ((num_of_line_chars_tmp < 11) || 
        (strncmp(line_buff, "list_len=", 9) != 0))
    {
        printf("Error in the first line - \"%s\" not matching" 
               "\"list_len=X\" pattern!\n", line_buff);

        return 3;
    }
    
    /* Check if the first line contains a number of integers */
    strncpy(str_buff_tmp, &line_buff[9], (size_t) num_of_line_chars_tmp - 10);
    if (!is_number(str_buff_tmp))
    {
     	printf("Error in the first line - \"%s\" is not a correct "
               "list length value\n", str_buff_tmp);

        return 4;
    }

    /* Store the number of integers in this variable */
    num_of_ints = atoi(str_buff_tmp);
    printf("Loading list of %d integer numbers...\n", num_of_ints);

    /* Allocate memory for all the integers */
    int *int_list = (int *) malloc(sizeof(int) * num_of_ints);

    /* Fill the memory with the integers from file */
    for (int i = 0; i < num_of_ints; i++)
    {
     	int_list[i] = get_next_num_from_file(file_load_ptr, 
                                             line_buff, 
                                             &buff_size);
    }

    /* Create a "LIST_FILENAME" file with write permission */
    file_gen_ptr  = fopen(LIST_FILENAME, "w");
    if (file_gen_ptr == NULL)
    {
     	printf("Couldn't open/create \"%s\" file\n", LIST_FILENAME);
        return 5;
    }

    /************** CUDA **************/

    /* Pointer to the current slice of the list */
    int *host_int_list_ptr = &int_list[0];

    /* Pointer to the space for device copy of the list */
    int *cuda_int_list;

    /* Remaining ints to process */    
    int ints_remaining = num_of_ints;

    /* Start timer */
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventRecord(start, 0);

    /* Allocate the space for device copy of the list-slice */
    cudaMalloc((void **)&cuda_int_list, 
               num_of_cuda_blocks * num_of_cuda_threads * sizeof(int));

    /* As long as the number of remaining ints is equal or greater than the 
     * total number of parallel instances use all of them to compute */
    while (ints_remaining > 0)
    {
        /* Resolve the number of blocks and threads that will be used */
        resolve_cuda_threads(ints_remaining,
                             &num_of_cuda_blocks,
                             &num_of_cuda_threads);

        /* Copy the slice of the list to the device */
        cudaMemcpy(cuda_int_list,
                   host_int_list_ptr,
                   num_of_cuda_blocks * num_of_cuda_threads * sizeof(int),
                   cudaMemcpyHostToDevice);
                   
        /* Run the kernel on all threads */
        is_prime_kernel<<<num_of_cuda_blocks, 
                          num_of_cuda_threads>>>(cuda_int_list);

        /* Copy the results back to the host */
        cudaMemcpy(host_int_list_ptr,
                   cuda_int_list,
                   num_of_cuda_blocks * num_of_cuda_threads * sizeof(int),
                   cudaMemcpyDeviceToHost);

        /* Update the host list pointer */
        host_int_list_ptr += num_of_cuda_blocks * num_of_cuda_threads;

        /* Update the number of remaining ints */
        ints_remaining -= (num_of_cuda_blocks * num_of_cuda_threads);
    }

    /* Free the device's memory */
    cudaFree(cuda_int_list);

    /* Write data to the file */
    for (int i = 0; i < num_of_ints; i++)
    {
        if (int_list[i] != -1)
        {
            prime_cnt++;
            fprintf(file_gen_ptr, "%d\n", int_list[i]);
        }
    }

    /* Put the number of primes int the first line of generated file */
    rewind(file_gen_ptr);
    fprintf(file_gen_ptr, "primes_found=%d(open-mp)\n", prime_cnt);

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&time, start, stop);
    printf("Elapsed: %f ms\n", time);
    printf("%d primes found...\n\r", prime_cnt);

    /**********************************/    

    /* Close the files and free the memory */    
    if (fclose(file_load_ptr) != 0)
    {
     	printf("Couldn't close \"%s\" file\n", filename);
        return 6;
    }

    if (fclose(file_gen_ptr) != 0)
    {
     	printf("Couldn't close \"%s\" file\n", LIST_FILENAME);
        return 7;
    }
    
    free(line_buff);
    free(int_list);

    printf("Done...\n");
    return 0;
}

/************************************ EOF *************************************/

	.file	"tmpxft_0037e628_00000000-6_cuda.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
	.globl	_Z35__device_stub__Z15is_prime_kernelPiPi
	.type	_Z35__device_stub__Z15is_prime_kernelPiPi, @function
_Z35__device_stub__Z15is_prime_kernelPiPi:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z15is_prime_kernelPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L2:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z35__device_stub__Z15is_prime_kernelPiPi, .-_Z35__device_stub__Z15is_prime_kernelPiPi
	.globl	_Z15is_prime_kernelPi
	.type	_Z15is_prime_kernelPi, @function
_Z15is_prime_kernelPi:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z15is_prime_kernelPiPi
	.cfi_endproc
.LFE2057:
	.size	_Z15is_prime_kernelPi, .-_Z15is_prime_kernelPi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"-------------------------CUDA Example-------------------------\n"
.LC1:
	.string	"Finds all the primes in the large list of positive integers\n\n"
.LC2:
	.string	"Program needs exactly one argument - filename of the list containing positive integer numbers!\n"
.LC3:
	.string	"r"
.LC4:
	.string	"Couldn't open \"%s\" file\n"
.LC5:
	.string	"list_len="
.LC6:
	.string	"Error in the first line - \"%s\" not matching\"list_len=X\" pattern!\n"
.LC7:
	.string	"w"
.LC8:
	.string	"prime_list.txt"
.LC9:
	.string	"Couldn't open/create \"%s\" file\n"
.LC10:
	.string	"%d\n"
.LC11:
	.string	"primes_found=%d(open-mp)\n"
.LC12:
	.string	"Elapsed: %f ms\n"
.LC13:
	.string	"%d primes found...\n\r"
.LC14:
	.string	"Couldn't close \"%s\" file\n"
.LC15:
	.string	"Done...\n"
.LC16:
	.string	"Error in the first line - \"%s\" is not a correct list length value\n"
.LC17:
	.string	"Loading list of %d integer numbers...\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.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
	movq	%rsi, %rbp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	movl	$2, %edi
	subq	$264, %rsp
	.cfi_def_cfa_offset 320
	movq	%fs:40, %rax
	movq	%rax, 248(%rsp)
	xorl	%eax, %eax
	movq	$128, 56(%rsp)
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	cmpl	$2, %ebx
	je	.L9
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	$1, %ebx
	call	__printf_chk@PLT
	jmp	.L10
.L9:
	movq	8(%rbp), %rax
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	fopen@PLT
	movq	%rax, 8(%rsp)
	testq	%rax, %rax
	jne	.L11
	movq	32(%rsp), %rdx
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L10
.L11:
	movq	56(%rsp), %rbx
	leaq	120(%rsp), %r12
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rcx
	movq	%rbx, %rdx
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, 48(%rsp)
	leaq	56(%rsp), %rbx
	call	__memset_chk@PLT
	xorl	%eax, %eax
	movq	8(%rsp), %rdx
	movq	%r12, %rdi
	movl	$32, %ecx
	movq	%rbx, %rsi
	rep stosl
	leaq	48(%rsp), %rdi
	call	getline@PLT
	movq	48(%rsp), %r13
	cmpl	$10, %eax
	movq	%rax, %r14
	jle	.L12
	movl	$9, %edx
	leaq	.LC5(%rip), %rsi
	movq	%r13, %rdi
	call	strncmp@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L13
.L12:
	movq	%r13, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	$3, %ebx
	leaq	.LC6(%rip), %rsi
	call	__printf_chk@PLT
	jmp	.L10
.L13:
	movslq	%r14d, %rdx
	leaq	9(%r13), %rsi
	movl	$128, %ecx
	movq	%r12, %rdi
	subq	$10, %rdx
	call	__strncpy_chk@PLT
	movq	%r12, %rdx
.L14:
	movb	(%rdx), %al
	testb	%al, %al
	je	.L47
	subl	$48, %eax
	cmpb	$9, %al
	ja	.L15
	incq	%rdx
	jmp	.L14
.L48:
	leaq	.LC8(%rip), %rbx
	leaq	.LC7(%rip), %rsi
	movq	%rbx, %rdi
	call	fopen@PLT
	movq	%rax, (%rsp)
	testq	%rax, %rax
	jne	.L23
	movq	%rbx, %rdx
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movl	$5, %ebx
	call	__printf_chk@PLT
.L10:
	movq	248(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L15:
	movq	%r12, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	$4, %ebx
	leaq	.LC16(%rip), %rsi
	call	__printf_chk@PLT
	jmp	.L10
.L47:
	movq	%r12, %rdi
	xorl	%r13d, %r13d
	xorl	%r12d, %r12d
	call	atoi@PLT
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	movl	%eax, 40(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	40(%rsp), %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r14
.L37:
	cmpl	%r13d, 40(%rsp)
	jle	.L48
	movq	48(%rsp), %rdx
	movq	56(%rsp), %rcx
	movl	%r12d, %eax
	movq	%rbx, %rsi
	movq	%rdx, %rdi
	movq	%rdx, 104(%rsp)
	movq	8(%rsp), %rdx
	rep stosb
	leaq	104(%rsp), %rdi
	call	getline@PLT
	movq	104(%rsp), %rdx
	cltq
	movb	$0, -1(%rdx,%rax)
	movq	104(%rsp), %rdi
	movq	%rdi, %rdx
.L18:
	movb	(%rdx), %al
	testb	%al, %al
	je	.L49
	subl	$48, %eax
	cmpb	$9, %al
	ja	.L39
	incq	%rdx
	jmp	.L18
.L39:
	orl	$-1, %eax
.L19:
	movl	%eax, (%r14,%r13,4)
	incq	%r13
	jmp	.L37
.L23:
	leaq	64(%rsp), %rdi
	movl	$128, %ebx
	movl	$64, %r13d
	movabsq	$4294967297, %r15
	call	cudaEventCreate@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	leaq	80(%rsp), %rdi
	movl	$32768, %esi
	call	cudaMalloc@PLT
	movq	%r14, 24(%rsp)
	movl	40(%rsp), %r12d
.L24:
	testl	%r12d, %r12d
	jle	.L50
	cmpl	$8191, %r12d
	ja	.L25
	movl	$128, %ebx
.L29:
	movl	%r12d, %eax
	cltd
	idivl	%ebx
	testl	%edx, %edx
	je	.L26
	decl	%ebx
	jmp	.L29
.L26:
	movl	%eax, %r13d
	cmpl	$63, %eax
	jle	.L25
	decl	%ebx
	jne	.L29
	movl	%r12d, %r13d
	movl	$128, %ebx
	shrl	$7, %r13d
.L25:
	movl	%r13d, %eax
	movq	24(%rsp), %rsi
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	imull	%ebx, %eax
	movl	%eax, 44(%rsp)
	cltq
	salq	$2, %rax
	movq	%rax, %rdx
	movq	%rax, 16(%rsp)
	call	cudaMemcpy@PLT
	movq	%r15, 108(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, 96(%rsp)
	movl	112(%rsp), %ecx
	movl	%ebx, 104(%rsp)
	movl	100(%rsp), %esi
	movl	%r13d, 92(%rsp)
	movq	104(%rsp), %rdx
	movq	92(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	movq	80(%rsp), %rdi
	call	_Z35__device_stub__Z15is_prime_kernelPiPi
.L30:
	movq	16(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movq	24(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	44(%rsp), %eax
	movq	16(%rsp), %rcx
	addq	%rcx, 24(%rsp)
	subl	%eax, %r12d
	jmp	.L24
.L50:
	movq	80(%rsp), %rdi
	xorl	%r12d, %r12d
	leaq	.LC10(%rip), %rbx
	call	cudaFree@PLT
.L32:
	cmpl	%r12d, 40(%rsp)
	jle	.L51
	movl	(%r14,%r12,4), %ecx
	cmpl	$-1, %ecx
	je	.L33
	movq	(%rsp), %rdi
	movq	%rbx, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	incl	%ebp
	call	__fprintf_chk@PLT
.L33:
	incq	%r12
	jmp	.L32
.L51:
	movq	(%rsp), %rdi
	call	rewind@PLT
	movq	(%rsp), %rdi
	movl	%ebp, %ecx
	movl	$2, %esi
	leaq	.LC11(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	leaq	104(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	104(%rsp), %xmm0
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movl	%ebp, %edx
	movl	$2, %edi
	leaq	.LC13(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	fclose@PLT
	testl	%eax, %eax
	je	.L35
	movq	32(%rsp), %rdx
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	$6, %ebx
	call	__printf_chk@PLT
	jmp	.L10
.L35:
	movq	(%rsp), %rdi
	call	fclose@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L36
	leaq	.LC8(%rip), %rdx
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$7, %ebx
	jmp	.L10
.L36:
	movq	48(%rsp), %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
.L49:
	call	atoi@PLT
	jmp	.L19
.L38:
	addq	$264, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebx, %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
	ret
	.cfi_endproc
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z15is_prime_kernelPi"
	.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	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z15is_prime_kernelPi(%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
	.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:

/**
 *  @file   cuda.cu
 *  @author Damian Smela <damian.a.smela@gmail.com>
 *  @date   10.02.2019
 *  @brief  CUDA example - finds all the primes in the large list of positive 
 *          integers.
 */

/********************************* INCLUDES ***********************************/

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <memory.h>

/********************************* DEFINES ************************************/

#define FILE_LINE_BUFF_SIZE (128U)
#define TMP_STR_BUFF_SIZE   (FILE_LINE_BUFF_SIZE)
#define LIST_FILENAME       "prime_list.txt"
#define NUM_OF_THREADS      (4U)

#define NUM_OF_CUDA_BLOCKS  (64U)
#define NUM_OF_CUDA_THREADS (128U)

/***************************** STATIC FUNCTIONS *******************************/

/* Converts ASCII char to corresponding number */
static int ascii_to_num(char ascii_char)
{
    return ((int) ascii_char) - 48;
}


/* Checks if given string is a integer number */
static bool is_number(char num_str[])
{
    char *str_ptr = &num_str[0];

    while(*str_ptr != '\0')
    {
     	if (ascii_to_num(*str_ptr) < 0 || ascii_to_num(*str_ptr) > 9)
        {
            return false;
        }
	    str_ptr++;
    }
    return true;
}


/* Returns the next positive integer from list file */
static int get_next_num_from_file(FILE      *file_ptr, 
                                  char      *line_buff, 
                                  size_t    *line_buff_size)
{
    int num_of_line_chars_tmp;

    memset(line_buff, 0, *line_buff_size);
    num_of_line_chars_tmp = (int) getline(&line_buff, line_buff_size, file_ptr);
    line_buff[num_of_line_chars_tmp - 1] = '\0';                                /* Erase '\n' char from string*/

    if (!is_number(line_buff))
    {
     	return -1;
    }
    else
    {
     	return atoi(line_buff);
    }
}


/* Resolve number of CUDA blocks and threads to cover all the remaining ints
 * to process */
static void resolve_cuda_threads(const int  ints_remaining,
                                 int        *num_of_cuda_blocks,
                                 int        *num_of_cuda_threads)
{
    /* Change the defaults only if there is lower number of data to process
     * than threads in a block */
    if (ints_remaining < NUM_OF_CUDA_BLOCKS * NUM_OF_CUDA_THREADS)
    {
        /* Load the defaults */
        *num_of_cuda_blocks = NUM_OF_CUDA_BLOCKS;
        *num_of_cuda_threads = NUM_OF_CUDA_THREADS;

        /* Check if the next iteration can be run in one-shot */
        for (int i = *num_of_cuda_threads; i > 0; i--)
        {
            if (ints_remaining % i == 0)
            {
                /* If there is enough blocks */
                if (ints_remaining / i < NUM_OF_CUDA_BLOCKS)
                {
                    /* The last iteration can be run in a one shot */
                    *num_of_cuda_blocks = ints_remaining / i;
                    *num_of_cuda_threads = i;
                    return;
                }
            }
        }

        /* The code reaches here if there is no way to run the code in
         * a one-shot */
        
        /* Calculate how many full blocks can run the next iteration 
         * and modify the defaults for the next iteration */
        *num_of_cuda_blocks = ints_remaining / NUM_OF_CUDA_THREADS;
    }
}                                                    

/******************************* CUDA KERNELS *********************************/

__global__ void is_prime_kernel(int *int_list)
{
    /* Get the unique thread index */
    int index = threadIdx.x + blockIdx.x * blockDim.x;

    /* Check if the integer of this index is prime */
    for (int i = 2; i < *(int_list + index); i++)
    {
        if (*(int_list + index) % i == 0)
        {
            /* If it's not a prime then change its value to -1 
             * so it wont be written to the file */
            *(int_list + index) = -1;
            break;
        }
    }
}

/*********************************** MAIN *************************************/

int main(int argc, char **argv)
{
    FILE *file_load_ptr = NULL;                                                 /* File pointer for loaded file */
    FILE *file_gen_ptr = NULL;                                                  /* File pointer for generated file */
    char *filename;                                                             /* Pointer to the string containing file name */
    char *line_buff;                                                            /* Buffer storing temp line of a file */
    size_t buff_size = FILE_LINE_BUFF_SIZE;                                     /* Size of a line buffer (can be realloc()-ed by the getline() func) */
    int num_of_line_chars_tmp;                                                  /* Var storing temp num of chars in the line */
    char str_buff_tmp[TMP_STR_BUFF_SIZE];                                       /* String buffer for temp actions */
    int num_of_ints;                                                            /* Number of integers to analyze */

    int num_of_cuda_blocks = NUM_OF_CUDA_BLOCKS;                                /* Number of cuda blocks */
    int num_of_cuda_threads = NUM_OF_CUDA_THREADS;                              /* Number of cuda threads */                     

    int prime_cnt = 0;                                                          /* Number of primes found */

    float time;                                                                 /* Variables used for measuring time */
    hipEvent_t start, stop;                                                    /* - || - */

    printf("-------------------------CUDA Example-------------------------\n");
    printf("Finds all the primes in the large list of positive integers\n\n");

    /* Check if there is exactly one argument given */
    if (argc != 2)
    {
     	printf("Program needs exactly one argument - filename of the list " 
               "containing positive integer numbers!\n");
        return 1;
    }

    filename = argv[1];

    /* Open the ./"filename" file with read permission */
    file_load_ptr = fopen(filename, "r");
    if (file_load_ptr == NULL)
    {
     	printf("Couldn't open \"%s\" file\n", filename);
        return 2;
    }

    /* Allocate buffers for string parsing operations */
    line_buff = (char *) malloc(buff_size);
    memset(line_buff, 0, buff_size);
    memset(str_buff_tmp, 0, TMP_STR_BUFF_SIZE);

    /* Read the first line from file */
    num_of_line_chars_tmp = (int) getline(&line_buff, 
                                          &buff_size, 
                                          file_load_ptr);

    /* Check if the first line fits the "list_len=X" pattern */
    if ((num_of_line_chars_tmp < 11) || 
        (strncmp(line_buff, "list_len=", 9) != 0))
    {
        printf("Error in the first line - \"%s\" not matching" 
               "\"list_len=X\" pattern!\n", line_buff);

        return 3;
    }
    
    /* Check if the first line contains a number of integers */
    strncpy(str_buff_tmp, &line_buff[9], (size_t) num_of_line_chars_tmp - 10);
    if (!is_number(str_buff_tmp))
    {
     	printf("Error in the first line - \"%s\" is not a correct "
               "list length value\n", str_buff_tmp);

        return 4;
    }

    /* Store the number of integers in this variable */
    num_of_ints = atoi(str_buff_tmp);
    printf("Loading list of %d integer numbers...\n", num_of_ints);

    /* Allocate memory for all the integers */
    int *int_list = (int *) malloc(sizeof(int) * num_of_ints);

    /* Fill the memory with the integers from file */
    for (int i = 0; i < num_of_ints; i++)
    {
     	int_list[i] = get_next_num_from_file(file_load_ptr, 
                                             line_buff, 
                                             &buff_size);
    }

    /* Create a "LIST_FILENAME" file with write permission */
    file_gen_ptr  = fopen(LIST_FILENAME, "w");
    if (file_gen_ptr == NULL)
    {
     	printf("Couldn't open/create \"%s\" file\n", LIST_FILENAME);
        return 5;
    }

    /************** CUDA **************/

    /* Pointer to the current slice of the list */
    int *host_int_list_ptr = &int_list[0];

    /* Pointer to the space for device copy of the list */
    int *cuda_int_list;

    /* Remaining ints to process */    
    int ints_remaining = num_of_ints;

    /* Start timer */
    hipEventCreate(&start);
    hipEventCreate(&stop);
    hipEventRecord(start, 0);

    /* Allocate the space for device copy of the list-slice */
    hipMalloc((void **)&cuda_int_list, 
               num_of_cuda_blocks * num_of_cuda_threads * sizeof(int));

    /* As long as the number of remaining ints is equal or greater than the 
     * total number of parallel instances use all of them to compute */
    while (ints_remaining > 0)
    {
        /* Resolve the number of blocks and threads that will be used */
        resolve_cuda_threads(ints_remaining,
                             &num_of_cuda_blocks,
                             &num_of_cuda_threads);

        /* Copy the slice of the list to the device */
        hipMemcpy(cuda_int_list,
                   host_int_list_ptr,
                   num_of_cuda_blocks * num_of_cuda_threads * sizeof(int),
                   hipMemcpyHostToDevice);
                   
        /* Run the kernel on all threads */
        is_prime_kernel<<<num_of_cuda_blocks, 
                          num_of_cuda_threads>>>(cuda_int_list);

        /* Copy the results back to the host */
        hipMemcpy(host_int_list_ptr,
                   cuda_int_list,
                   num_of_cuda_blocks * num_of_cuda_threads * sizeof(int),
                   hipMemcpyDeviceToHost);

        /* Update the host list pointer */
        host_int_list_ptr += num_of_cuda_blocks * num_of_cuda_threads;

        /* Update the number of remaining ints */
        ints_remaining -= (num_of_cuda_blocks * num_of_cuda_threads);
    }

    /* Free the device's memory */
    hipFree(cuda_int_list);

    /* Write data to the file */
    for (int i = 0; i < num_of_ints; i++)
    {
        if (int_list[i] != -1)
        {
            prime_cnt++;
            fprintf(file_gen_ptr, "%d\n", int_list[i]);
        }
    }

    /* Put the number of primes int the first line of generated file */
    rewind(file_gen_ptr);
    fprintf(file_gen_ptr, "primes_found=%d(open-mp)\n", prime_cnt);

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&time, start, stop);
    printf("Elapsed: %f ms\n", time);
    printf("%d primes found...\n\r", prime_cnt);

    /**********************************/    

    /* Close the files and free the memory */    
    if (fclose(file_load_ptr) != 0)
    {
     	printf("Couldn't close \"%s\" file\n", filename);
        return 6;
    }

    if (fclose(file_gen_ptr) != 0)
    {
     	printf("Couldn't close \"%s\" file\n", LIST_FILENAME);
        return 7;
    }
    
    free(line_buff);
    free(int_list);

    printf("Done...\n");
    return 0;
}

/************************************ EOF *************************************/

	.text
	.file	"cuda.hip"
	.globl	_Z30__device_stub__is_prime_kernelPi # -- Begin function _Z30__device_stub__is_prime_kernelPi
	.type	_Z30__device_stub__is_prime_kernelPi,@function
_Z30__device_stub__is_prime_kernelPi:   # @_Z30__device_stub__is_prime_kernelPi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.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)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z15is_prime_kernelPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end0:
	.size	_Z30__device_stub__is_prime_kernelPi, .Lfunc_end0-_Z30__device_stub__is_prime_kernelPi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.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	$232, %rsp
	.cfi_def_cfa_offset 288
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movq	$128, 48(%rsp)
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	cmpl	$2, %ebp
	jne	.LBB1_1
# %bb.2:
	movq	8(%rbx), %rbp
	movl	$.L.str.3, %esi
	movq	%rbp, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_3
# %bb.4:
	movq	%rax, %r14
	movl	$1, %edi
	movl	$128, %esi
	callq	calloc@PLT
	leaq	56(%rsp), %rbx
	movq	%rax, (%rbx)
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 96(%rsp)
	movaps	%xmm0, 112(%rsp)
	movaps	%xmm0, 128(%rsp)
	movaps	%xmm0, 144(%rsp)
	movaps	%xmm0, 160(%rsp)
	movaps	%xmm0, 176(%rsp)
	movaps	%xmm0, 192(%rsp)
	movaps	%xmm0, 208(%rsp)
	leaq	48(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	callq	getline
	movq	%rax, %r15
	movq	(%rbx), %rbx
	cmpl	$11, %r15d
	jl	.LBB1_6
# %bb.5:
	movl	$.L.str.5, %esi
	movl	$9, %edx
	movq	%rbx, %rdi
	callq	strncmp
	testl	%eax, %eax
	je	.LBB1_7
.LBB1_6:
	movl	$.L.str.6, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$3, %eax
	jmp	.LBB1_47
.LBB1_1:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$1, %eax
	jmp	.LBB1_47
.LBB1_3:
	movl	$.L.str.4, %edi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$2, %eax
.LBB1_47:
	addq	$232, %rsp
	.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
.LBB1_7:
	.cfi_def_cfa_offset 288
	addq	$9, %rbx
	movl	%r15d, %edx
	addq	$-10, %rdx
	leaq	96(%rsp), %r15
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	strncpy
	movb	(%r15), %cl
	testb	%cl, %cl
	je	.LBB1_13
# %bb.8:                                # %.lr.ph.i.preheader
	leaq	97(%rsp), %rax
.LBB1_10:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	cmpb	$48, %cl
	jl	.LBB1_12
# %bb.11:                               # %.lr.ph.i
                                        #   in Loop: Header=BB1_10 Depth=1
	movsbl	%cl, %ecx
	addl	$-48, %ecx
	cmpl	$10, %ecx
	jae	.LBB1_12
# %bb.9:                                #   in Loop: Header=BB1_10 Depth=1
	movb	(%rax), %cl
	incq	%rax
	testb	%cl, %cl
	jne	.LBB1_10
.LBB1_13:                               # %.loopexit
	leaq	96(%rsp), %rdi
	callq	atoi
	movl	%eax, %ebx
	movl	$.L.str.8, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movslq	%ebx, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	%ebx, 12(%rsp)                  # 4-byte Spill
	testl	%ebx, %ebx
	jle	.LBB1_22
# %bb.14:                               # %.lr.ph.preheader
	movl	12(%rsp), %ebx                  # 4-byte Reload
	xorl	%r13d, %r13d
	leaq	24(%rsp), %r15
	leaq	48(%rsp), %r12
.LBB1_15:                               # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_18 Depth 2
	movq	56(%rsp), %rdi
	movq	%rdi, 24(%rsp)
	movq	48(%rsp), %rdx
	xorl	%esi, %esi
	callq	memset@PLT
	movq	%r15, %rdi
	movq	%r12, %rsi
	movq	%r14, %rdx
	callq	getline
	movq	24(%rsp), %rcx
	decl	%eax
	cltq
	movb	$0, (%rcx,%rax)
	movq	24(%rsp), %rdi
	movb	(%rdi), %dl
	testb	%dl, %dl
	je	.LBB1_20
# %bb.16:                               # %.lr.ph.i.i.preheader
                                        #   in Loop: Header=BB1_15 Depth=1
	leaq	1(%rdi), %rcx
.LBB1_18:                               # %.lr.ph.i.i
                                        #   Parent Loop BB1_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$-1, %eax
	cmpb	$48, %dl
	jl	.LBB1_21
# %bb.19:                               # %.lr.ph.i.i
                                        #   in Loop: Header=BB1_18 Depth=2
	movsbl	%dl, %edx
	addl	$-48, %edx
	cmpl	$10, %edx
	jae	.LBB1_21
# %bb.17:                               #   in Loop: Header=BB1_18 Depth=2
	movb	(%rcx), %dl
	incq	%rcx
	testb	%dl, %dl
	jne	.LBB1_18
.LBB1_20:                               # %.loopexit.i
                                        #   in Loop: Header=BB1_15 Depth=1
	callq	atoi
.LBB1_21:                               # %_ZL22get_next_num_from_fileP8_IO_FILEPcPm.exit
                                        #   in Loop: Header=BB1_15 Depth=1
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movl	%eax, (%rcx,%r13,4)
	incq	%r13
	cmpq	%rbx, %r13
	jne	.LBB1_15
.LBB1_22:                               # %._crit_edge
	movl	$.L.str.9, %edi
	movl	$.L.str.10, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_23
# %bb.24:
	movq	%rax, %r13
	movq	%r14, 80(%rsp)                  # 8-byte Spill
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	16(%rsp), %rdi
	movl	$32768, %esi                    # imm = 0x8000
	callq	hipMalloc
	movl	12(%rsp), %r12d                 # 4-byte Reload
	testl	%r12d, %r12d
	jle	.LBB1_37
# %bb.25:                               # %.lr.ph86.preheader
	movq	%r13, 64(%rsp)                  # 8-byte Spill
	movq	%rbp, 72(%rsp)                  # 8-byte Spill
	movl	$128, %ebp
	movl	$64, %r13d
	movq	32(%rsp), %r15                  # 8-byte Reload
.LBB1_26:                               # %.lr.ph86
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_28 Depth 2
	cmpl	$8191, %r12d                    # imm = 0x1FFF
	ja	.LBB1_32
# %bb.27:                               # %.preheader.preheader
                                        #   in Loop: Header=BB1_26 Depth=1
	movl	$128, %ebp
.LBB1_28:                               # %.preheader
                                        #   Parent Loop BB1_26 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r12d, %eax
	xorl	%edx, %edx
	divl	%ebp
	testl	%edx, %edx
	jne	.LBB1_30
# %bb.29:                               # %.preheader
                                        #   in Loop: Header=BB1_28 Depth=2
	movl	%eax, %r13d
	cmpl	$64, %eax
	jb	.LBB1_32
.LBB1_30:                               #   in Loop: Header=BB1_28 Depth=2
	leal	-1(%rbp), %eax
	cmpl	$1, %ebp
	movl	%eax, %ebp
	ja	.LBB1_28
# %bb.31:                               #   in Loop: Header=BB1_26 Depth=1
	movl	%r12d, %r13d
	shrl	$7, %r13d
	movl	$128, %ebp
.LBB1_32:                               # %_ZL20resolve_cuda_threadsiPiS_.exit
                                        #   in Loop: Header=BB1_26 Depth=1
	movq	16(%rsp), %rdi
	movl	%r13d, %eax
	imull	%ebp, %eax
	movslq	%eax, %r14
	leaq	(,%r14,4), %rbx
	movq	%r15, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%r13d, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	movl	%ebp, %edx
	orq	%rax, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_34
# %bb.33:                               #   in Loop: Header=BB1_26 Depth=1
	movq	16(%rsp), %rdi
	callq	_Z30__device_stub__is_prime_kernelPi
.LBB1_34:                               #   in Loop: Header=BB1_26 Depth=1
	movq	16(%rsp), %rsi
	movq	%r15, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	(%r15,%r14,4), %r15
	subl	%r14d, %r12d
	jg	.LBB1_26
# %bb.35:                               # %._crit_edge87
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	12(%rsp), %eax                  # 4-byte Reload
	testl	%eax, %eax
	movq	72(%rsp), %rbp                  # 8-byte Reload
	movq	64(%rsp), %r13                  # 8-byte Reload
	jle	.LBB1_36
# %bb.40:                               # %.lr.ph91.preheader
	movl	%eax, %ebx
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.LBB1_41:                               # %.lr.ph91
                                        # =>This Inner Loop Header: Depth=1
	movq	32(%rsp), %rax                  # 8-byte Reload
	movl	(%rax,%r14,4), %edx
	cmpl	$-1, %edx
	je	.LBB1_43
# %bb.42:                               #   in Loop: Header=BB1_41 Depth=1
	incl	%r15d
	movl	$.L.str.12, %esi
	movq	%r13, %rdi
	xorl	%eax, %eax
	callq	fprintf
.LBB1_43:                               #   in Loop: Header=BB1_41 Depth=1
	incq	%r14
	cmpq	%r14, %rbx
	jne	.LBB1_41
	jmp	.LBB1_38
.LBB1_12:                               # %_ZL9is_numberPc.exit
	leaq	96(%rsp), %rsi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$4, %eax
	jmp	.LBB1_47
.LBB1_23:
	movl	$.L.str.11, %edi
	movl	$.L.str.9, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$5, %eax
	jmp	.LBB1_47
.LBB1_37:                               # %._crit_edge87.thread
	movq	16(%rsp), %rdi
	callq	hipFree
	jmp	.LBB1_38
.LBB1_36:
	xorl	%r15d, %r15d
.LBB1_38:                               # %._crit_edge92
	movq	%r13, %rdi
	callq	rewind
	movl	$.L.str.13, %esi
	movq	%r13, %rdi
	movl	%r15d, %edx
	xorl	%eax, %eax
	callq	fprintf
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	40(%rsp), %rdx
	leaq	92(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.14, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.15, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	80(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	testl	%eax, %eax
	je	.LBB1_44
# %bb.39:
	movl	$.L.str.16, %edi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$6, %eax
	jmp	.LBB1_47
.LBB1_44:
	movq	%r13, %rdi
	callq	fclose
	testl	%eax, %eax
	je	.LBB1_46
# %bb.45:
	movl	$.L.str.16, %edi
	movl	$.L.str.9, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$7, %eax
	jmp	.LBB1_47
.LBB1_46:
	movq	56(%rsp), %rdi
	callq	free
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	jmp	.LBB1_47
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15is_prime_kernelPi, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z15is_prime_kernelPi,@object   # @_Z15is_prime_kernelPi
	.section	.rodata,"a",@progbits
	.globl	_Z15is_prime_kernelPi
	.p2align	3, 0x0
_Z15is_prime_kernelPi:
	.quad	_Z30__device_stub__is_prime_kernelPi
	.size	_Z15is_prime_kernelPi, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"r"
	.size	.L.str.3, 2

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Couldn't open \"%s\" file\n"
	.size	.L.str.4, 25

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"list_len="
	.size	.L.str.5, 10

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error in the first line - \"%s\" not matching\"list_len=X\" pattern!\n"
	.size	.L.str.6, 66

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Error in the first line - \"%s\" is not a correct list length value\n"
	.size	.L.str.7, 67

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Loading list of %d integer numbers...\n"
	.size	.L.str.8, 39

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"prime_list.txt"
	.size	.L.str.9, 15

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"w"
	.size	.L.str.10, 2

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Couldn't open/create \"%s\" file\n"
	.size	.L.str.11, 32

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

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"primes_found=%d(open-mp)\n"
	.size	.L.str.13, 26

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Elapsed: %f ms\n"
	.size	.L.str.14, 16

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"%d primes found...\n\r"
	.size	.L.str.15, 21

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Couldn't close \"%s\" file\n"
	.size	.L.str.16, 26

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15is_prime_kernelPi"
	.size	.L__unnamed_1, 22

	.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	"-------------------------CUDA Example-------------------------"
	.size	.Lstr, 63

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Finds all the primes in the large list of positive integers\n"
	.size	.Lstr.1, 61

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Done..."
	.size	.Lstr.2, 8

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Program needs exactly one argument - filename of the list containing positive integer numbers!"
	.size	.Lstr.3, 95

	.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 _Z30__device_stub__is_prime_kernelPi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z15is_prime_kernelPi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15is_prime_kernelPi   ; -- Begin function _Z15is_prime_kernelPi
	.globl	_Z15is_prime_kernelPi
	.p2align	8
	.type	_Z15is_prime_kernelPi,@function
_Z15is_prime_kernelPi:                  ; @_Z15is_prime_kernelPi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_mov_b32 s0, 2
	s_mov_b32 s1, exec_lo
	global_load_b32 v2, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmpx_lt_i32_e32 2, v2
	s_cbranch_execz .LBB0_7
; %bb.1:                                ; %.lr.ph.preheader
	s_mov_b32 s1, 0
                                        ; implicit-def: $sgpr2
                                        ; implicit-def: $sgpr4
                                        ; implicit-def: $sgpr3
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_cvt_f32_u32_e32 v3, s0
	s_sub_i32 s5, 0, s0
	s_or_b32 s3, s3, exec_lo
	s_or_b32 s4, s4, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v3, v3
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v3, 0x4f7ffffe, v3
	v_cvt_u32_f32_e32 v3, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v4, s5, v3
	s_mov_b32 s5, exec_lo
	v_mul_hi_u32 v4, v3, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, v3, v4
	v_mul_hi_u32 v3, v2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, v3, s0
	v_sub_nc_u32_e32 v3, v2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v4, s0, v3
	v_cmp_le_u32_e32 vcc_lo, s0, v3
	v_cndmask_b32_e32 v3, v3, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v4, s0, v3
	v_cmp_le_u32_e32 vcc_lo, s0, v3
	v_cndmask_b32_e32 v3, v3, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ne_u32_e32 0, v3
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s0, s0, 1
	s_and_not1_b32 s4, s4, exec_lo
	v_cmp_eq_u32_e32 vcc_lo, s0, v2
	s_and_not1_b32 s3, s3, exec_lo
	s_and_b32 s6, vcc_lo, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s4, s4, s6
; %bb.4:                                ; %Flow13
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s5, exec_lo, s4
	s_or_b32 s1, s5, s1
	s_and_not1_b32 s2, s2, exec_lo
	s_and_b32 s5, s3, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s2, s2, s5
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_2
; %bb.5:                                ; %loop.exit.guard
	s_or_b32 exec_lo, exec_lo, s1
	s_and_saveexec_b32 s0, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s0, exec_lo, s0
	s_cbranch_execz .LBB0_7
; %bb.6:
	v_mov_b32_e32 v2, -1
	global_store_b32 v[0:1], v2, off
.LBB0_7:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15is_prime_kernelPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 5
		.amdhsa_next_free_sgpr 16
		.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	_Z15is_prime_kernelPi, .Lfunc_end0-_Z15is_prime_kernelPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 356
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15is_prime_kernelPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15is_prime_kernelPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
