#include "Output_Layer_GPU_Kernels.cuh"

__constant__ float anchors_416[10] = { 1.08, 1.19,  3.42, 4.41,  6.63, 11.38,  9.42, 5.11,  16.62, 10.52 };

__device__ float Sigmoid(float x) 
{
	float expValue = exp((double)-x);
	float result = 1 / (1 + expValue);

	return result;
}

__global__ void XY_BoundingBox_Coordinates_Transform_Kernel(float* input, int inputHeight, int inputWidth) 
{
	int threadIndex = (blockIdx.x + blockIdx.y * gridDim.x) * blockDim.x + threadIdx.x;
	int tensorXYSize = inputHeight * inputWidth;
	int tensorSize = boundingBoxesPerGridCell * tensorXYSize;
	

	if (threadIndex < tensorSize)
	{
		int threadDepthIndex = threadIndex % boundingBoxesPerGridCell;
		//int threadDepthIndexY = (threadIndex % XYCoordinatesCount) + 1;
		int threadXYIndex = threadIndex % tensorXYSize;
		int cy = threadXYIndex / inputWidth;
		int cx = threadXYIndex % inputWidth;
				
		//tensor[threadDepthIndex * tensorXYSize + threadXYIndex] = threadDepthIndex;
		input[threadDepthIndex * 4 * tensorXYSize + threadXYIndex] = (cx + Sigmoid(input[threadDepthIndex * 4 * tensorXYSize + threadXYIndex])) * downsampleFactor;
		input[(threadDepthIndex * 4 + 1) * tensorXYSize + threadXYIndex] = (cy + Sigmoid(input[(threadDepthIndex * 4 + 1) * tensorXYSize + threadXYIndex])) * downsampleFactor;
		//input[threadDepthIndex * 4 * tensorXYSize + threadXYIndex] = 1;
		//input[(threadDepthIndex * 4 + 1) * tensorXYSize + threadXYIndex] = 1;
	}
}
__global__ void WH_BoundingBox_Transform_Kernel(float* input, int inputHeight, int inputWidth) 
{
	int threadIndex = (blockIdx.x + blockIdx.y * gridDim.x) * blockDim.x + threadIdx.x;
	int tensorXYSize = inputHeight * inputWidth;
	int tensorSize = boundingBoxesPerGridCell * tensorXYSize;

	if (threadIndex < tensorSize)
	{
		int threadDepthIndex = threadIndex % boundingBoxesPerGridCell;
		//int threadDepthIndexY = (threadIndex % XYCoordinatesCount) + 1;
		int threadXYIndex = threadIndex % tensorXYSize;
		
		//tensor[threadDepthIndex * tensorXYSize + threadXYIndex] = threadDepthIndex;
		input[(threadDepthIndex * 4 + 2) * tensorXYSize + threadXYIndex] = exp(input[(threadDepthIndex * 4 + 2) * tensorXYSize + threadXYIndex]) *
			anchors_416[2 * threadDepthIndex] * downsampleFactor;
		input[(threadDepthIndex * 4 + 3) * tensorXYSize + threadXYIndex] = exp(input[(threadDepthIndex * 4 + 3) * tensorXYSize + threadXYIndex]) *
			anchors_416[2 * threadDepthIndex + 1] * downsampleFactor;
		//input[(threadDepthIndex * 4 + 2) * tensorXYSize + threadXYIndex] = anchors_416[2 * threadDepthIndex] = 1;
		//input[(threadDepthIndex * 4 + 3) * tensorXYSize + threadXYIndex] = anchors_416[2 * threadDepthIndex + 1] = 1;

		input[(20 + threadDepthIndex) * tensorXYSize + threadXYIndex] = Sigmoid(input[(20 + threadDepthIndex) * tensorXYSize + threadXYIndex]);
		//input[(20 + threadDepthIndex) * tensorXYSize + threadXYIndex] = 2;
	}
}

