# include <stdio.h>
# include <stdint.h>

# include "cuda_runtime.h"
# include "cuda_profiler_api.h"

#define ITERATIONS 2
#define DEBUG 1
#define MAX_SHARED_E 2048

#include <time.h>
#include <sys/time.h>
#define USECPSEC 1000000ULL

unsigned long long dtime_usec (unsigned long long start) {

  timeval tv;
  gettimeofday (&tv, 0);
  return ((tv.tv_sec * USECPSEC) + tv.tv_usec) - start;
}

//compile nvcc *.cu -o test

__global__ void init_device_array (unsigned int *, unsigned int, unsigned long long);
__global__ void global_latency (unsigned int *, unsigned long long , unsigned int, unsigned int *, unsigned long *);
unsigned int parametric_measure_global (unsigned long long , int, unsigned int);
void measure_global (unsigned int, unsigned int, unsigned int);

unsigned long long KB_TO_B (unsigned int x) {
    return (x * 1024LLU);
}
unsigned long long MB_TO_B (unsigned int x)  {
    return (x * 1024LLU * 1024LLU);
}

int main (int argc, char **argv) {

    if (argc < 5) {
        printf ("Usage: ./<executable>   from_mb   to_mb   stride_size_kb   device_no (0-1)\n");
        return 0;
    }

    /* Array size in mega bytes 1st argument. */
    unsigned int from_mb = (unsigned int) atof (argv[1]);

    /* Array size in mega bytes 2nd argument. */
    unsigned int to_mb = (unsigned int) atof (argv[2]);

    /* Stride size in kilo bytes 3rd argument. */
    unsigned int stride_size_kb = (unsigned int) atof (argv[3]);
    /* Set device number if there are many! */
    int device = atoi (argv[4]);

    cudaSetDevice (device);

    measure_global (from_mb, to_mb, stride_size_kb);

    cudaDeviceReset ();

    return 0;
}

void measure_global (unsigned int from_mb, unsigned int to_mb, unsigned int stride_size_kb) {

    unsigned int stride, stride_b, entries;
    unsigned long long N, array_size_b, elements;

    // stride in element, change here if needed!
    stride_b = KB_TO_B (stride_size_kb);
    // if argument is non zero take that, else 1 element stride
    stride_b = (stride_b > 0) ? stride_b : sizeof (unsigned int);
    stride = stride_b / sizeof (unsigned int);

    unsigned int d_time = 0;
    unsigned long long difft;
    for (int i = from_mb; i <= to_mb; i += 2) {
        // chage below for different array size creation!
        array_size_b = MB_TO_B (i);
        elements = array_size_b / sizeof (unsigned int);
        entries = array_size_b / stride_b;
        N = elements;

        /* Why 2 * MAX_SHARED_E, well there are 2 shared arrays in the kernel! */
        if (ITERATIONS * entries > (2 * MAX_SHARED_E)) {
            printf ("Hey, shared_memory is limited, either reduce ITERATIONS or increase stride!!");
            return;
        }

        printf ("\n=====%llu MB array, warm TLB, read %d elements====\n", array_size_b / MB_TO_B(1), entries);
        printf ("Iterations = %d, Stride = %u element, %u KB\n", ITERATIONS, stride, stride_size_kb);
        difft = dtime_usec (0);

        d_time = parametric_measure_global (N, stride, entries);

        difft = dtime_usec (difft);
        printf ("(H) Kernel Duration: %lf\n", (difft / ITERATIONS) / (float) USECPSEC);
        printf ("(D) Kernel Duration: %u\n", d_time);

        printf("\n===============================================\n\n");
    }
}

unsigned int parametric_measure_global (unsigned long long N, int stride, unsigned int entries) {

    cudaDeviceReset ();
    cudaError_t error_id;
    int i;

    unsigned int *h_a;
    /* allocate arrays on CPU, pinned host memory */
    cudaHostAlloc ((void **) &h_a, sizeof(unsigned int) * (N + 2), cudaHostAllocMapped);

    /* initialize array elements on CPU with pointers into d_a. */
    for (i = 0; i < N; i++) {        
        // Original:    
        h_a[i] = (i + stride) % N;
    }

    h_a[N] = 0;
    h_a[N + 1] = 0;

    unsigned int *d_a;
    /* allocate arrays on GPU */
    error_id = cudaHostGetDevicePointer ((void **) &d_a, h_a, 0);
    if (error_id != cudaSuccess) {
        printf ("Error 1.0 is %s\n", cudaGetErrorString (error_id));
    }

    unsigned int data_entries = ITERATIONS * entries;

    unsigned int *duration;
    unsigned int *h_duration;
    cudaHostAlloc ((void **) &h_duration, sizeof(unsigned int) * data_entries, cudaHostAllocMapped);
    error_id = cudaHostGetDevicePointer ((void **) &duration, h_duration, 0);;
    if (error_id != cudaSuccess) {
        printf ("Error 1.1 is %s\n", cudaGetErrorString (error_id));
    }

    unsigned long *address;
    unsigned long *h_address;
    cudaHostAlloc ((void **) &h_address, sizeof(unsigned int) * data_entries, cudaHostAllocMapped);
    error_id = cudaHostGetDevicePointer ((void **) &address, h_address, 0);;
    if (error_id != cudaSuccess) {
        printf ("Error 1.1 is %s\n", cudaGetErrorString (error_id));
    }

    cudaDeviceSynchronize ();
    /* launch kernel*/
    dim3 Db = dim3 (1);
    dim3 Dg = dim3 (1, 1, 1);

    init_device_array <<<Dg, Db>>> (d_a, N, entries);

    cudaProfilerStart ();
    global_latency <<<Dg, Db>>> (d_a, N, entries, duration, address);
    cudaProfilerStop ();

    cudaDeviceSynchronize ();

    unsigned int result = h_a[N + 1];
    cudaDeviceSynchronize ();

    int d_sum = 0, a_time;
    if (DEBUG) {
        printf ("\nAddress\t\tTime\n");
        for (int j = 0; j < ITERATIONS; j++) {
            printf ("==Iteration: %d ================================\n\n", j);
            for (int i = 0; i < entries; i++) {
                int idx = j * entries + i;
                a_time = duration[idx] / ITERATIONS;
                d_sum += a_time;
                printf ("%p : %u\n", (void *) address[i], a_time);
            }
            printf ("===============================================\n\n");
        }
    }

    /* free memory on CPU */
    cudaFreeHost (h_a);
    cudaFreeHost (h_address);
    cudaFreeHost (h_duration);
    
    cudaDeviceReset ();
    return d_sum;
}

