#include <stdio.h>

const int max_threads_per_block = 512;

#define HANDLE_CUDA_ERROR(err)	if (err) { printf("%s", cudaGetErrorString(err)); return; }



__device__ int cyclic_reduction_forward_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim, int step, const int to)
{
	/* Forward reduction */
	for (; (step * to * 3) <= dim; step <<= 1)
	{
		const int addr = (threadIdx.x * (step << 1)) + (step << 1) - 1;
		if (addr < dim)
		{
			if (addr - step >= 0)
			{
				const float alpha = -lower[addr] / diagonal[addr - step];
				equal[addr]    += (alpha * equal[addr - step]);
				diagonal[addr] += (alpha * upper[addr - step]);
				lower[addr]		= alpha * lower[addr - step];
			}

			if (addr + step < dim)
			{
				const float gamma = -upper[addr] / diagonal[addr + step];
				equal[addr]	   += (gamma * equal[addr + step]);
				diagonal[addr] += (gamma * lower[addr + step]);
				upper[addr]		= gamma * upper[addr + step];
			}
		}
		__syncthreads();
	}

	return step;
}


__device__ void cyclic_reduction_back_substitution(float *lower, float *diagonal, float *upper, float *equal, const int dim, int step, const int to)
{
	/* Backward substitution */
	for (; step > to; step >>= 1)
	{
		const int addr = (threadIdx.x * (step << 1)) + step - 1;
		if (addr < dim)
		{
			if (addr - step >= 0)
			{
				equal[addr] -= (lower[addr] * equal[addr - step]);
			}

			if (addr + step < dim)
			{
				equal[addr] -= (upper[addr] * equal[addr + step]);
			}

			equal[addr] = equal[addr] / diagonal[addr];
		}
		__syncthreads();
	}
}


__global__ void cyclic_reduction_device(float *lower_glb, float *diagonal_glb, float *upper_glb, float *equal_glb, const int dim)
{
	__shared__ float lower[512];
	__shared__ float diagonal[512];
	__shared__ float upper[512];
	__shared__ float equal[512];

	lower[threadIdx.x] = lower_glb[threadIdx.x];
	diagonal[threadIdx.x] = diagonal_glb[threadIdx.x];
	upper[threadIdx.x] = upper_glb[threadIdx.x];
	equal[threadIdx.x] = equal_glb[threadIdx.x];
	__syncthreads();

	/* Forward reduction */
	int step = cyclic_reduction_forward_reduction(lower, diagonal, upper, equal, dim, 1, 1);

	/* Solve base system */
	if (threadIdx.x == 0)
	{
		if ((dim / step) == 2) /* Solve simultaneous equations */
		{
			const int equal_addr = (step << 1) - 1;
			const float a0 = diagonal[equal_addr - step];
			const float a1 = lower[equal_addr];
			const float b0 = upper[equal_addr - step];
			const float b1 = diagonal[equal_addr];
			const float c0 = equal[equal_addr - step];
			const float c1 = equal[equal_addr];

			equal[equal_addr] = (c0 * a1 - a0 * c1) / (a1 * b0 - a0 * b1);
			equal[equal_addr - step] = (c0 - b0 * equal[equal_addr]) / a0;
		}
		else /* blk_size == 1, equations are already solved */
		{
			const int equal_addr = step - 1;
			equal[equal_addr] = equal[equal_addr] / diagonal[equal_addr];
		}
	}

	__syncthreads();
	step >>= 1;

	/* Backward substitution */
	cyclic_reduction_back_substitution(lower, diagonal, upper, equal, dim, step, 0);
	equal_glb[threadIdx.x] = equal[threadIdx.x];
}


