#include <cuda.h>
#include <stdlib.h>
#include <stdio.h>
#include <cuda_profiler_api.h>
#include <tuple>
#include <iostream>
#include <string.h>

double time_host = 0;
double time_device = 0;

int sample_rounds = 10;

void meanFilter_host(unsigned char* image_matrix,unsigned char* filtered_image_data,int image_width, int image_height, int window_size)
{
    int half_window = (window_size-window_size % 2)/2;
	
    for(int i = 0; i < image_height; i += 1){
        for(int j = 0; j < image_width; j += 1){
            int k = 3*(i*image_height+j);
            int top_boundary;
			int bottom_boundary;
			int left_boundary;
			int right_boundary; 
            if(i-half_window >= 0){
				top_boundary = i-half_window;
			}else{
				top_boundary = 0;
			}
            if(i+half_window <= image_height-1){
				bottom_boundary = i+half_window;
			}else{
				bottom_boundary = image_height-1;
			}
            if(j-half_window >= 0){
				left_boundary = j-half_window;
			}else{
				left_boundary = 0;
			}
            if(j+half_window <= image_width-1){
				right_boundary = j+half_window;
			}else{
				right_boundary = image_width-1;
			}
            double byte1 = 0; 
            double byte2 = 0; 
            double byte3 = 0; 
            
            for(int x = top_boundary; x <= bottom_boundary; x++){
                for(int y = left_boundary; y <= right_boundary; y++){
                    int pos = 3*(x*image_height + y); 
                    byte1 += image_matrix[pos];
                    byte2 += image_matrix[pos+1];
                    byte3 += image_matrix[pos+2];
                }
            }
            int effective_window_size = (bottom_boundary-top_boundary+1)*(right_boundary-left_boundary+1);
            filtered_image_data[k] = byte1/effective_window_size;
            filtered_image_data[k+1] = byte2/effective_window_size;
            filtered_image_data[k+2] = byte3/effective_window_size;

            
        }
    }
   
}

__global__ void meanFilter_device(unsigned char* image_matrix, unsigned char* filtered_image_data, int image_width, int image_height, int window_size)
{
    int j = blockIdx.x * blockDim.x + threadIdx.x;
    int i = blockIdx.y * blockDim.y + threadIdx.y;
	int half_window = (window_size-window_size % 2)/2;
	
    if (i < image_height && j < image_width){
        int k = 3*(i*image_height+j);
        int top_boundary;
		int bottom_boundary;
		int left_boundary;
		int right_boundary; 
        if(i-half_window >= 0){
			top_boundary = i-half_window;
		}else{
			top_boundary = 0;
		}
        if(i+half_window <= image_height-1){
			bottom_boundary = i+half_window;
		}else{
			bottom_boundary = image_height-1;
		}
        if(j-half_window >= 0){
			left_boundary = j-half_window;
		}else{
			left_boundary = 0;
		}
        if(j+half_window <= image_width-1){
			right_boundary = j+half_window;
		}else{
			right_boundary = image_width-1;
		}
        double byte1 = 0; 
        double byte2 = 0; 
        double byte3 = 0; 
       
        for(int x = top_boundary; x <= bottom_boundary; x++){
            for(int y = left_boundary; y <= right_boundary; y++){
                int pos = 3*(x*image_height + y); 
                byte1 += image_matrix[pos];
                byte2 += image_matrix[pos+1];
                byte3 += image_matrix[pos+2];
            }
        }
        int effective_window_size = (bottom_boundary-top_boundary+1)*(right_boundary-left_boundary+1);
        filtered_image_data[k] = byte1/effective_window_size;
        filtered_image_data[k+1] = byte2/effective_window_size;
        filtered_image_data[k+2] = byte3/effective_window_size;
    }
}


int main(int argc,char **argv)
{
   
    FILE* f = fopen(argv[1], "rb");
    unsigned char info[54];
    fread(info, sizeof(unsigned char), 54, f); 

    int width, height;
    memcpy(&width, info + 18, sizeof(int));
    memcpy(&height, info + 22, sizeof(int));

    int window_size = strtol(argv[2],NULL,10);
    printf("     Window size: %d\n",window_size);
    printf("Image dimensions: (%d, %d)\n",width,height);
        
    int size = 3 * width * abs(height);
    unsigned char* data = new unsigned char[size]; 
    unsigned char* result_image_data_d;
    unsigned char* result_image_data_h = new unsigned char[size];
    unsigned char* result_image_data_h1 = new unsigned char[size];

    unsigned char* image_data_d;

    fread(data, sizeof(unsigned char), size, f); 
    fclose(f);
   
    int block_size = 32;
    int grid_size = width/block_size;
    dim3 dimBlock(block_size, block_size, 1);
    dim3 dimGrid(grid_size, grid_size, 1);

    
    for(int i = 0; i < sample_rounds; i += 1)
    {
        cudaMalloc((void **)&image_data_d,size*sizeof(unsigned char));
        cudaMalloc((void **)&result_image_data_d,size*sizeof(unsigned char));
        cudaMemcpy(image_data_d,data,size*sizeof(unsigned char),cudaMemcpyHostToDevice);
        
       
        clock_t start_d=clock();
        meanFilter_device <<< dimGrid, dimBlock >>> (image_data_d, result_image_data_d, width, height, window_size);
        cudaThreadSynchronize();

        cudaError_t error = cudaGetLastError();
        if(error!=cudaSuccess)
        {
            fprintf(stderr,"ERROR: %s\n", cudaGetErrorString(error) );
            exit(-1);
        }
        clock_t end_d = clock();

        clock_t start_h = clock();
        meanFilter_host(data, result_image_data_h1, width, height, window_size);
        clock_t end_h = clock();

        cudaMemcpy(result_image_data_h,result_image_data_d,size*sizeof(unsigned char),cudaMemcpyDeviceToHost);

        time_host += (double)(end_h-start_h)/CLOCKS_PER_SEC;
        time_device += (double)(end_d-start_d)/CLOCKS_PER_SEC;

        cudaFree(image_data_d);
        cudaFree(result_image_data_d);
    }

    printf("    GPU Time: %f\n",(time_device/sample_rounds));
    printf("    CPU Time: %f\n",(time_host/sample_rounds));
    printf("CPU/GPU time: %f\n",(time_host/time_device));

    
    return 0;
}


	.file	"tmpxft_002cbc31_00000000-6_meanfilter1.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3639:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3639:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15meanFilter_hostPhS_iii
	.type	_Z15meanFilter_hostPhS_iii, @function
