Skip to content

Commit

Permalink
api for bp type check (pytorch#1017)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#1017

create an api to check if forwarded file is a bp file.

Reviewed By: tarun292

Differential Revision: D50433020

fbshipit-source-id: 44a81518375527b661555411b89249dca81d55bf
  • Loading branch information
Gasoonjia authored and facebook-github-bot committed Oct 20, 2023
1 parent ea8aa03 commit ff20f40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions util/bundled_program_verification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ __ET_NODISCARD Error GetProgramData(
size_t file_data_len,
const void** out_program_data,
size_t* out_program_data_len) {
if (bundled_program_flatbuffer::BundledProgramBufferHasIdentifier(
file_data)) {
if (IsBundledProgram(file_data)) {
auto program_bundled =
bundled_program_flatbuffer::GetBundledProgram(file_data);
*out_program_data = program_bundled->program()->data();
Expand All @@ -360,6 +359,11 @@ __ET_NODISCARD Error GetProgramData(
return Error::Ok;
}

bool IsBundledProgram(void* file_data) {
return bundled_program_flatbuffer::BundledProgramBufferHasIdentifier(
file_data);
}

} // namespace util
} // namespace executor
} // namespace torch
9 changes: 9 additions & 0 deletions util/bundled_program_verification.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ __ET_NODISCARD Error GetProgramData(
const void** out_program_data,
size_t* out_program_data_len);

/**
* Checks whether the given file is a bundled program.
*
* @param[in] file_data The contents of the given file.
*
* @returns true if the given file is a bundled program, false otherwise
*/
bool IsBundledProgram(void* file_data);

} // namespace util
} // namespace executor
} // namespace torch

0 comments on commit ff20f40

Please sign in to comment.