#include <iostream>
#include <algorithm>

using namespace std;

class Net {
private:
	int rows, cols;
	int** inputTensor;
	int** outputTensor;
public:
	Net(int, int);
	int relulayer();
	void poolingFunction(int, int, bool);
	void filterConvolve(int);
	void printArray();

};

Net::Net(int r, int c) {
	rows = r;
	cols = c;
	cout << "\n\nInitialization of " << rows << " x " << cols
			<< " 2D array with random values between -9 and 9\n\n";
	//input tensor initialization
	inputTensor = new int*[rows];
	for (int k = 0; k < rows; k++)
		inputTensor[k] = new int[cols];

	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			inputTensor[i][j] = rand() % 19 + (-9);
		}
	}

	//output tensor initialization to zero
	outputTensor = new int*[rows];
	for (int k = 0; k < rows; k++)
		outputTensor[k] = new int[cols];

	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			outputTensor[i][j] = 0;
		}
	}

}

int Net::relulayer() {
	/*
	 * A `ReLULayer` is the identity function for
	 * non-negative inputs, and gives zero for negative inputs.
	 */
	cout
			<< "\n\nReluLayer Identity Function converts negative inputs to zero\n\n";
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			if (inputTensor[i][j] < 0)
				outputTensor[i][j] = 0;
			else
				outputTensor[i][j] = inputTensor[i][j];
		}
	}
	return 0;
}

void Net::printArray() {

	cout << "\n\nINPUT TENSOR\n\n";
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			cout << inputTensor[i][j] << '\t';
		}
		cout << "\n";
	}

	cout << "\n\nOUTPUT TENSOR\n\n";
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			cout << outputTensor[i][j] << '\t';
		}
		cout << "\n";
	}
}

void Net::poolingFunction(int stride, int windowSize, bool minMax)
{

	//output matrix calculation
	//bool minMax=true implied min else max operation
	cout << "\n\nPooling function -- find on min/max operations\n\n";
	if (minMax == true)
		cout << "Pools using min operation, stride is " << stride
				<< " and window size is " << windowSize << endl;
	else
		cout << "Pools using max operation, stride is " << stride
				<< " and window size is " << windowSize << endl;


	int kernelSize = windowSize / 2;
	int minimum=999,maximum=-999;
	for (int y = 1; y < rows - 1; y++) {
		for (int x = 1; x < cols - 1; x++) {
			for (int k = -kernelSize; k <= kernelSize; k++) {
				for (int j = -kernelSize; j <= kernelSize; j++) {
					if (minMax == true)
						minimum = min(inputTensor[j + 1][k + 1],
								inputTensor[y - j][x - k]);
					else
						maximum = max(inputTensor[j + 1][k + 1],
								inputTensor[y - j][x - k]);
				}
			}
			if (minMax == true)
				outputTensor[y][x] = minimum;
			else
				outputTensor[y][x] = maximum;

		}
	}
}

void Net::filterConvolve(int windowSize) {
	cout << "\n\nConvolution function \n\n";
	int sum;
	int kernelSize = windowSize / 2;
	for (int y = 1; y < rows - 1; y++) {
		for (int x = 1; x < cols - 1; x++) {
			sum = 0;
			for (int k = -kernelSize; k <= kernelSize; k++) {
				for (int j = -kernelSize; j <= kernelSize; j++) {
					sum = sum
							+ inputTensor[j + 1][k + 1]
									* inputTensor[y - j][x - k];
				}
			}
			outputTensor[y][x] = sum;
		}
	}
}

int main() {
	Net net(3, 6);
	net.printArray();
	net.relulayer();
	net.printArray();
	net.poolingFunction(3, 3, false);
	net.printArray();
	net.filterConvolve(3);
	net.printArray();

	return 0;
}


	.file	"tmpxft_002fc16f_00000000-6_tensor.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3899:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3899:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0, @function
_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0:
.LFB4551:
	.cfi_startproc
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	(%rdi), %rax
	movb	%sil, 12(%rsp)
	movq	-24(%rax), %rax
	cmpq	$0, 16(%rdi,%rax)
	je	.L3
	leaq	12(%rsp), %rsi
	movl	$1, %edx
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	jmp	.L2
.L3:
	movsbl	12(%rsp), %esi
	call	_ZNSo3putEc@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4551:
	.size	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0, .-_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\n\nInitialization of "
.LC1:
	.string	" x "
.LC2:
	.string	" 2D array with random values between -9 and 9\n\n"
	.text
	.align 2
	.globl	_ZN3NetC2Eii
	.type	_ZN3NetC2Eii, @function
_ZN3NetC2Eii:
.LFB3890:
	.cfi_startproc
	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
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	movl	%edx, 4(%rdi)
	movl	%esi, (%rdi)
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%rbx), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	4(%rbx), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movslq	(%rbx), %rdi
	movabsq	$1152921504606846975, %rax
	cmpq	%rdi, %rax
	jb	.L8
	movabsq	$2305843009213693950, %r12
	salq	$3, %rdi
	xorl	%ebp, %ebp
	call	_Znam@PLT
	movq	%rax, 8(%rbx)
	jmp	.L9
.L8:
	call	__cxa_throw_bad_array_new_length@PLT
.L10:
	movslq	4(%rbx), %rdi
	cmpq	%rdi, %r12
	jb	.L8
	movq	8(%rbx), %rax
	salq	$2, %rdi
	leaq	(%rax,%rbp,8), %r13
	incq	%rbp
	call	_Znam@PLT
	movq	%rax, 0(%r13)
