// ================================================================================================
// A simple script to get memory usage & properties of CUDA supported NVIDIA devices
//
// Author: Sivagnanam Namasivayamurthy
//
// ================================================================================================

#include <stdio.h>
#include <time.h>

// CUDA C headers
#include <cuda.h>
#include <cuda_runtime.h>

/*
 *
 */
void printCurrentTime(){
  time_t t = time(NULL);
  struct tm tm = *localtime(&t);

  printf("\n%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}

/*
 * Get number of CUDA supported devices available
 *
 * returns: the number of CUDA supported devices
 */
int getCudaDevicesCount(){

  int deviceCount;

  cudaError_t cu_err = cudaGetDeviceCount(&deviceCount);
  if(cudaSuccess != cu_err){
    printf("Unable to get cudaGetDeviceCount : error num %d - %s\n", (int) cu_err, cudaGetErrorString(cu_err));
    exit(EXIT_FAILURE);
  }
  return deviceCount;
}

/*
 * Print the number of CUDA supported devices available
 */
void printDevicesCount(){

  int deviceCount = getCudaDevicesCount();

  if(0 == deviceCount){
    printf("No CUDA supported device(s) found !!! \n");
    exit(EXIT_FAILURE);
  } else {
    printf("Found %d CUDA supported device(s)\n", deviceCount);
  }
}

/*
 * Get device properties
 *
 * deviceId : ID of the CUDA supported device

 * returns: the cudaDeviceProp struct that contains the CUDA device properties
 */
cudaDeviceProp getCudaDeviceProps(int deviceId){

  cudaDeviceProp deviceProps;

  cudaError_t cu_err = cudaGetDeviceProperties(&deviceProps, deviceId);
  if(cudaSuccess != cu_err){
    printf("Unable to get cudaGetDeviceProperties for device ID %d : error num %d - %s\n", deviceId, (int) cu_err, cudaGetErrorString(cu_err));
    exit(EXIT_FAILURE);
  }

  return deviceProps;
}

/*
 * Print the CUDA device properties
 *
 * deviceId: ID of the CUDA supported device
 */
void printCudaDeviceProps(int deviceId)
{
  cudaDeviceProp deviceProps = getCudaDeviceProps(deviceId);
  printf("\n Device ID: %d       Name:      %s\n",  deviceId, deviceProps.name);
  printf("--------------------------------------------------------------\n");
  printf("CUDA capability Major/Minor version number:         %d.%d\n",  deviceProps.major, deviceProps.minor);
  printf("Total global memory:                                %0.f MB\n", (float)deviceProps.totalGlobalMem/(1048576.0f));
  printf("Total shared memory per block:                      %lu bytes\n", deviceProps.sharedMemPerBlock);
  printf("Total registers per block:                          %d\n",  deviceProps.regsPerBlock);
  printf("Warp size:                                          %d\n",  deviceProps.warpSize);
  printf("Maximum memory pitch:                               %lu bytes\n", deviceProps.memPitch);
  printf("Maximum threads per block:                          %d\n",  deviceProps.maxThreadsPerBlock);
  printf("Maximum sizes of each dimension of a block:         %d x %d x %d \n", deviceProps.maxThreadsDim[0], deviceProps.maxThreadsDim[1], deviceProps.maxThreadsDim[2]);
  printf("Maximum sizes of each dimension of a grid:          %d x %d x %d  \n", deviceProps.maxGridSize[0], deviceProps.maxGridSize[1], deviceProps.maxGridSize[2]);
  printf("Clock rate:                                         %d\n",  deviceProps.clockRate);
  printf("Total constant memory:                              %lu\n", deviceProps.totalConstMem);
  printf("Texture alignment:                                  %lu bytes\n", deviceProps.textureAlignment);
  printf("Concurrent copy and execution:                      %s\n",  (deviceProps.deviceOverlap ? "Yes" : "No"));
  printf("Number of multiprocessors:                          %d\n",  deviceProps.multiProcessorCount);
  printf("Kernel execution timeout:                           %s\n",  (deviceProps.kernelExecTimeoutEnabled ? "Yes" : "No"));
  printf("--------------------------------------------------------------\n");
}

/*
 * Find all CUDA supported devices & print their properties
 */
void printAllCudaDeviceProps(){
  int deviceCount = getCudaDevicesCount();
  printCurrentTime();
  printf("\nFound %d CUDA supported device(s)\n", deviceCount);

  for (int deviceId = 0; deviceId < deviceCount; ++deviceId){
    printCudaDeviceProps(deviceId);
  }
}

/*
 * Print the free & used memory information of all NVIDIA CUDA supported devices
 */
void printNvidiaDevicesMemoryInfo(){

  int driverVersion, runTimeVersion, deviceCount;
  size_t mem_available, mem_free;

  cudaDriverGetVersion(&driverVersion);
  cudaRuntimeGetVersion(&runTimeVersion);
  deviceCount = getCudaDevicesCount();

  printCurrentTime();
  printf("\n+----------------------------------------------------------------------+\n");
  printf("| CUDA Driver version: %d.%d               Runtime Version: %d.%d          |\n", driverVersion/1000, (driverVersion % 100)/10, runTimeVersion/1000, (runTimeVersion%100)/10);

  for (int deviceId = 0; deviceId < deviceCount; ++deviceId){

    cudaSetDevice(deviceId);
    cudaDeviceProp deviceProps = getCudaDeviceProps(deviceId);
    cudaMemGetInfo(&mem_free, &mem_available);
    printf("+----------------------------------------------------------------------------------------+\n");
    printf("| Device ID: %d      Name: %s           %.0f MB (free) / %.0f MB (total)    |\n", deviceId, deviceProps.name, (float)mem_free/(1024*1024.), (float)mem_available/(1024*1024.));
    printf("+----------------------------------------------------------------------------------------+\n");

  }

}

int main(int argc, char *argv[])
{
  if(argc < 2) {
    printNvidiaDevicesMemoryInfo(); // Print memory information if not argument is passed
  } else {
    if (0 == strcmp(argv[1], "-mem")){
      printNvidiaDevicesMemoryInfo();
    } else if (0 == strcmp(argv[1], "-props")) {
      printAllCudaDeviceProps();
    }
  }
  return 0;
}

	.file	"tmpxft_002f58c5_00000000-6_nvidia_gpu_stats.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2037:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2037:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\n%d-%d-%d %d:%d:%d"
	.text
	.globl	_Z16printCurrentTimev
	.type	_Z16printCurrentTimev, @function
_Z16printCurrentTimev:
.LFB2027:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	xorl	%edi, %edi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	time@PLT
	movq	%rsp, %rdi
	movq	%rax, (%rsp)
	call	localtime@PLT
	movl	$2, %edi
	movl	16(%rax), %edx
	movl	(%rax), %esi
	movl	8(%rax), %r9d
	movl	12(%rax), %r8d
	leal	1(%rdx), %ecx
	movl	20(%rax), %edx
	pushq	%rsi
	.cfi_def_cfa_offset 40
	leaq	.LC0(%rip), %rsi
	movl	4(%rax), %eax
	addl	$1900, %edx
	pushq	%rax
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rdx
	.cfi_def_cfa_offset 32
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z16printCurrentTimev, .-_Z16printCurrentTimev
	.section	.rodata.str1.1
.LC1:
	.string	"Unable to get cudaGetDeviceCount : error num %d - %s\n"
	.text
	.globl	_Z19getCudaDevicesCountv
	.type	_Z19getCudaDevicesCountv, @function
_Z19getCudaDevicesCountv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	testl	%eax, %eax
	je	.L7
	movl	%eax, %edi
	movl	%eax, %ebx
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	%ebx, %edx
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L7:
	movl	4(%rsp), %eax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z19getCudaDevicesCountv, .-_Z19getCudaDevicesCountv
	.section	.rodata.str1.1
.LC2:
	.string	"No CUDA supported device(s) found !!! \n"
.LC3:
	.string	"Found %d CUDA supported device(s)\n"
	.text
	.globl	_Z17printDevicesCountv
	.type	_Z17printDevicesCountv, @function
_Z17printDevicesCountv:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rsi
	.cfi_def_cfa_offset 16
	call	_Z19getCudaDevicesCountv
	testl	%eax, %eax
	jne	.L11
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L11:
	movl	%eax, %edx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z17printDevicesCountv, .-_Z17printDevicesCountv
	.section	.rodata.str1.1
.LC4:
	.string	"Unable to get cudaGetDeviceProperties for device ID %d : error num %d - %s\n"
	.text
	.globl	_Z18getCudaDevicePropsi
	.type	_Z18getCudaDevicePropsi, @function
_Z18getCudaDevicePropsi:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	cudaGetDeviceProperties_v2@PLT
	testl	%eax, %eax
	je	.L13
	movl	%eax, %edi
	movl	%eax, %ebx
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	%ebx, %ecx
	movl	%r12d, %edx
	movq	%rax, %r8
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L13:
	movq	%rbp, %rax
	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	_Z18getCudaDevicePropsi, .-_Z18getCudaDevicePropsi
	.section	.rodata.str1.1
.LC5:
	.string	"Yes"
.LC6:
	.string	"No"
.LC7:
	.string	"\n Device ID: %d       Name:      %s\n"
.LC8:
	.string	"--------------------------------------------------------------\n"
.LC9:
	.string	"CUDA capability Major/Minor version number:         %d.%d\n"
.LC11:
	.string	"Total global memory:                                %0.f MB\n"
.LC12:
	.string	"Total shared memory per block:                      %lu bytes\n"
.LC13:
	.string	"Total registers per block:                          %d\n"
.LC14:
	.string	"Warp size:                                          %d\n"
.LC15:
	.string	"Maximum memory pitch:                               %lu bytes\n"
.LC16:
	.string	"Maximum threads per block:                          %d\n"
.LC17:
	.string	"Maximum sizes of each dimension of a block:         %d x %d x %d \n"
.LC18:
	.string	"Maximum sizes of each dimension of a grid:          %d x %d x %d  \n"
.LC19:
	.string	"Clock rate:                                         %d\n"
.LC20:
	.string	"Total constant memory:                              %lu\n"
.LC21:
	.string	"Texture alignment:                                  %lu bytes\n"
.LC22:
	.string	"Concurrent copy and execution:                      %s\n"
.LC23:
	.string	"Number of multiprocessors:                          %d\n"
.LC24:
	.string	"Kernel execution timeout:                           %s\n"
	.text
	.globl	_Z20printCudaDevicePropsi
	.type	_Z20printCudaDevicePropsi, @function
_Z20printCudaDevicePropsi:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edi, %esi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edi, %ebx
	subq	$1040, %rsp
	.cfi_def_cfa_offset 1072
	movq	%fs:40, %rax
	movq	%rax, 1032(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbp
	movq	%rbp, %rdi
	call	_Z18getCudaDevicePropsi
	movl	%ebx, %edx
	movq	%rbp, %rcx
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC8(%rip), %rbx
	call	__printf_chk@PLT
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	364(%rsp), %ecx
	movl	$2, %edi
	xorl	%eax, %eax
	movl	360(%rsp), %edx
	leaq	.LC9(%rip), %rsi
	call	__printf_chk@PLT
	movq	288(%rsp), %rax
	testq	%rax, %rax
	js	.L17
	cvtsi2ssq	%rax, %xmm0
	jmp	.L18
.L17:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2ssq	%rdx, %xmm0
	addss	%xmm0, %xmm0
.L18:
	mulss	.LC10(%rip), %xmm0
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC5(%rip), %r12
	leaq	.LC6(%rip), %rbp
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movq	296(%rsp), %rdx
	leaq	.LC12(%rip), %rsi
	call	__printf_chk@PLT
	movl	304(%rsp), %edx
	leaq	.LC13(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	308(%rsp), %edx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	312(%rsp), %rdx
	leaq	.LC15(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	320(%rsp), %edx
	leaq	.LC16(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	332(%rsp), %r8d
	xorl	%eax, %eax
	movl	328(%rsp), %ecx
	movl	324(%rsp), %edx
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	344(%rsp), %r8d
	xorl	%eax, %eax
	movl	340(%rsp), %ecx
	movl	336(%rsp), %edx
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	348(%rsp), %edx
	leaq	.LC19(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	352(%rsp), %rdx
	leaq	.LC20(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	368(%rsp), %rdx
	leaq	.LC21(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpl	$0, 384(%rsp)
	movq	%r12, %rdx
	leaq	.LC22(%rip), %rsi
	cmove	%rbp, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	388(%rsp), %edx
	leaq	.LC23(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpl	$0, 392(%rsp)
	movq	%r12, %rdx
	leaq	.LC24(%rip), %rsi
	cmove	%rbp, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	1032(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$1040, %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
.LFE2031:
	.size	_Z20printCudaDevicePropsi, .-_Z20printCudaDevicePropsi
	.section	.rodata.str1.1
.LC25:
	.string	"\nFound %d CUDA supported device(s)\n"
	.text
	.globl	_Z23printAllCudaDevicePropsv
	.type	_Z23printAllCudaDevicePropsv, @function
_Z23printAllCudaDevicePropsv:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rdx
	.cfi_def_cfa_offset 32
	call	_Z19getCudaDevicesCountv
	movl	%eax, %ebx
	call	_Z16printCurrentTimev
	movl	%ebx, %edx
	leaq	.LC25(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
.L26:
	cmpl	%ebx, %ebp
	jge	.L29
	movl	%ebp, %edi
	incl	%ebp
	call	_Z20printCudaDevicePropsi
	jmp	.L26
.L29:
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z23printAllCudaDevicePropsv, .-_Z23printAllCudaDevicePropsv
	.section	.rodata.str1.1
.LC26:
	.string	"\n+----------------------------------------------------------------------+\n"
.LC27:
	.string	"| CUDA Driver version: %d.%d               Runtime Version: %d.%d          |\n"
.LC28:
	.string	"+----------------------------------------------------------------------------------------+\n"
.LC30:
	.string	"| Device ID: %d      Name: %s           %.0f MB (free) / %.0f MB (total)    |\n"
	.text
	.globl	_Z28printNvidiaDevicesMemoryInfov
	.type	_Z28printNvidiaDevicesMemoryInfov, @function
_Z28printNvidiaDevicesMemoryInfov:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC28(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	subq	$1080, %rsp
	.cfi_def_cfa_offset 1120
	movq	%fs:40, %rax
	movq	%rax, 1064(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaDriverGetVersion@PLT
	leaq	12(%rsp), %rdi
	call	cudaRuntimeGetVersion@PLT
	call	_Z19getCudaDevicesCountv
	movl	%eax, %ebp
	call	_Z16printCurrentTimev
	leaq	.LC26(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	12(%rsp), %eax
	movl	$100, %r10d
	movl	$10, %edi
	movl	$1000, %esi
	cltd
	idivl	%r10d
	movl	%edx, %eax
	cltd
	idivl	%edi
	movl	%eax, %r9d
	movl	12(%rsp), %eax
	cltd
	idivl	%esi
	movl	%eax, %r8d
	movl	8(%rsp), %eax
	cltd
	idivl	%r10d
	movl	%edx, %eax
	cltd
	idivl	%edi
	movl	$2, %edi
	movl	%eax, %ecx
	movl	8(%rsp), %eax
	cltd
	idivl	%esi
	leaq	.LC27(%rip), %rsi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L31:
	cmpl	%ebp, %ebx
	jge	.L39
	movl	%ebx, %edi
	leaq	32(%rsp), %r13
	call	cudaSetDevice@PLT
	movl	%ebx, %esi
	movq	%r13, %rdi
	call	_Z18getCudaDevicePropsi
	leaq	16(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaMemGetInfo@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rax
	testq	%rax, %rax
	js	.L32
	cvtsi2ssq	%rax, %xmm1
	jmp	.L33
.L32:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2ssq	%rdx, %xmm1
	addss	%xmm1, %xmm1
.L33:
	movsd	.LC29(%rip), %xmm2
	movq	24(%rsp), %rax
	cvtss2sd	%xmm1, %xmm1
	mulsd	%xmm2, %xmm1
	testq	%rax, %rax
	js	.L34
	cvtsi2ssq	%rax, %xmm0
	jmp	.L35
.L34:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2ssq	%rdx, %xmm0
	addss	%xmm0, %xmm0
.L35:
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm2, %xmm0
	movl	%ebx, %edx
	movq	%r13, %rcx
	leaq	.LC30(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	incl	%ebx
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L31
.L39:
	movq	1064(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$1080, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z28printNvidiaDevicesMemoryInfov, .-_Z28printNvidiaDevicesMemoryInfov
	.section	.rodata.str1.1
.LC31:
	.string	"-mem"
.LC32:
	.string	"-props"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2034:
	.cfi_startproc
	endbr64
	decl	%edi
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	jg	.L41
.L43:
	call	_Z28printNvidiaDevicesMemoryInfov
	jmp	.L42
.L41:
	movq	8(%rsi), %rbx
	leaq	.LC31(%rip), %rsi
	movq	%rbx, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L43
	leaq	.LC32(%rip), %rsi
	movq	%rbx, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L42
	call	_Z23printAllCudaDevicePropsv
.L42:
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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
.LFE2060:
	.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
.LC10:
	.long	897581056
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC29:
	.long	0
	.long	1051721728
	.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:

// ================================================================================================
// A simple script to get memory usage & properties of CUDA supported NVIDIA devices
//
// Author: Sivagnanam Namasivayamurthy
//
// ================================================================================================

#include <stdio.h>
#include <time.h>

// CUDA C headers
#include <hip/hip_runtime.h>


/*
 *
 */
void printCurrentTime(){
  time_t t = time(NULL);
  struct tm tm = *localtime(&t);

  printf("\n%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}

/*
 * Get number of CUDA supported devices available
 *
 * returns: the number of CUDA supported devices
 */
int getCudaDevicesCount(){

  int deviceCount;

  hipError_t cu_err = hipGetDeviceCount(&deviceCount);
  if(hipSuccess != cu_err){
    printf("Unable to get hipGetDeviceCount : error num %d - %s\n", (int) cu_err, hipGetErrorString(cu_err));
    exit(EXIT_FAILURE);
  }
  return deviceCount;
}

/*
 * Print the number of CUDA supported devices available
 */
void printDevicesCount(){

  int deviceCount = getCudaDevicesCount();

  if(0 == deviceCount){
    printf("No CUDA supported device(s) found !!! \n");
    exit(EXIT_FAILURE);
  } else {
    printf("Found %d CUDA supported device(s)\n", deviceCount);
  }
}

/*
 * Get device properties
 *
 * deviceId : ID of the CUDA supported device

 * returns: the cudaDeviceProp struct that contains the CUDA device properties
 */
hipDeviceProp_t getCudaDeviceProps(int deviceId){

  hipDeviceProp_t deviceProps;

  hipError_t cu_err = hipGetDeviceProperties(&deviceProps, deviceId);
  if(hipSuccess != cu_err){
    printf("Unable to get hipGetDeviceProperties for device ID %d : error num %d - %s\n", deviceId, (int) cu_err, hipGetErrorString(cu_err));
    exit(EXIT_FAILURE);
  }

  return deviceProps;
}

/*
 * Print the CUDA device properties
 *
 * deviceId: ID of the CUDA supported device
 */
void printCudaDeviceProps(int deviceId)
{
  hipDeviceProp_t deviceProps = getCudaDeviceProps(deviceId);
  printf("\n Device ID: %d       Name:      %s\n",  deviceId, deviceProps.name);
  printf("--------------------------------------------------------------\n");
  printf("CUDA capability Major/Minor version number:         %d.%d\n",  deviceProps.major, deviceProps.minor);
  printf("Total global memory:                                %0.f MB\n", (float)deviceProps.totalGlobalMem/(1048576.0f));
  printf("Total shared memory per block:                      %lu bytes\n", deviceProps.sharedMemPerBlock);
  printf("Total registers per block:                          %d\n",  deviceProps.regsPerBlock);
  printf("Warp size:                                          %d\n",  deviceProps.warpSize);
  printf("Maximum memory pitch:                               %lu bytes\n", deviceProps.memPitch);
  printf("Maximum threads per block:                          %d\n",  deviceProps.maxThreadsPerBlock);
  printf("Maximum sizes of each dimension of a block:         %d x %d x %d \n", deviceProps.maxThreadsDim[0], deviceProps.maxThreadsDim[1], deviceProps.maxThreadsDim[2]);
  printf("Maximum sizes of each dimension of a grid:          %d x %d x %d  \n", deviceProps.maxGridSize[0], deviceProps.maxGridSize[1], deviceProps.maxGridSize[2]);
  printf("Clock rate:                                         %d\n",  deviceProps.clockRate);
  printf("Total constant memory:                              %lu\n", deviceProps.totalConstMem);
  printf("Texture alignment:                                  %lu bytes\n", deviceProps.textureAlignment);
  printf("Concurrent copy and execution:                      %s\n",  (deviceProps.deviceOverlap ? "Yes" : "No"));
  printf("Number of multiprocessors:                          %d\n",  deviceProps.multiProcessorCount);
  printf("Kernel execution timeout:                           %s\n",  (deviceProps.kernelExecTimeoutEnabled ? "Yes" : "No"));
  printf("--------------------------------------------------------------\n");
}

/*
 * Find all CUDA supported devices & print their properties
 */
void printAllCudaDeviceProps(){
  int deviceCount = getCudaDevicesCount();
  printCurrentTime();
  printf("\nFound %d CUDA supported device(s)\n", deviceCount);

  for (int deviceId = 0; deviceId < deviceCount; ++deviceId){
    printCudaDeviceProps(deviceId);
  }
}

/*
 * Print the free & used memory information of all NVIDIA CUDA supported devices
 */
void printNvidiaDevicesMemoryInfo(){

  int driverVersion, runTimeVersion, deviceCount;
  size_t mem_available, mem_free;

  hipDriverGetVersion(&driverVersion);
  hipRuntimeGetVersion(&runTimeVersion);
  deviceCount = getCudaDevicesCount();

  printCurrentTime();
  printf("\n+----------------------------------------------------------------------+\n");
  printf("| CUDA Driver version: %d.%d               Runtime Version: %d.%d          |\n", driverVersion/1000, (driverVersion % 100)/10, runTimeVersion/1000, (runTimeVersion%100)/10);

  for (int deviceId = 0; deviceId < deviceCount; ++deviceId){

    hipSetDevice(deviceId);
    hipDeviceProp_t deviceProps = getCudaDeviceProps(deviceId);
    hipMemGetInfo(&mem_free, &mem_available);
    printf("+----------------------------------------------------------------------------------------+\n");
    printf("| Device ID: %d      Name: %s           %.0f MB (free) / %.0f MB (total)    |\n", deviceId, deviceProps.name, (float)mem_free/(1024*1024.), (float)mem_available/(1024*1024.));
    printf("+----------------------------------------------------------------------------------------+\n");

  }

}

int main(int argc, char *argv[])
{
  if(argc < 2) {
    printNvidiaDevicesMemoryInfo(); // Print memory information if not argument is passed
  } else {
    if (0 == strcmp(argv[1], "-mem")){
      printNvidiaDevicesMemoryInfo();
    } else if (0 == strcmp(argv[1], "-props")) {
      printAllCudaDeviceProps();
    }
  }
  return 0;
}

	.text
	.file	"nvidia_gpu_stats.hip"
	.globl	_Z16printCurrentTimev           # -- Begin function _Z16printCurrentTimev
	.type	_Z16printCurrentTimev,@function
_Z16printCurrentTimev:                  # @_Z16printCurrentTimev
	.cfi_startproc
# %bb.0:
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	xorl	%edi, %edi
	callq	time
	leaq	16(%rsp), %rdi
	movq	%rax, (%rdi)
	callq	localtime
	movl	(%rax), %edi
	movl	4(%rax), %r9d
	movl	8(%rax), %r8d
	movl	12(%rax), %ecx
	movl	16(%rax), %edx
	movl	$1900, %esi                     # imm = 0x76C
	addl	20(%rax), %esi
	incl	%edx
	movl	%edi, (%rsp)
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z16printCurrentTimev, .Lfunc_end0-_Z16printCurrentTimev
	.cfi_endproc
                                        # -- End function
	.globl	_Z19getCudaDevicesCountv        # -- Begin function _Z19getCudaDevicesCountv
	.type	_Z19getCudaDevicesCountv,@function
_Z19getCudaDevicesCountv:               # @_Z19getCudaDevicesCountv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	leaq	12(%rsp), %rdi
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movl	12(%rsp), %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB1_2:
	.cfi_def_cfa_offset 32
	movl	%eax, %ebx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %edi
	movl	%ebx, %esi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z19getCudaDevicesCountv, .Lfunc_end1-_Z19getCudaDevicesCountv
	.cfi_endproc
                                        # -- End function
	.globl	_Z17printDevicesCountv          # -- Begin function _Z17printDevicesCountv
	.type	_Z17printDevicesCountv,@function
_Z17printDevicesCountv:                 # @_Z17printDevicesCountv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	_Z19getCudaDevicesCountv
	testl	%eax, %eax
	je	.LBB2_1
# %bb.2:
	movl	$.L.str.3, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.LBB2_1:
	.cfi_def_cfa_offset 16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z17printDevicesCountv, .Lfunc_end2-_Z17printDevicesCountv
	.cfi_endproc
                                        # -- End function
	.globl	_Z18getCudaDevicePropsi         # -- Begin function _Z18getCudaDevicePropsi
	.type	_Z18getCudaDevicePropsi,@function
_Z18getCudaDevicePropsi:                # @_Z18getCudaDevicePropsi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movq	%r14, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_2:
	.cfi_def_cfa_offset 32
	movl	%eax, %ebp
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %edi
	movl	%ebx, %esi
	movl	%ebp, %edx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z18getCudaDevicePropsi, .Lfunc_end3-_Z18getCudaDevicePropsi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z20printCudaDevicePropsi
.LCPI4_0:
	.long	0x35800000                      # float 9.53674316E-7
	.text
	.globl	_Z20printCudaDevicePropsi
	.type	_Z20printCudaDevicePropsi,@function
_Z20printCudaDevicePropsi:              # @_Z20printCudaDevicePropsi
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edi, %ebx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_Z18getCudaDevicePropsi
	movl	$.L.str.5, %edi
	movl	%ebx, %esi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	360(%r14), %esi
	movl	364(%r14), %edx
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movq	288(%r14), %rax
	testq	%rax, %rax
	js	.LBB4_1
# %bb.2:
	cvtsi2ss	%rax, %xmm0
	jmp	.LBB4_3
.LBB4_1:
	movq	%rax, %rcx
	shrq	%rcx
	andl	$1, %eax
	orq	%rcx, %rax
	cvtsi2ss	%rax, %xmm0
	addss	%xmm0, %xmm0
.LBB4_3:
	mulss	.LCPI4_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movq	304(%rsp), %rsi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	312(%rsp), %esi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	316(%rsp), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movq	320(%rsp), %rsi
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	movl	328(%rsp), %esi
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	movl	332(%rsp), %esi
	movl	336(%rsp), %edx
	movl	340(%rsp), %ecx
	movl	$.L.str.14, %edi
	xorl	%eax, %eax
	callq	printf
	movl	344(%rsp), %esi
	movl	348(%rsp), %edx
	movl	352(%rsp), %ecx
	movl	$.L.str.15, %edi
	xorl	%eax, %eax
	callq	printf
	movl	356(%rsp), %esi
	movl	$.L.str.16, %edi
	xorl	%eax, %eax
	callq	printf
	movq	360(%rsp), %rsi
	movl	$.L.str.17, %edi
	xorl	%eax, %eax
	callq	printf
	movq	376(%rsp), %rsi
	movl	$.L.str.18, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 392(%rsp)
	movl	$.L.str.21, %r14d
	movl	$.L.str.20, %ebx
	movl	$.L.str.20, %esi
	cmoveq	%r14, %rsi
	movl	$.L.str.19, %edi
	xorl	%eax, %eax
	callq	printf
	movl	396(%rsp), %esi
	movl	$.L.str.22, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 400(%rsp)
	cmoveq	%r14, %rbx
	movl	$.L.str.23, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	addq	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z20printCudaDevicePropsi, .Lfunc_end4-_Z20printCudaDevicePropsi
	.cfi_endproc
                                        # -- End function
	.globl	_Z23printAllCudaDevicePropsv    # -- Begin function _Z23printAllCudaDevicePropsv
	.type	_Z23printAllCudaDevicePropsv,@function
_Z23printAllCudaDevicePropsv:           # @_Z23printAllCudaDevicePropsv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	callq	_Z19getCudaDevicesCountv
	movl	%eax, %ebx
	callq	_Z16printCurrentTimev
	xorl	%ebp, %ebp
	movl	$.L.str.24, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	testl	%ebx, %ebx
	jle	.LBB5_2
.LBB5_1:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebp, %edi
	callq	_Z20printCudaDevicePropsi
	incl	%ebp
	cmpl	%ebp, %ebx
	jne	.LBB5_1
.LBB5_2:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z23printAllCudaDevicePropsv, .Lfunc_end5-_Z23printAllCudaDevicePropsv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z28printNvidiaDevicesMemoryInfov
.LCPI6_0:
	.quad	0x3eb0000000000000              # double 9.5367431640625E-7
	.text
	.globl	_Z28printNvidiaDevicesMemoryInfov
	.type	_Z28printNvidiaDevicesMemoryInfov,@function
_Z28printNvidiaDevicesMemoryInfov:      # @_Z28printNvidiaDevicesMemoryInfov
	.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	$1504, %rsp                     # imm = 0x5E0
	.cfi_def_cfa_offset 1552
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	28(%rsp), %r15
	movq	%r15, %rdi
	callq	hipDriverGetVersion
	leaq	24(%rsp), %r14
	movq	%r14, %rdi
	callq	hipRuntimeGetVersion
	callq	_Z19getCudaDevicesCountv
	movl	%eax, %ebx
	callq	_Z16printCurrentTimev
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movslq	(%r15), %rax
	imulq	$274877907, %rax, %rsi          # imm = 0x10624DD3
	movq	%rsi, %rcx
	shrq	$63, %rcx
	sarq	$38, %rsi
	addl	%ecx, %esi
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	shrq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	movsbl	%al, %eax
	imull	$103, %eax, %ecx
	movl	$65535, %eax                    # imm = 0xFFFF
	movswl	%cx, %edx
	andl	%eax, %ecx
	shrl	$15, %ecx
	shrl	$10, %edx
	addb	%cl, %dl
	movsbl	%dl, %edx
	movslq	(%r14), %rdi
	imulq	$274877907, %rdi, %rcx          # imm = 0x10624DD3
	movq	%rcx, %r8
	shrq	$63, %r8
	sarq	$38, %rcx
	addl	%r8d, %ecx
	imulq	$1374389535, %rdi, %r8          # imm = 0x51EB851F
	movq	%r8, %r9
	shrq	$63, %r9
	shrq	$37, %r8
	addl	%r9d, %r8d
	imull	$100, %r8d, %r8d
	subl	%r8d, %edi
	movsbl	%dil, %edi
	imull	$103, %edi, %edi
	andl	%edi, %eax
	shrl	$15, %eax
	movswl	%di, %edi
	shrl	$10, %edi
	addb	%al, %dil
	movsbl	%dil, %r8d
	xorl	%ebp, %ebp
	movl	$.L.str.26, %edi
                                        # kill: def $esi killed $esi killed $rsi
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	printf
	testl	%ebx, %ebx
	jle	.LBB6_9
# %bb.1:                                # %.lr.ph.preheader
	leaq	32(%rsp), %r14
	leaq	8(%rsp), %r15
	leaq	16(%rsp), %r12
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebp, %edi
	callq	hipSetDevice
	movq	%r14, %rdi
	movl	%ebp, %esi
	callq	_Z18getCudaDevicePropsi
	movq	%r15, %rdi
	movq	%r12, %rsi
	callq	hipMemGetInfo
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movq	8(%rsp), %rax
	testq	%rax, %rax
	js	.LBB6_3
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB6_2 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	jmp	.LBB6_5
.LBB6_3:                                #   in Loop: Header=BB6_2 Depth=1
	movq	%rax, %rcx
	shrq	%rcx
	andl	$1, %eax
	orq	%rcx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	addss	%xmm0, %xmm0
.LBB6_5:                                # %.lr.ph
                                        #   in Loop: Header=BB6_2 Depth=1
	movq	16(%rsp), %rax
	testq	%rax, %rax
	js	.LBB6_6
# %bb.7:                                # %.lr.ph
                                        #   in Loop: Header=BB6_2 Depth=1
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	jmp	.LBB6_8
.LBB6_6:                                #   in Loop: Header=BB6_2 Depth=1
	movq	%rax, %rcx
	shrq	%rcx
	andl	$1, %eax
	orq	%rcx, %rax
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	addss	%xmm1, %xmm1
.LBB6_8:                                # %.lr.ph
                                        #   in Loop: Header=BB6_2 Depth=1
	cvtss2sd	%xmm0, %xmm0
	movsd	.LCPI6_0(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm0
	cvtss2sd	%xmm1, %xmm1
	mulsd	%xmm2, %xmm1
	movl	$.L.str.28, %edi
	movl	%ebp, %esi
	movq	%r14, %rdx
	movb	$2, %al
	callq	printf
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	incl	%ebp
	cmpl	%ebp, %ebx
	jne	.LBB6_2
.LBB6_9:                                # %._crit_edge
	addq	$1504, %rsp                     # imm = 0x5E0
	.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
.Lfunc_end6:
	.size	_Z28printNvidiaDevicesMemoryInfov, .Lfunc_end6-_Z28printNvidiaDevicesMemoryInfov
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	cmpl	$1, %edi
	jle	.LBB7_1
# %bb.2:
	movq	8(%rsi), %rbx
	movl	$.L.str.29, %esi
	movq	%rbx, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB7_1
# %bb.3:
	movl	$.L.str.30, %esi
	movq	%rbx, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB7_5
# %bb.4:
	callq	_Z23printAllCudaDevicePropsv
	jmp	.LBB7_5
.LBB7_1:
	callq	_Z28printNvidiaDevicesMemoryInfov
.LBB7_5:
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	main, .Lfunc_end7-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"\n%d-%d-%d %d:%d:%d"
	.size	.L.str, 19

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Unable to get hipGetDeviceCount : error num %d - %s\n"
	.size	.L.str.1, 53

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Found %d CUDA supported device(s)\n"
	.size	.L.str.3, 35

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Unable to get hipGetDeviceProperties for device ID %d : error num %d - %s\n"
	.size	.L.str.4, 75

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\n Device ID: %d       Name:      %s\n"
	.size	.L.str.5, 37

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"CUDA capability Major/Minor version number:         %d.%d\n"
	.size	.L.str.7, 59

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Total global memory:                                %0.f MB\n"
	.size	.L.str.8, 61

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Total shared memory per block:                      %lu bytes\n"
	.size	.L.str.9, 63

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Total registers per block:                          %d\n"
	.size	.L.str.10, 56

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Warp size:                                          %d\n"
	.size	.L.str.11, 56

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Maximum memory pitch:                               %lu bytes\n"
	.size	.L.str.12, 63

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Maximum threads per block:                          %d\n"
	.size	.L.str.13, 56

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Maximum sizes of each dimension of a block:         %d x %d x %d \n"
	.size	.L.str.14, 67

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Maximum sizes of each dimension of a grid:          %d x %d x %d  \n"
	.size	.L.str.15, 68

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Clock rate:                                         %d\n"
	.size	.L.str.16, 56

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Total constant memory:                              %lu\n"
	.size	.L.str.17, 57

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"Texture alignment:                                  %lu bytes\n"
	.size	.L.str.18, 63

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"Concurrent copy and execution:                      %s\n"
	.size	.L.str.19, 56

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

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"No"
	.size	.L.str.21, 3

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"Number of multiprocessors:                          %d\n"
	.size	.L.str.22, 56

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"Kernel execution timeout:                           %s\n"
	.size	.L.str.23, 56

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"\nFound %d CUDA supported device(s)\n"
	.size	.L.str.24, 36

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"| CUDA Driver version: %d.%d               Runtime Version: %d.%d          |\n"
	.size	.L.str.26, 78

	.type	.L.str.28,@object               # @.str.28
.L.str.28:
	.asciz	"| Device ID: %d      Name: %s           %.0f MB (free) / %.0f MB (total)    |\n"
	.size	.L.str.28, 79

	.type	.L.str.29,@object               # @.str.29
.L.str.29:
	.asciz	"-mem"
	.size	.L.str.29, 5

	.type	.L.str.30,@object               # @.str.30
.L.str.30:
	.asciz	"-props"
	.size	.L.str.30, 7

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"No CUDA supported device(s) found !!! "
	.size	.Lstr, 39

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"--------------------------------------------------------------"
	.size	.Lstr.2, 63

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"\n+----------------------------------------------------------------------+"
	.size	.Lstr.3, 74

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"+----------------------------------------------------------------------------------------+"
	.size	.Lstr.5, 91

	.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
