#include <device_launch_parameters.h>
#include <cuda_runtime.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>

//һκ˺üһCеԪ
void __global__ MVMulCUDA(float *A,  float *B, float *C, int rowSize, int columnSize, int wA){
	// Block index
	int bx = blockIdx.x;
	int by = blockIdx.y;

	// Thread index
	int tx = threadIdx.x;
	int ty = threadIdx.y;
	
	uint t_id = blockDim.x * bx+ tx;

    if(rowSize <= t_id)
		return;
    
	float Csub = 0;
    for(int i = 0; i < columnSize; i++){
		Csub += A[t_id * wA + i] * B[i];
    }
    C[t_id] = Csub;
}

void ConstantInit_A(float *data, int w, int h) {
	//row
	for (int i = 0; i < h; i++) {
		//column
		for (int j = 0; j<w; j++) {
			data[i*w + j] = i - 0.1*j + 1;
		}
	}
}

void ConstantInit_B(float *data, int h) {
	//row
	for (int i = 0; i < h; i++) {
		data[i] = log(sqrt(i*i - i + 1));
	}
}

void MVMul(float* A, float* B, float* C, int row, int column){
	int wA = 10;
	/*
	int width = column * sizeof(float);
	int	height = row;
	int columnSize = column * sizeof(float);
	int rowSize = row * sizeof(float);
	*/
	int size_A = row * column;
	int mem_size_A = sizeof(float)*size_A;
	float *h_A = (float*)malloc(mem_size_A);

	int size_B = row * 1;
	int mem_size_B = sizeof(float) * size_B;
	float *h_B = (float*)malloc(mem_size_B);

	// Allocate device memory
    float* d_A, *d_B, *d_C;
    
	// Allocate host vector C
	dim3 dimsC(row, 1, 1);
	int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
	float *h_C = reinterpret_cast<float *>(malloc(mem_size_C));
	if (h_C == NULL) {
		fprintf(stderr, "Failed to allocate host matrix C!\n");
		exit(EXIT_FAILURE);
	}

	//Allocate device memory
	cudaMalloc(&d_A, mem_size_A);
	cudaMalloc(&d_B, mem_size_B);
	cudaMalloc(&d_C, mem_size_C);
	

	// copy host memory to device
	cudaMemcpy(d_A, h_A, mem_size_A, cudaMemcpyHostToDevice);
	cudaMemcpy(d_B, h_B, mem_size_B, cudaMemcpyHostToDevice);

    //setup the execution configuration
    int dimGrid = 10;
    int dimBlock = 1000;

	// Allocate CUDA events that we'll use for timing
	cudaEvent_t start;
	cudaEventCreate(&start);

	cudaEvent_t stop;
	cudaEventCreate(&stop);

	// Record the start event
	cudaEventRecord(start, NULL);

    //Launch the device computeation threads
    MVMulCUDA<<<dimGrid, dimBlock>>>(d_A, d_B, d_C,row, column, wA/sizeof(float));
	
	// Record the stop event
	cudaEventRecord(stop, NULL);

	// Wait for the stop event to complete
	cudaEventSynchronize(stop);

	float msecTotal = 0.0f;
	cudaEventElapsedTime(&msecTotal, start, stop);

	// Compute and print the performance
	printf("GPU running time= %.12f msec\n",msecTotal);

    //Read C from device
    cudaMemcpy(C, d_C, mem_size_C, cudaMemcpyDeviceToHost);

    //Free device matrices
    cudaFree(d_A);
    cudaFree(d_B);
    cudaFree(d_C);
}


int show(float* C, int rowSize, int columnSize, int showsize){
    int i, j;
    if(showsize < rowSize)
        rowSize = showsize;
    if(rowSize == 1)
        columnSize = 0;
    for(i=0; i<rowSize; i++){
        for(j=0; j<showsize; j++){
            printf("%f ", C[i*columnSize + j]);
        }
        printf("\n");
    }
    return 0;
}


