﻿#include<cuda.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <iostream>
#include <sstream>

__global__ void fillArray(double* array, int size, double value)
{ 

	unsigned int i=threadIdx.x+blockIdx.x*blockDim.x;
	
	if(i<size){		
		array[i]=value;
	}
}


__global__ void applyDirichlet(double* load, double* csr_matrix, int* csr_col_device,int* csrRowPtr,int *isboundaryNode, unsigned int entries, int elementsX, int elementsY, int degree, double boundaryValue)
{ 

	unsigned int i=threadIdx.x+blockIdx.x*blockDim.x;
	int row=0;
	int col;
	int ucindex;
	unsigned long int pointCount=(degree+1+(elementsX-1)*degree)*(degree+1+(elementsY-1)*degree)-1;
	double sum=0;
	double bound[4];
	bound[0]=0;
	bound[1]=0;
	bound[2]=0;
	bound[3]=0;
	
	if(i<pointCount+1){
		int start=csrRowPtr[i];
		int end =csrRowPtr[i+1];

		for(int j=start;j<end;j++){	
			if(isboundaryNode[csr_col_device[j]]!=0){									
				sum+=bound[isboundaryNode[csr_col_device[j]]-1]*csr_matrix[j];
			}				
		}
		load[i]-=sum;
	}
	__syncthreads();

	if(i<entries){		
		col=csr_col_device[i];
		while((row<=pointCount) && (csrRowPtr[row]<=i)){		
			row++;
		}
		row--;		
			
		if((isboundaryNode[col]!=0)||(isboundaryNode[row]!=0)){			
			if(col!=row){				
				csr_matrix[i]=0;
			}
		}
		__syncthreads();		

		if((isboundaryNode[col]!=0)||(isboundaryNode[row]!=0)){
			if(col==row){		
				csr_matrix[i]=1;					
			}			
		}	
	}		
}


__global__ void vectorDirichlet(double* load, double* csr_matrix, int* csr_col_device,int* csrRowPtr,int *isboundaryNode,unsigned int entries, int elementsX, int elementsY, int degree, double boundaryValue)
{ 

	unsigned int i=threadIdx.x+blockIdx.x*blockDim.x;
	int row=0;
	int col;
	int ucindex;
	unsigned long int pointCount=(degree+1+(elementsX-1)*degree)*(degree+1+(elementsY-1)*degree)-1;
	double sum=0;
	double bound[4];
	bound[0]=0;
	bound[1]=0;
	bound[2]=0;
	bound[3]=0;
		
	if(i<entries){		
		col=csr_col_device[i];
		
		while((row<=pointCount) && (csrRowPtr[row]<=i)){		
			row++;
		}
		row--;
			
		if((isboundaryNode[col]!=0)||(isboundaryNode[row]!=0)){
				if(col==row){					
					load[col]=bound[isboundaryNode[col]-1];			
				}			
		}
	}		
}


__global__ void BernBinomCoeff(double *M, int n)
{

	unsigned  int i= threadIdx.x;
	unsigned  int j= threadIdx.y;

	unsigned int top_0=1;
	unsigned int top_1=1;
	unsigned int bottom=1;
	unsigned int n_save=n;
	//guarantees that every step in the solution is smaller than the final solution thus avoiding overflow
	for (int d=1; d <= i; d++){
		top_0*= n_save--;
        top_0 /= d;
    }
	n_save=n;
	
	for (int d=1; d <= j; d++)	{
		top_1*= n_save--;
        top_1 /= d;
    }
	n_save=2*n;

	for (int d=1; d <= i+j; d++)	{
		bottom*= n_save--;
        bottom /= d;
    }
		
	M[i+j*(n+1)]=(double)(top_0*top_1)/bottom;	
}

