#include <iostream>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <vector>
#include <algorithm>

// Define constants for 4K resolution
#define WIDTH 3840
#define HEIGHT 2160
#define CHANNELS 3
#define FRAME_SIZE (WIDTH * HEIGHT * CHANNELS)

// Kernel to process a frame (simple grayscale conversion as an example)
__global__ void processFrameKernel(unsigned char* input, unsigned char* output, int width, int height, int channels) {
    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;

    if (x < width && y < height) {
        int index = (y * width + x) * channels;
        unsigned char r = input[index];
        unsigned char g = input[index + 1];
        unsigned char b = input[index + 2];
        unsigned char gray = static_cast<unsigned char>(0.299f * r + 0.587f * g + 0.114f * b);
        output[index] = gray;
        output[index + 1] = gray;
        output[index + 2] = gray;
    }
}

// Function to initialize CUDA and process frames on multiple GPUs
void processFramesMultiGPU(const std::vector<unsigned char*>& inputFrames, std::vector<unsigned char*>& outputFrames) {
    int deviceCount;
    cudaGetDeviceCount(&deviceCount);

    if (deviceCount == 0) {
        std::cerr << "No CUDA devices found." << std::endl;
        return;
    }

    int framesPerDevice = inputFrames.size() / deviceCount;
    int remainder = inputFrames.size() % deviceCount;

    for (int d = 0; d < deviceCount; ++d) {
        cudaSetDevice(d);

        int startFrame = d * framesPerDevice;
        int endFrame = startFrame + framesPerDevice;
        if (d == deviceCount - 1) {
            endFrame += remainder; // Distribute remaining frames to the last device
        }

        for (int f = startFrame; f < endFrame; ++f) {
            unsigned char* d_input;
            unsigned char* d_output;
            cudaMalloc(&d_input, FRAME_SIZE);
            cudaMalloc(&d_output, FRAME_SIZE);

            cudaMemcpy(d_input, inputFrames[f], FRAME_SIZE, cudaMemcpyHostToDevice);

            dim3 blockSize(16, 16);
            dim3 gridSize((WIDTH + blockSize.x - 1) / blockSize.x, (HEIGHT + blockSize.y - 1) / blockSize.y);

            processFrameKernel<<<gridSize, blockSize>>>(d_input, d_output, WIDTH, HEIGHT, CHANNELS);

            cudaMemcpy(outputFrames[f], d_output, FRAME_SIZE, cudaMemcpyDeviceToHost);

            cudaFree(d_input);
            cudaFree(d_output);
        }
    }
}

int main() {
    // Simulate 4K frames for testing
    const int numFrames = 4; // For demonstration purposes, using 4 frames
    std::vector<unsigned char*> inputFrames(numFrames);
    std::vector<unsigned char*> outputFrames(numFrames);

    for (int i = 0; i < numFrames; ++i) {
        inputFrames[i] = new unsigned char[FRAME_SIZE];
        outputFrames[i] = new unsigned char[FRAME_SIZE];
        // Initialize input frames with some data
        std::fill(inputFrames[i], inputFrames[i] + FRAME_SIZE, static_cast<unsigned char>(i % 256));
    }

    processFramesMultiGPU(inputFrames, outputFrames);

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

    // Clean up
    for (int i = 0; i < numFrames; ++i) {
        delete[] inputFrames[i];
        delete[] outputFrames[i];
    }

    return 0;
}
	.file	"tmpxft_001a99df_00000000-6_cuda_code_046699.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4256:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4256:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii
	.type	_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii, @function
