/*
 * Copyright 1993-2010 NVIDIA Corporation.  All rights reserved.
 *
 * Please refer to the NVIDIA end user license agreement (EULA) associated
 * with this source code for terms and conditions that govern your use of
 * this software. Any use, reproduction, disclosure, or distribution of
 * this software and related documentation outside the terms of the EULA
 * is strictly prohibited.
 *
 */

/* Vector addition: C = A + B.
 *
 * This sample is a very basic sample that implements element by element
 * vector addition. It is the same as the sample illustrating Chapter 3
 * of the programming guide with some additions like error checking.
 *
 */

// Includes
#include <stdio.h>
#include <stdlib.h>


// includes CUDA
#include <cuda_runtime.h>

#define THREADS_PER_BLOCK 256
#define FIRST_PHASE_TIME 0xF//0xFFF
#define SECOND_PHASE_TIME 0xF//0xFFF

// Variables
float* h_A;
float* h_B;
float* h_C;
float* d_A;
float* d_B;
float* d_C;
bool noprompt = false;

// Functions
void CleanupResources(void);
void RandomInit(float*, int);
void ParseArguments(int, char**);

////////////////////////////////////////////////////////////////////////////////
// These are CUDA Helper functions

// This will output the proper CUDA error strings in the event that a CUDA host call returns an error
#define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)

inline void __checkCudaErrors(cudaError err, const char *file, const int line )
{
    if(cudaSuccess != err)
    {
        fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n",file, line, (int)err, cudaGetErrorString( err ) );
        exit(-1);        
    }
}

// This will output the proper error string when calling cudaGetLastError
#define getLastCudaError(msg)      __getLastCudaError (msg, __FILE__, __LINE__)

inline void __getLastCudaError(const char *errorMessage, const char *file, const int line )
{
    cudaError_t err = cudaGetLastError();
    if (cudaSuccess != err)
    {
        fprintf(stderr, "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n",
        file, line, errorMessage, (int)err, cudaGetErrorString( err ) );
        exit(-1);
    }
}

// end of CUDA Helper Functions


// Device code
__global__ void VecAdd(const float* A, const float* B, float* C, int N)
{
    int i = blockDim.x * blockIdx.x + threadIdx.x;
		int thread_id = threadIdx.x;
    int k = thread_id;
		__shared__ long counter[THREADS_PER_BLOCK];
		__shared__ double result[THREADS_PER_BLOCK];

		counter[k] = 0;
		result[k] = k;

		__syncthreads();

		while (counter[0] < FIRST_PHASE_TIME) {
			counter[k] ++;
			result[k] *= result[k];
		}
		__syncthreads();

		counter[k] = 0;

		__syncthreads();

		if (thread_id < 32) {
			while (counter[0] < SECOND_PHASE_TIME) {
				counter[k] ++;
				result[k] *= result[k];
			}
		}

		__syncthreads();

		//for(k=0;k<100;k++){
			//if (i < N)
       // C[i] = A[i] + B[i];
		//}
}

// Host code
int main(int argc, char** argv)
{

    printf("Vector Addition\n");
    int N = 8192;
    size_t size = N * sizeof(float);
    //ParseArguments(argc, argv);

    // Allocate input vectors h_A and h_B in host memory
    h_A = (float*)malloc(size);
    if (h_A == 0) CleanupResources();
    h_B = (float*)malloc(size);
    if (h_B == 0) CleanupResources();
    h_C = (float*)malloc(size);
    if (h_C == 0) CleanupResources();
    
    // Initialize input vectors
    RandomInit(h_A, N);
    RandomInit(h_B, N);

    // Allocate vectors in device memory
    checkCudaErrors( cudaMalloc((void**)&d_A, size) );
    checkCudaErrors( cudaMalloc((void**)&d_B, size) );
    checkCudaErrors( cudaMalloc((void**)&d_C, size) );

    // Copy vectors from host memory to device memory
    checkCudaErrors( cudaMemcpy(d_A, h_A, size, cudaMemcpyHostToDevice) );
    checkCudaErrors( cudaMemcpy(d_B, h_B, size, cudaMemcpyHostToDevice) );

    // Invoke kernel
    int threadsPerBlock = THREADS_PER_BLOCK;
    //int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
    int blocksPerGrid = 30;
    VecAdd<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
    getLastCudaError("kernel launch failure");
#ifdef _DEBUG
    checkCudaErrors( cudaDeviceSynchronize() );
#endif

    // Copy result from device memory to host memory
    // h_C contains the result in host memory
    checkCudaErrors( cudaMemcpy(h_C, d_C, size, cudaMemcpyDeviceToHost) );
    
    // Verify result
    int i;
    /*for (i = 0; i < N; ++i) {
        float sum = h_A[i] + h_B[i];
        if (fabs(h_C[i] - sum) > 1e-5)
            break;
    }*/

    CleanupResources();
}

