#include <iostream>
#include <cuda_runtime.h>
#include <cooperative_groups.h>
#include <cmath>

namespace cg = cooperative_groups;

#define BLOCK_SIZE 16
#define FILTER_SIZE 15
#define PADDING (FILTER_SIZE / 2)

// Kernel to apply Gabor filter using cooperative groups
__global__ void gaborFilterKernel(const float* input, float* output, int width, int height, const float* filter) {
    cg::thread_block cta = cg::this_thread_block();
    cg::thread_block_tile<32> tile32 = cg::tiled_partition<32>(cta);

    __shared__ float tile_data[BLOCK_SIZE + 2 * PADDING][BLOCK_SIZE + 2 * PADDING];

    int tx = threadIdx.x, ty = threadIdx.y;
    int bx = blockIdx.x, by = blockIdx.y;

    int row = by * BLOCK_SIZE + ty - PADDING;
    int col = bx * BLOCK_SIZE + tx - PADDING;

    // Load data into shared memory with halo
    if (row >= 0 && row < height && col >= 0 && col < width) {
        tile_data[ty + PADDING][tx + PADDING] = input[row * width + col];
    } else {
        tile_data[ty + PADDING][tx + PADDING] = 0.0f;
    }

    // Synchronize to ensure all data is loaded
    tile32.sync();

    // Load halo data into shared memory
    if (tx < PADDING) {
        if (col - PADDING >= 0 && row >= 0 && row < height) {
            tile_data[ty + PADDING][tx] = input[row * width + (col - PADDING)];
        } else {
            tile_data[ty + PADDING][tx] = 0.0f;
        }
    }
    if (tx >= BLOCK_SIZE) {
        if (col + BLOCK_SIZE < width && row >= 0 && row < height) {
            tile_data[ty + PADDING][tx + PADDING + 1] = input[row * width + (col + BLOCK_SIZE)];
        } else {
            tile_data[ty + PADDING][tx + PADDING + 1] = 0.0f;
        }
    }
    if (ty < PADDING) {
        if (row - PADDING >= 0 && col >= 0 && col < width) {
            tile_data[ty][tx + PADDING] = input[(row - PADDING) * width + col];
        } else {
            tile_data[ty][tx + PADDING] = 0.0f;
        }
    }
    if (ty >= BLOCK_SIZE) {
        if (row + BLOCK_SIZE < height && col >= 0 && col < width) {
            tile_data[ty + PADDING + 1][tx + PADDING] = input[(row + BLOCK_SIZE) * width + col];
        } else {
            tile_data[ty + PADDING + 1][tx + PADDING] = 0.0f;
        }
    }

    // Synchronize to ensure all halo data is loaded
    tile32.sync();

    // Apply Gabor filter
    float result = 0.0f;
    if (ty < BLOCK_SIZE && tx < BLOCK_SIZE && row >= 0 && row < height && col >= 0 && col < width) {
        for (int fty = 0; fty < FILTER_SIZE; ++fty) {
            for (int ftx = 0; ftx < FILTER_SIZE; ++ftx) {
                result += tile_data[ty + fty][tx + ftx] * filter[fty * FILTER_SIZE + ftx];
            }
        }
        output[row * width + col] = result;
    }
}

