﻿#include "kernels.cuh"

// TESETER: Tarek
// Incremement times by drawn RVs
// double[] randomVariables: The random variables array on device
// double[] times: The array of times on device
// size_t s: the number of simulations
__global__ void updateTimesKernel(double* randomVariables, double* times, size_t s) {
	int gid = blockIdx.x * blockDim.x + threadIdx.x;
	if (gid < s) {
		times[gid] += randomVariables[gid];
	}
}

// TESTER: Tarek
// Multiply the elements of 1D array x1 by the last column of 2D array x2 in-place
// double[] x1: 1D Array which is multiplied and stores the output
// double[] x2: 2D Array which multiplies x1 in place
// int n: Offset for each row in order to grab the final entry
// int size: overall size of x1 and the number of rows in x2
__global__ void offsetMultiplicationKernel(double* x1, double* x2, size_t n, size_t size) {
	int gid = blockIdx.x * blockDim.x + threadIdx.x;

	// Ignore excess threads for a multi-block invocation
	if (gid < size) {
		x1[gid] *= x2[n + gid * n - 1];
	}
}

// TESTER: Vidur
// fired_reactions: list (length s) of the IDs of the reaction fired for each simulation
// sim_configs: matrix giving configuration for each simulation
// state_changes: State change vector for each reaction
__global__ void updateSimsKernel(int s, int n, int* fired_reactions, int* sim_configs, int* state_changes, bool* stability_flags) {
	// Add reactions vectors given by checkBins() to simulation configs
	int gid = blockIdx.y * n + blockIdx.x * blockDim.x + threadIdx.x;
	int rid = blockIdx.x * blockDim.x + threadIdx.x;

	// Only progress if within bounds and simulation has not reached stability
	if (rid < n && stability_flags[blockIdx.y] == false) {
		sim_configs[gid] = sim_configs[gid] + state_changes[(fired_reactions[blockIdx.y]) * n + rid];
	}
}

__global__ void updatePropsKernel(int s, int n, int m, int max_reactants, int* sim_configs, int* reactants, double* reaction_rates, double* propensities) {
	// Each block updates one propensity value
	int gid = blockIdx.y * m + blockIdx.x * blockDim.x + threadIdx.x;
	int rid = blockIdx.x * blockDim.x + threadIdx.x;

	if (rid < m) {
		int reaction_num = rid; // gid % m;
		int reactants_starting_idx = reaction_num * max_reactants * 2;
		double propensity = reaction_rates[reaction_num];
		for (int i = 0; i < max_reactants; i++) {
			int molecule_idx = i * 2 + reactants_starting_idx;
			int reactant_coef_idx = i * 2 + reactants_starting_idx + 1;
			int molecule_amt = sim_configs[blockIdx.y * n + reactants[molecule_idx]]; // [sim*n + reactants[molecule_idx]];
			for (int j = 0; j < reactants[reactant_coef_idx]; j++) {
				propensity *= (molecule_amt - j);
			}
		}
		propensities[gid] = propensity;
	}
}

// TESTER: Zhecheng
// helper function for exponential RVs
__global__ void calculateExponentialRVsKernel(double* randomVariables, double* propscan, size_t s, size_t m) {
	int gid = blockIdx.y * gridDim.x * blockDim.x + blockIdx.x * blockDim.x + threadIdx.x;
	if (gid < s) {
		randomVariables[gid] = -1 / propscan[m + gid * m - 1] * log(1 - randomVariables[gid]); // replace each uniform variable in first half of RV array with exponential counterpart
	}
}