__global__ void ass_A_exact(double a, double b,int *coo_row_device,int *coo_col_device, double*coo_value, int degree,long long int* index, int *elements, double *M, double *M_m, int elementsX, int elementsY)
{

	unsigned long int pointCount=(degree+1+(elementsX-1)*degree)*(degree+1+(elementsY-1)*degree);
	double *B;
	B=(double*)malloc((degree+1)*(degree+1)*(degree+1)*(degree+1)*sizeof(double));
	unsigned int i_glob;
	unsigned int j_glob;
	unsigned int shift;
	double sum=0;
	unsigned int element=threadIdx.x+blockIdx.x*blockDim.x;
	int n=degree;

	if(element<elementsX*elementsY){
		for (int i=0; i<=n;i++)
			for(int j=0; j<=n;j++)
				for (int k=0; k<=n;k++)
					for(int l=0; l<=n;l++){
						sum=0;
						shift=i+j*(degree+1)+(degree+1)*(degree+1)*(k+l*(degree+1));
					
						if((i<n) && (k<n))
							sum+=M_m[i+n*k];					
						if((i>0) && (i-1<n) && (k<n))
							sum-=M_m[i-1+n*k];
						if((k>0)&& (i<n) && (k-1<n))
							sum-=M_m[i+n*(k-1)];
						if((k>0) && (i>0) && (i-1<n)&& (k-1<n))
							sum+=M_m[i-1+n*(k-1)];					
					
						B[shift]=M[j+l*(n+1)]*b/a*sum;
						sum=0;

						if((j<n) && (l<n))
							sum=M_m[j+n*l];				
						if((j>0) && (j-1<n) && (l<n))
							sum-=M_m[j-1+n*l];
						if((l>0)&& (j<n) && (l-1<n))
							sum-=M_m[j+n*(l-1)];
						if((l>0) && (j>0) && (j-1<n)&& (l-1<n))
							sum+=M_m[j-1+n*(l-1)];				
				
						B[shift]+=M[i+k*(n+1)]*a/b*(sum);			
						B[shift]*=(double)(n*n)/(4*n*n-1);					
						B[shift]*=(double)(n*n)/(4*n*n-1);						
					}

		for(int i=0; i<(n+1)*(n+1);i++){
			for(int j=0; j<(n+1)*(n+1);j++){
				i_glob=elements[element*(n+1)*(n+1)+i];
				j_glob=elements[element*(n+1)*(n+1)+j];
					
				coo_row_device[element*(n+1)*(n+1)*(n+1)*(n+1)+i+j*(n+1)*(n+1)]=i_glob;
				coo_col_device[element*(n+1)*(n+1)*(n+1)*(n+1)+i+j*(n+1)*(n+1)]=j_glob;
						
				index[element*(n+1)*(n+1)*(n+1)*(n+1)+i+j*(n+1)*(n+1)]=i_glob*pointCount+j_glob;
				coo_value[element*(n+1)*(n+1)*(n+1)*(n+1)+i+j*(n+1)*(n+1)]=B[i+j*(n+1)*(n+1)];
			}
		}

	}	
	free(B);	
}

__global__ void split(long long int* index, int*cols, int*rows,unsigned long int pointCount,unsigned long int length)
{

	unsigned int i=threadIdx.x+blockIdx.x*blockDim.x;
	if(i<length){
		rows[i]=index[i]/pointCount;
		cols[i]=index[i]%pointCount;		
	}	
}

__global__ void loadVector(double* loadList, int* index,int *elements, double a, double b, int degree, double func, int ElementCount)
{

	int i_glob;
	int element=threadIdx.x+blockIdx.x*blockDim.x;

	if(element<ElementCount){	
		for(int i=0;i<(degree+1)*(degree+1);i++){	
			loadList[element*(degree+1)*(degree+1)+i]=func*a*b/((degree+1)*(degree+1));	
			index[element*(degree+1)*(degree+1)+i]=elements[element*(degree+1)*(degree+1)+i];
		}
	}
}
	.file	"tmpxft_002180a5_00000000-6_kernel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3695:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3695:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z30__device_stub__Z9fillArrayPdidPdid
	.type	_Z30__device_stub__Z9fillArrayPdidPdid, @function
