/* Cuda Program for finding cos(0), cos(1*2*pi/N), ... , cos((N-1)*2*pi/N) */

// nvcc CUDA_example_01.cu -use_fast_math -o CUDA_example_01.out

/* --------------------------- header secton ----------------------------*/

#include<stdio.h>
#include<cuda.h>

#define PRINT_RESULT 1
#define COS_THREAD_CNT 512
#define N 1000000
#define TWO_PI 6.283185

/* --------------------------- target code ------------------------------*/

struct cosParams {
	float *arg;
	float *res;
	int n;
};

// CUDA kernel:

__global__ void cos_main(struct cosParams params)
{
	// Computes:
	// res[threadIdx.x + 0*COS_THREAD_CNT] = cos(threadIdx.x + 0*COS_THREAD_CNT)
	// res[threadIdx.x + 1*COS_THREAD_CNT] = cos(threadIdx.x + 1*COS_THREAD_CNT)
	// res[threadIdx.x + 2*COS_THREAD_CNT] = cos(threadIdx.x + 2*COS_THREAD_CNT)
	// ...etc...
	//
	// if COS_THREAD_CNT = 1, this computes all of the cosines in one go,
	// otherwise, it spreads it out across threads...
	//
	// Choice of either:
	//
	// __cosf:
	// Calculate the fast approximate cosine of the input argument x, measured in radians.
	//
	// cosf:
	// Calculate the cosine of the input argument x (measured in radians).

	int i;
	for (i=threadIdx.x; i<params.n; i+=COS_THREAD_CNT){
		// params.res[i] = __cosf(params.arg[i]);
		params.res[i] = cosf(params.arg[i]);
	}
	return;
}

/* --------------------------- host code ------------------------------*/
int main (int argc, char *argv[])
{
	printf("\nBeginning CUDA example code on the CPU...\n");

	printf("Getting some info about CUDA devices on your system...\n");

	int i, devCount;
	cudaGetDeviceCount(&devCount);
	
	if (devCount == 1){
    		printf("There is %d CUDA device on your system.\n", devCount);
 	} else {
 		printf("There are %d CUDA devices on your system.\n", devCount);
 	}

    	// Iterate through devices
    	for (i=0; i<devCount; i++)
    	{
        	// Get device properties
        	printf("\nCUDA Device #%d\n", i);
        	cudaDeviceProp devProp;
        	cudaGetDeviceProperties(&devProp, i);
		printf("Name:  %s\n", devProp.name);

	}
	printf("\n");

	// Begin cosine code:
	cudaError_t cudaStat;
	float* gpu_res = 0;
	float* gpu_arg = 0;

	printf("Allocating memory on the CPU... (n=%d)\n",(int)N);

	// Allocate the vector 1,...,N:
	float *arg = (float *) malloc(N*sizeof(float));
	// Allocate vector of length N to store the result:
	float *res = (float *) malloc(N*sizeof(float));
	int print_every = (int)((double)N/10.0);

	struct cosParams funcParams;

	// Populate arg with 1,...,N
	for(i=0; i<N; i++){
		arg[i] = (float)i*(float)TWO_PI/(float)N;
	}

	printf("Allocating memory on the GPU... (n=%d)\n",(int)N);

	// Key function:
	// cudaError_t cudaMalloc(void ** devPtr, size_t size);
	
	// Allocate N floats on the GPU for the argument 0,1,...,N-1, and make gpu_arg a pointer to that memory:
	// NOTE: sizeof(gpu_arg[0]) is equivalent to sizeof(float) here
	cudaStat = cudaMalloc((void **)&gpu_arg, N*sizeof(gpu_arg[0]));
	if (cudaStat){
		printf(" value = %d : Memory Allocation on GPU Device failed\n", cudaStat);
	} else {
		printf("done. Allocating more memory on the GPU...\n");
	}

	// Allocate N floats on the GPU to store the result, and make gpu_res a pointer to that memory:
	// NOTE: sizeof(gpu_res[0]) is equivalent to sizeof(float) here
	cudaStat = cudaMalloc((void **)&gpu_res, N*sizeof(gpu_res[0]));
	if (cudaStat){
		printf(" value = %d : Memory Allocation on GPU Device failed\n", (int)cudaStat);
	} else {
		printf("done again. Copying stuff from host (CPU) to device (GPU)...\n");
	}

	// Key function:
	// cudaError_t cudaMemcpy(void * dst, const void * src, size_t count, enum cudaMemcpyKind kind);	

	// Copy the vector 0,1,...,N-1 from arg (on the host) to gpu_arg (on the device)
	// NOTE: sizeof(arg[0]) is equivalent to sizeof(float) here
    cudaStat = cudaMemcpy(gpu_arg, arg, N*sizeof(arg[0]), cudaMemcpyHostToDevice);
	if (cudaStat){
		printf(" Memory Copy from Host to Device failed.\n");
	} else {
		printf("successful.\n");
	}

	// Set up the parameters for the GPU kernel:
	funcParams.res = gpu_res;
	funcParams.arg = gpu_arg;
	funcParams.n = N;

	printf("Launching kernel on GPU...\n");

	// Launch the GPU kernel...

	// Key code:
	// KernelFunction<<<dimGrid, dimBlock>>>(args);

	cos_main<<<1,COS_THREAD_CNT>>>(funcParams);

	printf("GPU computations finished. Copying result back to CPU...\n");

	// Copy the vector cos(0),cos(1),...,cos(N-1) from gpu_res (on the device) to res (on the host)
	cudaStat = cudaMemcpy(res, gpu_res, N*sizeof(gpu_res[0]), cudaMemcpyDeviceToHost);

	if (cudaStat){
		printf(" Memory Copy from Device to Host failed.\n");
	} else {
		printf("Copy back successful. Printing result...\n");
	}

	if (PRINT_RESULT){

		// Print the result?
		for(i=0; i < N; i++ ){
			if (i%print_every == 0 ){
				printf("cos(%f) = %f\n", arg[i], res[i] );
			}
		}

	}

    printf("Freeing memory...\n");
    free(arg);
    free(res);
    cudaFree(gpu_arg);
    cudaFree(gpu_res);

	printf("\n\nFinished. :)\n\n");

	return 0;
}



	.file	"tmpxft_002d600d_00000000-6_CUDA_example_01.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z35__device_stub__Z8cos_main9cosParamsR9cosParams
	.type	_Z35__device_stub__Z8cos_main9cosParamsR9cosParams, @function
