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

Class Format

dnn/include/megdnn/basic_types.h:168–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {
187 static_assert(std::is_base_of<ImplBase, Impl>::value, "bad type");
188 if (type() != Impl::TYPE) {
189 on_bad_cvt(Impl::TYPE);
190 }
191 return *static_cast<const Impl*>(m_impl);
192 }
193
194 //! get human-readable string description of this format
195 MGE_WIN_DECLSPEC_FUC std::string to_string() const;
196
197 MGE_WIN_DECLSPEC_FUC std::string serialize() const;
198 MGE_WIN_DECLSPEC_FUC static Format deserialize(
199 const std::string& bin, const Handle* handle);
200
201 //! whether this is the default tensor format
202 MGE_WIN_DECLSPEC_FUC bool is_default() const;
203
204 //! whether this is the lowbit aligned to bytes tensor format
205 MGE_WIN_DECLSPEC_FUC bool is_lowbit_aligned() const;
206
207 bool operator==(Format rhs) const { return m_impl == rhs.m_impl; }
208 bool operator!=(Format rhs) const { return m_impl != rhs.m_impl; }
209#endif
210
211 private:
212 const ImplBase* m_impl;
213
214#if MEGDNN_CC_HOST
215 Format(ImplBase* impl) : m_impl{impl} {}
216 MEGDNN_NORETURN void on_bad_cvt(Type dst_type) const;
217#endif
218 };
219
220 ptrdiff_t stride[MAX_NDIM];
221 DType dtype;

Callers 6

formatMethod · 0.50
CustomOpImplMethod · 0.50
tensor.hFile · 0.50
TensorLayoutMethod · 0.50
modify_dtype_inplaceMethod · 0.50
get_workspace_bundleMethod · 0.50

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected