/*
 * main.c
 *
 *  Created on: 06/12/2017
 *      Author: roussian
 */
#include "HostManager.cuh"
#include <stdio.h>

int main(int argc, char *argv[])
{
//	cudaSetDevice(0);
	//Argumentos
	if( argc < 5 ) {
		printf( "\n Parametros incorretos.\n Uso: <top_K>, <blockSize>, <BlockRoundNumber>, <iGlobalNumberRound>,"
				" <MergeNumberByBlock> <QueryType> onde: \n" );
		printf( "\t <top_K> - quantidade de documentos retornados (precisa ser multiplo do blockSize).\n" );
		printf( "\t <blockSize> - tamanho do bloco.\n" );
		printf( "\t <BlockRoundNumber> - numero de partes continuas que cada bloco ira processar.\n" );
		printf( "\t <GlobalNumberRound> - numero de partes nao continuas das listas invertidas que cada bloco ira processar.\n" );
		printf( "\t <MergeNumberByBlock> - numero de merge que cada bloco irá executar.\n" );
		printf( "\t <QueryType> (Optional) - [0] OR Query  --- [1] AND Query.\n" );
        return 0;
	}

	//Quantidade de postings em cada lista em função do tamanho do bloco que cada bloco irá processar
	int iTopk = atoi( argv[1] );
	int iBlockSize = atoi( argv[2] );
	int iBlockNumberRound = atoi( argv[3] );
	int iGlobalNumberRound = atoi( argv[4] );
	int iMergeNumberByBlock = atoi( argv[5] );
	int iQueryType = 0;

	if(argc == 7)
	   iQueryType = atoi( argv[6] );


//	#ifdef BATCH
//		queryBatchProcessingHost_Mix(iTopk, iBlockSize, iBlockNumberRound, iGlobalNumberRound, iMergeNumberByBlock, iQueryType);
//	#else
	querySingleProcessingHost(iTopk, iBlockSize, iBlockNumberRound, iGlobalNumberRound, iMergeNumberByBlock,  iQueryType, 1);
//	#endif

//	queryBatchProcessingHost_ByBlock(iTopk, iBlockSize, iBlockNumberRound,
//							 iGlobalNumberRound, iMergeNumberByBlock, iQueryType,500);


	exit(EXIT_SUCCESS);
}


	.file	"tmpxft_00211296_00000000-6_main.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	"\n Parametros incorretos.\n Uso: <top_K>, <blockSize>, <BlockRoundNumber>, <iGlobalNumberRound>, <MergeNumberByBlock> <QueryType> onde: \n"
.LC1:
	.string	"\t <top_K> - quantidade de documentos retornados (precisa ser multiplo do blockSize).\n"
.LC2:
	.string	"\t <blockSize> - tamanho do bloco.\n"
.LC3:
	.string	"\t <BlockRoundNumber> - numero de partes continuas que cada bloco ira processar.\n"
.LC4:
	.string	"\t <GlobalNumberRound> - numero de partes nao continuas das listas invertidas que cada bloco ira processar.\n"
.LC5:
	.string	"\t <MergeNumberByBlock> - numero de merge que cada bloco ir\303\241 executar.\n"
.LC6:
	.string	"\t <QueryType> (Optional) - [0] OR Query  --- [1] AND Query.\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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	cmpl	$4, %edi
	jle	.L7
	movl	%edi, %r15d
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movq	24(%rbx), %rdi
	movl	%eax, %r12d
	call	atoi@PLT
	movq	32(%rbx), %rdi
	movl	%eax, %r13d
	call	atoi@PLT
	movq	40(%rbx), %rdi
	movl	%eax, %r14d
	call	atoi@PLT
	xorl	%r9d, %r9d
	movl	%eax, %r8d
	cmpl	$7, %r15d
	jne	.L4
	movq	48(%rbx), %rdi
	movl	%eax, 12(%rsp)
	call	atoi@PLT
	movl	12(%rsp), %r8d
	movl	%eax, %r9d
.L4:
	pushq	%rax
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	%ebp, %edi
	movl	%r14d, %ecx
	movl	%r13d, %edx
	pushq	$1
	.cfi_def_cfa_offset 96
	movl	%r12d, %esi
	call	_Z25querySingleProcessingHostiiiiiii@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L7:
	.cfi_restore_state
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$24, %rsp
	.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:

/*
 * main.c
 *
 *  Created on: 06/12/2017
 *      Author: roussian
 */