int main() {
    int width = 256, height = 256;
    size_t size = width * height * sizeof(float);

    // Allocate and initialize input data
    float* h_input = new float[width * height];
    for (int i = 0; i < width * height; ++i) {
        h_input[i] = static_cast<float>(i % 256) / 255.0f;
    }

    // Allocate and initialize filter data
    float* h_filter = new float[FILTER_SIZE * FILTER_SIZE];
    float sigma = 2.0f, theta = 0.0f, lambd = 10.0f, gamma = 0.5f, psi = 0.0f;
    float sigma_x = sigma, sigma_y = sigma / gamma;
    float cos_theta = cos(theta), sin_theta = sin(theta);

    for (int y = -PADDING; y <= PADDING; ++y) {
        for (int x = -PADDING; x <= PADDING; ++x) {
            float x_theta = x * cos_theta + y * sin_theta;
            float y_theta = -x * sin_theta + y * cos_theta;
            h_filter[(y + PADDING) * FILTER_SIZE + (x + PADDING)] = exp(-(x_theta * x_theta / (2 * sigma_x * sigma_x) + y_theta * y_theta / (2 * sigma_y * sigma_y))) * cos(2 * M_PI * x_theta / lambd + psi);
        }
    }

    // Allocate device memory
    float* d_input, *d_output, *d_filter;
    cudaMalloc(&d_input, size);
    cudaMalloc(&d_output, size);
    cudaMalloc(&d_filter, FILTER_SIZE * FILTER_SIZE * sizeof(float));

    // Copy data to device
    cudaMemcpy(d_input, h_input, size, cudaMemcpyHostToDevice);
    cudaMemcpy(d_filter, h_filter, FILTER_SIZE * FILTER_SIZE * sizeof(float), cudaMemcpyHostToDevice);

    // Launch kernel
    dim3 threadsPerBlock(BLOCK_SIZE, BLOCK_SIZE);
    dim3 blocksPerGrid((width + BLOCK_SIZE - 1) / BLOCK_SIZE, (height + BLOCK_SIZE - 1) / BLOCK_SIZE);
    gaborFilterKernel<<<blocksPerGrid, threadsPerBlock>>>(d_input, d_output, width, height, d_filter);

    // Check for errors in kernel launch
    cudaError_t err = cudaGetLastError();
    if (err != cudaSuccess) {
        std::cerr << "CUDA error: " << cudaGetErrorString(err) << std::endl;
        return -1;
    }

    // Copy result back to host
    float* h_output = new float[width * height];
    cudaMemcpy(h_output, d_output, size, cudaMemcpyDeviceToHost);

    // Free device memory
    cudaFree(d_input);
    cudaFree(d_output);
    cudaFree(d_filter);

    // Free host memory
    delete[] h_input;
    delete[] h_filter;
    delete[] h_output;

    std::cout << "Gabor filter applied successfully." << std::endl;
    return 0;
}
	.file	"tmpxft_00027352_00000000-6_cuda_code_113804.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB6835:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE6835:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_
	.type	_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_, @function
_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_:
.LFB6857:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z17gaborFilterKernelPKfPfiiS0_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6857:
	.size	_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_, .-_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_
	.globl	_Z17gaborFilterKernelPKfPfiiS0_
	.type	_Z17gaborFilterKernelPKfPfiiS0_, @function
_Z17gaborFilterKernelPKfPfiiS0_:
.LFB6858:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_
	.cfi_endproc
.LFE6858:
	.size	_Z17gaborFilterKernelPKfPfiiS0_, .-_Z17gaborFilterKernelPKfPfiiS0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC8:
	.string	"CUDA error: "
.LC9:
	.string	"Gabor filter applied successfully."
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB6832:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$262144, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	movss	.LC0(%rip), %xmm1
	movq	%rax, %rbp
	xorl	%eax, %eax
.L9:
	movzbl	%al, %edx
	cvtsi2ssl	%edx, %xmm0
	divss	%xmm1, %xmm0
	movss	%xmm0, 0(%rbp,%rax,4)
	incq	%rax
	cmpq	$65536, %rax
	jne	.L9
	movl	$900, %edi
	movl	$-7, %r13d
	call	_Znam@PLT
	movq	%rax, %rbx
	leaq	-420(%rax), %r14
.L10:
	cvtsi2ssl	%r13d, %xmm3
	xorps	%xmm0, %xmm0
	movq	$-7, %r12
	mulss	%xmm3, %xmm0
	movss	%xmm0, (%rsp)
