#include "FloatMatrix.cuh"

#include <stdio.h>

#include "cuda_header.cuh"

FloatMatrix::FloatMatrix(long width, long height, FLOAT_MAT_TYPE* data) :Matrix(width, height) {
	this->data = data;
}

FLOAT_MAT_TYPE * FloatMatrix::getData() {
	return data;
}

FloatMatrix FloatMatrix::operator*(FloatMatrix& b) {
	FLOAT_MAT_TYPE* data = cublas_mul_matrix(this->getWidth(), this->getHeight(), this->getData(), b.getWidth(), b.getHeight(), b.getData());
	return FloatMatrix(b.getWidth(), this->getHeight(), data);
}

bool FloatMatrix::operator==(FloatMatrix& b) {
	if (this->getWidth() != b.getWidth() || this->getHeight() != b.getHeight())
		return false;
	for (unsigned long int i = 0; i < this->getWidth() * this->getHeight(); i++)
		if (this->data[i] != b.getData()[i]) {
			printf("Expected %f, got %f", data[i], b.getData()[i]);
			return false;
		}
	return true;
}

FloatMatrix::~FloatMatrix() {
	if (this->data)
		delete this->data;
}
	.file	"tmpxft_003738b7_00000000-6_FloatMatrix.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2038:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2038:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN11FloatMatrixC2EllPf
	.type	_ZN11FloatMatrixC2EllPf, @function
_ZN11FloatMatrixC2EllPf:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rcx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	_ZN6MatrixC2Ell@PLT
	movq	%rbp, 16(%rbx)
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_ZN11FloatMatrixC2EllPf, .-_ZN11FloatMatrixC2EllPf
	.globl	_ZN11FloatMatrixC1EllPf
	.set	_ZN11FloatMatrixC1EllPf,_ZN11FloatMatrixC2EllPf
	.align 2
	.globl	_ZN11FloatMatrix7getDataEv
	.type	_ZN11FloatMatrix7getDataEv, @function
_ZN11FloatMatrix7getDataEv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	16(%rdi), %rax
	ret
	.cfi_endproc
.LFE2030:
	.size	_ZN11FloatMatrix7getDataEv, .-_ZN11FloatMatrix7getDataEv
	.align 2
	.globl	_ZN11FloatMatrixmlERS_
	.type	_ZN11FloatMatrixmlERS_, @function
_ZN11FloatMatrixmlERS_:
.LFB2031:
	.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
	movq	%rdi, %r12
	movq	%rdx, %rdi
	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
	movq	%rdx, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	16(%rdx), %r9
	movq	%r9, 8(%rsp)
	call	_ZN6Matrix9getHeightEv@PLT
	movq	%rbx, %rdi
	movq	%rax, (%rsp)
	call	_ZN6Matrix8getWidthEv@PLT
	movq	%rbp, %rdi
	movq	16(%rbp), %r15
	movq	%rax, %r13
	call	_ZN6Matrix9getHeightEv@PLT
	movq	%rbp, %rdi
	movq	%rax, %r14
	call	_ZN6Matrix8getWidthEv@PLT
	movq	8(%rsp), %r9
	movq	%r13, %rcx
	movq	%r15, %rdx
	movq	(%rsp), %r8
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_Z17cublas_mul_matrixllPfllS_@PLT
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	_ZN6Matrix9getHeightEv@PLT
	movq	%rbx, %rdi
	movq	%rax, %rbp
	call	_ZN6Matrix8getWidthEv@PLT
	movq	%rbp, %rdx
	movq	%r12, %rdi
	movq	%rax, %rsi
	call	_ZN6MatrixC2Ell@PLT
	movq	%r13, 16(%r12)
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movq	%r12, %rax
	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
.LFE2031:
	.size	_ZN11FloatMatrixmlERS_, .-_ZN11FloatMatrixmlERS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Expected %f, got %f"
	.text
	.align 2
	.globl	_ZN11FloatMatrixeqERS_
	.type	_ZN11FloatMatrixeqERS_, @function
_ZN11FloatMatrixeqERS_:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rsi, %r13
	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
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	_ZN6Matrix8getWidthEv@PLT
	movq	%r13, %rdi
	movq	%rax, %rbp
	call	_ZN6Matrix8getWidthEv@PLT
	cmpq	%rax, %rbp
	jne	.L9
	movq	%rbx, %rdi
	xorl	%r12d, %r12d
	call	_ZN6Matrix9getHeightEv@PLT
	movq	%r13, %rdi
	movq	%rax, %rbp
	call	_ZN6Matrix9getHeightEv@PLT
	cmpq	%rax, %rbp
	je	.L11
	jmp	.L9
