#include<cuda.h>
#include<cuda_runtime.h>
#include<stdio.h>
#include"finitedifference.cuh"

#define field(a,b)      field[ (a)*Zm + (b) ]
#define diffield(a,b)   diffield[ (a)*Zm + (b) ]
#define coef(a,b)       coef[ (a)*Zm + (b) ]
#define difffield(a,b)  difffield[ (a)*Zm + (b)]


__global__ void compute_spatial_X_derivative(float* difffield, float* field, int Xm, int Zm)
{
    int tx = blockDim.x * blockIdx.x + threadIdx.x;
    int ty = blockDim.y * blockIdx.y + threadIdx.y;
    while(tx < Xm-2)
    {
        
        
        while(ty < Zm-2)
        {
            
            difffield(tx+1,ty+1) = 0.5*( field( tx + 2, ty + 1 )-field( tx ,ty + 1 ));
	    //printf("%d: %d => %f, %f, %f, %d, %d\n",tx,ty,difffield(tx+1,ty+1),field( tx + 2, ty + 1 ), field( tx ,ty + 1 ),Xm,Ym);
	    //printf("%d: %d=> %f\n",tx,ty,field(tx,ty));
            
            ty += blockDim.y * gridDim.y;
        }
        
        
        tx += blockDim.x * gridDim.x;
    }
    
}







__global__ void compute_spatial_Z_derivative(float* difffield, float* field, int Xm, int Zm)
{
    int tx = blockDim.x * blockIdx.x + threadIdx.x;
    int ty = blockDim.y * blockIdx.y + threadIdx.y;
    while(tx < Xm - 2)
    {
        
        
        while(ty < Zm - 2)
        {
            
            difffield( tx + 1,ty + 1 ) = 0.5*(field( tx + 1 , ty + 2 )-field( tx + 1 ,ty ));
            
            ty += blockDim.y * gridDim.y;
        }
        
        
        tx += blockDim.x*gridDim.x;
    }
    
}


__global__ void update_field(float* dev_veloc_u,
                             float* dev_veloc_w,
                             float *stress_xx,
                             float *stress_zz,
                             float *stress_xz,
                             float *dev_xx_x,
                             float *dev_zz_z,
                             float *dev_xz_x,
                             float *dev_xz_z,
                             float *dev_ux_x,
                             float *dev_ux_z,
                             float *dev_uz_x,
                             float *dev_uz_z,
                             float *lambda,
                             float *mu,
                             float *rho,
                             float dt,
                             int Xm,
                             int Zm)
{
    int tx = blockDim.x * blockIdx.x + threadIdx.x;
    int ty = blockDim.y * blockIdx.y + threadIdx.y;
    int thread = tx*Zm + ty;
    while(tx < Xm )
    {
        
        
        while(ty < Zm )
        {
            stress_xx[thread] += dt*(dev_ux_x[thread]*(lambda[thread]+2.0*mu[thread]) + dev_uz_z[thread]*lambda[thread]);
            stress_zz[thread] += dt*(dev_uz_z[thread]*(lambda[thread]+2.0*mu[thread]) + dev_ux_x[thread]*lambda[thread]);
            stress_xz[thread] += dt*mu[thread]*(dev_uz_x[thread] + dev_ux_z[thread]);
            dev_veloc_u[thread] += dt*(1./rho[thread])*(dev_xx_x[thread] + dev_xz_z[thread]);
            dev_veloc_w[thread] += dt*(1./rho[thread])*(dev_zz_z[thread] + dev_xz_x[thread]);
            ty += blockDim.y * gridDim.y;
        }
        tx += blockDim.x*gridDim.x;
    }
    
}

