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

using namespace std;

#define ARRAY_SIZE_X 32
#define ARRAY_SIZE_Y 16
#define ARRAY_SIZE_IN_BYTES (sizeof(unsigned int) * (ARRAY_SIZE_X * ARRAY_SIZE_Y))

/*定义 const 指针(由于指针本身的值不能改变所以必须得初始化）*/
__global__ void what_is_my_id_2d_A(
	unsigned int * const block_x,
	unsigned int * const block_y,
	unsigned int * const thread,
	unsigned int * const calc_thread,
	unsigned int * const x_thread,
	unsigned int * const y_thread,
	unsigned int * const grid_dimx,
	unsigned int * const block_dimx,
	unsigned int * const grid_dimy,
	unsigned int * const block_dimy)
{	
	const unsigned int idx = (blockIdx.x * blockDim.x) + threadIdx.x; // 0~W-1
	const unsigned int idy = (blockIdx.y * blockDim.y) + threadIdx.y; // 0~H-1
	const unsigned int thread_idx = ((gridDim.x * blockDim.x) * idy) + idx; // global 

	block_x[thread_idx] = blockIdx.x;
	block_y[thread_idx] = blockIdx.y;
	thread[thread_idx] = threadIdx.x;
	calc_thread[thread_idx] = thread_idx;
	x_thread[thread_idx] = idx;
	y_thread[thread_idx] = idy;
	grid_dimx[thread_idx] = gridDim.x;
	block_dimx[thread_idx] = blockDim.x;
	grid_dimy[thread_idx] = gridDim.y;
	block_dimy[thread_idx] = blockDim.y;

}

