#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <chrono>

#define BLOCK_SIZE 16

//функция ядра
__global__ void matrixMult(const double *A, const double *B, double *C, int n)
{
	int ai = n * (blockDim.y * blockIdx.y + threadIdx.y); // индекс начала строки матрицы A
	int bj = blockDim.x * blockIdx.x + threadIdx.x; // индекс начала строки матрицы B
	double sum = 0;
	for (int k = 0; k < n; k++)
		sum += A[ai + k] * B[k * n + bj];
	int index = n * (blockDim.y * blockIdx.y + threadIdx.y) + blockDim.x * blockIdx.x + threadIdx.x; // индекс вычисляемого элемента матрицы C 
	C[index] = sum;
}

//функция ядра с разделяемой памятью
__global__ void matrixMultShared(double* A, double* B, double* C, int n) {
	int bx = blockIdx.x;
	int by = blockIdx.y;
	int tx = threadIdx.x;
	int ty = threadIdx.y;
	int aBegin = n * BLOCK_SIZE * by; // индекс первой подматрицы A, обработанной блоком
	int aEnd = aBegin + n - 1; // индекс пследней подматрицы A
	int aStep = BLOCK_SIZE; // размер шага, используемый для итерации подматриц A
	int bBegin = BLOCK_SIZE * bx; // индекс первой подматрицы B, обработанной блоком
	int bStep = BLOCK_SIZE * n; // размер шага, используемый для итерации подматриц B
	double Csub = 0; 
	for (int a = aBegin, b = bBegin; a <= aEnd; a += aStep, b += bStep) {
		// объявление массивов для хранения подматриц в разделяемой памяти
		// с помощью модификатора __shared__
		__shared__ double As[BLOCK_SIZE][BLOCK_SIZE];
		__shared__ double Bs[BLOCK_SIZE][BLOCK_SIZE];
		As[ty][tx] = A[a + n * ty + tx];
		Bs[ty][tx] = B[b + n * ty + tx];
		__syncthreads(); 
		for (int k = 0; k < BLOCK_SIZE; ++k)
			Csub += As[ty][k] * Bs[k][tx];
		__syncthreads();
	}
	int c = n * BLOCK_SIZE * by + BLOCK_SIZE * bx;
	C[c + n * ty + tx] = Csub;
}

// генерация матриц
double * generateRandMatrix(int n, size_t sizeMatrix) {
	double * matrix = (double *)malloc(sizeMatrix);
	for (int i = 0; i < n * n; i++) {
		matrix[i] = (double)rand() / (double)RAND_MAX;
	}
	return matrix;
}

void printMatrix(double * matrix, int n) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			printf("%4.1lf ", matrix[i*n + j]);
		}
		printf("\n");
	}
}

// функция для последовательного варианта умножения матриц
void matrixMultCPU(double* A, double* B, double * C, int n) {
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			for (int k = 0; k<n; k++) {
				C[i*n + j] += A[i*n + k] * B[k*n + j];
			}
		}
	}
}

// проверка результатов умножения
bool checkMult(double * C1, double * C2, int n) {
	double accuracy = 1.e-6;
	for (int i = 0; i < n*n; i++) {
		if (abs(C1[i] - C2[i]) >= accuracy)
			return false;
	}
	return true;
}

int main(int argc, char *argv[])
{
    int N = atoi(argv[1]);
	int flag_s = atoi(argv[2]);
	if (N % 16 != 0) {
		printf("The number is not a multiple of the block size. The program will be closed.\n");
		system("pause");
		exit(1);
	}
	
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);

	srand(time(NULL));
	size_t sizeMatrix = sizeof(double) * N * N;

	double * h_A = generateRandMatrix(N, sizeMatrix);
	double * h_B = generateRandMatrix(N, sizeMatrix);
	double * h_C = (double *)malloc(sizeMatrix);
	double * h_C_seq = (double *)malloc(sizeMatrix);
	for (int i = 0; i<N*N; i++) {
		h_C_seq[i] = 0;
	}

	using namespace std::chrono;
	high_resolution_clock::time_point t1 = high_resolution_clock::now();
	matrixMultCPU(h_A, h_B, h_C_seq, N);
	high_resolution_clock::time_point t2 = high_resolution_clock::now();
	duration<double, std::milli> time_span = t2 - t1;
	double cpu_time = time_span.count();
	printf("The time: %f milliseconds\n", cpu_time);
	
	double *d_A;
	cudaMalloc((void **)&d_A, sizeMatrix);
	double *d_B;
	cudaMalloc((void **)&d_B, sizeMatrix);
	double * d_C;
	cudaMalloc((void **)&d_C, sizeMatrix);

	cudaMemcpy(d_A, h_A, sizeMatrix, cudaMemcpyHostToDevice);
	cudaMemcpy(d_B, h_B, sizeMatrix, cudaMemcpyHostToDevice);

   	dim3 threadsPerBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
	dim3 blocksPerGrid = dim3(N / BLOCK_SIZE, N / BLOCK_SIZE);
    
	if (flag_s) {
	    cudaEventRecord(start, 0);
	    matrixMultShared<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
	    cudaEventRecord(stop, 0);
	    cudaEventSynchronize(stop);
	}
	else {
	    cudaEventRecord(start, 0);
	    matrixMult<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
	    cudaEventRecord(stop, 0);
	    cudaEventSynchronize(stop);
	}
	float KernelTime;
	cudaEventElapsedTime(&KernelTime, start, stop);
	printf("KernelTime: %f milliseconds\n", KernelTime);

	double S = cpu_time / KernelTime;

	printf("Acceleration: %f\n", S);

	cudaMemcpy(h_C, d_C, sizeMatrix, cudaMemcpyDeviceToHost);


	if (checkMult(h_C, h_C_seq, N))
		printf("The multiplication results are correct.\n");
	else
		printf("Multiplication results are NOT correct.\n");

	cudaFree(d_A);
	cudaFree(d_B);
	cudaFree(d_C);
	free(h_A);
	free(h_B);
	free(h_C);
	free(h_C_seq);
	return 0;
}

	.file	"tmpxft_002e70a8_00000000-6_cuda_lab1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2137:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2137:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z18generateRandMatrixim
	.type	_Z18generateRandMatrixim, @function
