/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 * 
 * Author: Shih-Hao Tseng <shtseng@caltech.edu>
 */
#include "helper_functions.cuh"

/*
double normpdf(const double x, const double mu, const double sigma){
	double power = (x-mu)/sigma;
	return exp(-power*power/2)*INV_SQRT_2PI/sigma;
}
*/

__global__
void
gen_normpdf(int n, const double base, const double step, double *vec_x)
{
  int i = blockIdx.x*blockDim.x + threadIdx.x;
  if (i < n) {
    double current_pos = base + i * step;
    vec_x[i] = normpdf(current_pos,1.0);
  }
}

__host__ __device__
double
normpdf(const double x, const double sigma){
    // mu = 0
	double power = x/sigma;
	return exp(-power*power/2)*INV_SQRT_2PI/sigma;
}

__global__
void
gen_normpdf(int n, const float base, const float step, float *vec_x)
{
  int i = blockIdx.x*blockDim.x + threadIdx.x;
  if (i < n) {
    float current_pos = base + i * step;
    vec_x[i] = normpdf(current_pos,1.0);
  }
}

__host__ __device__
float
normpdf(const float x, const float sigma){
    // mu = 0
	float power = x/sigma;
	return exp(-power*power/2)*INV_SQRT_2PI/sigma;
}
	.file	"tmpxft_003ad29d_00000000-6_helper_functions.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2012:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2012:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7normpdfdd
	.type	_Z7normpdfdd, @function
_Z7normpdfdd:
.LFB2008:
	.cfi_startproc
	endbr64
	divsd	%xmm1, %xmm0
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movsd	%xmm1, 8(%rsp)
	movaps	%xmm0, %xmm2
	xorps	.LC0(%rip), %xmm2
	mulsd	%xmm2, %xmm0
	mulsd	.LC1(%rip), %xmm0
	call	exp@PLT
	mulsd	.LC2(%rip), %xmm0
	movsd	8(%rsp), %xmm1
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	divsd	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE2008:
	.size	_Z7normpdfdd, .-_Z7normpdfdd
	.globl	_Z7normpdfff
	.type	_Z7normpdfff, @function
_Z7normpdfff:
.LFB2009:
	.cfi_startproc
	endbr64
	divss	%xmm1, %xmm0
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movss	%xmm1, 12(%rsp)
	movaps	%xmm0, %xmm2
	xorps	.LC3(%rip), %xmm2
	mulss	%xmm2, %xmm0
	mulss	.LC4(%rip), %xmm0
	call	expf@PLT
	movss	12(%rsp), %xmm1
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC2(%rip), %xmm0
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	ret
	.cfi_endproc
.LFE2009:
	.size	_Z7normpdfff, .-_Z7normpdfff
	.globl	_Z34__device_stub__Z11gen_normpdfiddPdiddPd
	.type	_Z34__device_stub__Z11gen_normpdfiddPdiddPd, @function
_Z34__device_stub__Z11gen_normpdfiddPdiddPd:
.LFB2034:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	48(%rsp), %rcx
	leaq	40(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	56(%rsp), %rdi
	leaq	68(%rsp), %rsi
	movsd	%xmm0, 16(%rsp)
	movsd	%xmm1, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L6
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z11gen_normpdfiddPd(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L6:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z34__device_stub__Z11gen_normpdfiddPdiddPd, .-_Z34__device_stub__Z11gen_normpdfiddPdiddPd
	.globl	_Z11gen_normpdfiddPd
	.type	_Z11gen_normpdfiddPd, @function
_Z11gen_normpdfiddPd:
.LFB2035:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z11gen_normpdfiddPdiddPd
	.cfi_endproc
.LFE2035:
	.size	_Z11gen_normpdfiddPd, .-_Z11gen_normpdfiddPd
	.globl	_Z34__device_stub__Z11gen_normpdfiffPfiffPf
	.type	_Z34__device_stub__Z11gen_normpdfiffPfiffPf, @function
_Z34__device_stub__Z11gen_normpdfiffPfiffPf:
.LFB2036:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	48(%rsp), %rcx
	leaq	40(%rsp), %rdx
	movq	%rsi, 8(%rsp)
	leaq	56(%rsp), %rdi
	leaq	68(%rsp), %rsi
	movss	%xmm0, 24(%rsp)
	movss	%xmm1, 20(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z11gen_normpdfiffPf(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L12:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z34__device_stub__Z11gen_normpdfiffPfiffPf, .-_Z34__device_stub__Z11gen_normpdfiffPfiffPf
	.globl	_Z11gen_normpdfiffPf
	.type	_Z11gen_normpdfiffPf, @function
_Z11gen_normpdfiffPf:
.LFB2037:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z11gen_normpdfiffPfiffPf
	.cfi_endproc
.LFE2037:
	.size	_Z11gen_normpdfiffPf, .-_Z11gen_normpdfiffPf
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"_Z11gen_normpdfiffPf"
.LC6:
	.string	"_Z11gen_normpdfiddPd"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2039:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z11gen_normpdfiffPf(%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	.LC6(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11gen_normpdfiddPd(%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
.LFE2039:
	.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.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1071644672
	.align 8
.LC2:
	.long	869545558
	.long	1071220805
	.section	.rodata.cst16
	.align 16
.LC3:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC4:
	.long	1056964608
	.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:

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 * 
 * Author: Shih-Hao Tseng <shtseng@caltech.edu>
 */
#ifndef HELPER_FUNCTIONS_CUH
#define HELPER_FUNCTIONS_CUH

#include <math.h>

#define PI            3.141592653589793238462643383279502884 // 197169399
#define INV_SQRT_2PI  0.398942280401433
#define TWO_SQRT_TWO  2.828427124746190

__global__
void gen_normpdf(int n, const double base, const double step, double *vec_x);

__host__ __device__
double normpdf(const double x, const double sigma);

__global__
void gen_normpdf(int n, const float base, const float step, float *vec_x);

__host__ __device__
float normpdf(const float x, const float sigma);

#endif // HELPER_FUNCTIONS_CUH
	.text
	.file	"helper_functions.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
