#include "simuParams.cuh"

__host__ SimuParams::SimuParams(){}

__host__ SimuParams::SimuParams(int _number_of_particles,
	int _particles_per_stream,
	real _TR,
	real _TE,
	real _timestep,
	int _n_mags_track,
	Vector3 m_initial,
	Vector3 _B0,
	int _res_x,
	int _res_y,
	real _FOVx,
	real _FOVy
	):seed_offset(0){

	number_of_particles = _number_of_particles;
	particles_per_stream = _particles_per_stream;
	if (number_of_particles != particles_per_stream)
		particle_concurrency = true;
	else
		particle_concurrency = false;
	num_streams = number_of_particles / particles_per_stream;
	TR = _TR;
	TE = _TE;
	measurements = 1;
	timestep = _timestep;
	n_mags_track = _n_mags_track;
	seed = time(NULL);
	mx_initial = m_initial.x;
	my_initial = m_initial.y;
	mz_initial = m_initial.z;
	time_end = timestep*steps;
	B0 = _B0;
	blocks = particles_per_stream / SIM_THREADS;
	res_x = _res_x;
	res_y = _res_y;
	FOVx = _FOVx;
	FOVy = _FOVy;

	//END PARAMETERS.
	steps = (TR / timestep) * res_x;
	printf("Number of steps in simulation: %d\n", steps);
	copyToDevice();
}

__host__ int SimuParams::getSeed(){
	return seed+(particles_per_stream*seed_offset++);
}

__host__ void SimuParams::copyToDevice(){
	cudaMalloc(&devPointer, sizeof(SimuParams));
	cudaMemcpy(devPointer, this, sizeof(SimuParams), cudaMemcpyHostToDevice);
}

	.file	"tmpxft_00319b51_00000000-6_simuParams.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3805:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3805:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN10SimuParamsC2Ev
	.type	_ZN10SimuParamsC2Ev, @function
_ZN10SimuParamsC2Ev:
.LFB3796:
	.cfi_startproc
	endbr64
	movq	$0x000000000, 128(%rdi)
	movq	$0x000000000, 136(%rdi)
	movq	$0x000000000, 144(%rdi)
	ret
	.cfi_endproc
.LFE3796:
	.size	_ZN10SimuParamsC2Ev, .-_ZN10SimuParamsC2Ev
	.globl	_ZN10SimuParamsC1Ev
	.set	_ZN10SimuParamsC1Ev,_ZN10SimuParamsC2Ev
	.align 2
	.globl	_ZN10SimuParams7getSeedEv
	.type	_ZN10SimuParams7getSeedEv, @function
_ZN10SimuParams7getSeedEv:
.LFB3801:
	.cfi_startproc
	endbr64
	movl	52(%rdi), %eax
	leal	1(%rax), %edx
	movl	%edx, 52(%rdi)
	imull	4(%rdi), %eax
	addl	32(%rdi), %eax
	ret
	.cfi_endproc
.LFE3801:
	.size	_ZN10SimuParams7getSeedEv, .-_ZN10SimuParams7getSeedEv
	.align 2
	.globl	_ZN10SimuParams12copyToDeviceEv
	.type	_ZN10SimuParams12copyToDeviceEv, @function
_ZN10SimuParams12copyToDeviceEv:
.LFB3802:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	$160, %esi
	movq	%rdi, %rbx
	leaq	152(%rdi), %rdi
	call	cudaMalloc@PLT
	movq	152(%rbx), %rdi
	movq	%rbx, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 8
	movl	$1, %ecx
	movl	$160, %edx
	jmp	cudaMemcpy@PLT
	.cfi_endproc
.LFE3802:
	.size	_ZN10SimuParams12copyToDeviceEv, .-_ZN10SimuParams12copyToDeviceEv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Number of steps in simulation: %d\n"
	.text
	.align 2
	.globl	_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.type	_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd, @function