__global__ void init_device_array (unsigned int *my_array, unsigned int entries, unsigned long long length) {

    unsigned int k = 0, j, sum = 0;
    // first round, warm the TLB
    for (k = 0; k < entries; k++) {
        j = my_array[j];
        sum += j;
    }

    my_array[length] = sum;
}

__global__ void global_latency (unsigned int *my_array, unsigned long long array_length,
                                unsigned int entries, unsigned int *d_time, unsigned long *addr) {

    unsigned int start_time, end_time, pos_sum = 0, duration = 0;
    unsigned int j = 0, i, k, idx;

	// __shared__ unsigned int s_tvalue[MAX_SHARED_E];
	// __shared__ unsigned int s_index[MAX_SHARED_E];

    j = (j != 0) ? 0 : j;
    // second round, begin timestamp
    for (i = 0; i < ITERATIONS; i++) {
        for (k = 0; k < entries; k++) {

            idx = i * entries + k;
            addr[idx] = (unsigned long) &my_array[j];
            start_time = clock64 ();
            j = my_array[j];
            pos_sum += j;
            end_time = clock64 ();

            duration += (end_time - start_time);
            d_time[idx] = (end_time - start_time);

        }
    }

    // copy from shared to global array
    /*for (i = 0; i < ITERATIONS; i++) {
        for (k = 0; k < entries; k++) {

            idx = i * entries + k;
            addr[idx] = s_index[idx];
            d_time[idx] = s_tvalue[idx];

        }
    }*/

    my_array[array_length] = pos_sum;
    my_array[array_length + 1] = duration;
}

	.file	"tmpxft_0021dbd0_00000000-6_host_alloc.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10dtime_usecy
	.type	_Z10dtime_usecy, @function
_Z10dtime_usecy:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	xorl	%esi, %esi
	movq	%rdi, %rbx
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	imulq	$1000000, 8(%rsp), %rax
	addq	16(%rsp), %rax
	subq	%rbx, %rax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10dtime_usecy, .-_Z10dtime_usecy
	.globl	_Z7KB_TO_Bj
	.type	_Z7KB_TO_Bj, @function
_Z7KB_TO_Bj:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	salq	$10, %rax
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z7KB_TO_Bj, .-_Z7KB_TO_Bj
	.globl	_Z7MB_TO_Bj
	.type	_Z7MB_TO_Bj, @function
_Z7MB_TO_Bj:
.LFB2029:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	salq	$20, %rax
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7MB_TO_Bj, .-_Z7MB_TO_Bj
	.globl	_Z39__device_stub__Z17init_device_arrayPjjyPjjy
	.type	_Z39__device_stub__Z17init_device_arrayPjjyPjjy, @function
