#include <CL/cl.h>
#include <iostream>

const char* source =
"__kernel void sum( __global float * input) \n"
"{										\n"
"	int i = get_global_id(0);			\n"
"	input[i] = input[i] + i;			\n"
"}";

const unsigned int SIZE = 1024;

int main() {
	cl_int error = 0;

	cl_uint num_platforms = 0;
	clGetPlatformIDs(0, NULL, &num_platforms);

	cl_platform_id platform = NULL;
	if (0 < num_platforms) {
		cl_platform_id* platforms = new cl_platform_id[num_platforms];
		clGetPlatformIDs(num_platforms, platforms, NULL);
		platform = platforms[0];

		char platform_name[128];
		clGetPlatformInfo(platform, CL_PLATFORM_NAME, 128, platform_name, nullptr);
		std::cout << platform_name << std::endl;

		delete[] platforms;
	}

	cl_context_properties properties[3] = { CL_CONTEXT_PLATFORM,
		(cl_context_properties)platform, 0 };

	cl_context context =
		clCreateContextFromType((NULL == platform) ? NULL : properties,
			CL_DEVICE_TYPE_GPU, NULL, NULL, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create context from type failed" << std::endl;
	}

	size_t size = 0;

	clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);

	cl_device_id device = 0;
	if (size > 0) {
		cl_device_id* devices = (cl_device_id*)alloca(size);
		clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL);
		device = devices[0];

		char device_name[128];
		clGetDeviceInfo(device, CL_DEVICE_NAME, 128, device_name, nullptr);
		std::cout << device_name << std::endl;
	}

	cl_command_queue queue =
		clCreateCommandQueue(context, device, 0, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create command queue with properties failed" << std::endl;
	}

	size_t srclen[] = { strlen(source) };

	cl_program program =
		clCreateProgramWithSource(context, 1, &source, srclen, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create program with source failed" << std::endl;
	}

	clBuildProgram(program, 1, &device, NULL, NULL, NULL);

	cl_kernel kernel = clCreateKernel(program, "sum", &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create kernel failed" << std::endl;
	}

	size_t count = SIZE;
	float data[SIZE];
	float result[SIZE];
	size_t group = 0;

	for (int i = 0; i < SIZE; i++)
		data[i] = 10.0;

	cl_mem input = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * SIZE, NULL, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create buffer failed" << std::endl;
	}

	error = clEnqueueWriteBuffer(queue, input, CL_TRUE, 0, sizeof(float) * SIZE, data, 0, NULL, NULL);
	if (error != CL_SUCCESS) {
		std::cout << "Write buffer failed" << std::endl;
	}

	error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &input);
	if (error != CL_SUCCESS) {
		std::cout << "Set arg kernel failed" << std::endl;
	}

	clGetKernelWorkGroupInfo(kernel, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &group, NULL);
	clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &((count)), &group, 0, NULL, NULL);

	clEnqueueReadBuffer(queue, input, CL_TRUE, 0, sizeof(float) * SIZE, result, 0, NULL, NULL);

	for (int i = 0; i < SIZE; i++)
	{
		printf("result[%d] = %f\n", i, result[i]);
	}

	clFinish(queue);
	clReleaseMemObject(input);
	clReleaseProgram(program);
	clReleaseKernel(kernel);
	clReleaseCommandQueue(queue);
	clReleaseContext(context);
	return 0;
}


	.file	"tmpxft_002e27d0_00000000-6_kernel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4159:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4159:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4810:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4810:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Create context from type failed"
.LC1:
	.string	"Create command queue with properties failed"
.LC2:
	.string	"Create program with source failed"
.LC3:
	.string	"sum"
.LC4:
	.string	"Create kernel failed"
.LC6:
	.string	"Create buffer failed"
.LC7:
	.string	"Write buffer failed"
.LC8:
	.string	"Set arg kernel failed"
