#include "cuda_MP5.cuh"

////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int cuda_MP5(int argc, char* argv[])
{
  int num_elements = NUM_ELEMENTS;
  int errorM = 0;
  const unsigned int array_mem_size = sizeof(float) * num_elements;

  // allocate host memory to store the input data
  float* h_data = (float*)malloc(array_mem_size);

  // * No arguments: Randomly generate input data and compare against the 
  //   host's result.
  // * One argument: Read the input data array from the given file.
  switch (argc - 1)
  {
	case 1:  // One Argument
	  // errorM = ReadFile(h_data, argv[1]);
	  errorM = ReadFileData_MP5(h_data, argv[1]);
	  if (errorM != 1)
	  {
		printf("Error reading input file!\n");
		exit(1);
	  }
	  break;

	default:  
	  // No Arguments or one argument
	  // initialize the input data on the host to be integer values
	  // between 0 and 1000
	  for (unsigned int i = 0; i < num_elements; ++i)
	  {
		h_data[i] = floorf(1000 * (rand() / (float)RAND_MAX));
	  }
	  break;
  }

  // compute reference solution
  float reference = 0.0f;
  computeGold_MP5(&reference, h_data, num_elements);

  // **===-------- Modify the body of this function -----------===**
  float result = computeOnDevice_MP5(h_data, num_elements);
  // **===-----------------------------------------------------------===**

  // We can use an epsilon of 0 since values are integral and in a range 
  // that can be exactly represented
  float epsilon = 0.0f;
  unsigned int result_regtest = (abs(result - reference) <= epsilon);
  printf("Test %s\n", (1 == result_regtest) ? "PASSED" : "FAILED");
  printf("device: %f  host: %f\n", result, reference);
  // cleanup memory
  free(h_data);

  return 0;
}

int ReadFileData_MP5(float* M, char* file_name)
{
  unsigned int data_read = NUM_ELEMENTS;
  //  cutReadFilef(file_name, &(M->elements), &data_read, true);
  ifstream iFile(file_name);
  unsigned i = 0;
  if (iFile) {
	float data;
	while (iFile >> data) {
	  M[i++] = data;
	}
  }
  return (i != data_read);
}

////////////////////////////////////////////////////////////////////////////////
//! Compute reference data set
//! Each element is the sum of the elements before it in the array.
//! @param reference  reference data, computed but preallocated
//! @param idata      input data as provided to device
//! @param len        number of elements in reference / idata
////////////////////////////////////////////////////////////////////////////////
void computeGold_MP5(float* reference, float* idata, const unsigned int len)
{
  reference[0] = 0;
  double total_sum = 0;
  unsigned int i;
  for (i = 0; i < len; ++i)
  {
	total_sum += idata[i];
  }
  *reference = total_sum;
}

// **===----------------- Modify this function ---------------------===**
// Take h_data from host, copies it to device, setup grid and thread 
// dimensions, excutes kernel function, and copy result of scan back
// to h_data.
// Note: float* h_data is both the input and the output of this function.
float computeOnDevice_MP5(float* h_data, int num_elements)
{

  float* d_data;
  cudaMalloc((void**)&d_data, sizeof(float)*num_elements);
  cudaMemcpy(d_data, h_data, sizeof(float)*num_elements,
	cudaMemcpyHostToDevice);

  int num_block = ceil((float)num_elements / (2 * RD_BLOCK_SIZE));
  float* d_block_sum;
  cudaMalloc((void**)&d_block_sum, sizeof(float)*num_block);

  // placeholder
  dim3 dimGrid, dimBlock;
  
  dimGrid.x = num_block;
  dimGrid.y = dimGrid.z = 1;
  dimBlock.x = RD_BLOCK_SIZE;
  dimBlock.y = dimBlock.z = 1;

  reduction_kernel_MP5 << <dimGrid, dimBlock >> > (d_data, d_block_sum, num_elements);

  cudaDeviceSynchronize();

  float* h_block_sum = (float*)malloc(sizeof(float)*num_block);
  cudaMemcpy(h_block_sum, d_block_sum, sizeof(float)*num_block,
	cudaMemcpyDeviceToHost);

  cudaMemcpy(h_data, d_data, sizeof(float)*num_elements,
	cudaMemcpyDeviceToHost);

  cudaFree(d_block_sum);
  cudaFree(d_data);

  float sum = 0;
  for (int i = 0; i < num_block; i++) {
	sum += h_block_sum[i];
//	cout << i << " " << h_block_sum[i] << endl;
//	cout << (i + 1) * 128 - 1 << " " << h_data[(i + 1) * 128 - 1] << endl;
  }

  return sum;
//  return h_data[num_elements-1];
}