.L9:
	cmpl	%ebp, (%rbx)
	jg	.L10
	xorl	%r12d, %r12d
	movl	$19, %r13d
.L11:
	movslq	(%rbx), %rdi
	cmpl	%r12d, %edi
	jle	.L13
	leaq	0(,%r12,8), %r14
	xorl	%ebp, %ebp
.L14:
	cmpl	%ebp, 4(%rbx)
	jle	.L22
	call	rand@PLT
	movq	8(%rbx), %rdx
	movq	(%rdx,%r14), %rcx
	cltd
	idivl	%r13d
	subl	$9, %edx
	movl	%edx, (%rcx,%rbp,4)
	incq	%rbp
	jmp	.L14
.L22:
	incq	%r12
	jmp	.L11
.L13:
	movabsq	$1152921504606846975, %rax
	cmpq	%rdi, %rax
	jb	.L8
	movabsq	$2305843009213693950, %r12
	salq	$3, %rdi
	xorl	%ebp, %ebp
	call	_Znam@PLT
	movq	%rax, 16(%rbx)
.L15:
	movl	(%rbx), %ecx
	cmpl	%ebp, %ecx
	jle	.L23
	movslq	4(%rbx), %rdi
	cmpq	%rdi, %r12
	jb	.L8
	movq	16(%rbx), %rax
	salq	$2, %rdi
	leaq	(%rax,%rbp,8), %r13
	incq	%rbp
	call	_Znam@PLT
	movq	%rax, 0(%r13)
	jmp	.L15
.L23:
	xorl	%edx, %edx
.L17:
	cmpl	%edx, %ecx
	jle	.L7
	movl	4(%rbx), %edi
	leaq	0(,%rdx,8), %rsi
	xorl	%eax, %eax
.L20:
	cmpl	%eax, %edi
	jle	.L24
	movq	16(%rbx), %r8
	xorl	%r9d, %r9d
	movq	(%r8,%rsi), %r8
	movl	%r9d, (%r8,%rax,4)
	incq	%rax
	jmp	.L20
.L24:
	incq	%rdx
	jmp	.L17
.L7:
	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
.LFE3890:
	.size	_ZN3NetC2Eii, .-_ZN3NetC2Eii
	.globl	_ZN3NetC1Eii
	.set	_ZN3NetC1Eii,_ZN3NetC2Eii
	.section	.rodata.str1.1
.LC3:
	.string	"\n\nReluLayer Identity Function converts negative inputs to zero\n\n"
	.text
	.align 2
	.globl	_ZN3Net9relulayerEv
	.type	_ZN3Net9relulayerEv, @function
_ZN3Net9relulayerEv:
.LFB3892:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC3(%rip), %rsi
	movq	%rdi, %rbx
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	xorl	%edx, %edx
.L26:
	cmpl	%edx, (%rbx)
	jle	.L28
	leaq	0(,%rdx,8), %rsi
	xorl	%eax, %eax
.L29:
	cmpl	%eax, 4(%rbx)
	jle	.L31
	movq	16(%rbx), %rcx
	xorl	%r8d, %r8d
	movq	(%rcx,%rsi), %rdi
	movq	8(%rbx), %rcx
	movq	(%rcx,%rsi), %rcx
	movl	(%rcx,%rax,4), %ecx
	testl	%ecx, %ecx
	cmovs	%r8d, %ecx
	movl	%ecx, (%rdi,%rax,4)
	incq	%rax
	jmp	.L29
.L31:
	incq	%rdx
	jmp	.L26
.L28:
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3892:
	.size	_ZN3Net9relulayerEv, .-_ZN3Net9relulayerEv
	.section	.rodata.str1.1
.LC4:
	.string	"\n\nINPUT TENSOR\n\n"
.LC5:
	.string	"\n"
.LC6:
	.string	"\n\nOUTPUT TENSOR\n\n"
	.text
	.align 2
	.globl	_ZN3Net10printArrayEv
	.type	_ZN3Net10printArrayEv, @function
