#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define abs(x) ( (x > 0) ? (x) : (-x) )
#define M 32*64
#define N 16*64
#define L 128*128
#define l 128

float *matrix_init(int m, int n);
void matrix_print(float *A, int m, int n);
void matrix_mult(float *A, int m, int q, float *B, int p, int n, float *C);

__global__ void dot(float *A, float *B, float *C) {
	int i, j;
	int I = blockDim.x*blockIdx.x + threadIdx.x, J = threadIdx.x, k;
	__shared__ float AB[l];
	float s = 0.;
	for (i = 0; i < M; i++)
		for (j = 0; j < N; j++) {
			AB[J] = A[i*L+I]*B[I*N+j];
			__syncthreads();
			if (!J) {
				s = 0.;
				for (k = 0; k < l; k++)
					s += AB[k];
				atomicAdd((C+i*N+j), s);
			}
		}
}

int main(int argc, char *argv[]) {
	int i, j, k = 0;	time_t dt, ht;
	float *A, *B, *C, *D, *_A, *_B, *_C;
	A = matrix_init(M, L);
	B = matrix_init(L, N);
	C = matrix_init(M, N);
	D = matrix_init(M, N);
	cudaMalloc((void **) &_A, M*L*sizeof(float));
	cudaMalloc((void **) &_B, L*N*sizeof(float));
	cudaMalloc((void **) &_C, M*N*sizeof(float));
	srand(time(NULL));
	for (i = 0; i < M; i++)
		for (j = 0; j < L; j++) 
			*(A+i*L+j) = 1.;
	for (i = 0; i < L; i++)
		for (j = 0; j < N; j++) 
			*(B+i*N+j) = 1.;

	dt = time(NULL);
	cudaMemcpy(_A, A, M*L*sizeof(float), cudaMemcpyHostToDevice);
	cudaMemcpy(_B, B, L*N*sizeof(float), cudaMemcpyHostToDevice);
	cudaMemcpy(_C, C, M*N*sizeof(float), cudaMemcpyHostToDevice);
	dot<<<L/l, l>>>(_A, _B, _C);
	cudaMemcpy(C, _C, M*N*sizeof(float), cudaMemcpyDeviceToHost);
	dt = time(NULL) - dt;
	printf("device: %d sec\n", (int) dt);
	fflush(stdout);
	
	ht = time(NULL); 
	matrix_mult(A, M, L, B, L, N, D);
	ht = time(NULL) - ht; 
	printf("host: %d sec\n", (int) ht );		
	printf("acceleration: %.0lf\n", (((double)ht)/((double)dt)) );		

	for (i = 0; i < M; i++)
		for (j = 0; j < N; j++) 
			if(abs(*(C+i*N+j) - *(D+i*N+j)) > .0000001) 
				k++;
	printf("error: %d\n", k);

	cudaFree(_C); cudaFree(_B); cudaFree(_A);
	free(C); free(B); free(A);
	return 0;
}

// Matrix functions
float *matrix_init(int m, int n) {
	int i, j;
	float *A = (float *) malloc (m*n*sizeof(float *));
	for (i = 0; i < m; i++)
		for (j = 0; j < n; j++)
			*(A+i*n+j) = 0.;
	return A;
}
void matrix_print(float *A, int m, int n) {
	if (!A) {printf("Empty!\n"); return;}
	int i = 0, j = 0;
	printf("\n");
	for  (i = 0 ; i < m; i++) {
		printf(" |");
		for (j = 0; j < n; j++) 
			printf( "%7lg" , *(A+i*n+j) );
		printf("%6c|",' ');
		printf("\n"); 
	}	printf("\n");
}
void matrix_mult(float *A, int m, int q, float *B, int p, int n, float *C) {
	if (q != p) {C = NULL; return;}
	int i = 0, j = 0, r = 0; 
	float s = 0.0;
	for (i = 0; i < m; i++) 
		for (j = 0; j < n; j++) {
			s = 0.0;
			for (r = 0; r < q; r++) 
				s += (*(A+i*q+r))*(*(B+r*n+j));
			*(C+i*n+j) = s;
		}
}	

	.file	"tmpxft_0025c9fb_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_Z11matrix_multPfiiS_iiS_.part.0, @function
_Z11matrix_multPfiiS_iiS_.part.0:
.LFB2174:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r10d, %r10d
	xorl	%r11d, %r11d
	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
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	xorl	%esi, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%r8d, %rbx
	salq	$2, %rbx
