#include <float.h>
#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
#include <stdio.h>

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }

void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
    if (code != cudaSuccess)
    {
        fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
        if (abort) exit(code);
    }
}

int infTwoExp(int val)
{
    int inf=1;
    while(val>inf) inf<<=1;
    return inf;
}

void getGPULayout(
        int dim0,int dim1,int dim2,
        int* bdim0,int* bdim1,int* bdim2,
        int* tdim0,int* tdim1,int* tdim2
)
{
    (*tdim2)=64;
    if(dim2<(*tdim2)) (*tdim2)=infTwoExp(dim2);
    (*bdim2)=dim2/(*tdim2);
    if(dim2%(*tdim2)>0) (*bdim2)++;

    (*tdim1)=1024/(*tdim2);
    if(dim1<(*tdim1)) (*tdim1)=infTwoExp(dim1);
    (*bdim1)=dim1/(*tdim1);
    if(dim1%(*tdim1)>0) (*bdim1)++;

    (*tdim0)=1024/((*tdim1)*(*tdim2));
    if(dim0<(*tdim0)) (*tdim0)=infTwoExp(dim0);
    (*bdim0)=dim0/(*tdim0);
    if(dim0%(*tdim0)>0) (*bdim0)++;
}

__global__
void findNearestPoint3DIdxKernel(
    float* ref_pts,   // [b,pn1,3]
    float* que_pts,   // [b,pn2,3]
    int* idxs,        // [b,pn2]
    int b,
    int pn1,
    int pn2,
    int exclude_self
)
{
    int bi = threadIdx.x + blockIdx.x*blockDim.x;
    int p2i = threadIdx.y + blockIdx.y*blockDim.y;
    if(p2i>=pn2||bi>=b) return;

    float x2=que_pts[bi*pn2*3+p2i*3];
    float y2=que_pts[bi*pn2*3+p2i*3+1];
    float z2=que_pts[bi*pn2*3+p2i*3+2];
    float min_dist=FLT_MAX;
    int min_idx=0;
    for(int p1i=0;p1i<pn1;p1i++)
    {
        if(exclude_self&&p1i==p2i) continue;
        float x1=ref_pts[bi*pn1*3+p1i*3];
        float y1=ref_pts[bi*pn1*3+p1i*3+1];
        float z1=ref_pts[bi*pn1*3+p1i*3+2];

        float dist=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
        if(dist<min_dist)
        {
            min_dist=dist;
            min_idx=p1i;
        }
    }
    idxs[bi*pn2+p2i]=min_idx;
}
__global__
void findNearestPoint2DIdxKernel(
    float* ref_pts,   // [b,pn1,2]
    float* que_pts,   // [b,pn2,2]
    int* idxs,        // [b,pn2]
    int b,
    int pn1,
    int pn2,
    int exclude_self
)
{
    int bi = threadIdx.x + blockIdx.x*blockDim.x;
    int p2i = threadIdx.y + blockIdx.y*blockDim.y;
    if(p2i>=pn2||bi>=b) return;

    float x2=que_pts[bi*pn2*2+p2i*2];
    float y2=que_pts[bi*pn2*2+p2i*2+1];
    float min_dist=FLT_MAX;
    int min_idx=0;
    for(int p1i=0;p1i<pn1;p1i++)
    {
        if(exclude_self&&p1i==p2i) continue;
        float x1=ref_pts[bi*pn1*2+p1i*2];
        float y1=ref_pts[bi*pn1*2+p1i*2+1];

        float dist=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
        if(dist<min_dist)
        {
            min_dist=dist;
            min_idx=p1i;
        }
    }
    idxs[bi*pn2+p2i]=min_idx;
}