_ZN3Net10printArrayEv:
.LFB3893:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC4(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC5(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	_ZSt4cout(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	movq	%rbp, %rdi
	pushq	%rdx
	.cfi_def_cfa_offset 64
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L33:
	cmpl	%r13d, (%rbx)
	jle	.L35
	leaq	0(,%r13,8), %r15
	xorl	%r12d, %r12d
.L36:
	cmpl	%r12d, 4(%rbx)
	jle	.L42
	movq	8(%rbx), %rax
	movq	%rbp, %rdi
	movq	(%rax,%r15), %rax
	movl	(%rax,%r12,4), %esi
	incq	%r12
	call	_ZNSolsEi@PLT
	movl	$9, %esi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0
	jmp	.L36
.L42:
	movq	%r14, %rsi
	movq	%rbp, %rdi
	incq	%r13
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L33
.L35:
	leaq	.LC6(%rip), %rsi
	movq	%rbp, %rdi
	xorl	%r13d, %r13d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC5(%rip), %r14
.L37:
	cmpl	%r13d, (%rbx)
	jle	.L32
	leaq	0(,%r13,8), %r15
	xorl	%r12d, %r12d
.L40:
	cmpl	%r12d, 4(%rbx)
	jle	.L43
	movq	16(%rbx), %rax
	movq	%rbp, %rdi
	movq	(%rax,%r15), %rax
	movl	(%rax,%r12,4), %esi
	incq	%r12
	call	_ZNSolsEi@PLT
	movl	$9, %esi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.isra.0
	jmp	.L40
.L43:
	movq	%r14, %rsi
	movq	%rbp, %rdi
	incq	%r13
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L37
.L32:
	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
.LFE3893:
	.size	_ZN3Net10printArrayEv, .-_ZN3Net10printArrayEv
	.section	.rodata.str1.1
.LC7:
	.string	"\n\nPooling function -- find on min/max operations\n\n"
.LC8:
	.string	"Pools using min operation, stride is "
.LC9:
	.string	" and window size is "
.LC10:
	.string	"Pools using max operation, stride is "
	.text
	.align 2
	.globl	_ZN3Net15poolingFunctionEiib
	.type	_ZN3Net15poolingFunctionEiib, @function
_ZN3Net15poolingFunctionEiib:
.LFB3894:
	.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	%ecx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%esi, %r13d
	leaq	.LC7(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	leaq	_ZSt4cout(%rip), %rdi
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	testb	%r14b, %r14b
	leaq	_ZSt4cout(%rip), %rdi
	leaq	.LC9(%rip), %r14
	leaq	.LC8(%rip), %rsi
	jne	.L60
	leaq	.LC10(%rip), %rsi
.L60:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r13d, %esi
	movl	$-999, %r15d
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%r14, %rsi
	movl	$999, %r14d
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	%r12d, %eax
	movl	$2, %ecx
	movl	$1, 4(%rsp)
	cltd
	idivl	%ecx
	movl	%eax, %r11d
	negl	%r11d
	movslq	%r11d, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	%rcx, 8(%rsp)
	movl	$8, %ecx
.L47:
	movl	(%rbx), %edx
	movl	4(%rsp), %esi
	decl	%edx
	cmpl	%esi, %edx
	jle	.L61
	movl	$4, %r12d
	movl	$1, %esi
.L55:
	movl	4(%rbx), %edx
	decl	%edx
	cmpl	%esi, %edx
	jle	.L62
	movl	%r11d, %edx
.L54:
	cmpl	%eax, %edx
	jg	.L51
	movl	%esi, %edi
	movl	%r11d, %r13d
	subl	%edx, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	movq	%rdi, 16(%rsp)
	leal	1(%rdx), %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	movq	%rdi, 24(%rsp)
	movq	8(%rsp), %rdi
.L52:
	cmpl	%eax, %r13d
	jg	.L63
	movq	8(%rbx), %r8
	movq	%rcx, %r9
	movq	16(%rsp), %r10
	incl	%r13d
	subq	%rdi, %r9
	addq	$8, %rdi
	movq	(%r8,%r9), %r9
	movq	(%r8,%rdi), %r8
	movl	(%r9,%r10), %r9d
	movq	24(%rsp), %r10
	movl	(%r8,%r10), %r8d
	testb	%bpl, %bpl
	je	.L48
	cmpl	%r8d, %r9d
	movl	%r8d, %r14d
	cmovle	%r9d, %r14d
	jmp	.L52
.L48:
	cmpl	%r8d, %r9d
	movl	%r8d, %r15d
	cmovge	%r9d, %r15d
	jmp	.L52
.L63:
	incl	%edx
	jmp	.L54
.L51:
	movq	16(%rbx), %rdx
	movq	(%rdx,%rcx), %rdi
	addq	%r12, %rdi
	testb	%bpl, %bpl
	movq	%rdi, %rdx
	movl	%r15d, %edi
	cmovne	%r14d, %edi
	incl	%esi
	addq	$4, %r12
	movl	%edi, (%rdx)
	jmp	.L55
.L62:
	incl	4(%rsp)
	addq	$8, %rcx
	jmp	.L47
.L61:
	addq	$40, %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
.LFE3894:
	.size	_ZN3Net15poolingFunctionEiib, .-_ZN3Net15poolingFunctionEiib
	.section	.rodata.str1.1
.LC11:
	.string	"\n\nConvolution function \n\n"
	.text
	.align 2
	.globl	_ZN3Net14filterConvolveEi
	.type	_ZN3Net14filterConvolveEi, @function
_ZN3Net14filterConvolveEi:
.LFB3895:
	.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
	movl	%esi, %ebp
	leaq	.LC11(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	leaq	_ZSt4cout(%rip), %rdi
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %eax
	movl	$2, %ecx
	movl	$8, %edi
	cltd
	movl	$1, %r10d
	idivl	%ecx
	movl	%eax, %r11d
	negl	%r11d
	movslq	%r11d, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	%rcx, 8(%rsp)
.L65:
	movl	(%rbx), %ecx
	leal	-1(%rcx), %edx
	cmpl	%r10d, %edx
	jle	.L74
	movl	$4, %ebp
	movl	$1, %r8d
.L70:
	movl	4(%rbx), %ecx
	leal	-1(%rcx), %edx
	cmpl	%r8d, %edx
	jle	.L75
	movl	%r11d, %ecx
	xorl	%r12d, %r12d
.L69:
	cmpl	%eax, %ecx
	jg	.L67
	movl	%r8d, %edx
	leal	1(%rcx), %esi
	movq	8(%rsp), %r9
	movl	%r11d, %r13d
	subl	%ecx, %edx
	movslq	%esi, %rsi
	movslq	%edx, %rdx
	salq	$2, %rsi
	salq	$2, %rdx
	movq	%rdx, (%rsp)
.L68:
	leaq	8(%r9), %r14
	cmpl	%eax, %r13d
	jg	.L76
	movq	8(%rbx), %rdx
	movq	%rdi, %r15
	incl	%r13d
	subq	%r9, %r15
	movq	(%rdx,%r15), %r15
	movq	8(%rdx,%r9), %r9
	movq	(%rsp), %rdx
	movl	(%r15,%rdx), %r15d
	imull	(%r9,%rsi), %r15d
	movq	%r14, %r9
	addl	%r15d, %r12d
	jmp	.L68
.L76:
	incl	%ecx
	jmp	.L69
.L67:
	movq	16(%rbx), %rdx
	incl	%r8d
	movq	(%rdx,%rdi), %rdx
	movl	%r12d, (%rdx,%rbp)
	addq	$4, %rbp
	jmp	.L70
.L75:
	incl	%r10d
	addq	$8, %rdi
	jmp	.L65
.L74:
	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
.LFE3895:
	.size	_ZN3Net14filterConvolveEi, .-_ZN3Net14filterConvolveEi
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3896:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	$6, %edx
	movl	$3, %esi
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	call	_ZN3NetC1Eii
	movq	%rbx, %rdi
	call	_ZN3Net10printArrayEv
	movq	%rbx, %rdi
	call	_ZN3Net9relulayerEv
	movq	%rbx, %rdi
	call	_ZN3Net10printArrayEv
	xorl	%ecx, %ecx
	movl	$3, %edx
	movq	%rbx, %rdi
	movl	$3, %esi
	call	_ZN3Net15poolingFunctionEiib
	movq	%rbx, %rdi
	call	_ZN3Net10printArrayEv
	movq	%rbx, %rdi
	movl	$3, %esi
	call	_ZN3Net14filterConvolveEi
	movq	%rbx, %rdi
	call	_ZN3Net10printArrayEv
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L78
	call	__stack_chk_fail@PLT
.L78:
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3896:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3922:
	.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
.LFE3922:
	.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 <iostream>
#include <algorithm>

using namespace std;

class Net {
private:
	int rows, cols;
	int** inputTensor;
	int** outputTensor;
public:
	Net(int, int);
	int relulayer();
	void poolingFunction(int, int, bool);
	void filterConvolve(int);
	void printArray();

};

Net::Net(int r, int c) {
	rows = r;
	cols = c;
	cout << "\n\nInitialization of " << rows << " x " << cols
			<< " 2D array with random values between -9 and 9\n\n";
	//input tensor initialization
	inputTensor = new int*[rows];
	for (int k = 0; k < rows; k++)
		inputTensor[k] = new int[cols];

	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			inputTensor[i][j] = rand() % 19 + (-9);
		}
	}

	//output tensor initialization to zero
	outputTensor = new int*[rows];
	for (int k = 0; k < rows; k++)
		outputTensor[k] = new int[cols];

	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			outputTensor[i][j] = 0;
		}
	}

}

int Net::relulayer() {
	/*
	 * A `ReLULayer` is the identity function for
	 * non-negative inputs, and gives zero for negative inputs.
	 */
	cout
			<< "\n\nReluLayer Identity Function converts negative inputs to zero\n\n";
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			if (inputTensor[i][j] < 0)
				outputTensor[i][j] = 0;
			else
				outputTensor[i][j] = inputTensor[i][j];
		}
	}
	return 0;
}

