/*
* This sample implements a separable convolution 
* of a 2D image with an arbitrary filter.
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>


unsigned int filter_radius;

#define FILTER_LENGTH 	(2 * filter_radius + 1)
#define ABS(val)  	((val)<0.0 ? (-(val)) : (val))
#define accuracy  	0.05 


typedef float typeId;


////////////////////////////////////////////////////////////////////////////////
// Reference row convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionRowCPU(typeId *h_Dst, typeId *h_Src, typeId *h_Filter, 
                       int imageW, int imageH, int filterR) {

  int x, y, k;
                      
  for (y = 0; y < imageH; y++) {
    for (x = 0; x < imageW; x++) {
      typeId sum = 0;
	    
      for (k = -filterR; k <= filterR; k++) {
        int d = x + k;

        if (d >= 0 && d < imageW) {
          sum += h_Src[y * imageW + d] * h_Filter[filterR - k];
        }     

        h_Dst[y * imageW + x] = sum;
      }
    }
  }
        
}

/***************************************************	
 ********** ROW CONVOLUTION GPU	********************
 ***************************************************
 */

__global__ void convolutionRowGPU(typeId *d_Dst, typeId *d_Src, typeId *d_Filter, int imageW, int imageH, int filterR){
  
    int k;
    typeId sum = 0;
    int row = blockDim.y * blockIdx.y + threadIdx.y + filterR;
    int col = blockDim.x * blockIdx.x + threadIdx.x + filterR;
    int padW = imageW + filterR*2;
    
    for (k = -filterR; k <= filterR; k++) {
		int d = col + k;

		sum += d_Src[row * padW + d] * d_Filter[filterR - k];
    }
	d_Dst[row * padW + col] = sum;
    
}

////////////////////////////////////////////////////////////////////////////////
// Reference column convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionColumnCPU(typeId *h_Dst, typeId *h_Src, typeId *h_Filter,
    			   int imageW, int imageH, int filterR) {

  int x, y, k;
  
  for (y = 0; y < imageH; y++) {
    for (x = 0; x < imageW; x++) {
      typeId sum = 0;

      for (k = -filterR; k <= filterR; k++) {
        int d = y + k;

        if (d >= 0 && d < imageH) {
          sum += h_Src[d * imageW + x] * h_Filter[filterR - k];
        }   
 
        h_Dst[y * imageW + x] = sum;
      }
    }
  }
    
}

/***********************************************************	
 ******** COLUMN CONVOLUTION GPU ***************************
 ***********************************************************
 */
__global__ void convolutionColumnGPU(typeId *d_Dst, typeId *d_Src, typeId *d_Filter, int imageW, int imageH, int filterR) {
    
  int k;
  typeId sum = 0;
  int row = blockDim.y * blockIdx.y + threadIdx.y + filterR;
  int col = blockDim.x * blockIdx.x + threadIdx.x + filterR;
  int padW = imageW + filterR*2;
  
  for (k = -filterR; k <= filterR; k++) {
	int d = row + k;

	sum += d_Src[col + padW * d] * d_Filter[filterR - k];
  }
  d_Dst[row * padW + col] = sum;
  
    
}