void compute_derivative(int direction, float *inputfield, float *derivative, int Xm, int Zm, dim3 num_blocks, dim3 thread_per_block, cudaStream_t custream)
{
    if(direction == XDERIVATIVE)
    {
	//printf("compute X derivative!\n");
        compute_spatial_X_derivative<<<num_blocks, thread_per_block, 0, custream>>>(derivative, inputfield, Xm, Zm);
	cudaError_t error = cudaGetLastError();
	  if(error != cudaSuccess)
		    {
			        // print the CUDA error message and exit
				     printf("CUDA error: %s\n", cudaGetErrorString(error));
				         exit(-1);
	           }
    }
    if(direction == ZDERIVATIVE)
    {
        compute_spatial_Z_derivative<<<num_blocks, thread_per_block,0, custream>>>(derivative, inputfield, Xm, Zm);
	cudaError_t error = cudaGetLastError();
	  if(error != cudaSuccess)
		    {
			        // print the CUDA error message and exit
				     printf("CUDA error: %s\n", cudaGetErrorString(error));
				         exit(-1);
	           }

    }
}

void call_update_field(float* dev_veloc_u,
                       float* dev_veloc_w,
                       float *stress_xx,
                       float *stress_zz,
                       float *stress_xz,
                       float* dev_xx_x,
                       float* dev_zz_z,
                       float* dev_xz_x,
                       float* dev_xz_z,
                       float* dev_ux_x,
                       float* dev_ux_z,
                       float* dev_uz_x,
		       float* dev_uz_z,
                       float* lambda,
                       float* mu,
                       float* rho,
                       float dt,
                       int Xm,
                       int Zm,
                       dim3 num_blocks,
                       dim3 thread_per_block,
					   cudaStream_t custream)
{
    update_field<<<num_blocks, thread_per_block, 0, custream>>>( dev_veloc_u,
                                                   dev_veloc_w,
                                                   stress_xx,
                                                   stress_zz,
                                                   stress_xz,
                                                   dev_xx_x,
                                                   dev_zz_z,
                                                   dev_xz_x,
                                                   dev_xz_z,
                                                   dev_ux_x,
                                                   dev_ux_z,
                                                   dev_uz_x,
                                                   dev_uz_z,
                                                   lambda,
                                                   mu,
                                                   rho,
                                                   dt,
                                                   Xm,
                                                   Zm);
    
	cudaError_t error = cudaGetLastError();
	  if(error != cudaSuccess)
		    {
			        // print the CUDA error message and exit
				     printf("CUDA error: %s\n", cudaGetErrorString(error));
				         exit(-1);
	           }

}



	.file	"tmpxft_0021028b_00000000-6_finitedifference.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii
	.type	_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii, @function