.L3:
	cmpl	%ebp, %r11d
	jge	.L2
	movslq	%r10d, %rax
	leaq	(%r9,%rax,4), %r15
	movslq	%esi, %rax
	leaq	(%rdi,%rax,4), %r14
	xorl	%eax, %eax
.L8:
	cmpl	%eax, %r8d
	jle	.L5
	leaq	(%r12,%rax,4), %r13
	xorl	%ecx, %ecx
	xorps	%xmm0, %xmm0
.L6:
	cmpl	%ecx, %edx
	jle	.L11
	movss	(%r14,%rcx,4), %xmm1
	mulss	0(%r13), %xmm1
	incq	%rcx
	addq	%rbx, %r13
	addss	%xmm1, %xmm0
	jmp	.L6
.L11:
	movss	%xmm0, (%r15,%rax,4)
	incq	%rax
	jmp	.L8
.L5:
	incl	%r11d
	addl	%r8d, %r10d
	addl	%edx, %esi
	jmp	.L3
.L2:
	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
.LFE2174:
	.size	_Z11matrix_multPfiiS_iiS_.part.0, .-_Z11matrix_multPfiiS_iiS_.part.0
	.globl	_Z11matrix_initii
	.type	_Z11matrix_initii, @function
_Z11matrix_initii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%edi, %ebp
	imull	%esi, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%esi, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	malloc@PLT
	xorl	%ecx, %ecx
	xorl	%esi, %esi
.L13:
	cmpl	%ebp, %esi
	jge	.L12
	movslq	%ecx, %rdx
	leaq	(%rax,%rdx,4), %rdi
	xorl	%edx, %edx
.L16:
	cmpl	%edx, %ebx
	jle	.L18
	movl	$0x00000000, (%rdi,%rdx,4)
	incq	%rdx
	jmp	.L16
.L18:
	incl	%esi
	addl	%ebx, %ecx
	jmp	.L13
.L12:
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11matrix_initii, .-_Z11matrix_initii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Empty!\n"
.LC2:
	.string	"\n"
.LC3:
	.string	" |"
.LC4:
	.string	"%7lg"
.LC5:
	.string	"%6c|"
	.text
	.globl	_Z12matrix_printPfii
	.type	_Z12matrix_printPfii, @function
_Z12matrix_printPfii:
.LFB2029:
	.cfi_startproc
	endbr64
	testq	%rdi, %rdi
	jne	.L20
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	jmp	.L27
.L20:
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	leaq	.LC2(%rip), %rsi
	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
	movq	%rdi, %rbx
	movl	$2, %edi
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	__printf_chk@PLT
.L21:
	cmpl	%r12d, %r13d
	jge	.L28
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	call	__printf_chk@PLT
	movslq	%r14d, %rax
	leaq	(%rbx,%rax,4), %rcx
.L22:
	cmpl	%r15d, %ebp
	jle	.L29
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rcx,%r15,4), %xmm0
	movq	%rcx, 8(%rsp)
	incq	%r15
	call	__printf_chk@PLT
	movq	8(%rsp), %rcx
	jmp	.L22
.L29:
	movl	$32, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%r13d
	leaq	.LC5(%rip), %rsi
	addl	%ebp, %r14d
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L21
.L28:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_restore 3
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_restore 6
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_restore 13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_restore 14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_restore 15
	.cfi_def_cfa_offset 8
.L27:
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z12matrix_printPfii, .-_Z12matrix_printPfii
	.globl	_Z11matrix_multPfiiS_iiS_
	.type	_Z11matrix_multPfiiS_iiS_, @function
_Z11matrix_multPfiiS_iiS_:
.LFB2030:
	.cfi_startproc
	endbr64
	movl	%r8d, %eax
	movl	%r9d, %r8d
	movq	8(%rsp), %r9
	cmpl	%eax, %edx
	jne	.L30
	jmp	_Z11matrix_multPfiiS_iiS_.part.0
.L30:
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z11matrix_multPfiiS_iiS_, .-_Z11matrix_multPfiiS_iiS_
	.globl	_Z26__device_stub__Z3dotPfS_S_PfS_S_
	.type	_Z26__device_stub__Z3dotPfS_S_PfS_S_, @function