void Net::printArray() {

	cout << "\n\nINPUT TENSOR\n\n";
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			cout << inputTensor[i][j] << '\t';
		}
		cout << "\n";
	}

	cout << "\n\nOUTPUT TENSOR\n\n";
	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			cout << outputTensor[i][j] << '\t';
		}
		cout << "\n";
	}
}

void Net::poolingFunction(int stride, int windowSize, bool minMax)
{

	//output matrix calculation
	//bool minMax=true implied min else max operation
	cout << "\n\nPooling function -- find on min/max operations\n\n";
	if (minMax == true)
		cout << "Pools using min operation, stride is " << stride
				<< " and window size is " << windowSize << endl;
	else
		cout << "Pools using max operation, stride is " << stride
				<< " and window size is " << windowSize << endl;


	int kernelSize = windowSize / 2;
	int minimum=999,maximum=-999;
	for (int y = 1; y < rows - 1; y++) {
		for (int x = 1; x < cols - 1; x++) {
			for (int k = -kernelSize; k <= kernelSize; k++) {
				for (int j = -kernelSize; j <= kernelSize; j++) {
					if (minMax == true)
						minimum = min(inputTensor[j + 1][k + 1],
								inputTensor[y - j][x - k]);
					else
						maximum = max(inputTensor[j + 1][k + 1],
								inputTensor[y - j][x - k]);
				}
			}
			if (minMax == true)
				outputTensor[y][x] = minimum;
			else
				outputTensor[y][x] = maximum;

		}
	}
}

void Net::filterConvolve(int windowSize) {
	cout << "\n\nConvolution function \n\n";
	int sum;
	int kernelSize = windowSize / 2;
	for (int y = 1; y < rows - 1; y++) {
		for (int x = 1; x < cols - 1; x++) {
			sum = 0;
			for (int k = -kernelSize; k <= kernelSize; k++) {
				for (int j = -kernelSize; j <= kernelSize; j++) {
					sum = sum
							+ inputTensor[j + 1][k + 1]
									* inputTensor[y - j][x - k];
				}
			}
			outputTensor[y][x] = sum;
		}
	}
}

