
/*****************************************************************************


  Example     :  cuda-matrix-matrix-multiplication.cu
 
  Objective   : Write a CUDA Program to perform Matrix Matrix multiplication.

  Input       : None 

  Output      : Execution time in seconds , Gflops achieved
                                                                                                                            
  Created     : Aug 2011    

  E-mail      : RarchK         
                                 
****************************************************************************/

#include<stdio.h>
#include<cuda.h>
#define BLOCKSIZE 16
#define SIZE 128

cudaDeviceProp deviceProp;	
cudaEvent_t start,stop;
cudaError_t ret;
double *host_MatA,*host_MatB,*host_MatC,*CPU_Result;
double *device_MatA,*device_MatB,*device_MatC;
int size = SIZE;
float elapsedTime;
double Tsec,gflops;

/*kernel funtion*/
__global__ void Muld(double* A, double* B, int wA, int wB, double* C)
  {
   int bx = blockIdx.x;
   int by = blockIdx.y;
   int tx = threadIdx.x;
   int ty = threadIdx.y;
   int aBegin  = wA * BLOCKSIZE * by;
   int aEnd = aBegin + wA - 1;
   int aStep  = BLOCKSIZE;
   int bBegin  =  BLOCKSIZE * bx;
   int bStep = BLOCKSIZE * wB;
   double Csub = 0;
   for(int a = aBegin, b = bBegin; a <= aEnd ; a  += aStep, b += bStep)
     {
       __shared__ double As[BLOCKSIZE][BLOCKSIZE];
       __shared__ double Bs[BLOCKSIZE][BLOCKSIZE];
       As[ty][tx] = A[a + wA * ty + tx];
       Bs[ty][tx] = B[b+ wB * ty + tx];
       __syncthreads();
       for(int k= 0; k< BLOCKSIZE; ++k)
         Csub += As[ty][k] * Bs[k][tx];
       __syncthreads();
      }

     int c = wB * BLOCKSIZE * by + BLOCKSIZE * bx;
     C[ c+ wB * ty + tx] = Csub;

  }/* end of Muld device code */


/*mem error*/
void mem_error(char *arrayname, char *benchmark, int len, char *type)
{
        printf("\nMemory not sufficient to allocate for array %s\n\tBenchmark : %s  \n\tMemory requested = %d number of %s elements\n",arrayname, benchmark, len, type);
        exit(-1);
}


/*cuda safe call*/
void CUDA_SAFE_CALL(cudaError_t call)
{
        cudaError_t ret = call;
        //printf("RETURN FROM THE CUDA CALL:%d\t:",ret);                                        
        switch(ret)
        {
                case cudaSuccess:
                //              printf("Success\n");                    
                                break;
        /*      case cudaErrorInvalidValue:                             
                                {
                                printf("ERROR: InvalidValue:%i.\n",__LINE__);
                                exit(-1);
                                break;  
                                }                       
                case cudaErrorInvalidDevicePointer:                     
                                {
                                printf("ERROR:Invalid Device pointeri:%i.\n",__LINE__);
                                exit(-1);
                                break;
                                }                       
                case cudaErrorInvalidMemcpyDirection:                   
                                {
                                printf("ERROR:Invalid memcpy direction:%i.\n",__LINE__);        
                                exit(-1);
                                break;
                                }                       */
                default:
                        {
                                printf(" ERROR at line :%i.%d' ' %s\n",__LINE__,ret,cudaGetErrorString(ret));
                                exit(-1);
                                break;
                        }
        }
}



/* void SetUp_CUDA_Exe_Config() */
void check_block_grid_dim(cudaDeviceProp devProp,dim3 blockDim,dim3 gridDim)
{

        if( blockDim.x >= devProp.maxThreadsDim[0] || blockDim.y >= devProp.maxThreadsDim[1] || blockDim.z >= devProp.maxThreadsDim[2] )
        {
                printf("\nBlock Dimensions exceed the maximum limits:%d * %d * %d \n",devProp.maxThreadsDim[0],devProp.maxThreadsDim[1],devProp.maxThreadsDim[2]);
               exit(-1);
        }

        if( gridDim.x >= devProp.maxGridSize[0] || gridDim.y >= devProp.maxGridSize[1] || gridDim.z >= devProp.maxGridSize[2] )
        {
                printf("\nGrid Dimensions exceed the maximum limits:%d * %d * %d \n",devProp.maxGridSize[0],devProp.maxGridSize[1],devProp.maxGridSize[2]);
               exit(-1);
        }
}


/*function to free memory*/
void dfree(double * arr[],int len)
{
        for(int i=0;i<len;i++)
                CUDA_SAFE_CALL(cudaFree(arr[i]));
        printf("mem freed\n");
}


/*calculate Gflops*/
double calculate_gflops(double &Tsec)
{
	//printf("time taken is %.8lf\n",Tsec);
	double gflops=(1.0e-9 * (( 1.0 * size*size*size )/Tsec));
	//printf("Gflops is \t%f\n",gflops);
	return gflops;

}

/*get device count*/
int get_DeviceCount()
{
        int count;
        cudaGetDeviceCount(&count);
        return count;
}



/*launch kernel function is called in main()*/
void launch_kernel_MatMatMult()
{
/* threads_per_block= BLOCKSIZE, blocks_per_grid=size/dimBlock  */

	printf("in launch kernel\n");
	dim3 dimBlock(BLOCKSIZE,BLOCKSIZE);
	dim3 dimGrid(size/dimBlock.x,size/dimBlock.y);	
 
//checking the maximum limit of blocksize and gridsize-------------------	
	check_block_grid_dim(deviceProp,dimBlock,dimGrid);
 	printf("after check\n"); 
	cudaEventRecord(start,0);	
	Muld<<<dimGrid,dimBlock>>>(device_MatA,device_MatB,size,size,device_MatC);
	cudaEventRecord(stop,0);
	cudaEventSynchronize(stop);
	cudaEventElapsedTime(&elapsedTime,start,stop);
	Tsec=elapsedTime*1.0e-3;
	calculate_gflops(Tsec);

}

/* Fill in the vector with double precision values */
void fill_dp_vector(double* vec,int size)
{
        int ind;
        for(ind=0;ind<size;ind++)
                vec[ind]=drand48();
}

/*function to print on the screen*/
void print_on_screen(char * program_name,float tsec,double gflops,int size,int flag)//flag=1 if gflops has been calculated else flag =0
{
        printf("\n---------------%s----------------\n",program_name);
        printf("\tSIZE\t TIME_SEC\t Gflops\n");
        if(flag==1)
        printf("\t%d\t%f\t%lf\t",size,tsec,gflops);
        else
        printf("\t%d\t%lf\t%lf\t",size,"---","---");

}




/*-----main()-----*/

