//Based on the work of Andrew Krepps
#include <stdio.h>
#include <math.h>
#include <chrono>
/*
* Used for multiplying two square matrices of the same size.
* Uses shared memory to store matrix c until it is time to copy
* the final array out to the CPU.
*/

__host__ cudaEvent_t get_time(void)
{
	cudaEvent_t time;
	cudaEventCreate(&time);
	cudaEventRecord(time);
	return time;
}

__global__ void dotMultAddShared(float *A, float *B, float *C, const int sideLen) {
    
    const uint cola = (blockIdx.x * blockDim.x) + threadIdx.x;
    const uint rowa = (blockIdx.y * blockDim.y) + threadIdx.y;
    
    const uint idx = (rowa*sideLen) + cola;
    
    extern __shared__ float a[];
    
    a[idx]= A[idx];
    
    // Hold threads in block for copy to finish
    __syncthreads();
    //printf("a[%d]: %f b[%d]: %f\n", idx, a[idx], idx, B[idx]);
    C[idx] = a[idx] * B[idx] + a[idx] + B[idx];
}

/*
* Used for multiplying two square matrices of the same size.
* Uses global memory for matrix c until it is time to copy
* the final array out to the CPU.
*/
__global__ void dotMultAdd(float *A, float *B, float *C, const int sideLen) {
    uint cola = (blockIdx.x * blockDim.x) + threadIdx.x;
    uint rowa = (blockIdx.y * blockDim.y) + threadIdx.y;
    
    int idx = (rowa*sideLen) + cola;
    
    C[idx] = A[idx] * B[idx] + A[idx] + B[idx];
}