_Z26__device_stub__Z3dotPfS_S_PfS_S_:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z3dotPfS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L32:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z26__device_stub__Z3dotPfS_S_PfS_S_, .-_Z26__device_stub__Z3dotPfS_S_PfS_S_
	.globl	_Z3dotPfS_S_
	.type	_Z3dotPfS_S_, @function
_Z3dotPfS_S_:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z3dotPfS_S_PfS_S_
	.cfi_endproc
.LFE2056:
	.size	_Z3dotPfS_S_, .-_Z3dotPfS_S_
	.section	.rodata.str1.1
.LC7:
	.string	"device: %d sec\n"
.LC8:
	.string	"host: %d sec\n"
.LC9:
	.string	"acceleration: %.0lf\n"
.LC12:
	.string	"error: %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$16384, %esi
	movl	$2048, %edi
	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	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	_Z11matrix_initii
	movl	$1024, %esi
	movl	$16384, %edi
	movq	%rax, %rbx
	call	_Z11matrix_initii
	movl	$1024, %esi
	movl	$2048, %edi
	movq	%rax, %rbp
	call	_Z11matrix_initii
	movl	$1024, %esi
	movl	$2048, %edi
	movq	%rax, %r12
	call	_Z11matrix_initii
	leaq	24(%rsp), %rdi
	movl	$134217728, %esi
	movq	%rax, %r13
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	movl	$8388608, %esi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movss	.LC6(%rip), %xmm0
	xorl	%edx, %edx
.L38:
	leaq	(%rbx,%rdx,4), %rcx
	xorl	%eax, %eax
.L39:
	movss	%xmm0, (%rcx,%rax,4)
	incq	%rax
	cmpq	$16384, %rax
	jne	.L39
	addq	$16384, %rdx
	cmpq	$33554432, %rdx
	jne	.L38
	xorl	%edx, %edx
.L40:
	leaq	0(%rbp,%rdx,4), %rcx
	xorl	%eax, %eax
.L41:
	movss	%xmm0, (%rcx,%rax,4)
	incq	%rax
	cmpq	$1024, %rax
	jne	.L41
	addq	$1024, %rdx
	cmpq	$16777216, %rdx
	jne	.L40
	xorl	%edi, %edi
	call	time@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$134217728, %edx
	movq	%rax, %r15
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$8388608, %edx
	call	cudaMemcpy@PLT
	movl	$33554433, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$7, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movl	$1, 68(%rsp)
	movq	%rdi, %rdx
	movq	%rdi, 60(%rsp)
	movq	%rdi, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L43
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z26__device_stub__Z3dotPfS_S_PfS_S_
.L43:
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movl	$8388608, %edx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	xorl	%edi, %edi
	call	time@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	subq	%r15, %rax
	movl	%eax, %edx
	movq	%rax, %r14
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	xorl	%edi, %edi
	call	time@PLT
	movq	%rbp, %rcx
	movq	%r13, %r9
	movl	$16384, %edx
	movl	$1024, %r8d
	movl	$2048, %esi
	movq	%rbx, %rdi
	movq	%rax, 8(%rsp)
	call	_Z11matrix_multPfiiS_iiS_.part.0
	xorl	%edi, %edi
	call	time@PLT
	movq	8(%rsp), %r10
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	subq	%r10, %rax
	movl	%eax, %edx
	movq	%rax, %r15
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cvtsi2sdq	%r14, %xmm1
	movl	$2, %edi
	movb	$1, %al
	cvtsi2sdq	%r15, %xmm0
	leaq	.LC9(%rip), %rsi
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	xorps	%xmm3, %xmm3
	movsd	.LC11(%rip), %xmm4
	movss	.LC10(%rip), %xmm5
.L44:
	leaq	0(,%rdx,4), %rax
	xorl	%esi, %esi
.L48:
	movss	(%r12,%rax), %xmm2
	movss	0(%r13,%rax), %xmm1
	movaps	%xmm2, %xmm0
	subss	%xmm1, %xmm0
	comiss	%xmm3, %xmm0
	ja	.L45
	xorps	%xmm5, %xmm2
	movaps	%xmm2, %xmm0
	subss	%xmm1, %xmm0
.L45:
	cvtss2sd	%xmm0, %xmm0
	comisd	%xmm4, %xmm0
	jbe	.L46
	incl	%ecx
