#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>

#include <cstdio>

constexpr size_t BLOCKSIZE_x = 16;
constexpr size_t BLOCKSIZE_y = 16;

constexpr size_t N = 32;
constexpr size_t M = 16;
constexpr size_t W = 4;

//////////////////
// cuda_err_chk //
//////////////////

#define cuda_err_chk(ans)                                                      \
    {                                                                          \
        gpu_assert((ans), __FILE__, __LINE__);                                 \
    }

inline void gpu_assert(cudaError_t code, char const* file, int line)
{
    if (code != cudaSuccess)
    {
        fprintf(stderr, "assert failed: %s %s %dn", cudaGetErrorString(code),
            file, line);

        abort();
    }
}

//////////////
// i_div_up //
//////////////

int i_div_up(int a, int b)
{
    return ((a % b) != 0) ? (a / b + 1) : (a / b);
}

////////////////////
// test_kernel_3d //
////////////////////

__global__ void test_kernel_3d(cudaPitchedPtr dev_pitched_ptr)
{
    int tid_x = blockIdx.x * blockDim.x + threadIdx.x;
    int tid_y = blockIdx.y * blockDim.y + threadIdx.y;

    char* d_ptr = (char*) dev_pitched_ptr.ptr;
    size_t pitch = dev_pitched_ptr.pitch;
    size_t slice_pitch = pitch * N;

    for (int w = 0; w < W; ++w)
    {
        char* slice = d_ptr + w * slice_pitch;
        double* row = (double*) (slice + tid_y * pitch);
        row[tid_x] = row[tid_x] * row[tid_x];
    }
}

//////////
// main //
//////////

int main()
{
    double a[N][M][W];

    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < M; ++j)
        {
            for (int w = 0; w < W; ++w)
            {
                a[i][j][w] = 3.f;
                //printf("row %i column %i depth %i value %f n", i, j, w, a[i][j][w]);
            }
        }
    }

    cudaExtent extent = make_cudaExtent(M * sizeof(double), N, W);

    cudaPitchedPtr d_pitched_ptr;

    cuda_err_chk(cudaMalloc3D(&d_pitched_ptr, extent));

    cudaMemcpy3DParms p = {0};

    p.srcPtr.ptr = a;
    p.srcPtr.pitch = M * sizeof(double);
    p.srcPtr.xsize = M;
    p.srcPtr.ysize = N;
    p.dstPtr.ptr = d_pitched_ptr.ptr;
    p.dstPtr.pitch = d_pitched_ptr.pitch;
    p.dstPtr.xsize = M;
    p.dstPtr.ysize = N;
    p.extent.width = M * sizeof(double);
    p.extent.height = N;
    p.extent.depth = W;
    p.kind = cudaMemcpyHostToDevice;

    cuda_err_chk(cudaMemcpy3D(&p));

    dim3 grid_size(i_div_up(M, BLOCKSIZE_x), i_div_up(N, BLOCKSIZE_y));

    dim3 block_size(BLOCKSIZE_y, BLOCKSIZE_x);

    test_kernel_3d<<<grid_size, block_size>>>(d_pitched_ptr);

    cuda_err_chk(cudaPeekAtLastError());

    cuda_err_chk(cudaDeviceSynchronize());

    p.srcPtr.ptr = d_pitched_ptr.ptr;
    p.srcPtr.pitch = d_pitched_ptr.pitch;
    p.dstPtr.ptr = a;
    p.dstPtr.pitch = M * sizeof(double);
    p.kind = cudaMemcpyDeviceToHost;

    cuda_err_chk(cudaMemcpy3D(&p));

    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < M; ++j)
        {
            for (int w = 0; w < W; ++w)
            {
                printf("row %3i column %3i depth %3i value %f\n", i, j, w,
                    a[i][j][w]);
            }
        }
    }

    return 0;
}

	.file	"tmpxft_002ab15a_00000000-6_scratchpad-04.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z10gpu_assert9cudaErrorPKci.str1.1,"aMS",@progbits,1