.LC9:
	.string	"result[%d] = %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4156:
	.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
	subq	$4096, %rsp
	orq	$0, (%rsp)
	subq	$4096, %rsp
	orq	$0, (%rsp)
	subq	$248, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	xorl	%r9d, %r9d
	xorl	%edi, %edi
	xorl	%esi, %esi
	xorl	%ebx, %ebx
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	leaq	-8452(%rbp), %rdx
	movl	%r9d, -8456(%rbp)
	movl	%r9d, -8452(%rbp)
	call	clGetPlatformIDs@PLT
	movl	-8452(%rbp), %edi
	testl	%edi, %edi
	je	.L4
	salq	$3, %rdi
	leaq	-184(%rbp), %r13
	call	_Znam@PLT
	movl	-8452(%rbp), %edi
	xorl	%edx, %edx
	movq	%rax, %r12
	movq	%rax, %rsi
	call	clGetPlatformIDs@PLT
	movq	(%r12), %rbx
	xorl	%r8d, %r8d
	movq	%r13, %rcx
	movl	$128, %edx
	movl	$2306, %esi
	movq	%rbx, %rdi
	call	clGetPlatformInfo@PLT
	movq	%r13, %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r12, %rdi
	call	_ZdaPv@PLT
.L4:
	xorl	%r8d, %r8d
	movq	%rbx, -8392(%rbp)
	movq	%r8, -8384(%rbp)
	movq	$4228, -8400(%rbp)
	testq	%rbx, %rbx
	je	.L5
	leaq	-8400(%rbp), %rbx
.L5:
	leaq	-8456(%rbp), %r14
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	movl	$4, %esi
	movq	%r14, %r8
	movq	%rbx, %rdi
	call	clCreateContextFromType@PLT
	cmpl	$0, -8456(%rbp)
	movq	%rax, -8472(%rbp)
	je	.L6
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L6:
	movq	-8472(%rbp), %rdi
	xorl	%esi, %esi
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	movq	%rsi, -8448(%rbp)
	leaq	-8448(%rbp), %r8
	movl	$4225, %esi
	call	clGetContextInfo@PLT
	movq	-8448(%rbp), %rsi
	xorl	%edi, %edi
	movq	%rdi, -8440(%rbp)
	testq	%rsi, %rsi
	je	.L7
	leaq	23(%rsi), %rdx
	movq	%rsp, %rcx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L8:
	cmpq	%rcx, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L10
	orq	$0, -8(%rsp,%rax)