_Z18generateRandMatrixim:
.LFB2126:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edi, %ebx
	movq	%rsi, %rdi
	imull	%ebx, %ebx
	call	malloc@PLT
	movslq	%ebx, %rbx
	movq	%rax, %rbp
	movq	%rax, %r12
	leaq	(%rax,%rbx,8), %rbx
.L3:
	cmpq	%rbx, %r12
	je	.L7
	call	rand@PLT
	addq	$8, %r12
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC0(%rip), %xmm0
	movsd	%xmm0, -8(%r12)
	jmp	.L3
.L7:
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2126:
	.size	_Z18generateRandMatrixim, .-_Z18generateRandMatrixim
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%4.1lf "
.LC2:
	.string	"\n"
	.text
	.globl	_Z11printMatrixPdi
	.type	_Z11printMatrixPdi, @function
_Z11printMatrixPdi:
.LFB2127:
	.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
	leaq	.LC1(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r13, %rbp
	salq	$3, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 64
.L9:
	cmpl	%ebp, %r12d
	jge	.L14
	leaq	(%rbx,%r13), %r15
.L10:
	movsd	(%rbx), %xmm0
	movq	%r14, %rsi
	movl	$2, %edi
	movb	$1, %al
	addq	$8, %rbx
	call	__printf_chk@PLT
	cmpq	%r15, %rbx
	jne	.L10
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%r12d
	call	__printf_chk@PLT
	jmp	.L9
.L14:
	popq	%rax
	.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
.LFE2127:
	.size	_Z11printMatrixPdi, .-_Z11printMatrixPdi
	.globl	_Z13matrixMultCPUPdS_S_i
	.type	_Z13matrixMultCPUPdS_S_i, @function
_Z13matrixMultCPUPdS_S_i:
.LFB2128:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdx, %r10
	movq	%rdi, %r8
	xorl	%edx, %edx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	movslq	%ecx, %rsi
	movq	%rsi, %rax
	salq	$3, %rsi
.L16:
	cmpl	%eax, %ebp
	jge	.L15
	movq	%rbx, %r11
	leaq	(%r10,%rdx), %rcx
	leaq	(%r8,%rdx), %r13
	xorl	%r9d, %r9d
.L20:
	movq	%r11, %r12
	xorl	%edi, %edi
.L17:
	movsd	0(%r13,%rdi,8), %xmm0
	mulsd	(%r12), %xmm0
	incq	%rdi
	addq	%rsi, %r12
	addsd	(%rcx), %xmm0
	movsd	%xmm0, (%rcx)
	cmpl	%edi, %eax
	jg	.L17
	incl	%r9d
	addq	$8, %r11
	addq	$8, %rcx
	cmpl	%r9d, %eax
	jne	.L20
	incl	%ebp
	addq	%rsi, %rdx
	jmp	.L16
.L15:
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2128:
	.size	_Z13matrixMultCPUPdS_S_i, .-_Z13matrixMultCPUPdS_S_i
	.globl	_Z9checkMultPdS_i
	.type	_Z9checkMultPdS_i, @function
_Z9checkMultPdS_i:
.LFB2129:
	.cfi_startproc
	endbr64
	imull	%edx, %edx
	movq	.LC3(%rip), %xmm1
	movsd	.LC4(%rip), %xmm2
	xorl	%eax, %eax
.L24:
	cmpl	%eax, %edx
	jle	.L28
	movsd	(%rdi,%rax,8), %xmm0
	subsd	(%rsi,%rax,8), %xmm0
	incq	%rax
	andps	%xmm1, %xmm0
	comisd	%xmm2, %xmm0
	jb	.L24
	xorl	%eax, %eax
	ret
.L28:
	movb	$1, %al
	ret
	.cfi_endproc
.LFE2129:
	.size	_Z9checkMultPdS_i, .-_Z9checkMultPdS_i
	.globl	_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi
	.type	_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi, @function
_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi:
.LFB2159:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10matrixMultPKdS0_Pdi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L29:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2159:
	.size	_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi, .-_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi
	.globl	_Z10matrixMultPKdS0_Pdi
	.type	_Z10matrixMultPKdS0_Pdi, @function
_Z10matrixMultPKdS0_Pdi:
.LFB2160:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi
	.cfi_endproc
.LFE2160:
	.size	_Z10matrixMultPKdS0_Pdi, .-_Z10matrixMultPKdS0_Pdi
	.globl	_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i
	.type	_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i, @function
_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i:
.LFB2161:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16matrixMultSharedPdS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L34:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2161:
	.size	_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i, .-_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i
	.globl	_Z16matrixMultSharedPdS_S_i
	.type	_Z16matrixMultSharedPdS_S_i, @function
_Z16matrixMultSharedPdS_S_i:
.LFB2162:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i
	.cfi_endproc
.LFE2162:
	.size	_Z16matrixMultSharedPdS_S_i, .-_Z16matrixMultSharedPdS_S_i
	.section	.rodata.str1.1
.LC5:
	.string	"The number is not a multiple of the block size. The program will be closed.\n"
.LC6:
	.string	"pause"
.LC9:
	.string	"The time: %f milliseconds\n"
.LC10:
	.string	"KernelTime: %f milliseconds\n"
.LC11:
	.string	"Acceleration: %f\n"
.LC12:
	.string	"The multiplication results are correct.\n"
.LC13:
	.string	"Multiplication results are NOT correct.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2130:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	testb	$15, %bl
	je	.L40
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC6(%rip), %rdi
	call	system@PLT
	movl	$1, %edi
	call	exit@PLT
.L40:
	leaq	24(%rsp), %rdi
	movl	%eax, %r15d
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movslq	%ebx, %rax
	movl	%ebx, %edi
	imulq	%rax, %rax
	salq	$3, %rax
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	_Z18generateRandMatrixim
	movq	(%rsp), %rsi
	movl	%ebx, %edi
	movq	%rax, %r14
	call	_Z18generateRandMatrixim
	movq	(%rsp), %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	%ebx, %edx
	imull	%ebx, %edx
	movq	%rax, %rbp
	xorl	%eax, %eax
.L41:
	cmpl	%eax, %edx
	jle	.L52
	movq	$0x000000000, 0(%rbp,%rax,8)
	incq	%rax
	jmp	.L41
.L52:
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	%ebx, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rsi
	movq	%r14, %rdi
	movq	%rax, %r12
	call	_Z13matrixMultCPUPdS_S_i
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	subq	%r12, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC8(%rip), %xmm0
	movq	%xmm0, %r12
	call	__printf_chk@PLT
	movq	(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	48(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	$16, %ecx
	xorl	%esi, %esi
	movabsq	$68719476752, %rax
	movq	%rax, 64(%rsp)
	movl	%ebx, %eax
	movq	24(%rsp), %rdi
	cltd
	movl	$1, 72(%rsp)
	idivl	%ecx
	movl	$1, 84(%rsp)
	testl	%r15d, %r15d
	movl	%eax, 76(%rsp)
	movl	%eax, 80(%rsp)
	je	.L43
	call	cudaEventRecord@PLT
	movl	72(%rsp), %ecx
	movl	84(%rsp), %esi
	xorl	%r9d, %r9d
	movq	64(%rsp), %rdx
	movq	76(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	%ebx, %ecx
	movq	40(%rsp), %rdi
	call	_Z41__device_stub__Z16matrixMultSharedPdS_S_iPdS_S_i
	jmp	.L46
.L43:
	call	cudaEventRecord@PLT
	movl	72(%rsp), %ecx
	movl	84(%rsp), %esi
	xorl	%r9d, %r9d
	movq	64(%rsp), %rdx
	movq	76(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	%ebx, %ecx
	movq	40(%rsp), %rdi
	call	_Z37__device_stub__Z10matrixMultPKdS0_PdiPKdS0_Pdi
.L46:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r12, %xmm0
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm1
	divsd	%xmm1, %xmm0
	movl	$2, %edi
	leaq	.LC11(%rip), %rsi
	call	__printf_chk@PLT
	movq	(%rsp), %rdx
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	8(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	movq	%rbp, %rsi
	movl	%ebx, %edx
	call	_Z9checkMultPdS_i
	leaq	.LC12(%rip), %rsi
	testb	%al, %al
	jne	.L51
	leaq	.LC13(%rip), %rsi
.L51:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$104, %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
.LFE2130:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z16matrixMultSharedPdS_S_i"
.LC15:
	.string	"_Z10matrixMultPKdS0_Pdi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2164:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z16matrixMultSharedPdS_S_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z10matrixMultPKdS0_Pdi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2164:
	.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	-4194304
	.long	1105199103
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC3:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC4:
	.long	-1598689907
	.long	1051772663
	.align 8
.LC8:
	.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 <stdlib.h>
#include <time.h> 
#include <chrono>

#define BLOCK_SIZE 16

//функция ядра
__global__ void matrixMult(const double *A, const double *B, double *C, int n)
{
	int ai = n * (blockDim.y * blockIdx.y + threadIdx.y); // индекс начала строки матрицы A
	int bj = blockDim.x * blockIdx.x + threadIdx.x; // индекс начала строки матрицы B
	double sum = 0;
	for (int k = 0; k < n; k++)
		sum += A[ai + k] * B[k * n + bj];
	int index = n * (blockDim.y * blockIdx.y + threadIdx.y) + blockDim.x * blockIdx.x + threadIdx.x; // индекс вычисляемого элемента матрицы C 
	C[index] = sum;
}

//функция ядра с разделяемой памятью
__global__ void matrixMultShared(double* A, double* B, double* C, int n) {
	int bx = blockIdx.x;
	int by = blockIdx.y;
	int tx = threadIdx.x;
	int ty = threadIdx.y;
	int aBegin = n * BLOCK_SIZE * by; // индекс первой подматрицы A, обработанной блоком
	int aEnd = aBegin + n - 1; // индекс пследней подматрицы A
	int aStep = BLOCK_SIZE; // размер шага, используемый для итерации подматриц A
	int bBegin = BLOCK_SIZE * bx; // индекс первой подматрицы B, обработанной блоком
	int bStep = BLOCK_SIZE * n; // размер шага, используемый для итерации подматриц B
	double Csub = 0; 
	for (int a = aBegin, b = bBegin; a <= aEnd; a += aStep, b += bStep) {
		// объявление массивов для хранения подматриц в разделяемой памяти
		// с помощью модификатора __shared__
		__shared__ double As[BLOCK_SIZE][BLOCK_SIZE];
		__shared__ double Bs[BLOCK_SIZE][BLOCK_SIZE];
		As[ty][tx] = A[a + n * ty + tx];
		Bs[ty][tx] = B[b + n * ty + tx];
		__syncthreads(); 
		for (int k = 0; k < BLOCK_SIZE; ++k)
			Csub += As[ty][k] * Bs[k][tx];
		__syncthreads();
	}
	int c = n * BLOCK_SIZE * by + BLOCK_SIZE * bx;
	C[c + n * ty + tx] = Csub;
}

// генерация матриц
double * generateRandMatrix(int n, size_t sizeMatrix) {
	double * matrix = (double *)malloc(sizeMatrix);
	for (int i = 0; i < n * n; i++) {
		matrix[i] = (double)rand() / (double)RAND_MAX;
	}
	return matrix;
}

void printMatrix(double * matrix, int n) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			printf("%4.1lf ", matrix[i*n + j]);
		}
		printf("\n");
	}
}

// функция для последовательного варианта умножения матриц
void matrixMultCPU(double* A, double* B, double * C, int n) {
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			for (int k = 0; k<n; k++) {
				C[i*n + j] += A[i*n + k] * B[k*n + j];
			}
		}
	}
}

// проверка результатов умножения
bool checkMult(double * C1, double * C2, int n) {
	double accuracy = 1.e-6;
	for (int i = 0; i < n*n; i++) {
		if (abs(C1[i] - C2[i]) >= accuracy)
			return false;
	}
	return true;
}

int main(int argc, char *argv[])
{
    int N = atoi(argv[1]);
	int flag_s = atoi(argv[2]);
	if (N % 16 != 0) {
		printf("The number is not a multiple of the block size. The program will be closed.\n");
		system("pause");
		exit(1);
	}
	
	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);

	srand(time(NULL));
	size_t sizeMatrix = sizeof(double) * N * N;

	double * h_A = generateRandMatrix(N, sizeMatrix);
	double * h_B = generateRandMatrix(N, sizeMatrix);
	double * h_C = (double *)malloc(sizeMatrix);
	double * h_C_seq = (double *)malloc(sizeMatrix);
	for (int i = 0; i<N*N; i++) {
		h_C_seq[i] = 0;
	}

	using namespace std::chrono;
	high_resolution_clock::time_point t1 = high_resolution_clock::now();
	matrixMultCPU(h_A, h_B, h_C_seq, N);
	high_resolution_clock::time_point t2 = high_resolution_clock::now();
	duration<double, std::milli> time_span = t2 - t1;
	double cpu_time = time_span.count();
	printf("The time: %f milliseconds\n", cpu_time);
	
	double *d_A;
	hipMalloc((void **)&d_A, sizeMatrix);
	double *d_B;
	hipMalloc((void **)&d_B, sizeMatrix);
	double * d_C;
	hipMalloc((void **)&d_C, sizeMatrix);

	hipMemcpy(d_A, h_A, sizeMatrix, hipMemcpyHostToDevice);
	hipMemcpy(d_B, h_B, sizeMatrix, hipMemcpyHostToDevice);

   	dim3 threadsPerBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
	dim3 blocksPerGrid = dim3(N / BLOCK_SIZE, N / BLOCK_SIZE);
    
	if (flag_s) {
	    hipEventRecord(start, 0);
	    matrixMultShared<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
	    hipEventRecord(stop, 0);
	    hipEventSynchronize(stop);
	}
	else {
	    hipEventRecord(start, 0);
	    matrixMult<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
	    hipEventRecord(stop, 0);
	    hipEventSynchronize(stop);
	}
	float KernelTime;
	hipEventElapsedTime(&KernelTime, start, stop);
	printf("KernelTime: %f milliseconds\n", KernelTime);

	double S = cpu_time / KernelTime;

	printf("Acceleration: %f\n", S);

	hipMemcpy(h_C, d_C, sizeMatrix, hipMemcpyDeviceToHost);


	if (checkMult(h_C, h_C_seq, N))
		printf("The multiplication results are correct.\n");
	else
		printf("Multiplication results are NOT correct.\n");

	hipFree(d_A);
	hipFree(d_B);
	hipFree(d_C);
	free(h_A);
	free(h_B);
	free(h_C);
	free(h_C_seq);
	return 0;
}

	.text
	.file	"cuda_lab1.hip"
	.globl	_Z25__device_stub__matrixMultPKdS0_Pdi # -- Begin function _Z25__device_stub__matrixMultPKdS0_Pdi
	.type	_Z25__device_stub__matrixMultPKdS0_Pdi,@function
