#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
#include <assert.h>
#define MAX_STREAMS 3

uint32_t *bufferA[MAX_STREAMS], *bufferB[MAX_STREAMS];
int flags[MAX_STREAMS] = {1,1,1};
int max_iteration = 10;
pthread_mutex_t lock;

inline
cudaError_t checkCuda(cudaError_t result)
{
  if (result != cudaSuccess) {
    fprintf(stderr, "CUDA Runtime Error: %s\n", 
            cudaGetErrorString(result));
    assert(result == cudaSuccess);
  }
  return result;
}

// Data initialization kernel
__global__ void init_data(uint32_t *buff, const int vector_size){
	int idx = threadIdx.x+blockDim.x*blockIdx.x;
	int my_idx = idx;
	while (my_idx < vector_size){
		buff[my_idx] = my_idx;
		my_idx += gridDim.x*blockDim.x; // grid-striding loop
	}
}

// Vector addition kernel
__global__ void vector_add(uint32_t *ibuff, uint32_t *obuff, const int vector_size){
	
	int idx = threadIdx.x+blockDim.x*blockIdx.x;
	int my_idx = idx;
	while (my_idx < vector_size){
		obuff[my_idx] = ibuff[my_idx] + ibuff[my_idx];
		my_idx += gridDim.x*blockDim.x; // grid-striding loop
	}
}

// Read/write controller thread
void *read_write_controller(void *){
	int i = 0;
	printf("Starting read_write_controller\n");
	while (i<max_iteration) {
		sleep(0.0001);
		if (flags[i%MAX_STREAMS] == 1){

			// Printing bufferA and bufferB element
			printf("A : %d\n",bufferA[i%MAX_STREAMS][1]);
			printf("B : %d\n",bufferB[i%MAX_STREAMS][1]);
			
			// updating flag (mutex protected)
			pthread_mutex_lock(&lock);
			flags[i%MAX_STREAMS] = 0;
			printf("iteration (%d) : [%d,%d,%d]\n",i,flags[0],flags[1],flags[2]);
			pthread_mutex_unlock(&lock);

			i++;
		}
	}
	return NULL;	
}

int main(){

	uint32_t *ibuff[MAX_STREAMS], *obuff[MAX_STREAMS];
	int result=0, device_id=0;
	int numBlocks, numThreadsPerBlock = 1024;
	int vector_size = 1024*1024;
	size_t size = vector_size*sizeof(uint32_t);

	cudaStream_t streams[MAX_STREAMS];
	for (int stream = 0; stream < MAX_STREAMS; stream++){
		cudaStreamCreate(&streams[stream]);
	}

	////////////////////////////////////////////////////////////////
	//               MEMORY ALLOCATION ON GPU
	////////////////////////////////////////////////////////////////
	
	printf("Memory allocation GPU\n");
	cudaDeviceGetAttribute (&result, cudaDevAttrConcurrentManagedAccess, device_id);
	for (int stream = 0; stream < MAX_STREAMS; stream++){
		checkCuda(cudaMallocManaged(&ibuff[stream],size));
		checkCuda(cudaMallocManaged(&obuff[stream],size));	
	
		if (result) {
			checkCuda(cudaMemAdvise(ibuff[stream],size,cudaMemAdviseSetPreferredLocation,device_id));
			checkCuda(cudaMemAdvise(obuff[stream],size,cudaMemAdviseSetPreferredLocation,device_id));
		}
		
		checkCuda(cudaMemset(ibuff[stream], 0, size));
		checkCuda(cudaMemset(obuff[stream], 0, size));
	}
	////////////////////////////////////////////////////////////////
	//               MEMORY ALLOCATION ON HOST
	////////////////////////////////////////////////////////////////
	
	printf("Memory allocation HOST\n");
	for (int stream = 0; stream < MAX_STREAMS; stream++){
		checkCuda(cudaHostAlloc(&bufferA[stream], size, cudaHostAllocDefault));
		checkCuda(cudaHostAlloc(&bufferB[stream], size, cudaHostAllocDefault));
	}
	
	for (int i = 0; i < vector_size; i++){
		for (int stream = 0; stream < MAX_STREAMS; stream++){
			bufferA[stream][i] = i + 1000*stream;
		}
	}
	
	///////////////////////////////////////////////////////////////
	//	 RUNNING READ/WRITE CONTROLLER ON SPECIFIC THREAD
	///////////////////////////////////////////////////////////////

	pthread_t thread;
	printf("Running thread \n");
	if (pthread_create(&thread, NULL, &read_write_controller, NULL)){
		fprintf(stderr, "Error creating thread \n");
		return 1;
	}
 	
	if (pthread_mutex_init(&lock, NULL) != 0){
        	printf("Mutex initialization failed.\n");
       	 	return 1;
	}

	///////////////////////////////////////////////////////////////
	//             RUNNING GPU KERNEL PIPELINING
	//////////////////////////////////////////////////////////////
	int stream =0;
	cudaDeviceGetAttribute(&numBlocks, cudaDevAttrMultiProcessorCount, 0);	
	
	for (int iteration = 0; iteration < max_iteration; iteration++){
		stream = iteration % MAX_STREAMS;	
		
		//FPGA is writing data in buffer
		while(flags[stream] == 1){ 
			sleep(0.0001);
		}
		cudaMemcpyAsync(ibuff[stream],bufferA[stream], size, cudaMemcpyDeviceToHost, streams[stream]);
		vector_add<<<4*numBlocks, numThreadsPerBlock,0,streams[stream]>>>(ibuff[stream],obuff[stream],vector_size);
		cudaMemcpyAsync(bufferB[stream], obuff[stream], size, cudaMemcpyHostToDevice, streams[stream]);
	   	
		// FPGA can write new data	
		pthread_mutex_lock(&lock);	
		flags[stream] = 1;
		pthread_mutex_unlock(&lock);
	}
	
	pthread_join(thread, NULL);
	printf("Completed %d iterations successfully\n", max_iteration);

	for (int i = 0; i < MAX_STREAMS; i++){
		cudaFreeHost(bufferA[i]);
		cudaFreeHost(bufferB[i]);
		cudaFree(ibuff[i]);
		cudaFree(obuff[i]);
	}
}

	.file	"tmpxft_00392809_00000000-6_read_write_stream.cudafe1.cpp"
	.text