#ifdef __cplusplus
extern "C" {
#endif

void findNearestPointIdxLauncher(
    float* ref_pts,   // [b,pn1,dim]
    float* que_pts,   // [b,pn2,dim]
    int* idxs,        // [b,pn2]
    int b,
    int pn1,
    int pn2,
    int dim,
    int exclude_self
)
{
    float* ref_pts_dev,* que_pts_dev;
    int* idxs_dev;
    gpuErrchk(cudaMalloc(&ref_pts_dev,b*pn1*sizeof(float)*dim))
    gpuErrchk(cudaMalloc(&que_pts_dev,b*pn2*sizeof(float)*dim))
    gpuErrchk(cudaMalloc(&idxs_dev,b*pn2*sizeof(int)))

    gpuErrchk(cudaMemcpy(ref_pts_dev,ref_pts,b*pn1*sizeof(float)*dim,cudaMemcpyHostToDevice))
    gpuErrchk(cudaMemcpy(que_pts_dev,que_pts,b*pn2*sizeof(float)*dim,cudaMemcpyHostToDevice))
    gpuErrchk(cudaMemcpy(idxs_dev,idxs,b*pn2*sizeof(int),cudaMemcpyHostToDevice))

    int bdim0,bdim1,bdim2;
    int tdim0,tdim1,tdim2;

    getGPULayout(b,pn2,1,&bdim0,&bdim1,&bdim2,&tdim0,&tdim1,&tdim2);

    dim3 bdim(bdim0,bdim1,bdim2);
    dim3 tdim(tdim0,tdim1,tdim2);

    if(dim==3)
        findNearestPoint3DIdxKernel<<<bdim,tdim>>>(ref_pts_dev,que_pts_dev,idxs_dev,b,pn1,pn2,exclude_self);
    else
        findNearestPoint2DIdxKernel<<<bdim,tdim>>>(ref_pts_dev,que_pts_dev,idxs_dev,b,pn1,pn2,exclude_self);
    gpuErrchk(cudaGetLastError())

    gpuErrchk(cudaMemcpy(idxs,idxs_dev,b*pn2*sizeof(int),cudaMemcpyDeviceToHost))
    gpuErrchk(cudaFree(ref_pts_dev))
    gpuErrchk(cudaFree(que_pts_dev))
    gpuErrchk(cudaFree(idxs_dev))

}

#ifdef __cplusplus
}
#endif

	.file	"tmpxft_0035c37e_00000000-6_nearest_neighborhood.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"GPUassert: %s %s %d\n"
	.text
	.globl	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L8
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L2
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.globl	_Z9infTwoExpi
	.type	_Z9infTwoExpi, @function
_Z9infTwoExpi:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	$1, %eax
.L13:
	cmpl	%edi, %eax
	jge	.L15
	addl	%eax, %eax
	jmp	.L13
.L15:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9infTwoExpi, .-_Z9infTwoExpi
	.globl	_Z12getGPULayoutiiiPiS_S_S_S_S_
	.type	_Z12getGPULayoutiiiPiS_S_S_S_S_, @function
_Z12getGPULayoutiiiPiS_S_S_S_S_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edx, %r10d
	movl	$64, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	32(%rsp), %rbp
	movq	40(%rsp), %rbx
	movq	48(%rsp), %r11
	cmpl	$63, %edx
	jg	.L18
	movl	$1, %eax
.L17:
	cmpl	%eax, %r10d
	jle	.L18
	addl	%eax, %eax
	jmp	.L17
.L18:
	movl	%eax, (%r11)
	movl	%r10d, %eax
	cltd
	idivl	(%r11)
	movl	%eax, (%r9)
	movl	%eax, %r12d
	movl	%r10d, %eax
	cltd
	idivl	(%r11)
	testl	%edx, %edx
	jle	.L20
	incl	%r12d
	movl	%r12d, (%r9)
.L20:
	movl	$1024, %eax
	cltd
	idivl	(%r11)
	cmpl	%esi, %eax
	jle	.L22
	movl	$1, %eax
.L21:
	cmpl	%eax, %esi
	jle	.L22
	addl	%eax, %eax
	jmp	.L21
.L22:
	movl	%eax, (%rbx)
	movl	%esi, %eax
	cltd
	idivl	(%rbx)
	movl	%eax, (%r8)
	movl	%eax, %r9d
	movl	%esi, %eax
	cltd
	idivl	(%rbx)
	testl	%edx, %edx
	jle	.L24
	incl	%r9d
	movl	%r9d, (%r8)
.L24:
	movl	(%rbx), %esi
	imull	(%r11), %esi
	movl	$1024, %eax
	cltd
	idivl	%esi
	cmpl	%edi, %eax
	jle	.L26
	movl	$1, %eax
.L25:
	cmpl	%eax, %edi
	jle	.L26
	addl	%eax, %eax
	jmp	.L25
.L26:
	movl	%eax, 0(%rbp)
	movl	%edi, %eax
	cltd
	idivl	0(%rbp)
	movl	%eax, (%rcx)
	movl	%eax, %esi
	movl	%edi, %eax
	cltd
	idivl	0(%rbp)
	testl	%edx, %edx
	jle	.L16
	incl	%esi
	movl	%esi, (%rcx)
.L16:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z12getGPULayoutiiiPiS_S_S_S_S_, .-_Z12getGPULayoutiiiPiS_S_S_S_S_
	.globl	_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii
	.type	_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii, @function