.L20:
	jne	.L16
	incq	%r12
.L11:
	movq	%rbx, %rdi
	call	_ZN6Matrix8getWidthEv@PLT
	movq	%rbx, %rdi
	movq	%rax, %rbp
	call	_ZN6Matrix9getHeightEv@PLT
	imulq	%rax, %rbp
	cmpq	%rbp, %r12
	jnb	.L19
	movq	16(%rbx), %rax
	movss	(%rax,%r12,4), %xmm0
	movq	16(%r13), %rax
	movss	(%rax,%r12,4), %xmm1
	ucomiss	%xmm1, %xmm0
	jnp	.L20
.L16:
	movl	$2, %edi
	movb	$2, %al
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
.L9:
	xorl	%eax, %eax
	jmp	.L7
.L19:
	movb	$1, %al
.L7:
	popq	%rdx
	.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
.LFE2032:
	.size	_ZN11FloatMatrixeqERS_, .-_ZN11FloatMatrixeqERS_
	.align 2
	.globl	_ZN11FloatMatrixD2Ev
	.type	_ZN11FloatMatrixD2Ev, @function
_ZN11FloatMatrixD2Ev:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	16(%rdi), %rdi
	testq	%rdi, %rdi
	je	.L21
	movl	$4, %esi
	jmp	_ZdlPvm@PLT
.L21:
	ret
	.cfi_endproc
.LFE2034:
	.size	_ZN11FloatMatrixD2Ev, .-_ZN11FloatMatrixD2Ev
	.globl	_ZN11FloatMatrixD1Ev
	.set	_ZN11FloatMatrixD1Ev,_ZN11FloatMatrixD2Ev
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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
.LFE2061:
	.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
	.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 "FloatMatrix.cuh"

#include <stdio.h>

#include "cuda_header.cuh"

FloatMatrix::FloatMatrix(long width, long height, FLOAT_MAT_TYPE* data) :Matrix(width, height) {
	this->data = data;
}

FLOAT_MAT_TYPE * FloatMatrix::getData() {
	return data;
}

FloatMatrix FloatMatrix::operator*(FloatMatrix& b) {
	FLOAT_MAT_TYPE* data = cublas_mul_matrix(this->getWidth(), this->getHeight(), this->getData(), b.getWidth(), b.getHeight(), b.getData());
	return FloatMatrix(b.getWidth(), this->getHeight(), data);
}

bool FloatMatrix::operator==(FloatMatrix& b) {
	if (this->getWidth() != b.getWidth() || this->getHeight() != b.getHeight())
		return false;
	for (unsigned long int i = 0; i < this->getWidth() * this->getHeight(); i++)
		if (this->data[i] != b.getData()[i]) {
			printf("Expected %f, got %f", data[i], b.getData()[i]);
			return false;
		}
	return true;
}

FloatMatrix::~FloatMatrix() {
	if (this->data)
		delete this->data;
}
	.text
	.file	"FloatMatrix.hip"
	.globl	_ZN11FloatMatrixC2EllPf         # -- Begin function _ZN11FloatMatrixC2EllPf
	.p2align	1, 0x90
	.type	_ZN11FloatMatrixC2EllPf,@function
_ZN11FloatMatrixC2EllPf:                # @_ZN11FloatMatrixC2EllPf
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rcx, %rbx
	movq	%rdi, %r14
	callq	_ZN6MatrixC2Ell
	movq	%rbx, 16(%r14)
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_ZN11FloatMatrixC2EllPf, .Lfunc_end0-_ZN11FloatMatrixC2EllPf
	.cfi_endproc
                                        # -- End function
	.globl	_ZN11FloatMatrix7getDataEv      # -- Begin function _ZN11FloatMatrix7getDataEv
	.p2align	1, 0x90
	.type	_ZN11FloatMatrix7getDataEv,@function
_ZN11FloatMatrix7getDataEv:             # @_ZN11FloatMatrix7getDataEv
	.cfi_startproc
# %bb.0:
	movq	16(%rdi), %rax
	retq
.Lfunc_end1:
	.size	_ZN11FloatMatrix7getDataEv, .Lfunc_end1-_ZN11FloatMatrix7getDataEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN11FloatMatrixmlERS_          # -- Begin function _ZN11FloatMatrixmlERS_
	.p2align	1, 0x90
	.type	_ZN11FloatMatrixmlERS_,@function