/* Declare statically 6 arrays of ARRAY_SIZE each */
// the image is 32 x 16
unsigned int  cpu_block_x[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_block_y[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_calc_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_x_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_y_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_grid_dimx[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_block_dimx[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_grid_dimy[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_block_dimy[ARRAY_SIZE_Y][ARRAY_SIZE_X];

int main(void)
{
	/* Total thread count of one block = 2 * 64 = 128 */
	// Total thread of all grid 128*4=512
	const dim3 threads_rect(32, 4); // W=32, H=4
	const dim3 blocks_rect(1, 4); // it means W=1, H=4


	// another shape
	const dim3 threads_square(16, 8);
	const dim3 blocks_square(2, 2);

	// Declare pointers fro GPU based params
	unsigned int *  gpu_block_x;
	unsigned int *  gpu_block_y;
	unsigned int *  gpu_thread;
	unsigned int *  gpu_calc_thread;
	unsigned int *  gpu_x_thread;
	unsigned int *  gpu_y_thread;
	unsigned int *  gpu_grid_dimx;
	unsigned int *  gpu_block_dimx;
	unsigned int *  gpu_grid_dimy;
	unsigned int *  gpu_block_dimy;

	// Allocate four arrays on the GPU
	cudaMalloc((void **)&gpu_block_x, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_block_y, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_thread, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_calc_thread, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_x_thread, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_y_thread, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_grid_dimx, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_block_dimx, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_grid_dimy, ARRAY_SIZE_IN_BYTES);
	cudaMalloc((void **)&gpu_block_dimy, ARRAY_SIZE_IN_BYTES);


	// Execute the kernel
	for(int kernel=0; kernel < 2; kernel++)
	{
		switch(kernel)
		{
			case 0:
			{
				what_is_my_id_2d_A<<<blocks_rect, threads_rect>>>(
					gpu_block_x, gpu_block_y, gpu_thread, gpu_calc_thread,
					gpu_x_thread, gpu_y_thread, gpu_grid_dimx, gpu_block_dimx,
					gpu_grid_dimy, gpu_block_dimy
				);
			} break;

			case 1:
			{
				what_is_my_id_2d_A<<<blocks_square, threads_square>>>(
					gpu_block_x, gpu_block_y, gpu_thread, gpu_calc_thread,
					gpu_x_thread, gpu_y_thread, gpu_grid_dimx, gpu_block_dimx,
					gpu_grid_dimy, gpu_block_dimy
				);
			} break;

			default: exit(1); break;

		}
	}


	// copy back the gpu results to the cpu
	cudaMemcpy(cpu_block_x, gpu_block_x, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_block_y, gpu_block_y, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_thread, gpu_thread, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_calc_thread, gpu_calc_thread, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_x_thread, gpu_x_thread, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_y_thread, gpu_y_thread, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_grid_dimx, gpu_grid_dimx, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_block_dimx, gpu_block_dimx, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_grid_dimy, gpu_grid_dimy, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);
	cudaMemcpy(cpu_block_dimy, gpu_block_dimy, ARRAY_SIZE_IN_BYTES, cudaMemcpyDeviceToHost);


	// free the arrays on the GPU 
	cudaFree(gpu_block_x);
	cudaFree(gpu_block_y);
	cudaFree(gpu_thread);
	cudaFree(gpu_calc_thread);
	cudaFree(gpu_x_thread);
	cudaFree(gpu_y_thread);
	cudaFree(gpu_grid_dimx);
	cudaFree(gpu_block_dimx);
	cudaFree(gpu_grid_dimy);
	cudaFree(gpu_block_dimy);

	// print 
	for (int y=0; y <ARRAY_SIZE_Y; y++)
	{
		for (int x=0; x < ARRAY_SIZE_X; x++)
		{
			printf("CT: %d - Block_X-%d, Block_Y-%d, Thread_X-%d, Thread_Y-%d, Thread-%d,Grid_dimx-%d, Block_dimx-%d, Grid_dimy-%d, Block_dimy-%d\n",
					cpu_calc_thread[y][x], cpu_block_x[y][x], cpu_block_y[y][x], cpu_x_thread[y][x], cpu_y_thread[y][x],
			cpu_thread[y][x], cpu_grid_dimx[y][x], cpu_block_dimx[y][x], cpu_grid_dimy[y][x],cpu_block_dimy[y][x]);
		}
	}

}

	.file	"tmpxft_0026d03e_00000000-6_5.3_2d_array.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_
	.type	_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_, @function
_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_:
.LFB3660:
	.cfi_startproc
	endbr64
	subq	$248, %rsp
	.cfi_def_cfa_offset 256
	movq	256(%rsp), %rax
	movq	%rdi, 72(%rsp)
	leaq	104(%rsp), %rdi
	movq	%rsi, 64(%rsp)
	leaq	116(%rsp), %rsi
	movq	%rax, 24(%rsp)
	movq	264(%rsp), %rax
	movq	%rdx, 56(%rsp)
	leaq	88(%rsp), %rdx
	movq	%rax, 16(%rsp)
	movq	272(%rsp), %rax
	movq	%rcx, 48(%rsp)
	leaq	96(%rsp), %rcx
	movq	%rax, 8(%rsp)
	movq	280(%rsp), %rax
	movq	%r8, 40(%rsp)
	movq	%r9, 32(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	72(%rsp), %rax
	movl	$1, 112(%rsp)
	movq	%rax, 152(%rsp)
	leaq	64(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 208(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 216(%rsp)
	movq	%rsp, %rax
	movq	%rax, 224(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 104(%rsp)
	movq	%rax, 116(%rsp)
	movl	$1, 124(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	96(%rsp)
	.cfi_def_cfa_offset 264
	leaq	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_(%rip), %rdi
	pushq	96(%rsp)
	.cfi_def_cfa_offset 272
	movq	132(%rsp), %rcx
	movl	140(%rsp), %r8d
	movq	120(%rsp), %rsi
	movl	128(%rsp), %edx
	leaq	168(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 264
	popq	%rdx
	.cfi_def_cfa_offset 256
.L2:
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$248, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3660:
	.size	_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_, .-_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_
	.globl	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.type	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, @function
_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_:
.LFB3661:
	.cfi_startproc
	endbr64
	jmp	_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_
	.cfi_endproc
.LFE3661:
	.size	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, .-_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CT: %d - Block_X-%d, Block_Y-%d, Thread_X-%d, Thread_Y-%d, Thread-%d,Grid_dimx-%d, Block_dimx-%d, Grid_dimy-%d, Block_dimy-%d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$2048, %esi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$184, %rsp
	.cfi_def_cfa_offset 240
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	movabsq	$17179869216, %rax
	leaq	40(%rsp), %rdi
	movl	$1, 128(%rsp)
	movl	$1, 140(%rsp)
	movl	$1, 152(%rsp)
	movl	$1, 164(%rsp)
	movq	%rax, 120(%rsp)
	subq	$31, %rax
	movq	%rax, 132(%rsp)
	movl	$2147483649, %eax
	salq	$4, %rax
	movq	%rax, 144(%rsp)
	movabsq	$8589934594, %rax
	movq	%rax, 156(%rsp)
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	64(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	72(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	80(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	88(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	96(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	104(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	leaq	112(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	movq	120(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	128(%rsp), %ecx
	movq	132(%rsp), %rdi
	movl	140(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	pushq	112(%rsp)
	.cfi_def_cfa_offset 248
	pushq	112(%rsp)
	.cfi_def_cfa_offset 256
	pushq	112(%rsp)
	.cfi_def_cfa_offset 264
	pushq	112(%rsp)
	.cfi_def_cfa_offset 272
	movq	112(%rsp), %r9
	movq	104(%rsp), %r8
	movq	96(%rsp), %rcx
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_
	addq	$32, %rsp
	.cfi_def_cfa_offset 240
.L10:
	movl	152(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	144(%rsp), %rdx
	movq	156(%rsp), %rdi
	movl	164(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	112(%rsp)
	.cfi_def_cfa_offset 248
	pushq	112(%rsp)
	.cfi_def_cfa_offset 256
	pushq	112(%rsp)
	.cfi_def_cfa_offset 264
	pushq	112(%rsp)
	.cfi_def_cfa_offset 272
	movq	112(%rsp), %r9
	movq	104(%rsp), %r8
	movq	96(%rsp), %rcx
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_Z56__device_stub__Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_PjS_S_S_S_S_S_S_S_S_
	addq	$32, %rsp
	.cfi_def_cfa_offset 240
.L11:
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	leaq	cpu_block_x(%rip), %rbx
	movl	$2048, %edx
	movq	%rbx, %rdi
	leaq	cpu_block_y(%rip), %rbp
	leaq	cpu_thread(%rip), %r12
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$2048, %edx
	leaq	cpu_calc_thread(%rip), %r13
	leaq	cpu_x_thread(%rip), %r14
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$2048, %edx
	leaq	cpu_block_dimy(%rip), %r15
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$2048, %edx
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movq	%r14, %rdi
	movl	$2048, %edx
	call	cudaMemcpy@PLT
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movl	$2048, %edx
	leaq	cpu_y_thread(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movl	$2048, %edx
	leaq	cpu_grid_dimx(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	96(%rsp), %rsi
	movl	$2, %ecx
	movl	$2048, %edx
	leaq	cpu_block_dimx(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	104(%rsp), %rsi
	movl	$2, %ecx
	movl	$2048, %edx
	leaq	cpu_grid_dimy(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	112(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdi
	movl	$2048, %edx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%r11d, %r11d
.L15:
	movl	$32, 12(%rsp)
	movq	%r11, %r10
.L16:
	movl	(%r15,%r10), %eax
	movq	%r11, 24(%rsp)
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movl	(%rbx,%r10), %ecx
	movl	0(%r13,%r10), %edx
	pushq	%rax
	.cfi_def_cfa_offset 248
	leaq	cpu_grid_dimy(%rip), %rax
	movl	(%rax,%r10), %eax
	pushq	%rax
	.cfi_def_cfa_offset 256
	leaq	cpu_block_dimx(%rip), %rax
	movl	(%rax,%r10), %eax
	pushq	%rax
	.cfi_def_cfa_offset 264
	leaq	cpu_grid_dimx(%rip), %rax
	movl	(%rax,%r10), %eax
	pushq	%rax
	.cfi_def_cfa_offset 272
	movl	(%r12,%r10), %eax
	pushq	%rax
	.cfi_def_cfa_offset 280
	leaq	cpu_y_thread(%rip), %rax
	movl	(%rax,%r10), %eax
	pushq	%rax
	.cfi_def_cfa_offset 288
	movl	(%r14,%r10), %r9d
	xorl	%eax, %eax
	movl	0(%rbp,%r10), %r8d
	movq	%r10, 64(%rsp)
	call	__printf_chk@PLT
	movq	64(%rsp), %r10
	addq	$48, %rsp
	.cfi_def_cfa_offset 240
	movq	24(%rsp), %r11
	addq	$4, %r10
	decl	12(%rsp)
	jne	.L16
	subq	$-128, %r11
	cmpq	$2048, %r11
	jne	.L15
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$184, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE3635:
	.size	main, .-main
	.section	.rodata.str1.1
.LC1:
	.string	"_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3663:
	.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	.LC1(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_(%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
.LFE3663:
	.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	cpu_block_dimy
	.bss
	.align 32
	.type	cpu_block_dimy, @object
	.size	cpu_block_dimy, 2048
cpu_block_dimy:
	.zero	2048
	.globl	cpu_grid_dimy
	.align 32
	.type	cpu_grid_dimy, @object
	.size	cpu_grid_dimy, 2048
cpu_grid_dimy:
	.zero	2048
	.globl	cpu_block_dimx
	.align 32
	.type	cpu_block_dimx, @object
	.size	cpu_block_dimx, 2048
cpu_block_dimx:
	.zero	2048
	.globl	cpu_grid_dimx
	.align 32
	.type	cpu_grid_dimx, @object
	.size	cpu_grid_dimx, 2048
cpu_grid_dimx:
	.zero	2048
	.globl	cpu_y_thread
	.align 32
	.type	cpu_y_thread, @object
	.size	cpu_y_thread, 2048
cpu_y_thread:
	.zero	2048
	.globl	cpu_x_thread
	.align 32
	.type	cpu_x_thread, @object
	.size	cpu_x_thread, 2048
cpu_x_thread:
	.zero	2048
	.globl	cpu_calc_thread
	.align 32
	.type	cpu_calc_thread, @object
	.size	cpu_calc_thread, 2048
cpu_calc_thread:
	.zero	2048
	.globl	cpu_thread
	.align 32
	.type	cpu_thread, @object
	.size	cpu_thread, 2048
cpu_thread:
	.zero	2048
	.globl	cpu_block_y
	.align 32
	.type	cpu_block_y, @object
	.size	cpu_block_y, 2048
cpu_block_y:
	.zero	2048
	.globl	cpu_block_x
	.align 32
	.type	cpu_block_x, @object
	.size	cpu_block_x, 2048
cpu_block_x:
	.zero	2048
	.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 <iostream>
#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

#define ARRAY_SIZE_X 32
#define ARRAY_SIZE_Y 16
#define ARRAY_SIZE_IN_BYTES (sizeof(unsigned int) * (ARRAY_SIZE_X * ARRAY_SIZE_Y))

/*定义 const 指针(由于指针本身的值不能改变所以必须得初始化）*/
__global__ void what_is_my_id_2d_A(
	unsigned int * const block_x,
	unsigned int * const block_y,
	unsigned int * const thread,
	unsigned int * const calc_thread,
	unsigned int * const x_thread,
	unsigned int * const y_thread,
	unsigned int * const grid_dimx,
	unsigned int * const block_dimx,
	unsigned int * const grid_dimy,
	unsigned int * const block_dimy)
{	
	const unsigned int idx = (blockIdx.x * blockDim.x) + threadIdx.x; // 0~W-1
	const unsigned int idy = (blockIdx.y * blockDim.y) + threadIdx.y; // 0~H-1
	const unsigned int thread_idx = ((gridDim.x * blockDim.x) * idy) + idx; // global 

	block_x[thread_idx] = blockIdx.x;
	block_y[thread_idx] = blockIdx.y;
	thread[thread_idx] = threadIdx.x;
	calc_thread[thread_idx] = thread_idx;
	x_thread[thread_idx] = idx;
	y_thread[thread_idx] = idy;
	grid_dimx[thread_idx] = gridDim.x;
	block_dimx[thread_idx] = blockDim.x;
	grid_dimy[thread_idx] = gridDim.y;
	block_dimy[thread_idx] = blockDim.y;

}

/* Declare statically 6 arrays of ARRAY_SIZE each */
// the image is 32 x 16
unsigned int  cpu_block_x[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_block_y[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_calc_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_x_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_y_thread[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_grid_dimx[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_block_dimx[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_grid_dimy[ARRAY_SIZE_Y][ARRAY_SIZE_X];
unsigned int  cpu_block_dimy[ARRAY_SIZE_Y][ARRAY_SIZE_X];

int main(void)
{
	/* Total thread count of one block = 2 * 64 = 128 */
	// Total thread of all grid 128*4=512
	const dim3 threads_rect(32, 4); // W=32, H=4
	const dim3 blocks_rect(1, 4); // it means W=1, H=4


	// another shape
	const dim3 threads_square(16, 8);
	const dim3 blocks_square(2, 2);

	// Declare pointers fro GPU based params
	unsigned int *  gpu_block_x;
	unsigned int *  gpu_block_y;
	unsigned int *  gpu_thread;
	unsigned int *  gpu_calc_thread;
	unsigned int *  gpu_x_thread;
	unsigned int *  gpu_y_thread;
	unsigned int *  gpu_grid_dimx;
	unsigned int *  gpu_block_dimx;
	unsigned int *  gpu_grid_dimy;
	unsigned int *  gpu_block_dimy;

	// Allocate four arrays on the GPU
	hipMalloc((void **)&gpu_block_x, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_block_y, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_thread, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_calc_thread, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_x_thread, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_y_thread, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_grid_dimx, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_block_dimx, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_grid_dimy, ARRAY_SIZE_IN_BYTES);
	hipMalloc((void **)&gpu_block_dimy, ARRAY_SIZE_IN_BYTES);


	// Execute the kernel
	for(int kernel=0; kernel < 2; kernel++)
	{
		switch(kernel)
		{
			case 0:
			{
				what_is_my_id_2d_A<<<blocks_rect, threads_rect>>>(
					gpu_block_x, gpu_block_y, gpu_thread, gpu_calc_thread,
					gpu_x_thread, gpu_y_thread, gpu_grid_dimx, gpu_block_dimx,
					gpu_grid_dimy, gpu_block_dimy
				);
			} break;

			case 1:
			{
				what_is_my_id_2d_A<<<blocks_square, threads_square>>>(
					gpu_block_x, gpu_block_y, gpu_thread, gpu_calc_thread,
					gpu_x_thread, gpu_y_thread, gpu_grid_dimx, gpu_block_dimx,
					gpu_grid_dimy, gpu_block_dimy
				);
			} break;

			default: exit(1); break;

		}
	}


	// copy back the gpu results to the cpu
	hipMemcpy(cpu_block_x, gpu_block_x, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_block_y, gpu_block_y, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_thread, gpu_thread, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_calc_thread, gpu_calc_thread, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_x_thread, gpu_x_thread, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_y_thread, gpu_y_thread, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_grid_dimx, gpu_grid_dimx, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_block_dimx, gpu_block_dimx, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_grid_dimy, gpu_grid_dimy, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);
	hipMemcpy(cpu_block_dimy, gpu_block_dimy, ARRAY_SIZE_IN_BYTES, hipMemcpyDeviceToHost);


	// free the arrays on the GPU 
	hipFree(gpu_block_x);
	hipFree(gpu_block_y);
	hipFree(gpu_thread);
	hipFree(gpu_calc_thread);
	hipFree(gpu_x_thread);
	hipFree(gpu_y_thread);
	hipFree(gpu_grid_dimx);
	hipFree(gpu_block_dimx);
	hipFree(gpu_grid_dimy);
	hipFree(gpu_block_dimy);

	// print 
	for (int y=0; y <ARRAY_SIZE_Y; y++)
	{
		for (int x=0; x < ARRAY_SIZE_X; x++)
		{
			printf("CT: %d - Block_X-%d, Block_Y-%d, Thread_X-%d, Thread_Y-%d, Thread-%d,Grid_dimx-%d, Block_dimx-%d, Grid_dimy-%d, Block_dimy-%d\n",
					cpu_calc_thread[y][x], cpu_block_x[y][x], cpu_block_y[y][x], cpu_x_thread[y][x], cpu_y_thread[y][x],
			cpu_thread[y][x], cpu_grid_dimx[y][x], cpu_block_dimx[y][x], cpu_grid_dimy[y][x],cpu_block_dimy[y][x]);
		}
	}

}

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

                                        # End of file scope inline assembly
	.globl	_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_ # -- Begin function _Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.type	_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_,@function
_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_: # @_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.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	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	16(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	232(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	240(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	248(%rsp), %rax
	movq	%rax, 72(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	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	_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, .Lfunc_end0-_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$88, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	80(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	72(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	64(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	56(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	movabsq	$17179869185, %rdi              # imm = 0x400000001
	leaq	31(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	80(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rcx
	movq	48(%rsp), %r8
	movq	40(%rsp), %r9
	pushq	8(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	24(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	40(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB1_2:
	movabsq	$8589934594, %rdi               # imm = 0x200000002
	movabsq	$34359738384, %rdx              # imm = 0x800000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_3
# %bb.8:
	movq	80(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rcx
	movq	48(%rsp), %r8
	movq	40(%rsp), %r9
	pushq	8(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	24(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	40(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB1_3:
	movq	80(%rsp), %rsi
	movl	$cpu_block_x, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	72(%rsp), %rsi
	movl	$cpu_block_y, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rsi
	movl	$cpu_thread, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rsi
	movl	$cpu_calc_thread, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	48(%rsp), %rsi
	movl	$cpu_x_thread, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rsi
	movl	$cpu_y_thread, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rsi
	movl	$cpu_grid_dimx, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rsi
	movl	$cpu_block_dimx, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rsi
	movl	$cpu_grid_dimy, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rsi
	movl	$cpu_block_dimy, %edi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	80(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
.LBB1_4:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
	xorl	%r15d, %r15d
.LBB1_5:                                #   Parent Loop BB1_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	cpu_calc_thread(%rbx,%r15), %esi
	movl	cpu_block_x(%rbx,%r15), %edx
	movl	cpu_block_y(%rbx,%r15), %ecx
	movl	cpu_x_thread(%rbx,%r15), %r8d
	movl	cpu_y_thread(%rbx,%r15), %r9d
	movl	cpu_thread(%rbx,%r15), %r10d
	movl	cpu_grid_dimx(%rbx,%r15), %r11d
	movl	cpu_block_dimx(%rbx,%r15), %r12d
	movl	cpu_grid_dimy(%rbx,%r15), %r13d
	movl	cpu_block_dimy(%rbx,%r15), %ebp
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$.L.str, %edi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_adjust_cfa_offset 8
	pushq	%r13
	.cfi_adjust_cfa_offset 8
	pushq	%r12
	.cfi_adjust_cfa_offset 8
	pushq	%r11
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	printf
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
	addq	$4, %r15
	cmpq	$128, %r15
	jne	.LBB1_5
# %bb.6:                                #   in Loop: Header=BB1_4 Depth=1
	incq	%r14
	subq	$-128, %rbx
	cmpq	$16, %r14
	jne	.LBB1_4
# %bb.7:
	xorl	%eax, %eax
	addq	$88, %rsp
	.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	$_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, %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	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_,@object # @_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.section	.rodata,"a",@progbits
	.globl	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.p2align	3, 0x0
_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_:
	.quad	_Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.size	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, 8

	.type	cpu_block_x,@object             # @cpu_block_x
	.bss
	.globl	cpu_block_x
	.p2align	4, 0x0
cpu_block_x:
	.zero	2048
	.size	cpu_block_x, 2048

	.type	cpu_block_y,@object             # @cpu_block_y
	.globl	cpu_block_y
	.p2align	4, 0x0
cpu_block_y:
	.zero	2048
	.size	cpu_block_y, 2048

	.type	cpu_thread,@object              # @cpu_thread
	.globl	cpu_thread
	.p2align	4, 0x0
cpu_thread:
	.zero	2048
	.size	cpu_thread, 2048

	.type	cpu_calc_thread,@object         # @cpu_calc_thread
	.globl	cpu_calc_thread
	.p2align	4, 0x0
cpu_calc_thread:
	.zero	2048
	.size	cpu_calc_thread, 2048

	.type	cpu_x_thread,@object            # @cpu_x_thread
	.globl	cpu_x_thread
	.p2align	4, 0x0
cpu_x_thread:
	.zero	2048
	.size	cpu_x_thread, 2048

	.type	cpu_y_thread,@object            # @cpu_y_thread
	.globl	cpu_y_thread
	.p2align	4, 0x0
cpu_y_thread:
	.zero	2048
	.size	cpu_y_thread, 2048

	.type	cpu_grid_dimx,@object           # @cpu_grid_dimx
	.globl	cpu_grid_dimx
	.p2align	4, 0x0
cpu_grid_dimx:
	.zero	2048
	.size	cpu_grid_dimx, 2048

	.type	cpu_block_dimx,@object          # @cpu_block_dimx
	.globl	cpu_block_dimx
	.p2align	4, 0x0
cpu_block_dimx:
	.zero	2048
	.size	cpu_block_dimx, 2048

	.type	cpu_grid_dimy,@object           # @cpu_grid_dimy
	.globl	cpu_grid_dimy
	.p2align	4, 0x0
cpu_grid_dimy:
	.zero	2048
	.size	cpu_grid_dimy, 2048

	.type	cpu_block_dimy,@object          # @cpu_block_dimy
	.globl	cpu_block_dimy
	.p2align	4, 0x0
cpu_block_dimy:
	.zero	2048
	.size	cpu_block_dimy, 2048

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CT: %d - Block_X-%d, Block_Y-%d, Thread_X-%d, Thread_Y-%d, Thread-%d,Grid_dimx-%d, Block_dimx-%d, Grid_dimy-%d, Block_dimy-%d\n"
	.size	.L.str, 127

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_"
	.size	.L__unnamed_1, 43

	.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

	.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 _Z33__device_stub__what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.addrsig_sym cpu_block_x
	.addrsig_sym cpu_block_y
	.addrsig_sym cpu_thread
	.addrsig_sym cpu_calc_thread
	.addrsig_sym cpu_x_thread
	.addrsig_sym cpu_y_thread
	.addrsig_sym cpu_grid_dimx
	.addrsig_sym cpu_block_dimx
	.addrsig_sym cpu_grid_dimy
	.addrsig_sym cpu_block_dimy
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_ ; -- Begin function _Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.globl	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
	.p2align	8
	.type	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_,@function
_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_: ; @_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x5c
	s_load_b64 s[4:5], s[0:1], 0x50
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_load_b512 s[16:31], s[0:1], 0x0
	v_mov_b32_e32 v19, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s7, s2, 0xffff
	s_lshr_b32 s6, s2, 16
	v_mad_u64_u32 v[2:3], null, s14, s7, v[1:2]
	v_mad_u64_u32 v[3:4], null, s15, s6, v[0:1]
	s_mul_i32 s2, s4, s7
	v_mov_b32_e32 v0, s14
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[4:5], null, s2, v3, v[2:3]
	v_mov_b32_e32 v5, 0
	s_load_b128 s[0:3], s[0:1], 0x40
	v_lshlrev_b64 v[5:6], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, s16, v5
	v_add_co_ci_u32_e32 v8, vcc_lo, s17, v6, vcc_lo
	v_add_co_u32 v9, vcc_lo, s18, v5
	v_add_co_ci_u32_e32 v10, vcc_lo, s19, v6, vcc_lo
	v_add_co_u32 v11, vcc_lo, s20, v5
	v_add_co_ci_u32_e32 v12, vcc_lo, s21, v6, vcc_lo
	v_add_co_u32 v13, vcc_lo, s22, v5
	v_add_co_ci_u32_e32 v14, vcc_lo, s23, v6, vcc_lo
	v_add_co_u32 v15, vcc_lo, s24, v5
	v_add_co_ci_u32_e32 v16, vcc_lo, s25, v6, vcc_lo
	v_add_co_u32 v17, vcc_lo, s26, v5
	v_add_co_ci_u32_e32 v18, vcc_lo, s27, v6, vcc_lo
	global_store_b32 v[7:8], v0, off
	global_store_b32 v[9:10], v19, off
	global_store_b32 v[11:12], v1, off
	global_store_b32 v[13:14], v4, off
	global_store_b32 v[15:16], v2, off
	v_mov_b32_e32 v2, s4
	v_add_co_u32 v0, vcc_lo, s28, v5
	v_add_co_ci_u32_e32 v1, vcc_lo, s29, v6, vcc_lo
	v_add_co_u32 v7, vcc_lo, s30, v5
	v_add_co_ci_u32_e32 v8, vcc_lo, s31, v6, vcc_lo
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, vcc_lo, s0, v5
	v_add_co_ci_u32_e32 v10, vcc_lo, s1, v6, vcc_lo
	v_mov_b32_e32 v11, s7
	v_add_co_u32 v4, vcc_lo, s2, v5
	v_mov_b32_e32 v12, s5
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v6, vcc_lo
	v_mov_b32_e32 v6, s6
	global_store_b32 v[17:18], v3, off
	global_store_b32 v[0:1], v2, off
	global_store_b32 v[7:8], v11, off
	global_store_b32 v[9:10], v12, off
	global_store_b32 v[4:5], v6, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 336
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 20
		.amdhsa_next_free_sgpr 32
		.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	_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_, .Lfunc_end0-_Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 356
; NumSgprs: 34
; NumVgprs: 20
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 4
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 34
; NumVGPRsForWavesPerEU: 20
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         56
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         64
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         72
        .size:           8
        .value_kind:     global_buffer
      - .offset:         80
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         84
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         88
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         92
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         94
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         96
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         98
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         100
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         102
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         120
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         128
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         136
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         144
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 336
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     34
    .sgpr_spill_count: 0
    .symbol:         _Z18what_is_my_id_2d_APjS_S_S_S_S_S_S_S_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     20
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
