//general parts
#include <stdio.h>
#include <vector>
#include <memory>
#include <string.h>
#include <chrono>
#include <thread>
#include <iostream>
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>

//CUDA parts
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <cufft.h>

#define GROUP 1


void sample_1_benchmark_cuFFT_double(bool file_output, FILE* output, int device_id)
{

	const int num_runs = 3;
	if (file_output)
		fprintf(output, "1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision\n");
	printf("1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision\n");
	cudaSetDevice(device_id);
	double benchmark_result[2] = { 0,0 };//averaged result = sum(system_size/iteration_time)/num_benchmark_samples
	cufftDoubleComplex* inputC = (cufftDoubleComplex*)malloc((uint64_t)sizeof(cufftDoubleComplex) *pow(2, 27));
	for (uint64_t i = 0; i <pow(2, 27); i++) {
		inputC[i].x = 2 * ((double)rand()) / RAND_MAX - 1.0;
		inputC[i].y = 2 * ((double)rand()) / RAND_MAX - 1.0;
	}
	for (int n = 0; n < 24; n++) {
		double run_time[num_runs][2];
		for (int r = 0; r < num_runs; r++) {
			cufftHandle planZ2Z;
			cufftDoubleComplex* dataC;

			uint64_t dims[3];
			dims[0] = 4 * pow(2, n); //Multidimensional FFT dimensions sizes (default 1). For best performance (and stability), order dimensions in descendant size order as: x>y>z.   
			if (n == 0) dims[0] = 2048;
			dims[1] = 64 * 32 * pow(2, 15) / dims[0];
			//dims[1] = (dims[1] > 32768) ? 32768 : dims[1];
			if (dims[1] == 0) dims[1] = 1;
			dims[2] = 1;
			cudaMalloc((void**)&dataC, sizeof(cufftDoubleComplex) * dims[0] * dims[1] * dims[2]);

			cudaMemcpy(dataC, inputC, sizeof(cufftDoubleComplex) * dims[0] * dims[1] * dims[2], cudaMemcpyHostToDevice);
			if (cudaGetLastError() != cudaSuccess) {
				fprintf(stderr, "Cuda error: Failed to allocate\n");
				return;
			}
			uint64_t sizeCUDA;
			switch (1) {
			case 1:
				cufftPlan1d(&planZ2Z, dims[0], CUFFT_Z2Z, dims[1]);
				cufftEstimate1d(dims[0], CUFFT_Z2Z, 1, (size_t*)&sizeCUDA);
				break;
			case 2:
				cufftPlan2d(&planZ2Z, dims[1], dims[0], CUFFT_Z2Z);
				cufftEstimate2d(dims[1], dims[0], CUFFT_Z2Z, (size_t*)&sizeCUDA);
				break;
			case 3:
				cufftPlan3d(&planZ2Z, dims[2], dims[1], dims[0], CUFFT_Z2Z);
				cufftEstimate3d(dims[2], dims[1], dims[0], CUFFT_Z2Z, (size_t*)&sizeCUDA);
				break;
			}

			double totTime = 0;
			uint64_t cuBufferSize = sizeof(double) * 2 * dims[0] * dims[1] * dims[2];
			uint64_t num_iter = ((4096 * 1024.0 * 1024.0) / cuBufferSize > 1000) ? 1000 : (4096 * 1024.0 * 1024.0) / cuBufferSize ;
			if (num_iter == 0) num_iter = 1;
			std::chrono::steady_clock::time_point timeSubmit = std::chrono::steady_clock::now();
			for (int i = 0; i < num_iter; i++) {

				cufftExecZ2Z(planZ2Z, dataC, dataC, -1);
				cufftExecZ2Z(planZ2Z, dataC, dataC, 1);
			}
			cudaDeviceSynchronize();
			std::chrono::steady_clock::time_point timeEnd = std::chrono::steady_clock::now();
			totTime = (std::chrono::duration_cast<std::chrono::microseconds>(timeEnd - timeSubmit).count() * 0.001) / num_iter;
			run_time[r][0] = totTime;
			if (n > 0) {
				if (r == num_runs - 1) {
					double std_error = 0;
					double avg_time = 0;
					for (uint64_t t = 0; t < num_runs; t++) {
						avg_time += run_time[t][0];
					}
					avg_time /= num_runs;
					for (uint64_t t = 0; t < num_runs; t++) {
						std_error += (run_time[t][0] - avg_time) * (run_time[t][0] - avg_time);
					}
					std_error = sqrt(std_error / num_runs);
					if (file_output)
						fprintf(output, "cuFFT System: %" PRIu64 " %" PRIu64 "x%" PRIu64 " Buffer: %" PRIu64 " MB avg_time_per_step: %0.3f ms std_error: %0.3f num_iter: %" PRIu64 " benchmark: %" PRIu64 "\n", (uint64_t)log2(dims[0]), dims[0], dims[1], cuBufferSize / 1024 / 1024, avg_time, std_error, num_iter, (uint64_t)(((double)cuBufferSize * sizeof(float) / sizeof(double) / 1024) / avg_time));

					printf("cuFFT System: %" PRIu64 " %" PRIu64 "x%" PRIu64 " Buffer: %" PRIu64 " MB avg_time_per_step: %0.3f ms std_error: %0.3f num_iter: %" PRIu64 " benchmark: %" PRIu64 "\n", (uint64_t)log2(dims[0]), dims[0], dims[1], cuBufferSize / 1024 / 1024, avg_time, std_error, num_iter, (uint64_t)(((double)cuBufferSize * sizeof(float) / sizeof(double) / 1024) / avg_time));
					benchmark_result[0] += ((double)cuBufferSize * sizeof(float)/sizeof(double)/ 1024) / avg_time;
				}

			}
			cufftDestroy(planZ2Z);
			cudaFree(dataC);
			cudaDeviceSynchronize();
			//cufftDoubleComplex* output_cuFFT = (cufftDoubleComplex*)(malloc(sizeof(cufftDoubleComplex) * dims[0] * dims[1] * dims[2]));
			//cudaMemcpy(output_cuFFT, dataC, sizeof(cufftDoubleComplex) * dims[0] * dims[1] * dims[2], cudaMemcpyDeviceToHost);
			//cudaDeviceSynchronize();


		}
	}
	free(inputC);
	benchmark_result[0] /= (24 - 1);
	if (file_output)
		fprintf(output, "Benchmark score cuFFT: %" PRIu64 "\n", (uint64_t)(benchmark_result[0]));
	printf("Benchmark score cuFFT: %" PRIu64 "\n", (uint64_t)(benchmark_result[0]));

}

	.file	"tmpxft_0039ffe3_00000000-6_sample_1_benchmark_cuFFT_double.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4751:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4751:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision\n"
