#include <stdio.h>


#define CUDA_CHECK_RETURN( value ) {                                            \
    cudaError_t _m_cudaStat = value;                                        \
    if ( _m_cudaStat != cudaSuccess ) {                                     \
        fprintf( stderr, "Error '%s' at line %d in file %s\n",                  \
                cudaGetErrorString( _m_cudaStat ), __LINE__, __FILE__ );        \
        exit( 1 );                                                          \
    } }


//
void bandwidthTest( int gpu1, int gpu2, size_t memSize )
{
    printf( "Bandwidth test between " );
    float measuredTime = 0.0f;
    float bandwidthPeerAccessDisabled = 0.0f;
    float bandwidthPeerAccessEnabled = 0.0f;
    cudaEvent_t start, stop;
    cudaDeviceProp deviceProp;

    // alloc host memory
    unsigned char* h_array = new unsigned char[ memSize ];
    for( size_t i = 0; i < memSize; i++ )
        h_array[ i ] = ( unsigned char )( i & 0xff );

    // set first device
    CUDA_CHECK_RETURN( cudaSetDevice( gpu1 ) );

    // get gpu1 name
    CUDA_CHECK_RETURN( cudaGetDeviceProperties( &deviceProp, gpu1 ) );
    printf("GPU%d %s and", gpu1, deviceProp.name );

    // create events
    CUDA_CHECK_RETURN( cudaEventCreate( &start ) );
    CUDA_CHECK_RETURN( cudaEventCreate( &stop ) );

    // alloc mem on gpu1
    unsigned char *d_gpu1Array;
    CUDA_CHECK_RETURN( cudaMalloc( ( void ** )&d_gpu1Array, memSize ) );
    CUDA_CHECK_RETURN( cudaMemcpy( d_gpu1Array, h_array, memSize, cudaMemcpyHostToDevice ) );

    // set second gpu
    CUDA_CHECK_RETURN( cudaSetDevice( gpu2 ) );

    // get gpu2 name
    CUDA_CHECK_RETURN( cudaGetDeviceProperties( &deviceProp, gpu1 ) );
    printf(" GPU%d %s\n", gpu2, deviceProp.name );

    // alloc mem on gpu2
    unsigned char *d_gpu2Array;
    CUDA_CHECK_RETURN( cudaMalloc( ( void ** )&d_gpu2Array, memSize ) );

    // check accessible
    int accessible = 0;
    cudaDeviceCanAccessPeer( &accessible, gpu2, gpu1 );
    printf( "   GPU%d is capable of directly accessing memory from GPU%d: %s\n", gpu2, gpu1, accessible ? "yes" : "no" );
    for( int i = 0; i < 1 + accessible; i++ )
    {
        CUDA_CHECK_RETURN( cudaSetDevice( gpu2 ) );
        if( i == 1 )
            CUDA_CHECK_RETURN( cudaDeviceEnablePeerAccess( gpu1, 0 ) );

        // return back gpu1, cause create events on it
        CUDA_CHECK_RETURN( cudaSetDevice( gpu1 ) );

        CUDA_CHECK_RETURN( cudaEventRecord( start, 0 ) );

        const size_t STEPS = 10;
        for( size_t j = 0; j < STEPS; j++ )
            CUDA_CHECK_RETURN( cudaMemcpyPeer( d_gpu2Array, gpu2, d_gpu1Array, gpu1, memSize ) );

        CUDA_CHECK_RETURN( cudaEventRecord( stop, 0 ) );

        // waiting
        CUDA_CHECK_RETURN( cudaSetDevice( gpu2 ) );
        CUDA_CHECK_RETURN( cudaDeviceSynchronize() );
        CUDA_CHECK_RETURN( cudaSetDevice( gpu1 ) );
        CUDA_CHECK_RETURN( cudaDeviceSynchronize() );

        //
        CUDA_CHECK_RETURN( cudaEventElapsedTime( &measuredTime, start, stop ) );

        //
        ( i == 0 ? bandwidthPeerAccessDisabled : bandwidthPeerAccessEnabled ) = ( 1e3f * memSize * ( float )STEPS) / ( measuredTime * ( float )( 1 << 20 ) );
    }

    printf( "   Bandwidth with enabled peer acces:  %f mb/s\n", bandwidthPeerAccessEnabled );
    printf( "   Bandwidth with disabled peer acces: %f mb/s\n", bandwidthPeerAccessDisabled );

    //
    free( h_array );
    CUDA_CHECK_RETURN( cudaEventDestroy( stop ) );
    CUDA_CHECK_RETURN( cudaEventDestroy( start ) );
    CUDA_CHECK_RETURN( cudaFree( d_gpu1Array ) );

    CUDA_CHECK_RETURN( cudaSetDevice( gpu2 ) );
    CUDA_CHECK_RETURN( cudaFree( d_gpu2Array) );
    if( accessible )
        CUDA_CHECK_RETURN( cudaDeviceDisablePeerAccess( gpu1 ) );
}


