Skip to content

Commit

Permalink
[misc] pmx: rename EXTERNAL_DATA => EXTERNAL_MULTI_FILES
Browse files Browse the repository at this point in the history
  • Loading branch information
ouonline committed May 6, 2024
1 parent 0f86c12 commit 9271b50
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/ppl/nn/models/pmx/load_model_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ppl { namespace nn { namespace pmx {
#include "ppl/nn/common/common.h"

struct PPLNN_PUBLIC LoadModelOptions final {
/** load constant from external data files in `external_data_dir` if `EXTERNAL_DATA` is enabled. */
/** load constant from external data files in `external_data_dir` if `EXTERNAL_MULTI_FILES` is enabled. */
const char* external_data_dir = nullptr;
};

Expand Down
14 changes: 7 additions & 7 deletions src/ppl/nn/models/pmx/generated/pmx_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ struct Model;
struct ModelBuilder;

enum ConstantFlag : uint32_t {
ConstantFlag_EXTERNAL_DATA = 1,
ConstantFlag_MIN = ConstantFlag_EXTERNAL_DATA,
ConstantFlag_MAX = ConstantFlag_EXTERNAL_DATA
ConstantFlag_EXTERNAL_MULTI_FILES = 1,
ConstantFlag_MIN = ConstantFlag_EXTERNAL_MULTI_FILES,
ConstantFlag_MAX = ConstantFlag_EXTERNAL_MULTI_FILES
};

inline const ConstantFlag (&EnumValuesConstantFlag())[1] {
static const ConstantFlag values[] = {
ConstantFlag_EXTERNAL_DATA
ConstantFlag_EXTERNAL_MULTI_FILES
};
return values;
}

inline const char * const *EnumNamesConstantFlag() {
static const char * const names[2] = {
"EXTERNAL_DATA",
"EXTERNAL_MULTI_FILES",
nullptr
};
return names;
}

inline const char *EnumNameConstantFlag(ConstantFlag e) {
if (flatbuffers::IsOutRange(e, ConstantFlag_EXTERNAL_DATA, ConstantFlag_EXTERNAL_DATA)) return "";
const size_t index = static_cast<size_t>(e) - static_cast<size_t>(ConstantFlag_EXTERNAL_DATA);
if (flatbuffers::IsOutRange(e, ConstantFlag_EXTERNAL_MULTI_FILES, ConstantFlag_EXTERNAL_MULTI_FILES)) return "";
const size_t index = static_cast<size_t>(e) - static_cast<size_t>(ConstantFlag_EXTERNAL_MULTI_FILES);
return EnumNamesConstantFlag()[index];
}

Expand Down
4 changes: 2 additions & 2 deletions src/ppl/nn/models/pmx/graph_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class PmxConstantVisitor final : public ConstantVisitor {
RetCode ForEach(const function<RetCode(edgeid_t, uint64_t)>& f) const override {
for (auto fb_constant = fb_constants_->begin(); fb_constant != fb_constants_->end(); ++fb_constant) {
uint32_t flags = fb_constant->flags();
if (flags & ConstantFlag_EXTERNAL_DATA) {
if (flags & ConstantFlag_EXTERNAL_MULTI_FILES) {
if (fb_constant->data_offset() == UINT64_MAX) {
auto status = f(fb_constant->edge_id(), fb_constant->data_bytes());
if (status != RC_SUCCESS) {
Expand Down Expand Up @@ -197,7 +197,7 @@ class PmxConstantVisitor final : public ConstantVisitor {
}

uint32_t flags = fb_constant->flags();
if (flags & ConstantFlag_EXTERNAL_DATA) {
if (flags & ConstantFlag_EXTERNAL_MULTI_FILES) {
string path;
if (fb_constant->data_offset() == UINT64_MAX) {
path = external_data_dir_ + "/" +
Expand Down
4 changes: 2 additions & 2 deletions src/ppl/nn/models/pmx/schema/pmx.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ table NodeInfo {
}

enum ConstantFlag : uint32 {
EXTERNAL_DATA = 1,
EXTERNAL_MULTI_FILES = 1,
}

table Constant {
edge_id: uint32;
flags: uint32; // or-ed flags
// if EXTERNAL_DATA is set
// if EXTERNAL_MULTI_FILES is set
// - `data_offset` == UINT64_MAX: use the defalut gen name function to get the file name,
// `data_bytes` is the size of data
// - `data_offset` < UINT64_MAX: file name is stored in GraphData::shared_data + `data_offset`,
Expand Down
2 changes: 1 addition & 1 deletion src/ppl/nn/models/pmx/serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static RetCode CreateFbConstants(FlatBufferBuilder* builder, const SaveModelOpti
uint64_t offset = UINT64_MAX;

if (options.external_data_dir && options.external_data_dir[0] != '\0') {
flags |= ConstantFlag_EXTERNAL_DATA;
flags |= ConstantFlag_EXTERNAL_MULTI_FILES;
const string fname = utils::GenOutputFileName(edge->GetName());
const string path = string(options.external_data_dir) + "/" + fname;
auto rc = SaveData(data, path);
Expand Down

0 comments on commit 9271b50

Please sign in to comment.