#include "MatrixUtilities.cuh"

HostMatrix MatrixUtilities::loadFromFile(const char* fileName) {
    std::ifstream fin;
    fin.open(fileName);
    if (!fin.is_open()) {
        std::cerr << "Could not open " << fileName << "." << std::endl;
        exit(EXIT_FAILURE);
    }

    unsigned int height = 0;
    unsigned int width = 0;
    fin >> height >> width;

    HostMatrix matrix(height, width);
    for (unsigned int i = 0; i < height; ++i) {
        for (unsigned int j = 0; j < width; ++j) {
            float value = 0.0f;
            fin >> value;
            matrix.setElement(i, j, value);
        }
    }

    fin.close();
    return matrix;
}

void MatrixUtilities::saveToFile(const HostMatrix& matrix, const char* fileName) {
    std::ofstream fout;
    fout.open(fileName);
    if (!fout.is_open()) {
        std::cerr << "Could not open " << fileName << "." << std::endl;
        exit(EXIT_FAILURE);
    }

    fout.setf(std::ios::fixed, std::ios::floatfield);
    fout.precision(6);
    fout << matrix.getHeight() << " " << matrix.getWidth() << std::endl;
    for (unsigned int i = 0; i < matrix.getHeight(); ++i) {
        for (unsigned int j = 0; j < matrix.getWidth(); ++j) {
            fout << matrix.getElement(i, j) << " ";
        }
        fout << std::endl;
    }

    fout.close();
}

bool MatrixUtilities::compare(const HostMatrix& matrixA, const HostMatrix& matrixB, float epsilon) {
    if (matrixA.getHeight() != matrixB.getHeight() || matrixA.getWidth() != matrixB.getWidth()) {
        return false;
    } else {
        for (unsigned int i = 0; i < matrixA.getHeight(); ++i) {
            for (unsigned int j = 0; j < matrixA.getWidth(); ++j) {
                if (fabs(matrixA.getElement(i, j) - matrixB.getElement(i, j)) > epsilon) {
                    return false;
                }
            }
        }
        return true;
    }
}

HostMatrix MatrixUtilities::copyToHost(const Matrix& matrix) {
    HostMatrix matrixCopy(matrix.getHeight(), matrix.getWidth());
    size_t count = matrix.getHeight() * matrix.getWidth() * sizeof(float);
    cudaMemcpyKind kind = matrix.isOnDevice()? cudaMemcpyDeviceToHost: cudaMemcpyHostToHost;
    cudaMemcpy(matrixCopy.getElements(), matrix.getElements(), count, kind);
    return matrixCopy;
}

DeviceMatrix MatrixUtilities::copyToDevice(const Matrix& matrix) {
    DeviceMatrix matrixCopy(matrix.getHeight(), matrix.getWidth());
    size_t count = matrix.getHeight() * matrix.getWidth() * sizeof(float);
    cudaMemcpyKind kind = matrix.isOnDevice()? cudaMemcpyDeviceToDevice: cudaMemcpyHostToDevice;
    cudaMemcpy(matrixCopy.getElements(), matrix.getElements(), count, kind);
    return matrixCopy;
}

template <>
HostMatrix MatrixUtilities::copy<HostMatrix>(const HostMatrix& matrix) {
    HostMatrix matrixCopy(matrix.getHeight(), matrix.getWidth());
    size_t count = matrix.getHeight() * matrix.getWidth() * sizeof(float);
    cudaMemcpy(matrixCopy.getElements(), matrix.getElements(), count, cudaMemcpyHostToHost);
    return matrixCopy;
}

template <>
DeviceMatrix MatrixUtilities::copy<DeviceMatrix>(const DeviceMatrix& matrix) {
    DeviceMatrix matrixCopy(matrix.getHeight(), matrix.getWidth());
    size_t count = matrix.getHeight() * matrix.getWidth() * sizeof(float);
    cudaMemcpy(matrixCopy.getElements(), matrix.getElements(), count, cudaMemcpyDeviceToDevice);
    return matrixCopy;
}
	.file	"tmpxft_00240792_00000000-6_MatrixUtilities.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4695:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4695:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN15MatrixUtilities7compareERK10HostMatrixS2_f
	.type	_ZN15MatrixUtilities7compareERK10HostMatrixS2_f, @function