int main() {
	Net net(3, 6);
	net.printArray();
	net.relulayer();
	net.printArray();
	net.poolingFunction(3, 3, false);
	net.printArray();
	net.filterConvolve(3);
	net.printArray();

	return 0;
}


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

                                        # End of file scope inline assembly
	.globl	_ZN3NetC2Eii                    # -- Begin function _ZN3NetC2Eii
	.p2align	1, 0x90
	.type	_ZN3NetC2Eii,@function
_ZN3NetC2Eii:                           # @_ZN3NetC2Eii
	.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, %rbx
	movl	%esi, (%rdi)
	movl	%edx, 4(%rdi)
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rbx), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movq	%rax, %r14
	movl	$.L.str.1, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	4(%rbx), %esi
	movq	%r14, %rdi
	callq	_ZNSolsEi
	movl	$.L.str.2, %esi
	movl	$47, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movslq	(%rbx), %r12
	leaq	(,%r12,8), %r14
	testq	%r12, %r12
	movq	$-1, %r13
	movq	%r14, %rdi
	cmovsq	%r13, %rdi
	callq	_Znam
	movq	%rax, 8(%rbx)
	testq	%r12, %r12
	jle	.LBB0_12
# %bb.1:                                # %.lr.ph
	movl	%r12d, %ebp
	movslq	4(%rbx), %rax
	leaq	(,%rax,4), %r15
	testq	%rax, %rax
	cmovsq	%r13, %r15
	xorl	%r13d, %r13d
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	_Znam
	movq	8(%rbx), %rcx
	movq	%rax, (%rcx,%r13,8)
	incq	%r13
	cmpq	%r13, %rbp
	jne	.LBB0_2
# %bb.3:                                # %.preheader28
	testl	%r12d, %r12d
	jle	.LBB0_4
# %bb.5:                                # %.preheader27.preheader
	movl	4(%rbx), %eax
	xorl	%r15d, %r15d
	movq	$-1, %r13
.LBB0_6:                                # %.preheader27
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_8 Depth 2
	testl	%eax, %eax
	jle	.LBB0_10
# %bb.7:                                # %.lr.ph31.preheader
                                        #   in Loop: Header=BB0_6 Depth=1
	xorl	%r14d, %r14d
.LBB0_8:                                # %.lr.ph31
                                        #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1808407283, %rax, %rcx         # imm = 0x6BCA1AF3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$35, %rcx
	addl	%edx, %ecx
	leal	(%rcx,%rcx,8), %edx
	leal	(%rcx,%rdx,2), %ecx
	negl	%ecx
	addl	%ecx, %eax
	addl	$-9, %eax
	movq	8(%rbx), %rcx
	movq	(%rcx,%r15,8), %rcx
	movl	%eax, (%rcx,%r14,4)
	incq	%r14
	movslq	4(%rbx), %rax
	cmpq	%rax, %r14
	jl	.LBB0_8
# %bb.9:                                # %._crit_edge.loopexit
                                        #   in Loop: Header=BB0_6 Depth=1
	movl	(%rbx), %r12d
.LBB0_10:                               # %._crit_edge
                                        #   in Loop: Header=BB0_6 Depth=1
	incq	%r15
	movslq	%r12d, %r14
	cmpq	%r14, %r15
	jl	.LBB0_6
# %bb.11:                               # %._crit_edge33.loopexit
	shlq	$3, %r14
	jmp	.LBB0_12
.LBB0_4:
	movq	$-1, %r13
.LBB0_12:                               # %._crit_edge33
	testl	%r12d, %r12d
	cmovsq	%r13, %r14
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, 16(%rbx)
	testl	%r12d, %r12d
	jle	.LBB0_22
# %bb.13:                               # %.lr.ph36
	movslq	4(%rbx), %rax
	leaq	(,%rax,4), %rcx
	testq	%rax, %rax
	movq	$-1, %r14
	cmovnsq	%rcx, %r14
	movl	%r12d, %r15d
	xorl	%r13d, %r13d
.LBB0_14:                               # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	_Znam
	movq	16(%rbx), %rcx
	movq	%rax, (%rcx,%r13,8)
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB0_14
# %bb.15:                               # %.preheader26
	testl	%r12d, %r12d
	jle	.LBB0_22
# %bb.16:                               # %.preheader.lr.ph
	movq	16(%rbx), %rax
	movl	4(%rbx), %edx
	xorl	%ecx, %ecx
.LBB0_17:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_19 Depth 2
	testl	%edx, %edx
	jle	.LBB0_21
# %bb.18:                               # %.lr.ph38
                                        #   in Loop: Header=BB0_17 Depth=1
	movq	(%rax,%rcx,8), %rsi
	xorl	%edi, %edi
.LBB0_19:                               #   Parent Loop BB0_17 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$0, (%rsi,%rdi,4)
	incq	%rdi
	movslq	4(%rbx), %rdx
	cmpq	%rdx, %rdi
	jl	.LBB0_19
# %bb.20:                               # %._crit_edge39.loopexit
                                        #   in Loop: Header=BB0_17 Depth=1
	movl	(%rbx), %r12d
.LBB0_21:                               # %._crit_edge39
                                        #   in Loop: Header=BB0_17 Depth=1
	incq	%rcx
	movslq	%r12d, %rsi
	cmpq	%rsi, %rcx
	jl	.LBB0_17