_Z15meanFilter_hostPhS_iii:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%r8d, %eax
	movl	%edx, %r9d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	cltd
	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
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	movq	%rdi, -24(%rsp)
	movl	%ecx, %edi
	movl	$2, %ecx
	idivl	%ecx
	movq	%rsi, -16(%rsp)
	movl	%r8d, %eax
	leal	-1(%rdi), %esi
	movl	%esi, -8(%rsp)
	leal	-1(%r9), %esi
	movl	%esi, -4(%rsp)
	subl	%edx, %eax
	cltd
	idivl	%ecx
.L3:
	cmpl	%edi, %ebx
	jge	.L2
	movl	%ebx, %r8d
	movl	$0, %edx
	movq	-16(%rsp), %rcx
	subl	%eax, %r8d
	cmovs	%edx, %r8d
	leal	(%rax,%rbx), %edx
	cmpl	%edi, %edx
	cmovge	-8(%rsp), %edx
	xorl	%r11d, %r11d
	movl	%edx, -36(%rsp)
	subl	%r8d, %edx
	leal	1(%rdx), %esi
	movl	%esi, -32(%rsp)
	leal	0(%rbp,%rbp,2), %esi
	movslq	%esi, %rsi
	addq	%rcx, %rsi
	movl	%r8d, %ecx
	imull	%edi, %ecx
	movl	%ecx, -28(%rsp)
.L11:
	cmpl	%r9d, %r11d
	jge	.L14
	movl	%r11d, %r10d
	movl	$0, %edx
	xorps	%xmm0, %xmm0
	movl	-28(%rsp), %r12d
	subl	%eax, %r10d
	movaps	%xmm0, %xmm1
	movaps	%xmm0, %xmm2
	movl	%r8d, %r14d
	cmovs	%edx, %r10d
	leal	(%rax,%r11), %edx
	cmpl	%r9d, %edx
	cmovge	-4(%rsp), %edx
.L5:
	cmpl	%r14d, -36(%rsp)
	jl	.L7
	leal	(%r12,%r10), %ecx
	movq	-24(%rsp), %r15
	movslq	%r10d, %r13
	leal	(%rcx,%rcx,2), %ecx
	movslq	%ecx, %rcx
	addq	%r15, %rcx
.L8:
	cmpl	%r13d, %edx
	jl	.L15
	movzbl	(%rcx), %r15d
	incq	%r13
	addq	$3, %rcx
	cvtsi2sdl	%r15d, %xmm3
	movzbl	-2(%rcx), %r15d
	addsd	%xmm3, %xmm2
	cvtsi2sdl	%r15d, %xmm3
	movzbl	-1(%rcx), %r15d
	addsd	%xmm3, %xmm1
	cvtsi2sdl	%r15d, %xmm3
	addsd	%xmm3, %xmm0
	jmp	.L8
.L15:
	incl	%r14d
	addl	%edi, %r12d
	jmp	.L5
.L7:
	movl	-32(%rsp), %ecx
	subl	%r10d, %edx
	incl	%r11d
	addq	$3, %rsi
	incl	%edx
	imull	%ecx, %edx
	cvtsi2sdl	%edx, %xmm3
	divsd	%xmm3, %xmm2
	divsd	%xmm3, %xmm1
	cvttsd2sil	%xmm2, %edx
	movb	%dl, -3(%rsi)
	divsd	%xmm3, %xmm0
	cvttsd2sil	%xmm1, %edx
	movb	%dl, -2(%rsi)
	cvttsd2sil	%xmm0, %edx
	movb	%dl, -1(%rsi)
	jmp	.L11
.L14:
	incl	%ebx
	addl	%edi, %ebp
	jmp	.L3
.L2:
	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
.LFE3635:
	.size	_Z15meanFilter_hostPhS_iii, .-_Z15meanFilter_hostPhS_iii
	.globl	_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii
	.type	_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii, @function
_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii:
.LFB3661:
	.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	.L16
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z17meanFilter_devicePhS_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
.L16:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3661:
	.size	_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii, .-_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii
	.globl	_Z17meanFilter_devicePhS_iii
	.type	_Z17meanFilter_devicePhS_iii, @function
_Z17meanFilter_devicePhS_iii:
.LFB3662:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii
	.cfi_endproc
.LFE3662:
	.size	_Z17meanFilter_devicePhS_iii, .-_Z17meanFilter_devicePhS_iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"rb"
.LC2:
	.string	"     Window size: %d\n"
.LC3:
	.string	"Image dimensions: (%d, %d)\n"
.LC4:
	.string	"ERROR: %s\n"
.LC6:
	.string	"    GPU Time: %f\n"
.LC7:
	.string	"    CPU Time: %f\n"