int main()
 {
	int device_Count=get_DeviceCount();
        printf("\n\nNUmber of Devices : %d\n\n", device_Count);

        // Device Selection, Device 1: Tesla C1060
        cudaSetDevice(1);
	
	int device;
        // Current Device Detection
        cudaGetDevice(&device);         
        cudaGetDeviceProperties(&deviceProp,device);
	printf("Using device %d: %s \n", device, deviceProp.name);
	/* allocate memory for GPU events 
	start = (cudaEvent_t) malloc (sizeof(cudaEvent_t));	
	stop = (cudaEvent_t) malloc (sizeof(cudaEvent_t));
	if(start==NULL)
		mem_error("start","MatMatMult",1,"cudaEvent_t");
	if(stop==NULL)
		mem_error("stop","MatMatMult",1,"cudaEvent_t");*/
	//event creation...
	CUDA_SAFE_CALL(cudaEventCreate (&start));
        CUDA_SAFE_CALL(cudaEventCreate (&stop));
   

   
    	/*allocating the memory for each matrix */
	host_MatA = new double[size*size];
	host_MatB = new double[size*size];
	host_MatC = new double[size*size];
	CPU_Result= new double[size*size];
	 if(host_MatA==NULL)
                mem_error("host_MatA","MatMatMult",size,"double");

	if(host_MatB==NULL)
                mem_error("host_MatB","MatMatMult",size,"double");
	if(host_MatC==NULL)
                mem_error("host_MatC","MatMatMult",size,"double");
	if(CPU_Result==NULL)
                mem_error("CPU_Result","MatMatMult",size,"double");


	//--------filling the matrix with double precision-----------
  	fill_dp_vector(host_MatA,size*size);
  	fill_dp_vector(host_MatB,size*size); 
  
 	//allocating memory on GPU
	CUDA_SAFE_CALL(cudaMalloc( (void**)&device_MatA,size*size*sizeof(double)));
	CUDA_SAFE_CALL(cudaMalloc( (void**)&device_MatB, size*size*sizeof(double)));
	CUDA_SAFE_CALL(cudaMalloc( (void**)&device_MatC,size*size*sizeof(double)));

   	// copying host matrix to device matrix
    	CUDA_SAFE_CALL(cudaMemcpy((void*)device_MatA, (void*)host_MatA, size*size* sizeof(double) , cudaMemcpyHostToDevice ));
    	CUDA_SAFE_CALL(cudaMemcpy((void*)device_MatB, (void*)host_MatB, size*size*sizeof(double) , cudaMemcpyHostToDevice ));
 
	launch_kernel_MatMatMult(); //launching the kernel
	
   
   	//retriving result from device
   	CUDA_SAFE_CALL(cudaMemcpy((void*)host_MatC, (void*)device_MatC, size*size*sizeof(double) , cudaMemcpyDeviceToHost ));

	//comparing result of CPU-GPU
	//relError(CPU_Result,host_MatC,size*size);

	//printing the result on screen 
     	print_on_screen("MAT MAT Mult",Tsec,calculate_gflops(Tsec),size,1);


   
	//free the device memory----------
	double *array[3];
	array[0]=device_MatA;
	array[1]=device_MatB;
	array[2]=device_MatC;
	
	dfree(array,3);
	//free host memory----------

	free(host_MatA);
	free(host_MatB);
	free(host_MatC);
	free(CPU_Result);

}// end of main

	.file	"tmpxft_002b20ab_00000000-6_cuda-matrix-matrix-multiplication.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2039:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2039:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\nMemory not sufficient to allocate for array %s\n\tBenchmark : %s  \n\tMemory requested = %d number of %s elements\n"
	.text
	.globl	_Z9mem_errorPcS_iS_
	.type	_Z9mem_errorPcS_iS_, @function
_Z9mem_errorPcS_iS_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	%edx, %r8d
	movq	%rcx, %r9
	movq	%rdi, %rdx
	movq	%rsi, %rcx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z9mem_errorPcS_iS_, .-_Z9mem_errorPcS_iS_
	.section	.rodata.str1.1
.LC1:
	.string	" ERROR at line :%i.%d' ' %s\n"
	.text
	.globl	_Z14CUDA_SAFE_CALL9cudaError
	.type	_Z14CUDA_SAFE_CALL9cudaError, @function
_Z14CUDA_SAFE_CALL9cudaError:
.LFB2028:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L4
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %ebx
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	%ebx, %ecx
	movl	$102, %edx
	movq	%rax, %r8
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L4:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14CUDA_SAFE_CALL9cudaError, .-_Z14CUDA_SAFE_CALL9cudaError
	.section	.rodata.str1.1
.LC2:
	.string	"\nBlock Dimensions exceed the maximum limits:%d * %d * %d \n"
.LC3:
	.string	"\nGrid Dimensions exceed the maximum limits:%d * %d * %d \n"
	.text
	.globl	_Z20check_block_grid_dim14cudaDeviceProp4dim3S0_
	.type	_Z20check_block_grid_dim14cudaDeviceProp4dim3S0_, @function
_Z20check_block_grid_dim14cudaDeviceProp4dim3S0_:
.LFB2029:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movl	%esi, 24(%rsp)
	movl	372(%rsp), %esi
	movq	%rdx, (%rsp)
	movl	376(%rsp), %r9d
	movl	%ecx, 8(%rsp)
	movl	380(%rsp), %r8d
	movq	%rdi, 16(%rsp)
	movl	384(%rsp), %edx
	movl	388(%rsp), %ecx
	movl	392(%rsp), %eax
	cmpl	%edi, %esi
	jbe	.L11
	cmpl	%r9d, 20(%rsp)
	jnb	.L11
	cmpl	%r8d, 24(%rsp)
	jb	.L12
.L11:
	movl	%esi, %edx
	movl	%r9d, %ecx
	leaq	.LC2(%rip), %rsi
	jmp	.L16
.L12:
	cmpl	%edx, (%rsp)
	jnb	.L13
	cmpl	%ecx, 4(%rsp)
	jnb	.L13
	cmpl	%eax, 8(%rsp)
	jb	.L10
.L13:
	movl	%eax, %r8d
	leaq	.LC3(%rip), %rsi
.L16:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L10:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z20check_block_grid_dim14cudaDeviceProp4dim3S0_, .-_Z20check_block_grid_dim14cudaDeviceProp4dim3S0_
	.section	.rodata.str1.1
.LC4:
	.string	"mem freed\n"
	.text
	.globl	_Z5dfreePPdi
	.type	_Z5dfreePPdi, @function
_Z5dfreePPdi:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L18:
	cmpl	%ebx, %ebp
	jle	.L21
	movq	(%r12,%rbx,8), %rdi
	incq	%rbx
	call	cudaFree@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	jmp	.L18