_ZN11FloatMatrixmlERS_:                 # @_ZN11FloatMatrixmlERS_
	.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	%rdx, %r15
	movq	%rsi, %r14
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	callq	_ZN6Matrix8getWidthEv
	movq	%rax, (%rsp)                    # 8-byte Spill
	movq	%r14, %rdi
	callq	_ZN6Matrix9getHeightEv
	movq	%rax, %r13
	movq	16(%r14), %rbp
	movq	%r15, %rdi
	callq	_ZN6Matrix8getWidthEv
	movq	%rax, %r12
	movq	%r15, %rdi
	callq	_ZN6Matrix9getHeightEv
	movq	16(%r15), %r9
	movq	(%rsp), %rdi                    # 8-byte Reload
	movq	%r13, %rsi
	movq	%rbp, %rdx
	movq	%r12, %rcx
	movq	%rax, %r8
	callq	_Z17cublas_mul_matrixllPfllS_
	movq	%rax, %r12
	movq	%r15, %rdi
	callq	_ZN6Matrix8getWidthEv
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	_ZN6Matrix9getHeightEv
	movq	%rbx, %rdi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZN6MatrixC2Ell
	movq	%r12, 16(%rbx)
	movq	%rbx, %rax
	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_end2:
	.size	_ZN11FloatMatrixmlERS_, .Lfunc_end2-_ZN11FloatMatrixmlERS_
	.cfi_endproc
                                        # -- End function
	.globl	_ZN11FloatMatrixeqERS_          # -- Begin function _ZN11FloatMatrixeqERS_
	.p2align	1, 0x90
	.type	_ZN11FloatMatrixeqERS_,@function
_ZN11FloatMatrixeqERS_:                 # @_ZN11FloatMatrixeqERS_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	callq	_ZN6Matrix8getWidthEv
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	_ZN6Matrix8getWidthEv
	cmpq	%rax, %r15
	jne	.LBB3_7
# %bb.1:
	movq	%r14, %rdi
	callq	_ZN6Matrix9getHeightEv
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	_ZN6Matrix9getHeightEv
	cmpq	%rax, %r15
	jne	.LBB3_7
# %bb.2:                                # %.preheader
	movq	%r14, %rdi
	callq	_ZN6Matrix8getWidthEv
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	_ZN6Matrix9getHeightEv
	testq	%r15, %r15
	sete	%cl
	testq	%rax, %rax
	sete	%al
	orb	%cl, %al
	movb	$1, %bpl
	jne	.LBB3_8
# %bb.3:                                # %.lr.ph
	xorl	%r12d, %r12d
.LBB3_5:                                # =>This Inner Loop Header: Depth=1
	movq	16(%r14), %rax
	movss	(%rax,%r12,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movq	16(%rbx), %rax
	movss	(%rax,%r12,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm0
	jne	.LBB3_6
	jp	.LBB3_6
# %bb.4:                                #   in Loop: Header=BB3_5 Depth=1
	incq	%r12
	movq	%r14, %rdi
	callq	_ZN6Matrix8getWidthEv
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	_ZN6Matrix9getHeightEv
	imulq	%r15, %rax
	cmpq	%rax, %r12
	jb	.LBB3_5
	jmp	.LBB3_8
.LBB3_6:
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	movl	$.L.str, %edi
	movb	$2, %al
	callq	printf
.LBB3_7:                                # %.loopexit
	xorl	%ebp, %ebp
.LBB3_8:                                # %.loopexit
	movl	%ebp, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_ZN11FloatMatrixeqERS_, .Lfunc_end3-_ZN11FloatMatrixeqERS_
	.cfi_endproc
                                        # -- End function
	.globl	_ZN11FloatMatrixD2Ev            # -- Begin function _ZN11FloatMatrixD2Ev
	.p2align	1, 0x90
	.type	_ZN11FloatMatrixD2Ev,@function
_ZN11FloatMatrixD2Ev:                   # @_ZN11FloatMatrixD2Ev
	.cfi_startproc
# %bb.0:
	movq	16(%rdi), %rdi
	testq	%rdi, %rdi
	jne	_ZdlPv                          # TAILCALL
# %bb.1:
	retq
.Lfunc_end4:
	.size	_ZN11FloatMatrixD2Ev, .Lfunc_end4-_ZN11FloatMatrixD2Ev
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Expected %f, got %f"
	.size	.L.str, 20

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.globl	_ZN11FloatMatrixC1EllPf
	.type	_ZN11FloatMatrixC1EllPf,@function
.set _ZN11FloatMatrixC1EllPf, _ZN11FloatMatrixC2EllPf
	.globl	_ZN11FloatMatrixD1Ev
	.type	_ZN11FloatMatrixD1Ev,@function
.set _ZN11FloatMatrixD1Ev, _ZN11FloatMatrixD2Ev
	.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
