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

using namespace cooperative_groups;

#define BLOCK_SIZE 16
#define IMAGE_SIZE 1024

// Kernel function to perform feature extraction
__global__ void featureExtractionKernel(float* input, float* output) {
    grid_group grid = this_grid();
    thread_block block = this_thread_block();

    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;

    // Shared memory to hold a block of the image
    __shared__ float sharedImage[BLOCK_SIZE][BLOCK_SIZE];

    // Load data into shared memory
    if (x < IMAGE_SIZE && y < IMAGE_SIZE) {
        sharedImage[threadIdx.y][threadIdx.x] = input[y * IMAGE_SIZE + x];
    }
    block.sync();

    // Simple feature extraction: gradient magnitude
    float gradientX = 0.0f, gradientY = 0.0f;
    if (x > 0 && x < IMAGE_SIZE - 1 && y > 0 && y < IMAGE_SIZE - 1) {
        gradientX = sharedImage[threadIdx.y][threadIdx.x + 1] - sharedImage[threadIdx.y][threadIdx.x - 1];
        gradientY = sharedImage[threadIdx.y + 1][threadIdx.x] - sharedImage[threadIdx.y - 1][threadIdx.x];
    }
    block.sync();

    // Calculate gradient magnitude
    float magnitude = sqrtf(gradientX * gradientX + gradientY * gradientY);

    // Store result in global memory
    if (x < IMAGE_SIZE && y < IMAGE_SIZE) {
        output[y * IMAGE_SIZE + x] = magnitude;
    }
}

// Function to check CUDA errors
void checkCudaError(cudaError_t error, const char* message) {
    if (error != cudaSuccess) {
        std::cerr << "CUDA Error: " << message << " - " << cudaGetErrorString(error) << std::endl;
        exit(EXIT_FAILURE);
    }
}

int main() {
    int numGPUs;
    cudaGetDeviceCount(&numGPUs);
    if (numGPUs < 1) {
        std::cerr << "No CUDA-capable devices found." << std::endl;
        return EXIT_FAILURE;
    }

    // Allocate memory for input and output images
    float* h_input = new float[IMAGE_SIZE * IMAGE_SIZE];
    float* h_output = new float[IMAGE_SIZE * IMAGE_SIZE];

    // Initialize input image with random values
    for (int i = 0; i < IMAGE_SIZE * IMAGE_SIZE; ++i) {
        h_input[i] = static_cast<float>(rand()) / RAND_MAX;
    }

    // Allocate device memory
    float* d_input[numGPUs];
    float* d_output[numGPUs];
    for (int i = 0; i < numGPUs; ++i) {
        cudaSetDevice(i);
        checkCudaError(cudaMalloc(&d_input[i], IMAGE_SIZE * IMAGE_SIZE * sizeof(float)), "cudaMalloc d_input");
        checkCudaError(cudaMalloc(&d_output[i], IMAGE_SIZE * IMAGE_SIZE * sizeof(float)), "cudaMalloc d_output");
        checkCudaError(cudaMemcpy(d_input[i], h_input, IMAGE_SIZE * IMAGE_SIZE * sizeof(float), cudaMemcpyHostToDevice), "cudaMemcpy h_input to d_input");
    }

    // Launch kernel on each GPU
    dim3 blockSize(BLOCK_SIZE, BLOCK_SIZE);
    dim3 gridSize((IMAGE_SIZE + BLOCK_SIZE - 1) / BLOCK_SIZE, (IMAGE_SIZE + BLOCK_SIZE - 1) / BLOCK_SIZE);
    for (int i = 0; i < numGPUs; ++i) {
        cudaSetDevice(i);
        featureExtractionKernel<<<gridSize, blockSize>>>(d_input[i], d_output[i]);
        checkCudaError(cudaGetLastError(), "featureExtractionKernel launch");
    }

    // Copy results back to host
    for (int i = 0; i < numGPUs; ++i) {
        cudaSetDevice(i);
        checkCudaError(cudaMemcpy(h_output + i * (IMAGE_SIZE * IMAGE_SIZE / numGPUs), d_output[i], IMAGE_SIZE * IMAGE_SIZE * sizeof(float) / numGPUs, cudaMemcpyDeviceToHost), "cudaMemcpy d_output to h_output");
    }

    // Free device memory
    for (int i = 0; i < numGPUs; ++i) {
        cudaSetDevice(i);
        cudaFree(d_input[i]);
        cudaFree(d_output[i]);
    }

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

    return EXIT_SUCCESS;
}
	.file	"tmpxft_00090cda_00000000-6_cuda_code_059267.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB6836:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE6836:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA Error: "
