/****************************************************************************
 * cuda_bigger_block.cu - a simple multi-layer Nerual Network
 *
 * Assignment of Module 2 of Ap4AI course of AI master degree @unibo
 *
 * Last updated in 2021 by Hanying Zhang <hanying.zhang@studio.unibo.it>
 * 
 * To the extent possible under law, the author(s) nave dedicated all
 * copyright and related and neighboring rights to this software to the 
 * public domain worldwide. This software is distributed without any warranty.
 *
 * --------------------------------------------------------------------------
 *
 * compile with:
 * nvcc cuda_bigger_block.c -o cuda_bigger_block
 *
 * Run with:
 * ./cuda_bigger_block -n # of nodes -k # of layers
 * 
 ****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define R 3
const int BLKDIM = (64/R*R)*R;

/*  BLKDIM optimization
 *  # of threads shoule be able to divide (32 * R)
 *  (n_node / R * R) is # of nodes being able to divide R  ->
 *  (n_node / R * R) * R is # of threads being able to divide R
 */

// Use a __device__ function to calculate Sigmoid
__device__ float Sigmoid(float x, float b)
{
	return 1.0 / ( expf(-x - b) + 1 );
}

/* The calculation of y values for one layer */
__global__ void one_layer_calc(float *x, float *W, float *b, float *y, int N)
{
    int gidx = blockIdx.x * blockDim.x + threadIdx.x;  // global thread index
    int lidx = threadIdx.x;                            // local thread index
    int gi = gidx / R;            // global node index
	int li = lidx / R;            // local node index
    int j = gidx - gi * R;         // index of related values in previous layer for each value in y

	int pre_layer_len = N - R + 1; 
 
    float y_tmp = 0.0;
	// shared memory used to store local values in y
    __shared__ float local_y[BLKDIM];

    if(gi < pre_layer_len && j < R) {
        local_y[lidx] = x[gi + j] * W[gi * R + j];
        //printf("i:%d j:%d lidx: %d x:%.2f W:%.2f y:%.2f \n", \
		          gi, j, lidx, x[gi+j], W[gi * R + j], local_y[lidx]);
    }

    __syncthreads();
    //printf("\n");  
    
	// Accumulate R values of each node in y
    for (int p=0; p<R; p++) {
    	y_tmp += local_y[li * R + p];
    	//printf("i:%d j:%d lidx: %d local_y:%.2f tmp:%.2f \n", gi,j,lidx, local_y[li * R + p], y_tmp);
    }

    __syncthreads();
   
   	// Sigmoid
	y_tmp = Sigmoid(y_tmp, *b);

	// Copy temp values to y
    y[gi] = y_tmp;
}

/* Random values between -1 and 1 */
float random_init_small()
{
	return ((rand() % 2000) - 1000) / 1000.0;     // random Initialization to values in range [-1,1]
}

/* Initialize the W and b parameters for one layer */
void init_layer_parameters(float (*W)[R], float *b, int layer_len)
{
	for (int i=0; i<layer_len; i++) {
		for (int j=0; j<R; j++) {
			W[i][j] = random_init_small();
		}
	}

	*b = random_init_small();
}

/* Read in the network parameters (N, K) from command-line input. */
void parse_command_line_parameters(int argc, char *argv[], int *N, int *K)
{
	int c;
	while ((c = getopt (argc, argv, "n:k:")) != -1) {
		switch (c) {
			case 'n': // N
				*N = atoi(optarg);
				break;
			case 'k': // K
				*K = atoi(optarg);
				break;
		}
	}
}

