extern "C++" {
    #include "stdlib.h"
    #include "stdio.h"
}

#include <cuda.h>
#include <cuda_runtime.h>


__device__ __constant__ unsigned int
    d_input_height, d_input_width,
    d_filter_height, d_filter_width,
    d_output_height, d_output_width;


#define cudaErrorCheck(ans) { cudaAssert((ans), __FILE__, __LINE__); }


inline void cudaAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
    if (code != cudaSuccess)
    {
        fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
        if (abort) exit(code);
    }
}


void print_matrix(const char *name, float *matrix, int height, int width) {
    printf("%s\n", name);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            printf(" %5.4f", matrix[width * y + x]);
        }
        printf("\n");
    }
    printf("\n");
}


__device__
static int POSITION(int x, int y, int width) {
    return width * y + x;
}


__global__
void gpu__convolute(float *input, float *filter, float *output) {
    // idx = (width) * (y) + (x)
    int y = blockDim.y * blockIdx.y + threadIdx.y;
    int x = blockDim.x * blockIdx.x + threadIdx.x;
    int width = d_output_width;
    int idx = POSITION(x, y, width);

    if (x < d_output_width && y < d_output_height) {
        float result = 0.0;
        
        for (int cy = 0; cy < d_filter_height; cy++) {
            for (int cx = 0; cx < d_filter_width; cx++) {
                result += input[POSITION(x+cx, y+cy, d_input_width)] * filter[POSITION(cx, cy, d_filter_width)];
            }
        }
        
        output[idx] = result;
    }
}


void usage(char *executable) {
    printf("ERROR, incorrect arguments.\n");
    printf("usage:\n");
    printf("\t %s <input height: int> <input width: int> <filter height: int> <filter width: int>\n", executable);
    exit(1);
}


int main(int argc, char **argv) {
    if (argc < 5) {
        usage(argv[0]);
    }

    // Hard-code for testing output with linear version
    srand48(20171116);

    int input_height = atoi(argv[1]);
    int input_width = atoi(argv[2]);

    int filter_height = atoi(argv[3]);
    int filter_width = atoi(argv[4]);
    
    int no_write = 0;
    if (argc > 5 && !strcmp(argv[5], "--no-write")) {
        no_write = 1;
    }

    int output_height = input_height - filter_height + 1;
    int output_width = input_width - filter_width + 1;

    // Setup input array
    float *cpu__input = (float*) malloc(input_height * input_width * sizeof(float));
    for (int i = 0; i < input_height * input_width; i++) {
        cpu__input[i] = drand48() * 100;
    }

    // Setup filter array
    float *cpu__filter = (float*) malloc(filter_height * filter_width * sizeof(float));
    for (int i = 0; i < filter_height * filter_width; i++) {
        cpu__filter[i] = drand48() * 100;
    }

    // Setup output array
    float *cpu__output = (float*) malloc(output_height * output_width * sizeof(float));
    for (int i = 0; i < output_height * output_width; i++) {
        cpu__output[i] = 0.0;
    }

    if (!no_write) {
        print_matrix("input", cpu__input, input_height, input_width);
        print_matrix("filter", cpu__filter, filter_height, filter_width);
    }

    cudaSetDevice(0);

    // Copy scalar variables onto GPU
    cudaErrorCheck( cudaMemcpyToSymbol(d_input_height, (void*) &input_height, sizeof(unsigned int)) );
    cudaErrorCheck( cudaMemcpyToSymbol(d_input_width,  (void*) &input_width,  sizeof(unsigned int)) );

    cudaErrorCheck( cudaMemcpyToSymbol(d_filter_height, (void*) &filter_height, sizeof(unsigned int)) );
    cudaErrorCheck( cudaMemcpyToSymbol(d_filter_width,  (void*) &filter_width,  sizeof(unsigned int)) );

    cudaErrorCheck( cudaMemcpyToSymbol(d_output_height, (void*) &output_height, sizeof(unsigned int)) );
    cudaErrorCheck( cudaMemcpyToSymbol(d_output_width,  (void*) &output_width,  sizeof(unsigned int)) );

    float
        *gpu__input,
        *gpu__filter,
        *gpu__output;

    // Allocate memory for arrays on GPU
    cudaErrorCheck( cudaMalloc((void**) &gpu__input,  input_height  * input_width  * sizeof(float)) );
    cudaErrorCheck( cudaMalloc((void**) &gpu__filter, filter_height * filter_width * sizeof(float)) );
    cudaErrorCheck( cudaMalloc((void**) &gpu__output, output_height * output_width * sizeof(float)) );

    // Copy memory for arrays from CPU -> GPU
    cudaErrorCheck( cudaMemcpy(gpu__input,  cpu__input,  input_height  * input_width  * sizeof(float), cudaMemcpyHostToDevice) );
    cudaErrorCheck( cudaMemcpy(gpu__filter, cpu__filter, filter_height * filter_width * sizeof(float), cudaMemcpyHostToDevice) );
    cudaErrorCheck( cudaMemcpy(gpu__output, cpu__output, output_height * output_width * sizeof(float), cudaMemcpyHostToDevice) );

    float block_height = 16.0;
    float block_width = 16.0;

    dim3 dimGrid(ceil(output_width / block_width), ceil(output_height / block_height), 1);
    dim3 dimBlock(block_width, block_height, 1);

    gpu__convolute<<<dimGrid, dimBlock>>>(gpu__input, gpu__filter, gpu__output);
    
    cudaErrorCheck( cudaGetLastError() );

    // Copy memory for arrays from GPU -> CPU
    cudaErrorCheck( cudaMemcpy(cpu__output, gpu__output, output_height * output_width * sizeof(float), cudaMemcpyDeviceToHost) );

    if (!no_write) {
        print_matrix("output", cpu__output, output_height, output_width);
    }

    free(cpu__input);  cpu__input  = NULL;
    free(cpu__filter); cpu__filter = NULL;
    free(cpu__output); cpu__output = NULL;

    cudaFree(gpu__input);  gpu__input  = NULL;
    cudaFree(gpu__filter); gpu__filter = NULL;
    cudaFree(gpu__output); gpu__output = NULL;
}

	.file	"tmpxft_002077fb_00000000-6_convolution_gpu.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z10cudaAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC0:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z10cudaAssert9cudaErrorPKcib,"axG",@progbits,_Z10cudaAssert9cudaErrorPKcib,comdat
	.weak	_Z10cudaAssert9cudaErrorPKcib
	.type	_Z10cudaAssert9cudaErrorPKcib, @function