_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii:
.LFB4278:
	.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
	movl	%r8d, 4(%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)
	leaq	4(%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	_Z18processFrameKernelPhS_iii(%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
.LFE4278:
	.size	_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii, .-_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii
	.globl	_Z18processFrameKernelPhS_iii
	.type	_Z18processFrameKernelPhS_iii, @function
_Z18processFrameKernelPhS_iii:
.LFB4279:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii
	.cfi_endproc
.LFE4279:
	.size	_Z18processFrameKernelPhS_iii, .-_Z18processFrameKernelPhS_iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"No CUDA devices found."
	.text
	.globl	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
	.type	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_, @function
_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_:
.LFB4252:
	.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
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	44(%rsp), %edx
	testl	%edx, %edx
	jne	.L9
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	jmp	.L8
.L9:
	movq	8(%rbp), %rax
	subq	0(%rbp), %rax
	movslq	%edx, %rbx
	xorl	%edx, %edx
	sarq	$3, %rax
	xorl	%r12d, %r12d
	divq	%rbx
	xorl	%ebx, %ebx
	movl	%eax, %r15d
	cltq
	movq	%rdx, 24(%rsp)
	salq	$3, %rax
	movq	%rax, 16(%rsp)
	xorl	%eax, %eax
	movq	%rax, (%rsp)
.L11:
	cmpl	%ebx, 44(%rsp)
	jle	.L8
	movl	%ebx, %edi
	call	cudaSetDevice@PLT
	leal	(%r12,%r15), %eax
	movl	%eax, 12(%rsp)
	movl	44(%rsp), %eax
	decl	%eax
	cmpl	%ebx, %eax
	je	.L12
	movl	12(%rsp), %eax
	jmp	.L20
.L12:
	movl	24(%rsp), %eax
	addl	%r15d, %eax
	addl	%r12d, %eax
.L20:
	movl	%eax, 8(%rsp)
	movq	(%rsp), %r13
.L14:
	cmpl	%r12d, 8(%rsp)
	jle	.L21
	leaq	48(%rsp), %rdi
	movl	$24883200, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$24883200, %esi
	call	cudaMalloc@PLT
	movq	0(%rbp), %rax
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movl	$24883200, %edx
	movq	(%rax,%r13), %rsi
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$579820585200, %rax
	movl	$1, %esi
	movabsq	$68719476752, %rdx
	movl	$1, 84(%rsp)
	movq	%rax, %rdi
	movq	%rax, 76(%rsp)
	movq	%rdx, 64(%rsp)
	movl	$1, 72(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movq	56(%rsp), %rsi
	movq	48(%rsp), %rdi
	movl	$3, %r8d
	movl	$2160, %ecx
	movl	$3840, %edx
	call	_Z43__device_stub__Z18processFrameKernelPhS_iiiPhS_iii
.L15:
	movq	(%r14), %rax
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	incl	%r12d
	movl	$24883200, %edx
	movq	(%rax,%r13), %rdi
	addq	$8, %r13
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	jmp	.L14
.L21:
	movq	16(%rsp), %rcx
	movl	12(%rsp), %r12d
	incl	%ebx
	addq	%rcx, (%rsp)
	jmp	.L11
.L8:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$104, %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
.LFE4252:
	.size	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_, .-_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
	.section	.rodata.str1.1
.LC1:
	.string	"_Z18processFrameKernelPhS_iii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4281:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z18processFrameKernelPhS_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4281:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt6vectorIPhSaIS0_EED2Ev,"axG",@progbits,_ZNSt6vectorIPhSaIS0_EED5Ev,comdat
	.align 2
	.weak	_ZNSt6vectorIPhSaIS0_EED2Ev
	.type	_ZNSt6vectorIPhSaIS0_EED2Ev, @function
_ZNSt6vectorIPhSaIS0_EED2Ev:
.LFB4598:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L24
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L24:
	ret
	.cfi_endproc
.LFE4598:
	.size	_ZNSt6vectorIPhSaIS0_EED2Ev, .-_ZNSt6vectorIPhSaIS0_EED2Ev
	.weak	_ZNSt6vectorIPhSaIS0_EED1Ev
	.set	_ZNSt6vectorIPhSaIS0_EED1Ev,_ZNSt6vectorIPhSaIS0_EED2Ev
	.section	.rodata.str1.1
.LC2:
	.string	"CUDA error: "
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4253:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4253
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%esi, %esi
	movl	$32, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	movq	%rsi, 8(%rsp)
	movq	%rsi, 16(%rsp)
	movq	%rsi, 24(%rsp)
.LEHB0:
	call	_Znwm@PLT
.LEHE0:
	xorl	%edi, %edi
	xorl	%r8d, %r8d
	movq	%rdi, (%rax)
	leaq	32(%rax), %rdx
	movq	%rdi, 8(%rax)
	movq	%rdi, 16(%rax)
	movq	%rdi, 24(%rax)
	movl	$32, %edi
	movq	%rax, 8(%rsp)
	movq	%rdx, 24(%rsp)
	movq	%rdx, 16(%rsp)
	movq	%r8, 32(%rsp)
	movq	%r8, 40(%rsp)
	movq	%r8, 48(%rsp)
.LEHB1:
	call	_Znwm@PLT
.LEHE1:
	xorl	%ecx, %ecx
	leaq	32(%rax), %rdx
	movq	%rax, 32(%rsp)
	xorl	%ebx, %ebx
	movq	%rdx, 48(%rsp)
	movq	%rcx, (%rax)
	movq	%rcx, 8(%rax)
	movq	%rcx, 16(%rax)
	movq	%rcx, 24(%rax)
	movq	%rdx, 40(%rsp)
.L27:
	movl	$24883200, %edi
.LEHB2:
	call	_Znam@PLT
	movq	8(%rsp), %rdx
	movl	$24883200, %edi
	movq	%rax, (%rdx,%rbx,8)
	call	_Znam@PLT
	movq	32(%rsp), %rdx
	movl	$24883200, %ecx
	movq	%rax, (%rdx,%rbx,8)
	movq	8(%rsp), %rax
	movq	(%rax,%rbx,8), %rdx
	movl	%ebx, %eax
	incq	%rbx
	movq	%rdx, %rdi
	rep stosb
	cmpq	$4, %rbx
	jne	.L27
	leaq	32(%rsp), %r12
	leaq	8(%rsp), %rbp
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
	call	cudaGetLastError@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L28
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %edi
	movq	%rax, %r13
	call	cudaGetErrorString@PLT
	movq	%rax, %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.LEHE2:
.L28:
	xorl	%ebx, %ebx
.L31:
	movq	8(%rsp), %rax
	movq	(%rax,%rbx), %rdi
	testq	%rdi, %rdi
	je	.L29
	call	_ZdaPv@PLT
.L29:
	movq	32(%rsp), %rax
	movq	(%rax,%rbx), %rdi
	testq	%rdi, %rdi
	je	.L30
	call	_ZdaPv@PLT
.L30:
	addq	$8, %rbx
	cmpq	$32, %rbx
	jne	.L31
	movq	%r12, %rdi
	call	_ZNSt6vectorIPhSaIS0_EED1Ev
	movq	%rbp, %rdi
	call	_ZNSt6vectorIPhSaIS0_EED1Ev
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	jmp	.L49
.L37:
	endbr64
	movq	%rax, %rbx
.L32:
	leaq	32(%rsp), %rdi
	call	_ZNSt6vectorIPhSaIS0_EED1Ev
	jmp	.L33
.L36:
	endbr64
	movq	%rax, %rbx
.L33:
	leaq	8(%rsp), %rdi
	call	_ZNSt6vectorIPhSaIS0_EED1Ev
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L49
	movq	%rbx, %rdi
.LEHB3:
	call	_Unwind_Resume@PLT
.LEHE3:
.L49:
	call	__stack_chk_fail@PLT
.L35:
	addq	$72, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4253:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4253:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4253-.LLSDACSB4253
.LLSDACSB4253:
	.uleb128 .LEHB0-.LFB4253
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB4253
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L36-.LFB4253
	.uleb128 0
	.uleb128 .LEHB2-.LFB4253
	.uleb128 .LEHE2-.LEHB2
	.uleb128 .L37-.LFB4253
	.uleb128 0
	.uleb128 .LEHB3-.LFB4253
	.uleb128 .LEHE3-.LEHB3
	.uleb128 0
	.uleb128 0
.LLSDACSE4253:
	.section	.text.startup
	.size	main, .-main
	.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
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <vector>
#include <algorithm>

// Define constants for 4K resolution
#define WIDTH 3840
#define HEIGHT 2160
#define CHANNELS 3
#define FRAME_SIZE (WIDTH * HEIGHT * CHANNELS)

// Kernel to process a frame (simple grayscale conversion as an example)
__global__ void processFrameKernel(unsigned char* input, unsigned char* output, int width, int height, int channels) {
    int x = blockIdx.x * blockDim.x + threadIdx.x;
    int y = blockIdx.y * blockDim.y + threadIdx.y;

    if (x < width && y < height) {
        int index = (y * width + x) * channels;
        unsigned char r = input[index];
        unsigned char g = input[index + 1];
        unsigned char b = input[index + 2];
        unsigned char gray = static_cast<unsigned char>(0.299f * r + 0.587f * g + 0.114f * b);
        output[index] = gray;
        output[index + 1] = gray;
        output[index + 2] = gray;
    }
}

// Function to initialize CUDA and process frames on multiple GPUs
void processFramesMultiGPU(const std::vector<unsigned char*>& inputFrames, std::vector<unsigned char*>& outputFrames) {
    int deviceCount;
    hipGetDeviceCount(&deviceCount);

    if (deviceCount == 0) {
        std::cerr << "No CUDA devices found." << std::endl;
        return;
    }

    int framesPerDevice = inputFrames.size() / deviceCount;
    int remainder = inputFrames.size() % deviceCount;

    for (int d = 0; d < deviceCount; ++d) {
        hipSetDevice(d);

        int startFrame = d * framesPerDevice;
        int endFrame = startFrame + framesPerDevice;
        if (d == deviceCount - 1) {
            endFrame += remainder; // Distribute remaining frames to the last device
        }

        for (int f = startFrame; f < endFrame; ++f) {
            unsigned char* d_input;
            unsigned char* d_output;
            hipMalloc(&d_input, FRAME_SIZE);
            hipMalloc(&d_output, FRAME_SIZE);

            hipMemcpy(d_input, inputFrames[f], FRAME_SIZE, hipMemcpyHostToDevice);

            dim3 blockSize(16, 16);
            dim3 gridSize((WIDTH + blockSize.x - 1) / blockSize.x, (HEIGHT + blockSize.y - 1) / blockSize.y);

            processFrameKernel<<<gridSize, blockSize>>>(d_input, d_output, WIDTH, HEIGHT, CHANNELS);

            hipMemcpy(outputFrames[f], d_output, FRAME_SIZE, hipMemcpyDeviceToHost);

            hipFree(d_input);
            hipFree(d_output);
        }
    }
}

int main() {
    // Simulate 4K frames for testing
    const int numFrames = 4; // For demonstration purposes, using 4 frames
    std::vector<unsigned char*> inputFrames(numFrames);
    std::vector<unsigned char*> outputFrames(numFrames);

    for (int i = 0; i < numFrames; ++i) {
        inputFrames[i] = new unsigned char[FRAME_SIZE];
        outputFrames[i] = new unsigned char[FRAME_SIZE];
        // Initialize input frames with some data
        std::fill(inputFrames[i], inputFrames[i] + FRAME_SIZE, static_cast<unsigned char>(i % 256));
    }

    processFramesMultiGPU(inputFrames, outputFrames);

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

    // Clean up
    for (int i = 0; i < numFrames; ++i) {
        delete[] inputFrames[i];
        delete[] outputFrames[i];
    }

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

                                        # End of file scope inline assembly
	.globl	_Z33__device_stub__processFrameKernelPhS_iii # -- Begin function _Z33__device_stub__processFrameKernelPhS_iii
	.type	_Z33__device_stub__processFrameKernelPhS_iii,@function
_Z33__device_stub__processFrameKernelPhS_iii: # @_Z33__device_stub__processFrameKernelPhS_iii
	.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	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%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	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z18processFrameKernelPhS_iii, %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	_Z33__device_stub__processFrameKernelPhS_iii, .Lfunc_end0-_Z33__device_stub__processFrameKernelPhS_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_ # -- Begin function _Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
	.type	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_,@function
_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_: # @_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
	.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
	movq	%rsi, %rbx
	movq	%rdi, %r14
	leaq	12(%rsp), %r15
	movq	%r15, %rdi
	callq	hipGetDeviceCount
	movslq	(%r15), %rcx
	testq	%rcx, %rcx
	je	.LBB1_1
# %bb.2:
	movq	8(%r14), %rax
	subq	(%r14), %rax
	sarq	$3, %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	%rax, %r12
	xorl	%eax, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	testl	%ecx, %ecx
	jle	.LBB1_11
# %bb.3:                                # %.lr.ph32.preheader
	movq	%rdx, %rbp
	movabsq	$68719476752, %r15              # imm = 0x1000000010
	xorl	%r13d, %r13d
	movq	%r12, 48(%rsp)                  # 8-byte Spill
	movq	%rdx, 40(%rsp)                  # 8-byte Spill
.LBB1_4:                                # %.lr.ph32
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
	movl	%r13d, %edi
	callq	hipSetDevice
	movl	%r13d, %edx
	imull	%r12d, %edx
	leal	(%rdx,%r12), %esi
	movl	12(%rsp), %eax
	leal	-1(%rax), %ecx
	cmpl	%ecx, %r13d
	movl	$0, %ecx
	cmovel	%ebp, %ecx
	addl	%esi, %ecx
	cmpl	%ecx, %edx
	jge	.LBB1_10
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_4 Depth=1
	movslq	16(%rsp), %rbp                  # 4-byte Folded Reload
	movslq	%ecx, %r12
.LBB1_6:                                # %.lr.ph
                                        #   Parent Loop BB1_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$24883200, %esi                 # imm = 0x17BB000
	leaq	32(%rsp), %rdi
	callq	hipMalloc
	movl	$24883200, %esi                 # imm = 0x17BB000
	leaq	24(%rsp), %rdi
	callq	hipMalloc
	movq	32(%rsp), %rdi
	movq	(%r14), %rax
	movq	(%rax,%rbp,8), %rsi
	movl	$24883200, %edx                 # imm = 0x17BB000
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$579820585200, %rdi             # imm = 0x87000000F0
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.7:                                #   in Loop: Header=BB1_6 Depth=2
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movl	$3840, %edx                     # imm = 0xF00
	movl	$2160, %ecx                     # imm = 0x870
	movl	$3, %r8d
	callq	_Z33__device_stub__processFrameKernelPhS_iii
.LBB1_8:                                #   in Loop: Header=BB1_6 Depth=2
	movq	(%rbx), %rax
	movq	(%rax,%rbp,8), %rdi
	movq	24(%rsp), %rsi
	movl	$24883200, %edx                 # imm = 0x17BB000
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	incq	%rbp
	cmpq	%r12, %rbp
	jl	.LBB1_6
# %bb.9:                                # %._crit_edge.loopexit
                                        #   in Loop: Header=BB1_4 Depth=1
	movl	12(%rsp), %eax
	movq	48(%rsp), %r12                  # 8-byte Reload
	movq	40(%rsp), %rbp                  # 8-byte Reload
.LBB1_10:                               # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=1
	incl	%r13d
	movq	16(%rsp), %rcx                  # 8-byte Reload
	addl	%r12d, %ecx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	cmpl	%eax, %r13d
	jl	.LBB1_4
	jmp	.LBB1_11
.LBB1_1:
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$22, %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
.LBB1_11:                               # %.loopexit
	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	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_, .Lfunc_end1-_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$32, %edi
	callq	_Znwm
	movq	%rax, %rbx
	movq	%rax, 24(%rsp)
	addq	$32, %rax
	movq	%rax, 40(%rsp)
	xorps	%xmm0, %xmm0
	movups	%xmm0, (%rbx)
	movups	%xmm0, 16(%rbx)
	movq	%rax, 32(%rsp)
.Ltmp0:
	movl	$32, %edi
	callq	_Znwm
.Ltmp1:
# %bb.1:
	movq	%rax, %r14
	movq	%rax, (%rsp)
	addq	$32, %rax
	movq	%rax, 16(%rsp)
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%r14)
	movups	%xmm0, (%r14)
	movq	%rax, 8(%rsp)
	xorl	%r15d, %r15d
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
.Ltmp3:
	movl	$24883200, %edi                 # imm = 0x17BB000
	callq	_Znam
.Ltmp4:
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movq	%rax, %r12
	movq	%rax, (%rbx,%r15,8)
.Ltmp5:
	movl	$24883200, %edi                 # imm = 0x17BB000
	callq	_Znam
.Ltmp6:
# %bb.4:                                #   in Loop: Header=BB2_2 Depth=1
	movq	%rax, (%r14,%r15,8)
	movl	$24883200, %edx                 # imm = 0x17BB000
	movq	%r12, %rdi
	movl	%r15d, %esi
	callq	memset@PLT
	incq	%r15
	cmpq	$4, %r15
	jne	.LBB2_2
# %bb.5:
.Ltmp8:
	leaq	24(%rsp), %rdi
	movq	%rsp, %rsi
	callq	_Z21processFramesMultiGPURKSt6vectorIPhSaIS0_EERS2_
.Ltmp9:
# %bb.6:
.Ltmp11:
	callq	hipGetLastError
.Ltmp12:
# %bb.7:
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.LBB2_8
# %bb.15:
.Ltmp13:
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.1, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp14:
# %bb.16:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
.Ltmp15:
	movl	%ebp, %edi
	callq	hipGetErrorString
.Ltmp16:
# %bb.17:
	movq	%rax, %r15
	testq	%rax, %rax
	je	.LBB2_18
# %bb.19:
	movq	%r15, %rdi
	callq	strlen
.Ltmp17:
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp18:
	jmp	.LBB2_20
.LBB2_18:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
.Ltmp19:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp20:
.LBB2_20:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit30
	movq	_ZSt4cerr(%rip), %rax
	movl	$_ZSt4cerr, %edi
	addq	-24(%rax), %rdi
.Ltmp21:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp22:
# %bb.21:                               # %.noexc42
.Ltmp23:
	movsbl	%al, %esi
	movl	$_ZSt4cerr, %edi
	callq	_ZNSo3putEc
.Ltmp24:
# %bb.22:                               # %.noexc43
.Ltmp25:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp26:
.LBB2_8:                                # %_ZNSolsEPFRSoS_E.exit.preheader
	xorl	%r15d, %r15d
.LBB2_9:                                # %_ZNSolsEPFRSoS_E.exit
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r15,8), %rdi
	testq	%rdi, %rdi
	je	.LBB2_11
# %bb.10:                               #   in Loop: Header=BB2_9 Depth=1
	callq	_ZdaPv
.LBB2_11:                               #   in Loop: Header=BB2_9 Depth=1
	movq	(%r14,%r15,8), %rdi
	testq	%rdi, %rdi
	je	.LBB2_13
# %bb.12:                               #   in Loop: Header=BB2_9 Depth=1
	callq	_ZdaPv
.LBB2_13:                               #   in Loop: Header=BB2_9 Depth=1
	incq	%r15
	cmpq	$4, %r15
	jne	.LBB2_9
# %bb.14:                               # %_ZNSt6vectorIPhSaIS0_EED2Ev.exit34
	movq	%r14, %rdi
	callq	_ZdlPv
	movq	%rbx, %rdi
	callq	_ZdlPv
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB2_23:
	.cfi_def_cfa_offset 96
.Ltmp10:
	jmp	.LBB2_26
.LBB2_28:
.Ltmp2:
	movq	%rax, %r15
	jmp	.LBB2_27
.LBB2_24:
.Ltmp27:
	jmp	.LBB2_26
.LBB2_25:
.Ltmp7:
.LBB2_26:                               # %_ZNSt6vectorIPhSaIS0_EED2Ev.exit36
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	_ZdlPv
.LBB2_27:                               # %_ZNSt6vectorIPhSaIS0_EED2Ev.exit38
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	%r15, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp6-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp6
	.uleb128 .Ltmp7-.Lfunc_begin0           #     jumps to .Ltmp7
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp8-.Ltmp6                  #   Call between .Ltmp6 and .Ltmp8
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp8-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Ltmp9-.Ltmp8                  #   Call between .Ltmp8 and .Ltmp9
	.uleb128 .Ltmp10-.Lfunc_begin0          #     jumps to .Ltmp10
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp26-.Ltmp11                #   Call between .Ltmp11 and .Ltmp26
	.uleb128 .Ltmp27-.Lfunc_begin0          #     jumps to .Ltmp27
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp26-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Lfunc_end2-.Ltmp26            #   Call between .Ltmp26 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.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	$_Z18processFrameKernelPhS_iii, %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	_Z18processFrameKernelPhS_iii,@object # @_Z18processFrameKernelPhS_iii
	.section	.rodata,"a",@progbits
	.globl	_Z18processFrameKernelPhS_iii
	.p2align	3, 0x0
_Z18processFrameKernelPhS_iii:
	.quad	_Z33__device_stub__processFrameKernelPhS_iii
	.size	_Z18processFrameKernelPhS_iii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"No CUDA devices found."
	.size	.L.str, 23

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"CUDA error: "
	.size	.L.str.1, 13

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18processFrameKernelPhS_iii"
	.size	.L__unnamed_1, 30

	.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 _Z33__device_stub__processFrameKernelPhS_iii
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z18processFrameKernelPhS_iii
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18processFrameKernelPhS_iii ; -- Begin function _Z18processFrameKernelPhS_iii
	.globl	_Z18processFrameKernelPhS_iii
	.p2align	8
	.type	_Z18processFrameKernelPhS_iii,@function
_Z18processFrameKernelPhS_iii:          ; @_Z18processFrameKernelPhS_iii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b128 s[4:7], s[0:1], 0x10
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s4, v0
	v_cmp_gt_i32_e64 s2, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_mad_u64_u32 v[2:3], null, v1, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v2, v2, s6
	v_ashrrev_i32_e32 v3, 31, v2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v3, vcc_lo
	s_clause 0x1
	global_load_u16 v4, v[0:1], off
	global_load_u8 v0, v[0:1], off offset:2
	s_waitcnt vmcnt(1)
	v_cvt_f32_ubyte1_e32 v1, v4
	v_cvt_f32_ubyte0_e32 v4, v4
	s_waitcnt vmcnt(0)
	v_cvt_f32_ubyte0_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v1, 0x3f1645a2, v1
	v_fmamk_f32 v1, v4, 0x3e991687, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v0, v0, 0x3de978d5, v1
	v_cvt_i32_f32_e32 v4, v0
	v_add_co_u32 v0, vcc_lo, s2, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b16 v5, 8, v4
	v_or_b32_e32 v2, v4, v5
	s_clause 0x1
	global_store_b8 v[0:1], v4, off offset:2
	global_store_b16 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18processFrameKernelPhS_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 6
		.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	_Z18processFrameKernelPhS_iii, .Lfunc_end0-_Z18processFrameKernelPhS_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 292
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18processFrameKernelPhS_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18processFrameKernelPhS_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
