-
Notifications
You must be signed in to change notification settings - Fork 537
Xnnpack test for program-data separation #10532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lucylq
wants to merge
4
commits into
gh/lucylq/72/base
Choose a base branch
from
gh/lucylq/72/head
base: gh/lucylq/72/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4fc3695
Xnnpack test for program-data separation
lucylq b50f331
Update on "Xnnpack test for program-data separation"
lucylq 59e5222
Update on "Xnnpack test for program-data separation"
lucylq 2d4bfd7
Update on "Xnnpack test for program-data separation"
lucylq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
backends/xnnpack/test/runtime/test_xnn_data_separation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <executorch/extension/data_loader/file_data_loader.h> | ||
#include <executorch/extension/flat_tensor/flat_tensor_data_map.h> | ||
#include <executorch/runtime/core/error.h> | ||
#include <executorch/runtime/core/result.h> | ||
#include <executorch/runtime/executor/method.h> | ||
#include <executorch/runtime/executor/program.h> | ||
#include <executorch/runtime/executor/test/managed_memory_manager.h> | ||
#include <executorch/runtime/platform/runtime.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace ::testing; | ||
using executorch::extension::FlatTensorDataMap; | ||
using executorch::runtime::DataLoader; | ||
using executorch::runtime::Error; | ||
using executorch::runtime::FreeableBuffer; | ||
using executorch::runtime::Method; | ||
using executorch::runtime::Program; | ||
using executorch::runtime::Result; | ||
using executorch::runtime::testing::ManagedMemoryManager; | ||
using torch::executor::util::FileDataLoader; | ||
|
||
constexpr size_t kDefaultNonConstMemBytes = 32 * 1024U; | ||
constexpr size_t kDefaultRuntimeMemBytes = 32 * 1024U; | ||
|
||
class DataSeparationTest : public ::testing::Test { | ||
protected: | ||
void SetUp() override { | ||
// Since these tests cause ET_LOG to be called, the PAL must be initialized | ||
// first. | ||
executorch::runtime::runtime_init(); | ||
|
||
// Create data loaders. | ||
Result<FileDataLoader> linear_program_loader = | ||
FileDataLoader::from(std::getenv("ET_MODULE_LINEAR_XNN_PROGRAM_PATH")); | ||
ASSERT_EQ(linear_program_loader.error(), Error::Ok); | ||
linear_program_loader_ = std::make_unique<FileDataLoader>( | ||
std::move(linear_program_loader.get())); | ||
|
||
Result<FileDataLoader> linear_data_loader = | ||
FileDataLoader::from(std::getenv("ET_MODULE_LINEAR_XNN_DATA_PATH")); | ||
ASSERT_EQ(linear_data_loader.error(), Error::Ok); | ||
linear_data_loader_ = | ||
std::make_unique<FileDataLoader>(std::move(linear_data_loader.get())); | ||
|
||
// Create programs. | ||
Result<Program> linear_program = Program::load( | ||
linear_program_loader_.get(), | ||
Program::Verification::InternalConsistency); | ||
ASSERT_EQ(linear_program.error(), Error::Ok); | ||
linear_program_ = | ||
std::make_unique<Program>(std::move(linear_program.get())); | ||
|
||
Result<FlatTensorDataMap> linear_data_map = | ||
FlatTensorDataMap::load(linear_data_loader_.get()); | ||
EXPECT_EQ(linear_data_map.error(), Error::Ok); | ||
linear_data_map_ = | ||
std::make_unique<FlatTensorDataMap>(std::move(linear_data_map.get())); | ||
} | ||
|
||
private: | ||
std::unique_ptr<FileDataLoader> linear_program_loader_; | ||
std::unique_ptr<FileDataLoader> linear_data_loader_; | ||
|
||
protected: | ||
std::unique_ptr<Program> linear_program_; | ||
std::unique_ptr<FlatTensorDataMap> linear_data_map_; | ||
}; | ||
|
||
TEST_F(DataSeparationTest, TestExternalData) { | ||
FlatTensorDataMap* data_map = linear_data_map_.get(); | ||
EXPECT_EQ(data_map->get_num_keys().get(), 2); | ||
|
||
Result<const char*> key0 = data_map->get_key(0); | ||
EXPECT_EQ(key0.error(), Error::Ok); | ||
Result<const char*> key1 = data_map->get_key(1); | ||
EXPECT_EQ(key1.error(), Error::Ok); | ||
|
||
// Check that accessing keys out of bounds fails. | ||
EXPECT_EQ(data_map->get_key(2).error(), Error::InvalidArgument); | ||
|
||
// Linear.weight | ||
Result<FreeableBuffer> data0 = data_map->get_data(key0.get()); | ||
EXPECT_EQ(data0.error(), Error::Ok); | ||
EXPECT_EQ(data0.get().size(), 36); // 3*3*4 (3*3 matrix, 4 bytes per float) | ||
|
||
// Linear.bias | ||
Result<FreeableBuffer> data1 = data_map->get_data(key1.get()); | ||
EXPECT_EQ(data1.error(), Error::Ok); | ||
EXPECT_EQ(data1.get().size(), 12); // 3*4 (3 vector, 4 bytes per float) | ||
|
||
// Check that accessing non-existent data fails. | ||
Result<FreeableBuffer> data2 = data_map->get_data("nonexistent"); | ||
EXPECT_EQ(data2.error(), Error::NotFound); | ||
} | ||
|
||
TEST_F(DataSeparationTest, TestE2E) { | ||
ManagedMemoryManager mmm(kDefaultNonConstMemBytes, kDefaultRuntimeMemBytes); | ||
Result<Method> method = linear_program_->load_method( | ||
"forward", &mmm.get(), nullptr, linear_data_map_.get()); | ||
ASSERT_EQ(method.error(), Error::Ok); | ||
|
||
// Can execute the method. | ||
Error err = method->execute(); | ||
ASSERT_EQ(err, Error::Ok); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be an e2e test? instead of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmn, could you expand a bit more? It should test the E2E