#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <unistd.h>
#include <sys/time.h>

/* Problem size */
#define M 1024
#define N 1024


#define FLOAT_N 3214212.01

void init_arrays(double* data)
{
	int i, j;

	for (i = 1; i < (M+1); i++) {
		for (j = 1; j < (N+1); j++) {
			data[i*(N+1) + j] = ((double) i*j) / M;
		}
	}
}

__global__ void mean_kernel(double* data, double* mean)
{
	int j = blockIdx.x * blockDim.x + threadIdx.x + 1;
	__shared__ double mean_shared;

	if (j < (M+1))
	{
		mean_shared = 0.0;

		int i;
		for(i = 1; i < (N+1); i++)
		{
			mean_shared += data[i * (M+1) + j];
		}
		mean_shared /= FLOAT_N;
		mean[j] = mean_shared;
	}

}

__global__ void data_kernel(double* data, double* mean)
{
	int j = blockIdx.x * blockDim.x + threadIdx.x + 1;
	int i = blockIdx.y * blockDim.y + threadIdx.y + 1;
		
	if ((i < (N+1)) && (j < (M+1)))
	{
		data[i * (M+1) + j] -= mean[j];	
	}
}

__global__ void symmat_kernel(double* symmat, double* data)
{
	int j1 = blockIdx.x * blockDim.x + threadIdx.x + 1;
	int i, j2;
	__shared__ double symmat_shared;

	if (j1 < (M+1))
	{
		for (j2 = j1; j2 < (M+1); j2++)
		{		
			symmat_shared = 0.0;
			for(i = 1; i < (N+1); i++)
			{
				symmat_shared += data[i * (M+1) + j1] * data[i * (M+1) + j2];
			}
			symmat[j1 * (M+1) + j2] = symmat_shared;
			symmat[j2 * (M+1) + j1] = symmat[j1 * (M+1) + j2];
		}
	}
}

int main(int argc, char *argv[])
{
	double		*data_h, *data_d;
	double		*symmat_h, *symmat_d;
	double		*mean_h, *mean_d;
	struct timeval	cpu_start, cpu_end;

	data_h = (double*)malloc((M+1)*(N+1)*sizeof(double));
	mean_h = (double*)malloc((M+1)*sizeof(double));
	symmat_h = (double*)malloc((M+1)*(M+1)*sizeof(double));

	// Δέσμευση μνήμης στο device για τα διανύσματα
	cudaMalloc((void **) &data_d, (M+1)*(N+1)*sizeof(double));
	cudaMalloc((void **) &mean_d, (M+1)*sizeof(double));
	cudaMalloc((void **) &symmat_d, (M+1)*(M+1)*sizeof(double));

	cudaMemset(data_d, 0, (M+1)*(N+1)*sizeof(double));
	// cudaMemset(symmat_d, 0, (M+1)*(M+1)*sizeof(double));
	// cudaMemset(mean_d, 0, (M+1)*sizeof(double));

	init_arrays(data_h);

	// Αντιγραφή data στο device
	cudaMemcpy(data_d, data_h, (M+1)*(N+1)*sizeof(double), cudaMemcpyHostToDevice);
	//cudaMemcpy(symmat_d, symmat_h, (M+1)*(M+1)*sizeof(double), cudaMemcpyHostToDevice);
	//cudaMemcpy(mean_d, mean_h, (M+1)*sizeof(double), cudaMemcpyHostToDevice);

	
	//----------------------------------------------------------------------

	// Κάθε block θα έχει διάσταση 16x16
	unsigned int BLOCK_SIZE_PER_DIM = 16;

	// Ορισμός διαστάσεων πλέγματος
	dim3 dimGrid1((M - 1) / BLOCK_SIZE_PER_DIM + 1, 1);
	dim3 dimGrid2((M - 1) / BLOCK_SIZE_PER_DIM + 1, (N - 1) / BLOCK_SIZE_PER_DIM + 1);
	dim3 dimGrid3((M - 1) / BLOCK_SIZE_PER_DIM + 1, 1);

	// Ορισμός διαστάσεων block
	dim3 dimBlock(BLOCK_SIZE_PER_DIM, BLOCK_SIZE_PER_DIM, 1);




	//----------------------------------------------------------------------

	gettimeofday(&cpu_start, NULL);
	
	mean_kernel<<<dimGrid1, dimBlock>>>(data_d, mean_d);
	cudaThreadSynchronize();
	data_kernel<<<dimGrid2, dimBlock>>>(data_d, mean_d);
	cudaThreadSynchronize();
	symmat_kernel<<<dimGrid3, dimBlock>>>(symmat_d,data_d);
	cudaThreadSynchronize();

	cudaMemcpy(symmat_h, symmat_d, (M+1)*(M+1)*sizeof(double), cudaMemcpyDeviceToHost);


	gettimeofday(&cpu_end, NULL);
	fprintf(stdout, "GPU Runtime: %0.6lfs\n", ((cpu_end.tv_sec - cpu_start.tv_sec) * 1000000.0 + (cpu_end.tv_usec - cpu_start.tv_usec)) / 1000000.0);
	printf("================================\n");

	FILE *f = fopen("ask3_cuda_output.txt", "w+");
	if (f == NULL)
	{
	    printf("Error opening ask3_cuda_output.txt!\n");
	    exit(1);
	}


	for(int i = 1; i < (M+1); i++) {
		for(int j = 1; j < (M+1); j++){
			fprintf(f, "%f\n", symmat_h[i * (M+1) + j]);
		}
	}

	if(f) { printf("Results saved in ask3_cuda_output.txt!\n"); }

	fclose(f);

	// Αποδέσμευση μνήμης στον host
	free(data_h);
	free(mean_h);
	free(symmat_h);

	// Αποδέσμευση μνήμης στον host
	cudaFree(data_d);
	cudaFree(mean_d);
	cudaFree(symmat_d);

  	return 0;
}


	.file	"tmpxft_00308448_00000000-6_ask3_cuda.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2044:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2044:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11init_arraysPd
	.type	_Z11init_arraysPd, @function