int main(int argc, char** argv)
{
	// read command line arguments
	int totalThreads = (1 << 20);
	int blockSize = 256;
	
	if (argc >= 2) {
		totalThreads = atoi(argv[1]);
	}
	if (argc >= 3) {
		blockSize = atoi(argv[2]);
	}

	int numBlocks = totalThreads/blockSize;

	// validate command line arguments
	if (totalThreads % blockSize != 0) {
		++numBlocks;
		totalThreads = numBlocks*blockSize;
		
		printf("Warning: Total thread count is not evenly divisible by the block size\n");
		printf("The total number of threads will be rounded up to %d\n", totalThreads);
	}
	
// =======================================================================================
// Start my code

    // Using square matrices for ease.
    // Calculate matrix size and adjust totalThreads if it has no integer sqrt.
    const int side = static_cast<int>(sqrt(totalThreads));
    printf("Matrix size: %d x %d\n", side, side);
    if (totalThreads!=(side*side)) {
    	totalThreads = side*side;
    	numBlocks = totalThreads/blockSize;
    }
    
    printf("Total threads: %d\n", totalThreads);
    printf("Block size: %d\n", blockSize);
    printf("Number of blocks: %d\n", numBlocks);
    
    
    // 
    float *h_A, *h_B, *h_C1, *h_C2;
    float *d_a, *d_b, *d_c;
    
    h_A = (float*)malloc(totalThreads*sizeof(float));
    h_B = (float*)malloc(totalThreads*sizeof(float));
    h_C1 = (float*)malloc(totalThreads*sizeof(float));
    h_C2 = (float*)malloc(totalThreads*sizeof(float));
    
    cudaMalloc((void**)&d_a, totalThreads*sizeof(float));
    cudaMalloc((void**)&d_b, totalThreads*sizeof(float));
    cudaMalloc((void**)&d_c, totalThreads*sizeof(float));
    
    for(int i=0; i<totalThreads; i++) {
    	h_A[i] = 2.0f;
    	h_B[i] = 1.0f;
    	h_C1[i] = 0.0f;
    	h_C2[i] = 0.0f;
    }

    cudaEvent_t kernel_start, kernel_stop;
    cudaEventCreate(&kernel_start,0);
    cudaEventCreate(&kernel_stop,0);
    
    
    cudaMemcpy(d_a, h_A, totalThreads*sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, h_B, totalThreads*sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(d_c, h_C1, totalThreads*sizeof(float), cudaMemcpyHostToDevice);
    
    cudaEventRecord(kernel_start, 0);
    
    dotMultAddShared<<<numBlocks, blockSize, totalThreads*sizeof(int)>>>(d_a, d_b, d_c, side);
    
    cudaEventRecord(kernel_stop, 0);
    cudaEventSynchronize(kernel_stop);
    
    cudaMemcpy(h_C1, d_c, totalThreads*sizeof(float), cudaMemcpyDeviceToHost);
    
    float delta = 0.0f;
    cudaEventElapsedTime(&delta, kernel_start, kernel_stop);
    printf("duration using shared memory: %fmsn\n", delta);

    
    cudaEventRecord(kernel_start, 0);
    
    dotMultAdd<<<numBlocks, blockSize>>>(d_a, d_b, d_c, side);
    
    cudaEventRecord(kernel_stop, 0);
    cudaEventSynchronize(kernel_stop);
    
    cudaMemcpy(h_C2, d_c, totalThreads*sizeof(float), cudaMemcpyDeviceToHost);
    
    cudaEventElapsedTime(&delta, kernel_start, kernel_stop);
    printf("duration using global memory: %fmsn\n", delta);
    
    cudaFree(d_a);
    cudaFree(d_b);
    cudaFree(d_c);
    cudaEventDestroy(kernel_start);
    cudaEventDestroy(kernel_stop);
    
    bool different = false;
    for(int i=0; i<totalThreads; i++) {
    	if(h_C1[i] != h_C2[i])
    		different = true;
    }
    
    if(different)
    	printf("Different values detected at [%d]: h_C1=%f h_C2=%f\n", 0, h_C1[0], h_C2[0]);
    else
    	printf("%2.1f*%2.1f + %2.1f + %2.1f = %2.1f\n", h_A[0], h_B[0], h_A[0], h_B[0], h_C1[0]);
    
}

	.file	"tmpxft_00328063_00000000-6_assignment.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2130:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2130:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8get_timev
	.type	_Z8get_timev, @function
_Z8get_timev:
.LFB2126:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaEventCreate@PLT
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	(%rsp), %rax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2126:
	.size	_Z8get_timev, .-_Z8get_timev
	.globl	_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i
	.type	_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i, @function
_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i:
.LFB2152:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L6
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16dotMultAddSharedPfS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L6:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2152:
	.size	_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i, .-_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i
	.globl	_Z16dotMultAddSharedPfS_S_i
	.type	_Z16dotMultAddSharedPfS_S_i, @function
_Z16dotMultAddSharedPfS_S_i:
.LFB2153:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i
	.cfi_endproc
.LFE2153:
	.size	_Z16dotMultAddSharedPfS_S_i, .-_Z16dotMultAddSharedPfS_S_i
	.globl	_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i
	.type	_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i, @function
_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i:
.LFB2154:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10dotMultAddPfS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L11:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2154:
	.size	_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i, .-_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i
	.globl	_Z10dotMultAddPfS_S_i
	.type	_Z10dotMultAddPfS_S_i, @function
_Z10dotMultAddPfS_S_i:
.LFB2155:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i
	.cfi_endproc
.LFE2155:
	.size	_Z10dotMultAddPfS_S_i, .-_Z10dotMultAddPfS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Warning: Total thread count is not evenly divisible by the block size\n"
.LC1:
	.string	"The total number of threads will be rounded up to %d\n"
.LC2:
	.string	"Matrix size: %d x %d\n"
.LC3:
	.string	"Total threads: %d\n"
.LC4:
	.string	"Block size: %d\n"
.LC5:
	.string	"Number of blocks: %d\n"
.LC9:
	.string	"duration using shared memory: %fmsn\n"
.LC10:
	.string	"duration using global memory: %fmsn\n"
.LC11:
	.string	"Different values detected at [%d]: h_C1=%f h_C2=%f\n"
.LC12:
	.string	"%2.1f*%2.1f + %2.1f + %2.1f = %2.1f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2127:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	jle	.L31
	movl	%edi, %r13d
	movq	8(%rsi), %rdi
	movq	%rsi, %r12
	movl	$256, %ebx
	call	atoi@PLT
	movl	%eax, %ebp
	cmpl	$2, %r13d
	je	.L17
	movq	16(%r12), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	jmp	.L17
.L31:
	movl	$1048576, %ebp
	movl	$256, %ebx
.L17:
	movl	%ebp, %eax
	cltd
	idivl	%ebx
	movl	%eax, %r13d
	testl	%edx, %edx
	je	.L18
	incl	%r13d
	movl	%ebx, %ebp
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	imull	%r13d, %ebp
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	%ebp, %edx
	call	__printf_chk@PLT
.L18:
	cvtsi2sdl	%ebp, %xmm0
	call	sqrt@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	cvttsd2sil	%xmm0, %r15d
	movl	%r15d, %r12d
	movl	%r15d, %ecx
	movl	%r15d, %edx
	call	__printf_chk@PLT
	imull	%r15d, %r12d
	cmpl	%ebp, %r12d
	je	.L19
	movl	%r12d, %eax
	cltd
	idivl	%ebx
	movl	%eax, %r13d
.L19:
	movl	%r12d, %edx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%r13d, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	movslq	%r12d, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	(%rsp), %rsi
	leaq	40(%rsp), %rdi
	movq	%rax, %r14
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movss	.LC6(%rip), %xmm0
	movss	.LC7(%rip), %xmm1
	xorl	%eax, %eax
.L20:
	cmpl	%eax, %r12d
	jle	.L38
	movq	8(%rsp), %rcx
	movl	$0x00000000, 0(%rbp,%rax,4)
	movl	$0x00000000, (%r14,%rax,4)
	movss	%xmm0, (%rcx,%rax,4)
	movq	16(%rsp), %rcx
	movss	%xmm1, (%rcx,%rax,4)
	incq	%rax
	jmp	.L20
.L38:
	xorl	%esi, %esi
	leaq	64(%rsp), %rdi
	call	cudaEventCreateWithFlags@PLT
	xorl	%esi, %esi
	leaq	72(%rsp), %rdi
	call	cudaEventCreateWithFlags@PLT
	movq	(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movq	40(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	48(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	56(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%ebx, 92(%rsp)
	movq	(%rsp), %r8
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rax
	movl	%r13d, 80(%rsp)
	movq	%rax, 96(%rsp)
	movl	100(%rsp), %ecx
	movq	%rax, 84(%rsp)
	movq	92(%rsp), %rdx
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	%r15d, %ecx
	movq	40(%rsp), %rdi
	call	_Z41__device_stub__Z16dotMultAddSharedPfS_S_iPfS_S_i
.L22:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdx
	leaq	36(%rsp), %rax
	movq	64(%rsp), %rsi
	movq	%rax, %rdi
	movl	$0x00000000, 36(%rsp)
	movq	%rax, 24(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	36(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%ebx, 92(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r13d, 80(%rsp)
	movq	%rax, 96(%rsp)
	movl	100(%rsp), %ecx
	movq	%rax, 84(%rsp)
	movq	92(%rsp), %rdx
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	%r15d, %ecx
	movq	40(%rsp), %rdi
	call	_Z35__device_stub__Z10dotMultAddPfS_S_iPfS_S_i
.L23:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	%r14, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	36(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	72(%rsp), %rdi
	call	cudaEventDestroy@PLT
	xorl	%eax, %eax
	xorl	%edx, %edx
.L24:
	cmpl	%eax, %r12d
	jle	.L39
	movss	0(%rbp,%rax,4), %xmm0
	ucomiss	(%r14,%rax,4), %xmm0
	jp	.L33
	je	.L25
.L33:
	movb	$1, %dl
.L25:
	incq	%rax
	jmp	.L24
.L39:
	cvtss2sd	0(%rbp), %xmm4
	testb	%dl, %dl
	je	.L28
	movaps	%xmm4, %xmm0
	xorl	%edx, %edx
	leaq	.LC11(%rip), %rsi
	movb	$2, %al
	movl	$2, %edi
	cvtss2sd	(%r14), %xmm1
	call	__printf_chk@PLT
	jmp	.L29
.L28:
	movq	16(%rsp), %rax
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	(%rax), %xmm1
	movq	8(%rsp), %rax
	movaps	%xmm1, %xmm3
	cvtss2sd	(%rax), %xmm2
	movb	$5, %al
	movaps	%xmm2, %xmm0
	call	__printf_chk@PLT
.L29:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$120, %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
.LFE2127:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z10dotMultAddPfS_S_i"
.LC14:
	.string	"_Z16dotMultAddSharedPfS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2157:
	.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	.LC13(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10dotMultAddPfS_S_i(%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	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16dotMultAddSharedPfS_S_i(%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
.LFE2157:
	.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
.LC6:
	.long	1073741824
	.align 4
.LC7:
	.long	1065353216
	.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:

//Based on the work of Andrew Krepps

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <math.h>
#include <chrono>
/*
* Used for multiplying two square matrices of the same size.
* Uses shared memory to store matrix c until it is time to copy
* the final array out to the CPU.
*/

__host__ hipEvent_t get_time(void)
{
	hipEvent_t time;
	hipEventCreate(&time);
	hipEventRecord(time);
	return time;
}

__global__ void dotMultAddShared(float *A, float *B, float *C, const int sideLen) {
    
    const uint cola = (blockIdx.x * blockDim.x) + threadIdx.x;
    const uint rowa = (blockIdx.y * blockDim.y) + threadIdx.y;
    
    const uint idx = (rowa*sideLen) + cola;
    
    extern __shared__ float a[];
    
    a[idx]= A[idx];
    
    // Hold threads in block for copy to finish
    __syncthreads();
    //printf("a[%d]: %f b[%d]: %f\n", idx, a[idx], idx, B[idx]);
    C[idx] = a[idx] * B[idx] + a[idx] + B[idx];
}

/*
* Used for multiplying two square matrices of the same size.
* Uses global memory for matrix c until it is time to copy
* the final array out to the CPU.
*/
__global__ void dotMultAdd(float *A, float *B, float *C, const int sideLen) {
    uint cola = (blockIdx.x * blockDim.x) + threadIdx.x;
    uint rowa = (blockIdx.y * blockDim.y) + threadIdx.y;
    
    int idx = (rowa*sideLen) + cola;
    
    C[idx] = A[idx] * B[idx] + A[idx] + B[idx];
}


int main(int argc, char** argv)
{
	// read command line arguments
	int totalThreads = (1 << 20);
	int blockSize = 256;
	
	if (argc >= 2) {
		totalThreads = atoi(argv[1]);
	}
	if (argc >= 3) {
		blockSize = atoi(argv[2]);
	}

	int numBlocks = totalThreads/blockSize;

	// validate command line arguments
	if (totalThreads % blockSize != 0) {
		++numBlocks;
		totalThreads = numBlocks*blockSize;
		
		printf("Warning: Total thread count is not evenly divisible by the block size\n");
		printf("The total number of threads will be rounded up to %d\n", totalThreads);
	}
	
// =======================================================================================
// Start my code

    // Using square matrices for ease.
    // Calculate matrix size and adjust totalThreads if it has no integer sqrt.
    const int side = static_cast<int>(sqrt(totalThreads));
    printf("Matrix size: %d x %d\n", side, side);
    if (totalThreads!=(side*side)) {
    	totalThreads = side*side;
    	numBlocks = totalThreads/blockSize;
    }
    
    printf("Total threads: %d\n", totalThreads);
    printf("Block size: %d\n", blockSize);
    printf("Number of blocks: %d\n", numBlocks);
    
    
    // 
    float *h_A, *h_B, *h_C1, *h_C2;
    float *d_a, *d_b, *d_c;
    
    h_A = (float*)malloc(totalThreads*sizeof(float));
    h_B = (float*)malloc(totalThreads*sizeof(float));
    h_C1 = (float*)malloc(totalThreads*sizeof(float));
    h_C2 = (float*)malloc(totalThreads*sizeof(float));
    
    hipMalloc((void**)&d_a, totalThreads*sizeof(float));
    hipMalloc((void**)&d_b, totalThreads*sizeof(float));
    hipMalloc((void**)&d_c, totalThreads*sizeof(float));
    
    for(int i=0; i<totalThreads; i++) {
    	h_A[i] = 2.0f;
    	h_B[i] = 1.0f;
    	h_C1[i] = 0.0f;
    	h_C2[i] = 0.0f;
    }

    hipEvent_t kernel_start, kernel_stop;
    hipEventCreateWithFlags(&kernel_start,0);
    hipEventCreateWithFlags(&kernel_stop,0);
    
    
    hipMemcpy(d_a, h_A, totalThreads*sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(d_b, h_B, totalThreads*sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(d_c, h_C1, totalThreads*sizeof(float), hipMemcpyHostToDevice);
    
    hipEventRecord(kernel_start, 0);
    
    dotMultAddShared<<<numBlocks, blockSize, totalThreads*sizeof(int)>>>(d_a, d_b, d_c, side);
    
    hipEventRecord(kernel_stop, 0);
    hipEventSynchronize(kernel_stop);
    
    hipMemcpy(h_C1, d_c, totalThreads*sizeof(float), hipMemcpyDeviceToHost);
    
    float delta = 0.0f;
    hipEventElapsedTime(&delta, kernel_start, kernel_stop);
    printf("duration using shared memory: %fmsn\n", delta);

    
    hipEventRecord(kernel_start, 0);
    
    dotMultAdd<<<numBlocks, blockSize>>>(d_a, d_b, d_c, side);
    
    hipEventRecord(kernel_stop, 0);
    hipEventSynchronize(kernel_stop);
    
    hipMemcpy(h_C2, d_c, totalThreads*sizeof(float), hipMemcpyDeviceToHost);
    
    hipEventElapsedTime(&delta, kernel_start, kernel_stop);
    printf("duration using global memory: %fmsn\n", delta);
    
    hipFree(d_a);
    hipFree(d_b);
    hipFree(d_c);
    hipEventDestroy(kernel_start);
    hipEventDestroy(kernel_stop);
    
    bool different = false;
    for(int i=0; i<totalThreads; i++) {
    	if(h_C1[i] != h_C2[i])
    		different = true;
    }
    
    if(different)
    	printf("Different values detected at [%d]: h_C1=%f h_C2=%f\n", 0, h_C1[0], h_C2[0]);
    else
    	printf("%2.1f*%2.1f + %2.1f + %2.1f = %2.1f\n", h_A[0], h_B[0], h_A[0], h_B[0], h_C1[0]);
    
}

	.text
	.file	"assignment.hip"
	.globl	_Z8get_timev                    # -- Begin function _Z8get_timev
	.type	_Z8get_timev,@function
_Z8get_timev:                           # @_Z8get_timev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbx), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z8get_timev, .Lfunc_end0-_Z8get_timev
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__dotMultAddSharedPfS_S_i # -- Begin function _Z31__device_stub__dotMultAddSharedPfS_S_i
	.type	_Z31__device_stub__dotMultAddSharedPfS_S_i,@function
_Z31__device_stub__dotMultAddSharedPfS_S_i: # @_Z31__device_stub__dotMultAddSharedPfS_S_i
	.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), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z16dotMultAddSharedPfS_S_i, %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	_Z31__device_stub__dotMultAddSharedPfS_S_i, .Lfunc_end1-_Z31__device_stub__dotMultAddSharedPfS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__dotMultAddPfS_S_i # -- Begin function _Z25__device_stub__dotMultAddPfS_S_i
	.type	_Z25__device_stub__dotMultAddPfS_S_i,@function
_Z25__device_stub__dotMultAddPfS_S_i:   # @_Z25__device_stub__dotMultAddPfS_S_i
	.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), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z10dotMultAddPfS_S_i, %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_end2:
	.size	_Z25__device_stub__dotMultAddPfS_S_i, .Lfunc_end2-_Z25__device_stub__dotMultAddPfS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$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	$256, %r15d                     # imm = 0x100
	movl	$1048576, %r14d                 # imm = 0x100000
	cmpl	$2, %edi
	jl	.LBB3_3
# %bb.1:
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	cmpl	$2, %ebp
	je	.LBB3_3
# %bb.2:
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r15d
.LBB3_3:                                # %.thread
	movl	%r14d, %eax
	cltd
	idivl	%r15d
	movl	%eax, %ebp
	testl	%edx, %edx
	je	.LBB3_5
# %bb.4:
	incl	%ebp
	movl	%ebp, %r14d
	imull	%r15d, %r14d
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.1, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
.LBB3_5:
	cvtsi2sd	%r14d, %xmm0
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB3_7
# %bb.6:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB3_8
.LBB3_7:                                # %call.sqrt
	callq	sqrt
.LBB3_8:                                # %.split
	cvttsd2si	%xmm0, %ebx
	movl	$.L.str.2, %edi
	movl	%ebx, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	movl	%ebx, 28(%rsp)                  # 4-byte Spill
	imull	%ebx, %ebx
	cmpl	%ebx, %r14d
	je	.LBB3_10
# %bb.9:
	movl	%ebx, %eax
	xorl	%edx, %edx
	idivl	%r15d
	movl	%eax, %ebp
	movl	%ebx, %r14d
.LBB3_10:
	movl	$.L.str.3, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.4, %edi
	movl	%r15d, 64(%rsp)                 # 4-byte Spill
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	movl	%ebp, 56(%rsp)                  # 4-byte Spill
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movslq	%r14d, %rax
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rbx
	movq	%rbx, %rdi
	callq	malloc
	movl	%r14d, %ebp
	movq	%rax, %r14
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r13
	leaq	40(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%rbx, 80(%rsp)                  # 8-byte Spill
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	%ebp, 72(%rsp)                  # 4-byte Spill
	movl	%ebp, %ebp
	cmpl	$0, 48(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_13
# %bb.11:                               # %.lr.ph.preheader
	leaq	(,%rbp,4), %rdx
	movq	%rdx, 48(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	%r13, %rdi
	xorl	%esi, %esi
	movq	48(%rsp), %rdx                  # 8-byte Reload
	callq	memset@PLT
.LBB3_12:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$1073741824, (%r14,%rbx,4)      # imm = 0x40000000
	movl	$1065353216, (%r15,%rbx,4)      # imm = 0x3F800000
	incq	%rbx
	cmpq	%rbx, %rbp
	jne	.LBB3_12
.LBB3_13:                               # %._crit_edge
	leaq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventCreateWithFlags
	movq	%rsp, %rdi
	xorl	%esi, %esi
	callq	hipEventCreateWithFlags
	movq	40(%rsp), %rdi
	movq	%r14, %rsi
	movq	80(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	movq	%r15, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	56(%rsp), %edi                  # 4-byte Reload
	btsq	$32, %rdi
	movl	64(%rsp), %edx                  # 4-byte Reload
	btsq	$32, %rdx
	movq	%rdi, 64(%rsp)                  # 8-byte Spill
	movl	$1, %esi
	movq	%rdx, 56(%rsp)                  # 8-byte Spill
	movl	$1, %ecx
	movq	%rbx, %r8
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_15
# %bb.14:
	movq	40(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	28(%rsp), %ecx                  # 4-byte Reload
	callq	_Z31__device_stub__dotMultAddSharedPfS_S_i
.LBB3_15:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	%r12, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	76(%rsp), %rbx
	movl	$0, (%rbx)
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	64(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	56(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_17
# %bb.16:
	movq	40(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	28(%rsp), %ecx                  # 4-byte Reload
	callq	_Z25__device_stub__dotMultAddPfS_S_i
.LBB3_17:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	movq	80(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	76(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	cmpl	$0, 72(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_22
# %bb.18:                               # %.lr.ph109.preheader
	xorl	%eax, %eax
	movl	$1, %ecx
	xorl	%edx, %edx
.LBB3_19:                               # %.lr.ph109
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r12,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r13,%rax,4), %xmm0
	movzbl	%dl, %edx
	cmovnel	%ecx, %edx
	cmovpl	%ecx, %edx
	incq	%rax
	cmpq	%rax, %rbp
	jne	.LBB3_19
# %bb.20:                               # %._crit_edge110
	testb	$1, %dl
	jne	.LBB3_21
.LBB3_22:                               # %._crit_edge110.thread
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14), %xmm0
	cvtss2sd	(%r15), %xmm1
	cvtss2sd	(%r12), %xmm4
	movl	$.L.str.9, %edi
	movaps	%xmm0, %xmm2
	movaps	%xmm1, %xmm3
	movb	$5, %al
	callq	printf
	jmp	.LBB3_23
.LBB3_21:
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12), %xmm0
	cvtss2sd	(%r13), %xmm1
	movl	$.L.str.8, %edi
	xorl	%esi, %esi
	movb	$2, %al
	callq	printf
.LBB3_23:
	xorl	%eax, %eax
	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_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
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.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:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16dotMultAddSharedPfS_S_i, %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	$_Z10dotMultAddPfS_S_i, %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_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	_Z16dotMultAddSharedPfS_S_i,@object # @_Z16dotMultAddSharedPfS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z16dotMultAddSharedPfS_S_i
	.p2align	3, 0x0
_Z16dotMultAddSharedPfS_S_i:
	.quad	_Z31__device_stub__dotMultAddSharedPfS_S_i
	.size	_Z16dotMultAddSharedPfS_S_i, 8

	.type	_Z10dotMultAddPfS_S_i,@object   # @_Z10dotMultAddPfS_S_i
	.globl	_Z10dotMultAddPfS_S_i
	.p2align	3, 0x0
_Z10dotMultAddPfS_S_i:
	.quad	_Z25__device_stub__dotMultAddPfS_S_i
	.size	_Z10dotMultAddPfS_S_i, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"The total number of threads will be rounded up to %d\n"
	.size	.L.str.1, 54

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Matrix size: %d x %d\n"
	.size	.L.str.2, 22

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Total threads: %d\n"
	.size	.L.str.3, 19

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Block size: %d\n"
	.size	.L.str.4, 16

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Number of blocks: %d\n"
	.size	.L.str.5, 22

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"duration using shared memory: %fmsn\n"
	.size	.L.str.6, 37

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"duration using global memory: %fmsn\n"
	.size	.L.str.7, 37

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Different values detected at [%d]: h_C1=%f h_C2=%f\n"
	.size	.L.str.8, 52

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%2.1f*%2.1f + %2.1f + %2.1f = %2.1f\n"
	.size	.L.str.9, 37

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16dotMultAddSharedPfS_S_i"
	.size	.L__unnamed_1, 28

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z10dotMultAddPfS_S_i"
	.size	.L__unnamed_2, 22

	.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	"Warning: Total thread count is not evenly divisible by the block size"
	.size	.Lstr, 70

	.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 _Z31__device_stub__dotMultAddSharedPfS_S_i
	.addrsig_sym _Z25__device_stub__dotMultAddPfS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z16dotMultAddSharedPfS_S_i
	.addrsig_sym _Z10dotMultAddPfS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16dotMultAddSharedPfS_S_i ; -- Begin function _Z16dotMultAddSharedPfS_S_i
	.globl	_Z16dotMultAddSharedPfS_S_i
	.p2align	8
	.type	_Z16dotMultAddSharedPfS_S_i,@function
_Z16dotMultAddSharedPfS_S_i:            ; @_Z16dotMultAddSharedPfS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s4, v[1:2]
	v_mov_b32_e32 v1, 0
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mul_i32 s14, s14, s2
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v2, v2, s3
	v_add3_u32 v0, s14, v0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	v_lshl_add_u32 v0, v0, 2, 0
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s4, v1
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v2, vcc_lo
	global_load_b32 v5, v[3:4], off
	v_add_co_u32 v3, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v2, vcc_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v0, v5
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	global_load_b32 v3, v[3:4], off
	ds_load_b32 v0, v0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v0, v0, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v3, v3, v0
	v_add_co_u32 v0, vcc_lo, s0, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[0:1], v3, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16dotMultAddSharedPfS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 6
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z16dotMultAddSharedPfS_S_i, .Lfunc_end0-_Z16dotMultAddSharedPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 256
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z10dotMultAddPfS_S_i   ; -- Begin function _Z10dotMultAddPfS_S_i
	.globl	_Z10dotMultAddPfS_S_i
	.p2align	8
	.type	_Z10dotMultAddPfS_S_i,@function
_Z10dotMultAddPfS_S_i:                  ; @_Z10dotMultAddPfS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s4, v[1:2]
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mul_i32 s14, s14, s2
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v1, v2, s3
	v_add3_u32 v0, s14, v0, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v1, vcc_lo
	v_add_co_u32 v4, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[4:5], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v2, v2, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v2, v3, v2
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10dotMultAddPfS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 6
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z10dotMultAddPfS_S_i, .Lfunc_end1-_Z10dotMultAddPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 212
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
