1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
//------------------------------------------------------------------------------
// GraphBLAS/CUDA/GB_cuda_get_device_properties: get the properties of a GPU
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// This file: Copyright (c) 2024-2025, NVIDIA CORPORATION. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB_cuda.hpp"
#define CU_OK(cudaMethod) \
{ \
if ((cudaMethod) != cudaSuccess) return (false) ; \
}
//------------------------------------------------------------------------------
// GB_cuda_get_device: get the current GPU
//------------------------------------------------------------------------------
bool GB_cuda_get_device (int &device)
{
if (&device == NULL)
{
// invalid inputs
return (false) ;
}
CU_OK (cudaGetDevice (&device)) ;
return (true) ;
}
//------------------------------------------------------------------------------
// GB_cuda_set_device: set the current GPU
//------------------------------------------------------------------------------
bool GB_cuda_set_device (int device)
{
if (device < 0)
{
// invalid inputs
return (false) ;
}
CU_OK (cudaSetDevice (device)) ;
return (true) ;
}
//------------------------------------------------------------------------------
// GB_cuda_get_device_properties: determine all properties of a single GPU
//------------------------------------------------------------------------------
bool GB_cuda_get_device_properties // true if OK, false if failure
(
int device,
GB_cuda_device *prop
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
if (prop == NULL || device < 0)
{
// invalid inputs
return (false) ;
}
// clear the GPU settings
memset (prop, 0, sizeof (GB_cuda_device)) ;
int old_device ;
CU_OK (cudaGetDevice (&old_device )) ;
//--------------------------------------------------------------------------
// get the properties
//--------------------------------------------------------------------------
int num_sms, compute_capability_major, compute_capability_minor ;
size_t memfree, memtotal ;
CU_OK (cudaDeviceGetAttribute (&num_sms,
cudaDevAttrMultiProcessorCount, device)) ;
CU_OK (cudaDeviceGetAttribute (&compute_capability_major,
cudaDevAttrComputeCapabilityMajor, device)) ;
CU_OK (cudaDeviceGetAttribute (&compute_capability_minor,
cudaDevAttrComputeCapabilityMinor, device)) ;
CU_OK (cudaSetDevice (device )) ;
CU_OK (cudaMemGetInfo (&memfree, &memtotal)) ;
CU_OK (cudaSetDevice (old_device )) ;
prop->total_global_memory = memtotal ;
prop->number_of_sms = num_sms ;
prop->compute_capability_major = compute_capability_major ;
prop->compute_capability_minor = compute_capability_minor ;
// FIXME: remove this printf
printf ("\nDevice: %d: memory: %ld SMs: %d compute: %d.%d\n",
device, prop->total_global_memory, prop->number_of_sms,
prop->compute_capability_major, prop->compute_capability_minor) ;
//--------------------------------------------------------------------------
// return result
//--------------------------------------------------------------------------
return (true) ;
}
|