/*                                                          
  Finds: Maxwell TLB
  Soure code based on paper https://arxiv.org/pdf/1509.02308.pdf 
*/

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

#include "cuda_runtime.h"

#define LEN 256

__global__ void global_latency(unsigned int* my_array, int N, int iterations, unsigned int* duration, unsigned int* index) {
  // data access latencies array
  __shared__ unsigned int s_tvalue[LEN];
  // accessed data indices array
  __shared__ unsigned int s_index[LEN];

  // initialize arrays
  for (int k = 0; k < LEN; k++) {
    s_index[k] = 0;
    s_tvalue[k] = 0;
  }

  // warm up the TLB
  unsigned int j = 0; 
  for (int k = 0; k < LEN*iterations; k++) {
    j = my_array[j];
  }
  
  // ready to begin benchmarking
  unsigned int start_time, end_time;
  for (int k = 0; k < LEN; k++) {
    start_time = clock();
     
    // traverse array with elements initialized as indices of next memory access
    j = my_array[j];
    // handles ILP with this data dependency 
    s_index[k]= j;

    end_time = clock();
    s_tvalue[k] = end_time - start_time;
  }

  for(int k = 0; k < LEN; k++){
    index[k] = s_index[k];
    duration[k] = s_tvalue[k];
  }
}

void parametric_measure_global(int N, int iterations, int stride) {
  // destroy context
  cudaDeviceReset(); 

  cudaError_t error_id;

  // host (CPU) array 
  unsigned int * h_a;

  h_a = (unsigned int*) malloc(N * sizeof(unsigned int));

  for (int i = 0; i < N; i++) {   
    h_a[i] = (i+stride) % N;  
  }

  // device (GPU) array
  unsigned int * d_a;

  error_id = cudaMalloc((void **) &d_a, N * sizeof(unsigned int));
  if (error_id != cudaSuccess) {
    printf("Error from allocating device array is %s\n", cudaGetErrorString(error_id));
  }

  error_id = cudaMemcpy(d_a, h_a, N * sizeof(unsigned int), cudaMemcpyHostToDevice);
  if (error_id != cudaSuccess) {
    printf("Error from copying over host array is %s\n", cudaGetErrorString(error_id));
  }

  // accessed data indices array on host (CPU)
  unsigned int *h_index = (unsigned int*) malloc(LEN * sizeof(unsigned int));

  // accessed data indices array on device (GPU)
  unsigned int *d_index;
  error_id = cudaMalloc((void **) &d_index, LEN * sizeof(unsigned int));
  if (error_id != cudaSuccess) {
    printf("Error from allocating indices array is %s\n", cudaGetErrorString(error_id));
  }

  // data access latencies array on host (CPU)
  unsigned int *h_duration = (unsigned int*) malloc(LEN * sizeof(unsigned int));

  // data access latencies array on device (GPU)
  unsigned int *d_duration;
  error_id = cudaMalloc ((void**) &d_duration, LEN * sizeof(unsigned int));
  if (error_id != cudaSuccess) {
    printf("Error from allocating latencies array is %s\n", cudaGetErrorString(error_id));
  }

  // blocks until the device has completed all preceding requested tasks
  cudaThreadSynchronize();

  // launch kernel
  dim3 Db = dim3(1);
  dim3 Dg = dim3(1,1,1);
  global_latency<<<Dg, Db>>>(d_a, N, iterations, d_duration, d_index);
  cudaThreadSynchronize();

  error_id = cudaGetLastError();
  if (error_id != cudaSuccess) {
    printf("Error from kernel is %s\n", cudaGetErrorString(error_id));
  }
  cudaThreadSynchronize();

  // copy results from GPU to CPU
  error_id = cudaMemcpy((void*) h_duration, (void*) d_duration, LEN * sizeof(unsigned int), cudaMemcpyDeviceToHost);
  if (error_id != cudaSuccess) {
    printf("Error 2.0 is %s\n", cudaGetErrorString(error_id));
  }
  error_id = cudaMemcpy((void*) h_index, (void*) d_index, LEN * sizeof(unsigned int), cudaMemcpyDeviceToHost);
  if (error_id != cudaSuccess) {
    printf("Error 2.1 is %s\n", cudaGetErrorString(error_id));
  }
  cudaThreadSynchronize();

  for(int i = 0; i < LEN; i++) {
    printf("%d\n", h_duration[i]);
  }

  // free memory on GPU
  cudaFree(d_a);
  cudaFree(d_index);
  cudaFree(d_duration);

  // free memory on CPU 

  free(h_a);
  free(h_index);
  free(h_duration);
  
  // destroy context
  cudaDeviceReset();  
}

