#include<math.h>
#include<time.h>
#include<stdexcept>
#include<iostream>
#include<cstdlib> //for abs(x)
#include<stdio.h>

using namespace std;



__global__ void kernel_multiplication( int* A,  int* B, int* C,int N,int M);


int main()
{
	int NUMBER_OF_ELEMENTS;
	int VECTOR_SIZE;
	cout<<"Enter the vector size:";
	cin>>VECTOR_SIZE;
	NUMBER_OF_ELEMENTS=VECTOR_SIZE;
	int SIZE  = NUMBER_OF_ELEMENTS*sizeof(int);


	cudaEvent_t start,end,start1,end1;

	int* hostA = (int*)malloc(VECTOR_SIZE*sizeof(int));
	int* hostB = (int*)malloc(SIZE*VECTOR_SIZE*sizeof(int));
	int* hostC = (int*)malloc(VECTOR_SIZE*sizeof(int));

	int* deviceA,*deviceB,*deviceC;

	srand(time(0));
	int i,j;

	cout<<"\nVector:\n";
	for(i=0;i<VECTOR_SIZE;i++)
	{
		hostA[i] = rand()%VECTOR_SIZE;	
		cout<<hostA[i]<<"\t";
	}

	//initialize matrix by random elements
	for(i=0;i<NUMBER_OF_ELEMENTS;i++)
	{
		for(j=0;j<VECTOR_SIZE;j++)
		{
			hostB[i*VECTOR_SIZE+j] = rand()%VECTOR_SIZE;
		}
	}

	cout<<"\nMatrix=\n";
	for(i=0;i<NUMBER_OF_ELEMENTS;i++)
	{
		for(j=0;j<VECTOR_SIZE;j++)
		{
			cout<<hostB[i*VECTOR_SIZE+j]<<"\t";
		}
		cout<<"\n";
	}

	cudaMalloc(&deviceA,VECTOR_SIZE*sizeof(int));
	cudaMalloc(&deviceB,NUMBER_OF_ELEMENTS*VECTOR_SIZE*sizeof(int));
	cudaMalloc(&deviceC,VECTOR_SIZE*sizeof(int));

	cudaEventCreate(&start);
	cudaEventCreate(&end);
	cudaEventCreate(&start1);
	cudaEventCreate(&end1);

	cudaEventRecord(start);
	cudaMemcpy(deviceA,hostA,VECTOR_SIZE*sizeof(int),cudaMemcpyHostToDevice);
	cudaMemcpy(deviceB,hostB,SIZE*VECTOR_SIZE,cudaMemcpyHostToDevice);
	kernel_multiplication<<<NUMBER_OF_ELEMENTS,1>>>(deviceA,deviceB,deviceC,NUMBER_OF_ELEMENTS,VECTOR_SIZE);
	cudaDeviceSynchronize();
    cudaMemcpy(hostC,deviceC,VECTOR_SIZE*sizeof(int),cudaMemcpyDeviceToHost);
    cudaEventRecord(end);
    cudaEventSynchronize(end);
	float t=0;
	cudaEventElapsedTime(&t,start,end);


	cudaFree(deviceA);
	cudaFree(deviceB);
	cudaFree(deviceC);

	double error = 0;

    int* answer = (int*) malloc(VECTOR_SIZE*sizeof(int));

    cudaEventRecord(start1);
	for(int i=0;i<NUMBER_OF_ELEMENTS;i++)
	{
		int sum = 0;
		for(int j=0;j<VECTOR_SIZE;j++)
		{
			sum += hostA[j]*hostB[j*VECTOR_SIZE+i];
		}
		answer[i] = sum;
	}

	for(int k=0;k<VECTOR_SIZE;k++)
	{
		cout<<k<<")"<< "Expected value = "<<answer[k]<<" Actual value = "<<hostC[k]<<"\n";
		error += double(abs(answer[k]-hostC[k]));
	}

	error=sqrt(error);
	cout<<"error = "<<error<<"\n";
	cudaEventRecord(end1);
    cudaEventSynchronize(end1);
	float t1=0;
	cudaEventElapsedTime(&t1,start1,end1);

	cout<<"\nSequential time="<<t1;
	cout<<"\nParallel time="<<t<<endl;

	delete[] hostA;
    delete[] hostB;
    delete[] hostC;
    return cudaDeviceSynchronize();

}

