#include "GalaxyCollision.cuh"

__device__ int doPrint = 0;

__device__
float3 bodiesInteraction2(float4 body1, float4 body2, float3 acceleration)
{
    float EPS2 = 0.1f;
    float3 r;

    r.x = body2.x - body1.x;
    r.y = body2.y - body1.y;
    r.z = body2.z - body1.z;

    // distSqr = dot(r_ij, r_ij) + EPS^2  [6 FLOPS]
    float distSqr = sqrtf(r.x * r.x + r.y * r.y + r.z * r.z);
    distSqr *= distSqr;
    distSqr += EPS2;

    // invDistCube =1/distSqr^(3/2)  [4 FLOPS (2 mul, 1 sqrt, 1 inv)]
    float distSixth = distSqr * distSqr * distSqr;
    float invDistCube = 1.0f / sqrtf(distSixth);

    // s = m_j * invDistCube [1 FLOP]
    float s = body2.w * invDistCube;

    acceleration.x += r.x * s;
    acceleration.y += r.y * s;
    acceleration.z += r.z * s;

    return acceleration;
}

__device__
float3 bodiesInteraction(float4 body1, float4 body2, float3 acceleration)
{
    int tid = blockIdx.x * blockDim.x + threadIdx.x;

    float EPS2 = 0.01f;
    float ep = 1.0f;

    float3 r;
    r.x = body2.x - body1.x;
    r.y = body2.y - body1.y;
    r.z = body2.z - body1.z;

    float distSqr = (r.x * r.x) + (r.y * r.y) + (r.z * r.z);
    //distSqr *= distSqr;
    distSqr += EPS2;

    float dist = sqrtf(distSqr);
    float distCube = dist * dist * dist;

    float s = (body2.w) / distCube;

    acceleration.x += r.x * s * ep;
    acceleration.y += r.y * s * ep;
    acceleration.z += r.z * s * ep;
/*
    if(tid == 0 && r.y > 10.0)
    {
        doPrint = 99;
        printf("\n");

        printf("body1.w: %lf \n", body1.w);
        printf("body2.w: %lf \n", body2.w);

        printf("\n");

        printf("r.x: %lf \n", r.x);
        printf("r.y: %lf \n", r.y);
        printf("r.z: %lf \n", r.z);

        printf("\n");

        printf("distSqr: %lf \n", distSqr);
        printf("dist: %lf \n", dist);
        printf("distCube: %lf \n", distCube);
        printf("s: %lf \n", s);

        printf("\n");

        printf("acc.x: %lf \n", acceleration.x);
        printf("acc.y: %lf \n", acceleration.y);
        printf("acc.z: %lf \n", acceleration.z);
    }
*/
    return acceleration;
}

__device__
float3 tileAcceleration(float4 currPosition, float3 acceleration)
{
    int i;
    extern __shared__ float4 shPosition[];
    for (i = 0; i < blockDim.x; i++) {
        acceleration = bodiesInteraction(currPosition, shPosition[i], acceleration);
    }
    return acceleration;
}

__global__
void calculateForcesKernel(float4* bodyDescription, float3* acceleration, int size)
{
    int tid = blockIdx.x * blockDim.x + threadIdx.x;
    if (tid < size)
    {
        extern __shared__ float4 shPosition[];

        float4 currPosition;
        float3 acc = { 0.0f, 0.0f, 0.0f };

        int i, tile;

        currPosition = bodyDescription[tid];
        for (i = 0, tile = 0; i < size; i += blockDim.x, tile++)
        {
            int idx = tile * blockDim.x + threadIdx.x;
            if (idx < size){
                shPosition[threadIdx.x] = bodyDescription[idx];
                __syncthreads();
                acc = tileAcceleration(currPosition, acc);
                __syncthreads();
            }

        }

        // Save the result in global memory for the integration step.
        acceleration[tid] = acc;
    }
}