.L46:
	incl	%esi
	addq	$4, %rax
	cmpl	$1024, %esi
	jne	.L48
	addq	$1024, %rdx
	cmpq	$2097152, %rdx
	jne	.L44
	movl	%ecx, %edx
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L50
	call	__stack_chk_fail@PLT
.L50:
	addq	$88, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z3dotPfS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	_Z3dotPfS_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2058:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC6:
	.long	1065353216
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC10:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC11:
	.long	-1698910392
	.long	1048238066
	.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<time.h>
#define abs(x) ( (x > 0) ? (x) : (-x) )
#define M 32*64
#define N 16*64
#define L 128*128
#define l 128

float *matrix_init(int m, int n);
void matrix_print(float *A, int m, int n);
void matrix_mult(float *A, int m, int q, float *B, int p, int n, float *C);

__global__ void dot(float *A, float *B, float *C) {
	int i, j;
	int I = blockDim.x*blockIdx.x + threadIdx.x, J = threadIdx.x, k;
	__shared__ float AB[l];
	float s = 0.;
	for (i = 0; i < M; i++)
		for (j = 0; j < N; j++) {
			AB[J] = A[i*L+I]*B[I*N+j];
			__syncthreads();
			if (!J) {
				s = 0.;
				for (k = 0; k < l; k++)
					s += AB[k];
				atomicAdd((C+i*N+j), s);
			}
		}
}

int main(int argc, char *argv[]) {
	int i, j, k = 0;	time_t dt, ht;
	float *A, *B, *C, *D, *_A, *_B, *_C;
	A = matrix_init(M, L);
	B = matrix_init(L, N);
	C = matrix_init(M, N);
	D = matrix_init(M, N);
	hipMalloc((void **) &_A, M*L*sizeof(float));
	hipMalloc((void **) &_B, L*N*sizeof(float));
	hipMalloc((void **) &_C, M*N*sizeof(float));
	srand(time(NULL));
	for (i = 0; i < M; i++)
		for (j = 0; j < L; j++) 
			*(A+i*L+j) = 1.;
	for (i = 0; i < L; i++)
		for (j = 0; j < N; j++) 
			*(B+i*N+j) = 1.;

	dt = time(NULL);
	hipMemcpy(_A, A, M*L*sizeof(float), hipMemcpyHostToDevice);
	hipMemcpy(_B, B, L*N*sizeof(float), hipMemcpyHostToDevice);
	hipMemcpy(_C, C, M*N*sizeof(float), hipMemcpyHostToDevice);
	dot<<<L/l, l>>>(_A, _B, _C);
	hipMemcpy(C, _C, M*N*sizeof(float), hipMemcpyDeviceToHost);
	dt = time(NULL) - dt;
	printf("device: %d sec\n", (int) dt);
	fflush(stdout);
	
	ht = time(NULL); 
	matrix_mult(A, M, L, B, L, N, D);
	ht = time(NULL) - ht; 
	printf("host: %d sec\n", (int) ht );		
	printf("acceleration: %.0lf\n", (((double)ht)/((double)dt)) );		

	for (i = 0; i < M; i++)
		for (j = 0; j < N; j++) 
			if(abs(*(C+i*N+j) - *(D+i*N+j)) > .0000001) 
				k++;
	printf("error: %d\n", k);

	hipFree(_C); hipFree(_B); hipFree(_A);
	free(C); free(B); free(A);
	return 0;
}

// Matrix functions
float *matrix_init(int m, int n) {
	int i, j;
	float *A = (float *) malloc (m*n*sizeof(float *));
	for (i = 0; i < m; i++)
		for (j = 0; j < n; j++)
			*(A+i*n+j) = 0.;
	return A;
}
void matrix_print(float *A, int m, int n) {
	if (!A) {printf("Empty!\n"); return;}
	int i = 0, j = 0;
	printf("\n");
	for  (i = 0 ; i < m; i++) {
		printf(" |");
		for (j = 0; j < n; j++) 
			printf( "%7lg" , *(A+i*n+j) );
		printf("%6c|",' ');
		printf("\n"); 
	}	printf("\n");
}
void matrix_mult(float *A, int m, int q, float *B, int p, int n, float *C) {
	if (q != p) {C = NULL; return;}
	int i = 0, j = 0, r = 0; 
	float s = 0.0;
	for (i = 0; i < m; i++) 
		for (j = 0; j < n; j++) {
			s = 0.0;
			for (r = 0; r < q; r++) 
				s += (*(A+i*q+r))*(*(B+r*n+j));
			*(C+i*n+j) = s;
		}
}	

	.text
	.file	"main.hip"
	.globl	_Z18__device_stub__dotPfS_S_    # -- Begin function _Z18__device_stub__dotPfS_S_
	.type	_Z18__device_stub__dotPfS_S_,@function