int main( int argc, char *argv[] )
{
	srand(42);
	
    int N = 100;
    int K = 3;

    // get N, K from command line
    parse_command_line_parameters(argc, argv, &N, &K);
    printf("input size:%d, number of layers:%d.\n",  N, K);

    // Judge if the length of the k-th layer is bigger than 0
	int last_layer_len = N - (K-1) * (R-1);
    if (last_layer_len <= 0) {
	    printf("The parameters you input couldn't support k layers. \
			    Please give bigger size of layer 0 or use less layers.\n");
	    return EXIT_FAILURE;
    } 

    // initialize the values of the input layer
    float x[N];
    for (int i=0; i < N; i++) {
	    x[i] = random_init_small();
    }
    //TEST
    for (int i=0; i < N; i++) {
	    printf("%.2f ", x[i]);
    }
    printf("\n");

    // create an array to store the latest layer got calculated
    float latest_layer[N];
    memcpy(latest_layer, x, N * sizeof(float)); //the latest layer is the input layer at the beginning

    float *latest_layer_d;
    cudaMalloc( (void**)&latest_layer_d, N * sizeof(float) );
    cudaMemcpy( latest_layer_d, latest_layer, N * sizeof(float), cudaMemcpyHostToDevice);

	// Start recording time costage
    clock_t start = clock();

    // Loop over K layers
    for(int k=1; k<K; k++) {
        // calculate lengthes of this layer and the previous layer
        int layer_len = N - k * (R-1);
		int in_layer_len = layer_len + R -1;

  		// initialize parameters
        float b;
        float W[layer_len][R];
        float y[layer_len];
     
        init_layer_parameters(W, &b, layer_len);
     
        float *b_d;
        float *W_d;
        float *y_d;
    
        cudaMalloc( (void**)&b_d, sizeof(float) );
        cudaMalloc( (void**)&W_d, layer_len * R * sizeof(float) );
        cudaMalloc( (void**)&y_d, layer_len * sizeof(float) );

        cudaMemcpy(b_d, &b, sizeof(float), cudaMemcpyHostToDevice);
        cudaMemcpy(W_d, W, layer_len * R * sizeof(float), cudaMemcpyHostToDevice);
        cudaMemcpy(y_d, y, layer_len * sizeof(float), cudaMemcpyHostToDevice);

  		// calculation of each layer
        // printf("\nGRIDDIM %d BLKDIM: %d\n", (layer_len*R+BLKDIM-1)/BLKDIM, BLKDIM);
  		one_layer_calc<<<(layer_len*R+BLKDIM-1)/BLKDIM, BLKDIM>>>(latest_layer_d, W_d, b_d, y_d, in_layer_len);

        cudaDeviceSynchronize();

        // copy result back to host
        cudaMemcpy(y, y_d, layer_len * sizeof(float), cudaMemcpyDeviceToHost);

		/*
		// Print the result of each layer
        printf("\nThe layer result got\n");
        for(int i=0; i<layer_len; i++) {
            printf("%.2f ", y[i]);
        }
        printf("\n");
		*/

  		// save the latest_layer result
  		memcpy(latest_layer, y, layer_len * sizeof(float));
        cudaMemcpy(latest_layer_d, latest_layer, layer_len * sizeof(float), cudaMemcpyHostToDevice);

        // Free cuda memory
        cudaFree(W_d); cudaFree(y_d); cudaFree(b_d);
    }

    // calculate elapsed time
    clock_t end = clock();
    double time_elapsed = (double)(end - start) / CLOCKS_PER_SEC;
    printf("Time elapsed: %.3f\n", time_elapsed);

    cudaFree(latest_layer_d);

    // print final result
    printf("\nFinal result is: ");
    for(int i=0; i<last_layer_len; i++) {
	    printf("%.3f ", latest_layer[i]);
    }
    printf("\n");

    return EXIT_SUCCESS;
}

	.file	"tmpxft_00344ed4_00000000-6_cuda_v1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2047:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2047:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7Sigmoidff
	.type	_Z7Sigmoidff, @function
_Z7Sigmoidff:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2040:
	.size	_Z7Sigmoidff, .-_Z7Sigmoidff
	.globl	_Z17random_init_smallv
	.type	_Z17random_init_smallv, @function
_Z17random_init_smallv:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	rand@PLT
	movl	$2000, %ecx
	cltd
	idivl	%ecx
	subl	$1000, %edx
	cvtsi2sdl	%edx, %xmm0
	divsd	.LC0(%rip), %xmm0
	popq	%rdx
	.cfi_def_cfa_offset 8
	cvtsd2ss	%xmm0, %xmm0
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z17random_init_smallv, .-_Z17random_init_smallv
	.globl	_Z21init_layer_parametersPA3_fPfi
	.type	_Z21init_layer_parametersPA3_fPfi, @function
_Z21init_layer_parametersPA3_fPfi:
.LFB2042:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L7:
	cmpl	%r12d, %r13d
	jge	.L11
	call	_Z17random_init_smallv
	incl	%r13d
	addq	$12, %rbx
	movss	%xmm0, -12(%rbx)
	call	_Z17random_init_smallv
	movss	%xmm0, -8(%rbx)
	call	_Z17random_init_smallv
	movss	%xmm0, -4(%rbx)
	jmp	.L7
.L11:
	call	_Z17random_init_smallv
	movss	%xmm0, 0(%rbp)
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2042:
	.size	_Z21init_layer_parametersPA3_fPfi, .-_Z21init_layer_parametersPA3_fPfi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"n:k:"
	.text
	.globl	_Z29parse_command_line_parametersiPPcPiS1_
	.type	_Z29parse_command_line_parametersiPPcPiS1_, @function