_Z10cudaAssert9cudaErrorPKcib:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L8
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L2
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10cudaAssert9cudaErrorPKcib, .-_Z10cudaAssert9cudaErrorPKcib
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%s\n"
.LC2:
	.string	" %5.4f"
.LC3:
	.string	"\n"
	.text
	.globl	_Z12print_matrixPKcPfii
	.type	_Z12print_matrixPKcPfii, @function
_Z12print_matrixPKcPfii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	movq	%rdi, %rdx
	movl	$2, %edi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	leaq	.LC1(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	__printf_chk@PLT
.L13:
	cmpl	%r14d, %r13d
	jge	.L15
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %rcx
.L16:
	cmpl	%r15d, %ebx
	jle	.L18
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rcx,%r15,4), %xmm0
	movq	%rcx, 8(%rsp)
	incq	%r15
	call	__printf_chk@PLT
	movq	8(%rsp), %rcx
	jmp	.L16
.L18:
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L13
.L15:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z12print_matrixPKcPfii, .-_Z12print_matrixPKcPfii
	.section	.rodata.str1.1
.LC4:
	.string	"ERROR, incorrect arguments.\n"
.LC5:
	.string	"usage:\n"
.LC6:
	.string	"\t %s <input height: int> <input width: int> <filter height: int> <filter width: int>\n"
	.text
	.globl	_Z5usagePc
	.type	_Z5usagePc, @function
_Z5usagePc:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC4(%rip), %rsi
	movq	%rdi, %rbx
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$2, %edi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rsi
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z5usagePc, .-_Z5usagePc
	.globl	_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_
	.type	_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_, @function
_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%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	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z14gpu__convolutePfS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	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 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L21:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_, .-_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_
	.globl	_Z14gpu__convolutePfS_S_
	.type	_Z14gpu__convolutePfS_S_, @function
_Z14gpu__convolutePfS_S_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_
	.cfi_endproc
.LFE2057:
	.size	_Z14gpu__convolutePfS_S_, .-_Z14gpu__convolutePfS_S_
	.section	.rodata.str1.1
.LC7:
	.string	"--no-write"
.LC10:
	.string	"input"
.LC11:
	.string	"filter"
.LC12:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/KeltonKarboviak/Csci532/master/Lab4/convolution_gpu.cu"
.LC14:
	.string	"output"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.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
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	cmpl	$4, %edi
	jg	.L27
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L42
	movq	(%rsi), %rdi
	call	_Z5usagePc
.L27:
	movl	%edi, 12(%rsp)
	movl	$20171116, %edi
	xorl	%ebp, %ebp
	call	srand48@PLT
	movq	8(%r12), %rdi
	call	atoi@PLT
	movq	16(%r12), %rdi
	movl	%eax, 16(%rsp)
	movl	%eax, %ebx
	call	atoi@PLT
	movq	24(%r12), %rdi
	movl	%eax, 20(%rsp)
	movl	%eax, %r13d
	call	atoi@PLT
	movq	32(%r12), %rdi
	movl	%eax, 24(%rsp)
	movl	%eax, %r15d
	call	atoi@PLT
	movl	12(%rsp), %edx
	movl	%eax, 28(%rsp)
	movl	%eax, %r14d
	cmpl	$5, %edx
	je	.L29
	movq	40(%r12), %rdi
	leaq	.LC7(%rip), %rsi
	xorl	%ebp, %ebp
	call	strcmp@PLT
	testl	%eax, %eax
	sete	%bpl