__host__
void galaxyCollisionLogic(float4* d_bodyDescription, float3* d_acceleration, int size)
{
    double4 test;
    dim3 DimGrid((size / MAX_BLOCK_THREAD_COUNT) + 1, 1, 1);
    dim3 DimBlock(MAX_BLOCK_THREAD_COUNT, 1, 1);

    //printf("DimGrid: x: %d, y: %d, z: %d \n", DimGrid.x, DimGrid.y, DimGrid.z);
    //printf("DimBlock: x: %d, y: %d, z: %d \n\n", DimBlock.x, DimBlock.y, DimBlock.z);

    calculateForcesKernel << <DimGrid, DimBlock, MAX_BLOCK_THREAD_COUNT * sizeof(float4)>> >
        (d_bodyDescription, d_acceleration, size);

    cudaDeviceSynchronize();

    doPrint = 0;
}

__host__
void galaxyCollisionInit(float4* bodyDescription, float3* acceleration, int count)
{
    float4* d_bodyDescription;
    float3* d_acceleration;

    int sizef3 = count * sizeof(float3);
    int sizef4 = count * sizeof(float4);

    cudaError_t err;

    /*********** MEMORY ALLOCATION ***********/
    if ((err = cudaMalloc((void**)&d_bodyDescription, sizef4)) != cudaSuccess) C_ERR(err);
    if ((err = cudaMalloc((void**)&d_acceleration, sizef3)) != cudaSuccess) C_ERR(err);

    /*********** COPY MEMORY TO DEVICE ***********/
    if ((err = cudaMemcpy(d_bodyDescription, bodyDescription, sizef4, cudaMemcpyHostToDevice)) != cudaSuccess) C_ERR(err);
    //if ((err = cudaMemcpy(d_acceleration, acceleration, sizef3, cudaMemcpyHostToDevice)) != cudaSuccess) ERR(err);

    // Work
    galaxyCollisionLogic(d_bodyDescription, d_acceleration, count);

    /*********** COPY MEMORY BACK TO HOST ***********/
    if ((err = cudaMemcpy(acceleration, d_acceleration, sizef3, cudaMemcpyDeviceToHost)) != cudaSuccess) C_ERR(err);

    /*********** FREE MEMORY ***********/
    if ((err = cudaFree(d_bodyDescription)) != cudaSuccess) C_ERR(err);
    if ((err = cudaFree(d_acceleration)) != cudaSuccess) C_ERR(err);

    // Update galaxies ...
    /*
    for (int i = 0; i < count; i+=100)
    {
        printf("Acc: %lf, %lf, %lf\n", acceleration[i].x, acceleration[i].y, acceleration[i].z);
    }*/

    // Init the body description - position and mass
}

	.file	"tmpxft_003b2df9_00000000-6_GalaxyCollision.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z18bodiesInteraction26float4S_6float3
	.type	_Z18bodiesInteraction26float4S_6float3, @function
_Z18bodiesInteraction26float4S_6float3:
.LFB2176:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movl	$1, 28(%rsp)
	movl	28(%rsp), %edi
	movq	%xmm4, (%rsp)
	movss	%xmm5, 8(%rsp)
	call	exit@PLT
	.cfi_endproc
.LFE2176:
	.size	_Z18bodiesInteraction26float4S_6float3, .-_Z18bodiesInteraction26float4S_6float3
	.globl	_Z17bodiesInteraction6float4S_6float3
	.type	_Z17bodiesInteraction6float4S_6float3, @function
_Z17bodiesInteraction6float4S_6float3:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movl	$1, 28(%rsp)
	movl	28(%rsp), %edi
	movq	%xmm4, (%rsp)
	movss	%xmm5, 8(%rsp)
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z17bodiesInteraction6float4S_6float3, .-_Z17bodiesInteraction6float4S_6float3
	.globl	_Z16tileAcceleration6float46float3
	.type	_Z16tileAcceleration6float46float3, @function
_Z16tileAcceleration6float46float3:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movl	$1, 28(%rsp)
	movl	28(%rsp), %edi
	movq	%xmm2, (%rsp)
	movss	%xmm3, 8(%rsp)
	call	exit@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z16tileAcceleration6float46float3, .-_Z16tileAcceleration6float46float3
	.globl	_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i
	.type	_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i, @function
_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z21calculateForcesKernelP6float4P6float3i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L8:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i, .-_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i
	.globl	_Z21calculateForcesKernelP6float4P6float3i
	.type	_Z21calculateForcesKernelP6float4P6float3i, @function