// TESTER: Tarek
// Each row of blocks corresponds to a single simulation (gridDim.y = s)
// Each row has enough blocks to create enough threads to check every bin location at once (gridDim.x * blockDim.x >= m)
__global__ void checkBinsKernel(double* propensity_scan, double* uniformRVs, int* bins, size_t s, size_t m) {
	int tid = threadIdx.x;
	int rid = blockIdx.x * blockDim.x + tid;
	int gid = blockIdx.y * m + rid;

	// only threads with row index less than the number of bins will check so that excess threads in last block are excluded
	if (rid < m) {
		// Move uniform RV for simulation and the bins being checked to shared memory
		double urv = uniformRVs[blockIdx.y]; // make sure uniformRVs is pointer offset

		// TODO: Would be made more efficient by padding with 0 at the beginning of the scan, as this would eliminate the if statement
		// TODO: Each value is loaded twice, should be changed to avoid this
		double left_edge, right_edge;
		if (rid == 0) {
			left_edge = 0;
			right_edge = propensity_scan[gid];
		}
		else {
			left_edge = propensity_scan[gid - 1];
			right_edge = propensity_scan[gid];
		}

		// Last thread in row increases its right edge to include 1 in the boundary
		if (rid == m - 1) {
			right_edge += 1;
		}

		// Only one warp per row will diverge on this instruction
		if (left_edge <= urv && urv < right_edge) {
			bins[blockIdx.y] = rid;
		}
	}
}

__global__ void propCheckKernel(double* propscan, bool* stability_flags, int s, int m) {
	int tid = threadIdx.x;
	int gid = blockIdx.x * blockDim.x + tid;
	double prop_row_sum = propscan[m + tid * m - 1];

	// only set stability to true if the thread is within bounds and the simulation propensity sum is nonzero
	if (gid < s && prop_row_sum == 0) {
		stability_flags[gid] = true;
	}
}
	.file	"tmpxft_001fe509_00000000-6_kernels.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2010:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2010:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z40__device_stub__Z17updateTimesKernelPdS_mPdS_m
	.type	_Z40__device_stub__Z17updateTimesKernelPdS_mPdS_m, @function