_Z29parse_command_line_parametersiPPcPiS1_:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC1(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	%edi, %ebx
.L15:
	movq	%r14, %rdx
	movq	%rbp, %rsi
	movl	%ebx, %edi
	call	getopt@PLT
	cmpl	$-1, %eax
	je	.L20
	cmpl	$107, %eax
	je	.L14
	cmpl	$110, %eax
	jne	.L15
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, (%r12)
	jmp	.L15
.L14:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, 0(%r13)
	jmp	.L15
.L20:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2043:
	.size	_Z29parse_command_line_parametersiPPcPiS1_, .-_Z29parse_command_line_parametersiPPcPiS1_
	.globl	_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i
	.type	_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i, @function
_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i:
.LFB2069:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z14one_layer_calcPfS_S_S_i(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L21:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2069:
	.size	_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i, .-_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i
	.globl	_Z14one_layer_calcPfS_S_S_i
	.type	_Z14one_layer_calcPfS_S_S_i, @function
_Z14one_layer_calcPfS_S_S_i:
.LFB2070:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i
	.cfi_endproc
.LFE2070:
	.size	_Z14one_layer_calcPfS_S_S_i, .-_Z14one_layer_calcPfS_S_S_i
	.section	.rodata.str1.1
.LC2:
	.string	"input size:%d, number of layers:%d.\n"
.LC3:
	.string	"The parameters you input couldn't support k layers. \t\t\t    Please give bigger size of layer 0 or use less layers.\n"
.LC4:
	.string	"%.2f "
.LC5:
	.string	"\n"
.LC7:
	.string	"Time elapsed: %.3f\n"
.LC8:
	.string	"\nFinal result is: "
.LC9:
	.string	"%.3f "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2044:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movl	%edi, %ebx
	movl	$42, %edi
	subq	$168, %rsp
	movq	%rsi, -136(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	srand@PLT
	movl	%ebx, %edi
	leaq	-120(%rbp), %rcx
	leaq	-124(%rbp), %rdx
	movq	-136(%rbp), %rsi
	movl	$100, -124(%rbp)
	movl	$3, -120(%rbp)
	call	_Z29parse_command_line_parametersiPPcPiS1_
	movl	-120(%rbp), %ebx
	movl	-124(%rbp), %r13d
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movl	%ebx, %ecx
	movl	%r13d, %edx
	movl	%r13d, %r12d
	call	__printf_chk@PLT
	leal	-2(%rbx,%rbx), %eax
	subl	%eax, %r12d
	testl	%r12d, %r12d
	jg	.L27
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L26
.L27:
	movslq	%r13d, %rax
	movq	%rsp, %rdx
	salq	$2, %rax
	leaq	15(%rax), %rbx
	movq	%rax, -136(%rbp)
	movq	%rbx, %rcx
	movq	%rbx, %rax
	andq	$-4096, %rcx
	andq	$-16, %rax
	subq	%rcx, %rdx
.L29:
	cmpq	%rdx, %rsp
	je	.L30
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L29
.L30:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L31
	orq	$0, -8(%rsp,%rax)
.L31:
	movq	%rsp, %r14
	xorl	%r15d, %r15d
.L32:
	cmpl	%r15d, %r13d
	jle	.L64
	call	_Z17random_init_smallv
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	jmp	.L32
.L64:
	xorl	%r15d, %r15d
.L34:
	cmpl	%r15d, %r13d
	jle	.L65
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%r14,%r15,4), %xmm0
	call	__printf_chk@PLT
	incq	%r15
	jmp	.L34
.L65:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rax
	movq	%rsp, %rdx
	andq	$-4096, %rbx
	andq	$-16, %rax
	subq	%rbx, %rdx
.L36:
	cmpq	%rdx, %rsp
	je	.L37
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L36
.L37:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L38
	orq	$0, -8(%rsp,%rax)
.L38:
	movq	-136(%rbp), %rcx
	movq	%r14, %rsi
	movq	%rsp, %rdi
	movq	%rsp, -152(%rbp)
	movabsq	$4294967485, %r15
	movl	$1, %r13d
	movq	%rcx, %rdx
	call	__memcpy_chk@PLT
	movq	-136(%rbp), %rsi
	leaq	-112(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	-136(%rbp), %rdx
	movq	-112(%rbp), %rdi
	movl	$1, %ecx
	movq	-152(%rbp), %rsi
	call	cudaMemcpy@PLT
	call	clock@PLT
	movq	%rax, %r14
.L39:
	cmpl	%r13d, -120(%rbp)
	jle	.L66
	movl	-124(%rbp), %ebx
	leal	(%r13,%r13), %eax
	movq	%rsp, -192(%rbp)
	movq	%rsp, %rsi
	subl	%eax, %ebx
	movslq	%ebx, %rcx
	imulq	$12, %rcx, %rax
	addq	$15, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	andq	$-16, %rdx
	subq	%rax, %rsi
.L40:
	cmpq	%rsi, %rsp
	je	.L41
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L40
.L41:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L42
	orq	$0, -8(%rsp,%rax)
.L42:
	leaq	0(,%rcx,4), %rax
	movq	%rsp, -176(%rbp)
	movq	%rsp, %rcx
	leaq	15(%rax), %rdx
	movq	%rax, -144(%rbp)
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L43:
	cmpq	%rcx, %rsp
	je	.L44
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L43
.L44:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L45
	orq	$0, -8(%rsp,%rax)
.L45:
	leaq	-116(%rbp), %rax
	movq	-176(%rbp), %rdi
	movl	%ebx, %edx
	movq	%rsp, -160(%rbp)
	movq	%rax, %rsi
	movq	%rax, -184(%rbp)
	call	_Z21init_layer_parametersPA3_fPfi
	leaq	-104(%rbp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	leal	(%rbx,%rbx,2), %r8d
	leaq	-96(%rbp), %rdi
	movslq	%r8d, %rax
	movl	%r8d, -196(%rbp)
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, -168(%rbp)
	call	cudaMalloc@PLT
	movq	-144(%rbp), %rsi
	leaq	-88(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	-184(%rbp), %rsi
	movq	-104(%rbp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	-168(%rbp), %rdx
	movq	-96(%rbp), %rdi
	movl	$1, %ecx
	movq	-176(%rbp), %rsi
	call	cudaMemcpy@PLT
	movq	-144(%rbp), %rdx
	movq	-88(%rbp), %rdi
	movl	$1, %ecx
	movq	-160(%rbp), %rsi
	call	cudaMemcpy@PLT
	movl	-196(%rbp), %r8d
	xorl	%r9d, %r9d
	movq	%r15, -68(%rbp)
	movl	$189, %ecx
	movl	$1, -60(%rbp)
	leal	188(%r8), %eax
	xorl	%r8d, %r8d
	cltd
	idivl	%ecx
	movq	%r15, %rdx
	movl	$1, %ecx
	movl	%eax, -80(%rbp)
	movabsq	$4294967297, %rax
	movq	%rax, -76(%rbp)
	movq	-80(%rbp), %rdi
	movl	-72(%rbp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	-88(%rbp), %rcx
	movq	-104(%rbp), %rdx
	leal	2(%rbx), %r8d
	movq	-96(%rbp), %rsi
	movq	-112(%rbp), %rdi
	call	_Z41__device_stub__Z14one_layer_calcPfS_S_S_iPfS_S_S_i
.L46:
	call	cudaDeviceSynchronize@PLT
	movq	-144(%rbp), %rdx
	movq	-88(%rbp), %rsi
	incl	%r13d
	movq	-160(%rbp), %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	-136(%rbp), %rcx
	movq	-144(%rbp), %rdx
	movq	-160(%rbp), %rsi
	movq	-152(%rbp), %rdi
	call	__memcpy_chk@PLT
	movq	-144(%rbp), %rdx
	movq	-112(%rbp), %rdi
	movl	$1, %ecx
	movq	-152(%rbp), %rsi
	call	cudaMemcpy@PLT
	movq	-96(%rbp), %rdi
	call	cudaFree@PLT
	movq	-88(%rbp), %rdi
	call	cudaFree@PLT
	movq	-104(%rbp), %rdi
	call	cudaFree@PLT
	movq	-192(%rbp), %rsp
	jmp	.L39
.L66:
	call	clock@PLT
	leaq	.LC7(%rip), %rsi
	movslq	%r12d, %r12
	movl	$2, %edi
	subq	%r14, %rax
	leaq	.LC9(%rip), %r13
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC6(%rip), %xmm0
	call	__printf_chk@PLT
	movq	-112(%rbp), %rdi
	call	cudaFree@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-152(%rbp), %rbx
	leaq	(%rbx,%r12,4), %r12
.L48:
	cvtss2sd	(%rbx), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	addq	$4, %rbx
	cmpq	%r12, %rbx
	jne	.L48
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
.L26:
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2044:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z14one_layer_calcPfS_S_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2072:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14one_layer_calcPfS_S_S_i(%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
.LFE2072:
	.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	1083129856
	.align 8
.LC6:
	.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:

/****************************************************************************
 * cuda_bigger_block.cu - a simple multi-layer Nerual Network
 *
 * Assignment of Module 2 of Ap4AI course of AI master degree @unibo
 *
 * Last updated in 2021 by Hanying Zhang <hanying.zhang@studio.unibo.it>
 * 
 * To the extent possible under law, the author(s) nave dedicated all
 * copyright and related and neighboring rights to this software to the 
 * public domain worldwide. This software is distributed without any warranty.
 *
 * --------------------------------------------------------------------------
 *
 * compile with:
 * nvcc cuda_bigger_block.c -o cuda_bigger_block
 *
 * Run with:
 * ./cuda_bigger_block -n # of nodes -k # of layers
 * 
 ****************************************************************************/


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

#define R 3
const int BLKDIM = (64/R*R)*R;

/*  BLKDIM optimization
 *  # of threads shoule be able to divide (32 * R)
 *  (n_node / R * R) is # of nodes being able to divide R  ->
 *  (n_node / R * R) * R is # of threads being able to divide R
 */

// Use a __device__ function to calculate Sigmoid
__device__ float Sigmoid(float x, float b)
{
	return 1.0 / ( expf(-x - b) + 1 );
}

/* The calculation of y values for one layer */
__global__ void one_layer_calc(float *x, float *W, float *b, float *y, int N)
{
    int gidx = blockIdx.x * blockDim.x + threadIdx.x;  // global thread index
    int lidx = threadIdx.x;                            // local thread index
    int gi = gidx / R;            // global node index
	int li = lidx / R;            // local node index
    int j = gidx - gi * R;         // index of related values in previous layer for each value in y

	int pre_layer_len = N - R + 1; 
 
    float y_tmp = 0.0;
	// shared memory used to store local values in y
    __shared__ float local_y[BLKDIM];

    if(gi < pre_layer_len && j < R) {
        local_y[lidx] = x[gi + j] * W[gi * R + j];
        //printf("i:%d j:%d lidx: %d x:%.2f W:%.2f y:%.2f \n", \
		          gi, j, lidx, x[gi+j], W[gi * R + j], local_y[lidx]);
    }

    __syncthreads();
    //printf("\n");  
    
	// Accumulate R values of each node in y
    for (int p=0; p<R; p++) {
    	y_tmp += local_y[li * R + p];
    	//printf("i:%d j:%d lidx: %d local_y:%.2f tmp:%.2f \n", gi,j,lidx, local_y[li * R + p], y_tmp);
    }

    __syncthreads();
   
   	// Sigmoid
	y_tmp = Sigmoid(y_tmp, *b);

	// Copy temp values to y
    y[gi] = y_tmp;
}

/* Random values between -1 and 1 */
float random_init_small()
{
	return ((rand() % 2000) - 1000) / 1000.0;     // random Initialization to values in range [-1,1]
}

/* Initialize the W and b parameters for one layer */
void init_layer_parameters(float (*W)[R], float *b, int layer_len)
{
	for (int i=0; i<layer_len; i++) {
		for (int j=0; j<R; j++) {
			W[i][j] = random_init_small();
		}
	}

	*b = random_init_small();
}

/* Read in the network parameters (N, K) from command-line input. */
void parse_command_line_parameters(int argc, char *argv[], int *N, int *K)
{
	int c;
	while ((c = getopt (argc, argv, "n:k:")) != -1) {
		switch (c) {
			case 'n': // N
				*N = atoi(optarg);
				break;
			case 'k': // K
				*K = atoi(optarg);
				break;
		}
	}
}

int main( int argc, char *argv[] )
{
	srand(42);
	
    int N = 100;
    int K = 3;

    // get N, K from command line
    parse_command_line_parameters(argc, argv, &N, &K);
    printf("input size:%d, number of layers:%d.\n",  N, K);

    // Judge if the length of the k-th layer is bigger than 0
	int last_layer_len = N - (K-1) * (R-1);
    if (last_layer_len <= 0) {
	    printf("The parameters you input couldn't support k layers. \
			    Please give bigger size of layer 0 or use less layers.\n");
	    return EXIT_FAILURE;
    } 

    // initialize the values of the input layer
    float x[N];
    for (int i=0; i < N; i++) {
	    x[i] = random_init_small();
    }
    //TEST
    for (int i=0; i < N; i++) {
	    printf("%.2f ", x[i]);
    }
    printf("\n");

    // create an array to store the latest layer got calculated
    float latest_layer[N];
    memcpy(latest_layer, x, N * sizeof(float)); //the latest layer is the input layer at the beginning

    float *latest_layer_d;
    hipMalloc( (void**)&latest_layer_d, N * sizeof(float) );
    hipMemcpy( latest_layer_d, latest_layer, N * sizeof(float), hipMemcpyHostToDevice);

	// Start recording time costage
    clock_t start = clock();

    // Loop over K layers
    for(int k=1; k<K; k++) {
        // calculate lengthes of this layer and the previous layer
        int layer_len = N - k * (R-1);
		int in_layer_len = layer_len + R -1;

  		// initialize parameters
        float b;
        float W[layer_len][R];
        float y[layer_len];
     
        init_layer_parameters(W, &b, layer_len);
     
        float *b_d;
        float *W_d;
        float *y_d;
    
        hipMalloc( (void**)&b_d, sizeof(float) );
        hipMalloc( (void**)&W_d, layer_len * R * sizeof(float) );
        hipMalloc( (void**)&y_d, layer_len * sizeof(float) );

        hipMemcpy(b_d, &b, sizeof(float), hipMemcpyHostToDevice);
        hipMemcpy(W_d, W, layer_len * R * sizeof(float), hipMemcpyHostToDevice);
        hipMemcpy(y_d, y, layer_len * sizeof(float), hipMemcpyHostToDevice);

  		// calculation of each layer
        // printf("\nGRIDDIM %d BLKDIM: %d\n", (layer_len*R+BLKDIM-1)/BLKDIM, BLKDIM);
  		one_layer_calc<<<(layer_len*R+BLKDIM-1)/BLKDIM, BLKDIM>>>(latest_layer_d, W_d, b_d, y_d, in_layer_len);

        hipDeviceSynchronize();

        // copy result back to host
        hipMemcpy(y, y_d, layer_len * sizeof(float), hipMemcpyDeviceToHost);

		/*
		// Print the result of each layer
        printf("\nThe layer result got\n");
        for(int i=0; i<layer_len; i++) {
            printf("%.2f ", y[i]);
        }
        printf("\n");
		*/

  		// save the latest_layer result
  		memcpy(latest_layer, y, layer_len * sizeof(float));
        hipMemcpy(latest_layer_d, latest_layer, layer_len * sizeof(float), hipMemcpyHostToDevice);

        // Free cuda memory
        hipFree(W_d); hipFree(y_d); hipFree(b_d);
    }

    // calculate elapsed time
    clock_t end = clock();
    double time_elapsed = (double)(end - start) / CLOCKS_PER_SEC;
    printf("Time elapsed: %.3f\n", time_elapsed);

    hipFree(latest_layer_d);

    // print final result
    printf("\nFinal result is: ");
    for(int i=0; i<last_layer_len; i++) {
	    printf("%.3f ", latest_layer[i]);
    }
    printf("\n");

    return EXIT_SUCCESS;
}

	.text
	.file	"cuda_v1.hip"
	.globl	_Z29__device_stub__one_layer_calcPfS_S_S_i # -- Begin function _Z29__device_stub__one_layer_calcPfS_S_S_i
	.type	_Z29__device_stub__one_layer_calcPfS_S_S_i,@function
_Z29__device_stub__one_layer_calcPfS_S_S_i: # @_Z29__device_stub__one_layer_calcPfS_S_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z14one_layer_calcPfS_S_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z29__device_stub__one_layer_calcPfS_S_S_i, .Lfunc_end0-_Z29__device_stub__one_layer_calcPfS_S_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z17random_init_smallv
.LCPI1_0:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	_Z17random_init_smallv
	.type	_Z17random_init_smallv,@function
_Z17random_init_smallv:                 # @_Z17random_init_smallv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$39, %rcx
	addl	%edx, %ecx
	imull	$2000, %ecx, %ecx               # imm = 0x7D0
	negl	%ecx
	addl	%ecx, %eax
	addl	$-1000, %eax                    # imm = 0xFC18
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI1_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z17random_init_smallv, .Lfunc_end1-_Z17random_init_smallv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z21init_layer_parametersPA3_fPfi
.LCPI2_0:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	_Z21init_layer_parametersPA3_fPfi
	.type	_Z21init_layer_parametersPA3_fPfi,@function
_Z21init_layer_parametersPA3_fPfi:      # @_Z21init_layer_parametersPA3_fPfi
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	testl	%edx, %edx
	jle	.LBB2_5
# %bb.1:                                # %.preheader.preheader
	movq	%rdi, %r14
	movl	%edx, %r15d
	xorl	%r12d, %r12d
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
	xorl	%r13d, %r13d
.LBB2_3:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$39, %rcx
	addl	%edx, %ecx
	imull	$2000, %ecx, %ecx               # imm = 0x7D0
	negl	%ecx
	addl	%ecx, %eax
	addl	$-1000, %eax                    # imm = 0xFC18
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r13,4)
	incq	%r13
	cmpq	$3, %r13
	jne	.LBB2_3
# %bb.4:                                #   in Loop: Header=BB2_2 Depth=1
	incq	%r12
	addq	$12, %r14
	cmpq	%r15, %r12
	jne	.LBB2_2
.LBB2_5:                                # %._crit_edge
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$39, %rcx
	addl	%edx, %ecx
	imull	$2000, %ecx, %ecx               # imm = 0x7D0
	negl	%ecx
	addl	%ecx, %eax
	addl	$-1000, %eax                    # imm = 0xFC18
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI2_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rbx)
	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	_Z21init_layer_parametersPA3_fPfi, .Lfunc_end2-_Z21init_layer_parametersPA3_fPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z29parse_command_line_parametersiPPcPiS1_ # -- Begin function _Z29parse_command_line_parametersiPPcPiS1_
	.type	_Z29parse_command_line_parametersiPPcPiS1_,@function
_Z29parse_command_line_parametersiPPcPiS1_: # @_Z29parse_command_line_parametersiPPcPiS1_
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movq	%rdx, %r14
	movq	%rsi, %r15
	movl	%edi, %ebp
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str, %edx
	movl	%ebp, %edi
	movq	%r15, %rsi
	callq	getopt
	cmpl	$107, %eax
	je	.LBB3_5
# %bb.2:                                #   in Loop: Header=BB3_1 Depth=1
	movq	%r14, %r12
	cmpl	$110, %eax
	je	.LBB3_6
# %bb.3:                                #   in Loop: Header=BB3_1 Depth=1
	cmpl	$-1, %eax
	jne	.LBB3_1
	jmp	.LBB3_4
.LBB3_5:                                #   in Loop: Header=BB3_1 Depth=1
	movq	%rbx, %r12
.LBB3_6:                                # %.sink.split
                                        #   in Loop: Header=BB3_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	movl	%eax, (%r12)
	jmp	.LBB3_1
.LBB3_4:
	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_end3:
	.size	_Z29parse_command_line_parametersiPPcPiS1_, .Lfunc_end3-_Z29parse_command_line_parametersiPPcPiS1_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x408f400000000000              # double 1000
.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
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$120, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %rbx
	movl	%edi, %r14d
	movl	$42, %edi
	callq	srand
	leaq	-160(%rbp), %r15
	movl	$100, (%r15)
	leaq	-156(%rbp), %r12
	movl	$3, (%r12)
	movl	%r14d, %edi
	movq	%rbx, %rsi
	movq	%r15, %rdx
	movq	%r12, %rcx
	callq	_Z29parse_command_line_parametersiPPcPiS1_
	movl	(%r15), %r14d
	movl	(%r12), %ebx
	movl	$.L.str.1, %edi
	movl	%r14d, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	leal	(%rbx,%rbx), %eax
	negl	%eax
	addl	%r14d, %eax
	addl	$2, %eax
	testl	%eax, %eax
	jle	.LBB4_1
# %bb.2:
	movq	%r14, %r12
	movq	%rbx, -56(%rbp)                 # 8-byte Spill
	movl	%eax, -84(%rbp)                 # 4-byte Spill
	movq	%rsp, -120(%rbp)                # 8-byte Spill
	movslq	%r12d, %r13
	movq	%rsp, %r14
	leaq	15(,%r12,4), %rbx
	andq	$-16, %rbx
	subq	%rbx, %r14
	movq	%r14, %rsp
	testl	%r12d, %r12d
	jle	.LBB4_8
# %bb.3:                                # %.lr.ph.preheader
	xorl	%r15d, %r15d
.LBB4_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$39, %rcx
	addl	%edx, %ecx
	imull	$2000, %ecx, %ecx               # imm = 0x7D0
	negl	%ecx
	addl	%ecx, %eax
	addl	$-1000, %eax                    # imm = 0xFC18
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB4_4
# %bb.5:                                # %.preheader
	movq	%r12, %rsi
	testl	%esi, %esi
	jle	.LBB4_8
# %bb.6:                                # %.lr.ph48.preheader
	xorl	%r15d, %r15d
.LBB4_7:                                # %.lr.ph48
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	movq	%r12, %rax
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB4_7
.LBB4_8:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	movq	%rsp, %r15
	subq	%rbx, %r15
	movq	%r15, %rsp
	leaq	(,%r13,4), %rbx
	movq	%r15, %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	callq	memcpy@PLT
	leaq	-80(%rbp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%r15, -104(%rbp)                # 8-byte Spill
	movq	%r15, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, -112(%rbp)                # 8-byte Spill
	movq	-56(%rbp), %rcx                 # 8-byte Reload
	cmpl	$2, %ecx
	jl	.LBB4_13
# %bb.9:                                # %.lr.ph51.preheader
	movq	%r12, %r8
	movq	%r13, %rdi
	movabsq	$4294967296, %rsi               # imm = 0x100000000
	leal	(%r12,%r12,2), %r15d
	addl	$182, %r15d
	leaq	(,%r13,2), %rax
	addq	%r13, %rax
	leaq	-24(,%rax,4), %r13
	leaq	-8(,%rdi,4), %r12
	addq	$-2, %rdi
	decq	%rcx
	leaq	189(%rsi), %rax
	movq	%rax, -128(%rbp)                # 8-byte Spill
.LBB4_10:                               # %.lr.ph51
                                        # =>This Inner Loop Header: Depth=1
	movq	%r8, -136(%rbp)                 # 8-byte Spill
	movq	%rdi, -144(%rbp)                # 8-byte Spill
	movq	%rcx, -56(%rbp)                 # 8-byte Spill
	movq	%rsp, -152(%rbp)                # 8-byte Spill
	leal	-2(%r8), %edx
	movl	%edi, %eax
	movq	%rsp, %rbx
	leaq	(%rax,%rax,2), %rcx
	leaq	15(,%rcx,4), %rcx
	andq	$-16, %rcx
	subq	%rcx, %rbx
	movq	%rbx, %rsp
	movq	%rsp, %r14
	leaq	15(,%rax,4), %rax
	andq	$-16, %rax
	subq	%rax, %r14
	movq	%r14, %rsp
	movq	%rbx, %rdi
	leaq	-92(%rbp), %rsi
	movl	%edx, -88(%rbp)                 # 4-byte Spill
	callq	_Z21init_layer_parametersPA3_fPfi
	movl	$4, %esi
	leaq	-72(%rbp), %rdi
	callq	hipMalloc
	leaq	-64(%rbp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	-48(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	-72(%rbp), %rdi
	movl	$4, %edx
	leaq	-92(%rbp), %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	-64(%rbp), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	-48(%rbp), %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	%r15d, %rax
	imulq	$-1386206375, %rax, %rdi        # imm = 0xAD602B59
	shrq	$32, %rdi
	addl	%r15d, %edi
	movl	%edi, %eax
	shrl	$31, %eax
	sarl	$7, %edi
	addl	%eax, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	movl	$1, %esi
	movq	-128(%rbp), %rdx                # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_12
# %bb.11:                               #   in Loop: Header=BB4_10 Depth=1
	movq	-80(%rbp), %rdi
	movq	-64(%rbp), %rsi
	movq	-72(%rbp), %rdx
	movq	-48(%rbp), %rcx
	movq	-136(%rbp), %r8                 # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	callq	_Z29__device_stub__one_layer_calcPfS_S_S_i
.LBB4_12:                               #   in Loop: Header=BB4_10 Depth=1
	callq	hipDeviceSynchronize
	movq	-48(%rbp), %rsi
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	-104(%rbp), %rbx                # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	callq	memcpy@PLT
	movq	-80(%rbp), %rdi
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	-64(%rbp), %rdi
	callq	hipFree
	movq	-48(%rbp), %rdi
	callq	hipFree
	movq	-72(%rbp), %rdi
	callq	hipFree
	movq	-152(%rbp), %rsp                # 8-byte Reload
	addl	$-6, %r15d
	addq	$-24, %r13
	movq	-144(%rbp), %rdx                # 8-byte Reload
	addq	$-2, %rdx
	addq	$-8, %r12
	movl	-88(%rbp), %eax                 # 4-byte Reload
	movl	%eax, %r8d
	movq	-56(%rbp), %rcx                 # 8-byte Reload
	decq	%rcx
	movq	%rdx, %rdi
	jne	.LBB4_10
.LBB4_13:                               # %.lr.ph55.preheader
	callq	clock
	subq	-112(%rbp), %rax                # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI4_1(%rip), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movq	-80(%rbp), %rdi
	callq	hipFree
	xorl	%ebx, %ebx
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	-84(%rbp), %eax                 # 4-byte Reload
	cmpl	$2, %eax
	movl	$1, %r15d
	cmovgel	%eax, %r15d
	movq	-104(%rbp), %r14                # 8-byte Reload
.LBB4_14:                               # %.lr.ph55
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rbx,4), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%rbx
	cmpq	%rbx, %r15
	jne	.LBB4_14
# %bb.15:                               # %._crit_edge56
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%eax, %eax
	movq	-120(%rbp), %rsp                # 8-byte Reload
	jmp	.LBB4_16
.LBB4_1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %eax
.LBB4_16:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14one_layer_calcPfS_S_S_i, %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_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	_Z14one_layer_calcPfS_S_S_i,@object # @_Z14one_layer_calcPfS_S_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z14one_layer_calcPfS_S_S_i
	.p2align	3, 0x0
_Z14one_layer_calcPfS_S_S_i:
	.quad	_Z29__device_stub__one_layer_calcPfS_S_S_i
	.size	_Z14one_layer_calcPfS_S_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"n:k:"
	.size	.L.str, 5

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"input size:%d, number of layers:%d.\n"
	.size	.L.str.1, 37

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%.2f "
	.size	.L.str.3, 6

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Time elapsed: %.3f\n"
	.size	.L.str.5, 20

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\nFinal result is: "
	.size	.L.str.6, 19

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%.3f "
	.size	.L.str.7, 6

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

	.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	"The parameters you input couldn't support k layers. \t\t\t    Please give bigger size of layer 0 or use less layers."
	.size	.Lstr, 114

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z29__device_stub__one_layer_calcPfS_S_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14one_layer_calcPfS_S_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14one_layer_calcPfS_S_S_i ; -- Begin function _Z14one_layer_calcPfS_S_S_i
	.globl	_Z14one_layer_calcPfS_S_S_i
	.p2align	8
	.type	_Z14one_layer_calcPfS_S_S_i,@function
_Z14one_layer_calcPfS_S_S_i:            ; @_Z14one_layer_calcPfS_S_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b256 s[4:11], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s2, v[0:1]
	s_load_b32 s2, s[0:1], 0x20
	v_mul_hi_i32 v1, 0x55555556, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v3, 31, v1
	v_add_nc_u32_e32 v1, v1, v3
	s_waitcnt lgkmcnt(0)
	s_add_i32 s2, s2, -2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[3:4], null, v1, -3, v[2:3]
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	v_cmp_gt_i32_e64 s0, 3, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s1, vcc_lo, s0
	s_and_saveexec_b32 s0, s1
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_add_nc_u32_e32 v4, v3, v1
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	v_add_co_u32 v4, vcc_lo, s4, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	v_add_co_u32 v2, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v4, v[4:5], off
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	v_dual_mul_f32 v2, v4, v2 :: v_dual_lshlrev_b32 v3, 2, v0
	ds_store_b32 v3, v2
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s0
	v_mul_u32_u24_e32 v2, 0x5556, v0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_lshrrev_b32_e32 v2, 16, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u16 v2, v2, 3
	v_sub_nc_u16 v2, v0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v2, 0xffff, v2
	v_sub_nc_u32_e32 v0, v0, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b32_e32 v0, 2, v0
	ds_load_2addr_b32 v[2:3], v0 offset1:1
	ds_load_b32 v0, v0 offset:8
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_load_b32 s0, s[8:9], 0x0
	v_add_f32_e32 v2, 0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v2, v2, v3
	v_add_f32_e32 v0, v2, v0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_f32_e64 v0, -v0, s0
	v_mul_f32_e32 v2, 0x3fb8aa3b, v0
	v_cmp_ngt_f32_e32 vcc_lo, 0xc2ce8ed0, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fma_f32 v3, 0x3fb8aa3b, v0, -v2
	v_rndne_f32_e32 v4, v2
	v_dual_fmamk_f32 v3, v0, 0x32a5705f, v3 :: v_dual_sub_f32 v2, v2, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_f32_e32 v2, v2, v3
	v_cvt_i32_f32_e32 v3, v4
	v_exp_f32_e32 v2, v2
	s_waitcnt_depctr 0xfff
	v_ldexp_f32 v2, v2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v2, 0, v2, vcc_lo
	v_cmp_nlt_f32_e32 vcc_lo, 0x42b17218, v0
	v_cndmask_b32_e32 v0, 0x7f800000, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v3, 1.0, v0
	v_div_scale_f32 v0, null, v3, v3, 1.0
	v_div_scale_f32 v5, vcc_lo, 1.0, v3, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v4, v0
	s_waitcnt_depctr 0xfff
	v_fma_f32 v2, -v0, v4, 1.0
	v_fmac_f32_e32 v4, v2, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v6, v5, v4
	v_fma_f32 v2, -v0, v6, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v6, v2, v4
	v_ashrrev_i32_e32 v2, 31, v1
	v_fma_f32 v0, -v0, v6, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v4, v0, v4, v6
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v2, v4, v3, 1.0
	v_add_co_u32 v0, vcc_lo, s10, v0
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14one_layer_calcPfS_S_S_i
		.amdhsa_group_segment_fixed_size 756
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 7
		.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	_Z14one_layer_calcPfS_S_S_i, .Lfunc_end0-_Z14one_layer_calcPfS_S_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 624
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 756 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 756
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14one_layer_calcPfS_S_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14one_layer_calcPfS_S_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