.L21:
	popq	%rbx
	.cfi_def_cfa_offset 24
	leaq	.LC4(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z5dfreePPdi, .-_Z5dfreePPdi
	.globl	_Z16calculate_gflopsRd
	.type	_Z16calculate_gflopsRd, @function
_Z16calculate_gflopsRd:
.LFB2031:
	.cfi_startproc
	endbr64
	cvtsi2sdl	size(%rip), %xmm1
	movaps	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	divsd	(%rdi), %xmm0
	mulsd	.LC5(%rip), %xmm0
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z16calculate_gflopsRd, .-_Z16calculate_gflopsRd
	.globl	_Z15get_DeviceCountv
	.type	_Z15get_DeviceCountv, @function
_Z15get_DeviceCountv:
.LFB2032:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	4(%rsp), %eax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z15get_DeviceCountv, .-_Z15get_DeviceCountv
	.globl	_Z14fill_dp_vectorPdi
	.type	_Z14fill_dp_vectorPdi, @function
_Z14fill_dp_vectorPdi:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L27:
	cmpl	%ebx, %ebp
	jle	.L30
	call	drand48@PLT
	movsd	%xmm0, (%r12,%rbx,8)
	incq	%rbx
	jmp	.L27
.L30:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z14fill_dp_vectorPdi, .-_Z14fill_dp_vectorPdi
	.section	.rodata.str1.1
.LC6:
	.string	"\n---------------%s----------------\n"
.LC7:
	.string	"\tSIZE\t TIME_SEC\t Gflops\n"
.LC8:
	.string	"\t%d\t%f\t%lf\t"
.LC9:
	.string	"---"
.LC10:
	.string	"\t%d\t%lf\t%lf\t"
	.text
	.globl	_Z15print_on_screenPcfdii
	.type	_Z15print_on_screenPcfdii, @function
_Z15print_on_screenPcfdii:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%eax, %eax
	movl	%edx, %ebp
	movq	%rdi, %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	$2, %edi
	movl	%esi, %ebx
	leaq	.LC6(%rip), %rsi
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movss	%xmm0, 12(%rsp)
	movsd	%xmm1, (%rsp)
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	decl	%ebp
	movsd	(%rsp), %xmm1
	movss	12(%rsp), %xmm0
	jne	.L32
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	movl	%ebx, %edx
	leaq	.LC8(%rip), %rsi
	movb	$2, %al
	popq	%rbx
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 8
	cvtss2sd	%xmm0, %xmm0
	jmp	__printf_chk@PLT
.L32:
	.cfi_restore_state
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	leaq	.LC9(%rip), %r8
	movl	%ebx, %edx
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	movq	%r8, %rcx
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2035:
	.size	_Z15print_on_screenPcfdii, .-_Z15print_on_screenPcfdii
	.globl	_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_
	.type	_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_, @function
_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_:
.LFB2061:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z4MuldPdS_iiS_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L34:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2061:
	.size	_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_, .-_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_
	.globl	_Z4MuldPdS_iiS_
	.type	_Z4MuldPdS_iiS_, @function
_Z4MuldPdS_iiS_:
.LFB2062:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_
	.cfi_endproc
.LFE2062:
	.size	_Z4MuldPdS_iiS_, .-_Z4MuldPdS_iiS_
	.section	.rodata.str1.1
.LC11:
	.string	"in launch kernel\n"
.LC12:
	.string	"after check\n"
	.text
	.globl	_Z24launch_kernel_MatMatMultv
	.type	_Z24launch_kernel_MatMatMultv, @function
_Z24launch_kernel_MatMatMultv:
.LFB2033:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	size(%rip), %eax
	movl	$1, 28(%rsp)
	subq	$1040, %rsp
	.cfi_def_cfa_offset 1088
	movl	$1, 1056(%rsp)
	leaq	deviceProp(%rip), %rsi
	movl	$258, %ecx
	shrl	$4, %eax
	movl	%eax, 1060(%rsp)
	movl	%eax, 1064(%rsp)
	movabsq	$68719476752, %rax
	movq	%rax, 1048(%rsp)
	movq	%rsp, %rdi
	rep movsl
	movl	$1, %ecx
	movq	%rax, %rdi
	movl	$1, %esi
	movq	1060(%rsp), %rdx
	call	_Z20check_block_grid_dim14cudaDeviceProp4dim3S0_
	addq	$1040, %rsp
	.cfi_def_cfa_offset 48
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	start(%rip), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	16(%rsp), %ecx
	movl	28(%rsp), %esi
	xorl	%r9d, %r9d
	movq	8(%rsp), %rdx
	movq	20(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movl	size(%rip), %edx
	movq	device_MatC(%rip), %r8
	movq	device_MatB(%rip), %rsi
	movq	device_MatA(%rip), %rdi
	movl	%edx, %ecx
	call	_Z29__device_stub__Z4MuldPdS_iiS_PdS_iiS_
.L40:
	movq	stop(%rip), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	stop(%rip), %rdi
	call	cudaEventSynchronize@PLT
	movq	stop(%rip), %rdx
	movq	start(%rip), %rsi
	leaq	elapsedTime(%rip), %rdi
	call	cudaEventElapsedTime@PLT
	cvtss2sd	elapsedTime(%rip), %xmm0
	mulsd	.LC13(%rip), %xmm0
	movsd	%xmm0, Tsec(%rip)
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z24launch_kernel_MatMatMultv, .-_Z24launch_kernel_MatMatMultv
	.section	.rodata.str1.1
.LC15:
	.string	"\n\nNUmber of Devices : %d\n\n"
.LC16:
	.string	"Using device %d: %s \n"
.LC17:
	.string	"double"
.LC18:
	.string	"MatMatMult"
.LC19:
	.string	"host_MatA"
.LC20:
	.string	"host_MatB"
.LC21:
	.string	"host_MatC"
.LC22:
	.string	"MAT MAT Mult"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	deviceProp(%rip), %rbx
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z15get_DeviceCountv
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	cudaSetDevice@PLT
	leaq	12(%rsp), %rdi
	call	cudaGetDevice@PLT
	movl	12(%rsp), %esi
	movq	%rbx, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	12(%rsp), %edx
	movq	%rbx, %rcx
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	start(%rip), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	leaq	stop(%rip), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	movl	size(%rip), %edi
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	_Znam@PLT
	movl	size(%rip), %edi
	movq	%rax, host_MatA(%rip)
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	_Znam@PLT
	movl	size(%rip), %edi
	movq	%rax, host_MatB(%rip)
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	_Znam@PLT
	movl	size(%rip), %edi
	movq	%rax, host_MatC(%rip)
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	_Znam@PLT
	movq	host_MatA(%rip), %rdi
	movq	%rax, CPU_Result(%rip)
	testq	%rdi, %rdi
	jne	.L43
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L53
	movl	size(%rip), %edx
	leaq	.LC17(%rip), %rcx
	leaq	.LC18(%rip), %rsi
	leaq	.LC19(%rip), %rdi
	jmp	.L52
.L43:
	cmpq	$0, host_MatB(%rip)
	movl	size(%rip), %edx
	jne	.L45
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC17(%rip), %rcx
	leaq	.LC18(%rip), %rsi
	leaq	.LC20(%rip), %rdi
	je	.L52
	jmp	.L53
.L45:
	cmpq	$0, host_MatC(%rip)
	jne	.L47
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC17(%rip), %rcx
	leaq	.LC18(%rip), %rsi
	leaq	.LC21(%rip), %rdi
	jne	.L53
.L52:
	call	_Z9mem_errorPcS_iS_
.L47:
	imull	%edx, %edx
	movl	%edx, %esi
	call	_Z14fill_dp_vectorPdi
	movl	size(%rip), %esi
	movq	host_MatB(%rip), %rdi
	imull	%esi, %esi
	call	_Z14fill_dp_vectorPdi
	movl	size(%rip), %esi
	leaq	device_MatA(%rip), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$3, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	movl	size(%rip), %esi
	leaq	device_MatB(%rip), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$3, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	movl	size(%rip), %esi
	leaq	device_MatC(%rip), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$3, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	movl	size(%rip), %edx
	movl	$1, %ecx
	movq	host_MatA(%rip), %rsi
	movq	device_MatA(%rip), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	movl	size(%rip), %edx
	movl	$1, %ecx
	movq	host_MatB(%rip), %rsi
	movq	device_MatB(%rip), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	call	_Z24launch_kernel_MatMatMultv
	movl	size(%rip), %edx
	movl	$2, %ecx
	movq	device_MatC(%rip), %rsi
	movq	host_MatC(%rip), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_Z14CUDA_SAFE_CALL9cudaError
	leaq	Tsec(%rip), %rdi
	movl	$1, %edx
	call	_Z16calculate_gflopsRd
	movl	size(%rip), %esi
	leaq	.LC22(%rip), %rdi
	movaps	%xmm0, %xmm1
	cvtsd2ss	Tsec(%rip), %xmm0
	call	_Z15print_on_screenPcfdii
	movl	$3, %esi
	leaq	16(%rsp), %rdi
	movq	device_MatA(%rip), %rax
	movq	%rax, 16(%rsp)
	movq	device_MatB(%rip), %rax
	movq	%rax, 24(%rsp)
	movq	device_MatC(%rip), %rax
	movq	%rax, 32(%rsp)
	call	_Z5dfreePPdi
	movq	host_MatA(%rip), %rdi
	call	free@PLT
	movq	host_MatB(%rip), %rdi
	call	free@PLT
	movq	host_MatC(%rip), %rdi
	call	free@PLT
	movq	CPU_Result(%rip), %rdi
	call	free@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
.L53:
	call	__stack_chk_fail@PLT
.L49:
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	main, .-main
	.section	.rodata.str1.1
.LC23:
	.string	"_Z4MuldPdS_iiS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2064:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 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	.LC23(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4MuldPdS_iiS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2064:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	gflops
	.bss
	.align 8
	.type	gflops, @object
	.size	gflops, 8
gflops:
	.zero	8
	.globl	Tsec
	.align 8
	.type	Tsec, @object
	.size	Tsec, 8
Tsec:
	.zero	8
	.globl	elapsedTime
	.align 4
	.type	elapsedTime, @object
	.size	elapsedTime, 4
elapsedTime:
	.zero	4
	.globl	size
	.data
	.align 4
	.type	size, @object
	.size	size, 4
size:
	.long	128
	.globl	device_MatC
	.bss
	.align 8
	.type	device_MatC, @object
	.size	device_MatC, 8
device_MatC:
	.zero	8
	.globl	device_MatB
	.align 8
	.type	device_MatB, @object
	.size	device_MatB, 8
device_MatB:
	.zero	8
	.globl	device_MatA
	.align 8
	.type	device_MatA, @object
	.size	device_MatA, 8
device_MatA:
	.zero	8
	.globl	CPU_Result
	.align 8
	.type	CPU_Result, @object
	.size	CPU_Result, 8
CPU_Result:
	.zero	8
	.globl	host_MatC
	.align 8
	.type	host_MatC, @object
	.size	host_MatC, 8
host_MatC:
	.zero	8
	.globl	host_MatB
	.align 8
	.type	host_MatB, @object
	.size	host_MatB, 8
host_MatB:
	.zero	8
	.globl	host_MatA
	.align 8
	.type	host_MatA, @object
	.size	host_MatA, 8
host_MatA:
	.zero	8
	.globl	ret
	.align 4
	.type	ret, @object
	.size	ret, 4
ret:
	.zero	4
	.globl	stop
	.align 8
	.type	stop, @object
	.size	stop, 8
stop:
	.zero	8
	.globl	start
	.align 8
	.type	start, @object
	.size	start, 8
start:
	.zero	8
	.globl	deviceProp
	.align 32
	.type	deviceProp, @object
	.size	deviceProp, 1032
deviceProp:
	.zero	1032
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC5:
	.long	-400107883
	.long	1041313291
	.align 8
.LC13:
	.long	-755914244
	.long	1062232653
	.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:


/*****************************************************************************


  Example     :  cuda-matrix-matrix-multiplication.cu
 
  Objective   : Write a CUDA Program to perform Matrix Matrix multiplication.

  Input       : None 

  Output      : Execution time in seconds , Gflops achieved
                                                                                                                            
  Created     : Aug 2011    

  E-mail      : RarchK         
                                 
****************************************************************************/

#include<stdio.h>
#include<hip/hip_runtime.h>
#define BLOCKSIZE 16
#define SIZE 128

hipDeviceProp_t deviceProp;	
hipEvent_t start,stop;
hipError_t ret;
double *host_MatA,*host_MatB,*host_MatC,*CPU_Result;
double *device_MatA,*device_MatB,*device_MatC;
int size = SIZE;
float elapsedTime;
double Tsec,gflops;

/*kernel funtion*/
__global__ void Muld(double* A, double* B, int wA, int wB, double* C)
  {
   int bx = blockIdx.x;
   int by = blockIdx.y;
   int tx = threadIdx.x;
   int ty = threadIdx.y;
   int aBegin  = wA * BLOCKSIZE * by;
   int aEnd = aBegin + wA - 1;
   int aStep  = BLOCKSIZE;
   int bBegin  =  BLOCKSIZE * bx;
   int bStep = BLOCKSIZE * wB;
   double Csub = 0;
   for(int a = aBegin, b = bBegin; a <= aEnd ; a  += aStep, b += bStep)
     {
       __shared__ double As[BLOCKSIZE][BLOCKSIZE];
       __shared__ double Bs[BLOCKSIZE][BLOCKSIZE];
       As[ty][tx] = A[a + wA * ty + tx];
       Bs[ty][tx] = B[b+ wB * ty + tx];
       __syncthreads();
       for(int k= 0; k< BLOCKSIZE; ++k)
         Csub += As[ty][k] * Bs[k][tx];
       __syncthreads();
      }

     int c = wB * BLOCKSIZE * by + BLOCKSIZE * bx;
     C[ c+ wB * ty + tx] = Csub;

  }/* end of Muld device code */


/*mem error*/
void mem_error(char *arrayname, char *benchmark, int len, char *type)
{
        printf("\nMemory not sufficient to allocate for array %s\n\tBenchmark : %s  \n\tMemory requested = %d number of %s elements\n",arrayname, benchmark, len, type);
        exit(-1);
}


/*cuda safe call*/
void CUDA_SAFE_CALL(hipError_t call)
{
        hipError_t ret = call;
        //printf("RETURN FROM THE CUDA CALL:%d\t:",ret);                                        
        switch(ret)
        {
                case hipSuccess:
                //              printf("Success\n");                    
                                break;
        /*      case cudaErrorInvalidValue:                             
                                {
                                printf("ERROR: InvalidValue:%i.\n",__LINE__);
                                exit(-1);
                                break;  
                                }                       
                case cudaErrorInvalidDevicePointer:                     
                                {
                                printf("ERROR:Invalid Device pointeri:%i.\n",__LINE__);
                                exit(-1);
                                break;
                                }                       
                case cudaErrorInvalidMemcpyDirection:                   
                                {
                                printf("ERROR:Invalid memcpy direction:%i.\n",__LINE__);        
                                exit(-1);
                                break;
                                }                       */
                default:
                        {
                                printf(" ERROR at line :%i.%d' ' %s\n",__LINE__,ret,hipGetErrorString(ret));
                                exit(-1);
                                break;
                        }
        }
}



/* void SetUp_CUDA_Exe_Config() */
void check_block_grid_dim(hipDeviceProp_t devProp,dim3 blockDim,dim3 gridDim)
{

        if( blockDim.x >= devProp.maxThreadsDim[0] || blockDim.y >= devProp.maxThreadsDim[1] || blockDim.z >= devProp.maxThreadsDim[2] )
        {
                printf("\nBlock Dimensions exceed the maximum limits:%d * %d * %d \n",devProp.maxThreadsDim[0],devProp.maxThreadsDim[1],devProp.maxThreadsDim[2]);
               exit(-1);
        }

        if( gridDim.x >= devProp.maxGridSize[0] || gridDim.y >= devProp.maxGridSize[1] || gridDim.z >= devProp.maxGridSize[2] )
        {
                printf("\nGrid Dimensions exceed the maximum limits:%d * %d * %d \n",devProp.maxGridSize[0],devProp.maxGridSize[1],devProp.maxGridSize[2]);
               exit(-1);
        }
}


/*function to free memory*/
void dfree(double * arr[],int len)
{
        for(int i=0;i<len;i++)
                CUDA_SAFE_CALL(hipFree(arr[i]));
        printf("mem freed\n");
}


/*calculate Gflops*/
double calculate_gflops(double &Tsec)
{
	//printf("time taken is %.8lf\n",Tsec);
	double gflops=(1.0e-9 * (( 1.0 * size*size*size )/Tsec));
	//printf("Gflops is \t%f\n",gflops);
	return gflops;

}

/*get device count*/
int get_DeviceCount()
{
        int count;
        hipGetDeviceCount(&count);
        return count;
}



/*launch kernel function is called in main()*/
void launch_kernel_MatMatMult()
{
/* threads_per_block= BLOCKSIZE, blocks_per_grid=size/dimBlock  */

	printf("in launch kernel\n");
	dim3 dimBlock(BLOCKSIZE,BLOCKSIZE);
	dim3 dimGrid(size/dimBlock.x,size/dimBlock.y);	
 
//checking the maximum limit of blocksize and gridsize-------------------	
	check_block_grid_dim(deviceProp,dimBlock,dimGrid);
 	printf("after check\n"); 
	hipEventRecord(start,0);	
	Muld<<<dimGrid,dimBlock>>>(device_MatA,device_MatB,size,size,device_MatC);
	hipEventRecord(stop,0);
	hipEventSynchronize(stop);
	hipEventElapsedTime(&elapsedTime,start,stop);
	Tsec=elapsedTime*1.0e-3;
	calculate_gflops(Tsec);

}

/* Fill in the vector with double precision values */
void fill_dp_vector(double* vec,int size)
{
        int ind;
        for(ind=0;ind<size;ind++)
                vec[ind]=drand48();
}

/*function to print on the screen*/
void print_on_screen(char * program_name,float tsec,double gflops,int size,int flag)//flag=1 if gflops has been calculated else flag =0
{
        printf("\n---------------%s----------------\n",program_name);
        printf("\tSIZE\t TIME_SEC\t Gflops\n");
        if(flag==1)
        printf("\t%d\t%f\t%lf\t",size,tsec,gflops);
        else
        printf("\t%d\t%lf\t%lf\t",size,"---","---");

}




/*-----main()-----*/

int main()
 {
	int device_Count=get_DeviceCount();
        printf("\n\nNUmber of Devices : %d\n\n", device_Count);

        // Device Selection, Device 1: Tesla C1060
        hipSetDevice(1);
	
	int device;
        // Current Device Detection
        hipGetDevice(&device);         
        hipGetDeviceProperties(&deviceProp,device);
	printf("Using device %d: %s \n", device, deviceProp.name);
	/* allocate memory for GPU events 
	start = (cudaEvent_t) malloc (sizeof(cudaEvent_t));	
	stop = (cudaEvent_t) malloc (sizeof(cudaEvent_t));
	if(start==NULL)
		mem_error("start","MatMatMult",1,"cudaEvent_t");
	if(stop==NULL)
		mem_error("stop","MatMatMult",1,"cudaEvent_t");*/
	//event creation...
	CUDA_SAFE_CALL(hipEventCreate (&start));
        CUDA_SAFE_CALL(hipEventCreate (&stop));
   

   
    	/*allocating the memory for each matrix */
	host_MatA = new double[size*size];
	host_MatB = new double[size*size];
	host_MatC = new double[size*size];
	CPU_Result= new double[size*size];
	 if(host_MatA==NULL)
                mem_error("host_MatA","MatMatMult",size,"double");

	if(host_MatB==NULL)
                mem_error("host_MatB","MatMatMult",size,"double");
	if(host_MatC==NULL)
                mem_error("host_MatC","MatMatMult",size,"double");
	if(CPU_Result==NULL)
                mem_error("CPU_Result","MatMatMult",size,"double");


	//--------filling the matrix with double precision-----------
  	fill_dp_vector(host_MatA,size*size);
  	fill_dp_vector(host_MatB,size*size); 
  
 	//allocating memory on GPU
	CUDA_SAFE_CALL(hipMalloc( (void**)&device_MatA,size*size*sizeof(double)));
	CUDA_SAFE_CALL(hipMalloc( (void**)&device_MatB, size*size*sizeof(double)));
	CUDA_SAFE_CALL(hipMalloc( (void**)&device_MatC,size*size*sizeof(double)));

   	// copying host matrix to device matrix
    	CUDA_SAFE_CALL(hipMemcpy((void*)device_MatA, (void*)host_MatA, size*size* sizeof(double) , hipMemcpyHostToDevice ));
    	CUDA_SAFE_CALL(hipMemcpy((void*)device_MatB, (void*)host_MatB, size*size*sizeof(double) , hipMemcpyHostToDevice ));
 
	launch_kernel_MatMatMult(); //launching the kernel
	
   
   	//retriving result from device
   	CUDA_SAFE_CALL(hipMemcpy((void*)host_MatC, (void*)device_MatC, size*size*sizeof(double) , hipMemcpyDeviceToHost ));

	//comparing result of CPU-GPU
	//relError(CPU_Result,host_MatC,size*size);

	//printing the result on screen 
     	print_on_screen("MAT MAT Mult",Tsec,calculate_gflops(Tsec),size,1);


   
	//free the device memory----------
	double *array[3];
	array[0]=device_MatA;
	array[1]=device_MatB;
	array[2]=device_MatC;
	
	dfree(array,3);
	//free host memory----------

	free(host_MatA);
	free(host_MatB);
	free(host_MatC);
	free(CPU_Result);

}// end of main

	.text
	.file	"cuda-matrix-matrix-multiplication.hip"
	.globl	_Z19__device_stub__MuldPdS_iiS_ # -- Begin function _Z19__device_stub__MuldPdS_iiS_
	.type	_Z19__device_stub__MuldPdS_iiS_,@function
_Z19__device_stub__MuldPdS_iiS_:        # @_Z19__device_stub__MuldPdS_iiS_
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.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	4(%rsp), %rsi
	movl	%edx, (%rsi)
	movq	%rsp, %rdx
	movl	%ecx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%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	$_Z4MuldPdS_iiS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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_end0:
	.size	_Z19__device_stub__MuldPdS_iiS_, .Lfunc_end0-_Z19__device_stub__MuldPdS_iiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9mem_errorPcS_iS_             # -- Begin function _Z9mem_errorPcS_iS_
	.type	_Z9mem_errorPcS_iS_,@function
_Z9mem_errorPcS_iS_:                    # @_Z9mem_errorPcS_iS_
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rcx, %r8
	movl	%edx, %ecx
	movq	%rsi, %rdx
	movq	%rdi, %rsi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z9mem_errorPcS_iS_, .Lfunc_end1-_Z9mem_errorPcS_iS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z14CUDA_SAFE_CALL10hipError_t  # -- Begin function _Z14CUDA_SAFE_CALL10hipError_t
	.type	_Z14CUDA_SAFE_CALL10hipError_t,@function
_Z14CUDA_SAFE_CALL10hipError_t:         # @_Z14CUDA_SAFE_CALL10hipError_t
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB2_2
# %bb.1:
	retq
.LBB2_2:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	callq	hipGetErrorString
	movl	$.L.str.1, %edi
	movl	$102, %esi
	movl	%ebx, %edx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z14CUDA_SAFE_CALL10hipError_t, .Lfunc_end2-_Z14CUDA_SAFE_CALL10hipError_t
	.cfi_endproc
                                        # -- End function
	.globl	_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_ # -- Begin function _Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_
	.type	_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_,@function
_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_: # @_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	%esi, %r9d
	leaq	16(%rsp), %r10
	movl	324(%r10), %esi
	cmpl	%edi, %esi
	jbe	.LBB3_1
# %bb.2:
	shrq	$32, %rdi
	movl	328(%r10), %eax
	movl	332(%r10), %r8d
	cmpl	%edi, %eax
	jbe	.LBB3_4
# %bb.3:
	cmpl	%r9d, %r8d
	jbe	.LBB3_4
# %bb.6:
	movl	336(%r10), %esi
	movl	340(%r10), %eax
	movl	344(%r10), %r8d
	cmpl	%edx, %esi
	jbe	.LBB3_9
# %bb.7:
	shrq	$32, %rdx
	cmpl	%edx, %eax
	jbe	.LBB3_9
# %bb.8:
	cmpl	%ecx, %r8d
	jbe	.LBB3_9
# %bb.10:
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.LBB3_1:                                # %._crit_edge
	.cfi_def_cfa_offset 16
	movl	328(%r10), %eax
	movl	332(%r10), %r8d
.LBB3_4:
	movl	$.L.str.2, %edi
	jmp	.LBB3_5
.LBB3_9:
	movl	$.L.str.3, %edi
.LBB3_5:
	movl	%eax, %edx
	movl	%r8d, %ecx
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_, .Lfunc_end3-_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z5dfreePPdi                    # -- Begin function _Z5dfreePPdi
	.type	_Z5dfreePPdi,@function
_Z5dfreePPdi:                           # @_Z5dfreePPdi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB4_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r15,8), %rdi
	callq	hipFree
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB4_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_4:                                # %._crit_edge
	movl	$.Lstr, %edi
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end4:
	.size	_Z5dfreePPdi, .Lfunc_end4-_Z5dfreePPdi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z16calculate_gflopsRd
.LCPI5_0:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.text
	.globl	_Z16calculate_gflopsRd
	.type	_Z16calculate_gflopsRd,@function
_Z16calculate_gflopsRd:                 # @_Z16calculate_gflopsRd
	.cfi_startproc
# %bb.0:
	cvtsi2sdl	size(%rip), %xmm1
	movapd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	divsd	(%rdi), %xmm0
	mulsd	.LCPI5_0(%rip), %xmm0
	retq
.Lfunc_end5:
	.size	_Z16calculate_gflopsRd, .Lfunc_end5-_Z16calculate_gflopsRd
	.cfi_endproc
                                        # -- End function
	.globl	_Z15get_DeviceCountv            # -- Begin function _Z15get_DeviceCountv
	.type	_Z15get_DeviceCountv,@function
_Z15get_DeviceCountv:                   # @_Z15get_DeviceCountv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	leaq	12(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	(%rbx), %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z15get_DeviceCountv, .Lfunc_end6-_Z15get_DeviceCountv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z24launch_kernel_MatMatMultv
.LCPI7_0:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.text
	.globl	_Z24launch_kernel_MatMatMultv
	.type	_Z24launch_kernel_MatMatMultv,@function
_Z24launch_kernel_MatMatMultv:          # @_Z24launch_kernel_MatMatMultv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	size(%rip), %eax
	shrl	$4, %eax
	movq	%rax, %rbx
	shlq	$32, %rbx
	orq	%rax, %rbx
	movl	$184, %ecx
	movl	$deviceProp, %esi
	movq	%rsp, %rdi
	rep;movsq (%rsi), %es:(%rdi)
	movabsq	$68719476752, %r14              # imm = 0x1000000010
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	_Z20check_block_grid_dim20hipDeviceProp_tR06004dim3S0_
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	start(%rip), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_2
# %bb.1:
	movq	device_MatA(%rip), %rdi
	movq	device_MatB(%rip), %rsi
	movl	size(%rip), %ecx
	movq	device_MatC(%rip), %r8
	movl	%ecx, %edx
	callq	_Z19__device_stub__MuldPdS_iiS_
.LBB7_2:
	movq	stop(%rip), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	stop(%rip), %rdi
	callq	hipEventSynchronize
	movq	start(%rip), %rsi
	movq	stop(%rip), %rdx
	movl	$elapsedTime, %edi
	callq	hipEventElapsedTime
	cvtss2sd	elapsedTime(%rip), %xmm0
	mulsd	.LCPI7_0(%rip), %xmm0
	movsd	%xmm0, Tsec(%rip)
	addq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_Z24launch_kernel_MatMatMultv, .Lfunc_end7-_Z24launch_kernel_MatMatMultv
	.cfi_endproc
                                        # -- End function
	.globl	_Z14fill_dp_vectorPdi           # -- Begin function _Z14fill_dp_vectorPdi
	.type	_Z14fill_dp_vectorPdi,@function
_Z14fill_dp_vectorPdi:                  # @_Z14fill_dp_vectorPdi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB8_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB8_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	drand48
	movsd	%xmm0, (%rbx,%r15,8)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB8_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB8_4:                                # %._crit_edge
	retq
.Lfunc_end8:
	.size	_Z14fill_dp_vectorPdi, .Lfunc_end8-_Z14fill_dp_vectorPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z15print_on_screenPcfdii       # -- Begin function _Z15print_on_screenPcfdii
	.type	_Z15print_on_screenPcfdii,@function
_Z15print_on_screenPcfdii:              # @_Z15print_on_screenPcfdii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movl	%esi, %ebx
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	movq	%rdi, %rsi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	cmpl	$1, %ebp
	jne	.LBB9_2
# %bb.1:
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$.L.str.9, %edi
	movl	%ebx, %esi
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movb	$2, %al
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.LBB9_2:
	.cfi_def_cfa_offset 48
	movl	$.L.str.10, %edi
	movl	$.L.str.11, %edx
	movl	$.L.str.11, %ecx
	movl	%ebx, %esi
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end9:
	.size	_Z15print_on_screenPcfdii, .Lfunc_end9-_Z15print_on_screenPcfdii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI10_0:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	(%rbx), %esi
	xorl	%ebx, %ebx
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	hipSetDevice
	leaq	12(%rsp), %r14
	movq	%r14, %rdi
	callq	hipGetDevice
	movl	(%r14), %esi
	movl	$deviceProp, %edi
	callq	hipGetDevicePropertiesR0600
	movl	(%r14), %esi
	movl	$.L.str.13, %edi
	movl	$deviceProp, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$start, %edi
	callq	hipEventCreate
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movl	$stop, %edi
	callq	hipEventCreate
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movl	size(%rip), %ebp
	movl	%ebp, %r12d
	imull	%r12d, %r12d
	leaq	(,%r12,8), %r15
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%rax, host_MatA(%rip)
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, host_MatB(%rip)
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, host_MatC(%rip)
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, CPU_Result(%rip)
	testl	%ebp, %ebp
	je	.LBB10_8
# %bb.1:                                # %.lr.ph.i.preheader
	xorl	%ebx, %ebx
.LBB10_2:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	drand48
	movsd	%xmm0, (%r14,%rbx,8)
	incq	%rbx
	cmpq	%rbx, %r12
	jne	.LBB10_2
# %bb.3:                                # %_Z14fill_dp_vectorPdi.exit
	movl	size(%rip), %ebx
	testl	%ebx, %ebx
	je	.LBB10_4
# %bb.5:                                # %.lr.ph.preheader.i5
	movq	host_MatB(%rip), %r14
	imull	%ebx, %ebx
	xorl	%r15d, %r15d
.LBB10_6:                               # %.lr.ph.i7
                                        # =>This Inner Loop Header: Depth=1
	callq	drand48
	movsd	%xmm0, (%r14,%r15,8)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB10_6
# %bb.7:                                # %_Z14fill_dp_vectorPdi.exit11.loopexit
	movl	size(%rip), %ebx
	jmp	.LBB10_8
.LBB10_4:
	xorl	%ebx, %ebx
.LBB10_8:                               # %_Z14fill_dp_vectorPdi.exit11
	imull	%ebx, %ebx
	shlq	$3, %rbx
	movl	$device_MatA, %edi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movl	size(%rip), %esi
	imull	%esi, %esi
	shlq	$3, %rsi
	movl	$device_MatB, %edi
	callq	hipMalloc
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movl	size(%rip), %esi
	imull	%esi, %esi
	shlq	$3, %rsi
	movl	$device_MatC, %edi
	callq	hipMalloc
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movq	device_MatA(%rip), %rdi
	movq	host_MatA(%rip), %rsi
	movl	size(%rip), %edx
	imull	%edx, %edx
	shlq	$3, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movq	device_MatB(%rip), %rdi
	movq	host_MatB(%rip), %rsi
	movl	size(%rip), %edx
	imull	%edx, %edx
	shlq	$3, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	callq	_Z24launch_kernel_MatMatMultv
	movq	host_MatC(%rip), %rdi
	movq	device_MatC(%rip), %rsi
	movl	size(%rip), %edx
	imull	%edx, %edx
	shlq	$3, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_Z14CUDA_SAFE_CALL10hipError_t
	movsd	Tsec(%rip), %xmm2               # xmm2 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm2, %xmm0
	movl	size(%rip), %esi
	cvtsi2sd	%esi, %xmm3
	movapd	%xmm3, %xmm1
	mulsd	%xmm3, %xmm1
	mulsd	%xmm3, %xmm1
	divsd	%xmm2, %xmm1
	mulsd	.LCPI10_0(%rip), %xmm1
	movl	$.L.str.20, %edi
	movl	$1, %edx
	callq	_Z15print_on_screenPcfdii
	movq	device_MatA(%rip), %rax
	leaq	16(%rsp), %rdi
	movq	%rax, (%rdi)
	movq	device_MatB(%rip), %rax
	movq	%rax, 8(%rdi)
	movq	device_MatC(%rip), %rax
	movq	%rax, 16(%rdi)
	movl	$3, %esi
	callq	_Z5dfreePPdi
	movq	host_MatA(%rip), %rdi
	callq	free
	movq	host_MatB(%rip), %rdi
	callq	free
	movq	host_MatC(%rip), %rdi
	callq	free
	movq	CPU_Result(%rip), %rdi
	callq	free
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end10:
	.size	main, .Lfunc_end10-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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB11_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB11_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4MuldPdS_iiS_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end11:
	.size	__hip_module_ctor, .Lfunc_end11-__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	.LBB12_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
.LBB12_2:
	retq
.Lfunc_end12:
	.size	__hip_module_dtor, .Lfunc_end12-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	deviceProp,@object              # @deviceProp
	.bss
	.globl	deviceProp
	.p2align	3, 0x0
deviceProp:
	.zero	1472
	.size	deviceProp, 1472

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

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

	.type	ret,@object                     # @ret
	.globl	ret
	.p2align	2, 0x0
ret:
	.long	0                               # 0x0
	.size	ret, 4

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

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

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

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

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

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

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

	.type	size,@object                    # @size
	.data
	.globl	size
	.p2align	2, 0x0
size:
	.long	128                             # 0x80
	.size	size, 4

	.type	elapsedTime,@object             # @elapsedTime
	.bss
	.globl	elapsedTime
	.p2align	2, 0x0
elapsedTime:
	.long	0x00000000                      # float 0
	.size	elapsedTime, 4

	.type	Tsec,@object                    # @Tsec
	.globl	Tsec
	.p2align	3, 0x0
Tsec:
	.quad	0x0000000000000000              # double 0
	.size	Tsec, 8

	.type	gflops,@object                  # @gflops
	.globl	gflops
	.p2align	3, 0x0
gflops:
	.quad	0x0000000000000000              # double 0
	.size	gflops, 8

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"\nMemory not sufficient to allocate for array %s\n\tBenchmark : %s  \n\tMemory requested = %d number of %s elements\n"
	.size	.L.str, 112

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	" ERROR at line :%i.%d' ' %s\n"
	.size	.L.str.1, 29

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\nBlock Dimensions exceed the maximum limits:%d * %d * %d \n"
	.size	.L.str.2, 59

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\nGrid Dimensions exceed the maximum limits:%d * %d * %d \n"
	.size	.L.str.3, 58

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n---------------%s----------------\n"
	.size	.L.str.7, 36

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\t%d\t%f\t%lf\t"
	.size	.L.str.9, 12

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"\t%d\t%lf\t%lf\t"
	.size	.L.str.10, 13

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"---"
	.size	.L.str.11, 4

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"\n\nNUmber of Devices : %d\n\n"
	.size	.L.str.12, 27

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Using device %d: %s \n"
	.size	.L.str.13, 22

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"MAT MAT Mult"
	.size	.L.str.20, 13

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4MuldPdS_iiS_"
	.size	.L__unnamed_1, 16

	.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	"mem freed"
	.size	.Lstr, 10

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"in launch kernel"
	.size	.Lstr.1, 17

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"after check"
	.size	.Lstr.2, 12

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"\tSIZE\t TIME_SEC\t Gflops"
	.size	.Lstr.3, 24

	.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 _Z19__device_stub__MuldPdS_iiS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym deviceProp
	.addrsig_sym start
	.addrsig_sym stop
	.addrsig_sym device_MatA
	.addrsig_sym device_MatB
	.addrsig_sym device_MatC
	.addrsig_sym elapsedTime
	.addrsig_sym _Z4MuldPdS_iiS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4MuldPdS_iiS_         ; -- Begin function _Z4MuldPdS_iiS_
	.globl	_Z4MuldPdS_iiS_
	.p2align	8
	.type	_Z4MuldPdS_iiS_,@function
_Z4MuldPdS_iiS_:                        ; @_Z4MuldPdS_iiS_
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	s_mov_b32 s6, 0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_lo_u32 v5, v1, s3
	s_cmp_gt_i32 s2, 0
	s_cbranch_scc1 .LBB0_2
; %bb.1:                                ; %.._crit_edge_crit_edge
	v_mul_lo_u32 v3, v1, s3
	s_mov_b64 s[4:5], 0
	s_branch .LBB0_3
.LBB0_2:
	s_mov_b32 s6, -1
                                        ; implicit-def: $sgpr4_sgpr5
                                        ; implicit-def: $vgpr3
.LBB0_3:                                ; %Flow72
	v_and_b32_e32 v0, 0x3ff, v0
	s_lshl_b32 s8, s14, 4
	s_and_not1_b32 vcc_lo, exec_lo, s6
	s_lshl_b32 s3, s3, 4
	s_cbranch_vccnz .LBB0_9
; %bb.4:                                ; %.lr.ph
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshlrev_b32_e32 v2, 3, v0
	v_lshlrev_b32_e32 v6, 7, v1
	v_mad_u64_u32 v[3:4], null, v1, s2, v[0:1]
	s_mul_i32 s9, s2, s15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v7, 0x800, v2
	v_dual_mov_b32 v1, 0 :: v_dual_add_nc_u32 v4, v6, v2
	v_mov_b32_e32 v2, 0
	v_add_nc_u32_e32 v8, v5, v0
	s_delay_alu instid0(VALU_DEP_4)
	v_add_nc_u32_e32 v9, v7, v6
	s_lshl_b32 s9, s9, 4
	s_mov_b32 s10, s8
	s_add_i32 s2, s9, s2
.LBB0_5:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_6 Depth 2
	v_add_nc_u32_e32 v10, s9, v3
	v_add_nc_u32_e32 v12, s10, v8
	s_mov_b32 s11, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v11, 31, v10
	v_ashrrev_i32_e32 v13, 31, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[10:11], 3, v[10:11]
	v_lshlrev_b64 v[12:13], 3, v[12:13]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v10, vcc_lo, s4, v10
	v_add_co_ci_u32_e32 v11, vcc_lo, s5, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v12, vcc_lo, s6, v12
	v_add_co_ci_u32_e32 v13, vcc_lo, s7, v13, vcc_lo
	global_load_b64 v[14:15], v[10:11], off
	global_load_b64 v[11:12], v[12:13], off
	v_mov_b32_e32 v10, v7
	s_waitcnt vmcnt(1)
	ds_store_b64 v4, v[14:15]
	s_waitcnt vmcnt(0)
	ds_store_b64 v9, v[11:12]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_6:                                ;   Parent Loop BB0_5 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v13, s11, v6
	s_add_i32 s11, s11, 8
	ds_load_b64 v[11:12], v10
	ds_load_b64 v[13:14], v13
	v_add_nc_u32_e32 v10, 0x80, v10
	s_cmpk_eq_i32 s11, 0x80
	s_waitcnt lgkmcnt(0)
	v_fma_f64 v[1:2], v[13:14], v[11:12], v[1:2]
	s_cbranch_scc0 .LBB0_6
; %bb.7:                                ;   in Loop: Header=BB0_5 Depth=1
	s_add_i32 s9, s9, 16
	s_add_i32 s10, s10, s3
	s_cmp_ge_i32 s9, s2
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_5
; %bb.8:                                ; %Flow
	v_mov_b32_e32 v3, v5
	s_branch .LBB0_10
.LBB0_9:
	v_dual_mov_b32 v1, s4 :: v_dual_mov_b32 v2, s5
.LBB0_10:                               ; %Flow73
	v_add_nc_u32_e32 v0, s8, v0
	s_load_b64 s[0:1], s[0:1], 0x18
	s_mul_i32 s3, s3, s15
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add3_u32 v3, v0, v3, s3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[3:4], 3, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	global_store_b64 v[3:4], v[1:2], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4MuldPdS_iiS_
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 16
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z4MuldPdS_iiS_, .Lfunc_end0-_Z4MuldPdS_iiS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 484
; NumSgprs: 18
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 16
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4MuldPdS_iiS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4MuldPdS_iiS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
