Skip to content

Commit

Permalink
Fix Dispatch API test cases
Browse files Browse the repository at this point in the history
The NPU binary files were not being loaded from the right path

PiperOrigin-RevId: 708249997
  • Loading branch information
ai-edge-bot authored and copybara-github committed Dec 20, 2024
1 parent ad5c783 commit 2d4f82b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tflite/experimental/litert/core/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool Exists(absl::string_view path) { return StdExists(MakeStdPath(path)); }
Expected<size_t> Size(absl::string_view path) {
auto std_path = MakeStdPath(path);
if (!StdExists(std_path)) {
return Error(kLiteRtStatusErrorNotFound);
return Error(kLiteRtStatusErrorNotFound, "File not found");
}
return StdSize(std_path);
}
Expand All @@ -86,7 +86,7 @@ Expected<OwningBufferRef<uint8_t>> LoadBinaryFile(absl::string_view path) {
auto std_path = MakeStdPath(path);

if (!StdExists(std_path)) {
return Error(kLiteRtStatusErrorFileIO);
return Error(kLiteRtStatusErrorFileIO, "File not found");
}

OwningBufferRef<uint8_t> buf(StdSize(std_path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ TEST(DispatchApi, GoogleTensor) {
kLiteRtStatusOk);
ABSL_LOG(INFO) << "device_context: " << device_context;

auto model_file_name = kGoogleTensorModelFileName;
auto model_file_name =
litert::testing::GetTestFilePath(kGoogleTensorModelFileName);
auto model = litert::internal::LoadBinaryFile(model_file_name);
EXPECT_TRUE(model);
EXPECT_TRUE(model) << model.Error();
ABSL_LOG(INFO) << "Loaded model " << model_file_name << ", " << model->Size()
<< " bytes";

Expand Down
1 change: 1 addition & 0 deletions tflite/experimental/litert/vendors/mediatek/dispatch/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ cc_test(
"//tflite/experimental/litert/c:litert_common",
"//tflite/experimental/litert/c:litert_tensor_buffer",
"//tflite/experimental/litert/core:filesystem",
"//tflite/experimental/litert/test:common",
"//tflite/experimental/litert/test:simple_model_npu",
"//tflite/experimental/litert/vendors/c:litert_dispatch_c_api",
"@com_google_absl//absl/log",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "tflite/experimental/litert/c/litert_tensor_buffer.h"
#include "tflite/experimental/litert/c/litert_tensor_buffer_requirements.h"
#include "tflite/experimental/litert/core/filesystem.h"
#include "tflite/experimental/litert/test/common.h"
#include "tflite/experimental/litert/test/testdata/simple_model_test_vectors.h"
#include "tflite/experimental/litert/vendors/c/litert_dispatch.h"

Expand Down Expand Up @@ -60,9 +61,10 @@ TEST(DispatchApi, MediaTek) {
kLiteRtStatusOk);
ABSL_LOG(INFO) << "device_context: " << device_context;

auto model_file_name = kMediaTekModelFileName;
auto model_file_name =
litert::testing::GetTestFilePath(kMediaTekModelFileName);
auto model = litert::internal::LoadBinaryFile(model_file_name);
EXPECT_TRUE(model);
EXPECT_TRUE(model) << model.Error();
ABSL_LOG(INFO) << "Loaded model " << model_file_name << ", " << model->Size()
<< " bytes";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ struct LiteRtCompiledResultT {
LiteRtStatus LiteRtGetCompiledResultByteCode(
LiteRtCompiledResult compiled_result, const void** byte_code,
size_t* byte_code_size) {
if (!compiled_result || !byte_code || !byte_code_size) {
return kLiteRtStatusErrorInvalidArgument;
}
*byte_code = compiled_result->context_bin.data();
*byte_code_size = compiled_result->context_bin.size();
return kLiteRtStatusOk;
Expand All @@ -163,7 +166,9 @@ LiteRtStatus LiteRtGetCompiledResultByteCode(
LiteRtStatus LiteRtGetCompiledResultCallInfo(
LiteRtCompiledResult compiled_result, LiteRtParamIndex call_idx,
const void** call_info, size_t* call_info_size) {
if (call_idx >= compiled_result->graph_names.size()) {
if (!compiled_result || !call_info || !call_info_size) {
return kLiteRtStatusErrorInvalidArgument;
} else if (call_idx >= compiled_result->graph_names.size()) {
return kLiteRtStatusErrorIndexOOB;
}

Expand All @@ -175,6 +180,9 @@ LiteRtStatus LiteRtGetCompiledResultCallInfo(

LiteRtStatus LiteRtGetNumCompiledResultCalls(
LiteRtCompiledResult compiled_result, LiteRtParamIndex* num_calls) {
if (!compiled_result || !num_calls) {
return kLiteRtStatusErrorInvalidArgument;
}
*num_calls = compiled_result->graph_names.size();
return kLiteRtStatusOk;
}
Expand Down
1 change: 1 addition & 0 deletions tflite/experimental/litert/vendors/qualcomm/dispatch/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ cc_test(
"//tflite/experimental/litert/c:litert_common",
"//tflite/experimental/litert/c:litert_tensor_buffer",
"//tflite/experimental/litert/core:filesystem",
"//tflite/experimental/litert/test:common",
"//tflite/experimental/litert/test:simple_model_npu",
"//tflite/experimental/litert/vendors/c:litert_dispatch_c_api",
"@com_google_absl//absl/log",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "tflite/experimental/litert/c/litert_tensor_buffer.h"
#include "tflite/experimental/litert/c/litert_tensor_buffer_requirements.h"
#include "tflite/experimental/litert/core/filesystem.h"
#include "tflite/experimental/litert/test/common.h"
#include "tflite/experimental/litert/test/testdata/simple_model_test_vectors.h"
#include "tflite/experimental/litert/vendors/c/litert_dispatch.h"

Expand Down Expand Up @@ -60,9 +61,10 @@ TEST(Qualcomm, DispatchApiWithFastRpc) {
kLiteRtStatusOk);
ABSL_LOG(INFO) << "device_context: " << device_context;

auto model_file_name = kQualcommModelFileName;
auto model_file_name =
litert::testing::GetTestFilePath(kQualcommModelFileName);
auto model = litert::internal::LoadBinaryFile(model_file_name);
EXPECT_TRUE(model);
EXPECT_TRUE(model) << model.Error();
ABSL_LOG(INFO) << "Loaded model " << model_file_name << ", " << model->Size()
<< " bytes";

Expand Down Expand Up @@ -311,9 +313,10 @@ TEST(Qualcomm, DispatchApiWithDmaBuf) {
kLiteRtStatusOk);
ABSL_LOG(INFO) << "device_context: " << device_context;

auto model_file_name = kQualcommModelFileName;
auto model = ::litert::internal::LoadBinaryFile(model_file_name);
EXPECT_TRUE(model);
auto model_file_name =
litert::testing::GetTestFilePath(kQualcommModelFileName);
auto model = litert::internal::LoadBinaryFile(model_file_name);
EXPECT_TRUE(model) << model.Error();
ABSL_LOG(INFO) << "Loaded model " << model_file_name << ", " << model->Size()
<< " bytes";

Expand Down

0 comments on commit 2d4f82b

Please sign in to comment.