__global__ void kernel_multiplication( int* A,  int* B, int* C, int N,int M)
{
	int index =  threadIdx.x + blockIdx.x * blockDim.x;
	int sum = 0;
	if(index<N)
	{
		for(int i=0;i<M;i++)
		sum+=A[i]*B[(i*M)+index];
		C[index] = sum;
	}
}
	.file	"tmpxft_0021250a_00000000-6_vectmul.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii
	.type	_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii, @function
_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii:
.LFB3660:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%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	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%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	_Z21kernel_multiplicationPiS_S_ii(%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
.LFE3660:
	.size	_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii, .-_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii
	.globl	_Z21kernel_multiplicationPiS_S_ii
	.type	_Z21kernel_multiplicationPiS_S_ii, @function
_Z21kernel_multiplicationPiS_S_ii:
.LFB3661:
	.cfi_startproc
	endbr64
	jmp	_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii
	.cfi_endproc
.LFE3661:
	.size	_Z21kernel_multiplicationPiS_S_ii, .-_Z21kernel_multiplicationPiS_S_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Enter the vector size:"
.LC2:
	.string	"\nVector:\n"
.LC3:
	.string	"\t"
.LC4:
	.string	"\nMatrix=\n"
.LC5:
	.string	"\n"
.LC7:
	.string	")"
.LC8:
	.string	"Expected value = "
.LC9:
	.string	" Actual value = "
.LC10:
	.string	"error = "
.LC11:
	.string	"\nSequential time="
.LC12:
	.string	"\nParallel time="
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC1(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	xorl	%r15d, %r15d
	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	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	20(%rsp), %rsi
	leaq	_ZSt3cin(%rip), %rdi
	call	_ZNSirsERi@PLT
	movslq	20(%rsp), %r12
	movq	%r12, %rbx
	leal	0(,%r12,4), %r14d
	salq	$2, %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movl	%ebx, %edi
	imull	%r14d, %edi
	movq	%rax, %r13
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	xorl	%edi, %edi
	movq	%rax, %r12
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L9:
	cmpl	%r15d, 20(%rsp)
	jle	.L40
	call	rand@PLT
	leaq	_ZSt4cout(%rip), %rdi
	cltd
	idivl	20(%rsp)
	movl	%edx, 0(%r13,%r15,4)
	movl	%edx, %esi
	incq	%r15
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L9
.L40:
	xorl	%r15d, %r15d
.L11:
	cmpl	%ebx, %r15d
	jge	.L41
	xorl	%esi, %esi
.L13:
	cmpl	%esi, 20(%rsp)
	jle	.L42
	movl	%esi, 8(%rsp)
	call	rand@PLT
	movl	20(%rsp), %edi
	movl	8(%rsp), %esi
	cltd
	idivl	%edi
	movl	%edi, %ecx
	imull	%r15d, %ecx
	addl	%esi, %ecx
	incl	%esi
	movslq	%ecx, %rcx
	movl	%edx, 0(%rbp,%rcx,4)
	jmp	.L13
.L42:
	incl	%r15d
	jmp	.L11
.L41:
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	xorl	%r15d, %r15d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L14:
	cmpl	%ebx, %r15d
	jge	.L43
	xorl	%edx, %edx
.L16:
	movl	20(%rsp), %eax
	cmpl	%edx, %eax
	jle	.L44
	imull	%r15d, %eax
	leaq	_ZSt4cout(%rip), %rdi
	movl	%edx, 8(%rsp)
	addl	%edx, %eax
	cltq
	movl	0(%rbp,%rax,4), %esi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	8(%rsp), %edx
	incl	%edx
	jmp	.L16
.L44:
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incl	%r15d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L14
.L43:
	movslq	20(%rsp), %rsi
	leaq	56(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	20(%rsp), %esi
	leaq	64(%rsp), %rdi
	imull	%ebx, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	20(%rsp), %rsi
	leaq	72(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movslq	20(%rsp), %rdx
	movq	56(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	imull	20(%rsp), %r14d
	movq	64(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movslq	%r14d, %rdx
	call	cudaMemcpy@PLT
	movl	%ebx, 80(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdx
	movl	$1, %ecx
	movl	$1, 100(%rsp)
	movq	%rdx, 84(%rsp)
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	movq	%rdx, 92(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movl	20(%rsp), %r8d
	movq	72(%rsp), %rdx
	movl	%ebx, %ecx
	movq	64(%rsp), %rsi
	movq	56(%rsp), %rdi
	call	_Z47__device_stub__Z21kernel_multiplicationPiS_S_iiPiS_S_ii
.L17:
	call	cudaDeviceSynchronize@PLT
	movslq	20(%rsp), %rdx
	movq	72(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	80(%rsp), %rdi
	movl	$0x00000000, 80(%rsp)
	call	cudaEventElapsedTime@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movslq	20(%rsp), %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %r14
	call	cudaEventRecord@PLT
	movslq	20(%rsp), %rdi
	xorl	%eax, %eax
	movq	%rdi, %r9
	salq	$2, %rdi
.L18:
	cmpl	%eax, %ebx
	jle	.L29
	leaq	0(%rbp,%rax,4), %rsi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.L21:
	cmpl	%edx, %r9d
	jle	.L45
	movl	0(%r13,%rdx,4), %r8d
	imull	(%rsi), %r8d
	incq	%rdx
	addq	%rdi, %rsi
	addl	%r8d, %ecx
	jmp	.L21
.L45:
	movl	%ecx, (%r14,%rax,4)
	incq	%rax
	jmp	.L18
.L29:
	xorl	%r15d, %r15d
	xorps	%xmm0, %xmm0
.L20:
	movl	%r15d, %esi
	cmpl	%r15d, 20(%rsp)
	jle	.L46
	leaq	_ZSt4cout(%rip), %rdi
	movsd	%xmm0, 8(%rsp)
	call	_ZNSolsEi@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%r14,%r15,4), %ebx
	movq	%rax, %rdi
	movl	%ebx, %esi
	call	_ZNSolsEi@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%r12,%r15,4), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %eax
	subl	(%r12,%r15,4), %eax
	movsd	8(%rsp), %xmm0
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	incq	%r15
	cvtsi2sdl	%eax, %xmm1
	addsd	%xmm1, %xmm0
	jmp	.L20
.L46:
	call	sqrt@PLT
	leaq	.LC10(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movsd	%xmm0, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	92(%rsp), %rdi
	movl	$0x00000000, 92(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC11(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	92(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC12(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	80(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	testq	%r13, %r13
	je	.L23
	movq	%r13, %rdi
	call	_ZdaPv@PLT
.L23:
	testq	%rbp, %rbp
	je	.L24
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
.L24:
	testq	%r12, %r12
	je	.L25
	movq	%r12, %rdi
	call	_ZdaPv@PLT
.L25:
	call	cudaDeviceSynchronize@PLT
	movq	104(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$120, %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
.LFE3635:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z21kernel_multiplicationPiS_S_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3663:
	.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	.LC13(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z21kernel_multiplicationPiS_S_ii(%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
.LFE3663:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include<math.h>
#include<time.h>
#include<stdexcept>
#include<iostream>
#include<cstdlib> //for abs(x)
#include<stdio.h>

using namespace std;



__global__ void kernel_multiplication( int* A,  int* B, int* C,int N,int M);


int main()
{
	int NUMBER_OF_ELEMENTS;
	int VECTOR_SIZE;
	cout<<"Enter the vector size:";
	cin>>VECTOR_SIZE;
	NUMBER_OF_ELEMENTS=VECTOR_SIZE;
	int SIZE  = NUMBER_OF_ELEMENTS*sizeof(int);


	hipEvent_t start,end,start1,end1;

	int* hostA = (int*)malloc(VECTOR_SIZE*sizeof(int));
	int* hostB = (int*)malloc(SIZE*VECTOR_SIZE*sizeof(int));
	int* hostC = (int*)malloc(VECTOR_SIZE*sizeof(int));

	int* deviceA,*deviceB,*deviceC;

	srand(time(0));
	int i,j;

	cout<<"\nVector:\n";
	for(i=0;i<VECTOR_SIZE;i++)
	{
		hostA[i] = rand()%VECTOR_SIZE;	
		cout<<hostA[i]<<"\t";
	}

	//initialize matrix by random elements
	for(i=0;i<NUMBER_OF_ELEMENTS;i++)
	{
		for(j=0;j<VECTOR_SIZE;j++)
		{
			hostB[i*VECTOR_SIZE+j] = rand()%VECTOR_SIZE;
		}
	}

	cout<<"\nMatrix=\n";
	for(i=0;i<NUMBER_OF_ELEMENTS;i++)
	{
		for(j=0;j<VECTOR_SIZE;j++)
		{
			cout<<hostB[i*VECTOR_SIZE+j]<<"\t";
		}
		cout<<"\n";
	}

	hipMalloc(&deviceA,VECTOR_SIZE*sizeof(int));
	hipMalloc(&deviceB,NUMBER_OF_ELEMENTS*VECTOR_SIZE*sizeof(int));
	hipMalloc(&deviceC,VECTOR_SIZE*sizeof(int));

	hipEventCreate(&start);
	hipEventCreate(&end);
	hipEventCreate(&start1);
	hipEventCreate(&end1);

	hipEventRecord(start);
	hipMemcpy(deviceA,hostA,VECTOR_SIZE*sizeof(int),hipMemcpyHostToDevice);
	hipMemcpy(deviceB,hostB,SIZE*VECTOR_SIZE,hipMemcpyHostToDevice);
	kernel_multiplication<<<NUMBER_OF_ELEMENTS,1>>>(deviceA,deviceB,deviceC,NUMBER_OF_ELEMENTS,VECTOR_SIZE);
	hipDeviceSynchronize();
    hipMemcpy(hostC,deviceC,VECTOR_SIZE*sizeof(int),hipMemcpyDeviceToHost);
    hipEventRecord(end);
    hipEventSynchronize(end);
	float t=0;
	hipEventElapsedTime(&t,start,end);


	hipFree(deviceA);
	hipFree(deviceB);
	hipFree(deviceC);

	double error = 0;

    int* answer = (int*) malloc(VECTOR_SIZE*sizeof(int));

    hipEventRecord(start1);
	for(int i=0;i<NUMBER_OF_ELEMENTS;i++)
	{
		int sum = 0;
		for(int j=0;j<VECTOR_SIZE;j++)
		{
			sum += hostA[j]*hostB[j*VECTOR_SIZE+i];
		}
		answer[i] = sum;
	}

	for(int k=0;k<VECTOR_SIZE;k++)
	{
		cout<<k<<")"<< "Expected value = "<<answer[k]<<" Actual value = "<<hostC[k]<<"\n";
		error += double(abs(answer[k]-hostC[k]));
	}

	error=sqrt(error);
	cout<<"error = "<<error<<"\n";
	hipEventRecord(end1);
    hipEventSynchronize(end1);
	float t1=0;
	hipEventElapsedTime(&t1,start1,end1);

	cout<<"\nSequential time="<<t1;
	cout<<"\nParallel time="<<t<<endl;

	delete[] hostA;
    delete[] hostB;
    delete[] hostC;
    return hipDeviceSynchronize();

}

__global__ void kernel_multiplication( int* A,  int* B, int* C, int N,int M)
{
	int index =  threadIdx.x + blockIdx.x * blockDim.x;
	int sum = 0;
	if(index<N)
	{
		for(int i=0;i<M;i++)
		sum+=A[i]*B[(i*M)+index];
		C[index] = sum;
	}
}
	.text
	.file	"vectmul.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x0000000000000000              # double 0
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	.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	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$22, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	4(%rsp), %r13
	movl	$_ZSt3cin, %edi
	movq	%r13, %rsi
	callq	_ZNSirsERi
	movslq	(%r13), %r15
	movl	%r15d, %r12d
	leal	(,%r15,4), %ebp
	movq	%r15, %rbx
	shlq	$2, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r14
	movl	%ebp, 8(%rsp)                   # 4-byte Spill
	movl	%ebp, %eax
	imull	%r15d, %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%r13), %ecx
	testl	%ecx, %ecx
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltd
	idivl	4(%rsp)
	movl	%edx, (%r14,%rbx,4)
	movl	$_ZSt4cout, %edi
	movl	%edx, %esi
	callq	_ZNSolsEi
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%rbx
	movslq	4(%rsp), %rcx
	cmpq	%rcx, %rbx
	jl	.LBB0_2
.LBB0_3:                                # %.preheader83
	testl	%r12d, %r12d
	jle	.LBB0_15
# %bb.4:                                # %.preheader82.preheader
	xorl	%ebx, %ebx
.LBB0_5:                                # %.preheader82
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_7 Depth 2
	testl	%ecx, %ecx
	jle	.LBB0_8
# %bb.6:                                # %.lr.ph86.preheader
                                        #   in Loop: Header=BB0_5 Depth=1
	xorl	%r13d, %r13d
.LBB0_7:                                # %.lr.ph86
                                        #   Parent Loop BB0_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movl	4(%rsp), %ecx
	cltd
	idivl	%ecx
	movl	%ebx, %eax
	imull	%ecx, %eax
	cltq
	addq	%r13, %rax
	movl	%edx, (%r15,%rax,4)
	incq	%r13
	cmpl	%ecx, %r13d
	jl	.LBB0_7
.LBB0_8:                                # %._crit_edge
                                        #   in Loop: Header=BB0_5 Depth=1
	incl	%ebx
	cmpl	%r12d, %ebx
	jne	.LBB0_5
# %bb.9:                                # %._crit_edge88
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	testl	%r12d, %r12d
	jle	.LBB0_16
# %bb.10:                               # %.preheader81.preheader
	xorl	%ebx, %ebx
.LBB0_11:                               # %.preheader81
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_13 Depth 2
	movl	4(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB0_14
# %bb.12:                               # %.lr.ph90.preheader
                                        #   in Loop: Header=BB0_11 Depth=1
	xorl	%r13d, %r13d
.LBB0_13:                               # %.lr.ph90
                                        #   Parent Loop BB0_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	%ebx, %eax
	cltq
	addq	%r13, %rax
	movl	(%r15,%rax,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	4(%rsp), %eax
	incq	%r13
	cmpl	%eax, %r13d
	jl	.LBB0_13
.LBB0_14:                               # %._crit_edge91
                                        #   in Loop: Header=BB0_11 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incl	%ebx
	cmpl	%r12d, %ebx
	jne	.LBB0_11
	jmp	.LBB0_16
.LBB0_15:                               # %._crit_edge88.thread
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_16:                               # %._crit_edge93
	movslq	4(%rsp), %rsi
	shlq	$2, %rsi
	leaq	64(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movslq	4(%rsp), %rax
	movslq	%r12d, %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	56(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipMalloc
	movslq	4(%rsp), %rsi
	shlq	$2, %rsi
	leaq	24(%rsp), %rdi
	callq	hipMalloc
	leaq	88(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	leaq	72(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbx), %rdi
	movslq	4(%rsp), %rdx
	shlq	$2, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movslq	4(%rsp), %rax
	movslq	8(%rsp), %rdx                   # 4-byte Folded Reload
	imulq	%rax, %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_18
# %bb.17:
	movq	64(%rsp), %rdi
	movq	56(%rsp), %rsi
	movq	24(%rsp), %rdx
	movl	4(%rsp), %r8d
	movl	%r12d, %ecx
	callq	_Z36__device_stub__kernel_multiplicationPiS_S_ii
.LBB0_18:
	callq	hipDeviceSynchronize
	movq	24(%rsp), %rsi
	movslq	4(%rsp), %rdx
	shlq	$2, %rdx
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	52(%rsp), %rdi
	movl	$0, (%rdi)
	movq	88(%rsp), %rsi
	movq	40(%rsp), %rdx
	callq	hipEventElapsedTime
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movslq	4(%rsp), %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movslq	4(%rsp), %rcx
	movl	%ecx, %eax
	testl	%r12d, %r12d
	jle	.LBB0_24
# %bb.19:                               # %.preheader80.lr.ph
	leaq	(,%rcx,4), %rdx
	xorl	%esi, %esi
	movq	%r15, %rdi
.LBB0_20:                               # %.preheader80
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_22 Depth 2
	movl	$0, %r8d
	testl	%ecx, %ecx
	jle	.LBB0_23
# %bb.21:                               # %.lr.ph96.preheader
                                        #   in Loop: Header=BB0_20 Depth=1
	xorl	%r9d, %r9d
	movq	%rdi, %r10
	xorl	%r8d, %r8d
.LBB0_22:                               # %.lr.ph96
                                        #   Parent Loop BB0_20 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r10), %r11d
	imull	(%r14,%r9,4), %r11d
	addl	%r11d, %r8d
	incq	%r9
	addq	%rdx, %r10
	cmpq	%r9, %rax
	jne	.LBB0_22
.LBB0_23:                               # %._crit_edge97
                                        #   in Loop: Header=BB0_20 Depth=1
	movl	%r8d, (%r13,%rsi,4)
	incq	%rsi
	addq	$4, %rdi
	cmpq	%r12, %rsi
	jne	.LBB0_20
.LBB0_24:                               # %.preheader
	movq	%r14, 80(%rsp)                  # 8-byte Spill
	xorpd	%xmm0, %xmm0
	testl	%eax, %eax
	movq	16(%rsp), %r14                  # 8-byte Reload
	jle	.LBB0_27
# %bb.25:                               # %.lr.ph101.preheader
	xorl	%r12d, %r12d
.LBB0_26:                               # %.lr.ph101
                                        # =>This Inner Loop Header: Depth=1
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	%r12d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movl	$.L.str.5, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$.L.str.6, %esi
	movl	$17, %edx
	movq	%rbx, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%r13,%r12,4), %ebp
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movl	$.L.str.7, %esi
	movl	$16, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%r14,%r12,4), %esi
	movq	%rbx, %rdi
	callq	_ZNSolsEi
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	subl	(%r14,%r12,4), %ebp
	movl	%ebp, %eax
	negl	%eax
	cmovsl	%ebp, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	addsd	%xmm0, %xmm1
	movsd	%xmm1, 8(%rsp)                  # 8-byte Spill
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	incq	%r12
	movslq	4(%rsp), %rax
	cmpq	%rax, %r12
	jl	.LBB0_26
.LBB0_27:                               # %._crit_edge102
	ucomisd	.LCPI0_0(%rip), %xmm0
	movq	80(%rsp), %rbx                  # 8-byte Reload
	jb	.LBB0_29
# %bb.28:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB0_30
.LBB0_29:                               # %call.sqrt
	callq	sqrt
.LBB0_30:                               # %._crit_edge102.split
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$8, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	100(%rsp), %r12
	movl	$0, (%r12)
	movq	72(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$15, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	52(%rsp), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	testq	%rbx, %rbx
	je	.LBB0_32
# %bb.31:
	movq	%rbx, %rdi
	callq	_ZdaPv
.LBB0_32:
	testq	%r15, %r15
	je	.LBB0_34
# %bb.33:
	movq	%r15, %rdi
	callq	_ZdaPv
.LBB0_34:
	movq	16(%rsp), %rdi                  # 8-byte Reload
	testq	%rdi, %rdi
	je	.LBB0_36
# %bb.35:
	callq	_ZdaPv
.LBB0_36:
	callq	hipDeviceSynchronize
	addq	$104, %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_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z36__device_stub__kernel_multiplicationPiS_S_ii # -- Begin function _Z36__device_stub__kernel_multiplicationPiS_S_ii
	.type	_Z36__device_stub__kernel_multiplicationPiS_S_ii,@function
_Z36__device_stub__kernel_multiplicationPiS_S_ii: # @_Z36__device_stub__kernel_multiplicationPiS_S_ii
	.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	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%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	$_Z21kernel_multiplicationPiS_S_ii, %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_end1:
	.size	_Z36__device_stub__kernel_multiplicationPiS_S_ii, .Lfunc_end1-_Z36__device_stub__kernel_multiplicationPiS_S_ii
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21kernel_multiplicationPiS_S_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Enter the vector size:"
	.size	.L.str, 23

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\nVector:\n"
	.size	.L.str.1, 10

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\t"
	.size	.L.str.2, 2

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\nMatrix=\n"
	.size	.L.str.3, 10

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n"
	.size	.L.str.4, 2

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

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Expected value = "
	.size	.L.str.6, 18

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	" Actual value = "
	.size	.L.str.7, 17

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"error = "
	.size	.L.str.8, 9

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\nSequential time="
	.size	.L.str.9, 18

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"\nParallel time="
	.size	.L.str.10, 16

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21kernel_multiplicationPiS_S_ii"
	.size	.L__unnamed_1, 34

	.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

	.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 _Z36__device_stub__kernel_multiplicationPiS_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZSt3cin
	.addrsig_sym _Z21kernel_multiplicationPiS_S_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21kernel_multiplicationPiS_S_ii ; -- Begin function _Z21kernel_multiplicationPiS_S_ii
	.globl	_Z21kernel_multiplicationPiS_S_ii
	.p2align	8
	.type	_Z21kernel_multiplicationPiS_S_ii,@function
_Z21kernel_multiplicationPiS_S_ii:      ; @_Z21kernel_multiplicationPiS_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_cmp_lt_i32 s3, 1
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph.preheader
	v_mov_b32_e32 v0, 0
	v_mov_b32_e32 v2, v1
	s_mov_b32 s2, s3
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	s_waitcnt lgkmcnt(0)
	s_load_b32 s8, s[4:5], 0x0
	s_add_i32 s2, s2, -1
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_add_nc_u32_e32 v2, s3, v2
	s_cmp_eq_u32 s2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	global_load_b32 v5, v[3:4], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_mad_u64_u32 v[3:4], null, v5, s8, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v0, v3
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v0, 0
.LBB0_5:                                ; %Flow39
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[1:2], v0, off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21kernel_multiplicationPiS_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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_end0:
	.size	_Z21kernel_multiplicationPiS_S_ii, .Lfunc_end0-_Z21kernel_multiplicationPiS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 256
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21kernel_multiplicationPiS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z21kernel_multiplicationPiS_S_ii.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