void measure_global() {
  int iterations = 10;
  
  // 2 MB stride
  int stride = 2*1024*1024/sizeof(unsigned int); 

  for (int N = 120*1024*256; N <= 150*1024*256; N += stride) {
    printf("\n=====%3.1f MB array, warm TLB, read 256 element====\n", sizeof(unsigned int)*(float)N/1024/1024);
    parametric_measure_global(N, iterations, stride);
    printf("===============================================\n\n");
  }
}

int main() {
  // current device
  cudaSetDevice(0);

  measure_global();

  // destroy context
  cudaDeviceReset();
  return 0;
}

	.file	"tmpxft_00299263_00000000-6_maxwell_tlb.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_
	.type	_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_, @function
_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 16(%rsp)
	leaq	32(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%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	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14global_latencyPjiiS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	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 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_, .-_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_
	.globl	_Z14global_latencyPjiiS_S_
	.type	_Z14global_latencyPjiiS_S_, @function
_Z14global_latencyPjiiS_S_:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_
	.cfi_endproc
.LFE2055:
	.size	_Z14global_latencyPjiiS_S_, .-_Z14global_latencyPjiiS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Error from allocating device array is %s\n"
.LC1:
	.string	"Error from copying over host array is %s\n"
.LC2:
	.string	"Error from allocating indices array is %s\n"
.LC3:
	.string	"Error from allocating latencies array is %s\n"
.LC4:
	.string	"Error from kernel is %s\n"
.LC5:
	.string	"Error 2.0 is %s\n"
.LC6:
	.string	"Error 2.1 is %s\n"
.LC7:
	.string	"%d\n"
	.text
	.globl	_Z25parametric_measure_globaliii
	.type	_Z25parametric_measure_globaliii, @function
_Z25parametric_measure_globaliii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%esi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movslq	%edi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rbx
	salq	$2, %rbp
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	cudaDeviceReset@PLT
	movq	%rbp, %rdi
	call	malloc@PLT
	xorl	%ecx, %ecx
	movq	%rax, %r12
.L9:
	cmpl	%ecx, %ebx
	jle	.L44
	leal	(%r14,%rcx), %eax
	cltd
	idivl	%ebx
	movl	%edx, (%r12,%rcx,4)
	incq	%rcx
	jmp	.L9
.L44:
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L11
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L11:
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L12
	call	cudaGetErrorString@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	movl	$1024, %edi
	call	malloc@PLT
	leaq	16(%rsp), %rdi
	movl	$1024, %esi
	movq	%rax, %r14
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L13:
	movl	$1024, %edi
	call	malloc@PLT
	leaq	24(%rsp), %rdi
	movl	$1024, %esi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L14
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L14:
	call	cudaThreadSynchronize@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdi, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movq	16(%rsp), %r8
	movq	24(%rsp), %rcx
	movl	%r13d, %edx
	movl	%ebx, %esi
	movq	8(%rsp), %rdi
	call	_Z40__device_stub__Z14global_latencyPjiiS_S_PjiiS_S_
.L15:
	call	cudaThreadSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L16
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L16:
	call	cudaThreadSynchronize@PLT
	movq	24(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	movl	$1024, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L17:
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movl	$2, %ecx
	movl	$1024, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L18
	call	cudaGetErrorString@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L18:
	call	cudaThreadSynchronize@PLT
	xorl	%ebx, %ebx
	leaq	.LC7(%rip), %r13
.L19:
	movl	0(%rbp,%rbx,4), %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$256, %rbx
	jne	.L19
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	call	cudaDeviceReset@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z25parametric_measure_globaliii, .-_Z25parametric_measure_globaliii
	.section	.rodata.str1.1
.LC10:
	.string	"\n=====%3.1f MB array, warm TLB, read 256 element====\n"
.LC11:
	.string	"===============================================\n\n"
	.text
	.globl	_Z14measure_globalv
	.type	_Z14measure_globalv, @function
_Z14measure_globalv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	$31457280, %ebx
.L46:
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC8(%rip), %xmm0
	movl	$2, %edi
	movb	$1, %al
	movss	.LC9(%rip), %xmm1
	leaq	.LC10(%rip), %rsi
	mulss	%xmm1, %xmm0
	mulss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	%ebx, %edi
	movl	$524288, %edx
	movl	$10, %esi
	addl	$524288, %ebx
	call	_Z25parametric_measure_globaliii
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cmpl	$39845888, %ebx
	jne	.L46
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14measure_globalv, .-_Z14measure_globalv
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	call	_Z14measure_globalv
	call	cudaDeviceReset@PLT
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z14global_latencyPjiiS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14global_latencyPjiiS_S_(%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
.LFE2057:
	.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
.LC8:
	.long	1082130432
	.align 4
.LC9:
	.long	981467136
	.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:

/*                                                          
  Finds: Maxwell TLB
  Soure code based on paper https://arxiv.org/pdf/1509.02308.pdf 
*/

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

#include "hip/hip_runtime.h"

#define LEN 256

__global__ void global_latency(unsigned int* my_array, int N, int iterations, unsigned int* duration, unsigned int* index) {
  // data access latencies array
  __shared__ unsigned int s_tvalue[LEN];
  // accessed data indices array
  __shared__ unsigned int s_index[LEN];

  // initialize arrays
  for (int k = 0; k < LEN; k++) {
    s_index[k] = 0;
    s_tvalue[k] = 0;
  }

  // warm up the TLB
  unsigned int j = 0; 
  for (int k = 0; k < LEN*iterations; k++) {
    j = my_array[j];
  }
  
  // ready to begin benchmarking
  unsigned int start_time, end_time;
  for (int k = 0; k < LEN; k++) {
    start_time = clock();
     
    // traverse array with elements initialized as indices of next memory access
    j = my_array[j];
    // handles ILP with this data dependency 
    s_index[k]= j;

    end_time = clock();
    s_tvalue[k] = end_time - start_time;
  }

  for(int k = 0; k < LEN; k++){
    index[k] = s_index[k];
    duration[k] = s_tvalue[k];
  }
}

void parametric_measure_global(int N, int iterations, int stride) {
  // destroy context
  hipDeviceReset(); 

  hipError_t error_id;

  // host (CPU) array 
  unsigned int * h_a;

  h_a = (unsigned int*) malloc(N * sizeof(unsigned int));

  for (int i = 0; i < N; i++) {   
    h_a[i] = (i+stride) % N;  
  }

  // device (GPU) array
  unsigned int * d_a;

  error_id = hipMalloc((void **) &d_a, N * sizeof(unsigned int));
  if (error_id != hipSuccess) {
    printf("Error from allocating device array is %s\n", hipGetErrorString(error_id));
  }

  error_id = hipMemcpy(d_a, h_a, N * sizeof(unsigned int), hipMemcpyHostToDevice);
  if (error_id != hipSuccess) {
    printf("Error from copying over host array is %s\n", hipGetErrorString(error_id));
  }

  // accessed data indices array on host (CPU)
  unsigned int *h_index = (unsigned int*) malloc(LEN * sizeof(unsigned int));

  // accessed data indices array on device (GPU)
  unsigned int *d_index;
  error_id = hipMalloc((void **) &d_index, LEN * sizeof(unsigned int));
  if (error_id != hipSuccess) {
    printf("Error from allocating indices array is %s\n", hipGetErrorString(error_id));
  }

  // data access latencies array on host (CPU)
  unsigned int *h_duration = (unsigned int*) malloc(LEN * sizeof(unsigned int));

  // data access latencies array on device (GPU)
  unsigned int *d_duration;
  error_id = hipMalloc ((void**) &d_duration, LEN * sizeof(unsigned int));
  if (error_id != hipSuccess) {
    printf("Error from allocating latencies array is %s\n", hipGetErrorString(error_id));
  }

  // blocks until the device has completed all preceding requested tasks
  hipDeviceSynchronize();

  // launch kernel
  dim3 Db = dim3(1);
  dim3 Dg = dim3(1,1,1);
  global_latency<<<Dg, Db>>>(d_a, N, iterations, d_duration, d_index);
  hipDeviceSynchronize();

  error_id = hipGetLastError();
  if (error_id != hipSuccess) {
    printf("Error from kernel is %s\n", hipGetErrorString(error_id));
  }
  hipDeviceSynchronize();

  // copy results from GPU to CPU
  error_id = hipMemcpy((void*) h_duration, (void*) d_duration, LEN * sizeof(unsigned int), hipMemcpyDeviceToHost);
  if (error_id != hipSuccess) {
    printf("Error 2.0 is %s\n", hipGetErrorString(error_id));
  }
  error_id = hipMemcpy((void*) h_index, (void*) d_index, LEN * sizeof(unsigned int), hipMemcpyDeviceToHost);
  if (error_id != hipSuccess) {
    printf("Error 2.1 is %s\n", hipGetErrorString(error_id));
  }
  hipDeviceSynchronize();

  for(int i = 0; i < LEN; i++) {
    printf("%d\n", h_duration[i]);
  }

  // free memory on GPU
  hipFree(d_a);
  hipFree(d_index);
  hipFree(d_duration);

  // free memory on CPU 

  free(h_a);
  free(h_index);
  free(h_duration);
  
  // destroy context
  hipDeviceReset();  
}

void measure_global() {
  int iterations = 10;
  
  // 2 MB stride
  int stride = 2*1024*1024/sizeof(unsigned int); 

  for (int N = 120*1024*256; N <= 150*1024*256; N += stride) {
    printf("\n=====%3.1f MB array, warm TLB, read 256 element====\n", sizeof(unsigned int)*(float)N/1024/1024);
    parametric_measure_global(N, iterations, stride);
    printf("===============================================\n\n");
  }
}

int main() {
  // current device
  hipSetDevice(0);

  measure_global();

  // destroy context
  hipDeviceReset();
  return 0;
}

	.text
	.file	"maxwell_tlb.hip"
	.globl	_Z29__device_stub__global_latencyPjiiS_S_ # -- Begin function _Z29__device_stub__global_latencyPjiiS_S_
	.type	_Z29__device_stub__global_latencyPjiiS_S_,@function
_Z29__device_stub__global_latencyPjiiS_S_: # @_Z29__device_stub__global_latencyPjiiS_S_
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.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	4(%rsp), %rdi
	movl	%esi, (%rdi)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z14global_latencyPjiiS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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	_Z29__device_stub__global_latencyPjiiS_S_, .Lfunc_end0-_Z29__device_stub__global_latencyPjiiS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z25parametric_measure_globaliii # -- Begin function _Z25parametric_measure_globaliii
	.type	_Z25parametric_measure_globaliii,@function
_Z25parametric_measure_globaliii:       # @_Z25parametric_measure_globaliii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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, %r15d
	movl	%esi, %ebp
	movl	%edi, %r12d
	callq	hipDeviceReset
	movslq	%r12d, %r13
	leaq	(,%r13,4), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %rbx
	testl	%r13d, %r13d
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%r12d, %ecx
	movl	%r15d, %esi
	xorl	%edi, %edi
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	leal	(%rsi,%rdi), %eax
	cltd
	idivl	%ecx
	movl	%edx, (%rbx,%rdi,4)
	incq	%rdi
	cmpq	%rdi, %rcx
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_5
# %bb.4:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_5:
	movq	16(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_7
# %bb.6:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_7:
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	movq	%rax, %r14
	leaq	8(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_9
# %bb.8:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_9:
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	movq	%rax, %r15
	movq	%rsp, %rdi
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_11
# %bb.10:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_11:
	callq	hipDeviceSynchronize
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_13
# %bb.12:
	movq	16(%rsp), %rdi
	movq	(%rsp), %rcx
	movq	8(%rsp), %r8
	movl	%r12d, %esi
	movl	%ebp, %edx
	callq	_Z29__device_stub__global_latencyPjiiS_S_
.LBB1_13:
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB1_15
# %bb.14:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_15:
	callq	hipDeviceSynchronize
	movq	(%rsp), %rsi
	movl	$1024, %edx                     # imm = 0x400
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_17
# %bb.16:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_17:
	movq	8(%rsp), %rsi
	movl	$1024, %edx                     # imm = 0x400
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_19
# %bb.18:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.6, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_19:
	callq	hipDeviceSynchronize
	xorl	%r12d, %r12d
.LBB1_20:                               # =>This Inner Loop Header: Depth=1
	movl	(%r15,%r12,4), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r12
	cmpq	$256, %r12                      # imm = 0x100
	jne	.LBB1_20
# %bb.21:
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	callq	hipDeviceReset
	addq	$24, %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_end1:
	.size	_Z25parametric_measure_globaliii, .Lfunc_end1-_Z25parametric_measure_globaliii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z14measure_globalv
.LCPI2_0:
	.long	0x40800000                      # float 4
.LCPI2_1:
	.long	0x3a800000                      # float 9.765625E-4
	.text
	.globl	_Z14measure_globalv
	.type	_Z14measure_globalv,@function
_Z14measure_globalv:                    # @_Z14measure_globalv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$30932992, %ebx                 # imm = 0x1D80000
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	addl	$524288, %ebx                   # imm = 0x80000
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	mulss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movl	%ebx, %edi
	movl	$10, %esi
	movl	$524288, %edx                   # imm = 0x80000
	callq	_Z25parametric_measure_globaliii
	movl	$.Lstr, %edi
	callq	puts@PLT
	cmpl	$38797313, %ebx                 # imm = 0x2500001
	jb	.LBB2_1
# %bb.2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z14measure_globalv, .Lfunc_end2-_Z14measure_globalv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	callq	hipSetDevice
	callq	_Z14measure_globalv
	callq	hipDeviceReset
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14global_latencyPjiiS_S_, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14global_latencyPjiiS_S_,@object # @_Z14global_latencyPjiiS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z14global_latencyPjiiS_S_
	.p2align	3, 0x0
_Z14global_latencyPjiiS_S_:
	.quad	_Z29__device_stub__global_latencyPjiiS_S_
	.size	_Z14global_latencyPjiiS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Error from allocating device array is %s\n"
	.size	.L.str, 42

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Error from copying over host array is %s\n"
	.size	.L.str.1, 42

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Error from allocating indices array is %s\n"
	.size	.L.str.2, 43

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Error from allocating latencies array is %s\n"
	.size	.L.str.3, 45

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Error from kernel is %s\n"
	.size	.L.str.4, 25

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

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

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\n=====%3.1f MB array, warm TLB, read 256 element====\n"
	.size	.L.str.8, 54

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14global_latencyPjiiS_S_"
	.size	.L__unnamed_1, 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	"===============================================\n"
	.size	.Lstr, 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 _Z29__device_stub__global_latencyPjiiS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14global_latencyPjiiS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14global_latencyPjiiS_S_ ; -- Begin function _Z14global_latencyPjiiS_S_
	.globl	_Z14global_latencyPjiiS_S_
	.p2align	8
	.type	_Z14global_latencyPjiiS_S_,@function
_Z14global_latencyPjiiS_S_:             ; @_Z14global_latencyPjiiS_S_
; %bb.0:
	v_mov_b32_e32 v0, 0
	s_mov_b32 s2, 0
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_mov_b32_e32 v1, s2
	s_add_i32 s2, s2, 4
	s_cmpk_eq_i32 s2, 0x400
	ds_store_2addr_stride64_b32 v1, v0, v0 offset1:4
	s_cbranch_scc0 .LBB0_1
; %bb.2:                                ; %.preheader33
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0xc
	s_load_b64 s[2:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s4, 1
	s_cbranch_scc1 .LBB0_5
; %bb.3:                                ; %.lr.ph.preheader
	s_lshl_b32 s4, s4, 8
	s_mov_b32 s5, 0
	s_max_i32 s6, s4, 1
	s_mov_b32 s4, s5
.LBB0_4:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_lshl_b64 s[8:9], s[4:5], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s8, s2, s8
	s_addc_u32 s9, s3, s9
	s_add_i32 s6, s6, -1
	s_load_b32 s4, s[8:9], 0x0
	s_cmp_lg_u32 s6, 0
	s_cbranch_scc1 .LBB0_4
	s_branch .LBB0_6
.LBB0_5:
	s_mov_b32 s4, 0
.LBB0_6:                                ; %.preheader32.preheader
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v0, s4 :: v_dual_mov_b32 v1, 0
	s_mov_b32 s4, 0
.LBB0_7:                                ; %.preheader32
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[0:1]
	s_getreg_b32 s5, hwreg(HW_REG_SHADER_CYCLES, 0, 20)
	v_add_co_u32 v2, vcc_lo, s2, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v3, vcc_lo
	global_load_b32 v0, v[2:3], off
	v_mov_b32_e32 v2, s4
	s_add_i32 s4, s4, 4
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v0
	s_getreg_b32 s6, hwreg(HW_REG_SHADER_CYCLES, 0, 20)
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s5, s6, s5
	s_cmpk_lg_i32 s4, 0x400
	v_mov_b32_e32 v3, s5
	ds_store_b32 v2, v3 offset:1024
	s_cbranch_scc1 .LBB0_7
; %bb.8:                                ; %.preheader.preheader
	s_load_b128 s[0:3], s[0:1], 0x10
	v_mov_b32_e32 v0, 0
	s_mov_b64 s[4:5], 0
	s_mov_b32 s6, 0
.LBB0_9:                                ; %.preheader
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v1, s6
	s_waitcnt lgkmcnt(0)
	s_add_u32 s8, s2, s4
	s_addc_u32 s9, s3, s5
	s_add_u32 s10, s0, s4
	s_addc_u32 s11, s1, s5
	ds_load_2addr_stride64_b32 v[1:2], v1 offset1:4
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_add_i32 s6, s6, 4
	s_cmpk_eq_i32 s4, 0x400
	s_waitcnt lgkmcnt(0)
	s_clause 0x1
	global_store_b32 v0, v1, s[8:9]
	global_store_b32 v0, v2, s[10:11]
	s_cbranch_scc0 .LBB0_9
; %bb.10:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14global_latencyPjiiS_S_
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.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 4
		.amdhsa_next_free_sgpr 12
		.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	_Z14global_latencyPjiiS_S_, .Lfunc_end0-_Z14global_latencyPjiiS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 352
; NumSgprs: 14
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 14
; NumVGPRsForWavesPerEU: 4
; 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:         12
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14global_latencyPjiiS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     14
    .sgpr_spill_count: 0
    .symbol:         _Z14global_latencyPjiiS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