void cyclic_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim)
{
	const int log_dim = static_cast<int>(ceil(log(static_cast<float>(dim)) / log(2.0f)));

	/* Get device */
	HANDLE_CUDA_ERROR(cudaSetDevice(0));

	/* Allocate and copy memory */
	float *dev_equal;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_equal, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_equal, equal, dim * sizeof(float), cudaMemcpyHostToDevice));

	float *dev_lower;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_lower, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_lower, lower, dim * sizeof(float), cudaMemcpyHostToDevice));

	float *dev_diagonal;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_diagonal, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_diagonal, diagonal, dim * sizeof(float), cudaMemcpyHostToDevice));
	
	float *dev_upper;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_upper, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_upper, upper, dim * sizeof(float), cudaMemcpyHostToDevice));

	/* Run kernel */
	if (dim > max_threads_per_block)
	{
		printf("Thead count (%i) exceeds maximum", dim);
		return;
	}
	cyclic_reduction_device<<<1, dim>>>(dev_lower, dev_diagonal, dev_upper, dev_equal, dim);

	/* Copy data back */
	HANDLE_CUDA_ERROR(cudaDeviceSynchronize());
	HANDLE_CUDA_ERROR(cudaMemcpy(equal, dev_equal, dim * sizeof(float), cudaMemcpyDeviceToHost));

	/* Clean up */
	HANDLE_CUDA_ERROR(cudaFree(dev_equal));
	HANDLE_CUDA_ERROR(cudaFree(dev_lower));
	HANDLE_CUDA_ERROR(cudaFree(dev_diagonal));
	HANDLE_CUDA_ERROR(cudaFree(dev_upper));

	/* Flush profiling info */
	HANDLE_CUDA_ERROR(cudaDeviceReset());
}


__global__ void parallel_cyclic_reduction_device(float *lower_glb, float *diagonal_glb, float *upper_glb, float *equal_glb, const int dim)
{
	const int rank = threadIdx.x;
	__shared__ float lower[512];
	__shared__ float diagonal[512];
	__shared__ float upper[512];
	__shared__ float equal[512];

	lower[rank] = lower_glb[rank];
	diagonal[rank] = diagonal_glb[rank];
	upper[rank] = upper_glb[rank];
	equal[rank] = equal_glb[rank];
	__syncthreads();

	float lower_tmp;
	float upper_tmp;
	float result_tmp;
	float diag_tmp;
	for (int span = 1 ; span < dim; span <<= 1)
	{
		if (rank < dim)
		{
			result_tmp = equal[rank];
			diag_tmp = diagonal[rank];

			if (rank - span >= 0)
			{
				lower_tmp = -lower[rank] / diagonal[rank - span];
				diag_tmp += lower_tmp * upper[rank - span];
				result_tmp += lower_tmp * equal[rank - span];
				lower_tmp *= lower[rank - span];
			}

			if (rank + span < dim)
			{
				upper_tmp = -upper[rank] / diagonal[rank + span];
				diag_tmp += upper_tmp * lower[rank + span];
				result_tmp += upper_tmp * equal[rank + span];
				upper_tmp *= upper[rank + span];
			}
		}
		__syncthreads();

		if (rank < dim)
		{
			lower[rank] = lower_tmp;
			upper[rank] = upper_tmp;
			equal[rank] = result_tmp;
			diagonal[rank] = diag_tmp;
		}
		__syncthreads();
	}

	if (rank < dim)
	{
		equal_glb[rank] = equal[rank] / diagonal[rank];
	}
}