_Z25__device_stub__matrixMultPKdS0_Pdi: # @_Z25__device_stub__matrixMultPKdS0_Pdi
	.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), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z10matrixMultPKdS0_Pdi, %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	_Z25__device_stub__matrixMultPKdS0_Pdi, .Lfunc_end0-_Z25__device_stub__matrixMultPKdS0_Pdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__matrixMultSharedPdS_S_i # -- Begin function _Z31__device_stub__matrixMultSharedPdS_S_i
	.type	_Z31__device_stub__matrixMultSharedPdS_S_i,@function
_Z31__device_stub__matrixMultSharedPdS_S_i: # @_Z31__device_stub__matrixMultSharedPdS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z16matrixMultSharedPdS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z31__device_stub__matrixMultSharedPdS_S_i, .Lfunc_end1-_Z31__device_stub__matrixMultSharedPdS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z18generateRandMatrixim
.LCPI2_0:
	.quad	0x41dfffffffc00000              # double 2147483647
	.text
	.globl	_Z18generateRandMatrixim
	.type	_Z18generateRandMatrixim,@function
_Z18generateRandMatrixim:               # @_Z18generateRandMatrixim
	.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
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edi, %ebx
	movq	%rsi, %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%ebx, %ebx
	je	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	imull	%ebx, %ebx
	cmpl	$1, %ebx
	adcl	$0, %ebx
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI2_0(%rip), %xmm0
	movsd	%xmm0, (%r14,%r15,8)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movq	%r14, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z18generateRandMatrixim, .Lfunc_end2-_Z18generateRandMatrixim
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printMatrixPdi              # -- Begin function _Z11printMatrixPdi
	.type	_Z11printMatrixPdi,@function