#APP

	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Starting read_write_controller\n"
.LC1:
	.string	"A : %d\n"
.LC2:
	.string	"B : %d\n"
.LC3:
	.string	"iteration (%d) : [%d,%d,%d]\n"
#NO_APP
	.text
	.globl	_Z21read_write_controllerPv
	.type	_Z21read_write_controllerPv, @function
_Z21read_write_controllerPv:
.LFB2050:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	flags(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rsi
	.cfi_def_cfa_offset 48
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
.L2:
	movl	%ebx, %eax
	movl	$3, %ecx
	cltd
	idivl	%ecx
	movslq	%edx, %rbp
.L3:
	cmpl	max_iteration(%rip), %ebx
	jge	.L8
	xorl	%edi, %edi
	call	sleep@PLT
	cmpl	$1, 0(%r13,%rbp,4)
	jne	.L3
	leaq	bufferA(%rip), %rax
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	(%rax,%rbp,8), %rax
	leaq	lock(%rip), %r12
	movl	4(%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	bufferB(%rip), %rax
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	movq	(%rax,%rbp,8), %rax
	movl	4(%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	pthread_mutex_lock@PLT
	xorl	%ecx, %ecx
	movl	%ebx, %edx
	leaq	.LC3(%rip), %rsi
	movl	%ecx, 0(%r13,%rbp,4)
	movl	8+flags(%rip), %r9d
	xorl	%eax, %eax
	incl	%ebx
	movl	4+flags(%rip), %r8d
	movl	0(%r13), %ecx
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	pthread_mutex_unlock@PLT
	jmp	.L2
.L8:
	popq	%rdx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2050:
	.size	_Z21read_write_controllerPv, .-_Z21read_write_controllerPv
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2054:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2054:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1
.LC4:
	.string	"CUDA Runtime Error: %s\n"
	.text
	.type	_Z9checkCuda9cudaError.isra.0, @function
_Z9checkCuda9cudaError.isra.0:
.LFB2200:
	.cfi_startproc
	testl	%edi, %edi
	je	.L10
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	popq	%r8
	.cfi_def_cfa_offset 8
	movq	%rax, %rcx
	leaq	.LC4(%rip), %rdx
	xorl	%eax, %eax
	jmp	__fprintf_chk@PLT
.L10:
	ret
	.cfi_endproc
.LFE2200:
	.size	_Z9checkCuda9cudaError.isra.0, .-_Z9checkCuda9cudaError.isra.0
	.globl	_Z29__device_stub__Z9init_dataPjiPji
	.type	_Z29__device_stub__Z9init_dataPjiPji, @function
_Z29__device_stub__Z9init_dataPjiPji:
.LFB2076:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z9init_dataPji(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L15:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2076:
	.size	_Z29__device_stub__Z9init_dataPjiPji, .-_Z29__device_stub__Z9init_dataPjiPji
	.globl	_Z9init_dataPji
	.type	_Z9init_dataPji, @function
_Z9init_dataPji:
.LFB2077:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z9init_dataPjiPji
	.cfi_endproc
.LFE2077:
	.size	_Z9init_dataPji, .-_Z9init_dataPji
	.globl	_Z33__device_stub__Z10vector_addPjS_iPjS_i
	.type	_Z33__device_stub__Z10vector_addPjS_iPjS_i, @function
_Z33__device_stub__Z10vector_addPjS_iPjS_i:
.LFB2078:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%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	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%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	.L20
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z10vector_addPjS_i(%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
.L20:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2078:
	.size	_Z33__device_stub__Z10vector_addPjS_iPjS_i, .-_Z33__device_stub__Z10vector_addPjS_iPjS_i
	.globl	_Z10vector_addPjS_i
	.type	_Z10vector_addPjS_i, @function
_Z10vector_addPjS_i:
.LFB2079:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z10vector_addPjS_iPjS_i
	.cfi_endproc
.LFE2079:
	.size	_Z10vector_addPjS_i, .-_Z10vector_addPjS_i
	.section	.rodata.str1.1
.LC5:
	.string	"Memory allocation GPU\n"
.LC6:
	.string	"Memory allocation HOST\n"
.LC7:
	.string	"Running thread \n"
.LC8:
	.string	"Error creating thread \n"
.LC9:
	.string	"Mutex initialization failed.\n"
.LC10:
	.string	"Completed %d iterations successfully\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2051:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%edx, %edx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	112(%rsp), %rdi
	movl	%edx, 24(%rsp)
	leaq	88(%rsp), %rbp
	call	cudaStreamCreate@PLT
	leaq	120(%rsp), %rdi
	movq	%rbp, %r12
	movq	%rbp, %r14
	call	cudaStreamCreate@PLT
	leaq	128(%rsp), %rdi
	leaq	64(%rsp), %rbx
	call	cudaStreamCreate@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movq	%rbx, %r15
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	leaq	24(%rsp), %rdi
	xorl	%edx, %edx
	movl	$89, %esi
	call	cudaDeviceGetAttribute@PLT
.L27:
	movl	$1, %edx
	movl	$4194304, %esi
	movq	%rbx, %rdi
	call	cudaMallocManaged@PLT
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	movl	$1, %edx
	movl	$4194304, %esi
	movq	%rbp, %rdi
	call	cudaMallocManaged@PLT
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	cmpl	$0, 24(%rsp)
	je	.L26
	movq	(%rbx), %rdi
	xorl	%ecx, %ecx
	movl	$3, %edx
	movl	$4194304, %esi
	call	cudaMemAdvise@PLT
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	movq	0(%rbp), %rdi
	xorl	%ecx, %ecx
	movl	$3, %edx
	movl	$4194304, %esi
	call	cudaMemAdvise@PLT
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
.L26:
	movq	(%rbx), %rdi
	movl	$4194304, %edx
	xorl	%esi, %esi
	addq	$8, %rbx
	addq	$8, %rbp
	call	cudaMemset@PLT
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	movq	-8(%rbp), %rdi
	movl	$4194304, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	cmpq	%r12, %rbx
	jne	.L27
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	leaq	bufferA(%rip), %r12
.L28:
	leaq	(%rbx,%r12), %rdi
	xorl	%edx, %edx
	movl	$4194304, %esi
	call	cudaHostAlloc@PLT
	leaq	bufferB(%rip), %rbp
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	leaq	(%rbx,%rbp), %rdi
	xorl	%edx, %edx
	movl	$4194304, %esi
	call	cudaHostAlloc@PLT
	addq	$8, %rbx
	movl	%eax, %edi
	call	_Z9checkCuda9cudaError.isra.0
	cmpq	$24, %rbx
	jne	.L28
	movq	bufferA(%rip), %rdi
	movq	8+bufferA(%rip), %rsi
	xorl	%eax, %eax
	movq	16+bufferA(%rip), %rdx
.L29:
	leal	1000(%rax), %ecx
	movl	%eax, (%rdi,%rax,4)
	movl	%ecx, (%rsi,%rax,4)
	leal	2000(%rax), %ecx
	movl	%ecx, (%rdx,%rax,4)
	incq	%rax
	cmpq	$1048576, %rax
	jne	.L29
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	leaq	32(%rsp), %rdi
	leaq	_Z21read_write_controllerPv(%rip), %rdx
	call	pthread_create@PLT
	testl	%eax, %eax
	je	.L30
	movq	stderr(%rip), %rdi
	leaq	.LC8(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L31
.L30:
	xorl	%esi, %esi
	leaq	lock(%rip), %rdi
	call	pthread_mutex_init@PLT
	movl	%eax, 4(%rsp)
	testl	%eax, %eax
	je	.L32
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L31:
	movl	$1, 4(%rsp)
	jmp	.L25
.L32:
	leaq	28(%rsp), %rdi
	xorl	%edx, %edx
	movl	$16, %esi
	call	cudaDeviceGetAttribute@PLT
	xorl	%eax, %eax
	leaq	flags(%rip), %r13
	movl	%eax, (%rsp)
.L34:
	movl	(%rsp), %eax
	cmpl	%eax, max_iteration(%rip)
	jle	.L46
	movl	(%rsp), %eax
	movl	$3, %ecx
	cltd
	idivl	%ecx
	movl	%edx, 8(%rsp)
	movslq	%edx, %rbx
.L35:
	cmpl	$1, 0(%r13,%rbx,4)
	jne	.L47
	xorl	%edi, %edi
	call	sleep@PLT
	jmp	.L35
.L47:
	movq	(%r12,%rbx,8), %rsi
	movq	64(%rsp,%rbx,8), %rdi
	movl	$2, %ecx
	movl	$4194304, %edx
	movq	112(%rsp,%rbx,8), %r8
	call	cudaMemcpyAsync@PLT
	movl	28(%rsp), %eax
	movl	$4194305, %edx
	xorl	%r8d, %r8d
	movq	112(%rsp,%rbx,8), %r9
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, 60(%rsp)
	sall	$2, %eax
	movq	%rdx, 52(%rsp)
	movl	%eax, 40(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 44(%rsp)
	movq	40(%rsp), %rdi
	movl	48(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movq	88(%rsp,%rbx,8), %rsi
	movq	64(%rsp,%rbx,8), %rdi
	movl	$1048576, %edx
	call	_Z33__device_stub__Z10vector_addPjS_iPjS_i
.L37:
	movslq	8(%rsp), %r9
	movl	$1, %ecx
	movl	$4194304, %edx
	movq	88(%rsp,%r9,8), %rsi
	movq	0(%rbp,%r9,8), %rdi
	movq	%r9, 8(%rsp)
	movq	112(%rsp,%r9,8), %r8
	call	cudaMemcpyAsync@PLT
	leaq	lock(%rip), %rdi
	call	pthread_mutex_lock@PLT
	movq	8(%rsp), %r9
	leaq	lock(%rip), %rdi
	movl	$1, 0(%r13,%r9,4)
	call	pthread_mutex_unlock@PLT
	incl	(%rsp)
	jmp	.L34
.L46:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%ebx, %ebx
	call	pthread_join@PLT
	movl	max_iteration(%rip), %edx
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
.L39:
	movq	(%r12,%rbx), %rdi
	call	cudaFreeHost@PLT
	movq	0(%rbp,%rbx), %rdi
	call	cudaFreeHost@PLT
	movq	(%r15,%rbx), %rdi
	call	cudaFree@PLT
	movq	(%r14,%rbx), %rdi
	addq	$8, %rbx
	call	cudaFree@PLT
	cmpq	$24, %rbx
	jne	.L39
.L25:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	movl	4(%rsp), %eax
	addq	$152, %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
.LFE2051:
	.size	main, .-main
	.section	.rodata.str1.1
.LC11:
	.string	"_Z10vector_addPjS_i"
.LC12:
	.string	"_Z9init_dataPji"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2081:
	.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	.LC11(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10vector_addPjS_i(%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	.LC12(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z9init_dataPji(%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
.LFE2081:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	lock
	.bss
	.align 32
	.type	lock, @object
	.size	lock, 40
lock:
	.zero	40
	.globl	max_iteration
	.data
	.align 4
	.type	max_iteration, @object
	.size	max_iteration, 4
max_iteration:
	.long	10
	.globl	flags
	.align 8
	.type	flags, @object
	.size	flags, 12
flags:
	.long	1
	.long	1
	.long	1
	.globl	bufferB
	.bss
	.align 16
	.type	bufferB, @object
	.size	bufferB, 24
bufferB:
	.zero	24
	.globl	bufferA
	.align 16
	.type	bufferA, @object
	.size	bufferA, 24
bufferA:
	.zero	24
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
#include <assert.h>
#define MAX_STREAMS 3

uint32_t *bufferA[MAX_STREAMS], *bufferB[MAX_STREAMS];
int flags[MAX_STREAMS] = {1,1,1};
int max_iteration = 10;
pthread_mutex_t lock;

inline
hipError_t checkCuda(hipError_t result)
{
  if (result != hipSuccess) {
    fprintf(stderr, "CUDA Runtime Error: %s\n", 
            hipGetErrorString(result));
    assert(result == hipSuccess);
  }
  return result;
}

// Data initialization kernel
__global__ void init_data(uint32_t *buff, const int vector_size){
	int idx = threadIdx.x+blockDim.x*blockIdx.x;
	int my_idx = idx;
	while (my_idx < vector_size){
		buff[my_idx] = my_idx;
		my_idx += gridDim.x*blockDim.x; // grid-striding loop
	}
}

// Vector addition kernel
__global__ void vector_add(uint32_t *ibuff, uint32_t *obuff, const int vector_size){
	
	int idx = threadIdx.x+blockDim.x*blockIdx.x;
	int my_idx = idx;
	while (my_idx < vector_size){
		obuff[my_idx] = ibuff[my_idx] + ibuff[my_idx];
		my_idx += gridDim.x*blockDim.x; // grid-striding loop
	}
}

// Read/write controller thread
void *read_write_controller(void *){
	int i = 0;
	printf("Starting read_write_controller\n");
	while (i<max_iteration) {
		sleep(0.0001);
		if (flags[i%MAX_STREAMS] == 1){

			// Printing bufferA and bufferB element
			printf("A : %d\n",bufferA[i%MAX_STREAMS][1]);
			printf("B : %d\n",bufferB[i%MAX_STREAMS][1]);
			
			// updating flag (mutex protected)
			pthread_mutex_lock(&lock);
			flags[i%MAX_STREAMS] = 0;
			printf("iteration (%d) : [%d,%d,%d]\n",i,flags[0],flags[1],flags[2]);
			pthread_mutex_unlock(&lock);

			i++;
		}
	}
	return NULL;	
}

int main(){

	uint32_t *ibuff[MAX_STREAMS], *obuff[MAX_STREAMS];
	int result=0, device_id=0;
	int numBlocks, numThreadsPerBlock = 1024;
	int vector_size = 1024*1024;
	size_t size = vector_size*sizeof(uint32_t);

	hipStream_t streams[MAX_STREAMS];
	for (int stream = 0; stream < MAX_STREAMS; stream++){
		hipStreamCreate(&streams[stream]);
	}

	////////////////////////////////////////////////////////////////
	//               MEMORY ALLOCATION ON GPU
	////////////////////////////////////////////////////////////////
	
	printf("Memory allocation GPU\n");
	hipDeviceGetAttribute (&result, hipDeviceAttributeConcurrentManagedAccess, device_id);
	for (int stream = 0; stream < MAX_STREAMS; stream++){
		checkCuda(hipMallocManaged(&ibuff[stream],size));
		checkCuda(hipMallocManaged(&obuff[stream],size));	
	
		if (result) {
			checkCuda(hipMemAdvise(ibuff[stream],size,hipMemAdviseSetPreferredLocation,device_id));
			checkCuda(hipMemAdvise(obuff[stream],size,hipMemAdviseSetPreferredLocation,device_id));
		}
		
		checkCuda(hipMemset(ibuff[stream], 0, size));
		checkCuda(hipMemset(obuff[stream], 0, size));
	}
	////////////////////////////////////////////////////////////////
	//               MEMORY ALLOCATION ON HOST
	////////////////////////////////////////////////////////////////
	
	printf("Memory allocation HOST\n");
	for (int stream = 0; stream < MAX_STREAMS; stream++){
		checkCuda(hipHostAlloc(&bufferA[stream], size, hipHostMallocDefault));
		checkCuda(hipHostAlloc(&bufferB[stream], size, hipHostMallocDefault));
	}
	
	for (int i = 0; i < vector_size; i++){
		for (int stream = 0; stream < MAX_STREAMS; stream++){
			bufferA[stream][i] = i + 1000*stream;
		}
	}
	
	///////////////////////////////////////////////////////////////
	//	 RUNNING READ/WRITE CONTROLLER ON SPECIFIC THREAD
	///////////////////////////////////////////////////////////////

	pthread_t thread;
	printf("Running thread \n");
	if (pthread_create(&thread, NULL, &read_write_controller, NULL)){
		fprintf(stderr, "Error creating thread \n");
		return 1;
	}
 	
	if (pthread_mutex_init(&lock, NULL) != 0){
        	printf("Mutex initialization failed.\n");
       	 	return 1;
	}

	///////////////////////////////////////////////////////////////
	//             RUNNING GPU KERNEL PIPELINING
	//////////////////////////////////////////////////////////////
	int stream =0;
	hipDeviceGetAttribute(&numBlocks, hipDeviceAttributeMultiprocessorCount, 0);	
	
	for (int iteration = 0; iteration < max_iteration; iteration++){
		stream = iteration % MAX_STREAMS;	
		
		//FPGA is writing data in buffer
		while(flags[stream] == 1){ 
			sleep(0.0001);
		}
		hipMemcpyAsync(ibuff[stream],bufferA[stream], size, hipMemcpyDeviceToHost, streams[stream]);
		vector_add<<<4*numBlocks, numThreadsPerBlock,0,streams[stream]>>>(ibuff[stream],obuff[stream],vector_size);
		hipMemcpyAsync(bufferB[stream], obuff[stream], size, hipMemcpyHostToDevice, streams[stream]);
	   	
		// FPGA can write new data	
		pthread_mutex_lock(&lock);	
		flags[stream] = 1;
		pthread_mutex_unlock(&lock);
	}
	
	pthread_join(thread, NULL);
	printf("Completed %d iterations successfully\n", max_iteration);

	for (int i = 0; i < MAX_STREAMS; i++){
		hipHostFree(bufferA[i]);
		hipHostFree(bufferB[i]);
		hipFree(ibuff[i]);
		hipFree(obuff[i]);
	}
}

	.text
	.file	"read_write_stream.hip"
	.globl	_Z24__device_stub__init_dataPji # -- Begin function _Z24__device_stub__init_dataPji
	.type	_Z24__device_stub__init_dataPji,@function
_Z24__device_stub__init_dataPji:        # @_Z24__device_stub__init_dataPji
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z9init_dataPji, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z24__device_stub__init_dataPji, .Lfunc_end0-_Z24__device_stub__init_dataPji
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__vector_addPjS_i # -- Begin function _Z25__device_stub__vector_addPjS_i
	.type	_Z25__device_stub__vector_addPjS_i,@function
_Z25__device_stub__vector_addPjS_i:     # @_Z25__device_stub__vector_addPjS_i
	.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	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%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	$_Z10vector_addPjS_i, %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_end1:
	.size	_Z25__device_stub__vector_addPjS_i, .Lfunc_end1-_Z25__device_stub__vector_addPjS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z21read_write_controllerPv     # -- Begin function _Z21read_write_controllerPv
	.type	_Z21read_write_controllerPv,@function
_Z21read_write_controllerPv:            # @_Z21read_write_controllerPv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	cmpl	$0, max_iteration(%rip)
	jle	.LBB2_5
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorl	%edi, %edi
	callq	sleep
	movslq	%ebx, %rax
	imulq	$1431655766, %rax, %rcx         # imm = 0x55555556
	movq	%rcx, %rdx
	shrq	$63, %rdx
	shrq	$32, %rcx
	addl	%edx, %ecx
	leal	(%rcx,%rcx,2), %ecx
	subl	%ecx, %eax
	movslq	%eax, %r14
	cmpl	$1, flags(,%r14,4)
	jne	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movq	bufferA(,%r14,8), %rax
	movl	4(%rax), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	movq	bufferB(,%r14,8), %rax
	movl	4(%rax), %esi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$lock, %edi
	callq	pthread_mutex_lock
	movl	$0, flags(,%r14,4)
	movl	flags(%rip), %edx
	movl	flags+4(%rip), %ecx
	movl	flags+8(%rip), %r8d
	movl	$.L.str.3, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$lock, %edi
	callq	pthread_mutex_unlock
	incl	%ebx
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
	cmpl	max_iteration(%rip), %ebx
	jl	.LBB2_2
.LBB2_5:                                # %._crit_edge
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z21read_write_controllerPv, .Lfunc_end2-_Z21read_write_controllerPv
	.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	%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
	movl	$0, (%rsp)
	xorl	%ebx, %ebx
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	leaq	(%rsp,%rbx), %rdi
	addq	$16, %rdi
	callq	hipStreamCreate
	addq	$8, %rbx
	cmpq	$24, %rbx
	jne	.LBB3_1
# %bb.2:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	%rsp, %rdi
	movl	$9, %esi
	xorl	%edx, %edx
	callq	hipDeviceGetAttribute
	xorl	%r12d, %r12d
.LBB3_3:                                # =>This Inner Loop Header: Depth=1
	leaq	(%rsp,%r12), %r14
	addq	$80, %r14
	movl	$4194304, %esi                  # imm = 0x400000
	movq	%r14, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB3_11
.LBB3_4:                                # %_Z9checkCuda10hipError_t.exit
                                        #   in Loop: Header=BB3_3 Depth=1
	leaq	(%rsp,%r12), %rbx
	addq	$48, %rbx
	movl	$4194304, %esi                  # imm = 0x400000
	movq	%rbx, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB3_12
.LBB3_5:                                # %_Z9checkCuda10hipError_t.exit77
                                        #   in Loop: Header=BB3_3 Depth=1
	cmpl	$0, (%rsp)
	je	.LBB3_8
# %bb.6:                                #   in Loop: Header=BB3_3 Depth=1
	movq	(%r14), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	movl	$3, %edx
	xorl	%ecx, %ecx
	callq	hipMemAdvise
	testl	%eax, %eax
	jne	.LBB3_15
.LBB3_7:                                # %_Z9checkCuda10hipError_t.exit79
                                        #   in Loop: Header=BB3_3 Depth=1
	movq	(%rbx), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	movl	$3, %edx
	xorl	%ecx, %ecx
	callq	hipMemAdvise
	testl	%eax, %eax
	jne	.LBB3_16
.LBB3_8:                                # %_Z9checkCuda10hipError_t.exit81
                                        #   in Loop: Header=BB3_3 Depth=1
	movq	(%r14), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB3_13
.LBB3_9:                                # %_Z9checkCuda10hipError_t.exit83
                                        #   in Loop: Header=BB3_3 Depth=1
	movq	(%rbx), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB3_14
.LBB3_10:                               # %_Z9checkCuda10hipError_t.exit85
                                        #   in Loop: Header=BB3_3 Depth=1
	addq	$8, %r12
	cmpq	$24, %r12
	jne	.LBB3_3
	jmp	.LBB3_17
.LBB3_11:                               #   in Loop: Header=BB3_3 Depth=1
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_4
.LBB3_12:                               #   in Loop: Header=BB3_3 Depth=1
	movq	stderr(%rip), %r15
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%r15, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_5
.LBB3_13:                               #   in Loop: Header=BB3_3 Depth=1
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_9
.LBB3_14:                               #   in Loop: Header=BB3_3 Depth=1
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_10
.LBB3_15:                               #   in Loop: Header=BB3_3 Depth=1
	movq	stderr(%rip), %r15
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%r15, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_7
.LBB3_16:                               #   in Loop: Header=BB3_3 Depth=1
	movq	stderr(%rip), %r15
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%r15, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_8
.LBB3_17:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorl	%r14d, %r14d
.LBB3_18:                               # =>This Inner Loop Header: Depth=1
	leaq	bufferA(%r14), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	xorl	%edx, %edx
	callq	hipHostAlloc
	testl	%eax, %eax
	jne	.LBB3_21
.LBB3_19:                               # %_Z9checkCuda10hipError_t.exit87
                                        #   in Loop: Header=BB3_18 Depth=1
	leaq	bufferB(%r14), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	xorl	%edx, %edx
	callq	hipHostAlloc
	testl	%eax, %eax
	jne	.LBB3_22
.LBB3_20:                               # %_Z9checkCuda10hipError_t.exit89
                                        #   in Loop: Header=BB3_18 Depth=1
	addq	$8, %r14
	cmpq	$24, %r14
	jne	.LBB3_18
	jmp	.LBB3_23
.LBB3_21:                               #   in Loop: Header=BB3_18 Depth=1
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_19
.LBB3_22:                               #   in Loop: Header=BB3_18 Depth=1
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_20
.LBB3_23:                               # %.preheader.preheader
	xorl	%eax, %eax
.LBB3_24:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_25 Depth 2
	movq	$-24, %rcx
	movl	%eax, %edx
.LBB3_25:                               #   Parent Loop BB3_24 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	bufferA+24(%rcx), %rsi
	movl	%edx, (%rsi,%rax,4)
	addl	$1000, %edx                     # imm = 0x3E8
	addq	$8, %rcx
	jne	.LBB3_25
# %bb.26:                               #   in Loop: Header=BB3_24 Depth=1
	incq	%rax
	cmpq	$1048576, %rax                  # imm = 0x100000
	jne	.LBB3_24
# %bb.27:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	leaq	8(%rsp), %rdi
	movl	$_Z21read_write_controllerPv, %edx
	xorl	%esi, %esi
	xorl	%ecx, %ecx
	callq	pthread_create
	testl	%eax, %eax
	jne	.LBB3_42
# %bb.28:
	movl	$lock, %edi
	xorl	%esi, %esi
	callq	pthread_mutex_init
	testl	%eax, %eax
	je	.LBB3_31
# %bb.29:
	movl	$.Lstr.4, %edi
	callq	puts@PLT
.LBB3_30:                               # %.loopexit
	movl	$1, %ebx
	jmp	.LBB3_41
.LBB3_31:
	leaq	4(%rsp), %rdi
	xorl	%r14d, %r14d
	movl	$63, %esi
	xorl	%edx, %edx
	callq	hipDeviceGetAttribute
	cmpl	$0, max_iteration(%rip)
	jle	.LBB3_39
# %bb.32:                               # %.lr.ph104.preheader
	movabsq	$4294967296, %r15               # imm = 0x100000000
	movl	$2863311531, %r12d              # imm = 0xAAAAAAAB
	leaq	1024(%r15), %rbx
.LBB3_33:                               # %.lr.ph104
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_34 Depth 2
	movl	%r14d, %eax
	imulq	%r12, %rax
	shrq	$33, %rax
	leal	(%rax,%rax,2), %eax
	movl	%r14d, %r13d
	subl	%eax, %r13d
.LBB3_34:                               # %.lr.ph
                                        #   Parent Loop BB3_33 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpl	$1, flags(,%r13,4)
	jne	.LBB3_36
# %bb.35:                               # %.lr.ph
                                        #   in Loop: Header=BB3_34 Depth=2
	xorl	%edi, %edi
	callq	sleep
	jmp	.LBB3_34
.LBB3_36:                               # %._crit_edge
                                        #   in Loop: Header=BB3_33 Depth=1
	movq	80(%rsp,%r13,8), %rdi
	movq	bufferA(,%r13,8), %rsi
	movq	16(%rsp,%r13,8), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$2, %ecx
	callq	hipMemcpyAsync
	movl	4(%rsp), %edi
	shll	$2, %edi
	movq	16(%rsp,%r13,8), %r9
	orq	%r15, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_38
# %bb.37:                               #   in Loop: Header=BB3_33 Depth=1
	movq	80(%rsp,%r13,8), %rdi
	movq	48(%rsp,%r13,8), %rsi
	movl	$1048576, %edx                  # imm = 0x100000
	callq	_Z25__device_stub__vector_addPjS_i
.LBB3_38:                               #   in Loop: Header=BB3_33 Depth=1
	movq	bufferB(,%r13,8), %rdi
	movq	48(%rsp,%r13,8), %rsi
	movq	16(%rsp,%r13,8), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movl	$lock, %edi
	callq	pthread_mutex_lock
	movl	$1, flags(,%r13,4)
	movl	$lock, %edi
	callq	pthread_mutex_unlock
	incl	%r14d
	cmpl	max_iteration(%rip), %r14d
	jl	.LBB3_33
.LBB3_39:                               # %._crit_edge105
	movq	8(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	pthread_join
	movl	max_iteration(%rip), %esi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%r14d, %r14d
.LBB3_40:                               # =>This Inner Loop Header: Depth=1
	movq	bufferA(%r14), %rdi
	callq	hipHostFree
	movq	bufferB(%r14), %rdi
	callq	hipHostFree
	movq	80(%rsp,%r14), %rdi
	callq	hipFree
	movq	48(%rsp,%r14), %rdi
	callq	hipFree
	addq	$8, %r14
	cmpq	$24, %r14
	jne	.LBB3_40
.LBB3_41:                               # %.loopexit
	movl	%ebx, %eax
	addq	$112, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB3_42:
	.cfi_def_cfa_offset 160
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	movl	$23, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_30
.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:
	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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9init_dataPji, %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	$_Z10vector_addPjS_i, %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_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	bufferA,@object                 # @bufferA
	.bss
	.globl	bufferA
	.p2align	4, 0x0
bufferA:
	.zero	24
	.size	bufferA, 24

	.type	bufferB,@object                 # @bufferB
	.globl	bufferB
	.p2align	4, 0x0
bufferB:
	.zero	24
	.size	bufferB, 24

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

	.type	max_iteration,@object           # @max_iteration
	.globl	max_iteration
	.p2align	2, 0x0
max_iteration:
	.long	10                              # 0xa
	.size	max_iteration, 4

	.type	lock,@object                    # @lock
	.bss
	.globl	lock
	.p2align	3, 0x0
lock:
	.zero	40
	.size	lock, 40

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

	.type	_Z10vector_addPjS_i,@object     # @_Z10vector_addPjS_i
	.globl	_Z10vector_addPjS_i
	.p2align	3, 0x0
_Z10vector_addPjS_i:
	.quad	_Z25__device_stub__vector_addPjS_i
	.size	_Z10vector_addPjS_i, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"A : %d\n"
	.size	.L.str.1, 8

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"B : %d\n"
	.size	.L.str.2, 8

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"iteration (%d) : [%d,%d,%d]\n"
	.size	.L.str.3, 29

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Error creating thread \n"
	.size	.L.str.7, 24

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Completed %d iterations successfully\n"
	.size	.L.str.9, 38

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"CUDA Runtime Error: %s\n"
	.size	.L.str.10, 24

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z10vector_addPjS_i"
	.size	.L__unnamed_2, 20

	.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	"Starting read_write_controller"
	.size	.Lstr, 31

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Memory allocation GPU"
	.size	.Lstr.1, 22

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Memory allocation HOST"
	.size	.Lstr.2, 23

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Running thread "
	.size	.Lstr.3, 16

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Mutex initialization failed."
	.size	.Lstr.4, 29

	.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 _Z24__device_stub__init_dataPji
	.addrsig_sym _Z25__device_stub__vector_addPjS_i
	.addrsig_sym _Z21read_write_controllerPv
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym bufferA
	.addrsig_sym bufferB
	.addrsig_sym lock
	.addrsig_sym _Z9init_dataPji
	.addrsig_sym _Z10vector_addPjS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9init_dataPji         ; -- Begin function _Z9init_dataPji
	.globl	_Z9init_dataPji
	.p2align	8
	.type	_Z9init_dataPji,@function
_Z9init_dataPji:                        ; @_Z9init_dataPji
; %bb.0:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x1c
	s_load_b32 s4, s[0:1], 0x8
	s_add_u32 s2, s0, 16
	s_addc_u32 s3, s1, 0
	s_mov_b32 s6, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s5, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s5, v[0:1]
	v_cmpx_gt_i32_e64 s4, v1
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph
	s_load_b32 s2, s[2:3], 0x0
	s_load_b64 s[0:1], s[0:1], 0x0
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s2, s2, s5
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_store_b32 v[2:3], v1, off
	v_add_nc_u32_e32 v1, s2, v1
	v_cmp_le_i32_e32 vcc_lo, s4, v1
	s_or_b32 s3, vcc_lo, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s3
	s_cbranch_execnz .LBB0_2
.LBB0_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9init_dataPji
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z9init_dataPji, .Lfunc_end0-_Z9init_dataPji
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 172
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; 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
	.protected	_Z10vector_addPjS_i     ; -- Begin function _Z10vector_addPjS_i
	.globl	_Z10vector_addPjS_i
	.p2align	8
	.type	_Z10vector_addPjS_i,@function
_Z10vector_addPjS_i:                    ; @_Z10vector_addPjS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b32 s8, s[0:1], 0x10
	s_add_u32 s2, s0, 24
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s9, s4, 0xffff
	s_mov_b32 s4, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s9, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB1_3
; %bb.1:                                ; %.lr.ph
	s_load_b32 s2, s[2:3], 0x0
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s1, s2, s9
	s_mov_b32 s2, 0
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_nc_u32_e32 v1, s1, v1
	v_add_co_u32 v4, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	v_cmp_le_i32_e32 vcc_lo, s8, v1
	v_add_co_u32 v2, s0, s6, v2
	global_load_b32 v0, v[4:5], off
	v_add_co_ci_u32_e64 v3, s0, s7, v3, s0
	s_or_b32 s2, vcc_lo, s2
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v0, 1, v0
	global_store_b32 v[2:3], v0, off
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB1_2
.LBB1_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10vector_addPjS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z10vector_addPjS_i, .Lfunc_end1-_Z10vector_addPjS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 200
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; 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:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9init_dataPji
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9init_dataPji.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10vector_addPjS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10vector_addPjS_i.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