void parallel_cyclic_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim)
{
	/* Get device */
	HANDLE_CUDA_ERROR(cudaSetDevice(0));

	/* Allocate and copy memory */
	float *dev_equal;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_equal, dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_equal, equal, dim * sizeof(float), cudaMemcpyHostToDevice));

	float *dev_lower;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_lower, dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_lower, lower, dim * sizeof(float), cudaMemcpyHostToDevice));

	float *dev_diagonal;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_diagonal, dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_diagonal, diagonal, dim * sizeof(float), cudaMemcpyHostToDevice));
	
	float *dev_upper;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_upper, dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_upper, upper, dim * sizeof(float), cudaMemcpyHostToDevice));

	/* Run kernel */
	if (dim > max_threads_per_block)
	{
		printf("Thead count (%i) exceeds maximum", dim);
		return;
	}
	parallel_cyclic_reduction_device<<<1, dim>>>(dev_lower, dev_diagonal, dev_upper, dev_equal, dim);

	/* Copy data back */
	HANDLE_CUDA_ERROR(cudaDeviceSynchronize());
	HANDLE_CUDA_ERROR(cudaMemcpy(equal, dev_equal, dim * sizeof(float), cudaMemcpyDeviceToHost));

	/* Clean up */
	HANDLE_CUDA_ERROR(cudaFree(dev_equal));
	HANDLE_CUDA_ERROR(cudaFree(dev_lower));
	HANDLE_CUDA_ERROR(cudaFree(dev_diagonal));
	HANDLE_CUDA_ERROR(cudaFree(dev_upper));

	/* Flush profiling info */
	HANDLE_CUDA_ERROR(cudaDeviceReset());
}


__global__ void hybrid_cyclic_reduction_device(float *lower_glb, float *diagonal_glb, float *upper_glb, float *equal_glb, const int dim)
{
	__shared__ float lower[512];
	__shared__ float diagonal[512];
	__shared__ float upper[512];
	__shared__ float equal[512];

	lower[threadIdx.x] = lower_glb[threadIdx.x];
	diagonal[threadIdx.x] = diagonal_glb[threadIdx.x];
	upper[threadIdx.x] = upper_glb[threadIdx.x];
	equal[threadIdx.x] = equal_glb[threadIdx.x];
	__syncthreads();


	/* Cyclic forward reduction */
	int step = cyclic_reduction_forward_reduction(lower, diagonal, upper, equal, dim, 1, 128);

	/* Parallel cyclic reduction to solve system */
	float lower_tmp;
	float upper_tmp;
	float result_tmp;
	float diag_tmp;
	const int rank = (threadIdx.x * step) + step - 1;
	for (int span = step; span < dim; span <<= 1)
	{
		if (rank < dim)
		{
			result_tmp = equal[rank];
			diag_tmp = diagonal[rank];

			if (rank - span >= 0)
			{
				lower_tmp = -lower[rank] / diagonal[rank - span];
				diag_tmp += lower_tmp * upper[rank - span];
				result_tmp += lower_tmp * equal[rank - span];
				lower_tmp *= lower[rank - span];
			}

			if (rank + span < dim)
			{
				upper_tmp = -upper[rank] / diagonal[rank + span];
				diag_tmp += upper_tmp * lower[rank + span];
				result_tmp += upper_tmp * equal[rank + span];
				upper_tmp *= upper[rank + span];
			}
		}
		__syncthreads();

		if (rank < dim)
		{
			lower[rank] = lower_tmp;
			upper[rank] = upper_tmp;
			equal[rank] = result_tmp;
			diagonal[rank] = diag_tmp;
		}
		__syncthreads();
	}

	if (rank < dim)
	{
		equal[rank] /= diagonal[rank];
	}
	__syncthreads();


	/* Cyclic backward substitution */
	cyclic_reduction_back_substitution(lower, diagonal, upper, equal, dim, step >> 1, 0);
	equal_glb[threadIdx.x] = equal[threadIdx.x];
}