.LBB0_22:                               # %._crit_edge41
	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_end0:
	.size	_ZN3NetC2Eii, .Lfunc_end0-_ZN3NetC2Eii
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3Net9relulayerEv             # -- Begin function _ZN3Net9relulayerEv
	.p2align	1, 0x90
	.type	_ZN3Net9relulayerEv,@function
_ZN3Net9relulayerEv:                    # @_ZN3Net9relulayerEv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$64, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rbx), %edi
	testl	%edi, %edi
	jle	.LBB1_7
# %bb.1:                                # %.preheader.lr.ph
	movq	8(%rbx), %rax
	movl	4(%rbx), %esi
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	testl	%esi, %esi
	jle	.LBB1_6
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movq	(%rax,%rdx,8), %rdi
	movq	16(%rbx), %rsi
	movq	(%rsi,%rdx,8), %r8
	xorl	%r9d, %r9d
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rdi,%r9,4), %esi
	testl	%esi, %esi
	cmovlel	%ecx, %esi
	movl	%esi, (%r8,%r9,4)
	incq	%r9
	movslq	4(%rbx), %rsi
	cmpq	%rsi, %r9
	jl	.LBB1_4
# %bb.5:                                # %._crit_edge.loopexit
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	(%rbx), %edi
.LBB1_6:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%rdx
	movslq	%edi, %r8
	cmpq	%r8, %rdx
	jl	.LBB1_2
.LBB1_7:                                # %._crit_edge16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_ZN3Net9relulayerEv, .Lfunc_end1-_ZN3Net9relulayerEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3Net10printArrayEv           # -- Begin function _ZN3Net10printArrayEv
	.p2align	1, 0x90
	.type	_ZN3Net10printArrayEv,@function
_ZN3Net10printArrayEv:                  # @_ZN3Net10printArrayEv
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$16, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cmpl	$0, (%rbx)
	jle	.LBB2_6
# %bb.1:                                # %.preheader18.lr.ph
	xorl	%r15d, %r15d
	leaq	6(%rsp), %r14
.LBB2_2:                                # %.preheader18
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	cmpl	$0, 4(%rbx)
	jle	.LBB2_14
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_2 Depth=1
	xorl	%r12d, %r12d