.LC1:
	.string	" - "
	.text
	.globl	_Z14checkCudaError9cudaErrorPKc
	.type	_Z14checkCudaError9cudaErrorPKc, @function
_Z14checkCudaError9cudaErrorPKc:
.LFB6832:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	leaq	_ZSt4cerr(%rip), %rdi
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %edi
	movq	%rax, %rbp
	call	cudaGetErrorString@PLT
	movq	%rbp, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE6832:
	.size	_Z14checkCudaError9cudaErrorPKc, .-_Z14checkCudaError9cudaErrorPKc
	.globl	_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_
	.type	_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_, @function
_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_:
.LFB6858:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z23featureExtractionKernelPfS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L8:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6858:
	.size	_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_, .-_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_
	.globl	_Z23featureExtractionKernelPfS_
	.type	_Z23featureExtractionKernelPfS_, @function
_Z23featureExtractionKernelPfS_:
.LFB6859:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_
	.cfi_endproc
.LFE6859:
	.size	_Z23featureExtractionKernelPfS_, .-_Z23featureExtractionKernelPfS_
	.section	.rodata.str1.1
.LC2:
	.string	"No CUDA-capable devices found."
.LC4:
	.string	"cudaMalloc d_input"
.LC5:
	.string	"cudaMalloc d_output"
.LC6:
	.string	"cudaMemcpy h_input to d_input"
.LC7:
	.string	"featureExtractionKernel launch"
.LC8:
	.string	"cudaMemcpy d_output to h_output"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB6833:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	leaq	-84(%rbp), %rdi
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$72, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	cudaGetDeviceCount@PLT
	cmpl	$0, -84(%rbp)
	jg	.L14
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %eax
	jmp	.L13
.L14:
	movl	$4194304, %edi
	xorl	%r12d, %r12d
	call	_Znam@PLT
	movl	$4194304, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	movq	%rax, -104(%rbp)
.L16:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC3(%rip), %xmm0
	movss	%xmm0, (%rbx,%r12,4)
	incq	%r12
	cmpq	$1048576, %r12
	jne	.L16
	movslq	-84(%rbp), %rax
	movq	%rsp, %rcx
	leaq	15(,%rax,8), %rax
	movq	%rax, %rsi
	movq	%rax, %rdx
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L17:
	cmpq	%rcx, %rsp
	je	.L18
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L17
.L18:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L19
	orq	$0, -8(%rsp,%rdx)
.L19:
	movq	%rax, %rdx
	movq	%rsp, %rcx
	andq	$-4096, %rax
	movq	%rsp, %r14
	andq	$-16, %rdx
	subq	%rax, %rcx
.L20:
	cmpq	%rcx, %rsp
	je	.L21
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L20
.L21:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L22
	orq	$0, -8(%rsp,%rax)
.L22:
	movq	%rsp, %r12
	movq	%r14, %r13
	xorl	%r8d, %r8d
	movq	%r12, %r15
.L23:
	cmpl	%r8d, -84(%rbp)
	jle	.L41
	movl	%r8d, %edi
	movl	%r8d, -108(%rbp)
	call	cudaSetDevice@PLT
	movq	%r13, %rdi
	movl	$4194304, %esi
	addq	$8, %r13
	call	cudaMalloc@PLT
	leaq	.LC4(%rip), %rsi
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	movq	%r15, %rdi
	movl	$4194304, %esi
	addq	$8, %r15
	call	cudaMalloc@PLT
	leaq	.LC5(%rip), %rsi
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	movq	-8(%r13), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$4194304, %edx
	call	cudaMemcpy@PLT
	leaq	.LC6(%rip), %rsi
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	movl	-108(%rbp), %r8d
	incl	%r8d
	jmp	.L23
.L41:
	movabsq	$68719476752, %rax
	movl	$1, -72(%rbp)
	xorl	%r15d, %r15d
	leaq	.LC7(%rip), %r13
	movq	%rax, -80(%rbp)
	movabsq	$274877907008, %rax
	movq	%rax, -68(%rbp)
	movl	$1, -60(%rbp)