.LC8:
	.string	"CPU/GPU time: %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3636:
	.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$168, %rsp
	.cfi_def_cfa_offset 224
	movq	8(%rsi), %rdi
	leaq	.LC1(%rip), %rsi
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movl	$54, %ecx
	leaq	98(%rsp), %rdi
	movl	$1, %edx
	movq	%rax, %r8
	movl	$54, %esi
	movq	%rax, %r12
	call	__fread_chk@PLT
	movq	16(%r13), %rdi
	xorl	%esi, %esi
	movl	$10, %edx
	movl	116(%rsp), %ebp
	movl	120(%rsp), %ebx
	call	__isoc23_strtol@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	movl	%eax, 12(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %ecx
	movl	%ebp, %edx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %eax
	negl	%eax
	cmovs	%ebx, %eax
	xorl	%r14d, %r14d
	imull	%ebp, %eax
	leal	(%rax,%rax,2), %eax
	cltq
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	_Znam@PLT
	movq	(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	_Znam@PLT
	movq	(%rsp), %rdi
	movq	%rax, 24(%rsp)
	call	_Znam@PLT
	movq	(%rsp), %rcx
	movq	16(%rsp), %rdi
	movq	%r12, %r8
	movl	$1, %edx
	movq	%rax, 32(%rsp)
	movq	%rcx, %rsi
	call	__fread_chk@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movl	$32, %ecx
	movabsq	$137438953504, %rax
	movl	$1, 80(%rsp)
	movq	%rax, 72(%rsp)
	movl	%ebp, %eax
	cltd
	movl	$1, 92(%rsp)
	idivl	%ecx
	movl	%eax, 84(%rsp)
	movl	%eax, 88(%rsp)
.L22:
	movl	sample_rounds(%rip), %eax
	cmpl	%r14d, %eax
	jle	.L28
	movq	(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	64(%rsp), %rdi
	call	cudaMemcpy@PLT
	call	clock@PLT
	movl	80(%rsp), %ecx
	movl	92(%rsp), %esi
	xorl	%r9d, %r9d
	movq	72(%rsp), %rdx
	movq	84(%rsp), %rdi
	xorl	%r8d, %r8d
	movq	%rax, %r15
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movl	12(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	%ebx, %ecx
	movl	%ebp, %edx
	movq	64(%rsp), %rdi
	call	_Z42__device_stub__Z17meanFilter_devicePhS_iiiPhS_iii
.L23:
	call	cudaThreadSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC4(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L24:
	call	clock@PLT
	incl	%r14d
	movq	%rax, %r12
	call	clock@PLT
	movl	12(%rsp), %r8d
	movl	%ebx, %ecx
	movl	%ebp, %edx
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdi
	movq	%rax, 40(%rsp)
	subq	%r15, %r12
	call	_Z15meanFilter_hostPhS_iii
	call	clock@PLT
	movq	(%rsp), %rdx
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	24(%rsp), %rdi
	movq	%rax, %r13
	call	cudaMemcpy@PLT
	movq	40(%rsp), %r9
	movq	64(%rsp), %rdi
	subq	%r9, %r13
	cvtsi2sdq	%r13, %xmm0
	divsd	.LC5(%rip), %xmm0
	addsd	time_host(%rip), %xmm0
	movsd	%xmm0, time_host(%rip)
	cvtsi2sdq	%r12, %xmm0
	divsd	.LC5(%rip), %xmm0
	addsd	time_device(%rip), %xmm0
	movsd	%xmm0, time_device(%rip)
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	jmp	.L22
.L28:
	cvtsi2sdl	%eax, %xmm1
	movsd	time_device(%rip), %xmm0
	leaq	.LC6(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	cvtsi2sdl	sample_rounds(%rip), %xmm1
	movl	$2, %edi
	movb	$1, %al
	movsd	time_host(%rip), %xmm0
	leaq	.LC7(%rip), %rsi
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	leaq	.LC8(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	movsd	time_host(%rip), %xmm0
	divsd	time_device(%rip), %xmm0
	call	__printf_chk@PLT
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$168, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE3636:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z17meanFilter_devicePhS_iii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3664:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z17meanFilter_devicePhS_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
.LFE3664:
	.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
	.globl	sample_rounds
	.data
	.align 4
	.type	sample_rounds, @object
	.size	sample_rounds, 4
sample_rounds:
	.long	10
	.globl	time_device
	.bss
	.align 8
	.type	time_device, @object
	.size	time_device, 8
time_device:
	.zero	8
	.globl	time_host
	.align 8
	.type	time_host, @object
	.size	time_host, 8
time_host:
	.zero	8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC5:
	.long	0
	.long	1093567616
	.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 <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <hip/hip_runtime_api.h>
#include <tuple>
#include <iostream>
#include <string.h>

double time_host = 0;
double time_device = 0;

int sample_rounds = 10;

void meanFilter_host(unsigned char* image_matrix,unsigned char* filtered_image_data,int image_width, int image_height, int window_size)
{
    int half_window = (window_size-window_size % 2)/2;
	
    for(int i = 0; i < image_height; i += 1){
        for(int j = 0; j < image_width; j += 1){
            int k = 3*(i*image_height+j);
            int top_boundary;
			int bottom_boundary;
			int left_boundary;
			int right_boundary; 
            if(i-half_window >= 0){
				top_boundary = i-half_window;
			}else{
				top_boundary = 0;
			}
            if(i+half_window <= image_height-1){
				bottom_boundary = i+half_window;
			}else{
				bottom_boundary = image_height-1;
			}
            if(j-half_window >= 0){
				left_boundary = j-half_window;
			}else{
				left_boundary = 0;
			}
            if(j+half_window <= image_width-1){
				right_boundary = j+half_window;
			}else{
				right_boundary = image_width-1;
			}
            double byte1 = 0; 
            double byte2 = 0; 
            double byte3 = 0; 
            
            for(int x = top_boundary; x <= bottom_boundary; x++){
                for(int y = left_boundary; y <= right_boundary; y++){
                    int pos = 3*(x*image_height + y); 
                    byte1 += image_matrix[pos];
                    byte2 += image_matrix[pos+1];
                    byte3 += image_matrix[pos+2];
                }
            }
            int effective_window_size = (bottom_boundary-top_boundary+1)*(right_boundary-left_boundary+1);
            filtered_image_data[k] = byte1/effective_window_size;
            filtered_image_data[k+1] = byte2/effective_window_size;
            filtered_image_data[k+2] = byte3/effective_window_size;

            
        }
    }
   
}

__global__ void meanFilter_device(unsigned char* image_matrix, unsigned char* filtered_image_data, int image_width, int image_height, int window_size)
{
    int j = blockIdx.x * blockDim.x + threadIdx.x;
    int i = blockIdx.y * blockDim.y + threadIdx.y;
	int half_window = (window_size-window_size % 2)/2;
	
    if (i < image_height && j < image_width){
        int k = 3*(i*image_height+j);
        int top_boundary;
		int bottom_boundary;
		int left_boundary;
		int right_boundary; 
        if(i-half_window >= 0){
			top_boundary = i-half_window;
		}else{
			top_boundary = 0;
		}
        if(i+half_window <= image_height-1){
			bottom_boundary = i+half_window;
		}else{
			bottom_boundary = image_height-1;
		}
        if(j-half_window >= 0){
			left_boundary = j-half_window;
		}else{
			left_boundary = 0;
		}
        if(j+half_window <= image_width-1){
			right_boundary = j+half_window;
		}else{
			right_boundary = image_width-1;
		}
        double byte1 = 0; 
        double byte2 = 0; 
        double byte3 = 0; 
       
        for(int x = top_boundary; x <= bottom_boundary; x++){
            for(int y = left_boundary; y <= right_boundary; y++){
                int pos = 3*(x*image_height + y); 
                byte1 += image_matrix[pos];
                byte2 += image_matrix[pos+1];
                byte3 += image_matrix[pos+2];
            }
        }
        int effective_window_size = (bottom_boundary-top_boundary+1)*(right_boundary-left_boundary+1);
        filtered_image_data[k] = byte1/effective_window_size;
        filtered_image_data[k+1] = byte2/effective_window_size;
        filtered_image_data[k+2] = byte3/effective_window_size;
    }
}


int main(int argc,char **argv)
{
   
    FILE* f = fopen(argv[1], "rb");
    unsigned char info[54];
    fread(info, sizeof(unsigned char), 54, f); 

    int width, height;
    memcpy(&width, info + 18, sizeof(int));
    memcpy(&height, info + 22, sizeof(int));

    int window_size = strtol(argv[2],NULL,10);
    printf("     Window size: %d\n",window_size);
    printf("Image dimensions: (%d, %d)\n",width,height);
        
    int size = 3 * width * abs(height);
    unsigned char* data = new unsigned char[size]; 
    unsigned char* result_image_data_d;
    unsigned char* result_image_data_h = new unsigned char[size];
    unsigned char* result_image_data_h1 = new unsigned char[size];

    unsigned char* image_data_d;

    fread(data, sizeof(unsigned char), size, f); 
    fclose(f);
   
    int block_size = 32;
    int grid_size = width/block_size;
    dim3 dimBlock(block_size, block_size, 1);
    dim3 dimGrid(grid_size, grid_size, 1);

    
    for(int i = 0; i < sample_rounds; i += 1)
    {
        hipMalloc((void **)&image_data_d,size*sizeof(unsigned char));
        hipMalloc((void **)&result_image_data_d,size*sizeof(unsigned char));
        hipMemcpy(image_data_d,data,size*sizeof(unsigned char),hipMemcpyHostToDevice);
        
       
        clock_t start_d=clock();
        meanFilter_device <<< dimGrid, dimBlock >>> (image_data_d, result_image_data_d, width, height, window_size);
        hipDeviceSynchronize();

        hipError_t error = hipGetLastError();
        if(error!=hipSuccess)
        {
            fprintf(stderr,"ERROR: %s\n", hipGetErrorString(error) );
            exit(-1);
        }
        clock_t end_d = clock();

        clock_t start_h = clock();
        meanFilter_host(data, result_image_data_h1, width, height, window_size);
        clock_t end_h = clock();

        hipMemcpy(result_image_data_h,result_image_data_d,size*sizeof(unsigned char),hipMemcpyDeviceToHost);

        time_host += (double)(end_h-start_h)/CLOCKS_PER_SEC;
        time_device += (double)(end_d-start_d)/CLOCKS_PER_SEC;

        hipFree(image_data_d);
        hipFree(result_image_data_d);
    }

    printf("    GPU Time: %f\n",(time_device/sample_rounds));
    printf("    CPU Time: %f\n",(time_host/sample_rounds));
    printf("CPU/GPU time: %f\n",(time_host/time_device));

    
    return 0;
}


	.text
	.file	"meanfilter1.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z15meanFilter_hostPhS_iii      # -- Begin function _Z15meanFilter_hostPhS_iii
	.type	_Z15meanFilter_hostPhS_iii,@function
_Z15meanFilter_hostPhS_iii:             # @_Z15meanFilter_hostPhS_iii
	.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
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
                                        # kill: def $ecx killed $ecx def $rcx
                                        # kill: def $edx killed $edx def $rdx
	movq	%rdx, -80(%rsp)                 # 8-byte Spill
	movq	%rsi, -24(%rsp)                 # 8-byte Spill
	movq	%rcx, -88(%rsp)                 # 8-byte Spill
	testl	%ecx, %ecx
	jle	.LBB0_10
# %bb.1:                                # %.preheader88.lr.ph
	movl	%r8d, %edx
	shrl	$31, %edx
	addl	%r8d, %edx
	sarl	%edx
	movq	-88(%rsp), %rax                 # 8-byte Reload
	leal	-1(%rax), %ecx
	movl	%ecx, -112(%rsp)                # 4-byte Spill
	movq	-80(%rsp), %rcx                 # 8-byte Reload
	leal	-1(%rcx), %esi
	movl	%esi, -100(%rsp)                # 4-byte Spill
	movl	%eax, %esi
	movq	%rsi, -72(%rsp)                 # 8-byte Spill
	movslq	%edx, %rsi
	movq	%rsi, -56(%rsp)                 # 8-byte Spill
	negl	%edx
	movslq	%ecx, %rcx
	movq	%rcx, -32(%rsp)                 # 8-byte Spill
	movl	%ecx, %ecx
	movq	%rcx, -40(%rsp)                 # 8-byte Spill
	leal	(%rax,%rax,2), %ebp
	xorl	%eax, %eax
	movq	%rax, -120(%rsp)                # 8-byte Spill
	movl	%edx, -108(%rsp)                # 4-byte Spill
.LBB0_2:                                # %.preheader88
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
                                        #       Child Loop BB0_6 Depth 3
                                        #         Child Loop BB0_11 Depth 4
	testl	%edx, %edx
	movl	$0, %eax
	movl	%edx, -104(%rsp)                # 4-byte Spill
	cmovgl	%edx, %eax
	movq	%rax, -64(%rsp)                 # 8-byte Spill
	cmpl	$0, -80(%rsp)                   # 4-byte Folded Reload
	jle	.LBB0_9
# %bb.3:                                # %.lr.ph106
                                        #   in Loop: Header=BB0_2 Depth=1
	movq	-88(%rsp), %rax                 # 8-byte Reload
	movl	%eax, %ecx
	imull	-64(%rsp), %ecx                 # 4-byte Folded Reload
	movq	%rcx, -48(%rsp)                 # 8-byte Spill
	movq	-120(%rsp), %rsi                # 8-byte Reload
	movl	%esi, %r8d
	movq	-56(%rsp), %rcx                 # 8-byte Reload
	subl	%ecx, %r8d
	testl	%r8d, %r8d
	movl	$0, %edx
	cmovlel	%edx, %r8d
	addq	%rsi, %rcx
	cmpq	-72(%rsp), %rcx                 # 8-byte Folded Reload
	cmovgel	-112(%rsp), %ecx                # 4-byte Folded Reload
	movl	%ecx, %edx
	movl	%r8d, -92(%rsp)                 # 4-byte Spill
	subl	%r8d, %edx
	incl	%edx
	movl	%edx, -96(%rsp)                 # 4-byte Spill
	movq	%rcx, -8(%rsp)                  # 8-byte Spill
	movslq	%ecx, %r13
                                        # kill: def $esi killed $esi killed $rsi def $rsi
	imull	%eax, %esi
	movq	%rsi, -16(%rsp)                 # 8-byte Spill
	xorl	%r15d, %r15d
	movl	-108(%rsp), %esi                # 4-byte Reload
.LBB0_4:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_6 Depth 3
                                        #         Child Loop BB0_11 Depth 4
	testl	%esi, %esi
	movl	$0, %r10d
	cmovgl	%esi, %r10d
	movl	%r15d, %r8d
	movq	-56(%rsp), %rax                 # 8-byte Reload
	subl	%eax, %r8d
	testl	%r8d, %r8d
	movl	$0, %ecx
	cmovlel	%ecx, %r8d
	leaq	(%r15,%rax), %r9
	cmpq	-32(%rsp), %r9                  # 8-byte Folded Reload
	cmovgel	-100(%rsp), %r9d                # 4-byte Folded Reload
	xorpd	%xmm2, %xmm2
	xorpd	%xmm1, %xmm1
	xorpd	%xmm0, %xmm0
	movq	-8(%rsp), %rax                  # 8-byte Reload
	cmpl	%eax, -92(%rsp)                 # 4-byte Folded Reload
	jg	.LBB0_8
# %bb.5:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB0_4 Depth=2
	movq	-48(%rsp), %rax                 # 8-byte Reload
	addl	%r10d, %eax
	decq	%r10
	leal	(%rax,%rax,2), %edx
	movslq	%r9d, %r12
	movq	-64(%rsp), %rax                 # 8-byte Reload
.LBB0_6:                                # %.preheader
                                        #   Parent Loop BB0_2 Depth=1
                                        #     Parent Loop BB0_4 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB0_11 Depth 4
	movq	%r10, %rbx
	movl	%edx, %r14d
	cmpl	%r8d, %r9d
	jl	.LBB0_7
.LBB0_11:                               #   Parent Loop BB0_2 Depth=1
                                        #     Parent Loop BB0_4 Depth=2
                                        #       Parent Loop BB0_6 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movl	%r14d, %r11d
	movzbl	(%rdi,%r11), %ecx
	xorps	%xmm3, %xmm3
	cvtsi2sd	%ecx, %xmm3
	addsd	%xmm3, %xmm2
	movzbl	1(%rdi,%r11), %ecx
	xorps	%xmm3, %xmm3
	cvtsi2sd	%ecx, %xmm3
	addsd	%xmm3, %xmm1
	movzbl	2(%rdi,%r11), %ecx
	xorps	%xmm3, %xmm3
	cvtsi2sd	%ecx, %xmm3
	addsd	%xmm3, %xmm0
	addl	$3, %r14d
	incq	%rbx
	cmpq	%r12, %rbx
	jl	.LBB0_11
.LBB0_7:                                # %._crit_edge
                                        #   in Loop: Header=BB0_6 Depth=3
	leaq	1(%rax), %rbx
	addl	%ebp, %edx
	cmpq	%r13, %rax
	movq	%rbx, %rax
	jl	.LBB0_6
.LBB0_8:                                # %._crit_edge101
                                        #   in Loop: Header=BB0_4 Depth=2
	movq	-16(%rsp), %rax                 # 8-byte Reload
	addl	%r15d, %eax
	leal	(%rax,%rax,2), %eax
	subl	%r8d, %r9d
	incl	%r9d
	imull	-96(%rsp), %r9d                 # 4-byte Folded Reload
	xorps	%xmm3, %xmm3
	cvtsi2sd	%r9d, %xmm3
	divsd	%xmm3, %xmm2
	cvttsd2si	%xmm2, %edx
	movl	%eax, %eax
	movq	-24(%rsp), %rcx                 # 8-byte Reload
	movb	%dl, (%rcx,%rax)
	divsd	%xmm3, %xmm1
	cvttsd2si	%xmm1, %edx
	movb	%dl, 1(%rcx,%rax)
	divsd	%xmm3, %xmm0
	cvttsd2si	%xmm0, %edx
	movb	%dl, 2(%rcx,%rax)
	incq	%r15
	incl	%esi
	cmpq	-40(%rsp), %r15                 # 8-byte Folded Reload
	jne	.LBB0_4
.LBB0_9:                                # %._crit_edge107
                                        #   in Loop: Header=BB0_2 Depth=1
	movq	-120(%rsp), %rcx                # 8-byte Reload
	incq	%rcx
	movl	-104(%rsp), %edx                # 4-byte Reload
	incl	%edx
	movq	%rcx, %rax
	movq	%rcx, -120(%rsp)                # 8-byte Spill
	cmpq	-72(%rsp), %rcx                 # 8-byte Folded Reload
	jne	.LBB0_2
.LBB0_10:                               # %._crit_edge109
	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_end0:
	.size	_Z15meanFilter_hostPhS_iii, .Lfunc_end0-_Z15meanFilter_hostPhS_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z32__device_stub__meanFilter_devicePhS_iii # -- Begin function _Z32__device_stub__meanFilter_devicePhS_iii
	.type	_Z32__device_stub__meanFilter_devicePhS_iii,@function
_Z32__device_stub__meanFilter_devicePhS_iii: # @_Z32__device_stub__meanFilter_devicePhS_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	$_Z17meanFilter_devicePhS_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_end1:
	.size	_Z32__device_stub__meanFilter_devicePhS_iii, .Lfunc_end1-_Z32__device_stub__meanFilter_devicePhS_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.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	$136, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r15
	movq	8(%rsi), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r14
	leaq	80(%rsp), %r12
	movl	$1, %esi
	movl	$54, %edx
	movq	%r12, %rdi
	movq	%rax, %rcx
	callq	fread
	movl	18(%r12), %ebx
	movl	22(%r12), %ebp
	movq	16(%r15), %rdi
	xorl	%r12d, %r12d
	xorl	%esi, %esi
	movl	$10, %edx
	callq	__isoc23_strtol
	movl	$.L.str.1, %edi
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.2, %edi
	movl	%ebx, %esi
	movl	%ebp, %edx
	xorl	%eax, %eax
	callq	printf
	movl	%ebp, %eax
	negl	%eax
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	cmovsl	%ebp, %eax
	imull	%ebx, %eax
	leal	(%rax,%rax,2), %eax
	movslq	%eax, %r15
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r13
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movl	$1, %esi
	movq	%r13, %rdi
	movq	%r15, %rdx
	movq	%r14, %rcx
	callq	fread
	movq	%r14, %rdi
	callq	fclose
	leal	31(%rbx), %eax
	testl	%ebx, %ebx
	movq	%rbx, 40(%rsp)                  # 8-byte Spill
	cmovnsl	%ebx, %eax
	movl	sample_rounds(%rip), %ecx
	testl	%ecx, %ecx
	jle	.LBB2_6
# %bb.1:                                # %.lr.ph.preheader
	sarl	$5, %eax
	movq	%rax, %rcx
	shlq	$32, %rcx
	orq	%rax, %rcx
	movq	%rcx, 48(%rsp)                  # 8-byte Spill
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	16(%rsp), %rdi
	movq	%r13, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movq	16(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	40(%rsp), %rdx                  # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	12(%rsp), %ecx                  # 4-byte Reload
	movq	32(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	callq	_Z32__device_stub__meanFilter_devicePhS_iii
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_7
# %bb.5:                                #   in Loop: Header=BB2_2 Depth=1
	callq	clock
	movq	%rax, %rbp
	callq	clock
	movq	%rax, %rbx
	movq	%r13, %rdi
	movq	56(%rsp), %rsi                  # 8-byte Reload
	movq	40(%rsp), %rdx                  # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	12(%rsp), %ecx                  # 4-byte Reload
	movq	32(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	callq	_Z15meanFilter_hostPhS_iii
	callq	clock
	movq	%r13, %r14
	movq	%rax, %r13
	movq	24(%rsp), %rsi
	movq	64(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	subq	%rbx, %r13
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13, %xmm0
	movq	%r14, %r13
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm1, %xmm0
	addsd	time_host(%rip), %xmm0
	movsd	%xmm0, time_host(%rip)
	subq	72(%rsp), %rbp                  # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rbp, %xmm0
	divsd	%xmm1, %xmm0
	addsd	time_device(%rip), %xmm0
	movsd	%xmm0, time_device(%rip)
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	incl	%r12d
	movl	sample_rounds(%rip), %ecx
	cmpl	%ecx, %r12d
	jl	.LBB2_2
.LBB2_6:                                # %._crit_edge
	movsd	time_device(%rip), %xmm0        # xmm0 = mem[0],zero
	xorps	%xmm1, %xmm1
	cvtsi2sd	%ecx, %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	movsd	time_host(%rip), %xmm0          # xmm0 = mem[0],zero
	xorps	%xmm1, %xmm1
	cvtsi2sdl	sample_rounds(%rip), %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movsd	time_host(%rip), %xmm0          # xmm0 = mem[0],zero
	divsd	time_device(%rip), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_7:
	.cfi_def_cfa_offset 192
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %edi
	callq	exit
.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	$_Z17meanFilter_devicePhS_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	time_host,@object               # @time_host
	.bss
	.globl	time_host
	.p2align	3, 0x0
time_host:
	.quad	0x0000000000000000              # double 0
	.size	time_host, 8

	.type	time_device,@object             # @time_device
	.globl	time_device
	.p2align	3, 0x0
time_device:
	.quad	0x0000000000000000              # double 0
	.size	time_device, 8

	.type	sample_rounds,@object           # @sample_rounds
	.data
	.globl	sample_rounds
	.p2align	2, 0x0
sample_rounds:
	.long	10                              # 0xa
	.size	sample_rounds, 4

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"rb"
	.size	.L.str, 3

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"     Window size: %d\n"
	.size	.L.str.1, 22

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Image dimensions: (%d, %d)\n"
	.size	.L.str.2, 28

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"ERROR: %s\n"
	.size	.L.str.3, 11

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"    GPU Time: %f\n"
	.size	.L.str.4, 18

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"    CPU Time: %f\n"
	.size	.L.str.5, 18

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"CPU/GPU time: %f\n"
	.size	.L.str.6, 18

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z17meanFilter_devicePhS_iii"
	.size	.L__unnamed_1, 29

	.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__meanFilter_devicePhS_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z17meanFilter_devicePhS_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17meanFilter_devicePhS_iii ; -- Begin function _Z17meanFilter_devicePhS_iii
	.globl	_Z17meanFilter_devicePhS_iii
	.p2align	8
	.type	_Z17meanFilter_devicePhS_iii,@function
_Z17meanFilter_devicePhS_iii:           ; @_Z17meanFilter_devicePhS_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_bfe_u32 v2, v0, 10, 10
	v_and_b32_e32 v3, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[0:1], null, s15, s3, v[2:3]
	v_mad_u64_u32 v[1:2], null, s14, s2, v[3:4]
	v_cmp_gt_i32_e32 vcc_lo, s5, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s4, v1
	s_and_b32 s2, s2, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_10
; %bb.1:
	s_lshr_b32 s2, s6, 31
	s_load_b128 s[8:11], s[0:1], 0x0
	s_add_i32 s2, s6, s2
	s_add_i32 s0, s5, -1
	s_ashr_i32 s2, s2, 1
	s_mov_b32 s1, exec_lo
	v_add_nc_u32_e32 v3, s2, v0
	v_subrev_nc_u32_e32 v2, s2, v0
	v_add_nc_u32_e32 v5, s2, v1
	v_subrev_nc_u32_e32 v4, s2, v1
	s_mov_b32 s2, 0
	v_cmp_gt_i32_e32 vcc_lo, s5, v3
	v_max_i32_e32 v9, 0, v2
	s_delay_alu instid0(VALU_DEP_3)
	v_max_i32_e32 v8, 0, v4
	v_cndmask_b32_e32 v10, s0, v3, vcc_lo
	v_mov_b32_e32 v2, 0
	v_mov_b32_e32 v3, 0
	v_cmp_gt_i32_e32 vcc_lo, s4, v5
	s_add_i32 s0, s4, -1
	s_delay_alu instid0(VALU_DEP_2)
	v_mov_b32_e32 v7, v3
	v_cndmask_b32_e32 v11, s0, v5, vcc_lo
	v_dual_mov_b32 v5, v3 :: v_dual_mov_b32 v6, v2
	v_mov_b32_e32 v4, v2
	v_cmpx_ge_i32_e64 v10, v9
	s_cbranch_execz .LBB0_9
; %bb.2:                                ; %.preheader.lr.ph
	v_mad_u64_u32 v[6:7], null, s5, v9, v[8:9]
	v_mov_b32_e32 v2, 0
	v_dual_mov_b32 v3, 0 :: v_dual_add_nc_u32 v12, -1, v8
	v_mov_b32_e32 v14, v9
	v_cmp_ge_i32_e32 vcc_lo, v11, v8
	s_mul_i32 s3, s5, 3
	s_delay_alu instid0(VALU_DEP_3)
	v_dual_mov_b32 v5, v3 :: v_dual_mov_b32 v4, v2
	v_lshl_add_u32 v13, v6, 1, v6
	v_dual_mov_b32 v7, v3 :: v_dual_mov_b32 v6, v2
.LBB0_3:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB0_7
; %bb.4:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v15, v13 :: v_dual_mov_b32 v16, v12
	s_mov_b32 s6, 0
.LBB0_5:                                ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_ashrrev_i32_e32 v18, 31, v15
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v17, s0, s8, v15
	v_add_nc_u32_e32 v16, 1, v16
	v_add_nc_u32_e32 v15, 3, v15
	v_add_co_ci_u32_e64 v18, s0, s9, v18, s0
	s_clause 0x1
	global_load_u16 v19, v[17:18], off
	global_load_u8 v17, v[17:18], off offset:2
	v_cmp_ge_i32_e64 s0, v16, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	s_or_b32 s6, s0, s6
	s_waitcnt vmcnt(1)
	v_and_b32_e32 v18, 0xff, v19
	v_bfe_u32 v19, v19, 8, 8
	v_and_b32_e32 v21, 0xffff, v18
	s_waitcnt vmcnt(0)
	v_cvt_f64_u32_e32 v[17:18], v17
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f64_u32_e32 v[19:20], v19
	v_cvt_f64_u32_e32 v[21:22], v21
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_f64 v[2:3], v[2:3], v[17:18]
	v_add_f64 v[4:5], v[4:5], v[19:20]
	s_delay_alu instid0(VALU_DEP_3)
	v_add_f64 v[6:7], v[6:7], v[21:22]
	s_and_not1_b32 exec_lo, exec_lo, s6
	s_cbranch_execnz .LBB0_5
; %bb.6:                                ; %Flow
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s6
.LBB0_7:                                ; %Flow139
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	s_or_b32 exec_lo, exec_lo, s4
	v_add_nc_u32_e32 v15, 1, v14
	v_cmp_ge_i32_e64 s0, v14, v10
	v_dual_mov_b32 v14, v15 :: v_dual_add_nc_u32 v13, s3, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s2, s0, s2
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB0_3
; %bb.8:                                ; %Flow140
	s_or_b32 exec_lo, exec_lo, s2
.LBB0_9:                                ; %Flow141
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	s_or_b32 exec_lo, exec_lo, s1
	v_sub_nc_u32_e32 v8, v11, v8
	v_sub_nc_u32_e32 v11, v10, v9
	v_add_nc_u32_e32 v8, 1, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[9:10], null, v8, v11, v[8:9]
	v_cvt_f64_i32_e32 v[8:9], v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_div_scale_f64 v[10:11], null, v[8:9], v[8:9], v[6:7]
	v_div_scale_f64 v[12:13], null, v[8:9], v[8:9], v[4:5]
	v_div_scale_f64 v[14:15], null, v[8:9], v[8:9], v[2:3]
	v_div_scale_f64 v[28:29], vcc_lo, v[6:7], v[8:9], v[6:7]
	v_rcp_f64_e32 v[16:17], v[10:11]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f64_e32 v[18:19], v[12:13]
	v_rcp_f64_e32 v[20:21], v[14:15]
	s_delay_alu instid0(TRANS32_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_3)
	v_fma_f64 v[22:23], -v[10:11], v[16:17], 1.0
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[24:25], -v[12:13], v[18:19], 1.0
	v_fma_f64 v[26:27], -v[14:15], v[20:21], 1.0
	v_fma_f64 v[16:17], v[16:17], v[22:23], v[16:17]
	v_fma_f64 v[18:19], v[18:19], v[24:25], v[18:19]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[20:21], v[20:21], v[26:27], v[20:21]
	v_fma_f64 v[22:23], -v[10:11], v[16:17], 1.0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[24:25], -v[12:13], v[18:19], 1.0
	v_fma_f64 v[26:27], -v[14:15], v[20:21], 1.0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_fma_f64 v[16:17], v[16:17], v[22:23], v[16:17]
	v_div_scale_f64 v[22:23], s0, v[4:5], v[8:9], v[4:5]
	v_fma_f64 v[18:19], v[18:19], v[24:25], v[18:19]
	v_div_scale_f64 v[24:25], s1, v[2:3], v[8:9], v[2:3]
	v_fma_f64 v[20:21], v[20:21], v[26:27], v[20:21]
	v_mul_f64 v[26:27], v[28:29], v[16:17]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_f64 v[30:31], v[22:23], v[18:19]
	v_mul_f64 v[32:33], v[24:25], v[20:21]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[10:11], -v[10:11], v[26:27], v[28:29]
	v_fma_f64 v[12:13], -v[12:13], v[30:31], v[22:23]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[14:15], -v[14:15], v[32:33], v[24:25]
	v_div_fmas_f64 v[10:11], v[10:11], v[16:17], v[26:27]
	s_mov_b32 vcc_lo, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_fmas_f64 v[12:13], v[12:13], v[18:19], v[30:31]
	s_mov_b32 vcc_lo, s1
	v_div_fmas_f64 v[14:15], v[14:15], v[20:21], v[32:33]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fixup_f64 v[6:7], v[10:11], v[8:9], v[6:7]
	v_div_fixup_f64 v[4:5], v[12:13], v[8:9], v[4:5]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f64 v[2:3], v[14:15], v[8:9], v[2:3]
	v_cvt_i32_f64_e32 v4, v[4:5]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_i32_f64_e32 v5, v[6:7]
	v_cvt_i32_f64_e32 v6, v[2:3]
	v_mad_u64_u32 v[2:3], null, v0, s5, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v0, v2, 1, v2
	v_ashrrev_i32_e32 v1, 31, v0
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s10, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	v_lshlrev_b16 v2, 8, v4
	v_or_b32_e32 v2, v5, v2
	s_clause 0x1
	global_store_b8 v[0:1], v6, off offset:2
	global_store_b16 v[0:1], v2, off
.LBB0_10:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17meanFilter_devicePhS_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 34
		.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	_Z17meanFilter_devicePhS_iii, .Lfunc_end0-_Z17meanFilter_devicePhS_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 972
; NumSgprs: 18
; NumVgprs: 34
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 4
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 34
; 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:           _Z17meanFilter_devicePhS_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z17meanFilter_devicePhS_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     34
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