#include <hip/hip_runtime.h>
#include "HostManager.cuh"
#include <stdio.h>

int main(int argc, char *argv[])
{
//	cudaSetDevice(0);
	//Argumentos
	if( argc < 5 ) {
		printf( "\n Parametros incorretos.\n Uso: <top_K>, <blockSize>, <BlockRoundNumber>, <iGlobalNumberRound>,"
				" <MergeNumberByBlock> <QueryType> onde: \n" );
		printf( "\t <top_K> - quantidade de documentos retornados (precisa ser multiplo do blockSize).\n" );
		printf( "\t <blockSize> - tamanho do bloco.\n" );
		printf( "\t <BlockRoundNumber> - numero de partes continuas que cada bloco ira processar.\n" );
		printf( "\t <GlobalNumberRound> - numero de partes nao continuas das listas invertidas que cada bloco ira processar.\n" );
		printf( "\t <MergeNumberByBlock> - numero de merge que cada bloco irá executar.\n" );
		printf( "\t <QueryType> (Optional) - [0] OR Query  --- [1] AND Query.\n" );
        return 0;
	}

	//Quantidade de postings em cada lista em função do tamanho do bloco que cada bloco irá processar
	int iTopk = atoi( argv[1] );
	int iBlockSize = atoi( argv[2] );
	int iBlockNumberRound = atoi( argv[3] );
	int iGlobalNumberRound = atoi( argv[4] );
	int iMergeNumberByBlock = atoi( argv[5] );
	int iQueryType = 0;

	if(argc == 7)
	   iQueryType = atoi( argv[6] );


//	#ifdef BATCH
//		queryBatchProcessingHost_Mix(iTopk, iBlockSize, iBlockNumberRound, iGlobalNumberRound, iMergeNumberByBlock, iQueryType);
//	#else
	querySingleProcessingHost(iTopk, iBlockSize, iBlockNumberRound, iGlobalNumberRound, iMergeNumberByBlock,  iQueryType, 1);
//	#endif

//	queryBatchProcessingHost_ByBlock(iTopk, iBlockSize, iBlockNumberRound,
//							 iGlobalNumberRound, iMergeNumberByBlock, iQueryType,500);


	exit(EXIT_SUCCESS);
}


	.text
	.file	"main.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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$4, %edi
	jg	.LBB0_1
# %bb.4:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$24, %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
.LBB0_1:
	.cfi_def_cfa_offset 80
	movq	%rsi, %r14
	movl	%edi, %r15d
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, 20(%rsp)                  # 4-byte Spill
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	24(%r14), %rdi
	callq	atoi
	movl	%eax, %r12d
	movq	32(%r14), %rdi
	callq	atoi
	movl	%eax, %r13d
	movq	40(%r14), %rdi
	callq	atoi
	movl	%eax, %ebx
	xorl	%r9d, %r9d
	cmpl	$7, %r15d
	jne	.LBB0_3
# %bb.2:
	movq	48(%r14), %rdi
	callq	atoi
	movl	%eax, %r9d
.LBB0_3:
	movl	$1, (%rsp)
	movl	20(%rsp), %edi                  # 4-byte Reload
	movl	%ebp, %esi
	movl	%r12d, %edx
	movl	%r13d, %ecx
	movl	%ebx, %r8d
	callq	_Z25querySingleProcessingHostiiiiiii
	xorl	%edi, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.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	"\n Parametros incorretos.\n Uso: <top_K>, <blockSize>, <BlockRoundNumber>, <iGlobalNumberRound>, <MergeNumberByBlock> <QueryType> onde: "
	.size	.Lstr, 135

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\t <top_K> - quantidade de documentos retornados (precisa ser multiplo do blockSize)."
	.size	.Lstr.1, 85

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"\t <blockSize> - tamanho do bloco."
	.size	.Lstr.2, 34

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"\t <BlockRoundNumber> - numero de partes continuas que cada bloco ira processar."
	.size	.Lstr.3, 80

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"\t <GlobalNumberRound> - numero de partes nao continuas das listas invertidas que cada bloco ira processar."
	.size	.Lstr.4, 107

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"\t <MergeNumberByBlock> - numero de merge que cada bloco ir\303\241 executar."
	.size	.Lstr.5, 71

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"\t <QueryType> (Optional) - [0] OR Query  --- [1] AND Query."
	.size	.Lstr.6, 60

	.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