void hybrid_cyclic_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim)
{
	const int log_dim = static_cast<int>(ceil(log(static_cast<float>(dim)) / log(2.0f)));

	/* Get device */
	HANDLE_CUDA_ERROR(cudaSetDevice(0));

	/* Allocate and copy memory */
	float *dev_equal;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_equal, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_equal, equal, dim * sizeof(float), cudaMemcpyHostToDevice));

	float *dev_lower;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_lower, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_lower, lower, dim * sizeof(float), cudaMemcpyHostToDevice));

	float *dev_diagonal;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_diagonal, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_diagonal, diagonal, dim * sizeof(float), cudaMemcpyHostToDevice));
	
	float *dev_upper;
	HANDLE_CUDA_ERROR(cudaMalloc((void **)&dev_upper, dim * log_dim * sizeof(float)));
	HANDLE_CUDA_ERROR(cudaMemcpy(dev_upper, upper, dim * sizeof(float), cudaMemcpyHostToDevice));

	/* Run kernel */
	if (dim > max_threads_per_block)
	{
		printf("Thead count (%i) exceeds maximum", dim);
		return;
	}
	hybrid_cyclic_reduction_device<<<1, dim>>>(dev_lower, dev_diagonal, dev_upper, dev_equal, dim);

	/* Copy data back */
	HANDLE_CUDA_ERROR(cudaDeviceSynchronize());
	HANDLE_CUDA_ERROR(cudaMemcpy(equal, dev_equal, dim * sizeof(float), cudaMemcpyDeviceToHost));

	/* Clean up */
	HANDLE_CUDA_ERROR(cudaFree(dev_equal));
	HANDLE_CUDA_ERROR(cudaFree(dev_lower));
	HANDLE_CUDA_ERROR(cudaFree(dev_diagonal));
	HANDLE_CUDA_ERROR(cudaFree(dev_upper));

	/* Flush profiling info */
	HANDLE_CUDA_ERROR(cudaDeviceReset());
}

	.file	"tmpxft_002caa59_00000000-6_cyclic_reduction.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z34cyclic_reduction_forward_reductionPfS_S_S_iii
	.type	_Z34cyclic_reduction_forward_reductionPfS_S_S_iii, @function
_Z34cyclic_reduction_forward_reductionPfS_S_S_iii:
.LFB2027:
	.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
.LFE2027:
	.size	_Z34cyclic_reduction_forward_reductionPfS_S_S_iii, .-_Z34cyclic_reduction_forward_reductionPfS_S_S_iii
	.globl	_Z34cyclic_reduction_back_substitutionPfS_S_S_iii
	.type	_Z34cyclic_reduction_back_substitutionPfS_S_S_iii, @function
_Z34cyclic_reduction_back_substitutionPfS_S_S_iii:
.LFB2028:
	.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
.LFE2028:
	.size	_Z34cyclic_reduction_back_substitutionPfS_S_S_iii, .-_Z34cyclic_reduction_back_substitutionPfS_S_S_iii
	.globl	_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.type	_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i, @function