.L10:
	leaq	15(%rsp), %rbx
	movq	-8472(%rbp), %rdi
	movq	%rsi, %rdx
	xorl	%r8d, %r8d
	andq	$-16, %rbx
	movl	$4225, %esi
	movq	%rbx, %rcx
	call	clGetContextInfo@PLT
	movq	(%rbx), %rdi
	xorl	%r8d, %r8d
	movl	$128, %edx
	leaq	-184(%rbp), %rbx
	movl	$4139, %esi
	movq	%rbx, %rcx
	movq	%rdi, -8440(%rbp)
	call	clGetDeviceInfo@PLT
	movq	%rbx, %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L7:
	movq	-8440(%rbp), %rsi
	movq	-8472(%rbp), %rdi
	xorl	%edx, %edx
	movq	%r14, %rcx
	call	clCreateCommandQueue@PLT
	cmpl	$0, -8456(%rbp)
	movq	%rax, -8480(%rbp)
	je	.L11
	leaq	.LC1(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L11:
	movq	source(%rip), %rdi
	call	strlen@PLT
	movq	-8472(%rbp), %rdi
	movq	%r14, %r8
	leaq	-8408(%rbp), %rcx
	leaq	source(%rip), %rdx
	movl	$1, %esi
	movq	%rax, -8408(%rbp)
	call	clCreateProgramWithSource@PLT
	cmpl	$0, -8456(%rbp)
	movq	%rax, %r13
	je	.L12
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L12:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	xorl	%ecx, %ecx
	movl	$1, %esi
	leaq	-8440(%rbp), %rdx
	movq	%r13, %rdi
	call	clBuildProgram@PLT
	movq	%r14, %rdx
	leaq	.LC3(%rip), %rsi
	movq	%r13, %rdi
	call	clCreateKernel@PLT
	cmpl	$0, -8456(%rbp)
	movq	%rax, %r12
	je	.L13
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L13:
	xorl	%ecx, %ecx
	movss	.LC5(%rip), %xmm0
	xorl	%eax, %eax
	movq	$1024, -8432(%rbp)
	movq	%rcx, -8424(%rbp)
	leaq	-8376(%rbp), %r15
.L14:
	movss	%xmm0, (%r15,%rax,4)
	incq	%rax
	cmpq	$1024, %rax
	jne	.L14
	xorl	%ecx, %ecx
	movq	%r14, %r8
	movl	$4096, %edx
	movl	$1, %esi
	movq	-8472(%rbp), %rdi
	call	clCreateBuffer@PLT
	cmpl	$0, -8456(%rbp)
	movq	%rax, -8416(%rbp)
	je	.L15
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L15:
	pushq	%rdx
	movq	-8416(%rbp), %rsi
	movq	%r15, %r9
	xorl	%ecx, %ecx
	pushq	$0
	movl	$4096, %r8d
	movl	$1, %edx
	movq	-8480(%rbp), %rdi
	pushq	$0
	pushq	$0
	call	clEnqueueWriteBuffer@PLT
	addq	$32, %rsp
	movl	%eax, -8456(%rbp)
	testl	%eax, %eax
	je	.L16
	leaq	.LC7(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L16:
	leaq	-8416(%rbp), %rcx
	movl	$8, %edx
	xorl	%esi, %esi
	movq	%r12, %rdi
	call	clSetKernelArg@PLT
	movl	%eax, -8456(%rbp)
	testl	%eax, %eax
	je	.L17
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L17:
	leaq	-8424(%rbp), %r14
	xorl	%r9d, %r9d
	movq	%r12, %rdi
	xorl	%ebx, %ebx
	movq	-8440(%rbp), %rsi
	movq	%r14, %r8
	movl	$8, %ecx
	movl	$4528, %edx
	leaq	.LC9(%rip), %r15
	call	clGetKernelWorkGroupInfo@PLT
	movq	%r14, %r9
	xorl	%ecx, %ecx
	movl	$1, %edx
	pushq	%rax
	movq	-8480(%rbp), %rdi
	leaq	-8432(%rbp), %r8
	movq	%r12, %rsi
	pushq	$0
	leaq	-4280(%rbp), %r14
	pushq	$0
	pushq	$0
	call	clEnqueueNDRangeKernel@PLT
	addq	$24, %rsp
	movq	%r14, %r9
	xorl	%ecx, %ecx
	pushq	$0
	movq	-8416(%rbp), %rsi
	movl	$1, %edx
	movl	$4096, %r8d
	pushq	$0
	movq	-8480(%rbp), %rdi
	pushq	$0
	call	clEnqueueReadBuffer@PLT
	addq	$32, %rsp
.L18:
	movl	%ebx, %edx
	cvtss2sd	(%r14,%rbx,4), %xmm0
	movq	%r15, %rsi
	movb	$1, %al
	movl	$2, %edi
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$1024, %rbx
	jne	.L18
	movq	-8480(%rbp), %rdi
	call	clFinish@PLT
	movq	-8416(%rbp), %rdi
	call	clReleaseMemObject@PLT
	movq	%r13, %rdi
	call	clReleaseProgram@PLT
	movq	%r12, %rdi
	call	clReleaseKernel@PLT
	movq	-8480(%rbp), %rdi
	call	clReleaseCommandQueue@PLT
	movq	-8472(%rbp), %rdi
	call	clReleaseContext@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4156:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4182:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4182:
	.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	source
	.section	.rodata.str1.1
.LC10:
	.string	"__kernel void sum( __global float * input) \n{\t\t\t\t\t\t\t\t\t\t\n\tint i = get_global_id(0);\t\t\t\n\tinput[i] = input[i] + i;\t\t\t\n}"
	.section	.data.rel.local,"aw"
	.align 8
	.type	source, @object
	.size	source, 8
source:
	.quad	.LC10
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC5:
	.long	1092616192
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <CL/cl.h>
#include <iostream>

const char* source =
"__kernel void sum( __global float * input) \n"
"{										\n"
"	int i = get_global_id(0);			\n"
"	input[i] = input[i] + i;			\n"
"}";

const unsigned int SIZE = 1024;

int main() {
	cl_int error = 0;

	cl_uint num_platforms = 0;
	clGetPlatformIDs(0, NULL, &num_platforms);

	cl_platform_id platform = NULL;
	if (0 < num_platforms) {
		cl_platform_id* platforms = new cl_platform_id[num_platforms];
		clGetPlatformIDs(num_platforms, platforms, NULL);
		platform = platforms[0];

		char platform_name[128];
		clGetPlatformInfo(platform, CL_PLATFORM_NAME, 128, platform_name, nullptr);
		std::cout << platform_name << std::endl;

		delete[] platforms;
	}

	cl_context_properties properties[3] = { CL_CONTEXT_PLATFORM,
		(cl_context_properties)platform, 0 };

	cl_context context =
		clCreateContextFromType((NULL == platform) ? NULL : properties,
			CL_DEVICE_TYPE_GPU, NULL, NULL, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create context from type failed" << std::endl;
	}

	size_t size = 0;

	clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);

	cl_device_id device = 0;
	if (size > 0) {
		cl_device_id* devices = (cl_device_id*)alloca(size);
		clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL);
		device = devices[0];

		char device_name[128];
		clGetDeviceInfo(device, CL_DEVICE_NAME, 128, device_name, nullptr);
		std::cout << device_name << std::endl;
	}

	cl_command_queue queue =
		clCreateCommandQueue(context, device, 0, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create command queue with properties failed" << std::endl;
	}

	size_t srclen[] = { strlen(source) };

	cl_program program =
		clCreateProgramWithSource(context, 1, &source, srclen, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create program with source failed" << std::endl;
	}

	clBuildProgram(program, 1, &device, NULL, NULL, NULL);

	cl_kernel kernel = clCreateKernel(program, "sum", &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create kernel failed" << std::endl;
	}

	size_t count = SIZE;
	float data[SIZE];
	float result[SIZE];
	size_t group = 0;

	for (int i = 0; i < SIZE; i++)
		data[i] = 10.0;

	cl_mem input = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * SIZE, NULL, &error);
	if (error != CL_SUCCESS) {
		std::cout << "Create buffer failed" << std::endl;
	}

	error = clEnqueueWriteBuffer(queue, input, CL_TRUE, 0, sizeof(float) * SIZE, data, 0, NULL, NULL);
	if (error != CL_SUCCESS) {
		std::cout << "Write buffer failed" << std::endl;
	}

	error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &input);
	if (error != CL_SUCCESS) {
		std::cout << "Set arg kernel failed" << std::endl;
	}

	clGetKernelWorkGroupInfo(kernel, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &group, NULL);
	clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &((count)), &group, 0, NULL, NULL);

	clEnqueueReadBuffer(queue, input, CL_TRUE, 0, sizeof(float) * SIZE, result, 0, NULL, NULL);

	for (int i = 0; i < SIZE; i++)
	{
		printf("result[%d] = %f\n", i, result[i]);
	}

	clFinish(queue);
	clReleaseMemObject(input);
	clReleaseProgram(program);
	clReleaseKernel(kernel);
	clReleaseCommandQueue(queue);
	clReleaseContext(context);
	return 0;
}


	.text
	.file	"kernel.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI0_0:
	.zero	16
	.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	$8296, %rsp                     # imm = 0x2068
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	xorl	%ebx, %ebx
	movl	%ebx, -44(%rbp)
	leaq	-92(%rbp), %r14
	movl	%ebx, (%r14)
	xorl	%edi, %edi
	xorl	%esi, %esi
	movq	%r14, %rdx
	callq	clGetPlatformIDs
	movl	(%r14), %r15d
	testq	%r15, %r15
	je	.LBB0_2
