#define EIGEN_USE_GPU
#include <cuda.h>
#include <stdio.h>
#include <algorithm>


#define THREADS_PER_BLOCK 1024
#define MAX_STREAMS 100
using namespace std; 


__global__ void getValidKernalPositions(
    const int block,
    const int input_feature_width,
    const int kernal_width,
    const int *kernal_deltas,
    const int *kernal_postions,
    int *kernel_pointers,
    int threadOffset = 0) 
{
    const int threadID = threadOffset + threadIdx.x;
    const int ix = block * (input_feature_width*input_feature_width) + (threadID / (kernal_width*kernal_width)); 
    const int kernal_start = block     *  (input_feature_width*input_feature_width);
    const int kernal_end   = (block+1) *  (input_feature_width*input_feature_width);

    const int row = (threadID % (kernal_width*kernal_width)) / kernal_width;
    const int row_iX = ix + kernal_postions[(row * kernal_width) + int(kernal_width/2)];

    const int column = (threadID % (kernal_width*kernal_width)) % kernal_width;

    if ( (kernal_start <= row_iX) && (kernal_end > row_iX) )
    {
        const int row_start = (row_iX < input_feature_width) ? 0 : (row_iX - ( (row_iX - input_feature_width) % input_feature_width ));
        const int row_end = row_start + input_feature_width;

        const int p         = ((row * kernal_width) + column);
        const int pointer   = (ix * ( kernal_width*kernal_width ) ) + p;
        const int location  = ix + kernal_postions[p];

        if ( (row_start <= location) && (row_end > location) )
        {
            kernel_pointers[pointer] = location;
        } else {
            kernel_pointers[pointer] = -1;
        }
    } else {
        const int pointer = (ix * ( kernal_width*kernal_width ) ) + ((row * kernal_width) + column);
        kernel_pointers[pointer] = -1;
    }
}

__global__ void RecurrentKernel_splitThreaded(
    const int block,
    const double* inputs,
    const double* weights,
    const int iterations,
    const int batch_samples, 
    const int units, 
    const int input_feature_width,
    const int kernal_width,
    const int *kernal_deltas,
    int *kernel_pointers,
    double *output,
    double *output_clones) 
{
    const int cell = (block * units) + threadIdx.x;

    for (int i = 0; i < iterations; i++)
    {
         __syncthreads();

         for (int j = 0; j < (kernal_width*kernal_width); j++)
         {
             const int cell_pointer      = (cell * (kernal_width*kernal_width))  + j;
             const int cell_position = kernel_pointers[cell_pointer];

            if (cell_position >= 0.0)
            {   
                const int weight_pointer = (block * (kernal_width*kernal_width)) + j;
                const double weight = weights[ weight_pointer ]/100;
                const double value  = output[cell];
                const double o = value * weight;
                atomicAdd(&output_clones[ cell_position ], o);
            }
        }
        __syncthreads();

        output[cell] = output_clones[cell];
    }

    // RELU
    output[cell] = (output[cell] > 0) ? output[cell] : 0;
}

__global__ void RecurrentKernel(
    const int block,
    const double* inputs,
    const double* weights,
    const int iterations,
    const int batch_samples, 
    const int units, 
    const int input_feature_width,
    const int kernal_width,
    const int *kernal_deltas,
    int *kernel_pointers,
    double *output,
    double *output_clones) 
{
    const int cell = block * (input_feature_width*input_feature_width) + (threadIdx.x / (kernal_width*kernal_width)); 
    const int offset = (threadIdx.x % (kernal_width*kernal_width));
    const int cell_pointer      = (cell * (kernal_width*kernal_width)) + offset;
    const int cell_position = kernel_pointers[cell_pointer];

    for (int i = 0; i < iterations; i++)
    {
         __syncthreads();
        if (cell_position >= 0.0)
        {   
            const int weight_pointer = (block * (kernal_width*kernal_width)) + offset; 
            const double weight = weights[weight_pointer]/100;
            const double value  = output[cell];
            const double o = value * weight;
            atomicAdd(&output_clones[cell_position], o);
        }

        __syncthreads();

        output[cell] = output_clones[cell];
    }

    // RELU
    output[cell] = (output[cell] > 0) ? output[cell] : 0;
}

void RecurrentKernelLauncher(
        const double* inputs, 
        const double* weights,
        const int iterations,
        const int batch_samples, 
        const int units, 
        const int input_feature_width,
        const int kernal_width,
        double* output) 
{
    const int    numOfThreads = (units*(kernal_width*kernal_width));
    const size_t inputBytes = (units * batch_samples) * sizeof(double);
    const size_t kernalCellPositionBytes = (( units * batch_samples ) * (kernal_width * kernal_width )) * sizeof(int);
    const size_t kernalBytes = ( kernal_width * kernal_width ) * sizeof(int);
    const size_t weightBytes = (( kernal_width * kernal_width ) * batch_samples) * sizeof(double);
    size_t sharedMemory = (inputBytes*3) + kernalCellPositionBytes + kernalBytes + weightBytes;
    printf("sharedMemory: %i bytes\n", sharedMemory);

    // blocks are limited to 1024 // if threads go beyond this, threads are broken up by row
    int threadSplit     = 0;
    int threadIntervals = 0;
    int endingThread    = 0;
    int numOfStreams    = 0;
    if (numOfThreads > THREADS_PER_BLOCK) {
        threadSplit = (int)(numOfThreads/THREADS_PER_BLOCK)+1;
        threadIntervals = numOfThreads/threadSplit;
        endingThread = numOfThreads - ((threadSplit-1) * threadIntervals);
    }
    if (batch_samples > MAX_STREAMS) {
        numOfStreams = MAX_STREAMS;
    } else {
        numOfStreams = batch_samples;
    }

    // allocate and initialize an array of stream handles
    cudaStream_t *streams;
    int *kernal_deltas, *d_kernal_deltas, *kernel_pointers, *d_kernel_pointers; 
    double *d_output, *d_output_clones, *d_inputs, *d_weights;

    cudaMallocHost(&streams,(numOfStreams * sizeof(cudaStream_t)));
    for (int i = 0; i < numOfStreams; i++) cudaStreamCreate(&(streams[i]));

    cudaMallocHost(&kernal_deltas, kernalBytes);

    int strtPos = -(kernal_width/2);
    int endPos  =   kernal_width - abs(strtPos);
    int pointer = 0;

    for(int fx=strtPos; fx < endPos; fx++) for(int fy=strtPos; fy < endPos; fy++)   {
        kernal_deltas[pointer] = ((fx * input_feature_width) + fy);
        pointer++;
    }

    cudaMalloc( (void **)&d_kernal_deltas, kernalBytes );
    cudaMemcpy(d_kernal_deltas, kernal_deltas, kernalBytes, cudaMemcpyHostToDevice);

    cudaMalloc( (void **)&d_output, inputBytes );
    cudaMemcpy(d_output, inputs, inputBytes, cudaMemcpyHostToDevice);

    cudaMalloc( (void **)&d_output_clones, inputBytes );
    cudaMemcpy(d_output_clones, inputs, inputBytes, cudaMemcpyHostToDevice);

    cudaMalloc( (void **)&d_inputs, inputBytes );
    cudaMemcpy(d_inputs, inputs, inputBytes, cudaMemcpyHostToDevice);

    cudaMalloc( (void **)&d_weights, weightBytes );
    cudaMemcpy(d_weights, weights, weightBytes, cudaMemcpyHostToDevice);

    cudaMallocHost( (void **)&kernel_pointers, kernalCellPositionBytes );
    cudaMalloc( (void **)&d_kernel_pointers, kernalCellPositionBytes );
    cudaMemcpy(d_kernel_pointers, kernel_pointers, kernalCellPositionBytes, cudaMemcpyHostToDevice);
    cudaDeviceSynchronize();

    int stream = 0;
    if (numOfThreads > THREADS_PER_BLOCK)
    {
        for (int i = 0; i < batch_samples; i++) {
            for (int j = 0; j < threadSplit; j++) {
                int k_threads = (j == ( threadSplit-1 )) ? endingThread : threadIntervals;
                getValidKernalPositions<<<1, k_threads, 0, streams[stream]>>>(i, input_feature_width, kernal_width, kernal_deltas,d_kernal_deltas, d_kernel_pointers, j*threadIntervals);
                stream++;
                if ((stream % numOfStreams) == 0) stream = 0;
            }
        }
    } else {
        for (int i = 0; i < batch_samples; i++) {
            getValidKernalPositions<<<1, numOfThreads, 0, streams[stream]>>>(i, input_feature_width, kernal_width, kernal_deltas,d_kernal_deltas, d_kernel_pointers);
            stream++;
            if ((stream % numOfStreams) == 0) stream = 0;
        }
    }
    cudaDeviceSynchronize();

    cudaMemcpy(kernal_deltas, d_kernal_deltas, kernalBytes, cudaMemcpyDeviceToHost);
    cudaMemcpy(d_kernal_deltas, kernal_deltas, kernalBytes, cudaMemcpyHostToDevice);
    cudaDeviceSynchronize();

    // batch_samples is the number of instances of the kernel
    // units is the number of threads within each instance
    stream = 0;
    if (numOfThreads > THREADS_PER_BLOCK)
    {
        for (int i = 0; i < batch_samples; i++) {
            RecurrentKernel_splitThreaded<<<1, units, 0, streams[stream]>>>(i, d_inputs, d_weights,iterations, batch_samples, units, input_feature_width,kernal_width, kernal_deltas, d_kernel_pointers, d_output, d_output_clones);
            stream++;
            if ((stream % numOfStreams) == 0) stream = 0;
        }
    } else {
        for (int i = 0; i < batch_samples; i++) {
            RecurrentKernel<<<1, numOfThreads, 0, streams[stream]>>>(i, d_inputs, d_weights, iterations, batch_samples, units, input_feature_width,kernal_width, kernal_deltas, d_kernel_pointers, d_output, d_output_clones);
            stream++;
            if ((stream % numOfStreams) == 0) stream = 0;
        }
    }

    cudaError_t cudaerr = cudaDeviceSynchronize();
    cudaMemcpy(output, d_output, inputBytes, cudaMemcpyDeviceToHost);

    cudaFreeHost(kernal_deltas);
    cudaFreeHost(kernel_pointers);
    cudaFree(d_kernal_deltas);
    cudaFree(d_kernel_pointers);
    cudaFree(d_output);
    cudaFree(d_output_clones);
    cudaFree(d_inputs);
    cudaFree(d_weights);
    if (cudaerr != cudaSuccess)
    {
        printf("kernel launch failed with error \"%s\".\n", cudaGetErrorString(cudaerr));
    }
}
	.file	"tmpxft_002df377_00000000-6_cuda_op_recurrent.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2310:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2310:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii
	.type	_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii, @function
