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

#define TILE_WIDTH 16

void printDevProp(cudaDeviceProp devProp) {
    // Source: https://stackoverflow.com/questions/32530604/how-can-i-get-number-of-cores-in-cuda-device
    printf("%s\n", devProp.name);
    printf("Major revision number:         %d\n", devProp.major);
    printf("Minor revision number:         %d\n", devProp.minor);
    printf("Total global memory:           %u bytes\n", devProp.totalGlobalMem);
    printf("Number of multiprocessors:     %d\n", devProp.multiProcessorCount);
    printf("Total shared memory per block: %u\n",devProp.sharedMemPerBlock);
    printf("Total registers per block:     %d\n", devProp.regsPerBlock);
    printf("Warp size:                     %d\n", devProp.warpSize);
    printf("Maximum memory pitch:          %u\n", devProp.memPitch);
    printf("Total constant memory:         %u\n", devProp.totalConstMem);
    printf("Maximum threads per block:     %d\n", devProp.maxThreadsPerBlock);
    printf("Maximum threads per dimension: %d,%d,%d\n", devProp.maxThreadsDim[0], devProp.maxThreadsDim[1], devProp.maxThreadsDim[2]);
    return;
}

void printMatrix(float *A, int rows, int cols) {
    printf("[\n");
    for (int i=0; i<rows; i++) {
        printf("  [");
        for (int j=0; j<cols; j++) {
            printf("%.2f, ", A[i*cols + j]);
        }
        printf("]\n");
    }
    printf("]\n");
}

void printMatrixFlat(float *A, int rows, int cols) {
    printf("[");
    for (int i=0; i<rows; i++) {
        for (int j=0; j<cols; j++) {
            printf("%.2f, ", A[i*cols + j]);
        }
    }
    printf("]\n");
}

void populateMatrix(float *A, int rows, int cols) {
    // Generate the values
    for (int i=0; i<rows; i++) {
        for (int j=0; j<cols; j++) {
            A[i*cols + j] = (float) rand() / (float) (RAND_MAX / 100);
        }
    }
}

__global__
void matmul_rec_glob(float *d_A, float *d_B, float *d_C, int n, int m, int k) {
    int rows = blockIdx.y * blockDim.y + threadIdx.y;
    int cols = blockIdx.x * blockDim.x + threadIdx.x;

    if ((rows < n) && (cols < m)) {
        float val = 0;
        for (int i = 0; i < k; i++) {
            val += d_B[rows*k + i] * d_C[i*m + cols];
        }
        d_A[rows*m + cols] = val;
    }
}

__global__
void matmul_rec_shar(float *d_A, float *d_B, float *d_C, int n, int m, int k) {

    __shared__ float B_shared[TILE_WIDTH][TILE_WIDTH];
    __shared__ float C_shared[TILE_WIDTH][TILE_WIDTH];

    int rows = blockIdx.y * TILE_WIDTH + threadIdx.y;
    int cols = blockIdx.x * TILE_WIDTH + threadIdx.x;

    if ((rows < n) && (cols < m)) {
        float val = 0;
        for (int i = 0; i<k/TILE_WIDTH; ++i){
            B_shared[threadIdx.y][threadIdx.x] = d_B[rows*k + i*TILE_WIDTH + threadIdx.x];
            C_shared[threadIdx.y][threadIdx.x] = d_C[(i*TILE_WIDTH + threadIdx.y)*k + cols];
            __syncthreads();
            for (int j = 0; j < TILE_WIDTH; ++j) {
                val += B_shared[threadIdx.y][j] * C_shared[j][threadIdx.x];
            }
            d_A[rows*k + cols] = val;
        }
    }
}