_Z40__device_stub__Z17updateTimesKernelPdS_mPdS_m:
.LFB2032:
	.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
	movq	%rdx, 8(%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	8(%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	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z17updateTimesKernelPdS_m(%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
.L2:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z40__device_stub__Z17updateTimesKernelPdS_mPdS_m, .-_Z40__device_stub__Z17updateTimesKernelPdS_mPdS_m
	.globl	_Z17updateTimesKernelPdS_m
	.type	_Z17updateTimesKernelPdS_m, @function
_Z17updateTimesKernelPdS_m:
.LFB2033:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z17updateTimesKernelPdS_mPdS_m
	.cfi_endproc
.LFE2033:
	.size	_Z17updateTimesKernelPdS_m, .-_Z17updateTimesKernelPdS_m
	.globl	_Z50__device_stub__Z26offsetMultiplicationKernelPdS_mmPdS_mm
	.type	_Z50__device_stub__Z26offsetMultiplicationKernelPdS_mmPdS_mm, @function
_Z50__device_stub__Z26offsetMultiplicationKernelPdS_mmPdS_mm:
.LFB2034:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%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	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z26offsetMultiplicationKernelPdS_mm(%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
.L8:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z50__device_stub__Z26offsetMultiplicationKernelPdS_mmPdS_mm, .-_Z50__device_stub__Z26offsetMultiplicationKernelPdS_mmPdS_mm
	.globl	_Z26offsetMultiplicationKernelPdS_mm
	.type	_Z26offsetMultiplicationKernelPdS_mm, @function
_Z26offsetMultiplicationKernelPdS_mm:
.LFB2035:
	.cfi_startproc
	endbr64
	jmp	_Z50__device_stub__Z26offsetMultiplicationKernelPdS_mmPdS_mm
	.cfi_endproc
.LFE2035:
	.size	_Z26offsetMultiplicationKernelPdS_mm, .-_Z26offsetMultiplicationKernelPdS_mm
	.globl	_Z44__device_stub__Z16updateSimsKerneliiPiS_S_PbiiPiS_S_Pb
	.type	_Z44__device_stub__Z16updateSimsKerneliiPiS_S_PbiiPiS_S_Pb, @function
_Z44__device_stub__Z16updateSimsKerneliiPiS_S_PbiiPiS_S_Pb:
.LFB2036:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movl	%edi, 44(%rsp)
	leaq	72(%rsp), %rdi
	movl	%esi, 40(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 32(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 16(%rsp)
	movq	%r9, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z16updateSimsKerneliiPiS_S_Pb(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L13:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z44__device_stub__Z16updateSimsKerneliiPiS_S_PbiiPiS_S_Pb, .-_Z44__device_stub__Z16updateSimsKerneliiPiS_S_PbiiPiS_S_Pb
	.globl	_Z16updateSimsKerneliiPiS_S_Pb
	.type	_Z16updateSimsKerneliiPiS_S_Pb, @function
_Z16updateSimsKerneliiPiS_S_Pb:
.LFB2037:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z16updateSimsKerneliiPiS_S_PbiiPiS_S_Pb
	.cfi_endproc
.LFE2037:
	.size	_Z16updateSimsKerneliiPiS_S_Pb, .-_Z16updateSimsKerneliiPiS_S_Pb
	.globl	_Z48__device_stub__Z17updatePropsKerneliiiiPiS_PdS0_iiiiPiS_PdS0_
	.type	_Z48__device_stub__Z17updatePropsKerneliiiiPiS_PdS0_iiiiPiS_PdS0_, @function
_Z48__device_stub__Z17updatePropsKerneliiiiPiS_PdS0_iiiiPiS_PdS0_:
.LFB2038:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movq	208(%rsp), %rax
	movl	%edi, 44(%rsp)
	leaq	72(%rsp), %rdi
	movl	%esi, 40(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rax, 8(%rsp)
	movq	216(%rsp), %rax
	movl	%edx, 36(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 32(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 168(%rsp)
	movq	%rsp, %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	64(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z17updatePropsKerneliiiiPiS_PdS0_(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 224
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L18:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z48__device_stub__Z17updatePropsKerneliiiiPiS_PdS0_iiiiPiS_PdS0_, .-_Z48__device_stub__Z17updatePropsKerneliiiiPiS_PdS0_iiiiPiS_PdS0_
	.globl	_Z17updatePropsKerneliiiiPiS_PdS0_
	.type	_Z17updatePropsKerneliiiiPiS_PdS0_, @function
_Z17updatePropsKerneliiiiPiS_PdS0_:
.LFB2039:
	.cfi_startproc
	endbr64
	jmp	_Z48__device_stub__Z17updatePropsKerneliiiiPiS_PdS0_iiiiPiS_PdS0_
	.cfi_endproc
.LFE2039:
	.size	_Z17updatePropsKerneliiiiPiS_PdS0_, .-_Z17updatePropsKerneliiiiPiS_PdS0_
	.globl	_Z53__device_stub__Z29calculateExponentialRVsKernelPdS_mmPdS_mm
	.type	_Z53__device_stub__Z29calculateExponentialRVsKernelPdS_mmPdS_mm, @function
_Z53__device_stub__Z29calculateExponentialRVsKernelPdS_mmPdS_mm:
.LFB2040:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%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	.L23
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z29calculateExponentialRVsKernelPdS_mm(%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
.L23:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z53__device_stub__Z29calculateExponentialRVsKernelPdS_mmPdS_mm, .-_Z53__device_stub__Z29calculateExponentialRVsKernelPdS_mmPdS_mm
	.globl	_Z29calculateExponentialRVsKernelPdS_mm
	.type	_Z29calculateExponentialRVsKernelPdS_mm, @function
_Z29calculateExponentialRVsKernelPdS_mm:
.LFB2041:
	.cfi_startproc
	endbr64
	jmp	_Z53__device_stub__Z29calculateExponentialRVsKernelPdS_mmPdS_mm
	.cfi_endproc
.LFE2041:
	.size	_Z29calculateExponentialRVsKernelPdS_mm, .-_Z29calculateExponentialRVsKernelPdS_mm
	.globl	_Z41__device_stub__Z15checkBinsKernelPdS_PimmPdS_Pimm
	.type	_Z41__device_stub__Z15checkBinsKernelPdS_PimmPdS_Pimm, @function
_Z41__device_stub__Z15checkBinsKernelPdS_PimmPdS_Pimm:
.LFB2042:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z15checkBinsKernelPdS_Pimm(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L28:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2042:
	.size	_Z41__device_stub__Z15checkBinsKernelPdS_PimmPdS_Pimm, .-_Z41__device_stub__Z15checkBinsKernelPdS_PimmPdS_Pimm
	.globl	_Z15checkBinsKernelPdS_Pimm
	.type	_Z15checkBinsKernelPdS_Pimm, @function
_Z15checkBinsKernelPdS_Pimm:
.LFB2043:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z15checkBinsKernelPdS_PimmPdS_Pimm
	.cfi_endproc
.LFE2043:
	.size	_Z15checkBinsKernelPdS_Pimm, .-_Z15checkBinsKernelPdS_Pimm
	.globl	_Z39__device_stub__Z15propCheckKernelPdPbiiPdPbii
	.type	_Z39__device_stub__Z15propCheckKernelPdPbiiPdPbii, @function
_Z39__device_stub__Z15propCheckKernelPdPbiiPdPbii:
.LFB2044:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%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	.L33
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z15propCheckKernelPdPbii(%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
.L33:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2044:
	.size	_Z39__device_stub__Z15propCheckKernelPdPbiiPdPbii, .-_Z39__device_stub__Z15propCheckKernelPdPbiiPdPbii
	.globl	_Z15propCheckKernelPdPbii
	.type	_Z15propCheckKernelPdPbii, @function
_Z15propCheckKernelPdPbii:
.LFB2045:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z15propCheckKernelPdPbiiPdPbii
	.cfi_endproc
.LFE2045:
	.size	_Z15propCheckKernelPdPbii, .-_Z15propCheckKernelPdPbii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z15propCheckKernelPdPbii"
.LC1:
	.string	"_Z15checkBinsKernelPdS_Pimm"
.LC2:
	.string	"_Z29calculateExponentialRVsKernelPdS_mm"
.LC3:
	.string	"_Z17updatePropsKerneliiiiPiS_PdS0_"
.LC4:
	.string	"_Z16updateSimsKerneliiPiS_S_Pb"
.LC5:
	.string	"_Z26offsetMultiplicationKernelPdS_mm"
.LC6:
	.string	"_Z17updateTimesKernelPdS_m"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2047:
	.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	.LC0(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15propCheckKernelPdPbii(%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	.LC1(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15checkBinsKernelPdS_Pimm(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC2(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z29calculateExponentialRVsKernelPdS_mm(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z17updatePropsKerneliiiiPiS_PdS0_(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC4(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16updateSimsKerneliiPiS_S_Pb(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC5(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z26offsetMultiplicationKernelPdS_mm(%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
	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	_Z17updateTimesKernelPdS_m(%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
.LFE2047:
	.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:

﻿#ifndef KERNELS_H
#define KERNELS_H

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


__global__ void updateTimesKernel(double* randomVariables, double* times, size_t s);

__global__ void offsetMultiplicationKernel(double* x1, double* x2, size_t n, size_t size);

__global__ void updateSimsKernel(int s, int n, int* fired_reactions, int* sim_configs, int* state_changes, bool* stability_flags);

__global__ void updatePropsKernel(int s, int n, int m, int max_reactants, int* sim_configs, int* reactants, double* reaction_rates, double* propensities);

__global__ void calculateExponentialRVsKernel(double* randomVariables, double* propscan, size_t s, size_t m);

__global__ void checkBinsKernel(double* propensity_scan, double* uniformRVs, int* bins, size_t s, size_t m);

__global__ void propCheckKernel(double* propscan, bool* stability_flags, int s, int m);

#endif
	.text
	.file	"kernels.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
