File: GB_cuda_get_device_properties.cu

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (106 lines) | stat: -rw-r--r-- 3,799 bytes parent folder | download | duplicates (2)
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
//------------------------------------------------------------------------------
// GB_cuda_get_device_properties.cu: get the properties of a GPU
//------------------------------------------------------------------------------

// SPDX-License-Identifier: Apache-2.0
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2019, All Rights Reserved.
// http://suitesparse.com   See GraphBLAS/Doc/License.txt for license.

//------------------------------------------------------------------------------

#include "GB_cuda.h"

//------------------------------------------------------------------------------
// GB_cuda_get_device: get the current GPU
//------------------------------------------------------------------------------

bool GB_cuda_get_device (int &device)
{
    if (&device == NULL)
    {
        // invalid inputs
        return (false) ;
    }
    CHECK_CUDA_SIMPLE (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) ;
    }
    CHECK_CUDA_SIMPLE (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 ;
    CHECK_CUDA_SIMPLE ( cudaGetDevice( &old_device ) ) ;

    //--------------------------------------------------------------------------
    // get the properties
    //--------------------------------------------------------------------------

    int num_sms, compute_capability_major, compute_capability_minor ;
    size_t memfree, memtotal ;

    CHECK_CUDA_SIMPLE( cudaDeviceGetAttribute (&num_sms,
                                         cudaDevAttrMultiProcessorCount,
                                         device) ) ;
    CHECK_CUDA_SIMPLE( cudaDeviceGetAttribute (&compute_capability_major,
                                         cudaDevAttrComputeCapabilityMajor,
                                         device) ) ;
    CHECK_CUDA_SIMPLE( cudaDeviceGetAttribute (&compute_capability_minor,
                                         cudaDevAttrComputeCapabilityMajor,
                                         device) ) ;

    CHECK_CUDA_SIMPLE ( cudaSetDevice( device ) ) ;
    CHECK_CUDA_SIMPLE ( cudaMemGetInfo( & memfree, &memtotal) ) ;
    CHECK_CUDA_SIMPLE ( 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 ;

    printf ("Device: %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) ;
}