_Z11printMatrixPdi:                     # @_Z11printMatrixPdi
	.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
	movq	%rdi, (%rsp)                    # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB3_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %ebx
	movl	%esi, %r15d
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB3_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_3 Depth 2
	movl	%r12d, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,8), %rbp
	xorl	%r14d, %r14d
.LBB3_3:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rbp,%r14,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB3_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r13
	addl	%ebx, %r12d
	cmpq	%r15, %r13
	jne	.LBB3_2
.LBB3_5:                                # %._crit_edge13
	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_end3:
	.size	_Z11printMatrixPdi, .Lfunc_end3-_Z11printMatrixPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z13matrixMultCPUPdS_S_i        # -- Begin function _Z13matrixMultCPUPdS_S_i
	.type	_Z13matrixMultCPUPdS_S_i,@function
_Z13matrixMultCPUPdS_S_i:               # @_Z13matrixMultCPUPdS_S_i
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB4_8
# %bb.1:                                # %.preheader23.lr.ph
	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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%ecx, %eax
	leaq	(,%rax,8), %r8
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.LBB4_2:                                # %.preheader.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_3 Depth 2
                                        #       Child Loop BB4_4 Depth 3
	movl	%r9d, %r11d
	leaq	(%rdi,%r11,8), %r11
	movq	%r10, %rbx
	imulq	%rax, %rbx
	leaq	(%rdx,%rbx,8), %rbx
	movq	%rsi, %r14
	xorl	%r15d, %r15d
