aboutsummaryrefslogtreecommitdiff
path: root/deps/cudnn-frontend/include/cudnn_frontend/context.h
blob: 86e878d972f0c53f88c9e0df53253c596b145331 (plain) (blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#pragma once

#include "../cudnn_frontend_shim.h"
#include "../cudnn_frontend_utils.h"

namespace cudnn_frontend::detail {

class Context {
    DataType_t compute_data_type      = DataType_t::NOT_SET;
    DataType_t intermediate_data_type = DataType_t::NOT_SET;
    DataType_t io_data_type           = DataType_t::NOT_SET;
    int32_t target_sm_count           = -1;
    mutable int32_t target_sm_version = -1;
    bool is_dynamic_shape_enabled     = false;
    bool is_override_shape_enabled    = false;

    std::string name = "";

   public:
    Context&
    set_intermediate_data_type(DataType_t const type) {
        intermediate_data_type = type;
        return *this;
    }

    Context&
    set_io_data_type(DataType_t const type) {
        io_data_type = type;
        return *this;
    }

    Context&
    set_compute_data_type(DataType_t const type) {
        compute_data_type = type;
        return *this;
    }

    DataType_t
    get_io_data_type() const {
        return io_data_type;
    }

    DataType_t
    get_intermediate_data_type() const {
        return intermediate_data_type;
    }

    DataType_t
    get_compute_data_type() const {
        return compute_data_type;
    }

    Context&
    set_name(std::string const& name_) {
        name = name_;
        return *this;
    }

    std::string
    get_name() const {
        return name;
    }

    Context&
    set_target_sm_count(int32_t count) {
        target_sm_count = count;
        return *this;
    }

    Context&
    set_sm_version(int32_t version) {
        target_sm_version = version;
        return *this;
    }

    Context&
    set_dynamic_shape_enabled(bool is_enabled) {
        is_dynamic_shape_enabled = is_enabled;
        return *this;
    }

    Context&
    set_override_shape_enabled(bool is_enabled) {
        is_override_shape_enabled = is_enabled;
        return *this;
    }

    bool
    get_dynamic_shape_enabled() const {
        return is_dynamic_shape_enabled;
    }

    bool
    get_override_shape_enabled() const {
        return is_override_shape_enabled;
    }

    int32_t
    get_target_sm_count() const {
        return target_sm_count;
    }

    int32_t
    get_sm_version() const {
        return target_sm_version;
    }

    error_t
    populate_sm_version_from_device() const {
        if (target_sm_version > 0) {
            // Already set by user or previous call
            return {error_code_t::OK, ""};
        }
        cudaDeviceProp prop;
        int device;
        _CUDNN_CHECK_CUDA_ERROR(cuda_get_device(&device));
        _CUDNN_CHECK_CUDA_ERROR(cuda_get_device_properties(&prop, device));
        target_sm_version = prop.major * 10 + prop.minor;
        CUDNN_FE_LOG_LABEL_ENDL("INFO: Populated SM version from device: " << device << " " << target_sm_version);
        return {error_code_t::OK, ""};
    }

    Context&
    fill_missing_properties(Context const& global_context) {
        if (get_compute_data_type() == DataType_t::NOT_SET) {
            set_compute_data_type(global_context.get_compute_data_type());
        }
        if (get_intermediate_data_type() == DataType_t::NOT_SET) {
            set_intermediate_data_type(global_context.get_intermediate_data_type());
        }
        if (get_io_data_type() == DataType_t::NOT_SET) {
            set_io_data_type(global_context.get_io_data_type());
        }
        return *this;
    }
};

}  // namespace cudnn_frontend::detail