#include <cuda.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>


#define NTYPES  3
#define MAXVARS 16



// Array counts by type
static int dcount=0;
static int fcount=0;
static int icount=0;


// CPU memory
double *dvec[MAXVARS];
float *fvec[MAXVARS];
int *ivec[MAXVARS];


// Host memory
double* devdVec[MAXVARS];
float* devfVec[MAXVARS];
int* deviVec[MAXVARS];



static dim3 ngrids;
static dim3 nblocks;
static dim3 nthreads;







void freeAllmem(){

     int i;

     printf("Freeing integer variables\n");
     for(i=0;i<=icount;i++){
         if(ivec[icount])free(ivec[icount]);
         if(deviVec[icount])free(deviVec[icount]);
     }

     printf("Freeing float variables\n");
     for(i=0;i<=fcount;i++){
         if(fvec[fcount])free(fvec[fcount]);
         if(devfVec[fcount])free(devfVec[fcount]);
     }

     printf("Freeing double variables\n");
     for(i=0;i<=dcount;i++){
	 if(dvec[dcount])free(dvec[dcount]);
	 if(devdVec[dcount])free(devdVec[dcount]);
     }

     printf("Done freeing memory...\n\n\n");
     return;
}




void init_kernel(int argc,...){
	
	


	int i;

	//Get device information
	int count;
	cudaGetDeviceCount(&count);
	cudaDeviceProp prop;
	cudaGetDeviceProperties(&prop,0);
	printf("\n\nCompute capability: %d.%d\n",prop.major,prop.minor);


	cudaError_t cudastatus0,cudastatus1;

	int arraysize;
	int typesizes[NTYPES]={sizeof(double),sizeof(float),sizeof(int)};
	int tnum=-1;
	
	// stdarg list vars
	int vindex;
	va_list	varlist;
	va_start(varlist,argc);


	for(vindex=0;vindex<argc/2;vindex++){
	   
	   tnum=va_arg(varlist,int);

	   if(tnum==0){
	   	   printf("......found a double.\n");
		   arraysize=va_arg(varlist,int);

		   dvec[dcount] = (double*) calloc(arraysize, typesizes[tnum]);

		   cudastatus0=cudaMalloc((void**)&devdVec[dcount],arraysize*typesizes[tnum]);
		   cudastatus1=cudaMemcpy(devdVec[dcount],dvec[dcount],arraysize*typesizes[tnum],
				cudaMemcpyHostToDevice);

		   // Error check
		   if(cudastatus0!=cudaSuccess|cudastatus1!=cudaSuccess){
			printf("Error in devdVec memory allocation:\nstatus0: %s\nstatus1: %s\n",
  				cudaGetErrorString(cudastatus0),
			        cudaGetErrorString(cudastatus1));
	 
			freeAllmem();
          	   	exit(EXIT_FAILURE);
	           }

		   // update double vector count
		   dcount++;
     		   printf("Allocated double variable of size: %d\n",arraysize);

	   }else if(tnum==1){
	   	   printf("......found a float.\n");
		   arraysize=va_arg(varlist,int);

		   fvec[fcount] = (float*) calloc(arraysize, typesizes[tnum]);

		   cudastatus0=cudaMalloc((void**)&devfVec[fcount],arraysize*typesizes[tnum]);
		   cudastatus1=cudaMemcpy(devfVec[fcount],fvec[fcount],arraysize*typesizes[tnum],
				cudaMemcpyHostToDevice);

		   // Error check
		   if(cudastatus0!=cudaSuccess|cudastatus1!=cudaSuccess){
			printf("Error in devfVec memory allocation:\nstatus0: %s\nstatus1: %s\n",
  				cudaGetErrorString(cudastatus0),
			        cudaGetErrorString(cudastatus1));

			freeAllmem();
          	   	exit(EXIT_FAILURE);
	           }
		   
		   // update float vector count
		   fcount++;
     		   printf("Allocated float variable of size: %d\n",arraysize);

	   }else if(tnum==2){
	   	   printf("......found an int.\n");
		   arraysize=va_arg(varlist,int);

		   ivec[icount] = (int*) calloc(arraysize, typesizes[tnum]);

		   cudastatus0=cudaMalloc((void**)&deviVec[icount],arraysize*typesizes[tnum]);
		   cudastatus1=cudaMemcpy(deviVec[icount],ivec[icount],arraysize*typesizes[tnum],
				cudaMemcpyHostToDevice);

		   // Error check
		   if(cudastatus0!=cudaSuccess|cudastatus1!=cudaSuccess){
			printf("Error in deviVec memory allocation:\nstatus0: %s\nstatus1: %s\n",
  				cudaGetErrorString(cudastatus0),
			        cudaGetErrorString(cudastatus1));

 			freeAllmem();
          	   	exit(EXIT_FAILURE);
	           }
		   
		   // update float vector count
		   icount++;
     		   printf("Allocated integer variable of size: %d\n",arraysize);

	   }else{
		   printf("Error, unknown datatype: %d.\n", tnum);
		   freeAllmem();
		   printf("Exiting on failure...\n\n\n");
		   exit(EXIT_FAILURE);
	   }

		    
	}//end for-loop

	va_end(varlist);
	

	return;

}


	.file	"tmpxft_00293f1d_00000000-6_init_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Freeing integer variables\n"