//
int main( int argc, char* argv[] )
{
    size_t memSize = 1 << 29;
    if( argc == 2 )
         memSize = atoi( argv[ 1 ] );

    int deviceCount;
    CUDA_CHECK_RETURN( cudaGetDeviceCount( &deviceCount ) );
    printf( "Device count: %d %u\n", deviceCount, memSize );

    for( int i = 0; i < deviceCount; i++ )
        for( int j = i + 1; j < deviceCount; j++ )
        {
            if( i == j )
                continue;

            printf( "\n" );
            bandwidthTest( i, j, memSize );
        }

    return 0;
}
	.file	"tmpxft_0022e54c_00000000-6_bandwidth.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"yes"
.LC1:
	.string	"no"
.LC3:
	.string	"Bandwidth test between "
.LC4:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/RuslanKutdusov/convexHull/master/bandwidth.cu"
.LC5:
	.string	"Error '%s' at line %d in file %s\n"
.LC6:
	.string	"GPU%d %s and"
.LC7:
	.string	" GPU%d %s\n"
.LC8:
	.string	"   GPU%d is capable of directly accessing memory from GPU%d: %s\n"
.LC12:
	.string	"   Bandwidth with enabled peer acces:  %f mb/s\n"
.LC13:
	.string	"   Bandwidth with disabled peer acces: %f mb/s\n"
	.text
	.globl	_Z13bandwidthTestiim
	.type	_Z13bandwidthTestiim, @function