_Z39__device_stub__Z17init_device_arrayPjjyPjjy:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z17init_device_arrayPjjy(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L8:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z39__device_stub__Z17init_device_arrayPjjyPjjy, .-_Z39__device_stub__Z17init_device_arrayPjjyPjjy
	.globl	_Z17init_device_arrayPjjy
	.type	_Z17init_device_arrayPjjy, @function
_Z17init_device_arrayPjjy:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z17init_device_arrayPjjyPjjy
	.cfi_endproc
.LFE2058:
	.size	_Z17init_device_arrayPjjy, .-_Z17init_device_arrayPjjy
	.globl	_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm
	.type	_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm, @function
_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z14global_latencyPjyjS_Pm(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L13:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm, .-_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm
	.globl	_Z14global_latencyPjyjS_Pm
	.type	_Z14global_latencyPjyjS_Pm, @function
_Z14global_latencyPjyjS_Pm:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm
	.cfi_endproc
.LFE2060:
	.size	_Z14global_latencyPjyjS_Pm, .-_Z14global_latencyPjyjS_Pm
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Error 1.0 is %s\n"
.LC1:
	.string	"Error 1.1 is %s\n"
.LC2:
	.string	"\nAddress\t\tTime\n"
.LC3:
	.string	"==Iteration: %d ================================\n\n"
.LC4:
	.string	"%p : %u\n"
.LC5:
	.string	"===============================================\n\n"
	.text
	.globl	_Z25parametric_measure_globalyij
	.type	_Z25parametric_measure_globalyij, @function
_Z25parametric_measure_globalyij:
.LFB2032:
	.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
	movslq	%esi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	8(,%rbp,4), %r13
	movl	%edx, %ebx
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	cudaDeviceReset@PLT
	movq	%r13, %rsi
	movq	%rsp, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	movq	(%rsp), %rsi
	xorl	%ecx, %ecx
.L19:
	cmpq	%rcx, %rbp
	je	.L41
	leaq	(%r12,%rcx), %rax
	xorl	%edx, %edx
	divq	%rbp
	movl	%edx, (%rsi,%rcx,4)
	incq	%rcx
	jmp	.L19
.L41:
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	xorl	%edx, %edx
	movl	%eax, -8(%rsi,%r13)
	movl	%eax, -4(%rsi,%r13)
	call	cudaHostGetDevicePointer@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L21:
	leal	(%rbx,%rbx), %r12d
	leaq	24(%rsp), %rdi
	movl	$2, %edx
	salq	$2, %r12
	movq	%r12, %rsi
	call	cudaHostAlloc@PLT
	movq	24(%rsp), %rsi
	leaq	16(%rsp), %rdi
	xorl	%edx, %edx
	call	cudaHostGetDevicePointer@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L22:
	leaq	40(%rsp), %rdi
	movl	$2, %edx
	movq	%r12, %rsi
	call	cudaHostAlloc@PLT
	movq	40(%rsp), %rsi
	leaq	32(%rsp), %rdi
	xorl	%edx, %edx
	call	cudaHostGetDevicePointer@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L23:
	call	cudaDeviceSynchronize@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movl	$1, %esi
	movl	$1, 56(%rsp)
	movl	%ebx, %r14d
	movabsq	$4294967297, %rdi
	movq	%rdi, %rdx
	movq	%rdi, 48(%rsp)
	movq	%rdi, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	8(%rsp), %rdi
	movq	%r14, %rdx
	movl	%ebp, %esi
	call	_Z39__device_stub__Z17init_device_arrayPjjyPjjy
.L24:
	call	cudaProfilerStart@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	48(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	32(%rsp), %r8
	movq	16(%rsp), %rcx
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movq	8(%rsp), %rdi
	call	_Z40__device_stub__Z14global_latencyPjyjS_PmPjyjS_Pm
.L25:
	call	cudaProfilerStop@PLT
	xorl	%r13d, %r13d
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
	call	cudaDeviceSynchronize@PLT
	call	cudaDeviceSynchronize@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L28:
	movl	%r12d, %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	movl	$2, %edi
	call	__printf_chk@PLT
.L26:
	cmpq	%r14, %r15
	je	.L42
	movq	16(%rsp), %rdx
	leal	0(%r13,%r15), %eax
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	cltq
	movl	(%rdx,%rax,4), %ecx
	movq	32(%rsp), %rax
	movq	(%rax,%r15,8), %rdx
	shrl	%ecx
	xorl	%eax, %eax
	incq	%r15
	addl	%ecx, %ebp
	call	__printf_chk@PLT
	jmp	.L26
.L42:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	addl	%ebx, %r13d
	call	__printf_chk@PLT
	testl	%r12d, %r12d
	jne	.L43
	movl	$1, %r12d
	jmp	.L28
.L43:
	movq	(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	24(%rsp), %rdi
	call	cudaFreeHost@PLT
	call	cudaDeviceReset@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebp, %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
.LFE2032:
	.size	_Z25parametric_measure_globalyij, .-_Z25parametric_measure_globalyij
	.section	.rodata.str1.1
.LC6:
	.string	"Hey, shared_memory is limited, either reduce ITERATIONS or increase stride!!"
.LC7:
	.string	"\n=====%llu MB array, warm TLB, read %d elements====\n"
.LC8:
	.string	"Iterations = %d, Stride = %u element, %u KB\n"
.LC10:
	.string	"(H) Kernel Duration: %lf\n"
.LC11:
	.string	"(D) Kernel Duration: %u\n"
.LC12:
	.string	"\n===============================================\n\n"
	.text
	.globl	_Z14measure_globaljjj
	.type	_Z14measure_globaljjj, @function
_Z14measure_globaljjj:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %r9d
	movl	$4, %eax
	movl	%edi, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC7(%rip), %r14
	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
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r9, %rbx
	salq	$10, %r9
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	testl	%r9d, %r9d
	cmovne	%r9d, %eax
	movl	%eax, %r12d
	shrl	$2, %eax
	movl	%eax, 12(%rsp)
.L46:
	cmpl	%r15d, %ebp
	jb	.L50
	movl	%r15d, %esi
	xorl	%edx, %edx
	movq	%rsi, %rcx
	movq	%rsi, %rax
	salq	$18, %rcx
	salq	$20, %rax
	movq	%rcx, 16(%rsp)
	movl	%r12d, %ecx
	divq	%rcx
	movl	%eax, %r13d
	addl	%eax, %eax
	cmpl	$4096, %eax
	jbe	.L47
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	.LC6(%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
.L47:
	.cfi_restore_state
	movl	%r13d, %ecx
	movq	%rsi, %rdx
	movl	$2, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	addl	$2, %r15d
	call	__printf_chk@PLT
	movl	12(%rsp), %ecx
	movl	%ebx, %r8d
	xorl	%eax, %eax
	movl	$2, %edx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	_Z10dtime_usecy
	movl	12(%rsp), %esi
	movq	16(%rsp), %rdi
	movl	%r13d, %edx
	movq	%rax, 24(%rsp)
	call	_Z25parametric_measure_globalyij
	movq	24(%rsp), %rdi
	movl	%eax, %r13d
	call	_Z10dtime_usecy
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	shrq	%rax
	cvtsi2ssq	%rax, %xmm0
	movb	$1, %al
	divss	.LC9(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	%r13d, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC11(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L46
.L50:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	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	_Z14measure_globaljjj, .-_Z14measure_globaljjj
	.section	.rodata.str1.1
.LC13:
	.string	"Usage: ./<executable>   from_mb   to_mb   stride_size_kb   device_no (0-1)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	cmpl	$4, %edi
	jg	.L52
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L53
.L52:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	call	atof@PLT
	movq	16(%rbx), %rdi
	movsd	%xmm0, 24(%rsp)
	call	atof@PLT
	movq	24(%rbx), %rdi
	movsd	%xmm0, 16(%rsp)
	call	atof@PLT
	movq	32(%rbx), %rdi
	movsd	%xmm0, 8(%rsp)
	call	atoi@PLT
	movl	%eax, %edi
	call	cudaSetDevice@PLT
	movsd	8(%rsp), %xmm0
	movsd	16(%rsp), %xmm2
	movsd	24(%rsp), %xmm1
	cvttsd2siq	%xmm0, %rdx
	cvttsd2siq	%xmm2, %rsi
	cvttsd2siq	%xmm1, %rdi
	call	_Z14measure_globaljjj
	call	cudaDeviceReset@PLT
.L53:
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z14global_latencyPjyjS_Pm"
.LC15:
	.string	"_Z17init_device_arrayPjjy"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2062:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z14global_latencyPjyjS_Pm(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z17init_device_arrayPjjy(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2062:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC9:
	.long	1232348160
	.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 <stdio.h>
# include <stdint.h>

# include "hip/hip_runtime.h"
# include "hip/hip_runtime_api.h"

#define ITERATIONS 2
#define DEBUG 1
#define MAX_SHARED_E 2048

#include <time.h>
#include <sys/time.h>
#define USECPSEC 1000000ULL

unsigned long long dtime_usec (unsigned long long start) {

  timeval tv;
  gettimeofday (&tv, 0);
  return ((tv.tv_sec * USECPSEC) + tv.tv_usec) - start;
}

//compile nvcc *.cu -o test

__global__ void init_device_array (unsigned int *, unsigned int, unsigned long long);
__global__ void global_latency (unsigned int *, unsigned long long , unsigned int, unsigned int *, unsigned long *);
unsigned int parametric_measure_global (unsigned long long , int, unsigned int);
void measure_global (unsigned int, unsigned int, unsigned int);

unsigned long long KB_TO_B (unsigned int x) {
    return (x * 1024LLU);
}
unsigned long long MB_TO_B (unsigned int x)  {
    return (x * 1024LLU * 1024LLU);
}

int main (int argc, char **argv) {

    if (argc < 5) {
        printf ("Usage: ./<executable>   from_mb   to_mb   stride_size_kb   device_no (0-1)\n");
        return 0;
    }

    /* Array size in mega bytes 1st argument. */
    unsigned int from_mb = (unsigned int) atof (argv[1]);

    /* Array size in mega bytes 2nd argument. */
    unsigned int to_mb = (unsigned int) atof (argv[2]);

    /* Stride size in kilo bytes 3rd argument. */
    unsigned int stride_size_kb = (unsigned int) atof (argv[3]);
    /* Set device number if there are many! */
    int device = atoi (argv[4]);

    hipSetDevice (device);

    measure_global (from_mb, to_mb, stride_size_kb);

    hipDeviceReset ();

    return 0;
}

void measure_global (unsigned int from_mb, unsigned int to_mb, unsigned int stride_size_kb) {

    unsigned int stride, stride_b, entries;
    unsigned long long N, array_size_b, elements;

    // stride in element, change here if needed!
    stride_b = KB_TO_B (stride_size_kb);
    // if argument is non zero take that, else 1 element stride
    stride_b = (stride_b > 0) ? stride_b : sizeof (unsigned int);
    stride = stride_b / sizeof (unsigned int);

    unsigned int d_time = 0;
    unsigned long long difft;
    for (int i = from_mb; i <= to_mb; i += 2) {
        // chage below for different array size creation!
        array_size_b = MB_TO_B (i);
        elements = array_size_b / sizeof (unsigned int);
        entries = array_size_b / stride_b;
        N = elements;

        /* Why 2 * MAX_SHARED_E, well there are 2 shared arrays in the kernel! */
        if (ITERATIONS * entries > (2 * MAX_SHARED_E)) {
            printf ("Hey, shared_memory is limited, either reduce ITERATIONS or increase stride!!");
            return;
        }

        printf ("\n=====%llu MB array, warm TLB, read %d elements====\n", array_size_b / MB_TO_B(1), entries);
        printf ("Iterations = %d, Stride = %u element, %u KB\n", ITERATIONS, stride, stride_size_kb);
        difft = dtime_usec (0);

        d_time = parametric_measure_global (N, stride, entries);

        difft = dtime_usec (difft);
        printf ("(H) Kernel Duration: %lf\n", (difft / ITERATIONS) / (float) USECPSEC);
        printf ("(D) Kernel Duration: %u\n", d_time);

        printf("\n===============================================\n\n");
    }
}

unsigned int parametric_measure_global (unsigned long long N, int stride, unsigned int entries) {

    hipDeviceReset ();
    hipError_t error_id;
    int i;

    unsigned int *h_a;
    /* allocate arrays on CPU, pinned host memory */
    hipHostAlloc ((void **) &h_a, sizeof(unsigned int) * (N + 2), hipHostMallocMapped);

    /* initialize array elements on CPU with pointers into d_a. */
    for (i = 0; i < N; i++) {        
        // Original:    
        h_a[i] = (i + stride) % N;
    }

    h_a[N] = 0;
    h_a[N + 1] = 0;

    unsigned int *d_a;
    /* allocate arrays on GPU */
    error_id = hipHostGetDevicePointer ((void **) &d_a, h_a, 0);
    if (error_id != hipSuccess) {
        printf ("Error 1.0 is %s\n", hipGetErrorString (error_id));
    }

    unsigned int data_entries = ITERATIONS * entries;

    unsigned int *duration;
    unsigned int *h_duration;
    hipHostAlloc ((void **) &h_duration, sizeof(unsigned int) * data_entries, hipHostMallocMapped);
    error_id = hipHostGetDevicePointer ((void **) &duration, h_duration, 0);;
    if (error_id != hipSuccess) {
        printf ("Error 1.1 is %s\n", hipGetErrorString (error_id));
    }

    unsigned long *address;
    unsigned long *h_address;
    hipHostAlloc ((void **) &h_address, sizeof(unsigned int) * data_entries, hipHostMallocMapped);
    error_id = hipHostGetDevicePointer ((void **) &address, h_address, 0);;
    if (error_id != hipSuccess) {
        printf ("Error 1.1 is %s\n", hipGetErrorString (error_id));
    }

    hipDeviceSynchronize ();
    /* launch kernel*/
    dim3 Db = dim3 (1);
    dim3 Dg = dim3 (1, 1, 1);

    init_device_array <<<Dg, Db>>> (d_a, N, entries);

    hipProfilerStart ();
    global_latency <<<Dg, Db>>> (d_a, N, entries, duration, address);
    hipProfilerStop ();

    hipDeviceSynchronize ();

    unsigned int result = h_a[N + 1];
    hipDeviceSynchronize ();

    int d_sum = 0, a_time;
    if (DEBUG) {
        printf ("\nAddress\t\tTime\n");
        for (int j = 0; j < ITERATIONS; j++) {
            printf ("==Iteration: %d ================================\n\n", j);
            for (int i = 0; i < entries; i++) {
                int idx = j * entries + i;
                a_time = duration[idx] / ITERATIONS;
                d_sum += a_time;
                printf ("%p : %u\n", (void *) address[i], a_time);
            }
            printf ("===============================================\n\n");
        }
    }

    /* free memory on CPU */
    hipHostFree (h_a);
    hipHostFree (h_address);
    hipHostFree (h_duration);
    
    hipDeviceReset ();
    return d_sum;
}

__global__ void init_device_array (unsigned int *my_array, unsigned int entries, unsigned long long length) {

    unsigned int k = 0, j, sum = 0;
    // first round, warm the TLB
    for (k = 0; k < entries; k++) {
        j = my_array[j];
        sum += j;
    }

    my_array[length] = sum;
}

__global__ void global_latency (unsigned int *my_array, unsigned long long array_length,
                                unsigned int entries, unsigned int *d_time, unsigned long *addr) {

    unsigned int start_time, end_time, pos_sum = 0, duration = 0;
    unsigned int j = 0, i, k, idx;

	// __shared__ unsigned int s_tvalue[MAX_SHARED_E];
	// __shared__ unsigned int s_index[MAX_SHARED_E];

    j = (j != 0) ? 0 : j;
    // second round, begin timestamp
    for (i = 0; i < ITERATIONS; i++) {
        for (k = 0; k < entries; k++) {

            idx = i * entries + k;
            addr[idx] = (unsigned long) &my_array[j];
            start_time = clock64 ();
            j = my_array[j];
            pos_sum += j;
            end_time = clock64 ();

            duration += (end_time - start_time);
            d_time[idx] = (end_time - start_time);

        }
    }

    // copy from shared to global array
    /*for (i = 0; i < ITERATIONS; i++) {
        for (k = 0; k < entries; k++) {

            idx = i * entries + k;
            addr[idx] = s_index[idx];
            d_time[idx] = s_tvalue[idx];

        }
    }*/

    my_array[array_length] = pos_sum;
    my_array[array_length + 1] = duration;
}

	.text
	.file	"host_alloc.hip"
	.globl	_Z10dtime_usecy                 # -- Begin function _Z10dtime_usecy
	.type	_Z10dtime_usecy,@function
_Z10dtime_usecy:                        # @_Z10dtime_usecy
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, (%r14), %rcx          # imm = 0xF4240
	movq	8(%r14), %rax
	subq	%rbx, %rax
	addq	%rcx, %rax
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z10dtime_usecy, .Lfunc_end0-_Z10dtime_usecy
	.cfi_endproc
                                        # -- End function
	.globl	_Z7KB_TO_Bj                     # -- Begin function _Z7KB_TO_Bj
	.type	_Z7KB_TO_Bj,@function
_Z7KB_TO_Bj:                            # @_Z7KB_TO_Bj
	.cfi_startproc
# %bb.0:
	movl	%edi, %eax
	shlq	$10, %rax
	retq
.Lfunc_end1:
	.size	_Z7KB_TO_Bj, .Lfunc_end1-_Z7KB_TO_Bj
	.cfi_endproc
                                        # -- End function
	.globl	_Z7MB_TO_Bj                     # -- Begin function _Z7MB_TO_Bj
	.type	_Z7MB_TO_Bj,@function
_Z7MB_TO_Bj:                            # @_Z7MB_TO_Bj
	.cfi_startproc
# %bb.0:
	movl	%edi, %eax
	shlq	$20, %rax
	retq
.Lfunc_end2:
	.size	_Z7MB_TO_Bj, .Lfunc_end2-_Z7MB_TO_Bj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.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 %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$4, %edi
	jg	.LBB3_2
# %bb.1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	jmp	.LBB3_3
.LBB3_2:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atof
	cvttsd2si	%xmm0, %r14
	movq	16(%rbx), %rdi
	callq	atof
	cvttsd2si	%xmm0, %r15
	movq	24(%rbx), %rdi
	callq	atof
	cvttsd2si	%xmm0, %r12
	movq	32(%rbx), %rdi
	callq	atoi
	movl	%eax, %edi
	callq	hipSetDevice
	movl	%r14d, %edi
	movl	%r15d, %esi
	movl	%r12d, %edx
	callq	_Z14measure_globaljjj
	callq	hipDeviceReset
.LBB3_3:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z14measure_globaljjj
.LCPI4_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z14measure_globaljjj
	.type	_Z14measure_globaljjj,@function
_Z14measure_globaljjj:                  # @_Z14measure_globaljjj
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, 12(%rsp)                  # 4-byte Spill
	movl	%edx, %eax
	shll	$10, %eax
	movl	$4, %ecx
	cmovneq	%rax, %rcx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	movl	%esi, 8(%rsp)                   # 4-byte Spill
	cmpl	%esi, %edi
	ja	.LBB4_4
# %bb.1:                                # %.lr.ph
	movq	16(%rsp), %rax                  # 8-byte Reload
                                        # kill: def $eax killed $eax killed $rax
	shrl	$2, %eax
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movl	4(%rsp), %ebx                   # 4-byte Reload
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
	movl	%edi, %r15d
	movq	%r15, %rax
	shlq	$20, %rax
	xorl	%edx, %edx
	divq	16(%rsp)                        # 8-byte Folded Reload
	movq	%rax, %r13
	addl	%eax, %eax
	cmpl	$4097, %eax                     # imm = 0x1001
	jae	.LBB4_5
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	movq	%r15, %r12
	shlq	$18, %r12
	movl	$.L.str.2, %edi
	movq	%r15, %rsi
	movl	%r13d, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %edi
	movl	$2, %esi
	movl	%ebx, %edx
	movl	12(%rsp), %ecx                  # 4-byte Reload
	xorl	%eax, %eax
	callq	printf
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	24(%rsp), %rbp
	movq	32(%rsp), %r14
	movq	%r12, %rdi
	movl	%ebx, %esi
	movl	%r13d, %edx
	callq	_Z25parametric_measure_globalyij
	movl	%eax, %r12d
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	24(%rsp), %rax
	subq	%rbp, %rax
	movq	32(%rsp), %rcx
	subq	%r14, %rcx
	imulq	$1000000, %rax, %rax            # imm = 0xF4240
	addq	%rcx, %rax
	shrq	%rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	divss	.LCPI4_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.5, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leal	2(%r15), %edi
	cmpl	8(%rsp), %edi                   # 4-byte Folded Reload
	jbe	.LBB4_2
.LBB4_4:                                # %.loopexit
	addq	$40, %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
.LBB4_5:
	.cfi_def_cfa_offset 96
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	addq	$40, %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
	jmp	printf                          # TAILCALL
.Lfunc_end4:
	.size	_Z14measure_globaljjj, .Lfunc_end4-_Z14measure_globaljjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z25parametric_measure_globalyij # -- Begin function _Z25parametric_measure_globalyij
	.type	_Z25parametric_measure_globalyij,@function
_Z25parametric_measure_globalyij:       # @_Z25parametric_measure_globalyij
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
	callq	hipDeviceReset
	leaq	8(,%r14,4), %rsi
	leaq	48(%rsp), %r15
	movq	%r15, %rdi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r15), %rsi
	testq	%r14, %r14
	je	.LBB5_3
# %bb.1:                                # %.lr.ph
	movslq	%ebp, %rcx
	xorl	%edi, %edi
.LBB5_2:                                # =>This Inner Loop Header: Depth=1
	leaq	(%rcx,%rdi), %rax
	xorl	%edx, %edx
	divq	%r14
	movl	%edx, (%rsi,%rdi,4)
	incq	%rdi
	cmpq	%rdi, %r14
	jne	.LBB5_2
.LBB5_3:                                # %._crit_edge
	movq	$0, (%rsi,%r14,4)
	leaq	24(%rsp), %rdi
	xorl	%edx, %edx
	callq	hipHostGetDevicePointer
	testl	%eax, %eax
	je	.LBB5_5
# %bb.4:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.7, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB5_5:
	leal	(%rbx,%rbx), %r15d
	shlq	$2, %r15
	leaq	40(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r12), %rsi
	leaq	16(%rsp), %rdi
	xorl	%edx, %edx
	callq	hipHostGetDevicePointer
	testl	%eax, %eax
	je	.LBB5_7
# %bb.6:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB5_7:
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r12), %rsi
	leaq	8(%rsp), %rdi
	xorl	%edx, %edx
	callq	hipHostGetDevicePointer
	testl	%eax, %eax
	je	.LBB5_9
# %bb.8:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB5_9:
	movabsq	$4294967297, %r12               # imm = 0x100000001
	callq	hipDeviceSynchronize
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	movl	%ebx, %r15d
	testl	%eax, %eax
	jne	.LBB5_11
# %bb.10:
	movq	24(%rsp), %rdi
	movl	%r14d, %esi
	movq	%r15, %rdx
	callq	_Z32__device_stub__init_device_arrayPjjy
.LBB5_11:
	callq	hipProfilerStart
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_13
# %bb.12:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rcx
	movq	8(%rsp), %r8
	movq	%r14, %rsi
	movl	%ebx, %edx
	callq	_Z29__device_stub__global_latencyPjyjS_Pm
.LBB5_13:
	callq	hipProfilerStop
	callq	hipDeviceSynchronize
	callq	hipDeviceSynchronize
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movb	$1, %r12b
	xorl	%r14d, %r14d
	xorl	%ebp, %ebp
.LBB5_14:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_16 Depth 2
	movl	$.L.str.10, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	testl	%ebx, %ebx
	je	.LBB5_17
# %bb.15:                               # %.lr.ph78
                                        #   in Loop: Header=BB5_14 Depth=1
	imull	%ebx, %r14d
	xorl	%r13d, %r13d
.LBB5_16:                               #   Parent Loop BB5_14 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%r14,%r13), %eax
	movq	16(%rsp), %rcx
	cltq
	movl	(%rcx,%rax,4), %edx
	shrl	%edx
	addl	%edx, %ebp
	movq	8(%rsp), %rax
	movq	(%rax,%r13,8), %rsi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB5_16
.LBB5_17:                               # %._crit_edge79
                                        #   in Loop: Header=BB5_14 Depth=1
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$1, %r14d
	testb	$1, %r12b
	movl	$0, %r12d
	jne	.LBB5_14
# %bb.18:
	movq	48(%rsp), %rdi
	callq	hipHostFree
	movq	32(%rsp), %rdi
	callq	hipHostFree
	movq	40(%rsp), %rdi
	callq	hipHostFree
	callq	hipDeviceReset
	movl	%ebp, %eax
	addq	$56, %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
.Lfunc_end5:
	.size	_Z25parametric_measure_globalyij, .Lfunc_end5-_Z25parametric_measure_globalyij
	.cfi_endproc
                                        # -- End function
	.globl	_Z32__device_stub__init_device_arrayPjjy # -- Begin function _Z32__device_stub__init_device_arrayPjjy
	.type	_Z32__device_stub__init_device_arrayPjjy,@function
_Z32__device_stub__init_device_arrayPjjy: # @_Z32__device_stub__init_device_arrayPjjy
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z17init_device_arrayPjjy, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end6:
	.size	_Z32__device_stub__init_device_arrayPjjy, .Lfunc_end6-_Z32__device_stub__init_device_arrayPjjy
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__global_latencyPjyjS_Pm # -- Begin function _Z29__device_stub__global_latencyPjyjS_Pm
	.type	_Z29__device_stub__global_latencyPjyjS_Pm,@function
_Z29__device_stub__global_latencyPjyjS_Pm: # @_Z29__device_stub__global_latencyPjyjS_Pm
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	32(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z14global_latencyPjyjS_Pm, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end7:
	.size	_Z29__device_stub__global_latencyPjyjS_Pm, .Lfunc_end7-_Z29__device_stub__global_latencyPjyjS_Pm
	.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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17init_device_arrayPjjy, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14global_latencyPjyjS_Pm, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Hey, shared_memory is limited, either reduce ITERATIONS or increase stride!!"
	.size	.L.str.1, 77

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\n=====%llu MB array, warm TLB, read %d elements====\n"
	.size	.L.str.2, 53

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Iterations = %d, Stride = %u element, %u KB\n"
	.size	.L.str.3, 45

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"(H) Kernel Duration: %lf\n"
	.size	.L.str.4, 26

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"(D) Kernel Duration: %u\n"
	.size	.L.str.5, 25

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Error 1.0 is %s\n"
	.size	.L.str.7, 17

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Error 1.1 is %s\n"
	.size	.L.str.8, 17

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

	.type	_Z14global_latencyPjyjS_Pm,@object # @_Z14global_latencyPjyjS_Pm
	.globl	_Z14global_latencyPjyjS_Pm
	.p2align	3, 0x0
_Z14global_latencyPjyjS_Pm:
	.quad	_Z29__device_stub__global_latencyPjyjS_Pm
	.size	_Z14global_latencyPjyjS_Pm, 8

	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.10:
	.asciz	"==Iteration: %d ================================\n\n"
	.size	.L.str.10, 51

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"%p : %u\n"
	.size	.L.str.11, 9

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z17init_device_arrayPjjy"
	.size	.L__unnamed_1, 26

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z14global_latencyPjyjS_Pm"
	.size	.L__unnamed_2, 27

	.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	"Usage: ./<executable>   from_mb   to_mb   stride_size_kb   device_no (0-1)"
	.size	.Lstr, 75

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\n===============================================\n"
	.size	.Lstr.1, 50

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"\nAddress\t\tTime"
	.size	.Lstr.2, 15

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"===============================================\n"
	.size	.Lstr.3, 49

	.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 _Z32__device_stub__init_device_arrayPjjy
	.addrsig_sym _Z29__device_stub__global_latencyPjyjS_Pm
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z17init_device_arrayPjjy
	.addrsig_sym _Z14global_latencyPjyjS_Pm
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17init_device_arrayPjjy ; -- Begin function _Z17init_device_arrayPjjy
	.globl	_Z17init_device_arrayPjjy
	.p2align	8
	.type	_Z17init_device_arrayPjjy,@function
_Z17init_device_arrayPjjy:              ; @_Z17init_device_arrayPjjy
; %bb.0:
	s_clause 0x1
	s_load_b32 s7, s[0:1], 0x8
	s_load_b64 s[2:3], s[0:1], 0x0
	s_mov_b32 s6, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s7, 0
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_mov_b32 s5, 0
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[8:9], s[4:5], 2
	s_add_u32 s8, s2, s8
	s_addc_u32 s9, s3, s9
	s_add_i32 s7, s7, -1
	s_load_b32 s4, s[8:9], 0x0
	s_waitcnt lgkmcnt(0)
	s_add_i32 s6, s4, s6
	s_cmp_lg_u32 s7, 0
	s_cbranch_scc1 .LBB0_2
.LBB0_3:                                ; %._crit_edge
	s_load_b64 s[0:1], s[0:1], 0x10
	v_dual_mov_b32 v0, 0 :: v_dual_mov_b32 v1, s6
	s_waitcnt lgkmcnt(0)
	s_lshl_b64 s[0:1], s[0:1], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s2, s0
	s_addc_u32 s1, s3, s1
	global_store_b32 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 _Z17init_device_arrayPjjy
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 10
		.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	_Z17init_device_arrayPjjy, .Lfunc_end0-_Z17init_device_arrayPjjy
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 140
; NumSgprs: 10
; NumVgprs: 2
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 10
; 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
	.protected	_Z14global_latencyPjyjS_Pm ; -- Begin function _Z14global_latencyPjyjS_Pm
	.globl	_Z14global_latencyPjyjS_Pm
	.p2align	8
	.type	_Z14global_latencyPjyjS_Pm,@function
_Z14global_latencyPjyjS_Pm:             ; @_Z14global_latencyPjyjS_Pm
; %bb.0:
	s_clause 0x2
	s_load_b32 s12, s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b128 s[8:11], s[0:1], 0x18
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 0
	v_mov_b32_e32 v0, 0
	s_mov_b32 s13, -1
	s_mov_b32 s3, 0
	s_mov_b32 s2, 0
	s_mov_b32 s1, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_lg_u32 s12, 0
	s_cselect_b32 s0, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v1, 0, 1, s0
	v_cmp_ne_u32_e64 s0, 1, v1
	v_mov_b32_e32 v1, v2
.LBB1_1:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_3 Depth 2
	s_delay_alu instid0(VALU_DEP_2)
	s_and_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccnz .LBB1_4
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_mul_i32 s2, s2, s12
	s_mov_b32 s14, s12
.LBB1_3:                                ;   Parent Loop BB1_1 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	s_lshl_b64 s[16:17], s[2:3], 3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_add_u32 s16, s10, s16
	s_addc_u32 s17, s11, s17
	v_add_co_u32 v4, vcc_lo, s4, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	global_store_b64 v3, v[4:5], s[16:17]
	s_getreg_b32 s15, hwreg(HW_REG_SHADER_CYCLES, 0, 20)
	global_load_b32 v1, v[4:5], off
	s_getreg_b32 s18, hwreg(HW_REG_SHADER_CYCLES, 0, 20)
	s_lshl_b64 s[16:17], s[2:3], 2
	s_sub_i32 s15, s18, s15
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_i32 s1, s15, s1
	v_mov_b32_e32 v4, s15
	s_add_u32 s16, s8, s16
	s_addc_u32 s17, s9, s17
	s_add_i32 s14, s14, -1
	s_add_i32 s2, s2, 1
	s_cmp_lg_u32 s14, 0
	global_store_b32 v3, v4, s[16:17]
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v0, v1, v0
	s_cbranch_scc1 .LBB1_3
.LBB1_4:                                ; %Flow77
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_xor_b32 s13, s13, -1
	s_mov_b32 s2, 1
	s_and_not1_b32 vcc_lo, exec_lo, s13
	s_mov_b32 s13, 0
	s_cbranch_vccnz .LBB1_1
; %bb.5:
	s_lshl_b64 s[2:3], s[6:7], 2
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v1, s1
	s_add_u32 s0, s4, s2
	s_addc_u32 s1, s5, s3
	global_store_b64 v2, v[0:1], s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14global_latencyPjyjS_Pm
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.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 6
		.amdhsa_next_free_sgpr 19
		.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_end1:
	.size	_Z14global_latencyPjyjS_Pm, .Lfunc_end1-_Z14global_latencyPjyjS_Pm
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 296
; NumSgprs: 21
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 21
; NumVGPRsForWavesPerEU: 6
; 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:     by_value
      - .offset:         16
        .size:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17init_device_arrayPjjy
    .private_segment_fixed_size: 0
    .sgpr_count:     10
    .sgpr_spill_count: 0
    .symbol:         _Z17init_device_arrayPjjy.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     2
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           8
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 40
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14global_latencyPjyjS_Pm
    .private_segment_fixed_size: 0
    .sgpr_count:     21
    .sgpr_spill_count: 0
    .symbol:         _Z14global_latencyPjyjS_Pm.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
