diff --git a/compiler/luci/export/src/CircleExporterUtils.h b/compiler/luci/export/src/CircleExporterUtils.h index 83b040753dc..9103d2689f1 100644 --- a/compiler/luci/export/src/CircleExporterUtils.h +++ b/compiler/luci/export/src/CircleExporterUtils.h @@ -26,6 +26,9 @@ #include +// limitation of current flatbuffers file size +inline constexpr unsigned int FLATBUFFERS_SIZE_MAX = 2147483648; + namespace luci { @@ -60,6 +63,12 @@ void set_tensor_index(loco::Node *node, const CircleTensorIndex &tensor_id); void clear_tensor_index(loco::Node *node); CircleTensorIndex get_tensor_index(loco::Node *node); +// check if Flatbuffer builder can no longer hold the given amount of the data +inline bool check_size_limit(flatbuffers::FlatBufferBuilder &fb, const uint64_t data_size) +{ + return data_size > FLATBUFFERS_SIZE_MAX - fb.GetSize(); +} + } // namespace luci #endif // __CIRCLE_EXPORTER_UTILS_H__