MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / set

Method set

dnn/src/cuda/cudnn_wrapper.cpp:109–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109void TensorDesc::set(
110 const TensorLayout& layout, const param::Convolution::Format format) {
111 // Layout can be not contiguous; group conv needs it.
112 // megdnn_assert_contiguous(layout);
113 if (format == param::Convolution::Format::NCHW4 ||
114 format == param::Convolution::Format::NCHW32)
115 megdnn_assert_eq_size_t(layout.ndim, 5_z);
116 else
117 megdnn_assert_eq_size_t(layout.ndim, 4_z);
118
119 size_t c_pos, spatial_pos;
120 if (format == param::Convolution::Format::NCHW ||
121 format == param::Convolution::Format::NCHW4 ||
122 format == param::Convolution::Format::NCHW32) {
123 c_pos = 1;
124 spatial_pos = 2;
125 } else {
126 megdnn_assert(format == param::Convolution::Format::NHWC);
127 c_pos = 3;
128 spatial_pos = 1;
129 }
130 if (format == param::Convolution::Format::NCHW4) {
131 megdnn_assert(layout.is_physical_contiguous());
132 cudnn_check(cudnnSetTensor4dDescriptor(
133 desc, to_cudnn_format(format), to_cudnn_dtype(layout.dtype, format),
134 layout.shape[0], layout.shape[c_pos] * 4, layout.shape[spatial_pos + 0],
135 layout.shape[spatial_pos + 1]));
136 } else if (format == param::Convolution::Format::NCHW32) {
137 megdnn_assert(layout.is_physical_contiguous());
138 cudnn_check(cudnnSetTensor4dDescriptor(
139 desc, to_cudnn_format(format), to_cudnn_dtype(layout.dtype, format),
140 layout.shape[0], layout.shape[c_pos] * 32,
141 layout.shape[spatial_pos + 0], layout.shape[spatial_pos + 1]));
142
143 } else {
144 cudnn_check(cudnnSetTensor4dDescriptorEx(
145 desc, to_cudnn_dtype(layout.dtype), layout.shape[0],
146 layout.shape[c_pos], layout.shape[spatial_pos + 0],
147 layout.shape[spatial_pos + 1], layout.stride[0], layout.stride[c_pos],
148 layout.stride[spatial_pos + 0], layout.stride[spatial_pos + 1]));
149 }
150}
151
152std::string TensorDesc::to_string() {
153 cudnnDataType_t data_type;

Callers

nothing calls this directly

Calls 7

to_cudnn_formatFunction · 0.85
get_compute_type_fp16Function · 0.85
categoryMethod · 0.80
to_cudnn_dtypeFunction · 0.70
scFunction · 0.70
enumvMethod · 0.45

Tested by

no test coverage detected