.L29:
	movl	%ebx, %eax
	imull	%r13d, %ebx
	subl	%r15d, %eax
	incl	%eax
	movl	%eax, 32(%rsp)
	movl	%r13d, %eax
	movslq	%ebx, %rdi
	xorl	%ebx, %ebx
	subl	%r14d, %eax
	salq	$2, %rdi
	incl	%eax
	movl	%eax, 36(%rsp)
	call	malloc@PLT
	movq	%rax, %r14
.L30:
	movl	16(%rsp), %eax
	imull	20(%rsp), %eax
	cmpl	%ebx, %eax
	jle	.L43
	call	drand48@PLT
	mulsd	.LC8(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%rbx,4)
	incq	%rbx
	jmp	.L30
.L43:
	movl	24(%rsp), %edi
	imull	28(%rsp), %edi
	xorl	%ebx, %ebx
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r13
.L32:
	movl	24(%rsp), %eax
	imull	28(%rsp), %eax
	cmpl	%ebx, %eax
	jle	.L44
	call	drand48@PLT
	mulsd	.LC8(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 0(%r13,%rbx,4)
	incq	%rbx
	jmp	.L32
.L44:
	movl	32(%rsp), %ebx
	imull	36(%rsp), %ebx
	movslq	%ebx, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r12
	xorl	%eax, %eax
.L34:
	cmpl	%eax, %ebx
	jle	.L45
	movl	$0x00000000, (%r12,%rax,4)
	incq	%rax
	jmp	.L34
.L45:
	testl	%ebp, %ebp
	jne	.L36
	movl	20(%rsp), %ecx
	movl	16(%rsp), %edx
	movq	%r14, %rsi
	leaq	.LC10(%rip), %rdi
	call	_Z12print_matrixPKcPfii
	movl	28(%rsp), %ecx
	movl	24(%rsp), %edx
	movq	%r13, %rsi
	leaq	.LC11(%rip), %rdi
	call	_Z12print_matrixPKcPfii
.L36:
	xorl	%edi, %edi
	leaq	.LC12(%rip), %rbx
	call	cudaSetDevice@PLT
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	16(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL14d_input_height(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$125, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	20(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL13d_input_width(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$126, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	24(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL15d_filter_height(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$128, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	28(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL14d_filter_width(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$129, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	32(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL15d_output_height(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$131, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	36(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL14d_output_width(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$132, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	16(%rsp), %esi
	imull	20(%rsp), %esi
	leaq	40(%rsp), %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$140, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	24(%rsp), %esi
	imull	28(%rsp), %esi
	leaq	48(%rsp), %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$141, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	32(%rsp), %esi
	imull	36(%rsp), %esi
	leaq	56(%rsp), %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$142, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	16(%rsp), %edx
	imull	20(%rsp), %edx
	movq	%r14, %rsi
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$145, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	24(%rsp), %edx
	imull	28(%rsp), %edx
	movq	%r13, %rsi
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$146, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	32(%rsp), %edx
	imull	36(%rsp), %edx
	movq	%r12, %rsi
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$147, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	cvtsi2ssl	32(%rsp), %xmm0
	mulss	.LC13(%rip), %xmm0
	call	ceilf@PLT
	movd	%xmm0, %r15d
	cvtsi2ssl	36(%rsp), %xmm0
	mulss	.LC13(%rip), %xmm0
	call	ceilf@PLT
	movd	%r15d, %xmm1
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttss2siq	%xmm0, %rax
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$68719476752, %rdx
	movl	%eax, 64(%rsp)
	cvttss2siq	%xmm1, %rax
	movl	%eax, 68(%rsp)
	movq	64(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z38__device_stub__Z14gpu__convolutePfS_S_PfS_S_
.L37:
	call	cudaGetLastError@PLT
	movl	$1, %ecx
	movl	$157, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	movl	32(%rsp), %edx
	imull	36(%rsp), %edx
	movq	%r12, %rdi
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$160, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z10cudaAssert9cudaErrorPKcib
	testl	%ebp, %ebp
	jne	.L38
	movl	36(%rsp), %ecx
	movl	32(%rsp), %edx
	movq	%r12, %rsi
	leaq	.LC14(%rip), %rdi
	call	_Z12print_matrixPKcPfii
.L38:
	movq	%r14, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	xorl	%eax, %eax
	movq	%rax, 40(%rsp)
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	xorl	%edx, %edx
	movq	%rdx, 48(%rsp)
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
.L42:
	call	__stack_chk_fail@PLT
.L39:
	addq	$104, %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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z14gpu__convolutePfS_S_"
.LC16:
	.string	"d_input_height"
.LC17:
	.string	"d_input_width"
.LC18:
	.string	"d_filter_height"
.LC19:
	.string	"d_filter_width"
.LC20:
	.string	"d_output_height"
.LC21:
	.string	"d_output_width"
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z14gpu__convolutePfS_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC16(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL14d_input_height(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC17(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL13d_input_width(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC18(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL15d_filter_height(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC19(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL14d_filter_width(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC20(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL15d_output_height(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC21(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL14d_output_width(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.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
	.local	_ZL14d_output_width
	.comm	_ZL14d_output_width,4,4
	.local	_ZL15d_output_height
	.comm	_ZL15d_output_height,4,4
	.local	_ZL14d_filter_width
	.comm	_ZL14d_filter_width,4,4
	.local	_ZL15d_filter_height
	.comm	_ZL15d_filter_height,4,4
	.local	_ZL13d_input_width
	.comm	_ZL13d_input_width,4,4
	.local	_ZL14d_input_height
	.comm	_ZL14d_input_height,4,4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC8:
	.long	0
	.long	1079574528
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC13:
	.long	1031798784
	.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:

extern "C++" {
    #include "stdlib.h"
    #include "stdio.h"
}

#include <hip/hip_runtime.h>



__device__ __constant__ unsigned int
    d_input_height, d_input_width,
    d_filter_height, d_filter_width,
    d_output_height, d_output_width;


#define cudaErrorCheck(ans) { cudaAssert((ans), __FILE__, __LINE__); }


inline void cudaAssert(hipError_t code, const char *file, int line, bool abort=true)
{
    if (code != hipSuccess)
    {
        fprintf(stderr,"GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
        if (abort) exit(code);
    }
}


void print_matrix(const char *name, float *matrix, int height, int width) {
    printf("%s\n", name);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            printf(" %5.4f", matrix[width * y + x]);
        }
        printf("\n");
    }
    printf("\n");
}


__device__
static int POSITION(int x, int y, int width) {
    return width * y + x;
}


__global__
void gpu__convolute(float *input, float *filter, float *output) {
    // idx = (width) * (y) + (x)
    int y = blockDim.y * blockIdx.y + threadIdx.y;
    int x = blockDim.x * blockIdx.x + threadIdx.x;
    int width = d_output_width;
    int idx = POSITION(x, y, width);

    if (x < d_output_width && y < d_output_height) {
        float result = 0.0;
        
        for (int cy = 0; cy < d_filter_height; cy++) {
            for (int cx = 0; cx < d_filter_width; cx++) {
                result += input[POSITION(x+cx, y+cy, d_input_width)] * filter[POSITION(cx, cy, d_filter_width)];
            }
        }
        
        output[idx] = result;
    }
}


void usage(char *executable) {
    printf("ERROR, incorrect arguments.\n");
    printf("usage:\n");
    printf("\t %s <input height: int> <input width: int> <filter height: int> <filter width: int>\n", executable);
    exit(1);
}


int main(int argc, char **argv) {
    if (argc < 5) {
        usage(argv[0]);
    }

    // Hard-code for testing output with linear version
    srand48(20171116);

    int input_height = atoi(argv[1]);
    int input_width = atoi(argv[2]);

    int filter_height = atoi(argv[3]);
    int filter_width = atoi(argv[4]);
    
    int no_write = 0;
    if (argc > 5 && !strcmp(argv[5], "--no-write")) {
        no_write = 1;
    }

    int output_height = input_height - filter_height + 1;
    int output_width = input_width - filter_width + 1;

    // Setup input array
    float *cpu__input = (float*) malloc(input_height * input_width * sizeof(float));
    for (int i = 0; i < input_height * input_width; i++) {
        cpu__input[i] = drand48() * 100;
    }

    // Setup filter array
    float *cpu__filter = (float*) malloc(filter_height * filter_width * sizeof(float));
    for (int i = 0; i < filter_height * filter_width; i++) {
        cpu__filter[i] = drand48() * 100;
    }

    // Setup output array
    float *cpu__output = (float*) malloc(output_height * output_width * sizeof(float));
    for (int i = 0; i < output_height * output_width; i++) {
        cpu__output[i] = 0.0;
    }

    if (!no_write) {
        print_matrix("input", cpu__input, input_height, input_width);
        print_matrix("filter", cpu__filter, filter_height, filter_width);
    }

    hipSetDevice(0);

    // Copy scalar variables onto GPU
    cudaErrorCheck( hipMemcpyToSymbol(HIP_SYMBOL(d_input_height), (void*) &input_height, sizeof(unsigned int)) );
    cudaErrorCheck( hipMemcpyToSymbol(HIP_SYMBOL(d_input_width),  (void*) &input_width,  sizeof(unsigned int)) );

    cudaErrorCheck( hipMemcpyToSymbol(HIP_SYMBOL(d_filter_height), (void*) &filter_height, sizeof(unsigned int)) );
    cudaErrorCheck( hipMemcpyToSymbol(HIP_SYMBOL(d_filter_width),  (void*) &filter_width,  sizeof(unsigned int)) );

    cudaErrorCheck( hipMemcpyToSymbol(HIP_SYMBOL(d_output_height), (void*) &output_height, sizeof(unsigned int)) );
    cudaErrorCheck( hipMemcpyToSymbol(HIP_SYMBOL(d_output_width),  (void*) &output_width,  sizeof(unsigned int)) );

    float
        *gpu__input,
        *gpu__filter,
        *gpu__output;

    // Allocate memory for arrays on GPU
    cudaErrorCheck( hipMalloc((void**) &gpu__input,  input_height  * input_width  * sizeof(float)) );
    cudaErrorCheck( hipMalloc((void**) &gpu__filter, filter_height * filter_width * sizeof(float)) );
    cudaErrorCheck( hipMalloc((void**) &gpu__output, output_height * output_width * sizeof(float)) );

    // Copy memory for arrays from CPU -> GPU
    cudaErrorCheck( hipMemcpy(gpu__input,  cpu__input,  input_height  * input_width  * sizeof(float), hipMemcpyHostToDevice) );
    cudaErrorCheck( hipMemcpy(gpu__filter, cpu__filter, filter_height * filter_width * sizeof(float), hipMemcpyHostToDevice) );
    cudaErrorCheck( hipMemcpy(gpu__output, cpu__output, output_height * output_width * sizeof(float), hipMemcpyHostToDevice) );

    float block_height = 16.0;
    float block_width = 16.0;

    dim3 dimGrid(ceil(output_width / block_width), ceil(output_height / block_height), 1);
    dim3 dimBlock(block_width, block_height, 1);

    gpu__convolute<<<dimGrid, dimBlock>>>(gpu__input, gpu__filter, gpu__output);
    
    cudaErrorCheck( hipGetLastError() );

    // Copy memory for arrays from GPU -> CPU
    cudaErrorCheck( hipMemcpy(cpu__output, gpu__output, output_height * output_width * sizeof(float), hipMemcpyDeviceToHost) );

    if (!no_write) {
        print_matrix("output", cpu__output, output_height, output_width);
    }

    free(cpu__input);  cpu__input  = NULL;
    free(cpu__filter); cpu__filter = NULL;
    free(cpu__output); cpu__output = NULL;

    hipFree(gpu__input);  gpu__input  = NULL;
    hipFree(gpu__filter); gpu__filter = NULL;
    hipFree(gpu__output); gpu__output = NULL;
}

	.text
	.file	"convolution_gpu.hip"
	.globl	_Z12print_matrixPKcPfii         # -- Begin function _Z12print_matrixPKcPfii
	.type	_Z12print_matrixPKcPfii,@function
_Z12print_matrixPKcPfii:                # @_Z12print_matrixPKcPfii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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, %ebx
	movl	%edx, %ebp
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	callq	puts@PLT
	testl	%ebp, %ebp
	jle	.LBB0_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%ebx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB0_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB0_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB0_4:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB0_4
.LBB0_5:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB0_2
.LBB0_6:                                # %._crit_edge15
	movl	$10, %edi
	addq	$24, %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
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end0:
	.size	_Z12print_matrixPKcPfii, .Lfunc_end0-_Z12print_matrixPKcPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__gpu__convolutePfS_S_ # -- Begin function _Z29__device_stub__gpu__convolutePfS_S_
	.type	_Z29__device_stub__gpu__convolutePfS_S_,@function
_Z29__device_stub__gpu__convolutePfS_S_: # @_Z29__device_stub__gpu__convolutePfS_S_
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14gpu__convolutePfS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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	_Z29__device_stub__gpu__convolutePfS_S_, .Lfunc_end1-_Z29__device_stub__gpu__convolutePfS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z5usagePc                      # -- Begin function _Z5usagePc
	.type	_Z5usagePc,@function
_Z5usagePc:                             # @_Z5usagePc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z5usagePc, .Lfunc_end2-_Z5usagePc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x4059000000000000              # double 100
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI3_1:
	.long	0x3d800000                      # float 0.0625
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	cmpl	$4, %edi
	jle	.LBB3_47
# %bb.1:
	movl	%edi, %r14d
	movl	$20171116, %edi                 # imm = 0x133C96C
	callq	srand48
	movq	8(%rbx), %rdi
	callq	atoi
	movl	%eax, %r15d
	movl	%eax, 36(%rsp)
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r13d
	movl	%eax, 32(%rsp)
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, 20(%rsp)                  # 4-byte Spill
	movl	%eax, 28(%rsp)
	movq	32(%rbx), %rdi
	callq	atoi
	movl	%eax, 16(%rsp)                  # 4-byte Spill
	movl	%eax, 24(%rsp)
	movb	$1, %al
	cmpl	$5, %r14d
	je	.LBB3_3
# %bb.2:
	movq	40(%rbx), %rdi
	movl	$.L.str.6, %esi
	callq	strcmp
	testl	%eax, %eax
	setne	%al
.LBB3_3:
	movb	%al, 7(%rsp)                    # 1-byte Spill
	movl	%r15d, %ebp
	subl	20(%rsp), %ebp                  # 4-byte Folded Reload
	incl	%ebp
	movl	%ebp, 12(%rsp)
	movl	%r13d, %r12d
	subl	16(%rsp), %r12d                 # 4-byte Folded Reload
	incl	%r12d
	movl	%r12d, 8(%rsp)
	movl	%r13d, 64(%rsp)                 # 4-byte Spill
	movl	%r15d, 68(%rsp)                 # 4-byte Spill
	imull	%r15d, %r13d
	movslq	%r13d, %r15
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, %rbx
	testl	%r15d, %r15d
	jle	.LBB3_6
# %bb.4:                                # %.lr.ph.preheader
	movl	%r13d, %r14d
	xorl	%r13d, %r13d
.LBB3_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	drand48
	mulsd	.LCPI3_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rbx,%r13,4)
	incq	%r13
	cmpq	%r13, %r14
	jne	.LBB3_5
.LBB3_6:                                # %._crit_edge
	movl	16(%rsp), %r15d                 # 4-byte Reload
	imull	20(%rsp), %r15d                 # 4-byte Folded Reload
	movslq	%r15d, %r13
	leaq	(,%r13,4), %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%r13d, %r13d
	jle	.LBB3_9
# %bb.7:                                # %.lr.ph80.preheader
	movl	%r15d, %r13d
	xorl	%r15d, %r15d
.LBB3_8:                                # %.lr.ph80
                                        # =>This Inner Loop Header: Depth=1
	callq	drand48
	mulsd	.LCPI3_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %r13
	jne	.LBB3_8
.LBB3_9:                                # %._crit_edge81
	imull	%ebp, %r12d
	movslq	%r12d, %r15
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, %r13
	testl	%r15d, %r15d
	jle	.LBB3_11
# %bb.10:                               # %.lr.ph84.preheader
	movl	%r12d, %edx
	shlq	$2, %rdx
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB3_11:                               # %._crit_edge85
	movb	7(%rsp), %r12b                  # 1-byte Reload
	testb	%r12b, %r12b
	je	.LBB3_13
# %bb.12:
	movl	$.L.str.7, %edi
	movq	%rbx, %rsi
	movl	68(%rsp), %edx                  # 4-byte Reload
	movl	64(%rsp), %ecx                  # 4-byte Reload
	callq	_Z12print_matrixPKcPfii
	movl	$.L.str.8, %edi
	movq	%r14, %rsi
	movl	20(%rsp), %edx                  # 4-byte Reload
	movl	16(%rsp), %ecx                  # 4-byte Reload
	callq	_Z12print_matrixPKcPfii
.LBB3_13:
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	36(%rsp), %rsi
	movl	$d_input_height, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_14
# %bb.16:                               # %_Z10cudaAssert10hipError_tPKcib.exit
	leaq	32(%rsp), %rsi
	movl	$d_input_width, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_17
# %bb.18:                               # %_Z10cudaAssert10hipError_tPKcib.exit48
	leaq	28(%rsp), %rsi
	movl	$d_filter_height, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_19
# %bb.20:                               # %_Z10cudaAssert10hipError_tPKcib.exit50
	leaq	24(%rsp), %rsi
	movl	$d_filter_width, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_21
# %bb.22:                               # %_Z10cudaAssert10hipError_tPKcib.exit52
	leaq	12(%rsp), %rsi
	movl	$d_output_height, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_23
# %bb.24:                               # %_Z10cudaAssert10hipError_tPKcib.exit54
	leaq	8(%rsp), %rsi
	movl	$d_output_width, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB3_25
# %bb.26:                               # %_Z10cudaAssert10hipError_tPKcib.exit56
	movslq	36(%rsp), %rax
	movslq	32(%rsp), %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	56(%rsp), %rdi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_27
# %bb.28:                               # %_Z10cudaAssert10hipError_tPKcib.exit58
	movslq	28(%rsp), %rax
	movslq	24(%rsp), %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	48(%rsp), %rdi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_29
# %bb.30:                               # %_Z10cudaAssert10hipError_tPKcib.exit60
	movslq	12(%rsp), %rax
	movslq	8(%rsp), %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	40(%rsp), %rdi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_31
# %bb.32:                               # %_Z10cudaAssert10hipError_tPKcib.exit62
	movq	56(%rsp), %rdi
	movslq	36(%rsp), %rax
	movslq	32(%rsp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_33
# %bb.34:                               # %_Z10cudaAssert10hipError_tPKcib.exit64
	movq	48(%rsp), %rdi
	movslq	28(%rsp), %rax
	movslq	24(%rsp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_35
# %bb.36:                               # %_Z10cudaAssert10hipError_tPKcib.exit66
	movq	40(%rsp), %rdi
	movslq	12(%rsp), %rax
	movslq	8(%rsp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_37
# %bb.38:                               # %_Z10cudaAssert10hipError_tPKcib.exit68
	cvtsi2ssl	8(%rsp), %xmm0
	mulss	.LCPI3_1(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r15
	xorps	%xmm0, %xmm0
	cvtsi2ssl	12(%rsp), %xmm0
	mulss	.LCPI3_1(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %rdi
	movl	%r15d, %eax
	shlq	$32, %rdi
	orq	%rax, %rdi
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_40
# %bb.39:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	callq	_Z29__device_stub__gpu__convolutePfS_S_
.LBB3_40:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_41
# %bb.42:                               # %_Z10cudaAssert10hipError_tPKcib.exit70
	movq	40(%rsp), %rsi
	movslq	12(%rsp), %rax
	movslq	8(%rsp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_43
# %bb.44:                               # %_Z10cudaAssert10hipError_tPKcib.exit72
	testb	%r12b, %r12b
	je	.LBB3_46
# %bb.45:
	movl	12(%rsp), %edx
	movl	8(%rsp), %ecx
	movl	$.L.str.10, %edi
	movq	%r13, %rsi
	callq	_Z12print_matrixPKcPfii
.LBB3_46:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	56(%rsp), %rdi
	callq	hipFree
	xorl	%ebx, %ebx
	movq	%rbx, 56(%rsp)
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	%rbx, 48(%rsp)
	movq	40(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$72, %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
.LBB3_47:
	.cfi_def_cfa_offset 128
	movq	(%rbx), %rdi
	callq	_Z5usagePc
.LBB3_14:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$125, %r8d
	jmp	.LBB3_15
.LBB3_17:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$126, %r8d
	jmp	.LBB3_15
.LBB3_19:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$128, %r8d
	jmp	.LBB3_15
.LBB3_21:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$129, %r8d
	jmp	.LBB3_15
.LBB3_23:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$131, %r8d
	jmp	.LBB3_15
.LBB3_25:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$132, %r8d
	jmp	.LBB3_15
.LBB3_27:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$140, %r8d
	jmp	.LBB3_15
.LBB3_29:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$141, %r8d
	jmp	.LBB3_15
.LBB3_31:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$142, %r8d
	jmp	.LBB3_15
.LBB3_33:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$145, %r8d
	jmp	.LBB3_15
.LBB3_35:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$146, %r8d
	jmp	.LBB3_15
.LBB3_37:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$147, %r8d
	jmp	.LBB3_15
.LBB3_41:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$157, %r8d
	jmp	.LBB3_15
.LBB3_43:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movl	$.L.str.9, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$160, %r8d
.LBB3_15:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebp, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-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
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	subq	$32, %rsp
	.cfi_adjust_cfa_offset 32
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14gpu__convolutePfS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$d_input_height, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$d_input_width, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$d_filter_height, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$d_filter_width, %esi
	movl	$.L__unnamed_5, %edx
	movl	$.L__unnamed_5, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$d_output_height, %esi
	movl	$.L__unnamed_6, %edx
	movl	$.L__unnamed_6, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$d_output_width, %esi
	movl	$.L__unnamed_7, %edx
	movl	$.L__unnamed_7, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$__hip_module_dtor, %edi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	d_input_height,@object          # @d_input_height
	.local	d_input_height
	.comm	d_input_height,4,4
	.type	d_input_width,@object           # @d_input_width
	.local	d_input_width
	.comm	d_input_width,4,4
	.type	d_filter_height,@object         # @d_filter_height
	.local	d_filter_height
	.comm	d_filter_height,4,4
	.type	d_filter_width,@object          # @d_filter_width
	.local	d_filter_width
	.comm	d_filter_width,4,4
	.type	d_output_height,@object         # @d_output_height
	.local	d_output_height
	.comm	d_output_height,4,4
	.type	d_output_width,@object          # @d_output_width
	.local	d_output_width
	.comm	d_output_width,4,4
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	" %5.4f"
	.size	.L.str.1, 7

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

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"\t %s <input height: int> <input width: int> <filter height: int> <filter width: int>\n"
	.size	.L.str.5, 86

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"--no-write"
	.size	.L.str.6, 11

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"input"
	.size	.L.str.7, 6

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"filter"
	.size	.L.str.8, 7

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/KeltonKarboviak/Csci532/master/Lab4/convolution_gpu.hip"
	.size	.L.str.9, 118

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"output"
	.size	.L.str.10, 7

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str.11, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14gpu__convolutePfS_S_"
	.size	.L__unnamed_1, 25

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"d_input_height"
	.size	.L__unnamed_2, 15

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"d_input_width"
	.size	.L__unnamed_3, 14

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"d_filter_height"
	.size	.L__unnamed_4, 16

	.type	.L__unnamed_5,@object           # @4
.L__unnamed_5:
	.asciz	"d_filter_width"
	.size	.L__unnamed_5, 15

	.type	.L__unnamed_6,@object           # @5
.L__unnamed_6:
	.asciz	"d_output_height"
	.size	.L__unnamed_6, 16

	.type	.L__unnamed_7,@object           # @6
.L__unnamed_7:
	.asciz	"d_output_width"
	.size	.L__unnamed_7, 15

	.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	"ERROR, incorrect arguments."
	.size	.Lstr, 28

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"usage:"
	.size	.Lstr.1, 7

	.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 _Z29__device_stub__gpu__convolutePfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_input_height
	.addrsig_sym d_input_width
	.addrsig_sym d_filter_height
	.addrsig_sym d_filter_width
	.addrsig_sym d_output_height
	.addrsig_sym d_output_width
	.addrsig_sym _Z14gpu__convolutePfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14gpu__convolutePfS_S_ ; -- Begin function _Z14gpu__convolutePfS_S_
	.globl	_Z14gpu__convolutePfS_S_
	.p2align	8
	.type	_Z14gpu__convolutePfS_S_,@function
_Z14gpu__convolutePfS_S_:               ; @_Z14gpu__convolutePfS_S_
; %bb.0:
	s_load_b32 s6, s[0:1], 0x24
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, d_output_width@rel32@lo+4
	s_addc_u32 s3, s3, d_output_width@rel32@hi+12
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, d_output_height@rel32@lo+4
	s_addc_u32 s5, s5, d_output_height@rel32@hi+12
	s_load_b32 s10, s[2:3], 0x0
	s_load_b32 s2, s[4:5], 0x0
	v_bfe_u32 v3, v0, 10, 10
	v_and_b32_e32 v2, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s6, 16
	s_and_b32 s4, s6, 0xffff
	v_mad_u64_u32 v[0:1], null, s15, s3, v[3:4]
	s_mul_i32 s3, s14, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v1, s3, v2
	v_cmp_gt_u32_e64 s2, s2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, s10, v1
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s2
	s_cbranch_execz .LBB0_9
; %bb.1:                                ; %.preheader29
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, d_filter_height@rel32@lo+4
	s_addc_u32 s5, s5, d_filter_height@rel32@hi+12
	s_mov_b32 s2, 0
	s_load_b32 s11, s[4:5], 0x0
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s11, 0
	s_cbranch_scc1 .LBB0_7
; %bb.2:                                ; %.preheader.lr.ph
	s_getpc_b64 s[8:9]
	s_add_u32 s8, s8, d_filter_width@rel32@lo+4
	s_addc_u32 s9, s9, d_filter_width@rel32@hi+12
	v_mov_b32_e32 v4, 0
	s_load_b32 s12, s[8:9], 0x0
	s_mov_b32 s15, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_lg_u32 s12, 0
	s_cselect_b32 s13, -1, 0
	s_getpc_b64 s[8:9]
	s_add_u32 s8, s8, d_input_width@rel32@lo+4
	s_addc_u32 s9, s9, d_input_width@rel32@hi+12
	s_load_b32 s14, s[8:9], 0x0
	s_waitcnt lgkmcnt(0)
	v_mul_lo_u32 v3, s14, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v5, v2, v3, s3
.LBB0_3:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	s_and_not1_b32 vcc_lo, exec_lo, s13
	s_cbranch_vccnz .LBB0_6
; %bb.4:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v2, v5
	s_lshl_b64 s[8:9], s[2:3], 2
	s_mov_b32 s3, s12
	s_add_u32 s8, s6, s8
	s_addc_u32 s9, s7, s9
.LBB0_5:                                ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_ashrrev_i32_e32 v3, 31, v2
	s_load_b32 s16, s[8:9], 0x0
	s_add_i32 s3, s3, -1
	s_add_u32 s8, s8, 4
	s_addc_u32 s9, s9, 0
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	v_add_nc_u32_e32 v2, 1, v2
	s_cmp_eq_u32 s3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v6, vcc_lo, s4, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v7, vcc_lo
	global_load_b32 v3, v[6:7], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v4, s16, v3
	s_cbranch_scc0 .LBB0_5
.LBB0_6:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v5, s14, v5
	s_add_i32 s15, s15, 1
	s_add_i32 s2, s2, s12
	s_cmp_eq_u32 s15, s11
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_8
.LBB0_7:
	v_mov_b32_e32 v4, 0
.LBB0_8:                                ; %._crit_edge34
	v_mad_u64_u32 v[2:3], null, v0, s10, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v4, off
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14gpu__convolutePfS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 17
		.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	_Z14gpu__convolutePfS_S_, .Lfunc_end0-_Z14gpu__convolutePfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 516
; NumSgprs: 19
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	d_input_height          ; @d_input_height
	.type	d_input_height,@object
	.section	.bss,"aw",@nobits
	.globl	d_input_height
	.p2align	2, 0x0
d_input_height:
	.long	0                               ; 0x0
	.size	d_input_height, 4

	.protected	d_input_width           ; @d_input_width
	.type	d_input_width,@object
	.globl	d_input_width
	.p2align	2, 0x0
d_input_width:
	.long	0                               ; 0x0
	.size	d_input_width, 4

	.protected	d_filter_height         ; @d_filter_height
	.type	d_filter_height,@object
	.globl	d_filter_height
	.p2align	2, 0x0
d_filter_height:
	.long	0                               ; 0x0
	.size	d_filter_height, 4

	.protected	d_filter_width          ; @d_filter_width
	.type	d_filter_width,@object
	.globl	d_filter_width
	.p2align	2, 0x0
d_filter_width:
	.long	0                               ; 0x0
	.size	d_filter_width, 4

	.protected	d_output_height         ; @d_output_height
	.type	d_output_height,@object
	.globl	d_output_height
	.p2align	2, 0x0
d_output_height:
	.long	0                               ; 0x0
	.size	d_output_height, 4

	.protected	d_output_width          ; @d_output_width
	.type	d_output_width,@object
	.globl	d_output_width
	.p2align	2, 0x0
d_output_width:
	.long	0                               ; 0x0
	.size	d_output_width, 4

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 d_input_height
	.addrsig_sym d_input_width
	.addrsig_sym d_filter_height
	.addrsig_sym d_filter_width
	.addrsig_sym d_output_height
	.addrsig_sym d_output_width
	.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:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14gpu__convolutePfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z14gpu__convolutePfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