_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%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	.L33
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z27findNearestPoint3DIdxKernelPfS_Piiiii(%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
.L33:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii, .-_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii
	.globl	_Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.type	_Z27findNearestPoint3DIdxKernelPfS_Piiiii, @function
_Z27findNearestPoint3DIdxKernelPfS_Piiiii:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii
	.cfi_endproc
.LFE2056:
	.size	_Z27findNearestPoint3DIdxKernelPfS_Piiiii, .-_Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.globl	_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii
	.type	_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii, @function
_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%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	.L38
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z27findNearestPoint2DIdxKernelPfS_Piiiii(%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
.L38:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii, .-_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii
	.globl	_Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.type	_Z27findNearestPoint2DIdxKernelPfS_Piiiii, @function
_Z27findNearestPoint2DIdxKernelPfS_Piiiii:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii
	.cfi_endproc
.LFE2058:
	.size	_Z27findNearestPoint2DIdxKernelPfS_Piiiii, .-_Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.section	.rodata.str1.1
.LC1:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/zju3dv/pvnet/master/lib/utils/extend_utils/src/nearest_neighborhood.cu"
	.text
	.globl	findNearestPointIdxLauncher
	.type	findNearestPointIdxLauncher, @function
findNearestPointIdxLauncher:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%r8d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	imull	%r8d, %r13d
	movl	%r9d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	movslq	%r13d, %r13
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movslq	176(%rsp), %rbp
	movq	%rdi, 16(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 24(%rsp)
	salq	$2, %rbp
	movq	%rdx, 8(%rsp)
	imulq	%rbp, %r13
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$136, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	%ebx, %r8d
	leaq	64(%rsp), %rdi
	imull	%r12d, %r8d
	movslq	%r8d, %r15
	imulq	%r15, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$137, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	0(,%r15,4), %rax
	leaq	72(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, %r15
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$138, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	16(%rsp), %rsi
	movq	56(%rsp), %rdi
	movq	%r13, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$140, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	24(%rsp), %rsi
	movq	64(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$141, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	8(%rsp), %rsi
	movq	72(%rsp), %rdi
	movq	%r15, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$142, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	32(%rsp), %rcx
	movl	$1, %edx
	movl	%r12d, %esi
	pushq	%rdi
	.cfi_remember_state
	.cfi_def_cfa_offset 184
	movl	%ebx, %edi
	leaq	60(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 192
	leaq	64(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 200
	leaq	68(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 208
	leaq	72(%rsp), %r9
	leaq	68(%rsp), %r8
	call	_Z12getGPULayoutiiiPiS_S_S_S_S_
	movl	64(%rsp), %eax
	movl	72(%rsp), %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%eax, 112(%rsp)
	movl	68(%rsp), %eax
	movl	%eax, 116(%rsp)
	movl	76(%rsp), %eax
	movl	%eax, 124(%rsp)
	movl	80(%rsp), %eax
	movl	%eax, 128(%rsp)
	addq	$32, %rsp
	.cfi_def_cfa_offset 176
	movl	52(%rsp), %ecx
	cmpl	$3, 176(%rsp)
	movq	92(%rsp), %rdx
	movq	80(%rsp), %rdi
	jne	.L44
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	pushq	%rsi
	.cfi_def_cfa_offset 184
	movl	192(%rsp), %eax
	movl	%r12d, %r9d
	movl	%r14d, %r8d
	movl	%ebx, %ecx
	pushq	%rax
	.cfi_def_cfa_offset 192
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_Z55__device_stub__Z27findNearestPoint3DIdxKernelPfS_PiiiiiPfS_Piiiii
	jmp	.L50
.L44:
	.cfi_restore_state
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	pushq	%rcx
	.cfi_def_cfa_offset 184
	movl	192(%rsp), %eax
	movl	%r12d, %r9d
	movl	%r14d, %r8d
	movl	%ebx, %ecx
	pushq	%rax
	.cfi_def_cfa_offset 192
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_Z55__device_stub__Z27findNearestPoint2DIdxKernelPfS_PiiiiiPfS_Piiiii
.L50:
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L46:
	call	cudaGetLastError@PLT
	movl	$1, %ecx
	movl	$156, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	72(%rsp), %rsi
	movq	8(%rsp), %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$158, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$159, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$160, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$161, %edx
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	addq	$120, %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
.LFE2030:
	.size	findNearestPointIdxLauncher, .-findNearestPointIdxLauncher
	.section	.rodata.str1.1
.LC2:
	.string	"_Z27findNearestPoint2DIdxKernelPfS_Piiiii"
.LC3:
	.string	"_Z27findNearestPoint3DIdxKernelPfS_Piiiii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC2(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z27findNearestPoint2DIdxKernelPfS_Piiiii(%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	_Z27findNearestPoint3DIdxKernelPfS_Piiiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <float.h>
#include <stdio.h>
#include <hip/hip_runtime.h>

#include <hip/hip_runtime_api.h>
#include <stdio.h>

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }

void gpuAssert(hipError_t code, const char *file, int line, bool abort=true)
{
    if (code != hipSuccess)
    {
        fprintf(stderr,"GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
        if (abort) exit(code);
    }
}

int infTwoExp(int val)
{
    int inf=1;
    while(val>inf) inf<<=1;
    return inf;
}

void getGPULayout(
        int dim0,int dim1,int dim2,
        int* bdim0,int* bdim1,int* bdim2,
        int* tdim0,int* tdim1,int* tdim2
)
{
    (*tdim2)=64;
    if(dim2<(*tdim2)) (*tdim2)=infTwoExp(dim2);
    (*bdim2)=dim2/(*tdim2);
    if(dim2%(*tdim2)>0) (*bdim2)++;

    (*tdim1)=1024/(*tdim2);
    if(dim1<(*tdim1)) (*tdim1)=infTwoExp(dim1);
    (*bdim1)=dim1/(*tdim1);
    if(dim1%(*tdim1)>0) (*bdim1)++;

    (*tdim0)=1024/((*tdim1)*(*tdim2));
    if(dim0<(*tdim0)) (*tdim0)=infTwoExp(dim0);
    (*bdim0)=dim0/(*tdim0);
    if(dim0%(*tdim0)>0) (*bdim0)++;
}

__global__
void findNearestPoint3DIdxKernel(
    float* ref_pts,   // [b,pn1,3]
    float* que_pts,   // [b,pn2,3]
    int* idxs,        // [b,pn2]
    int b,
    int pn1,
    int pn2,
    int exclude_self
)
{
    int bi = threadIdx.x + blockIdx.x*blockDim.x;
    int p2i = threadIdx.y + blockIdx.y*blockDim.y;
    if(p2i>=pn2||bi>=b) return;

    float x2=que_pts[bi*pn2*3+p2i*3];
    float y2=que_pts[bi*pn2*3+p2i*3+1];
    float z2=que_pts[bi*pn2*3+p2i*3+2];
    float min_dist=FLT_MAX;
    int min_idx=0;
    for(int p1i=0;p1i<pn1;p1i++)
    {
        if(exclude_self&&p1i==p2i) continue;
        float x1=ref_pts[bi*pn1*3+p1i*3];
        float y1=ref_pts[bi*pn1*3+p1i*3+1];
        float z1=ref_pts[bi*pn1*3+p1i*3+2];

        float dist=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
        if(dist<min_dist)
        {
            min_dist=dist;
            min_idx=p1i;
        }
    }
    idxs[bi*pn2+p2i]=min_idx;
}
__global__
void findNearestPoint2DIdxKernel(
    float* ref_pts,   // [b,pn1,2]
    float* que_pts,   // [b,pn2,2]
    int* idxs,        // [b,pn2]
    int b,
    int pn1,
    int pn2,
    int exclude_self
)
{
    int bi = threadIdx.x + blockIdx.x*blockDim.x;
    int p2i = threadIdx.y + blockIdx.y*blockDim.y;
    if(p2i>=pn2||bi>=b) return;

    float x2=que_pts[bi*pn2*2+p2i*2];
    float y2=que_pts[bi*pn2*2+p2i*2+1];
    float min_dist=FLT_MAX;
    int min_idx=0;
    for(int p1i=0;p1i<pn1;p1i++)
    {
        if(exclude_self&&p1i==p2i) continue;
        float x1=ref_pts[bi*pn1*2+p1i*2];
        float y1=ref_pts[bi*pn1*2+p1i*2+1];

        float dist=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
        if(dist<min_dist)
        {
            min_dist=dist;
            min_idx=p1i;
        }
    }
    idxs[bi*pn2+p2i]=min_idx;
}

#ifdef __cplusplus
extern "C" {
#endif

void findNearestPointIdxLauncher(
    float* ref_pts,   // [b,pn1,dim]
    float* que_pts,   // [b,pn2,dim]
    int* idxs,        // [b,pn2]
    int b,
    int pn1,
    int pn2,
    int dim,
    int exclude_self
)
{
    float* ref_pts_dev,* que_pts_dev;
    int* idxs_dev;
    gpuErrchk(hipMalloc(&ref_pts_dev,b*pn1*sizeof(float)*dim))
    gpuErrchk(hipMalloc(&que_pts_dev,b*pn2*sizeof(float)*dim))
    gpuErrchk(hipMalloc(&idxs_dev,b*pn2*sizeof(int)))

    gpuErrchk(hipMemcpy(ref_pts_dev,ref_pts,b*pn1*sizeof(float)*dim,hipMemcpyHostToDevice))
    gpuErrchk(hipMemcpy(que_pts_dev,que_pts,b*pn2*sizeof(float)*dim,hipMemcpyHostToDevice))
    gpuErrchk(hipMemcpy(idxs_dev,idxs,b*pn2*sizeof(int),hipMemcpyHostToDevice))

    int bdim0,bdim1,bdim2;
    int tdim0,tdim1,tdim2;

    getGPULayout(b,pn2,1,&bdim0,&bdim1,&bdim2,&tdim0,&tdim1,&tdim2);

    dim3 bdim(bdim0,bdim1,bdim2);
    dim3 tdim(tdim0,tdim1,tdim2);

    if(dim==3)
        findNearestPoint3DIdxKernel<<<bdim,tdim>>>(ref_pts_dev,que_pts_dev,idxs_dev,b,pn1,pn2,exclude_self);
    else
        findNearestPoint2DIdxKernel<<<bdim,tdim>>>(ref_pts_dev,que_pts_dev,idxs_dev,b,pn1,pn2,exclude_self);
    gpuErrchk(hipGetLastError())

    gpuErrchk(hipMemcpy(idxs,idxs_dev,b*pn2*sizeof(int),hipMemcpyDeviceToHost))
    gpuErrchk(hipFree(ref_pts_dev))
    gpuErrchk(hipFree(que_pts_dev))
    gpuErrchk(hipFree(idxs_dev))

}

#ifdef __cplusplus
}
#endif

	.text
	.file	"nearest_neighborhood.hip"
	.globl	_Z9gpuAssert10hipError_tPKcib   # -- Begin function _Z9gpuAssert10hipError_tPKcib
	.type	_Z9gpuAssert10hipError_tPKcib,@function
_Z9gpuAssert10hipError_tPKcib:          # @_Z9gpuAssert10hipError_tPKcib
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	testl	%edi, %edi
	jne	.LBB0_1
.LBB0_2:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
.LBB0_1:
	.cfi_def_cfa_offset 48
	movl	%ecx, %ebp
	movl	%edx, %r14d
	movq	%rsi, %r15
	movl	%edi, %ebx
	movq	stderr(%rip), %r12
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%r12, %rdi
	movq	%rax, %rdx
	movq	%r15, %rcx
	movl	%r14d, %r8d
	xorl	%eax, %eax
	callq	fprintf
	testb	%bpl, %bpl
	je	.LBB0_2
# %bb.3:
	movl	%ebx, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z9gpuAssert10hipError_tPKcib, .Lfunc_end0-_Z9gpuAssert10hipError_tPKcib
	.cfi_endproc
                                        # -- End function
	.globl	_Z9infTwoExpi                   # -- Begin function _Z9infTwoExpi
	.type	_Z9infTwoExpi,@function
_Z9infTwoExpi:                          # @_Z9infTwoExpi
	.cfi_startproc
# %bb.0:
	movl	$1, %ecx
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movl	%ecx, %eax
	leal	(%rax,%rax), %ecx
	cmpl	%edi, %eax
	jl	.LBB1_1
# %bb.2:
                                        # kill: def $eax killed $eax killed $rax
	retq
.Lfunc_end1:
	.size	_Z9infTwoExpi, .Lfunc_end1-_Z9infTwoExpi
	.cfi_endproc
                                        # -- End function
	.globl	_Z12getGPULayoutiiiPiS_S_S_S_S_ # -- Begin function _Z12getGPULayoutiiiPiS_S_S_S_S_
	.type	_Z12getGPULayoutiiiPiS_S_S_S_S_,@function
_Z12getGPULayoutiiiPiS_S_S_S_S_:        # @_Z12getGPULayoutiiiPiS_S_S_S_S_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%edx, %r10d
	movq	48(%rsp), %rbx
	movl	$64, (%rbx)
	movl	$64, %r11d
	cmpl	$63, %edx
	jg	.LBB2_4
# %bb.1:                                # %.preheader42.preheader
	movl	$1, %eax
.LBB2_2:                                # %.preheader42
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %r11d
	leal	(%r11,%r11), %eax
	cmpl	%r10d, %r11d
	jl	.LBB2_2
# %bb.3:                                # %_Z9infTwoExpi.exit
	movl	%r11d, (%rbx)
.LBB2_4:
	movq	40(%rsp), %r14
	movl	%r10d, %eax
	cltd
	idivl	%r11d
	movl	%eax, %r11d
	movl	%eax, (%r9)
	movl	(%rbx), %ebp
	movl	%r10d, %eax
	cltd
	idivl	%ebp
	testl	%edx, %edx
	jle	.LBB2_6
# %bb.5:
	incl	%r11d
	movl	%r11d, (%r9)
	movl	(%rbx), %ebp
.LBB2_6:
	movl	$1024, %eax                     # imm = 0x400
	xorl	%edx, %edx
	idivl	%ebp
	movl	%eax, %r9d
	movl	%eax, (%r14)
	cmpl	%esi, %eax
	jle	.LBB2_10
# %bb.7:                                # %.preheader41.preheader
	movl	$1, %eax
.LBB2_8:                                # %.preheader41
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %r9d
	leal	(%r9,%r9), %eax
	cmpl	%esi, %r9d
	jl	.LBB2_8
# %bb.9:                                # %_Z9infTwoExpi.exit38
	movl	%r9d, (%r14)
.LBB2_10:
	movq	32(%rsp), %r10
	movl	%esi, %eax
	cltd
	idivl	%r9d
	movl	%eax, %r9d
	movl	%eax, (%r8)
	movl	(%r14), %r11d
	movl	%esi, %eax
	cltd
	idivl	%r11d
	testl	%edx, %edx
	jle	.LBB2_12
# %bb.11:
	incl	%r9d
	movl	%r9d, (%r8)
	movl	(%r14), %r11d
.LBB2_12:
	imull	(%rbx), %r11d
	movl	$1024, %eax                     # imm = 0x400
	xorl	%edx, %edx
	idivl	%r11d
	movl	%eax, %esi
	movl	%eax, (%r10)
	cmpl	%edi, %eax
	jle	.LBB2_16
# %bb.13:                               # %.preheader.preheader
	movl	$1, %eax
.LBB2_14:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %esi
	leal	(%rsi,%rsi), %eax
	cmpl	%edi, %esi
	jl	.LBB2_14
# %bb.15:                               # %_Z9infTwoExpi.exit40
	movl	%esi, (%r10)
.LBB2_16:
	movl	%edi, %eax
	cltd
	idivl	%esi
	movl	%eax, %esi
	movl	%eax, (%rcx)
	movl	%edi, %eax
	cltd
	idivl	(%r10)
	testl	%edx, %edx
	jle	.LBB2_18
# %bb.17:
	incl	%esi
	movl	%esi, (%rcx)
.LBB2_18:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z12getGPULayoutiiiPiS_S_S_S_S_, .Lfunc_end2-_Z12getGPULayoutiiiPiS_S_S_S_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii # -- Begin function _Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii
	.type	_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii,@function
_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii: # @_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii
	.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	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%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	$_Z27findNearestPoint3DIdxKernelPfS_Piiiii, %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_end3:
	.size	_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii, .Lfunc_end3-_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii # -- Begin function _Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii
	.type	_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii,@function
_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii: # @_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii
	.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	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%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	$_Z27findNearestPoint2DIdxKernelPfS_Piiiii, %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_end4:
	.size	_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii, .Lfunc_end4-_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii
	.cfi_endproc
                                        # -- End function
	.globl	findNearestPointIdxLauncher     # -- Begin function findNearestPointIdxLauncher
	.type	findNearestPointIdxLauncher,@function
findNearestPointIdxLauncher:            # @findNearestPointIdxLauncher
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r9d, %r12d
	movl	%r9d, 24(%rsp)                  # 4-byte Spill
	movl	%ecx, %ebp
	movq	%rdx, %r15
	movq	%rsi, 64(%rsp)                  # 8-byte Spill
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	movslq	160(%rsp), %r14
	movl	%r8d, 28(%rsp)                  # 4-byte Spill
	movl	%r8d, %eax
	imull	%ecx, %eax
	movslq	%eax, %rbx
	imulq	%r14, %rbx
	movq	%r14, 80(%rsp)                  # 8-byte Spill
	shlq	$2, %rbx
	leaq	56(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$136, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	imull	%ebp, %r12d
	movslq	%r12d, %r13
	shlq	$2, %r13
	movq	%r13, %r12
	imulq	%r14, %r12
	leaq	48(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$137, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$138, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	leaq	56(%rsp), %rax
	movq	(%rax), %rdi
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$140, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	leaq	48(%rsp), %rax
	movq	(%rax), %rdi
	movq	64(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$141, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	movq	(%r14), %rdi
	movq	%r15, 64(%rsp)                  # 8-byte Spill
	movq	%r15, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$142, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	leaq	72(%rsp), %rax
	movq	%rax, 16(%rsp)
	leaq	76(%rsp), %rax
	movq	%rax, 8(%rsp)
	leaq	88(%rsp), %r12
	movq	%r12, (%rsp)
	leaq	100(%rsp), %rbx
	leaq	96(%rsp), %r14
	leaq	92(%rsp), %r15
	movl	%ebp, 32(%rsp)                  # 4-byte Spill
	movl	%ebp, %edi
	movl	24(%rsp), %esi                  # 4-byte Reload
	movl	$1, %edx
	movq	%rbx, %rcx
	movq	%r14, %r8
	movq	%r15, %r9
	callq	_Z12getGPULayoutiiiPiS_S_S_S_S_
	movl	(%rbx), %eax
	movl	(%r15), %esi
	movl	(%r14), %edi
	shlq	$32, %rdi
	orq	%rax, %rdi
	movl	(%r12), %eax
	leaq	72(%rsp), %rcx
	movl	(%rcx), %ecx
	leaq	76(%rsp), %rdx
	movl	(%rdx), %edx
	shlq	$32, %rdx
	orq	%rax, %rdx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	cmpq	$3, 80(%rsp)                    # 8-byte Folded Reload
	jne	.LBB5_3
# %bb.1:
	testl	%eax, %eax
	jne	.LBB5_5
# %bb.2:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	movl	168(%rsp), %eax
	movl	%eax, (%rsp)
	movl	32(%rsp), %ecx                  # 4-byte Reload
	movl	28(%rsp), %r8d                  # 4-byte Reload
	movl	24(%rsp), %r9d                  # 4-byte Reload
	callq	_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii
	jmp	.LBB5_5
.LBB5_3:
	testl	%eax, %eax
	jne	.LBB5_5
# %bb.4:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	movl	168(%rsp), %eax
	movl	%eax, (%rsp)
	movl	32(%rsp), %ecx                  # 4-byte Reload
	movl	28(%rsp), %r8d                  # 4-byte Reload
	movl	24(%rsp), %r9d                  # 4-byte Reload
	callq	_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii
.LBB5_5:
	callq	hipGetLastError
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$156, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	movq	40(%rsp), %rsi
	movq	64(%rsp), %rdi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$158, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	movq	56(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$159, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	movq	48(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$160, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	movq	40(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$161, %edx
	movl	$1, %ecx
	callq	_Z9gpuAssert10hipError_tPKcib
	addq	$104, %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_end5:
	.size	findNearestPointIdxLauncher, .Lfunc_end5-findNearestPointIdxLauncher
	.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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z27findNearestPoint3DIdxKernelPfS_Piiiii, %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	$_Z27findNearestPoint2DIdxKernelPfS_Piiiii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str, 21

	.type	_Z27findNearestPoint3DIdxKernelPfS_Piiiii,@object # @_Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.section	.rodata,"a",@progbits
	.globl	_Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.p2align	3, 0x0
_Z27findNearestPoint3DIdxKernelPfS_Piiiii:
	.quad	_Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii
	.size	_Z27findNearestPoint3DIdxKernelPfS_Piiiii, 8

	.type	_Z27findNearestPoint2DIdxKernelPfS_Piiiii,@object # @_Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.globl	_Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.p2align	3, 0x0
_Z27findNearestPoint2DIdxKernelPfS_Piiiii:
	.quad	_Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii
	.size	_Z27findNearestPoint2DIdxKernelPfS_Piiiii, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/zju3dv/pvnet/master/lib/utils/extend_utils/src/nearest_neighborhood.hip"
	.size	.L.str.1, 134

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z27findNearestPoint3DIdxKernelPfS_Piiiii"
	.size	.L__unnamed_1, 42

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z27findNearestPoint2DIdxKernelPfS_Piiiii"
	.size	.L__unnamed_2, 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 _Z42__device_stub__findNearestPoint3DIdxKernelPfS_Piiiii
	.addrsig_sym _Z42__device_stub__findNearestPoint2DIdxKernelPfS_Piiiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.addrsig_sym _Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z27findNearestPoint3DIdxKernelPfS_Piiiii ; -- Begin function _Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.globl	_Z27findNearestPoint3DIdxKernelPfS_Piiiii
	.p2align	8
	.type	_Z27findNearestPoint3DIdxKernelPfS_Piiiii,@function
_Z27findNearestPoint3DIdxKernelPfS_Piiiii: ; @_Z27findNearestPoint3DIdxKernelPfS_Piiiii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[5:6], null, s15, s3, v[1:2]
	v_mad_u64_u32 v[6:7], null, s14, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s6, v5
	v_cmp_gt_i32_e64 s2, s4, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, vcc_lo
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_8
; %bb.1:
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_mad_u64_u32 v[3:4], null, v6, s6, v[5:6]
	s_cmp_lt_i32 s5, 1
	s_cbranch_scc1 .LBB0_6
; %bb.2:                                ; %.lr.ph
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v0, v3, 1, v3
	v_mul_lo_u32 v4, s5, v6
	s_cmp_lg_u32 s7, 0
	v_mov_b32_e32 v8, 0
	s_cselect_b32 s3, -1, 0
	v_ashrrev_i32_e32 v1, 31, v0
	s_mov_b32 s2, 0
	s_xor_b32 s3, s3, -1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v6, v4, 1, v4
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_mov_b32_e32 v4, 0x7f7fffff
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s10, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	global_load_b96 v[0:2], v[0:1], off
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	v_cmp_ne_u32_e32 vcc_lo, s2, v5
	s_or_b32 s6, s3, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s6
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	v_ashrrev_i32_e32 v7, 31, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[6:7]
	v_add_co_u32 v9, vcc_lo, s8, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v10, vcc_lo, s9, v10, vcc_lo
	global_load_b96 v[9:11], v[9:10], off
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v7, v10, v1
	v_sub_f32_e32 v9, v9, v0
	v_mul_f32_e32 v7, v7, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v7, v9, v9
	v_sub_f32_e32 v9, v11, v2
	v_fmac_f32_e32 v7, v9, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_f32_e32 vcc_lo, v7, v4
	v_cndmask_b32_e32 v4, v4, v7, vcc_lo
	v_cndmask_b32_e64 v8, v8, s2, vcc_lo
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	v_add_nc_u32_e32 v6, 3, v6
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s5, s2
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_7
.LBB0_6:
	v_mov_b32_e32 v8, 0
.LBB0_7:                                ; %Flow95
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[0:1], 2, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v8, off
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z27findNearestPoint3DIdxKernelPfS_Piiiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 12
		.amdhsa_next_free_sgpr 16
		.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	_Z27findNearestPoint3DIdxKernelPfS_Piiiii, .Lfunc_end0-_Z27findNearestPoint3DIdxKernelPfS_Piiiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 440
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z27findNearestPoint2DIdxKernelPfS_Piiiii ; -- Begin function _Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.globl	_Z27findNearestPoint2DIdxKernelPfS_Piiiii
	.p2align	8
	.type	_Z27findNearestPoint2DIdxKernelPfS_Piiiii,@function
_Z27findNearestPoint2DIdxKernelPfS_Piiiii: ; @_Z27findNearestPoint2DIdxKernelPfS_Piiiii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s3, v[1:2]
	v_mad_u64_u32 v[5:6], null, s14, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s6, v2
	v_cmp_gt_i32_e64 s2, s4, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, vcc_lo
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB1_8
; %bb.1:
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_mad_u64_u32 v[0:1], null, v5, s6, v[2:3]
	s_cmp_lt_i32 s5, 1
	s_cbranch_scc1 .LBB1_6
; %bb.2:                                ; %.lr.ph
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b32_e32 v3, 1, v0
	v_mul_lo_u32 v1, s5, v5
	s_cmp_lg_u32 s7, 0
	v_mov_b32_e32 v7, 0
	s_cselect_b32 s3, -1, 0
	v_ashrrev_i32_e32 v4, 31, v3
	s_mov_b32 s2, 0
	s_xor_b32 s3, s3, -1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v5, 1, v1
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	v_mov_b32_e32 v1, 0x7f7fffff
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s10, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s11, v4, vcc_lo
	global_load_b64 v[3:4], v[3:4], off
.LBB1_3:                                ; =>This Inner Loop Header: Depth=1
	v_cmp_ne_u32_e32 vcc_lo, s2, v2
	s_or_b32 s6, s3, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s6
	s_cbranch_execz .LBB1_5
; %bb.4:                                ;   in Loop: Header=BB1_3 Depth=1
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[8:9], 2, v[5:6]
	v_add_co_u32 v8, vcc_lo, s8, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v9, vcc_lo, s9, v9, vcc_lo
	global_load_b64 v[8:9], v[8:9], off
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v6, v9, v4
	v_sub_f32_e32 v8, v8, v3
	v_mul_f32_e32 v6, v6, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v8, v8
	v_cmp_lt_f32_e32 vcc_lo, v6, v1
	v_cndmask_b32_e32 v1, v1, v6, vcc_lo
	v_cndmask_b32_e64 v7, v7, s2, vcc_lo
.LBB1_5:                                ;   in Loop: Header=BB1_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	v_add_nc_u32_e32 v5, 2, v5
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s5, s2
	s_cbranch_scc0 .LBB1_3
	s_branch .LBB1_7
.LBB1_6:
	v_mov_b32_e32 v7, 0
.LBB1_7:                                ; %Flow83
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v7, off
.LBB1_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z27findNearestPoint2DIdxKernelPfS_Piiiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 10
		.amdhsa_next_free_sgpr 16
		.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	_Z27findNearestPoint2DIdxKernelPfS_Piiiii, .Lfunc_end1-_Z27findNearestPoint2DIdxKernelPfS_Piiiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 416
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.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:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .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:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z27findNearestPoint3DIdxKernelPfS_Piiiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z27findNearestPoint3DIdxKernelPfS_Piiiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .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:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z27findNearestPoint2DIdxKernelPfS_Piiiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z27findNearestPoint2DIdxKernelPfS_Piiiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