void CleanupResources(void)
{
    // Free device memory
    if (d_A)
        cudaFree(d_A);
    if (d_B)
        cudaFree(d_B);
    if (d_C)
        cudaFree(d_C);

    // Free host memory
    if (h_A)
        free(h_A);
    if (h_B)
        free(h_B);
    if (h_C)
        free(h_C);
        
}

// Allocates an array with random float entries.
void RandomInit(float* data, int n)
{
    for (int i = 0; i < n; ++i)
        data[i] = rand() / (float)RAND_MAX;
}

// Parse program arguments
void ParseArguments(int argc, char** argv)
{
    for (int i = 0; i < argc; ++i) {
        if (strcmp(argv[i], "--noprompt") == 0 ||
            strcmp(argv[i], "-noprompt") == 0) 
        {
            noprompt = true;
            break;
        }
    }
}

	.file	"tmpxft_0033a337_00000000-6_PP_FP_MEM.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z17__checkCudaErrors9cudaErrorPKci.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s(%i) : CUDA Runtime API error %d: %s.\n"
	.section	.text._Z17__checkCudaErrors9cudaErrorPKci,"axG",@progbits,_Z17__checkCudaErrors9cudaErrorPKci,comdat
	.weak	_Z17__checkCudaErrors9cudaErrorPKci
	.type	_Z17__checkCudaErrors9cudaErrorPKci, @function
_Z17__checkCudaErrors9cudaErrorPKci:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	movl	%edx, 12(%rsp)
	movl	%edi, 8(%rsp)
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	movl	$2, %esi
	pushq	%rdx
	.cfi_def_cfa_offset 40
	leaq	.LC0(%rip), %rdx
	pushq	%rax
	.cfi_def_cfa_offset 48
	movl	24(%rsp), %r9d
	xorl	%eax, %eax
	movl	28(%rsp), %r8d
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z17__checkCudaErrors9cudaErrorPKci, .-_Z17__checkCudaErrors9cudaErrorPKci
	.text
	.globl	_Z16CleanupResourcesv
	.type	_Z16CleanupResourcesv, @function
_Z16CleanupResourcesv:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rcx
	.cfi_def_cfa_offset 16
	movq	d_A(%rip), %rdi
	testq	%rdi, %rdi
	je	.L9
	call	cudaFree@PLT
.L9:
	movq	d_B(%rip), %rdi
	testq	%rdi, %rdi
	je	.L10
	call	cudaFree@PLT
.L10:
	movq	d_C(%rip), %rdi
	testq	%rdi, %rdi
	je	.L11
	call	cudaFree@PLT
.L11:
	movq	h_A(%rip), %rdi
	testq	%rdi, %rdi
	je	.L12
	call	free@PLT
.L12:
	movq	h_B(%rip), %rdi
	testq	%rdi, %rdi
	je	.L13
	call	free@PLT
.L13:
	movq	h_C(%rip), %rdi
	testq	%rdi, %rdi
	je	.L8
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	free@PLT
.L8:
	.cfi_restore_state
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z16CleanupResourcesv, .-_Z16CleanupResourcesv
	.globl	_Z10RandomInitPfi
	.type	_Z10RandomInitPfi, @function
_Z10RandomInitPfi:
.LFB2031:
	.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
