Browse Source

fix(serialization): do not gate enum entries by macro

GitOrigin-RevId: aa27ecbf21
release-0.6
Megvii Engine Team Xu Xinran 5 years ago
parent
commit
9006d76bea
3 changed files with 16 additions and 7 deletions
  1. +7
    -0
      src/core/include/megbrain/common.h
  2. +4
    -2
      src/serialization/impl/serializer.cpp
  3. +5
    -5
      src/serialization/include/megbrain/serialization/opr_load_dump.h

+ 7
- 0
src/core/include/megbrain/common.h View File

@@ -48,6 +48,13 @@ namespace mgb {
//! warn if result of a function is not used //! warn if result of a function is not used
#define MGB_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #define MGB_WARN_UNUSED_RESULT __attribute__((warn_unused_result))


#if __cplusplus >= 201703L || __clang_major__ >= 4
#define MGB_FALLTHRU [[fallthrough]];
#elif __GNUC__ >= 7
#define MGB_FALLTHRU __attribute__((fallthrough));
#else
#define MGB_FALLTHRU
#endif


/* ================ exception and assertion ================ */ /* ================ exception and assertion ================ */




+ 4
- 2
src/serialization/impl/serializer.cpp View File

@@ -53,10 +53,11 @@ bool GraphDumper::should_remove_in_dump(cg::OperatorNodeBase *opr) {
std::unique_ptr<GraphDumper> GraphDumper::make(std::unique_ptr<OutputFile> file, std::unique_ptr<GraphDumper> GraphDumper::make(std::unique_ptr<OutputFile> file,
GraphDumpFormat format) { GraphDumpFormat format) {
switch (format) { switch (format) {
#if MGB_ENABLE_FBS_SERIALIZATION
case GraphDumpFormat::FLATBUFFERS: case GraphDumpFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
return make_fbs_dumper(std::move(file)); return make_fbs_dumper(std::move(file));
#endif #endif
MGB_FALLTHRU
default: default:
mgb_throw(SerializationError, mgb_throw(SerializationError,
"unsupported serialization format requested"); "unsupported serialization format requested");
@@ -66,10 +67,11 @@ std::unique_ptr<GraphDumper> GraphDumper::make(std::unique_ptr<OutputFile> file,


std::unique_ptr<GraphLoader> GraphLoader::make(std::unique_ptr<InputFile> file, GraphDumpFormat format) { std::unique_ptr<GraphLoader> GraphLoader::make(std::unique_ptr<InputFile> file, GraphDumpFormat format) {
switch (format) { switch (format) {
#if MGB_ENABLE_FBS_SERIALIZATION
case GraphDumpFormat::FLATBUFFERS: case GraphDumpFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
return make_fbs_loader(std::move(file)); return make_fbs_loader(std::move(file));
#endif #endif
MGB_FALLTHRU
default: default:
mgb_throw(SerializationError, mgb_throw(SerializationError,
"unsupported serialization format requested"); "unsupported serialization format requested");


+ 5
- 5
src/serialization/include/megbrain/serialization/opr_load_dump.h View File

@@ -29,9 +29,7 @@ struct OperatorParamTraits;


enum class SerializationFormat { enum class SerializationFormat {
RAW_POD, RAW_POD,
#if MGB_ENABLE_FBS_SERIALIZATION
FLATBUFFERS, FLATBUFFERS,
#endif
}; };


//! context for serializing a single operator //! context for serializing a single operator
@@ -162,12 +160,12 @@ void OprDumpContext::write_param(const Param& p) {
case SerializationFormat::RAW_POD: case SerializationFormat::RAW_POD:
static_cast<OprDumpContextRawPOD*>(this)->write_param(p); static_cast<OprDumpContextRawPOD*>(this)->write_param(p);
break; break;
#if MGB_ENABLE_FBS_SERIALIZATION
case SerializationFormat::FLATBUFFERS: case SerializationFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
static_cast<OprDumpContextFlatBuffers*>(this)->write_param( static_cast<OprDumpContextFlatBuffers*>(this)->write_param(
p, fbs::SupportFlatBuffersSerialization<Param>{}); p, fbs::SupportFlatBuffersSerialization<Param>{});
break;
#endif #endif
break;
} }
} }


@@ -322,11 +320,13 @@ Param OprLoadContext::read_param() {
case SerializationFormat::RAW_POD: case SerializationFormat::RAW_POD:
return static_cast<OprLoadContextRawPOD*>(this) return static_cast<OprLoadContextRawPOD*>(this)
->read_param<Param>(); ->read_param<Param>();
#if MGB_ENABLE_FBS_SERIALIZATION
case SerializationFormat::FLATBUFFERS: case SerializationFormat::FLATBUFFERS:
#if MGB_ENABLE_FBS_SERIALIZATION
return static_cast<OprLoadContextFlatBuffers*>(this) return static_cast<OprLoadContextFlatBuffers*>(this)
->read_param<Param>( ->read_param<Param>(
fbs::SupportFlatBuffersSerialization<Param>{}); fbs::SupportFlatBuffersSerialization<Param>{});
#else
mgb_trap();
#endif #endif
} }
mgb_assert(0); mgb_assert(0);


Loading…
Cancel
Save