_ZN15MatrixUtilities7compareERK10HostMatrixS2_f:
.LFB4682:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movl	8(%rdi), %eax
	movss	%xmm0, 8(%rsp)
	cmpl	%eax, 8(%rsi)
	jne	.L3
	movl	12(%rsi), %eax
	movq	%rdi, %rbx
	movq	%rsi, %r13
	xorl	%ebp, %ebp
	cmpl	%eax, 12(%rdi)
	jne	.L3
.L4:
	cmpl	8(%rbx), %ebp
	jnb	.L11
	xorl	%r12d, %r12d
.L6:
	cmpl	12(%rbx), %r12d
	jnb	.L12
	movq	(%rbx), %rax
	movl	%r12d, %edx
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	*(%rax)
	movq	0(%r13), %rax
	movl	%r12d, %edx
	movl	%ebp, %esi
	movss	%xmm0, 12(%rsp)
	movq	%r13, %rdi
	call	*(%rax)
	movss	12(%rsp), %xmm1
	subss	%xmm0, %xmm1
	andps	.LC0(%rip), %xmm1
	comiss	8(%rsp), %xmm1
	ja	.L3
	incl	%r12d
	jmp	.L6
.L12:
	incl	%ebp
	jmp	.L4
.L11:
	movb	$1, %al
	jmp	.L2
.L3:
	xorl	%eax, %eax
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	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
.LFE4682:
	.size	_ZN15MatrixUtilities7compareERK10HostMatrixS2_f, .-_ZN15MatrixUtilities7compareERK10HostMatrixS2_f
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4718:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4718:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv,"axG",@progbits,_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv,comdat
	.align 2
	.weak	_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv
	.type	_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv, @function
_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv:
.LFB5038:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	(%rdi), %rax
	movq	%rdi, 8(%rsp)
	call	*16(%rax)
	cmpb	$0, __libc_single_threaded(%rip)
	movq	8(%rsp), %rdi
	je	.L16
	movl	12(%rdi), %eax
	leal	-1(%rax), %edx
	movl	%edx, 12(%rdi)
	jmp	.L17
.L16:
	orl	$-1, %eax
	lock xaddl	%eax, 12(%rdi)
.L17:
	decl	%eax
	jne	.L15
	movq	(%rdi), %rax
	movq	24(%rax), %rax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	*%rax
.L15:
	.cfi_restore_state
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5038:
	.size	_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv, .-_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv
	.section	.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev,"axG",@progbits,_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED5Ev,comdat
	.align 2
	.weak	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev
	.type	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev, @function
_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev:
.LFB5044:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rdi
	testq	%rdi, %rdi
	je	.L20
	movq	8(%rdi), %rcx
	leaq	8(%rdi), %rdx
	movabsq	$4294967297, %rax
	cmpq	%rax, %rcx
	jne	.L23
	xorl	%eax, %eax
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rax, 8(%rdi)
	movq	(%rdi), %rax
	movq	%rdi, 8(%rsp)
	call	*16(%rax)
	movq	8(%rsp), %rdi
	movq	(%rdi), %rax
	movq	24(%rax), %rax
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	jmp	*%rax
.L23:
	cmpb	$0, __libc_single_threaded(%rip)
	je	.L24
	movl	8(%rdi), %eax
	leal	-1(%rax), %edx
	movl	%edx, 8(%rdi)
	jmp	.L25
.L24:
	orl	$-1, %eax
	lock xaddl	%eax, (%rdx)
.L25:
	decl	%eax
	jne	.L20
	jmp	_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE24_M_release_last_use_coldEv
.L20:
	ret
	.cfi_endproc
.LFE5044:
	.size	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev, .-_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev
	.weak	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev
	.set	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev,_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev
	.text
	.align 2
	.globl	_ZN15MatrixUtilities12copyToDeviceERK6Matrix
	.type	_ZN15MatrixUtilities12copyToDeviceERK6Matrix, @function
_ZN15MatrixUtilities12copyToDeviceERK6Matrix:
.LFB4684:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4684
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movl	12(%rsi), %edx
	movl	8(%rsi), %esi
.LEHB0:
	call	_ZN12DeviceMatrixC1Ejj@PLT
.LEHE0:
	movl	8(%rbp), %edx
	imull	12(%rbp), %edx
	movq	24(%rbp), %rsi
	movq	24(%rbx), %rdi
	salq	$2, %rdx
	cmpb	$1, 16(%rbp)
	sbbl	%ecx, %ecx
	andl	$-2, %ecx
	addl	$3, %ecx
.LEHB1:
	call	cudaMemcpy@PLT
.LEHE1:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L34:
	.cfi_restore_state
	endbr64
	movq	%rax, %rbp
.L32:
	leaq	16+_ZTV6Matrix(%rip), %rax
	leaq	32(%rbx), %rdi
	movq	%rax, (%rbx)
	call	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev
	movq	%rbp, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
	.cfi_endproc
.LFE4684:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4684:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4684-.LLSDACSB4684
.LLSDACSB4684:
	.uleb128 .LEHB0-.LFB4684
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB4684
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L34-.LFB4684
	.uleb128 0
	.uleb128 .LEHB2-.LFB4684
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE4684:
	.text
	.size	_ZN15MatrixUtilities12copyToDeviceERK6Matrix, .-_ZN15MatrixUtilities12copyToDeviceERK6Matrix
	.align 2
	.globl	_ZN15MatrixUtilities10copyToHostERK6Matrix
	.type	_ZN15MatrixUtilities10copyToHostERK6Matrix, @function
_ZN15MatrixUtilities10copyToHostERK6Matrix:
.LFB4683:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4683
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movl	12(%rsi), %edx
	movl	8(%rsi), %esi
.LEHB3:
	call	_ZN10HostMatrixC1Ejj@PLT
.LEHE3:
	movl	8(%rbp), %edx
	imull	12(%rbp), %edx
	movzbl	16(%rbp), %ecx
	movq	24(%rbp), %rsi
	movq	24(%rbx), %rdi
	addl	%ecx, %ecx
	salq	$2, %rdx
.LEHB4:
	call	cudaMemcpy@PLT
.LEHE4:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L39:
	.cfi_restore_state
	endbr64
	movq	%rax, %rbp
.L38:
	leaq	16+_ZTV6Matrix(%rip), %rax
	leaq	32(%rbx), %rdi
	movq	%rax, (%rbx)
	call	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev
	movq	%rbp, %rdi
.LEHB5:
	call	_Unwind_Resume@PLT
.LEHE5:
	.cfi_endproc
.LFE4683:
	.section	.gcc_except_table
.LLSDA4683:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4683-.LLSDACSB4683
.LLSDACSB4683:
	.uleb128 .LEHB3-.LFB4683
	.uleb128 .LEHE3-.LEHB3
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB4-.LFB4683
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L39-.LFB4683
	.uleb128 0
	.uleb128 .LEHB5-.LFB4683
	.uleb128 .LEHE5-.LEHB5
	.uleb128 0
	.uleb128 0
.LLSDACSE4683:
	.text
	.size	_ZN15MatrixUtilities10copyToHostERK6Matrix, .-_ZN15MatrixUtilities10copyToHostERK6Matrix
	.align 2
	.globl	_ZN15MatrixUtilities4copyI12DeviceMatrixEET_RKS2_
	.type	_ZN15MatrixUtilities4copyI12DeviceMatrixEET_RKS2_, @function
_ZN15MatrixUtilities4copyI12DeviceMatrixEET_RKS2_:
.LFB4692:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4692
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movl	12(%rsi), %edx
	movl	8(%rsi), %esi
.LEHB6:
	call	_ZN12DeviceMatrixC1Ejj@PLT
.LEHE6:
	movl	8(%rbp), %edx
	imull	12(%rbp), %edx
	movl	$3, %ecx
	movq	24(%rbp), %rsi
	movq	24(%rbx), %rdi
	salq	$2, %rdx
.LEHB7:
	call	cudaMemcpy@PLT
.LEHE7:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L44:
	.cfi_restore_state
	endbr64
	movq	%rax, %rbp
.L43:
	leaq	16+_ZTV6Matrix(%rip), %rax
	leaq	32(%rbx), %rdi
	movq	%rax, (%rbx)
	call	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev
	movq	%rbp, %rdi
.LEHB8:
	call	_Unwind_Resume@PLT
.LEHE8:
	.cfi_endproc
.LFE4692:
	.section	.gcc_except_table
.LLSDA4692:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4692-.LLSDACSB4692
.LLSDACSB4692:
	.uleb128 .LEHB6-.LFB4692
	.uleb128 .LEHE6-.LEHB6
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB7-.LFB4692
	.uleb128 .LEHE7-.LEHB7
	.uleb128 .L44-.LFB4692
	.uleb128 0
	.uleb128 .LEHB8-.LFB4692
	.uleb128 .LEHE8-.LEHB8
	.uleb128 0
	.uleb128 0
.LLSDACSE4692:
	.text
	.size	_ZN15MatrixUtilities4copyI12DeviceMatrixEET_RKS2_, .-_ZN15MatrixUtilities4copyI12DeviceMatrixEET_RKS2_
	.align 2
	.globl	_ZN15MatrixUtilities4copyI10HostMatrixEET_RKS2_
	.type	_ZN15MatrixUtilities4copyI10HostMatrixEET_RKS2_, @function
_ZN15MatrixUtilities4copyI10HostMatrixEET_RKS2_:
.LFB4691:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4691
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	movl	12(%rsi), %edx
	movl	8(%rsi), %esi
.LEHB9:
	call	_ZN10HostMatrixC1Ejj@PLT
.LEHE9:
	movl	8(%rbp), %edx
	imull	12(%rbp), %edx
	xorl	%ecx, %ecx
	movq	24(%rbp), %rsi
	movq	24(%rbx), %rdi
	salq	$2, %rdx
.LEHB10:
	call	cudaMemcpy@PLT
.LEHE10:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L49:
	.cfi_restore_state
	endbr64
	movq	%rax, %rbp
.L48:
	leaq	16+_ZTV6Matrix(%rip), %rax
	leaq	32(%rbx), %rdi
	movq	%rax, (%rbx)
	call	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev
	movq	%rbp, %rdi
.LEHB11:
	call	_Unwind_Resume@PLT
.LEHE11:
	.cfi_endproc
.LFE4691:
	.section	.gcc_except_table
.LLSDA4691:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4691-.LLSDACSB4691
.LLSDACSB4691:
	.uleb128 .LEHB9-.LFB4691
	.uleb128 .LEHE9-.LEHB9
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB10-.LFB4691
	.uleb128 .LEHE10-.LEHB10
	.uleb128 .L49-.LFB4691
	.uleb128 0
	.uleb128 .LEHB11-.LFB4691
	.uleb128 .LEHE11-.LEHB11
	.uleb128 0
	.uleb128 0
.LLSDACSE4691:
	.text
	.size	_ZN15MatrixUtilities4copyI10HostMatrixEET_RKS2_, .-_ZN15MatrixUtilities4copyI10HostMatrixEET_RKS2_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Could not open "
.LC2:
	.string	"."
	.text
	.align 2
	.globl	_ZN15MatrixUtilities12loadFromFileEPKc
	.type	_ZN15MatrixUtilities12loadFromFileEPKc, @function
