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

Class TensorLayout

dnn/include/megdnn/basic_types.h:129–407  ·  view source on GitHub ↗

* \brief Describing the tensor shape with its actual layout in memory and dtype * * x(i, j, ...) is stored at offset * stride[0]*i + stride[1]*j + ..., in number of elements; physical offset needs * to be multiplied by dtype size. */

Source from the content-addressed store, hash-verified

127 * to be multiplied by dtype size.
128 */
129struct TensorLayout : public TensorShape {
130 /*!
131 * \brief Describes min and max offsets of tensor elements with respect to
132 * its first element, so all tensor elements are guaranteed to be in
133 * the range [elem[0]+low, elem[0]+last). Besides, we have a high to
134 * describe the range including row pitch when using image2D
135 */
136 struct Span {
137 ptrdiff_t low_elem, low_byte;
138 size_t high_elem, high_byte;
139 //! The differece between high_elem and last elem is that last_elem describes
140 //! the last element of a tensor regardless of the row pitch at the last row. It
141 //! will be useful when copying into a part of image.
142 size_t last_elem, last_byte;
143
144 Span(ptrdiff_t low_elem, ptrdiff_t low_byte, size_t high_elem, size_t high_byte,
145 size_t last_elem, size_t last_byte)
146 : low_elem(low_elem),
147 low_byte(low_byte),
148 high_elem(high_elem),
149 high_byte(high_byte),
150 last_elem(last_elem),
151 last_byte(last_byte) {}
152 size_t dist_elem() const { return high_elem - low_elem; }
153
154 size_t dist_byte() const { return high_byte - low_byte; }
155
156 size_t dist_last_byte() const { return last_byte - low_byte; }
157 };
158
159 /*!
160 * \brief Describing the requirements for tensor layouts
161 *
162 * Some runtime (e.g. opencl) may have alignment requirements for special
163 * memory types (e.g. image in texture memory). Format objects can be used
164 * to impose such constraints on methods related to tensor strides.
165 *
166 * Note that ImplBase is defined in tensor_format.h
167 */
168 class Format {
169 public:
170 class ImplBase;
171
172#if MEGDNN_CC_HOST
173 MGE_WIN_DECLSPEC_FUC Format();
174 MGE_WIN_DECLSPEC_FUC Format(DType dtype);
175
176 const ImplBase* impl() const { return m_impl; }
177
178 enum class Type;
179
180 //! get impl type; defined in tensor_format.h
181 inline Type type() const;
182
183 //! convert to the implementation class; exception would be raised if
184 //! type mismatches
185 template <class Impl>
186 const Impl& as_impl() const {

Callers 15

TESTFunction · 0.85
makeFunction · 0.85
ProfilerPluginMethod · 0.85
apply_on_physical_tensorFunction · 0.85
infer_output_attrsMethod · 0.85
create_layoutFunction · 0.85

Calls 1

to_stringFunction · 0.85

Tested by 15

TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
output_canonizerFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TEST_FFunction · 0.68
TEST_FFunction · 0.68