.LBB4_3:                                # %.preheader
                                        #   Parent Loop BB4_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_4 Depth 3
	movsd	(%rbx,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movq	%r14, %r12
	xorl	%r13d, %r13d
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_3 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%r11,%r13,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%r12), %xmm1
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%rbx,%r15,8)
	incq	%r13
	addq	%r8, %r12
	cmpq	%r13, %rax
	jne	.LBB4_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB4_3 Depth=2
	incq	%r15
	addq	$8, %r14
	cmpq	%rax, %r15
	jne	.LBB4_3
# %bb.6:                                # %._crit_edge26
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%r10
	addl	%ecx, %r9d
	cmpq	%rax, %r10
	jne	.LBB4_2
# %bb.7:
	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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_8:                                # %._crit_edge28
	retq
.Lfunc_end4:
	.size	_Z13matrixMultCPUPdS_S_i, .Lfunc_end4-_Z13matrixMultCPUPdS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z9checkMultPdS_i
.LCPI5_0:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI5_1:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	_Z9checkMultPdS_i
	.type	_Z9checkMultPdS_i,@function
_Z9checkMultPdS_i:                      # @_Z9checkMultPdS_i
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	testl	%edx, %edx
	je	.LBB5_6
# %bb.1:                                # %.lr.ph.preheader
	imull	%edx, %edx
	cmpl	$1, %edx
	movl	%edx, %eax
	adcl	$0, %eax
	movsd	(%rdi), %xmm0                   # xmm0 = mem[0],zero
	subsd	(%rsi), %xmm0
	andpd	.LCPI5_0(%rip), %xmm0
	ucomisd	.LCPI5_1(%rip), %xmm0
	jae	.LBB5_8