_Z11init_arraysPd:
.LFB2040:
	.cfi_startproc
	endbr64
	movsd	.LC0(%rip), %xmm2
	addq	$8200, %rdi
	movl	$1, %edx
.L3:
	cvtsi2sdl	%edx, %xmm1
	movl	$1, %eax
.L4:
	cvtsi2sdl	%eax, %xmm0
	mulsd	%xmm1, %xmm0
	mulsd	%xmm2, %xmm0
	movsd	%xmm0, (%rdi,%rax,8)
	incq	%rax
	cmpq	$1025, %rax
	jne	.L4
	incl	%edx
	addq	$8200, %rdi
	cmpl	$1025, %edx
	jne	.L3
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z11init_arraysPd, .-_Z11init_arraysPd
	.globl	_Z33__device_stub__Z11mean_kernelPdS_PdS_
	.type	_Z33__device_stub__Z11mean_kernelPdS_PdS_, @function
_Z33__device_stub__Z11mean_kernelPdS_PdS_:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z11mean_kernelPdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L8:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z33__device_stub__Z11mean_kernelPdS_PdS_, .-_Z33__device_stub__Z11mean_kernelPdS_PdS_
	.globl	_Z11mean_kernelPdS_
	.type	_Z11mean_kernelPdS_, @function
_Z11mean_kernelPdS_:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z11mean_kernelPdS_PdS_
	.cfi_endproc
.LFE2067:
	.size	_Z11mean_kernelPdS_, .-_Z11mean_kernelPdS_
	.globl	_Z33__device_stub__Z11data_kernelPdS_PdS_
	.type	_Z33__device_stub__Z11data_kernelPdS_PdS_, @function
_Z33__device_stub__Z11data_kernelPdS_PdS_:
.LFB2068:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z11data_kernelPdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L13:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2068:
	.size	_Z33__device_stub__Z11data_kernelPdS_PdS_, .-_Z33__device_stub__Z11data_kernelPdS_PdS_
	.globl	_Z11data_kernelPdS_
	.type	_Z11data_kernelPdS_, @function
_Z11data_kernelPdS_:
.LFB2069:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z11data_kernelPdS_PdS_
	.cfi_endproc
.LFE2069:
	.size	_Z11data_kernelPdS_, .-_Z11data_kernelPdS_
	.globl	_Z35__device_stub__Z13symmat_kernelPdS_PdS_
	.type	_Z35__device_stub__Z13symmat_kernelPdS_PdS_, @function