_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd:
.LFB3799:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %eax
	movl	%edx, %esi
	xorl	%edx, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%r9d, %r12d
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	cmpl	%esi, %eax
	movl	%edx, 52(%rdi)
	setne	8(%rdi)
	cltd
	movl	%eax, (%rdi)
	idivl	%esi
	movl	%esi, 4(%rdi)
	movl	%ecx, 24(%rdi)
	movq	$0x000000000, 128(%rdi)
	movq	$0x000000000, 136(%rdi)
	movq	$0x000000000, 144(%rdi)
	movl	$1, 20(%rdi)
	movsd	%xmm0, 56(%rdi)
	movsd	%xmm1, 64(%rdi)
	movsd	%xmm2, 72(%rdi)
	movsd	%xmm3, 8(%rsp)
	movsd	%xmm4, (%rsp)
	movl	%eax, 12(%rdi)
	xorl	%edi, %edi
	call	time@PLT
	movsd	48(%rsp), %xmm0
	movsd	72(%rbx), %xmm1
	movl	%ebp, 44(%rbx)
	movq	%rax, 32(%rbx)
	movq	88(%rsp), %rax
	movl	$128, %ecx
	movl	$2, %edi
	movsd	%xmm0, 80(%rbx)
	movups	72(%rsp), %xmm5
	movsd	(%rsp), %xmm4
	leaq	.LC1(%rip), %rsi
	movsd	56(%rsp), %xmm0
	movsd	8(%rsp), %xmm3
	movl	%r12d, 48(%rbx)
	movq	%rax, 144(%rbx)
	movl	4(%rbx), %eax
	movsd	%xmm0, 88(%rbx)
	movsd	64(%rsp), %xmm0
	cltd
	movups	%xmm5, 128(%rbx)
	idivl	%ecx
	movsd	%xmm0, 96(%rbx)
	movsd	%xmm3, 112(%rbx)
	movsd	%xmm4, 120(%rbx)
	cvtsi2sdl	16(%rbx), %xmm0
	mulsd	%xmm1, %xmm0
	movsd	%xmm0, 104(%rbx)
	movsd	56(%rbx), %xmm0
	divsd	%xmm1, %xmm0
	cvtsi2sdl	%ebp, %xmm1
	movl	%eax, 40(%rbx)
	xorl	%eax, %eax
	mulsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %edx
	movl	%edx, 16(%rbx)
	call	__printf_chk@PLT
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_ZN10SimuParams12copyToDeviceEv
	.cfi_endproc
.LFE3799:
	.size	_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd, .-_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.globl	_ZN10SimuParamsC1Eiidddi7Vector3S0_iidd
	.set	_ZN10SimuParamsC1Eiidddi7Vector3S0_iidd,_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3828:
	.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
.LFE3828:
	.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:


#include <hip/hip_runtime.h>
#include "simuParams.cuh"

__host__ SimuParams::SimuParams(){}

__host__ SimuParams::SimuParams(int _number_of_particles,
	int _particles_per_stream,
	real _TR,
	real _TE,
	real _timestep,
	int _n_mags_track,
	Vector3 m_initial,
	Vector3 _B0,
	int _res_x,
	int _res_y,
	real _FOVx,
	real _FOVy
	):seed_offset(0){

	number_of_particles = _number_of_particles;
	particles_per_stream = _particles_per_stream;
	if (number_of_particles != particles_per_stream)
		particle_concurrency = true;
	else
		particle_concurrency = false;
	num_streams = number_of_particles / particles_per_stream;
	TR = _TR;
	TE = _TE;
	measurements = 1;
	timestep = _timestep;
	n_mags_track = _n_mags_track;
	seed = time(NULL);
	mx_initial = m_initial.x;
	my_initial = m_initial.y;
	mz_initial = m_initial.z;
	time_end = timestep*steps;
	B0 = _B0;
	blocks = particles_per_stream / SIM_THREADS;
	res_x = _res_x;
	res_y = _res_y;
	FOVx = _FOVx;
	FOVy = _FOVy;

	//END PARAMETERS.
	steps = (TR / timestep) * res_x;
	printf("Number of steps in simulation: %d\n", steps);
	copyToDevice();
}

__host__ int SimuParams::getSeed(){
	return seed+(particles_per_stream*seed_offset++);
}

__host__ void SimuParams::copyToDevice(){
	hipMalloc(&devPointer, sizeof(SimuParams));
	hipMemcpy(devPointer, this, sizeof(SimuParams), hipMemcpyHostToDevice);
}

	.text
	.file	"simuParams.hip"
	.globl	_ZN10SimuParamsC2Ev             # -- Begin function _ZN10SimuParamsC2Ev
	.p2align	1, 0x90
	.type	_ZN10SimuParamsC2Ev,@function
_ZN10SimuParamsC2Ev:                    # @_ZN10SimuParamsC2Ev
	.cfi_startproc
# %bb.0:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 128(%rdi)
	movq	$0, 144(%rdi)
	retq
.Lfunc_end0:
	.size	_ZN10SimuParamsC2Ev, .Lfunc_end0-_ZN10SimuParamsC2Ev
	.cfi_endproc
                                        # -- End function
	.globl	_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd # -- Begin function _ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.p2align	1, 0x90
	.type	_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd,@function