.LBB2_4:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	8(%rbx), %rax
	movq	(%rax,%r15,8), %rax
	movl	(%rax,%r12,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movb	$9, 6(%rsp)
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	cmpq	$0, 16(%rax,%rcx)
	je	.LBB2_12
# %bb.5:                                #   in Loop: Header=BB2_4 Depth=2
	movl	$1, %edx
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB2_13
.LBB2_12:                               #   in Loop: Header=BB2_4 Depth=2
	movq	%rax, %rdi
	movl	$9, %esi
	callq	_ZNSo3putEc
.LBB2_13:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.exit
                                        #   in Loop: Header=BB2_4 Depth=2
	incq	%r12
	movslq	4(%rbx), %rax
	cmpq	%rax, %r12
	jl	.LBB2_4
.LBB2_14:                               # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r15
	movslq	(%rbx), %rax
	cmpq	%rax, %r15
	jl	.LBB2_2
.LBB2_6:                                # %._crit_edge21
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cmpl	$0, (%rbx)
	jle	.LBB2_16
# %bb.7:                                # %.preheader.lr.ph
	xorl	%r15d, %r15d
	leaq	7(%rsp), %r14
.LBB2_8:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_10 Depth 2
	cmpl	$0, 4(%rbx)
	jle	.LBB2_15
# %bb.9:                                # %.lr.ph23.preheader
                                        #   in Loop: Header=BB2_8 Depth=1
	xorl	%r12d, %r12d
.LBB2_10:                               # %.lr.ph23
                                        #   Parent Loop BB2_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	16(%rbx), %rax
	movq	(%rax,%r15,8), %rax
	movl	(%rax,%r12,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movb	$9, 7(%rsp)
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	cmpq	$0, 16(%rax,%rcx)
	je	.LBB2_17
# %bb.11:                               #   in Loop: Header=BB2_10 Depth=2
	movl	$1, %edx
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB2_18
.LBB2_17:                               #   in Loop: Header=BB2_10 Depth=2
	movq	%rax, %rdi
	movl	$9, %esi
	callq	_ZNSo3putEc
.LBB2_18:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c.exit17
                                        #   in Loop: Header=BB2_10 Depth=2
	incq	%r12
	movslq	4(%rbx), %rax
	cmpq	%rax, %r12
	jl	.LBB2_10
.LBB2_15:                               # %._crit_edge24
                                        #   in Loop: Header=BB2_8 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r15
	movslq	(%rbx), %rax
	cmpq	%rax, %r15
	jl	.LBB2_8
.LBB2_16:                               # %._crit_edge26
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_ZN3Net10printArrayEv, .Lfunc_end2-_ZN3Net10printArrayEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3Net15poolingFunctionEiib    # -- Begin function _ZN3Net15poolingFunctionEiib
	.p2align	1, 0x90
	.type	_ZN3Net15poolingFunctionEiib,@function
_ZN3Net15poolingFunctionEiib:           # @_ZN3Net15poolingFunctionEiib
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %ebx
	movl	%edx, %ebp
	movl	%esi, %r15d
	movq	%rdi, %r14
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$50, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$.L.str.8, %eax
	movl	$.L.str.10, %esi
	testl	%ebx, %ebx
	cmovneq	%rax, %rsi
	movl	$_ZSt4cout, %edi
	movl	$37, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r15d, %esi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movl	$.L.str.9, %esi
	movl	$20, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r15, %rdi
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r14, (%rsp)                    # 8-byte Spill
	movl	(%r14), %r15d
	cmpl	$3, %r15d
	jl	.LBB3_11
# %bb.1:                                # %.preheader49.lr.ph
	movl	12(%rsp), %ecx                  # 4-byte Reload
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	movl	%eax, %ecx
	negl	%ecx
	movslq	%ecx, %rdx
	movslq	%eax, %rsi
	cmovnsl	%edx, %eax
	incl	%eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	movl	4(%rcx), %r13d
	leaq	(,%rsi,8), %rcx
	movl	$8, %edi
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	subq	%rcx, %rdi
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	cmpl	%edx, %esi
	movq	%rdx, 40(%rsp)                  # 8-byte Spill
	movl	%edx, %ecx
	cmovgl	%esi, %ecx
	negl	%ecx
	movslq	%ecx, %r8
	decq	%r8
	movl	$999, %r14d                     # imm = 0x3E7
	movl	$-999, %r11d                    # imm = 0xFC19
	movl	$1, %edx
.LBB3_2:                                # %.preheader49
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
                                        #       Child Loop BB3_6 Depth 3
                                        #         Child Loop BB3_7 Depth 4
	cmpl	$3, %r13d
	jl	.LBB3_10
# %bb.3:                                # %.lr.ph67
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%rsp), %rcx                    # 8-byte Reload
	movq	16(%rcx), %rcx
	movq	%rdx, 24(%rsp)                  # 8-byte Spill
	movq	(%rcx,%rdx,8), %rcx
	movq	%rcx, 48(%rsp)                  # 8-byte Spill
	movl	$1, %edi
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_6 Depth 3
                                        #         Child Loop BB3_7 Depth 4
	cmpl	$-1, 12(%rsp)                   # 4-byte Folded Reload
	jl	.LBB3_13
# %bb.5:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB3_4 Depth=2
	movq	(%rsp), %rcx                    # 8-byte Reload
	movq	8(%rcx), %rbp
	movq	16(%rsp), %rcx                  # 8-byte Reload
	addq	%rbp, %rcx
	addq	32(%rsp), %rbp                  # 8-byte Folded Reload
	movq	40(%rsp), %r9                   # 8-byte Reload
.LBB3_6:                                # %.preheader
                                        #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB3_7 Depth 4
	movq	%rdi, %r12
	subq	%r9, %r12
	movq	%rbp, %r13
	movq	%rsi, %rdx
.LBB3_7:                                #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        #       Parent Loop BB3_6 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movq	(%r13), %r10
	movl	4(%r10,%r9,4), %r15d
	movq	(%rcx,%rdx,8), %r10
	movl	(%r10,%r12,4), %r10d
	testb	%bl, %bl
	je	.LBB3_14
# %bb.8:                                #   in Loop: Header=BB3_7 Depth=4
	cmpl	%r10d, %r15d
	cmovll	%r15d, %r10d
	movl	%r10d, %r14d
	jmp	.LBB3_15
.LBB3_14:                               #   in Loop: Header=BB3_7 Depth=4
	cmpl	%r10d, %r15d
	cmovgl	%r15d, %r10d
	movl	%r10d, %r11d
.LBB3_15:                               #   in Loop: Header=BB3_7 Depth=4
	decq	%rdx
	addq	$8, %r13
	cmpl	%edx, %r8d
	jne	.LBB3_7
# %bb.12:                               # %._crit_edge
                                        #   in Loop: Header=BB3_6 Depth=3
	incq	%r9
	cmpl	%r9d, %eax
	jne	.LBB3_6
.LBB3_13:                               # %._crit_edge61
                                        #   in Loop: Header=BB3_4 Depth=2
	testb	%bl, %bl
	movl	%r11d, %ecx
	cmovnel	%r14d, %ecx
	movq	48(%rsp), %rdx                  # 8-byte Reload
	movl	%ecx, (%rdx,%rdi,4)
	incq	%rdi
	movq	(%rsp), %rcx                    # 8-byte Reload
	movslq	4(%rcx), %r13
	leaq	-1(%r13), %rcx
	cmpq	%rcx, %rdi
	jl	.LBB3_4
# %bb.9:                                # %._crit_edge68.loopexit
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%rsp), %rcx                    # 8-byte Reload
	movl	(%rcx), %r15d
	movq	24(%rsp), %rdx                  # 8-byte Reload
.LBB3_10:                               # %._crit_edge68
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%rdx
	leal	-1(%r15), %ecx
	movslq	%ecx, %rcx
	addq	$8, 16(%rsp)                    # 8-byte Folded Spill
	cmpq	%rcx, %rdx
	jl	.LBB3_2
.LBB3_11:                               # %._crit_edge74
	addq	$56, %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	_ZN3Net15poolingFunctionEiib, .Lfunc_end3-_ZN3Net15poolingFunctionEiib
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3Net14filterConvolveEi       # -- Begin function _ZN3Net14filterConvolveEi
	.p2align	1, 0x90
	.type	_ZN3Net14filterConvolveEi,@function
_ZN3Net14filterConvolveEi:              # @_ZN3Net14filterConvolveEi
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, 12(%rsp)                  # 4-byte Spill
	movq	%rdi, %r14
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$25, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%r14), %r9d
	cmpl	$3, %r9d
	jl	.LBB4_12