# %bb.1:
	movq	%r15, %rdi
	shlq	$3, %rdi
	callq	_Znam
	movq	%rax, %r14
	movl	%r15d, %edi
	movq	%rax, %rsi
	xorl	%edx, %edx
	callq	clGetPlatformIDs
	movq	(%r14), %rbx
	leaq	-4240(%rbp), %r15
	movl	$128, %edx
	movq	%rbx, %rdi
	movl	$2306, %esi                     # imm = 0x902
	movq	%r15, %rcx
	xorl	%r8d, %r8d
	callq	clGetPlatformInfo
	movq	%r15, %rdi
	callq	strlen
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r14, %rdi
	callq	_ZdaPv
.LBB0_2:
	leaq	-144(%rbp), %rdi
	movq	$4228, (%rdi)                   # imm = 0x1084
	movq	%rbx, 8(%rdi)
	movq	$0, 16(%rdi)
	testq	%rbx, %rbx
	cmoveq	%rbx, %rdi
	leaq	-44(%rbp), %r14
	movl	$4, %esi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	movq	%r14, %r8
	callq	clCreateContextFromType
	movq	%rax, %rbx
	cmpl	$0, (%r14)
	je	.LBB0_4
# %bb.3:
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$31, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_4:
	xorl	%r14d, %r14d
	leaq	-112(%rbp), %r15
	movq	%r14, (%r15)
	movq	%rbx, %rdi
	movl	$4225, %esi                     # imm = 0x1081
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	movq	%r15, %r8
	callq	clGetContextInfo
	movq	%r14, -64(%rbp)
	movq	(%r15), %rdx
	testq	%rdx, %rdx
	je	.LBB0_6
