From f925126cf8771d894d3fe27a2947026fbd126e15 Mon Sep 17 00:00:00 2001 From: SaeHie Park Date: Mon, 2 Sep 2024 00:05:15 +0000 Subject: [PATCH] [luci/export] Introduce check_size_limit This will introduce check_size_limit method to check limit of flatbuffers size. ONE-DCO-1.0-Signed-off-by: SaeHie Park --- compiler/luci/export/src/CircleExporterUtils.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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__