__global__ void Softmax_Kernel(float* input, int classesCount, int inputHeight, int inputWidth)
{
	int threadIndex = (blockIdx.x + blockIdx.y * gridDim.x) * blockDim.x + threadIdx.x;
	int tensorXYSize = inputHeight * inputWidth;
	int tensorSize = boundingBoxesPerGridCell * tensorXYSize;

	if (threadIndex < tensorSize)
	{
		int threadDepthIndex = threadIndex % boundingBoxesPerGridCell;
		int threadXYIndex = threadIndex % tensorXYSize;
		float maxClassProbability = FLOAT_MIN;

		for (size_t i = 0; i < classesCount; i++)
		{
			float classProbability = input[(25 + threadDepthIndex * classesCount + i) * tensorXYSize + threadXYIndex];

			if (classProbability > maxClassProbability)
			{
				maxClassProbability = classProbability;
			}
		}

		float classProbabilitiesSum = 0;
		for (size_t i = 0; i < classesCount; i++)
		{
			float exponent = exp(input[(25 + threadDepthIndex * classesCount + i) * tensorXYSize + threadXYIndex] - maxClassProbability);
			classProbabilitiesSum += exponent;
			input[(25 + threadDepthIndex * classesCount + i) * tensorXYSize + threadXYIndex] = exponent;
		}

		for (size_t i = 0; i < classesCount; i++)
		{
			input[(25 + threadDepthIndex * classesCount + i) * tensorXYSize + threadXYIndex] /= classProbabilitiesSum;
			//input[(25 + threadDepthIndex * classesCount + i) * tensorXYSize + threadXYIndex] = i;
			//input[(25 + threadDepthIndex * classesCount + i) * tensorXYSize + threadXYIndex] = 3;
		}
	}
}


void WH_BoundingBox_Transform(float* input, int inputHeight, int inputWidth) 
{
	int tensorSize = boundingBoxesPerGridCell * inputHeight * inputWidth;
	int gridXDim = ceil(tensorSize / 512.0);
	WH_BoundingBox_Transform_Kernel << <gridXDim, 512 >> > (input, inputHeight, inputWidth);
}

void XY_BoundingBox_Coordinates_Transform(float* input, int inputHeight, int inputWidth)
{
	int tensorSize = boundingBoxesPerGridCell * inputHeight * inputWidth;
	int gridXDim = ceil(tensorSize / 512.0);
	XY_BoundingBox_Coordinates_Transform_Kernel << <gridXDim, 512 >> > (input, inputHeight, inputWidth);
}

void Softmax_GPU(float* input, int classesCount, int inputHeight, int inputWidth)
{
	int tensorSize = boundingBoxesPerGridCell * inputHeight * inputWidth;
	int gridXDim = ceil(tensorSize / 512.0);
	Softmax_Kernel << <gridXDim, 512 >> > (input, classesCount, inputHeight, inputWidth);
}
	.file	"tmpxft_0021bb74_00000000-6_Output_Layer_GPU_Kernels.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2014:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2014:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7Sigmoidf
	.type	_Z7Sigmoidf, @function
_Z7Sigmoidf:
.LFB2008:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2008:
	.size	_Z7Sigmoidf, .-_Z7Sigmoidf
	.globl	_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii
	.type	_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii, @function
_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii:
.LFB2036:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L4:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii, .-_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii
	.globl	_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii
	.type	_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii, @function
_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii:
.LFB2037:
	.cfi_startproc
	endbr64
	jmp	_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii
	.cfi_endproc
.LFE2037:
	.size	_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii, .-_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii
	.globl	_Z36XY_BoundingBox_Coordinates_TransformPfii
	.type	_Z36XY_BoundingBox_Coordinates_TransformPfii, @function