_Z30__device_stub__Z9fillArrayPdidPdid:
.LFB3717:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	32(%rsp), %rdx
	movl	%esi, 20(%rsp)
	leaq	48(%rsp), %rdi
	leaq	60(%rsp), %rsi
	movsd	%xmm0, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	20(%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	_Z9fillArrayPdid(%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
.LFE3717:
	.size	_Z30__device_stub__Z9fillArrayPdidPdid, .-_Z30__device_stub__Z9fillArrayPdidPdid
	.globl	_Z9fillArrayPdid
	.type	_Z9fillArrayPdid, @function
_Z9fillArrayPdid:
.LFB3718:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z9fillArrayPdidPdid
	.cfi_endproc
.LFE3718:
	.size	_Z9fillArrayPdid, .-_Z9fillArrayPdid
	.globl	_Z49__device_stub__Z14applyDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid
	.type	_Z49__device_stub__Z14applyDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid, @function
_Z49__device_stub__Z14applyDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid:
.LFB3719:
	.cfi_startproc
	endbr64
	subq	$232, %rsp
	.cfi_def_cfa_offset 240
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movl	%r9d, 20(%rsp)
	movsd	%xmm0, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	240(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	248(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	256(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 208(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	80(%rsp)
	.cfi_def_cfa_offset 248
	leaq	_Z14applyDirichletPdS_PiS0_S0_jiiid(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 256
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 248
	popq	%rdx
	.cfi_def_cfa_offset 240
.L8:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$232, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3719:
	.size	_Z49__device_stub__Z14applyDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid, .-_Z49__device_stub__Z14applyDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid
	.globl	_Z14applyDirichletPdS_PiS0_S0_jiiid
	.type	_Z14applyDirichletPdS_PiS0_S0_jiiid, @function
_Z14applyDirichletPdS_PiS0_S0_jiiid:
.LFB3720:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z14applyDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid
	.cfi_endproc
.LFE3720:
	.size	_Z14applyDirichletPdS_PiS0_S0_jiiid, .-_Z14applyDirichletPdS_PiS0_S0_jiiid
	.globl	_Z50__device_stub__Z15vectorDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid
	.type	_Z50__device_stub__Z15vectorDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid, @function
_Z50__device_stub__Z15vectorDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid:
.LFB3721:
	.cfi_startproc
	endbr64
	subq	$232, %rsp
	.cfi_def_cfa_offset 240
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movl	%r9d, 20(%rsp)
	movsd	%xmm0, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	240(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	248(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	256(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 208(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	80(%rsp)
	.cfi_def_cfa_offset 248
	leaq	_Z15vectorDirichletPdS_PiS0_S0_jiiid(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 256
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 248
	popq	%rdx
	.cfi_def_cfa_offset 240
.L13:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$232, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3721:
	.size	_Z50__device_stub__Z15vectorDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid, .-_Z50__device_stub__Z15vectorDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid
	.globl	_Z15vectorDirichletPdS_PiS0_S0_jiiid
	.type	_Z15vectorDirichletPdS_PiS0_S0_jiiid, @function
_Z15vectorDirichletPdS_PiS0_S0_jiiid:
.LFB3722:
	.cfi_startproc
	endbr64
	jmp	_Z50__device_stub__Z15vectorDirichletPdS_PiS0_S0_jiiidPdS_PiS0_S0_jiiid
	.cfi_endproc
.LFE3722:
	.size	_Z15vectorDirichletPdS_PiS0_S0_jiiid, .-_Z15vectorDirichletPdS_PiS0_S0_jiiid
	.globl	_Z35__device_stub__Z14BernBinomCoeffPdiPdi
	.type	_Z35__device_stub__Z14BernBinomCoeffPdiPdi, @function
_Z35__device_stub__Z14BernBinomCoeffPdiPdi:
.LFB3723:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z14BernBinomCoeffPdi(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L18:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3723:
	.size	_Z35__device_stub__Z14BernBinomCoeffPdiPdi, .-_Z35__device_stub__Z14BernBinomCoeffPdiPdi
	.globl	_Z14BernBinomCoeffPdi
	.type	_Z14BernBinomCoeffPdi, @function
_Z14BernBinomCoeffPdi:
.LFB3724:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z14BernBinomCoeffPdiPdi
	.cfi_endproc
.LFE3724:
	.size	_Z14BernBinomCoeffPdi, .-_Z14BernBinomCoeffPdi
	.globl	_Z50__device_stub__Z11ass_A_exactddPiS_PdiPxS_S0_S0_iiddPiS_PdiPxS_S0_S0_ii
	.type	_Z50__device_stub__Z11ass_A_exactddPiS_PdiPxS_S0_S0_iiddPiS_PdiPxS_S0_S0_ii, @function
_Z50__device_stub__Z11ass_A_exactddPiS_PdiPxS_S0_S0_iiddPiS_PdiPxS_S0_S0_ii:
.LFB3725:
	.cfi_startproc
	endbr64
	subq	$264, %rsp
	.cfi_def_cfa_offset 272
	movq	272(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	104(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	116(%rsp), %rsi
	movq	%rax, 8(%rsp)
	movq	280(%rsp), %rax
	movq	%rdx, 40(%rsp)
	leaq	88(%rsp), %rdx
	movl	%ecx, 36(%rsp)
	leaq	96(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, (%rsp)
	movsd	%xmm0, 72(%rsp)
	movsd	%xmm1, 64(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 248(%rsp)
	xorl	%eax, %eax
	leaq	72(%rsp), %rax
	movl	$1, 112(%rsp)
	movq	%rax, 152(%rsp)
	leaq	64(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 208(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 216(%rsp)
	movq	%rsp, %rax
	movq	%rax, 224(%rsp)
	leaq	288(%rsp), %rax
	movq	%rax, 232(%rsp)
	leaq	296(%rsp), %rax
	movq	%rax, 240(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 104(%rsp)
	movq	%rax, 116(%rsp)
	movl	$1, 124(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	96(%rsp)
	.cfi_def_cfa_offset 280
	leaq	_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii(%rip), %rdi
	pushq	96(%rsp)
	.cfi_def_cfa_offset 288
	movq	132(%rsp), %rcx
	movl	140(%rsp), %r8d
	movq	120(%rsp), %rsi
	movl	128(%rsp), %edx
	leaq	168(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 280
	popq	%rdx
	.cfi_def_cfa_offset 272
.L23:
	movq	248(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$264, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3725:
	.size	_Z50__device_stub__Z11ass_A_exactddPiS_PdiPxS_S0_S0_iiddPiS_PdiPxS_S0_S0_ii, .-_Z50__device_stub__Z11ass_A_exactddPiS_PdiPxS_S0_S0_iiddPiS_PdiPxS_S0_S0_ii
	.globl	_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii
	.type	_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii, @function
_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii:
.LFB3726:
	.cfi_startproc
	endbr64
	jmp	_Z50__device_stub__Z11ass_A_exactddPiS_PdiPxS_S0_S0_iiddPiS_PdiPxS_S0_S0_ii
	.cfi_endproc
.LFE3726:
	.size	_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii, .-_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii
	.globl	_Z31__device_stub__Z5splitPxPiS0_mmPxPiS0_mm
	.type	_Z31__device_stub__Z5splitPxPiS0_mmPxPiS0_mm, @function
_Z31__device_stub__Z5splitPxPiS0_mmPxPiS0_mm:
.LFB3727:
	.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	_Z5splitPxPiS0_mm(%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
.LFE3727:
	.size	_Z31__device_stub__Z5splitPxPiS0_mmPxPiS0_mm, .-_Z31__device_stub__Z5splitPxPiS0_mmPxPiS0_mm
	.globl	_Z5splitPxPiS0_mm
	.type	_Z5splitPxPiS0_mm, @function
_Z5splitPxPiS0_mm:
.LFB3728:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z5splitPxPiS0_mmPxPiS0_mm
	.cfi_endproc
.LFE3728:
	.size	_Z5splitPxPiS0_mm, .-_Z5splitPxPiS0_mm
	.globl	_Z40__device_stub__Z10loadVectorPdPiS0_ddidiPdPiS0_ddidi
	.type	_Z40__device_stub__Z10loadVectorPdPiS0_ddidiPdPiS0_ddidi, @function
_Z40__device_stub__Z10loadVectorPdPiS0_ddidiPdPiS0_ddidi:
.LFB3729:
	.cfi_startproc
	endbr64
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	80(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movsd	%xmm0, 32(%rsp)
	movsd	%xmm1, 24(%rsp)
	movsd	%xmm2, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 192(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	pushq	80(%rsp)
	.cfi_def_cfa_offset 232
	leaq	_Z10loadVectorPdPiS0_ddidi(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 240
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L33:
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$216, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3729:
	.size	_Z40__device_stub__Z10loadVectorPdPiS0_ddidiPdPiS0_ddidi, .-_Z40__device_stub__Z10loadVectorPdPiS0_ddidiPdPiS0_ddidi
	.globl	_Z10loadVectorPdPiS0_ddidi
	.type	_Z10loadVectorPdPiS0_ddidi, @function
_Z10loadVectorPdPiS0_ddidi:
.LFB3730:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z10loadVectorPdPiS0_ddidiPdPiS0_ddidi
	.cfi_endproc
.LFE3730:
	.size	_Z10loadVectorPdPiS0_ddidi, .-_Z10loadVectorPdPiS0_ddidi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z10loadVectorPdPiS0_ddidi"
.LC1:
	.string	"_Z5splitPxPiS0_mm"
.LC2:
	.string	"_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii"
.LC3:
	.string	"_Z14BernBinomCoeffPdi"
.LC4:
	.string	"_Z15vectorDirichletPdS_PiS0_S0_jiiid"
.LC5:
	.string	"_Z14applyDirichletPdS_PiS0_S0_jiiid"
.LC6:
	.string	"_Z9fillArrayPdid"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3732:
	.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	_Z10loadVectorPdPiS0_ddidi(%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	_Z5splitPxPiS0_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	.LC2(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11ass_A_exactddPiS_PdiPxS_S0_S0_ii(%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	_Z14BernBinomCoeffPdi(%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	_Z15vectorDirichletPdS_PiS0_S0_jiiid(%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	_Z14applyDirichletPdS_PiS0_S0_jiiid(%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	_Z9fillArrayPdid(%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
.LFE3732:
	.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 kernel_cuh
#define kernel_cuh

struct coordinates;

//computes the product of bernstein coeffitients
__global__ void BernBinomCoeff(double *M, int n);

//computes list of elemental stiffnes matrices
__global__ void ass_A_exact(double a, double b, int *coo_row_device,int *coo_col_device, double*coo_value,int degree,long long int* index, int *elements, double *M, double *M_m, int elementsX, int elementsY);


//fill array with size <size> with value <value>
__global__ void fillArray(double* array, int size, double value);

//applies Dirichlet to matrix
__global__ void applyDirichlet(double* load, double* csr_matrix, int* csr_col_device,int* csrRowPtr,int *isboundaryNode, unsigned int entries, int elementsX, int elementsY, int degree, double boundaryValue);

//applies dirichlet to RHS
__global__ void vectorDirichlet(double* load, double* csr_matrix, int* csr_col_device,int* csrRowPtr,int *isboundaryNode,unsigned int entries, int elementsX, int elementsY, int degree, double boundaryValue);

//splits index to (i,j) pair
__global__ void split(long long int *index, int*cols, int*rows,unsigned long int pointCount,unsigned long int length);

//computes load vector
__global__ void loadVector(double* loadList, int* index,int *elements, double a, double b, int degree, double func, int ElementCount);
#endif

	.text
	.file	"kernel.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