# %bb.5:
	movq	%rsp, %r14
	leaq	15(%rdx), %r15
	andq	$-16, %r15
	movq	%r14, %rcx
	subq	%r15, %rcx
	movq	%rcx, %rsp
	negq	%r15
	movq	%rbx, %rdi
	movl	$4225, %esi                     # imm = 0x1081
	xorl	%r8d, %r8d
	callq	clGetContextInfo
	movq	(%r14,%r15), %r14
	movq	%r14, -64(%rbp)
	leaq	-4240(%rbp), %r15
	movl	$128, %edx
	movq	%r14, %rdi
	movl	$4139, %esi                     # imm = 0x102B
	movq	%r15, %rcx
	xorl	%r8d, %r8d
	callq	clGetDeviceInfo
	movq	%r15, %rdi
	callq	strlen
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_6:
	leaq	-44(%rbp), %r15
	movq	%rbx, %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	movq	%r15, %rcx
	callq	clCreateCommandQueue
	movq	%rax, %r14
	cmpl	$0, (%r15)
	je	.LBB0_8
# %bb.7:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$43, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_8:
	movq	source(%rip), %rdi
	callq	strlen
	leaq	-104(%rbp), %rcx
	movq	%rax, (%rcx)
	leaq	-44(%rbp), %r12
	movl	$source, %edx
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r12, %r8
	callq	clCreateProgramWithSource
	movq	%rax, -72(%rbp)                 # 8-byte Spill
	cmpl	$0, (%r12)
	je	.LBB0_10
# %bb.9:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$33, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_10:
	leaq	-64(%rbp), %rdx
	movq	-72(%rbp), %r15                 # 8-byte Reload
	movq	%r15, %rdi
	movl	$1, %esi
	xorl	%ecx, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	clBuildProgram
	leaq	-44(%rbp), %r13
	movl	$.L.str.4, %esi
	movq	%r15, %rdi
	movq	%r13, %rdx
	callq	clCreateKernel
	movq	%rax, %r12
	cmpl	$0, (%r13)
	je	.LBB0_12
# %bb.11:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_12:
	movq	$1024, -88(%rbp)                # imm = 0x400
	movq	$0, -80(%rbp)
	xorl	%eax, %eax
.LBB0_13:                               # =>This Inner Loop Header: Depth=1
	movl	$1092616192, -4240(%rbp,%rax,4) # imm = 0x41200000
	incq	%rax
	cmpq	$1024, %rax                     # imm = 0x400
	jne	.LBB0_13