.L32:
	cmpl	%ebx, %ebp
	jle	.L35
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC1(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L32
.L35:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z10RandomInitPfi, .-_Z10RandomInitPfi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"--noprompt"
.LC3:
	.string	"-noprompt"
	.text
	.globl	_Z14ParseArgumentsiPPc
	.type	_Z14ParseArgumentsiPPc, @function
_Z14ParseArgumentsiPPc:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC3(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC2(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 64
.L37:
	cmpl	%ebx, %ebp
	jle	.L36
	movq	(%r12,%rbx,8), %r13
	movq	%r14, %rsi
	movq	%r13, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L38
	movq	%r15, %rsi
	movq	%r13, %rdi
	incq	%rbx
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L37
.L38:
	movb	$1, noprompt(%rip)
.L36:
	popq	%rax
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z14ParseArgumentsiPPc, .-_Z14ParseArgumentsiPPc
	.globl	_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi
	.type	_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi, @function
_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6VecAddPKfS0_Pfi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L46:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi, .-_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi
	.globl	_Z6VecAddPKfS0_Pfi
	.type	_Z6VecAddPKfS0_Pfi, @function
_Z6VecAddPKfS0_Pfi:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi
	.cfi_endproc
.LFE2058:
	.size	_Z6VecAddPKfS0_Pfi, .-_Z6VecAddPKfS0_Pfi
	.section	.rodata.str1.1
.LC4:
	.string	"Vector Addition\n"
.LC5:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/speverel/gpgpu-sim_simulations/master/benchmarks/src/cuda/gpuwattch-ubench/mix_benchmarks/PP_FP_MEM/PP_FP_MEM.cu"
.LC6:
	.string	"kernel launch failure"
.LC7:
	.string	"%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	call	__printf_chk@PLT
	movl	$32768, %edi
	call	malloc@PLT
	movq	%rax, h_A(%rip)
	testq	%rax, %rax
	jne	.L52
	call	_Z16CleanupResourcesv
.L52:
	movl	$32768, %edi
	call	malloc@PLT
	movq	%rax, h_B(%rip)
	testq	%rax, %rax
	jne	.L53
	call	_Z16CleanupResourcesv
.L53:
	movl	$32768, %edi
	call	malloc@PLT
	movq	%rax, h_C(%rip)
	testq	%rax, %rax
	jne	.L54
	call	_Z16CleanupResourcesv
.L54:
	movq	h_A(%rip), %rdi
	movl	$8192, %esi
	leaq	.LC5(%rip), %rbx
	call	_Z10RandomInitPfi
	movq	h_B(%rip), %rdi
	movl	$8192, %esi
	call	_Z10RandomInitPfi
	movl	$32768, %esi
	leaq	d_A(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$139, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z17__checkCudaErrors9cudaErrorPKci
	movl	$32768, %esi
	leaq	d_B(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$140, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z17__checkCudaErrors9cudaErrorPKci
	movl	$32768, %esi
	leaq	d_C(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$141, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z17__checkCudaErrors9cudaErrorPKci
	movl	$1, %ecx
	movl	$32768, %edx
	movq	h_A(%rip), %rsi
	movq	d_A(%rip), %rdi
	call	cudaMemcpy@PLT
	movl	$144, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z17__checkCudaErrors9cudaErrorPKci
	movl	$1, %ecx
	movl	$32768, %edx
	movq	h_B(%rip), %rsi
	movq	d_B(%rip), %rdi
	call	cudaMemcpy@PLT
	movl	$145, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z17__checkCudaErrors9cudaErrorPKci
	movl	$16777217, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$2147483663, %edi
	salq	$8, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	addq	%rdi, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L55
	movq	d_C(%rip), %rdx
	movq	d_B(%rip), %rsi
	movl	$8192, %ecx
	movq	d_A(%rip), %rdi
	call	_Z32__device_stub__Z6VecAddPKfS0_PfiPKfS0_Pfi
.L55:
	call	cudaGetLastError@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L56
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	movl	$2, %esi
	pushq	%rax
	.cfi_remember_state
	.cfi_def_cfa_offset 72
	leaq	.LC6(%rip), %r9
	movl	$152, %r8d
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 80
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L56:
	.cfi_restore_state
	movq	d_C(%rip), %rsi
	movl	$2, %ecx
	movl	$32768, %edx
	movq	h_C(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	%rbx, %rsi
	movl	$159, %edx
	movl	%eax, %edi
	call	_Z17__checkCudaErrors9cudaErrorPKci
	call	_Z16CleanupResourcesv
	addq	$40, %rsp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC8:
	.string	"_Z6VecAddPKfS0_Pfi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC8(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6VecAddPKfS0_Pfi(%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
.LFE2060:
	.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	noprompt
	.bss
	.type	noprompt, @object
	.size	noprompt, 1
noprompt:
	.zero	1
	.globl	d_C
	.align 8
	.type	d_C, @object
	.size	d_C, 8
d_C:
	.zero	8
	.globl	d_B
	.align 8
	.type	d_B, @object
	.size	d_B, 8
d_B:
	.zero	8
	.globl	d_A
	.align 8
	.type	d_A, @object
	.size	d_A, 8
d_A:
	.zero	8
	.globl	h_C
	.align 8
	.type	h_C, @object
	.size	h_C, 8
h_C:
	.zero	8
	.globl	h_B
	.align 8
	.type	h_B, @object
	.size	h_B, 8
h_B:
	.zero	8
	.globl	h_A
	.align 8
	.type	h_A, @object
	.size	h_A, 8
h_A:
	.zero	8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	805306368
	.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:

/*
 * Copyright 1993-2010 NVIDIA Corporation.  All rights reserved.
 *
 * Please refer to the NVIDIA end user license agreement (EULA) associated
 * with this source code for terms and conditions that govern your use of
 * this software. Any use, reproduction, disclosure, or distribution of
 * this software and related documentation outside the terms of the EULA
 * is strictly prohibited.
 *
 */

/* Vector addition: C = A + B.
 *
 * This sample is a very basic sample that implements element by element
 * vector addition. It is the same as the sample illustrating Chapter 3
 * of the programming guide with some additions like error checking.
 *
 */

// Includes
#include <stdio.h>
#include <stdlib.h>


// includes CUDA
#include <hip/hip_runtime.h>

#define THREADS_PER_BLOCK 256
#define FIRST_PHASE_TIME 0xF//0xFFF
#define SECOND_PHASE_TIME 0xF//0xFFF

// Variables
float* h_A;
float* h_B;
float* h_C;
float* d_A;
float* d_B;
float* d_C;
bool noprompt = false;

// Functions
void CleanupResources(void);
void RandomInit(float*, int);
void ParseArguments(int, char**);

////////////////////////////////////////////////////////////////////////////////
// These are CUDA Helper functions

// This will output the proper CUDA error strings in the event that a CUDA host call returns an error
#define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)

inline void __checkCudaErrors(hipError_t err, const char *file, const int line )
{
    if(hipSuccess != err)
    {
        fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n",file, line, (int)err, hipGetErrorString( err ) );
        exit(-1);        
    }
}

// This will output the proper error string when calling cudaGetLastError
#define getLastCudaError(msg)      __getLastCudaError (msg, __FILE__, __LINE__)

inline void __getLastCudaError(const char *errorMessage, const char *file, const int line )
{
    hipError_t err = hipGetLastError();
    if (hipSuccess != err)
    {
        fprintf(stderr, "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n",
        file, line, errorMessage, (int)err, hipGetErrorString( err ) );
        exit(-1);
    }
}

// end of CUDA Helper Functions


// Device code
__global__ void VecAdd(const float* A, const float* B, float* C, int N)
{
    int i = blockDim.x * blockIdx.x + threadIdx.x;
		int thread_id = threadIdx.x;
    int k = thread_id;
		__shared__ long counter[THREADS_PER_BLOCK];
		__shared__ double result[THREADS_PER_BLOCK];

		counter[k] = 0;
		result[k] = k;

		__syncthreads();

		while (counter[0] < FIRST_PHASE_TIME) {
			counter[k] ++;
			result[k] *= result[k];
		}
		__syncthreads();

		counter[k] = 0;

		__syncthreads();

		if (thread_id < 32) {
			while (counter[0] < SECOND_PHASE_TIME) {
				counter[k] ++;
				result[k] *= result[k];
			}
		}

		__syncthreads();

		//for(k=0;k<100;k++){
			//if (i < N)
       // C[i] = A[i] + B[i];
		//}
}

// Host code
int main(int argc, char** argv)
{

    printf("Vector Addition\n");
    int N = 8192;
    size_t size = N * sizeof(float);
    //ParseArguments(argc, argv);

    // Allocate input vectors h_A and h_B in host memory
    h_A = (float*)malloc(size);
    if (h_A == 0) CleanupResources();
    h_B = (float*)malloc(size);
    if (h_B == 0) CleanupResources();
    h_C = (float*)malloc(size);
    if (h_C == 0) CleanupResources();
    
    // Initialize input vectors
    RandomInit(h_A, N);
    RandomInit(h_B, N);

    // Allocate vectors in device memory
    checkCudaErrors( hipMalloc((void**)&d_A, size) );
    checkCudaErrors( hipMalloc((void**)&d_B, size) );
    checkCudaErrors( hipMalloc((void**)&d_C, size) );

    // Copy vectors from host memory to device memory
    checkCudaErrors( hipMemcpy(d_A, h_A, size, hipMemcpyHostToDevice) );
    checkCudaErrors( hipMemcpy(d_B, h_B, size, hipMemcpyHostToDevice) );

    // Invoke kernel
    int threadsPerBlock = THREADS_PER_BLOCK;
    //int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
    int blocksPerGrid = 30;
    VecAdd<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N);
    getLastCudaError("kernel launch failure");
#ifdef _DEBUG
    checkCudaErrors( hipDeviceSynchronize() );
#endif

    // Copy result from device memory to host memory
    // h_C contains the result in host memory
    checkCudaErrors( hipMemcpy(h_C, d_C, size, hipMemcpyDeviceToHost) );
    
    // Verify result
    int i;
    /*for (i = 0; i < N; ++i) {
        float sum = h_A[i] + h_B[i];
        if (fabs(h_C[i] - sum) > 1e-5)
            break;
    }*/

    CleanupResources();
}

void CleanupResources(void)
{
    // Free device memory
    if (d_A)
        hipFree(d_A);
    if (d_B)
        hipFree(d_B);
    if (d_C)
        hipFree(d_C);

    // Free host memory
    if (h_A)
        free(h_A);
    if (h_B)
        free(h_B);
    if (h_C)
        free(h_C);
        
}

// Allocates an array with random float entries.
void RandomInit(float* data, int n)
{
    for (int i = 0; i < n; ++i)
        data[i] = rand() / (float)RAND_MAX;
}

// Parse program arguments
void ParseArguments(int argc, char** argv)
{
    for (int i = 0; i < argc; ++i) {
        if (strcmp(argv[i], "--noprompt") == 0 ||
            strcmp(argv[i], "-noprompt") == 0) 
        {
            noprompt = true;
            break;
        }
    }
}

	.text
	.file	"PP_FP_MEM.hip"
	.globl	_Z21__device_stub__VecAddPKfS0_Pfi # -- Begin function _Z21__device_stub__VecAddPKfS0_Pfi
	.type	_Z21__device_stub__VecAddPKfS0_Pfi,@function
_Z21__device_stub__VecAddPKfS0_Pfi:     # @_Z21__device_stub__VecAddPKfS0_Pfi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6VecAddPKfS0_Pfi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21__device_stub__VecAddPKfS0_Pfi, .Lfunc_end0-_Z21__device_stub__VecAddPKfS0_Pfi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$32768, %edi                    # imm = 0x8000
	callq	malloc
	movq	%rax, h_A(%rip)
	testq	%rax, %rax
	jne	.LBB1_2
# %bb.1:
	callq	_Z16CleanupResourcesv
.LBB1_2:
	movl	$32768, %edi                    # imm = 0x8000
	callq	malloc
	movq	%rax, h_B(%rip)
	testq	%rax, %rax
	jne	.LBB1_4
# %bb.3:
	callq	_Z16CleanupResourcesv
.LBB1_4:
	movl	$32768, %edi                    # imm = 0x8000
	callq	malloc
	movq	%rax, h_C(%rip)
	testq	%rax, %rax
	jne	.LBB1_6
# %bb.5:
	callq	_Z16CleanupResourcesv
.LBB1_6:
	movq	h_A(%rip), %rbx
	xorl	%r14d, %r14d
.LBB1_7:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movss	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%rbx,%r14,4)
	incq	%r14
	cmpq	$8192, %r14                     # imm = 0x2000
	jne	.LBB1_7
# %bb.8:                                # %_Z10RandomInitPfi.exit
	movq	h_B(%rip), %rbx
	xorl	%r14d, %r14d
.LBB1_9:                                # %.lr.ph.i18
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r14,4)
	incq	%r14
	cmpq	$8192, %r14                     # imm = 0x2000
	jne	.LBB1_9
# %bb.10:                               # %_Z10RandomInitPfi.exit22
	movl	$d_A, %edi
	movl	$32768, %esi                    # imm = 0x8000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_20
# %bb.11:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit
	movl	$d_B, %edi
	movl	$32768, %esi                    # imm = 0x8000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_21
# %bb.12:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit24
	movl	$d_C, %edi
	movl	$32768, %esi                    # imm = 0x8000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_22
# %bb.13:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit26
	movq	d_A(%rip), %rdi
	movq	h_A(%rip), %rsi
	movl	$32768, %edx                    # imm = 0x8000
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_23
# %bb.14:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit28
	movq	d_B(%rip), %rdi
	movq	h_B(%rip), %rsi
	movl	$32768, %edx                    # imm = 0x8000
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_24
# %bb.15:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit30
	movabsq	$4294967326, %rdi               # imm = 0x10000001E
	leaq	226(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_17
# %bb.16:
	movq	d_A(%rip), %rdi
	movq	d_B(%rip), %rsi
	movq	d_C(%rip), %rdx
	movl	$8192, %ecx                     # imm = 0x2000
	callq	_Z21__device_stub__VecAddPKfS0_Pfi
.LBB1_17:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_25
# %bb.18:                               # %_Z18__getLastCudaErrorPKcS0_i.exit
	movq	h_C(%rip), %rdi
	movq	d_C(%rip), %rsi
	movl	$32768, %edx                    # imm = 0x8000
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_26
# %bb.19:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit33
	callq	_Z16CleanupResourcesv
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB1_20:
	.cfi_def_cfa_offset 32
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str.1, %edx
	movq	%r14, %rdi
	movl	$139, %ecx
	jmp	.LBB1_27
.LBB1_21:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str.1, %edx
	movq	%r14, %rdi
	movl	$140, %ecx
	jmp	.LBB1_27
.LBB1_22:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str.1, %edx
	movq	%r14, %rdi
	movl	$141, %ecx
	jmp	.LBB1_27
.LBB1_23:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str.1, %edx
	movq	%r14, %rdi
	movl	$144, %ecx
	jmp	.LBB1_27
.LBB1_24:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str.1, %edx
	movq	%r14, %rdi
	movl	$145, %ecx
	jmp	.LBB1_27
.LBB1_25:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movq	%rax, (%rsp)
	movl	$.L.str.6, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.2, %r8d
	movq	%r14, %rdi
	movl	$152, %ecx
	movl	%ebx, %r9d
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_28
.LBB1_26:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movl	$.L.str.1, %edx
	movq	%r14, %rdi
	movl	$159, %ecx
.LBB1_27:
	movl	%ebx, %r8d
	movq	%rax, %r9
	xorl	%eax, %eax
	callq	fprintf
.LBB1_28:
	movl	$-1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z16CleanupResourcesv           # -- Begin function _Z16CleanupResourcesv
	.type	_Z16CleanupResourcesv,@function
_Z16CleanupResourcesv:                  # @_Z16CleanupResourcesv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	d_A(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB2_2
# %bb.1:
	callq	hipFree
.LBB2_2:
	movq	d_B(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB2_4
# %bb.3:
	callq	hipFree
.LBB2_4:
	movq	d_C(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB2_6
# %bb.5:
	callq	hipFree
.LBB2_6:
	movq	h_A(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB2_8
# %bb.7:
	callq	free
.LBB2_8:
	movq	h_B(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB2_10
# %bb.9:
	callq	free
.LBB2_10:
	movq	h_C(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB2_11
# %bb.12:
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.LBB2_11:
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z16CleanupResourcesv, .Lfunc_end2-_Z16CleanupResourcesv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z10RandomInitPfi
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z10RandomInitPfi
	.type	_Z10RandomInitPfi,@function
_Z10RandomInitPfi:                      # @_Z10RandomInitPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB3_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
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB3_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
.LBB3_4:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z10RandomInitPfi, .Lfunc_end3-_Z10RandomInitPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z14ParseArgumentsiPPc          # -- Begin function _Z14ParseArgumentsiPPc
	.type	_Z14ParseArgumentsiPPc,@function
_Z14ParseArgumentsiPPc:                 # @_Z14ParseArgumentsiPPc
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jle	.LBB4_7
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movl	%edi, %r15d
	xorl	%r12d, %r12d
.LBB4_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r12,8), %r14
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB4_5
# %bb.4:                                #   in Loop: Header=BB4_3 Depth=1
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB4_5
# %bb.2:                                #   in Loop: Header=BB4_3 Depth=1
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB4_3
	jmp	.LBB4_6
.LBB4_5:
	movb	$1, noprompt(%rip)
.LBB4_6:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_7:                                # %.loopexit
	retq
.Lfunc_end4:
	.size	_Z14ParseArgumentsiPPc, .Lfunc_end4-_Z14ParseArgumentsiPPc
	.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	$_Z6VecAddPKfS0_Pfi, %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	h_A,@object                     # @h_A
	.bss
	.globl	h_A
	.p2align	3, 0x0
h_A:
	.quad	0
	.size	h_A, 8

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

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

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

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

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

	.type	noprompt,@object                # @noprompt
	.globl	noprompt
noprompt:
	.byte	0                               # 0x0
	.size	noprompt, 1

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

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/speverel/gpgpu-sim_simulations/master/benchmarks/src/cuda/gpuwattch-ubench/mix_benchmarks/PP_FP_MEM/PP_FP_MEM.hip"
	.size	.L.str.1, 176

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"kernel launch failure"
	.size	.L.str.2, 22

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%s(%i) : CUDA Runtime API error %d: %s.\n"
	.size	.L.str.5, 41

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n"
	.size	.L.str.6, 56

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6VecAddPKfS0_Pfi"
	.size	.L__unnamed_1, 19

	.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	"Vector Addition"
	.size	.Lstr, 16

	.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 _Z21__device_stub__VecAddPKfS0_Pfi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_A
	.addrsig_sym d_B
	.addrsig_sym d_C
	.addrsig_sym _Z6VecAddPKfS0_Pfi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6VecAddPKfS0_Pfi      ; -- Begin function _Z6VecAddPKfS0_Pfi
	.globl	_Z6VecAddPKfS0_Pfi
	.p2align	8
	.type	_Z6VecAddPKfS0_Pfi,@function
_Z6VecAddPKfS0_Pfi:                     ; @_Z6VecAddPKfS0_Pfi
; %bb.0:
	v_cvt_f64_i32_e32 v[3:4], v0
	v_lshlrev_b32_e32 v7, 3, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v1, 0 :: v_dual_add_nc_u32 v8, 0x800, v7
	v_mov_b32_e32 v2, v1
	ds_store_2addr_stride64_b64 v7, v[3:4], v[1:2] offset1:4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b64 v[3:4], v1 offset:2048
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_i64_e32 vcc_lo, 14, v[3:4]
	s_cbranch_vccnz .LBB0_4
; %bb.1:                                ; %.lr.ph
	ds_load_b64 v[5:6], v8
	ds_load_b64 v[3:4], v7
	s_waitcnt lgkmcnt(1)
	v_add_co_u32 v5, vcc_lo, v5, 1
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v6, vcc_lo
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	v_mul_f64 v[3:4], v[3:4], v[3:4]
	ds_store_b64 v8, v[5:6]
	ds_load_b64 v[9:10], v1 offset:2048
	v_add_co_u32 v5, s0, v5, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v6, s0, 0, v6, s0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i64_e32 vcc_lo, 15, v[9:10]
	s_cbranch_vccnz .LBB0_2
; %bb.3:                                ; %._crit_edge
	ds_store_b64 v7, v[3:4]
.LBB0_4:
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_store_b64 v8, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b64 v[1:2], v1 offset:2048
	v_cmp_gt_u32_e64 s0, 32, v0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i64_e32 vcc_lo, 15, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, vcc_lo
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_8
; %bb.5:                                ; %.preheader
	ds_load_b64 v[2:3], v8
	ds_load_b64 v[0:1], v7
	v_mov_b32_e32 v4, 0
	s_waitcnt lgkmcnt(1)
	v_add_co_u32 v2, vcc_lo, v2, 1
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
.LBB0_6:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	v_mul_f64 v[0:1], v[0:1], v[0:1]
	ds_store_b64 v8, v[2:3]
	ds_load_b64 v[5:6], v4 offset:2048
	v_add_co_u32 v2, s0, v2, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s0, 0, v3, s0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i64_e32 vcc_lo, 15, v[5:6]
	s_cbranch_vccnz .LBB0_6
; %bb.7:                                ; %.loopexit
	ds_store_b64 v7, v[0:1]
.LBB0_8:                                ; %Flow
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6VecAddPKfS0_Pfi
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 11
		.amdhsa_next_free_sgpr 2
		.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	_Z6VecAddPKfS0_Pfi, .Lfunc_end0-_Z6VecAddPKfS0_Pfi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 380
; NumSgprs: 4
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 4
; NumVGPRsForWavesPerEU: 11
; 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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6VecAddPKfS0_Pfi
    .private_segment_fixed_size: 0
    .sgpr_count:     4
    .sgpr_spill_count: 0
    .symbol:         _Z6VecAddPKfS0_Pfi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