_ZN15MatrixUtilities12loadFromFileEPKc:
.LFB4671:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4671
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	subq	$544, %rsp
	.cfi_def_cfa_offset 592
	movq	%fs:40, %rax
	movq	%rax, 536(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %r12
	movq	%r12, %rdi
.LEHB12:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE12:
	movl	$8, %edx
	movq	%rbp, %rsi
	movq	%r12, %rdi
.LEHB13:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	leaq	136(%rsp), %rdi
	call	_ZNKSt12__basic_fileIcE7is_openEv@PLT
	testb	%al, %al
	jne	.L53
	leaq	.LC1(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movq	%rbp, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	leaq	.LC2(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L53:
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	movq	%r12, %rdi
	movl	%eax, 4(%rsp)
	movl	%eax, 8(%rsp)
	call	_ZNSi10_M_extractIjEERSiRT_@PLT
	movq	%rax, %rdi
	leaq	8(%rsp), %rsi
	call	_ZNSi10_M_extractIjEERSiRT_@PLT
	movl	8(%rsp), %edx
	movl	4(%rsp), %esi
	movq	%rbx, %rdi
	call	_ZN10HostMatrixC1Ejj@PLT
.LEHE13:
	xorl	%ebp, %ebp
	leaq	12(%rsp), %r14
.L54:
	cmpl	4(%rsp), %ebp
	jnb	.L68
	xorl	%r13d, %r13d
.L56:
	cmpl	8(%rsp), %r13d
	jnb	.L69
	movq	%r14, %rsi
	movq	%r12, %rdi
	movl	$0x00000000, 12(%rsp)
.LEHB14:
	call	_ZNSi10_M_extractIfEERSiRT_@PLT
	movss	12(%rsp), %xmm0
	movl	%r13d, %edx
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_ZN10HostMatrix10setElementEjjf@PLT
	incl	%r13d
	jmp	.L56
.L69:
	incl	%ebp
	jmp	.L54
.L68:
	movq	%r12, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv@PLT
.LEHE14:
	movq	%r12, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	536(%rsp), %rax
	subq	%fs:40, %rax
	je	.L60
	jmp	.L66
.L64:
	endbr64
	movq	%rax, %rbp
.L57:
	leaq	16+_ZTV6Matrix(%rip), %rax
	leaq	32(%rbx), %rdi
	movq	%rax, (%rbx)
	call	_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED1Ev
	jmp	.L58
.L63:
	endbr64
	movq	%rax, %rbp
.L58:
	movq	%r12, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	536(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L66
	movq	%rbp, %rdi
.LEHB15:
	call	_Unwind_Resume@PLT
.LEHE15:
.L66:
	call	__stack_chk_fail@PLT
.L60:
	addq	$544, %rsp
	.cfi_def_cfa_offset 48
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4671:
	.section	.gcc_except_table
.LLSDA4671:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4671-.LLSDACSB4671
.LLSDACSB4671:
	.uleb128 .LEHB12-.LFB4671
	.uleb128 .LEHE12-.LEHB12
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB13-.LFB4671
	.uleb128 .LEHE13-.LEHB13
	.uleb128 .L63-.LFB4671
	.uleb128 0
	.uleb128 .LEHB14-.LFB4671
	.uleb128 .LEHE14-.LEHB14
	.uleb128 .L64-.LFB4671
	.uleb128 0
	.uleb128 .LEHB15-.LFB4671
	.uleb128 .LEHE15-.LEHB15
	.uleb128 0
	.uleb128 0
.LLSDACSE4671:
	.text
	.size	_ZN15MatrixUtilities12loadFromFileEPKc, .-_ZN15MatrixUtilities12loadFromFileEPKc
	.section	.rodata.str1.1
.LC4:
	.string	" "
	.text
	.align 2
	.globl	_ZN15MatrixUtilities10saveToFileERK10HostMatrixPKc
	.type	_ZN15MatrixUtilities10saveToFileERK10HostMatrixPKc, @function
_ZN15MatrixUtilities10saveToFileERK10HostMatrixPKc:
.LFB4681:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4681
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$528, %rsp
	.cfi_def_cfa_offset 576
	movq	%fs:40, %rax
	movq	%rax, 520(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
.LEHB16:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE16:
	movl	$16, %edx
	movq	%r12, %rsi
	movq	%rbx, %rdi
.LEHB17:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	leaq	120(%rsp), %rdi
	call	_ZNKSt12__basic_fileIcE7is_openEv@PLT
	testb	%al, %al
	jne	.L71
	leaq	.LC1(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movq	%r12, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	leaq	.LC2(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L71:
	movl	280(%rsp), %eax
	movl	8(%rbp), %esi
	movq	%rbx, %rdi
	movq	$6, 264(%rsp)
	andl	$-261, %eax
	orl	$4, %eax
	movl	%eax, 280(%rsp)
	call	_ZNSo9_M_insertImEERSoT_@PLT
	leaq	.LC4(%rip), %r14
	movq	%rax, %rdi
	movq	%r14, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	12(%rbp), %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	xorl	%r12d, %r12d
.L72:
	cmpl	8(%rbp), %r12d
	jnb	.L84
	xorl	%r13d, %r13d
.L74:
	cmpl	12(%rbp), %r13d
	jnb	.L85
	movq	0(%rbp), %rax
	movl	%r13d, %edx
	movl	%r12d, %esi
	movq	%rbp, %rdi
	call	*(%rax)
	movq	%rbx, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	movq	%r14, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	incl	%r13d
	jmp	.L74
.L85:
	movq	%rbx, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	incl	%r12d
	jmp	.L72
.L84:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv@PLT
.LEHE17:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	je	.L77
	jmp	.L82
.L80:
	endbr64
	movq	%rax, %rbp
.L75:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L82
	movq	%rbp, %rdi
.LEHB18:
	call	_Unwind_Resume@PLT
.LEHE18:
.L82:
	call	__stack_chk_fail@PLT
.L77:
	addq	$528, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4681:
	.section	.gcc_except_table
.LLSDA4681:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4681-.LLSDACSB4681
.LLSDACSB4681:
	.uleb128 .LEHB16-.LFB4681
	.uleb128 .LEHE16-.LEHB16
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB17-.LFB4681
	.uleb128 .LEHE17-.LEHB17
	.uleb128 .L80-.LFB4681
	.uleb128 0
	.uleb128 .LEHB18-.LFB4681
	.uleb128 .LEHE18-.LEHB18
	.uleb128 0
	.uleb128 0
.LLSDACSE4681:
	.text
	.size	_ZN15MatrixUtilities10saveToFileERK10HostMatrixPKc, .-_ZN15MatrixUtilities10saveToFileERK10HostMatrixPKc
	.weak	_ZTS6Matrix
	.section	.rodata._ZTS6Matrix,"aG",@progbits,_ZTS6Matrix,comdat
	.align 8
	.type	_ZTS6Matrix, @object
	.size	_ZTS6Matrix, 8
_ZTS6Matrix:
	.string	"6Matrix"
	.weak	_ZTI6Matrix
	.section	.data.rel.ro._ZTI6Matrix,"awG",@progbits,_ZTI6Matrix,comdat
	.align 8
	.type	_ZTI6Matrix, @object
	.size	_ZTI6Matrix, 16
_ZTI6Matrix:
	.quad	_ZTVN10__cxxabiv117__class_type_infoE+16
	.quad	_ZTS6Matrix
	.weak	_ZTV6Matrix
	.section	.data.rel.ro._ZTV6Matrix,"awG",@progbits,_ZTV6Matrix,comdat
	.align 8
	.type	_ZTV6Matrix, @object
	.size	_ZTV6Matrix, 32
_ZTV6Matrix:
	.quad	0
	.quad	_ZTI6Matrix
	.quad	__cxa_pure_virtual
	.quad	__cxa_pure_virtual
	.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.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.weak	__cxa_pure_virtual
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 _MATRIXUTILITIES_CUH_
#define _MATRIXUTILITIES_CUH_

#include "Matrix.cuh"

class MatrixUtilities {
public:
    static HostMatrix loadFromFile(const char* fileName);
    static void saveToFile(const HostMatrix& matrix, const char* fileName);

    static bool compare(const HostMatrix& matrixA, const HostMatrix& matrixB, float epsilon);

    static HostMatrix copyToHost(const Matrix& matrix);
    static DeviceMatrix copyToDevice(const Matrix& matrix);

    template <typename MatrixType>
    static MatrixType copy(const MatrixType& matrix);
};

#endif
	.text
	.file	"MatrixUtilities.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.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