_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd: # @_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movsd	%xmm4, 8(%rsp)                  # 8-byte Spill
	movsd	%xmm3, (%rsp)                   # 8-byte Spill
	movl	%r9d, %r14d
	movl	%r8d, %ebp
	movl	%edx, %r8d
	movl	%esi, %eax
	movq	%rdi, %rbx
	movl	$0, 52(%rdi)
	xorps	%xmm3, %xmm3
	movups	%xmm3, 128(%rdi)
	movq	$0, 144(%rdi)
	movl	%esi, (%rdi)
	movl	%edx, 4(%rdi)
	cmpl	%edx, %esi
	setne	8(%rdi)
	cltd
	idivl	%r8d
	movl	%eax, 12(%rdi)
	movsd	%xmm0, 56(%rdi)
	movsd	%xmm1, 64(%rdi)
	movl	$1, 20(%rdi)
	movsd	%xmm2, 72(%rdi)
	movl	%ecx, 24(%rdi)
	xorl	%edi, %edi
	callq	time
	movq	%rax, 32(%rbx)
	movsd	48(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movsd	%xmm0, 80(%rbx)
	movsd	56(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movsd	%xmm0, 88(%rbx)
	movsd	64(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movsd	%xmm0, 96(%rbx)
	movsd	72(%rbx), %xmm0                 # xmm0 = mem[0],zero
	xorps	%xmm1, %xmm1
	cvtsi2sdl	16(%rbx), %xmm1
	mulsd	%xmm0, %xmm1
	movsd	%xmm1, 104(%rbx)
	movq	88(%rsp), %rax
	movq	%rax, 144(%rbx)
	movups	72(%rsp), %xmm1
	movups	%xmm1, 128(%rbx)
	movl	4(%rbx), %eax
	leal	127(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$7, %ecx
	movl	%ecx, 40(%rbx)
	movl	%ebp, 44(%rbx)
	movl	%r14d, 48(%rbx)
	movsd	(%rsp), %xmm1                   # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movsd	%xmm1, 112(%rbx)
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movsd	%xmm1, 120(%rbx)
	movsd	56(%rbx), %xmm1                 # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	mulsd	%xmm1, %xmm0
	cvttsd2si	%xmm0, %esi
	movl	%esi, 16(%rbx)
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	152(%rbx), %rdi
	movl	$160, %esi
	callq	hipMalloc
	movq	152(%rbx), %rdi
	movl	$160, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	hipMemcpy                       # TAILCALL
.Lfunc_end1:
	.size	_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd, .Lfunc_end1-_ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.cfi_endproc
                                        # -- End function
	.globl	_ZN10SimuParams12copyToDeviceEv # -- Begin function _ZN10SimuParams12copyToDeviceEv
	.p2align	1, 0x90
	.type	_ZN10SimuParams12copyToDeviceEv,@function
_ZN10SimuParams12copyToDeviceEv:        # @_ZN10SimuParams12copyToDeviceEv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	addq	$152, %rdi
	movl	$160, %esi
	callq	hipMalloc
	movq	152(%rbx), %rdi
	movl	$160, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	hipMemcpy                       # TAILCALL
.Lfunc_end2:
	.size	_ZN10SimuParams12copyToDeviceEv, .Lfunc_end2-_ZN10SimuParams12copyToDeviceEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN10SimuParams7getSeedEv       # -- Begin function _ZN10SimuParams7getSeedEv
	.p2align	1, 0x90
	.type	_ZN10SimuParams7getSeedEv,@function
_ZN10SimuParams7getSeedEv:              # @_ZN10SimuParams7getSeedEv
	.cfi_startproc
# %bb.0:
	movl	52(%rdi), %eax
	leal	1(%rax), %ecx
	movl	%ecx, 52(%rdi)
	imull	4(%rdi), %eax
	addl	32(%rdi), %eax
                                        # kill: def $eax killed $eax killed $rax
	retq
.Lfunc_end3:
	.size	_ZN10SimuParams7getSeedEv, .Lfunc_end3-_ZN10SimuParams7getSeedEv
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Number of steps in simulation: %d\n"
	.size	.L.str, 35

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

	.globl	_ZN10SimuParamsC1Ev
	.type	_ZN10SimuParamsC1Ev,@function
.set _ZN10SimuParamsC1Ev, _ZN10SimuParamsC2Ev
	.globl	_ZN10SimuParamsC1Eiidddi7Vector3S0_iidd
	.type	_ZN10SimuParamsC1Eiidddi7Vector3S0_iidd,@function
.set _ZN10SimuParamsC1Eiidddi7Vector3S0_iidd, _ZN10SimuParamsC2Eiidddi7Vector3S0_iidd
	.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