.LC1:
	.string	"Freeing float variables\n"
.LC2:
	.string	"Freeing double variables\n"
.LC3:
	.string	"Done freeing memory...\n\n\n"
	.text
	.globl	_Z10freeAllmemv
	.type	_Z10freeAllmemv, @function
_Z10freeAllmemv:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	ivec(%rip), %r12
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__printf_chk@PLT
.L3:
	movslq	_ZL6icount(%rip), %rbx
	cmpl	%ebp, %ebx
	jl	.L35
	movq	(%r12,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L4
	call	free@PLT
.L4:
	leaq	deviVec(%rip), %rax
	movq	(%rax,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L5
	call	free@PLT
.L5:
	incl	%ebp
	jmp	.L3
.L35:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
	leaq	fvec(%rip), %r12
.L7:
	movslq	_ZL6fcount(%rip), %rbx
	cmpl	%ebp, %ebx
	jl	.L36
	movq	(%r12,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L8
	call	free@PLT
.L8:
	leaq	devfVec(%rip), %rax
	movq	(%rax,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L9
	call	free@PLT
.L9:
	incl	%ebp
	jmp	.L7
.L36:
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
	leaq	dvec(%rip), %r12
.L11:
	movslq	_ZL6dcount(%rip), %rbx
	cmpl	%ebp, %ebx
	jl	.L37
	movq	(%r12,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L12
	call	free@PLT
.L12:
	leaq	devdVec(%rip), %rax
	movq	(%rax,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L13
	call	free@PLT
.L13:
	incl	%ebp
	jmp	.L11
.L37:
	popq	%rbx
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z10freeAllmemv, .-_Z10freeAllmemv
	.section	.rodata.str1.1
.LC4:
	.string	"\n\nCompute capability: %d.%d\n"
.LC5:
	.string	"......found a double.\n"
.LC6:
	.string	"Error in devdVec memory allocation:\nstatus0: %s\nstatus1: %s\n"
.LC7:
	.string	"Allocated double variable of size: %d\n"
.LC8:
	.string	"......found a float.\n"
.LC9:
	.string	"Error in devfVec memory allocation:\nstatus0: %s\nstatus1: %s\n"
.LC10:
	.string	"Allocated float variable of size: %d\n"
.LC11:
	.string	"......found an int.\n"
.LC12:
	.string	"Error in deviVec memory allocation:\nstatus0: %s\nstatus1: %s\n"
.LC13:
	.string	"Allocated integer variable of size: %d\n"
.LC14:
	.string	"Error, unknown datatype: %d.\n"
.LC15:
	.string	"Exiting on failure...\n\n\n"
	.text
	.globl	_Z11init_kerneliz
	.type	_Z11init_kerneliz, @function
_Z11init_kerneliz:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$1144, %rsp
	.cfi_def_cfa_offset 1200
	movq	%rdx, 1104(%rsp)
	leaq	20(%rsp), %rdi
	movq	%rcx, 1112(%rsp)
	movq	%r8, 1120(%rsp)
	movq	%r9, 1128(%rsp)
	movq	%rsi, 1096(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 1080(%rsp)
	xorl	%eax, %eax
	call	cudaGetDeviceCount@PLT
	leaq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	412(%rsp), %ecx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	408(%rsp), %edx
	leaq	.LC4(%rip), %rsi
	call	__printf_chk@PLT
	leaq	1200(%rsp), %rax
	movl	$2, %ecx
	movl	$8, 24(%rsp)
	movq	%rax, 32(%rsp)
	leaq	1088(%rsp), %rax
	movq	%rax, 40(%rsp)
	movl	%ebx, %eax
	cltd
	idivl	%ecx
	movl	%eax, 12(%rsp)
.L39:
	cmpl	%ebp, 12(%rsp)
	jle	.L61
	movl	24(%rsp), %edx
	cmpl	$47, %edx
	ja	.L40
	movl	%edx, %eax
	addl	$8, %edx
	addq	40(%rsp), %rax
	movl	%edx, 24(%rsp)
	jmp	.L41
.L40:
	movq	32(%rsp), %rax
	leaq	8(%rax), %rdx
	movq	%rdx, 32(%rsp)
.L41:
	movl	(%rax), %edx
	testl	%edx, %edx
	jne	.L42
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	24(%rsp), %edx
	cmpl	$47, %edx
	ja	.L43
	movl	%edx, %eax
	addl	$8, %edx
	addq	40(%rsp), %rax
	movl	%edx, 24(%rsp)
	jmp	.L44
.L43:
	movq	32(%rsp), %rax
	leaq	8(%rax), %rdx
	movq	%rdx, 32(%rsp)
.L44:
	movslq	(%rax), %rdi
	movl	_ZL6dcount(%rip), %r13d
	movl	$8, %esi
	leaq	devdVec(%rip), %rbx
	leaq	dvec(%rip), %r12
	movq	%rdi, %r14
	call	calloc@PLT
	leal	0(,%r14,8), %r15d
	movq	%rax, %rdx
	movslq	%r15d, %r15
	movslq	%r13d, %rax
	leaq	(%rbx,%rax,8), %rdi
	movq	%r15, %rsi
	movq	%rdx, (%r12,%rax,8)
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movq	%r15, %rdx
	movl	%eax, %r13d
	movslq	_ZL6dcount(%rip), %rax
	movq	(%rbx,%rax,8), %rdi
	movq	(%r12,%rax,8), %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	movl	%r13d, %eax
	orl	%edi, %eax
	je	.L45
	call	cudaGetErrorString@PLT
	movl	%r13d, %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rcx
	leaq	.LC6(%rip), %rsi
	movq	%rax, %rdx
	jmp	.L59
.L45:
	incl	_ZL6dcount(%rip)
	movl	%r14d, %edx
	leaq	.LC7(%rip), %rsi
	jmp	.L58
.L42:
	cmpl	$1, %edx
	jne	.L47
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	24(%rsp), %edx
	cmpl	$47, %edx
	ja	.L48
	movl	%edx, %eax
	addl	$8, %edx
	addq	40(%rsp), %rax
	movl	%edx, 24(%rsp)
	jmp	.L49
.L48:
	movq	32(%rsp), %rax
	leaq	8(%rax), %rdx
	movq	%rdx, 32(%rsp)
.L49:
	movslq	(%rax), %rdi
	movl	_ZL6fcount(%rip), %r13d
	movl	$4, %esi
	leaq	devfVec(%rip), %rbx
	leaq	fvec(%rip), %r12
	movq	%rdi, %r14
	call	calloc@PLT
	leal	0(,%r14,4), %r15d
	movq	%rax, %rdx
	movslq	%r15d, %r15
	movslq	%r13d, %rax
	leaq	(%rbx,%rax,8), %rdi
	movq	%r15, %rsi
	movq	%rdx, (%r12,%rax,8)
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movq	%r15, %rdx
	movl	%eax, %r13d
	movslq	_ZL6fcount(%rip), %rax
	movq	(%rbx,%rax,8), %rdi
	movq	(%r12,%rax,8), %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	movl	%r13d, %eax
	orl	%edi, %eax
	je	.L50
	call	cudaGetErrorString@PLT
	movl	%r13d, %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rcx
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdx
.L59:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	_Z10freeAllmemv
.L60:
	movl	$1, %edi
	call	exit@PLT
.L50:
	incl	_ZL6fcount(%rip)
	movl	%r14d, %edx
	leaq	.LC10(%rip), %rsi
	jmp	.L58
.L47:
	cmpl	$2, %edx
	jne	.L51
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	24(%rsp), %edx
	cmpl	$47, %edx
	ja	.L52
	movl	%edx, %eax
	addl	$8, %edx
	addq	40(%rsp), %rax
	movl	%edx, 24(%rsp)
	jmp	.L53
.L52:
	movq	32(%rsp), %rax
	leaq	8(%rax), %rdx
	movq	%rdx, 32(%rsp)
.L53:
	movslq	(%rax), %rdi
	movl	_ZL6icount(%rip), %r13d
	movl	$4, %esi
	leaq	deviVec(%rip), %r12
	leaq	ivec(%rip), %rbx
	movq	%rdi, %r14
	call	calloc@PLT
	leal	0(,%r14,4), %r15d
	movq	%rax, %rdx
	movslq	%r15d, %r15
	movslq	%r13d, %rax
	leaq	(%r12,%rax,8), %rdi
	movq	%r15, %rsi
	movq	%rdx, (%rbx,%rax,8)
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movq	%r15, %rdx
	movl	%eax, %r13d
	movslq	_ZL6icount(%rip), %rax
	movq	(%r12,%rax,8), %rdi
	movq	(%rbx,%rax,8), %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	movl	%r13d, %eax
	orl	%edi, %eax
	je	.L54
	call	cudaGetErrorString@PLT
	movl	%r13d, %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rcx
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdx
	jmp	.L59
.L54:
	incl	_ZL6icount(%rip)
	movl	%r14d, %edx
	leaq	.LC13(%rip), %rsi
.L58:
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebp
	call	__printf_chk@PLT
	jmp	.L39
.L51:
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	_Z10freeAllmemv
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L60
.L61:
	movq	1080(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$1144, %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
.LFE2028:
	.size	_Z11init_kerneliz, .-_Z11init_kerneliz
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.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	deviVec
	.bss
	.align 32
	.type	deviVec, @object
	.size	deviVec, 128
deviVec:
	.zero	128
	.globl	devfVec
	.align 32
	.type	devfVec, @object
	.size	devfVec, 128
devfVec:
	.zero	128
	.globl	devdVec
	.align 32
	.type	devdVec, @object
	.size	devdVec, 128
devdVec:
	.zero	128
	.globl	ivec
	.align 32
	.type	ivec, @object
	.size	ivec, 128
ivec:
	.zero	128
	.globl	fvec
	.align 32
	.type	fvec, @object
	.size	fvec, 128
fvec:
	.zero	128
	.globl	dvec
	.align 32
	.type	dvec, @object
	.size	dvec, 128
dvec:
	.zero	128
	.local	_ZL6icount
	.comm	_ZL6icount,4,4
	.local	_ZL6fcount
	.comm	_ZL6fcount,4,4
	.local	_ZL6dcount
	.comm	_ZL6dcount,4,4
	.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 <stdlib.h>
#include <string.h>
#include <stdarg.h>


#define NTYPES  3
#define MAXVARS 16



// Array counts by type
static int dcount=0;
static int fcount=0;
static int icount=0;


// CPU memory
double *dvec[MAXVARS];
float *fvec[MAXVARS];
int *ivec[MAXVARS];


// Host memory
double* devdVec[MAXVARS];
float* devfVec[MAXVARS];
int* deviVec[MAXVARS];



static dim3 ngrids;
static dim3 nblocks;
static dim3 nthreads;







void freeAllmem(){

     int i;

     printf("Freeing integer variables\n");
     for(i=0;i<=icount;i++){
         if(ivec[icount])free(ivec[icount]);
         if(deviVec[icount])free(deviVec[icount]);
     }

     printf("Freeing float variables\n");
     for(i=0;i<=fcount;i++){
         if(fvec[fcount])free(fvec[fcount]);
         if(devfVec[fcount])free(devfVec[fcount]);
     }

     printf("Freeing double variables\n");
     for(i=0;i<=dcount;i++){
	 if(dvec[dcount])free(dvec[dcount]);
	 if(devdVec[dcount])free(devdVec[dcount]);
     }

     printf("Done freeing memory...\n\n\n");
     return;
}




void init_kernel(int argc,...){
	
	


	int i;

	//Get device information
	int count;
	hipGetDeviceCount(&count);
	hipDeviceProp_t prop;
	hipGetDeviceProperties(&prop,0);
	printf("\n\nCompute capability: %d.%d\n",prop.major,prop.minor);


	hipError_t cudastatus0,cudastatus1;

	int arraysize;
	int typesizes[NTYPES]={sizeof(double),sizeof(float),sizeof(int)};
	int tnum=-1;
	
	// stdarg list vars
	int vindex;
	va_list	varlist;
	va_start(varlist,argc);


	for(vindex=0;vindex<argc/2;vindex++){
	   
	   tnum=va_arg(varlist,int);

	   if(tnum==0){
	   	   printf("......found a double.\n");
		   arraysize=va_arg(varlist,int);

		   dvec[dcount] = (double*) calloc(arraysize, typesizes[tnum]);

		   cudastatus0=hipMalloc((void**)&devdVec[dcount],arraysize*typesizes[tnum]);
		   cudastatus1=hipMemcpy(devdVec[dcount],dvec[dcount],arraysize*typesizes[tnum],
				hipMemcpyHostToDevice);

		   // Error check
		   if(cudastatus0!=hipSuccess|cudastatus1!=hipSuccess){
			printf("Error in devdVec memory allocation:\nstatus0: %s\nstatus1: %s\n",
  				hipGetErrorString(cudastatus0),
			        hipGetErrorString(cudastatus1));
	 
			freeAllmem();
          	   	exit(EXIT_FAILURE);
	           }

		   // update double vector count
		   dcount++;
     		   printf("Allocated double variable of size: %d\n",arraysize);

	   }else if(tnum==1){
	   	   printf("......found a float.\n");
		   arraysize=va_arg(varlist,int);

		   fvec[fcount] = (float*) calloc(arraysize, typesizes[tnum]);

		   cudastatus0=hipMalloc((void**)&devfVec[fcount],arraysize*typesizes[tnum]);
		   cudastatus1=hipMemcpy(devfVec[fcount],fvec[fcount],arraysize*typesizes[tnum],
				hipMemcpyHostToDevice);

		   // Error check
		   if(cudastatus0!=hipSuccess|cudastatus1!=hipSuccess){
			printf("Error in devfVec memory allocation:\nstatus0: %s\nstatus1: %s\n",
  				hipGetErrorString(cudastatus0),
			        hipGetErrorString(cudastatus1));

			freeAllmem();
          	   	exit(EXIT_FAILURE);
	           }
		   
		   // update float vector count
		   fcount++;
     		   printf("Allocated float variable of size: %d\n",arraysize);

	   }else if(tnum==2){
	   	   printf("......found an int.\n");
		   arraysize=va_arg(varlist,int);

		   ivec[icount] = (int*) calloc(arraysize, typesizes[tnum]);

		   cudastatus0=hipMalloc((void**)&deviVec[icount],arraysize*typesizes[tnum]);
		   cudastatus1=hipMemcpy(deviVec[icount],ivec[icount],arraysize*typesizes[tnum],
				hipMemcpyHostToDevice);

		   // Error check
		   if(cudastatus0!=hipSuccess|cudastatus1!=hipSuccess){
			printf("Error in deviVec memory allocation:\nstatus0: %s\nstatus1: %s\n",
  				hipGetErrorString(cudastatus0),
			        hipGetErrorString(cudastatus1));

 			freeAllmem();
          	   	exit(EXIT_FAILURE);
	           }
		   
		   // update float vector count
		   icount++;
     		   printf("Allocated integer variable of size: %d\n",arraysize);

	   }else{
		   printf("Error, unknown datatype: %d.\n", tnum);
		   freeAllmem();
		   printf("Exiting on failure...\n\n\n");
		   exit(EXIT_FAILURE);
	   }

		    
	}//end for-loop

	va_end(varlist);
	

	return;

}


	.text
	.file	"init_kernel.hip"
	.globl	_Z10freeAllmemv                 # -- Begin function _Z10freeAllmemv
	.type	_Z10freeAllmemv,@function
_Z10freeAllmemv:                        # @_Z10freeAllmemv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	_ZL6icount(%rip), %ebx
	testl	%ebx, %ebx
	js	.LBB0_7
# %bb.1:                                # %.lr.ph
	leal	1(%rbx), %ebp
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	ivec(,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB0_4
# %bb.3:                                #   in Loop: Header=BB0_2 Depth=1
	callq	free
.LBB0_4:                                #   in Loop: Header=BB0_2 Depth=1
	movq	deviVec(,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB0_6
# %bb.5:                                #   in Loop: Header=BB0_2 Depth=1
	callq	free
.LBB0_6:                                #   in Loop: Header=BB0_2 Depth=1
	decl	%ebp
	jne	.LBB0_2
.LBB0_7:                                # %._crit_edge
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	_ZL6fcount(%rip), %ebx
	testl	%ebx, %ebx
	js	.LBB0_14
# %bb.8:                                # %.lr.ph31
	leal	1(%rbx), %ebp
.LBB0_9:                                # =>This Inner Loop Header: Depth=1
	movq	fvec(,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB0_11
# %bb.10:                               #   in Loop: Header=BB0_9 Depth=1
	callq	free
.LBB0_11:                               #   in Loop: Header=BB0_9 Depth=1
	movq	devfVec(,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB0_13
# %bb.12:                               #   in Loop: Header=BB0_9 Depth=1
	callq	free
.LBB0_13:                               #   in Loop: Header=BB0_9 Depth=1
	decl	%ebp
	jne	.LBB0_9
.LBB0_14:                               # %._crit_edge32
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	_ZL6dcount(%rip), %ebx
	testl	%ebx, %ebx
	js	.LBB0_21
# %bb.15:                               # %.lr.ph36
	leal	1(%rbx), %ebp
.LBB0_16:                               # =>This Inner Loop Header: Depth=1
	movq	dvec(,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB0_18
# %bb.17:                               #   in Loop: Header=BB0_16 Depth=1
	callq	free
.LBB0_18:                               #   in Loop: Header=BB0_16 Depth=1
	movq	devdVec(,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB0_20
# %bb.19:                               #   in Loop: Header=BB0_16 Depth=1
	callq	free
.LBB0_20:                               #   in Loop: Header=BB0_16 Depth=1
	decl	%ebp
	jne	.LBB0_16
.LBB0_21:                               # %._crit_edge37
	movl	$.Lstr.3, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end0:
	.size	_Z10freeAllmemv, .Lfunc_end0-_Z10freeAllmemv
	.cfi_endproc
                                        # -- End function
	.globl	_Z11init_kerneliz               # -- Begin function _Z11init_kerneliz
	.type	_Z11init_kerneliz,@function
_Z11init_kerneliz:                      # @_Z11init_kerneliz
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$1688, %rsp                     # imm = 0x698
	.cfi_def_cfa_offset 1728
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edi, %ebx
	leaq	32(%rsp), %r15
	movq	%rsi, 8(%r15)
	movq	%rdx, 16(%r15)
	movq	%rcx, 24(%r15)
	movq	%r8, 32(%r15)
	movq	%r9, 40(%r15)
	testb	%al, %al
	je	.LBB1_2
# %bb.1:
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.LBB1_2:
	leaq	28(%rsp), %rdi
	callq	hipGetDeviceCount
	leaq	216(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	360(%r14), %esi
	movl	364(%r14), %edx
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%r15, 16(%rsp)
	leaq	1728(%rsp), %rax
	movq	%rax, 8(%rsp)
	movabsq	$206158430216, %rax             # imm = 0x3000000008
	movq	%rax, (%rsp)
	cmpl	$2, %ebx
	jl	.LBB1_26
# %bb.3:                                # %.lr.ph
	movl	%ebx, %r15d
	shrl	$31, %r15d
	addl	%ebx, %r15d
	sarl	%r15d
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movl	(%rsp), %ecx
	cmpq	$40, %rcx
	ja	.LBB1_6
# %bb.5:                                #   in Loop: Header=BB1_4 Depth=1
	movq	%rcx, %rax
	addq	16(%rsp), %rax
	addl	$8, %ecx
	movl	%ecx, (%rsp)
	jmp	.LBB1_7
.LBB1_6:                                #   in Loop: Header=BB1_4 Depth=1
	movq	8(%rsp), %rax
	leaq	8(%rax), %rcx
	movq	%rcx, 8(%rsp)
.LBB1_7:                                #   in Loop: Header=BB1_4 Depth=1
	movl	(%rax), %esi
	cmpl	$2, %esi
	je	.LBB1_14
# %bb.8:                                #   in Loop: Header=BB1_4 Depth=1
	cmpl	$1, %esi
	je	.LBB1_12
# %bb.9:                                #   in Loop: Header=BB1_4 Depth=1
	testl	%esi, %esi
	jne	.LBB1_27
# %bb.10:                               #   in Loop: Header=BB1_4 Depth=1
	movl	$.Lstr.7, %edi
	callq	puts@PLT
	movl	(%rsp), %ecx
	cmpq	$40, %rcx
	ja	.LBB1_22
# %bb.11:                               #   in Loop: Header=BB1_4 Depth=1
	movq	%rcx, %rax
	addq	16(%rsp), %rax
	addl	$8, %ecx
	movl	%ecx, (%rsp)
	jmp	.LBB1_23
.LBB1_12:                               #   in Loop: Header=BB1_4 Depth=1
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	movl	(%rsp), %ecx
	cmpq	$40, %rcx
	ja	.LBB1_16
# %bb.13:                               #   in Loop: Header=BB1_4 Depth=1
	movq	%rcx, %rax
	addq	16(%rsp), %rax
	addl	$8, %ecx
	movl	%ecx, (%rsp)
	jmp	.LBB1_17
.LBB1_14:                               #   in Loop: Header=BB1_4 Depth=1
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movl	(%rsp), %ecx
	cmpq	$40, %rcx
	ja	.LBB1_19
# %bb.15:                               #   in Loop: Header=BB1_4 Depth=1
	movq	%rcx, %rax
	addq	16(%rsp), %rax
	addl	$8, %ecx
	movl	%ecx, (%rsp)
	jmp	.LBB1_20
.LBB1_16:                               #   in Loop: Header=BB1_4 Depth=1
	movq	8(%rsp), %rax
	leaq	8(%rax), %rcx
	movq	%rcx, 8(%rsp)
.LBB1_17:                               #   in Loop: Header=BB1_4 Depth=1
	movl	(%rax), %ebx
	movslq	%ebx, %r14
	movl	$4, %esi
	movq	%r14, %rdi
	callq	calloc
	movslq	_ZL6fcount(%rip), %rcx
	movq	%rax, fvec(,%rcx,8)
	leaq	devfVec(,%rcx,8), %rdi
	shlq	$2, %r14
	movq	%r14, %rsi
	callq	hipMalloc
	movl	%eax, %ebp
	movslq	_ZL6fcount(%rip), %rax
	movq	devfVec(,%rax,8), %rdi
	movq	fvec(,%rax,8), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %r14d
	orl	%ebp, %eax
	jne	.LBB1_28
# %bb.18:                               #   in Loop: Header=BB1_4 Depth=1
	incl	_ZL6fcount(%rip)
	movl	$.L.str.10, %edi
	jmp	.LBB1_25
.LBB1_19:                               #   in Loop: Header=BB1_4 Depth=1
	movq	8(%rsp), %rax
	leaq	8(%rax), %rcx
	movq	%rcx, 8(%rsp)
.LBB1_20:                               #   in Loop: Header=BB1_4 Depth=1
	movl	(%rax), %ebx
	movslq	%ebx, %r14
	movl	$4, %esi
	movq	%r14, %rdi
	callq	calloc
	movslq	_ZL6icount(%rip), %rcx
	movq	%rax, ivec(,%rcx,8)
	leaq	deviVec(,%rcx,8), %rdi
	shlq	$2, %r14
	movq	%r14, %rsi
	callq	hipMalloc
	movl	%eax, %ebp
	movslq	_ZL6icount(%rip), %rax
	movq	deviVec(,%rax,8), %rdi
	movq	ivec(,%rax,8), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %r14d
	orl	%ebp, %eax
	jne	.LBB1_29
# %bb.21:                               #   in Loop: Header=BB1_4 Depth=1
	incl	_ZL6icount(%rip)
	movl	$.L.str.13, %edi
	jmp	.LBB1_25
.LBB1_22:                               #   in Loop: Header=BB1_4 Depth=1
	movq	8(%rsp), %rax
	leaq	8(%rax), %rcx
	movq	%rcx, 8(%rsp)
.LBB1_23:                               #   in Loop: Header=BB1_4 Depth=1
	movl	(%rax), %ebx
	movslq	%ebx, %r14
	movl	$8, %esi
	movq	%r14, %rdi
	callq	calloc
	movslq	_ZL6dcount(%rip), %rcx
	movq	%rax, dvec(,%rcx,8)
	leaq	devdVec(,%rcx,8), %rdi
	shlq	$3, %r14
	movq	%r14, %rsi
	callq	hipMalloc
	movl	%eax, %ebp
	movslq	_ZL6dcount(%rip), %rax
	movq	devdVec(,%rax,8), %rdi
	movq	dvec(,%rax,8), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %r14d
	orl	%ebp, %eax
	jne	.LBB1_30
# %bb.24:                               #   in Loop: Header=BB1_4 Depth=1
	incl	_ZL6dcount(%rip)
	movl	$.L.str.7, %edi
.LBB1_25:                               #   in Loop: Header=BB1_4 Depth=1
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	decl	%r15d
	jne	.LBB1_4
.LBB1_26:                               # %._crit_edge
	addq	$1688, %rsp                     # imm = 0x698
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_27:
	.cfi_def_cfa_offset 1728
	movl	$.L.str.14, %edi
	xorl	%eax, %eax
	callq	printf
	callq	_Z10freeAllmemv
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	jmp	.LBB1_32
.LBB1_28:
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%rax, %rbx
	movl	%r14d, %edi
	callq	hipGetErrorString
	movl	$.L.str.9, %edi
	jmp	.LBB1_31
.LBB1_29:
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%rax, %rbx
	movl	%r14d, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %edi
	jmp	.LBB1_31
.LBB1_30:
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%rax, %rbx
	movl	%r14d, %edi
	callq	hipGetErrorString
	movl	$.L.str.6, %edi
.LBB1_31:
	movq	%rbx, %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
	callq	_Z10freeAllmemv
.LBB1_32:
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z11init_kerneliz, .Lfunc_end1-_Z11init_kerneliz
	.cfi_endproc
                                        # -- End function
	.type	dvec,@object                    # @dvec
	.bss
	.globl	dvec
	.p2align	4, 0x0
dvec:
	.zero	128
	.size	dvec, 128

	.type	fvec,@object                    # @fvec
	.globl	fvec
	.p2align	4, 0x0
fvec:
	.zero	128
	.size	fvec, 128

	.type	ivec,@object                    # @ivec
	.globl	ivec
	.p2align	4, 0x0
ivec:
	.zero	128
	.size	ivec, 128

	.type	devdVec,@object                 # @devdVec
	.globl	devdVec
	.p2align	4, 0x0
devdVec:
	.zero	128
	.size	devdVec, 128

	.type	devfVec,@object                 # @devfVec
	.globl	devfVec
	.p2align	4, 0x0
devfVec:
	.zero	128
	.size	devfVec, 128

	.type	deviVec,@object                 # @deviVec
	.globl	deviVec
	.p2align	4, 0x0
deviVec:
	.zero	128
	.size	deviVec, 128

	.type	_ZL6icount,@object              # @_ZL6icount
	.local	_ZL6icount
	.comm	_ZL6icount,4,4
	.type	_ZL6fcount,@object              # @_ZL6fcount
	.local	_ZL6fcount
	.comm	_ZL6fcount,4,4
	.type	_ZL6dcount,@object              # @_ZL6dcount
	.local	_ZL6dcount
	.comm	_ZL6dcount,4,4
	.type	.L.str.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"\n\nCompute capability: %d.%d\n"
	.size	.L.str.4, 29

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error in devdVec memory allocation:\nstatus0: %s\nstatus1: %s\n"
	.size	.L.str.6, 61

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Allocated double variable of size: %d\n"
	.size	.L.str.7, 39

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Error in devfVec memory allocation:\nstatus0: %s\nstatus1: %s\n"
	.size	.L.str.9, 61

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Allocated float variable of size: %d\n"
	.size	.L.str.10, 38

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Error in deviVec memory allocation:\nstatus0: %s\nstatus1: %s\n"
	.size	.L.str.12, 61

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Allocated integer variable of size: %d\n"
	.size	.L.str.13, 40

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Error, unknown datatype: %d.\n"
	.size	.L.str.14, 30

	.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	"Freeing integer variables"
	.size	.Lstr, 26

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Freeing float variables"
	.size	.Lstr.1, 24

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Freeing double variables"
	.size	.Lstr.2, 25

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Done freeing memory...\n\n"
	.size	.Lstr.3, 25

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Exiting on failure...\n\n"
	.size	.Lstr.4, 24

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"......found an int."
	.size	.Lstr.5, 20

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"......found a float."
	.size	.Lstr.6, 21

	.type	.Lstr.7,@object                 # @str.7
.Lstr.7:
	.asciz	"......found a double."
	.size	.Lstr.7, 22

	.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 devdVec
	.addrsig_sym devfVec
	.addrsig_sym deviVec
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