////////////////////////////////////////////////////////////////////////////////
// Main program
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
    
    typeId
    *h_Filter,
    *h_Input,
    *h_Buffer,
    *h_OutputCPU,
    *h_PaddedInput,
    *d_Filter,
    *d_Input,
    *d_Buffer,
    *d_OutputGPU,
    *result,
    diff;

    float elapsedTime;

    cudaSetDevice(0);
    struct timespec  tv1, tv2;
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    int imageW;
    int imageH;
    unsigned int i, j;

	printf("Enter filter radius : ");
	scanf("%d", &filter_radius);

    printf("Enter image size. Should be a power of two and greater than %d : ", FILTER_LENGTH);
    scanf("%d", &imageW);
    imageH = imageW;

    printf("Image Width x Height = %i x %i\n\n", imageW, imageH);
    printf("Allocating and initializing host arrays...\n");
    
    h_Filter    = (typeId *)malloc(FILTER_LENGTH * sizeof(typeId));
    h_Input     = (typeId *)malloc(imageW * imageH * sizeof(typeId));
    h_Buffer    = (typeId *)malloc(imageW * imageH * sizeof(typeId));
    h_OutputCPU = (typeId *)malloc(imageW * imageH * sizeof(typeId));
    result 	= (typeId *)malloc((imageW+2*filter_radius) * (imageH+2*filter_radius)* sizeof(typeId));
    h_PaddedInput  = (typeId *)malloc((imageW+filter_radius*2 )*(2*filter_radius+ imageH) * sizeof(typeId));
    // Memory allocation check if any of them not allocated then error
    
    if(!(h_Filter && h_Input && h_Buffer && h_OutputCPU && h_PaddedInput && result)) {
		printf("Error allocating memory\n");
		exit(EXIT_FAILURE);
    }
    
    // Memory allocation on Device
    cudaMalloc(&d_Filter,FILTER_LENGTH*sizeof(typeId));
    cudaMalloc(&d_Input,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    cudaMalloc(&d_Buffer,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    cudaMalloc(&d_OutputGPU,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    
    // Check memory allocation on Device, if any of them failed, exit
    if (!(d_Filter && d_Input && d_Buffer && d_OutputGPU)) {
		printf("Cuda memory allocation failed\n");
		exit(EXIT_FAILURE);
    }
    // Initializing device values
    cudaMemset(d_OutputGPU,0,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    cudaMemset(d_Buffer,0,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    cudaMemset(d_Input,0,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));

    srand(200);

    for (i = 0; i < FILTER_LENGTH; i++) {
        h_Filter[i] = (typeId)(rand() % 16);
    }

    for (i = 0; i < imageW * imageH; i++) {
        h_Input[i] = (typeId)rand() / ((typeId)RAND_MAX / 255) + (typeId)rand() / (typeId)RAND_MAX;
    }


    // CPU computation
    printf("CPU computation...\n");
    clock_gettime(CLOCK_MONOTONIC_RAW, &tv1);
    convolutionRowCPU(h_Buffer, h_Input, h_Filter, imageW, imageH, filter_radius); 
    convolutionColumnCPU(h_OutputCPU, h_Buffer, h_Filter, imageW, imageH, filter_radius);     
    clock_gettime(CLOCK_MONOTONIC_RAW, &tv2);
     
    printf ("CPU time:  %10g seconds\n\n",
			(double) (tv2.tv_nsec - tv1.tv_nsec) / 1000000000.0 +
			(double) (tv2.tv_sec - tv1.tv_sec)); 
 
	dim3 dimGrid((imageH-1)/32 + 1,(imageH-1)/32 + 1);
	dim3 dimBlock(32,32);
    
    // init padded Input
    for(i=0;i<(imageW+2*filter_radius)*(imageW+2*filter_radius);i++) h_PaddedInput[i]=0;
    // filling the cells   
    for(i=0;i<imageH;i++){
      for(j=0;j<imageW;j++){
		h_PaddedInput[(i+filter_radius)*(2*filter_radius+imageW)+filter_radius+j]=h_Input[i*imageW+j];
      }
    }
    
    printf("GPU computation... \n");
    
    cudaMemcpy(d_Filter,h_Filter,FILTER_LENGTH*sizeof(typeId),cudaMemcpyHostToDevice);
    cudaMemcpy(d_Input,h_PaddedInput,(imageH+2*filter_radius)*(imageW+2*filter_radius)*sizeof(typeId),cudaMemcpyHostToDevice);
	cudaEventRecord(start,0);
    // kernel invocation
    convolutionRowGPU <<< dimGrid,dimBlock >>>(d_Buffer,d_Input, d_Filter, imageW, imageH, filter_radius);
    cudaThreadSynchronize();
    
    //Check for errors
    cudaError_t err = cudaGetLastError();
    if(err != cudaSuccess){
    	printf("Device Error:%s\n",cudaGetErrorString(err));
    	cudaDeviceReset();
    	return 0;
    }
    
    convolutionColumnGPU <<< dimGrid,dimBlock >>>(d_OutputGPU,d_Buffer, d_Filter, imageW, imageH, filter_radius);
    cudaThreadSynchronize();
    
    //Check for errors
    err = cudaGetLastError();
    if(err != cudaSuccess) {
		printf("Device Error:%s\n",cudaGetErrorString(err));
		cudaDeviceReset();
		return 0;
	}
	cudaEventRecord(stop,0);
    //Copy results to host
    cudaMemcpy(result, d_OutputGPU, (imageH+2*filter_radius)*(imageW+2*filter_radius)*sizeof(typeId), cudaMemcpyDeviceToHost);
    
    
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&elapsedTime,start,stop);
    printf("GPU time: %f ms.\n\n",elapsedTime);
    
    // Checking accuracy error CPU vs CPU
    for(i=0; i<imageW; i++) {
		for(j=0; j<imageH; j++){
			diff= h_OutputCPU[i*imageW+j]-result[(i+filter_radius)*(imageW+2*filter_radius)+filter_radius+j];
				if(ABS(diff) > accuracy) {
					printf("Accuracy error <<%f>>\n ",ABS(diff));
					free(h_OutputCPU);
					free(h_Buffer);
					free(h_Input);
					free(h_Filter);
					free(h_PaddedInput);
					cudaFree(d_OutputGPU);
					cudaFree(d_Buffer);
					cudaFree(d_Input);
					cudaFree(d_Filter);
					cudaDeviceReset();
					exit(EXIT_FAILURE);
				}
		}
	}

    // free all the allocated memory
    free(h_OutputCPU);
    free(h_Buffer);
    free(h_Input);
    free(h_Filter);
    free(h_PaddedInput);
    cudaFree(d_OutputGPU);
    cudaFree(d_Buffer);
    cudaFree(d_Input);
	cudaFree(d_Filter);
    
    // Do a device reset just in case... Bgalte to sxolio otan ylopoihsete CUDA
    cudaDeviceReset();


    return 0;
}

	.file	"tmpxft_00370e51_00000000-6_non_tiled_conv.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z17convolutionRowCPUPfS_S_iii
	.type	_Z17convolutionRowCPUPfS_S_iii, @function
_Z17convolutionRowCPUPfS_S_iii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdi, %r11
	movl	%ecx, %eax
	xorl	%r10d, %r10d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rsi, %rbx
	xorl	%esi, %esi
.L3:
	cmpl	%r8d, %r10d
	jge	.L15
	xorl	%edx, %edx
.L8:
	cmpl	%eax, %edx
	jge	.L16
	leal	(%rdx,%rsi), %ecx
	movl	%r9d, %edi
	xorps	%xmm0, %xmm0
	movslq	%ecx, %rcx
	negl	%edi
	leaq	(%r11,%rcx,4), %r13
	movl	%edx, %ecx
	subl	%r9d, %ecx
.L4:
	cmpl	%r9d, %edi
	jg	.L17
	testl	%ecx, %ecx
	js	.L5
	cmpl	%ecx, %eax
	jle	.L5
	movl	%r9d, %r12d
	leal	(%rcx,%rsi), %r14d
	subl	%edi, %r12d
	movslq	%r14d, %r14
	movslq	%r12d, %r12
	movss	(%rbx,%r14,4), %xmm1
	mulss	0(%rbp,%r12,4), %xmm1
	addss	%xmm1, %xmm0
.L5:
	movss	%xmm0, 0(%r13)
	incl	%edi
	incl	%ecx
	jmp	.L4
.L17:
	incl	%edx
	jmp	.L8
.L16:
	incl	%r10d
	addl	%eax, %esi
	jmp	.L3
.L15:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z17convolutionRowCPUPfS_S_iii, .-_Z17convolutionRowCPUPfS_S_iii
	.globl	_Z20convolutionColumnCPUPfS_S_iii
	.type	_Z20convolutionColumnCPUPfS_S_iii, @function
_Z20convolutionColumnCPUPfS_S_iii:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%r9d, %r10d
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r11
	movl	%ecx, %eax
	negl	%r10d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%edi, %edi
	imull	%ecx, %r10d
	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	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	xorl	%esi, %esi
.L19:
	cmpl	%r8d, %esi
	jge	.L18
	leal	(%rdi,%r10), %ecx
	movl	%ecx, -4(%rsp)
	xorl	%ecx, %ecx
.L25:
	cmpl	%eax, %ecx
	jge	.L30
	movl	-4(%rsp), %r14d
	leal	(%rcx,%rdi), %r12d
	movl	%r9d, %edx
	xorps	%xmm0, %xmm0
	movslq	%r12d, %r12
	negl	%edx
	leaq	(%r11,%r12,4), %r15
	leal	(%r14,%rcx), %r12d
.L20:
	cmpl	%r9d, %edx
	jg	.L31
	movl	%esi, %r13d
	addl	%edx, %r13d
	js	.L21
	cmpl	%r13d, %r8d
	jle	.L21
	movl	%r9d, %r14d
	movslq	%r12d, %r13
	subl	%edx, %r14d
	movslq	%r14d, %r14
	movss	0(%rbp,%r14,4), %xmm1
	mulss	(%rbx,%r13,4), %xmm1
	addss	%xmm1, %xmm0
.L21:
	movss	%xmm0, (%r15)
	incl	%edx
	addl	%eax, %r12d
	jmp	.L20
.L31:
	incl	%ecx
	jmp	.L25
.L30:
	incl	%esi
	addl	%eax, %edi
	jmp	.L19
.L18:
	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
.LFE2028:
	.size	_Z20convolutionColumnCPUPfS_S_iii, .-_Z20convolutionColumnCPUPfS_S_iii
	.globl	_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii
	.type	_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii, @function
_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z17convolutionRowGPUPfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L32:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii, .-_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii
	.globl	_Z17convolutionRowGPUPfS_S_iii
	.type	_Z17convolutionRowGPUPfS_S_iii, @function
_Z17convolutionRowGPUPfS_S_iii:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2055:
	.size	_Z17convolutionRowGPUPfS_S_iii, .-_Z17convolutionRowGPUPfS_S_iii
	.globl	_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii
	.type	_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii, @function
_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z20convolutionColumnGPUPfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L37:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii, .-_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii
	.globl	_Z20convolutionColumnGPUPfS_S_iii
	.type	_Z20convolutionColumnGPUPfS_S_iii, @function
_Z20convolutionColumnGPUPfS_S_iii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2057:
	.size	_Z20convolutionColumnGPUPfS_S_iii, .-_Z20convolutionColumnGPUPfS_S_iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Enter filter radius : "
.LC2:
	.string	"%d"
.LC3:
	.string	"Enter image size. Should be a power of two and greater than %d : "
.LC4:
	.string	"Image Width x Height = %i x %i\n\n"
.LC5:
	.string	"Allocating and initializing host arrays...\n"
.LC6:
	.string	"Error allocating memory\n"
.LC7:
	.string	"Cuda memory allocation failed\n"
.LC10:
	.string	"CPU computation...\n"
.LC12:
	.string	"CPU time:  %10g seconds\n\n"
.LC13:
	.string	"GPU computation... \n"
.LC14:
	.string	"Device Error:%s\n"
.LC15:
	.string	"GPU time: %f ms.\n\n"
.LC18:
	.string	"Accuracy error <<%f>>\n "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%edi, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC2(%rip), %rbx
	subq	$168, %rsp
	.cfi_def_cfa_offset 224
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	call	cudaSetDevice@PLT
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	88(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	leaq	filter_radius(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	filter_radius(%rip), %eax
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	leal	1(%rax,%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	leaq	44(%rsp), %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	44(%rsp), %ebx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	movl	%ebx, %ecx
	movl	%ebx, %edx
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %r14d
	leal	1(%r14), %r15d
	salq	$2, %r15
	movq	%r15, %rdi
	call	malloc@PLT
	movl	44(%rsp), %ebp
	movq	%rax, 8(%rsp)
	movl	%ebp, %r13d
	addl	%r14d, %ebp
	addl	%ebx, %r14d
	imull	%ebx, %r13d
	imull	%r14d, %ebp
	movslq	%r13d, %r13
	salq	$2, %r13
	salq	$2, %rbp
	movq	%r13, %rdi
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%r13, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r14
	call	malloc@PLT
	cmpq	$0, 8(%rsp)
	je	.L43
	testq	%r12, %r12
	je	.L43
	cmpq	$0, 16(%rsp)
	je	.L43
	testq	%r13, %r13
	je	.L43
	movq	%rax, %rbp
	testq	%rax, %rax
	je	.L43
	testq	%r14, %r14
	jne	.L44
.L43:
	leaq	.LC6(%rip), %rsi
	jmp	.L77
.L44:
	leaq	48(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	movl	filter_radius(%rip), %eax
	movl	44(%rsp), %esi
	leaq	56(%rsp), %rdi
	addl	%eax, %eax
	addl	%eax, %esi
	addl	%ebx, %eax
	imull	%eax, %esi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	filter_radius(%rip), %eax
	movl	44(%rsp), %esi
	leaq	64(%rsp), %rdi
	addl	%eax, %eax
	addl	%eax, %esi
	addl	%ebx, %eax
	imull	%eax, %esi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	filter_radius(%rip), %eax
	movl	44(%rsp), %esi
	leaq	72(%rsp), %rdi
	addl	%eax, %eax
	addl	%eax, %esi
	addl	%ebx, %eax
	imull	%eax, %esi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	cmpq	$0, 48(%rsp)
	je	.L46
	cmpq	$0, 56(%rsp)
	je	.L46
	cmpq	$0, 64(%rsp)
	je	.L46
	movq	72(%rsp), %rdi
	testq	%rdi, %rdi
	jne	.L47
.L46:
	leaq	.LC7(%rip), %rsi
.L77:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L78:
	movl	$1, %edi
	call	exit@PLT
.L47:
	movl	filter_radius(%rip), %eax
	movl	44(%rsp), %edx
	xorl	%esi, %esi
	xorl	%r15d, %r15d
	addl	%eax, %eax
	addl	%eax, %edx
	addl	%ebx, %eax
	imull	%eax, %edx
	salq	$2, %rdx
	call	cudaMemset@PLT
	movl	44(%rsp), %edx
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	movl	filter_radius(%rip), %eax
	addl	%eax, %eax
	addl	%eax, %edx
	addl	%ebx, %eax
	imull	%eax, %edx
	salq	$2, %rdx
	call	cudaMemset@PLT
	movl	44(%rsp), %edx
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	movl	filter_radius(%rip), %eax
	addl	%eax, %eax
	addl	%eax, %edx
	addl	%ebx, %eax
	imull	%eax, %edx
	salq	$2, %rdx
	call	cudaMemset@PLT
	movl	$200, %edi
	call	srand@PLT
.L48:
	movl	filter_radius(%rip), %eax
	leal	1(%rax,%rax), %eax
	cmpl	%eax, %r15d
	jnb	.L80
	call	rand@PLT
	movl	$16, %ecx
	movl	%r15d, %esi
	incl	%r15d
	cltd
	idivl	%ecx
	movq	8(%rsp), %rax
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%rax,%rsi,4)
	jmp	.L48
.L80:
	xorl	%r15d, %r15d
.L50:
	movl	44(%rsp), %eax
	imull	%ebx, %eax
	cmpl	%eax, %r15d
	jnb	.L81
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	divss	.LC8(%rip), %xmm0
	movss	%xmm0, 28(%rsp)
	call	rand@PLT
	movl	%eax, %edx
	movl	%r15d, %eax
	incl	%r15d
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC9(%rip), %xmm0
	addss	28(%rsp), %xmm0
	movss	%xmm0, (%r12,%rax,4)
	jmp	.L50
.L81:
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	120(%rsp), %rsi
	movl	$4, %edi
	call	clock_gettime@PLT
	movl	44(%rsp), %r15d
	movl	%ebx, %r8d
	movq	%r12, %rsi
	movl	filter_radius(%rip), %r9d
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	%r15d, %ecx
	call	_Z17convolutionRowCPUPfS_S_iii
	movq	8(%rsp), %rdx
	movl	%r15d, %ecx
	movq	%r13, %rdi
	movq	16(%rsp), %rsi
	call	_Z20convolutionColumnCPUPfS_S_iii
	leaq	136(%rsp), %rsi
	movl	$4, %edi
	call	clock_gettime@PLT
	movq	144(%rsp), %rax
	movl	$2, %edi
	subq	128(%rsp), %rax
	cvtsi2sdq	%rax, %xmm0
	movq	136(%rsp), %rax
	subq	120(%rsp), %rax
	divsd	.LC11(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	leaq	.LC12(%rip), %rsi
	movb	$1, %al
	addsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	leal	-1(%rbx), %eax
	movl	$32, %ecx
	movl	44(%rsp), %edi
	cltd
	movl	$1, 104(%rsp)
	idivl	%ecx
	movl	filter_radius(%rip), %edx
	movl	$1, 116(%rsp)
	leal	(%rdi,%rdx,2), %ecx
	movl	%ecx, %esi
	imull	%ecx, %esi
	incl	%eax
	movl	%eax, 96(%rsp)
	movl	%eax, 100(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 108(%rsp)
	xorl	%eax, %eax
.L52:
	cmpl	%esi, %eax
	jnb	.L82
	movl	$0x00000000, 0(%rbp,%rax,4)
	incq	%rax
	jmp	.L52
.L82:
	leal	1(%rcx), %eax
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	imull	%edx, %eax
.L54:
	cmpl	%esi, %ebx
	je	.L83
	xorl	%edx, %edx
.L56:
	cmpl	%edx, %edi
	je	.L84
	leal	(%rdx,%r8), %r10d
	leal	(%rdx,%rax), %r9d
	incl	%edx
	movss	(%r12,%r10,4), %xmm0
	movss	%xmm0, 0(%rbp,%r9,4)
	jmp	.L56
.L84:
	incl	%esi
	addl	%edi, %r8d
	addl	%ecx, %eax
	jmp	.L54
.L83:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	filter_radius(%rip), %eax
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movq	48(%rsp), %rdi
	leal	1(%rax,%rax), %edx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	filter_radius(%rip), %eax
	movl	44(%rsp), %edx
	movq	%rbp, %rsi
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	addl	%eax, %eax
	addl	%eax, %edx
	addl	%ebx, %eax
	imull	%eax, %edx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	116(%rsp), %ecx
	movl	104(%rsp), %esi
	xorl	%r9d, %r9d
	movq	108(%rsp), %rdx
	movq	96(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L57
	movl	filter_radius(%rip), %r9d
	movl	44(%rsp), %ecx
	movl	%ebx, %r8d
	movq	48(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z44__device_stub__Z17convolutionRowGPUPfS_S_iiiPfS_S_iii
.L57:
	call	cudaThreadSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L79
	movl	116(%rsp), %ecx
	movq	108(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	96(%rsp), %rdi
	movl	104(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L60
	movl	filter_radius(%rip), %r9d
	movl	44(%rsp), %ecx
	movl	%ebx, %r8d
	movq	48(%rsp), %rdx
	movq	64(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_Z47__device_stub__Z20convolutionColumnGPUPfS_S_iiiPfS_S_iii
.L60:
	call	cudaThreadSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L61
.L79:
	call	cudaGetErrorString@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L76
.L61:
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	filter_radius(%rip), %eax
	movl	44(%rsp), %edx
	movq	%r14, %rdi
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	addl	%eax, %eax
	addl	%eax, %edx
	addl	%ebx, %eax
	imull	%eax, %edx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	40(%rsp), %xmm0
	call	__printf_chk@PLT
	xorl	%edi, %edi
	xorl	%ecx, %ecx
	movl	filter_radius(%rip), %edx
	movl	44(%rsp), %esi
	xorps	%xmm1, %xmm1
	movss	.LC16(%rip), %xmm2
	movsd	.LC17(%rip), %xmm3
	leal	(%rsi,%rdx,2), %r9d
	leal	1(%r9), %eax
	imull	%edx, %eax
.L62:
	cmpl	%ecx, %esi
	je	.L85
	xorl	%edx, %edx
.L68:
	cmpl	%edx, %ebx
	je	.L86
	leal	(%rdx,%rdi), %r10d
	leal	(%rax,%rdx), %r8d
	movss	0(%r13,%r10,4), %xmm0
	subss	(%r14,%r8,4), %xmm0
	comiss	%xmm0, %xmm1
	jbe	.L63
	xorps	%xmm2, %xmm0
.L63:
	cvtss2sd	%xmm0, %xmm0
	comisd	%xmm3, %xmm0
	jbe	.L74
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	call	cudaDeviceReset@PLT
	jmp	.L78
.L74:
	incl	%edx
	jmp	.L68
.L86:
	incl	%ecx
	addl	%esi, %edi
	addl	%r9d, %eax
	jmp	.L62
.L85:
	movq	%r13, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
.L76:
	call	cudaDeviceReset@PLT
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L69
	call	__stack_chk_fail@PLT
.L69:
	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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z20convolutionColumnGPUPfS_S_iii"
.LC20:
	.string	"_Z17convolutionRowGPUPfS_S_iii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC19(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z20convolutionColumnGPUPfS_S_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC20(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z17convolutionRowGPUPfS_S_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2059:
	.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	filter_radius
	.bss
	.align 4
	.type	filter_radius, @object
	.size	filter_radius, 4
filter_radius:
	.zero	4
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC8:
	.long	1258324097
	.align 4
.LC9:
	.long	805306368
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC11:
	.long	0
	.long	1104006501
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC16:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC17:
	.long	-1717986918
	.long	1068079513
	.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:

/*
* This sample implements a separable convolution 
* of a 2D image with an arbitrary filter.
*/


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


unsigned int filter_radius;

#define FILTER_LENGTH 	(2 * filter_radius + 1)
#define ABS(val)  	((val)<0.0 ? (-(val)) : (val))
#define accuracy  	0.05 


typedef float typeId;


////////////////////////////////////////////////////////////////////////////////
// Reference row convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionRowCPU(typeId *h_Dst, typeId *h_Src, typeId *h_Filter, 
                       int imageW, int imageH, int filterR) {

  int x, y, k;
                      
  for (y = 0; y < imageH; y++) {
    for (x = 0; x < imageW; x++) {
      typeId sum = 0;
	    
      for (k = -filterR; k <= filterR; k++) {
        int d = x + k;

        if (d >= 0 && d < imageW) {
          sum += h_Src[y * imageW + d] * h_Filter[filterR - k];
        }     

        h_Dst[y * imageW + x] = sum;
      }
    }
  }
        
}

/***************************************************	
 ********** ROW CONVOLUTION GPU	********************
 ***************************************************
 */

__global__ void convolutionRowGPU(typeId *d_Dst, typeId *d_Src, typeId *d_Filter, int imageW, int imageH, int filterR){
  
    int k;
    typeId sum = 0;
    int row = blockDim.y * blockIdx.y + threadIdx.y + filterR;
    int col = blockDim.x * blockIdx.x + threadIdx.x + filterR;
    int padW = imageW + filterR*2;
    
    for (k = -filterR; k <= filterR; k++) {
		int d = col + k;

		sum += d_Src[row * padW + d] * d_Filter[filterR - k];
    }
	d_Dst[row * padW + col] = sum;
    
}

////////////////////////////////////////////////////////////////////////////////
// Reference column convolution filter
////////////////////////////////////////////////////////////////////////////////
void convolutionColumnCPU(typeId *h_Dst, typeId *h_Src, typeId *h_Filter,
    			   int imageW, int imageH, int filterR) {

  int x, y, k;
  
  for (y = 0; y < imageH; y++) {
    for (x = 0; x < imageW; x++) {
      typeId sum = 0;

      for (k = -filterR; k <= filterR; k++) {
        int d = y + k;

        if (d >= 0 && d < imageH) {
          sum += h_Src[d * imageW + x] * h_Filter[filterR - k];
        }   
 
        h_Dst[y * imageW + x] = sum;
      }
    }
  }
    
}

/***********************************************************	
 ******** COLUMN CONVOLUTION GPU ***************************
 ***********************************************************
 */
__global__ void convolutionColumnGPU(typeId *d_Dst, typeId *d_Src, typeId *d_Filter, int imageW, int imageH, int filterR) {
    
  int k;
  typeId sum = 0;
  int row = blockDim.y * blockIdx.y + threadIdx.y + filterR;
  int col = blockDim.x * blockIdx.x + threadIdx.x + filterR;
  int padW = imageW + filterR*2;
  
  for (k = -filterR; k <= filterR; k++) {
	int d = row + k;

	sum += d_Src[col + padW * d] * d_Filter[filterR - k];
  }
  d_Dst[row * padW + col] = sum;
  
    
}


////////////////////////////////////////////////////////////////////////////////
// Main program
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
    
    typeId
    *h_Filter,
    *h_Input,
    *h_Buffer,
    *h_OutputCPU,
    *h_PaddedInput,
    *d_Filter,
    *d_Input,
    *d_Buffer,
    *d_OutputGPU,
    *result,
    diff;

    float elapsedTime;

    hipSetDevice(0);
    struct timespec  tv1, tv2;
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);
    int imageW;
    int imageH;
    unsigned int i, j;

	printf("Enter filter radius : ");
	scanf("%d", &filter_radius);

    printf("Enter image size. Should be a power of two and greater than %d : ", FILTER_LENGTH);
    scanf("%d", &imageW);
    imageH = imageW;

    printf("Image Width x Height = %i x %i\n\n", imageW, imageH);
    printf("Allocating and initializing host arrays...\n");
    
    h_Filter    = (typeId *)malloc(FILTER_LENGTH * sizeof(typeId));
    h_Input     = (typeId *)malloc(imageW * imageH * sizeof(typeId));
    h_Buffer    = (typeId *)malloc(imageW * imageH * sizeof(typeId));
    h_OutputCPU = (typeId *)malloc(imageW * imageH * sizeof(typeId));
    result 	= (typeId *)malloc((imageW+2*filter_radius) * (imageH+2*filter_radius)* sizeof(typeId));
    h_PaddedInput  = (typeId *)malloc((imageW+filter_radius*2 )*(2*filter_radius+ imageH) * sizeof(typeId));
    // Memory allocation check if any of them not allocated then error
    
    if(!(h_Filter && h_Input && h_Buffer && h_OutputCPU && h_PaddedInput && result)) {
		printf("Error allocating memory\n");
		exit(EXIT_FAILURE);
    }
    
    // Memory allocation on Device
    hipMalloc(&d_Filter,FILTER_LENGTH*sizeof(typeId));
    hipMalloc(&d_Input,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    hipMalloc(&d_Buffer,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    hipMalloc(&d_OutputGPU,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    
    // Check memory allocation on Device, if any of them failed, exit
    if (!(d_Filter && d_Input && d_Buffer && d_OutputGPU)) {
		printf("Cuda memory allocation failed\n");
		exit(EXIT_FAILURE);
    }
    // Initializing device values
    hipMemset(d_OutputGPU,0,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    hipMemset(d_Buffer,0,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));
    hipMemset(d_Input,0,(imageW+2*filter_radius)*(imageH+2*filter_radius)*sizeof(typeId));

    srand(200);

    for (i = 0; i < FILTER_LENGTH; i++) {
        h_Filter[i] = (typeId)(rand() % 16);
    }

    for (i = 0; i < imageW * imageH; i++) {
        h_Input[i] = (typeId)rand() / ((typeId)RAND_MAX / 255) + (typeId)rand() / (typeId)RAND_MAX;
    }


    // CPU computation
    printf("CPU computation...\n");
    clock_gettime(CLOCK_MONOTONIC_RAW, &tv1);
    convolutionRowCPU(h_Buffer, h_Input, h_Filter, imageW, imageH, filter_radius); 
    convolutionColumnCPU(h_OutputCPU, h_Buffer, h_Filter, imageW, imageH, filter_radius);     
    clock_gettime(CLOCK_MONOTONIC_RAW, &tv2);
     
    printf ("CPU time:  %10g seconds\n\n",
			(double) (tv2.tv_nsec - tv1.tv_nsec) / 1000000000.0 +
			(double) (tv2.tv_sec - tv1.tv_sec)); 
 
	dim3 dimGrid((imageH-1)/32 + 1,(imageH-1)/32 + 1);
	dim3 dimBlock(32,32);
    
    // init padded Input
    for(i=0;i<(imageW+2*filter_radius)*(imageW+2*filter_radius);i++) h_PaddedInput[i]=0;
    // filling the cells   
    for(i=0;i<imageH;i++){
      for(j=0;j<imageW;j++){
		h_PaddedInput[(i+filter_radius)*(2*filter_radius+imageW)+filter_radius+j]=h_Input[i*imageW+j];
      }
    }
    
    printf("GPU computation... \n");
    
    hipMemcpy(d_Filter,h_Filter,FILTER_LENGTH*sizeof(typeId),hipMemcpyHostToDevice);
    hipMemcpy(d_Input,h_PaddedInput,(imageH+2*filter_radius)*(imageW+2*filter_radius)*sizeof(typeId),hipMemcpyHostToDevice);
	hipEventRecord(start,0);
    // kernel invocation
    convolutionRowGPU <<< dimGrid,dimBlock >>>(d_Buffer,d_Input, d_Filter, imageW, imageH, filter_radius);
    hipDeviceSynchronize();
    
    //Check for errors
    hipError_t err = hipGetLastError();
    if(err != hipSuccess){
    	printf("Device Error:%s\n",hipGetErrorString(err));
    	hipDeviceReset();
    	return 0;
    }
    
    convolutionColumnGPU <<< dimGrid,dimBlock >>>(d_OutputGPU,d_Buffer, d_Filter, imageW, imageH, filter_radius);
    hipDeviceSynchronize();
    
    //Check for errors
    err = hipGetLastError();
    if(err != hipSuccess) {
		printf("Device Error:%s\n",hipGetErrorString(err));
		hipDeviceReset();
		return 0;
	}
	hipEventRecord(stop,0);
    //Copy results to host
    hipMemcpy(result, d_OutputGPU, (imageH+2*filter_radius)*(imageW+2*filter_radius)*sizeof(typeId), hipMemcpyDeviceToHost);
    
    
    hipEventSynchronize(stop);
    hipEventElapsedTime(&elapsedTime,start,stop);
    printf("GPU time: %f ms.\n\n",elapsedTime);
    
    // Checking accuracy error CPU vs CPU
    for(i=0; i<imageW; i++) {
		for(j=0; j<imageH; j++){
			diff= h_OutputCPU[i*imageW+j]-result[(i+filter_radius)*(imageW+2*filter_radius)+filter_radius+j];
				if(ABS(diff) > accuracy) {
					printf("Accuracy error <<%f>>\n ",ABS(diff));
					free(h_OutputCPU);
					free(h_Buffer);
					free(h_Input);
					free(h_Filter);
					free(h_PaddedInput);
					hipFree(d_OutputGPU);
					hipFree(d_Buffer);
					hipFree(d_Input);
					hipFree(d_Filter);
					hipDeviceReset();
					exit(EXIT_FAILURE);
				}
		}
	}

    // free all the allocated memory
    free(h_OutputCPU);
    free(h_Buffer);
    free(h_Input);
    free(h_Filter);
    free(h_PaddedInput);
    hipFree(d_OutputGPU);
    hipFree(d_Buffer);
    hipFree(d_Input);
	hipFree(d_Filter);
    
    // Do a device reset just in case... Bgalte to sxolio otan ylopoihsete CUDA
    hipDeviceReset();


    return 0;
}

	.text
	.file	"non_tiled_conv.hip"
	.globl	_Z17convolutionRowCPUPfS_S_iii  # -- Begin function _Z17convolutionRowCPUPfS_S_iii
	.type	_Z17convolutionRowCPUPfS_S_iii,@function
_Z17convolutionRowCPUPfS_S_iii:         # @_Z17convolutionRowCPUPfS_S_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
	movq	%rdi, -16(%rsp)                 # 8-byte Spill
	testl	%r8d, %r8d
	jle	.LBB0_11
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdx, %rax
	movl	%r9d, %edx
	negl	%edx
	movq	%rdx, -24(%rsp)                 # 8-byte Spill
	movslq	%edx, %rdx
	movslq	%r9d, %r10
	movslq	%ecx, %r14
	movl	%r8d, %edi
	movq	%rdi, -8(%rsp)                  # 8-byte Spill
	movl	%r14d, %ebx
	leaq	(,%r10,4), %rdi
	leaq	(,%rdx,4), %r11
	subq	%r11, %rdi
	addq	%rdi, %rax
	leaq	(%rsi,%rdx,4), %rsi
	movq	%r14, -32(%rsp)                 # 8-byte Spill
	leaq	(,%r14,4), %r14
	addl	%r10d, %r10d
	orq	$1, %r10
	xorl	%r15d, %r15d
.LBB0_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
                                        #       Child Loop BB0_6 Depth 3
	testl	%ecx, %ecx
	jle	.LBB0_10
# %bb.3:                                # %.lr.ph37
                                        #   in Loop: Header=BB0_2 Depth=1
	movq	%r15, %rdx
	imulq	-32(%rsp), %rdx                 # 8-byte Folded Reload
	movq	-16(%rsp), %rdi                 # 8-byte Reload
	leaq	(%rdi,%rdx,4), %r12
	movq	-24(%rsp), %r13                 # 8-byte Reload
	movq	%rsi, %rbp
	xorl	%r11d, %r11d
.LBB0_4:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_6 Depth 3
	testl	%r9d, %r9d
	js	.LBB0_9
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB0_4 Depth=2
	xorps	%xmm0, %xmm0
	xorl	%edi, %edi
	movq	%rax, %rdx
.LBB0_6:                                #   Parent Loop BB0_2 Depth=1
                                        #     Parent Loop BB0_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	leal	(%rdi,%r13), %r8d
	cmpl	%ecx, %r8d
	jae	.LBB0_8
# %bb.7:                                #   in Loop: Header=BB0_6 Depth=3
	movss	(%rbp,%rdi,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdx), %xmm1
	addss	%xmm1, %xmm0
.LBB0_8:                                #   in Loop: Header=BB0_6 Depth=3
	movss	%xmm0, (%r12,%r11,4)
	addq	$-4, %rdx
	incq	%rdi
	cmpl	%edi, %r10d
	jne	.LBB0_6
.LBB0_9:                                # %._crit_edge
                                        #   in Loop: Header=BB0_4 Depth=2
	incq	%r11
	addq	$4, %rbp
	incq	%r13
	cmpq	%rbx, %r11
	jne	.LBB0_4
.LBB0_10:                               # %._crit_edge38
                                        #   in Loop: Header=BB0_2 Depth=1
	incq	%r15
	addq	%r14, %rsi
	cmpq	-8(%rsp), %r15                  # 8-byte Folded Reload
	jne	.LBB0_2
.LBB0_11:                               # %._crit_edge40
	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	_Z17convolutionRowCPUPfS_S_iii, .Lfunc_end0-_Z17convolutionRowCPUPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z32__device_stub__convolutionRowGPUPfS_S_iii # -- Begin function _Z32__device_stub__convolutionRowGPUPfS_S_iii
	.type	_Z32__device_stub__convolutionRowGPUPfS_S_iii,@function
_Z32__device_stub__convolutionRowGPUPfS_S_iii: # @_Z32__device_stub__convolutionRowGPUPfS_S_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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z17convolutionRowGPUPfS_S_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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__convolutionRowGPUPfS_S_iii, .Lfunc_end1-_Z32__device_stub__convolutionRowGPUPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z20convolutionColumnCPUPfS_S_iii # -- Begin function _Z20convolutionColumnCPUPfS_S_iii
	.type	_Z20convolutionColumnCPUPfS_S_iii,@function
_Z20convolutionColumnCPUPfS_S_iii:      # @_Z20convolutionColumnCPUPfS_S_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
	movl	%ecx, -36(%rsp)                 # 4-byte Spill
	movq	%rdi, -16(%rsp)                 # 8-byte Spill
	testl	%r8d, %r8d
	jle	.LBB2_11
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdx, %r11
	movl	%r9d, %ecx
	negl	%ecx
	movslq	%ecx, %rax
	movslq	-36(%rsp), %r14                 # 4-byte Folded Reload
	movslq	%r9d, %rdx
	movl	%r8d, %edi
	movq	%rdi, -8(%rsp)                  # 8-byte Spill
	movl	%r14d, %ebx
	leaq	(,%rdx,4), %rdi
	leaq	(,%rax,4), %r10
	subq	%r10, %rdi
	addq	%rdi, %r11
	imulq	%r14, %rax
	leaq	(%rsi,%rax,4), %rax
	movq	%rax, -32(%rsp)                 # 8-byte Spill
	movq	%r14, -24(%rsp)                 # 8-byte Spill
	leaq	(,%r14,4), %r14
	leal	1(,%rdx,2), %edi
	xorl	%r15d, %r15d
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
                                        #       Child Loop BB2_6 Depth 3
	cmpl	$0, -36(%rsp)                   # 4-byte Folded Reload
	jle	.LBB2_10
# %bb.3:                                # %.lr.ph38
                                        #   in Loop: Header=BB2_2 Depth=1
	movq	%r15, %rax
	imulq	-24(%rsp), %rax                 # 8-byte Folded Reload
	movq	-16(%rsp), %rdx                 # 8-byte Reload
	leaq	(%rdx,%rax,4), %r12
	movq	-32(%rsp), %rsi                 # 8-byte Reload
	xorl	%r10d, %r10d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_6 Depth 3
	testl	%r9d, %r9d
	js	.LBB2_9
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB2_4 Depth=2
	xorps	%xmm0, %xmm0
	movl	%edi, %ebp
	movq	%rsi, %r13
	movl	%ecx, %eax
	movq	%r11, %rdx
.LBB2_6:                                #   Parent Loop BB2_2 Depth=1
                                        #     Parent Loop BB2_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	cmpl	%r8d, %eax
	jae	.LBB2_8
# %bb.7:                                #   in Loop: Header=BB2_6 Depth=3
	movss	(%r13), %xmm1                   # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdx), %xmm1
	addss	%xmm1, %xmm0
.LBB2_8:                                #   in Loop: Header=BB2_6 Depth=3
	movss	%xmm0, (%r12,%r10,4)
	addq	$-4, %rdx
	incl	%eax
	addq	%r14, %r13
	decl	%ebp
	jne	.LBB2_6
.LBB2_9:                                # %._crit_edge
                                        #   in Loop: Header=BB2_4 Depth=2
	incq	%r10
	addq	$4, %rsi
	cmpq	%rbx, %r10
	jne	.LBB2_4
.LBB2_10:                               # %._crit_edge39
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r15
	incl	%ecx
	addq	%r14, -32(%rsp)                 # 8-byte Folded Spill
	cmpq	-8(%rsp), %r15                  # 8-byte Folded Reload
	jne	.LBB2_2
.LBB2_11:                               # %._crit_edge41
	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_end2:
	.size	_Z20convolutionColumnCPUPfS_S_iii, .Lfunc_end2-_Z20convolutionColumnCPUPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z35__device_stub__convolutionColumnGPUPfS_S_iii # -- Begin function _Z35__device_stub__convolutionColumnGPUPfS_S_iii
	.type	_Z35__device_stub__convolutionColumnGPUPfS_S_iii,@function
_Z35__device_stub__convolutionColumnGPUPfS_S_iii: # @_Z35__device_stub__convolutionColumnGPUPfS_S_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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z20convolutionColumnGPUPfS_S_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z35__device_stub__convolutionColumnGPUPfS_S_iii, .Lfunc_end3-_Z35__device_stub__convolutionColumnGPUPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x4b008081                      # float 8421505
.LCPI4_1:
	.long	0x30000000                      # float 4.65661287E-10
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_2:
	.quad	0x41cdcd6500000000              # double 1.0E+9
.LCPI4_4:
	.quad	0x3fa999999999999a              # double 0.050000000000000003
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI4_3:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	96(%rsp), %rdi
	callq	hipEventCreate
	leaq	88(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.1, %edi
	movl	$filter_radius, %esi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	filter_radius(%rip), %eax
	leal	1(,%rax,2), %esi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	12(%rsp), %r15
	movl	$.L.str.1, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%r15), %r14d
	movl	$.L.str.3, %edi
	movl	%r14d, %esi
	movl	%r14d, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	filter_radius(%rip), %r13d
	leal	(,%r13,2), %eax
	leaq	4(,%rax,4), %rdi
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %rbx
	movl	(%r15), %ebp
	movl	%ebp, %eax
	imull	%r14d, %eax
	movslq	%eax, %r12
	shlq	$2, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, 80(%rsp)                  # 8-byte Spill
	leal	(%rbp,%r13,2), %eax
	movq	%rbx, %rbp
	leal	(%r14,%r13,2), %r13d
	imull	%eax, %r13d
	shlq	$2, %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%r13, %rdi
	callq	malloc
	testq	%r12, %r12
	je	.LBB4_39
# %bb.1:
	testq	%rbp, %rbp
	je	.LBB4_39
# %bb.2:
	testq	%r15, %r15
	je	.LBB4_39
# %bb.3:
	cmpq	$0, 56(%rsp)                    # 8-byte Folded Reload
	je	.LBB4_39
# %bb.4:
	cmpq	$0, 80(%rsp)                    # 8-byte Folded Reload
	je	.LBB4_39
# %bb.5:
	movq	%rax, %r13
	testq	%rax, %rax
	je	.LBB4_39
# %bb.6:
	leaq	48(%rsp), %rbx
	movq	%rbx, %rdi
	movq	16(%rsp), %rsi                  # 8-byte Reload
	callq	hipMalloc
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %ecx
	addl	12(%rsp), %ecx
	leal	(%r14,%rax,2), %esi
	imull	%ecx, %esi
	shlq	$2, %rsi
	leaq	32(%rsp), %rdi
	callq	hipMalloc
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %ecx
	addl	12(%rsp), %ecx
	leal	(%r14,%rax,2), %esi
	imull	%ecx, %esi
	shlq	$2, %rsi
	leaq	24(%rsp), %rdi
	callq	hipMalloc
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %ecx
	addl	12(%rsp), %ecx
	leal	(%r14,%rax,2), %esi
	imull	%ecx, %esi
	shlq	$2, %rsi
	leaq	40(%rsp), %rdi
	callq	hipMalloc
	cmpq	$0, (%rbx)
	je	.LBB4_40
# %bb.7:
	cmpq	$0, 32(%rsp)
	je	.LBB4_40
# %bb.8:
	cmpq	$0, 24(%rsp)
	je	.LBB4_40
# %bb.9:
	movq	40(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_40
# %bb.10:
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %ecx
	addl	12(%rsp), %ecx
	leal	(%r14,%rax,2), %edx
	imull	%ecx, %edx
	shlq	$2, %rdx
	xorl	%esi, %esi
	callq	hipMemset
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %ecx
	addl	12(%rsp), %ecx
	movq	24(%rsp), %rdi
	leal	(%r14,%rax,2), %edx
	imull	%ecx, %edx
	shlq	$2, %rdx
	xorl	%esi, %esi
	callq	hipMemset
	movl	filter_radius(%rip), %eax
	leal	(%rax,%rax), %ecx
	addl	12(%rsp), %ecx
	movq	32(%rsp), %rdi
	leal	(%r14,%rax,2), %edx
	imull	%ecx, %edx
	shlq	$2, %rdx
	xorl	%esi, %esi
	callq	hipMemset
	movl	$200, %edi
	callq	srand
	movq	$-1, %rbx
.LBB4_11:                               # =>This Inner Loop Header: Depth=1
	callq	rand
                                        # kill: def $eax killed $eax def $rax
	leal	15(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-16, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, 4(%rbp,%rbx,4)
	movl	filter_radius(%rip), %eax
	addl	%eax, %eax
	incq	%rbx
	cmpq	%rax, %rbx
	jb	.LBB4_11
# %bb.12:                               # %.preheader146
	cmpl	$0, 12(%rsp)
	sete	%al
	testq	%r14, %r14
	sete	%cl
	orb	%al, %cl
	jne	.LBB4_15
# %bb.13:                               # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB4_14:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, 16(%rsp)                 # 4-byte Spill
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_1(%rip), %xmm0
	addss	16(%rsp), %xmm0                 # 4-byte Folded Reload
	movss	%xmm0, (%r15,%rbx,4)
	incq	%rbx
	movl	12(%rsp), %eax
	imull	%r14d, %eax
	cmpq	%rax, %rbx
	jb	.LBB4_14
.LBB4_15:                               # %._crit_edge
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	leaq	120(%rsp), %rsi
	movl	$4, %edi
	callq	clock_gettime
	movl	12(%rsp), %ecx
	movl	%ecx, 64(%rsp)                  # 4-byte Spill
	movl	filter_radius(%rip), %r9d
	movl	%r9d, 16(%rsp)                  # 4-byte Spill
	movq	56(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r15, %rsi
	movq	%rbp, %rdx
	movl	%r14d, %r8d
	callq	_Z17convolutionRowCPUPfS_S_iii
	movq	80(%rsp), %rdi                  # 8-byte Reload
	movq	%rbx, %rsi
	movq	%rbp, 72(%rsp)                  # 8-byte Spill
	movq	%rbp, %rdx
	movl	64(%rsp), %ecx                  # 4-byte Reload
	movl	%r14d, %r8d
	movl	16(%rsp), %r9d                  # 4-byte Reload
	callq	_Z20convolutionColumnCPUPfS_S_iii
	leaq	136(%rsp), %rbx
	movl	$4, %edi
	movq	%rbx, %rsi
	callq	clock_gettime
	movq	(%rbx), %rax
	movq	8(%rbx), %rcx
	leaq	120(%rsp), %rdx
	subq	8(%rdx), %rcx
	cvtsi2sd	%rcx, %xmm1
	divsd	.LCPI4_2(%rip), %xmm1
	subq	(%rdx), %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm1, %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	leal	-1(%r14), %eax
	leal	30(%r14), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$5, %ecx
	incl	%ecx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	movq	%rcx, %rdx
	shlq	$32, %rdx
	movl	12(%rsp), %ebx
	movl	filter_radius(%rip), %ecx
	leal	(%rbx,%rcx,2), %ebp
	movl	%ebp, %eax
	imull	%ebp, %eax
	testl	%eax, %eax
	je	.LBB4_17
# %bb.16:                               # %.lr.ph154.preheader
	movq	%rdx, 104(%rsp)                 # 8-byte Spill
	movl	%eax, %edx
	shlq	$2, %rdx
	movq	%r13, %rdi
	xorl	%esi, %esi
	movq	%rcx, 64(%rsp)                  # 8-byte Spill
	callq	memset@PLT
	movq	104(%rsp), %rdx                 # 8-byte Reload
	movq	64(%rsp), %rcx                  # 8-byte Reload
.LBB4_17:                               # %.preheader145
	addq	%rdx, 16(%rsp)                  # 8-byte Folded Spill
	testq	%r14, %r14
	je	.LBB4_23
# %bb.18:                               # %.preheader144.lr.ph
	leal	(%rcx,%rcx), %eax
	addl	%ebx, %eax
	incl	%eax
	imull	%ecx, %eax
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.LBB4_19:                               # %.preheader144
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_21 Depth 2
	testq	%rbx, %rbx
	je	.LBB4_22
# %bb.20:                               # %.lr.ph158
                                        #   in Loop: Header=BB4_19 Depth=1
	movq	%rbx, %rsi
	movl	%ecx, %edi
	movl	%eax, %r8d
.LBB4_21:                               #   Parent Loop BB4_19 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edi, %r9d
	movss	(%r15,%r9,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movl	%r8d, %r9d
	movss	%xmm0, (%r13,%r9,4)
	incl	%r8d
	incl	%edi
	decq	%rsi
	jne	.LBB4_21
.LBB4_22:                               # %._crit_edge159
                                        #   in Loop: Header=BB4_19 Depth=1
	incl	%edx
	addl	%ebp, %eax
	addl	%ebx, %ecx
	cmpl	%r14d, %edx
	jne	.LBB4_19
.LBB4_23:                               # %._crit_edge161
	movabsq	$137438953504, %rbp             # imm = 0x2000000020
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movq	48(%rsp), %rdi
	movl	filter_radius(%rip), %eax
	addl	%eax, %eax
	leaq	4(,%rax,4), %rdx
	movq	72(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	movl	filter_radius(%rip), %edx
	leal	(%r14,%rdx,2), %eax
                                        # kill: def $edx killed $edx killed $rdx def $rdx
	addl	%edx, %edx
	addl	12(%rsp), %edx
	imull	%eax, %edx
	shlq	$2, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	96(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_25
# %bb.24:
	movq	24(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	48(%rsp), %rdx
	movl	12(%rsp), %ecx
	movl	filter_radius(%rip), %r9d
	movl	%r14d, %r8d
	callq	_Z32__device_stub__convolutionRowGPUPfS_S_iii
.LBB4_25:
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB4_29
# %bb.26:
	movq	%rbx, %rdi
	movl	$1, %esi
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_28
# %bb.27:
	movq	40(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	48(%rsp), %rdx
	movl	12(%rsp), %ecx
	movl	filter_radius(%rip), %r9d
	movl	%r14d, %r8d
	callq	_Z35__device_stub__convolutionColumnGPUPfS_S_iii
.LBB4_28:
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB4_31
.LBB4_29:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB4_30:
	callq	hipDeviceReset
	xorl	%eax, %eax
	addq	$152, %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
.LBB4_31:
	.cfi_def_cfa_offset 208
	movq	88(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rsi
	movl	filter_radius(%rip), %edx
	leal	(%r14,%rdx,2), %eax
                                        # kill: def $edx killed $edx killed $rdx def $rdx
	addl	%edx, %edx
	addl	12(%rsp), %edx
	imull	%eax, %edx
	shlq	$2, %rdx
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	88(%rsp), %rdi
	callq	hipEventSynchronize
	movq	96(%rsp), %rsi
	movq	88(%rsp), %rdx
	leaq	116(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbp), %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movl	12(%rsp), %eax
	testl	%eax, %eax
	movq	80(%rsp), %r11                  # 8-byte Reload
	je	.LBB4_37
# %bb.32:                               # %.preheader.lr.ph
	movl	filter_radius(%rip), %esi
	leal	(%rax,%rsi,2), %ecx
	leal	(%rax,%rsi,2), %edx
	incl	%edx
	imull	%esi, %edx
	movaps	.LCPI4_3(%rip), %xmm1           # xmm1 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	movsd	.LCPI4_4(%rip), %xmm2           # xmm2 = mem[0],zero
	xorl	%esi, %esi
.LBB4_33:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_34 Depth 2
	movq	%r14, %rdi
	movl	%ebx, %r8d
	movl	%edx, %r9d
	testq	%r14, %r14
	je	.LBB4_36
.LBB4_34:                               #   Parent Loop BB4_33 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r8d, %r10d
	movss	(%r11,%r10,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movl	%r9d, %r10d
	subss	(%r12,%r10,4), %xmm0
	movaps	%xmm0, %xmm3
	xorps	%xmm1, %xmm3
	maxss	%xmm0, %xmm3
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm3, %xmm0
	ucomisd	%xmm2, %xmm0
	ja	.LBB4_38
# %bb.35:                               #   in Loop: Header=BB4_34 Depth=2
	incl	%r9d
	incl	%r8d
	decq	%rdi
	jne	.LBB4_34
.LBB4_36:                               # %._crit_edge164
                                        #   in Loop: Header=BB4_33 Depth=1
	incl	%esi
	addl	%ecx, %edx
	addl	%eax, %ebx
	cmpl	%eax, %esi
	jne	.LBB4_33
.LBB4_37:                               # %._crit_edge166
	movq	%r11, %rdi
	callq	free
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	72(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	jmp	.LBB4_30
.LBB4_38:
	movl	$.L.str.12, %edi
	movb	$1, %al
	movq	%r11, %rbx
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	72(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	callq	hipDeviceReset
.LBB4_42:
	movl	$1, %edi
	callq	exit
.LBB4_39:
	movl	$.Lstr.1, %edi
	jmp	.LBB4_41
.LBB4_40:
	movl	$.Lstr.2, %edi
.LBB4_41:
	callq	puts@PLT
	jmp	.LBB4_42
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17convolutionRowGPUPfS_S_iii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z20convolutionColumnGPUPfS_S_iii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	filter_radius,@object           # @filter_radius
	.bss
	.globl	filter_radius
	.p2align	2, 0x0
filter_radius:
	.long	0                               # 0x0
	.size	filter_radius, 4

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

	.type	_Z20convolutionColumnGPUPfS_S_iii,@object # @_Z20convolutionColumnGPUPfS_S_iii
	.globl	_Z20convolutionColumnGPUPfS_S_iii
	.p2align	3, 0x0
_Z20convolutionColumnGPUPfS_S_iii:
	.quad	_Z35__device_stub__convolutionColumnGPUPfS_S_iii
	.size	_Z20convolutionColumnGPUPfS_S_iii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Enter filter radius : "
	.size	.L.str, 23

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%d"
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Enter image size. Should be a power of two and greater than %d : "
	.size	.L.str.2, 66

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Image Width x Height = %i x %i\n\n"
	.size	.L.str.3, 33

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"CPU time:  %10g seconds\n\n"
	.size	.L.str.8, 26

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Device Error:%s\n"
	.size	.L.str.10, 17

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"GPU time: %f ms.\n\n"
	.size	.L.str.11, 19

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Accuracy error <<%f>>\n "
	.size	.L.str.12, 24

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z17convolutionRowGPUPfS_S_iii"
	.size	.L__unnamed_1, 31

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z20convolutionColumnGPUPfS_S_iii"
	.size	.L__unnamed_2, 34

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Allocating and initializing host arrays..."
	.size	.Lstr, 43

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Error allocating memory"
	.size	.Lstr.1, 24

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Cuda memory allocation failed"
	.size	.Lstr.2, 30

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"CPU computation..."
	.size	.Lstr.3, 19

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"GPU computation... "
	.size	.Lstr.4, 20

	.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__convolutionRowGPUPfS_S_iii
	.addrsig_sym _Z35__device_stub__convolutionColumnGPUPfS_S_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym filter_radius
	.addrsig_sym _Z17convolutionRowGPUPfS_S_iii
	.addrsig_sym _Z20convolutionColumnGPUPfS_S_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17convolutionRowGPUPfS_S_iii ; -- Begin function _Z17convolutionRowGPUPfS_S_iii
	.globl	_Z17convolutionRowGPUPfS_S_iii
	.p2align	8
	.type	_Z17convolutionRowGPUPfS_S_iii,@function
_Z17convolutionRowGPUPfS_S_iii:         ; @_Z17convolutionRowGPUPfS_S_iii
; %bb.0:
	s_clause 0x4
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s3, s[0:1], 0x20
	s_load_b32 s8, s[0:1], 0x18
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v2, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s9, s2, 16
	s_and_b32 s10, s2, 0xffff
	s_mul_i32 s15, s15, s9
	s_mul_i32 s14, s14, s10
	s_lshl_b32 s2, s3, 1
	v_add3_u32 v4, s15, s3, v1
	v_add3_u32 v0, s14, s3, v2
	s_add_i32 s8, s2, s8
	s_cmp_gt_i32 s3, -1
	s_cbranch_scc0 .LBB0_4
; %bb.1:                                ; %.lr.ph
	v_mul_lo_u32 v3, v4, s8
	v_mov_b32_e32 v5, 0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v1, v3, v0
	v_add3_u32 v2, v2, v3, s14
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_ashrrev_i32_e32 v3, 31, v2
	s_ashr_i32 s3, s2, 31
	s_lshl_b64 s[10:11], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_add_u32 s10, s0, s10
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	s_addc_u32 s11, s1, s11
	s_add_i32 s2, s2, -1
	s_load_b32 s3, s[10:11], 0x0
	s_cmp_lg_u32 s2, -1
	v_add_nc_u32_e32 v2, 1, v2
	v_add_co_u32 v6, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v7, vcc_lo
	global_load_b32 v3, v[6:7], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v5, s3, v3
	s_cbranch_scc1 .LBB0_2
; %bb.3:                                ; %Flow
	s_mov_b32 s0, 0
	s_branch .LBB0_5
.LBB0_4:
	s_mov_b32 s0, -1
                                        ; implicit-def: $vgpr5
                                        ; implicit-def: $vgpr1
.LBB0_5:                                ; %Flow49
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccz .LBB0_7
; %bb.6:                                ; %.._crit_edge_crit_edge
	v_mad_u64_u32 v[1:2], null, v4, s8, v[0:1]
	v_mov_b32_e32 v5, 0
.LBB0_7:                                ; %._crit_edge
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_store_b32 v[0:1], v5, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17convolutionRowGPUPfS_S_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z17convolutionRowGPUPfS_S_iii, .Lfunc_end0-_Z17convolutionRowGPUPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 320
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z20convolutionColumnGPUPfS_S_iii ; -- Begin function _Z20convolutionColumnGPUPfS_S_iii
	.globl	_Z20convolutionColumnGPUPfS_S_iii
	.p2align	8
	.type	_Z20convolutionColumnGPUPfS_S_iii,@function
_Z20convolutionColumnGPUPfS_S_iii:      ; @_Z20convolutionColumnGPUPfS_S_iii
; %bb.0:
	s_clause 0x4
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s8, s[0:1], 0x20
	s_load_b32 s3, s[0:1], 0x18
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_dual_mov_b32 v2, 0 :: v_dual_and_b32 v1, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s9, s2, 16
	s_and_b32 s10, s2, 0xffff
	v_add_nc_u32_e32 v4, s8, v1
	s_lshl_b32 s2, s8, 1
	s_mul_i32 s15, s15, s9
	s_add_i32 s9, s2, s3
	s_cmp_lt_i32 s8, 0
	s_mul_i32 s14, s14, s10
	s_cbranch_scc1 .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	v_add_nc_u32_e32 v0, s15, v3
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v0, s9
	v_add3_u32 v0, v4, v0, s14
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_ashrrev_i32_e32 v1, 31, v0
	s_ashr_i32 s3, s2, 31
	s_lshl_b64 s[10:11], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_add_u32 s10, s0, s10
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_addc_u32 s11, s1, s11
	v_add_nc_u32_e32 v0, s9, v0
	s_load_b32 s3, s[10:11], 0x0
	s_add_i32 s2, s2, -1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s6, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v6, vcc_lo
	s_cmp_lg_u32 s2, -1
	global_load_b32 v1, v[5:6], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v2, s3, v1
	s_cbranch_scc1 .LBB1_2
.LBB1_3:                                ; %._crit_edge
	v_add3_u32 v0, s15, s8, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v0, s9
	v_add3_u32 v0, v4, s14, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z20convolutionColumnGPUPfS_S_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z20convolutionColumnGPUPfS_S_iii, .Lfunc_end1-_Z20convolutionColumnGPUPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 308
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17convolutionRowGPUPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z17convolutionRowGPUPfS_S_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z20convolutionColumnGPUPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z20convolutionColumnGPUPfS_S_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