.LC9:
	.string	"Cuda error: Failed to allocate\n"
.LC14:
	.string	"cuFFT System: %lu %lux%lu Buffer: %lu MB avg_time_per_step: %0.3f ms std_error: %0.3f num_iter: %lu benchmark: %lu\n"
.LC18:
	.string	"Benchmark score cuFFT: %lu\n"
	.text
	.globl	_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi
	.type	_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi, @function
_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi:
.LFB4745:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	.cfi_offset 15, -24
	movl	%edi, %r15d
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$184, %rsp
	movq	%rsi, -208(%rbp)
	movb	%dil, -209(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	testb	%dil, %dil
	je	.L3
	movq	-208(%rbp), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
.L3:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	call	__printf_chk@PLT
	movl	%ebx, %edi
	call	cudaSetDevice@PLT
	movl	$2147483648, %edi
	call	malloc@PLT
	movq	%rax, -200(%rbp)
	movq	%rax, %rbx
.L4:
	cvtsi2sdq	%r14, %xmm0
	movsd	.LC4(%rip), %xmm6
	comisd	%xmm0, %xmm6
	jbe	.L58
	call	rand@PLT
	addq	$16, %rbx
	cvtsi2sdl	%eax, %xmm0
	addsd	%xmm0, %xmm0
	divsd	.LC2(%rip), %xmm0
	subsd	.LC3(%rip), %xmm0
	movsd	%xmm0, -16(%rbx)
	call	rand@PLT
	cvtsi2sdl	%eax, %xmm0
	movq	%r14, %rax
	incq	%rax
	movq	%rax, %r14
	addsd	%xmm0, %xmm0
	divsd	.LC2(%rip), %xmm0
	subsd	.LC3(%rip), %xmm0
	movsd	%xmm0, -8(%rbx)
	jmp	.L4
.L58:
	movq	$0x000000000, -192(%rbp)
	xorl	%r13d, %r13d
.L6:
	xorl	%eax, %eax
	movq	%rax, -176(%rbp)
.L32:
	cvtsi2sdl	%r13d, %xmm1
	movsd	.LC5(%rip), %xmm0
	call	pow@PLT
	testl	%r13d, %r13d
	je	.L41
	mulsd	.LC6(%rip), %xmm0
	comisd	.LC7(%rip), %xmm0
	jnb	.L8
	cvttsd2siq	%xmm0, %rbx
	jmp	.L7
.L8:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %rbx
	btcq	$63, %rbx
	jmp	.L7
.L41:
	movl	$2048, %ebx
	jmp	.L54
.L7:
	testq	%rbx, %rbx
	js	.L10
.L54:
	cvtsi2sdq	%rbx, %xmm7
	movsd	%xmm7, -168(%rbp)
	jmp	.L11
.L10:
	movq	%rbx, %rax
	movq	%rbx, %rdx
	shrq	%rax
	andl	$1, %edx
	orq	%rdx, %rax
	cvtsi2sdq	%rax, %xmm0
	addsd	%xmm0, %xmm0
	movsd	%xmm0, -168(%rbp)
.L11:
	movsd	.LC8(%rip), %xmm0
	divsd	-168(%rbp), %xmm0
	comisd	.LC7(%rip), %xmm0
	jnb	.L12
	cvttsd2siq	%xmm0, %r12
	jmp	.L13
.L12:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %r12
	btcq	$63, %r12
.L13:
	testq	%r12, %r12
	movl	$1, %eax
	leaq	-128(%rbp), %rdi
	cmove	%rax, %r12
	movq	%rbx, %rax
	imulq	%r12, %rax
	salq	$4, %rax
	movq	%rax, %rsi
	movq	%rax, -160(%rbp)
	call	cudaMalloc@PLT
	movq	-160(%rbp), %rdx
	movq	-128(%rbp), %rdi
	movl	$1, %ecx
	movq	-200(%rbp), %rsi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L14
	movq	stderr(%rip), %rdi
	xorl	%eax, %eax
	movl	$2, %esi
	leaq	.LC9(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L40
	jmp	.L55
.L14:
	leaq	-132(%rbp), %rdi
	movl	%r12d, %ecx
	movl	$105, %edx
	movl	%ebx, %esi
	call	cufftPlan1d@PLT
	leaq	-120(%rbp), %rcx
	movl	$1, %edx
	movl	%ebx, %edi
	movl	$105, %esi
	call	cufftEstimate1d@PLT
	cmpq	$0, -160(%rbp)
	js	.L16
	cvtsi2sdq	-160(%rbp), %xmm7
	movsd	%xmm7, -184(%rbp)
	jmp	.L17
.L16:
	movq	-160(%rbp), %rax
	shrq	%rax
	cvtsi2sdq	%rax, %xmm0
	addsd	%xmm0, %xmm0
	movsd	%xmm0, -184(%rbp)
.L17:
	movsd	.LC10(%rip), %xmm0
	divsd	-184(%rbp), %xmm0
	comisd	.LC11(%rip), %xmm0
	movl	$1000, %r8d
	ja	.L18
	comisd	.LC7(%rip), %xmm0
	jnb	.L19
	cvttsd2siq	%xmm0, %r8
	jmp	.L20
.L19:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %r8
	btcq	$63, %r8
.L20:
	testq	%r8, %r8
	movl	$1, %eax
	cmove	%rax, %r8
.L18:
	movq	%r8, -224(%rbp)
	xorl	%r14d, %r14d
	call	_ZNSt6chrono3_V212steady_clock3nowEv@PLT
	movq	-224(%rbp), %r8
	movq	%rax, -152(%rbp)
.L21:
	movq	-128(%rbp), %rsi
	movl	-132(%rbp), %edi
	orl	$-1, %ecx
	incq	%r14
	movq	%r8, -224(%rbp)
	movq	%rsi, %rdx
	call	cufftExecZ2Z@PLT
	movq	-128(%rbp), %rsi
	movl	-132(%rbp), %edi
	movl	$1, %ecx
	movq	%rsi, %rdx
	call	cufftExecZ2Z@PLT
	movq	-224(%rbp), %r8
	cmpq	%r14, %r8
	jne	.L21
	call	cudaDeviceSynchronize@PLT
	call	_ZNSt6chrono3_V212steady_clock3nowEv@PLT
	movq	-152(%rbp), %rsi
	cvtsi2sdq	%r14, %xmm1
	movq	-176(%rbp), %rcx
	subq	%rsi, %rax
	movl	$1000, %esi
	salq	$4, %rcx
	cqto
	idivq	%rsi
	cmpl	$2, -176(%rbp)
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC12(%rip), %xmm0
	divsd	%xmm1, %xmm0
	movsd	%xmm0, -112(%rbp,%rcx)
	jne	.L22
	testl	%r13d, %r13d
	je	.L22
	movsd	-112(%rbp), %xmm2
	xorps	%xmm5, %xmm5
	movsd	-96(%rbp), %xmm0
	movsd	-80(%rbp), %xmm1
	movsd	.LC13(%rip), %xmm4
	movaps	%xmm2, %xmm3
	addsd	%xmm5, %xmm3
	addsd	%xmm0, %xmm3
	addsd	%xmm1, %xmm3
	divsd	%xmm4, %xmm3
	subsd	%xmm3, %xmm2
	subsd	%xmm3, %xmm0
	movsd	%xmm3, -152(%rbp)
	subsd	%xmm3, %xmm1
	mulsd	%xmm2, %xmm2
	mulsd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm1
	addsd	%xmm5, %xmm2
	addsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	divsd	%xmm4, %xmm0
	call	sqrt@PLT
	movq	-160(%rbp), %rax
	movaps	%xmm0, %xmm1
	shrq	$20, %rax
	cmpb	$0, -209(%rbp)
	movq	%rax, -160(%rbp)
	je	.L23
	movsd	%xmm0, -224(%rbp)
	movsd	-168(%rbp), %xmm0
	call	log2@PLT
	comisd	.LC7(%rip), %xmm0
	movsd	-224(%rbp), %xmm1
	jnb	.L24
	cvttsd2siq	%xmm0, %rcx
	jmp	.L25
.L24:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %rcx
	btcq	$63, %rcx
.L25:
	movsd	.LC6(%rip), %xmm0
	pushq	%rsi
	mulsd	-184(%rbp), %xmm0
	mulsd	.LC15(%rip), %xmm0
	mulsd	.LC16(%rip), %xmm0
	divsd	-152(%rbp), %xmm0
	comisd	.LC7(%rip), %xmm0
	jnb	.L26
	cvttsd2siq	%xmm0, %rax
	jmp	.L27
.L26:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %rax
	btcq	$63, %rax
.L27:
	pushq	%rax
	movq	%r12, %r9
	movq	%rbx, %r8
	leaq	.LC14(%rip), %rdx
	pushq	%r14
	movl	$2, %esi
	movb	$2, %al
	pushq	-160(%rbp)
	movsd	-152(%rbp), %xmm0
	movq	-208(%rbp), %rdi
	movsd	%xmm1, -224(%rbp)
	call	__fprintf_chk@PLT
	movsd	-224(%rbp), %xmm1
	addq	$32, %rsp
.L23:
	movsd	.LC6(%rip), %xmm2
	mulsd	-184(%rbp), %xmm2
	movsd	%xmm1, -224(%rbp)
	mulsd	.LC15(%rip), %xmm2
	movsd	-168(%rbp), %xmm0
	mulsd	.LC16(%rip), %xmm2
	divsd	-152(%rbp), %xmm2
	movsd	%xmm2, -184(%rbp)
	call	log2@PLT
	comisd	.LC7(%rip), %xmm0
	movsd	-184(%rbp), %xmm2
	movsd	-224(%rbp), %xmm1
	jnb	.L28
	cvttsd2siq	%xmm0, %rdx
	jmp	.L29
.L28:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %rdx
	btcq	$63, %rdx
.L29:
	comisd	.LC7(%rip), %xmm2
	jnb	.L30
	cvttsd2siq	%xmm2, %rax
	jmp	.L31
.L30:
	movaps	%xmm2, %xmm0
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %rax
	btcq	$63, %rax
.L31:
	movsd	%xmm2, -168(%rbp)
	movq	%rbx, %rcx
	movq	%r12, %r8
	leaq	.LC14(%rip), %rsi
	pushq	%rax
	movl	$2, %edi
	movb	$2, %al
	pushq	%r14
	movsd	-152(%rbp), %xmm0
	movq	-160(%rbp), %r9
	call	__printf_chk@PLT
	movsd	-168(%rbp), %xmm2
	addsd	-192(%rbp), %xmm2
	movsd	%xmm2, -192(%rbp)
	popq	%rdx
	popq	%rcx
.L22:
	movl	-132(%rbp), %edi
	call	cufftDestroy@PLT
	movq	-128(%rbp), %rdi
	call	cudaFree@PLT
	call	cudaDeviceSynchronize@PLT
	incq	-176(%rbp)
	cmpq	$3, -176(%rbp)
	jne	.L32
	incl	%r13d
	cmpl	$24, %r13d
	jne	.L6
	movq	-200(%rbp), %rdi
	leaq	.LC18(%rip), %rbx
	call	free@PLT
	testb	%r15b, %r15b
	movsd	-192(%rbp), %xmm0
	divsd	.LC17(%rip), %xmm0
	je	.L34
	comisd	.LC7(%rip), %xmm0
	jnb	.L35
	cvttsd2siq	%xmm0, %rcx
	jmp	.L36
.L35:
	movaps	%xmm0, %xmm1
	subsd	.LC7(%rip), %xmm1
	cvttsd2siq	%xmm1, %rcx
	btcq	$63, %rcx
.L36:
	movq	-208(%rbp), %rdi
	movq	%rbx, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	movsd	%xmm0, -152(%rbp)
	call	__fprintf_chk@PLT
	movsd	-152(%rbp), %xmm0
.L34:
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L55
	comisd	.LC7(%rip), %xmm0
	jnb	.L38
	cvttsd2siq	%xmm0, %rdx
	jmp	.L39
.L38:
	subsd	.LC7(%rip), %xmm0
	cvttsd2siq	%xmm0, %rdx
	btcq	$63, %rdx
.L39:
	leaq	-40(%rbp), %rsp
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	jmp	__printf_chk@PLT
.L55:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
.L40:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4745:
	.size	_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi, .-_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4774:
	.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
.LFE4774:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	-4194304
	.long	1105199103
	.align 8
.LC3:
	.long	0
	.long	1072693248
	.align 8
.LC4:
	.long	0
	.long	1101004800
	.align 8
.LC5:
	.long	0
	.long	1073741824
	.align 8
.LC6:
	.long	0
	.long	1074790400
	.align 8
.LC7:
	.long	0
	.long	1138753536
	.align 8
.LC8:
	.long	0
	.long	1099956224
	.align 8
.LC10:
	.long	0
	.long	1106247680
	.align 8
.LC11:
	.long	0
	.long	1083129856
	.align 8
.LC12:
	.long	-755914244
	.long	1062232653
	.align 8
.LC13:
	.long	0
	.long	1074266112
	.align 8
.LC15:
	.long	0
	.long	1069547520
	.align 8
.LC16:
	.long	0
	.long	1062207488
	.align 8
.LC17:
	.long	0
	.long	1077346304
	.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:

//general parts
#include <stdio.h>
#include <vector>
#include <memory>
#include <string.h>
#include <chrono>
#include <thread>
#include <iostream>
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>

//CUDA parts
#include "hip/hip_runtime.h"

#include <hipfft/hipfft.h>

#define GROUP 1


void sample_1_benchmark_cuFFT_double(bool file_output, FILE* output, int device_id)
{

	const int num_runs = 3;
	if (file_output)
		fprintf(output, "1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision\n");
	printf("1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision\n");
	hipSetDevice(device_id);
	double benchmark_result[2] = { 0,0 };//averaged result = sum(system_size/iteration_time)/num_benchmark_samples
	hipfftDoubleComplex* inputC = (hipfftDoubleComplex*)malloc((uint64_t)sizeof(hipfftDoubleComplex) *pow(2, 27));
	for (uint64_t i = 0; i <pow(2, 27); i++) {
		inputC[i].x = 2 * ((double)rand()) / RAND_MAX - 1.0;
		inputC[i].y = 2 * ((double)rand()) / RAND_MAX - 1.0;
	}
	for (int n = 0; n < 24; n++) {
		double run_time[num_runs][2];
		for (int r = 0; r < num_runs; r++) {
			hipfftHandle planZ2Z;
			hipfftDoubleComplex* dataC;

			uint64_t dims[3];
			dims[0] = 4 * pow(2, n); //Multidimensional FFT dimensions sizes (default 1). For best performance (and stability), order dimensions in descendant size order as: x>y>z.   
			if (n == 0) dims[0] = 2048;
			dims[1] = 64 * 32 * pow(2, 15) / dims[0];
			//dims[1] = (dims[1] > 32768) ? 32768 : dims[1];
			if (dims[1] == 0) dims[1] = 1;
			dims[2] = 1;
			hipMalloc((void**)&dataC, sizeof(hipfftDoubleComplex) * dims[0] * dims[1] * dims[2]);

			hipMemcpy(dataC, inputC, sizeof(hipfftDoubleComplex) * dims[0] * dims[1] * dims[2], hipMemcpyHostToDevice);
			if (hipGetLastError() != hipSuccess) {
				fprintf(stderr, "Cuda error: Failed to allocate\n");
				return;
			}
			uint64_t sizeCUDA;
			switch (1) {
			case 1:
				hipfftPlan1d(&planZ2Z, dims[0], HIPFFT_Z2Z, dims[1]);
				hipfftEstimate1d(dims[0], HIPFFT_Z2Z, 1, (size_t*)&sizeCUDA);
				break;
			case 2:
				hipfftPlan2d(&planZ2Z, dims[1], dims[0], HIPFFT_Z2Z);
				hipfftEstimate2d(dims[1], dims[0], HIPFFT_Z2Z, (size_t*)&sizeCUDA);
				break;
			case 3:
				hipfftPlan3d(&planZ2Z, dims[2], dims[1], dims[0], HIPFFT_Z2Z);
				hipfftEstimate3d(dims[2], dims[1], dims[0], HIPFFT_Z2Z, (size_t*)&sizeCUDA);
				break;
			}

			double totTime = 0;
			uint64_t cuBufferSize = sizeof(double) * 2 * dims[0] * dims[1] * dims[2];
			uint64_t num_iter = ((4096 * 1024.0 * 1024.0) / cuBufferSize > 1000) ? 1000 : (4096 * 1024.0 * 1024.0) / cuBufferSize ;
			if (num_iter == 0) num_iter = 1;
			std::chrono::steady_clock::time_point timeSubmit = std::chrono::steady_clock::now();
			for (int i = 0; i < num_iter; i++) {

				hipfftExecZ2Z(planZ2Z, dataC, dataC, -1);
				hipfftExecZ2Z(planZ2Z, dataC, dataC, 1);
			}
			hipDeviceSynchronize();
			std::chrono::steady_clock::time_point timeEnd = std::chrono::steady_clock::now();
			totTime = (std::chrono::duration_cast<std::chrono::microseconds>(timeEnd - timeSubmit).count() * 0.001) / num_iter;
			run_time[r][0] = totTime;
			if (n > 0) {
				if (r == num_runs - 1) {
					double std_error = 0;
					double avg_time = 0;
					for (uint64_t t = 0; t < num_runs; t++) {
						avg_time += run_time[t][0];
					}
					avg_time /= num_runs;
					for (uint64_t t = 0; t < num_runs; t++) {
						std_error += (run_time[t][0] - avg_time) * (run_time[t][0] - avg_time);
					}
					std_error = sqrt(std_error / num_runs);
					if (file_output)
						fprintf(output, "cuFFT System: %" PRIu64 " %" PRIu64 "x%" PRIu64 " Buffer: %" PRIu64 " MB avg_time_per_step: %0.3f ms std_error: %0.3f num_iter: %" PRIu64 " benchmark: %" PRIu64 "\n", (uint64_t)log2(dims[0]), dims[0], dims[1], cuBufferSize / 1024 / 1024, avg_time, std_error, num_iter, (uint64_t)(((double)cuBufferSize * sizeof(float) / sizeof(double) / 1024) / avg_time));

					printf("cuFFT System: %" PRIu64 " %" PRIu64 "x%" PRIu64 " Buffer: %" PRIu64 " MB avg_time_per_step: %0.3f ms std_error: %0.3f num_iter: %" PRIu64 " benchmark: %" PRIu64 "\n", (uint64_t)log2(dims[0]), dims[0], dims[1], cuBufferSize / 1024 / 1024, avg_time, std_error, num_iter, (uint64_t)(((double)cuBufferSize * sizeof(float) / sizeof(double) / 1024) / avg_time));
					benchmark_result[0] += ((double)cuBufferSize * sizeof(float)/sizeof(double)/ 1024) / avg_time;
				}

			}
			hipfftDestroy(planZ2Z);
			hipFree(dataC);
			hipDeviceSynchronize();
			//cufftDoubleComplex* output_cuFFT = (cufftDoubleComplex*)(malloc(sizeof(cufftDoubleComplex) * dims[0] * dims[1] * dims[2]));
			//cudaMemcpy(output_cuFFT, dataC, sizeof(cufftDoubleComplex) * dims[0] * dims[1] * dims[2], cudaMemcpyDeviceToHost);
			//cudaDeviceSynchronize();


		}
	}
	free(inputC);
	benchmark_result[0] /= (24 - 1);
	if (file_output)
		fprintf(output, "Benchmark score cuFFT: %" PRIu64 "\n", (uint64_t)(benchmark_result[0]));
	printf("Benchmark score cuFFT: %" PRIu64 "\n", (uint64_t)(benchmark_result[0]));

}

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

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi
.LCPI0_0:
	.quad	0x41dfffffffc00000              # double 2147483647
.LCPI0_1:
	.quad	0xbff0000000000000              # double -1
.LCPI0_2:
	.quad	0x3ff0000000000000              # double 1
.LCPI0_3:
	.quad	0x4010000000000000              # double 4
.LCPI0_4:
	.quad	0x43e0000000000000              # double 9.2233720368547758E+18
.LCPI0_7:
	.quad	0x4190000000000000              # double 67108864
.LCPI0_8:
	.quad	0x41f0000000000000              # double 4294967296
.LCPI0_9:
	.quad	0x408f400000000000              # double 1000
.LCPI0_10:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
.LCPI0_11:
	.quad	0x4008000000000000              # double 3
.LCPI0_12:
	.quad	0x3fc0000000000000              # double 0.125
.LCPI0_13:
	.quad	0x3f50000000000000              # double 9.765625E-4
.LCPI0_14:
	.quad	0x4037000000000000              # double 23
.LCPI0_15:
	.quad	0x0000000000000000              # double 0
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_5:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI0_6:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.text
	.globl	_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi
	.type	_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi,@function
_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi: # @_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi
	.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	$200, %rsp
	.cfi_def_cfa_offset 256
	.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	%edx, %ebx
	movq	%rsi, 24(%rsp)                  # 8-byte Spill
	movl	%edi, 12(%rsp)                  # 4-byte Spill
	testl	%edi, %edi
	je	.LBB0_2
# %bb.1:
	movl	$.L.str, %edi
	movl	$66, %esi
	movl	$1, %edx
	movq	24(%rsp), %rcx                  # 8-byte Reload
	callq	fwrite@PLT
.LBB0_2:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	%ebx, %edi
	callq	hipSetDevice
	movl	$2147483648, %ebx               # imm = 0x80000000
	movl	$2147483648, %edi               # imm = 0x80000000
	callq	malloc
	movq	%rax, %r15
	xorl	%r14d, %r14d
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	addsd	%xmm0, %xmm0
	movsd	.LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm1, %xmm0
	movsd	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%r15,%r14)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	addsd	%xmm0, %xmm0
	divsd	.LCPI0_0(%rip), %xmm0
	addsd	.LCPI0_1(%rip), %xmm0
	movsd	%xmm0, 8(%r15,%r14)
	addq	$16, %r14
	cmpq	%rbx, %r14
	jne	.LBB0_3
# %bb.4:                                # %.split.preheader
	xorl	%ebx, %ebx
	xorpd	%xmm0, %xmm0
	movapd	%xmm0, 80(%rsp)                 # 16-byte Spill
	movq	%r15, 120(%rsp)                 # 8-byte Spill
.LBB0_5:                                # %.split
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_6 Depth 2
                                        #       Child Loop BB0_17 Depth 3
                                        #       Child Loop BB0_11 Depth 3
                                        #       Child Loop BB0_13 Depth 3
	xorl	%r14d, %r14d
	movq	%rbx, 128(%rsp)                 # 8-byte Spill
.LBB0_6:                                #   Parent Loop BB0_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_17 Depth 3
                                        #       Child Loop BB0_11 Depth 3
                                        #       Child Loop BB0_13 Depth 3
	movsd	.LCPI0_2(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	%ebx, %edi
	callq	ldexp@PLT
	mulsd	.LCPI0_3(%rip), %xmm0
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	movsd	.LCPI0_4(%rip), %xmm2           # xmm2 = mem[0],zero
	subsd	%xmm2, %xmm0
	cvttsd2si	%xmm0, %rbp
	andq	%rcx, %rbp
	orq	%rax, %rbp
	testl	%ebx, %ebx
	movl	$2048, %eax                     # imm = 0x800
	cmoveq	%rax, %rbp
	movq	%rbp, %xmm0
	movdqa	.LCPI0_5(%rip), %xmm1           # xmm1 = [1127219200,1160773632,0,0]
	punpckldq	%xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
	movapd	.LCPI0_6(%rip), %xmm1           # xmm1 = [4.503599627370496E+15,1.9342813113834067E+25]
	subpd	%xmm1, %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	movsd	.LCPI0_7(%rip), %xmm0           # xmm0 = mem[0],zero
	movapd	%xmm1, 96(%rsp)                 # 16-byte Spill
	divsd	%xmm1, %xmm0
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subsd	%xmm2, %xmm0
	cvttsd2si	%xmm0, %r12
	andq	%rcx, %r12
	orq	%rax, %r12
	cmpq	$1, %r12
	adcq	$0, %r12
	movq	%rbp, %r13
	imulq	%r12, %r13
	shlq	$4, %r13
	leaq	16(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	16(%rsp), %rdi
	movq	%r15, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB0_7
# %bb.16:                               #   in Loop: Header=BB0_6 Depth=2
	movq	%r14, 72(%rsp)                  # 8-byte Spill
	leaq	40(%rsp), %rdi
	movl	%ebp, %esi
	movl	$105, %edx
	movl	%r12d, %ecx
	callq	hipfftPlan1d
	movl	%ebp, %edi
	movl	$105, %esi
	movl	$1, %edx
	leaq	136(%rsp), %rcx
	callq	hipfftEstimate1d
	movq	%r13, %xmm0
	punpckldq	.LCPI0_5(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
	subpd	.LCPI0_6(%rip), %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	movsd	.LCPI0_8(%rip), %xmm0           # xmm0 = mem[0],zero
	movapd	%xmm1, 48(%rsp)                 # 16-byte Spill
	divsd	%xmm1, %xmm0
	movsd	.LCPI0_9(%rip), %xmm1           # xmm1 = mem[0],zero
	minsd	%xmm0, %xmm1
	cvttsd2si	%xmm1, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subsd	.LCPI0_4(%rip), %xmm1
	cvttsd2si	%xmm1, %r15
	andq	%rcx, %r15
	orq	%rax, %r15
	callq	_ZNSt6chrono3_V212steady_clock3nowEv
	movq	%rax, %r14
	cmpq	$1, %r15
	adcq	$0, %r15
	movq	%r15, %rbx
.LBB0_17:                               #   Parent Loop BB0_5 Depth=1
                                        #     Parent Loop BB0_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	40(%rsp), %rdi
	movq	16(%rsp), %rdx
	movq	%rdx, %rsi
	movl	$-1, %ecx
	callq	hipfftExecZ2Z
	movq	40(%rsp), %rdi
	movq	16(%rsp), %rdx
	movq	%rdx, %rsi
	movl	$1, %ecx
	callq	hipfftExecZ2Z
	decq	%rbx
	jne	.LBB0_17
# %bb.8:                                #   in Loop: Header=BB0_6 Depth=2
	callq	hipDeviceSynchronize
	callq	_ZNSt6chrono3_V212steady_clock3nowEv
	subq	%r14, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	movq	72(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rax
	shlq	$4, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rdx, %xmm0
	mulsd	.LCPI0_10(%rip), %xmm0
	movq	%r15, %xmm1
	punpckldq	.LCPI0_5(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
	subpd	.LCPI0_6(%rip), %xmm1
	movapd	%xmm1, %xmm2
	unpckhpd	%xmm1, %xmm2                    # xmm2 = xmm2[1],xmm1[1]
	addsd	%xmm1, %xmm2
	divsd	%xmm2, %xmm0
	movsd	%xmm0, 144(%rsp,%rax)
	movq	128(%rsp), %rbx                 # 8-byte Reload
	testl	%ebx, %ebx
	je	.LBB0_23
# %bb.9:                                #   in Loop: Header=BB0_6 Depth=2
	cmpq	$2, %r14
	jne	.LBB0_23
# %bb.10:                               # %.preheader.preheader
                                        #   in Loop: Header=BB0_6 Depth=2
	xorpd	%xmm2, %xmm2
	xorl	%eax, %eax
.LBB0_11:                               # %.preheader
                                        #   Parent Loop BB0_5 Depth=1
                                        #     Parent Loop BB0_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	addsd	144(%rsp,%rax), %xmm2
	addq	$16, %rax
	cmpq	$48, %rax
	jne	.LBB0_11
# %bb.12:                               #   in Loop: Header=BB0_6 Depth=2
	divsd	.LCPI0_11(%rip), %xmm2
	xorpd	%xmm0, %xmm0
	xorl	%eax, %eax
.LBB0_13:                               #   Parent Loop BB0_5 Depth=1
                                        #     Parent Loop BB0_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	144(%rsp,%rax), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm2, %xmm1
	mulsd	%xmm1, %xmm1
	addsd	%xmm1, %xmm0
	addq	$16, %rax
	cmpq	$48, %rax
	jne	.LBB0_13
# %bb.14:                               #   in Loop: Header=BB0_6 Depth=2
	divsd	.LCPI0_11(%rip), %xmm0
	ucomisd	.LCPI0_15(%rip), %xmm0
	movsd	%xmm2, 32(%rsp)                 # 8-byte Spill
	jb	.LBB0_18
# %bb.15:                               #   in Loop: Header=BB0_6 Depth=2
	xorps	%xmm1, %xmm1
	sqrtsd	%xmm0, %xmm1
	jmp	.LBB0_19
.LBB0_18:                               # %call.sqrt
                                        #   in Loop: Header=BB0_6 Depth=2
	callq	sqrt
	movapd	%xmm0, %xmm1
.LBB0_19:                               # %.split160
                                        #   in Loop: Header=BB0_6 Depth=2
	movapd	96(%rsp), %xmm0                 # 16-byte Reload
	movsd	%xmm1, 64(%rsp)                 # 8-byte Spill
	cmpb	$0, 12(%rsp)                    # 1-byte Folded Reload
	je	.LBB0_20
# %bb.21:                               #   in Loop: Header=BB0_6 Depth=2
	callq	log2
	cvttsd2si	%xmm0, %rax
	movsd	.LCPI0_4(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm1, %xmm0
	cvttsd2si	%xmm0, %rcx
	movq	%rax, %rdx
	sarq	$63, %rdx
	andq	%rcx, %rdx
	orq	%rax, %rdx
	shrq	$20, %r13
	movapd	48(%rsp), %xmm0                 # 16-byte Reload
	mulsd	.LCPI0_3(%rip), %xmm0
	mulsd	.LCPI0_12(%rip), %xmm0
	mulsd	.LCPI0_13(%rip), %xmm0
	movsd	32(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm0
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	movapd	%xmm0, 48(%rsp)                 # 16-byte Spill
	subsd	%xmm1, %xmm0
	cvttsd2si	%xmm0, %r14
	andq	%rcx, %r14
	orq	%rax, %r14
	movl	$.L.str.2, %esi
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movq	%rbp, %rcx
	movq	%r12, %r8
	movq	%r13, %r9
	movapd	%xmm2, %xmm0
	movsd	64(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movb	$2, %al
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	callq	fprintf
	movapd	112(%rsp), %xmm0                # 16-byte Reload
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	jmp	.LBB0_22
.LBB0_20:                               # %._crit_edge
                                        #   in Loop: Header=BB0_6 Depth=2
	shrq	$20, %r13
	movapd	48(%rsp), %xmm2                 # 16-byte Reload
	mulsd	.LCPI0_3(%rip), %xmm2
	mulsd	.LCPI0_12(%rip), %xmm2
	mulsd	.LCPI0_13(%rip), %xmm2
	divsd	32(%rsp), %xmm2                 # 8-byte Folded Reload
	cvttsd2si	%xmm2, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	movapd	%xmm2, 48(%rsp)                 # 16-byte Spill
	movsd	.LCPI0_4(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm1, %xmm2
	cvttsd2si	%xmm2, %r14
	andq	%rcx, %r14
	orq	%rax, %r14
.LBB0_22:                               #   in Loop: Header=BB0_6 Depth=2
	callq	log2
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subsd	.LCPI0_4(%rip), %xmm0
	cvttsd2si	%xmm0, %rsi
	andq	%rcx, %rsi
	orq	%rax, %rsi
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$.L.str.2, %edi
	movq	%rbp, %rdx
	movq	%r12, %rcx
	movq	%r13, %r8
	movsd	40(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	72(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movq	%r15, %r9
	movb	$2, %al
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	callq	printf
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movapd	80(%rsp), %xmm0                 # 16-byte Reload
	addsd	48(%rsp), %xmm0                 # 16-byte Folded Reload
	movapd	%xmm0, 80(%rsp)                 # 16-byte Spill
	movq	72(%rsp), %r14                  # 8-byte Reload
.LBB0_23:                               #   in Loop: Header=BB0_6 Depth=2
	movq	40(%rsp), %rdi
	callq	hipfftDestroy
	movq	16(%rsp), %rdi
	callq	hipFree
	callq	hipDeviceSynchronize
	incq	%r14
	cmpq	$3, %r14
	movq	120(%rsp), %r15                 # 8-byte Reload
	jne	.LBB0_6
# %bb.24:                               # %.thread101
                                        #   in Loop: Header=BB0_5 Depth=1
	incl	%ebx
	cmpl	$24, %ebx
	jne	.LBB0_5
# %bb.25:                               # %.thread106
	movq	%r15, %rdi
	callq	free
	movapd	80(%rsp), %xmm0                 # 16-byte Reload
	divsd	.LCPI0_14(%rip), %xmm0
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	subsd	.LCPI0_4(%rip), %xmm0
	cvttsd2si	%xmm0, %rbx
	sarq	$63, %rcx
	andq	%rcx, %rbx
	orq	%rax, %rbx
	cmpb	$0, 12(%rsp)                    # 1-byte Folded Reload
	je	.LBB0_27
# %bb.26:
	movl	$.L.str.3, %esi
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	fprintf
.LBB0_27:                               # %.thread106._crit_edge
	movl	$.L.str.3, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB0_28
.LBB0_7:                                # %.thread104
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$31, %esi
	movl	$1, %edx
	callq	fwrite@PLT
.LBB0_28:
	addq	$200, %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	_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi, .Lfunc_end0-_Z31sample_1_benchmark_cuFFT_doublebP8_IO_FILEi
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision\n"
	.size	.L.str, 67

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Cuda error: Failed to allocate\n"
	.size	.L.str.1, 32

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"cuFFT System: %lu %lux%lu Buffer: %lu MB avg_time_per_step: %0.3f ms std_error: %0.3f num_iter: %lu benchmark: %lu\n"
	.size	.L.str.2, 116

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Benchmark score cuFFT: %lu\n"
	.size	.L.str.3, 28

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"1 - cuFFT FFT + iFFT C2C benchmark 1D batched in double precision"
	.size	.Lstr, 66

	.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