# %bb.1:                                # %.preheader29.lr.ph
	movl	12(%rsp), %ecx                  # 4-byte Reload
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	movq	16(%r14), %rcx
	movq	%rcx, 24(%rsp)                  # 8-byte Spill
	movl	%eax, %ecx
	negl	%ecx
	movslq	%ecx, %r8
	movslq	%eax, %rsi
	cmovnsl	%r8d, %eax
	incl	%eax
	movl	4(%r14), %r11d
	leaq	8(,%rsi,8), %rcx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	cmpl	%r8d, %esi
	cmovlel	%r8d, %esi
	incl	%esi
	movl	$1, %edx
.LBB4_2:                                # %.preheader29
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
                                        #       Child Loop BB4_6 Depth 3
                                        #         Child Loop BB4_7 Depth 4
	cmpl	$3, %r11d
	jl	.LBB4_11
# %bb.3:                                # %.lr.ph39
                                        #   in Loop: Header=BB4_2 Depth=1
	movq	24(%rsp), %rcx                  # 8-byte Reload
	movq	%rdx, 32(%rsp)                  # 8-byte Spill
	movq	(%rcx,%rdx,8), %r9
	movl	$1, %r10d
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_6 Depth 3
                                        #         Child Loop BB4_7 Depth 4
	xorl	%r11d, %r11d
	cmpl	$-1, 12(%rsp)                   # 4-byte Folded Reload
	jl	.LBB4_9
# %bb.5:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB4_4 Depth=2
	movq	8(%r14), %r15
	movq	16(%rsp), %rcx                  # 8-byte Reload
	addq	%r15, %rcx
	xorl	%r11d, %r11d
	movq	%r8, %r13
.LBB4_6:                                # %.preheader
                                        #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB4_7 Depth 4
	movq	%r10, %rbp
	subq	%r13, %rbp
	movq	%rcx, %r12
	movq	%r8, %rdx
.LBB4_7:                                #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        #       Parent Loop BB4_6 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movq	8(%r15,%rdx,8), %rbx
	movq	(%r12), %rdi
	movl	(%rdi,%rbp,4), %edi
	imull	4(%rbx,%r13,4), %edi
	incq	%rdx
	addl	%edi, %r11d
	addq	$-8, %r12
	cmpq	%rdx, %rsi
	jne	.LBB4_7
# %bb.8:                                # %._crit_edge
                                        #   in Loop: Header=BB4_6 Depth=3
	incq	%r13
	cmpl	%r13d, %eax
	jne	.LBB4_6
.LBB4_9:                                # %._crit_edge36
                                        #   in Loop: Header=BB4_4 Depth=2
	movl	%r11d, (%r9,%r10,4)
	incq	%r10
	movslq	4(%r14), %r11
	leaq	-1(%r11), %rcx
	cmpq	%rcx, %r10
	jl	.LBB4_4
# %bb.10:                               # %._crit_edge40.loopexit
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	(%r14), %r9d
	movq	32(%rsp), %rdx                  # 8-byte Reload
.LBB4_11:                               # %._crit_edge40
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%rdx
	leal	-1(%r9), %ecx
	movslq	%ecx, %rcx
	addq	$8, 16(%rsp)                    # 8-byte Folded Spill
	cmpq	%rcx, %rdx
	jl	.LBB4_2
.LBB4_12:                               # %._crit_edge42
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_ZN3Net14filterConvolveEi, .Lfunc_end4-_ZN3Net14filterConvolveEi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	movl	$3, %esi
	movl	$6, %edx
	callq	_ZN3NetC2Eii
	movq	%rbx, %rdi
	callq	_ZN3Net10printArrayEv
	movq	%rbx, %rdi
	callq	_ZN3Net9relulayerEv
	movq	%rbx, %rdi
	callq	_ZN3Net10printArrayEv
	movq	%rbx, %rdi
	movl	$3, %esi
	movl	$3, %edx
	xorl	%ecx, %ecx
	callq	_ZN3Net15poolingFunctionEiib
	movq	%rbx, %rdi
	callq	_ZN3Net10printArrayEv
	movq	%rbx, %rdi
	movl	$3, %esi
	callq	_ZN3Net14filterConvolveEi
	movq	%rbx, %rdi
	callq	_ZN3Net10printArrayEv
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"\n\nInitialization of "
	.size	.L.str, 21

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	" x "
	.size	.L.str.1, 4

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	" 2D array with random values between -9 and 9\n\n"
	.size	.L.str.2, 48

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\n\nReluLayer Identity Function converts negative inputs to zero\n\n"
	.size	.L.str.3, 65

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n\nINPUT TENSOR\n\n"
	.size	.L.str.4, 17

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\n"
	.size	.L.str.5, 2

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\n\nOUTPUT TENSOR\n\n"
	.size	.L.str.6, 18

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n\nPooling function -- find on min/max operations\n\n"
	.size	.L.str.7, 51

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Pools using min operation, stride is "
	.size	.L.str.8, 38

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	" and window size is "
	.size	.L.str.9, 21

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Pools using max operation, stride is "
	.size	.L.str.10, 38

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"\n\nConvolution function \n\n"
	.size	.L.str.11, 26

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

	.globl	_ZN3NetC1Eii
	.type	_ZN3NetC1Eii,@function
.set _ZN3NetC1Eii, _ZN3NetC2Eii
	.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 _ZSt4cout
	.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