# %bb.2:                                # %.lr.ph18.preheader
	movl	$1, %r8d
	movapd	.LCPI5_0(%rip), %xmm0           # xmm0 = [NaN,NaN]
	movsd	.LCPI5_1(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB5_3:                                # %.lr.ph18
                                        # =>This Inner Loop Header: Depth=1
	movq	%r8, %rcx
	cmpq	%r8, %rax
	je	.LBB5_5
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB5_3 Depth=1
	movsd	(%rdi,%rcx,8), %xmm2            # xmm2 = mem[0],zero
	subsd	(%rsi,%rcx,8), %xmm2
	andpd	%xmm0, %xmm2
	leaq	1(%rcx), %r8
	ucomisd	%xmm1, %xmm2
	jb	.LBB5_3
.LBB5_5:                                # %.critedge.loopexit
	cmpq	%rdx, %rcx
	setae	%al
                                        # kill: def $al killed $al killed $eax
	retq
.LBB5_6:
	movb	$1, %al
                                        # kill: def $al killed $al killed $eax
	retq
.LBB5_8:
	xorl	%eax, %eax
                                        # kill: def $al killed $al killed $eax
	retq
.Lfunc_end5:
	.size	_Z9checkMultPdS_i, .Lfunc_end5-_Z9checkMultPdS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI6_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI6_2:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI6_1:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	16(%rbx), %rdi
	callq	atoi
	testb	$15, %bpl
	jne	.LBB6_16
# %bb.1:
	movl	%eax, 36(%rsp)                  # 4-byte Spill
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movslq	%ebp, %r13
	imulq	%r13, %r13
	shlq	$3, %r13
	movl	%ebp, %edi
	movq	%r13, %rsi
	callq	_Z18generateRandMatrixim
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movl	%ebp, %edi
	movq	%r13, %rsi
	callq	_Z18generateRandMatrixim
	movq	%rax, %r14
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r12
	movl	%ebp, %ebx
	imull	%ebp, %ebx
	testl	%ebp, %ebp
	je	.LBB6_3
# %bb.2:                                # %.lr.ph.preheader
	cmpl	$1, %ebx
	movl	%ebx, %edx
	adcl	$0, %edx
	shlq	$3, %rdx
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB6_3:                                # %._crit_edge
	movl	%ebx, 32(%rsp)                  # 4-byte Spill
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %rbx
	movq	40(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movq	%r14, %rsi
	movq	%r12, 64(%rsp)                  # 8-byte Spill
	movq	%r12, %rdx
	movl	%ebp, %ecx
	callq	_Z13matrixMultCPUPdS_S_i
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%rbx, %rax
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI6_0(%rip), %xmm0
	movl	$.L.str.4, %edi
	movsd	%xmm0, 56(%rsp)                 # 8-byte Spill
	movb	$1, %al
	callq	printf
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	%r15, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r12), %rdi
	movq	%r14, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%ebp, %eax
	sarl	$4, %eax
	movq	%rax, %rbx
	shlq	$32, %rbx
	orq	%rax, %rbx
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	cmpl	$0, 36(%rsp)                    # 4-byte Folded Reload
	je	.LBB6_6
# %bb.4:
	testl	%eax, %eax
	jne	.LBB6_8
# %bb.5:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	%ebp, %ecx
	callq	_Z31__device_stub__matrixMultSharedPdS_S_i
	jmp	.LBB6_8
.LBB6_6:
	testl	%eax, %eax
	jne	.LBB6_8
# %bb.7:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	%ebp, %ecx
	callq	_Z25__device_stub__matrixMultPKdS0_Pdi
.LBB6_8:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	movq	48(%rsp), %rsi
	movq	24(%rsp), %rdx
	leaq	84(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	cvtss2sd	(%rbx), %xmm1
	movsd	56(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	%xmm1, %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movq	(%rsp), %rsi
	movq	72(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.Lstr.1, %edi
	testl	%ebp, %ebp
	movq	64(%rsp), %r15                  # 8-byte Reload
	je	.LBB6_15
# %bb.9:                                # %.lr.ph.preheader.i
	movl	32(%rsp), %ecx                  # 4-byte Reload
	cmpl	$1, %ecx
	movl	%ecx, %eax
	adcl	$0, %eax
	movsd	(%rbx), %xmm0                   # xmm0 = mem[0],zero
	subsd	(%r15), %xmm0
	andpd	.LCPI6_1(%rip), %xmm0
	ucomisd	.LCPI6_2(%rip), %xmm0
	jae	.LBB6_14
# %bb.10:                               # %.lr.ph76.preheader
	movl	%ecx, %ecx
	movl	$1, %esi
	movapd	.LCPI6_1(%rip), %xmm0           # xmm0 = [NaN,NaN]
	movsd	.LCPI6_2(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB6_11:                               # %.lr.ph76
                                        # =>This Inner Loop Header: Depth=1
	movq	%rsi, %rdx
	cmpq	%rsi, %rax
	je	.LBB6_13
# %bb.12:                               # %.lr.ph.i
                                        #   in Loop: Header=BB6_11 Depth=1
	movsd	(%rbx,%rdx,8), %xmm2            # xmm2 = mem[0],zero
	subsd	(%r15,%rdx,8), %xmm2
	andpd	%xmm0, %xmm2
	leaq	1(%rdx), %rsi
	ucomisd	%xmm1, %xmm2
	jb	.LBB6_11
.LBB6_13:                               # %_Z9checkMultPdS_i.exit
	cmpq	%rcx, %rdx
	jae	.LBB6_15
.LBB6_14:                               # %.critedge
	movl	$.Lstr, %edi
.LBB6_15:                               # %_Z9checkMultPdS_i.exit.thread
	callq	puts@PLT
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$88, %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
.LBB6_16:
	.cfi_def_cfa_offset 144
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.L.str.3, %edi
	callq	system
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	main, .Lfunc_end6-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10matrixMultPKdS0_Pdi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16matrixMultSharedPdS_S_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z10matrixMultPKdS0_Pdi,@object # @_Z10matrixMultPKdS0_Pdi
	.section	.rodata,"a",@progbits
	.globl	_Z10matrixMultPKdS0_Pdi
	.p2align	3, 0x0
_Z10matrixMultPKdS0_Pdi:
	.quad	_Z25__device_stub__matrixMultPKdS0_Pdi
	.size	_Z10matrixMultPKdS0_Pdi, 8

	.type	_Z16matrixMultSharedPdS_S_i,@object # @_Z16matrixMultSharedPdS_S_i
	.globl	_Z16matrixMultSharedPdS_S_i
	.p2align	3, 0x0
_Z16matrixMultSharedPdS_S_i:
	.quad	_Z31__device_stub__matrixMultSharedPdS_S_i
	.size	_Z16matrixMultSharedPdS_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%4.1lf "
	.size	.L.str, 8

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"The time: %f milliseconds\n"
	.size	.L.str.4, 27

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"KernelTime: %f milliseconds\n"
	.size	.L.str.5, 29

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Acceleration: %f\n"
	.size	.L.str.6, 18

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10matrixMultPKdS0_Pdi"
	.size	.L__unnamed_1, 24

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z16matrixMultSharedPdS_S_i"
	.size	.L__unnamed_2, 28

	.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	"Multiplication results are NOT correct."
	.size	.Lstr, 40

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"The multiplication results are correct."
	.size	.Lstr.1, 40

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"The number is not a multiple of the block size. The program will be closed."
	.size	.Lstr.2, 76

	.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 _Z25__device_stub__matrixMultPKdS0_Pdi
	.addrsig_sym _Z31__device_stub__matrixMultSharedPdS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z10matrixMultPKdS0_Pdi
	.addrsig_sym _Z16matrixMultSharedPdS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10matrixMultPKdS0_Pdi ; -- Begin function _Z10matrixMultPKdS0_Pdi
	.globl	_Z10matrixMultPKdS0_Pdi
	.p2align	8
	.type	_Z10matrixMultPKdS0_Pdi,@function
_Z10matrixMultPKdS0_Pdi:                ; @_Z10matrixMultPKdS0_Pdi
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x2c
	s_load_b32 s2, s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s8, s3, 16
	s_and_b32 s3, s3, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s8, v[1:2]
	v_and_b32_e32 v1, 0x3ff, v0
	s_cmp_lt_i32 s2, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v0, v2, s2
	v_mad_u64_u32 v[2:3], null, s14, s3, v[1:2]
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v1, 31, v0
	v_mov_b32_e32 v3, 0
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v7, v2
	s_mov_b32 s3, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 3, v[0:1]
	v_add_co_u32 v5, vcc_lo, s4, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v8, 31, v7
	s_add_i32 s3, s3, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s3, 0
	v_lshlrev_b64 v[8:9], 3, v[7:8]
	v_add_nc_u32_e32 v7, s2, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v8, vcc_lo, s6, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s7, v9, vcc_lo
	global_load_b64 v[10:11], v[5:6], off
	global_load_b64 v[8:9], v[8:9], off
	v_add_co_u32 v5, vcc_lo, v5, 8
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v6, vcc_lo
	s_waitcnt vmcnt(0)
	v_fma_f64 v[3:4], v[10:11], v[8:9], v[3:4]
	s_cbranch_scc0 .LBB0_2
	s_branch .LBB0_4
.LBB0_3:
	v_mov_b32_e32 v3, 0
	v_mov_b32_e32 v4, 0
.LBB0_4:                                ; %Flow41
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v2, v0
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[0:1]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b64 v[0:1], v[3:4], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10matrixMultPKdS0_Pdi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 12
		.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	_Z10matrixMultPKdS0_Pdi, .Lfunc_end0-_Z10matrixMultPKdS0_Pdi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 320
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z16matrixMultSharedPdS_S_i ; -- Begin function _Z16matrixMultSharedPdS_S_i
	.globl	_Z16matrixMultSharedPdS_S_i
	.p2align	8
	.type	_Z16matrixMultSharedPdS_S_i,@function
_Z16matrixMultSharedPdS_S_i:            ; @_Z16matrixMultSharedPdS_S_i
; %bb.0:
	s_clause 0x2
	s_load_b32 s9, s[0:1], 0x18
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v3, 0x3ff, v0
	s_lshl_b32 s2, s14, 4
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_lo_u32 v2, v1, s9
	s_lshl_b32 s8, s9, 4
	s_cmp_lt_i32 s9, 1
	s_mul_i32 s3, s8, s15
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph
	v_lshlrev_b32_e32 v0, 3, v3
	v_lshlrev_b32_e32 v4, 7, v1
	s_delay_alu instid0(VALU_DEP_3)
	v_add_nc_u32_e32 v6, v2, v3
	s_add_i32 s9, s3, s9
	s_mov_b32 s10, s2
	v_add_nc_u32_e32 v5, 0x800, v0
	v_dual_mov_b32 v0, 0 :: v_dual_add_nc_u32 v7, v4, v0
	v_mov_b32_e32 v1, 0
	s_mov_b32 s11, s3
	s_delay_alu instid0(VALU_DEP_3)
	v_add_nc_u32_e32 v8, v5, v4
.LBB1_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_3 Depth 2
	v_add_nc_u32_e32 v9, s11, v6
	v_add_nc_u32_e32 v11, s10, v6
	s_mov_b32 s12, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v10, 31, v9
	v_ashrrev_i32_e32 v12, 31, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[9:10], 3, v[9:10]
	v_lshlrev_b64 v[11:12], 3, v[11:12]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v9, vcc_lo, s4, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v11, vcc_lo, s6, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s7, v12, vcc_lo
	global_load_b64 v[13:14], v[9:10], off
	global_load_b64 v[10:11], v[11:12], off
	v_mov_b32_e32 v9, v5
	s_waitcnt vmcnt(1)
	ds_store_b64 v7, v[13:14]
	s_waitcnt vmcnt(0)
	ds_store_b64 v8, v[10:11]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB1_3:                                ;   Parent Loop BB1_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v12, s12, v4
	s_add_i32 s12, s12, 8
	ds_load_b64 v[10:11], v9
	ds_load_b64 v[12:13], v12
	v_add_nc_u32_e32 v9, 0x80, v9
	s_cmpk_eq_i32 s12, 0x80
	s_waitcnt lgkmcnt(0)
	v_fma_f64 v[0:1], v[12:13], v[10:11], v[0:1]
	s_cbranch_scc0 .LBB1_3
; %bb.4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_add_i32 s11, s11, 16
	s_add_i32 s10, s10, s8
	s_cmp_ge_i32 s11, s9
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB1_2
	s_branch .LBB1_6
.LBB1_5:
	v_mov_b32_e32 v0, 0
	v_mov_b32_e32 v1, 0
.LBB1_6:                                ; %Flow69
	v_add_nc_u32_e32 v3, s2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v2, v3, v2, s3
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[2:3]
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_store_b64 v[2:3], v[0:1], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16matrixMultSharedPdS_S_i
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 15
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z16matrixMultSharedPdS_S_i, .Lfunc_end1-_Z16matrixMultSharedPdS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 432
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.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:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10matrixMultPKdS0_Pdi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10matrixMultPKdS0_Pdi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16matrixMultSharedPdS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16matrixMultSharedPdS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