_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L6
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z23cyclic_reduction_devicePfS_S_S_i(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L6:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i, .-_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.globl	_Z23cyclic_reduction_devicePfS_S_S_i
	.type	_Z23cyclic_reduction_devicePfS_S_S_i, @function
_Z23cyclic_reduction_devicePfS_S_S_i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.cfi_endproc
.LFE2057:
	.size	_Z23cyclic_reduction_devicePfS_S_S_i, .-_Z23cyclic_reduction_devicePfS_S_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s"
.LC2:
	.string	"Thead count (%i) exceeds maximum"
	.text
	.globl	_Z16cyclic_reductionPfS_S_S_i
	.type	_Z16cyclic_reductionPfS_S_S_i, @function
_Z16cyclic_reductionPfS_S_S_i:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	cvtsi2ssl	%r8d, %xmm0
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	logf@PLT
	xorl	%edi, %edi
	movss	%xmm0, (%rsp)
	call	cudaSetDevice@PLT
	movss	(%rsp), %xmm0
	testl	%eax, %eax
	je	.L13
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rdx
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L38
	addq	$88, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
.L13:
	.cfi_restore_state
	divss	.LC1(%rip), %xmm0
	call	ceilf@PLT
	leaq	16(%rsp), %rdi
	cvttss2sil	%xmm0, %ebx
	movq	%rdi, (%rsp)
	imull	%ebp, %ebx
	movslq	%ebx, %rbx
	salq	$2, %rbx
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	testl	%eax, %eax
	jne	.L42
	movslq	%ebp, %rax
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	salq	$2, %rax
	movq	%rax, %rdx
	movq	%rax, (%rsp)
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L17
	movq	(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	jmp	.L40
.L17:
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rdi, 8(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	testl	%eax, %eax
	je	.L18
.L42:
	movq	%rbx, %rsi
	jmp	.L39
.L18:
	movq	(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L19
	movq	(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rsi
	jmp	.L40
.L19:
	leaq	32(%rsp), %r15
	movq	%rbx, %rsi
	movq	%r15, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L20
	movq	%rbx, %rsi
	movq	%r15, %rdi
	jmp	.L39
.L20:
	movq	(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L21
	movq	(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	jmp	.L40
.L21:
	leaq	40(%rsp), %r14
	movq	%rbx, %rsi
	movq	%r14, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L22
	movq	%rbx, %rsi
	movq	%r14, %rdi
.L39:
	call	cudaMalloc@PLT
	jmp	.L37
.L22:
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L23
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	jmp	.L40
.L23:
	cmpl	$512, %ebp
	jle	.L24
	movl	%ebp, %edx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L12
.L24:
	movl	%ebp, 60(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movq	%rdi, 64(%rsp)
	movl	68(%rsp), %ecx
	movq	60(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	16(%rsp), %rcx
	movq	40(%rsp), %rdx
	movl	%ebp, %r8d
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z50__device_stub__Z23cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
.L25:
	call	cudaDeviceSynchronize@PLT
	testl	%eax, %eax
	je	.L26
	call	cudaDeviceSynchronize@PLT
	jmp	.L37
.L26:
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	$2, %ecx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	testl	%eax, %eax
	je	.L27
	movq	(%rsp), %rdx
	movl	$2, %ecx
	movq	%r12, %rdi
.L40:
	call	cudaMemcpy@PLT
	jmp	.L37
.L27:
	movq	%rsi, %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L28
	movq	16(%rsp), %rdi
	jmp	.L41
.L28:
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L29
	movq	24(%rsp), %rdi
	jmp	.L41
.L29:
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L30
	movq	32(%rsp), %rdi
	jmp	.L41
.L30:
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L31
	movq	40(%rsp), %rdi
.L41:
	call	cudaFree@PLT
	jmp	.L37
.L31:
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L12
	call	cudaDeviceReset@PLT
.L37:
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
.L38:
	call	__stack_chk_fail@PLT
.L32:
	addq	$88, %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
.LFE2029:
	.size	_Z16cyclic_reductionPfS_S_S_i, .-_Z16cyclic_reductionPfS_S_S_i
	.globl	_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.type	_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i, @function
_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L43
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z32parallel_cyclic_reduction_devicePfS_S_S_i(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L43:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
	call	__stack_chk_fail@PLT
.L45:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i, .-_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.globl	_Z32parallel_cyclic_reduction_devicePfS_S_S_i
	.type	_Z32parallel_cyclic_reduction_devicePfS_S_S_i, @function
_Z32parallel_cyclic_reduction_devicePfS_S_S_i:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.cfi_endproc
.LFE2059:
	.size	_Z32parallel_cyclic_reduction_devicePfS_S_S_i, .-_Z32parallel_cyclic_reduction_devicePfS_S_S_i
	.globl	_Z25parallel_cyclic_reductionPfS_S_S_i
	.type	_Z25parallel_cyclic_reductionPfS_S_S_i, @function
_Z25parallel_cyclic_reductionPfS_S_S_i:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	xorl	%edi, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L49
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rdx
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L74
	addq	$88, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
.L49:
	.cfi_restore_state
	movslq	%ebp, %rbx
	leaq	16(%rsp), %rdi
	salq	$2, %rbx
	movq	%rdi, 8(%rsp)
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	testl	%eax, %eax
	jne	.L78
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L53
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rsi
	jmp	.L76
.L53:
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rdi, 8(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	testl	%eax, %eax
	je	.L54
.L78:
	movq	%rbx, %rsi
	jmp	.L75
.L54:
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L55
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r15, %rsi
	jmp	.L76
.L55:
	leaq	32(%rsp), %r15
	movq	%rbx, %rsi
	movq	%r15, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L56
	movq	%rbx, %rsi
	movq	%r15, %rdi
	jmp	.L75
.L56:
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L57
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r14, %rsi
	jmp	.L76
.L57:
	leaq	40(%rsp), %r14
	movq	%rbx, %rsi
	movq	%r14, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L58
	movq	%rbx, %rsi
	movq	%r14, %rdi
.L75:
	call	cudaMalloc@PLT
	jmp	.L73
.L58:
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L59
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r13, %rsi
	jmp	.L76
.L59:
	cmpl	$512, %ebp
	jle	.L60
	movl	%ebp, %edx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L48
.L60:
	movl	%ebp, 60(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movq	%rdi, 64(%rsp)
	movl	68(%rsp), %ecx
	movq	60(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L61
	movq	16(%rsp), %rcx
	movq	40(%rsp), %rdx
	movl	%ebp, %r8d
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z59__device_stub__Z32parallel_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
.L61:
	call	cudaDeviceSynchronize@PLT
	testl	%eax, %eax
	je	.L62
	call	cudaDeviceSynchronize@PLT
	jmp	.L73
.L62:
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	testl	%eax, %eax
	je	.L63
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rdi
.L76:
	call	cudaMemcpy@PLT
	jmp	.L73
.L63:
	movq	%rsi, %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L64
	movq	16(%rsp), %rdi
	jmp	.L77
.L64:
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L65
	movq	24(%rsp), %rdi
	jmp	.L77
.L65:
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L66
	movq	32(%rsp), %rdi
	jmp	.L77
.L66:
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L67
	movq	40(%rsp), %rdi
.L77:
	call	cudaFree@PLT
	jmp	.L73
.L67:
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L48
	call	cudaDeviceReset@PLT
.L73:
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L48:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L68
.L74:
	call	__stack_chk_fail@PLT
.L68:
	addq	$88, %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
.LFE2030:
	.size	_Z25parallel_cyclic_reductionPfS_S_S_i, .-_Z25parallel_cyclic_reductionPfS_S_S_i
	.globl	_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.type	_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i, @function
_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i:
.LFB2060:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L79
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z30hybrid_cyclic_reduction_devicePfS_S_S_i(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L79:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L81
	call	__stack_chk_fail@PLT
.L81:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i, .-_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.globl	_Z30hybrid_cyclic_reduction_devicePfS_S_S_i
	.type	_Z30hybrid_cyclic_reduction_devicePfS_S_S_i, @function
_Z30hybrid_cyclic_reduction_devicePfS_S_S_i:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
	.cfi_endproc
.LFE2061:
	.size	_Z30hybrid_cyclic_reduction_devicePfS_S_S_i, .-_Z30hybrid_cyclic_reduction_devicePfS_S_S_i
	.globl	_Z23hybrid_cyclic_reductionPfS_S_S_i
	.type	_Z23hybrid_cyclic_reductionPfS_S_S_i, @function
_Z23hybrid_cyclic_reductionPfS_S_S_i:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	cvtsi2ssl	%r8d, %xmm0
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	logf@PLT
	xorl	%edi, %edi
	movss	%xmm0, (%rsp)
	call	cudaSetDevice@PLT
	movss	(%rsp), %xmm0
	testl	%eax, %eax
	je	.L85
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rdx
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L110
	addq	$88, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
.L85:
	.cfi_restore_state
	divss	.LC1(%rip), %xmm0
	call	ceilf@PLT
	leaq	16(%rsp), %rdi
	cvttss2sil	%xmm0, %ebx
	movq	%rdi, (%rsp)
	imull	%ebp, %ebx
	movslq	%ebx, %rbx
	salq	$2, %rbx
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	testl	%eax, %eax
	jne	.L114
	movslq	%ebp, %rax
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	salq	$2, %rax
	movq	%rax, %rdx
	movq	%rax, (%rsp)
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L89
	movq	(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	jmp	.L112
.L89:
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rdi, 8(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	testl	%eax, %eax
	je	.L90
.L114:
	movq	%rbx, %rsi
	jmp	.L111
.L90:
	movq	(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L91
	movq	(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rsi
	jmp	.L112
.L91:
	leaq	32(%rsp), %r15
	movq	%rbx, %rsi
	movq	%r15, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L92
	movq	%rbx, %rsi
	movq	%r15, %rdi
	jmp	.L111
.L92:
	movq	(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L93
	movq	(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	jmp	.L112
.L93:
	leaq	40(%rsp), %r14
	movq	%rbx, %rsi
	movq	%r14, %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L94
	movq	%rbx, %rsi
	movq	%r14, %rdi
.L111:
	call	cudaMalloc@PLT
	jmp	.L109
.L94:
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L95
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	jmp	.L112
.L95:
	cmpl	$512, %ebp
	jle	.L96
	movl	%ebp, %edx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L84
.L96:
	movl	%ebp, 60(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movq	%rdi, 64(%rsp)
	movl	68(%rsp), %ecx
	movq	60(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L97
	movq	16(%rsp), %rcx
	movq	40(%rsp), %rdx
	movl	%ebp, %r8d
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z57__device_stub__Z30hybrid_cyclic_reduction_devicePfS_S_S_iPfS_S_S_i
.L97:
	call	cudaDeviceSynchronize@PLT
	testl	%eax, %eax
	je	.L98
	call	cudaDeviceSynchronize@PLT
	jmp	.L109
.L98:
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	$2, %ecx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	testl	%eax, %eax
	je	.L99
	movq	(%rsp), %rdx
	movl	$2, %ecx
	movq	%r12, %rdi
.L112:
	call	cudaMemcpy@PLT
	jmp	.L109
.L99:
	movq	%rsi, %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L100
	movq	16(%rsp), %rdi
	jmp	.L113
.L100:
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L101
	movq	24(%rsp), %rdi
	jmp	.L113
.L101:
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L102
	movq	32(%rsp), %rdi
	jmp	.L113
.L102:
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L103
	movq	40(%rsp), %rdi
.L113:
	call	cudaFree@PLT
	jmp	.L109
.L103:
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L84
	call	cudaDeviceReset@PLT
.L109:
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L84:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L104
.L110:
	call	__stack_chk_fail@PLT
.L104:
	addq	$88, %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
.LFE2031:
	.size	_Z23hybrid_cyclic_reductionPfS_S_S_i, .-_Z23hybrid_cyclic_reductionPfS_S_S_i
	.section	.rodata.str1.1
.LC3:
	.string	"_Z30hybrid_cyclic_reduction_devicePfS_S_S_i"
.LC4:
	.string	"_Z32parallel_cyclic_reduction_devicePfS_S_S_i"
.LC5:
	.string	"_Z23cyclic_reduction_devicePfS_S_S_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2063:
	.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	.LC3(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z30hybrid_cyclic_reduction_devicePfS_S_S_i(%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	.LC4(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z32parallel_cyclic_reduction_devicePfS_S_S_i(%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	.LC5(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z23cyclic_reduction_devicePfS_S_S_i(%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
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.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
.LFE2063:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1060205080
	.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>
void cyclic_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim);
void parallel_cyclic_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim);
void hybrid_cyclic_reduction(float *lower, float *diagonal, float *upper, float *equal, const int dim);
	.text
	.file	"cyclic_reduction.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