.LC0:
	.string	"assert failed: %s %s %dn"
	.section	.text._Z10gpu_assert9cudaErrorPKci,"axG",@progbits,_Z10gpu_assert9cudaErrorPKci,comdat
	.weak	_Z10gpu_assert9cudaErrorPKci
	.type	_Z10gpu_assert9cudaErrorPKci, @function
_Z10gpu_assert9cudaErrorPKci:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	abort@PLT
.L2:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10gpu_assert9cudaErrorPKci, .-_Z10gpu_assert9cudaErrorPKci
	.text
	.globl	_Z8i_div_upii
	.type	_Z8i_div_upii, @function
_Z8i_div_upii:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	cltd
	idivl	%esi
	cmpl	$1, %edx
	sbbl	$-1, %eax
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z8i_div_upii, .-_Z8i_div_upii
	.globl	_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr
	.type	_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr, @function
_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr:
.LFB2054:
	.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	.L12
	pushq	8(%rsp)
	.cfi_def_cfa_offset 104
	leaq	_Z14test_kernel_3d14cudaPitchedPtr(%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
.L12:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$88, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr, .-_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr
	.globl	_Z14test_kernel_3d14cudaPitchedPtr
	.type	_Z14test_kernel_3d14cudaPitchedPtr, @function
_Z14test_kernel_3d14cudaPitchedPtr:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	16(%rsp), %rdi
	call	_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z14test_kernel_3d14cudaPitchedPtr, .-_Z14test_kernel_3d14cudaPitchedPtr
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/parsa/octorad/master/scratchpad/scratchpad-04.cu"
.LC3:
	.string	"row %3i column %3i depth %3i value %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	leaq	-16384(%rsp), %r11
	.cfi_def_cfa 11, 16440
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$312, %rsp
	.cfi_def_cfa_offset 16752
	movsd	.LC1(%rip), %xmm0
	movq	%fs:40, %rax
	movq	%rax, 16680(%rsp)
	xorl	%eax, %eax
	leaq	296(%rsp), %rbx
	leaq	16680(%rsp), %rcx
	movq	%rbx, %rdx
.L19:
	movq	%rdx, %rax
	movl	$16, %r12d
.L20:
	movsd	%xmm0, (%rax)
	addq	$32, %rax
	movsd	%xmm0, -24(%rax)
	movsd	%xmm0, -16(%rax)
	movsd	%xmm0, -8(%rax)
	decl	%r12d
	jne	.L20
	addq	$512, %rdx
	cmpq	%rcx, %rdx
	jne	.L19
	movq	$128, 48(%rsp)
	leaq	72(%rsp), %rdi
	subq	$32, %rsp
	.cfi_def_cfa_offset 16784
	leaq	.LC2(%rip), %rbp
	movq	$32, 88(%rsp)
	movq	$4, 96(%rsp)
	movups	80(%rsp), %xmm1
	movq	$4, 16(%rsp)
	movups	%xmm1, (%rsp)
	call	cudaMalloc3D@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16752
	movl	$88, %edx
	movq	%rbp, %rsi
	movl	%eax, %edi
	call	_Z10gpu_assert9cudaErrorPKci
	movl	%r12d, %eax
	movl	$40, %ecx
	leaq	136(%rsp), %rdi
	rep stosl
	movq	72(%rsp), %rax
	leaq	136(%rsp), %r12
	movq	%rbx, 168(%rsp)
	movq	$128, 176(%rsp)
	movq	%r12, %rdi
	movq	%rax, 232(%rsp)
	movq	80(%rsp), %rax
	movq	$16, 184(%rsp)
	movq	$32, 192(%rsp)
	movq	%rax, 240(%rsp)
	movq	$16, 248(%rsp)
	movq	$32, 256(%rsp)
	movq	$128, 264(%rsp)
	movq	$32, 272(%rsp)
	movq	$4, 280(%rsp)
	movl	$1, 288(%rsp)
	call	cudaMemcpy3D@PLT
	movl	$105, %edx
	movq	%rbp, %rsi
	movl	%eax, %edi
	call	_Z10gpu_assert9cudaErrorPKci
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$8589934593, %rdi
	movl	$1, %esi
	movabsq	$68719476752, %rdx
	movl	$1, 32(%rsp)
	movq	%rdi, 24(%rsp)
	movq	%rdx, 36(%rsp)
	movl	$1, 44(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	movups	72(%rsp), %xmm2
	movups	88(%rsp), %xmm3
	leaq	104(%rsp), %rdi
	movups	%xmm2, 104(%rsp)
	movups	%xmm3, 120(%rsp)
	call	_Z48__device_stub__Z14test_kernel_3d14cudaPitchedPtrR14cudaPitchedPtr
.L22:
	call	cudaPeekAtLastError@PLT
	movl	$113, %edx
	movq	%rbp, %rsi
	xorl	%r13d, %r13d
	movl	%eax, %edi
	leaq	.LC3(%rip), %r15
	call	_Z10gpu_assert9cudaErrorPKci
	call	cudaDeviceSynchronize@PLT
	movl	$115, %edx
	movq	%rbp, %rsi
	movl	%eax, %edi
	call	_Z10gpu_assert9cudaErrorPKci
	movq	72(%rsp), %rax
	movq	%r12, %rdi
	movq	%rbx, 232(%rsp)
	movq	$128, 240(%rsp)
	movq	%rax, 168(%rsp)
	movq	80(%rsp), %rax
	movl	$2, 288(%rsp)
	movq	%rax, 176(%rsp)
	call	cudaMemcpy3D@PLT
	movl	$123, %edx
	movq	%rbp, %rsi
	movl	%eax, %edi
	call	_Z10gpu_assert9cudaErrorPKci
.L23:
	movl	%r13d, 12(%rsp)
	movq	%rbx, %r14
	xorl	%r12d, %r12d
.L27:
	xorl	%ebp, %ebp
.L24:
	movsd	(%r14,%rbp,8), %xmm0
	movl	12(%rsp), %edx
	movl	%ebp, %r8d
	movl	%r12d, %ecx
	movq	%r15, %rsi
	movl	$2, %edi
	movb	$1, %al
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$4, %rbp
	jne	.L24
	incl	%r12d
	addq	$32, %r14
	cmpl	$16, %r12d
	jne	.L27
	incq	%r13
	addq	$512, %rbx
	cmpq	$32, %r13
	jne	.L23
	movq	16680(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$16696, %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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC4:
	.string	"_Z14test_kernel_3d14cudaPitchedPtr"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC4(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14test_kernel_3d14cudaPitchedPtr(%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
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1074266112
	.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 <cstdio>

constexpr size_t BLOCKSIZE_x = 16;
constexpr size_t BLOCKSIZE_y = 16;

constexpr size_t N = 32;
constexpr size_t M = 16;
constexpr size_t W = 4;

//////////////////
// cuda_err_chk //
//////////////////

#define cuda_err_chk(ans)                                                      \
    {                                                                          \
        gpu_assert((ans), __FILE__, __LINE__);                                 \
    }

inline void gpu_assert(hipError_t code, char const* file, int line)
{
    if (code != hipSuccess)
    {
        fprintf(stderr, "assert failed: %s %s %dn", hipGetErrorString(code),
            file, line);

        abort();
    }
}

//////////////
// i_div_up //
//////////////

int i_div_up(int a, int b)
{
    return ((a % b) != 0) ? (a / b + 1) : (a / b);
}

////////////////////
// test_kernel_3d //
////////////////////

__global__ void test_kernel_3d(hipPitchedPtr dev_pitched_ptr)
{
    int tid_x = blockIdx.x * blockDim.x + threadIdx.x;
    int tid_y = blockIdx.y * blockDim.y + threadIdx.y;

    char* d_ptr = (char*) dev_pitched_ptr.ptr;
    size_t pitch = dev_pitched_ptr.pitch;
    size_t slice_pitch = pitch * N;

    for (int w = 0; w < W; ++w)
    {
        char* slice = d_ptr + w * slice_pitch;
        double* row = (double*) (slice + tid_y * pitch);
        row[tid_x] = row[tid_x] * row[tid_x];
    }
}

//////////
// main //
//////////

int main()
{
    double a[N][M][W];

    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < M; ++j)
        {
            for (int w = 0; w < W; ++w)
            {
                a[i][j][w] = 3.f;
                //printf("row %i column %i depth %i value %f n", i, j, w, a[i][j][w]);
            }
        }
    }

    hipExtent extent = make_hipExtent(M * sizeof(double), N, W);

    hipPitchedPtr d_pitched_ptr;

    cuda_err_chk(hipMalloc3D(&d_pitched_ptr, extent));

    hipMemcpy3DParms p = {0};

    p.srcPtr.ptr = a;
    p.srcPtr.pitch = M * sizeof(double);
    p.srcPtr.xsize = M;
    p.srcPtr.ysize = N;
    p.dstPtr.ptr = d_pitched_ptr.ptr;
    p.dstPtr.pitch = d_pitched_ptr.pitch;
    p.dstPtr.xsize = M;
    p.dstPtr.ysize = N;
    p.extent.width = M * sizeof(double);
    p.extent.height = N;
    p.extent.depth = W;
    p.kind = hipMemcpyHostToDevice;

    cuda_err_chk(hipMemcpy3D(&p));

    dim3 grid_size(i_div_up(M, BLOCKSIZE_x), i_div_up(N, BLOCKSIZE_y));

    dim3 block_size(BLOCKSIZE_y, BLOCKSIZE_x);

    test_kernel_3d<<<grid_size, block_size>>>(d_pitched_ptr);

    cuda_err_chk(hipPeekAtLastError());

    cuda_err_chk(hipDeviceSynchronize());

    p.srcPtr.ptr = d_pitched_ptr.ptr;
    p.srcPtr.pitch = d_pitched_ptr.pitch;
    p.dstPtr.ptr = a;
    p.dstPtr.pitch = M * sizeof(double);
    p.kind = hipMemcpyDeviceToHost;

    cuda_err_chk(hipMemcpy3D(&p));

    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < M; ++j)
        {
            for (int w = 0; w < W; ++w)
            {
                printf("row %3i column %3i depth %3i value %f\n", i, j, w,
                    a[i][j][w]);
            }
        }
    }

    return 0;
}

	.text
	.file	"scratchpad-04.hip"
	.globl	_Z8i_div_upii                   # -- Begin function _Z8i_div_upii
	.type	_Z8i_div_upii,@function
_Z8i_div_upii:                          # @_Z8i_div_upii
	.cfi_startproc
# %bb.0:
	movl	%edi, %eax
	cltd
	idivl	%esi
	cmpl	$1, %edx
	sbbl	$-1, %eax
	retq
.Lfunc_end0:
	.size	_Z8i_div_upii, .Lfunc_end0-_Z8i_div_upii
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__test_kernel_3d13hipPitchedPtr # -- Begin function _Z29__device_stub__test_kernel_3d13hipPitchedPtr
	.type	_Z29__device_stub__test_kernel_3d13hipPitchedPtr,@function
_Z29__device_stub__test_kernel_3d13hipPitchedPtr: # @_Z29__device_stub__test_kernel_3d13hipPitchedPtr
	.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	$_Z14test_kernel_3d13hipPitchedPtr, %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_end1:
	.size	_Z29__device_stub__test_kernel_3d13hipPitchedPtr, .Lfunc_end1-_Z29__device_stub__test_kernel_3d13hipPitchedPtr
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.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	$16640, %rsp                    # imm = 0x4100
	.cfi_def_cfa_offset 16688
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	256(%rsp), %rax
	xorl	%ecx, %ecx
	movabsq	$4613937818241073152, %rdx      # imm = 0x4008000000000000
.LBB2_1:                                # %.preheader53
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_2 Depth 2
                                        #       Child Loop BB2_3 Depth 3
	movq	%rax, %rsi
	xorl	%edi, %edi
.LBB2_2:                                # %.preheader52
                                        #   Parent Loop BB2_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_3 Depth 3
	xorl	%r8d, %r8d
.LBB2_3:                                #   Parent Loop BB2_1 Depth=1
                                        #     Parent Loop BB2_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	%rdx, (%rsi,%r8,8)
	incq	%r8
	cmpq	$4, %r8
	jne	.LBB2_3
# %bb.4:                                #   in Loop: Header=BB2_2 Depth=2
	incq	%rdi
	addq	$32, %rsi
	cmpq	$16, %rdi
	jne	.LBB2_2
# %bb.5:                                #   in Loop: Header=BB2_1 Depth=1
	incq	%rcx
	addq	$512, %rax                      # imm = 0x200
	cmpq	$32, %rcx
	jne	.LBB2_1
# %bb.6:
	movq	$128, 40(%rsp)
	movq	$32, 48(%rsp)
	movl	$4, %eax
	movq	%rax, 56(%rsp)
	movq	%rax, 16(%rsp)
	movups	40(%rsp), %xmm0
	movups	%xmm0, (%rsp)
	leaq	64(%rsp), %rdi
	callq	hipMalloc3D
	testl	%eax, %eax
	jne	.LBB2_7
# %bb.9:                                # %_Z10gpu_assert10hipError_tPKci.exit
	leaq	96(%rsp), %rbx
	movl	$160, %edx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	leaq	256(%rsp), %r12
	movq	%r12, 32(%rbx)
	movl	$128, %eax
	movq	%rax, 40(%rbx)
	movl	$16, %ecx
	movq	%rcx, 48(%rbx)
	movl	$32, %edx
	movq	%rdx, 56(%rbx)
	movups	64(%rsp), %xmm0
	movups	%xmm0, 96(%rbx)
	movq	%rcx, 112(%rbx)
	movq	%rdx, 120(%rbx)
	movq	%rax, 128(%rbx)
	movq	%rdx, 136(%rbx)
	movq	$4, 144(%rbx)
	movl	$1, 152(%rbx)
	movq	%rbx, %rdi
	callq	hipMemcpy3D
	testl	%eax, %eax
	jne	.LBB2_10
# %bb.11:                               # %_Z10gpu_assert10hipError_tPKci.exit40
	movabsq	$8589934593, %rdi               # imm = 0x200000001
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_13
# %bb.12:
	movups	64(%rsp), %xmm0
	movups	80(%rsp), %xmm1
	movups	%xmm1, 16(%rsp)
	movups	%xmm0, (%rsp)
	callq	_Z29__device_stub__test_kernel_3d13hipPitchedPtr
.LBB2_13:
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB2_14
# %bb.15:                               # %_Z10gpu_assert10hipError_tPKci.exit42
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB2_16
# %bb.17:                               # %_Z10gpu_assert10hipError_tPKci.exit44
	movups	64(%rsp), %xmm0
	leaq	96(%rsp), %rdi
	movups	%xmm0, 32(%rdi)
	movq	%r12, 96(%rdi)
	movq	$128, 104(%rdi)
	movl	$2, 152(%rdi)
	callq	hipMemcpy3D
	testl	%eax, %eax
	jne	.LBB2_25
# %bb.18:                               # %.preheader51.preheader
	xorl	%ebx, %ebx
.LBB2_19:                               # %.preheader51
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_20 Depth 2
                                        #       Child Loop BB2_21 Depth 3
	movq	%r12, %r13
	xorl	%r14d, %r14d
.LBB2_20:                               # %.preheader
                                        #   Parent Loop BB2_19 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_21 Depth 3
	xorl	%r15d, %r15d
.LBB2_21:                               #   Parent Loop BB2_19 Depth=1
                                        #     Parent Loop BB2_20 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%r13,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.1, %edi
	movl	%ebx, %esi
	movl	%r14d, %edx
	movl	%r15d, %ecx
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	$4, %r15
	jne	.LBB2_21
# %bb.22:                               #   in Loop: Header=BB2_20 Depth=2
	incq	%r14
	addq	$32, %r13
	cmpq	$16, %r14
	jne	.LBB2_20
# %bb.23:                               # %_Z10gpu_assert10hipError_tPKci.exit46
                                        #   in Loop: Header=BB2_19 Depth=1
	incq	%rbx
	addq	$512, %r12                      # imm = 0x200
	cmpq	$32, %rbx
	jne	.LBB2_19
# %bb.24:
	xorl	%eax, %eax
	addq	$16640, %rsp                    # imm = 0x4100
	.cfi_def_cfa_offset 48
	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
.LBB2_7:
	.cfi_def_cfa_offset 16688
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$88, %r8d
	jmp	.LBB2_8
.LBB2_10:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$105, %r8d
	jmp	.LBB2_8
.LBB2_14:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$113, %r8d
	jmp	.LBB2_8
.LBB2_16:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$115, %r8d
	jmp	.LBB2_8
.LBB2_25:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$123, %r8d
.LBB2_8:
	xorl	%eax, %eax
	callq	fprintf
	callq	abort
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14test_kernel_3d13hipPitchedPtr, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14test_kernel_3d13hipPitchedPtr,@object # @_Z14test_kernel_3d13hipPitchedPtr
	.section	.rodata,"a",@progbits
	.globl	_Z14test_kernel_3d13hipPitchedPtr
	.p2align	3, 0x0
_Z14test_kernel_3d13hipPitchedPtr:
	.quad	_Z29__device_stub__test_kernel_3d13hipPitchedPtr
	.size	_Z14test_kernel_3d13hipPitchedPtr, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/parsa/octorad/master/scratchpad/scratchpad-04.hip"
	.size	.L.str, 112

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"row %3i column %3i depth %3i value %f\n"
	.size	.L.str.1, 39

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"assert failed: %s %s %dn"
	.size	.L.str.2, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14test_kernel_3d13hipPitchedPtr"
	.size	.L__unnamed_1, 34

	.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 _Z29__device_stub__test_kernel_3d13hipPitchedPtr
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14test_kernel_3d13hipPitchedPtr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14test_kernel_3d13hipPitchedPtr ; -- Begin function _Z14test_kernel_3d13hipPitchedPtr
	.globl	_Z14test_kernel_3d13hipPitchedPtr
	.p2align	8
	.type	_Z14test_kernel_3d13hipPitchedPtr,@function
_Z14test_kernel_3d13hipPitchedPtr:      ; @_Z14test_kernel_3d13hipPitchedPtr
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b128 s[0:3], s[0:1], 0x0
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s5, s4, 16
	s_and_b32 s4, s4, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s5, v[1:2]
	v_mad_u64_u32 v[3:4], null, s14, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v4, 31, v2
	v_mul_lo_u32 v5, s3, v2
	v_mad_u64_u32 v[0:1], null, s2, v2, s[0:1]
	s_lshl_b64 s[0:1], s[2:3], 5
	v_mul_lo_u32 v6, s2, v4
	v_ashrrev_i32_e32 v4, 31, v3
	s_mov_b32 s2, 4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 3, v[3:4]
	v_add3_u32 v1, v5, v1, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, v0, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	global_load_b64 v[2:3], v[0:1], off
	s_add_i32 s2, s2, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 0
	s_waitcnt vmcnt(0)
	v_mul_f64 v[2:3], v[2:3], v[2:3]
	global_store_b64 v[0:1], v[2:3], off
	v_add_co_u32 v0, vcc_lo, v0, s0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_cbranch_scc0 .LBB0_1
; %bb.2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14test_kernel_3d13hipPitchedPtr
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z14test_kernel_3d13hipPitchedPtr, .Lfunc_end0-_Z14test_kernel_3d13hipPitchedPtr
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 216
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 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:
      - .offset:         0
        .size:           32
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14test_kernel_3d13hipPitchedPtr
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14test_kernel_3d13hipPitchedPtr.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
