Only prod log interpreter creation on mobile platforms
PiperOrigin-RevId: 263674744
This commit is contained in:
parent
4225c4f697
commit
4735b9bc02
@ -29,6 +29,20 @@ limitations under the License.
|
|||||||
#include "tensorflow/lite/schema/schema_generated.h"
|
#include "tensorflow/lite/schema/schema_generated.h"
|
||||||
#include "tensorflow/lite/util.h"
|
#include "tensorflow/lite/util.h"
|
||||||
|
|
||||||
|
// TODO(b/139446230): Move to portable platform header.
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#define TFLITE_IS_MOBILE_PLATFORM
|
||||||
|
#endif // defined(__ANDROID__)
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
|
#define TFLITE_IS_MOBILE_PLATFORM
|
||||||
|
#elif TARGET_OS_IPHONE
|
||||||
|
#define TFLITE_IS_MOBILE_PLATFORM
|
||||||
|
#endif
|
||||||
|
#endif // defined(__APPLE__)
|
||||||
|
|
||||||
// TODO(b/132087118): move static_assert to c_api_internal when compiled with
|
// TODO(b/132087118): move static_assert to c_api_internal when compiled with
|
||||||
// C++.
|
// C++.
|
||||||
static_assert(sizeof(TfLiteFloat16) == sizeof(uint16_t),
|
static_assert(sizeof(TfLiteFloat16) == sizeof(uint16_t),
|
||||||
@ -60,7 +74,13 @@ Interpreter::Interpreter(ErrorReporter* error_reporter)
|
|||||||
: error_reporter_(error_reporter ? error_reporter
|
: error_reporter_(error_reporter ? error_reporter
|
||||||
: DefaultErrorReporter()) {
|
: DefaultErrorReporter()) {
|
||||||
// TODO(b/128420794): Include the TFLite runtime version in the log.
|
// TODO(b/128420794): Include the TFLite runtime version in the log.
|
||||||
|
// Prod logging is useful for mobile platforms where scraping console logs is
|
||||||
|
// critical for debugging.
|
||||||
|
#if defined(TFLITE_IS_MOBILE_PLATFORM)
|
||||||
TFLITE_LOG_PROD_ONCE(TFLITE_LOG_INFO, "Initialized TensorFlow Lite runtime.");
|
TFLITE_LOG_PROD_ONCE(TFLITE_LOG_INFO, "Initialized TensorFlow Lite runtime.");
|
||||||
|
#else
|
||||||
|
TFLITE_LOG_ONCE(TFLITE_LOG_INFO, "Initialized TensorFlow Lite runtime.");
|
||||||
|
#endif
|
||||||
|
|
||||||
// There's always at least 1 subgraph which is the primary subgraph.
|
// There's always at least 1 subgraph which is the primary subgraph.
|
||||||
AddSubgraphs(1);
|
AddSubgraphs(1);
|
||||||
|
@ -65,8 +65,14 @@ TEST(BasicInterpreter, ZeroInterpreter) {
|
|||||||
testing::internal::CaptureStderr();
|
testing::internal::CaptureStderr();
|
||||||
|
|
||||||
Interpreter interpreter;
|
Interpreter interpreter;
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
const char* kExpectedLog = "INFO: Initialized TensorFlow Lite runtime";
|
||||||
|
#else
|
||||||
|
const char* kExpectedLog = "";
|
||||||
|
#endif
|
||||||
EXPECT_THAT(testing::internal::GetCapturedStderr(),
|
EXPECT_THAT(testing::internal::GetCapturedStderr(),
|
||||||
testing::HasSubstr("INFO: Initialized TensorFlow Lite runtime"));
|
testing::HasSubstr(kExpectedLog));
|
||||||
|
|
||||||
interpreter.SetInputs({});
|
interpreter.SetInputs({});
|
||||||
interpreter.SetOutputs({});
|
interpreter.SetOutputs({});
|
||||||
|
@ -68,12 +68,14 @@ class MinimalLogger {
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// In debug builds, always log.
|
// In debug builds, always log.
|
||||||
#define TFLITE_LOG TFLITE_LOG_PROD
|
#define TFLITE_LOG TFLITE_LOG_PROD
|
||||||
|
#define TFLITE_LOG_ONCE TFLITE_LOG_PROD_ONCE
|
||||||
#else
|
#else
|
||||||
// In prod builds, never log, but ensure the code is well-formed and compiles.
|
// In prod builds, never log, but ensure the code is well-formed and compiles.
|
||||||
#define TFLITE_LOG(severity, format, ...) \
|
#define TFLITE_LOG(severity, format, ...) \
|
||||||
while (false) { \
|
while (false) { \
|
||||||
TFLITE_LOG_PROD(severity, format, ##__VA_ARGS__); \
|
TFLITE_LOG_PROD(severity, format, ##__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
|
#define TFLITE_LOG_ONCE TFLITE_LOG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_MINIMAL_LOGGING_H_
|
#endif // TENSORFLOW_LITE_MINIMAL_LOGGING_H_
|
||||||
|
@ -73,6 +73,18 @@ TEST(MinimalLogging, Debug) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MinimalLogging, DebugOnce) {
|
||||||
|
testing::internal::CaptureStderr();
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
TFLITE_LOG_ONCE(TFLITE_LOG_INFO, "Count: %d", i);
|
||||||
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
EXPECT_EQ("INFO: Count: 0\n", testing::internal::GetCapturedStderr());
|
||||||
|
#else
|
||||||
|
EXPECT_TRUE(testing::internal::GetCapturedStderr().empty());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tflite
|
} // namespace tflite
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
Loading…
Reference in New Issue
Block a user