.L11:
	movl	%r12d, %eax
	xorps	%xmm0, %xmm0
	movss	%xmm3, 12(%rsp)
	negl	%eax
	cvtsi2ssl	%r12d, %xmm1
	addss	(%rsp), %xmm1
	cvtsi2ssl	%eax, %xmm2
	movss	%xmm1, 8(%rsp)
	mulss	%xmm0, %xmm2
	movaps	%xmm1, %xmm0
	mulss	%xmm1, %xmm0
	mulss	.LC2(%rip), %xmm0
	addss	%xmm3, %xmm2
	mulss	%xmm2, %xmm2
	mulss	.LC3(%rip), %xmm2
	addss	%xmm2, %xmm0
	xorps	.LC4(%rip), %xmm0
	call	expf@PLT
	movss	8(%rsp), %xmm1
	movss	%xmm0, 4(%rsp)
	cvtss2sd	%xmm1, %xmm0
	mulsd	.LC5(%rip), %xmm0
	xorps	%xmm1, %xmm1
	divsd	.LC6(%rip), %xmm0
	addsd	%xmm1, %xmm0
	call	cos@PLT
	movss	4(%rsp), %xmm2
	movss	12(%rsp), %xmm3
	movaps	%xmm0, %xmm1
	cvtss2sd	%xmm2, %xmm0
	mulsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 448(%r14,%r12,4)
	incq	%r12
	cmpq	$8, %r12
	jne	.L11
	incl	%r13d
	addq	$60, %r14
	cmpl	$8, %r13d
	jne	.L10
	leaq	24(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$900, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$900, %edx
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$68719476752, %rdi
	movl	$1, %esi
	movq	%rdi, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	movq	40(%rsp), %r8
	movq	32(%rsp), %rsi
	movl	$256, %ecx
	movl	$256, %edx
	movq	24(%rsp), %rdi
	call	_Z45__device_stub__Z17gaborFilterKernelPKfPfiiS0_PKfPfiiS0_
.L13:
	call	cudaGetLastError@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L14
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	orl	$-1, %eax
	jmp	.L8
.L14:
	movl	$262144, %edi
	call	_Znam@PLT
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movl	$262144, %edx
	movq	%rax, %rdi
	movq	%rax, %r12
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	leaq	.LC9(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	xorl	%eax, %eax
.L8:
	movq	72(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$80, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6832:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z17gaborFilterKernelPKfPfiiS0_"
.LC11:
	.string	"_ZN50_INTERNAL_d70b8835_19_cuda_code_113804_cu_f7680d7c4cuda3std3__419piecewise_constructE"
.LC12:
	.string	"_ZN50_INTERNAL_d70b8835_19_cuda_code_113804_cu_f7680d7c4cuda3std6ranges3__45__cpo4swapE"
.LC13:
	.string	"_ZN50_INTERNAL_d70b8835_19_cuda_code_113804_cu_f7680d7c4cuda3std6ranges3__45__cpo9iter_moveE"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB6860:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z17gaborFilterKernelPKfPfiiS0_(%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	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC11(%rip), %rdx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__419piecewise_constructE(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC12(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std6ranges3__45__cpo4swapE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$1, %r9d
	movq	%rdx, %rcx
	leaq	_ZN4cuda3std6ranges3__45__cpo9iter_moveE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r8
	.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
.LFE6860:
	.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
	.weak	_ZN4cuda3std3__419piecewise_constructE
	.section	.rodata._ZN4cuda3std3__419piecewise_constructE,"aG",@progbits,_ZN4cuda3std3__419piecewise_constructE,comdat
	.type	_ZN4cuda3std3__419piecewise_constructE, @gnu_unique_object
	.size	_ZN4cuda3std3__419piecewise_constructE, 1
_ZN4cuda3std3__419piecewise_constructE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo9iter_moveE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo9iter_moveE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo9iter_moveE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo9iter_moveE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo9iter_moveE, 1
_ZN4cuda3std6ranges3__45__cpo9iter_moveE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo4swapE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo4swapE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo4swapE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo4swapE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo4swapE, 1
_ZN4cuda3std6ranges3__45__cpo4swapE:
	.zero	1
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1132396544
	.align 4
.LC2:
	.long	1040187392
	.align 4
.LC3:
	.long	1023410176
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC4:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC5:
	.long	1413754136
	.long	1075388923
	.align 8
.LC6:
	.long	0
	.long	1076101120
	.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 <iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_cooperative_groups.h>
#include <cmath>

namespace cg = cooperative_groups;

#define BLOCK_SIZE 16
#define FILTER_SIZE 15
#define PADDING (FILTER_SIZE / 2)

// Kernel to apply Gabor filter using cooperative groups
__global__ void gaborFilterKernel(const float* input, float* output, int width, int height, const float* filter) {
    cg::thread_block cta = cg::this_thread_block();
    cg::thread_block_tile<32> tile32 = cg::tiled_partition<32>(cta);

    __shared__ float tile_data[BLOCK_SIZE + 2 * PADDING][BLOCK_SIZE + 2 * PADDING];

    int tx = threadIdx.x, ty = threadIdx.y;
    int bx = blockIdx.x, by = blockIdx.y;

    int row = by * BLOCK_SIZE + ty - PADDING;
    int col = bx * BLOCK_SIZE + tx - PADDING;

    // Load data into shared memory with halo
    if (row >= 0 && row < height && col >= 0 && col < width) {
        tile_data[ty + PADDING][tx + PADDING] = input[row * width + col];
    } else {
        tile_data[ty + PADDING][tx + PADDING] = 0.0f;
    }

    // Synchronize to ensure all data is loaded
    tile32.sync();

    // Load halo data into shared memory
    if (tx < PADDING) {
        if (col - PADDING >= 0 && row >= 0 && row < height) {
            tile_data[ty + PADDING][tx] = input[row * width + (col - PADDING)];
        } else {
            tile_data[ty + PADDING][tx] = 0.0f;
        }
    }
    if (tx >= BLOCK_SIZE) {
        if (col + BLOCK_SIZE < width && row >= 0 && row < height) {
            tile_data[ty + PADDING][tx + PADDING + 1] = input[row * width + (col + BLOCK_SIZE)];
        } else {
            tile_data[ty + PADDING][tx + PADDING + 1] = 0.0f;
        }
    }
    if (ty < PADDING) {
        if (row - PADDING >= 0 && col >= 0 && col < width) {
            tile_data[ty][tx + PADDING] = input[(row - PADDING) * width + col];
        } else {
            tile_data[ty][tx + PADDING] = 0.0f;
        }
    }
    if (ty >= BLOCK_SIZE) {
        if (row + BLOCK_SIZE < height && col >= 0 && col < width) {
            tile_data[ty + PADDING + 1][tx + PADDING] = input[(row + BLOCK_SIZE) * width + col];
        } else {
            tile_data[ty + PADDING + 1][tx + PADDING] = 0.0f;
        }
    }

    // Synchronize to ensure all halo data is loaded
    tile32.sync();

    // Apply Gabor filter
    float result = 0.0f;
    if (ty < BLOCK_SIZE && tx < BLOCK_SIZE && row >= 0 && row < height && col >= 0 && col < width) {
        for (int fty = 0; fty < FILTER_SIZE; ++fty) {
            for (int ftx = 0; ftx < FILTER_SIZE; ++ftx) {
                result += tile_data[ty + fty][tx + ftx] * filter[fty * FILTER_SIZE + ftx];
            }
        }
        output[row * width + col] = result;
    }
}

int main() {
    int width = 256, height = 256;
    size_t size = width * height * sizeof(float);

    // Allocate and initialize input data
    float* h_input = new float[width * height];
    for (int i = 0; i < width * height; ++i) {
        h_input[i] = static_cast<float>(i % 256) / 255.0f;
    }

    // Allocate and initialize filter data
    float* h_filter = new float[FILTER_SIZE * FILTER_SIZE];
    float sigma = 2.0f, theta = 0.0f, lambd = 10.0f, gamma = 0.5f, psi = 0.0f;
    float sigma_x = sigma, sigma_y = sigma / gamma;
    float cos_theta = cos(theta), sin_theta = sin(theta);

    for (int y = -PADDING; y <= PADDING; ++y) {
        for (int x = -PADDING; x <= PADDING; ++x) {
            float x_theta = x * cos_theta + y * sin_theta;
            float y_theta = -x * sin_theta + y * cos_theta;
            h_filter[(y + PADDING) * FILTER_SIZE + (x + PADDING)] = exp(-(x_theta * x_theta / (2 * sigma_x * sigma_x) + y_theta * y_theta / (2 * sigma_y * sigma_y))) * cos(2 * M_PI * x_theta / lambd + psi);
        }
    }

    // Allocate device memory
    float* d_input, *d_output, *d_filter;
    hipMalloc(&d_input, size);
    hipMalloc(&d_output, size);
    hipMalloc(&d_filter, FILTER_SIZE * FILTER_SIZE * sizeof(float));

    // Copy data to device
    hipMemcpy(d_input, h_input, size, hipMemcpyHostToDevice);
    hipMemcpy(d_filter, h_filter, FILTER_SIZE * FILTER_SIZE * sizeof(float), hipMemcpyHostToDevice);

    // Launch kernel
    dim3 threadsPerBlock(BLOCK_SIZE, BLOCK_SIZE);
    dim3 blocksPerGrid((width + BLOCK_SIZE - 1) / BLOCK_SIZE, (height + BLOCK_SIZE - 1) / BLOCK_SIZE);
    gaborFilterKernel<<<blocksPerGrid, threadsPerBlock>>>(d_input, d_output, width, height, d_filter);

    // Check for errors in kernel launch
    hipError_t err = hipGetLastError();
    if (err != hipSuccess) {
        std::cerr << "CUDA error: " << hipGetErrorString(err) << std::endl;
        return -1;
    }

    // Copy result back to host
    float* h_output = new float[width * height];
    hipMemcpy(h_output, d_output, size, hipMemcpyDeviceToHost);

    // Free device memory
    hipFree(d_input);
    hipFree(d_output);
    hipFree(d_filter);

    // Free host memory
    delete[] h_input;
    delete[] h_filter;
    delete[] h_output;

    std::cout << "Gabor filter applied successfully." << std::endl;
    return 0;
}
	.text
	.file	"cuda_code_113804.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z32__device_stub__gaborFilterKernelPKfPfiiS0_ # -- Begin function _Z32__device_stub__gaborFilterKernelPKfPfiiS0_
	.type	_Z32__device_stub__gaborFilterKernelPKfPfiiS0_,@function
_Z32__device_stub__gaborFilterKernelPKfPfiiS0_: # @_Z32__device_stub__gaborFilterKernelPKfPfiiS0_
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	4(%rsp), %rsi
	movl	%edx, (%rsi)
	movq	%rsp, %rdx
	movl	%ecx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z17gaborFilterKernelPKfPfiiS0_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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	_Z32__device_stub__gaborFilterKernelPKfPfiiS0_, .Lfunc_end0-_Z32__device_stub__gaborFilterKernelPKfPfiiS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x437f0000                      # float 255
.LCPI1_1:
	.long	0x3e000000                      # float 0.125
.LCPI1_2:
	.long	0x3d000000                      # float 0.03125
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI1_3:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_4:
	.quad	0x401921fb54442d18              # double 6.2831853071795862
.LCPI1_5:
	.quad	0x4024000000000000              # double 10
.LCPI1_6:
	.quad	0x0000000000000000              # double 0
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	$262144, %edi                   # imm = 0x40000
	callq	_Znam
	movq	%rax, %rbx
	xorl	%eax, %eax
	movss	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movzbl	%al, %ecx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ecx, %xmm1
	divss	%xmm0, %xmm1
	movss	%xmm1, (%rbx,%rax,4)
	incq	%rax
	cmpq	$65536, %rax                    # imm = 0x10000
	jne	.LBB1_1
# %bb.2:
	movl	$900, %edi                      # imm = 0x384
	callq	_Znam
	movq	%rax, %r14
	movq	$-7, %r15
	xorps	%xmm1, %xmm1
	movss	.LCPI1_1(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movss	.LCPI1_2(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movaps	.LCPI1_3(%rip), %xmm4           # xmm4 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	movq	%rax, %r12
.LBB1_3:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	movss	%xmm0, 24(%rsp)                 # 4-byte Spill
	mulss	%xmm1, %xmm0
	movss	%xmm0, 20(%rsp)                 # 4-byte Spill
	movl	$7, %ebp
	xorl	%r13d, %r13d
.LBB1_4:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	-7(%r13), %eax
	xorps	%xmm5, %xmm5
	cvtsi2ss	%eax, %xmm5
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebp, %xmm0
	addss	20(%rsp), %xmm5                 # 4-byte Folded Reload
	movss	%xmm5, 28(%rsp)                 # 4-byte Spill
	mulss	%xmm1, %xmm0
	addss	24(%rsp), %xmm0                 # 4-byte Folded Reload
	movaps	%xmm5, %xmm1
	mulss	%xmm5, %xmm1
	mulss	%xmm2, %xmm1
	mulss	%xmm0, %xmm0
	mulss	%xmm3, %xmm0
	addss	%xmm1, %xmm0
	xorps	%xmm4, %xmm0
	cvtss2sd	%xmm0, %xmm0
	callq	exp
	movsd	%xmm0, 48(%rsp)                 # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtss2sd	28(%rsp), %xmm0                 # 4-byte Folded Reload
	mulsd	.LCPI1_4(%rip), %xmm0
	divsd	.LCPI1_5(%rip), %xmm0
	addsd	.LCPI1_6(%rip), %xmm0
	callq	cos
	movaps	.LCPI1_3(%rip), %xmm4           # xmm4 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	movss	.LCPI1_2(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movss	.LCPI1_1(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	mulsd	48(%rsp), %xmm0                 # 8-byte Folded Reload
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	decl	%ebp
	cmpq	$15, %r13
	jne	.LBB1_4
# %bb.5:                                #   in Loop: Header=BB1_3 Depth=1
	incq	%r15
	addq	$60, %r12
	cmpq	$8, %r15
	jne	.LBB1_3
# %bb.6:
	leaq	40(%rsp), %r15
	movl	$262144, %esi                   # imm = 0x40000
	movq	%r15, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	leaq	32(%rsp), %r12
	movl	$900, %esi                      # imm = 0x384
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r12), %rdi
	movl	$900, %edx                      # imm = 0x384
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$68719476752, %rdi              # imm = 0x1000000010
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.7:
	movq	40(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	32(%rsp), %r8
	movl	$256, %edx                      # imm = 0x100
	movl	$256, %ecx                      # imm = 0x100
	callq	_Z32__device_stub__gaborFilterKernelPKfPfiiS0_
.LBB1_8:
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB1_11
# %bb.9:
	movl	%eax, %ebp
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%ebp, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB1_12
# %bb.10:
	movq	%rax, %r14
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB1_13
.LBB1_11:
	movl	$262144, %edi                   # imm = 0x40000
	callq	_Znam
	movq	%rax, %r15
	movq	8(%rsp), %rsi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_ZdaPv
	movq	%r15, %rdi
	callq	_ZdaPv
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$34, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%ebp, %ebp
	jmp	.LBB1_14
.LBB1_12:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB1_13:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movl	$-1, %ebp
.LBB1_14:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	%ebp, %eax
	addq	$56, %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_end1:
	.size	main, .Lfunc_end1-main
	.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17gaborFilterKernelPKfPfiiS0_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z17gaborFilterKernelPKfPfiiS0_,@object # @_Z17gaborFilterKernelPKfPfiiS0_
	.section	.rodata,"a",@progbits
	.globl	_Z17gaborFilterKernelPKfPfiiS0_
	.p2align	3, 0x0
_Z17gaborFilterKernelPKfPfiiS0_:
	.quad	_Z32__device_stub__gaborFilterKernelPKfPfiiS0_
	.size	_Z17gaborFilterKernelPKfPfiiS0_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA error: "
	.size	.L.str, 13

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Gabor filter applied successfully."
	.size	.L.str.1, 35

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z17gaborFilterKernelPKfPfiiS0_"
	.size	.L__unnamed_1, 32

	.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 _Z32__device_stub__gaborFilterKernelPKfPfiiS0_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z17gaborFilterKernelPKfPfiiS0_
	.addrsig_sym _ZSt4cerr
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17gaborFilterKernelPKfPfiiS0_ ; -- Begin function _Z17gaborFilterKernelPKfPfiiS0_
	.globl	_Z17gaborFilterKernelPKfPfiiS0_
	.p2align	8
	.type	_Z17gaborFilterKernelPKfPfiiS0_,@function
_Z17gaborFilterKernelPKfPfiiS0_:        ; @_Z17gaborFilterKernelPKfPfiiS0_
; %bb.0:
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[6:7], s[0:1], 0x10
	v_bfe_u32 v4, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	v_mov_b32_e32 v7, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshl_add_u32 v6, s15, 4, v4
	v_lshl_add_u32 v0, s14, 4, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v1, -7, v6
	v_add_nc_u32_e32 v3, -7, v0
	v_cmp_lt_i32_e32 vcc_lo, 6, v6
	s_and_saveexec_b32 s5, vcc_lo
	s_cbranch_execz .LBB0_4
; %bb.1:
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e64 s2, s7, v1
	v_cmp_gt_i32_e64 s3, s6, v3
	v_cmp_lt_i32_e64 s4, 6, v0
	v_mov_b32_e32 v7, 0
	s_delay_alu instid0(VALU_DEP_3)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_3
; %bb.2:
	v_mul_lo_u32 v2, v1, s6
	v_ashrrev_i32_e32 v8, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v2
	v_add_co_u32 v7, s2, v2, v0
	v_add_co_ci_u32_e64 v8, s2, v9, v8, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_add_co_u32 v7, s2, s8, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v8, s2, s9, v8, s2
	global_load_b32 v7, v[7:8], off offset:-28
.LBB0_3:                                ; %Flow221
	s_or_b32 exec_lo, exec_lo, s3
.LBB0_4:
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s5
	v_lshlrev_b32_e32 v2, 2, v5
	s_mov_b32 s4, exec_lo
	v_mad_u32_u24 v2, 0x78, v4, v2
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v7 offset:868
	s_waitcnt lgkmcnt(0)
	buffer_gl1_inv
	buffer_gl0_inv
	v_cmpx_gt_u32_e32 7, v5
	s_cbranch_execz .LBB0_8
; %bb.5:
	v_cmp_lt_i32_e64 s2, 13, v0
	v_cmp_gt_i32_e64 s3, s7, v1
	v_mov_b32_e32 v7, 0
	s_delay_alu instid0(VALU_DEP_3)
	s_and_b32 s2, s2, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_7
; %bb.6:
	v_mul_lo_u32 v7, v1, s6
	v_ashrrev_i32_e32 v8, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v7
	v_add_co_u32 v7, s2, v0, v7
	v_add_co_ci_u32_e64 v8, s2, v8, v9, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_add_co_u32 v7, s2, s8, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v8, s2, s9, v8, s2
	global_load_b32 v7, v[7:8], off offset:-56
.LBB0_7:                                ; %.sink.split
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v7 offset:840
.LBB0_8:                                ; %Flow220
	s_or_b32 exec_lo, exec_lo, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s4, exec_lo
	v_cmpx_lt_u32_e32 15, v5
	s_cbranch_execz .LBB0_12
; %bb.9:
	v_add_nc_u32_e32 v7, 9, v0
	v_cmp_gt_i32_e64 s3, s7, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e64 s2, s6, v7
	v_mov_b32_e32 v7, 0
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_3) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_11
; %bb.10:
	v_mul_lo_u32 v7, v1, s6
	v_ashrrev_i32_e32 v8, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v7
	v_add_co_u32 v7, s2, v7, v0
	v_add_co_ci_u32_e64 v8, s2, v9, v8, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_add_co_u32 v7, s2, s8, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v8, s2, s9, v8, s2
	global_load_b32 v7, v[7:8], off offset:36
.LBB0_11:                               ; %.sink.split183
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v7 offset:872
.LBB0_12:                               ; %Flow219
	s_or_b32 exec_lo, exec_lo, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s5, exec_lo
	v_cmpx_gt_u32_e32 7, v4
	s_cbranch_execz .LBB0_16
; %bb.13:
	v_cmp_lt_i32_e64 s2, 13, v6
	v_cmp_lt_i32_e64 s3, 6, v0
	v_cmp_gt_i32_e64 s4, s6, v3
	v_mov_b32_e32 v7, 0
	s_delay_alu instid0(VALU_DEP_3)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_15
; %bb.14:
	v_add_nc_u32_e32 v7, -14, v6
	v_ashrrev_i32_e32 v8, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v7, v7, s6
	v_ashrrev_i32_e32 v9, 31, v7
	v_add_co_u32 v7, s2, v7, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v8, s2, v9, v8, s2
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v7, s2, s8, v7
	v_add_co_ci_u32_e64 v8, s2, s9, v8, s2
	global_load_b32 v7, v[7:8], off offset:-28
.LBB0_15:                               ; %.sink.split188
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v7 offset:28
.LBB0_16:                               ; %Flow218
	s_or_b32 exec_lo, exec_lo, s5
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s5, exec_lo
	v_cmpx_lt_u32_e32 15, v4
	s_cbranch_execz .LBB0_20
; %bb.17:
	v_dual_mov_b32 v7, 0 :: v_dual_add_nc_u32 v6, 9, v6
	v_cmp_gt_i32_e64 s3, s6, v3
	v_cmp_lt_i32_e64 s4, 6, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s7, v6
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_19
; %bb.18:
	v_mul_lo_u32 v6, v6, s6
	v_ashrrev_i32_e32 v7, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v8, 31, v6
	v_add_co_u32 v6, s2, v6, v0
	v_add_co_ci_u32_e64 v7, s2, v8, v7, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	v_add_co_u32 v6, s2, s8, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s2, s9, v7, s2
	global_load_b32 v7, v[6:7], off offset:-28
.LBB0_19:                               ; %.sink.split192
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v7 offset:988
.LBB0_20:                               ; %Flow217
	s_or_b32 exec_lo, exec_lo, s5
	v_or_b32_e32 v4, v4, v5
	s_waitcnt lgkmcnt(0)
	buffer_gl1_inv
	buffer_gl0_inv
	v_cmp_gt_u32_e64 s2, 16, v4
	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_27
; %bb.21:
	v_cmp_gt_i32_e32 vcc_lo, s7, v1
	v_cmp_gt_i32_e64 s2, s6, v3
	v_cmp_lt_i32_e64 s3, 6, v0
	s_delay_alu instid0(VALU_DEP_2)
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s2
	s_cbranch_execz .LBB0_27
; %bb.22:                               ; %.preheader.preheader
	s_load_b64 s[0:1], s[0:1], 0x18
	v_mov_b32_e32 v3, 0
	s_mov_b32 s4, 0
.LBB0_23:                               ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_24 Depth 2
	s_waitcnt lgkmcnt(0)
	s_mov_b64 s[2:3], s[0:1]
	s_mov_b32 s5, 0
.LBB0_24:                               ;   Parent Loop BB0_23 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v4, s5, v2
	s_load_b32 s7, s[2:3], 0x0
	s_add_i32 s5, s5, 4
	s_add_u32 s2, s2, 4
	s_addc_u32 s3, s3, 0
	ds_load_b32 v4, v4
	s_cmp_eq_u32 s5, 60
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v3, s7, v4
	s_cbranch_scc0 .LBB0_24
; %bb.25:                               ;   in Loop: Header=BB0_23 Depth=1
	s_add_i32 s4, s4, 1
	v_add_nc_u32_e32 v2, 0x78, v2
	s_add_u32 s0, s0, 60
	s_addc_u32 s1, s1, 0
	s_cmp_eq_u32 s4, 15
	s_cbranch_scc0 .LBB0_23
; %bb.26:
	v_mul_lo_u32 v1, v1, s6
	v_ashrrev_i32_e32 v2, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v4, 31, v1
	v_add_co_u32 v0, vcc_lo, v1, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, v4, v2, vcc_lo
	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, s10, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	global_store_b32 v[0:1], v3, off offset:-28
.LBB0_27:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17gaborFilterKernelPKfPfiiS0_
		.amdhsa_group_segment_fixed_size 3600
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.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_end0:
	.size	_Z17gaborFilterKernelPKfPfiiS0_, .Lfunc_end0-_Z17gaborFilterKernelPKfPfiiS0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1228
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 3600 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
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 3600
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17gaborFilterKernelPKfPfiiS0_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z17gaborFilterKernelPKfPfiiS0_.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