int main(){

    //ڴ
    float* A;
    float* B;
    float* C;
    int i, j, rowSize = 10000, columnSize = 10000;
    int size = rowSize * columnSize;
    A = (float*)malloc(size * sizeof(float));
    B = (float*)malloc(columnSize * sizeof(float));
    C = (float*)malloc(rowSize * sizeof(float));
	
	//Initial matrix A and vector B
	ConstantInit_A(A, columnSize, rowSize);
	ConstantInit_B(B, rowSize);

    struct timeval tvs,tve;

    //Calculate
    cudaDeviceReset(); 
    gettimeofday(&tvs,NULL);  
    MVMul(A, B, C, rowSize, columnSize);
    gettimeofday(&tve,NULL);
    cudaDeviceReset();    

    //Result examples
    double span = tve.tv_sec-tvs.tv_sec + (tve.tv_usec-tvs.tv_usec)/1000000.0;
    printf("Total running time: %.12f sec\n",span);
    printf("Result examples:\n");
    show(C, 1, rowSize, 10);

    free(A);
    free(B);
    free(C);
    A = NULL;
    B = NULL;
    C = NULL;

    return 0;
}

	.file	"tmpxft_002c989f_00000000-6_naive.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2047:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2047:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z14ConstantInit_APfii
	.type	_Z14ConstantInit_APfii, @function
_Z14ConstantInit_APfii:
.LFB2040:
	.cfi_startproc
	endbr64
	movsd	.LC0(%rip), %xmm2
	movsd	.LC1(%rip), %xmm3
	xorl	%r8d, %r8d
	xorl	%ecx, %ecx
.L3:
	cmpl	%edx, %ecx
	jge	.L2
	movslq	%r8d, %rax
	leaq	(%rdi,%rax,4), %r9
	xorl	%eax, %eax
.L6:
	cmpl	%eax, %esi
	jle	.L8
	cvtsi2sdl	%eax, %xmm1
	cvtsi2sdl	%ecx, %xmm0
	mulsd	%xmm2, %xmm1
	subsd	%xmm1, %xmm0
	addsd	%xmm3, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r9,%rax,4)
	incq	%rax
	jmp	.L6
.L8:
	incl	%ecx
	addl	%esi, %r8d
	jmp	.L3
.L2:
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z14ConstantInit_APfii, .-_Z14ConstantInit_APfii
	.globl	_Z14ConstantInit_BPfi
	.type	_Z14ConstantInit_BPfi, @function
_Z14ConstantInit_BPfi:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L10:
	cmpl	%ebx, %ebp
	jle	.L13
	leal	-1(%rbx), %eax
	imull	%ebx, %eax
	incl	%eax
	cvtsi2sdl	%eax, %xmm0
	call	sqrt@PLT
	call	log@PLT
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L10
.L13:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z14ConstantInit_BPfi, .-_Z14ConstantInit_BPfi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"%f "
.LC3:
	.string	"\n"
	.text
	.globl	_Z4showPfiii
	.type	_Z4showPfiii, @function
_Z4showPfiii:
.LFB2043:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%ecx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	cmpl	%esi, %ecx
	cmovle	%ecx, %ebx
	xorl	%eax, %eax
	cmpl	$1, %ebx
	cmove	%eax, %ebp
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.L16:
	cmpl	%ebx, %r15d
	jge	.L18
	movslq	%r14d, %rax
	xorl	%edx, %edx
	leaq	0(%r13,%rax,4), %rcx
.L19:
	cmpl	%edx, %r12d
	jle	.L22
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rcx,%rdx,4), %xmm0
	leaq	.LC2(%rip), %rsi
	movq	%rcx, 8(%rsp)
	movq	%rdx, (%rsp)
	call	__printf_chk@PLT
	movq	(%rsp), %rdx
	movq	8(%rsp), %rcx
	incq	%rdx
	jmp	.L19
.L22:
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	incl	%r15d
	addl	%ebp, %r14d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L16
.L18:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2043:
	.size	_Z4showPfiii, .-_Z4showPfiii
	.globl	_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii
	.type	_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii, @function
_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii:
.LFB2069:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z9MVMulCUDAPfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L23:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2069:
	.size	_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii, .-_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii
	.globl	_Z9MVMulCUDAPfS_S_iii
	.type	_Z9MVMulCUDAPfS_S_iii, @function
_Z9MVMulCUDAPfS_S_iii:
.LFB2070:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2070:
	.size	_Z9MVMulCUDAPfS_S_iii, .-_Z9MVMulCUDAPfS_S_iii
	.section	.rodata.str1.1
.LC4:
	.string	"Failed to allocate host matrix C!\n"
.LC6:
	.string	"GPU running time= %.12f msec\n"
	.text
	.globl	_Z5MVMulPfS_S_ii
	.type	_Z5MVMulPfS_S_ii, @function