_Z36XY_BoundingBox_Coordinates_TransformPfii:
.LFB2010:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	imull	%edx, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%esi, %ebx
	leal	(%rax,%rax,4), %eax
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC0(%rip), %xmm0
	call	ceil@PLT
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttsd2sil	%xmm0, %eax
	salq	$9, %rdx
	movl	$1, %ecx
	movl	%eax, 8(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movl	%ebp, %edx
	movl	%ebx, %esi
	movq	%r12, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_Z65__device_stub__Z43XY_BoundingBox_Coordinates_Transform_KernelPfiiPfii
.L10:
	.cfi_restore_state
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2010:
	.size	_Z36XY_BoundingBox_Coordinates_TransformPfii, .-_Z36XY_BoundingBox_Coordinates_TransformPfii
	.globl	_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii
	.type	_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii, @function
_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii:
.LFB2038:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z31WH_BoundingBox_Transform_KernelPfii(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L13:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii, .-_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii
	.globl	_Z31WH_BoundingBox_Transform_KernelPfii
	.type	_Z31WH_BoundingBox_Transform_KernelPfii, @function
_Z31WH_BoundingBox_Transform_KernelPfii:
.LFB2039:
	.cfi_startproc
	endbr64
	jmp	_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii
	.cfi_endproc
.LFE2039:
	.size	_Z31WH_BoundingBox_Transform_KernelPfii, .-_Z31WH_BoundingBox_Transform_KernelPfii
	.globl	_Z24WH_BoundingBox_TransformPfii
	.type	_Z24WH_BoundingBox_TransformPfii, @function
_Z24WH_BoundingBox_TransformPfii:
.LFB2009:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	imull	%edx, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%esi, %ebx
	leal	(%rax,%rax,4), %eax
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC0(%rip), %xmm0
	call	ceil@PLT
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttsd2sil	%xmm0, %eax
	salq	$9, %rdx
	movl	$1, %ecx
	movl	%eax, 8(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movl	%ebp, %edx
	movl	%ebx, %esi
	movq	%r12, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_Z53__device_stub__Z31WH_BoundingBox_Transform_KernelPfiiPfii
.L18:
	.cfi_restore_state
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2009:
	.size	_Z24WH_BoundingBox_TransformPfii, .-_Z24WH_BoundingBox_TransformPfii
	.globl	_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii
	.type	_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii, @function
_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii:
.LFB2040:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 16(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 12(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14Softmax_KernelPfiii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L21:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii, .-_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii
	.globl	_Z14Softmax_KernelPfiii
	.type	_Z14Softmax_KernelPfiii, @function
_Z14Softmax_KernelPfiii:
.LFB2041:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii
	.cfi_endproc
.LFE2041:
	.size	_Z14Softmax_KernelPfiii, .-_Z14Softmax_KernelPfiii
	.globl	_Z11Softmax_GPUPfiii
	.type	_Z11Softmax_GPUPfiii, @function
_Z11Softmax_GPUPfiii:
.LFB2011:
	.cfi_startproc
	endbr64
	movl	%edx, %eax
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%esi, %r13d
	imull	%ecx, %eax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%edx, %ebx
	leal	(%rax,%rax,4), %eax
	cvtsi2sdl	%eax, %xmm0
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	mulsd	.LC0(%rip), %xmm0
	call	ceil@PLT
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttsd2sil	%xmm0, %eax
	salq	$9, %rdx
	movl	$1, %ecx
	movl	%eax, 8(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%ebp, %ecx
	movl	%ebx, %edx
	movl	%r13d, %esi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%r12, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_Z37__device_stub__Z14Softmax_KernelPfiiiPfiii
.L26:
	.cfi_restore_state
	addq	$40, %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
.LFE2011:
	.size	_Z11Softmax_GPUPfiii, .-_Z11Softmax_GPUPfiii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"_Z14Softmax_KernelPfiii"
.LC2:
	.string	"_Z31WH_BoundingBox_Transform_KernelPfii"
.LC3:
	.string	"_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii"
.LC4:
	.string	"downsampleFactor"
.LC5:
	.string	"boundingBoxesPerGridCell"
.LC6:
	.string	"FLOAT_MIN"
.LC7:
	.string	"anchors_416"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z14Softmax_KernelPfiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC2(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z31WH_BoundingBox_Transform_KernelPfii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z43XY_BoundingBox_Coordinates_Transform_KernelPfii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC4(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL16downsampleFactor(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC5(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL24boundingBoxesPerGridCell(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC6(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL9FLOAT_MIN(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC7(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$40, %r9d
	movq	%rdx, %rcx
	leaq	_ZL11anchors_416(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2043:
	.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
	.local	_ZL11anchors_416
	.comm	_ZL11anchors_416,40,32
	.section	.rodata
	.align 4
	.type	_ZL9FLOAT_MIN, @object
	.size	_ZL9FLOAT_MIN, 4
_ZL9FLOAT_MIN:
	.long	8388608
	.align 4
	.type	_ZL24boundingBoxesPerGridCell, @object
	.size	_ZL24boundingBoxesPerGridCell, 4
_ZL24boundingBoxesPerGridCell:
	.long	5
	.align 4
	.type	_ZL16downsampleFactor, @object
	.size	_ZL16downsampleFactor, 4
_ZL16downsampleFactor:
	.long	32
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1063256064
	.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:

#pragma once
#include<hip/hip_runtime.h>

#include <math.h>

__device__ const int downsampleFactor = 32;
__device__ const int boundingBoxesPerGridCell = 5;
__device__ const float FLOAT_MIN = 1.17549435e-38;

//__global__ void BoundingBox_ConfidenceScores_Transform_Kernel(float* input, int inputHeight, int inputWidth);
__global__ void XY_BoundingBox_Coordinates_Transform_Kernel(float* input, int inputHeight, int inputWidth);
__global__ void WH_BoundingBox_Transform_Kernel(float* input, int inputHeight, int inputWidth);
__global__ void Softmax_Kernel(float* input, int classesCount, int inputHeight, int inputWidth);

void XY_BoundingBox_Coordinates_Transform(float* input, int inputHeight, int inputWidth);
void WH_BoundingBox_Transform(float* input, int inputHeight, int inputWidth);
void Softmax_GPU(float* input, int classesCount, int inputHeight, int inputWidth);
//void BoundingBox_ConfidenceScores_Transform(float* input, int inputHeight, int inputWidth);
	.text
	.file	"Output_Layer_GPU_Kernels.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