_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii:
.LFB2332:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movl	%edi, 44(%rsp)
	leaq	64(%rsp), %rdi
	movl	%esi, 40(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 36(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 24(%rsp)
	leaq	56(%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, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	192(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z23getValidKernalPositionsiiiPKiS0_Pii(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	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 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L2:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2332:
	.size	_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii, .-_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii
	.globl	_Z23getValidKernalPositionsiiiPKiS0_Pii
	.type	_Z23getValidKernalPositionsiiiPKiS0_Pii, @function
_Z23getValidKernalPositionsiiiPKiS0_Pii:
.LFB2333:
	.cfi_startproc
	endbr64
	jmp	_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii
	.cfi_endproc
.LFE2333:
	.size	_Z23getValidKernalPositionsiiiPKiS0_Pii, .-_Z23getValidKernalPositionsiiiPKiS0_Pii
	.globl	_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	.type	_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_, @function
_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_:
.LFB2334:
	.cfi_startproc
	endbr64
	subq	$248, %rsp
	.cfi_def_cfa_offset 256
	movq	272(%rsp), %rax
	movl	%edi, 60(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rax, 24(%rsp)
	movq	280(%rsp), %rax
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rax, 16(%rsp)
	movq	288(%rsp), %rax
	movl	%ecx, 56(%rsp)
	leaq	80(%rsp), %rcx
	movq	%rax, 8(%rsp)
	movq	296(%rsp), %rax
	movl	%r8d, 36(%rsp)
	movl	%r9d, 32(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	60(%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	56(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	256(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	264(%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)
	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 264
	leaq	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 272
	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 264
	popq	%rdx
	.cfi_def_cfa_offset 256
.L8:
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$248, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2334:
	.size	_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_, .-_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.type	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, @function
_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_:
.LFB2335:
	.cfi_startproc
	endbr64
	jmp	_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	.cfi_endproc
.LFE2335:
	.size	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, .-_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	.type	_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_, @function
_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_:
.LFB2336:
	.cfi_startproc
	endbr64
	subq	$248, %rsp
	.cfi_def_cfa_offset 256
	movq	272(%rsp), %rax
	movl	%edi, 60(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rax, 24(%rsp)
	movq	280(%rsp), %rax
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rax, 16(%rsp)
	movq	288(%rsp), %rax
	movl	%ecx, 56(%rsp)
	leaq	80(%rsp), %rcx
	movq	%rax, 8(%rsp)
	movq	296(%rsp), %rax
	movl	%r8d, 36(%rsp)
	movl	%r9d, 32(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	60(%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	56(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	256(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	264(%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)
	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 264
	leaq	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 272
	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 264
	popq	%rdx
	.cfi_def_cfa_offset 256
.L13:
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$248, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2336:
	.size	_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_, .-_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.type	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, @function
_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_:
.LFB2337:
	.cfi_startproc
	endbr64
	jmp	_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	.cfi_endproc
.LFE2337:
	.size	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, .-_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"sharedMemory: %i bytes\n"
.LC1:
	.string	"kernel launch failed with error \"%s\".\n"
	.text
	.globl	_Z23RecurrentKernelLauncherPKdS0_iiiiiPd
	.type	_Z23RecurrentKernelLauncherPKdS0_iiiiiPd, @function
_Z23RecurrentKernelLauncherPKdS0_iiiiiPd:
.LFB2307:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%r9d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	movl	%r8d, %ecx
	imull	%ebx, %ecx
	subq	$184, %rsp
	.cfi_def_cfa_offset 240
	movl	%edx, 44(%rsp)
	movq	248(%rsp), %rax
	movl	240(%rsp), %edx
	movq	%rdi, 32(%rsp)
	movl	$2, %edi
	movq	%rsi, 48(%rsp)
	imull	%edx, %edx
	movl	%r8d, 20(%rsp)
	movq	%rax, 56(%rsp)
	imull	%edx, %ebp
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	movslq	%ecx, %rax
	imull	%edx, %ecx
	leaq	0(,%rax,8), %rsi
	movq	%rsi, (%rsp)
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %r14
	movslq	%edx, %rcx
	imull	%ebx, %edx
	leaq	0(,%rcx,4), %rsi
	movq	%rsi, 8(%rsp)
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %r13
	imulq	$24, %rax, %rdx
	xorl	%eax, %eax
	addq	%rsi, %rdx
	leaq	.LC0(%rip), %rsi
	addq	%r14, %rdx
	addq	%r13, %rdx
	call	__printf_chk@PLT
	cmpl	$1024, %ebp
	jle	.L49
	movl	%ebp, %ecx
	sarl	$10, %ecx
	leal	1(%rcx), %eax
	movl	%eax, 24(%rsp)
	movl	%ebp, %eax
	cltd
	idivl	24(%rsp)
	imull	%eax, %ecx
	movl	%eax, 28(%rsp)
	movl	%ebp, %eax
	subl	%ecx, %eax
	movl	%eax, 40(%rsp)
	jmp	.L19
.L49:
	xorl	%r10d, %r10d
	movl	%r10d, 40(%rsp)
	movl	%r10d, 28(%rsp)
	movl	%r10d, 24(%rsp)
.L19:
	movl	$100, %eax
	leaq	72(%rsp), %rdi
	cmpl	%eax, %ebx
	cmovle	%ebx, %eax
	xorl	%edx, %edx
	xorl	%r12d, %r12d
	movslq	%eax, %rsi
	movl	%eax, 16(%rsp)
	salq	$3, %rsi
	call	cudaHostAlloc@PLT
.L20:
	cmpl	%r12d, 16(%rsp)
	jle	.L62
	movq	72(%rsp), %rax
	leaq	(%rax,%r12,8), %rdi
	incq	%r12
	call	cudaStreamCreate@PLT
	jmp	.L20
.L62:
	movq	8(%rsp), %rsi
	xorl	%edx, %edx
	leaq	80(%rsp), %rdi
	call	cudaHostAlloc@PLT
	movl	240(%rsp), %eax
	movl	$2, %ecx
	movl	%r15d, %r9d
	movq	80(%rsp), %r10
	cltd
	idivl	%ecx
	movl	240(%rsp), %ecx
	negl	%eax
	movl	%eax, %edx
	movl	%eax, %r8d
	negl	%edx
	cmovs	%eax, %edx
	imull	%eax, %r9d
	xorl	%edi, %edi
	xorl	%r11d, %r11d
	subl	%edx, %ecx
.L22:
	cmpl	%ecx, %r8d
	jge	.L24
	movslq	%edi, %rsi
	movl	%eax, %edx
.L25:
	cmpl	%ecx, %edx
	jge	.L63
	leal	(%rdx,%r9), %r12d
	incl	%edx
	movl	%r12d, (%r10,%rsi,4)
	incq	%rsi
	jmp	.L25
.L63:
	movl	%ecx, %edx
	subl	%eax, %edx
	cmpl	%ecx, %eax
	cmovg	%r11d, %edx
	incl	%r8d
	addl	%r15d, %r9d
	addl	%edx, %edi
	jmp	.L22
.L24:
	movq	8(%rsp), %rsi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	$1, %ecx
	movq	88(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	leaq	112(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	112(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	leaq	120(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	120(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	leaq	128(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	128(%rsp), %rdi
	call	cudaMemcpy@PLT
	leaq	136(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	%r13, %rdx
	movq	136(%rsp), %rdi
	call	cudaMemcpy@PLT
	leaq	96(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMallocHost@PLT
	leaq	104(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movq	96(%rsp), %rsi
	movq	104(%rsp), %rdi
	movq	%r14, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	call	cudaDeviceSynchronize@PLT
	cmpl	$1024, %ebp
	jg	.L50
	movabsq	$4294967297, %r14
	xorl	%r13d, %r13d
	xorl	%r12d, %r12d
	jmp	.L27
.L50:
	xorl	%esi, %esi
	xorl	%r12d, %r12d
	movl	%esi, 32(%rsp)
.L26:
	cmpl	%ebx, 32(%rsp)
	jge	.L32
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
.L33:
	cmpl	%r13d, 24(%rsp)
	je	.L64
	movl	24(%rsp), %eax
	movl	40(%rsp), %edx
	movabsq	$4294967297, %rsi
	movl	$1, 152(%rsp)
	movq	%rsi, 160(%rsp)
	movl	164(%rsp), %ecx
	movq	%rsi, %rdi
	decl	%eax
	movq	%rsi, 144(%rsp)
	movl	$1, %esi
	cmpl	%r13d, %eax
	cmovne	28(%rsp), %edx
	movslq	%r12d, %rax
	xorl	%r8d, %r8d
	movl	%edx, 156(%rsp)
	movq	72(%rsp), %rdx
	movq	(%rdx,%rax,8), %r9
	movq	156(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	%rdi
	.cfi_def_cfa_offset 248
	movl	%r15d, %esi
	pushq	%r14
	.cfi_def_cfa_offset 256
	movq	120(%rsp), %r9
	movq	104(%rsp), %r8
	movq	96(%rsp), %rcx
	movl	256(%rsp), %edx
	movl	48(%rsp), %edi
	call	_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii
	popq	%r8
	.cfi_def_cfa_offset 248
	popq	%r9
	.cfi_def_cfa_offset 240
.L29:
	incl	%r12d
	movl	%r12d, %eax
	cltd
	idivl	16(%rsp)
	movl	28(%rsp), %eax
	testl	%edx, %edx
	cmove	%edx, %r12d
	incl	%r13d
	addl	%eax, %r14d
	jmp	.L33
.L64:
	incl	32(%rsp)
	jmp	.L26
.L38:
	movq	72(%rsp), %rdx
	movslq	%r12d, %rax
	xorl	%r8d, %r8d
	movq	%r14, %rdi
	movq	%r14, 160(%rsp)
	movl	164(%rsp), %ecx
	movl	$1, %esi
	movl	%ebp, 156(%rsp)
	movq	(%rdx,%rax,8), %r9
	movq	156(%rsp), %rdx
	movq	%r14, 144(%rsp)
	movl	$1, 152(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	pushq	%rax
	.cfi_def_cfa_offset 248
	movl	%r15d, %esi
	movl	%r13d, %edi
	pushq	$0
	.cfi_def_cfa_offset 256
	movq	120(%rsp), %r9
	movq	104(%rsp), %r8
	movq	96(%rsp), %rcx
	movl	256(%rsp), %edx
	call	_Z53__device_stub__Z23getValidKernalPositionsiiiPKiS0_PiiiiiPKiS0_Pii
	popq	%rdx
	.cfi_def_cfa_offset 248
	popq	%rcx
	.cfi_def_cfa_offset 240
.L36:
	incl	%r12d
	movl	%r12d, %eax
	cltd
	idivl	16(%rsp)
	testl	%edx, %edx
	cmove	%edx, %r12d
	incl	%r13d
.L27:
	cmpl	%ebx, %r13d
	jl	.L38
.L32:
	call	cudaDeviceSynchronize@PLT
	movq	8(%rsp), %rdx
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movq	80(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	$1, %ecx
	movq	88(%rsp), %rdi
	call	cudaMemcpy@PLT
	call	cudaDeviceSynchronize@PLT
	cmpl	$1024, %ebp
	jg	.L52
	movabsq	$4294967297, %r14
	xorl	%r13d, %r13d
	xorl	%r12d, %r12d
	jmp	.L35
.L52:
	movabsq	$4294967297, %r13
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
.L34:
	cmpl	%ebx, %r12d
	jge	.L47
	movl	20(%rsp), %ecx
	movq	72(%rsp), %rdx
	movslq	%ebp, %rax
	xorl	%r8d, %r8d
	movq	%r13, 160(%rsp)
	movq	%r13, %rdi
	movl	$1, %esi
	movl	%ecx, 156(%rsp)
	movq	(%rdx,%rax,8), %r9
	movl	164(%rsp), %ecx
	movq	156(%rsp), %rdx
	movq	%r13, 144(%rsp)
	movl	$1, 152(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	pushq	120(%rsp)
	.cfi_def_cfa_offset 248
	movl	%ebx, %r8d
	movl	%r12d, %edi
	pushq	120(%rsp)
	.cfi_def_cfa_offset 256
	pushq	120(%rsp)
	.cfi_def_cfa_offset 264
	pushq	104(%rsp)
	.cfi_def_cfa_offset 272
	movl	272(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 280
	pushq	%r15
	.cfi_def_cfa_offset 288
	movl	68(%rsp), %r9d
	movl	92(%rsp), %ecx
	movq	184(%rsp), %rdx
	movq	176(%rsp), %rsi
	call	_Z69__device_stub__Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	addq	$48, %rsp
	.cfi_def_cfa_offset 240
.L39:
	incl	%ebp
	movl	%ebp, %eax
	cltd
	idivl	16(%rsp)
	testl	%edx, %edx
	cmove	%edx, %ebp
	incl	%r12d
	jmp	.L34
.L46:
	movq	72(%rsp), %rdx
	movslq	%r12d, %rax
	xorl	%r8d, %r8d
	movq	%r14, %rdi
	movq	%r14, 160(%rsp)
	movl	164(%rsp), %ecx
	movl	$1, %esi
	movl	%ebp, 156(%rsp)
	movq	(%rdx,%rax,8), %r9
	movq	156(%rsp), %rdx
	movq	%r14, 144(%rsp)
	movl	$1, 152(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L44
	pushq	120(%rsp)
	.cfi_def_cfa_offset 248
	movl	%ebx, %r8d
	movl	%r13d, %edi
	pushq	120(%rsp)
	.cfi_def_cfa_offset 256
	pushq	120(%rsp)
	.cfi_def_cfa_offset 264
	pushq	104(%rsp)
	.cfi_def_cfa_offset 272
	movl	272(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 280
	pushq	%r15
	.cfi_def_cfa_offset 288
	movl	68(%rsp), %r9d
	movl	92(%rsp), %ecx
	movq	184(%rsp), %rdx
	movq	176(%rsp), %rsi
	call	_Z55__device_stub__Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_iPKdS0_iiiiiPKiPiPdS4_
	addq	$48, %rsp
	.cfi_def_cfa_offset 240
.L44:
	incl	%r12d
	movl	%r12d, %eax
	cltd
	idivl	16(%rsp)
	testl	%edx, %edx
	cmove	%edx, %r12d
	incl	%r13d
.L35:
	cmpl	%ebx, %r13d
	jl	.L46
.L47:
	call	cudaDeviceSynchronize@PLT
	movq	(%rsp), %rdx
	movq	112(%rsp), %rsi
	movl	$2, %ecx
	movq	56(%rsp), %rdi
	movl	%eax, %ebx
	call	cudaMemcpy@PLT
	movq	80(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	96(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rdi
	call	cudaFree@PLT
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rdi
	call	cudaFree@PLT
	testl	%ebx, %ebx
	je	.L18
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L18:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	addq	$184, %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
.LFE2307:
	.size	_Z23RecurrentKernelLauncherPKdS0_iiiiiPd, .-_Z23RecurrentKernelLauncherPKdS0_iiiiiPd
	.section	.rodata.str1.1
.LC2:
	.string	"_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_"
.LC3:
	.string	"_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_"
.LC4:
	.string	"_Z23getValidKernalPositionsiiiPKiS0_Pii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2339:
	.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	.LC2(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_(%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	.LC3(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_(%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	_Z23getValidKernalPositionsiiiPKiS0_Pii(%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
.LFE2339:
	.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:

#define EIGEN_USE_GPU
#include <hip/hip_runtime.h>
#include <stdio.h>
#include <algorithm>


#define THREADS_PER_BLOCK 1024
#define MAX_STREAMS 100
using namespace std; 


__global__ void getValidKernalPositions(
    const int block,
    const int input_feature_width,
    const int kernal_width,
    const int *kernal_deltas,
    const int *kernal_postions,
    int *kernel_pointers,
    int threadOffset = 0) 
{
    const int threadID = threadOffset + threadIdx.x;
    const int ix = block * (input_feature_width*input_feature_width) + (threadID / (kernal_width*kernal_width)); 
    const int kernal_start = block     *  (input_feature_width*input_feature_width);
    const int kernal_end   = (block+1) *  (input_feature_width*input_feature_width);

    const int row = (threadID % (kernal_width*kernal_width)) / kernal_width;
    const int row_iX = ix + kernal_postions[(row * kernal_width) + int(kernal_width/2)];

    const int column = (threadID % (kernal_width*kernal_width)) % kernal_width;

    if ( (kernal_start <= row_iX) && (kernal_end > row_iX) )
    {
        const int row_start = (row_iX < input_feature_width) ? 0 : (row_iX - ( (row_iX - input_feature_width) % input_feature_width ));
        const int row_end = row_start + input_feature_width;

        const int p         = ((row * kernal_width) + column);
        const int pointer   = (ix * ( kernal_width*kernal_width ) ) + p;
        const int location  = ix + kernal_postions[p];

        if ( (row_start <= location) && (row_end > location) )
        {
            kernel_pointers[pointer] = location;
        } else {
            kernel_pointers[pointer] = -1;
        }
    } else {
        const int pointer = (ix * ( kernal_width*kernal_width ) ) + ((row * kernal_width) + column);
        kernel_pointers[pointer] = -1;
    }
}

__global__ void RecurrentKernel_splitThreaded(
    const int block,
    const double* inputs,
    const double* weights,
    const int iterations,
    const int batch_samples, 
    const int units, 
    const int input_feature_width,
    const int kernal_width,
    const int *kernal_deltas,
    int *kernel_pointers,
    double *output,
    double *output_clones) 
{
    const int cell = (block * units) + threadIdx.x;

    for (int i = 0; i < iterations; i++)
    {
         __syncthreads();

         for (int j = 0; j < (kernal_width*kernal_width); j++)
         {
             const int cell_pointer      = (cell * (kernal_width*kernal_width))  + j;
             const int cell_position = kernel_pointers[cell_pointer];

            if (cell_position >= 0.0)
            {   
                const int weight_pointer = (block * (kernal_width*kernal_width)) + j;
                const double weight = weights[ weight_pointer ]/100;
                const double value  = output[cell];
                const double o = value * weight;
                atomicAdd(&output_clones[ cell_position ], o);
            }
        }
        __syncthreads();

        output[cell] = output_clones[cell];
    }

    // RELU
    output[cell] = (output[cell] > 0) ? output[cell] : 0;
}

__global__ void RecurrentKernel(
    const int block,
    const double* inputs,
    const double* weights,
    const int iterations,
    const int batch_samples, 
    const int units, 
    const int input_feature_width,
    const int kernal_width,
    const int *kernal_deltas,
    int *kernel_pointers,
    double *output,
    double *output_clones) 
{
    const int cell = block * (input_feature_width*input_feature_width) + (threadIdx.x / (kernal_width*kernal_width)); 
    const int offset = (threadIdx.x % (kernal_width*kernal_width));
    const int cell_pointer      = (cell * (kernal_width*kernal_width)) + offset;
    const int cell_position = kernel_pointers[cell_pointer];

    for (int i = 0; i < iterations; i++)
    {
         __syncthreads();
        if (cell_position >= 0.0)
        {   
            const int weight_pointer = (block * (kernal_width*kernal_width)) + offset; 
            const double weight = weights[weight_pointer]/100;
            const double value  = output[cell];
            const double o = value * weight;
            atomicAdd(&output_clones[cell_position], o);
        }

        __syncthreads();

        output[cell] = output_clones[cell];
    }

    // RELU
    output[cell] = (output[cell] > 0) ? output[cell] : 0;
}

void RecurrentKernelLauncher(
        const double* inputs, 
        const double* weights,
        const int iterations,
        const int batch_samples, 
        const int units, 
        const int input_feature_width,
        const int kernal_width,
        double* output) 
{
    const int    numOfThreads = (units*(kernal_width*kernal_width));
    const size_t inputBytes = (units * batch_samples) * sizeof(double);
    const size_t kernalCellPositionBytes = (( units * batch_samples ) * (kernal_width * kernal_width )) * sizeof(int);
    const size_t kernalBytes = ( kernal_width * kernal_width ) * sizeof(int);
    const size_t weightBytes = (( kernal_width * kernal_width ) * batch_samples) * sizeof(double);
    size_t sharedMemory = (inputBytes*3) + kernalCellPositionBytes + kernalBytes + weightBytes;
    printf("sharedMemory: %i bytes\n", sharedMemory);

    // blocks are limited to 1024 // if threads go beyond this, threads are broken up by row
    int threadSplit     = 0;
    int threadIntervals = 0;
    int endingThread    = 0;
    int numOfStreams    = 0;
    if (numOfThreads > THREADS_PER_BLOCK) {
        threadSplit = (int)(numOfThreads/THREADS_PER_BLOCK)+1;
        threadIntervals = numOfThreads/threadSplit;
        endingThread = numOfThreads - ((threadSplit-1) * threadIntervals);
    }
    if (batch_samples > MAX_STREAMS) {
        numOfStreams = MAX_STREAMS;
    } else {
        numOfStreams = batch_samples;
    }

    // allocate and initialize an array of stream handles
    hipStream_t *streams;
    int *kernal_deltas, *d_kernal_deltas, *kernel_pointers, *d_kernel_pointers; 
    double *d_output, *d_output_clones, *d_inputs, *d_weights;

    hipHostMalloc(&streams,(numOfStreams * sizeof(hipStream_t)), hipHostMallocDefault);
    for (int i = 0; i < numOfStreams; i++) hipStreamCreate(&(streams[i]));

    hipHostMalloc(&kernal_deltas, kernalBytes, hipHostMallocDefault);

    int strtPos = -(kernal_width/2);
    int endPos  =   kernal_width - abs(strtPos);
    int pointer = 0;

    for(int fx=strtPos; fx < endPos; fx++) for(int fy=strtPos; fy < endPos; fy++)   {
        kernal_deltas[pointer] = ((fx * input_feature_width) + fy);
        pointer++;
    }

    hipMalloc( (void **)&d_kernal_deltas, kernalBytes );
    hipMemcpy(d_kernal_deltas, kernal_deltas, kernalBytes, hipMemcpyHostToDevice);

    hipMalloc( (void **)&d_output, inputBytes );
    hipMemcpy(d_output, inputs, inputBytes, hipMemcpyHostToDevice);

    hipMalloc( (void **)&d_output_clones, inputBytes );
    hipMemcpy(d_output_clones, inputs, inputBytes, hipMemcpyHostToDevice);

    hipMalloc( (void **)&d_inputs, inputBytes );
    hipMemcpy(d_inputs, inputs, inputBytes, hipMemcpyHostToDevice);

    hipMalloc( (void **)&d_weights, weightBytes );
    hipMemcpy(d_weights, weights, weightBytes, hipMemcpyHostToDevice);

    hipHostMalloc( (void **)&kernel_pointers, kernalCellPositionBytes , hipHostMallocDefault);
    hipMalloc( (void **)&d_kernel_pointers, kernalCellPositionBytes );
    hipMemcpy(d_kernel_pointers, kernel_pointers, kernalCellPositionBytes, hipMemcpyHostToDevice);
    hipDeviceSynchronize();

    int stream = 0;
    if (numOfThreads > THREADS_PER_BLOCK)
    {
        for (int i = 0; i < batch_samples; i++) {
            for (int j = 0; j < threadSplit; j++) {
                int k_threads = (j == ( threadSplit-1 )) ? endingThread : threadIntervals;
                getValidKernalPositions<<<1, k_threads, 0, streams[stream]>>>(i, input_feature_width, kernal_width, kernal_deltas,d_kernal_deltas, d_kernel_pointers, j*threadIntervals);
                stream++;
                if ((stream % numOfStreams) == 0) stream = 0;
            }
        }
    } else {
        for (int i = 0; i < batch_samples; i++) {
            getValidKernalPositions<<<1, numOfThreads, 0, streams[stream]>>>(i, input_feature_width, kernal_width, kernal_deltas,d_kernal_deltas, d_kernel_pointers);
            stream++;
            if ((stream % numOfStreams) == 0) stream = 0;
        }
    }
    hipDeviceSynchronize();

    hipMemcpy(kernal_deltas, d_kernal_deltas, kernalBytes, hipMemcpyDeviceToHost);
    hipMemcpy(d_kernal_deltas, kernal_deltas, kernalBytes, hipMemcpyHostToDevice);
    hipDeviceSynchronize();

    // batch_samples is the number of instances of the kernel
    // units is the number of threads within each instance
    stream = 0;
    if (numOfThreads > THREADS_PER_BLOCK)
    {
        for (int i = 0; i < batch_samples; i++) {
            RecurrentKernel_splitThreaded<<<1, units, 0, streams[stream]>>>(i, d_inputs, d_weights,iterations, batch_samples, units, input_feature_width,kernal_width, kernal_deltas, d_kernel_pointers, d_output, d_output_clones);
            stream++;
            if ((stream % numOfStreams) == 0) stream = 0;
        }
    } else {
        for (int i = 0; i < batch_samples; i++) {
            RecurrentKernel<<<1, numOfThreads, 0, streams[stream]>>>(i, d_inputs, d_weights, iterations, batch_samples, units, input_feature_width,kernal_width, kernal_deltas, d_kernel_pointers, d_output, d_output_clones);
            stream++;
            if ((stream % numOfStreams) == 0) stream = 0;
        }
    }

    hipError_t cudaerr = hipDeviceSynchronize();
    hipMemcpy(output, d_output, inputBytes, hipMemcpyDeviceToHost);

    hipHostFree(kernal_deltas);
    hipHostFree(kernel_pointers);
    hipFree(d_kernal_deltas);
    hipFree(d_kernel_pointers);
    hipFree(d_output);
    hipFree(d_output_clones);
    hipFree(d_inputs);
    hipFree(d_weights);
    if (cudaerr != hipSuccess)
    {
        printf("kernel launch failed with error \"%s\".\n", hipGetErrorString(cudaerr));
    }
}
	.text
	.file	"cuda_op_recurrent.hip"
	.globl	_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii # -- Begin function _Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	.type	_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii,@function
_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii: # @_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	20(%rsp), %rax
	movl	%edi, (%rax)
	leaq	16(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	56(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	48(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z23getValidKernalPositionsiiiPKiS0_Pii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	popq	%rbx
	.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
	retq
.Lfunc_end0:
	.size	_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii, .Lfunc_end0-_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	.cfi_endproc
                                        # -- End function
	.globl	_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_ # -- Begin function _Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.type	_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_,@function
_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_: # @_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	movq	%rsp, %r8
	movl	%r9d, (%r8)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	232(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	240(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	248(%rsp), %rax
	movq	%rax, 72(%rbx)
	leaq	256(%rsp), %rax
	movq	%rax, 80(%rbx)
	leaq	264(%rsp), %rax
	movq	%rax, 88(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	popq	%rbx
	.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
	retq
.Lfunc_end1:
	.size	_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, .Lfunc_end1-_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_ # -- Begin function _Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.type	_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_,@function
_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_: # @_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	movq	%rsp, %r8
	movl	%r9d, (%r8)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	232(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	240(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	248(%rsp), %rax
	movq	%rax, 72(%rbx)
	leaq	256(%rsp), %rax
	movq	%rax, 80(%rbx)
	leaq	264(%rsp), %rax
	movq	%rax, 88(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	popq	%rbx
	.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
	retq
.Lfunc_end2:
	.size	_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, .Lfunc_end2-_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.cfi_endproc
                                        # -- End function
	.globl	_Z23RecurrentKernelLauncherPKdS0_iiiiiPd # -- Begin function _Z23RecurrentKernelLauncherPKdS0_iiiiiPd
	.type	_Z23RecurrentKernelLauncherPKdS0_iiiiiPd,@function
_Z23RecurrentKernelLauncherPKdS0_iiiiiPd: # @_Z23RecurrentKernelLauncherPKdS0_iiiiiPd
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
                                        # kill: def $r9d killed $r9d def $r9
	movq	%r9, 24(%rsp)                   # 8-byte Spill
	movl	%edx, 56(%rsp)                  # 4-byte Spill
	movq	%rsi, 120(%rsp)                 # 8-byte Spill
	movq	%rdi, 72(%rsp)                  # 8-byte Spill
	movl	192(%rsp), %ebx
                                        # kill: def $ebx killed $ebx killed $rbx def $rbx
	imull	%ebx, %ebx
	movl	%ebx, %r14d
	imull	%r8d, %r14d
	movl	%r8d, 16(%rsp)                  # 4-byte Spill
	movl	%r8d, %eax
	imull	%ecx, %eax
	movslq	%eax, %r13
	movl	%r13d, %eax
	imull	%ebx, %eax
	movslq	%eax, %r15
	movl	%ebx, %eax
	movl	%ecx, 20(%rsp)                  # 4-byte Spill
	imull	%ecx, %eax
	movslq	%eax, %r12
	leaq	(,%r13,2), %rax
	addq	%r13, %rax
	shlq	$3, %rax
	leaq	(%rax,%rbx,4), %rax
	leaq	(%rax,%r15,4), %rax
	leaq	(%rax,%r12,8), %rsi
	movl	$0, 60(%rsp)                    # 4-byte Folded Spill
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$0, %ebp
	movl	$0, %edi
	movl	%r14d, (%rsp)                   # 4-byte Spill
	cmpl	$1025, %r14d                    # imm = 0x401
	jl	.LBB3_2
# %bb.1:
	movl	(%rsp), %esi                    # 4-byte Reload
	movl	%esi, %ecx
	shrl	$10, %ecx
	leal	1(%rcx), %edi
	movl	%esi, %eax
	xorl	%edx, %edx
	divl	%edi
	movl	%eax, %ebp
	imull	%eax, %ecx
	subl	%ecx, %esi
	movl	%esi, 60(%rsp)                  # 4-byte Spill
.LBB3_2:
	movl	%edi, 116(%rsp)                 # 4-byte Spill
	leaq	(,%rbx,4), %rax
	movq	%rax, 80(%rsp)                  # 8-byte Spill
	movl	20(%rsp), %ebx                  # 4-byte Reload
	cmpl	$100, %ebx
	movl	$100, %eax
	cmovll	%ebx, %eax
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movslq	%eax, %rsi
	shlq	$3, %rsi
	leaq	48(%rsp), %rdi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%ebx, %ebx
	jle	.LBB3_5
# %bb.3:                                # %.lr.ph.preheader
	movl	4(%rsp), %ebx                   # 4-byte Reload
	shlq	$3, %rbx
	xorl	%r14d, %r14d
.LBB3_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	48(%rsp), %rdi
	addq	%r14, %rdi
	callq	hipStreamCreate
	addq	$8, %r14
	cmpq	%r14, %rbx
	jne	.LBB3_4
.LBB3_5:                                # %._crit_edge
	shlq	$3, %r13
	shlq	$2, %r15
	shlq	$3, %r12
	leaq	8(%rsp), %rdi
	movq	80(%rsp), %rsi                  # 8-byte Reload
	xorl	%edx, %edx
	callq	hipHostMalloc
	movl	192(%rsp), %eax
	movq	%rax, %rdx
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	negl	%eax
	movl	%eax, %ecx
	negl	%ecx
	cmovnsl	%eax, %ecx
	addl	%edx, %ecx
	cmpl	%ecx, %eax
	jge	.LBB3_10
# %bb.6:                                # %.preheader204.lr.ph
	movq	8(%rsp), %rdx
	movq	24(%rsp), %rsi                  # 8-byte Reload
	incl	%esi
	imull	%eax, %esi
	xorl	%edi, %edi
	movl	%eax, %r8d
.LBB3_7:                                # %.lr.ph208
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_8 Depth 2
	movslq	%edi, %rdi
	movl	%esi, %r9d
	movl	%eax, %r10d
.LBB3_8:                                #   Parent Loop BB3_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r9d, (%rdx,%rdi,4)
	incq	%rdi
	incl	%r10d
	incl	%r9d
	cmpl	%ecx, %r10d
	jl	.LBB3_8
# %bb.9:                                # %._crit_edge209
                                        #   in Loop: Header=BB3_7 Depth=1
	incl	%r8d
	addl	24(%rsp), %esi                  # 4-byte Folded Reload
	cmpl	%ecx, %r8d
	jl	.LBB3_7
.LBB3_10:                               # %._crit_edge212
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	movq	80(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	8(%rsp), %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	64(%rsp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	72(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	104(%rsp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	96(%rsp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%rbx, %rsi
	movq	%r13, 72(%rsp)                  # 8-byte Spill
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	88(%rsp), %r14
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	120(%rsp), %rsi                 # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	128(%rsp), %r14
	movq	%r14, %rdi
	movq	%r15, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	(%r14), %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	cmpl	$1024, (%rsp)                   # 4-byte Folded Reload
                                        # imm = 0x400
	movl	20(%rsp), %ebx                  # 4-byte Reload
	jle	.LBB3_11
# %bb.16:                               # %.preheader200
	testl	%ebx, %ebx
	jle	.LBB3_24
# %bb.17:                               # %.preheader199.lr.ph
	xorl	%r12d, %r12d
	movabsq	$4294967296, %rax               # imm = 0x100000000
	leaq	1(%rax), %r13
	xorl	%r14d, %r14d
.LBB3_18:                               # %.preheader199
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_20 Depth 2
	movl	116(%rsp), %r15d                # 4-byte Reload
	testl	%r15d, %r15d
	jle	.LBB3_23
# %bb.19:                               # %.lr.ph218.preheader
                                        #   in Loop: Header=BB3_18 Depth=1
	xorl	%ebx, %ebx
.LBB3_20:                               # %.lr.ph218
                                        #   Parent Loop BB3_18 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpl	$1, %r15d
	movl	%ebp, %edx
	cmovel	60(%rsp), %edx                  # 4-byte Folded Reload
	movq	48(%rsp), %rax
	movslq	%r12d, %rcx
	movq	(%rax,%rcx,8), %r9
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdx
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_22
# %bb.21:                               #   in Loop: Header=BB3_20 Depth=2
	movq	8(%rsp), %rcx
	movq	40(%rsp), %r8
	movq	32(%rsp), %r9
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	%r14d, %edi
	movq	32(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movl	200(%rsp), %edx
                                        # kill: def $edx killed $edx killed $rdx
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	callq	_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB3_22:                               #   in Loop: Header=BB3_20 Depth=2
	incl	%r12d
	movl	%r12d, %eax
	cltd
	idivl	4(%rsp)                         # 4-byte Folded Reload
	testl	%edx, %edx
	cmovel	%edx, %r12d
	addl	%ebp, %ebx
	decl	%r15d
	jne	.LBB3_20
.LBB3_23:                               # %._crit_edge219
                                        #   in Loop: Header=BB3_18 Depth=1
	incl	%r14d
	movl	20(%rsp), %ebx                  # 4-byte Reload
	cmpl	%ebx, %r14d
	jne	.LBB3_18
	jmp	.LBB3_24
.LBB3_11:                               # %.preheader202
	testl	%ebx, %ebx
	jle	.LBB3_24
# %bb.12:                               # %.lr.ph215
	movl	(%rsp), %r14d                   # 4-byte Reload
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %r14
	xorl	%r12d, %r12d
	leaq	1(%rax), %r13
	xorl	%ebp, %ebp
.LBB3_13:                               # =>This Inner Loop Header: Depth=1
	movq	48(%rsp), %rax
	movslq	%r12d, %rcx
	movq	(%rax,%rcx,8), %r9
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_15
# %bb.14:                               #   in Loop: Header=BB3_13 Depth=1
	movq	8(%rsp), %rcx
	movq	40(%rsp), %r8
	movq	32(%rsp), %r9
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	%ebp, %edi
	movq	32(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movl	200(%rsp), %edx
                                        # kill: def $edx killed $edx killed $rdx
	pushq	$0
	.cfi_adjust_cfa_offset 8
	callq	_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB3_15:                               #   in Loop: Header=BB3_13 Depth=1
	incl	%r12d
	movl	%r12d, %eax
	cltd
	idivl	4(%rsp)                         # 4-byte Folded Reload
	testl	%edx, %edx
	cmovel	%edx, %r12d
	incl	%ebp
	cmpl	%ebp, %ebx
	jne	.LBB3_13
.LBB3_24:                               # %.loopexit201
	movq	200(%rsp), %r12
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rdi
	movq	40(%rsp), %rsi
	movq	80(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	cmpl	$1024, (%rsp)                   # 4-byte Folded Reload
                                        # imm = 0x400
	jle	.LBB3_25
# %bb.30:                               # %.preheader
	testl	%ebx, %ebx
	jle	.LBB3_35
# %bb.31:                               # %.lr.ph228
	movl	16(%rsp), %r14d                 # 4-byte Reload
	movabsq	$4294967296, %r15               # imm = 0x100000000
	orq	%r15, %r14
	xorl	%r13d, %r13d
	incq	%r15
	xorl	%ebp, %ebp
.LBB3_32:                               # =>This Inner Loop Header: Depth=1
	movq	48(%rsp), %rax
	movslq	%ebp, %rcx
	movq	(%rax,%rcx,8), %r9
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_34
# %bb.33:                               #   in Loop: Header=BB3_32 Depth=1
	movq	96(%rsp), %rsi
	movq	88(%rsp), %rdx
	movl	%r13d, %edi
	movl	56(%rsp), %ecx                  # 4-byte Reload
	movl	%ebx, %r8d
	movl	16(%rsp), %r9d                  # 4-byte Reload
	pushq	104(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	48(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	32(%rsp)
	.cfi_adjust_cfa_offset 8
	movl	224(%rsp), %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	64(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	callq	_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
.LBB3_34:                               #   in Loop: Header=BB3_32 Depth=1
	incl	%ebp
	movl	%ebp, %eax
	cltd
	idivl	4(%rsp)                         # 4-byte Folded Reload
	testl	%edx, %edx
	cmovel	%edx, %ebp
	incl	%r13d
	cmpl	%r13d, %ebx
	jne	.LBB3_32
	jmp	.LBB3_35
.LBB3_25:                               # %.preheader197
	testl	%ebx, %ebx
	jle	.LBB3_35
# %bb.26:                               # %.lr.ph225
	movl	(%rsp), %r14d                   # 4-byte Reload
	movabsq	$4294967296, %r15               # imm = 0x100000000
	orq	%r15, %r14
	xorl	%r13d, %r13d
	incq	%r15
	xorl	%ebp, %ebp
.LBB3_27:                               # =>This Inner Loop Header: Depth=1
	movq	48(%rsp), %rax
	movslq	%ebp, %rcx
	movq	(%rax,%rcx,8), %r9
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_29
# %bb.28:                               #   in Loop: Header=BB3_27 Depth=1
	movq	96(%rsp), %rsi
	movq	88(%rsp), %rdx
	movl	%r13d, %edi
	movl	56(%rsp), %ecx                  # 4-byte Reload
	movl	%ebx, %r8d
	movl	16(%rsp), %r9d                  # 4-byte Reload
	pushq	104(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	48(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	32(%rsp)
	.cfi_adjust_cfa_offset 8
	movl	224(%rsp), %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	64(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	callq	_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
.LBB3_29:                               #   in Loop: Header=BB3_27 Depth=1
	incl	%ebp
	movl	%ebp, %eax
	cltd
	idivl	4(%rsp)                         # 4-byte Folded Reload
	testl	%edx, %edx
	cmovel	%edx, %ebp
	incl	%r13d
	cmpl	%r13d, %ebx
	jne	.LBB3_27
.LBB3_35:                               # %.loopexit
	callq	hipDeviceSynchronize
	movl	%eax, %ebx
	movq	64(%rsp), %rsi
	movq	%r12, %rdi
	movq	72(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipHostFree
	movq	128(%rsp), %rdi
	callq	hipHostFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	104(%rsp), %rdi
	callq	hipFree
	movq	96(%rsp), %rdi
	callq	hipFree
	movq	88(%rsp), %rdi
	callq	hipFree
	testl	%ebx, %ebx
	je	.LBB3_37
# %bb.36:
	movl	%ebx, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB3_37:
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z23RecurrentKernelLauncherPKdS0_iiiiiPd, .Lfunc_end3-_Z23RecurrentKernelLauncherPKdS0_iiiiiPd
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23getValidKernalPositionsiiiPKiS0_Pii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z23getValidKernalPositionsiiiPKiS0_Pii,@object # @_Z23getValidKernalPositionsiiiPKiS0_Pii
	.section	.rodata,"a",@progbits
	.globl	_Z23getValidKernalPositionsiiiPKiS0_Pii
	.p2align	3, 0x0
_Z23getValidKernalPositionsiiiPKiS0_Pii:
	.quad	_Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	.size	_Z23getValidKernalPositionsiiiPKiS0_Pii, 8

	.type	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_,@object # @_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.p2align	3, 0x0
_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_:
	.quad	_Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.size	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, 8

	.type	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_,@object # @_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.p2align	3, 0x0
_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_:
	.quad	_Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.size	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"sharedMemory: %i bytes\n"
	.size	.L.str, 24

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"kernel launch failed with error \"%s\".\n"
	.size	.L.str.1, 39

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z23getValidKernalPositionsiiiPKiS0_Pii"
	.size	.L__unnamed_1, 40

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_"
	.size	.L__unnamed_2, 56

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_"
	.size	.L__unnamed_3, 42

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.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 _Z38__device_stub__getValidKernalPositionsiiiPKiS0_Pii
	.addrsig_sym _Z44__device_stub__RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.addrsig_sym _Z30__device_stub__RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z23getValidKernalPositionsiiiPKiS0_Pii
	.addrsig_sym _Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.addrsig_sym _Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z23getValidKernalPositionsiiiPKiS0_Pii ; -- Begin function _Z23getValidKernalPositionsiiiPKiS0_Pii
	.globl	_Z23getValidKernalPositionsiiiPKiS0_Pii
	.p2align	8
	.type	_Z23getValidKernalPositionsiiiPKiS0_Pii,@function
_Z23getValidKernalPositionsiiiPKiS0_Pii: ; @_Z23getValidKernalPositionsiiiPKiS0_Pii
; %bb.0:
	s_clause 0x2
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b128 s[4:7], s[0:1], 0x18
	s_load_b32 s0, s[0:1], 0x28
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s3, s10, s10
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
	s_ashr_i32 s2, s3, 31
	v_add_nc_u32_e32 v0, s0, v0
	s_add_i32 s11, s3, s2
	s_ashr_i32 s0, s10, 31
	s_xor_b32 s11, s11, s2
	v_cvt_f32_u32_e32 v1, s11
	s_sub_i32 s1, 0, s11
	v_ashrrev_i32_e32 v3, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	v_add_nc_u32_e32 v4, v0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v4, v4, v3
	v_xor_b32_e32 v3, s2, v3
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_mul_lo_u32 v2, s1, v1
	s_add_i32 s1, s10, s0
	s_xor_b32 s0, s1, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_sub_i32 s1, 0, s0
	v_mul_hi_u32 v2, v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, v1, v2
	v_mul_hi_u32 v1, v4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v2, v1, s11
	v_sub_nc_u32_e32 v2, v4, v2
	v_add_nc_u32_e32 v4, 1, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v5, s11, v2
	v_cmp_le_u32_e32 vcc_lo, s11, v2
	v_dual_cndmask_b32 v2, v2, v5 :: v_dual_cndmask_b32 v1, v1, v4
	v_cvt_f32_u32_e32 v5, s0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_le_u32_e32 vcc_lo, s11, v2
	v_add_nc_u32_e32 v4, 1, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v2, v5
	v_cndmask_b32_e32 v1, v1, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v1, v1, v3
	v_sub_nc_u32_e32 v4, v1, v3
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v2
	v_mul_lo_u32 v2, v4, s3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v3, v1
	v_mul_lo_u32 v5, s1, v3
	s_mul_i32 s1, s9, s9
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v0, v0, v2
	s_mul_i32 s2, s1, s8
	s_mov_b32 s8, exec_lo
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v2, v3, v5
	v_add_nc_u32_e32 v5, v0, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, v3, v2
	v_xor_b32_e32 v3, v5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v2, v3, v2
	v_mul_lo_u32 v2, v2, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v2, v3, v2
	v_subrev_nc_u32_e32 v3, s0, v2
	v_cmp_le_u32_e32 vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v2, v2, v3, vcc_lo
	v_subrev_nc_u32_e32 v3, s0, v2
	v_cmp_le_u32_e32 vcc_lo, s0, v2
	s_lshr_b32 s0, s10, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	s_add_i32 s0, s10, s0
	v_cndmask_b32_e32 v2, v2, v3, vcc_lo
	s_ashr_i32 s0, s0, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v2, v2, v1
	v_sub_nc_u32_e32 v2, v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v2, v0, s0, v2
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v2, v[2:3], off
	v_add_nc_u32_e32 v3, s2, v4
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v2, v2, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, s2, v2
	v_cmpx_le_i32_e64 s2, v2
	s_cbranch_execz .LBB0_10
; %bb.1:
	s_add_i32 s2, s2, s1
	s_mov_b32 s1, -1
	s_mov_b32 s10, exec_lo
	v_cmpx_gt_i32_e64 s2, v2
	s_cbranch_execz .LBB0_9
; %bb.2:
	v_mov_b32_e32 v4, 0
	s_mov_b32 s1, exec_lo
	v_cmpx_le_i32_e64 s9, v2
	s_cbranch_execz .LBB0_4
; %bb.3:
	s_ashr_i32 s0, s9, 31
	v_subrev_nc_u32_e32 v5, s9, v2
	s_add_i32 s2, s9, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_xor_b32 s2, s2, s0
	v_ashrrev_i32_e32 v7, 31, v5
	v_cvt_f32_u32_e32 v4, s2
	s_sub_i32 s0, 0, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, v5, v7
	v_rcp_iflag_f32_e32 v4, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v5, v5, v7
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v4, 0x4f7ffffe, v4
	v_cvt_u32_f32_e32 v4, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v6, s0, v4
	v_mul_hi_u32 v6, v4, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v4, v4, v6
	v_mul_hi_u32 v4, v5, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v4, v4, s2
	v_sub_nc_u32_e32 v4, v5, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_subrev_nc_u32_e32 v5, s2, v4
	v_cmp_le_u32_e64 s0, s2, v4
	v_cndmask_b32_e64 v4, v4, v5, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_subrev_nc_u32_e32 v5, s2, v4
	v_cmp_le_u32_e64 s0, s2, v4
	v_cndmask_b32_e64 v4, v4, v5, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v4, v4, v7
	v_sub_nc_u32_e32 v4, v7, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v4, v2, v4
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s1
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v8, s9, v4
	v_add_co_u32 v5, s0, s4, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v6, s0, s5, v6, s0
	global_load_b32 v2, v[5:6], off
	v_mad_u64_u32 v[6:7], null, v3, s3, v[0:1]
	v_ashrrev_i32_e32 v7, 31, v6
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v5, v2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[1:2], 2, v[6:7]
	v_cmp_gt_i32_e64 s0, v4, v5
	v_cmp_le_i32_e64 s1, v8, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v1, s2, s6, v1
	v_add_co_ci_u32_e64 v2, s2, s7, v2, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s0, s0, s1
	s_and_saveexec_b32 s1, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s0, exec_lo, s1
	s_cbranch_execz .LBB0_6
; %bb.5:
	v_mov_b32_e32 v4, -1
                                        ; implicit-def: $vgpr5
	global_store_b32 v[1:2], v4, off
                                        ; implicit-def: $vgpr1_vgpr2
.LBB0_6:                                ; %Flow
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB0_8
; %bb.7:
	global_store_b32 v[1:2], v5, off
.LBB0_8:                                ; %Flow88
	s_or_b32 exec_lo, exec_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s1, exec_lo, -1
.LBB0_9:                                ; %Flow90
	s_or_b32 exec_lo, exec_lo, s10
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	s_and_not1_b32 s0, vcc_lo, exec_lo
	s_and_b32 s1, s1, exec_lo
	s_or_b32 vcc_lo, s0, s1
.LBB0_10:                               ; %Flow89
	s_or_b32 exec_lo, exec_lo, s8
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB0_12
; %bb.11:
	v_mad_u64_u32 v[1:2], null, v3, s3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_mov_b32_e32 v2, -1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23getValidKernalPositionsiiiPKiS0_Pii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 44
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 9
		.amdhsa_next_free_sgpr 12
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z23getValidKernalPositionsiiiPKiS0_Pii, .Lfunc_end0-_Z23getValidKernalPositionsiiiPKiS0_Pii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1008
; NumSgprs: 14
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 14
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_ ; -- Begin function _Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
	.p2align	8
	.type	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_,@function
_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_: ; @_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
; %bb.0:
	s_clause 0x3
	s_load_b32 s2, s[0:1], 0x20
	s_load_b32 s11, s[0:1], 0x0
	s_load_b32 s8, s[0:1], 0x18
	s_load_b128 s[4:7], s[0:1], 0x38
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[4:5], null, s2, s11, v[0:1]
	s_cmp_gt_i32 s8, 0
	s_mov_b32 s2, 0
	s_cbranch_scc1 .LBB1_2
; %bb.1:                                ; %.._crit_edge51_crit_edge
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[0:1], 3, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	global_load_b64 v[0:1], v[0:1], off
	s_branch .LBB1_3
.LBB1_2:
	s_mov_b32 s2, -1
                                        ; implicit-def: $vgpr0_vgpr1
.LBB1_3:                                ; %Flow76
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB1_12
; %bb.4:                                ; %.lr.ph50
	s_clause 0x1
	s_load_b32 s9, s[0:1], 0x28
	s_load_b64 s[2:3], s[0:1], 0x48
	v_ashrrev_i32_e32 v5, 31, v4
	s_load_b64 s[0:1], s[0:1], 0x10
	v_mov_b32_e32 v11, 0
	s_mov_b32 s10, 0
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[0:1], 3, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s12, s9, s9
	v_add_co_u32 v8, vcc_lo, s2, v0
	v_mul_lo_u32 v16, s12, v4
	v_add_co_ci_u32_e32 v9, vcc_lo, s3, v1, vcc_lo
	s_cmp_lg_u32 s9, 0
	s_mul_i32 s11, s12, s11
	s_cselect_b32 s9, -1, 0
	s_max_u32 s12, s12, 1
.LBB1_5:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_7 Depth 2
                                        ;       Child Loop BB1_9 Depth 3
	s_and_not1_b32 vcc_lo, exec_lo, s9
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccnz .LBB1_11
; %bb.6:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB1_5 Depth=1
	s_mov_b32 s13, 0
.LBB1_7:                                ; %.lr.ph
                                        ;   Parent Loop BB1_5 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB1_9 Depth 3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, s13, v16
	s_mov_b32 s14, exec_lo
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v10, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmpx_lt_i32_e32 -1, v10
	s_cbranch_execz .LBB1_10
; %bb.8:                                ;   in Loop: Header=BB1_7 Depth=2
	s_add_i32 s16, s13, s11
	global_load_b64 v[19:20], v[6:7], off
	s_ashr_i32 s17, s16, 31
	v_lshlrev_b64 v[2:3], 3, v[10:11]
	s_lshl_b64 s[16:17], s[16:17], 3
	s_mov_b32 s15, 0
	s_add_u32 s16, s0, s16
	s_addc_u32 s17, s1, s17
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_u32 v12, vcc_lo, s2, v2
	global_load_b64 v[0:1], v11, s[16:17]
	v_add_co_ci_u32_e32 v13, vcc_lo, s3, v3, vcc_lo
	global_load_b64 v[2:3], v[12:13], off
	s_waitcnt vmcnt(1)
	v_div_scale_f64 v[14:15], null, 0x40590000, 0x40590000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[17:18], v[14:15]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[21:22], -v[14:15], v[17:18], 1.0
	v_fma_f64 v[17:18], v[17:18], v[21:22], v[17:18]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[21:22], -v[14:15], v[17:18], 1.0
	v_fma_f64 v[17:18], v[17:18], v[21:22], v[17:18]
	v_div_scale_f64 v[21:22], vcc_lo, v[0:1], 0x40590000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[23:24], v[21:22], v[17:18]
	v_fma_f64 v[14:15], -v[14:15], v[23:24], v[21:22]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[14:15], v[14:15], v[17:18], v[23:24]
	v_div_fixup_f64 v[0:1], v[14:15], 0x40590000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f64 v[14:15], v[19:20], v[0:1]
.LBB1_9:                                ; %atomicrmw.start
                                        ;   Parent Loop BB1_5 Depth=1
                                        ;     Parent Loop BB1_7 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[0:1], v[2:3], v[14:15]
	global_atomic_cmpswap_b64 v[0:1], v[12:13], v[0:3], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u64_e32 vcc_lo, v[0:1], v[2:3]
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v2, v0
	s_or_b32 s15, vcc_lo, s15
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s15
	s_cbranch_execnz .LBB1_9
.LBB1_10:                               ; %Flow72
                                        ;   in Loop: Header=BB1_7 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
	s_add_i32 s13, s13, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s13, s12
	s_cbranch_scc0 .LBB1_7
.LBB1_11:                               ; %._crit_edge
                                        ;   in Loop: Header=BB1_5 Depth=1
	s_barrier
	buffer_gl0_inv
	global_load_b64 v[0:1], v[8:9], off
	s_add_i32 s10, s10, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s10, s8
	s_waitcnt vmcnt(0)
	global_store_b64 v[6:7], v[0:1], off
	s_cbranch_scc0 .LBB1_5
.LBB1_12:                               ; %Flow77
	s_waitcnt vmcnt(0)
	v_max_f64 v[0:1], v[0:1], v[0:1]
	v_lshlrev_b64 v[2:3], 3, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_max_f64 v[0:1], v[0:1], 0
	global_store_b64 v[2:3], v[0:1], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 80
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 25
		.amdhsa_next_free_sgpr 18
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_, .Lfunc_end1-_Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 720
; NumSgprs: 20
; NumVgprs: 25
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 25
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_ ; -- Begin function _Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.globl	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
	.p2align	8
	.type	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_,@function
_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_: ; @_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
; %bb.0:
	s_clause 0x2
	s_load_b64 s[10:11], s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x38
	s_load_b32 s8, s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s3, s11, s11
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v1, s3
	s_sub_i32 s2, 0, s3
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v1, v1
	v_mul_lo_u32 v2, s2, v1
	s_load_b32 s2, s[0:1], 0x18
	s_mul_i32 s9, s10, s8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v2, v1, v2
	v_add_nc_u32_e32 v1, v1, v2
	s_waitcnt lgkmcnt(0)
	s_cmp_gt_i32 s2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v1, v0, v1
	v_mul_lo_u32 v2, v1, s3
	v_add_nc_u32_e32 v3, 1, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v2, v0, v2
	v_subrev_nc_u32_e32 v4, s3, v2
	v_cmp_le_u32_e32 vcc_lo, s3, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v2, v2, v4 :: v_dual_cndmask_b32 v1, v1, v3
	v_cmp_le_u32_e32 vcc_lo, s3, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, 1, v1
	v_cndmask_b32_e32 v1, v1, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[4:5], null, s9, s10, v[1:2]
	s_mov_b32 s9, 0
	v_ashrrev_i32_e32 v5, 31, v4
	s_cbranch_scc1 .LBB2_2
; %bb.1:                                ; %.._crit_edge_crit_edge
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[4:5]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b64 v[2:3], v[2:3], off
	s_branch .LBB2_3
.LBB2_2:
	s_mov_b32 s9, -1
                                        ; implicit-def: $vgpr2_vgpr3
.LBB2_3:                                ; %Flow70
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s9
	s_cbranch_vccnz .LBB2_9
; %bb.4:                                ; %.lr.ph
	v_mul_lo_u32 v1, v1, s3
	v_lshlrev_b64 v[12:13], 3, v[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v0, v0, v1
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[1:2], null, v4, s3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v2, vcc_lo
	s_load_b64 s[4:5], s[0:1], 0x10
	global_load_b32 v1, v[1:2], off
	v_mov_b32_e32 v2, 0
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[6:7], null, s3, s8, v[0:1]
	s_load_b64 s[8:9], s[0:1], 0x48
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	v_cmp_lt_i32_e64 s0, -1, v1
	s_mov_b32 s1, 0
	v_ashrrev_i32_e32 v7, 31, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[8:9], 3, v[6:7]
	v_add_co_u32 v6, vcc_lo, s6, v12
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v13, vcc_lo
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v8, vcc_lo, s4, v8
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v9, vcc_lo, s5, v9, vcc_lo
	v_add_co_u32 v10, vcc_lo, s8, v2
	v_add_co_ci_u32_e32 v11, vcc_lo, s9, v3, vcc_lo
	v_add_co_u32 v12, vcc_lo, s8, v12
	v_add_co_ci_u32_e32 v13, vcc_lo, s9, v13, vcc_lo
.LBB2_5:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB2_7 Depth 2
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s3, s0
	s_cbranch_execz .LBB2_8
; %bb.6:                                ;   in Loop: Header=BB2_5 Depth=1
	global_load_b64 v[0:1], v[8:9], off
	global_load_b64 v[18:19], v[6:7], off
	global_load_b64 v[2:3], v[10:11], off
	s_mov_b32 s4, 0
	s_waitcnt vmcnt(2)
	v_div_scale_f64 v[14:15], null, 0x40590000, 0x40590000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[16:17], v[14:15]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[20:21], -v[14:15], v[16:17], 1.0
	v_fma_f64 v[16:17], v[16:17], v[20:21], v[16:17]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[20:21], -v[14:15], v[16:17], 1.0
	v_fma_f64 v[16:17], v[16:17], v[20:21], v[16:17]
	v_div_scale_f64 v[20:21], vcc_lo, v[0:1], 0x40590000, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[22:23], v[20:21], v[16:17]
	v_fma_f64 v[14:15], -v[14:15], v[22:23], v[20:21]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[14:15], v[14:15], v[16:17], v[22:23]
	v_div_fixup_f64 v[0:1], v[14:15], 0x40590000, v[0:1]
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f64 v[14:15], v[18:19], v[0:1]
.LBB2_7:                                ; %atomicrmw.start
                                        ;   Parent Loop BB2_5 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[0:1], v[2:3], v[14:15]
	global_atomic_cmpswap_b64 v[0:1], v[10:11], v[0:3], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u64_e32 vcc_lo, v[0:1], v[2:3]
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v2, v0
	s_or_b32 s4, vcc_lo, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s4
	s_cbranch_execnz .LBB2_7
.LBB2_8:                                ; %Flow68
                                        ;   in Loop: Header=BB2_5 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_barrier
	buffer_gl0_inv
	global_load_b64 v[2:3], v[12:13], off
	s_add_i32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s1, s2
	s_waitcnt vmcnt(0)
	global_store_b64 v[6:7], v[2:3], off
	s_cbranch_scc0 .LBB2_5
.LBB2_9:                                ; %Flow71
	s_waitcnt vmcnt(0)
	v_max_f64 v[0:1], v[2:3], v[2:3]
	v_lshlrev_b64 v[2:3], 3, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_max_f64 v[0:1], v[0:1], 0
	global_store_b64 v[2:3], v[0:1], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 80
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 24
		.amdhsa_next_free_sgpr 12
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end2:
	.size	_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_, .Lfunc_end2-_Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 832
; NumSgprs: 14
; NumVgprs: 24
; ScratchSize: 0
; MemoryBound: 1
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 14
; NumVGPRsForWavesPerEU: 24
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 44
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23getValidKernalPositionsiiiPKiS0_Pii
    .private_segment_fixed_size: 0
    .sgpr_count:     14
    .sgpr_spill_count: 0
    .symbol:         _Z23getValidKernalPositionsiiiPKiS0_Pii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         56
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         64
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         72
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 80
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z29RecurrentKernel_splitThreadediPKdS0_iiiiiPKiPiPdS4_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     25
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         56
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         64
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         72
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 80
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_
    .private_segment_fixed_size: 0
    .sgpr_count:     14
    .sgpr_spill_count: 0
    .symbol:         _Z15RecurrentKerneliPKdS0_iiiiiPKiPiPdS4_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     24
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