// **===----------------- MP4.1 - Modify this function --------------------===**
//! @param g_idata  input data in global memory
//                  result is expected in index 0 of g_idata
//! @param n        input number of elements to scan from input data
// **===------------------------------------------------------------------===**
__global__ void reduction_kernel_MP5(float *g_data, float *blocksum, int n)
{
  __shared__ float ds_data[2 * RD_BLOCK_SIZE];
  unsigned int tx = threadIdx.x;
  unsigned int id = threadIdx.x + blockIdx.x*blockDim.x;
  if (2 * id + 1 < n) {
	ds_data[2 * tx] = g_data[2 * id];
	ds_data[2 * tx + 1] = g_data[2 * id + 1];
  }

  for (unsigned int stride = 1; stride <= blockDim.x; stride *= 2) {
	__syncthreads();
	unsigned int index = (threadIdx.x + 1) * 2 * stride - 1;
	if (index < 2 * blockDim.x)
	  ds_data[index] += ds_data[index - stride];
  }
  __syncthreads();

  if (threadIdx.x == 0)
	blocksum[blockIdx.x] = ds_data[2 * blockDim.x - 1];


  if (2 * id + 1 < n) {
	g_data[2 * id] = ds_data[2 * tx];
	g_data[2 * id + 1] = ds_data[2 * tx + 1];
  }
  
}
	.file	"tmpxft_0028c82b_00000000-6_cuda_MP5.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3772:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3772:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15computeGold_MP5PfS_j
	.type	_Z15computeGold_MP5PfS_j, @function
_Z15computeGold_MP5PfS_j:
.LFB3768:
	.cfi_startproc
	endbr64
	movl	$0x00000000, (%rdi)
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L3:
	cmpl	%edx, %eax
	jnb	.L6
	cvtss2sd	(%rsi,%rax,4), %xmm1
	incq	%rax
	addsd	%xmm1, %xmm0
	jmp	.L3
.L6:
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rdi)
	ret
	.cfi_endproc
.LFE3768:
	.size	_Z15computeGold_MP5PfS_j, .-_Z15computeGold_MP5PfS_j
	.globl	_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i
	.type	_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i, @function
_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i:
.LFB3794:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L7
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z20reduction_kernel_MP5PfS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L7:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3794:
	.size	_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i, .-_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i
	.globl	_Z20reduction_kernel_MP5PfS_i
	.type	_Z20reduction_kernel_MP5PfS_i, @function
_Z20reduction_kernel_MP5PfS_i:
.LFB3795:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i
	.cfi_endproc
.LFE3795:
	.size	_Z20reduction_kernel_MP5PfS_i, .-_Z20reduction_kernel_MP5PfS_i
	.globl	_Z19computeOnDevice_MP5Pfi
	.type	_Z19computeOnDevice_MP5Pfi, @function
