/*
 * singleGpuSpectrometer
 * 
 * Version 2.0, April 12 2010
 *
 * This program was written by Hirofumi Kondo at the Supercomputing Engineering Laboratory,
 * Graduate School of Information Science and Technology, Osaka University, Japan.
 *
 * Copyright 2010 Supercomputing Engineering Laboratory, Graduate School of Information
 * Science and Technology, Osaka University, Japan
 *
 *
 * Compile : 
 *   nvcc -o singleGpuSpectrometer singleGpuSpectrometer.cu -I /usr/local/cuda/NVIDIA_GPU_Computing_SDK/common/inc
 *                                                             /usr/local/cuda/NVIDIA_GPU_Computing_SDK/C/lib/libcutil.a
 *                                                          -L /usr/local/cuda/lib -l cufft
 *
 * Usage : ./singleGpuSpectrometer [options]
 *   -length           : signal length of this spectrometer handle in M-points 
 *   -boxcar           : length of boxcar for smoothing
 *   -threshold        : value of threshold
 *   -max_detect_point : value of maximum detected points over threshold in each boxcar
 *   -output_file      : filename of output file
 *
 * Output file format :
 *   The file format is binary format.
 *   The output file records all spikes whose power exceed (boxcar_mean) * (threashold).
 *   The file contains 3 data
 *     1) index of signal
 *     2) the power of signal
 *     3) mean power of boxcar which the signal is in
 * 
 * Special Instruction
 *   1) Memory capacity
 *     The memory capacity that this GPU spectrometer requires is changed by the signal length.
 *     If you want to analyze 128M-points signal, GPU has to have 4GB VRAM.
 *     The maximum length that 1GB VRAM GPU can handle is 32M-points.
 *
 *   2) CUDA
 *     We recommend that you use CUDA 2.3 and CUFFT 2.3.
 *     This is not necessary condition.
 *     But the execution time is wrong if you use CUDA 2.2 and CUFFT 2.2.
 */


// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include <cuda.h>
//#include <cutil_inline.h>
//#include <cufft.h>

//#include "bench_fft.h"


//#include "output_greg.c"


/* 
 * Prototype declaration
 */

/* Modified by Jayanth Chennamangalam on 2013.01.31 --> */
/*void do_analyze_on_gpu();*/
void do_analyze_on_gpu(int signalLength);
/* <-- Modified by Jayanth Chennamangalam on 2013.01.31 */



/*
 * Program main
 */
int main(int argc, char** argv){
 

    int i;
    int signalLength = 1024 * 1024;


    for (i=1;i<argc;i++) {
        if (!strcmp(argv[i], "-length")) {
        	signalLength = atoi(argv[++i]) * 1024 * 1024;
        } /*else if (!strcmp(argv[i], "-boxcar")){
		boxcar = atoi(argv[++i]);
	} else if (!strcmp(argv[i], "-threshold")){
		threshold = atoi(argv[++i]);
	} else if (!strcmp(argv[i], "-max_detect_point")){
		maximumDetectPointInBoxcar = atoi(argv[++i]);
	} else if (!strcmp(argv[i], "-output_file")){
		strncpy(outputFileName, argv[++i], FILENAME_BUFSIZE);
		if(outputFileName[FILENAME_BUFSIZE-1]!='\0'){
			fprintf(stderr,"Error : Too long output file name. maximum length = %d\n", FILENAME_BUFSIZE-1);
			exit(-1);
		}
	} else {
		fprintf(stderr,"Error : wrong argument\n");
        }*/
    }

    // Analyze signal on GPU
    printf("Calling GPU\n");
    do_analyze_on_gpu(signalLength);

    return 0;
}




	.file	"tmpxft_0022fde7_00000000-6_bench_fft.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"-length"
.LC1:
	.string	"Calling GPU\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	$1048576, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$1, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 64
.L3:
	cmpl	%r13d, %ebx
	jge	.L8
	movslq	%ebx, %rax
	movq	%r14, %rsi
	movq	(%r12,%rax,8), %rdi
	leaq	0(,%rax,8), %r15
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L4
	movq	8(%r12,%r15), %rdi
	incl	%ebx
	call	atoi@PLT
	sall	$20, %eax
	movl	%eax, %ebp
.L4:
	incl	%ebx
	jmp	.L3
.L8:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebp, %edi
	call	_Z17do_analyze_on_gpui@PLT
	popq	%rdx
	.cfi_def_cfa_offset 56
	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
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2053:
	.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
.LFE2053:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