# %bb.14:
	leaq	-44(%rbp), %r15
	movl	$1, %esi
	movl	$4096, %edx                     # imm = 0x1000
	movq	%rbx, %rdi
	xorl	%ecx, %ecx
	movq	%r15, %r8
	callq	clCreateBuffer
	movq	%rax, %r13
	movq	%rax, -56(%rbp)
	cmpl	$0, (%r15)
	je	.LBB0_16
# %bb.15:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_16:
	subq	$32, %rsp
	xorps	%xmm0, %xmm0
	movups	%xmm0, 8(%rsp)
	movl	$0, (%rsp)
	leaq	-4240(%rbp), %r9
	movl	$4096, %r8d                     # imm = 0x1000
	movq	%r14, %rdi
	movq	%r13, %rsi
	movl	$1, %edx
	xorl	%ecx, %ecx
	callq	clEnqueueWriteBuffer
	addq	$32, %rsp
	movl	%eax, -44(%rbp)
	testl	%eax, %eax
	je	.LBB0_18
# %bb.17:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$19, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_18:
	xorl	%r13d, %r13d
	leaq	-56(%rbp), %rcx
	movl	$8, %edx
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	clSetKernelArg
	movl	%eax, -44(%rbp)
	testl	%eax, %eax
	je	.LBB0_20
# %bb.19:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB0_20:
	movq	-64(%rbp), %rsi
	leaq	-80(%rbp), %r15
	movl	$8, %ecx
	movq	%r12, %rdi
	movl	$4528, %edx                     # imm = 0x11B0
	movq	%r15, %r8
	xorl	%r9d, %r9d
	callq	clGetKernelWorkGroupInfo
	subq	$32, %rsp
	xorps	%xmm0, %xmm0
	movups	%xmm0, 8(%rsp)
	movl	%r13d, (%rsp)
	leaq	-88(%rbp), %r8
	movq	%r14, %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	xorl	%ecx, %ecx
	movq	%r15, %r9
	callq	clEnqueueNDRangeKernel
	addq	$32, %rsp
	movq	-56(%rbp), %rsi
	subq	$32, %rsp
	xorps	%xmm0, %xmm0
	movups	%xmm0, 8(%rsp)
	movl	%r13d, (%rsp)
	leaq	-8336(%rbp), %r9
	movl	$4096, %r8d                     # imm = 0x1000
	movq	%r14, %rdi
	movl	$1, %edx
	xorl	%ecx, %ecx
	callq	clEnqueueReadBuffer
	addq	$32, %rsp
.LBB0_21:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	-8336(%rbp,%r13,4), %xmm0
	movl	$.L.str.9, %edi
	movl	%r13d, %esi
	movb	$1, %al
	callq	printf
	incq	%r13
	cmpq	$1024, %r13                     # imm = 0x400
	jne	.LBB0_21
# %bb.22:
	movq	%r14, %rdi
	callq	clFinish
	movq	-56(%rbp), %rdi
	callq	clReleaseMemObject
	movq	-72(%rbp), %rdi                 # 8-byte Reload
	callq	clReleaseProgram
	movq	%r12, %rdi
	callq	clReleaseKernel
	movq	%r14, %rdi
	callq	clReleaseCommandQueue
	movq	%rbx, %rdi
	callq	clReleaseContext
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"__kernel void sum( __global float * input) \n{\t\t\t\t\t\t\t\t\t\t\n\tint i = get_global_id(0);\t\t\t\n\tinput[i] = input[i] + i;\t\t\t\n}"
	.size	.L.str, 117

	.type	source,@object                  # @source
	.data
	.globl	source
	.p2align	3, 0x0
source:
	.quad	.L.str
	.size	source, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Create context from type failed"
	.size	.L.str.1, 32

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Create command queue with properties failed"
	.size	.L.str.2, 44

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Create program with source failed"
	.size	.L.str.3, 34

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Create kernel failed"
	.size	.L.str.5, 21

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Create buffer failed"
	.size	.L.str.6, 21

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Write buffer failed"
	.size	.L.str.7, 20

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Set arg kernel failed"
	.size	.L.str.8, 22

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"result[%d] = %f\n"
	.size	.L.str.9, 17

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.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 source
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