_Z13bandwidthTestiim:
.LFB2027:
	.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
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	leaq	.LC3(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	movl	$2, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	subq	$1112, %rsp
	.cfi_def_cfa_offset 1168
	movq	%fs:40, %rax
	movq	%rax, 1096(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	movl	$0x00000000, 24(%rsp)
	call	_Znam@PLT
	movq	%rax, %r13
.L3:
	cmpq	%rbx, %r14
	je	.L53
	movb	%r14b, 0(%r13,%r14)
	incq	%r14
	jmp	.L3
.L53:
	movl	%ebp, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L5
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$29, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L5:
	leaq	64(%rsp), %r15
	movl	%ebp, %esi
	movq	%r15, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L6
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$32, %r8d
	movq	%rax, %rcx
.L51:
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L6:
	movq	%r15, %rcx
	movl	%ebp, %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L7
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$36, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L7:
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L8
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$37, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L8:
	leaq	48(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L9
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$41, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L9:
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rdx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L10
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$42, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L10:
	movl	%r12d, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L11
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$45, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L11:
	movq	%r15, %rdi
	movl	%ebp, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L12
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$48, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L12:
	movq	%r15, %rcx
	movl	%r12d, %edx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	56(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$53, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L13:
	xorl	%eax, %eax
	leaq	28(%rsp), %rdi
	movl	%ebp, %edx
	movl	%r12d, %esi
	movl	%eax, 28(%rsp)
	call	cudaDeviceCanAccessPeer@PLT
	cmpl	$0, 28(%rsp)
	movl	%ebp, %ecx
	movl	%r12d, %edx
	leaq	.LC0(%rip), %rax
	leaq	.LC1(%rip), %r8
	movl	$2, %edi
	cmovne	%rax, %r8
	leaq	.LC8(%rip), %rsi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	call	__printf_chk@PLT
	movl	$0x00000000, 12(%rsp)
	movl	$0x00000000, 8(%rsp)
.L15:
	cmpl	%r14d, 28(%rsp)
	jl	.L54
	movl	%r12d, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L16
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$61, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L16:
	cmpl	$1, %r14d
	jne	.L17
	movl	%ebp, %edi
	xorl	%esi, %esi
	call	cudaDeviceEnablePeerAccess@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$63, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L17:
	movl	%ebp, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L18
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$66, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L18:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L42
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$68, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L42:
	movl	$10, %r15d
.L19:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rdx
	movq	%rbx, %r8
	movl	%ebp, %ecx
	movl	%r12d, %esi
	call	cudaMemcpyPeer@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$72, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L20:
	decq	%r15
	jne	.L19
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$74, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L21:
	movl	%r12d, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$77, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L22:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$78, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L23:
	movl	%ebp, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$79, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L24:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L25
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$80, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L25:
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L26
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$83, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L26:
	testl	%r14d, %r14d
	movss	24(%rsp), %xmm2
	movss	.LC10(%rip), %xmm4
	movss	.LC11(%rip), %xmm3
	jne	.L27
	testq	%rbx, %rbx
	js	.L28
	cvtsi2ssq	%rbx, %xmm0
	jmp	.L29
.L28:
	movq	%rbx, %rax
	movq	%rbx, %rdx
	shrq	%rax
	andl	$1, %edx
	orq	%rdx, %rax
	cvtsi2ssq	%rax, %xmm0
	addss	%xmm0, %xmm0
.L29:
	mulss	.LC9(%rip), %xmm0
	mulss	%xmm3, %xmm2
	mulss	%xmm4, %xmm0
	divss	%xmm2, %xmm0
	movss	%xmm0, 8(%rsp)
	jmp	.L30
.L27:
	testq	%rbx, %rbx
	js	.L31
	cvtsi2ssq	%rbx, %xmm1
	jmp	.L32
.L31:
	movq	%rbx, %rax
	movq	%rbx, %rdx
	shrq	%rax
	andl	$1, %edx
	orq	%rdx, %rax
	cvtsi2ssq	%rax, %xmm1
	addss	%xmm1, %xmm1
.L32:
	mulss	.LC9(%rip), %xmm1
	mulss	%xmm3, %xmm2
	mulss	%xmm4, %xmm1
	divss	%xmm2, %xmm1
	movss	%xmm1, 12(%rsp)
.L30:
	incl	%r14d
	jmp	.L15
.L54:
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	8(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L34
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$94, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L34:
	movq	32(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L35
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$95, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L35:
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L36
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$96, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L36:
	movl	%r12d, %edi
	call	cudaSetDevice@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L37
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$98, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L37:
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L38
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$99, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L38:
	cmpl	$0, 28(%rsp)
	je	.L2
	movl	%ebp, %edi
	call	cudaDeviceDisablePeerAccess@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L2
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$101, %r8d
	movq	%rax, %rcx
	jmp	.L51
.L2:
	movq	1096(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$1112, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2027:
	.size	_Z13bandwidthTestiim, .-_Z13bandwidthTestiim
	.section	.rodata.str1.1
.LC14:
	.string	"Device count: %d %u\n"
.LC15:
	.string	"\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	$536870912, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jne	.L56
	movq	8(%rsi), %rdi
	call	atoi@PLT
	movslq	%eax, %rbp
.L56:
	leaq	4(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L57
	call	cudaGetErrorString@PLT
	movl	$113, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %r9
	movq	%rax, %rcx
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L57:
	movl	4(%rsp), %edx
	movq	%rbp, %rcx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	xorl	%ebx, %ebx
	leaq	.LC15(%rip), %r14
	call	__printf_chk@PLT
.L58:
	cmpl	%ebx, 4(%rsp)
	jle	.L67
	leal	1(%rbx), %r13d
	movl	%r13d, %r12d
.L59:
	cmpl	%r12d, 4(%rsp)
	jle	.L68
	cmpl	%r12d, %ebx
	je	.L60
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdx
	movl	%r12d, %esi
	movl	%ebx, %edi
	call	_Z13bandwidthTestiim
.L60:
	incl	%r12d
	jmp	.L59
.L68:
	movl	%r13d, %ebx
	jmp	.L58
.L67:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L63
	call	__stack_chk_fail@PLT
.L63:
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	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
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC9:
	.long	1148846080
	.align 4
.LC10:
	.long	1092616192
	.align 4
.LC11:
	.long	1233125376
	.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 <stdio.h>


#define CUDA_CHECK_RETURN( value ) {                                            \
    hipError_t _m_cudaStat = value;                                        \
    if ( _m_cudaStat != hipSuccess ) {                                     \
        fprintf( stderr, "Error '%s' at line %d in file %s\n",                  \
                hipGetErrorString( _m_cudaStat ), __LINE__, __FILE__ );        \
        exit( 1 );                                                          \
    } }


//
void bandwidthTest( int gpu1, int gpu2, size_t memSize )
{
    printf( "Bandwidth test between " );
    float measuredTime = 0.0f;
    float bandwidthPeerAccessDisabled = 0.0f;
    float bandwidthPeerAccessEnabled = 0.0f;
    hipEvent_t start, stop;
    hipDeviceProp_t deviceProp;

    // alloc host memory
    unsigned char* h_array = new unsigned char[ memSize ];
    for( size_t i = 0; i < memSize; i++ )
        h_array[ i ] = ( unsigned char )( i & 0xff );

    // set first device
    CUDA_CHECK_RETURN( hipSetDevice( gpu1 ) );

    // get gpu1 name
    CUDA_CHECK_RETURN( hipGetDeviceProperties( &deviceProp, gpu1 ) );
    printf("GPU%d %s and", gpu1, deviceProp.name );

    // create events
    CUDA_CHECK_RETURN( hipEventCreate( &start ) );
    CUDA_CHECK_RETURN( hipEventCreate( &stop ) );

    // alloc mem on gpu1
    unsigned char *d_gpu1Array;
    CUDA_CHECK_RETURN( hipMalloc( ( void ** )&d_gpu1Array, memSize ) );
    CUDA_CHECK_RETURN( hipMemcpy( d_gpu1Array, h_array, memSize, hipMemcpyHostToDevice ) );

    // set second gpu
    CUDA_CHECK_RETURN( hipSetDevice( gpu2 ) );

    // get gpu2 name
    CUDA_CHECK_RETURN( hipGetDeviceProperties( &deviceProp, gpu1 ) );
    printf(" GPU%d %s\n", gpu2, deviceProp.name );

    // alloc mem on gpu2
    unsigned char *d_gpu2Array;
    CUDA_CHECK_RETURN( hipMalloc( ( void ** )&d_gpu2Array, memSize ) );

    // check accessible
    int accessible = 0;
    hipDeviceCanAccessPeer( &accessible, gpu2, gpu1 );
    printf( "   GPU%d is capable of directly accessing memory from GPU%d: %s\n", gpu2, gpu1, accessible ? "yes" : "no" );
    for( int i = 0; i < 1 + accessible; i++ )
    {
        CUDA_CHECK_RETURN( hipSetDevice( gpu2 ) );
        if( i == 1 )
            CUDA_CHECK_RETURN( hipDeviceEnablePeerAccess( gpu1, 0 ) );

        // return back gpu1, cause create events on it
        CUDA_CHECK_RETURN( hipSetDevice( gpu1 ) );

        CUDA_CHECK_RETURN( hipEventRecord( start, 0 ) );

        const size_t STEPS = 10;
        for( size_t j = 0; j < STEPS; j++ )
            CUDA_CHECK_RETURN( hipMemcpyPeer( d_gpu2Array, gpu2, d_gpu1Array, gpu1, memSize ) );

        CUDA_CHECK_RETURN( hipEventRecord( stop, 0 ) );

        // waiting
        CUDA_CHECK_RETURN( hipSetDevice( gpu2 ) );
        CUDA_CHECK_RETURN( hipDeviceSynchronize() );
        CUDA_CHECK_RETURN( hipSetDevice( gpu1 ) );
        CUDA_CHECK_RETURN( hipDeviceSynchronize() );

        //
        CUDA_CHECK_RETURN( hipEventElapsedTime( &measuredTime, start, stop ) );

        //
        ( i == 0 ? bandwidthPeerAccessDisabled : bandwidthPeerAccessEnabled ) = ( 1e3f * memSize * ( float )STEPS) / ( measuredTime * ( float )( 1 << 20 ) );
    }

    printf( "   Bandwidth with enabled peer acces:  %f mb/s\n", bandwidthPeerAccessEnabled );
    printf( "   Bandwidth with disabled peer acces: %f mb/s\n", bandwidthPeerAccessDisabled );

    //
    free( h_array );
    CUDA_CHECK_RETURN( hipEventDestroy( stop ) );
    CUDA_CHECK_RETURN( hipEventDestroy( start ) );
    CUDA_CHECK_RETURN( hipFree( d_gpu1Array ) );

    CUDA_CHECK_RETURN( hipSetDevice( gpu2 ) );
    CUDA_CHECK_RETURN( hipFree( d_gpu2Array) );
    if( accessible )
        CUDA_CHECK_RETURN( hipDeviceDisablePeerAccess( gpu1 ) );
}


//
int main( int argc, char* argv[] )
{
    size_t memSize = 1 << 29;
    if( argc == 2 )
         memSize = atoi( argv[ 1 ] );

    int deviceCount;
    CUDA_CHECK_RETURN( hipGetDeviceCount( &deviceCount ) );
    printf( "Device count: %d %u\n", deviceCount, memSize );

    for( int i = 0; i < deviceCount; i++ )
        for( int j = i + 1; j < deviceCount; j++ )
        {
            if( i == j )
                continue;

            printf( "\n" );
            bandwidthTest( i, j, memSize );
        }

    return 0;
}
	.text
	.file	"bandwidth.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13bandwidthTestiim
.LCPI0_0:
	.long	0x447a0000                      # float 1000
.LCPI0_1:
	.long	0x41200000                      # float 10
.LCPI0_2:
	.long	0x49800000                      # float 1048576
	.text
	.globl	_Z13bandwidthTestiim
	.type	_Z13bandwidthTestiim,@function
_Z13bandwidthTestiim:                   # @_Z13bandwidthTestiim
	.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	$1528, %rsp                     # imm = 0x5F8
	.cfi_def_cfa_offset 1584
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r15
	movl	%esi, %ebp
	movl	%edi, %ebx
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$0, 12(%rsp)
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r14
	testq	%r15, %r15
	je	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%eax, %eax
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	%al, (%r14,%rax)
	incq	%rax
	cmpq	%rax, %r15
	jne	.LBB0_2
.LBB0_3:                                # %._crit_edge
	movl	%ebx, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_4
# %bb.6:
	leaq	56(%rsp), %rdi
	movl	%ebx, %esi
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB0_7
# %bb.8:
	leaq	56(%rsp), %rdx
	movl	$.L.str.3, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB0_9
# %bb.10:
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB0_11
# %bb.12:
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_13
# %bb.14:
	movq	24(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_15
# %bb.16:
	movl	%ebp, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_17
# %bb.18:
	leaq	56(%rsp), %rdi
	movl	%ebx, %esi
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB0_19
# %bb.20:
	leaq	56(%rsp), %rdx
	movl	$.L.str.4, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	leaq	48(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_21
# %bb.22:
	leaq	8(%rsp), %r12
	movl	$0, (%r12)
	movq	%r12, %rdi
	movl	%ebp, %esi
	movl	%ebx, %edx
	callq	hipDeviceCanAccessPeer
	cmpl	$0, (%r12)
	movl	$.L.str.7, %eax
	movl	$.L.str.6, %ecx
	cmoveq	%rax, %rcx
	movl	$.L.str.5, %edi
	movl	%ebp, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, (%r12)
	js	.LBB0_23
# %bb.24:                               # %.lr.ph231
	testq	%r15, %r15
	js	.LBB0_25
# %bb.26:                               # %.lr.ph231
	cvtsi2ss	%r15, %xmm2
	jmp	.LBB0_27
.LBB0_23:
	xorps	%xmm0, %xmm0
	xorps	%xmm1, %xmm1
	jmp	.LBB0_31
.LBB0_25:
	movq	%r15, %rax
	shrq	%rax
	movl	%r15d, %ecx
	andl	$1, %ecx
	orq	%rax, %rcx
	cvtsi2ss	%rcx, %xmm2
	addss	%xmm2, %xmm2
.LBB0_27:                               # %.lr.ph231
	mulss	.LCPI0_0(%rip), %xmm2
	mulss	.LCPI0_1(%rip), %xmm2
	xorl	%r13d, %r13d
	xorps	%xmm0, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movss	%xmm0, (%rsp)                   # 4-byte Spill
	movss	%xmm2, 16(%rsp)                 # 4-byte Spill
.LBB0_28:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_40 Depth 2
	movl	%ebp, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_29
# %bb.33:                               #   in Loop: Header=BB0_28 Depth=1
	cmpl	$1, %r13d
	jne	.LBB0_36
# %bb.34:                               #   in Loop: Header=BB0_28 Depth=1
	movl	%ebx, %edi
	xorl	%esi, %esi
	callq	hipDeviceEnablePeerAccess
	testl	%eax, %eax
	jne	.LBB0_35
.LBB0_36:                               #   in Loop: Header=BB0_28 Depth=1
	movl	%ebx, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_37
# %bb.38:                               #   in Loop: Header=BB0_28 Depth=1
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_42
# %bb.39:                               # %.preheader.preheader
                                        #   in Loop: Header=BB0_28 Depth=1
	movl	$10, %r12d
.LBB0_40:                               # %.preheader
                                        #   Parent Loop BB0_28 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	48(%rsp), %rdi
	movq	24(%rsp), %rdx
	movl	%ebp, %esi
	movl	%ebx, %ecx
	movq	%r15, %r8
	callq	hipMemcpyPeer
	testl	%eax, %eax
	jne	.LBB0_41
# %bb.43:                               #   in Loop: Header=BB0_40 Depth=2
	decq	%r12
	jne	.LBB0_40
# %bb.44:                               #   in Loop: Header=BB0_28 Depth=1
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_45
# %bb.46:                               #   in Loop: Header=BB0_28 Depth=1
	movl	%ebp, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_47
# %bb.48:                               #   in Loop: Header=BB0_28 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_49
# %bb.50:                               #   in Loop: Header=BB0_28 Depth=1
	movl	%ebx, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_51
# %bb.52:                               #   in Loop: Header=BB0_28 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_53
# %bb.54:                               #   in Loop: Header=BB0_28 Depth=1
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB0_55
# %bb.56:                               # %.cont
                                        #   in Loop: Header=BB0_28 Depth=1
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	mulss	.LCPI0_2(%rip), %xmm1
	movss	16(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	testl	%r13d, %r13d
	je	.LBB0_57
# %bb.58:                               # %.cont
                                        #   in Loop: Header=BB0_28 Depth=1
	movss	%xmm0, (%rsp)                   # 4-byte Spill
	jmp	.LBB0_59
.LBB0_57:                               #   in Loop: Header=BB0_28 Depth=1
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
.LBB0_59:                               # %.cont
                                        #   in Loop: Header=BB0_28 Depth=1
	leal	1(%r13), %eax
	cmpl	8(%rsp), %r13d
	movl	%eax, %r13d
	jl	.LBB0_28
# %bb.30:                               # %._crit_edge232.loopexit
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rsp), %xmm0                   # 4-byte Folded Reload
	xorps	%xmm1, %xmm1
	cvtss2sd	4(%rsp), %xmm1                  # 4-byte Folded Reload
.LBB0_31:                               # %._crit_edge232
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.9, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movq	%r14, %rdi
	callq	free
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB0_32
# %bb.60:
	movq	40(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB0_61
# %bb.62:
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB0_63
# %bb.64:
	movl	%ebp, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_65
# %bb.66:
	movq	48(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB0_67
# %bb.68:
	cmpl	$0, 8(%rsp)
	je	.LBB0_71
# %bb.69:
	movl	%ebx, %edi
	callq	hipDeviceDisablePeerAccess
	testl	%eax, %eax
	jne	.LBB0_70
.LBB0_71:
	addq	$1528, %rsp                     # imm = 0x5F8
	.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
.LBB0_41:
	.cfi_def_cfa_offset 1584
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$74, %ecx
.LBB0_5:
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB0_42:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$70, %ecx
	jmp	.LBB0_5
.LBB0_37:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$68, %ecx
	jmp	.LBB0_5
.LBB0_29:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$63, %ecx
	jmp	.LBB0_5
.LBB0_55:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$85, %ecx
	jmp	.LBB0_5
.LBB0_53:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$82, %ecx
	jmp	.LBB0_5
.LBB0_51:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$81, %ecx
	jmp	.LBB0_5
.LBB0_49:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$80, %ecx
	jmp	.LBB0_5
.LBB0_47:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$79, %ecx
	jmp	.LBB0_5
.LBB0_45:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$76, %ecx
	jmp	.LBB0_5
.LBB0_35:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$65, %ecx
	jmp	.LBB0_5
.LBB0_4:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$31, %ecx
	jmp	.LBB0_5
.LBB0_7:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$34, %ecx
	jmp	.LBB0_5
.LBB0_9:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$38, %ecx
	jmp	.LBB0_5
.LBB0_11:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$39, %ecx
	jmp	.LBB0_5
.LBB0_13:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$43, %ecx
	jmp	.LBB0_5
.LBB0_15:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$44, %ecx
	jmp	.LBB0_5
.LBB0_17:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$47, %ecx
	jmp	.LBB0_5
.LBB0_19:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$50, %ecx
	jmp	.LBB0_5
.LBB0_21:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$55, %ecx
	jmp	.LBB0_5
.LBB0_32:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$96, %ecx
	jmp	.LBB0_5
.LBB0_61:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$97, %ecx
	jmp	.LBB0_5
.LBB0_63:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$98, %ecx
	jmp	.LBB0_5
.LBB0_65:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$100, %ecx
	jmp	.LBB0_5
.LBB0_67:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$101, %ecx
	jmp	.LBB0_5
.LBB0_70:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$103, %ecx
	jmp	.LBB0_5
.Lfunc_end0:
	.size	_Z13bandwidthTestiim, .Lfunc_end0-_Z13bandwidthTestiim
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$536870912, %ebx                # imm = 0x20000000
	cmpl	$2, %edi
	jne	.LBB1_2
# %bb.1:
	movq	8(%rsi), %rdi
	callq	atoi
	movslq	%eax, %rbx
.LBB1_2:
	leaq	12(%rsp), %rdi
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB1_11
# %bb.3:
	movl	12(%rsp), %esi
	xorl	%r15d, %r15d
	movl	$.L.str.10, %edi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB1_4
.LBB1_6:                                # %.lr.ph20
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_8 Depth 2
	movl	%r15d, %r14d
	leal	1(%r14), %r15d
	cmpl	%eax, %r15d
	jge	.LBB1_5
# %bb.7:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_6 Depth=1
	movl	$1, %r12d
.LBB1_8:                                # %.lr.ph
                                        #   Parent Loop BB1_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	testl	%r12d, %r12d
	je	.LBB1_10
# %bb.9:                                #   in Loop: Header=BB1_8 Depth=2
	leal	(%r14,%r12), %ebp
	movl	$10, %edi
	callq	putchar@PLT
	movl	%r14d, %edi
	movl	%ebp, %esi
	movq	%rbx, %rdx
	callq	_Z13bandwidthTestiim
	movl	12(%rsp), %eax
.LBB1_10:                               #   in Loop: Header=BB1_8 Depth=2
	leal	(%r14,%r12), %ecx
	incl	%ecx
	movl	%r12d, %edx
	incl	%edx
	movl	%edx, %r12d
	cmpl	%eax, %ecx
	jl	.LBB1_8
.LBB1_5:                                # %.loopexit
                                        #   in Loop: Header=BB1_6 Depth=1
	cmpl	%eax, %r15d
	jl	.LBB1_6
.LBB1_4:                                # %._crit_edge
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
.LBB1_11:
	.cfi_def_cfa_offset 64
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$115, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Bandwidth test between "
	.size	.L.str, 24

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Error '%s' at line %d in file %s\n"
	.size	.L.str.1, 34

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/RuslanKutdusov/convexHull/master/bandwidth.hip"
	.size	.L.str.2, 109

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"GPU%d %s and"
	.size	.L.str.3, 13

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" GPU%d %s\n"
	.size	.L.str.4, 11

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"   GPU%d is capable of directly accessing memory from GPU%d: %s\n"
	.size	.L.str.5, 65

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"no"
	.size	.L.str.7, 3

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"   Bandwidth with enabled peer acces:  %f mb/s\n"
	.size	.L.str.8, 48

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"   Bandwidth with disabled peer acces: %f mb/s\n"
	.size	.L.str.9, 48

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Device count: %d %u\n"
	.size	.L.str.10, 21

	.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