_Z5MVMulPfS_S_ii:
.LFB2042:
	.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
	movl	%r8d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%ecx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	imull	%r8d, %ebp
	leal	0(,%r12,4), %ebx
	movslq	%ebx, %rbx
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	sall	$2, %ebp
	movq	%rdx, 8(%rsp)
	movslq	%ebp, %rbp
	movq	%rbp, %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, %r15
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, %r14
	call	malloc@PLT
	testq	%rax, %rax
	jne	.L29
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L29:
	leaq	24(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$536871037, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$2147483653, %edi
	salq	$3, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	addq	%rdi, %rdi
	movq	%rdx, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	%r13d, %r8d
	movl	%r12d, %ecx
	movq	24(%rsp), %rdi
	movl	$2, %r9d
	call	_Z35__device_stub__Z9MVMulCUDAPfS_S_iiiPfS_S_iii
.L30:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	76(%rsp), %rdi
	movl	$0x00000000, 76(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	76(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	40(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$2, %ecx
	movq	%rbx, %rdx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$104, %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
.LFE2042:
	.size	_Z5MVMulPfS_S_ii, .-_Z5MVMulPfS_S_ii
	.section	.rodata.str1.1
.LC8:
	.string	"Total running time: %.12f sec\n"
.LC9:
	.string	"Result examples:\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2044:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$400000000, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$40000, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$40000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$10000, %edx
	movl	$10000, %esi
	movq	%r12, %rdi
	movq	%rax, %rbx
	call	_Z14ConstantInit_APfii
	movq	%rbp, %rdi
	call	_Z14ConstantInit_BPfi
	call	cudaDeviceReset@PLT
	xorl	%esi, %esi
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	movl	$10000, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movl	$10000, %r8d
	movq	%r12, %rdi
	call	_Z5MVMulPfS_S_ii
	xorl	%esi, %esi
	leaq	24(%rsp), %rdi
	call	gettimeofday@PLT
	call	cudaDeviceReset@PLT
	movq	32(%rsp), %rax
	subq	16(%rsp), %rax
	leaq	.LC8(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	movq	24(%rsp), %rax
	subq	8(%rsp), %rax
	divsd	.LC7(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	movl	$2, %edi
	movb	$1, %al
	addsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$10, %ecx
	movl	$10000, %edx
	movq	%rbx, %rdi
	movl	$1, %esi
	call	_Z4showPfiii
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2044:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z9MVMulCUDAPfS_S_iii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2072:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9MVMulCUDAPfS_S_iii(%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
.LFE2072:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	-1717986918
	.long	1069128089
	.align 8
.LC1:
	.long	0
	.long	1072693248
	.align 8
.LC7:
	.long	0
	.long	1093567616
	.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 <sys/time.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>

//һκ˺üһCеԪ
void __global__ MVMulCUDA(float *A,  float *B, float *C, int rowSize, int columnSize, int wA){
	// Block index
	int bx = blockIdx.x;
	int by = blockIdx.y;

	// Thread index
	int tx = threadIdx.x;
	int ty = threadIdx.y;
	
	uint t_id = blockDim.x * bx+ tx;

    if(rowSize <= t_id)
		return;
    
	float Csub = 0;
    for(int i = 0; i < columnSize; i++){
		Csub += A[t_id * wA + i] * B[i];
    }
    C[t_id] = Csub;
}

void ConstantInit_A(float *data, int w, int h) {
	//row
	for (int i = 0; i < h; i++) {
		//column
		for (int j = 0; j<w; j++) {
			data[i*w + j] = i - 0.1*j + 1;
		}
	}
}

void ConstantInit_B(float *data, int h) {
	//row
	for (int i = 0; i < h; i++) {
		data[i] = log(sqrt(i*i - i + 1));
	}
}

void MVMul(float* A, float* B, float* C, int row, int column){
	int wA = 10;
	/*
	int width = column * sizeof(float);
	int	height = row;
	int columnSize = column * sizeof(float);
	int rowSize = row * sizeof(float);
	*/
	int size_A = row * column;
	int mem_size_A = sizeof(float)*size_A;
	float *h_A = (float*)malloc(mem_size_A);

	int size_B = row * 1;
	int mem_size_B = sizeof(float) * size_B;
	float *h_B = (float*)malloc(mem_size_B);

	// Allocate device memory
    float* d_A, *d_B, *d_C;
    
	// Allocate host vector C
	dim3 dimsC(row, 1, 1);
	int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
	float *h_C = reinterpret_cast<float *>(malloc(mem_size_C));
	if (h_C == NULL) {
		fprintf(stderr, "Failed to allocate host matrix C!\n");
		exit(EXIT_FAILURE);
	}

	//Allocate device memory
	hipMalloc(&d_A, mem_size_A);
	hipMalloc(&d_B, mem_size_B);
	hipMalloc(&d_C, mem_size_C);
	

	// copy host memory to device
	hipMemcpy(d_A, h_A, mem_size_A, hipMemcpyHostToDevice);
	hipMemcpy(d_B, h_B, mem_size_B, hipMemcpyHostToDevice);

    //setup the execution configuration
    int dimGrid = 10;
    int dimBlock = 1000;

	// Allocate CUDA events that we'll use for timing
	hipEvent_t start;
	hipEventCreate(&start);

	hipEvent_t stop;
	hipEventCreate(&stop);

	// Record the start event
	hipEventRecord(start, NULL);

    //Launch the device computeation threads
    MVMulCUDA<<<dimGrid, dimBlock>>>(d_A, d_B, d_C,row, column, wA/sizeof(float));
	
	// Record the stop event
	hipEventRecord(stop, NULL);

	// Wait for the stop event to complete
	hipEventSynchronize(stop);

	float msecTotal = 0.0f;
	hipEventElapsedTime(&msecTotal, start, stop);

	// Compute and print the performance
	printf("GPU running time= %.12f msec\n",msecTotal);

    //Read C from device
    hipMemcpy(C, d_C, mem_size_C, hipMemcpyDeviceToHost);

    //Free device matrices
    hipFree(d_A);
    hipFree(d_B);
    hipFree(d_C);
}


int show(float* C, int rowSize, int columnSize, int showsize){
    int i, j;
    if(showsize < rowSize)
        rowSize = showsize;
    if(rowSize == 1)
        columnSize = 0;
    for(i=0; i<rowSize; i++){
        for(j=0; j<showsize; j++){
            printf("%f ", C[i*columnSize + j]);
        }
        printf("\n");
    }
    return 0;
}


int main(){

    //ڴ
    float* A;
    float* B;
    float* C;
    int i, j, rowSize = 10000, columnSize = 10000;
    int size = rowSize * columnSize;
    A = (float*)malloc(size * sizeof(float));
    B = (float*)malloc(columnSize * sizeof(float));
    C = (float*)malloc(rowSize * sizeof(float));
	
	//Initial matrix A and vector B
	ConstantInit_A(A, columnSize, rowSize);
	ConstantInit_B(B, rowSize);

    struct timeval tvs,tve;

    //Calculate
    hipDeviceReset(); 
    gettimeofday(&tvs,NULL);  
    MVMul(A, B, C, rowSize, columnSize);
    gettimeofday(&tve,NULL);
    hipDeviceReset();    

    //Result examples
    double span = tve.tv_sec-tvs.tv_sec + (tve.tv_usec-tvs.tv_usec)/1000000.0;
    printf("Total running time: %.12f sec\n",span);
    printf("Result examples:\n");
    show(C, 1, rowSize, 10);

    free(A);
    free(B);
    free(C);
    A = NULL;
    B = NULL;
    C = NULL;

    return 0;
}

	.text
	.file	"naive.hip"
	.globl	_Z24__device_stub__MVMulCUDAPfS_S_iii # -- Begin function _Z24__device_stub__MVMulCUDAPfS_S_iii
	.type	_Z24__device_stub__MVMulCUDAPfS_S_iii,@function
_Z24__device_stub__MVMulCUDAPfS_S_iii:  # @_Z24__device_stub__MVMulCUDAPfS_S_iii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z9MVMulCUDAPfS_S_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z24__device_stub__MVMulCUDAPfS_S_iii, .Lfunc_end0-_Z24__device_stub__MVMulCUDAPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z14ConstantInit_APfii
.LCPI1_0:
	.quad	0xbfb999999999999a              # double -0.10000000000000001
.LCPI1_1:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z14ConstantInit_APfii
	.type	_Z14ConstantInit_APfii,@function
_Z14ConstantInit_APfii:                 # @_Z14ConstantInit_APfii
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB1_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %eax
	movl	%esi, %ecx
	xorl	%edx, %edx
	movsd	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	.LCPI1_1(%rip), %xmm1           # xmm1 = mem[0],zero
	xorl	%r8d, %r8d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	testl	%esi, %esi
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	%edx, %r9d
	leaq	(%rdi,%r9,4), %r9
	xorps	%xmm2, %xmm2
	cvtsi2sd	%r8d, %xmm2
	xorl	%r10d, %r10d
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm3, %xmm3
	cvtsi2sd	%r10d, %xmm3
	mulsd	%xmm0, %xmm3
	addsd	%xmm2, %xmm3
	addsd	%xmm1, %xmm3
	cvtsd2ss	%xmm3, %xmm3
	movss	%xmm3, (%r9,%r10,4)
	incq	%r10
	cmpq	%r10, %rcx
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%r8
	addl	%esi, %edx
	cmpq	%rax, %r8
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge15
	retq
.Lfunc_end1:
	.size	_Z14ConstantInit_APfii, .Lfunc_end1-_Z14ConstantInit_APfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z14ConstantInit_BPfi
.LCPI2_0:
	.quad	0x0000000000000000              # double 0
	.text
	.globl	_Z14ConstantInit_BPfi
	.type	_Z14ConstantInit_BPfi,@function
_Z14ConstantInit_BPfi:                  # @_Z14ConstantInit_BPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_7
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	leal	-1(%r15), %eax
	imull	%r15d, %eax
	incl	%eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	ucomisd	.LCPI2_0(%rip), %xmm0
	jb	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB2_5
.LBB2_4:                                # %call.sqrt
                                        #   in Loop: Header=BB2_2 Depth=1
	callq	sqrt
.LBB2_5:                                # %.lr.ph.split
                                        #   in Loop: Header=BB2_2 Depth=1
	callq	log
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB2_7:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z14ConstantInit_BPfi, .Lfunc_end2-_Z14ConstantInit_BPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z5MVMulPfS_S_ii                # -- Begin function _Z5MVMulPfS_S_ii
	.type	_Z5MVMulPfS_S_ii,@function
_Z5MVMulPfS_S_ii:                       # @_Z5MVMulPfS_S_ii
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
                                        # kill: def $ecx killed $ecx def $rcx
	movq	%rdx, 48(%rsp)                  # 8-byte Spill
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	leal	(,%rcx,4), %ebp
	movl	%ebp, %eax
	movl	%r8d, 20(%rsp)                  # 4-byte Spill
	imull	%r8d, %eax
	movslq	%eax, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %rbx
	movslq	%ebp, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r13
	leaq	32(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	(%rbp), %rdi
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movq	%r13, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967306, %rdi               # imm = 0x10000000A
	leaq	990(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rcx                  # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	movl	20(%rsp), %r8d                  # 4-byte Reload
	movl	$2, %r9d
	callq	_Z24__device_stub__MVMulCUDAPfS_S_iii
.LBB3_2:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	68(%rsp), %rbx
	movl	$0, (%rbx)
	movq	56(%rsp), %rsi
	movq	(%rsp), %rdx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movq	8(%rsp), %rsi
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	addq	$72, %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_end3:
	.size	_Z5MVMulPfS_S_ii, .Lfunc_end3-_Z5MVMulPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z4showPfiii                    # -- Begin function _Z4showPfiii
	.type	_Z4showPfiii,@function
_Z4showPfiii:                           # @_Z4showPfiii
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	%esi, %ecx
	movl	%ecx, 4(%rsp)                   # 4-byte Spill
	cmovll	%ecx, %esi
	testl	%esi, %esi
	jle	.LBB4_6
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdi, %r14
	xorl	%r15d, %r15d
	cmpl	$1, %esi
	cmovel	%r15d, %edx
	movslq	%edx, %r12
	movl	%esi, %r13d
	movl	4(%rsp), %ebp                   # 4-byte Reload
	shlq	$2, %r12
.LBB4_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB4_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB4_2 Depth=1
	xorl	%ebx, %ebx
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rbx,4), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	incq	%rbx
	cmpq	%rbx, %rbp
	jne	.LBB4_4
.LBB4_5:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r15
	addq	%r12, %r14
	cmpq	%r13, %r15
	jne	.LBB4_2
.LBB4_6:                                # %._crit_edge20
	xorl	%eax, %eax
	addq	$8, %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_end4:
	.size	_Z4showPfiii, .Lfunc_end4-_Z4showPfiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI5_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI5_1:
	.quad	0x0000000000000000              # double 0
	.text
	.globl	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	%rbx
	.cfi_def_cfa_offset 32
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$40000, %edi                    # imm = 0x9C40
	callq	malloc
	movq	%rax, %rbx
	xorl	%eax, %eax
.LBB5_1:                                # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_2 Depth 2
	movl	$10000, %ecx                    # imm = 0x2710
.LBB5_2:                                #   Parent Loop BB5_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	decq	%rcx
	jne	.LBB5_2
# %bb.3:                                # %._crit_edge.i
                                        #   in Loop: Header=BB5_1 Depth=1
	incq	%rax
	cmpq	$10000, %rax                    # imm = 0x2710
	jne	.LBB5_1
# %bb.4:                                # %.lr.ph.i.preheader
	xorl	%r14d, %r14d
.LBB5_5:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	leal	-1(%r14), %eax
	imull	%r14d, %eax
	incl	%eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	ucomisd	.LCPI5_1(%rip), %xmm0
	jb	.LBB5_7
# %bb.6:                                #   in Loop: Header=BB5_5 Depth=1
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB5_8
.LBB5_7:                                # %call.sqrt
                                        #   in Loop: Header=BB5_5 Depth=1
	callq	sqrt
.LBB5_8:                                # %.lr.ph.i.split
                                        #   in Loop: Header=BB5_5 Depth=1
	callq	log
	incq	%r14
	cmpq	$10000, %r14                    # imm = 0x2710
	jne	.LBB5_5
# %bb.9:                                # %_Z14ConstantInit_BPfi.exit
	callq	hipDeviceReset
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%rbx, %rdx
	movl	$10000, %ecx                    # imm = 0x2710
	movl	$10000, %r8d                    # imm = 0x2710
	callq	_Z5MVMulPfS_S_ii
	movq	%rsp, %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	callq	hipDeviceReset
	movq	(%r15), %rax
	movq	8(%r15), %rcx
	subq	(%r14), %rax
	cvtsi2sd	%rax, %xmm1
	subq	8(%r14), %rcx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rcx, %xmm0
	divsd	.LCPI5_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$10000, %edx                    # imm = 0x2710
	movl	$10, %ecx
	callq	_Z4showPfiii
	movq	%rbx, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9MVMulCUDAPfS_S_iii, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9MVMulCUDAPfS_S_iii,@object   # @_Z9MVMulCUDAPfS_S_iii
	.section	.rodata,"a",@progbits
	.globl	_Z9MVMulCUDAPfS_S_iii
	.p2align	3, 0x0
_Z9MVMulCUDAPfS_S_iii:
	.quad	_Z24__device_stub__MVMulCUDAPfS_S_iii
	.size	_Z9MVMulCUDAPfS_S_iii, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"GPU running time= %.12f msec\n"
	.size	.L.str.1, 30

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%f "
	.size	.L.str.2, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Total running time: %.12f sec\n"
	.size	.L.str.4, 31

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9MVMulCUDAPfS_S_iii"
	.size	.L__unnamed_1, 22

	.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	"Result examples:"
	.size	.Lstr, 17

	.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__MVMulCUDAPfS_S_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9MVMulCUDAPfS_S_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9MVMulCUDAPfS_S_iii   ; -- Begin function _Z9MVMulCUDAPfS_S_iii
	.globl	_Z9MVMulCUDAPfS_S_iii
	.p2align	8
	.type	_Z9MVMulCUDAPfS_S_iii,@function
_Z9MVMulCUDAPfS_S_iii:                  ; @_Z9MVMulCUDAPfS_S_iii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_u32_e64 s4, v1
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_cmp_lt_i32 s5, 1
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	v_mov_b32_e32 v3, 0
	v_mul_lo_u32 v2, v1, s6
	s_delay_alu instid0(VALU_DEP_2)
	v_mov_b32_e32 v0, v3
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2)
	v_lshlrev_b64 v[4:5], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_load_b32 s2, s[10:11], 0x0
	s_add_i32 s5, s5, -1
	v_add_nc_u32_e32 v2, 1, v2
	s_add_u32 s10, s10, 4
	s_addc_u32 s11, s11, 0
	v_add_co_u32 v4, vcc_lo, s8, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s9, v5, vcc_lo
	s_cmp_eq_u32 s5, 0
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v0, s2, v4
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v0, 0
.LBB0_5:                                ; %Flow43
	v_mov_b32_e32 v2, 0
	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 _Z9MVMulCUDAPfS_S_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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	_Z9MVMulCUDAPfS_S_iii, .Lfunc_end0-_Z9MVMulCUDAPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 248
; 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:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9MVMulCUDAPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9MVMulCUDAPfS_S_iii.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