/*
 * singleGpuSpectrometer
 * 
 * Version 2.0, April 12 2010
 *
 * This program was written by Hirofumi Kondo at the Supercomputing Engineering Laboratory,
 * Graduate School of Information Science and Technology, Osaka University, Japan.
 *
 * Copyright 2010 Supercomputing Engineering Laboratory, Graduate School of Information
 * Science and Technology, Osaka University, Japan
 *
 *
 * Compile : 
 *   nvcc -o singleGpuSpectrometer singleGpuSpectrometer.cu -I /usr/local/cuda/NVIDIA_GPU_Computing_SDK/common/inc
 *                                                             /usr/local/cuda/NVIDIA_GPU_Computing_SDK/C/lib/libcutil.a
 *                                                          -L /usr/local/cuda/lib -l cufft
 *
 * Usage : ./singleGpuSpectrometer [options]
 *   -length           : signal length of this spectrometer handle in M-points 
 *   -boxcar           : length of boxcar for smoothing
 *   -threshold        : value of threshold
 *   -max_detect_point : value of maximum detected points over threshold in each boxcar
 *   -output_file      : filename of output file
 *
 * Output file format :
 *   The file format is binary format.
 *   The output file records all spikes whose power exceed (boxcar_mean) * (threashold).
 *   The file contains 3 data
 *     1) index of signal
 *     2) the power of signal
 *     3) mean power of boxcar which the signal is in
 * 
 * Special Instruction
 *   1) Memory capacity
 *     The memory capacity that this GPU spectrometer requires is changed by the signal length.
 *     If you want to analyze 128M-points signal, GPU has to have 4GB VRAM.
 *     The maximum length that 1GB VRAM GPU can handle is 32M-points.
 *
 *   2) CUDA
 *     We recommend that you use CUDA 2.3 and CUFFT 2.3.
 *     This is not necessary condition.
 *     But the execution time is wrong if you use CUDA 2.2 and CUFFT 2.2.
 */


// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include <hip/hip_runtime.h>
//#include <cutil_inline.h>
//#include <cufft.h>

//#include "bench_fft.h"


//#include "output_greg.c"


/* 
 * Prototype declaration
 */

/* Modified by Jayanth Chennamangalam on 2013.01.31 --> */
/*void do_analyze_on_gpu();*/
void do_analyze_on_gpu(int signalLength);
/* <-- Modified by Jayanth Chennamangalam on 2013.01.31 */



/*
 * Program main
 */
int main(int argc, char** argv){
 

    int i;
    int signalLength = 1024 * 1024;


    for (i=1;i<argc;i++) {
        if (!strcmp(argv[i], "-length")) {
        	signalLength = atoi(argv[++i]) * 1024 * 1024;
        } /*else if (!strcmp(argv[i], "-boxcar")){
		boxcar = atoi(argv[++i]);
	} else if (!strcmp(argv[i], "-threshold")){
		threshold = atoi(argv[++i]);
	} else if (!strcmp(argv[i], "-max_detect_point")){
		maximumDetectPointInBoxcar = atoi(argv[++i]);
	} else if (!strcmp(argv[i], "-output_file")){
		strncpy(outputFileName, argv[++i], FILENAME_BUFSIZE);
		if(outputFileName[FILENAME_BUFSIZE-1]!='\0'){
			fprintf(stderr,"Error : Too long output file name. maximum length = %d\n", FILENAME_BUFSIZE-1);
			exit(-1);
		}
	} else {
		fprintf(stderr,"Error : wrong argument\n");
        }*/
    }

    // Analyze signal on GPU
    printf("Calling GPU\n");
    do_analyze_on_gpu(signalLength);

    return 0;
}




	.text
	.file	"bench_fft.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$1048576, %r14d                 # imm = 0x100000
	cmpl	$2, %edi
	jl	.LBB0_5
# %bb.1:                                # %.lr.ph.preheader
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movl	$1, %r15d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movslq	%r15d, %r12
	movq	(%rbx,%r12,8), %rdi
	movl	$.L.str, %esi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB0_4
# %bb.3:                                #   in Loop: Header=BB0_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atoi
	movl	%eax, %r14d
	shll	$20, %r14d
.LBB0_4:                                #   in Loop: Header=BB0_2 Depth=1
	incl	%r15d
	cmpl	%ebp, %r15d
	jl	.LBB0_2
.LBB0_5:                                # %._crit_edge
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	%r14d, %edi
	callq	_Z17do_analyze_on_gpui
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"-length"
	.size	.L.str, 8

	.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	"Calling GPU"
	.size	.Lstr, 12

	.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