_Z19computeOnDevice_MP5Pfi:
.LFB3769:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movslq	%esi, %rbx
	movq	%rbx, %r12
	salq	$2, %rbx
	movq	%rbx, %rsi
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	cvtsi2ssl	%r12d, %xmm0
	mulss	.LC2(%rip), %xmm0
	call	ceilf@PLT
	leaq	8(%rsp), %rdi
	cvttss2sil	%xmm0, %r13d
	movslq	%r13d, %rbp
	salq	$2, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%r13d, 16(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	$67108865, %edx
	movl	$1, %ecx
	movq	%rax, 20(%rsp)
	movq	16(%rsp), %rdi
	salq	$6, %rdx
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%r12d, %edx
	call	_Z43__device_stub__Z20reduction_kernel_MP5PfS_iPfS_i
.L13:
	call	cudaDeviceSynchronize@PLT
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%rax, %rdi
	movq	%rax, %r12
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%r14, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%edx, %edx
	xorps	%xmm0, %xmm0
.L14:
	cmpl	%edx, %r13d
	jle	.L18
	addss	(%r12,%rdx,4), %xmm0
	incq	%rdx
	jmp	.L14
.L18:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3769:
	.size	_Z19computeOnDevice_MP5Pfi, .-_Z19computeOnDevice_MP5Pfi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"_Z20reduction_kernel_MP5PfS_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3797:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 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
	leaq	_Z20reduction_kernel_MP5PfS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3797:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.text
	.globl	_Z16ReadFileData_MP5PfPc
	.type	_Z16ReadFileData_MP5PfPc, @function
_Z16ReadFileData_MP5PfPc:
.LFB3767:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3767
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$8, %edx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$552, %rsp
	.cfi_def_cfa_offset 592
	movq	%fs:40, %rax
	movq	%rax, 536(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbx
	leaq	12(%rsp), %r13
	movq	%rbx, %rdi
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
	testb	$5, 304(%rsp)
	jne	.L23
.L22:
	movq	%r13, %rsi
	movq	%rbx, %rdi
.LEHB1:
	call	_ZNSi10_M_extractIfEERSiRT_@PLT
.LEHE1:
	movq	(%rax), %rdx
	movq	-24(%rdx), %rdx
	testb	$5, 32(%rax,%rdx)
	jne	.L23
	movss	12(%rsp), %xmm0
	movl	%ebp, %eax
	incl	%ebp
	movss	%xmm0, (%r12,%rax,4)
	jmp	.L22
.L23:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	xorl	%eax, %eax
	cmpl	$512, %ebp
	setne	%al
	movq	536(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L27
	jmp	.L31
.L29:
	endbr64
	movq	%rax, %rbp
.L25:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	536(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	movq	%rbp, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L31:
	call	__stack_chk_fail@PLT
.L27:
	addq	$552, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3767:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3767:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3767-.LLSDACSB3767
.LLSDACSB3767:
	.uleb128 .LEHB0-.LFB3767
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3767
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L29-.LFB3767
	.uleb128 0
	.uleb128 .LEHB2-.LFB3767
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3767:
	.text
	.size	_Z16ReadFileData_MP5PfPc, .-_Z16ReadFileData_MP5PfPc
	.section	.rodata.str1.1
.LC4:
	.string	"PASSED"
.LC5:
	.string	"FAILED"
.LC6:
	.string	"Error reading input file!\n"
.LC10:
	.string	"Test %s\n"
.LC11:
	.string	"device: %f  host: %f\n"
	.text
	.globl	_Z8cuda_MP5iPPc
	.type	_Z8cuda_MP5iPPc, @function
_Z8cuda_MP5iPPc:
.LFB3766:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edi, %r13d
	movl	$2048, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movq	%rax, %rbx
	cmpl	$2, %r13d
	jne	.L35
	movq	8(%r12), %rsi
	movq	%rax, %rdi
	call	_Z16ReadFileData_MP5PfPc
	decl	%eax
	je	.L36
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L35:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC7(%rip), %xmm0
	mulss	.LC8(%rip), %xmm0
	call	floorf@PLT
	movss	%xmm0, (%rbx,%rbp,4)
	incq	%rbp
	cmpq	$512, %rbp
	jne	.L35
.L36:
	movl	$512, %edx
	leaq	20(%rsp), %rdi
	movq	%rbx, %rsi
	call	_Z15computeGold_MP5PfS_j
	movl	$512, %esi
	movq	%rbx, %rdi
	call	_Z19computeOnDevice_MP5Pfi
	movss	20(%rsp), %xmm1
	xorps	%xmm3, %xmm3
	leaq	.LC5(%rip), %rax
	movaps	%xmm0, %xmm2
	movl	$2, %edi
	leaq	.LC4(%rip), %rdx
	movss	%xmm0, 12(%rsp)
	subss	%xmm1, %xmm2
	andps	.LC9(%rip), %xmm2
	leaq	.LC10(%rip), %rsi
	movss	%xmm1, 8(%rsp)
	comiss	%xmm2, %xmm3
	cmovb	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm0
	movb	$2, %al
	movss	8(%rsp), %xmm1
	movl	$2, %edi
	leaq	.LC11(%rip), %rsi
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z8cuda_MP5iPPc, .-_Z8cuda_MP5iPPc
	.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
.LC2:
	.long	1006632960
	.align 4
.LC7:
	.long	805306368
	.align 4
.LC8:
	.long	1148846080
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC9:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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:

#ifndef CUDA_MP5_CUH
#define CUDA_MP5_CUH

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <fstream>

#include <hip/hip_runtime.h>
#include <hip/device_functions.h>



using namespace std;

#define NUM_ELEMENTS 512
#define RD_BLOCK_SIZE 64

int cuda_MP5(int argc, char* argv[]);
int ReadFileData_MP5(float* M, char* file_name);
void computeGold_MP5(float* reference, float* idata, const unsigned int len);
float computeOnDevice_MP5(float* h_data, int num_elements);
__global__ void reduction_kernel_MP5(float *g_data, float *blocksum, int n);

#endif // !CUDA_MP5_CUH
	.text
	.file	"cuda_MP5.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.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