double hostFunction(float *A, float *B, float *C, int n, int m, int k, int blockSize, int kernel_choice) {
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    // Allocate device memory
    // A = B * C
    // A: n x m
    // B: n x k
    // C: k x m
    float *d_A, *d_B, *d_C;

    cudaMalloc(&d_A, n*m*sizeof(float));
    cudaMalloc(&d_B, n*k*sizeof(float));
    cudaMalloc(&d_C, k*m*sizeof(float));

    // Copy values to device memory
    cudaMemcpy(d_B, B, n*k*sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(d_C, C, k*m*sizeof(float), cudaMemcpyHostToDevice);

    // Call kernel function
    const int dimY = 16;
    const int dimX = 16;
    dim3 dimBlock(dimX, dimY, 1);
    dim3 dimGrid(ceil((float) n / dimX), ceil((float) m / dimY), 1);

    cudaEventRecord(start);
    if (kernel_choice == 0) {
        matmul_rec_glob<<<dimGrid, dimBlock>>>(d_A, d_B, d_C, n, m, k);
    }
    else if (kernel_choice == 1) {
        matmul_rec_shar<<<dimGrid, dimBlock>>>(d_A, d_B, d_C, n, m, k);
    }
    cudaEventRecord(stop);
    cudaDeviceSynchronize();

    cudaEventSynchronize(stop);
    float milliseconds = 0;
    cudaEventElapsedTime(&milliseconds, start, stop);

    // Get return value
    cudaMemcpy(A, d_A, n*m*sizeof(float), cudaMemcpyDeviceToHost);

    // Free memory
    cudaFree(d_A);
    cudaFree(d_B);
    cudaFree(d_C);

    return milliseconds;
}

int main() {
    // Device Query first
    int deviceCount;
    int blockSize = 1024;
    cudaGetDeviceCount(&deviceCount);
    int device;
    for (device = 0; device < deviceCount; ++device) {
        cudaDeviceProp deviceProp;
        cudaGetDeviceProperties(&deviceProp, device);
        printDevProp(deviceProp);
        blockSize = deviceProp.maxThreadsPerBlock;
    }

    // In my (Francis) local machine there is only one CUDA machine, so I'll hardcode that one here
    // Allocate memory
    // A = B * C
    // A: n x m
    // B: n x k
    // C: k x m
    const int n = 16;
    const int m = 16;
    const int k = 16;
    float *A, *B, *C;
    A = (float*) malloc(sizeof(float) * n * m);
    B = (float*) malloc(sizeof(float) * n * k);
    C = (float*) malloc(sizeof(float) * k * m);

    // Benchmarking
    // Source: https://devblogs.nvidia.com/how-implement-performance-metrics-cuda-cc/
    int kernel = 0;
    int runs = 5;
    double time_spent = 0.0;
    double ave_time = 0.0;
    printf("\n");

    while (kernel < 2) {
        printf("#%d:\t", kernel);
        for (int run=0; run<runs; run++) {
            populateMatrix(B, n, k);
            populateMatrix(C, k, m);
            time_spent = hostFunction(A, B, C, n, m, k, blockSize, kernel);
            ave_time += time_spent;
            printf("%.4f\t", time_spent);
        }
        ave_time /= runs;
        printf("Ave: %.4f\n", ave_time);
        kernel++;
    }

    // Check matrices
    printMatrix(A, n, m);
    printMatrix(B, n, k);
    printMatrix(C, k, m);

    // printMatrixFlat(A, n, m);
    // printMatrixFlat(B, n, k);
    // printMatrixFlat(C, k, m);

    // Free memory
    free(A);
    free(B);
    free(C);

    printf("\nDone!\n");
}
	.file	"tmpxft_002a8fa7_00000000-6_cs171-me2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s\n"
.LC1:
	.string	"Major revision number:         %d\n"
.LC2:
	.string	"Minor revision number:         %d\n"
.LC3:
	.string	"Total global memory:           %u bytes\n"
.LC4:
	.string	"Number of multiprocessors:     %d\n"
.LC5:
	.string	"Total shared memory per block: %u\n"
.LC6:
	.string	"Total registers per block:     %d\n"
.LC7:
	.string	"Warp size:                     %d\n"
.LC8:
	.string	"Maximum memory pitch:          %u\n"
.LC9:
	.string	"Total constant memory:         %u\n"
.LC10:
	.string	"Maximum threads per block:     %d\n"
.LC11:
	.string	"Maximum threads per dimension: %d,%d,%d\n"
	.text
	.globl	_Z12printDevProp14cudaDeviceProp
	.type	_Z12printDevProp14cudaDeviceProp, @function
_Z12printDevProp14cudaDeviceProp:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	16(%rsp), %rdx
	call	__printf_chk@PLT
	movl	376(%rsp), %edx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	380(%rsp), %edx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	304(%rsp), %rdx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	404(%rsp), %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	312(%rsp), %rdx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	320(%rsp), %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	324(%rsp), %edx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	328(%rsp), %rdx
	leaq	.LC8(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	368(%rsp), %rdx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	336(%rsp), %edx
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	348(%rsp), %r8d
	xorl	%eax, %eax
	movl	344(%rsp), %ecx
	movl	340(%rsp), %edx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12printDevProp14cudaDeviceProp, .-_Z12printDevProp14cudaDeviceProp
	.section	.rodata.str1.1
.LC12:
	.string	"[\n"
.LC13:
	.string	"  ["
.LC14:
	.string	"%.2f, "
.LC15:
	.string	"]\n"
	.text
	.globl	_Z11printMatrixPfii
	.type	_Z11printMatrixPfii, @function
_Z11printMatrixPfii:
.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
	movq	%rdi, %r14
	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
	movl	%esi, %ebp
	leaq	.LC12(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	__printf_chk@PLT
.L5:
	cmpl	%ebp, %r12d
	jge	.L11
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	call	__printf_chk@PLT
	movslq	%r13d, %rax
	leaq	(%r14,%rax,4), %rcx
.L6:
	cmpl	%r15d, %ebx
	jle	.L12
	leaq	.LC14(%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	.L6
.L12:
	leaq	.LC15(%rip), %rsi
	xorl	%eax, %eax
	incl	%r12d
	addl	%ebx, %r13d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L5
.L11:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC15(%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	_Z11printMatrixPfii, .-_Z11printMatrixPfii
	.section	.rodata.str1.1
.LC16:
	.string	"["
	.text
	.globl	_Z15printMatrixFlatPfii
	.type	_Z15printMatrixFlatPfii, @function
_Z15printMatrixFlatPfii:
.LFB2029:
	.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	%esi, %r14d
	leaq	.LC16(%rip), %rsi
	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
	movq	%rdi, %r12
	movl	$2, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	__printf_chk@PLT
	xorl	%edx, %edx
.L14:
	cmpl	%r14d, %edx
	jge	.L16
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,4), %r15
.L17:
	cmpl	%ebx, %ebp
	jle	.L19
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movl	%edx, 12(%rsp)
	cvtss2sd	(%r15,%rbx,4), %xmm0
	call	__printf_chk@PLT
	incq	%rbx
	movl	12(%rsp), %edx
	jmp	.L17
.L19:
	incl	%edx
	addl	%ebp, %r13d
	jmp	.L14
.L16:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC15(%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
.LFE2029:
	.size	_Z15printMatrixFlatPfii, .-_Z15printMatrixFlatPfii
	.globl	_Z14populateMatrixPfii
	.type	_Z14populateMatrixPfii, @function
_Z14populateMatrixPfii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%esi, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	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
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L21:
	cmpl	%r15d, %r14d
	jge	.L20
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,4), %rdx
.L24:
	cmpl	%ebx, %ebp
	jle	.L26
	movq	%rdx, 8(%rsp)
	call	rand@PLT
	movq	8(%rsp), %rdx
	cvtsi2ssl	%eax, %xmm0
	divss	.LC17(%rip), %xmm0
	movss	%xmm0, (%rdx,%rbx,4)
	incq	%rbx
	jmp	.L24
.L26:
	incl	%r14d
	addl	%ebp, %r13d
	jmp	.L21
.L20:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z14populateMatrixPfii, .-_Z14populateMatrixPfii
	.globl	_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii
	.type	_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii, @function
_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii:
.LFB2057:
	.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	.L27
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z15matmul_rec_globPfS_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
.L27:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii, .-_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii
	.globl	_Z15matmul_rec_globPfS_S_iii
	.type	_Z15matmul_rec_globPfS_S_iii, @function
_Z15matmul_rec_globPfS_S_iii:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2058:
	.size	_Z15matmul_rec_globPfS_S_iii, .-_Z15matmul_rec_globPfS_S_iii
	.globl	_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii
	.type	_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii, @function
_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii:
.LFB2059:
	.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	_Z15matmul_rec_sharPfS_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
.LFE2059:
	.size	_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii, .-_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii
	.globl	_Z15matmul_rec_sharPfS_S_iii
	.type	_Z15matmul_rec_sharPfS_S_iii, @function
_Z15matmul_rec_sharPfS_S_iii:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2060:
	.size	_Z15matmul_rec_sharPfS_S_iii, .-_Z15matmul_rec_sharPfS_S_iii
	.globl	_Z12hostFunctionPfS_S_iiiii
	.type	_Z12hostFunctionPfS_S_iiiii, @function
_Z12hostFunctionPfS_S_iiiii:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%r9d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%ebx, %eax
	leaq	56(%rsp), %rdi
	imull	%ebp, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movl	%ebx, %edx
	leaq	64(%rsp), %rdi
	imull	%r12d, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	movq	%rdx, %rsi
	movq	%rdx, 24(%rsp)
	call	cudaMalloc@PLT
	movl	%ebp, %eax
	leaq	72(%rsp), %rdi
	imull	%r12d, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdx
	movq	64(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	72(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	cvtsi2ssl	%ebp, %xmm0
	mulss	.LC18(%rip), %xmm0
	movabsq	$68719476752, %rax
	movq	%rax, 80(%rsp)
	movl	$1, 88(%rsp)
	call	ceilf@PLT
	movd	%xmm0, %r14d
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC18(%rip), %xmm0
	call	ceilf@PLT
	movd	%r14d, %xmm1
	xorl	%esi, %esi
	movq	40(%rsp), %rdi
	cvttss2siq	%xmm0, %rax
	movl	$1, 100(%rsp)
	movl	%eax, 92(%rsp)
	cvttss2siq	%xmm1, %rax
	movl	%eax, 96(%rsp)
	call	cudaEventRecord@PLT
	cmpl	$0, 184(%rsp)
	jne	.L38
	movl	88(%rsp), %ecx
	movq	80(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	92(%rsp), %rdi
	movl	100(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	movl	%r12d, %r9d
	movl	%ebp, %r8d
	movq	56(%rsp), %rdi
	movl	%ebx, %ecx
	call	_Z42__device_stub__Z15matmul_rec_globPfS_S_iiiPfS_S_iii
	jmp	.L40
.L38:
	cmpl	$1, 184(%rsp)
	jne	.L40
	movl	88(%rsp), %ecx
	movq	80(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	92(%rsp), %rdi
	movl	100(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	movl	%r12d, %r9d
	movl	%ebp, %r8d
	movq	56(%rsp), %rdi
	movl	%ebx, %ecx
	call	_Z42__device_stub__Z15matmul_rec_sharPfS_S_iiiPfS_S_iii
.L40:
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	call	cudaDeviceSynchronize@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	36(%rsp), %rdi
	movl	$0x00000000, 36(%rsp)
	call	cudaEventElapsedTime@PLT
	movq	8(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	%r13, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	cvtss2sd	36(%rsp), %xmm0
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	call	__stack_chk_fail@PLT
.L42:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z12hostFunctionPfS_S_iiiii, .-_Z12hostFunctionPfS_S_iiiii
	.section	.rodata.str1.1
.LC21:
	.string	"\n"
.LC22:
	.string	"#%d:\t"
.LC23:
	.string	"%.4f\t"
.LC25:
	.string	"Ave: %.4f\n"
.LC26:
	.string	"\nDone!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.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
	movl	$1024, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$1096, %rsp
	.cfi_def_cfa_offset 1152
	movq	%fs:40, %rax
	movq	%rax, 1080(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rdi
	leaq	48(%rsp), %rbp
	call	cudaGetDeviceCount@PLT
.L45:
	cmpl	%ebx, 44(%rsp)
	jle	.L53
	movl	%ebx, %esi
	movq	%rbp, %rdi
	incl	%ebx
	call	cudaGetDeviceProperties_v2@PLT
	subq	$1040, %rsp
	.cfi_def_cfa_offset 2192
	movl	$258, %ecx
	movq	%rbp, %rsi
	movq	%rsp, %rdi
	rep movsl
	call	_Z12printDevProp14cudaDeviceProp
	movl	1408(%rsp), %r12d
	addq	$1040, %rsp
	.cfi_def_cfa_offset 1152
	jmp	.L45
.L53:
	movl	$1024, %edi
	xorl	%ebp, %ebp
	leaq	.LC22(%rip), %r13
	call	malloc@PLT
	movl	$1024, %edi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movl	$1024, %edi
	movq	%rax, %r15
	call	malloc@PLT
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	movq	%rax, 16(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	$0x000000000, 8(%rsp)
.L48:
	movl	%ebp, %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$5, %ebx
	leaq	.LC23(%rip), %r14
.L47:
	movl	$16, %edx
	movl	$16, %esi
	movq	%r15, %rdi
	call	_Z14populateMatrixPfii
	movq	16(%rsp), %rdi
	movl	$16, %edx
	movl	$16, %esi
	call	_Z14populateMatrixPfii
	pushq	%rbp
	.cfi_def_cfa_offset 1160
	movq	%r15, %rsi
	movl	$16, %r9d
	pushq	%r12
	.cfi_def_cfa_offset 1168
	movq	40(%rsp), %rdi
	movl	$16, %r8d
	movl	$16, %ecx
	movq	32(%rsp), %rdx
	call	_Z12hostFunctionPfS_S_iiiii
	movsd	24(%rsp), %xmm1
	movq	%r14, %rsi
	movl	$2, %edi
	addsd	%xmm0, %xmm1
	movsd	%xmm1, 24(%rsp)
	popq	%rax
	.cfi_def_cfa_offset 1160
	movb	$1, %al
	popq	%rdx
	.cfi_def_cfa_offset 1152
	call	__printf_chk@PLT
	decl	%ebx
	jne	.L47
	movsd	8(%rsp), %xmm2
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	divsd	.LC24(%rip), %xmm2
	movaps	%xmm2, %xmm0
	movsd	%xmm2, 8(%rsp)
	call	__printf_chk@PLT
	testl	%ebp, %ebp
	jne	.L54
	movl	$1, %ebp
	jmp	.L48
.L54:
	movq	24(%rsp), %rdi
	movl	$16, %edx
	movl	$16, %esi
	call	_Z11printMatrixPfii
	movl	$16, %edx
	movl	$16, %esi
	movq	%r15, %rdi
	call	_Z11printMatrixPfii
	movq	16(%rsp), %rdi
	movl	$16, %esi
	movl	$16, %edx
	call	_Z11printMatrixPfii
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC26(%rip), %rsi
	call	__printf_chk@PLT
	movq	1080(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$1096, %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
.LFE2032:
	.size	main, .-main
	.section	.rodata.str1.1
.LC27:
	.string	"_Z15matmul_rec_sharPfS_S_iii"
.LC28:
	.string	"_Z15matmul_rec_globPfS_S_iii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2062:
	.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	.LC27(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15matmul_rec_sharPfS_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	.LC28(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15matmul_rec_globPfS_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
.LFE2062:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC17:
	.long	1269028618
	.align 4
.LC18:
	.long	1031798784
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC24:
	.long	0
	.long	1075052544
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

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

#define TILE_WIDTH 16

void printDevProp(hipDeviceProp_t devProp) {
    // Source: https://stackoverflow.com/questions/32530604/how-can-i-get-number-of-cores-in-cuda-device
    printf("%s\n", devProp.name);
    printf("Major revision number:         %d\n", devProp.major);
    printf("Minor revision number:         %d\n", devProp.minor);
    printf("Total global memory:           %u bytes\n", devProp.totalGlobalMem);
    printf("Number of multiprocessors:     %d\n", devProp.multiProcessorCount);
    printf("Total shared memory per block: %u\n",devProp.sharedMemPerBlock);
    printf("Total registers per block:     %d\n", devProp.regsPerBlock);
    printf("Warp size:                     %d\n", devProp.warpSize);
    printf("Maximum memory pitch:          %u\n", devProp.memPitch);
    printf("Total constant memory:         %u\n", devProp.totalConstMem);
    printf("Maximum threads per block:     %d\n", devProp.maxThreadsPerBlock);
    printf("Maximum threads per dimension: %d,%d,%d\n", devProp.maxThreadsDim[0], devProp.maxThreadsDim[1], devProp.maxThreadsDim[2]);
    return;
}

void printMatrix(float *A, int rows, int cols) {
    printf("[\n");
    for (int i=0; i<rows; i++) {
        printf("  [");
        for (int j=0; j<cols; j++) {
            printf("%.2f, ", A[i*cols + j]);
        }
        printf("]\n");
    }
    printf("]\n");
}

void printMatrixFlat(float *A, int rows, int cols) {
    printf("[");
    for (int i=0; i<rows; i++) {
        for (int j=0; j<cols; j++) {
            printf("%.2f, ", A[i*cols + j]);
        }
    }
    printf("]\n");
}

void populateMatrix(float *A, int rows, int cols) {
    // Generate the values
    for (int i=0; i<rows; i++) {
        for (int j=0; j<cols; j++) {
            A[i*cols + j] = (float) rand() / (float) (RAND_MAX / 100);
        }
    }
}

__global__
void matmul_rec_glob(float *d_A, float *d_B, float *d_C, int n, int m, int k) {
    int rows = blockIdx.y * blockDim.y + threadIdx.y;
    int cols = blockIdx.x * blockDim.x + threadIdx.x;

    if ((rows < n) && (cols < m)) {
        float val = 0;
        for (int i = 0; i < k; i++) {
            val += d_B[rows*k + i] * d_C[i*m + cols];
        }
        d_A[rows*m + cols] = val;
    }
}

__global__
void matmul_rec_shar(float *d_A, float *d_B, float *d_C, int n, int m, int k) {

    __shared__ float B_shared[TILE_WIDTH][TILE_WIDTH];
    __shared__ float C_shared[TILE_WIDTH][TILE_WIDTH];

    int rows = blockIdx.y * TILE_WIDTH + threadIdx.y;
    int cols = blockIdx.x * TILE_WIDTH + threadIdx.x;

    if ((rows < n) && (cols < m)) {
        float val = 0;
        for (int i = 0; i<k/TILE_WIDTH; ++i){
            B_shared[threadIdx.y][threadIdx.x] = d_B[rows*k + i*TILE_WIDTH + threadIdx.x];
            C_shared[threadIdx.y][threadIdx.x] = d_C[(i*TILE_WIDTH + threadIdx.y)*k + cols];
            __syncthreads();
            for (int j = 0; j < TILE_WIDTH; ++j) {
                val += B_shared[threadIdx.y][j] * C_shared[j][threadIdx.x];
            }
            d_A[rows*k + cols] = val;
        }
    }
}

double hostFunction(float *A, float *B, float *C, int n, int m, int k, int blockSize, int kernel_choice) {
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);

    // Allocate device memory
    // A = B * C
    // A: n x m
    // B: n x k
    // C: k x m
    float *d_A, *d_B, *d_C;

    hipMalloc(&d_A, n*m*sizeof(float));
    hipMalloc(&d_B, n*k*sizeof(float));
    hipMalloc(&d_C, k*m*sizeof(float));

    // Copy values to device memory
    hipMemcpy(d_B, B, n*k*sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(d_C, C, k*m*sizeof(float), hipMemcpyHostToDevice);

    // Call kernel function
    const int dimY = 16;
    const int dimX = 16;
    dim3 dimBlock(dimX, dimY, 1);
    dim3 dimGrid(ceil((float) n / dimX), ceil((float) m / dimY), 1);

    hipEventRecord(start);
    if (kernel_choice == 0) {
        matmul_rec_glob<<<dimGrid, dimBlock>>>(d_A, d_B, d_C, n, m, k);
    }
    else if (kernel_choice == 1) {
        matmul_rec_shar<<<dimGrid, dimBlock>>>(d_A, d_B, d_C, n, m, k);
    }
    hipEventRecord(stop);
    hipDeviceSynchronize();

    hipEventSynchronize(stop);
    float milliseconds = 0;
    hipEventElapsedTime(&milliseconds, start, stop);

    // Get return value
    hipMemcpy(A, d_A, n*m*sizeof(float), hipMemcpyDeviceToHost);

    // Free memory
    hipFree(d_A);
    hipFree(d_B);
    hipFree(d_C);

    return milliseconds;
}

int main() {
    // Device Query first
    int deviceCount;
    int blockSize = 1024;
    hipGetDeviceCount(&deviceCount);
    int device;
    for (device = 0; device < deviceCount; ++device) {
        hipDeviceProp_t deviceProp;
        hipGetDeviceProperties(&deviceProp, device);
        printDevProp(deviceProp);
        blockSize = deviceProp.maxThreadsPerBlock;
    }

    // In my (Francis) local machine there is only one CUDA machine, so I'll hardcode that one here
    // Allocate memory
    // A = B * C
    // A: n x m
    // B: n x k
    // C: k x m
    const int n = 16;
    const int m = 16;
    const int k = 16;
    float *A, *B, *C;
    A = (float*) malloc(sizeof(float) * n * m);
    B = (float*) malloc(sizeof(float) * n * k);
    C = (float*) malloc(sizeof(float) * k * m);

    // Benchmarking
    // Source: https://devblogs.nvidia.com/how-implement-performance-metrics-cuda-cc/
    int kernel = 0;
    int runs = 5;
    double time_spent = 0.0;
    double ave_time = 0.0;
    printf("\n");

    while (kernel < 2) {
        printf("#%d:\t", kernel);
        for (int run=0; run<runs; run++) {
            populateMatrix(B, n, k);
            populateMatrix(C, k, m);
            time_spent = hostFunction(A, B, C, n, m, k, blockSize, kernel);
            ave_time += time_spent;
            printf("%.4f\t", time_spent);
        }
        ave_time /= runs;
        printf("Ave: %.4f\n", ave_time);
        kernel++;
    }

    // Check matrices
    printMatrix(A, n, m);
    printMatrix(B, n, k);
    printMatrix(C, k, m);

    // printMatrixFlat(A, n, m);
    // printMatrixFlat(B, n, k);
    // printMatrixFlat(C, k, m);

    // Free memory
    free(A);
    free(B);
    free(C);

    printf("\nDone!\n");
}
	.text
	.file	"cs171-me2.hip"
	.globl	_Z12printDevProp20hipDeviceProp_tR0600 # -- Begin function _Z12printDevProp20hipDeviceProp_tR0600
	.type	_Z12printDevProp20hipDeviceProp_tR0600,@function
_Z12printDevProp20hipDeviceProp_tR0600: # @_Z12printDevProp20hipDeviceProp_tR0600
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	puts@PLT
	movl	360(%rbx), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	movl	364(%rbx), %esi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movq	288(%rbx), %rsi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	388(%rbx), %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movq	296(%rbx), %rsi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	304(%rbx), %esi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	308(%rbx), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movq	312(%rbx), %rsi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movq	352(%rbx), %rsi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	320(%rbx), %esi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	324(%rbx), %esi
	movl	328(%rbx), %edx
	movl	332(%rbx), %ecx
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end0:
	.size	_Z12printDevProp20hipDeviceProp_tR0600, .Lfunc_end0-_Z12printDevProp20hipDeviceProp_tR0600
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printMatrixPfii             # -- Begin function _Z11printMatrixPfii
	.type	_Z11printMatrixPfii,@function
_Z11printMatrixPfii:                    # @_Z11printMatrixPfii
	.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	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	movl	$.Lstr, %edi
	callq	puts@PLT
	testl	%ebp, %ebp
	jle	.LBB1_6
# %bb.1:                                # %.lr.ph16
	movl	%ebp, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%ebx, %r12d
	xorl	%ebp, %ebp
	xorl	%r13d, %r13d
.LBB1_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	testl	%ebx, %ebx
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	%ebp, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.14, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	incq	%r13
	addl	%ebx, %ebp
	cmpq	16(%rsp), %r13                  # 8-byte Folded Reload
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge17
	movl	$.Lstr.3, %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	puts@PLT                        # TAILCALL
.Lfunc_end1:
	.size	_Z11printMatrixPfii, .Lfunc_end1-_Z11printMatrixPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z15printMatrixFlatPfii         # -- Begin function _Z15printMatrixFlatPfii
	.type	_Z15printMatrixFlatPfii,@function
_Z15printMatrixFlatPfii:                # @_Z15printMatrixFlatPfii
	.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	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	movl	$91, %edi
	callq	putchar@PLT
	testl	%ebp, %ebp
	jle	.LBB2_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
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.14, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB2_2
.LBB2_6:                                # %._crit_edge13
	movl	$.Lstr.3, %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	puts@PLT                        # TAILCALL
.Lfunc_end2:
	.size	_Z15printMatrixFlatPfii, .Lfunc_end2-_Z15printMatrixFlatPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z14populateMatrixPfii
.LCPI3_0:
	.long	0x4ba3d70a                      # float 21474836
	.text
	.globl	_Z14populateMatrixPfii
	.type	_Z14populateMatrixPfii,@function
_Z14populateMatrixPfii:                 # @_Z14populateMatrixPfii
	.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
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB3_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB3_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	%xmm1, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB3_4
.LBB3_5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB3_2
.LBB3_6:                                # %._crit_edge13
	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
	retq
.Lfunc_end3:
	.size	_Z14populateMatrixPfii, .Lfunc_end3-_Z14populateMatrixPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__matmul_rec_globPfS_S_iii # -- Begin function _Z30__device_stub__matmul_rec_globPfS_S_iii
	.type	_Z30__device_stub__matmul_rec_globPfS_S_iii,@function
_Z30__device_stub__matmul_rec_globPfS_S_iii: # @_Z30__device_stub__matmul_rec_globPfS_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	$_Z15matmul_rec_globPfS_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_end4:
	.size	_Z30__device_stub__matmul_rec_globPfS_S_iii, .Lfunc_end4-_Z30__device_stub__matmul_rec_globPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__matmul_rec_sharPfS_S_iii # -- Begin function _Z30__device_stub__matmul_rec_sharPfS_S_iii
	.type	_Z30__device_stub__matmul_rec_sharPfS_S_iii,@function
_Z30__device_stub__matmul_rec_sharPfS_S_iii: # @_Z30__device_stub__matmul_rec_sharPfS_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	$_Z15matmul_rec_sharPfS_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_end5:
	.size	_Z30__device_stub__matmul_rec_sharPfS_S_iii, .Lfunc_end5-_Z30__device_stub__matmul_rec_sharPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z12hostFunctionPfS_S_iiiii
.LCPI6_0:
	.long	0x3d800000                      # float 0.0625
	.text
	.globl	_Z12hostFunctionPfS_S_iiiii
	.type	_Z12hostFunctionPfS_S_iiiii,@function
_Z12hostFunctionPfS_S_iiiii:            # @_Z12hostFunctionPfS_S_iiiii
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	%r9d, %ebx
	movl	%r8d, %r13d
	movl	%ecx, %r14d
	movq	%rdx, 56(%rsp)                  # 8-byte Spill
	movq	%rsi, 48(%rsp)                  # 8-byte Spill
	movq	%rdi, 72(%rsp)                  # 8-byte Spill
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	movl	%r13d, %eax
	imull	%r14d, %eax
	movslq	%eax, %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %rdi
	movq	%rsi, 64(%rsp)                  # 8-byte Spill
	callq	hipMalloc
	movl	%ebx, %eax
	imull	%r14d, %eax
	movslq	%eax, %rbp
	shlq	$2, %rbp
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	movl	%ebx, 4(%rsp)                   # 4-byte Spill
	imull	%r13d, %ebx
	movslq	%ebx, %r12
	shlq	$2, %r12
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rdi
	movq	56(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	cvtsi2ss	%r14d, %xmm0
	mulss	.LCPI6_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r15
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r13d, %xmm0
	mulss	.LCPI6_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %rbx
	movl	%r15d, %eax
	shlq	$32, %rbx
	orq	%rax, %rbx
	leaq	40(%rsp), %rax
	movq	(%rax), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	152(%rsp), %eax
	cmpl	$1, %eax
	je	.LBB6_4
# %bb.1:
	testl	%eax, %eax
	jne	.LBB6_6
# %bb.2:
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_6
# %bb.3:
	movq	8(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movl	%r14d, %ecx
	movl	%r13d, %r8d
	movl	4(%rsp), %r9d                   # 4-byte Reload
	callq	_Z30__device_stub__matmul_rec_globPfS_S_iii
	jmp	.LBB6_6
.LBB6_4:
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_6
# %bb.5:
	movq	8(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movl	%r14d, %ecx
	movl	%r13d, %r8d
	movl	4(%rsp), %r9d                   # 4-byte Reload
	callq	_Z30__device_stub__matmul_rec_sharPfS_S_iii
.LBB6_6:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	callq	hipDeviceSynchronize
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	84(%rsp), %rbx
	movl	$0, (%rbx)
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	movq	8(%rsp), %rsi
	movq	72(%rsp), %rdi                  # 8-byte Reload
	movq	64(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z12hostFunctionPfS_S_iiiii, .Lfunc_end6-_Z12hostFunctionPfS_S_iiiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI7_0:
	.long	0x4ba3d70a                      # float 21474836
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI7_1:
	.quad	0x4014000000000000              # double 5
	.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	$2984, %rsp                     # imm = 0xBA8
	.cfi_def_cfa_offset 3040
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	1500(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	jle	.LBB7_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
	leaq	1512(%rsp), %r14
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$184, %ecx
	movq	%rsp, %rdi
	movq	%r14, %rsi
	rep;movsq (%rsi), %es:(%rdi)
	callq	_Z12printDevProp20hipDeviceProp_tR0600
	incl	%ebx
	cmpl	1500(%rsp), %ebx
	jl	.LBB7_2
.LBB7_3:                                # %._crit_edge
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	movq	%rax, 1504(%rsp)                # 8-byte Spill
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	movq	%rax, %r14
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	movq	%rax, 1488(%rsp)                # 8-byte Spill
	movl	$10, %edi
	callq	putchar@PLT
	movb	$1, %al
	xorpd	%xmm0, %xmm0
	movsd	%xmm0, 1480(%rsp)               # 8-byte Spill
	xorl	%r12d, %r12d
.LBB7_4:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_5 Depth 2
                                        #       Child Loop BB7_6 Depth 3
                                        #         Child Loop BB7_7 Depth 4
                                        #       Child Loop BB7_10 Depth 3
                                        #         Child Loop BB7_11 Depth 4
	movl	%eax, 1496(%rsp)                # 4-byte Spill
	movl	$.L.str.18, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	xorl	%r13d, %r13d
.LBB7_5:                                # %.preheader.i.preheader
                                        #   Parent Loop BB7_4 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB7_6 Depth 3
                                        #         Child Loop BB7_7 Depth 4
                                        #       Child Loop BB7_10 Depth 3
                                        #         Child Loop BB7_11 Depth 4
	movq	%r14, %r15
	xorl	%ebx, %ebx
.LBB7_6:                                # %.preheader.i
                                        #   Parent Loop BB7_4 Depth=1
                                        #     Parent Loop BB7_5 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB7_7 Depth 4
	xorl	%ebp, %ebp
.LBB7_7:                                #   Parent Loop BB7_4 Depth=1
                                        #     Parent Loop BB7_5 Depth=2
                                        #       Parent Loop BB7_6 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI7_0(%rip), %xmm0
	movss	%xmm0, (%r14,%rbp,4)
	incq	%rbp
	cmpq	$16, %rbp
	jne	.LBB7_7
# %bb.8:                                # %._crit_edge.i
                                        #   in Loop: Header=BB7_6 Depth=3
	incq	%rbx
	addq	$64, %r14
	cmpq	$16, %rbx
	jne	.LBB7_6
# %bb.9:                                # %.preheader.i32.preheader
                                        #   in Loop: Header=BB7_5 Depth=2
	movq	1488(%rsp), %r14                # 8-byte Reload
	xorl	%ebx, %ebx
.LBB7_10:                               # %.preheader.i32
                                        #   Parent Loop BB7_4 Depth=1
                                        #     Parent Loop BB7_5 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB7_11 Depth 4
	xorl	%ebp, %ebp
.LBB7_11:                               #   Parent Loop BB7_4 Depth=1
                                        #     Parent Loop BB7_5 Depth=2
                                        #       Parent Loop BB7_10 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI7_0(%rip), %xmm0
	movss	%xmm0, (%r14,%rbp,4)
	incq	%rbp
	cmpq	$16, %rbp
	jne	.LBB7_11
# %bb.12:                               # %._crit_edge.i39
                                        #   in Loop: Header=BB7_10 Depth=3
	incq	%rbx
	addq	$64, %r14
	cmpq	$16, %rbx
	jne	.LBB7_10
# %bb.13:                               # %_Z14populateMatrixPfii.exit42
                                        #   in Loop: Header=BB7_5 Depth=2
	movl	%r12d, 8(%rsp)
	movq	1504(%rsp), %rdi                # 8-byte Reload
	movq	%r15, %r14
	movq	%r15, %rsi
	movq	1488(%rsp), %rdx                # 8-byte Reload
	movl	$16, %ecx
	movl	$16, %r8d
	movl	$16, %r9d
	callq	_Z12hostFunctionPfS_S_iiiii
	movsd	1480(%rsp), %xmm1               # 8-byte Reload
                                        # xmm1 = mem[0],zero
	addsd	%xmm0, %xmm1
	movsd	%xmm1, 1480(%rsp)               # 8-byte Spill
	movl	$.L.str.19, %edi
	movb	$1, %al
	callq	printf
	incl	%r13d
	cmpl	$5, %r13d
	jne	.LBB7_5
# %bb.14:                               #   in Loop: Header=BB7_4 Depth=1
	movsd	1480(%rsp), %xmm0               # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	.LCPI7_1(%rip), %xmm0
	movl	$.L.str.20, %edi
	movsd	%xmm0, 1480(%rsp)               # 8-byte Spill
	movb	$1, %al
	callq	printf
	movl	$1, %r12d
	testb	$1, 1496(%rsp)                  # 1-byte Folded Reload
	movl	$0, %eax
	jne	.LBB7_4
# %bb.15:
	movq	1504(%rsp), %rbx                # 8-byte Reload
	movq	%rbx, %rdi
	movl	$16, %esi
	movl	$16, %edx
	callq	_Z11printMatrixPfii
	movq	%r14, %rdi
	movl	$16, %esi
	movl	$16, %edx
	callq	_Z11printMatrixPfii
	movq	1488(%rsp), %r15                # 8-byte Reload
	movq	%r15, %rdi
	movl	$16, %esi
	movl	$16, %edx
	callq	_Z11printMatrixPfii
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$2984, %rsp                     # imm = 0xBA8
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	main, .Lfunc_end7-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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15matmul_rec_globPfS_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	$_Z15matmul_rec_sharPfS_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_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Major revision number:         %d\n"
	.size	.L.str.1, 35

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Minor revision number:         %d\n"
	.size	.L.str.2, 35

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Total global memory:           %u bytes\n"
	.size	.L.str.3, 41

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Number of multiprocessors:     %d\n"
	.size	.L.str.4, 35

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Total shared memory per block: %u\n"
	.size	.L.str.5, 35

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Total registers per block:     %d\n"
	.size	.L.str.6, 35

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Warp size:                     %d\n"
	.size	.L.str.7, 35

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Maximum memory pitch:          %u\n"
	.size	.L.str.8, 35

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Total constant memory:         %u\n"
	.size	.L.str.9, 35

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Maximum threads per block:     %d\n"
	.size	.L.str.10, 35

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Maximum threads per dimension: %d,%d,%d\n"
	.size	.L.str.11, 41

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"  ["
	.size	.L.str.13, 4

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"%.2f, "
	.size	.L.str.14, 7

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

	.type	_Z15matmul_rec_sharPfS_S_iii,@object # @_Z15matmul_rec_sharPfS_S_iii
	.globl	_Z15matmul_rec_sharPfS_S_iii
	.p2align	3, 0x0
_Z15matmul_rec_sharPfS_S_iii:
	.quad	_Z30__device_stub__matmul_rec_sharPfS_S_iii
	.size	_Z15matmul_rec_sharPfS_S_iii, 8

	.type	.L.str.18,@object               # @.str.18
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.18:
	.asciz	"#%d:\t"
	.size	.L.str.18, 6

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"%.4f\t"
	.size	.L.str.19, 6

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"Ave: %.4f\n"
	.size	.L.str.20, 11

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z15matmul_rec_sharPfS_S_iii"
	.size	.L__unnamed_2, 29

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"["
	.size	.Lstr, 2

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"]"
	.size	.Lstr.3, 2

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"\nDone!"
	.size	.Lstr.4, 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 _Z30__device_stub__matmul_rec_globPfS_S_iii
	.addrsig_sym _Z30__device_stub__matmul_rec_sharPfS_S_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z15matmul_rec_globPfS_S_iii
	.addrsig_sym _Z15matmul_rec_sharPfS_S_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15matmul_rec_globPfS_S_iii ; -- Begin function _Z15matmul_rec_globPfS_S_iii
	.globl	_Z15matmul_rec_globPfS_S_iii
	.p2align	8
	.type	_Z15matmul_rec_globPfS_S_iii,@function
_Z15matmul_rec_globPfS_S_iii:           ; @_Z15matmul_rec_globPfS_S_iii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v2, v0, 10, 10
	v_and_b32_e32 v3, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[0:1], null, s15, s3, v[2:3]
	v_mad_u64_u32 v[1:2], null, s14, s2, v[3:4]
	v_cmp_gt_i32_e32 vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s5, v1
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_cmp_lt_i32 s6, 1
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	v_mul_lo_u32 v2, v0, s6
	v_mov_b32_e32 v6, 0
	v_mov_b32_e32 v4, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s10, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s11, v3, vcc_lo
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v5, 31, v4
	s_add_i32 s6, s6, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s6, 0
	v_lshlrev_b64 v[7:8], 2, v[4:5]
	v_add_nc_u32_e32 v4, s5, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s0, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	global_load_b32 v5, v[2:3], off
	global_load_b32 v7, v[7:8], off
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v6, v5, v7
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v6, 0
.LBB0_5:                                ; %Flow54
	v_mad_u64_u32 v[2:3], null, v0, s5, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s9, v1, vcc_lo
	global_store_b32 v[0:1], v6, off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15matmul_rec_globPfS_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 9
		.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	_Z15matmul_rec_globPfS_S_iii, .Lfunc_end0-_Z15matmul_rec_globPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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	_Z15matmul_rec_sharPfS_S_iii ; -- Begin function _Z15matmul_rec_sharPfS_S_iii
	.globl	_Z15matmul_rec_sharPfS_S_iii
	.p2align	8
	.type	_Z15matmul_rec_sharPfS_S_iii,@function
_Z15matmul_rec_sharPfS_S_iii:           ; @_Z15matmul_rec_sharPfS_S_iii
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v5, v0, 10, 10
	v_and_b32_e32 v1, 0x3ff, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v2, s15, 4, v5
	v_lshl_add_u32 v0, s14, 4, v1
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s4, v2
	v_cmp_gt_i32_e64 s2, s5, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB1_6
; %bb.1:                                ; %.preheader
	s_cmp_lt_i32 s6, 16
	s_cbranch_scc1 .LBB1_6
; %bb.2:                                ; %.lr.ph
	v_mul_lo_u32 v9, v2, s6
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_dual_mov_b32 v11, 0 :: v_dual_lshlrev_b32 v8, 2, v1
	v_lshlrev_b32_e32 v6, 6, v5
	s_ashr_i32 s2, s6, 31
	s_mov_b32 s3, 0
	v_dual_mov_b32 v2, 0 :: v_dual_add_nc_u32 v3, v9, v0
	v_add_nc_u32_e32 v7, 0x400, v8
	s_lshr_b32 s2, s2, 28
	v_add_nc_u32_e32 v8, v6, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_add_nc_u32_e32 v9, v9, v1
	v_add_nc_u32_e32 v10, v7, v6
	s_add_i32 s2, s6, s2
	s_ashr_i32 s2, s2, 4
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s9, v4, vcc_lo
.LBB1_3:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_4 Depth 2
	s_lshl_b32 s4, s3, 4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v14, s4, v5
	v_add_nc_u32_e32 v1, s4, v9
	s_mov_b32 s4, 0
	v_mad_u64_u32 v[12:13], null, v14, s6, v[0:1]
	v_mov_b32_e32 v13, v2
	v_lshlrev_b64 v[14:15], 2, v[1:2]
	v_mov_b32_e32 v1, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[12:13], 2, v[12:13]
	v_add_co_u32 v14, vcc_lo, s10, v14
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v15, vcc_lo, s11, v15, vcc_lo
	v_add_co_u32 v12, vcc_lo, s0, v12
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v13, vcc_lo, s1, v13, vcc_lo
	global_load_b32 v14, v[14:15], off
	global_load_b32 v12, v[12:13], off
	s_waitcnt vmcnt(1)
	ds_store_b32 v8, v14
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v12
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB1_4:                                ;   Parent Loop BB1_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v12, s4, v6
	s_add_i32 s4, s4, 4
	ds_load_b32 v13, v1
	ds_load_b32 v12, v12
	v_add_nc_u32_e32 v1, 64, v1
	s_cmp_eq_u32 s4, 64
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v11, v12, v13
	s_cbranch_scc0 .LBB1_4
; %bb.5:                                ;   in Loop: Header=BB1_3 Depth=1
	s_add_i32 s3, s3, 1
	global_store_b32 v[3:4], v11, off
	s_cmp_eq_u32 s3, s2
	s_cbranch_scc0 .LBB1_3
.LBB1_6:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15matmul_rec_sharPfS_S_iii
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 36
		.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 16
		.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	_Z15matmul_rec_sharPfS_S_iii, .Lfunc_end1-_Z15matmul_rec_sharPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 436
; NumSgprs: 18
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 16
; 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:           _Z15matmul_rec_globPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15matmul_rec_globPfS_S_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .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
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 36
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15matmul_rec_sharPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15matmul_rec_sharPfS_S_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