.L25:
	movl	%r15d, %edi
	cmpl	%r15d, -84(%rbp)
	jle	.L42
	call	cudaSetDevice@PLT
	movl	-72(%rbp), %ecx
	movq	-80(%rbp), %rdx
	xorl	%r9d, %r9d
	movq	-68(%rbp), %rdi
	movl	-60(%rbp), %esi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	(%r12,%r15,8), %rsi
	movq	(%r14,%r15,8), %rdi
	call	_Z45__device_stub__Z23featureExtractionKernelPfS_PfS_
.L26:
	call	cudaGetLastError@PLT
	movq	%r13, %rsi
	incq	%r15
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	jmp	.L25
.L42:
	xorl	%r15d, %r15d
	leaq	.LC8(%rip), %r13
.L28:
	movl	%r15d, %edi
	cmpl	%r15d, -84(%rbp)
	jle	.L43
	call	cudaSetDevice@PLT
	movslq	-84(%rbp), %rsi
	movl	$4194304, %eax
	xorl	%edx, %edx
	divq	%rsi
	movq	%rsi, %rcx
	movq	(%r12,%r15,8), %rsi
	movq	%rax, %r8
	movl	$1048576, %eax
	cltd
	idivl	%ecx
	movq	%r8, %rdx
	imull	%r15d, %eax
	incq	%r15
	movslq	%eax, %rcx
	movq	-104(%rbp), %rax
	leaq	(%rax,%rcx,4), %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	%r13, %rsi
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	jmp	.L28
.L43:
	xorl	%r13d, %r13d
.L30:
	movl	%r13d, %edi
	cmpl	%r13d, -84(%rbp)
	jle	.L44
	call	cudaSetDevice@PLT
	movq	(%r14,%r13,8), %rdi
	call	cudaFree@PLT
	movq	(%r12,%r13,8), %rdi
	incq	%r13
	call	cudaFree@PLT
	jmp	.L30
.L44:
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	-104(%rbp), %rdi
	call	_ZdaPv@PLT
	xorl	%eax, %eax
.L13:
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6833:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z23featureExtractionKernelPfS_"
.LC10:
	.string	"_ZN50_INTERNAL_dc24b4ea_19_cuda_code_059267_cu_e35244744cuda3std3__419piecewise_constructE"
.LC11:
	.string	"_ZN50_INTERNAL_dc24b4ea_19_cuda_code_059267_cu_e35244744cuda3std6ranges3__45__cpo4swapE"