_Z18__device_stub__dotPfS_S_:           # @_Z18__device_stub__dotPfS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z3dotPfS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z18__device_stub__dotPfS_S_, .Lfunc_end0-_Z18__device_stub__dotPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_1:
	.quad	0x3e7ad7f29abcaf48              # double 9.9999999999999995E-8
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:                                # %_Z11matrix_initii.exit
	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	$40, %rsp
	.cfi_def_cfa_offset 96
	.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	$268435456, %edi                # imm = 0x10000000
	callq	malloc
	movq	%rax, %r15
	xorl	%ebx, %ebx
	movl	$134217728, %edx                # imm = 0x8000000
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$134217728, %edi                # imm = 0x8000000
	callq	malloc
	movq	%rax, %r14
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	malloc
	movq	%rax, %r13
	movl	$8388608, %edx                  # imm = 0x800000
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	malloc
	movq	%rax, %r12
	movl	$8388608, %edx                  # imm = 0x800000
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	leaq	16(%rsp), %rdi
	movl	$134217728, %esi                # imm = 0x8000000
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	movq	%rsp, %rdi
	movl	$8388608, %esi                  # imm = 0x800000
	callq	hipMalloc
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movq	%r15, %rax
.LBB1_1:                                # %.preheader89
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_2 Depth 2
	xorl	%ecx, %ecx
.LBB1_2:                                #   Parent Loop BB1_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$1065353216, (%rax,%rcx,4)      # imm = 0x3F800000
	incq	%rcx
	cmpq	$16384, %rcx                    # imm = 0x4000
	jne	.LBB1_2
# %bb.3:                                #   in Loop: Header=BB1_1 Depth=1
	incq	%rbx
	addq	$65536, %rax                    # imm = 0x10000
	cmpq	$2048, %rbx                     # imm = 0x800
	jne	.LBB1_1
# %bb.4:                                # %.preheader87.preheader
	xorl	%eax, %eax
	movq	%r14, %rcx
.LBB1_5:                                # %.preheader87
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
	xorl	%edx, %edx
.LBB1_6:                                #   Parent Loop BB1_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$1065353216, (%rcx,%rdx,4)      # imm = 0x3F800000
	incq	%rdx
	cmpq	$1024, %rdx                     # imm = 0x400
	jne	.LBB1_6
# %bb.7:                                #   in Loop: Header=BB1_5 Depth=1
	incq	%rax
	addq	$4096, %rcx                     # imm = 0x1000
	cmpq	$16384, %rax                    # imm = 0x4000
	jne	.LBB1_5