_Z35__device_stub__Z8cos_main9cosParamsR9cosParams:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$88, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rcx
	movq	%rdi, 64(%rsp)
	movq	%rsp, %rdx
	movabsq	$4294967297, %rax
	leaq	28(%rsp), %rsi
	leaq	16(%rsp), %rdi
	movl	$1, 24(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	8(%rsp)
	.cfi_def_cfa_offset 104
	leaq	_Z8cos_main9cosParams(%rip), %rdi
	pushq	8(%rsp)
	.cfi_def_cfa_offset 112
	movq	44(%rsp), %rcx
	movl	52(%rsp), %r8d
	movq	32(%rsp), %rsi
	movl	40(%rsp), %edx
	leaq	80(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 104
	popq	%rdx
	.cfi_def_cfa_offset 96
.L2:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$88, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z35__device_stub__Z8cos_main9cosParamsR9cosParams, .-_Z35__device_stub__Z8cos_main9cosParamsR9cosParams
	.globl	_Z8cos_main9cosParams
	.type	_Z8cos_main9cosParams, @function
_Z8cos_main9cosParams:
.LFB2053:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	16(%rsp), %rdi
	call	_Z35__device_stub__Z8cos_main9cosParamsR9cosParams
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z8cos_main9cosParams, .-_Z8cos_main9cosParams
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\nBeginning CUDA example code on the CPU...\n"
.LC1:
	.string	"Getting some info about CUDA devices on your system...\n"
.LC2:
	.string	"There is %d CUDA device on your system.\n"
.LC3:
	.string	"There are %d CUDA devices on your system.\n"
.LC4:
	.string	"\nCUDA Device #%d\n"
.LC5:
	.string	"Name:  %s\n"
.LC6:
	.string	"\n"
.LC7:
	.string	"Allocating memory on the CPU... (n=%d)\n"
.LC10:
	.string	"Allocating memory on the GPU... (n=%d)\n"
.LC11:
	.string	" value = %d : Memory Allocation on GPU Device failed\n"
.LC12:
	.string	"done. Allocating more memory on the GPU...\n"
.LC13:
	.string	"done again. Copying stuff from host (CPU) to device (GPU)...\n"
.LC14:
	.string	" Memory Copy from Host to Device failed.\n"
.LC15:
	.string	"successful.\n"
.LC16:
	.string	"Launching kernel on GPU...\n"
.LC17:
	.string	"GPU computations finished. Copying result back to CPU...\n"
.LC18:
	.string	" Memory Copy from Device to Host failed.\n"
.LC19:
	.string	"Copy back successful. Printing result...\n"
.LC20:
	.string	"cos(%f) = %f\n"
.LC21:
	.string	"Freeing memory...\n"
.LC22:
	.string	"\n\nFinished. :)\n\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$1128, %rsp
	.cfi_def_cfa_offset 1168
	movq	%fs:40, %rax
	movq	%rax, 1112(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	12(%rsp), %edx
	leaq	.LC3(%rip), %rsi
	cmpl	$1, %edx
	jne	.L30
	leaq	.LC2(%rip), %rsi
.L30:
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r12
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
.L11:
	cmpl	%ebx, 12(%rsp)
	jle	.L33
	movl	%ebx, %edx
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	80(%rsp), %rbp
	movl	%ebx, %esi
	incl	%ebx
	movq	%rbp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	%rbp, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	jmp	.L11
.L33:
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movl	$1000000, %edx
	leaq	.LC7(%rip), %rsi
	movq	%rax, 16(%rsp)
	movl	$2, %edi
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$4000000, %edi
	call	malloc@PLT
	movl	$4000000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movss	.LC8(%rip), %xmm2
	movss	.LC9(%rip), %xmm1
	movq	%rax, %r12
	xorl	%eax, %eax
.L14:
	cvtsi2ssl	%eax, %xmm0
	mulss	%xmm2, %xmm0
	divss	%xmm1, %xmm0
	movss	%xmm0, 0(%rbp,%rax,4)
	incq	%rax
	cmpq	$1000000, %rax
	jne	.L14
	movl	$1000000, %edx
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	24(%rsp), %rdi
	movl	$4000000, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edx
	testl	%eax, %eax
	je	.L15
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L16
.L15:
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L16:
	leaq	16(%rsp), %rdi
	movl	$4000000, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edx
	testl	%eax, %eax
	je	.L17
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L18
.L17:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L18:
	movq	24(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$4000000, %edx
	call	cudaMemcpy@PLT
	leaq	.LC14(%rip), %rsi
	testl	%eax, %eax
	jne	.L31
	leaq	.LC15(%rip), %rsi
.L31:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movq	16(%rsp), %rbx
	movq	24(%rsp), %r13
	call	__printf_chk@PLT
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$9, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	leaq	56(%rsp), %rdi
	movq	%r13, 56(%rsp)
	movq	%rbx, 64(%rsp)
	movl	$1000000, 72(%rsp)
	call	_Z35__device_stub__Z8cos_main9cosParamsR9cosParams
.L21:
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$4000000, %edx
	call	cudaMemcpy@PLT
	leaq	.LC18(%rip), %rsi
	testl	%eax, %eax
	jne	.L32
	leaq	.LC19(%rip), %rsi
.L32:
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC20(%rip), %r13
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
.L25:
	movl	%ebx, %eax
	movl	$100000, %ecx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L24
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$2, %al
	cvtss2sd	0(%rbp,%rbx,4), %xmm0
	cvtss2sd	(%r12,%rbx,4), %xmm1
	call	__printf_chk@PLT
.L24:
	incq	%rbx
	cmpq	$1000000, %rbx
	jne	.L25
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC22(%rip), %rsi
	call	__printf_chk@PLT
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$1128, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC23:
	.string	"_Z8cos_main9cosParams"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC23(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8cos_main9cosParams(%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
.LFE2055:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC8:
	.long	1086918618
	.align 4
.LC9:
	.long	1232348160
	.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 Program for finding cos(0), cos(1*2*pi/N), ... , cos((N-1)*2*pi/N) */

// nvcc CUDA_example_01.cu -use_fast_math -o CUDA_example_01.out

/* --------------------------- header secton ----------------------------*/

#include<stdio.h>
#include<hip/hip_runtime.h>

#define PRINT_RESULT 1
#define COS_THREAD_CNT 512
#define N 1000000
#define TWO_PI 6.283185

/* --------------------------- target code ------------------------------*/

struct cosParams {
	float *arg;
	float *res;
	int n;
};

// CUDA kernel:

__global__ void cos_main(struct cosParams params)
{
	// Computes:
	// res[threadIdx.x + 0*COS_THREAD_CNT] = cos(threadIdx.x + 0*COS_THREAD_CNT)
	// res[threadIdx.x + 1*COS_THREAD_CNT] = cos(threadIdx.x + 1*COS_THREAD_CNT)
	// res[threadIdx.x + 2*COS_THREAD_CNT] = cos(threadIdx.x + 2*COS_THREAD_CNT)
	// ...etc...
	//
	// if COS_THREAD_CNT = 1, this computes all of the cosines in one go,
	// otherwise, it spreads it out across threads...
	//
	// Choice of either:
	//
	// __cosf:
	// Calculate the fast approximate cosine of the input argument x, measured in radians.
	//
	// cosf:
	// Calculate the cosine of the input argument x (measured in radians).

	int i;
	for (i=threadIdx.x; i<params.n; i+=COS_THREAD_CNT){
		// params.res[i] = __cosf(params.arg[i]);
		params.res[i] = cosf(params.arg[i]);
	}
	return;
}

/* --------------------------- host code ------------------------------*/
int main (int argc, char *argv[])
{
	printf("\nBeginning CUDA example code on the CPU...\n");

	printf("Getting some info about CUDA devices on your system...\n");

	int i, devCount;
	hipGetDeviceCount(&devCount);
	
	if (devCount == 1){
    		printf("There is %d CUDA device on your system.\n", devCount);
 	} else {
 		printf("There are %d CUDA devices on your system.\n", devCount);
 	}

    	// Iterate through devices
    	for (i=0; i<devCount; i++)
    	{
        	// Get device properties
        	printf("\nCUDA Device #%d\n", i);
        	hipDeviceProp_t devProp;
        	hipGetDeviceProperties(&devProp, i);
		printf("Name:  %s\n", devProp.name);

	}
	printf("\n");

	// Begin cosine code:
	hipError_t cudaStat;
	float* gpu_res = 0;
	float* gpu_arg = 0;

	printf("Allocating memory on the CPU... (n=%d)\n",(int)N);

	// Allocate the vector 1,...,N:
	float *arg = (float *) malloc(N*sizeof(float));
	// Allocate vector of length N to store the result:
	float *res = (float *) malloc(N*sizeof(float));
	int print_every = (int)((double)N/10.0);

	struct cosParams funcParams;

	// Populate arg with 1,...,N
	for(i=0; i<N; i++){
		arg[i] = (float)i*(float)TWO_PI/(float)N;
	}

	printf("Allocating memory on the GPU... (n=%d)\n",(int)N);

	// Key function:
	// cudaError_t cudaMalloc(void ** devPtr, size_t size);
	
	// Allocate N floats on the GPU for the argument 0,1,...,N-1, and make gpu_arg a pointer to that memory:
	// NOTE: sizeof(gpu_arg[0]) is equivalent to sizeof(float) here
	cudaStat = hipMalloc((void **)&gpu_arg, N*sizeof(gpu_arg[0]));
	if (cudaStat){
		printf(" value = %d : Memory Allocation on GPU Device failed\n", cudaStat);
	} else {
		printf("done. Allocating more memory on the GPU...\n");
	}

	// Allocate N floats on the GPU to store the result, and make gpu_res a pointer to that memory:
	// NOTE: sizeof(gpu_res[0]) is equivalent to sizeof(float) here
	cudaStat = hipMalloc((void **)&gpu_res, N*sizeof(gpu_res[0]));
	if (cudaStat){
		printf(" value = %d : Memory Allocation on GPU Device failed\n", (int)cudaStat);
	} else {
		printf("done again. Copying stuff from host (CPU) to device (GPU)...\n");
	}

	// Key function:
	// cudaError_t cudaMemcpy(void * dst, const void * src, size_t count, enum cudaMemcpyKind kind);	

	// Copy the vector 0,1,...,N-1 from arg (on the host) to gpu_arg (on the device)
	// NOTE: sizeof(arg[0]) is equivalent to sizeof(float) here
    cudaStat = hipMemcpy(gpu_arg, arg, N*sizeof(arg[0]), hipMemcpyHostToDevice);
	if (cudaStat){
		printf(" Memory Copy from Host to Device failed.\n");
	} else {
		printf("successful.\n");
	}

	// Set up the parameters for the GPU kernel:
	funcParams.res = gpu_res;
	funcParams.arg = gpu_arg;
	funcParams.n = N;

	printf("Launching kernel on GPU...\n");

	// Launch the GPU kernel...

	// Key code:
	// KernelFunction<<<dimGrid, dimBlock>>>(args);

	cos_main<<<1,COS_THREAD_CNT>>>(funcParams);

	printf("GPU computations finished. Copying result back to CPU...\n");

	// Copy the vector cos(0),cos(1),...,cos(N-1) from gpu_res (on the device) to res (on the host)
	cudaStat = hipMemcpy(res, gpu_res, N*sizeof(gpu_res[0]), hipMemcpyDeviceToHost);

	if (cudaStat){
		printf(" Memory Copy from Device to Host failed.\n");
	} else {
		printf("Copy back successful. Printing result...\n");
	}

	if (PRINT_RESULT){

		// Print the result?
		for(i=0; i < N; i++ ){
			if (i%print_every == 0 ){
				printf("cos(%f) = %f\n", arg[i], res[i] );
			}
		}

	}

    printf("Freeing memory...\n");
    free(arg);
    free(res);
    hipFree(gpu_arg);
    hipFree(gpu_res);

	printf("\n\nFinished. :)\n\n");

	return 0;
}



	.text
	.file	"CUDA_example_01.hip"
	.globl	_Z23__device_stub__cos_main9cosParams # -- Begin function _Z23__device_stub__cos_main9cosParams
	.type	_Z23__device_stub__cos_main9cosParams,@function
_Z23__device_stub__cos_main9cosParams:  # @_Z23__device_stub__cos_main9cosParams
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	112(%rsp), %rax
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z8cos_main9cosParams, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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	_Z23__device_stub__cos_main9cosParams, .Lfunc_end0-_Z23__device_stub__cos_main9cosParams
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x40c90fda                      # float 6.283185
.LCPI1_1:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$1544, %rsp                     # imm = 0x608
	.cfi_def_cfa_offset 1600
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leaq	36(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	(%rbx), %esi
	cmpl	$1, %esi
	jne	.LBB1_2
# %bb.1:
	movl	$.L.str.2, %edi
	movl	$1, %esi
	jmp	.LBB1_3
.LBB1_2:
	movl	$.L.str.3, %edi
.LBB1_3:
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 36(%rsp)
	jle	.LBB1_6
# %bb.4:                                # %.lr.ph.preheader
	leaq	72(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB1_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.4, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	cmpl	36(%rsp), %ebp
	jl	.LBB1_5
.LBB1_6:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%r15d, %r15d
	movq	%r15, 72(%rsp)
	movq	%r15, 40(%rsp)
	movl	$.L.str.7, %edi
	movl	$1000000, %esi                  # imm = 0xF4240
	xorl	%eax, %eax
	callq	printf
	movl	$4000000, %edi                  # imm = 0x3D0900
	callq	malloc
	movq	%rax, %rbx
	movl	$4000000, %edi                  # imm = 0x3D0900
	callq	malloc
	movq	%rax, %r14
	movss	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI1_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB1_7:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm2, %xmm2
	cvtsi2ss	%r15d, %xmm2
	mulss	%xmm0, %xmm2
	divss	%xmm1, %xmm2
	movss	%xmm2, (%rbx,%r15,4)
	incq	%r15
	cmpq	$1000000, %r15                  # imm = 0xF4240
	jne	.LBB1_7
# %bb.8:
	movl	$.L.str.8, %edi
	movl	$1000000, %esi                  # imm = 0xF4240
	xorl	%eax, %eax
	callq	printf
	leaq	40(%rsp), %rdi
	movl	$4000000, %esi                  # imm = 0x3D0900
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_10
# %bb.9:
	movl	$.L.str.9, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_11
.LBB1_10:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB1_11:
	leaq	72(%rsp), %rdi
	movl	$4000000, %esi                  # imm = 0x3D0900
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_13
# %bb.12:
	movl	$.L.str.9, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_14
.LBB1_13:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
.LBB1_14:
	movq	40(%rsp), %rdi
	movl	$4000000, %edx                  # imm = 0x3D0900
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	movl	$.Lstr.4, %eax
	movl	$.Lstr.5, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	movq	72(%rsp), %r12
	movq	40(%rsp), %r13
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	511(%rdi), %rdx
	xorl	%r15d, %r15d
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.15:
	movq	%r13, 48(%rsp)
	movq	%r12, 56(%rsp)
	movl	$1000000, 64(%rsp)              # imm = 0xF4240
	movq	64(%rsp), %rax
	movq	%rax, 16(%rsp)
	movups	48(%rsp), %xmm0
	movups	%xmm0, (%rsp)
	callq	_Z23__device_stub__cos_main9cosParams
.LBB1_16:
	movl	$.Lstr.7, %edi
	callq	puts@PLT
	movq	72(%rsp), %rsi
	movl	$4000000, %edx                  # imm = 0x3D0900
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	movl	$.Lstr.8, %eax
	movl	$.Lstr.9, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	xorl	%r12d, %r12d
.LBB1_17:                               # =>This Inner Loop Header: Depth=1
	movl	%r12d, %eax
	shrl	$5, %eax
	imulq	$175921861, %rax, %rax          # imm = 0xA7C5AC5
	shrq	$39, %rax
	imull	$100000, %eax, %eax             # imm = 0x186A0
	addl	%r15d, %eax
	jne	.LBB1_19
# %bb.18:                               #   in Loop: Header=BB1_17 Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r12,4), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%r14,%r12,4), %xmm1
	movl	$.L.str.18, %edi
	movb	$2, %al
	callq	printf
.LBB1_19:                               #   in Loop: Header=BB1_17 Depth=1
	incq	%r12
	decl	%r15d
	cmpq	$1000000, %r12                  # imm = 0xF4240
	jne	.LBB1_17
# %bb.20:
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movl	$.Lstr.11, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$1544, %rsp                     # imm = 0x608
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8cos_main9cosParams, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z8cos_main9cosParams,@object   # @_Z8cos_main9cosParams
	.section	.rodata,"a",@progbits
	.globl	_Z8cos_main9cosParams
	.p2align	3, 0x0
_Z8cos_main9cosParams:
	.quad	_Z23__device_stub__cos_main9cosParams
	.size	_Z8cos_main9cosParams, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"There is %d CUDA device on your system.\n"
	.size	.L.str.2, 41

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"There are %d CUDA devices on your system.\n"
	.size	.L.str.3, 43

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\nCUDA Device #%d\n"
	.size	.L.str.4, 18

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Name:  %s\n"
	.size	.L.str.5, 11

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Allocating memory on the CPU... (n=%d)\n"
	.size	.L.str.7, 40

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Allocating memory on the GPU... (n=%d)\n"
	.size	.L.str.8, 40

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	" value = %d : Memory Allocation on GPU Device failed\n"
	.size	.L.str.9, 54

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"cos(%f) = %f\n"
	.size	.L.str.18, 14

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8cos_main9cosParams"
	.size	.L__unnamed_1, 22

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"\nBeginning CUDA example code on the CPU..."
	.size	.Lstr, 43

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Getting some info about CUDA devices on your system..."
	.size	.Lstr.1, 55

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"done. Allocating more memory on the GPU..."
	.size	.Lstr.2, 43

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"done again. Copying stuff from host (CPU) to device (GPU)..."
	.size	.Lstr.3, 61

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"successful."
	.size	.Lstr.4, 12

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	" Memory Copy from Host to Device failed."
	.size	.Lstr.5, 41

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"Launching kernel on GPU..."
	.size	.Lstr.6, 27

	.type	.Lstr.7,@object                 # @str.7
.Lstr.7:
	.asciz	"GPU computations finished. Copying result back to CPU..."
	.size	.Lstr.7, 57

	.type	.Lstr.8,@object                 # @str.8
.Lstr.8:
	.asciz	"Copy back successful. Printing result..."
	.size	.Lstr.8, 41

	.type	.Lstr.9,@object                 # @str.9
.Lstr.9:
	.asciz	" Memory Copy from Device to Host failed."
	.size	.Lstr.9, 41

	.type	.Lstr.10,@object                # @str.10
.Lstr.10:
	.asciz	"Freeing memory..."
	.size	.Lstr.10, 18

	.type	.Lstr.11,@object                # @str.11
.Lstr.11:
	.asciz	"\n\nFinished. :)\n"
	.size	.Lstr.11, 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 _Z23__device_stub__cos_main9cosParams
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8cos_main9cosParams
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8cos_main9cosParams   ; -- Begin function _Z8cos_main9cosParams
	.globl	_Z8cos_main9cosParams
	.p2align	8
	.type	_Z8cos_main9cosParams,@function
_Z8cos_main9cosParams:                  ; @_Z8cos_main9cosParams
; %bb.0:
	s_load_b32 s2, s[0:1], 0x10
	s_mov_b32 s3, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_i32_e64 s2, v0
	s_cbranch_execz .LBB0_7
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b128 s[4:7], s[0:1], 0x0
	v_dual_mov_b32 v6, 0 :: v_dual_lshlrev_b32 v3, 2, v0
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v1, s0, s4, v3
	v_add_co_ci_u32_e64 v2, null, s5, 0, s0
	v_add_co_u32 v3, s0, s6, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v4, null, s7, 0, s0
	s_mov_b32 s4, 0x7fffff
	s_mov_b32 s5, 0xb94c1982
	s_mov_b32 s6, 0x37d75334
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v7, v[1:2], off
                                        ; implicit-def: $vgpr8
                                        ; implicit-def: $vgpr5
	s_mov_b32 s1, exec_lo
	s_waitcnt vmcnt(0)
	v_cmpx_ngt_f32_e64 0x48000000, |v7|
	s_xor_b32 s7, exec_lo, s1
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_and_b32_e32 v13, 0x7fffffff, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_and_or_b32 v16, v13, s4, 0x800000
	v_lshrrev_b32_e32 v13, 23, v13
	v_mad_u64_u32 v[8:9], null, 0xfe5163ab, v16, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v14, 0xffffff88, v13
	v_cmp_lt_u32_e32 vcc_lo, 63, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v5, v9
	v_cndmask_b32_e64 v15, 0, 0xffffffc0, vcc_lo
	v_mad_u64_u32 v[9:10], null, 0x3c439041, v16, v[5:6]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v15, v15, v14
	v_mov_b32_e32 v5, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_lt_u32_e64 s0, 31, v15
	v_mad_u64_u32 v[10:11], null, 0xdb629599, v16, v[5:6]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v17, 0, 0xffffffe0, s0
	v_add_nc_u32_e32 v17, v17, v15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v5, v11 :: v_dual_cndmask_b32 v8, v10, v8
	v_cmp_lt_u32_e64 s1, 31, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[11:12], null, 0xf534ddc0, v16, v[5:6]
	v_mov_b32_e32 v5, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v9, v11, v9, vcc_lo
	v_mad_u64_u32 v[12:13], null, 0xfc2757d1, v16, v[5:6]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v8, v9, v8, s0
	v_mov_b32_e32 v5, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[13:14], null, 0x4e441529, v16, v[5:6]
	v_mov_b32_e32 v5, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_mad_u64_u32 v[14:15], null, 0xa2f9836e, v16, v[5:6]
	v_cndmask_b32_e64 v5, 0, 0xffffffe0, s1
	v_cndmask_b32_e32 v16, v13, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_dual_cndmask_b32 v14, v14, v12 :: v_dual_add_nc_u32 v5, v5, v17
	v_dual_cndmask_b32 v13, v15, v13 :: v_dual_cndmask_b32 v12, v12, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v15, 32, v5
	v_cndmask_b32_e64 v11, v14, v16, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v13, v13, v14, s0
	v_cndmask_b32_e64 v14, v16, v12, s0
	v_cndmask_b32_e64 v12, v12, v9, s0
	v_cmp_eq_u32_e32 vcc_lo, 0, v5
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v13, v13, v11, s1
	v_cndmask_b32_e64 v11, v11, v14, s1
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v14, v14, v12, s1
	v_cndmask_b32_e64 v8, v12, v8, s1
	v_alignbit_b32 v16, v13, v11, v15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_alignbit_b32 v10, v11, v14, v15
	v_cndmask_b32_e32 v5, v16, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v9, v10, v11, vcc_lo
	v_alignbit_b32 v13, v14, v8, v15
	v_bfe_u32 v10, v5, 29, 1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_alignbit_b32 v11, v5, v9, 30
	v_cndmask_b32_e32 v13, v13, v14, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v12, 0, v10
	v_alignbit_b32 v9, v9, v13, 30
	v_alignbit_b32 v8, v13, v8, 30
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v11, v11, v12
	v_xor_b32_e32 v9, v9, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v8, v8, v12
	v_lshrrev_b32_e32 v12, 29, v5
	v_clz_i32_u32_e32 v14, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v12, 31, v12
	v_min_u32_e32 v14, 32, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_or_b32_e32 v15, 0.5, v12
	v_sub_nc_u32_e32 v13, 31, v14
	v_lshlrev_b32_e32 v16, 23, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_alignbit_b32 v11, v11, v9, v13
	v_alignbit_b32 v8, v9, v8, v13
	v_sub_nc_u32_e32 v15, v15, v16
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_alignbit_b32 v9, v11, v8, 9
	v_lshrrev_b32_e32 v11, 9, v11
	v_clz_i32_u32_e32 v13, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_min_u32_e32 v13, 32, v13
	v_sub_nc_u32_e32 v17, 31, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_alignbit_b32 v8, v9, v8, v17
	v_or_b32_e32 v9, v11, v15
	v_add_lshl_u32 v11, v13, v14, 23
	v_lshrrev_b32_e32 v8, 9, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v13, 0x3fc90fda, v9
	v_sub_nc_u32_e32 v8, v8, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v11, 0x3fc90fda, v9, -v13
	v_add_nc_u32_e32 v8, 0x33000000, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v11, 0x33a22168, v9
	v_or_b32_e32 v8, v8, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v11, 0x3fc90fda, v8
	v_lshrrev_b32_e32 v8, 30, v5
	v_dual_add_f32 v5, v13, v11 :: v_dual_add_nc_u32 v8, v10, v8
.LBB0_4:                                ; %Flow
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_saveexec_b32 s0, s7
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_mul_f32_e64 v5, 0x3f22f983, |v7|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rndne_f32_e32 v8, v5
	v_fma_f32 v5, 0xbfc90fda, v8, |v7|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v5, 0xb3a22168, v8
	v_fmac_f32_e32 v5, 0xa7c234c4, v8
	v_cvt_i32_f32_e32 v8, v8
; %bb.6:                                ; %_ZL4cosff.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_dual_mul_f32 v9, v5, v5 :: v_dual_and_b32 v12, 1, v8
	v_add_nc_u32_e32 v0, 0x200, v0
	v_lshlrev_b32_e32 v8, 30, v8
	v_fmaak_f32 v10, s5, v9, 0x3c0881c4
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_eq_u32_e32 vcc_lo, 0, v12
	v_and_b32_e32 v8, 0x80000000, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmaak_f32 v10, v9, v10, 0xbe2aaa9d
	v_dual_fmaak_f32 v11, s6, v9, 0xbab64f3b :: v_dual_mul_f32 v10, v9, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmaak_f32 v11, v9, v11, 0x3d2aabf7
	v_fmac_f32_e32 v5, v5, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmaak_f32 v11, v9, v11, 0xbf000004
	v_fma_f32 v9, v9, v11, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v5, -v5, v9, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v7, 0x1f8
	v_xor_b32_e32 v5, v8, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_cndmask_b32_e32 v5, 0x7fc00000, v5, vcc_lo
	v_add_co_u32 v1, vcc_lo, 0x800, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, 0, v2, vcc_lo
	v_cmp_le_i32_e32 vcc_lo, s2, v0
	global_store_b32 v[3:4], v5, off
	v_add_co_u32 v3, s0, 0x800, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_add_co_ci_u32_e64 v4, s0, 0, v4, s0
	s_or_b32 s3, vcc_lo, s3
	s_and_not1_b32 exec_lo, exec_lo, s3
	s_cbranch_execnz .LBB0_2
.LBB0_7:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8cos_main9cosParams
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 18
		.amdhsa_next_free_sgpr 8
		.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	_Z8cos_main9cosParams, .Lfunc_end0-_Z8cos_main9cosParams
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1128
; NumSgprs: 10
; NumVgprs: 18
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 10
; NumVGPRsForWavesPerEU: 18
; 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:
      - .offset:         0
        .size:           24
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8cos_main9cosParams
    .private_segment_fixed_size: 0
    .sgpr_count:     10
    .sgpr_spill_count: 0
    .symbol:         _Z8cos_main9cosParams.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     18
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
