#include <cuda_runtime.h>
#include "device_launch_parameters.h"

#include <stdio.h>
#include <iostream>
#include <omp.h>
#include <chrono>
#include <random>
#include <iomanip>
#include <cmath>

#include "matrix_operations.cuh"

#define BLOCKSIZE_1 16

__global__ void kernel_naive_multiply_cuda(double* Ad, double* Bd, double* Cd, int M, int K, int N)
{
	double val = 0.;
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;

	if (row >= 0 && row < M && col >= 0 && col < N)
	{
		for (int k = 0; k < K; ++k)
		{
			val += *(Ad + (row)+k * M) * *(Bd + (col * K) + k);
		}
	}
	*(Cd + row + col * M) = val;
}

int naive_multiply_cuda(double* __restrict__ A, double* __restrict__ B,
	double* __restrict__ C, int M, int K, int N)
{
	dim3 threads(BLOCKSIZE_1, BLOCKSIZE_1); //threads per block
	unsigned int blocks_x = (N + threads.x - 1) / threads.x; //basically ceil(N/threads.x)
	unsigned int blocks_y = (M + threads.y - 1) / threads.y;
	dim3 blocks(blocks_x, blocks_y);
	kernel_naive_multiply_cuda<<<blocks, threads>>>(A, B, C, M, K, N);
	return 0;
}

int random_uniform_initialize(double* m, int M, int N, double lower, double upper)
{
	std::default_random_engine generator;
	std::uniform_real_distribution<double> distribution(lower, upper);

	for (int i = 0; i < M * N; ++i)
	{
		*(m + i) = distribution(generator);
	}
	return 0;
}

int naive_multiply_sequential(double* A, double* B, double* C, int M, int K, int N)
{
	for (int i = 0; i < M * N; ++i)
	{
		double val = 0.;
		int row = i % M;
		int col = i / M;
		for (int j = 0; j < K; ++j)
		{
			val += *(A + j * M + row) * *(B + col * K + j);
		}
		*(C + i) = val;
	}
	return 0;
}

int naive_multiply_omp(double* A, double* B, double* C, int M, int K, int N)
{
#pragma omp parallel for
	for (int i = 0; i < M * N; ++i)
	{
		//printf("hello from thread %d", omp_get_thread_num());
		double val = 0.;
		int row = i % M;
		int col = i / M;
		for (int j = 0; j < K; ++j)
		{
			val += *(A + j * M + row) * *(B + col * K + j);
		}
		*(C + i) = val;
	}
	return 0;
}

void print_matrix(const double* mat, int M, int N)
{
	std::cout << std::endl;
	for (int i = 0; i < M; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			std::cout << std::fixed << std::setprecision(3) << std::setw(8) << *(mat + j * M + i) << " ";
		}
		std::cout << std::endl;
	}
}

void print_matrix_big(const double* mat, int M, int N, int include)
{
	std::cout << std::endl << "[" << std::endl;
	for (int i = 0; i < include; ++i)
	{
		for (int j = 0; j < include; ++j)
		{
			std::cout << std::fixed << std::setprecision(3) << std::setw(8) << *(mat + j * M + i) << " ";
		}
		std::cout << "        ..." << std::endl;
	}
	std::cout << "                ...";
	for (int i = (M - include); i < M; ++i)
	{
		std::cout << std::endl << "                ...    ";
		for (int j = (N - include); j < N; ++j)
		{
			std::cout << std::fixed << std::setprecision(3) << std::setw(8) << *(mat + j * M + i) << " ";
		}
	}
	std::cout << std::endl << "]" << std::endl;
}

double max_diff(const double* mat1, const double* mat2, int M, int N)
{
	double maxd = 0.;
	double tdiff = 0.;
	for (int i = 0; i < M * N; ++i)
	{
		tdiff = std::abs(*(mat1 + i) - *(mat2 + i));
		if (tdiff > maxd)
		{
			maxd = tdiff;
		}
	}
	return maxd;
}
	.file	"tmpxft_00337851_00000000-6_matrix_operations.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.section	.text._ZSt5fixedRSt8ios_base,"axG",@progbits,_ZSt5fixedRSt8ios_base,comdat
	.weak	_ZSt5fixedRSt8ios_base
	.type	_ZSt5fixedRSt8ios_base, @function
_ZSt5fixedRSt8ios_base:
.LFB3285:
	.cfi_startproc
	endbr64
	movl	24(%rdi), %edx
	movq	%rdi, %rax
	andl	$-261, %edx
	orl	$4, %edx
	movl	%edx, 24(%rdi)
	ret
	.cfi_endproc
.LFE3285:
	.size	_ZSt5fixedRSt8ios_base, .-_ZSt5fixedRSt8ios_base
	.text
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB5107:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE5107:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z25random_uniform_initializePdiidd
	.type	_Z25random_uniform_initializePdiidd, @function
_Z25random_uniform_initializePdiidd:
.LFB5099:
	.cfi_startproc
	endbr64
	imull	%edx, %esi
	movsd	.LC2(%rip), %xmm5
	movaps	%xmm0, %xmm3
	xorl	%ecx, %ecx
	movsd	.LC3(%rip), %xmm6
	movsd	.LC4(%rip), %xmm7
	movl	$1, %edx
	xorps	%xmm4, %xmm4
	movl	%esi, %r8d
	movl	$2147483647, %esi
.L4:
	cmpl	%ecx, %r8d
	jle	.L13
	imulq	$16807, %rdx, %rax
	xorl	%edx, %edx
	divq	%rsi
	movq	%rdx, %rax
	decq	%rax
	js	.L5
	cvtsi2sdq	%rax, %xmm0
	jmp	.L6
.L5:
	movq	%rax, %r9
	andl	$1, %eax
	shrq	%r9
	orq	%rax, %r9
	cvtsi2sdq	%r9, %xmm0
	addsd	%xmm0, %xmm0
.L6:
	imulq	$16807, %rdx, %rax
	xorl	%edx, %edx
	addsd	%xmm4, %xmm0
	divq	%rsi
	movq	%rdx, %rax
	decq	%rax
	js	.L7
	cvtsi2sdq	%rax, %xmm2
	jmp	.L8
.L7:
	movq	%rax, %r9
	andl	$1, %eax
	shrq	%r9
	orq	%rax, %r9
	cvtsi2sdq	%r9, %xmm2
	addsd	%xmm2, %xmm2
.L8:
	mulsd	%xmm5, %xmm2
	addsd	%xmm2, %xmm0
	divsd	%xmm6, %xmm0
	comisd	%xmm7, %xmm0
	jb	.L9
	movsd	.LC0(%rip), %xmm0
.L9:
	movaps	%xmm1, %xmm2
	subsd	%xmm3, %xmm2
	mulsd	%xmm0, %xmm2
	addsd	%xmm3, %xmm2
	movsd	%xmm2, (%rdi,%rcx,8)
	incq	%rcx
	jmp	.L4
.L13:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE5099:
	.size	_Z25random_uniform_initializePdiidd, .-_Z25random_uniform_initializePdiidd
	.globl	_Z25naive_multiply_sequentialPdS_S_iii
	.type	_Z25naive_multiply_sequentialPdS_S_iii, @function
_Z25naive_multiply_sequentialPdS_S_iii:
.LFB5100:
	.cfi_startproc
	endbr64
	imull	%ecx, %r9d
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %r10
	movq	%rdx, %r11
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movslq	%ecx, %rbx
	xorl	%esi, %esi
	salq	$3, %rbx
.L15:
	movl	%esi, %eax
	cmpl	%esi, %r9d
	jle	.L20
	cltd
	xorps	%xmm0, %xmm0
	idivl	%ecx
	imull	%r8d, %eax
	movslq	%edx, %rdx
	leaq	(%rdi,%rdx,8), %rdx
	cltq
	leaq	(%r10,%rax,8), %rbp
	xorl	%eax, %eax
.L16:
	cmpl	%eax, %r8d
	jle	.L21
	movsd	(%rdx), %xmm1
	mulsd	0(%rbp,%rax,8), %xmm1
	addq	%rbx, %rdx
	incq	%rax
	addsd	%xmm1, %xmm0
	jmp	.L16
.L21:
	movsd	%xmm0, (%r11,%rsi,8)
	incq	%rsi
	jmp	.L15
.L20:
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5100:
	.size	_Z25naive_multiply_sequentialPdS_S_iii, .-_Z25naive_multiply_sequentialPdS_S_iii
	.globl	_Z18naive_multiply_ompPdS_S_iii
	.type	_Z18naive_multiply_ompPdS_S_iii, @function
_Z18naive_multiply_ompPdS_S_iii:
.LFB5892:
	.cfi_startproc
	endbr64
	jmp	_Z25naive_multiply_sequentialPdS_S_iii
	.cfi_endproc
.LFE5892:
	.size	_Z18naive_multiply_ompPdS_S_iii, .-_Z18naive_multiply_ompPdS_S_iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	" "
	.text
	.globl	_Z12print_matrixPKdii
	.type	_Z12print_matrixPKdii, @function
_Z12print_matrixPKdii:
.LFB5102:
	.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
	movl	%edx, %r14d
	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
	movq	%rdi, %r12
	leaq	_ZSt4cout(%rip), %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r13, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	0(,%r13,8), %rax
	xorl	%r13d, %r13d
	movq	%rax, 8(%rsp)
.L24:
	cmpl	%r13d, %ebx
	jle	.L23
	leaq	(%r12,%r13,8), %rbp
	xorl	%r15d, %r15d
.L27:
	cmpl	%r14d, %r15d
	jge	.L29
	leaq	_ZSt5fixedRSt8ios_base(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incl	%r15d
	call	_ZNSolsEPFRSt8ios_baseS0_E@PLT
	movsd	0(%rbp), %xmm0
	movq	%rax, %rdi
	movq	(%rax), %rax
	movq	-24(%rax), %rsi
	movq	$3, 8(%rdi,%rsi)
	movq	-24(%rax), %rax
	movq	$8, 16(%rdi,%rax)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	8(%rsp), %rax
	addq	%rax, %rbp
	jmp	.L27
.L29:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incq	%r13
	call	_ZNSolsEPFRSoS_E@PLT
	jmp	.L24
.L23:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5102:
	.size	_Z12print_matrixPKdii, .-_Z12print_matrixPKdii
	.section	.rodata.str1.1
.LC6:
	.string	"["
.LC7:
	.string	"        ..."
.LC8:
	.string	"                ..."
.LC9:
	.string	"                ...    "
.LC10:
	.string	"]"
	.text
	.globl	_Z16print_matrix_bigPKdiii
	.type	_Z16print_matrix_bigPKdiii, @function
_Z16print_matrix_bigPKdiii:
.LFB5103:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movslq	%ecx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	leaq	_ZSt4cout(%rip), %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r14, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movl	%edx, 20(%rsp)
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC6(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	movslq	%ebx, %rax
	salq	$3, %rax
	movq	%rax, 8(%rsp)
.L31:
	cmpl	%r15d, %ebp
	jle	.L40
	leaq	(%r12,%r15,8), %r13
	xorl	%ecx, %ecx
.L32:
	leaq	_ZSt5fixedRSt8ios_base(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rcx, 24(%rsp)
	call	_ZNSolsEPFRSt8ios_baseS0_E@PLT
	movsd	0(%r13), %xmm0
	movq	%rax, %rdi
	movq	(%rax), %rax
	movq	-24(%rax), %rsi
	movq	$3, 8(%rdi,%rsi)
	movq	-24(%rax), %rax
	movq	$8, 16(%rdi,%rax)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	24(%rsp), %rcx
	movq	8(%rsp), %rax
	incq	%rcx
	addq	%rax, %r13
	cmpq	%r14, %rcx
	jne	.L32
	leaq	.LC7(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incq	%r15
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	jmp	.L31
.L40:
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%ebx, %r13d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	20(%rsp), %r15d
	movl	%ebx, %eax
	subl	%ebp, %r13d
	movslq	%r13d, %r14
	subl	%ebp, %r15d
	imull	%r15d, %eax
	cltq
	leaq	(%r12,%rax,8), %r12
.L34:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	cmpl	%ebx, %r13d
	jge	.L41
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC9(%rip), %rsi
	leaq	(%r12,%r14,8), %rbp
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movslq	%r15d, %rdx
.L35:
	cmpl	%edx, 20(%rsp)
	jle	.L42
	leaq	_ZSt5fixedRSt8ios_base(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rdx, 24(%rsp)
	call	_ZNSolsEPFRSt8ios_baseS0_E@PLT
	movsd	0(%rbp), %xmm0
	movq	%rax, %rdi
	movq	(%rax), %rax
	movq	-24(%rax), %rcx
	movq	$3, 8(%rdi,%rcx)
	movq	-24(%rax), %rax
	movq	$8, 16(%rdi,%rax)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	24(%rsp), %rdx
	movq	8(%rsp), %rax
	incq	%rdx
	addq	%rax, %rbp
	jmp	.L35
.L42:
	incl	%r13d
	incq	%r14
	jmp	.L34
.L41:
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	movq	%rax, %rdi
	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
	jmp	_ZNSolsEPFRSoS_E@PLT
	.cfi_endproc
.LFE5103:
	.size	_Z16print_matrix_bigPKdiii, .-_Z16print_matrix_bigPKdiii
	.globl	_Z8max_diffPKdS0_ii
	.type	_Z8max_diffPKdS0_ii, @function
_Z8max_diffPKdS0_ii:
.LFB5104:
	.cfi_startproc
	endbr64
	imull	%ecx, %edx
	movq	.LC11(%rip), %xmm2
	xorl	%eax, %eax
	xorps	%xmm1, %xmm1
.L44:
	cmpl	%eax, %edx
	jle	.L47
	movsd	(%rdi,%rax,8), %xmm0
	subsd	(%rsi,%rax,8), %xmm0
	incq	%rax
	andps	%xmm2, %xmm0
	maxsd	%xmm1, %xmm0
	movaps	%xmm0, %xmm1
	jmp	.L44
.L47:
	movaps	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE5104:
	.size	_Z8max_diffPKdS0_ii, .-_Z8max_diffPKdS0_ii
	.globl	_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii
	.type	_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii, @function
_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii:
.LFB5129:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L48
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z26kernel_naive_multiply_cudaPdS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L48:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L50
	call	__stack_chk_fail@PLT
.L50:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5129:
	.size	_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii, .-_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii
	.globl	_Z26kernel_naive_multiply_cudaPdS_S_iii
	.type	_Z26kernel_naive_multiply_cudaPdS_S_iii, @function
_Z26kernel_naive_multiply_cudaPdS_S_iii:
.LFB5130:
	.cfi_startproc
	endbr64
	jmp	_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii
	.cfi_endproc
.LFE5130:
	.size	_Z26kernel_naive_multiply_cudaPdS_S_iii, .-_Z26kernel_naive_multiply_cudaPdS_S_iii
	.globl	_Z19naive_multiply_cudaPdS_S_iii
	.type	_Z19naive_multiply_cudaPdS_S_iii, @function
_Z19naive_multiply_cudaPdS_S_iii:
.LFB5098:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leal	15(%r9), %eax
	movl	%r8d, %r15d
	xorl	%r8d, %r8d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	shrl	$4, %eax
	movq	%rdx, %r14
	movabsq	$68719476752, %rdx
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	movl	$1, %esi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r9d, %ebp
	xorl	%r9d, %r9d
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	%eax, 20(%rsp)
	leal	15(%rcx), %eax
	movl	$1, %ecx
	shrl	$4, %eax
	movl	%eax, 24(%rsp)
	movq	20(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	movl	%ebp, %r9d
	movl	%r15d, %r8d
	movl	%ebx, %ecx
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z53__device_stub__Z26kernel_naive_multiply_cudaPdS_S_iiiPdS_S_iii
.L54:
	addq	$40, %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
.LFE5098:
	.size	_Z19naive_multiply_cudaPdS_S_iii, .-_Z19naive_multiply_cudaPdS_S_iii
	.section	.rodata.str1.1
.LC12:
	.string	"_Z26kernel_naive_multiply_cudaPdS_S_iii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB5132:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z26kernel_naive_multiply_cudaPdS_S_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE5132:
	.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	-1
	.long	1072693247
	.align 8
.LC2:
	.long	-8388608
	.long	1105199103
	.align 8
.LC3:
	.long	-16777216
	.long	1137704959
	.align 8
.LC4:
	.long	0
	.long	1072693248
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC11:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.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:

#ifndef MAT_OP
#define MAT_OP

int random_uniform_initialize(double* m, int M, int N, double lower, double upper);
int naive_multiply_sequential(double* A, double* B, double* C, int M, int K, int N);
int naive_multiply_omp(double* A, double* B, double* C, int M, int K, int N);
void print_matrix(const double* mat, int M, int N);
void print_matrix_big(const double* mat, int M, int N, int include);
double max_diff(const double* mat1, const double* mat2, int M, int N);

__global__ void kernel_naive_multiply_cuda(double* Ad, double* Bd, double* Cd, int M, int K, int N);
int naive_multiply_cuda(double* __restrict__ A, double* __restrict__ B, double* __restrict__ C, int M, int K, int N);

#endif
	.text
	.file	"matrix_operations.hip"
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