_Z21calculateForcesKernelP6float4P6float3i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i
	.cfi_endproc
.LFE2057:
	.size	_Z21calculateForcesKernelP6float4P6float3i, .-_Z21calculateForcesKernelP6float4P6float3i
	.globl	_Z20galaxyCollisionLogicP6float4P6float3i
	.type	_Z20galaxyCollisionLogicP6float4P6float3i, @function
_Z20galaxyCollisionLogicP6float4P6float3i:
.LFB2030:
	.cfi_startproc
	endbr64
	movl	%edx, %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$512, %ecx
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	xorl	%r9d, %r9d
	movl	$8192, %r8d
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edx, %ebx
	cltd
	idivl	%ecx
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	movl	$8388609, %edx
	movl	$1, %ecx
	salq	$9, %rdx
	incl	%eax
	movl	%eax, 8(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	_Z56__device_stub__Z21calculateForcesKernelP6float4P6float3iP6float4P6float3i
.L15:
	call	cudaDeviceSynchronize@PLT
	xorl	%eax, %eax
	movl	%eax, _ZL7doPrint(%rip)
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z20galaxyCollisionLogicP6float4P6float3i, .-_Z20galaxyCollisionLogicP6float4P6float3i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/Jakub-Ciecierski/GalaxyCollisionCUDA/master/src/cuda/GalaxyCollision.cu"
.LC1:
	.string	"%s in %s at line %d\n"
	.text
	.globl	_Z19galaxyCollisionInitP6float4P6float3i
	.type	_Z19galaxyCollisionInitP6float4P6float3i, @function
_Z19galaxyCollisionInitP6float4P6float3i:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	sall	$4, %r12d
	imull	$12, %edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movslq	%r12d, %r12
	movl	%edx, %ebx
	movq	%r12, %rsi
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L18
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$163, %r8d
	movq	%rax, %rdx
	jmp	.L26
.L18:
	movslq	%ebp, %rbp
	leaq	16(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L19
	call	cudaGetErrorString@PLT
	movl	$164, %r8d
	movq	%rax, %rdx
.L26:
	movl	$2, %edi
	leaq	.LC0(%rip), %rcx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L19:
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	movl	$167, %r8d
	movq	%rax, %rdx
	jmp	.L26
.L20:
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z20galaxyCollisionLogicP6float4P6float3i
	movq	16(%rsp), %rsi
	movq	%r13, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	movl	$174, %r8d
	movq	%rax, %rdx
	jmp	.L26
.L21:
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	movl	$177, %r8d
	movq	%rax, %rdx
	jmp	.L26
.L22:
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	movl	$178, %r8d
	movq	%rax, %rdx
	jmp	.L26
.L17:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z19galaxyCollisionInitP6float4P6float3i, .-_Z19galaxyCollisionInitP6float4P6float3i
	.section	.rodata.str1.1
.LC2:
	.string	"_Z21calculateForcesKernelP6float4P6float3i"
.LC3:
	.string	"doPrint"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC2(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z21calculateForcesKernelP6float4P6float3i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL7doPrint(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2059:
	.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
	.local	_ZL7doPrint
	.comm	_ZL7doPrint,4,4
	.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:

#ifndef _SHORTEST_CUDA_H_
#define _SHORTEST_CUDA_H_

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "hip/hip_runtime.h"


#define MAX_GRID_DIM_SIZE 65535

#define MAX_BLOCK_THREAD_COUNT 512

#define MAX_BLOCK_DIM_SIZE 32

#define C_ERR(err) (printf("%s in %s at line %d\n", hipGetErrorString(err), __FILE__, __LINE__),\
                    exit(EXIT_FAILURE))

__device__
float3 bodiesInteraction(float4 body1, float4 body2, float3 acceleration);

__device__
float3 tileAcceleration(float4 currPosition, float3 acceleration);

__global__
void calculateForcesKernel(float4* bodyDescription, float3* acceleration, int n);

__host__
void galaxyCollisionLogic(float4* d_bodyDescription, float3* d_acceleration, int n);

__host__
void galaxyCollisionInit(float4* bodyDescription, float3* acceleration, int count);

#endif

	.text
	.file	"GalaxyCollision.hip"
	.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 __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