# %bb.8:
	xorl	%edi, %edi
	callq	time
	movq	%rax, %rbp
	movq	16(%rsp), %rdi
	movl	$134217728, %edx                # imm = 0x8000000
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	movl	$8388608, %edx                  # imm = 0x800000
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967424, %rdi               # imm = 0x100000080
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_10
# %bb.9:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	callq	_Z18__device_stub__dotPfS_S_
.LBB1_10:
	movq	(%rsp), %rsi
	movl	$8388608, %edx                  # imm = 0x800000
	movq	%r13, 24(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	xorl	%ebx, %ebx
	xorl	%edi, %edi
	callq	time
	movq	%rax, %r13
	subq	%rbp, %r13
	movl	$.L.str, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
	xorl	%edi, %edi
	callq	time
	movq	%rax, %rbp
	movq	%r15, %rax
.LBB1_11:                               # %.preheader29.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_12 Depth 2
                                        #       Child Loop BB1_13 Depth 3
	movq	%rbx, %rcx
	shlq	$12, %rcx
	addq	%r12, %rcx
	movq	%r14, %rdx
	xorl	%esi, %esi
.LBB1_12:                               # %.preheader.i80
                                        #   Parent Loop BB1_11 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_13 Depth 3
	xorps	%xmm0, %xmm0
	movq	%rdx, %rdi
	xorl	%r8d, %r8d
.LBB1_13:                               #   Parent Loop BB1_11 Depth=1
                                        #     Parent Loop BB1_12 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%rax,%r8,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdi), %xmm1
	addss	%xmm1, %xmm0
	incq	%r8
	addq	$4096, %rdi                     # imm = 0x1000
	cmpq	$16384, %r8                     # imm = 0x4000
	jne	.LBB1_13
# %bb.14:                               # %._crit_edge.i
                                        #   in Loop: Header=BB1_12 Depth=2
	movss	%xmm0, (%rcx,%rsi,4)
	incq	%rsi
	addq	$4, %rdx
	cmpq	$1024, %rsi                     # imm = 0x400
	jne	.LBB1_12
# %bb.15:                               # %._crit_edge34.i
                                        #   in Loop: Header=BB1_11 Depth=1
	incq	%rbx
	addq	$65536, %rax                    # imm = 0x10000
	cmpq	$2048, %rbx                     # imm = 0x800
	jne	.LBB1_11
# %bb.16:                               # %_Z11matrix_multPfiiS_iiS_.exit
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	xorl	%r15d, %r15d
	xorl	%edi, %edi
	callq	time
	movq	%rax, %rbx
	subq	%rbp, %rbx
	movl	$.L.str.1, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rbx, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r13, %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	movaps	.LCPI1_0(%rip), %xmm0           # xmm0 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	movsd	.LCPI1_1(%rip), %xmm1           # xmm1 = mem[0],zero
	movl	$4096, %eax                     # imm = 0x1000
	movq	24(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rcx
	xorl	%esi, %esi
.LBB1_17:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_18 Depth 2
	xorl	%edx, %edx
.LBB1_18:                               #   Parent Loop BB1_17 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rcx,%rdx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	movss	(%r12,%rdx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm2, %xmm4
	subss	%xmm3, %xmm4
	xorps	%xmm0, %xmm2
	subss	%xmm3, %xmm2
	xorps	%xmm3, %xmm3
	cmpltss	%xmm4, %xmm3
	andps	%xmm3, %xmm4
	andnps	%xmm2, %xmm3
	orps	%xmm4, %xmm3
	xorps	%xmm2, %xmm2
	cvtss2sd	%xmm3, %xmm2
	xorl	%edi, %edi
	ucomisd	%xmm1, %xmm2
	seta	%dil
	addl	%edi, %esi
	incq	%rdx
	cmpq	$1024, %rdx                     # imm = 0x400
	jne	.LBB1_18
# %bb.19:                               #   in Loop: Header=BB1_17 Depth=1
	incq	%r15
	addq	%rax, %r12
	addq	%rax, %rcx
	cmpq	$2048, %r15                     # imm = 0x800
	jne	.LBB1_17
# %bb.20:
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movq	(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z11matrix_initii               # -- Begin function _Z11matrix_initii
	.type	_Z11matrix_initii,@function
_Z11matrix_initii:                      # @_Z11matrix_initii
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movl	%edi, %ebp
	movl	%esi, %eax
	imull	%edi, %eax
	movslq	%eax, %rdi
	shlq	$3, %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%ebp, %ebp
	jle	.LBB2_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %r15d
	shlq	$2, %r15
	movl	%ebp, %r12d
	xorl	%ebp, %ebp
.LBB2_2:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	testl	%ebx, %ebx
	jle	.LBB2_4
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%ebp, %eax
	leaq	(%r14,%rax,4), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
.LBB2_4:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	addl	%ebx, %ebp
	decq	%r12
	jne	.LBB2_2
.LBB2_5:                                # %._crit_edge16
	movq	%r14, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end2:
	.size	_Z11matrix_initii, .Lfunc_end2-_Z11matrix_initii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11matrix_multPfiiS_iiS_       # -- Begin function _Z11matrix_multPfiiS_iiS_
	.type	_Z11matrix_multPfiiS_iiS_,@function
_Z11matrix_multPfiiS_iiS_:              # @_Z11matrix_multPfiiS_iiS_
	.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
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, -8(%rsp)                  # 8-byte Spill
	cmpl	%r8d, %edx
	jne	.LBB3_10
# %bb.1:
	testl	%esi, %esi
	jle	.LBB3_10
# %bb.2:                                # %.preheader29.lr.ph
	movslq	%r9d, %r8
	movslq	%edx, %r10
	movl	%esi, %esi
	movl	%r8d, %r11d
	movl	%edx, %ebx
	leaq	(,%r8,4), %r14
	shlq	$2, %r10
	xorl	%r15d, %r15d
.LBB3_3:                                # %.preheader29
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_5 Depth 2
                                        #       Child Loop BB3_7 Depth 3
	testl	%r9d, %r9d
	jle	.LBB3_9
# %bb.4:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB3_3 Depth=1
	movq	%r15, %rax
	imulq	%r8, %rax
	movq	56(%rsp), %rcx
	leaq	(%rcx,%rax,4), %r12
	movq	-8(%rsp), %rcx                  # 8-byte Reload
	xorl	%ebp, %ebp
.LBB3_5:                                # %.preheader
                                        #   Parent Loop BB3_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_7 Depth 3
	xorps	%xmm0, %xmm0
	testl	%edx, %edx
	jle	.LBB3_8
# %bb.6:                                # %.lr.ph
                                        #   in Loop: Header=BB3_5 Depth=2
	movq	%rcx, %r13
	xorl	%eax, %eax
.LBB3_7:                                #   Parent Loop BB3_3 Depth=1
                                        #     Parent Loop BB3_5 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%rdi,%rax,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%r13), %xmm1
	addss	%xmm1, %xmm0
	incq	%rax
	addq	%r14, %r13
	cmpq	%rax, %rbx
	jne	.LBB3_7
.LBB3_8:                                # %._crit_edge
                                        #   in Loop: Header=BB3_5 Depth=2
	movss	%xmm0, (%r12,%rbp,4)
	incq	%rbp
	addq	$4, %rcx
	cmpq	%r11, %rbp
	jne	.LBB3_5
.LBB3_9:                                # %._crit_edge34
                                        #   in Loop: Header=BB3_3 Depth=1
	incq	%r15
	addq	%r10, %rdi
	cmpq	%rsi, %r15
	jne	.LBB3_3
.LBB3_10:                               # %.loopexit
	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	_Z11matrix_multPfiiS_iiS_, .Lfunc_end3-_Z11matrix_multPfiiS_iiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12matrix_printPfii            # -- Begin function _Z12matrix_printPfii
	.type	_Z12matrix_printPfii,@function
_Z12matrix_printPfii:                   # @_Z12matrix_printPfii
	.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
	movl	%edx, 4(%rsp)                   # 4-byte Spill
	testq	%rdi, %rdi
	je	.LBB4_8
# %bb.1:
	movl	%esi, %ebp
	movq	%rdi, %r14
	movl	$10, %edi
	callq	putchar@PLT
	testl	%ebp, %ebp
	jle	.LBB4_7
# %bb.2:                                # %.lr.ph18
	movslq	4(%rsp), %r15                   # 4-byte Folded Reload
	movl	%ebp, %r12d
	movl	%r15d, %r13d
	shlq	$2, %r15
	xorl	%ebp, %ebp
.LBB4_3:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_5 Depth 2
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB4_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB4_3 Depth=1
	xorl	%ebx, %ebx
.LBB4_5:                                #   Parent Loop BB4_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rbx,4), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%rbx
	cmpq	%rbx, %r13
	jne	.LBB4_5
.LBB4_6:                                # %._crit_edge
                                        #   in Loop: Header=BB4_3 Depth=1
	movl	$.L.str.8, %edi
	movl	$32, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbp
	addq	%r15, %r14
	cmpq	%r12, %rbp
	jne	.LBB4_3
.LBB4_7:                                # %._crit_edge19
	movl	$10, %edi
	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
	jmp	putchar@PLT                     # TAILCALL
.LBB4_8:
	.cfi_def_cfa_offset 64
	movl	$.Lstr, %edi
	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
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end4:
	.size	_Z12matrix_printPfii, .Lfunc_end4-_Z12matrix_printPfii
	.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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3dotPfS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z3dotPfS_S_,@object            # @_Z3dotPfS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z3dotPfS_S_
	.p2align	3, 0x0
_Z3dotPfS_S_:
	.quad	_Z18__device_stub__dotPfS_S_
	.size	_Z3dotPfS_S_, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"host: %d sec\n"
	.size	.L.str.1, 14

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"acceleration: %.0lf\n"
	.size	.L.str.2, 21

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"error: %d\n"
	.size	.L.str.3, 11

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	" |"
	.size	.L.str.6, 3

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%7lg"
	.size	.L.str.7, 5

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%6c|"
	.size	.L.str.8, 5

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3dotPfS_S_"
	.size	.L__unnamed_1, 13

	.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	"Empty!"
	.size	.Lstr, 7

	.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 _Z18__device_stub__dotPfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z3dotPfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3dotPfS_S_            ; -- Begin function _Z3dotPfS_S_
	.globl	_Z3dotPfS_S_
	.p2align	8
	.type	_Z3dotPfS_S_,@function
_Z3dotPfS_S_:                           ; @_Z3dotPfS_S_
; %bb.0:
	s_clause 0x2
	s_load_b32 s8, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	v_dual_mov_b32 v7, 0 :: v_dual_lshlrev_b32 v6, 2, v0
	v_cmp_eq_u32_e32 vcc_lo, 0, v0
	s_mov_b32 s9, 0
	s_mov_b32 s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s8, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s0, v[0:1]
	v_lshlrev_b32_e32 v0, 10, v1
.LBB0_1:                                ; %.preheader25
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_2 Depth 2
                                        ;       Child Loop BB0_4 Depth 3
                                        ;       Child Loop BB0_7 Depth 3
	v_lshl_add_u32 v2, s1, 14, v1
	s_lshl_b32 s8, s1, 10
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_lshl_b64 s[10:11], s[8:9], 2
	s_mov_b32 s8, s9
	v_ashrrev_i32_e32 v3, 31, v2
	s_add_u32 s12, s2, s10
	s_addc_u32 s13, s3, s11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_add_co_u32 v2, s0, s4, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s0, s5, v3, s0
.LBB0_2:                                ;   Parent Loop BB0_1 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_4 Depth 3
                                        ;       Child Loop BB0_7 Depth 3
	v_add_nc_u32_e32 v4, s8, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v4, s0, s6, v4
	v_add_co_ci_u32_e64 v5, s0, s7, v5, s0
	global_load_b32 v8, v[2:3], off
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v4, v8, v4
	ds_store_b32 v6, v4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s14, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.3:                                ; %.preheader.preheader
                                        ;   in Loop: Header=BB0_2 Depth=2
	v_mov_b32_e32 v4, 0
	s_mov_b32 s0, 0
.LBB0_4:                                ; %.preheader
                                        ;   Parent Loop BB0_1 Depth=1
                                        ;     Parent Loop BB0_2 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_mov_b32_e32 v5, s0
	s_add_i32 s0, s0, 4
	s_cmpk_lg_i32 s0, 0x200
	ds_load_b32 v5, v5
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v4, v4, v5
	s_cbranch_scc1 .LBB0_4
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=2
	s_mov_b32 s15, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mbcnt_lo_u32_b32 v5, s15, 0
	v_cmp_eq_u32_e64 s0, 0, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, exec_lo, s0
	s_mov_b32 exec_lo, s0
	s_cbranch_execz .LBB0_8
; %bb.6:                                ;   in Loop: Header=BB0_2 Depth=2
	s_lshl_b64 s[10:11], s[8:9], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s10, s12, s10
	s_addc_u32 s11, s13, s11
	s_bcnt1_i32_b32 s0, s15
	global_load_b32 v5, v7, s[10:11]
	v_cvt_f32_ubyte0_e32 v8, s0
	s_mov_b32 s15, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f32_e32 v8, v4, v8
.LBB0_7:                                ; %atomicrmw.start
                                        ;   Parent Loop BB0_1 Depth=1
                                        ;     Parent Loop BB0_2 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_add_f32_e32 v4, v5, v8
	global_atomic_cmpswap_b32 v4, v7, v[4:5], s[10:11] glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e64 s0, v4, v5
	v_mov_b32_e32 v5, v4
	s_or_b32 s15, s0, s15
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s15
	s_cbranch_execnz .LBB0_7
.LBB0_8:                                ; %Flow41
                                        ;   in Loop: Header=BB0_2 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
	s_add_i32 s8, s8, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_lg_i32 s8, 0x400
	s_cbranch_scc1 .LBB0_2
; %bb.9:                                ;   in Loop: Header=BB0_1 Depth=1
	s_add_i32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_lg_i32 s1, 0x800
	s_cbranch_scc1 .LBB0_1
; %bb.10:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3dotPfS_S_
		.amdhsa_group_segment_fixed_size 512
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 9
		.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	_Z3dotPfS_S_, .Lfunc_end0-_Z3dotPfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 460
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 512 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 512
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z3dotPfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z3dotPfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