_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii:
.LFB2053:
	.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	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z28compute_spatial_X_derivativePfS_ii(%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
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii, .-_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii
	.globl	_Z28compute_spatial_X_derivativePfS_ii
	.type	_Z28compute_spatial_X_derivativePfS_ii, @function
_Z28compute_spatial_X_derivativePfS_ii:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii
	.cfi_endproc
.LFE2054:
	.size	_Z28compute_spatial_X_derivativePfS_ii, .-_Z28compute_spatial_X_derivativePfS_ii
	.globl	_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii
	.type	_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii, @function
_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii:
.LFB2055:
	.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	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z28compute_spatial_Z_derivativePfS_ii(%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
.LFE2055:
	.size	_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii, .-_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii
	.globl	_Z28compute_spatial_Z_derivativePfS_ii
	.type	_Z28compute_spatial_Z_derivativePfS_ii, @function
_Z28compute_spatial_Z_derivativePfS_ii:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii
	.cfi_endproc
.LFE2056:
	.size	_Z28compute_spatial_Z_derivativePfS_ii, .-_Z28compute_spatial_Z_derivativePfS_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error: %s\n"
	.text
	.globl	_Z18compute_derivativeiPfS_ii4dim3S0_P11CUstream_st
	.type	_Z18compute_derivativeiPfS_ii4dim3S0_P11CUstream_st, @function
_Z18compute_derivativeiPfS_ii4dim3S0_P11CUstream_st:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%r8d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%ecx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdx, %rbx
	pushq	%r10
	.cfi_def_cfa_offset 48
	cmpl	$1, %edi
	jne	.L14
	movl	72(%rsp), %ecx
	movq	64(%rsp), %rdx
	xorl	%r8d, %r8d
	movq	48(%rsp), %rdi
	movl	56(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movl	%r13d, %ecx
	movl	%r12d, %edx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	_Z52__device_stub__Z28compute_spatial_X_derivativePfS_iiPfS_ii
	jmp	.L17
.L14:
	cmpl	$2, %edi
	jne	.L13
	movl	72(%rsp), %ecx
	movq	64(%rsp), %rdx
	xorl	%r8d, %r8d
	movq	48(%rsp), %rdi
	movl	56(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movl	%r13d, %ecx
	movl	%r12d, %edx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	_Z52__device_stub__Z28compute_spatial_Z_derivativePfS_iiPfS_ii
.L17:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L13:
	popq	%rax
	.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
.LFE2027:
	.size	_Z18compute_derivativeiPfS_ii4dim3S0_P11CUstream_st, .-_Z18compute_derivativeiPfS_ii4dim3S0_P11CUstream_st
	.globl	_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii
	.type	_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii, @function
_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$376, %rsp
	.cfi_def_cfa_offset 384
	movq	384(%rsp), %rax
	movq	%rdi, 136(%rsp)
	leaq	160(%rsp), %rdi
	movq	%rsi, 128(%rsp)
	leaq	172(%rsp), %rsi
	movq	%rax, 88(%rsp)
	movq	392(%rsp), %rax
	movq	%rdx, 120(%rsp)
	leaq	144(%rsp), %rdx
	movq	%rax, 80(%rsp)
	movq	400(%rsp), %rax
	movq	%rcx, 112(%rsp)
	leaq	152(%rsp), %rcx
	movq	%rax, 72(%rsp)
	movq	408(%rsp), %rax
	movq	%r8, 104(%rsp)
	movq	%rax, 64(%rsp)
	movq	416(%rsp), %rax
	movq	%r9, 96(%rsp)
	movq	%rax, 56(%rsp)
	movq	424(%rsp), %rax
	movss	%xmm0, 12(%rsp)
	movq	%rax, 48(%rsp)
	movq	432(%rsp), %rax
	movq	%rax, 40(%rsp)
	movq	440(%rsp), %rax
	movq	%rax, 32(%rsp)
	movq	448(%rsp), %rax
	movq	%rax, 24(%rsp)
	movq	456(%rsp), %rax
	movq	%rax, 16(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 360(%rsp)
	xorl	%eax, %eax
	leaq	136(%rsp), %rax
	movq	%rax, 208(%rsp)
	leaq	128(%rsp), %rax
	movq	%rax, 216(%rsp)
	leaq	120(%rsp), %rax
	movq	%rax, 224(%rsp)
	leaq	112(%rsp), %rax
	movq	%rax, 232(%rsp)
	leaq	104(%rsp), %rax
	movq	%rax, 240(%rsp)
	leaq	96(%rsp), %rax
	movq	%rax, 248(%rsp)
	leaq	88(%rsp), %rax
	movq	%rax, 256(%rsp)
	leaq	80(%rsp), %rax
	movq	%rax, 264(%rsp)
	leaq	72(%rsp), %rax
	movq	%rax, 272(%rsp)
	leaq	64(%rsp), %rax
	movq	%rax, 280(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 288(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 296(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 304(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 312(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 320(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 328(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 336(%rsp)
	leaq	464(%rsp), %rax
	movq	%rax, 344(%rsp)
	leaq	472(%rsp), %rax
	movq	%rax, 352(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 160(%rsp)
	movl	$1, 168(%rsp)
	movq	%rax, 172(%rsp)
	movl	$1, 180(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	pushq	152(%rsp)
	.cfi_def_cfa_offset 392
	leaq	_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii(%rip), %rdi
	pushq	152(%rsp)
	.cfi_def_cfa_offset 400
	movq	188(%rsp), %rcx
	movl	196(%rsp), %r8d
	movq	176(%rsp), %rsi
	movl	184(%rsp), %edx
	leaq	224(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 392
	popq	%rdx
	.cfi_def_cfa_offset 384
.L27:
	movq	360(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$376, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii, .-_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii
	.globl	_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii
	.type	_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii, @function
_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii
	.cfi_endproc
.LFE2058:
	.size	_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii, .-_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii
	.globl	_Z17call_update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii4dim3S0_P11CUstream_st
	.type	_Z17call_update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii4dim3S0_P11CUstream_st, @function
_Z17call_update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii4dim3S0_P11CUstream_st:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%r9, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r8, %r14
	xorl	%r8d, %r8d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	200(%rsp), %ecx
	movq	208(%rsp), %r9
	movss	%xmm0, 12(%rsp)
	movq	192(%rsp), %rdx
	movq	176(%rsp), %rdi
	movl	184(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	movss	12(%rsp), %xmm0
	testl	%eax, %eax
	jne	.L33
	movl	168(%rsp), %eax
	movq	%r15, %r9
	movq	%r14, %r8
	movq	%r13, %rcx
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	pushq	%rax
	.cfi_def_cfa_offset 88
	movl	168(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 96
	pushq	168(%rsp)
	.cfi_def_cfa_offset 104
	pushq	168(%rsp)
	.cfi_def_cfa_offset 112
	pushq	168(%rsp)
	.cfi_def_cfa_offset 120
	pushq	168(%rsp)
	.cfi_def_cfa_offset 128
	pushq	168(%rsp)
	.cfi_def_cfa_offset 136
	pushq	168(%rsp)
	.cfi_def_cfa_offset 144
	pushq	168(%rsp)
	.cfi_def_cfa_offset 152
	pushq	168(%rsp)
	.cfi_def_cfa_offset 160
	pushq	168(%rsp)
	.cfi_def_cfa_offset 168
	pushq	168(%rsp)
	.cfi_def_cfa_offset 176
	call	_Z65__device_stub__Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fiiPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii
	addq	$96, %rsp
	.cfi_def_cfa_offset 80
.L33:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L32
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L32:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z17call_update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii4dim3S0_P11CUstream_st, .-_Z17call_update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii4dim3S0_P11CUstream_st
	.section	.rodata.str1.1
.LC1:
	.string	"_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii"
.LC2:
	.string	"_Z28compute_spatial_Z_derivativePfS_ii"
.LC3:
	.string	"_Z28compute_spatial_X_derivativePfS_ii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC1(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z12update_fieldPfS_S_S_S_S_S_S_S_S_S_S_S_S_S_S_fii(%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	.LC2(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z28compute_spatial_Z_derivativePfS_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	_Z28compute_spatial_X_derivativePfS_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
	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
.LFE2060:
	.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>
#define XDERIVATIVE 1
#define ZDERIVATIVE 2

void compute_derivative(int direction, float *inputfield, float *derivative, int Xm, int Zm, dim3 num_blocks, dim3 thread_per_block, hipStream_t custream);



void call_update_field(float* dev_veloc_u,
                       float* dev_veloc_w,
                       float *stress_xx,
                       float *stress_zz,
                       float *stress_xz,
                       float* dev_xx_x,
                       float* dev_zz_z,
                       float* dev_xz_x,
                       float* dev_xz_z,
                       float* dev_ux_x,
                       float* dev_ux_z,
                       float* dev_uz_x,
                       float* uz_z,
                       float* lambda,
                       float* mu,
                       float* rho,
                       float dt,
                       int Xm,
                       int Zm,
                       dim3 num_blocks,
                       dim3 thread_per_block,
					   hipStream_t custream);




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