.LC12:
	.string	"_ZN50_INTERNAL_dc24b4ea_19_cuda_code_059267_cu_e35244744cuda3std6ranges3__45__cpo9iter_moveE"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB6861:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z23featureExtractionKernelPfS_(%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	.LC10(%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	.LC11(%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	.LC12(%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
.LFE6861:
	.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
.LC3:
	.long	805306368
	.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>

using namespace cooperative_groups;

#define BLOCK_SIZE 16
#define IMAGE_SIZE 1024

// Kernel function to perform feature extraction
__global__ void featureExtractionKernel(float* input, float* output) {
    grid_group grid = this_grid();
    thread_block block = this_thread_block();

    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;

    // Shared memory to hold a block of the image
    __shared__ float sharedImage[BLOCK_SIZE][BLOCK_SIZE];

    // Load data into shared memory
    if (x < IMAGE_SIZE && y < IMAGE_SIZE) {
        sharedImage[threadIdx.y][threadIdx.x] = input[y * IMAGE_SIZE + x];
    }
    block.sync();

    // Simple feature extraction: gradient magnitude
    float gradientX = 0.0f, gradientY = 0.0f;
    if (x > 0 && x < IMAGE_SIZE - 1 && y > 0 && y < IMAGE_SIZE - 1) {
        gradientX = sharedImage[threadIdx.y][threadIdx.x + 1] - sharedImage[threadIdx.y][threadIdx.x - 1];
        gradientY = sharedImage[threadIdx.y + 1][threadIdx.x] - sharedImage[threadIdx.y - 1][threadIdx.x];
    }
    block.sync();

    // Calculate gradient magnitude
    float magnitude = sqrtf(gradientX * gradientX + gradientY * gradientY);

    // Store result in global memory
    if (x < IMAGE_SIZE && y < IMAGE_SIZE) {
        output[y * IMAGE_SIZE + x] = magnitude;
    }
}

// Function to check CUDA errors
void checkCudaError(hipError_t error, const char* message) {
    if (error != hipSuccess) {
        std::cerr << "CUDA Error: " << message << " - " << hipGetErrorString(error) << std::endl;
        exit(EXIT_FAILURE);
    }
}

int main() {
    int numGPUs;
    hipGetDeviceCount(&numGPUs);
    if (numGPUs < 1) {
        std::cerr << "No CUDA-capable devices found." << std::endl;
        return EXIT_FAILURE;
    }

    // Allocate memory for input and output images
    float* h_input = new float[IMAGE_SIZE * IMAGE_SIZE];
    float* h_output = new float[IMAGE_SIZE * IMAGE_SIZE];

    // Initialize input image with random values
    for (int i = 0; i < IMAGE_SIZE * IMAGE_SIZE; ++i) {
        h_input[i] = static_cast<float>(rand()) / RAND_MAX;
    }

    // Allocate device memory
    float* d_input[numGPUs];
    float* d_output[numGPUs];
    for (int i = 0; i < numGPUs; ++i) {
        hipSetDevice(i);
        checkCudaError(hipMalloc(&d_input[i], IMAGE_SIZE * IMAGE_SIZE * sizeof(float)), "hipMalloc d_input");
        checkCudaError(hipMalloc(&d_output[i], IMAGE_SIZE * IMAGE_SIZE * sizeof(float)), "hipMalloc d_output");
        checkCudaError(hipMemcpy(d_input[i], h_input, IMAGE_SIZE * IMAGE_SIZE * sizeof(float), hipMemcpyHostToDevice), "hipMemcpy h_input to d_input");
    }

    // Launch kernel on each GPU
    dim3 blockSize(BLOCK_SIZE, BLOCK_SIZE);
    dim3 gridSize((IMAGE_SIZE + BLOCK_SIZE - 1) / BLOCK_SIZE, (IMAGE_SIZE + BLOCK_SIZE - 1) / BLOCK_SIZE);
    for (int i = 0; i < numGPUs; ++i) {
        hipSetDevice(i);
        featureExtractionKernel<<<gridSize, blockSize>>>(d_input[i], d_output[i]);
        checkCudaError(hipGetLastError(), "featureExtractionKernel launch");
    }

    // Copy results back to host
    for (int i = 0; i < numGPUs; ++i) {
        hipSetDevice(i);
        checkCudaError(hipMemcpy(h_output + i * (IMAGE_SIZE * IMAGE_SIZE / numGPUs), d_output[i], IMAGE_SIZE * IMAGE_SIZE * sizeof(float) / numGPUs, hipMemcpyDeviceToHost), "hipMemcpy d_output to h_output");
    }

    // Free device memory
    for (int i = 0; i < numGPUs; ++i) {
        hipSetDevice(i);
        hipFree(d_input[i]);
        hipFree(d_output[i]);
    }

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

    return EXIT_SUCCESS;
}
	.text
	.file	"cuda_code_059267.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z38__device_stub__featureExtractionKernelPfS_ # -- Begin function _Z38__device_stub__featureExtractionKernelPfS_
	.type	_Z38__device_stub__featureExtractionKernelPfS_,@function
_Z38__device_stub__featureExtractionKernelPfS_: # @_Z38__device_stub__featureExtractionKernelPfS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z23featureExtractionKernelPfS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z38__device_stub__featureExtractionKernelPfS_, .Lfunc_end0-_Z38__device_stub__featureExtractionKernelPfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z14checkCudaError10hipError_tPKc # -- Begin function _Z14checkCudaError10hipError_tPKc
	.type	_Z14checkCudaError10hipError_tPKc,@function
_Z14checkCudaError10hipError_tPKc:      # @_Z14checkCudaError10hipError_tPKc
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB1_2
# %bb.1:
	retq
.LBB1_2:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %r14
	movl	%edi, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebx, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z14checkCudaError10hipError_tPKc, .Lfunc_end1-_Z14checkCudaError10hipError_tPKc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	leaq	-44(%rbp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	jle	.LBB2_1
# %bb.18:
	movl	$4194304, %edi                  # imm = 0x400000
	callq	_Znam
	movq	%rax, %rbx
	movl	$4194304, %edi                  # imm = 0x400000
	callq	_Znam
	movq	%rax, %r12
	xorl	%r14d, %r14d
.LBB2_19:                               # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r14,4)
	incq	%r14
	cmpq	$1048576, %r14                  # imm = 0x100000
	jne	.LBB2_19
# %bb.2:
	movq	%rsp, -72(%rbp)                 # 8-byte Spill
	movl	-44(%rbp), %eax
	movq	%rsp, %rdx
	leaq	15(,%rax,8), %rax
	andq	$-16, %rax
	subq	%rax, %rdx
	movq	%rdx, %rsp
	movl	-44(%rbp), %eax
	movq	%rsp, %r14
	leaq	15(,%rax,8), %rcx
	andq	$-16, %rcx
	subq	%rcx, %r14
	movq	%r14, %rsp
	testl	%eax, %eax
	jle	.LBB2_16
# %bb.3:                                # %.lr.ph.preheader
	movq	%r12, -56(%rbp)                 # 8-byte Spill
	xorl	%r15d, %r15d
	movq	%rdx, -64(%rbp)                 # 8-byte Spill
	movq	%rdx, %r12
	movq	%r14, %r13
.LBB2_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%r15d, %edi
	callq	hipSetDevice
	movl	$4194304, %esi                  # imm = 0x400000
	movq	%r12, %rdi
	callq	hipMalloc
	movl	$.L.str.3, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
	movl	$4194304, %esi                  # imm = 0x400000
	movq	%r13, %rdi
	callq	hipMalloc
	movl	$.L.str.4, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
	movq	(%r12), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.5, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
	incq	%r15
	movslq	-44(%rbp), %rax
	addq	$8, %r13
	addq	$8, %r12
	cmpq	%rax, %r15
	jl	.LBB2_4
# %bb.5:                                # %.preheader44
	testl	%eax, %eax
	movq	-56(%rbp), %r12                 # 8-byte Reload
	jle	.LBB2_16
# %bb.6:                                # %.lr.ph48.preheader
	xorl	%r15d, %r15d
	movabsq	$274877907008, %r12             # imm = 0x4000000040
	movabsq	$68719476752, %r13              # imm = 0x1000000010
.LBB2_7:                                # %.lr.ph48
                                        # =>This Inner Loop Header: Depth=1
	movl	%r15d, %edi
	callq	hipSetDevice
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.8:                                #   in Loop: Header=BB2_7 Depth=1
	movq	-64(%rbp), %rax                 # 8-byte Reload
	movq	(%rax,%r15,8), %rdi
	movq	(%r14,%r15,8), %rsi
	callq	_Z38__device_stub__featureExtractionKernelPfS_
.LBB2_9:                                #   in Loop: Header=BB2_7 Depth=1
	callq	hipGetLastError
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
	incq	%r15
	movslq	-44(%rbp), %rax
	cmpq	%rax, %r15
	jl	.LBB2_7
# %bb.10:                               # %.preheader43
	testl	%eax, %eax
	movq	-56(%rbp), %r12                 # 8-byte Reload
	movq	-64(%rbp), %r13                 # 8-byte Reload
	jle	.LBB2_16
# %bb.11:                               # %.lr.ph50.preheader
	xorl	%r15d, %r15d
.LBB2_12:                               # %.lr.ph50
                                        # =>This Inner Loop Header: Depth=1
	movl	%r15d, %edi
	callq	hipSetDevice
	movslq	-44(%rbp), %rcx
	movl	$1048576, %eax                  # imm = 0x100000
	xorl	%edx, %edx
	idivl	%ecx
	imull	%r15d, %eax
	cltq
	leaq	(%r12,%rax,4), %rdi
	movq	(%r14,%r15,8), %rsi
	movl	$4194304, %eax                  # imm = 0x400000
	xorl	%edx, %edx
	divq	%rcx
	movq	%rax, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.7, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
	incq	%r15
	movslq	-44(%rbp), %rax
	cmpq	%rax, %r15
	jl	.LBB2_12
# %bb.13:                               # %.preheader
	testl	%eax, %eax
	jle	.LBB2_16
# %bb.14:                               # %.lr.ph52.preheader
	xorl	%r15d, %r15d
.LBB2_15:                               # %.lr.ph52
                                        # =>This Inner Loop Header: Depth=1
	movl	%r15d, %edi
	callq	hipSetDevice
	movq	(%r13,%r15,8), %rdi
	callq	hipFree
	movq	(%r14,%r15,8), %rdi
	callq	hipFree
	incq	%r15
	movslq	-44(%rbp), %rax
	cmpq	%rax, %r15
	jl	.LBB2_15
.LBB2_16:                               # %._crit_edge
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r12, %rdi
	callq	_ZdaPv
	xorl	%eax, %eax
	movq	-72(%rbp), %rsp                 # 8-byte Reload
	jmp	.LBB2_17
.LBB2_1:
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.2, %esi
	movl	$30, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cerr, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$1, %eax
.LBB2_17:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23featureExtractionKernelPfS_, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z23featureExtractionKernelPfS_,@object # @_Z23featureExtractionKernelPfS_
	.section	.rodata,"a",@progbits
	.globl	_Z23featureExtractionKernelPfS_
	.p2align	3, 0x0
_Z23featureExtractionKernelPfS_:
	.quad	_Z38__device_stub__featureExtractionKernelPfS_
	.size	_Z23featureExtractionKernelPfS_, 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	" - "
	.size	.L.str.1, 4

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"No CUDA-capable devices found."
	.size	.L.str.2, 31

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"hipMalloc d_input"
	.size	.L.str.3, 18

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipMalloc d_output"
	.size	.L.str.4, 19

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipMemcpy h_input to d_input"
	.size	.L.str.5, 29

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"featureExtractionKernel launch"
	.size	.L.str.6, 31

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"hipMemcpy d_output to h_output"
	.size	.L.str.7, 31

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z23featureExtractionKernelPfS_"
	.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 _Z38__device_stub__featureExtractionKernelPfS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z23featureExtractionKernelPfS_
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z23featureExtractionKernelPfS_ ; -- Begin function _Z23featureExtractionKernelPfS_
	.globl	_Z23featureExtractionKernelPfS_
	.p2align	8
	.type	_Z23featureExtractionKernelPfS_,@function
_Z23featureExtractionKernelPfS_:        ; @_Z23featureExtractionKernelPfS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v2, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s5, s4, 16
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[3:4], null, s14, s4, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[4:5], null, s15, s5, v[2:3]
	v_lshlrev_b32_e32 v5, 2, v1
	v_max_i32_e32 v0, v4, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, 0x400, v0
	v_lshl_add_u32 v0, v4, 10, v3
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[6:7], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v6, s0, s0, v6
	v_add_co_ci_u32_e64 v7, s0, s1, v7, s0
	global_load_b32 v1, v[6:7], off
	v_lshl_add_u32 v6, v2, 6, v5
	s_waitcnt vmcnt(0)
	ds_store_b32 v6, v1
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s4
	v_add_nc_u32_e32 v1, -1, v3
	v_add_nc_u32_e32 v3, -1, v4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_max_u32_e32 v3, v3, v1
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e64 s0, 0x3fe, v3
	v_mov_b32_e32 v3, 0
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_lshl_add_u32 v1, v2, 6, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v3, -4, v1
	v_subrev_nc_u32_e32 v4, 64, v1
	ds_load_2addr_b32 v[1:2], v1 offset0:1 offset1:16
	ds_load_b32 v3, v3
	ds_load_b32 v4, v4
	s_waitcnt lgkmcnt(1)
	v_sub_f32_e32 v3, v1, v3
	s_waitcnt lgkmcnt(0)
	v_sub_f32_e32 v1, v2, v4
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s1
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB0_6
; %bb.5:
	v_mul_f32_e32 v2, v3, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v2, v1, v1
	v_mul_f32_e32 v1, 0x4f800000, v2
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v2, v2, v1, vcc_lo
	v_sqrt_f32_e32 v1, v2
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v3, -1, v1
	v_add_nc_u32_e32 v4, 1, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v5, -v3, v1, v2
	v_fma_f32 v6, -v4, v1, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s0, 0, v5
	v_cndmask_b32_e64 v1, v1, v3, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s0, 0, v6
	v_cndmask_b32_e64 v3, v1, v4, s0
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v4, 0x37800000, v3
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v3, v3, v4, vcc_lo
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v2, 0x260
	v_cndmask_b32_e32 v2, v3, v2, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23featureExtractionKernelPfS_
		.amdhsa_group_segment_fixed_size 1024
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 8
		.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	_Z23featureExtractionKernelPfS_, .Lfunc_end0-_Z23featureExtractionKernelPfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 520
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; 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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23featureExtractionKernelPfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z23featureExtractionKernelPfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