_Z35__device_stub__Z13symmat_kernelPdS_PdS_:
.LFB2070:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z13symmat_kernelPdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L18:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2070:
	.size	_Z35__device_stub__Z13symmat_kernelPdS_PdS_, .-_Z35__device_stub__Z13symmat_kernelPdS_PdS_
	.globl	_Z13symmat_kernelPdS_
	.type	_Z13symmat_kernelPdS_, @function
_Z13symmat_kernelPdS_:
.LFB2071:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z13symmat_kernelPdS_PdS_
	.cfi_endproc
.LFE2071:
	.size	_Z13symmat_kernelPdS_, .-_Z13symmat_kernelPdS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"GPU Runtime: %0.6lfs\n"
.LC3:
	.string	"================================\n"
.LC4:
	.string	"w+"
.LC5:
	.string	"ask3_cuda_output.txt"
.LC6:
	.string	"Error opening ask3_cuda_output.txt!\n"
.LC7:
	.string	"%f\n"
.LC8:
	.string	"Results saved in ask3_cuda_output.txt!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$8405000, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$8405000, %edi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	leaq	16(%rsp), %rdi
	movl	$8405000, %esi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$8200, %esi
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$8405000, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$8405000, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	call	_Z11init_arraysPd
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$8405000, %edx
	call	cudaMemcpy@PLT
	movl	$67108865, %eax
	xorl	%esi, %esi
	movabsq	$274877907008, %rdx
	salq	$6, %rax
	leaq	88(%rsp), %rdi
	movq	%rdx, 52(%rsp)
	movq	%rax, 40(%rsp)
	movq	%rax, 64(%rsp)
	movabsq	$68719476752, %rax
	movl	$1, 48(%rsp)
	movl	$1, 60(%rsp)
	movl	$1, 72(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	gettimeofday@PLT
	movl	84(%rsp), %ecx
	movl	48(%rsp), %esi
	xorl	%r9d, %r9d
	movq	76(%rsp), %rdx
	movq	40(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z33__device_stub__Z11mean_kernelPdS_PdS_
.L24:
	call	cudaThreadSynchronize@PLT
	movl	84(%rsp), %ecx
	movl	60(%rsp), %esi
	xorl	%r9d, %r9d
	movq	76(%rsp), %rdx
	movq	52(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z33__device_stub__Z11data_kernelPdS_PdS_
.L25:
	call	cudaThreadSynchronize@PLT
	movl	84(%rsp), %ecx
	movl	72(%rsp), %esi
	xorl	%r9d, %r9d
	movq	76(%rsp), %rdx
	movq	64(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z35__device_stub__Z13symmat_kernelPdS_PdS_
.L26:
	call	cudaThreadSynchronize@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$8405000, %edx
	call	cudaMemcpy@PLT
	leaq	104(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	104(%rsp), %rax
	subq	88(%rsp), %rax
	leaq	.LC2(%rip), %rdx
	cvtsi2sdq	%rax, %xmm0
	movq	112(%rsp), %rax
	subq	96(%rsp), %rax
	movl	$2, %esi
	movsd	.LC1(%rip), %xmm1
	cvtsi2sdq	%rax, %xmm2
	movb	$1, %al
	movq	stdout(%rip), %rdi
	mulsd	%xmm1, %xmm0
	addsd	%xmm2, %xmm0
	divsd	%xmm1, %xmm0
	call	__fprintf_chk@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %rsi
	leaq	.LC5(%rip), %rdi
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	je	.L27
	leaq	8200(%rbx), %r14
	movl	$1025, %ebp
	leaq	.LC7(%rip), %r15
	jmp	.L28
.L27:
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L29:
	movsd	(%r14,%r13,8), %xmm0
	movq	%r15, %rdx
	movl	$2, %esi
	movb	$1, %al
	movq	%r12, %rdi
	incq	%r13
	call	__fprintf_chk@PLT
	cmpq	$1025, %r13
	jne	.L29
	addl	$1025, %ebp
	addq	$8200, %r14
	cmpl	$1050625, %ebp
	je	.L30
.L28:
	movl	$1, %r13d
	jmp	.L29
.L30:
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$136, %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
.LFE2041:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z13symmat_kernelPdS_"
.LC10:
	.string	"_Z11data_kernelPdS_"
.LC11:
	.string	"_Z11mean_kernelPdS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2073:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z13symmat_kernelPdS_(%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	.LC10(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11data_kernelPdS_(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC11(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11mean_kernelPdS_(%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
.LFE2073:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1062207488
	.align 8
.LC1:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


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

/* Problem size */
#define M 1024
#define N 1024


#define FLOAT_N 3214212.01

void init_arrays(double* data)
{
	int i, j;

	for (i = 1; i < (M+1); i++) {
		for (j = 1; j < (N+1); j++) {
			data[i*(N+1) + j] = ((double) i*j) / M;
		}
	}
}

__global__ void mean_kernel(double* data, double* mean)
{
	int j = blockIdx.x * blockDim.x + threadIdx.x + 1;
	__shared__ double mean_shared;

	if (j < (M+1))
	{
		mean_shared = 0.0;

		int i;
		for(i = 1; i < (N+1); i++)
		{
			mean_shared += data[i * (M+1) + j];
		}
		mean_shared /= FLOAT_N;
		mean[j] = mean_shared;
	}

}

__global__ void data_kernel(double* data, double* mean)
{
	int j = blockIdx.x * blockDim.x + threadIdx.x + 1;
	int i = blockIdx.y * blockDim.y + threadIdx.y + 1;
		
	if ((i < (N+1)) && (j < (M+1)))
	{
		data[i * (M+1) + j] -= mean[j];	
	}
}

__global__ void symmat_kernel(double* symmat, double* data)
{
	int j1 = blockIdx.x * blockDim.x + threadIdx.x + 1;
	int i, j2;
	__shared__ double symmat_shared;

	if (j1 < (M+1))
	{
		for (j2 = j1; j2 < (M+1); j2++)
		{		
			symmat_shared = 0.0;
			for(i = 1; i < (N+1); i++)
			{
				symmat_shared += data[i * (M+1) + j1] * data[i * (M+1) + j2];
			}
			symmat[j1 * (M+1) + j2] = symmat_shared;
			symmat[j2 * (M+1) + j1] = symmat[j1 * (M+1) + j2];
		}
	}
}

int main(int argc, char *argv[])
{
	double		*data_h, *data_d;
	double		*symmat_h, *symmat_d;
	double		*mean_h, *mean_d;
	struct timeval	cpu_start, cpu_end;

	data_h = (double*)malloc((M+1)*(N+1)*sizeof(double));
	mean_h = (double*)malloc((M+1)*sizeof(double));
	symmat_h = (double*)malloc((M+1)*(M+1)*sizeof(double));

	// Δέσμευση μνήμης στο device για τα διανύσματα
	hipMalloc((void **) &data_d, (M+1)*(N+1)*sizeof(double));
	hipMalloc((void **) &mean_d, (M+1)*sizeof(double));
	hipMalloc((void **) &symmat_d, (M+1)*(M+1)*sizeof(double));

	hipMemset(data_d, 0, (M+1)*(N+1)*sizeof(double));
	// cudaMemset(symmat_d, 0, (M+1)*(M+1)*sizeof(double));
	// cudaMemset(mean_d, 0, (M+1)*sizeof(double));

	init_arrays(data_h);

	// Αντιγραφή data στο device
	hipMemcpy(data_d, data_h, (M+1)*(N+1)*sizeof(double), hipMemcpyHostToDevice);
	//cudaMemcpy(symmat_d, symmat_h, (M+1)*(M+1)*sizeof(double), cudaMemcpyHostToDevice);
	//cudaMemcpy(mean_d, mean_h, (M+1)*sizeof(double), cudaMemcpyHostToDevice);

	
	//----------------------------------------------------------------------

	// Κάθε block θα έχει διάσταση 16x16
	unsigned int BLOCK_SIZE_PER_DIM = 16;

	// Ορισμός διαστάσεων πλέγματος
	dim3 dimGrid1((M - 1) / BLOCK_SIZE_PER_DIM + 1, 1);
	dim3 dimGrid2((M - 1) / BLOCK_SIZE_PER_DIM + 1, (N - 1) / BLOCK_SIZE_PER_DIM + 1);
	dim3 dimGrid3((M - 1) / BLOCK_SIZE_PER_DIM + 1, 1);

	// Ορισμός διαστάσεων block
	dim3 dimBlock(BLOCK_SIZE_PER_DIM, BLOCK_SIZE_PER_DIM, 1);




	//----------------------------------------------------------------------

	gettimeofday(&cpu_start, NULL);
	
	mean_kernel<<<dimGrid1, dimBlock>>>(data_d, mean_d);
	hipDeviceSynchronize();
	data_kernel<<<dimGrid2, dimBlock>>>(data_d, mean_d);
	hipDeviceSynchronize();
	symmat_kernel<<<dimGrid3, dimBlock>>>(symmat_d,data_d);
	hipDeviceSynchronize();

	hipMemcpy(symmat_h, symmat_d, (M+1)*(M+1)*sizeof(double), hipMemcpyDeviceToHost);


	gettimeofday(&cpu_end, NULL);
	fprintf(stdout, "GPU Runtime: %0.6lfs\n", ((cpu_end.tv_sec - cpu_start.tv_sec) * 1000000.0 + (cpu_end.tv_usec - cpu_start.tv_usec)) / 1000000.0);
	printf("================================\n");

	FILE *f = fopen("ask3_cuda_output.txt", "w+");
	if (f == NULL)
	{
	    printf("Error opening ask3_cuda_output.txt!\n");
	    exit(1);
	}


	for(int i = 1; i < (M+1); i++) {
		for(int j = 1; j < (M+1); j++){
			fprintf(f, "%f\n", symmat_h[i * (M+1) + j]);
		}
	}

	if(f) { printf("Results saved in ask3_cuda_output.txt!\n"); }

	fclose(f);

	// Αποδέσμευση μνήμης στον host
	free(data_h);
	free(mean_h);
	free(symmat_h);

	// Αποδέσμευση μνήμης στον host
	hipFree(data_d);
	hipFree(mean_d);
	hipFree(symmat_d);

  	return 0;
}


	.text
	.file	"ask3_cuda.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z11init_arraysPd
.LCPI0_0:
	.quad	0x3f50000000000000              # double 9.765625E-4
	.text
	.globl	_Z11init_arraysPd
	.type	_Z11init_arraysPd,@function
_Z11init_arraysPd:                      # @_Z11init_arraysPd
	.cfi_startproc
# %bb.0:
	addq	$8208, %rdi                     # imm = 0x2010
	movl	$1, %eax
	movsd	.LCPI0_0(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB0_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	xorl	%ecx, %ecx
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leaq	1(%rcx), %rdx
	xorps	%xmm2, %xmm2
	cvtsi2sd	%edx, %xmm2
	mulsd	%xmm1, %xmm2
	mulsd	%xmm0, %xmm2
	movsd	%xmm2, (%rdi,%rcx,8)
	movq	%rdx, %rcx
	cmpq	$1024, %rdx                     # imm = 0x400
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	incq	%rax
	addq	$8200, %rdi                     # imm = 0x2008
	cmpq	$1025, %rax                     # imm = 0x401
	jne	.LBB0_1
# %bb.4:
	retq
.Lfunc_end0:
	.size	_Z11init_arraysPd, .Lfunc_end0-_Z11init_arraysPd
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__mean_kernelPdS_ # -- Begin function _Z26__device_stub__mean_kernelPdS_
	.type	_Z26__device_stub__mean_kernelPdS_,@function
_Z26__device_stub__mean_kernelPdS_:     # @_Z26__device_stub__mean_kernelPdS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z11mean_kernelPdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z26__device_stub__mean_kernelPdS_, .Lfunc_end1-_Z26__device_stub__mean_kernelPdS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__data_kernelPdS_ # -- Begin function _Z26__device_stub__data_kernelPdS_
	.type	_Z26__device_stub__data_kernelPdS_,@function
_Z26__device_stub__data_kernelPdS_:     # @_Z26__device_stub__data_kernelPdS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z11data_kernelPdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z26__device_stub__data_kernelPdS_, .Lfunc_end2-_Z26__device_stub__data_kernelPdS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__symmat_kernelPdS_ # -- Begin function _Z28__device_stub__symmat_kernelPdS_
	.type	_Z28__device_stub__symmat_kernelPdS_,@function
_Z28__device_stub__symmat_kernelPdS_:   # @_Z28__device_stub__symmat_kernelPdS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z13symmat_kernelPdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z28__device_stub__symmat_kernelPdS_, .Lfunc_end3-_Z28__device_stub__symmat_kernelPdS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x3f50000000000000              # double 9.765625E-4
.LCPI4_1:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	$8405000, %edi                  # imm = 0x804008
	callq	malloc
	movq	%rax, %rbx
	movl	$8405000, %edi                  # imm = 0x804008
	callq	malloc
	movq	%rax, %r14
	movq	%rsp, %r15
	movl	$8405000, %esi                  # imm = 0x804008
	movq	%r15, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$8200, %esi                     # imm = 0x2008
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$8405000, %esi                  # imm = 0x804008
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$8405000, %edx                  # imm = 0x804008
	xorl	%esi, %esi
	callq	hipMemset
	movq	%rbx, %rax
	addq	$8208, %rax                     # imm = 0x2010
	movl	$1, %ecx
	movsd	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB4_1:                                # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_2 Depth 2
	xorps	%xmm1, %xmm1
	cvtsi2sd	%ecx, %xmm1
	xorl	%edx, %edx
.LBB4_2:                                #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leaq	1(%rdx), %rsi
	xorps	%xmm2, %xmm2
	cvtsi2sd	%esi, %xmm2
	mulsd	%xmm1, %xmm2
	mulsd	%xmm0, %xmm2
	movsd	%xmm2, (%rax,%rdx,8)
	movq	%rsi, %rdx
	cmpq	$1024, %rsi                     # imm = 0x400
	jne	.LBB4_2
# %bb.3:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%rcx
	addq	$8200, %rax                     # imm = 0x2008
	cmpq	$1025, %rcx                     # imm = 0x401
	jne	.LBB4_1
# %bb.4:                                # %_Z11init_arraysPd.exit
	movabsq	$68719476752, %r15              # imm = 0x1000000010
	movabsq	$4294967360, %r12               # imm = 0x100000040
	movq	(%rsp), %rdi
	movl	$8405000, %edx                  # imm = 0x804008
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_6
# %bb.5:
	movq	(%rsp), %rdi
	movq	8(%rsp), %rsi
	callq	_Z26__device_stub__mean_kernelPdS_
.LBB4_6:
	callq	hipDeviceSynchronize
	movabsq	$274877907008, %rdi             # imm = 0x4000000040
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_8
# %bb.7:
	movq	(%rsp), %rdi
	movq	8(%rsp), %rsi
	callq	_Z26__device_stub__data_kernelPdS_
.LBB4_8:
	callq	hipDeviceSynchronize
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_10
# %bb.9:
	movq	16(%rsp), %rdi
	movq	(%rsp), %rsi
	callq	_Z28__device_stub__symmat_kernelPdS_
.LBB4_10:
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rsi
	movl	$8405000, %edx                  # imm = 0x804008
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	stdout(%rip), %rdi
	movq	(%r15), %rax
	movq	8(%r15), %rcx
	subq	24(%rsp), %rax
	cvtsi2sd	%rax, %xmm1
	movsd	.LCPI4_1(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm1
	subq	32(%rsp), %rcx
	cvtsi2sd	%rcx, %xmm0
	addsd	%xmm1, %xmm0
	divsd	%xmm2, %xmm0
	movl	$.L.str, %esi
	movb	$1, %al
	callq	fprintf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_16
# %bb.11:                               # %.preheader.preheader
	movq	%rax, %r15
	movq	%r14, %r12
	addq	$8208, %r12                     # imm = 0x2010
	movl	$1, %r13d
.LBB4_12:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_13 Depth 2
	xorl	%ebp, %ebp
.LBB4_13:                               #   Parent Loop BB4_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r12,%rbp,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.5, %esi
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%rbp
	cmpq	$1024, %rbp                     # imm = 0x400
	jne	.LBB4_13
# %bb.14:                               #   in Loop: Header=BB4_12 Depth=1
	incq	%r13
	addq	$8200, %r12                     # imm = 0x2008
	cmpq	$1025, %r13                     # imm = 0x401
	jne	.LBB4_12
# %bb.15:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	%r15, %rdi
	callq	fclose
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB4_16:
	.cfi_def_cfa_offset 112
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11mean_kernelPdS_, %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	$_Z11data_kernelPdS_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13symmat_kernelPdS_, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z11mean_kernelPdS_,@object     # @_Z11mean_kernelPdS_
	.section	.rodata,"a",@progbits
	.globl	_Z11mean_kernelPdS_
	.p2align	3, 0x0
_Z11mean_kernelPdS_:
	.quad	_Z26__device_stub__mean_kernelPdS_
	.size	_Z11mean_kernelPdS_, 8

	.type	_Z11data_kernelPdS_,@object     # @_Z11data_kernelPdS_
	.globl	_Z11data_kernelPdS_
	.p2align	3, 0x0
_Z11data_kernelPdS_:
	.quad	_Z26__device_stub__data_kernelPdS_
	.size	_Z11data_kernelPdS_, 8

	.type	_Z13symmat_kernelPdS_,@object   # @_Z13symmat_kernelPdS_
	.globl	_Z13symmat_kernelPdS_
	.p2align	3, 0x0
_Z13symmat_kernelPdS_:
	.quad	_Z28__device_stub__symmat_kernelPdS_
	.size	_Z13symmat_kernelPdS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"GPU Runtime: %0.6lfs\n"
	.size	.L.str, 22

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"ask3_cuda_output.txt"
	.size	.L.str.2, 21

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"w+"
	.size	.L.str.3, 3

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11mean_kernelPdS_"
	.size	.L__unnamed_1, 20

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z11data_kernelPdS_"
	.size	.L__unnamed_2, 20

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z13symmat_kernelPdS_"
	.size	.L__unnamed_3, 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	"================================"
	.size	.Lstr, 33

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Results saved in ask3_cuda_output.txt!"
	.size	.Lstr.1, 39

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Error opening ask3_cuda_output.txt!"
	.size	.Lstr.2, 36

	.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 _Z26__device_stub__mean_kernelPdS_
	.addrsig_sym _Z26__device_stub__data_kernelPdS_
	.addrsig_sym _Z28__device_stub__symmat_kernelPdS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11mean_kernelPdS_
	.addrsig_sym _Z11data_kernelPdS_
	.addrsig_sym _Z13symmat_kernelPdS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11mean_kernelPdS_     ; -- Begin function _Z11mean_kernelPdS_
	.globl	_Z11mean_kernelPdS_
	.p2align	8
	.type	_Z11mean_kernelPdS_,@function
_Z11mean_kernelPdS_:                    ; @_Z11mean_kernelPdS_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x1c
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_mul_i32 s15, s15, s2
	s_mov_b32 s2, exec_lo
	v_add3_u32 v1, v0, s15, 1
	v_cmpx_gt_i32_e32 0x401, v1
	s_cbranch_execz .LBB0_4
; %bb.1:                                ; %.preheader.preheader
	s_load_b128 s[0:3], s[0:1], 0x0
	v_mov_b32_e32 v2, 0
	v_dual_mov_b32 v3, 0 :: v_dual_add_nc_u32 v0, s15, v0
	s_movk_i32 s4, 0x402
.LBB0_2:                                ; %.preheader
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v4, s4, v0
	s_addk_i32 s4, 0x401
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_lg_u32 s4, 0x100802
	v_ashrrev_i32_e32 v5, 31, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 3, v[4:5]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v4, vcc_lo, s0, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	global_load_b64 v[4:5], v[4:5], off
	s_waitcnt vmcnt(0)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_cbranch_scc1 .LBB0_2
; %bb.3:
	s_mov_b32 s0, 0x147ae14
	s_mov_b32 s1, 0x414885c2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_div_scale_f64 v[4:5], null, s[0:1], s[0:1], v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_div_scale_f64 v[8:9], vcc_lo, v[2:3], s[0:1], v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[8:9], v[6:7]
	v_fma_f64 v[4:5], -v[4:5], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[10:11]
	v_div_fixup_f64 v[3:4], v[4:5], s[0:1], v[2:3]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[1:2]
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_store_b64 v[0:1], v[3:4], off
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11mean_kernelPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 12
		.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	_Z11mean_kernelPdS_, .Lfunc_end0-_Z11mean_kernelPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 336
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z11data_kernelPdS_     ; -- Begin function _Z11data_kernelPdS_
	.globl	_Z11data_kernelPdS_
	.p2align	8
	.type	_Z11data_kernelPdS_,@function
_Z11data_kernelPdS_:                    ; @_Z11data_kernelPdS_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x1c
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v2, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s2, 0xffff
	s_lshr_b32 s2, s2, 16
	s_mul_i32 s14, s14, s3
	s_mul_i32 s15, s15, s2
	v_add3_u32 v0, v1, s14, 1
	v_add3_u32 v2, v2, s15, 1
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_i32_e32 v1, v0, v2
	v_cmpx_gt_i32_e32 0x401, v1
	s_cbranch_execz .LBB1_2
; %bb.1:
	v_ashrrev_i32_e32 v1, 31, v0
	s_load_b128 s[0:3], s[0:1], 0x0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[3:4], null, 0x401, v2, v[0:1]
	v_lshlrev_b64 v[0:1], 3, v[0:1]
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 3, v[3:4]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_load_b64 v[0:1], v[0:1], off
	global_load_b64 v[4:5], v[2:3], off
	s_waitcnt vmcnt(0)
	v_add_f64 v[0:1], v[4:5], -v[0:1]
	global_store_b64 v[2:3], v[0:1], off
.LBB1_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11data_kernelPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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	_Z11data_kernelPdS_, .Lfunc_end1-_Z11data_kernelPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 224
; 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	_Z13symmat_kernelPdS_   ; -- Begin function _Z13symmat_kernelPdS_
	.globl	_Z13symmat_kernelPdS_
	.p2align	8
	.type	_Z13symmat_kernelPdS_,@function
_Z13symmat_kernelPdS_:                  ; @_Z13symmat_kernelPdS_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x1c
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_mul_i32 s15, s15, s2
	s_mov_b32 s2, exec_lo
	v_add3_u32 v1, v0, s15, 1
	v_cmpx_gt_i32_e32 0x401, v1
	s_cbranch_execz .LBB2_5
; %bb.1:                                ; %.preheader
	v_dual_mov_b32 v9, v1 :: v_dual_add_nc_u32 v0, s15, v0
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshl_add_u32 v8, v1, 10, v1
	s_mov_b32 s1, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v2, 0x402, v0
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
.LBB2_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB2_3 Depth 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v7, v3
	v_dual_mov_b32 v5, 0 :: v_dual_mov_b32 v6, v2
	s_movk_i32 s0, 0x402
.LBB2_3:                                ;   Parent Loop BB2_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v10, s0, v0
	s_addk_i32 s0, 0x401
	s_cmp_lg_u32 s0, 0x100802
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v11, 31, v10
	v_lshlrev_b64 v[10:11], 3, v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v10, vcc_lo, s6, v10
	v_add_co_ci_u32_e32 v11, vcc_lo, s7, v11, vcc_lo
	global_load_b64 v[12:13], v[6:7], off
	global_load_b64 v[10:11], v[10:11], off
	v_add_co_u32 v6, vcc_lo, 0x2008, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v7, vcc_lo
	s_waitcnt vmcnt(0)
	v_fma_f64 v[4:5], v[10:11], v[12:13], v[4:5]
	s_cbranch_scc1 .LBB2_3
; %bb.4:                                ;   in Loop: Header=BB2_2 Depth=1
	v_add_nc_u32_e32 v6, v9, v8
	v_mad_u64_u32 v[10:11], null, 0x401, v9, v[1:2]
	v_add_nc_u32_e32 v13, 1, v9
	v_cmp_lt_i32_e32 vcc_lo, 0x3ff, v9
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v7, 31, v6
	s_or_b32 s1, vcc_lo, s1
	v_ashrrev_i32_e32 v11, 31, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[6:7], 3, v[6:7]
	v_lshlrev_b64 v[9:10], 3, v[10:11]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v6, s0, s4, v6
	v_add_co_ci_u32_e64 v7, s0, s5, v7, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v11, s0, s4, v9
	v_add_co_ci_u32_e64 v12, s0, s5, v10, s0
	v_add_co_u32 v2, s0, v2, 8
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s0, 0, v3, s0
	v_mov_b32_e32 v9, v13
	s_clause 0x1
	global_store_b64 v[6:7], v[4:5], off
	global_store_b64 v[11:12], v[4:5], off
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB2_2
.LBB2_5:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13symmat_kernelPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 14
		.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_end2:
	.size	_Z13symmat_kernelPdS_, .Lfunc_end2-_Z13symmat_kernelPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 420
; NumSgprs: 18
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11mean_kernelPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11mean_kernelPdS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .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
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11data_kernelPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11data_kernelPdS_.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
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13symmat_kernelPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13symmat_kernelPdS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
